/** {@inheritDoc} */ @Override protected double doIntegrate() throws TooManyEvaluationsException, MaxCountExceededException { TrapezoidIntegrator qtrap = new TrapezoidIntegrator(); if (getMinimalIterationCount() == 1) { return (4 * qtrap.stage(this, 1) - qtrap.stage(this, 0)) / 3.0; } // Simpson's rule requires at least two trapezoid stages. double olds = 0; double oldt = qtrap.stage(this, 0); while (true) { final double t = qtrap.stage(this, getIterations()); incrementCount(); final double s = (4 * t - oldt) / 3.0; if (getIterations() >= getMinimalIterationCount()) { final double delta = FastMath.abs(s - olds); final double rLimit = getRelativeAccuracy() * (FastMath.abs(olds) + FastMath.abs(s)) * 0.5; if ((delta <= rLimit) || (delta <= getAbsoluteAccuracy())) { return s; } } olds = s; oldt = t; } }
/** {@inheritDoc} */ @Override protected double doIntegrate() throws MathIllegalArgumentException, TooManyEvaluationsException, MaxCountExceededException { double oldt = stage(this, 0); incrementCount(); while (true) { final int i = getIterations(); final double t = stage(this, i); if (i >= getMinimalIterationCount()) { final double delta = FastMath.abs(t - oldt); final double rLimit = getRelativeAccuracy() * (FastMath.abs(oldt) + FastMath.abs(t)) * 0.5; if ((delta <= rLimit) || (delta <= getAbsoluteAccuracy())) { return t; } } oldt = t; incrementCount(); } }
private double integrate(String method, IAST list, IExpr function) throws ConvergenceException { ISymbol xVar = (ISymbol) list.get(1); ISignedNumber min = (ISignedNumber) list.get(2); ISignedNumber max = (ISignedNumber) list.get(3); final EvalEngine engine = EvalEngine.get(); function = F.eval(function); DifferentiableUnivariateFunction f = new UnaryNumerical(function, xVar, engine); UnivariateIntegrator integrator = new TrapezoidIntegrator(); if (method.equals("Simpson")) { integrator = new SimpsonIntegrator(); } else if (method.equals("LegendreGauss")) { integrator = new LegendreGaussIntegrator(3, BaseAbstractUnivariateIntegrator.DEFAULT_RELATIVE_ACCURACY, BaseAbstractUnivariateIntegrator.DEFAULT_ABSOLUTE_ACCURACY, BaseAbstractUnivariateIntegrator.DEFAULT_MIN_ITERATIONS_COUNT, 64); } else if (method.equals("Romberg")) { integrator = new RombergIntegrator(); } else { // default: TrapezoidIntegrator } return integrator.integrate(10000, f, min.doubleValue(), max.doubleValue()); }
/** {@inheritDoc} */ @Override protected double doIntegrate() throws MathIllegalArgumentException, TooManyEvaluationsException, MaxCountExceededException { double oldt = stage(this, 0); incrementCount(); while (true) { final int i = getIterations(); final double t = stage(this, i); if (i >= getMinimalIterationCount()) { final double delta = Math.abs(t - oldt); final double rLimit = getRelativeAccuracy() * (Math.abs(oldt) + Math.abs(t)) * 0.5; if ((delta <= rLimit) || (delta <= getAbsoluteAccuracy())) { return t; } } oldt = t; incrementCount(); } }
double currentRow[] = new double[m]; TrapezoidIntegrator qtrap = new TrapezoidIntegrator(); currentRow[0] = qtrap.stage(this, 0); incrementCount(); double olds = currentRow[0]; currentRow = tmpRow; currentRow[0] = qtrap.stage(this, i); incrementCount(); for (int j = 1; j <= i; j++) {
/** {@inheritDoc} */ @Override protected double doIntegrate() throws MathIllegalArgumentException, TooManyEvaluationsException, MaxCountExceededException { double oldt = stage(this, 0); incrementCount(); while (true) { final int i = getIterations(); final double t = stage(this, i); if (i >= getMinimalIterationCount()) { final double delta = FastMath.abs(t - oldt); final double rLimit = getRelativeAccuracy() * (FastMath.abs(oldt) + FastMath.abs(t)) * 0.5; if ((delta <= rLimit) || (delta <= getAbsoluteAccuracy())) { return t; } } oldt = t; incrementCount(); } }
/** {@inheritDoc} */ @Override protected double doIntegrate() throws TooManyEvaluationsException, MaxCountExceededException { TrapezoidIntegrator qtrap = new TrapezoidIntegrator(); if (getMinimalIterationCount() == 1) { return (4 * qtrap.stage(this, 1) - qtrap.stage(this, 0)) / 3.0; } // Simpson's rule requires at least two trapezoid stages. double olds = 0; double oldt = qtrap.stage(this, 0); while (true) { final double t = qtrap.stage(this, getIterations()); incrementCount(); final double s = (4 * t - oldt) / 3.0; if (getIterations() >= getMinimalIterationCount()) { final double delta = Math.abs(s - olds); final double rLimit = getRelativeAccuracy() * (Math.abs(olds) + Math.abs(s)) * 0.5; if ((delta <= rLimit) || (delta <= getAbsoluteAccuracy())) { return s; } } olds = s; oldt = t; } }
/** {@inheritDoc} */ @Override protected double doIntegrate() throws TooManyEvaluationsException, MaxCountExceededException { TrapezoidIntegrator qtrap = new TrapezoidIntegrator(); if (getMinimalIterationCount() == 1) { return (4 * qtrap.stage(this, 1) - qtrap.stage(this, 0)) / 3.0; } // Simpson's rule requires at least two trapezoid stages. double olds = 0; double oldt = qtrap.stage(this, 0); while (true) { final double t = qtrap.stage(this, getIterations()); incrementCount(); final double s = (4 * t - oldt) / 3.0; if (getIterations() >= getMinimalIterationCount()) { final double delta = FastMath.abs(s - olds); final double rLimit = getRelativeAccuracy() * (FastMath.abs(olds) + FastMath.abs(s)) * 0.5; if ((delta <= rLimit) || (delta <= getAbsoluteAccuracy())) { return s; } } olds = s; oldt = t; } }
double currentRow[] = new double[m]; TrapezoidIntegrator qtrap = new TrapezoidIntegrator(); currentRow[0] = qtrap.stage(this, 0); incrementCount(); double olds = currentRow[0]; currentRow = tmpRow; currentRow[0] = qtrap.stage(this, i); incrementCount(); for (int j = 1; j <= i; j++) {
double currentRow[] = new double[m]; TrapezoidIntegrator qtrap = new TrapezoidIntegrator(); currentRow[0] = qtrap.stage(this, 0); incrementCount(); double olds = currentRow[0]; currentRow = tmpRow; currentRow[0] = qtrap.stage(this, i); incrementCount(); for (int j = 1; j <= i; j++) {