use of org.matheclipse.core.generic.UnaryNumerical in project symja_android_library by axkr.
the class Plot method plotLine.
/**
*
* @param xMin
* the minimum x-range value
* @param xMax
* the maximum x-range value
* @param yMin
* if <code>yMin != 0 && yMax != 0</code> filter only results
* which are in the y-range and set yMin or yMax as plot
* result-range.
* @param yMax
* if <code>yMin != 0 && yMax != 0</code> filter only results
* which are in the y-range and set yMin or yMax as plot
* result-range.
* @param function
* the function which should be plotted
* @param xVar
* the variable name
* @param engine
* the evaluation engine
* @return <code>F.NIL</code> is no conversion of the data into an
* <code>IExpr</code> was possible
*/
public IExpr plotLine(final double xMin, final double xMax, final double yMin, final double yMax, final IExpr function, final ISymbol xVar, final EvalEngine engine) {
final double step = (xMax - xMin) / N;
double y;
final UnaryNumerical hun = new UnaryNumerical(function, xVar, engine);
final double[][] data = new double[2][N + 1];
double x = xMin;
for (int i = 0; i < N + 1; i++) {
y = hun.value(x);
if ((yMin != 0.0) || (yMax != 0.0)) {
if ((y >= yMin) && (y <= yMax)) {
data[0][i] = x;
data[1][i] = y;
} else {
if (y < yMin) {
data[0][i] = x;
data[1][i] = yMin;
} else {
data[0][i] = x;
data[1][i] = yMax;
}
}
} else {
data[0][i] = x;
data[1][i] = y;
}
x += step;
}
return Convert.toExprTransposed(data);
}
use of org.matheclipse.core.generic.UnaryNumerical in project symja_android_library by axkr.
the class NIntegrate method integrate.
/**
* Integrate a function numerically.
*
* @param method
* the following methods are possible: LegendreGauss, Simpson,
* Romberg, Trapezoid
* @param list
* a list of the form <code>{x, lowerBound, upperBound}</code>,
* where <code>lowerBound</code> and <code>upperBound</code> are
* numbers which could be converted to a Java double value.
* @param min
* Lower bound of the integration interval.
* @param max
* Upper bound of the integration interval.
* @param function
* the function which should be integrated.
* @param maxPoints
* maximum number of points
* @param maxIterations
* maximum number of iterations
* @return
* @throws MathIllegalStateException
*/
public static double integrate(String method, IAST list, double min, double max, IExpr function, int maxPoints, int maxIterations) throws MathIllegalStateException {
GaussIntegratorFactory factory = new GaussIntegratorFactory();
ISymbol xVar = (ISymbol) list.arg1();
final EvalEngine engine = EvalEngine.get();
IExpr tempFunction = F.eval(function);
UnivariateFunction f = new UnaryNumerical(tempFunction, xVar, engine);
UnivariateIntegrator integrator;
if ("Simpson".equalsIgnoreCase(method)) {
integrator = new SimpsonIntegrator();
} else if ("Romberg".equalsIgnoreCase(method)) {
integrator = new RombergIntegrator();
} else if ("Trapezoid".equalsIgnoreCase(method)) {
integrator = new TrapezoidIntegrator();
} else {
// default: LegendreGauss
GaussIntegrator integ = factory.legendre(maxPoints, min, max);
return integ.integrate(f);
}
return integrator.integrate(maxIterations, f, min, max);
}
use of org.matheclipse.core.generic.UnaryNumerical in project symja_android_library by axkr.
the class NFourierTransform method evaluate.
@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
Validate.checkRange(ast, 4, 5);
IExpr expr = ast.arg1();
ISymbol t = Validate.checkSymbolType(ast, 2);
// IExpr omega = ast.arg3();
if (ast.size() > 4) {
final Options options = new Options(ast.topHead(), ast, 4, engine);
IExpr optionFourierParameters = options.getOption("FourierParameters");
if (optionFourierParameters.isList()) {
// analyze the parameters, if they are correct
}
}
UnivariateFunction f = new UnaryNumerical(expr, t, engine);
FastFourierTransformer fft = new FastFourierTransformer(DftNormalization.STANDARD);
org.hipparchus.complex.Complex[] result = fft.transform(f, -1.0, 1.0, 8, TransformType.FORWARD);
return Object2Expr.convertComplex(result);
}
use of org.matheclipse.core.generic.UnaryNumerical in project symja_android_library by axkr.
the class FindRoot method findRoot.
private double findRoot(ISymbol method, int maxIterations, IAST list, ISignedNumber min, ISignedNumber max, IExpr function, EvalEngine engine) {
ISymbol xVar = (ISymbol) list.arg1();
function = engine.evaluate(function);
UnivariateFunction f = new UnaryNumerical(function, xVar, engine);
BaseAbstractUnivariateSolver<UnivariateFunction> solver = null;
if (method.isSymbolName("Bisection")) {
solver = new BisectionSolver();
} else if (method.isSymbolName("Brent")) {
solver = new BrentSolver();
// } else if (method.isSymbolName("Laguerre")) {
// solver = new LaguerreSolver();
} else if (method.isSymbolName("Muller")) {
solver = new MullerSolver();
} else if (method.isSymbolName("Ridders")) {
solver = new RiddersSolver();
} else if (method.isSymbolName("Secant")) {
solver = new SecantSolver();
} else if (method.isSymbolName("RegulaFalsi")) {
solver = new RegulaFalsiSolver();
} else if (method.isSymbolName("Illinois")) {
solver = new IllinoisSolver();
} else if (method.isSymbolName("Pegasus")) {
solver = new PegasusSolver();
} else {
// default: NewtonSolver
DifferentiableUnivariateFunction fNewton = new UnaryNumerical(function, xVar, engine);
BaseAbstractUnivariateSolver<DifferentiableUnivariateFunction> solver2 = new NewtonSolver();
if (max == null) {
return solver2.solve(maxIterations, fNewton, min.doubleValue());
}
return solver2.solve(maxIterations, fNewton, min.doubleValue(), max.doubleValue());
}
if (max == null) {
return solver.solve(maxIterations, f, min.doubleValue());
}
return solver.solve(maxIterations, f, min.doubleValue(), max.doubleValue());
}
Aggregations