List of usage examples for org.apache.commons.math.analysis.integration LegendreGaussIntegrator LegendreGaussIntegrator
public LegendreGaussIntegrator(final int n, final int defaultMaximalIterationCount) throws IllegalArgumentException
From source file:geogebra.kernel.AlgoIntegralDefinite.java
private static double doAdaptiveGaussQuad(RealRootFunction fun, double a, double b) { if (++adaptiveGaussQuadCounter > MAX_GAUSS_QUAD_CALLS) { return Double.NaN; }/* w w w. j av a 2 s . com*/ // init GaussQuad classes for numerical integration if (firstGauss == null) { firstGauss = new LegendreGaussIntegrator(FIRST_ORDER, MAX_ITER); secondGauss = new LegendreGaussIntegrator(SECOND_ORDER, MAX_ITER); } double firstSum = 0; double secondSum = 0; boolean error = false; // integrate using gauss quadrature try { firstSum = firstGauss.integrate(new RealRootAdapter(fun), a, b); if (Double.isNaN(firstSum)) return Double.NaN; secondSum = secondGauss.integrate(new RealRootAdapter(fun), a, b); if (Double.isNaN(secondSum)) return Double.NaN; } catch (MaxIterationsExceededException e) { error = true; } catch (ConvergenceException e) { error = true; } catch (FunctionEvaluationException e) { return Double.NaN; } catch (IllegalArgumentException e) { return Double.NaN; } //if (!error) Application.debug(a+" "+b+" "+(firstSum - secondSum), Kernel.isEqual(firstSum, secondSum, Kernel.STANDARD_PRECISION) ? 1 : 0); //else Application.debug(a+" "+b+" error",1); // check if both results are equal boolean equal = !error && Kernel.isEqual(firstSum, secondSum, Kernel.STANDARD_PRECISION); if (equal) { // success return secondSum; } else { double mid = (a + b) / 2; double left = doAdaptiveGaussQuad(fun, a, mid); if (Double.isNaN(left)) return Double.NaN; else return left + doAdaptiveGaussQuad(fun, mid, b); } }
From source file:geogebra.common.kernel.cas.AlgoIntegralDefinite.java
private static double doAdaptiveGaussQuad(RealRootFunction fun, double a, double b) { if (++adaptiveGaussQuadCounter > MAX_GAUSS_QUAD_CALLS) { return Double.NaN; }//from www .j av a 2 s.c o m // init GaussQuad classes for numerical integration if (firstGauss == null) { firstGauss = new LegendreGaussIntegrator(FIRST_ORDER, MAX_ITER); secondGauss = new LegendreGaussIntegrator(SECOND_ORDER, MAX_ITER); } double firstSum = 0; double secondSum = 0; boolean error = false; // integrate using gauss quadrature try { firstSum = firstGauss.integrate((new RealRootAdapter(fun)), a, b); if (Double.isNaN(firstSum)) return Double.NaN; secondSum = secondGauss.integrate((new RealRootAdapter(fun)), a, b); if (Double.isNaN(secondSum)) return Double.NaN; } catch (MaxIterationsExceededException e) { error = true; } catch (ConvergenceException e) { error = true; } catch (FunctionEvaluationException e) { return Double.NaN; } catch (IllegalArgumentException e) { return Double.NaN; } // if (!error) Application.debug(a+" "+b+" "+(firstSum - secondSum), // Kernel.isEqual(firstSum, secondSum, Kernel.STANDARD_PRECISION) ? 1 : // 0); // else Application.debug(a+" "+b+" error",1); // check if both results are equal boolean equal = !error && Kernel.isEqual(firstSum, secondSum, Kernel.STANDARD_PRECISION); if (equal) { // success return secondSum; } double mid = (a + b) / 2; double left = doAdaptiveGaussQuad(fun, a, mid); if (Double.isNaN(left)) { return Double.NaN; } return left + doAdaptiveGaussQuad(fun, mid, b); }