[SciPy-user] fsolve and additional parameters

matt matt at hotdispatch.com
Mon Jul 19 17:10:13 CDT 2004


fsolve's  first argument is a function of a single variable.  it tries 
to modify the input until the output is 0.   What if I want the 
function to take an extra parameter as an input to be ignored by 
fsolve?

My specific problem is that I want to set up an OO system that uses 
fsolve.  I have a superclass with a method that uses fsolve.  I have 
subclasses that define different systems of equations in their methods. 
  I want the superclass to call fsolve on the subclasses method and 
collect results.  The problem is that envoking the subclass method 
inherently passes the object as the first argument and fsolve expects a 
single input single output function.

Doing it in the form:

class superclassname
	def mysolve
		fsolve(self.equations,guesses)

class subclassname(superclassname):
	def equations(x)
		return x

fails because envoking self.equations passes self as the first arg 
automatically, and python complains that method equations got 1 arg and 
needs 2

Alternately in the form:

class superclassname
	def mysolve
		fsolve(self.equations,guesses)

class subclassname(superclassname):
	def equations(self,x)
		return self,x

fails because fsolve says that the input and output shapes of equations 
are not the same.


Any ideas on how to use fsolve on a class method??

-Matt



More information about the SciPy-user mailing list