【问题标题】:Still can't get basic Symja evaluation to work仍然无法让基本的 Symja 评估工作
【发布时间】:2013-12-18 20:37:15
【问题描述】:

大约一周以来,我一直试图让 Symja 在我的 Eclipse 项目中工作,但到目前为止还没有成功。看到无数的运行时错误让我感到非常沮丧,所以我希望有人愿意深入帮助我解决这个问题。

首先,我使用 Project->Properties->Java Build Path->Add External JARs 将 symja_android_library.rar 添加到我的类路径中,然后尝试运行一个简单的导数计算。我收到一条错误消息,说找不到“com.google.common.base.Predicate”,所以我用谷歌搜索了这个 JAR 并安装了它。它现在被称为“番石榴”,但我使用相同的过程将它添加到我的类路径中。现在,我可以在我的类路径中看到 com.google.common.base.Predicate,因此该错误消失了。不幸的是,我现在收到此错误:

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)

System.out.println(); 语句似乎正在输出一些东西,因为我得到了以下输出:

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

这是我正在运行的代码:

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();
                }
        }
}

编辑:我删除了集成,以简化我的问题,并使搜索答案更容易。我现在只想推导。

有人可以向我解释为什么会发生此错误吗?从字面上看,我想做的只是在我的 Eclipse 项目中进行符号集成和派生。我会走错路线吗?我需要做什么来解决这个问题?

我对逐步解决方案感兴趣。我试图在其他问题上解决这个问题,但回答者没有回复我的 cmets 的答案,所以我没能走得很远。我让人们用他们说有效的代码做出回应,所以我知道有办法让它工作,我只是不知道它是什么。

【问题讨论】:

    标签: java math evaluate


    【解决方案1】:

    我知道已经有一段时间了,但也许我的评论可以帮助其他人。

    您的输入字符串错误。函数 d(导数)的调用有两个参数。第一个是您要导出的术语,第二个是变量。所以你的输入字符串应该是“d(x^3,x)”。

    集成的输入字符串应类似于“integrate(term,{variable, min, max})”

    有一个在线演示,你可以尝试表达式

    symja online demo

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      • 1970-01-01
      • 2017-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-21
      相关资源
      最近更新 更多