On Tue, Mar 27, 2012 at 1:32 PM, Gilles Sadowski <
[email protected]> wrote:

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

Hi Detlef,

thanks for following up the discussion and testing out exp4j. This looks
really good, and I think we can leave it as it is, meaning if somebody
wants to use an math expression parser, exp4j is a good choice (considering
it is already under apache license and in maven central).


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

Hi Gilles,

you (and sebb) have a good point in *not* integrating something like this
into CM, so for me this issue is resolved and I learned something new today
(also jexl looks pretty good, never used it before) ;-)

Thomas

Reply via email to