Пример #1
0
        public void OdeAiry()
        {
            // This is the airy differential equation
            Func <double, double, double> f = (double x, double y) => x * y;

            // Solutions should be of the form f(x) = a Ai(x) + b Bi(x).
            // Given initial value of f and f', this equation plus the Wronskian can be solved to give
            //   a = \pi ( f Bi' - f' Bi )    b = \pi ( f' Ai - f Ai' )

            // Start with some initial conditions
            double x0  = 0.0;
            double y0  = 0.0;
            double yp0 = 1.0;

            // Find the a and b coefficients consistent with those values
            SolutionPair s0 = AdvancedMath.Airy(x0);
            double       a  = Math.PI * (y0 * s0.SecondSolutionDerivative - yp0 * s0.SecondSolutionValue);
            double       b  = Math.PI * (yp0 * s0.FirstSolutionValue - y0 * s0.FirstSolutionDerivative);

            Assert.IsTrue(TestUtilities.IsNearlyEqual(y0, a * s0.FirstSolutionValue + b * s0.SecondSolutionValue));
            Assert.IsTrue(TestUtilities.IsNearlyEqual(yp0, a * s0.FirstSolutionDerivative + b * s0.SecondSolutionDerivative));

            // Integrate to a new point (pick a negative one so we test left integration)
            double    x1     = -5.0;
            OdeResult result = FunctionMath.IntegrateConservativeOde(f, x0, y0, yp0, x1);

            Assert.IsTrue(TestUtilities.IsNearlyEqual(result.X, x1));
            Console.WriteLine(result.EvaluationCount);

            // The solution should still hold
            SolutionPair s1 = AdvancedMath.Airy(x1);

            Assert.IsTrue(TestUtilities.IsNearlyEqual(result.Y, a * s1.FirstSolutionValue + b * s1.SecondSolutionValue, result.Settings));
            Assert.IsTrue(TestUtilities.IsNearlyEqual(result.YPrime, a * s1.FirstSolutionDerivative + b * s1.SecondSolutionDerivative, result.Settings));
        }
Пример #2
0
 public void AiryAgreement()
 {
     foreach (double x in TestUtilities.GenerateRealValues(1.0E-2, 1.0E2, 4))
     {
         SolutionPair s = AdvancedMath.Airy(-x);
         Assert.IsTrue(TestUtilities.IsNearlyEqual(s.FirstSolutionValue, AdvancedMath.AiryAi(-x)));
         Assert.IsTrue(TestUtilities.IsNearlyEqual(s.SecondSolutionValue, AdvancedMath.AiryBi(-x)));
     }
 }
Пример #3
0
        public void AiryWronskian()
        {
            foreach (double x in TestUtilities.GenerateRealValues(1.0E-2, 1.0E2, 8))
            {
                SolutionPair p = AdvancedMath.Airy(x);
                Assert.IsTrue(TestUtilities.IsSumNearlyEqual(p.FirstSolutionValue * p.SecondSolutionDerivative, -p.SecondSolutionValue * p.FirstSolutionDerivative, 1.0 / Math.PI));

                SolutionPair q = AdvancedMath.Airy(-x);
                Assert.IsTrue(TestUtilities.IsSumNearlyEqual(q.FirstSolutionValue * q.SecondSolutionDerivative, -q.SecondSolutionValue * q.FirstSolutionDerivative, 1.0 / Math.PI));
            }
        }
Пример #4
0
        public void AiryPowerIntegrals()
        {
            // Bernard Laurenzi, "Moment Integrals of Powers of Airy Functions", ZAMP 44 (1993) 891

            double I2 = FunctionMath.Integrate(t => MoreMath.Pow(AdvancedMath.AiryAi(t), 2), 0.0, Double.PositiveInfinity);

            Assert.IsTrue(TestUtilities.IsNearlyEqual(I2, MoreMath.Sqr(AdvancedMath.Airy(0.0).FirstSolutionDerivative)));

            // I3 involves difference of 2F1 functions

            double I4 = FunctionMath.Integrate(t => MoreMath.Pow(AdvancedMath.AiryAi(t), 4), 0.0, Double.PositiveInfinity);

            Assert.IsTrue(TestUtilities.IsNearlyEqual(I4, Math.Log(3.0) / (24.0 * Math.PI * Math.PI)));
        }
Пример #5
0
        public void AiryModulusMomentIntegrals()
        {
            // https://math.stackexchange.com/questions/507425/an-integral-involving-airy-functions-int-0-infty-fracxp-operatornameai

            double I0 = FunctionMath.Integrate(t => {
                SolutionPair s = AdvancedMath.Airy(t);
                return(1.0 / (MoreMath.Sqr(s.FirstSolutionValue) + MoreMath.Sqr(s.SecondSolutionValue)));
            }, 0.0, Double.PositiveInfinity);

            Assert.IsTrue(TestUtilities.IsNearlyEqual(I0, Math.PI * Math.PI / 6.0));

            double I3 = FunctionMath.Integrate(t => {
                SolutionPair s = AdvancedMath.Airy(t);
                return(MoreMath.Pow(t, 3) / (MoreMath.Sqr(s.FirstSolutionValue) + MoreMath.Sqr(s.SecondSolutionValue)));
            }, 0.0, Double.PositiveInfinity);

            Assert.IsTrue(TestUtilities.IsNearlyEqual(I3, 5.0 * Math.PI * Math.PI / 32.0));
        }