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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to