Next: Interpolation (interpolate) Up: Optimization (optimize) Previous: Bounded minimization (optimize.fminbound)

Root finding (optimize.fsolve)

To find the roots of a polynomial, the command roots from Numeric Python is useful (this is also available as roots). To find a root of a set of non-linear equations, the command optimize.fsolve is needed. For example, the following example finds the roots of the single-variable transcendental equation

\begin{displaymath}
x+2\cos \left( x\right) =0,\end{displaymath}

and the set of non-linear equations

\begin{eqnarray*}
x_{0}\cos \left( x_{1}\right) & = & 4,\\
x_{0}x_{1}-x_{1} & = & 5.
\end{eqnarray*}



The results are \( x=-1.0299 \) and \( x_{0}=6.5041,  x_{1}=0.9084 \).


>>> def func(x):
        return x + 2*cos(x)

>>> def func2(x):
        out = [x[0]*cos(x[1]) - 4]
        out.append(x[1]*x[0] - x[1] - 5)
        return out

>>> from scipy.optimize import fsolve
>>> x0 = fsolve(func, 0.3)
>>> print x0
-1.02986652932

>>> x02 = fsolve(func2, [1, 1])
>>> print x02
[ 6.5041  0.9084]



2001-07-27