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;
}
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);
}
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);
}
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());
}
Aggregations