![](https://secure.gravatar.com/avatar/d41fa6e1fe29e6c5c5821b5a3f31f190.jpg?s=120&d=mm&r=g)
Hi all, Is it somehow possible to improve the accuracy of derivative ? A small example is attached. from scipy import * def func(x): return exp(2*x) for i in arange(1,6): print i,' derivative of exp(2*x) at x=0',derivative(func,0.0,0.01,i,order=7),'exact',2**i Any suggestion ? Nils
![](https://secure.gravatar.com/avatar/80473ff660f57aa7f90affadd2240008.jpg?s=120&d=mm&r=g)
Nils Wagner wrote:
Hi all,
Is it somehow possible to improve the accuracy of derivative ?
Higher order? from scipy import * def func(x): return exp(2*x) for i in arange(1,6): d=derivative(func,0.0,dx,i,order=9) print i,' derivative of exp(2*x) at x=0',d,'exact',2**i print ' rel error %e' % (d/2**i - 1) Changing the order to 9 improves the accuracy of the 6th derivative from 1e-4 to 3e-7.
![](https://secure.gravatar.com/avatar/d41fa6e1fe29e6c5c5821b5a3f31f190.jpg?s=120&d=mm&r=g)
Stephen Walton wrote:
Nils Wagner wrote:
Hi all,
Is it somehow possible to improve the accuracy of derivative ?
Higher order?
from scipy import *
def func(x): return exp(2*x)
for i in arange(1,6): d=derivative(func,0.0,dx,i,order=9) print i,' derivative of exp(2*x) at x=0',d,'exact',2**i print ' rel error %e' % (d/2**i - 1)
Changing the order to 9 improves the accuracy of the 6th derivative from 1e-4 to 3e-7.
The problem is that I need very accurate results, since I want to use them as an input of cof in SUBROUTINE pade (see my previous E-mail Pade Approximants). cof contains the leading terms of the power series expansion of a function. Nils
_______________________________________________ SciPy-user mailing list SciPy-user@scipy.net http://www.scipy.net/mailman/listinfo/scipy-user
![](https://secure.gravatar.com/avatar/80473ff660f57aa7f90affadd2240008.jpg?s=120&d=mm&r=g)
Numerical derivatives are limited in accuracy by their very nature. I don't know very much about Pade computations, I'm afraid, But, if the code you need the derivative of is in C or Fortran, you might try one of the automatic differentation codes out there. The basic idea is that, since any computation on a real computer is composed of elementary operations with analytic derivatives, repeated automatic application of the chain rule results in a derivative which is accurate to machine precision. Of course, these codes will only produce a first or second derivative in my experience, not a sixth. Do you need sixth derivatives?
![](https://secure.gravatar.com/avatar/d41fa6e1fe29e6c5c5821b5a3f31f190.jpg?s=120&d=mm&r=g)
On Wed, 23 Feb 2005 09:34:13 -0800 Stephen Walton <stephen.walton@csun.edu> wrote:
Numerical derivatives are limited in accuracy by their very nature. I don't know very much about Pade computations, I'm afraid, But, if the code you need the derivative of is in C or Fortran, you might try one of the automatic differentation codes out there. The basic idea is that, since any computation on a real computer is composed of elementary operations with analytic derivatives, repeated automatic application of the chain rule results in a derivative which is accurate to machine precision. Of course, these codes will only produce a first or second derivative in my experience, not a sixth. Do you need sixth derivatives?
This depends on the order of the Taylor series expansion. pade(an,8) is quite common in approximating the matrix exponential. pade(an, m) Given Taylor series coefficients in an, return a Pade approximation to the function as the ratio of two polynomials p / q where the order of q is m. Nils
_______________________________________________ SciPy-user mailing list SciPy-user@scipy.net http://www.scipy.net/mailman/listinfo/scipy-user
participants (2)
-
Nils Wagner
-
Stephen Walton