有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何使用Symja解决不等式?

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

我试着这样:

EvalUtilities solver = new EvalUtilities();

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

IExpr result = solver.evaluate(myExpresion);

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


共 (1) 个答案

  1. # 1 楼答案

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

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