Created
December 6, 2023 11:58
Calculates probability density, assuming normal distribution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The normal probability density function (PDF) is used in statistics to calculate the probability of a specific value occurring in a normal distribution. | |
func normalProbabilityDensityFunction(x: Double, mean: Double, stdDev: Double) -> Double { | |
let power = pow((x - mean), 2) | |
let numerator = exp(-1.0 * power / (2.0 * stdDev * stdDev)) | |
let denominator = 2.0 * Double.pi * stdDev * stdDev | |
return 1.0 / sqrt(denominator) * numerator | |
} | |
print(normalProbabilityDensityFunction(x: 60, mean: 64.43, stdDev: 2.99)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment