public void LaguerreInequality()
 {
     foreach (int n in TestUtilities.GenerateRealValues(1.0, 1.0E2, 5))
     {
         foreach (double x in TestUtilities.GenerateRealValues(1.0E-2, 1.0E2, 5))
         {
             Assert.IsTrue(OrthogonalPolynomials.LaguerreL(n, x) <= Math.Exp(x / 2.0));
         }
     }
 }
 public void LaguerreSpecialCases()
 {
     foreach (int n in TestUtilities.GenerateIntegerValues(1, 100, 5))
     {
         Assert.IsTrue(OrthogonalPolynomials.LaguerreL(n, 0.0) == 1.0);
     }
     foreach (double x in TestUtilities.GenerateRealValues(1.0E-4, 1.0E4, 5))
     {
         Assert.IsTrue(OrthogonalPolynomials.LaguerreL(0, x) == 1.0);
     }
 }
 public void LaguerreRecurrence()
 {
     foreach (int n in TestUtilities.GenerateRealValues(1.0, 1.0E2, 5))
     {
         foreach (double x in TestUtilities.GenerateRealValues(1.0E-4, 1.0E4, 10))
         {
             double LP = OrthogonalPolynomials.LaguerreL(n + 1, x);
             double L  = OrthogonalPolynomials.LaguerreL(n, x);
             double LM = OrthogonalPolynomials.LaguerreL(n - 1, x);
             Assert.IsTrue(TestUtilities.IsSumNearlyEqual((n + 1) * LP, n * LM, (2 * n + 1 - x) * L));
         }
     }
 }
 public void AssociatedLaguerreSpecialCases()
 {
     foreach (double a in TestUtilities.GenerateRealValues(0.01, 100.0, 5))
     {
         foreach (double x in TestUtilities.GenerateRealValues(0.01, 100.0, 5))
         {
             Assert.IsTrue(TestUtilities.IsNearlyEqual(
                               OrthogonalPolynomials.LaguerreL(0, a, x), 1.0
                               ));
             Assert.IsTrue(TestUtilities.IsNearlyEqual(
                               OrthogonalPolynomials.LaguerreL(1, a, x), 1.0 + a - x
                               ));
         }
     }
 }
        public void AssociatedLaguerreOrthonormality()
        {
            // don't let orders get too big, or (1) the Gamma function will overflow and (2) our integral will become highly oscilatory
            foreach (int n in TestUtilities.GenerateIntegerValues(1, 10, 3))
            {
                foreach (int m in TestUtilities.GenerateIntegerValues(1, 10, 3))
                {
                    foreach (double a in TestUtilities.GenerateRealValues(0.1, 10.0, 5))
                    {
                        //int n = 2;
                        //int m = 4;
                        //double a = 3.5;

                        Console.WriteLine("n={0} m={1} a={2}", n, m, a);

                        // evaluate the orthonormal integral
                        Func <double, double> f = delegate(double x) {
                            return(Math.Pow(x, a) * Math.Exp(-x) *
                                   OrthogonalPolynomials.LaguerreL(m, a, x) *
                                   OrthogonalPolynomials.LaguerreL(n, a, x)
                                   );
                        };
                        Interval r = Interval.FromEndpoints(0.0, Double.PositiveInfinity);

                        // need to loosen default evaluation settings in order to get convergence in some of these cases
                        // seems to have most convergence problems for large a
                        IntegrationSettings e = new IntegrationSettings();
                        e.AbsolutePrecision = TestUtilities.TargetPrecision;
                        e.RelativePrecision = TestUtilities.TargetPrecision;

                        double I = FunctionMath.Integrate(f, r, e).Value;
                        Console.WriteLine(I);

                        // test for orthonormality
                        if (n == m)
                        {
                            Assert.IsTrue(TestUtilities.IsNearlyEqual(
                                              I, AdvancedMath.Gamma(n + a + 1) / AdvancedIntegerMath.Factorial(n)
                                              ));
                        }
                        else
                        {
                            Assert.IsTrue(Math.Abs(I) < TestUtilities.TargetPrecision);
                        }
                    }
                }
            }
        }
 public void AssociatedLaguerreAlphaRecurrence()
 {
     foreach (int n in TestUtilities.GenerateIntegerValues(1, 100, 5))
     {
         foreach (double a in TestUtilities.GenerateRealValues(0.01, 100.0, 5))
         {
             foreach (double x in TestUtilities.GenerateRealValues(0.01, 100.0, 5))
             {
                 Assert.IsTrue(TestUtilities.IsSumNearlyEqual(
                                   OrthogonalPolynomials.LaguerreL(n, a - 1.0, x), OrthogonalPolynomials.LaguerreL(n - 1, a, x),
                                   OrthogonalPolynomials.LaguerreL(n, a, x)
                                   ));
             }
         }
     }
 }
        public void LaguerreOrthonormality()
        {
            // to avoid highly oscilatory integrals, don't use very high orders
            int[] orders = TestUtilities.GenerateIntegerValues(1, 30, 3);
            for (int i = 0; i < orders.Length; i++)
            {
                int n = orders[i];
                for (int j = 0; j <= i; j++)
                {
                    int m = orders[j];

                    Func <double, double> f = delegate(double x) {
                        return(Math.Exp(-x) * OrthogonalPolynomials.LaguerreL(n, x) * OrthogonalPolynomials.LaguerreL(m, x));
                    };
                    Interval r = Interval.FromEndpoints(0.0, Double.PositiveInfinity);
                    double   I = FunctionMath.Integrate(f, r);
                    Console.WriteLine("{0} {1} {2}", n, m, I);
                    if (n == m)
                    {
                        Assert.IsTrue(TestUtilities.IsNearlyEqual(I, 1.0));
                    }
                    else
                    {
                        Assert.IsTrue(Math.Abs(I) < TestUtilities.TargetPrecision);
                    }
                }
            }

            /*
             * foreach (int n in TestUtilities.GenerateIntegerValues(1, 100, 3)) {
             *  foreach (int m in TestUtilities.GenerateIntegerValues(1, 100, 3)) {
             *      Function<double, double> f = delegate(double x) {
             *          return (Math.Exp(-x) * OrthogonalPolynomials.LaguerreL(n, x) * OrthogonalPolynomials.LaguerreL(m, x));
             *      };
             *      Interval r = Interval.FromEndpoints(0.0, Double.PositiveInfinity);
             *      double I = FunctionMath.Integrate(f, r);
             *      Console.WriteLine("{0} {1} {2}", n, m, I);
             *      if (n == m) {
             *          Assert.IsTrue(TestUtilities.IsNearlyEqual(I, 1.0));
             *      } else {
             *          Assert.IsTrue(Math.Abs(I) < TestUtilities.TargetPrecision);
             *      }
             *  }
             * }
             */
        }
        public void AssociatedLaguerreSum()
        {
            foreach (int n in TestUtilities.GenerateRealValues(1, 100, 5))
            {
                foreach (double a in TestUtilities.GenerateRealValues(0.1, 100.0, 5))
                {
                    foreach (double x in TestUtilities.GenerateRealValues(0.01, 1000.0, 5))
                    {
                        Console.WriteLine("n={0}, a={1}, x={2}", n, a, x);

                        List <double> L = new List <double>(n + 1);
                        for (int k = 0; k <= n; k++)
                        {
                            L.Add(OrthogonalPolynomials.LaguerreL(k, a, x));
                        }

                        Assert.IsTrue(TestUtilities.IsSumNearlyEqual(
                                          L, OrthogonalPolynomials.LaguerreL(n, a + 1.0, x)
                                          ));
                    }
                }
            }
        }
 public void LaguerreInvalidArgument()
 {
     OrthogonalPolynomials.LaguerreL(1, -0.1);
 }
 public void LaguerreInvalidOrder()
 {
     OrthogonalPolynomials.LaguerreL(-1, 1.0);
 }