2

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

我尝试这样:

EvalUtilities solver = new EvalUtilities();

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

IExpr result = solver.evaluate(myExpresion);

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

4

1 回答 1

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();
    }
  }
}
于 2014-07-05T18:30:47.290 回答