Find the points at which two given functions intersect

Consider the example of finding the intersection of a polynomial and a line:

y1=x1^2
y2=x2+1

   1 from scipy.optimize import fsolve
   2 
   3 import numpy as np
   4 
   5 def f(xy):
   6    x, y = xy
   7    z = np.array([y - x**2, y - x - 1.0])
   8    return z
   9 
  10 fsolve(f, [1.0, 2.0])

The result of this should be:

   1 array([ 1.61803399,  2.61803399])

See also: http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.fsolve.html#scipy.optimize.fsolve

Cookbook/Intersection (last edited 2009-07-31 18:53:08 by nokfi)