Question concerning numerical evaluation #206
-
Hello there, I need to evaluate a function with a certain precision. I first define some variables with the values i want to evaluatet he function at and then try to evaluate the function. My first approach was using I then tried to use At this point I am quite confused. Did I stumble upon a bug? Am I using the library (completely) wrong? And how do I get the result in my preferred precision? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
This comment has been hidden.
This comment has been hidden.
-
Symja uses apfloat for arbitrary precision arithmetic. As you can see in the apfloat tutorial there are some caveats with the double constructor. The recommendation is to use exact number input as much as possible. For your example you can write: eval.eval("a = N[425/500, 50]");
eval.eval("u = N[295/100, 50]"); Commit #aac80f0 should fix the error in Note: high precision calculations are available in Symja only for the functions which apfloat support. import org.matheclipse.core.eval.ExprEvaluator;
public class Discussion206 {
public static void main(String[] args) {
ExprEvaluator eval = new ExprEvaluator();
String function = "(1/log(1-(a/u)))";
eval.eval("a = N[425/500, 50]");
eval.eval("u = N[295/100, 50]");
try {
System.out.println(eval.eval("N[" + function + ", 50]"));
System.out.println(eval.getEvalEngine().evaluate("N[" + function + ", 50]"));
} catch (RuntimeException rex) {
rex.printStackTrace();
}
try {
String function2 = "log(1-(a/u))";
System.out.println(eval.eval("N[" + function2 + ", 50]"));
System.out.println(eval.getEvalEngine().evaluate("N[" + function2 + ", 50]"));
} catch (RuntimeException rex) {
rex.printStackTrace();
}
}
} |
Beta Was this translation helpful? Give feedback.
Symja uses apfloat for arbitrary precision arithmetic.
As you can see in the apfloat tutorial there are some caveats with the double constructor.
The recommendation is to use exact number input as much as possible.
For your example you can write:
Commit #aac80f0 should fix the error in
Power#e2ApfloatArg()
method for negative exponents.Note: high precision calculations are available in Symja only for the functions which apfloat support.