# commons-dev mailing list archives

##### Site index · List index
Message view
Top
From "Mark R. Diggory" <mdigg...@latte.harvard.edu>
Subject Re: [math] Numerical Derivative pattern q.
Date Wed, 12 Nov 2003 02:58:21 GMT
```Bear with me, I'm trying to catchup a little bit here.

My first thought here is, how is calling Function.value(x) different
from calling Function.firstDerivative(x)? We don't really implement a
"Evaluator" or "EvaluatorFactory" for returning a function's
Function.value(x). We only provide Solvers and Solver factories for
different ways of Numerically solving the Functions value(x) method for 0.

Will a Differentiator/Factory be solving for the derivative? In which
case, as the algorithms used are really already implemented in the
solvers, wouldn't we just expand them with methods that allow us to
solve for the derivatives? For Example:

UnivariateRealSolver bs = new BisectionSolver(...);

double d = bs.solveFirstDerivative(min,max);

and

double d = bs.solveSecondDerivative(min,max);

-Mark

Matt Cliff wrote:
> I have been scratching out an implementation of a numerical derivative to
> add to the commons-math and keep going back and forth between two
> approaches.
>
>   (all this would be in the o.a.c.math.analysis package)
>   (for brevity I have omitted the prefix UnivariateReal* )
> --------------------------------------------------------------------
>  (1) a couple classes like Differentiator (interface) and
> DifferentiatorFactory (class), where we have a method like
>    "Differentiator DifferentiatorFactory.getDefaultDifferentiator(
> Function f )"
>
>   and another method like "double Differentiator.derivate( double x)"
>      or  "double Differentiator.value(double x)"
>
>
>    this keeps the same type of pattern as that of the *Solver
>
> OR
>
>   (2) Add a class like DerivativeFactory which has a method like
>         "Function DerivativeFactory.getDefaultDerivative( Function f )"
>
>    and use the existing "double Function.value( double x)" to obtain the
> numerical estimate.
>
>
>   I first implemented it using approach (1) but as the code and usage
> turned out, it seems that (2) was easier to use (and numerically has the
> same number or operations and function evaluations).
>
>
>
>
> ----------------------------------------------------------------------
> using (2) the client code would look like
>
> public myMethod() {
>    UnivariateRealFunction f = new SomeUserDefinedFunction();
>
>    UnivariateRealFunction fprime =
>          DerivativeFactory.newInstance().getDefaultDerivative( f );
>
>    System.out.println( "f'(1.0) = "+ fprime.value(1.0) );
> }
>
>
> -------------------------------------------------------------------------
>
>  of course the Factory could allow for multiple types of Derivatives,  the
> one I have currently implemented is a centered 5-point algorithm, which
> has an operational parameter of h (or a step-size), there may also be
> parameters to handle "infinite" derivative or jumps.
>
>
>

--
Mark Diggory
Software Developer
Harvard MIT Data Center
http://osprey.hmdc.harvard.edu

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org