On Tue, Mar 27, 2012 at 12:53:25PM +0200, "Detlef Günther" wrote:
> Hi Thomas,
> 
> congrace may be used by writing a wrapper "Expression" to UnivarteFunction:
> 
> 
> import org.apache.commons.math3.analysis.UnivariateFunction;
> 
> import de.congrace.exp4j.Calculable;
> import de.congrace.exp4j.ExpressionBuilder;
> 
> public class Expression implements UnivariateFunction {
>       private Calculable      calc    = null;
> 
>       public Expression(String function) throws Exception {
>               calc = new 
> ExpressionBuilder(function).withVariableNames("x").build();
>       }
> 
>       public double value(double x) {
>               calc.setVariable("x", x);
>               return calc.calculate();
>       }
> 
> }
> 
> Using this you get the folowing code:
> 
> final double relativeAccuracy = 1.0e-10;
> final double absoluteAccuracy = 1.0e-10;
> UnivariateSolver solver = new RegulaFalsiSolver(relativeAccuracy,
>                                               absoluteAccuracy);
> Expression exp = new Expression("sin(3*x)");
> double root = solver.solve(99999, exp, 9.4, 9.7);
> System.out.println("root is " + root + " / " + exp.value(root));
> 
> with output:
> 
> root is 9.42477796076938 / 1.102182119232618E-15  (= 3*PI)
> 
> ==> Interpreter may be integrated in commons/math, the same result as my 
> interpreter.

The above shows a fine _use_ of Commons Math. What added value would there
be from integrating it into Commons Math?

> [...]

Gilles

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

Reply via email to