public void HermiteSpecialCases()
 {
     foreach (double x in aArguments)
     {
         Assert.IsTrue(OrthogonalPolynomials.HermiteH(0, x) == 1.0);
         Assert.IsTrue(OrthogonalPolynomials.HermiteH(1, x) == 2.0 * x);
     }
     foreach (int n in orders)
     {
         if (n > 100)
         {
             continue;
         }
         if (n % 2 == 0)
         {
             int m = n / 2;
             int s = 1;
             if (m % 2 != 0)
             {
                 s = -s;
             }
             Assert.IsTrue(TestUtilities.IsNearlyEqual(OrthogonalPolynomials.HermiteH(n, 0.0), s * AdvancedIntegerMath.Factorial(n) / AdvancedIntegerMath.Factorial(m)));
         }
         else
         {
             Assert.IsTrue(OrthogonalPolynomials.HermiteH(n, 0.0) == 0.0);
         }
     }
 }
 public void HermiteAddition()
 {
     foreach (int n in orders)
     {
         if (n > 100)
         {
             continue;
         }
         foreach (double x in aArguments)
         {
             foreach (double y in aArguments)
             {
                 double   value = OrthogonalPolynomials.HermiteH(n, x + y);
                 double[] terms = new double[n + 1]; double sum = 0.0;
                 for (int k = 0; k <= n; k++)
                 {
                     terms[k] = AdvancedIntegerMath.BinomialCoefficient(n, k) * OrthogonalPolynomials.HermiteH(k, x) * Math.Pow(2 * y, n - k);
                     sum     += terms[k];
                 }
                 Console.WriteLine("n={0}, x={1}, y={2}, H(x+y)={3}, sum={4}", n, x, y, value, sum);
                 Assert.IsTrue(TestUtilities.IsSumNearlyEqual(terms, value));
             }
         }
     }
 }
 public void HermiteRecurrence()
 {
     foreach (int n in TestUtilities.GenerateIntegerValues(1, 100, 10))
     {
         foreach (double x in TestUtilities.GenerateRealValues(1.0, 1000.0, 10))
         {
             Console.WriteLine("n={0} x={1}", n, x);
             Assert.IsTrue(TestUtilities.IsSumNearlyEqual(
                               OrthogonalPolynomials.HermiteH(n + 1, x), 2.0 * n * OrthogonalPolynomials.HermiteH(n - 1, x),
                               2.0 * x * OrthogonalPolynomials.HermiteH(n, x)
                               ));
         }
     }
 }
 public void HermiteReflection()
 {
     foreach (int n in TestUtilities.GenerateIntegerValues(1, 100, 10))
     {
         foreach (double x in TestUtilities.GenerateRealValues(1.0, 1000.0, 10))
         {
             Console.WriteLine("n={0} x={1}", n, x);
             if (n % 2 == 0)
             {
                 Assert.IsTrue(TestUtilities.IsNearlyEqual(OrthogonalPolynomials.HermiteH(n, -x), OrthogonalPolynomials.HermiteH(n, x)));
             }
             else
             {
                 Assert.IsTrue(TestUtilities.IsNearlyEqual(OrthogonalPolynomials.HermiteH(n, -x), -OrthogonalPolynomials.HermiteH(n, x)));
             }
         }
     }
 }
 public void HermiteSum()
 {
     // accuracy of equality falls at high n because of cancelations among large terms
     for (int n = 0; n < 12; n++)
     {
         double sum = 0.0;
         for (int k = 0; k <= n; k++)
         {
             double term = AdvancedIntegerMath.BinomialCoefficient(n, k) * OrthogonalPolynomials.HermiteH(n, k);
             Console.WriteLine("  k={0}, term={1}", k, term);
             if ((n - k) % 2 == 0)
             {
                 sum += term;
             }
             else
             {
                 sum -= term;
             }
         }
         Console.WriteLine("n={0}, sum={1}", n, sum);
         Assert.IsTrue(TestUtilities.IsNearlyEqual(sum, Math.Pow(2, n) * AdvancedIntegerMath.Factorial(n)));
     }
 }
 public void HermiteOrthonormality()
 {
     foreach (int n in TestUtilities.GenerateIntegerValues(1, 30, 3))
     {
         foreach (int m in TestUtilities.GenerateIntegerValues(1, 30, 3))
         {
             Func <double, double> f = delegate(double x) {
                 return(Math.Exp(-x * x) * OrthogonalPolynomials.HermiteH(n, x) * OrthogonalPolynomials.HermiteH(m, x));
             };
             Interval r = Interval.FromEndpoints(Double.NegativeInfinity, Double.PositiveInfinity);
             double   I = FunctionMath.Integrate(f, r);
             double   N = Math.Sqrt(Math.PI) * Math.Pow(2.0, n) * AdvancedIntegerMath.Factorial(n);
             Console.WriteLine("{0} {1} {2} {3}", n, m, I, N);
             if (n == m)
             {
                 Assert.IsTrue(TestUtilities.IsNearlyEqual(I, N));
             }
             else
             {
                 Assert.IsTrue(Math.Abs(I) <= TestUtilities.TargetPrecision);
             }
         }
     }
 }
 public void HermiteInvalidOrder()
 {
     OrthogonalPolynomials.HermiteH(-1, 1.0);
 }