# [math] Numerical derivatives in Commons Math Classic List Threaded 12 messages Open this post in threaded view
|

## [math] Numerical derivatives in Commons Math

 Hello, I have a proposal for a numerical derivatives framework for Commons Math. I'd like to add the ability to take any UnivariateRealFunction and produce another function that represents it's derivative for an arbitrary order. Basically, I'm saying add a factory-like interface that looks something like the following: public interface UniverateNumericalDeriver {  public UnivariateRealFunction derive(UnivariateRealFunction f, int derivOrder); } For an initial implementation of this interface, I propose using finite differences - either central, forward, or backward. Computing the finite difference coefficients, for any derivative order and any error order, is a relatively trivial linear algebra problem. The user will simply choose an error order and difference type when setting up an FD univariate deriver - everything else will happen automagically. You can compute the FD coefficients once the user invokes the function in the interface above (might be expensive), and determine an appropriate stencil width when they call evaluate(double) on the function returned by the aformentioned method - for example, if the user has asked for the nth derivative, we simply use the nth root of the machine epsilon/double ulp for the stencil width. It would also be pretty easy to let the user control this (which might be desirable in some cases). Wikipedia has decent article on FDs of all flavors: http://en.wikipedia.org/wiki/Finite_differenceThere are, of course, many other univariate numerical derivative schemes that could be added in the future - using Fourier transforms, Barak's adaptive degree polynomial method, etc. These could be added later. We could also add the ability to numerically differentiate at single point using an arbitrary or user-defined grid (rather than an automatically generated one, like above). Barak's method and Fornberg finite difference coefficients could be used in this case: http://pubs.acs.org/doi/abs/10.1021/ac00113a006http://amath.colorado.edu/faculty/fornberg/Docs/MathComp_88_FD_formulas.pdfIt would also make sense to add vectorial and matrix-flavored versions of interface above. These interfaces would be slightly more complex, but nothing too crazy. Again, the initial implementation would be finite differences. This would also be really easy to implement, since multivariate FD coefficients are nothing more than an outer product of their univariate cousins. The Wikipedia article also has some good introductory material on multivariate FDs. Cheers, Fran. --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email]
Open this post in threaded view
|

## Re: [math] Numerical derivatives in Commons Math

Open this post in threaded view
|

## Re: [math] Numerical derivatives in Commons Math

Open this post in threaded view
|

## Re: [math] Numerical derivatives in Commons Math

Open this post in threaded view
|

## Re: [math] Numerical derivatives in Commons Math

 As Patrick suggested, this approach should really be extended to multivariate functions. To cite but one example, I recently attended a conf where Pr. Prevost (Princeton) talked about non-linear finite elements calcs. The long standing approach had always been to implement the analytical expressions tangent stiffness (which is nothing but a jacobian matrix). He argued strongly against it for at least two reasons   - it is error-prone,   - most of the time, the expressions are so complex that their evaluation is just as time-consuming as a numerical derivative. So, having some robust algorithms for multidimensional functions already implemented in CM would in my view be invaluable. Sébastien --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email]
Open this post in threaded view
|

## Re: [math] Numerical derivatives in Commons Math

Open this post in threaded view
|

## Re: [math] Numerical derivatives in Commons Math

Open this post in threaded view
|

## Re: [math] Numerical derivatives in Commons Math

Open this post in threaded view
|

## Re: [math] Numerical derivatives in Commons Math

Open this post in threaded view
|