home *** CD-ROM | disk | FTP | other *** search
/ Compute! Gazette 1994 August / 1994-08b.d64 / mtool (.txt) < prev    next >
Commodore BASIC  |  2022-09-20  |  7KB  |  225 lines

  1. 10 rem copyright 1994 - compute publications intl ltd - all rights reserved
  2. 20 print"[147]":poke 53280,6:poke 53281,6
  3. 30 print"[158]":ms$="[205]athematics [212]oolbox":gosub 5000
  4. 40 print"[159]":ms$="by [194]ruce [205]. [194]owden":gosub5000:print""
  5. 50 ms$="[195]opyright  1994":gosub5000:ms$="[195][207][205][208][213][212][197] [208]ublications [201]ntl [204]td":gosub5000
  6. 60 ms$="[193]ll [210]ights [210]eserved":gosub 5000:gosub6000
  7. 70 rem this program is self-modifying. do not renumber
  8. 100 goto150
  9. 110 deffnf(x)=x*x
  10. 120 return
  11. 130 deffng(x)=x
  12. 140 return
  13. 150 print"[147][213]se the function keys to make your      selection:"
  14. 160 print"f1 *** [201]ntegral [211]olution"
  15. 170 print"f3 *** [210]oots by [194]isection"
  16. 180 print"f5 *** [198]actorization of [201]ntegers"
  17. 185 print"f7 *** [209]uit the program       "
  18. 190 geta$:ifa$=""ora$<"[133]"ora$>"[136]"then190
  19. 200 print"[147]":x=asc(a$)-132:on x goto 210,1410,1750,3000
  20. 210 print" [201][206][212][197][199][210][193][212][201][207][206][160][194][217][160][211][201][205][208][211][207][206]'[211][160][193][208][208][210][207][216][201][205][193][212][201][207][206]"
  21. 220 print"[212]his part of the [205]athematics [212]oolbox"
  22. 230 print"[208]rogram uses [211]impson's [193]pproximation to"
  23. 240 print"solve for various integration problems.":gosub 6000
  24. 250 print"[147][213]se the function keys to make your      selection:"
  25. 260 print"f1 *** [193]rea under a rectangular curve"
  26. 270 print"f3 *** [193]rea under a polar curve"
  27. 280 print"f5 *** [193]rea between two rectangular            curves"
  28. 290 print"f7 *** [193]rea between two polar curves"
  29. 300 print"f2 *** [196][201][211][208][204][193][217] [205][207][210][197][160][195][200][207][201][195][197][211]"
  30. 310 geta$:ifa$=""then310
  31. 320 x=asc(a$)-132:ifx<1orx>5then310
  32. 330 print"[147]":onxgoto 490,560,630,690,340
  33. 340 print"[193]dditional [211]elections:"
  34. 350 print"f1 *** [204]ength of a rectangular curve"
  35. 360 print"f3 *** [204]ength of a polar curve"
  36. 370 print"f5 *** [211]urface of revol. about y-axis"
  37. 380 print"f7 *** [211]urface of revol. about x-axis"
  38. 390 print"f2 *** [196][201][211][208][204][193][217] [205][207][210][197][160][195][200][207][201][195][197][211]"
  39. 400 geta$:ifa$=""ora$<"[133]"ora$>"[137]"then400
  40. 410 x=asc(a$)-132:print"[147]":onxgoto 730,780,820,880,420
  41. 420 print"[193]dditional [211]elections:"
  42. 430 print"f1 *** [211]olid of revolution about y-axis"
  43. 440 print"f3 *** [211]olid of revolution about x-axis"
  44. 450 print"f5 *** [193]verage for a curve"
  45. 460 print"f7 *** [210][197][214][201][197][215] [195][200][207][201][195][197][211]"
  46. 465 print"f2 *** [210][197][212][213][210][206][160][212][207][160][205][193][201][206][160][205][197][206][213]"
  47. 470 geta$:ifa$=""ora$<"[133]"ora$>"[137]"then470
  48. 480 print"[147]":x=asc(a$)-132:onxgoto 920,980,1010,250,150
  49. 490 print"[147]     [193][210][197][193][160][213][206][196][197][210] [193][160][210][197][195][212][193][206][199][213][204][193][210][160][195][213][210][214][197]     [146]"
  50. 500 zz=510:goto2480
  51. 510 pr=1:gosub110
  52. 520 gosub1230
  53. 530 print"[212]he integral of your function, from":printa;"to";b;
  54. 540 print"[157], by [211]impson's [193]pproximation":print"with";c;"partitions, is"
  55. 545 printi
  56. 550 gosub 6000:goto150
  57. 560 print"[147]        [193][210][197][193][160][213][206][196][197][210][160][193][160][208][207][204][193][210][160][195][213][210][214][197]        [146]"
  58. 570 zz=580:goto2480
  59. 580 pr=2:gosub110:gosub130
  60. 590 gosub1230
  61. 600 print"[212]he integral of your function, from":printa;"to";b;
  62. 610 print"[157], by [211]impson's [193]pproximation":print"with";c;"partitions, is"
  63. 615 printi
  64. 620 gosub 6000:goto150
  65. 630 print"[147]   [193][210][197][193][160][194][197][212][215][197][197][206][160][212][215][207][160][210][197][195][212][193][206][199][213][204][193][210][160][195][213][210][214][197][211]  [146]"
  66. 640 zz=650:goto2520
  67. 650 pr=3:gosub110:gosub130
  68. 660 gosub1230
  69. 670 print"[212]he area, from";a;"to";b:print"with";c;"partitions, is"
  70. 675 printi
  71. 680 goto620
  72. 690 print"[147]      [193][210][197][193][160][194][197][212][215][197][197][206][160][212][215][207][160][208][207][204][193][210][160][195][213][210][214][197][211]     [146]"
  73. 700 zz=710:goto2520
  74. 710 pr=4:gosub110:gosub130
  75. 720 goto660
  76. 730 print"[147]      [204][197][206][199][212][200][160][207][198][160][193] [210][197][195][212][193][206][199][213][204][193][210][160][195][213][210][214][197]     [146]"
  77. 740 zz=750:goto2480
  78. 750 pr=5:gosub110:gosub130
  79. 760 gosub1230
  80. 770 print"[212]he length, from";a;"to";b:print"with";c;"partitions, is"
  81. 775 print i:goto620
  82. 780 print"[147]        [204][197][206][199][212][200][160][207][198][160][193] [208][207][204][193][210][160][195][213][210][214][197]         [146]"
  83. 790 zz=800:goto2480
  84. 800 pr=6:gosub110:gosub130
  85. 810 goto760
  86. 820 print"[147]   [211][213][210][198][193][195][197][160][207][198][160][210][197][214][207][204][213][212][201][207][206][160][193][194][207][213][212][160][217]-[193][216][201][211]   [146]"
  87. 830 zz=840:goto2480
  88. 840 pr=7:gosub110:gosub130
  89. 850 gosub1230
  90. 860 print"[212]he surface of revolution,":print"from";a;"to";b;
  91. 870 print"with";c;"partitions, is":printi;"square units":gosub 6000:goto150
  92. 880 print"[147]   [211][213][210][198][193][195][197][160][207][198][160][210][197][214][207][204][213][212][201][207][206][160][193][194][207][213][212][160][216]-[193][216][201][211]   [146]"
  93. 890 zz=900:goto2480
  94. 900 pr=8:gosub110:gosub130
  95. 910 goto850
  96. 920 print"[147]    [211][207][204][201][196][160][207][198][160][210][197][214][207][204][213][212][201][207][206][160][193][194][207][213][212][160][217]-[193][216][201][211]    [146]"
  97. 930 zz=940:goto2480
  98. 940 pr=9:gosub110:gosub130
  99. 950 gosub1230
  100. 960 print"[212]he solid of revolution,":print"from";a;"to";b;
  101. 970 print"with";c;"partitions, is":printi;"cubic units":gosub 6000:goto150
  102. 980 print"[147]    [211][207][204][201][196][160][207][198][160][210][197][214][207][204][213][212][201][207][206][160][193][194][207][213][212][160][216]-[193][216][201][211]    [146]"
  103. 990 zz=1000:goto2480
  104. 1000 pr=10:gosub110:gosub130:goto950
  105. 1010 print"[147]      [193][214][197][210][193][199][197][160][214][193][204][213][197][160][207][198][160][193][160][198][213][206][195][212][201][207][206]       [146]"
  106. 1020 zz=1030:goto2480
  107. 1030 pr=11:gosub110:gosub130
  108. 1040 gosub1230
  109. 1050 print"[147][212]he average value in the interval from":printa;"to";b;
  110. 1060 print"with";c;"partitions, is"
  111. 1065 print i:gosub 6000:goto150
  112. 1070 on pr goto 1080,1090,1100,1110,1120,1170,1180,1190,1200,1210,1220
  113. 1080 ev=fnf(x):return
  114. 1090 ev=.5*fnf(x)^2:return
  115. 1100 ev=abs(fnf(x)-fng(x)):return
  116. 1110 ev=abs(.5*(fnf(x)^2-fng(x)^2)):return
  117. 1120 gosub1130:ev=sqr(1+ev^2):return
  118. 1130 m1=x:ifx=0then1160
  119. 1140 m2=10^(log(abs(x))/log(10)-4)
  120. 1150 x=m1+m2:m3=fnf(x):x=m1-m2:ev=(m3-fnf(x))/2/m2:x=m1:return
  121. 1160 m2=1e-18:goto1150
  122. 1170 gosub1130:ev=sqr(fnf(x)^2+ev^2):return
  123. 1180 gosub1120:ev=2*(NULL)*x*ev:return
  124. 1190 gosub1120:ev=2*(NULL)*fnf(x)*ev:return
  125. 1200 ev=2*(NULL)*fnf(x)*x:return
  126. 1210 ev=(NULL)*fnf(x)^2:return
  127. 1220 ev=fnf(x)/(b-a):return
  128. 1230 input"[147][215]hat is the [204]ower [194]ound";a
  129. 1240 input"[215]hat is the [213]pper [194]ound";b
  130. 1250 input"[215]hat number of partitions";c:c=2*int(c/2+.5):print"";
  131. 1255 ms$="[195]omputing...":gosub5000
  132. 1260 p=(b-a)/3/c:x=a:gosub1070:y=ev:l=y:x=b:gosub1070:y=ev:l=l+y:o=(b-a)/c
  133. 1270 r=c-1:t=0
  134. 1280 x=o*r+a:gosub1070:y=ev:r=r-2:t=t+y:ifr=-1then1330
  135. 1290 goto1280
  136. 1300 r=c-2:t=0
  137. 1310 x=o*r+a:gosub1070:y=ev:r=r-2:t=t+y:ifr=0then1340
  138. 1320 goto1310
  139. 1330 l=l+4*t:goto1300
  140. 1340 i=p*(l+2*t):q$="":print"[147]":return
  141. 1350 :
  142. 1360 rem end of simpson
  143. 1370 :
  144. 1380 :
  145. 1390 rem start of roots
  146. 1400 :
  147. 1410 print"         [210][207][207][212][211][160][194][217][160][194][201][211][197][195][212][201][207][206]"
  148. 1420 print"[212]his part of the [205]athematics [212]oolbox"
  149. 1430 print"[208]rogram uses the bisection method to"
  150. 1440 print"solve for the unknown in any single-"
  151. 1450 print"variable function such that f(x)=0."
  152. 1460 gosub 6000
  153. 1470 zz=1480:print"[147]":goto2480
  154. 1480 print"[147]"
  155. 1490 input"[147][215]hat is the lower bound of the interval to be searched"