Still can't get basic Symja evaluation to work

795 views Asked by At

I have been trying to get Symja to work in my Eclipse project for about a week, but so far have been unsuccessful. It is becoming rather frustrating to me seeing countless runtime errors so I am hoping someone would be willing to help me out in depth with this problem.

First, I added the symja_android_library.rar to my classpath using Project->Properties->Java Build Path->Add External JARs, and then tried to run a simple derivative calculation. I got an erorr saying that "com.google.common.base.Predicate" wasn't found, so I google'd this JAR and installed it. It is now called "guava" but nonetheless, I used the same process to add it to my classpath. Now, I can see com.google.common.base.Predicate in my classpath, so that error is gone. Unfortunately, I now get this error:

java.lang.NullPointerException
    at org.matheclipse.core.eval.EvalEngine.evalLoop(EvalEngine.java:761)
    at org.matheclipse.core.eval.EvalEngine.evalAST(EvalEngine.java:462)
    at org.matheclipse.core.expression.AST.evaluate(AST.java:1078)
    at org.matheclipse.core.eval.EvalEngine.evalLoop(EvalEngine.java:761)
    at org.matheclipse.core.eval.EvalEngine.evalWithoutNumericReset(EvalEngine.java:268)
    at org.matheclipse.core.eval.EvalEngine.evaluate(EvalEngine.java:287)
    at org.matheclipse.core.eval.EvalEngine.addRules(EvalEngine.java:1069)
    at org.matheclipse.core.eval.interfaces.AbstractFunctionEvaluator.setUp(AbstractFunctionEvaluator.java:46)
    at org.matheclipse.core.reflection.system.Power.setUp(Power.java:394)
    at org.matheclipse.core.expression.Symbol.setEvaluator(Symbol.java:327)
    at org.matheclipse.core.eval.Namespace.setEvaluator(Namespace.java:87)
    at org.matheclipse.core.expression.F.$s(F.java:2693)
    at org.matheclipse.core.convert.AST2Expr.convert(AST2Expr.java:188)
    at org.matheclipse.core.convert.AST2Expr.convert(AST2Expr.java:131)
    at org.matheclipse.core.convert.AST2Expr.convert(AST2Expr.java:133)
    at org.matheclipse.core.eval.EvalEngine.parse(EvalEngine.java:979)
    at org.matheclipse.core.eval.EvalUtilities.evaluate(EvalUtilities.java:42)
    at CalculusExample.main(CalculusExample.java:18)

And the System.out.println(); statements seem to be outputting something because I am getting the following output:

Times[d, Power[x, 3]]
Times[integrate, sin, Power[x, 5]]

Here is the code I am running:

import com.google.*;
import symja_android_library.*;
import static org.matheclipse.core.expression.F.*;
import org.matheclipse.core.eval.EvalUtilities;
import org.matheclipse.core.interfaces.IAST;
import org.matheclipse.core.interfaces.IExpr;
import org.matheclipse.parser.client.SyntaxError;
import org.matheclipse.parser.client.math.MathException;

public class CalculusExample {
    public static void main(String[] args) {
                try {

                        EvalUtilities util = new EvalUtilities(true);

                        IExpr result;

                        result = util.evaluate("d(x^3)");
                        System.out.println(result.toString());

                } catch (SyntaxError e) {

                        System.out.println(e.getMessage());
                } catch (MathException me) {

                        System.out.println(me.getMessage());
                } catch (Exception e) {
                        e.printStackTrace();
                }
        }
}

Edit: I removed the integration as a means to simplifying my question, and making a search for the answer easier. I now only want to derive.

Could someone please explain to me why this error is occurring? Literally all I want to do is symbolic integration and derivation inside my Eclipse project. Am I going to wrong route? What do I need to do to fix this problem?

I'd be interested in a step-by-step solution. I have tried to fix this on other questions but answerers have not responded to my comments on their answers, so I wasn't able to get very far. I have had people respond with code they say worked so I know there's a way to make it work, I just can't figure out what it is.

1

There are 1 answers

0
Panzenbaby On BEST ANSWER

I know it's been a while but maybe my comment can help someone else.

Your input string is wrong. The call of the function d (derivative) has two arguments. The first is the term you want to derive and the second is the variable. So your input string should be "d(x^3,x)".

The input string for integration should look like "integrate(term,{variable, min, max})"

There is a online demo where you can try expressions

symja online demo