21 lines
595 B
Text
21 lines
595 B
Text
mean(v)={
|
|
vecsum(v)/#v
|
|
};
|
|
stdev(v,mu="")={ \\ This is the population standard deviation; for the sample standard deviation, replace #v with (#v-1) for Bessel's correction.
|
|
if(mu=="",mu=mean(v));
|
|
sqrt(sum(i=1,#v,(v[i]-mu)^2)/#v)
|
|
};
|
|
histogram(v,bins=16,low=0,high=1)={
|
|
my(u=vector(bins),width=(high-low)/bins);
|
|
for(i=1,#v,u[(v[i]-low)\width+1]++);
|
|
u
|
|
};
|
|
show(n)={
|
|
my(v=vector(n,i,random(1.)),mu=mean(v),s=stdev(v,mu),h=histogram(v),sz=ceil(n/50/16));
|
|
for(i=1,16,for(j=1,h[i]\sz,print1("#"));print());
|
|
print("Mean: "mu);
|
|
print("Stdev: "s);
|
|
};
|
|
show(100);
|
|
show(1000);
|
|
show(10000);
|