Solve() exception

Issue #53 resolved
alfredorosa80 created an issue

Hi, my java code is:

public static void evaluateLinearSystem() { try {

        F.initSymbols(null);
        EvalUtilities util = new EvalUtilities();
        StringBufferWriter buf = new StringBufferWriter();
       String input = "Solve[{1.0*d*q4+1.0*e == 100,1.0*c*q3 == 100,1.0*a*q1 == 100,1.0*e*q5 == 100,1.0*b*q2 == 100}, {a,b,c,d,e}]";

        IExpr result = util.evaluate(input);
        OutputFormFactory.get().convert(buf, result);
        String output = buf.toString();
        System.out.println("Evaluation for " + input + " is " + output);



    } catch (Exception e) {
        e.printStackTrace();
    }
}

It returns the following exception:

java.lang.NullPointerException at org.matheclipse.core.eval.EvalEngine.evalObject(EvalEngine.java:873) at org.matheclipse.core.eval.EvalEngine.evalLoop(EvalEngine.java:824) at org.matheclipse.core.eval.EvalEngine.evalWithoutNumericReset(EvalEngine.java:278) at org.matheclipse.core.eval.EvalEngine.evaluate(EvalEngine.java:297) at org.matheclipse.core.eval.EvalEngine.eval(EvalEngine.java:337) at org.matheclipse.core.expression.F.eval(F.java:2859) at org.matheclipse.core.reflection.system.Roots.rootsOfVariable(Roots.java:123) at org.matheclipse.core.reflection.system.Solve.rootsOfUnivariatePolynomial(Solve.java:421) at org.matheclipse.core.reflection.system.Solve.analyzeSublist(Solve.java:330) at org.matheclipse.core.reflection.system.Solve.analyzeSublist(Solve.java:359) at org.matheclipse.core.reflection.system.Solve.analyzeSublist(Solve.java:359) at org.matheclipse.core.reflection.system.Solve.analyzeSublist(Solve.java:359) at org.matheclipse.core.reflection.system.Solve.analyzeSublist(Solve.java:359) at org.matheclipse.core.reflection.system.Solve.evaluate(Solve.java:499) at org.matheclipse.core.eval.EvalEngine.evalASTBuiltinFunction(EvalEngine.java:644) at org.matheclipse.core.eval.EvalEngine.evalAST(EvalEngine.java:560) at org.matheclipse.core.eval.EvalEngine.evalObject(EvalEngine.java:874) at org.matheclipse.core.eval.EvalEngine.evalLoop(EvalEngine.java:837) at org.matheclipse.core.eval.EvalEngine.evalWithoutNumericReset(EvalEngine.java:278) at org.matheclipse.core.eval.EvalEngine.evaluate(EvalEngine.java:297) at org.matheclipse.core.eval.EvalUtilities.evaluate(EvalUtilities.java:45)

Where am I wrong?

Thanks in advance, Best Regards, Alfredo Rosa

Comments (2)

  1. Axel Kramer repo owner

    Try this with the latest downloads!?

    package org.matheclipse.core.examples;
    
    import org.matheclipse.core.eval.EvalUtilities;
    import org.matheclipse.core.form.output.OutputFormFactory;
    import org.matheclipse.core.interfaces.IExpr;
    
    public class SolveExample {
        public static void main(String[] args) {
            try {
                EvalUtilities util = new EvalUtilities();
                String input = "Solve [{d*q4+e == 100,c*q3 == 100,a*q1 == 100,e*q5 == 100,b*q2 == 100}, {a,b,c,d,e}]";
                IExpr result = util.evaluate(input);
    
                StringBuffer buf = new StringBuffer();
                OutputFormFactory.get().convert(buf, result);
                String output = buf.toString();
                System.out.println("Evaluation for " + input + " is " + output);
    
                input = "Solve[{1.0*d*q4+1.0*e == 100,1.0*c*q3 == 100,1.0*a*q1 == 100,1.0*e*q5 == 100,1.0*b*q2 == 100}, {a,b,c,d,e}]";
                result = util.evaluate(input);
                buf = new StringBuffer();
                OutputFormFactory.get().convert(buf, result);
                output = buf.toString();
                System.out.println("Evaluation for " + input + " is " + output);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    
  2. Log in to comment