Search in sources :

Example 6 with SymjaMathException

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");
}
Also used : SymjaMathException(org.matheclipse.core.eval.exception.SymjaMathException) MathException(org.matheclipse.parser.client.math.MathException) ASTNode(org.matheclipse.parser.client.ast.ASTNode) SymjaMathException(org.matheclipse.core.eval.exception.SymjaMathException)

Aggregations

SymjaMathException (org.matheclipse.core.eval.exception.SymjaMathException)6 IExpr (org.matheclipse.core.interfaces.IExpr)5 ValidateException (org.matheclipse.core.eval.exception.ValidateException)3 FlowControlException (org.matheclipse.core.eval.exception.FlowControlException)2 IAST (org.matheclipse.core.interfaces.IAST)2 IBuiltInSymbol (org.matheclipse.core.interfaces.IBuiltInSymbol)2 IEvaluator (org.matheclipse.core.interfaces.IEvaluator)2 ASTNode (org.matheclipse.parser.client.ast.ASTNode)2 MathException (org.matheclipse.parser.client.math.MathException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Parameter (java.lang.reflect.Parameter)1 Entry (java.util.Map.Entry)1 AST2Expr (org.matheclipse.core.convert.AST2Expr)1 EvalEngine (org.matheclipse.core.eval.EvalEngine)1 LimitException (org.matheclipse.core.eval.exception.LimitException)1 AbstractFunctionOptionEvaluator (org.matheclipse.core.eval.interfaces.AbstractFunctionOptionEvaluator)1 ICoreFunctionEvaluator (org.matheclipse.core.eval.interfaces.ICoreFunctionEvaluator)1 IFunctionEvaluator (org.matheclipse.core.eval.interfaces.IFunctionEvaluator)1 ASTSeriesData (org.matheclipse.core.expression.ASTSeriesData)1