commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Cliff <m...@mattcliff.com>
Subject Re: [math] Numerical Derivative pattern q.
Date Wed, 12 Nov 2003 07:50:33 GMT
The numerical root solving methods are completely independant of the 
numerical derivative routines.  
   
This doesnt quite make sense to me.  The Solver implemenations are Root 
solver routines which address the question of which value for x exists  
between (min,max) such that f(x) = 0.  

The numerical derivative routines estimate the value of the limit of 
(f(x+h)-f(x))/h as h approaches 0.

  I dont understand why (or how) a Bisection Solver routine would address
the question of approximating the derivative of a function at a point.


  How would the BisectionSolver be related to an estimate for the 
Derivative?

  I was thinking along the lines of having an implementation of a 
numerical derivative solver that take a function and a value of h as a 
parameter and return a function.  something like
----------------------------------------------------
public class  DefaultForwardDerivative {
  private Function f = null;
  private double h = 0.0;
  public DefaultForwardDerivative( Function f, double h ) {
       this.f = f;
       this.h = h;
  }

  // this should also have some upper limit on the
  //   absolute value of the return function
  //   so we dont introduce singularities
  public double value( double x ) throws MathException {
    double y0 = f.value( x );
    double y1 = f.value( x + h);

    return (( y1 - y0 ) / h);
  }

}
--------------------------------------------------

   A Factory could be placed in front to pull this or a backward (use -h 
value), or centered, or multi-point estimate for the derivative. The 
factory would hide the 'h' value with some default.

  The second (or higher) derivative could be obtained as follows

------------------------------------
  DerivativeFactory factory = DeriviateFactory.getInstance();  

  Function f = new SomeUserFunction();
  Function g = factory.derivative( f );
  Function h = factory.deritivate( g );

 ------------------------------------
   In this example, f' = g, and g' = h, and f'' = h...



On Tue, 11 Nov 2003, Mark R. Diggory wrote:

> 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.
> > 
> > 
> > 
> 
> 

-- 
      Matt Cliff            
      Cliff Consulting
      303.757.4912
      720.280.6324 (c)


      The label said install Windows 98 or better so I installed Linux.



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message