### Find the points at which two given functions intersect

Submitted by
SciPy Central on 17 July 2011
Download
File
Update history
Revision 2 of 3: previous next
Updated by
kevindunn on 21 July 2011
Tags
from scipy.optimize import fsolve import numpy as np def f(input_vector): x, y = input_vector return np.array([y - x**2, y - x - 1.0]) # Solve the function, using (x=1, y=2) as the initial guess fsolve(f, [1.0, 2.0])

The code considers the case of finding the intersection of a polynomial, $$y=x^2$$ and a line, $$y=x+1$$.

Write these functions in the form $$\mathbf{f(x) = 0}$$, in other words:

$\begin{split}f_1(x, y) &= y - x^2 = 0\\\end{split}$$\begin{split}f_2(x, y) &= y - x - 1 = 0\end{split}$

Now write your Python function, as shown in the code, so that it accepts a vector of these inputs, $$x$$ and $$y$$, and return another vector of outputs which contains $$\mathbf{f(x)}$$.

Entry inspired by http://scipy.org/Cookbook/Intersection

Read the documentation for fsolve.

Please Sign in or Register to leave a comment

• Creative Commons Zero. No rights reserved.
Users have permission to do anything with the code and other material on this page. (More details)
• X 17
• X 14
• X 11
• X 8
• X 8
• X 7
• X 7
• X 6
• X 5
• X 4
• X 4
• X 4
• X 3
• X 3
• X 3
• Trademarks are property of their respective owners. Code and comments are owned by their respective posters. © 2013 All Rights Reserved