automatic_replot = 0 ; # Demonstrate the central limit theorem # for any discrete distribution over integers. # To use this, run octave, then type doit # Define x_n is a random variable from: # P(x) = p(0),p(1),p(2)....p(k) p=[ 0.5, 0.5 ]; p=[ 0.9 , 0.1 ]; p=[ 0.5 , 0, 0,0, 0.3 , 0.1 ,0,0, 0.1 ]; # z= sum(x_n); # compute P(z) = p*p*p*p .... *p . # where "*" denotes convolution. gset nokey clear y ; Nmax = 2500; # Find prob distbn of r, the number of # heads, # given N tosses y = p ; for N=1:Nmax # loop over N=1...Nmax # to tell gnuplot numbers that octave # knows, # we have to build a string, then # evaluate it. command = sprintf(" gset yrange [0: %f]", max(y) ) ; eval(command); # let's set the xrange in a smart way. s = size(y) ; command = sprintf(" gset xrange [0: %d]", s(2)-1 ) ; eval(command); # add a nice title command = sprintf(" gset title \"%d\" " , N ) ; eval(command); # do the plot! gplot y' w impulse 3 if( N<35 ) ans= input("ready?") ; endif y= conv(y,p); # do the convolution of y with p endfor