Search in sources :

Example 6 with DoubleVariable

use of org.matheclipse.parser.client.eval.DoubleVariable in project symja_android_library by axkr.

the class EvalDoubleTestCase method testEval007.

public void testEval007() {
    try {
        DoubleEvaluator engine = new DoubleEvaluator();
        // IDoubleValue vdi = new DoubleVariable(1.0);
        // engine.defineVariable("$i", vdi);
        IDoubleValue vd = new DoubleVariable(3.0);
        engine.defineVariable("$1", vd);
        IDoubleValue vd2 = new DoubleVariable(-4.0);
        engine.defineVariable("$2", vd2);
        double d = engine.evaluate("$i = $1+$2; If[$i>0, 1, -1]");
        Assert.assertEquals(d, -1d, DoubleEvaluator.EPSILON);
        vd2.setValue(4.0);
        d = engine.evaluate();
        Assert.assertEquals(d, 1d, DoubleEvaluator.EPSILON);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.assertEquals("", e.getMessage());
    }
}
Also used : DoubleEvaluator(org.matheclipse.parser.client.eval.DoubleEvaluator) IDoubleValue(org.matheclipse.parser.client.eval.IDoubleValue) DoubleVariable(org.matheclipse.parser.client.eval.DoubleVariable) MathException(org.matheclipse.parser.client.math.MathException)

Example 7 with DoubleVariable

use of org.matheclipse.parser.client.eval.DoubleVariable in project symja_android_library by axkr.

the class EvalDoubleCallbackTestCase method testEval005.

public void testEval005() {
    try {
        IDoubleValue vd = new DoubleVariable(3.0);
        DoubleEvaluator engine = new DoubleEvaluator();
        engine.defineVariable("x", vd);
        double d = engine.evaluate("x^2*x^2-1");
        assertEquals(Double.valueOf(d).toString(), "80.0");
        vd.setValue(4);
        d = engine.evaluate();
        assertEquals(Double.valueOf(d).toString(), "255.0");
    } catch (Exception e) {
        e.printStackTrace();
        assertEquals("", e.getMessage());
    }
}
Also used : DoubleEvaluator(org.matheclipse.parser.client.eval.DoubleEvaluator) IDoubleValue(org.matheclipse.parser.client.eval.IDoubleValue) DoubleVariable(org.matheclipse.parser.client.eval.DoubleVariable) MathException(org.matheclipse.parser.client.math.MathException)

Example 8 with DoubleVariable

use of org.matheclipse.parser.client.eval.DoubleVariable in project symja_android_library by axkr.

the class EvalDoubleCallbackTestCase method testEval007.

public void testEval007() {
    try {
        DoubleEvaluator engine = new DoubleEvaluator();
        // IDoubleValue vdi = new DoubleVariable(1.0);
        // engine.defineVariable("$i", vdi);
        IDoubleValue vd = new DoubleVariable(3.0);
        engine.defineVariable("$1", vd);
        IDoubleValue vd2 = new DoubleVariable(-4.0);
        engine.defineVariable("$2", vd2);
        double d = engine.evaluate("$i = $1+$2; If[$i>0, 1, -1]");
        Assert.assertEquals(d, -1d, DoubleEvaluator.EPSILON);
        vd2.setValue(4.0);
        d = engine.evaluate();
        Assert.assertEquals(d, 1d, DoubleEvaluator.EPSILON);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.assertEquals("", e.getMessage());
    }
}
Also used : DoubleEvaluator(org.matheclipse.parser.client.eval.DoubleEvaluator) IDoubleValue(org.matheclipse.parser.client.eval.IDoubleValue) DoubleVariable(org.matheclipse.parser.client.eval.DoubleVariable) MathException(org.matheclipse.parser.client.math.MathException)

Example 9 with DoubleVariable

use of org.matheclipse.parser.client.eval.DoubleVariable in project symja_android_library by axkr.

the class MathUtils method isValid.

public static boolean[] isValid(String[] fun, String[] var) {
    EvalDouble dEval = new EvalDouble(true);
    for (String v : var) {
        dEval.defineVariable(v, new DoubleVariable(0.0));
    }
    boolean[] b = new boolean[fun.length];
    for (int i = 0; i < fun.length; i++) {
        try {
            dEval.parse(fun[i]);
            b[i] = true;
        } catch (Exception e) {
            b[i] = false;
        }
    }
    return b;
}
Also used : DoubleVariable(org.matheclipse.parser.client.eval.DoubleVariable) SymjaMathException(org.matheclipse.core.eval.exception.SymjaMathException) MathException(org.matheclipse.parser.client.math.MathException)

Aggregations

DoubleVariable (org.matheclipse.parser.client.eval.DoubleVariable)9 MathException (org.matheclipse.parser.client.math.MathException)9 DoubleEvaluator (org.matheclipse.parser.client.eval.DoubleEvaluator)8 IDoubleValue (org.matheclipse.parser.client.eval.IDoubleValue)6 SymjaMathException (org.matheclipse.core.eval.exception.SymjaMathException)1