PI_Basic.html
• Go back to Main Menu
• Go back to Math
• Go Back to PI Stuff
• ##### 10 ! Some Fib & PI tests 26-Oct-2010 by dac20 ! 29-Jan-2011 by dac,30 Ver\$="HTML.BAS"40 !50 GOSUB Init60 !70 ON KEY 1 LABEL " 2D GAUSSIAN" GOSUB D2_gauss80 ON KEY 2 LABEL " 3D GAUSSIAN" GOSUB D3_gauss90 ON KEY 3 LABEL "SIN(x)/x AREA " GOSUB Sin_x_area100 ON KEY 4 LABEL "SIN(x)/x INT " GOSUB Sin_x_int110 ON KEY 5 LABEL "1-1/3 +1/5-1/7" GOSUB One_div_n 120 ON KEY 6 LABEL "A SERIESOF SUMS " GOSUB Sos 130 ON KEY 7 LABEL " " GOSUB Null 140 ON KEY 8 LABEL " MAKE GIF " GOSUB Make_gif 150 GOTO 70 160 Null:! 170 ! 180 D2_gauss:! 190 CONTROL 1;1,2 200 PRINT " #1) 2D-Gaussian Area SUM: "&CHR\$(251)&CHR\$(227) 210 Sum=0 220 Stp=.2 225 Xr=0.2 227 Steps=2*Xr/Stp 230 FOR I=-Xr TO Xr STEP Stp 240 Y=1/EXP(I^2) 250 Dif_area=Y*Stp 260 Sum=Sum+Dif_area 270 DISP Sum 280 NEXT I 290 CONTROL 1;1,3 300 PRINT USING "5X,6A,12D,10X,5A,D.11D,2X,D.11D";"Iter: ";Steps;"SUM: ";Sum;Sum^2 310 RETURN 320 ! 330 D3_gauss:! 340 CONTROL 1;1,5 350 PRINT " #2) 3D-Gaussian Volume SUM: "&CHR\$(227) 360 Sum=0 370 Stp=.00002 380 Xr=5.2 385 I=0 390 FOR R=0 TO Xr STEP Stp 400 I=I+1 410 Y=1/EXP(R^2) 420 Dif_vol=Y*Stp*2*PI*R! Cylindrical differential vol, uses pi 430 Sum=Sum+Dif_vol 440 NEXT R 450 CONTROL 1;1,6 460 PRINT USING "5X,6A,12D,10X,5A,D.11D";"Iter: ";I;"SUM: ";Sum 470 RETURN 480 ! 490 Sin_x_area:! 500 CONTROL 1;1,8 510 PRINT " #3) y=SIN(x)/x For Area SUM: "&CHR\$(227) 520 Sum=0 530 Di=0 540 Dx=.5! Width of element Dx=0.2, 0.5, 1.0 all converge on PI 550 Dx2=Dx/2 560 FOR I=1 TO Loops 570 Di=Di+Dx 580 Sum=Sum+2*Dx*SIN(Di-Dx2)/(Di-Dx2) 590 IF I MOD Mod=0 THEN DISP I,Sum 600 NEXT I 610 I=I-1 620 CONTROL 1;1,9 630 PRINT USING "5X,6A,12D,10X,5A,D.11D";"Iter: ";I;"SUM: ";Sum 640 RETURN 650 ! 660 Sin_x_int:! 670 RAD 680 CONTROL 1;1,11 690 PRINT " #4) SIN(k)/k Integer SUM: ("&CHR\$(227)&"-1)/2" 700 Sum=0 710 FOR I=1 TO Loops 720 Sum=Sum+SIN(I)/I 730 IF I MOD Mod=0 THEN DISP I,Sum*2+1 740 NEXT I 750 I=I-1 760 CONTROL 1;1,12 770 PRINT USING "5X,6A,12D,10X,5A,D.11D,2X,D.11D";"Iter: ";I;"SUM: ";Sum;2*Sum+1 780 RETURN 790 ! 800 One_div_n:! 810 CONTROL 1;1,14 820 PRINT " #5) Odd Integer Reciprocals SUM: ("&CHR\$(227)&"/4)" 830 Sum=0 840 Sgn=1 850 It=Mod 860 FOR k=1 TO Loops ! PI to 10 places in 1E+9 steps 870 Sgn=-Sgn 880 Sum=Sum+Sgn/(1-2*k) ! SUM 1/1-1/3+1/5-1/7+1/9-... 890 IF k>It THEN 900 DISP k,4*Sum 910 It=It+Mod 920 END IF 930 NEXT k 940 k=k-1 950 CONTROL 1;1,15 960 PRINT USING "5X,6A,12D,10X,5A,D.11D,2X,D.11D";"Iter: ";k;"SUM: ";Sum;4*Sum 970 RETURN 980 ! 990 Sos:! 1000 S=1 1010 RESTORE 1020 1020 DATA 6, 90, 945, 9450, 93555 ! Constants 1030 CONTROL 1;1,17 1040 PRINT " #6) Sum(s) Of Similar SUMations:" 1050 READ K(*) 1060 FOR Exp=2 TO 10 STEP 2! Exponent Index 1070 Sum=0 1080 I=0 1090 Pilast=0 1100 WHILE I 1110 I=I+1 1120 Sum=Sum+1/I^Exp 1140 Pi=(K(Exp/2)*Sum)^(1/Exp) 1150 IF Pi=Pilast THEN GOTO 1180 1160 Pilast=Pi 1170 END WHILE 1180 Indx(Exp/2)=I! store WHILE Loops to converge on PI 1190 CONTROL 1;1,18+Exp/2 1200 PRINT USING "5X,4A,2D,2X,5A,12D, 3X,5A,D.11D,2X,D.11D";"Exp=";Exp;"Iter:";I;"SUM: ";Pi 1210 NEXT Exp 1220 RETURN 1230 ! 1240 Make_gif:! works directly into HTML, borrowed from DRAG8.BAS 1250 OUTPUT 2;Gname\$;RPT\$(CHR\$(255)&"B",10); 1260 INPUT "Input Gname\$ of GIF file to disk drive A: (Include Drive) ",Gname\$ 1270 CREATE BDAT Gname\$,20000! Bytes may have to be ed 4 busy graph 1280 DISP "List Of SUMation Example Results" 1290 CONFIGURE DUMP TO "GIF" 1300 DUMP DEVICE IS Gname\$ 1310 DUMP GRAPHICS 1320 CONFIGURE DUMP TO "HP-PCL" 1330 DUMP DEVICE IS 10! Set Dump Device back to printer from file 1340 RETURN 1350 ! 1360 Init: ! 1370 PLOTTER IS CRT,"INTERNAL";COLOR MAP 1380 SET PEN -Number INTENSITY .4,.1,.4! BLK 0,0,0 WHT 1,1,1 1390 COM K(1:5),Indx(1:5),Mod 1400 Loops=1.E+6 1410 REAL I 1420 Mod=100000 1430 RAD ! Radian Mode 1440 RETURN 1450 ! 1460 END
• Go Back to PI Stuff