2012/3/27 "Detlef Günther" <[email protected]>

> Hello,
>
> it would be nice to have an interpreter for mathematical expressions so
> that functions may be defined at runtime.
>
> Example for f(x):
>
>  ExpInter ei = new ExpInter();
>  ei.setFunction("ln(3*sin(2*x)+3)");
>  // Plot the function:
>  for (double x=0.0;x<3.0;x+=0.1) {
>    y = ei(x);
>    // ... do something useful with x,y
>  }
>
> Can be expanded to f(x,y) or functions wit params f(x,p1,p2,p3):
>
>  ei.setFunction("1+p0*x-5*p1*(p2+7)*p3/x");
>  double[] params = { 1.0, 2.0, 4.0, -1 };
>  ei.setParams(params);
>  // plot ....
>
> If the interpreter implements UnivariateFunction it would be even nicer:
>
> ExpInter function = new ExpInter("x^3-2*x^2+x-27");
> double root = solver.solve(99999, function, 0.0, 5.0);
> System.out.println("root is " + root + " / " + function.value(root));
>
> function.setFunction("sin(x)");
> root = solver.solve(99999, function, 3.0, 4.0);
> System.out.println("root is " + root + " / " + function.value(root));
>
> Result:
> de.guenther.roots.RegulaFalsi:
>        [java] root is 3.7009897720655234 / 0.0
>        [java] root is 3.141592653589793 / 1.2246467991473532E-16
>
> I may post my interpreter.
>

Hi Detlef,

this is something really interesting, I was thinking of this myself several
times. I guess you know similar projects like jformula or jep, but their
license is usually quite restrictive.
So if you are willing to work on something like this and contribute it to
commons-math, I would be very much in favor and can help with it.

Thomas

Reply via email to