from scipy.optimize import fsolve import pylab import numpy pow3 = lambda x : x**3 result = fsolve(pow3,10) # starting from x = 10 print result x = numpy.linspace(-1,1,50) pylab.plot(x,pow3(x),result,pow3(result),'ro') pylab.grid(b=1) pylab.show()In the following graph we can see f(x) (blue curve) and the solution found (red dot)

## Monday, May 9, 2011

### How to find the roots of a function with fsolve

The function fsolve provided by numpy return the roots of the (non-linear) equations defined by func(x) = 0 given a starting estimate. We will see how to use fsolve to find the root of the function

Subscribe to:
Post Comments (Atom)

how can use this module in google app engine??

ReplyDeleteHello Dhwanit, I'm sorry but you can't use this code in Google App Engine because it doesn't include the scipy library.

ReplyDeletewith what you make that program? I type it in python 2.7 error

ReplyDeleteI made it with python 2.7. Make sure you have scipy installed on your system.

Delete