Search in sources :

Example 1 with UnaryNumerical

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);
}
Also used : UnaryNumerical(org.matheclipse.core.generic.UnaryNumerical)

Example 2 with UnaryNumerical

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);
}
Also used : SimpsonIntegrator(org.hipparchus.analysis.integration.SimpsonIntegrator) UnaryNumerical(org.matheclipse.core.generic.UnaryNumerical) ISymbol(org.matheclipse.core.interfaces.ISymbol) UnivariateFunction(org.hipparchus.analysis.UnivariateFunction) UnivariateIntegrator(org.hipparchus.analysis.integration.UnivariateIntegrator) RombergIntegrator(org.hipparchus.analysis.integration.RombergIntegrator) EvalEngine(org.matheclipse.core.eval.EvalEngine) IExpr(org.matheclipse.core.interfaces.IExpr) GaussIntegratorFactory(org.hipparchus.analysis.integration.gauss.GaussIntegratorFactory) TrapezoidIntegrator(org.hipparchus.analysis.integration.TrapezoidIntegrator) GaussIntegrator(org.hipparchus.analysis.integration.gauss.GaussIntegrator)

Example 3 with UnaryNumerical

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);
}
Also used : Options(org.matheclipse.core.eval.util.Options) UnaryNumerical(org.matheclipse.core.generic.UnaryNumerical) ISymbol(org.matheclipse.core.interfaces.ISymbol) UnivariateFunction(org.hipparchus.analysis.UnivariateFunction) IExpr(org.matheclipse.core.interfaces.IExpr) FastFourierTransformer(org.hipparchus.transform.FastFourierTransformer)

Example 4 with UnaryNumerical

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());
}
Also used : BrentSolver(org.hipparchus.analysis.solvers.BrentSolver) UnaryNumerical(org.matheclipse.core.generic.UnaryNumerical) ISymbol(org.matheclipse.core.interfaces.ISymbol) UnivariateFunction(org.hipparchus.analysis.UnivariateFunction) DifferentiableUnivariateFunction(org.matheclipse.commons.math.analysis.solvers.DifferentiableUnivariateFunction) SecantSolver(org.hipparchus.analysis.solvers.SecantSolver) NewtonSolver(org.matheclipse.commons.math.analysis.solvers.NewtonSolver) IllinoisSolver(org.hipparchus.analysis.solvers.IllinoisSolver) BaseAbstractUnivariateSolver(org.hipparchus.analysis.solvers.BaseAbstractUnivariateSolver) PegasusSolver(org.hipparchus.analysis.solvers.PegasusSolver) MullerSolver(org.hipparchus.analysis.solvers.MullerSolver) BisectionSolver(org.hipparchus.analysis.solvers.BisectionSolver) RegulaFalsiSolver(org.hipparchus.analysis.solvers.RegulaFalsiSolver) RiddersSolver(org.hipparchus.analysis.solvers.RiddersSolver) DifferentiableUnivariateFunction(org.matheclipse.commons.math.analysis.solvers.DifferentiableUnivariateFunction)

Aggregations

UnaryNumerical (org.matheclipse.core.generic.UnaryNumerical)4 UnivariateFunction (org.hipparchus.analysis.UnivariateFunction)3 ISymbol (org.matheclipse.core.interfaces.ISymbol)3 IExpr (org.matheclipse.core.interfaces.IExpr)2 RombergIntegrator (org.hipparchus.analysis.integration.RombergIntegrator)1 SimpsonIntegrator (org.hipparchus.analysis.integration.SimpsonIntegrator)1 TrapezoidIntegrator (org.hipparchus.analysis.integration.TrapezoidIntegrator)1 UnivariateIntegrator (org.hipparchus.analysis.integration.UnivariateIntegrator)1 GaussIntegrator (org.hipparchus.analysis.integration.gauss.GaussIntegrator)1 GaussIntegratorFactory (org.hipparchus.analysis.integration.gauss.GaussIntegratorFactory)1 BaseAbstractUnivariateSolver (org.hipparchus.analysis.solvers.BaseAbstractUnivariateSolver)1 BisectionSolver (org.hipparchus.analysis.solvers.BisectionSolver)1 BrentSolver (org.hipparchus.analysis.solvers.BrentSolver)1 IllinoisSolver (org.hipparchus.analysis.solvers.IllinoisSolver)1 MullerSolver (org.hipparchus.analysis.solvers.MullerSolver)1 PegasusSolver (org.hipparchus.analysis.solvers.PegasusSolver)1 RegulaFalsiSolver (org.hipparchus.analysis.solvers.RegulaFalsiSolver)1 RiddersSolver (org.hipparchus.analysis.solvers.RiddersSolver)1 SecantSolver (org.hipparchus.analysis.solvers.SecantSolver)1 FastFourierTransformer (org.hipparchus.transform.FastFourierTransformer)1