# [SciPy-user] RE: root finding

Nils Wagner nwagner at mecha.uni-stuttgart.de
Tue Aug 9 07:05:35 CDT 2005

```Howey, David A wrote:

>oops, should have checked out the documentation, there is something called 'newton' in the optimize package. Still, I would appreciate any tips for use.
>
>
A small example is given below:

from scipy import *
from pylab import *
data = []

def func(x):
global data
data.append(x)
return x**2+x-2

x0 = -1.5
root = optimize.newton(func, x0, fprime=None, args=(), tol=1.48e-08,
maxiter=50)
plot(range(len(data)),data)
xlabel('Iteration')
show()

Nils

>________________________________
>
>From: scipy-user-bounces at scipy.net on behalf of Howey, David A
>Sent: Tue 09/08/2005 11:32
>To: SciPy Users List
>Subject: root finding
>
>
>Hi,
>
>I am pondering the best way to do some root finding. I have a function which I give a mass flow value to and it returns a pressure. I need to iterate the mass flow value until a specific pressure is reached. As long as sensible initial guess are chosen, the function produces a pretty smooth curve with a unique root.
>
>Initially I had a rough and ready algorithm which shoved a range of mass flows (in an array) through the function and looked for a zero crossing, and then fine tuned the result a few times. This works, but I'm wondering whether something like Newton-Raphson would be better, although I don't directly know the derivative, so I would be using a numerical approximation (I think this is called the secant method). Does scipy have an implementation of this? Any tips for use?
>
>Thanks
>
>Dave
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>SciPy-user mailing list
>SciPy-user at scipy.net
>http://www.scipy.net/mailman/listinfo/scipy-user
>
>

```