如何用Symja解决不平等?

时间:2014-01-19 17:36:34

标签: java inequalities symja

有没有人知道如何在Symja中解决一个简单的不等式?

我试着这样:

EvalUtilities solver = new EvalUtilities();

myExpresion = "Solve[Less[{2*x + 4},{10}],{x}]";

IExpr result = solver.evaluate(myExpresion);

但这不起作用。如何解决一个简单的不等式?

1 个答案:

答案 0 :(得分:2)

您可以直接输入这种不等式:

package org.matheclipse.core.examples;

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 InEqualityExample {
  public static void main(String[] args) {
    try {
        EvalUtilities util = new EvalUtilities(false, true);
        IExpr result = util.evaluate("2*x + 4 < 10");
        // print: x < 3
        System.out.println(result.toString());

        // Create an expression with F.* static methods:
        IAST function = Less(Plus(Times(integer(2), x), integer(4)), integer(10));
        result = util.evaluate(function);
        // print: x < 3
        System.out.println(result.toString());

    } catch (SyntaxError e) {
        // catch Symja parser errors here
        System.out.println(e.getMessage());
    } catch (MathException me) {
        // catch Symja math errors here
        System.out.println(me.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
    }
  }
}