/// <summary> /// The Irwin-Hall distribution results from the sum on n independent standard uniform variables /// </summary> /// <param name="x">The value at which to evaluate the distribution.</param> /// <param name="n">The number of standard uniform variables.</param> public static double IrwinHallProbabilityDensityFunction(double x, int n) { if (x < 0 || x > n) { return(0.0); } double d = 0; for (int i = 0; i <= n; i++) { d += Math.Pow(-1, i) * MMath.Combinations(n, i) * Math.Pow(x - i, n - 1) * Math.Sign(x - i); } d *= 0.5; d /= MMath.Factorial(n - 1); return(d); }
/// <summary> /// The PDF of the Poisson distribution. /// The probability of n iid events occuring in an interval, if the expected number of event is lambda. /// </summary> /// <param name="lambda">Equals both the mean and variance of the distribution.</param> /// <param name="n">The number of events.</param> public static double PoissonProbabilityDensityFunction(double lambda, int n) { return(Math.Pow(lambda, n) * Math.Exp(-lambda) / MMath.Factorial(n)); }