Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 30191 invoked from network); 12 Nov 2003 07:50:13 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 12 Nov 2003 07:50:13 -0000 Received: (qmail 38913 invoked by uid 500); 12 Nov 2003 07:49:36 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 38537 invoked by uid 500); 12 Nov 2003 07:49:33 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 38518 invoked from network); 12 Nov 2003 07:49:33 -0000 Received: from unknown (HELO localhost.localdomain) (216.17.172.192) by daedalus.apache.org with SMTP; 12 Nov 2003 07:49:33 -0000 Received: from mail.mattcliff.com (mail.mattcliff.com [216.17.172.194]) by localhost.localdomain (8.11.6/8.11.6) with ESMTP id hAC7oXC15357 for ; Wed, 12 Nov 2003 00:50:33 -0700 Date: Wed, 12 Nov 2003 00:50:33 -0700 (MST) From: Matt Cliff X-X-Sender: cliff@localhost.localdomain To: Jakarta Commons Developers List Subject: Re: [math] Numerical Derivative pattern q. In-Reply-To: <3FB1A1CD.1070802@latte.harvard.edu> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N 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