22 lines
466 B
Plaintext
22 lines
466 B
Plaintext
mean(v)={
|
|
vecsum(v)/#v
|
|
};
|
|
stdev(v,mu="")={
|
|
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);
|