[SciPy-User] Solve an arbitrary function
Thu Jul 30 23:17:33 CDT 2009
On Thu, Jul 30, 2009 at 23:03, Permafacture<email@example.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.
In : from scipy.optimize import fsolve
In : import numpy as np
In : def f(xy):
...: x, y = xy
...: z = np.array([y - x**2, y - x - 1.0])
...: return z
In : fsolve(f, [1.0, 2.0])
Out: array([ 1.61803399, 2.61803399])
In : fsolve(f, [-0.5, 1.5])
Out: array([-0.61803399, 0.38196601])
"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
More information about the SciPy-User