[SciPy-user] Partial Derivatives
oliphant at ee.byu.edu
Fri Feb 25 17:56:21 CST 2005
R. Padraic Springuel wrote:
> Is there a way to use the "derivative" function to take a partial
> derivative? What if one of the inputs is a list of numbers instead of
> a single number?
> def y(x,p):
> return p + p*x + p*x**2
> I can get the derivative with respect to x fairly easily with the
> derivative(y, 3, args=([[0, 0, 1]])
> where the numbers can be arbitrarily replaced. However I can't seem
> to get the derivative with respect to say p or any other member of
> p. I keep getting a TypeError regarding the number of arguments for
> y. Any suggestions?
derivative is hard-wired for the first argument. This could be changed
relatively easily and is a nice suggestion.
In the mean-time, you can define intermediate functions:
def y3(p1, x, p0, p2):
def y4(p2, x, p0, p1):
return y(x, [p0, p1, p2])
and use derivative on those functions.
More information about the SciPy-user