Animation of a Monte Carlo Simulation

This is just a short demo for EMT.  We generate some random numbers and show, how the distribution approaches the normal distribution. The user can stop with the return key.

>function sampleanimate (n) ...
$fullwindow();
$X=normal(1,n);
$for k=2:n;
$   r=5;
$   {x,y}=histo(X[1:k],v=-r:0.5:r);
$   plot2d(x,y/k/0.5,a=-4,b=4,c=-0.2,d=0.45,>bar,<grid); 
$   plot2d("qnormal(x,0,1)",color=red,thickness=2,>add);
$   plot2d([-r,r],[-0.1,-0.1],>add);
$   plot2d(X[1:k],-0.1,>points,style="|",>add);
$   textbox("n = "+k,style="t",w=0.1);
$   if testkey() then break; endif;
$   wait(0.05);
$end;
$endfunction
>sampleanimate(1000):

test-001

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.