Re: Random simulation (and stimulation?) Message #2 Posted by Valentin Albillo on 18 July 2006, 2:19 p.m., in response to message #1 by Kiyoshi Akima
Hi, Kiyoshi Akima:
Kiyoshi Akima posted:
"Extra Credit
On your HP calculator, evaluate the following integral, giving the value and an estimate of the error.
/1 /1 /1 /1 /1 /1 /1 /1 dA dB dC dD dE eF dG DH
I =         
/0 /0 /0 /0 /0 /0 /0 /0 1 + A + B + C + D + E + F + G + H
Something a little more precise than The minimum value of the function is 1/9 and the maximum value is 1. Thus 1/9 < I < 1.
(After part 3 of this series, you will know how to do this.)"
I think I pretty much know how to do this right now :)
Matter of fact this is just a straightforward application of Monte Carlo techniques,
so to merely evaluate the 8dimensional integral this 3liner for the barebones HP71B (93 bytes) will do:
1 DESTROY ALL @ RANDOMIZE PI @ FOR K=1 TO 7 @ M=10^K @ S=0
2 FOR N=1 TO M @ S=S+1/(1+RND+RND+RND+RND+RND+RND+RND+RND) @ NEXT N
3 I=S/M @ DISP K;M,I @ NEXT K
>RUN
# Points Integral

1 10 .186416796277
2 100 .206225523207
3 1000 .206581885362
4 10000 .20584278312
5 100000 .205729644257
6 1000000 .205804443536
7 10000000 .20580445907
so your 8dimensional integral evaluates to I = 0.20580, correct to all five digits plus or
minus 1 ulp.
If you alwo want to compute a running estimate of the error, this slightly longer
version will do, still at 3 lines:
1 DESTROY ALL @ RANDOMIZE PI @ FOR K=1 TO 7 @ M=10^K @ S=0 @ E=0
2 FOR N=1 TO M @ T=1/(1+RND+RND+RND+RND+RND+RND+RND+RND) @ S=S+T @ E=E+T*T
3 NEXT N @ I=S/M @ E=SQR((E/MI*I)/M) @ DISP K;M,I,E @ NEXT K
>RUN
# Points Integral Estimated error

1 10 .186416796277 7.87240479015E3
2 100 .206225523207 3.63497557268E3
3 1000 .206581885362 1.1943736672E3
4 10000 .20584278312 3.62667298278E4
5 100000 .205729644257 1.15685295773E4
6 1000000 .205804443536 3.66089195702E5
7 10000000 .20580445907 1.15814079667E5
so we can now confidently state that I = 0.205804 + 0.000012 which arguably is "a little more
precise than 1/9 < I < 1", as you requested.
As is typical of Monte Carlo methods, the error is proportional to 1/Sqrt(N), where N is the number of random multidimensional points used, so the error diminishes by a factor of Sqrt(10) = 3.16+ for each increase of an order of magnitude in the number of points used. This is evident in the above data, where each Estimated Error
approximatey equals the previous one divided by 3.16+.
Faster convergence (order 1/N and better) may be easily obtained by a simple modification to the above 3liners but for the purposes of computing "a little more precise" value, this will do.
Your first question is a simple case of B*****'s needle, which I'll leave for others to deal with, and as for the World Cup I couldn't care less ! :)
Best regards from V.
Edited: 18 July 2006, 2:21 p.m.
