Hi Franz,

you can take a look at the following class which is used for the unit tests:

public class QuinticFunction implements UnivariateDifferentiableFunction {

    /* Evaluate quintic.
     * @see org.apache.commons.math3.UnivariateFunction#value(double)
     */
    public double value(double x) {
        return (x-1)*(x-0.5)*x*(x+0.5)*(x+1);
    }

    public DerivativeStructure value(DerivativeStructure t) {
        return
t.subtract(1).multiply(t.subtract(0.5)).multiply(t).multiply(t.add(0.5)).multiply(t.add(1));
    }

}

The DerivativeStructure provides the standard arithmetic operations which
you can use.
So in your case the value method would look like this imho:

    public DerivativeStructure value(DerivativeStructure t) {
        return t.multiply(t);
    }

This just a quick help from myside, Luc (Maisonobe) will surely give you
more infos on how to use the DerivativeStructure.

Thomas



On Tue, May 21, 2013 at 4:21 PM, Franz Simons <
[email protected]> wrote:

> Dear all,
>
> I don't understand the usage of the new DerivativeStructure in version 3
> of the commons math.
>
> In the old version I had the following function, which was then used in
> the Newton solver:
>
> public class MyFunction implements
>          DifferentiableUnivariateRealFunction {
>
>
>         public double value(double x) {
>                 // example value
>                 return x*x;
>         }
>
>         public UnivariateRealFunction derivative() {
>                 return new UnivariateRealFunction() {
>                         public double value(double x) {
>                                 // example derivative
>                                 return 2.*x;
>                         }
>                 }
>         }
> }
>
> To use the Newton Raphson solver in version 3, I have to implement the
> new UnivariateDifferentiableFunction interface:
>
> public class MyFunctionNew implements
>          UnivariateDifferentiableFunction {
>
>         public double value(double x) {
>                 // example value
>                 return x*x;
>         }
>
>         public DerivativeStructure value(DerivativeStructure t) {
>
>                 // What do I have to do here??
>                 // return what?
>         }
> }
>
> I don't know how to use the DerivativeStructure. What do I have to do,
> to get the same functionality like in the the previous function? How can
> I define the derivative of my function?
> I tried to understand from the user guide, but it wasn't clear for me.
>
> It would be great if someone could give me a hint or further explanation
> on this.
>
> Thank you very much in advance!
>
> Best regards,
> Franz
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

Reply via email to