Пример #1
0
 /// <summary>
 /// Finds all real roots of polynomial.
 /// </summary>
 /// <param name="coeficents">The coefficients of polynomial.</param>
 /// <param name="error">The error tollerance, actual roots are further polished to give
 /// much better approximation (around 1/100 of unpolished).</param>
 /// <returns>List of zeros.</returns>
 public static List <double> RealRoots([NotNull] double[] coeficents, Intervald range, double error)
 {
     // For now, replace by Laguerre when implemented.
     return(RootFinder.MultiBisectionAndPolish(
                Polynomial.CreateFunctiond(coeficents),
                Polynomial.CreateFunctiond(Polynomial.Differentiate(coeficents)),
                range, error, error * 0.01));
 }
Пример #2
0
        public void MultiBisection()
        {
            List <double> roots = RootFinder.MultiBisection(delegate(double x)
                                                            { return(x * x * x + 2.0 * x * x - x - 2.0); }, new Intervald(-4.0, 2.0), 0.01);

            roots.Sort();

            Assert.AreEqual(3, roots.Count);
            Assert.IsTrue(MathHelper.NearEqual(roots[0], -2.0, 0.01));
            Assert.IsTrue(MathHelper.NearEqual(roots[1], -1.0, 0.01));
            Assert.IsTrue(MathHelper.NearEqual(roots[2], 1.0, 0.01));
        }
Пример #3
0
 public void TangentRoot()
 {
     Assert.IsTrue(MathHelper.NearEqual(RootFinder.TangentRoot(delegate(double x) { return(x * x - 1.0); },
                                                               delegate(double x) { return(2 * x); }, 2.0, 0.001), 1.0, 0.0011));
 }
Пример #4
0
 public void Bisection()
 {
     Assert.IsTrue(MathHelper.NearEqual(RootFinder.Bisection(delegate(double x)
                                                             { return(x * x - 1.0); }, new Intervald(0.0, 10.0), 0.019), 1.0, 0.02));
 }