[SciPy-User] fsolve - pass keyword arguments

Ashley DaSilva amd405 at psu.edu
Thu Feb 17 10:19:06 EST 2011


Hello all,

I have a function which takes some keyword arguments,

def f(x,kw1=None,kw2=None,kw3=None):
    (some stuff)
    return F

Depending on which of the kw arguments is None the function might do extra
steps to determine them. I want to use scipy.optimize.fsolve to find the
root of this function when kw3 is an integer. I am calling fsolve like this:

ans=scipy.optimize.fsolve(f, x0, args=(kw3=N,))

where x0 is an initial guess to the root and N is the integer. But I get the
error: "SyntaxError: invalid syntax". If I move kw3 to the 2nd position

def f(x,kw3=None,kw1=None,kw2=None):
    (some stuff)
    return F

and call like this:

ans=scipy.optimize.fsolve(f, x0, args=(N,))

then the function works. Does this mean that passing keyword arguments using
fsolve is not allowed? Or am I doing something incorrectly?

Thanks!
Ashley
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20110217/0ed30899/attachment.html>


More information about the SciPy-User mailing list