Statistics/Normal distribution: Difference between revisions

Adding C#
m (→‎{{header|REXX}}: changed comments, somplified some functions.)
(Adding C#)
Line 11:
* You may refer to code in [[Statistics/Basic]] if available.
<br><br>
 
=={{header|C sharp|C#}}==
{{libheader|Math.Net}}
<lang csharp>using System;
using MathNet.Numerics.Distributions;
using MathNet.Numerics.Statistics;
 
class Program
{
static void RunNormal(int sampleSize)
{
double[] X = new double[sampleSize];
var norm = new Normal(new Random());
norm.Samples(X);
 
const int numBuckets = 10;
var histogram = new Histogram(X, numBuckets);
Console.WriteLine("Sample size: {0:N0}", sampleSize);
for (int i = 0; i < numBuckets; i++)
{
string bar = new String('#', (int)(histogram[i].Count * 360 / sampleSize));
Console.WriteLine(" {0:0.00} : {1}", histogram[i].LowerBound, bar);
}
var statistics = new DescriptiveStatistics(X);
Console.WriteLine(" Mean: " + statistics.Mean);
Console.WriteLine("StdDev: " + statistics.StandardDeviation);
Console.WriteLine();
}
static void Main(string[] args)
{
RunNormal(100);
RunNormal(1000);
RunNormal(10000);
}
}</lang>
{{out}}
<pre>Sample size: 100
-2.12 : #######
-1.66 : ############################
-1.19 : #######################################
-0.72 : ##############################################
-0.26 : ###############################################################################
0.21 : ######################################################################################
0.68 : ################################
1.14 : #########################
1.61 : ###
2.07 : ##########
Mean: 0.0394411345297757
StdDev: 0.925286665513647
 
Sample size: 1,000
-2.98 : ##
-2.34 : ##########
-1.69 : ##############################
-1.05 : ################################################################
-0.40 : ###########################################################################################
0.24 : ########################################################################################
0.88 : ##############################################
1.53 : ##################
2.17 : #####
2.82 : ##
Mean: 0.0868718238400114
StdDev: 0.989120264661867
 
Sample size: 10,000
-3.88 :
-3.12 : ##
-2.35 : #################
-1.59 : ####################################################
-0.82 : ################################################################################################
-0.06 : ####################################################################################################
0.71 : ###############################################################
1.47 : #####################
2.23 : ####
3.00 :
Mean: 0.0208920122989818
StdDev: 1.00046328880424</pre>
 
=={{header|C++}}==
Anonymous user