[SciPy-user] optimize.fsolve
Brett Olivier
bgoli at sun.ac.za
Thu Aug 18 09:47:13 EDT 2005
Hi
This is a simple example but perhaps it will help:
######
import scipy
x0 = 10.0
x2 = 0.0
init_val = [10,20]
def DE_explicit_ss(s):
sdot = scipy.zeros((2),'d')
sdot[0] = (10.0*x0 - s[0])-(5.0*s[0] - s[1])
sdot[1] = (5.0*s[0] - s[1])-(s[1] - x2)
return sdot
sres = scipy.optimize.fsolve(DE_explicit_ss, init_val)
print 'result'
print sres
######
"fsolve" is a wrapper around MINPACK's hybrd and hybrj algorithms.
From scipy/Lib/optimize/minpack/hybrd.f
c the purpose of hybrd is to find a zero of a system of
c n nonlinear functions in n variables by a modification
c of the powell hybrid method. the user must provide a
c subroutine which calculates the functions. the jacobian is
c then calculated by a forward-difference approximation.
Brett
On Thursday 18 August 2005 15:14, Ryan Krauss wrote:
> Yes, I think it is doing exactly what Matlab would do. You can have a
> vector input, you just need to have a scalar output that you are trying
> to drive to zero.
>
> Howey, David A wrote:
> > Thanks for this... interesting.
> >
> > What I'm trying to do eventually use fsolve to solve for two unknowns
> > (call them p and v) in two non-linear equations (call them F1, F2). In
> > matlab, one would define a vector function say myfunc returning a vector
> > F with F(1) (first element in the vector) evaluating to the first
> > equation and F(2) to the second. The function would accept a vector
> > input, say x, which is = [ p ; v]. ie a vector of the two unknowns.
> >
> > Do you think scipy's fsolve can work on vectors (arrays) like this in the
> > same way?
> >
> > Dave
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > SciPy-user mailing list
> > SciPy-user at scipy.net
> > http://www.scipy.net/mailman/listinfo/scipy-user
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.net
> http://www.scipy.net/mailman/listinfo/scipy-user
--
Brett G. Olivier Ph.D.
Triple-J Group for Molecular Cell Physiology
Stellenbosch University
bgoli at sun dot ac dot za http://glue.jjj.sun.ac.za/~bgoli
Tel +27-21-8082704 Fax +27-21-8085863 Mobile +27-82-7329306
I wouldn't be so paranoid if you weren't all out to get me!!
More information about the SciPy-User
mailing list