use of org.matheclipse.core.interfaces.ISymbol in project symja_android_library by axkr.
the class Plot method evaluate.
public IExpr evaluate(final IAST ast, EvalEngine engine) {
if ((ast.size() >= 3) && (ast.size() <= 4) && ast.arg2().isList()) {
try {
final IAST rangeList = (IAST) ast.arg2();
if (rangeList.isAST3()) {
final ISymbol x = (ISymbol) rangeList.arg1();
final IExpr xMin = engine.evalN(rangeList.arg2());
final IExpr xMax = engine.evalN(rangeList.arg3());
if ((!(xMin instanceof INum)) || (!(xMax instanceof INum))) {
return F.NIL;
}
final double xMinD = ((INum) xMin).getRealPart();
final double xMaxd = ((INum) xMax).getRealPart();
if (xMaxd <= xMinD) {
return F.NIL;
}
double yMinD = 0.0f;
double yMaxD = 0.0f;
if ((ast.isAST3()) && ast.get(3).isList()) {
final IAST lsty = (IAST) ast.arg3();
if (lsty.isAST2()) {
final IExpr y0 = engine.evalN(lsty.arg1());
final IExpr y1 = engine.evalN(lsty.arg2());
if ((y0 instanceof INum) && (y1 instanceof INum)) {
yMinD = ((INum) y0).getRealPart();
yMaxD = ((INum) y1).getRealPart();
}
}
}
final IAST graphics = Graphics();
IAST line = Line();
IExpr temp;
if (ast.get(1).isList()) {
final IAST list = (IAST) ast.get(1);
final IAST primitives = List();
for (int i = 1; i < list.size(); i++) {
temp = plotLine(xMinD, xMaxd, yMinD, yMaxD, list.get(2), x, engine);
if (temp.isPresent()) {
line.append(temp);
primitives.append(line);
}
if (i < list.size() - 1) {
line = Line();
}
}
graphics.append(primitives);
} else {
temp = plotLine(xMinD, xMaxd, yMinD, yMaxD, ast.get(1), x, engine);
if (temp.isPresent()) {
line.append(temp);
graphics.append(line);
}
}
final IExpr[] options = { Rule(F.PlotRange, F.Automatic), Rule(F.AxesStyle, F.Automatic), Rule(F.AxesOrigin, List(F.C0, F.C0)), Rule(F.Axes, F.True), Rule(F.Background, F.White) };
graphics.append(F.ast(options, F.List));
return Show(graphics);
}
} catch (RuntimeException rex) {
if (Config.SHOW_STACKTRACE) {
rex.printStackTrace();
}
}
}
return F.Null;
}
use of org.matheclipse.core.interfaces.ISymbol in project symja_android_library by axkr.
the class NRoots method roots.
public static IAST roots(final IExpr arg1, IAST variables, EvalEngine engine) {
if (variables.size() != 2) {
// factor only possible for univariate polynomials
engine.printMessage("NRoots: factorization only possible for univariate polynomials");
return F.NIL;
}
IExpr expr = evalExpandAll(arg1);
ISymbol sym = (ISymbol) variables.arg1();
double[] coefficients = Expr2Object.toPolynomial(expr, sym);
if (coefficients != null) {
LaguerreSolver solver = new LaguerreSolver(Config.DEFAULT_ROOTS_CHOP_DELTA);
Complex[] roots = solver.solveAllComplex(coefficients, 0);
return Object2Expr.convertComplex(roots);
}
IExpr denom = F.C1;
if (expr.isAST()) {
expr = Algebra.together((IAST) expr);
// split expr into numerator and denominator
denom = engine.evaluate(F.Denominator(expr));
if (!denom.isOne()) {
// search roots for the numerator expression
expr = engine.evaluate(F.Numerator(expr));
}
}
return rootsOfVariable(expr, denom);
}
use of org.matheclipse.core.interfaces.ISymbol in project symja_android_library by axkr.
the class NSolve method rootsOfUnivariatePolynomial.
/**
* Evaluate the roots of a univariate polynomial with the Roots[] function.
*
* @param exprAnalyzer
* @param fListOfVariables
* @return
*/
private static IAST rootsOfUnivariatePolynomial(ExprAnalyzer exprAnalyzer, EvalEngine engine) {
IExpr expr = exprAnalyzer.getNumerator();
IExpr denom = exprAnalyzer.getDenominator();
// try to solve the expr for a symbol in the symbol set
for (ISymbol sym : exprAnalyzer.getSymbolSet()) {
IExpr temp = Roots.rootsOfVariable(expr, denom, F.List(sym), true, engine);
if (temp.isPresent()) {
IAST resultList = F.List();
if (temp.isASTSizeGE(F.List, 2)) {
IAST rootsList = (IAST) temp;
for (IExpr root : rootsList) {
IAST rule = F.Rule(sym, root);
resultList.append(rule);
}
return resultList;
}
return F.NIL;
}
}
return F.NIL;
}
use of org.matheclipse.core.interfaces.ISymbol in project symja_android_library by axkr.
the class Resultant method evaluate.
@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
Validate.checkSize(ast, 4);
// TODO allow multinomials
IExpr arg3 = Validate.checkSymbolType(ast, 3);
ISymbol x = (ISymbol) arg3;
IExpr a = F.evalExpandAll(ast.arg1());
IExpr b = F.evalExpandAll(ast.arg2());
ExprPolynomialRing ring = new ExprPolynomialRing(F.List(x));
try {
// check if a is a polynomial otherwise check ArithmeticException,
// ClassCastException
ring.create(a);
} catch (RuntimeException ex) {
throw new WrongArgumentType(ast, a, 1, "Polynomial expected!");
}
try {
// check if b is a polynomial otherwise check ArithmeticException,
// ClassCastException
ring.create(b);
return F.Together(resultant(a, b, x, engine));
} catch (RuntimeException ex) {
throw new WrongArgumentType(ast, b, 2, "Polynomial expected!");
}
}
use of org.matheclipse.core.interfaces.ISymbol in project symja_android_library by axkr.
the class Plot3D method evaluate.
public IExpr evaluate(final IAST ast, EvalEngine engine) {
// ISymbol optionsArray[] = new ISymbol[] { f.BoxRatios, f.PlotRange };
if ((ast.size() >= 4) && ast.get(2).isList() && ast.get(3).isList()) {
try {
final IAST graphics = SurfaceGraphics();
IExpr temp;
// x-Range
final IAST lst1 = (IAST) ast.arg2();
// y-Range
final IAST lst2 = (IAST) ast.arg3();
if (lst1.isAST3() && lst2.isAST3()) {
// final Options hOptions = new Options(F.Plot3D, ast, 4);
// IAST allOptions = List();
// for (int i = 0; i < optionsArray.length; i++) {
// allOptions.add(optionsArray[i]);
// }
// allOptions = hOptions.replaceAll(allOptions);
final ISymbol x = (ISymbol) lst1.arg1();
final IExpr xMin = engine.evalN(lst1.arg2());
final IExpr xMax = engine.evalN(lst1.arg3());
final ISymbol y = (ISymbol) lst2.arg1();
final IExpr yMin = engine.evalN(lst2.arg2());
final IExpr yMax = engine.evalN(lst2.arg3());
if ((!(xMin instanceof INum)) || (!(xMax instanceof INum)) || (!(yMin instanceof INum)) || (!(yMax instanceof INum))) {
return F.NIL;
}
final double xMinD = ((INum) xMin).getRealPart();
final double xMaxD = ((INum) xMax).getRealPart();
final double yMinD = ((INum) yMin).getRealPart();
final double yMaxD = ((INum) yMax).getRealPart();
if (xMaxD <= xMinD) {
return F.NIL;
}
if (yMaxD <= yMinD) {
return F.NIL;
}
// double y0d = -10.0f;
// double y1d = 10.0f;
// double params[] = {ad, bd, cd, dd, -10.0, 10.0};
temp = plotArray(xMinD, xMaxD, yMinD, yMaxD, ast.get(1), (ISymbol) lst1.get(1), (ISymbol) lst2.get(1), engine);
graphics.append(temp);
final IAST options = List();
// for (int i = 0; i < optionsArray.length; i++) {
// options.add(Rule(optionsArray[i], allOptions.get(i)));
// }
options.append(Rule(F.PlotRange, F.Automatic));
options.append(Rule(F.MeshRange, List(List(xMin, xMax), List(yMin, yMax))));
graphics.append(options);
return Show(graphics);
}
} catch (RuntimeException rex) {
if (Config.SHOW_STACKTRACE) {
rex.printStackTrace();
}
}
}
return F.Null;
}
Aggregations