Article View: comp.sources.hp48
Article #38v07i018: approxpi.dcl - Find PI v1.0, Part01/01
From: DANIEL COHEN-LAROQUE
Date: Mon, 28 Sep 1992 21:39
Date: Mon, 28 Sep 1992 21:39
221 lines
8380 bytes
8380 bytes
Checksum: 2743647618 (verify with brik -cv)
Submitted-by: DANIEL COHEN-LAROQUE <COHEN_LA@eldi.epfl.ch>
Posting-number: Volume 7, Issue 18
Archive-name: approxpi.dcl
BEGIN_DOC approxpi.doc
Hi all,
There are so many algorithms for finding the number PI that it
was difficult not to try a few ones.
The following program uses the MonteCarlo's method which is based
on the repartition of random numbers:
|-----------|
| - - |
|- -|
|- -|
| - - |
|-----------|
If the radius of the circle is r then the surface inside is PI*r^2=S1
The surface inside the entire square is immediately S2=4*r^2
So, the ratio S1/S2 gives PI/4 and stands for the ratio between
the points droped inside the circle and the ones inside the square!
Don't expect this method to be accurate: the best result I obtained
is about 2% (relative error) with 5'000 points...
This simulation has no scientific purposes and is completely useless.
However, I post it because of the originality of the method.
A French expression says:"Le hasard fait bien les choses!"
Mail me the American translation or any comments to:
Daniel COHEN-LAROQUE
Swiss Federal Institute of Technology
cohen_la@eldi.epfl.ch
END_DOC
BEGIN_RPL approxpi.rpl
%%HP: T(3)A(R)F(.);
@ Approxime par la methode de MonteCarlo
DIR
GO
\<< 0 0 \-> n in
\<< INIT
DO RANDXY
"PLOTING POINTS"
WARN 1 10
START \GS-
V\-> \->V2 DUP (-3.3,0)
- ABS 3.1 \<=
\<< 'in'
INCR DROP
\>> IFT
PIXON 1000 .02 BEEP
NEXT
"UPDATING RESULT"
WARN 'n' 10 STO+
PICT (4.1,1.5) n
\->STR 1 \->GROB REPL
in n / 4 * \-> t
\<< PICT
(1.6,-.5) t 10 RND
1 \->GROB REPL PICT
(3.3,-1.5) t \pi \->NUM
%CH ABS 2 RND 1
\->GROB REPL
\>>
UNTIL KEY
END DROP
"ON TO EXIT" WARN {
} PVIEW
\>>
\>>
WARN
\<< 1 \->GROB \-> s
\<< PICT
(.4,-2.4) PICT
(.1,-2.2) # 63d
# 9d BLANK NEG REPL
s GXOR
\>>
\>>
RANDXY
\<< 0 RDZ
"WAIT RANDOM #"
WARN 1 10
START RAND
6.2 * 6.4 - RAND
6.2 * 3.1 - 2 \->ARRY
1 RND \GS+ 800 .01
BEEP
NEXT
\>>
INIT
\<< -19 SF STD
RAD PICT PURGE {
# 0d # 0d } PVIEW {
# 32d # 32d } # 31d
0 6.3 ARC { # 1d
# 1d } { # 63d
# 63d } BOX PICT {
# 69d # 3d }
"Computing:" 2
\->GROB REPL { # 129d
# 63d } { # 66d
# 1d } BOX { # 129d
# 12d } { # 66d
# 12d } LINE PICT
(.3,1.5)
"# POINTS: 0" 1
\->GROB REPL PICT
(.4,.5) "\pi: " \pi
\->NUM 10 RND + 1
\->GROB REPL PICT
(.4,-.5) "PI: 0" 1
\->GROB REPL PICT
(.4,-1.5)
"\GDr [%]: \oo" 1 \->GROB
REPL
\>>
PPAR {
(-6.5,-3.1)
(6.5,3.2) X 0 (0,0)
FUNCTION Y }
END
END_RPL
BEGIN_ASC approxpi.asc
%%HP: T(1)A(R)F(.); @ tasc v2.52 file
"69A20FF7D47000000040050514254047A2077920000000000000056900000000
00000139779200000000000000560000000000000023084E2010854B2A277920
00000000000000000000000000000000166E184E201095B21301A0004094E494
4540D9D20E1632339201000000000000919472C1684C14B3C1634E1EFE0247A2
0E4A20510000000000000000000E4A20510000000000000000000B21300F2E14
7A20E4A20510000200000000000000E4A20510000200000000000000B2130E4A
2051000F1000000000000004B2A23392000000000000003602D5E147A20E4A20
510001000000000000000E4A20510001000000000000000B213047A20E4A2051
000F300000000000000E4A2051000F300000000000000B2130CE3E1634E147A2
0E4A20510005400000000000000E4A20510003000000000000000B2130C2A209
100034F6D607574796E676A3ED2A2DA5E1AE8C147A20E4A20510001800000000
000000E4A2051000F300000000000000B213047A20E4A2051000240000000000
0000E4A20510001000000000000000B2130CE3E147A20E4A2051000180000000
0000000E4A2051000C000000000000000B213047A20E4A205100024000000000
00000E4A2051000C000000000000000B2130893E1634E1779209990000000000
0300000000000000510C2A20B1000320205F494E44535A302039C2A2DA5E1AE8
C1634E17792099900000000000409990000000000050C2A20B000078A302DBAA
14E5A133920100000000000001055DB176BA19C2A2DA5E1AE8C1634E17792099
900000000000409990000000000059C2A20F00000594A302039C2A2DA5E1AE8C
1634E17792099900000000000400000000000000519C2A2071000B92702B552D
5A302F99C2A2DA5E1AE8C193632B213086400602514E444859560D9D20E16324
B2A24D1C1C2A20F100075149445022514E444F4D4023284E2040751425E49C2A
2339201000000000000010301329B1C1339200000000000000260EEDA1339200
00000000000046090DA19B1C1339200000000000000260EEDA13392000000000
0000013090DA1ED2A2900D19C2A255DB116DF133920200000000000008033920
89900000000000104C5A1C423293632B2130F310040751425E440D9D20E16329
C2A2DA5E11C432D6E201037E1632634E17792099900000000000400000000000
000429634E17792099900000000000100000000000000229E4A2051000F30000
0000000000E4A20510009000000000000000614E1599A1AE8C1D6E2010374E4E
1EF53293632B21307E0002074F420D9D20E16324B2A24B2A21C432D6E2010E6D
6E202096E6E163284E204094E494453C03284E20602514E4448595C2A2012000
05C4F44594E4740205F494E4453584E2040751425E49C2A23392010000000000
0001030132B8DF160DD166ED178BF17792000000000000003390000000000000
00090DA1F1AA1339200000000000000130CFCE1C9432D9D20E163245632D6E20
2096E6976324F8028DBF193632B2130DC4A1A13E133920300000000000001033
92089900000000000204C5A1C4232C2A2032000550544144594E474022554355
5C44584E2040751425E445632D6E2010E697632339201000000000000010B440
2634E17792000000000000001400000000000000510D6E2010E6B0BC19C2A2DA
5E1AE8C1D6E202096E6D6E2010E650FA1803A2EEDA11C432D6E201047E163263
4E17792000000000000006109990000000000059D6E201047339201000000000
00001055DB19C2A2DA5E1AE8C1634E1779200000000000000330000000000000
0519D6E201047DBAA14E5A1941C1F1AA1ED2A255DB19C2A2DA5E1AE8C1EF532D
E032378A19B6328DBF1C2A2091000F4E40245F4025485944584E2040751425E4
47A20B21300F2E1EF53293632B21309A29"
@ BYTES: #92A9h 1391
END_ASC
BYTES: #92A9h 1391
BEGIN_UU approxpi.uue
begin 644 approxpi
M2%!(4#0X+466*O!_30<````$4%!!4@1T*G"7`@```````%"6````````$)-W
M*0````````!E`````````#*`Y`(!6+2B<I<"`````````````````````&'F
M@>0"`5DK,1`*``1)3DE4!)TMX&$C,RD0````````&4DG'(;$03L<-N3A[R!T
M*N"D`A4```````````#@I`(5````````````L!(#\.)!IP).*E`!`"``````
M````3BI0`0`@`````````"LQX*0"%0#P`0```````$`K*C,I`````````&,@
M71YT*N"D`A4`$`````````#@I`(5`!``````````L!(#="K@I`(5`/`#````
M````X*0"%0#P`P```````+`2`^SC84,>="K@I`(5`%`$````````X*0"%0`P
M`````````+`2`RPJD`$`0V]M<'5T:6YG.MZBTEH>ZLA!IP).*E`!`($`````
M````3BI0`0`_`````````"LQ0*<"3BI0`0!"`````````$XJ4`$``0``````
M```K,<`^'G0JX*0"%0`0"````````."D`A4`P`````````"P$@-T*N"D`A4`
M(`0```````#@I`(5`,``````````L!(#F.-A0QYW*9"9```````P````````
M`!7`H@(;`#`"`O64Y$0UI0,"DRPJK>6ACAPVY'&7`ID)```````$F0D`````
M``4L*K```(<Z(+VJ05X:,RD0````````$%#5&V>KD2PJK>6ACAPVY'&7`ID)
M```````$F0D``````)4L*O```%!).B`PR:+26A[JR&%#'G<ID)D``````$``
M````````%<FB`A<`L"D'LE72I0/RF2PJK>6ACAPY-K(2`V@$8"`5Y$2$E670
MV0(>-D(K*M3!P:("'P!P%91$!2(5Y$3TU`0R@N0"!%=!4D[)HC*3`@$`````
M```!`S&2&QPS*0````````!BX-X:,RD`````````9)#0&KG!,9,"````````
M(`;NK3&3`@```````!`#":WA+2H)T)$L*E6]$=8?,RD@````````@#"3`I@)
M```````!Q*7!)",Y-K(2`S\!0'`5).5$T-D"'C:2+"JMY1%,(VTN$##G82,V
MY'&7`ID)```````$````````0)(VY'&7`ID)```````!````````()).*E`!
M`#\`````````3BI0`0`)`````````!;D49D:ZLC1Y@(!<^3DX5\C.3:R$@/G
M`"!P]"30V0(>-D(K*K2B$DPC;2X0X-;F`@)I;AXV@N0"!$E.253#,(+D`@92
M04Y$6%DL*A`"`%!,3U1)3D<@4$])3E132"Y`<!4DY90L*C,I$````````!`P
M$".+_6'0'6;><;@?=RD`````````,PD`````````D-`:'ZHQDP(````````0
M`_SLP4DCG2W@82-4-M+F`@)I;GDV0H\@V/N18R,K,=!,&AKC,9,"`P``````
M``$S*8"9```````@0%P:3#+"H@(C`%`%111$E>1T!")5-%7%1(7D`@1705).
M5#;2Y@(!;GDV,I,"`0````````%+!&)#'G<I`````````$$`````````%=#F
M`@%N"\N1+"JMY:&.'&TN()#FUN8"`6X%KX$P*NZM$4PC;2X00.=A(S;D<9<"
M````````8`&9"0``````E6TN$$`WDP(!`````````56]D2PJK>6ACAPVY'&7
M`@```````#`#````````4)%M+A!`UZL:Y*61%!P?JN$M*E6]D2PJK>6ACAS^
M-=(.(W.HD6LCV/O!H@(9`/#D!$+U!%*$E42%Y`($5T%23G0JL!(#\.+A7R,Y
$-K(2`[(2
`
end
sum -r/size 62570/1957 section (from "begin" to "end")
sum -r/size 35298/1399 entire input file
END_UU
Technical Details
Message-ID:
<1992Sep28.213956.7904@seq.uncwil.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!sun-barr!ames!haven.umd.edu!darwin.sura.net!gatech!concert!seq!spellShow Full Headers
Complete Article Headers
Newsgroups: comp.sources.hp48 Path: arc1-ca.pugleaf.net!sparky!uunet!sun-barr!ames!haven.umd.edu!darwin.sura.net!gatech!concert!seq!spell From: DANIEL COHEN-LAROQUE <COHEN_LA@eldi.epfl.ch> Subject: v07i018: approxpi.dcl - Find PI v1.0, Part01/01 Message-ID: <1992Sep28.213956.7904@seq.uncwil.edu> Followup-To: comp.sys.hp48 Sender: spell@seq.uncwil.edu (Chris Spell) Organization: Univ. of North Carolina @ Wilmington Date: Mon, 28 Sep 1992 21:39:56 GMT Approved: spell@seq.uncwil.edu Lines: 225