public void DoubleFactorialSpecialCases() { Assert.IsTrue(AdvancedIntegerMath.DoubleFactorial(0) == 1); Assert.IsTrue(AdvancedIntegerMath.DoubleFactorial(1) == 1); Assert.IsTrue(AdvancedIntegerMath.DoubleFactorial(2) == 2); Assert.IsTrue(AdvancedIntegerMath.DoubleFactorial(3) == 3); Assert.IsTrue(AdvancedIntegerMath.DoubleFactorial(4) == 8); Assert.IsTrue(AdvancedIntegerMath.DoubleFactorial(5) == 15); }
/// <inheritdoc /> public override double CentralMoment(int r) { if (r < 0) { throw new ArgumentOutOfRangeException(nameof(r)); } else if (r == 0) { return(1.0); } else if ((r % 2) == 0) { // (r-1)!! \sigma^r return(AdvancedIntegerMath.DoubleFactorial(r - 1) * MoreMath.Pow(sigma, r)); } else { return(0.0); } }
/// <inheritdoc /> public override double Cumulant(int r) { if (r < 0) { throw new ArgumentOutOfRangeException("r"); } else if (r == 0) { return(0.0); } else if (r == 1) { return(Mean); } else { // K_{r+1} = \frac{(2 r)!}{2^r r! \mu^{2r+1} \lambda^r} = \frac{(2r - 1)!! \mu^{2r+1}}{\lambda^r} return(AdvancedIntegerMath.DoubleFactorial(2 * r - 3) * MoreMath.Pow(mu, 2 * r - 1) / MoreMath.Pow(lambda, r - 1)); } }
/// <inheritdoc /> public override double Cumulant(int r) { if (r < 0) { throw new ArgumentOutOfRangeException(nameof(r)); } else if (r == 0) { return(0.0); } else if (r == 1) { return(Mean); } else { // Mathworld (http://mathworld.wolfram.com/InverseGaussianDistribution.html) says: // K_{r+1} = \frac{(2 r)!}{2^r r! \mu^{2r+1} \lambda^r} // = \frac{(2r - 1)!! \mu^{2r+1}}{\lambda^r} return(AdvancedIntegerMath.DoubleFactorial(2 * r - 3) * MoreMath.Pow(mu * mu / lambda, r - 1) * mu); } }
public override double MomentAboutMean(int n) { if (n < 0) { throw new ArgumentOutOfRangeException("n"); } else if (n == 0) { return(1.0); } else if (n % 2 != 0) { return(0.0); } else { // Using // \int_0^D x^{2m} e^{-x^2 / 2} = 2^{m-1/2} \left[ \Gamma(m+1/2) - \Gamma(m+1/2, D^2 / 2) \right] // and \Gamma(m + 1/2) = \frac{(2m-1)!!}{2^m} \sqrt{\pi} and normalization above, you get // C_{2m} = \frac{(2m-1)!!}{\erf(D/\sqrt{2}) \left[ 1 - \frac{\Gamma(m+1/2, D^2 / 2)}{\Gamma(m + 1/2)} \right] // which reduced to standard normal (2m-1)!! in D \rightarrow \infty limit as expected. return(AdvancedIntegerMath.DoubleFactorial(n - 1) * (1.0 - AdvancedMath.RightRegularizedGamma(n / 2 + 0.5, D * D / 2.0)) / ED); } }
public void SphericalBesselMomentIntegral() { // \int_0^{\infty} dx x^n j_{n+1}(x) = 1/(2n+1)!! // which follows from derivative formula // (https://math.stackexchange.com/questions/805379/integral-involving-the-spherical-bessel-function-of-the-first-kind-int-0) foreach (int n in TestUtilities.GenerateIntegerValues(4, 100, 4)) { IntegrationResult M = FunctionMath.Integrate(x => MoreMath.Pow(x, -n) * AdvancedMath.SphericalBesselJ(n + 1, x), 0.0, Double.PositiveInfinity); Assert.IsTrue(M.Estimate.ConfidenceInterval(0.95).ClosedContains(1.0 / AdvancedIntegerMath.DoubleFactorial(2 * n + 1))); } }