commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@worden.org
Subject Re: [math] Some changes to Polynomial
Date Wed, 31 Mar 2004 05:09:02 GMT
On Tue, 30 Mar 2004 21:29:42 -0700, Phil Steitz wrote:

> 
> 0. To help debug the SplineInterpolater (PR #28019 et al), I need to 
> expose the coefficients in o.a.c.m.analysis.Polynomial as a
read-only 
> property (returning an array copy). Any objections to adding this?


> 1. Add protected static double evaluate(double[] coefficients,
double 
> argument) implementing Horner to get the function value; and change 
> value(double) to just call this.

+1

> 
> 2. Add protected static double[] differentiate(double[] coefficients)
> to 
> return the coefficients of the derivative of the polynomial with 
> coefficients equal to the actual parameter.  Then change 
> firstDerivative(x) to just return
> evaluate(differentiate(coefficients), x).  Similar for
> secondDerivative.
> I could adapt Horner for the derivatives, but that seems messy to me
> and 
> the slight memory cost to create the temp arrays seems worth it.

+1 on the differntiate method.

Are the firstDerivate and secondDerivative methods needed anymore with
the addition of your derivative method below?  I would favor removing
the prior two methods if possible.

> 
> 3. I would also like to add
> public PolynomialFunction derivative() {
>    return new PolynomialFunction(differentiate(coefficients));
> }

Have we considered a design for the general derivative case (i.e. for
UnivariateRealFunction objects)?  I was thinking about a
Differentiable interface that either extends from URF or is a base
interface.  It would have a single derivative method with a URF return
value.

Specialized URF types, like PolynomialFunction, could implement and
general derivative method and could provide their own specialized
derivative methods.  Much like java.util.List with iterator and
listIterator.

With this approach, the derivative impl for PolynomialFunction could
be:

public PolynomialFunction polynomialDerivative() {
    return new PolynomialFunction(differentiate(coefficients));
}

public UnivariateRealFunction derivative() {
    return polynomialDerivative();
}

Counter thoughts?

Brent Worden
http://www.brent.worden.org/

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