/// <summary>
 /// Tests that the inputs to the root-finder are not null, and that a root is bracketed by the bounding values.
 /// </summary>
 /// <param name="function"> The function, not null </param>
 /// <param name="x1"> The first bound, not null </param>
 /// <param name="x2"> The second bound, not null, must be greater than x1 </param>
 /// <exception cref="IllegalArgumentException"> if x1 and x2 do not bracket a root </exception>
 protected internal virtual void checkInputs(DoubleFunction1D function, double?x1, double?x2)
 {
     ArgChecker.notNull(function, "function");
     ArgChecker.notNull(x1, "x1");
     ArgChecker.notNull(x2, "x2");
     ArgChecker.isTrue(x1 <= x2, "x1 must be less or equal to  x2");
     ArgChecker.isTrue(function.applyAsDouble(x1) * function.applyAsDouble(x2) <= 0, "x1 and x2 do not bracket a root");
 }
Ejemplo n.º 2
0
        /// <summary>
        /// {@inheritDoc}
        /// </summary>
        public virtual GaussianQuadratureData generate(int n)
        {
            ArgChecker.isTrue(n > 0);
            Pair <DoubleFunction1D, DoubleFunction1D>[] polynomials = LAGUERRE.getPolynomialsAndFirstDerivative(n, _alpha);
            Pair <DoubleFunction1D, DoubleFunction1D>   pair        = polynomials[n];
            DoubleFunction1D p1         = polynomials[n - 1].First;
            DoubleFunction1D function   = pair.First;
            DoubleFunction1D derivative = pair.Second;

            double[] x    = new double[n];
            double[] w    = new double[n];
            double   root = 0;

            for (int i = 0; i < n; i++)
            {
                root = ROOT_FINDER.getRoot(function, derivative, getInitialRootGuess(root, i, n, x)).Value;
                x[i] = root;
                w[i] = -GAMMA_FUNCTION.applyAsDouble(_alpha + n) / CombinatoricsUtils.factorialDouble(n) / (derivative.applyAsDouble(root) * p1.applyAsDouble(root));
            }
            return(new GaussianQuadratureData(x, w));
        }