Search in sources :

Example 1 with DoubleEvaluator

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

the class EvalDoubleTestCase method testEval004.

public void testEval004() {
    try {
        IDoubleValue vd = new DoubleVariable(3.0);
        DoubleEvaluator engine = new DoubleEvaluator();
        engine.defineVariable("x", vd);
        double d = engine.evaluate("x^2+3");
        assertEquals(Double.valueOf(d).toString(), "12.0");
        vd.setValue(4);
        d = engine.evaluate();
        assertEquals(Double.valueOf(d).toString(), "19.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 2 with DoubleEvaluator

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

the class EvalDoubleTestCase method testInterpolatingFunction.

public void testInterpolatingFunction() {
    try {
        DoubleEvaluator engine = new DoubleEvaluator();
        engine.setCallbackFunction(CoreCallbackFunction.CONST);
        engine.defineVariable("x", new DoubleVariable(3.0));
        double d = engine.evaluate("InterpolatingFunction[{{0, 0}, {1, 1}, {2, 3}, {3, 4}, {4, 3}, {5, 0}}][x]");
        assertEquals(Double.toString(d), "4.0");
    } catch (MathException e) {
        e.printStackTrace();
        assertEquals("EvalDouble#evaluateFunction(FunctionNode) not possible for: aTest(1.0)", e.getMessage());
    }
}
Also used : DoubleEvaluator(org.matheclipse.parser.client.eval.DoubleEvaluator) MathException(org.matheclipse.parser.client.math.MathException) DoubleVariable(org.matheclipse.parser.client.eval.DoubleVariable)

Example 3 with DoubleEvaluator

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

the class EvalDoubleTestCase method testEval003.

public void testEval003() {
    try {
        DoubleEvaluator engine = new DoubleEvaluator();
        double d = engine.evaluate("Sin[Pi/2*Cos[Pi]]");
        assertEquals(Double.toString(d), "-1.0");
    } catch (Exception e) {
        e.printStackTrace();
        assertEquals("", e.getMessage());
    }
}
Also used : DoubleEvaluator(org.matheclipse.parser.client.eval.DoubleEvaluator) MathException(org.matheclipse.parser.client.math.MathException)

Example 4 with DoubleEvaluator

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

the class EvalDoubleTestCase method testEval009.

public void testEval009() {
    try {
        DoubleEvaluator engine = new DoubleEvaluator();
        BooleanVariable vb = new BooleanVariable(true);
        engine.defineVariable("$1", vb);
        double d = engine.evaluate("If[$1, 1, 0]");
        Assert.assertEquals(d, 1d, DoubleEvaluator.EPSILON);
        vb.setValue(false);
        d = engine.evaluate();
        Assert.assertEquals(d, 0d, DoubleEvaluator.EPSILON);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.assertEquals("", e.getMessage());
    }
}
Also used : DoubleEvaluator(org.matheclipse.parser.client.eval.DoubleEvaluator) BooleanVariable(org.matheclipse.parser.client.eval.BooleanVariable) MathException(org.matheclipse.parser.client.math.MathException)

Example 5 with DoubleEvaluator

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

the class EvalDoubleTestCase method testEval006.

public void testEval006() {
    try {
        DoubleEvaluator engine = new DoubleEvaluator();
        BooleanVariable vb = new BooleanVariable(true);
        engine.defineVariable("$1", vb);
        BooleanVariable vb2 = new BooleanVariable(true);
        engine.defineVariable("$2", vb2);
        double d = engine.evaluate("If[$1 && $2, 1, 0]");
        Assert.assertEquals(d, 1d, DoubleEvaluator.EPSILON);
        vb.setValue(false);
        d = engine.evaluate();
        Assert.assertEquals(d, 0d, DoubleEvaluator.EPSILON);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.assertEquals("", e.getMessage());
    }
}
Also used : DoubleEvaluator(org.matheclipse.parser.client.eval.DoubleEvaluator) BooleanVariable(org.matheclipse.parser.client.eval.BooleanVariable) MathException(org.matheclipse.parser.client.math.MathException)

Aggregations

DoubleEvaluator (org.matheclipse.parser.client.eval.DoubleEvaluator)19 MathException (org.matheclipse.parser.client.math.MathException)19 DoubleVariable (org.matheclipse.parser.client.eval.DoubleVariable)8 IDoubleValue (org.matheclipse.parser.client.eval.IDoubleValue)6 BooleanVariable (org.matheclipse.parser.client.eval.BooleanVariable)4