4

So I'm trying to find "k" which satisfies the equation

F(k,u,v,w) = 0

and u, v, and w are extra parameters. I've been trying to solve it using newton_krylov (http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.optimize.newton_krylov.html), which will solve the system numerically based on a guess for k, but there does not appear to be a way to include the other parameters.

My trouble is that I need to pass F the additional arguments, but there does not appear to be a way to pass them to F. Is there a way to pass them that I don't know about? or is there a hack I can do to make it work?

Also if there is a more appropriate function for this situation that would be cool too.

mcruz
  • 1,534
  • 2
  • 11
  • 14
James Urban
  • 320
  • 1
  • 4
  • 12
  • One assumes you could write a function F(k) that knew about u, v, and w. F(k) could either be a method of a class that include ways to set and get the other parameters, or could use u, v, and w out of a namespace defined by you that your F(k) has access to, or (last choice) use global... – Jon Custer Mar 07 '16 at 22:59

1 Answers1

7

You can pass F wrapped in lambda function into newton_krylov, something like this:

newton_krylov(lambda k:F(k,1,2,3), ... )
Aleksei Shestakov
  • 2,508
  • 2
  • 13
  • 14