commons-user mailing list archives

Site index · List index
Message view
Top
From Franz Simons <franz.sim...@wahyd.tu-berlin.de>
Subject Re: [math] Help needed for usage of Newton-Raphson solver
Date Fri, 24 May 2013 11:19:45 GMT
```Hi Luc,

thank you for the explaination! The benchmark is a good idea. However, I
don't understand how I can give the derivation myself since version 3?

Cheers,
Franz

Am Donnerstag, den 23.05.2013, 20:44 +0200 schrieb Luc Maisonobe:
> Le 22/05/2013 15:24, Franz Simons a écrit :
> > Hi Thomas,
> >
> > great, it works that way! Thank you very much! It is nice that I don't
> > have to do the derivation myself anymore! Is there any perfomance
> > drawback if the derivation is done internally?
>
> Hi Franz,
>
> Yes, there are performance drawbacks as with a general framework, we
> cannot detect things like multiplications by 1 or additions of 0 and
> optimize these operations away. The performance drop highly depends on
> the function, so your mileage may vary. If you are concerned about that,
> I'll suggest you to do your own benchmarks. One very important feature
> is that with an automated framework, maintainance of the code is much
> easier when the complexity of the function increases.
>
> best regards,
> Luc
>
> >
> > Best regards,
> > Franz
> >
> >
> >
> > Am Mittwoch, den 22.05.2013, 14:51 +0200 schrieb Thomas Neidhart:
> >> 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
> >>     }
> >>
> >> }
> >>
> >> 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
> >>
> >> Thomas
> >>
> >>
> >>
> >> On Tue, May 21, 2013 at 4:21 PM, Franz Simons <
> >> franz.simons@wahyd.tu-berlin.de> 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: user-unsubscribe@commons.apache.org
> >>> For additional commands, e-mail: user-help@commons.apache.org
> >>>
> >>>
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

--
Dipl.-Ing. Franz Simons
Fachgebiet Wasserwirtschaft und Hydrosystemmodellierung
Chair of Water Resources Management and Modeling of Hydrosystems

Institut für Bauingenieurwesen
Technische Universität Berlin | Sekr. TIB 1-B14
Gustav-Meyer-Allee 25 | 13355 Berlin | Germany
Tel.: +49 30 314-72429 | Fax: +49 30 314-72430
franz.simons@wahyd.tu-berlin.de | www.wahyd.tu-berlin.de

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