# [SciPy-User] Solve an arbitrary function

Robert Kern robert.kern@gmail....
Thu Jul 30 23:17:33 CDT 2009

```On Thu, Jul 30, 2009 at 23:03, Permafacture<permafacture@gmail.com> wrote:
> I'm new to this package, and am used to mathematica.
>
> I've been reading through the tutorials and numpy lists of functions,
> yet i cannot find the answer to this, though it would be trivial in
> mathematica.  Can someone show me an example of how to find the
> intersection of a line and a polynomial?
>
> for instance: y1=x1^2, y2=x2+1
>
> Solving a system of linear equations is pretty straight forward, but
> it isn't clear to me how to approach this in scipy.  The most general
> approach to this would probably be the most useful to me.

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

In [1]: from scipy.optimize import fsolve

In [2]: import numpy as np

In [3]: def f(xy):
...:     x, y = xy
...:     z = np.array([y - x**2, y - x - 1.0])
...:     return z
...:

In [4]: fsolve(f, [1.0, 2.0])
Out[4]: array([ 1.61803399,  2.61803399])

In [5]: fsolve(f, [-0.5, 1.5])
Out[5]: array([-0.61803399,  0.38196601])

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
```