> "By hitting return you will load a hopefully useful histogram program":


restart;
with(stats):
with(stats[statplots]):
Convert:=proc(data)
local hap,hap1,d,j1,j2,j3,mean;
hap:=[];
hap1:=[];
d:=[];
for j1 from 1 to nops(data)
do
hap:=[op(hap),data[j1][2]];
od;
mean := nops(data)*describe[mean](hap);
for j2 from 1 to nops(data)
do
hap1:=[op(hap1), hap[j2]/mean];
od;
for j3 from 1 to nops(data)
do
d:=[op(d), [data[j3][1],hap1[j3]]];
od;
d;
end:
Bargraph:=proc(data,xmin,xmax,k)
local sorteddata,dx,graphicslist,f:
sorteddata:=[]:
dx:=(xmax-xmin)/k:
graphicslist:=[]:
sorteddata:=sort(data):
if ((op(1,sorteddata)<xmin) or (op(nops(sorteddata),sorteddata)>xmax))
then
lprint(`Note: some data values lie outside the user-defined interval.`):
fi:
f:=proc(k,sorteddata,xmin,dx,xmax)
local i,j,currentupperlim,leng,index,counter,result,finallist,q,numb,
linelist:
linelist:=[]: finallist:=[]:
index:=1:
leng:=nops(sorteddata):
currentupperlim:=xmin+dx:
result:=[]:
for q from 1 to leng do
if ((op(q,sorteddata)>=xmin) and (op(q,sorteddata)<=xmax))
then finallist:=[op(finallist),op(q,sorteddata)]
fi:
od:
numb:=nops(finallist):
for i from 1 to k do
counter:=0:
while ((index<=numb) and (op(index,finallist)<=currentupperlim)) do
counter:=counter+1:
index:=index+1:
od:
result:=[op(result),counter]:
currentupperlim:=currentupperlim+dx:
od:
for j from 1 to k do
linelist:=[op(linelist),[xmin + (j-1)*dx,0]]:
linelist:=[op(linelist),[xmin + (j-1)*dx,op(j,result)/leng]]:
linelist:=[op(linelist),[xmin + j*dx,op(j,result)/leng]]:
linelist:=[op(linelist),[xmin + j*dx,0]]:
od:
plot(linelist,style=LINE);
end:
f(k,sorteddata,xmin,dx,xmax):
end:Areabargraph:=proc(data,xmin,xmax,k)
local sorteddata, dx, lines,graphicslist, f:
sorteddata:=[]:
dx:=(xmax-xmin)/k:
lines:=[]:
graphicslist:=[]:
sorteddata:=sort(data):
if ((op(1,sorteddata)<xmin) or (op(nops(sorteddata),sorteddata)>xmax))
then
lprint(`Note: some data values lie outside the user-defined interval.`)
fi:
f:=proc(k,sorteddata,xmin,dx,xmax,lines::evaln)
local i,j,currentupperlim,leng,index,counter,result,
finallist,q,numb,linelist:
finallist:=[]:
linelist:=[]:
index:=1:
leng:=nops(sorteddata):
currentupperlim:=xmin+dx:
result:=[]:
for q from 1 to leng do
if ((op(q,sorteddata)>=xmin) and (op(q,sorteddata)<=xmax))
then finallist:=[op(finallist),op(q,sorteddata)]
fi:
od:
numb:=nops(finallist):
for i from 1 to k do
counter:=0:
while ((index<=numb) and (op(index,finallist)<=currentupperlim)) do
counter:=counter+1:
index:=index+1:
od:
result:=[op(result),counter]:
currentupperlim:=currentupperlim+dx:
od:
for j from 1 to k do
linelist:=[op(linelist),[xmin + (j-1)*dx,0]]:
linelist:=[op(linelist),[xmin + (j-1)*dx,op(j,result)/(leng*dx)]]:
linelist:=[op(linelist),[xmin + j*dx,op(j,result)/(leng*dx)]]:
linelist:=[op(linelist),[xmin + j*dx,0]]:
od:
lines:=linelist:
end:
f(k,sorteddata,xmin,dx,xmax,lines):
plot(lines,style=LINE);
end:

