gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 09:12:59 27 4
gpt4 key购买 nike

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

我这样尝试:

EvalUtilities solver = new EvalUtilities();

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

IExpr result = solver.evaluate(myExpresion);

但这行不通。如何解决一个简单的不等式?

最佳答案

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

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

关于java - 如何用 Symja 解决不等式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21220205/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com