[SciPy-user] optimize.fsolve

Ryan Krauss ryanfedora at comcast.net
Thu Aug 18 08:19:39 EDT 2005


David,

Here is a script that does what I think you are trying to do:

from scipy.optimize import fsolve

def myfunc(xin):
     a1=12.2
     b1=3.0
     a2=-2.7
     b2=-3.5
     y1=a1*xin+b1
     y2=a2*xin+b2
     return y2-y1

myres=fsolve(myfunc,3.3)
print('Results:'+str(myres))



Looking at the docstring for fsolve (i.e. help scipy.optimize.fsolve in 
Ipython), fsolve is trying to find the where func(x)=0.  So, the 
function needs to return a scalar value that is zero at the input values 
you are looking for.

Ryan

Howey, David A wrote:
> Hi,
>  
> I'm having trouble getting fsolve to work. Does this work in a similar way to matlab's fsolve?
>  
> I thought I'd start with something really simple, just solving for where two lines cross (y = ax + b - twice). I implemented a function which takes a vector for x and y (ie. say x[0], x[1]) and 'solves' the two equations, returning F[0] and F[1].
>  
> I then call fsolve on this function... unfortunately it seems to just converge on whatever starting guess I give it, or go to massive numbers!
>  
> Dave
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.net
> http://www.scipy.net/mailman/listinfo/scipy-user




More information about the SciPy-User mailing list