Analysis:=proc(L)
local m,v,sd,k,S,i,j,l;
m:=0;
v:=0;
sd:=0;
for k from 1 to nops(L)
do
m:=m+L[k];
od;
m:=evalf(m/nops(L));
for i from 1 to nops(L)
do
v:=v+(L[i]-m)^2;
od;
v:=evalf(v/nops(L));
sd:=evalf(sqrt(v));
[m,v,sd];
end:

Histogram:=proc(d,n)
local list1,j1,j2,A,ml,mh,sl,sh,Al,Ah,L;
L:=list1;
Al:=Analysis(d);
ml:=Al[1];
sl:=Al[3];
lprint("the Mean is",ml);
lprint("the Standard deviation is",sl);
lprint("A histogram looks like");
Areabargraph(d,min(op(d))-.5,max(op(d))+.5,n );
end:

Histogram2:=proc(d,n)
local list1,j1,j2,A,ml,mh,sl,sh,Al,Ah,L;
L:=list1;
Al:=Analysis(d);
ml:=Al[1];
sl:=Al[3];
lprint("the Mean is",ml);
lprint("the Standard deviation is",sl);
end:



> R:=rand();
randomize(R);

StPete:=proc(view)
local U,C,r,i;
C:=0;
U:=0;
for i from 1 while U<>1
do
C:=C+1:
r:=stats[random, discreteuniform[0,1]](1);
if view=show
then
lprint(r);
fi;
if
r=1
then U:=1
fi;
od:

2^C;

end:

R := 427419669081

427419669081

> StPete(show);

0

0

0

1

16

> ManySt:=proc(m,k)
local i,L;
L:=[];
for i from 1 to m
do
L:=[op(L),StPete(noshow)];
od:
lprint("the maximum win was", max(op(L)));
Histogram2(L,k);
end:

> ManySt(1000,10);

"the maximum win was", 4096

"the Mean is", 20.15800000

"the Standard deviation is", 174.5922403

"A histogram looks like"

[Maple Plot]

> ManySt(10000,10);

"the maximum win was", 8192

"the Mean is", 13.48220000

"the Standard deviation is", 150.8084217

"A histogram looks like"

[Maple Plot]

> ManySt(100000,10);

"the maximum win was", 1048576

"the Mean is", 27.18446000

"the Standard deviation is", 3349.877123

"A histogram looks like"

Warning, computation interrupted

> ManySt(10000,10);
ManySt(10000,10);
ManySt(10000,10);
ManySt(10000,10);
ManySt(10000,10);
ManySt(10000,10);
ManySt(10000,10);
ManySt(10000,10);
ManySt(10000,10);
ManySt(10000,10);

"the maximum win was", 8192

"the Mean is", 12.34240000

"the Standard deviation is", 118.4458163

"the maximum win was", 8192

"the Mean is", 12.50240000

"the Standard deviation is", 124.0494203

"the maximum win was", 16384

"the Mean is", 13.30660000

"the Standard deviation is", 185.1975625

"the maximum win was", 1048576

"the Mean is", 119.9292000

"the Standard deviation is", 10490.42705

"the maximum win was", 8192

"the Mean is", 13.86640000

"the Standard deviation is", 169.1024652

"the maximum win was", 8192

"the Mean is", 11.87160000

"the Standard deviation is", 113.4501477

"the maximum win was", 65536

"the Mean is", 21.77360000

"the Standard deviation is", 687.1646089

"the maximum win was", 65536

"the Mean is", 29.56440000

"the Standard deviation is", 991.0011633

"the maximum win was", 65536

"the Mean is", 21.96740000

"the Standard deviation is", 741.1068826

"the maximum win was", 8192

"the Mean is", 12.15400000

"the Standard deviation is", 113.8784716

> ManySt(10000,10);
ManySt(10000,10);
ManySt(10000,10);
ManySt(10000,10);
ManySt(10000,10);

"the maximum win was", 8192

"the Mean is", 16.74920000

"the Standard deviation is", 188.1173467

"the maximum win was", 131072

"the Mean is", 26.07880000

"the Standard deviation is", 1315.591215

"the maximum win was", 4096

"the Mean is", 11.71720000

"the Standard deviation is", 83.07246608

"the maximum win was", 16384

"the Mean is", 14.27740000

"the Standard deviation is", 241.3519785

"the maximum win was", 16384

"the Mean is", 14.35240000

"the Standard deviation is", 215.1245355