How to solve inequalities with Symja?

1.1k Views Asked by At

Does anyone know how to solve one simple inequalities in Symja?

I try like this:

EvalUtilities solver = new EvalUtilities();

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

IExpr result = solver.evaluate(myExpresion);

But this doesn't work. How to solve one simple inequalities?

1

There are 1 best solutions below

2
On

You can input this kind of inequality directly:

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