Well, there was a thread about a frequency function and a bell curve in Excel.

http://www.daniweb.com/forums/thread295203.html

So here it is how about to do the NORMDIST function in Excel in C#.

# Simulating NORMDIST function of Excel in C#

2,466 Views

About the Author

ddanbe
2,724
Professional Procrastinator
Featured Poster

Have programmed in Modula-2 on a professional basis in the eighties. Now I am quite fond of C# AND Python!

```
// Evaluation of the bell or Gauss curve.
// See http://en.wikipedia.org/wiki/Normal_distribution
public static double NormalDist(double x, double mean, double standard_dev)
{
double fact = standard_dev * Math.Sqrt(2.0 * Math.PI);
double expo = (x - mean) * (x - mean) / (2.0 * standard_dev * standard_dev);
return Math.Exp(-expo) / fact;
}
// Simulation of Excel's NORMDIST function, I guess not as it is done there
public static double NORMDIST(double x, double mean, double standard_dev, bool cumulative)
{
const double parts = 50000.0; //large enough to make the trapzoids small enough
double lowBound = 0.0;
if (cumulative) //do integration: trapezoidal rule used here
{
double width = (x - lowBound) / (parts - 1.0);
double integral = 0.0;
for (int i = 1; i < parts - 1; i++)
{
integral += 0.5 * width * (NormalDist(lowBound + width * i, mean, standard_dev) +
(NormalDist(lowBound + width * (i + 1), mean, standard_dev)));
}
return integral;
}
else //return function value
{
return NormalDist(x, mean, standard_dev);
}
}
```

Johan_1
0
Newbie Poster

ddanbe
2,724
Professional Procrastinator
Featured Poster

dlhockey12
0
Newbie Poster

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.