use of org.matheclipse.core.eval.exception.SymjaMathException in project symja_android_library by axkr.
the class MathUtils method getFunctionVal.
public static String getFunctionVal(String fun, String[] var, String resp, String[] vals) throws MathException {
// return evaluate(command.toString(), null);
try {
EvalDouble parParser = new EvalDouble(true);
double[] values = new double[vals.length];
for (int i = 0; i < vals.length; i++) {
values[i] = parParser.evaluate(vals[i]);
}
String respVar = null;
for (int i = 0; i < var.length; i++) {
if (var[i].equals(resp)) {
respVar = resp;
// parParser.add(respVar);
// respVar.setVal(values[i]);
parParser.defineVariable(respVar, values[i]);
} else {
String temp = var[i];
parParser.defineVariable(temp, values[i]);
}
}
if (respVar != null) {
try {
ASTNode f = parParser.parse(fun);
return parParser.evaluateNode(f) + "";
} catch (MathException e) {
// e.getMessage(), e.context);
throw e;
}
}
} catch (MathException e) {
// ParserContext(resp, 0, null));
throw e;
}
throw new SymjaMathException("MathUtils:getFunctionVal - cannot compute function values");
}
Aggregations