Back to Richel Bilderbeek's homepage.
Back to Richel Bilderbeek's Code Snippets.
Gets the density at a certain x of a normal distribution with a certain mean and standard deviation.
Code in plain text can be found here.
#include <cmath>
//From http://www.richelbilderbeek.nl/CppGetDensityNormal.htm
double GetDensityNormal(const double x, const double mean, const double stddev)
{
const double firstTerm = 1.0 / (stddev * std::sqrt(2.0 * M_PI));
const double secondTerm = -( (x - mean) * (x - mean) / (2.0 * stddev * stddev) );
const double result = firstTerm * std::exp(secondTerm);
return result;
}
Back to Richel Bilderbeek's Code Snippets.
Back to Richel Bilderbeek's homepage.