Example #1
0
        public virtual double Laguerre(double lo, double hi, double fLo, double fHi)
        {
            Complex[] c = ComplexUtils.convertToComplex(Coefficients);

            Complex initial = new Complex(0.5 * (lo + hi), 0);
            Complex z = ComplexSolver.Solve(c, initial);
            if (ComplexSolver.IsRoot(lo, hi, z))
            {
                return z.Real;
            }
            else
            {
                double r = double.NaN;
                // Solve all roots and select the one we are seeking.
                Complex[] root = ComplexSolver.SolveAll(c, initial);
                for (int i = 0; i < root.Length; i++)
                {
                    if (ComplexSolver.IsRoot(lo, hi, root[i]))
                    {
                        r = root[i].Real;
                        break;
                    }
                }
                return r;
            }
        }
Example #2
0
 /// <summary>
 /// Find all complex roots for the polynomial with the given
 /// coefficients, starting from the given initial value.
 /// <br/>
 /// Note: This method is not part of the API of <seealso cref="BaseUnivariateSolver"/>.
 /// </summary>
 /// <param name="coefficients"> Polynomial coefficients. </param>
 /// <param name="initial"> Start value. </param>
 /// <returns> the point at which the function value is zero. </returns>
 /// <exception cref="org.apache.commons.math3.exception.TooManyEvaluationsException">
 /// if the maximum number of evaluations is exceeded. </exception>
 /// <exception cref="NullArgumentException"> if the {@code coefficients} is
 /// {@code null}. </exception>
 /// <exception cref="NoDataException"> if the {@code coefficients} array is empty.
 /// @since 3.1 </exception>
 public virtual Complex[] SolveAllComplex(double[] coefficients, double initial)
 {
     Setup(int.MaxValue, new PolynomialFunction(coefficients), double.NegativeInfinity, double.PositiveInfinity, initial);
     return ComplexSolver.SolveAll(ComplexUtils.convertToComplex(coefficients), new Complex(initial, 0d));
 }