use of org.matheclipse.core.eval.ExprEvaluator in project symja_android_library by axkr.
the class PolynomialExample method main.
public static void main(String[] args) {
try {
ExprEvaluator util = new ExprEvaluator();
IExpr expr = util.evaluate("x^2+y+a*x+b*y+c");
System.out.println(expr.toString());
final IAST variables = F.List(F.x, F.y);
ExprPolynomialRing ring = new ExprPolynomialRing(ExprRingFactory.CONST, variables, variables.size() - 1, ExprTermOrderByName.Lexicographic, false);
ExprPolynomial poly = ring.create(expr);
System.out.println(poly.toString());
// x degree
System.out.println(poly.degree(0));
// y degree
System.out.println(poly.degree(1));
// show internal structure:
System.out.println(poly.coefficientRules());
System.out.println();
for (ExprMonomial monomial : poly) {
System.out.println(monomial.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.core.eval.ExprEvaluator in project symja_android_library by axkr.
the class SolveExample method main.
public static void main(String[] args) {
try {
ExprEvaluator util = new ExprEvaluator();
IExpr result = util.evaluate("Solve(2*x==5 + 4*x,x)");
// print: {{x->-5/2}}
System.out.println(result.toString());
result = util.evaluate("Roots(2*x==5+4*x, x)");
// print: x==-5/2
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();
} catch (final StackOverflowError soe) {
System.out.println(soe.getMessage());
} catch (final OutOfMemoryError oome) {
System.out.println(oome.getMessage());
}
}
use of org.matheclipse.core.eval.ExprEvaluator in project symja_android_library by axkr.
the class SolveSO39753012 method main.
public static void main(String[] args) {
try {
ExprEvaluator util = new ExprEvaluator();
IExpr eq = F.Equal(F.Plus(F.a, F.b), F.c);
IExpr eq1 = eq.replaceAll(F.Rule(F.a, F.integer(1)));
eq1 = eq1.replaceAll(F.Rule(F.b, F.integer(2)));
// Solve(1+2==c, c)
IExpr result = util.evaluate(F.Solve(eq1, F.c));
// print: {{c->3}}
System.out.println(result.toString());
IExpr eq2 = eq.replaceAll(F.Rule(F.a, F.integer(1)));
eq2 = eq2.replaceAll(F.Rule(F.c, F.integer(3)));
// Solve(1+b==3, b)
result = util.evaluate(F.Solve(eq2, F.b));
// print: {{b->2}}
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();
} catch (final StackOverflowError soe) {
System.out.println(soe.getMessage());
} catch (final OutOfMemoryError oome) {
System.out.println(oome.getMessage());
}
}
use of org.matheclipse.core.eval.ExprEvaluator in project symja_android_library by axkr.
the class SolveSO43024172 method main.
public static void main(String[] args) {
try {
ExprEvaluator util = new ExprEvaluator();
IExpr expr = util.evaluate("(x1)^2+4*(x2)^2-2*x1-4*x2");
System.out.println(expr.toString());
// determine the variables used in the expression
IAST variableList = VariablesSet.getVariables(expr);
System.out.println(variableList.toString());
IExpr a = util.evaluate("a");
IExpr x1 = util.evaluate("x1");
IExpr x2 = util.evaluate("x2");
IExpr x1Substitute = util.evaluate("5+a");
IExpr x2Substitute = util.evaluate("2");
IAST astRules = F.List(F.Rule(x1, x1Substitute), F.Rule(x2, x2Substitute));
// {x1->5+a,x2->2}
System.out.println(astRules.toString());
IExpr replacedExpr = expr.replaceAll(astRules);
// -2*(5+a)+(5+a)^2+(-4)*2+4*2^2
System.out.println(replacedExpr.toString());
// 8+(5+a)^2-2*(5+a)
replacedExpr = util.evaluate(replacedExpr);
System.out.println(replacedExpr.toString());
// replacedExpr = util.evaluate(F.ExpandAll(replacedExpr));
// 23+8*a+a^2
// System.out.println(replacedExpr.toString());
IExpr derivedExpr = util.evaluate(F.D(replacedExpr, a));
// -2+2*(5+a)
System.out.println(derivedExpr.toString());
IExpr equation = F.Equal(derivedExpr, F.C0);
// -2+2*(5+a)==0
System.out.println(equation.toString());
IExpr solvedEquation = util.evaluate(F.Solve(equation, a));
// {{a->-4}}
System.out.println(solvedEquation.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.core.eval.ExprEvaluator 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.evaluate(formula);
// print: I*Sqrt(2)
System.out.println(result.toString());
// numerical evaluations
result = util.evaluate(F.N(formula));
// I*1.4142135623730951
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();
} catch (final StackOverflowError soe) {
System.out.println(soe.getMessage());
} catch (final OutOfMemoryError oome) {
System.out.println(oome.getMessage());
}
}
Aggregations