Search in sources :

Example 1 with UnivariateFunction

use of org.hipparchus.analysis.UnivariateFunction in project symja_android_library by axkr.

the class InterpolatingFunction method interpolateSpline.

private double interpolateSpline(RealMatrix matrix, double interpolationX) {
    int rowDim = matrix.getRowDimension();
    double[] x = new double[rowDim];
    double[] y = new double[rowDim];
    double[][] data = matrix.getData();
    for (int i = 0; i < rowDim; i++) {
        x[i] = data[i][0];
        y[i] = data[i][1];
    }
    UnivariateInterpolator interpolator = new SplineInterpolator();
    UnivariateFunction function = interpolator.interpolate(x, y);
    double interpolatedY = function.value(interpolationX);
    return interpolatedY;
}
Also used : UnivariateFunction(org.hipparchus.analysis.UnivariateFunction) SplineInterpolator(org.hipparchus.analysis.interpolation.SplineInterpolator) UnivariateInterpolator(org.hipparchus.analysis.interpolation.UnivariateInterpolator)

Example 2 with UnivariateFunction

use of org.hipparchus.analysis.UnivariateFunction 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 UnivariateFunction

use of org.hipparchus.analysis.UnivariateFunction 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 UnivariateFunction

use of org.hipparchus.analysis.UnivariateFunction 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

UnivariateFunction (org.hipparchus.analysis.UnivariateFunction)4 UnaryNumerical (org.matheclipse.core.generic.UnaryNumerical)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 SplineInterpolator (org.hipparchus.analysis.interpolation.SplineInterpolator)1 UnivariateInterpolator (org.hipparchus.analysis.interpolation.UnivariateInterpolator)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