CalM is Java library for evaluating mathematical expressions. The following snippet shows how to use the math parser in code.
Stringinput="5.2+ln 2e^sin 2.6pi";MathParserparser=StandardConfig.getParser();try{Expressionexpress=parser.parse(input);Operandresult=express.evaluate(true);System.out.println(result.getValue());}catch(RPNExceptionex){System.out.println("Error:" + ex.getMessage()); // The exception might have a fragment with the location of the error. ex.getDetail().ifPresent(fragment -> { // The fragment's position is a zero-based char index. System.out.println("Atposition:"+(fragment.getPosition()+1));});}
CalM also includes a script interpreter that's based on the math parser. Below is a script that calculates the first iterations of the sequence Zn+1 = Zn^2 + c in the orbit of zero. The script prompts the user for the complex number c and the number of iterations to run. Convergence of this sequence determines whether c is in the Mandelbrot set or not.
exec print "Fc(Z) = Z^2 + c"
c := prompt "c: "
Fc(Z) := Z^2 + c
n := prompt "How many iterations? "
Z := 0
I
exec
for I := 1; I <= n; I inc 1 do
print "Fc(" + Z + ") = " + (Z := round(Fc(Z), 7))
end
Last edit: Tone Sommerland ™ 2016-05-17
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
CalM
CalM is Java library for evaluating mathematical expressions. The following snippet shows how to use the math parser in code.
CalM also includes a script interpreter that's based on the math parser. Below is a script that calculates the first iterations of the sequence Zn+1 = Zn^2 + c in the orbit of zero. The script prompts the user for the complex number c and the number of iterations to run. Convergence of this sequence determines whether c is in the Mandelbrot set or not.
Last edit: Tone Sommerland ™ 2016-05-17