Hi, I'm trying to figure out how to compute the derivatives of a function with scipy, but the documentation is a bit terse for me: def derivative(func,x0,dx=1.0,n=1,args=(),order=3): """Given a function, use an N-point central differenece formula with spacing dx to compute the nth derivative at x0, where N is the value of order and must be odd. Warning: Decreasing the step size too small can result in round-off error. """ I would like to compute a derivative of an arbitrary order, but by reading the docs, I'm not sure what the n and order parameters exactly means. Someone smarter than me can help me? -- Francesc Alted
Francesc Alted wrote:
Hi,
I'm trying to figure out how to compute the derivatives of a function with scipy, but the documentation is a bit terse for me:
def derivative(func,x0,dx=1.0,n=1,args=(),order=3): """Given a function, use an N-point central differenece formula with spacing dx to compute the nth derivative at x0, where N is the value of order and must be odd.
Warning: Decreasing the step size too small can result in round-off error. """
I would like to compute a derivative of an arbitrary order, but by reading the docs, I'm not sure what the n and order parameters exactly means.
n is the derivative you are computing and order is the order of the central difference approximateion formula you will use to approximate it (i.e. how many sample values of func will be used) order should probably default to n+2 or something rather than only three all the time. But suggestions are welcome. -Travis O.
Francesc Alted wrote:
Hi,
I'm trying to figure out how to compute the derivatives of a function with scipy, but the documentation is a bit terse for me:
def derivative(func,x0,dx=1.0,n=1,args=(),order=3): """Given a function, use an N-point central differenece formula with spacing dx to compute the nth derivative at x0, where N is the value of order and must be odd.
Warning: Decreasing the step size too small can result in round-off error. """
I would like to compute a derivative of an arbitrary order, but by reading the docs, I'm not sure what the n and order parameters exactly means.
Someone smarter than me can help me?
'n' as in d^n/dx^n . Somewhat confusingly, 'N' is being used in the docstring as a synonym for 'order' and is the number of discrete points used to evaluate the numerical derivative. I'm going to fix that. For example, when n=2, and order=3, one is computing the second central derivative using 3 points [x0-dx, x0, x0+dx]. -- Robert Kern rkern@ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter
'n' as in d^n/dx^n .
Somewhat confusingly, 'N' is being used in the docstring as a synonym for 'order' and is the number of discrete points used to evaluate the numerical derivative. I'm going to fix that.
For example, when n=2, and order=3, one is computing the second central derivative using 3 points [x0-dx, x0, x0+dx].
Normally, one would expect "order" to be an indication of the accuracy of the derivative. So, order=p should mean d^n/dx^n (exact answer) - (what's computed) = O(dx^p) where dx is the mesh spacing. Clearly, with three points for the second derivative, the order is only two, so this is clearly not a mathematically correct use of the word "order"... -- Giovanni Samaey
Giovanni Samaey wrote:
'n' as in d^n/dx^n .
Somewhat confusingly, 'N' is being used in the docstring as a synonym for 'order' and is the number of discrete points used to evaluate the numerical derivative. I'm going to fix that.
For example, when n=2, and order=3, one is computing the second central derivative using 3 points [x0-dx, x0, x0+dx].
Normally, one would expect "order" to be an indication of the accuracy of the derivative. So, order=p should mean d^n/dx^n (exact answer) - (what's computed) = O(dx^p) where dx is the mesh spacing. Clearly, with three points for the second derivative, the order is only two, so this is clearly not a mathematically correct use of the word "order"...
Not really. "Order" is an incredibly overloaded word in this area. Its usage here is one of several acceptable ones. "numpoints" may be clearer, though. -- Robert Kern rkern@ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter
Robert Kern wrote:
Giovanni Samaey wrote:
'n' as in d^n/dx^n .
Somewhat confusingly, 'N' is being used in the docstring as a synonym for 'order' and is the number of discrete points used to evaluate the numerical derivative. I'm going to fix that.
For example, when n=2, and order=3, one is computing the second central derivative using 3 points [x0-dx, x0, x0+dx].
Normally, one would expect "order" to be an indication of the accuracy of the derivative. So, order=p should mean d^n/dx^n (exact answer) - (what's computed) = O(dx^p) where dx is the mesh spacing. Clearly, with three points for the second derivative, the order is only two, so this is clearly not a mathematically correct use of the word "order"...
Not really. "Order" is an incredibly overloaded word in this area. Its usage here is one of several acceptable ones. "numpoints" may be clearer, though.
Where is the derivative function in scipy?
David Grant wrote:
Robert Kern wrote:
Giovanni Samaey wrote:
'n' as in d^n/dx^n .
Somewhat confusingly, 'N' is being used in the docstring as a synonym for 'order' and is the number of discrete points used to evaluate the numerical derivative. I'm going to fix that.
For example, when n=2, and order=3, one is computing the second central derivative using 3 points [x0-dx, x0, x0+dx].
Normally, one would expect "order" to be an indication of the accuracy of the derivative. So, order=p should mean d^n/dx^n (exact answer) - (what's computed) = O(dx^p) where dx is the mesh spacing. Clearly, with three points for the second derivative, the order is only two, so this is clearly not a mathematically correct use of the word "order"...
Not really. "Order" is an incredibly overloaded word in this area. Its usage here is one of several acceptable ones. "numpoints" may be clearer, though.
Where is the derivative function in scipy?
doh, found it. It would be nice if the api docs page had an index of all functions, instead of having to "guess" that it was in common and clicking there.
doh, found it. It would be nice if the api docs page had an index of all functions, instead of having to "guess" that it was in common and clicking there.
Timely comment ... I just spent 15 minutes looking for bisect(), which I knew had to be somewhere, but I didn't know where. (optimize, btw).
participants (6)
-
David Grant
-
Francesc Alted
-
Gary
-
Giovanni Samaey
-
Robert Kern
-
Travis Oliphant