话不多说,直接上代码
class Program
{
static void Main(string[] args)
{
var list = new double[]{
177.4656067141880,
177.6392486051540,
177.8128904961200,
177.9865323870850,
178.1601742780510,
178.3338161690170,
178.5074580599820,
178.6810999509480,
178.8547418419140,
179.0283837328790,
179.2020256238450,
179.3756675148110,
179.5493094057760,
179.7229512967420,
179.8965931877080,
180.0702350786730,
180.2438769696390,
180.4175188606050,
180.5911607515700,
180.7648026425360};
foreach (var item in list)
{
var value = NormDist(item, 179.115204678362, 0.412399491043473, false);
Console.WriteLine(value.ToString("#0.0000000000000000000000000000000000000000"));
}
Console.Read();
}
private static double Stdev_S(IEnumerable<double> values)
{
double ret = 0;
if (values.Count() > 0)
{
double avg = values.Average();
double sum = values.Sum(d => Math.Pow(d - avg, 2));
ret = Math.Sqrt(sum / (values.Count()-1));
}
return ret;
}
private static double Stdev_P(IEnumerable<double> values)
{
double ret = 0;
if (values.Count() > 0)
{
double avg = values.Average();
double sum = values.Sum(d => Math.Pow(d - avg, 2));
ret = Math.Sqrt(sum / values.Count());
}
return ret;
}
private static double NormDist(double x,double mean,double standard_dev,bool cumulative)
{
if (cumulative)
return NormDistTrue(x, mean, standard_dev);
else
return NormDistFalse(x, mean, standard_dev);
}
private static double NormDistTrue(double x, double mean, double standard_dev)
{
var x2 = (x - mean) / standard_dev;
if (x2==0)
{
return 0.5;
}
else
{
var oor2pi = 1 / Math.Sqrt(2.0 * Math.PI);
var t = 1 / (1.0 + 0.2316419 * Math.Abs(x2));
t = t * oor2pi * Math.Exp(-0.5 * x2 * x2)
* (0.31938153 + t
* (-0.356563782 + t
* (1.781477937 + t
* (-1.821255978 + t
* 1.330274429))));
if (x2>0)
{
return 1.0 - t;
}
else
{
return t;
}
}
}
private static double NormDistFalse(double x, double mean, double standard_dev)
{
double PowOfE = -(Math.Pow(x - mean, 2) / (2.0 * Math.Pow(standard_dev, 2)));
return (1 / (Math.Sqrt(2.0 * Math.PI) * standard_dev)) * Math.Pow(Math.E, PowOfE);
}
}