use of org.matheclipse.parser.client.math.MathException in project symja_android_library by axkr.
the class Issue212 method main.
public static void main(String[] args) {
try {
ExprEvaluator util = new ExprEvaluator(false, (short) 100);
ISymbol a = F.Dummy("a");
ISymbol b = F.Dummy("b");
ISymbol c = F.Dummy("c");
IAST compound = F.CompoundExpression(F.Set(a, F.ZZ(13)), F.Set(b, F.ZZ(11)), F.Set(c, F.ZZ(12)), F.Plus(a, b, c));
IExpr result = util.eval(compound);
// print 36
if (result.isInteger()) {
IInteger n = (IInteger) result;
System.out.println(n.toString());
}
// solve({x==y,y==2},{x,y})
ISymbol x = F.Dummy("x");
ISymbol y = F.Dummy("y");
IAST solve = //
F.Solve(//
F.List(F.Equal(x, y), F.Equal(y, F.ZZ(2))), F.List(x, y));
result = util.eval(solve);
if (result.isListOfLists()) {
IAST list = (IAST) result;
for (int i = 1; i < list.size(); i++) {
IExpr arg = list.get(i);
if (arg.isListOfRules()) {
IAST listOfRules = (IAST) arg;
for (int j = 1; j < listOfRules.size(); j++) {
IAST rule = (IAST) listOfRules.get(j);
System.out.println(rule.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 (final Exception ex) {
System.out.println(ex.getMessage());
} catch (final StackOverflowError soe) {
System.out.println(soe.getMessage());
} catch (final OutOfMemoryError oome) {
System.out.println(oome.getMessage());
}
}
use of org.matheclipse.parser.client.math.MathException in project symja_android_library by axkr.
the class QuantityExample method main.
public static void main(String[] args) {
try {
F.initSymbols();
EvalEngine engine = new EvalEngine(false);
// ExprEvaluator engine = new ExprEvaluator(false, 100);
IAST function = F.Times(F.C7, F.Quantity(F.C2, F.$str("ft")));
IExpr result = engine.evaluate(function);
// print: 14[ft]
System.out.println("Out[1]: " + 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 (final Exception ex) {
System.out.println(ex.getMessage());
} catch (final StackOverflowError soe) {
System.out.println(soe.getMessage());
} catch (final OutOfMemoryError oome) {
System.out.println(oome.getMessage());
}
}
use of org.matheclipse.parser.client.math.MathException in project symja_android_library by axkr.
the class SolveIssue171 method main.
public static void main(String[] args) {
try {
ExprEvaluator util = new ExprEvaluator();
// IExpr exp1 = util.evaluate("x=985.3698808807793");
IExpr exp2 = util.eval("y=89.73311105248706");
IExpr exp3 = util.eval("z=30.358930164378133");
IExpr exp4 = util.eval("w=143.26674070021394");
IExpr exp5 = util.eval("q=923.282853878973");
IExpr exp6 = util.eval("j=955.7677262340256");
// IExpr exp = util.evaluate(" N(Solve({q/w==(m+2.0*y)/(m+z+x+j)},m))");
IExpr exp = util.eval("Solve(4.027433300199394==(110.70534+x)/(1015.3739400000001+x),x)");
// -1314.2
System.out.println(exp.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();
} catch (final StackOverflowError soe) {
System.out.println(soe.getMessage());
} catch (final OutOfMemoryError oome) {
System.out.println(oome.getMessage());
}
}
use of org.matheclipse.parser.client.math.MathException in project symja_android_library by axkr.
the class SymbolicSO43739728 method main.
public static void main(String[] args) {
try {
ExprEvaluator util = new ExprEvaluator();
// (3/4)*(4/3)*Sqrt(2)*I
IExpr formula = F.Times(F.QQ(3, 4), F.QQ(4, 3), F.Sqrt(F.ZZ(2)), F.CI);
// symbolic evaluation
IExpr result = util.eval(formula);
// print: I*Sqrt(2)
System.out.println(result.toString());
// numerical evaluations
result = util.eval(F.N(formula));
// I*1.4142135623730951
System.out.println(result.toString());
// print result in decimal format
final StringWriter buf = new StringWriter();
OutputFormFactory.get(true, false, 5, 7).convert(buf, result);
// I*1.41421
System.out.println(buf.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();
} catch (final StackOverflowError soe) {
System.out.println(soe.getMessage());
} catch (final OutOfMemoryError oome) {
System.out.println(oome.getMessage());
}
}
use of org.matheclipse.parser.client.math.MathException in project symja_android_library by axkr.
the class ImportJSON method main.
public static void main(String[] args) {
try {
Config.FILESYSTEM_ENABLED = true;
IOInit.init();
ExprEvaluator util = new ExprEvaluator();
IExpr expr = util.eval("Import(\"https://json-stat.org/samples/oecd.json\",\"JSON\")");
StringBuilder buf = new StringBuilder();
OutputFormFactory off = OutputFormFactory.get(false, false);
off.setIgnoreNewLine(true);
off.setInputForm(true);
if (off.convert(buf, expr)) {
System.out.println(buf);
}
} 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();
} catch (final StackOverflowError soe) {
System.out.println(soe.getMessage());
} catch (final OutOfMemoryError oome) {
System.out.println(oome.getMessage());
}
}
Aggregations