> "By hitting return you will load a hopefully useful histogram making program allowing to easily analyze data given as a list of experimentally
determined values.":

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,ml-max(abs(ml-min(op(d))),abs(ml-max(op(d)))),
ml+max(abs(ml-min(op(d))),abs(ml-max(op(d)))),n);
end:

"You will need to go to the flipping program (we will use the ManyToss program) and you will need to go to the histogram progrm (we will use the
Histogram progrm). Hit return in order to load the following packages.":

with(plots):
with(stats):

Warning, these names have been redefined: anova, describe, fit, importdata, random, statevalf, statplots, transform

Warning, these names have been redefined: boxplot, histogram, scatterplot, xscale, xshift, xyexchange, xzexchange, yscale, yshift, yzexchange, zscale, zshift

Warning, the name changecoords has been redefined

Warning, these names have been redefined: anova, describe, fit, importdata, random, statevalf, statplots, transform

> "Here we have a program that flips a fair coin n times":

with(stats):

CoinToss:=proc(n)
local T,i,L;
T:=[];
L:=[random[empirical[.5,.5]](n)];
for i from 1 to n
do
T:=[op(T),2*(L[i]-3/2)];
od;
T;
end:

"Here we have a program that gives the running total of a list of numbers":

RunTotal:=proc(L)
local n,T,V,i;
n:=nops(L);
T:=[];
V:=0;
for i from 1 to n
do
V:=V+L[i];
T:=[op(T),V];
od;
T;
end:

"Here we have a program that perform the follwing experiment m times: take a coin and flip it n times and records the total.":


ManyToss:=proc(n,m)
local i,T;
T:=[];
for i from 1 to m
do
T:=[op(T),RunTotal(CoinToss(n))[n]];
od;
T;
end:

"The only new program here is a program wich makes a linear change to the elements of a list. We will use it to standardize a sum.":


Modify:=proc(L,u,c)
local i,H;
H:=[];
for i from 1 to nops(L)
do
H:=[op(H),evalf(c*(L[i]-u))];
od;
H;
end:



"Open and run the the Flipping program! This is because the Streaks program uses data produced by the CoinToss program and MaxStreaks uses the
program itself.":


"Here is a program that takes a coin flip list (Produced by CoinToss) and lists all the streak totals associted to the list.":

with(stats):

Streaks:=proc(L)
local n,R,t,k;
R:=[];
t:=1;
n:=nops(L);
for k from 2 to n
do
if
L[k] = L[k-1]
then
t:=t+1;
fi;
if L[k] <> L[k-1]
then
R:=[op(R),t] ;
t:=1;
fi;
od;
[op(R),t];
end:

"Here we have a program that perform the follwing experiment m times: take a coin and flip it n times and record the longest streak each time.":

MaxStreak:=proc(n,m)
local i,T;
T:=[];
for i from 1 to m
do
T:=[op(T),max(op(Streaks(CoinToss(n))))];
od;
T;
end:


Warning, these names have been redefined: anova, describe, fit, importdata, random, statevalf, statplots, transform

Warning, these names have been redefined: anova, describe, fit, importdata, random, statevalf, statplots, transform

> MS1:=MaxStreak(14,2000):

Histogram(MS1,9);

"the Mean is", 4.131500000

"the Standard deviation is", 1.491712958

"A histogram looks like"

[Maple Plot]

> SumIt:=proc(L)
local i,A;
A:=0;
for i from 1 to nops(L)
do
A:=A+L[i];
od;
A;
end:

Modify2:=proc(L,u,s,N)
local i,H;
H:=[];
for i from 1 to nops(L)
do
H:=[op(H),evalf((L[i]-u)/(sqrt(N)*s))];
od;
H;
end:

Exper:=proc(n,N,m,u,s)
local H,i;
H:=[];
for i from 1 to m
do
H:=[op(H),SumIt(Modify2(MaxStreak(n,N),u,s,N))];
od;
H;
end:

> E2:=Exper(14,100,500,4.13,1.5):

> H2:=Histogram(E2,11):

Nor:=plot((1/(sqrt(2*Pi)))*exp(-x^2/(2)),x =-3..3,color=blue):

display(H2,Nor);

"the Mean is", .8493333364e-1

"the Standard deviation is", .9723166512

"A histogram looks like"

[Maple Plot]

> MS1:=MaxStreak(200,2000):

> Histogram(MS1,11);

"the Mean is", 7.984500000

"the Standard deviation is", 1.832555464

"A histogram looks like"

[Maple Plot]

> Data:=[5,7,6,5,6,7,4,3,5,5,4,7,5,5,7,5,5,8,9,7,6,17,5,3,6,9,7,5,5,6,4,7,7,6,14,4,6,8,6,4];

Histogram(Data,9);

Data := [5, 7, 6, 5, 6, 7, 4, 3, 5, 5, 4, 7, 5, 5, ...

"the Mean is", 6.250000000

"the Standard deviation is", 2.576334606

"A histogram looks like"

[Maple Plot]

> E2:=Exper(200,40,100,7.95,1.7):

> H2:=Histogram(E2,7):

Nor:=plot((1/(sqrt(2*Pi)))*exp(-x^2/(2)),x =-4..4,color=blue):

display(H2,Nor);

"the Mean is", -.5394473701e-1

"the Standard deviation is", .9974170794

"A histogram looks like"

[Maple Plot]

> evalf((250-40*7.9)/(sqrt(40)*1.7));

-6.138538985