commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Luc Maisonobe <...@spaceroots.org>
Subject Re: [math] - Java help with DerivativeStructure through UnivariateDifferentiableFunction
Date Fri, 11 Sep 2015 08:48:36 GMT
Le 10/09/2015 23:40, Matthew Kehoe a écrit :
> Hello All,

Hi Matthew,

> 
> I ran into trouble while creating a Java program for the
> NewtonRaphsonSolver algorithm.
> 
> I made a post about this problem on Stack Overflow at
> http://stackoverflow.com/questions/32511458/java-derivativestructure-inside-the-apache-math-commons-library
> .
> 
> At the bottom of the User Guide, the following information is posted
> 
> There are several ways a user can create an implementation of the
> UnivariateDifferentiableFunction
> <http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/analysis/differentiation/UnivariateDifferentiableFunction.html>
> interface. The first method is to simply write it directly using the
> appropriate methods from DerivativeStructure
> <http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/analysis/differentiation/DerivativeStructure.html>
> to compute addition, subtraction, sine, cosine... This is often quite
> straigthforward and there is no need to remember the rules for
> differentiation: the user code only represent the function itself, the
> differentials will be computed automatically under the hood. The second
> method is to write a classical UnivariateFunction
> <http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/analysis/UnivariateFunction.html>
> and to pass it to an existing implementation of the
> UnivariateFunctionDifferentiator
> <http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/analysis/differentiation/UnivariateFunctionDifferentiator.html>
> interface to retrieve a differentiated version of the same function. The
> first method is more suited to small functions for which user already
> control all the underlying code. The second method is more suited to either
> large functions that would be cumbersome to write using the
> DerivativeStructure
> <http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/analysis/differentiation/DerivativeStructure.html>
> API, or functions for which user does not have control to the full
> underlying code (for example functions that call external libraries).
> 
> The trouble occurs inside
> 
> The second method is to write a classical UnivariateFunction
> <http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/analysis/UnivariateFunction.html>
> and to pass it to an existing implementation of the
> UnivariateFunctionDifferentiator
> <http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/analysis/differentiation/UnivariateFunctionDifferentiator.html>
> interface to retrieve a differentiated version of the same function.
> 
> Would it be possible to create an example for the second method? This was
> rather confusing to a new user that has never implemented the Commons Math
> library. Please let me know if you would like any further information.

I have improved the documentation online. Could you check the last
example here:
<http://commons.apache.org/proper/commons-math/userguide/analysis.html#a4.7_Differentiation>.

Also take care about the note just after the example, which explains
that using finite differences differentiator just to be able to
use Newton-Raphson method is a bad idea. If all you need is compute
the roots of a function for which you naturally have only the value
and not the derivatives, it is far better to use a solver that uses
only the values (like BracketingNthOrderBrentSolver) rather than to
compute an approximate value of the derivative and then use a solver
that relies on derivatives. In fact BracketingNthOrderBrentSolver is
in any case more efficient than Newton-Raphson.

best regards,
Luc

> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message