home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / sys / atari / 8bit / 4199 < prev    next >
Encoding:
Internet Message Format  |  1992-08-13  |  5.7 KB

  1. Path: sparky!uunet!dtix!darwin.sura.net!mips!sdd.hp.com!hpscdc!hplextra!hpl-opus!hpnmdla!frankh
  2. From: frankh@hpnmdla.sr.hp.com (Frank Hamlin)
  3. Newsgroups: comp.sys.atari.8bit
  4. Subject: Re: Math Progs for the 8-bit
  5. Message-ID: <800016@hpnmdla.sr.hp.com>
  6. Date: 13 Aug 92 15:21:24 GMT
  7. References: <9208120111.AA20305@nettlerash.berkeley.edu>
  8. Organization: Hewlett-Packard, Santa Rosa, CA
  9. Lines: 162
  10.  
  11. > In comp.sys.atari.8bit, bp112@cleveland.Freenet.Edu (Steven C. Lin) writes:
  12. > >In a previous article, frankh@hpnmdla.sr.hp.com (Frank Hamlin) says:
  13. > >Or you could let BASIC do it for you, and the program becomes trivial.
  14. > >About 5 years ago my son was learning to graph, so I wrote such a program
  15. > >that finds mins, max, differentiates, finds mins & max of the
  16. > >differential, and plots the equation.  I haven't done anything with the
  17. > >Atari in over 3 years, so I do not know if I still have this.  If I find
  18. > >it, I will post the program.
  19. > >
  20. > I too have written programs that find the DEFINITE integral and/or NUMERIC
  21. > derivative of a function at a certain point.  But, from what I have seen
  22. > of Derive/Mathematica type programs (which the original post refered to),
  23. > they are able to find the INDEFINITE integral and/or the indefinite (is
  24. > that the right term?) derivitive, that is, the function that expresses the
  25. > int. or der., not just the answer... But if all you want is the numeric
  26. > answers, or a function grapher, yes, Atari BASIC will do the job with not
  27. > very much problem at all!
  28. > Steve Lin
  29. > bp112@cleveland.freenet.edu
  30. > -- 
  31.  
  32. This program will not give you a function that expresses the int. or
  33. der.,  but it plots the function, gives the roots, and gives the mins
  34. and maxs.  DEFINITE integral and/or NUMERIC derivative of a function at
  35. a certain point would be easy to add.  I just put this together so my
  36. son would have fun with plotting.  The program was written in TURBO
  37. BASIC.  I stole the plotting section from another program.  The equation
  38. being solved in in line 30
  39.  
  40.  
  41.  
  42. 10 GO# BEGIN
  43. 20 PROC F_X:REM FUNCTION in 21-49
  44. 30   FUNCTION=4*X^5-13*X^4+18*X^2-3
  45. 50 ENDPROC 
  46. 60 GRAPHICS 0
  47. 70 REM *** GRAPHING PROGRAM ***
  48. 80 REM *** INITIAL CONSTANTS ***
  49. 90 X1=-20:X2=20:Y1=-10:Y2=10:XIN=1:YIN=1
  50. 100 LIST 20,50
  51. 110 PRINT "WINDOW (X1,X2,Y1,Y2)";
  52. 120 TRAP 150
  53. 130 INPUT X1,X2,Y1,Y2
  54. 140 IF X2-X1=0 OR Y2-Y1=0 THEN 110
  55. 150 PRINT CHR$(125);"INTERVAL (X AXIS,YAXIS)";
  56. 160 TRAP 190
  57. 170 INPUT XIN,YIN
  58. 180 IF XIN<=0 OR YIN<=0 THEN 150
  59. 190 GRAPHICS 8:SETCOLOR 2,8,4:SETCOLOR 1,0,14:COLOR 1:POKE 752,1
  60. 200 REM *** DRAW AXES ***
  61. 210 XTOP=Y2/(Y2-Y1)*159
  62. 220 IF Y2<0 THEN XTOP=0
  63. 230 IF Y1>0 THEN XTOP=159
  64. 240 YSIDE=ABS(X1)/(X2-X1)*319
  65. 250 IF X1>0 THEN YSIDE=0
  66. 260 IF X2<0 THEN YSIDE=319
  67. 270 PLOT 0,XTOP:DRAWTO 319,XTOP:PLOT YSIDE,0:DRAWTO YSIDE,159
  68. 280 REM *** DRAW TIC MARKS ***
  69. 290 TIC1=XTOP-1*(XTOP>0):TIC2=XTOP+1*(XTOP<159)
  70. 300 FX=INT(X2/XIN)*XIN
  71. 310 XV=(FX-X1)/(X2-X1)*319:IF XV<0 THEN 340
  72. 320 PLOT XV,TIC1:DRAWTO XV,TIC2
  73. 330 FX=FX-XIN:GOTO 310
  74. 340 TIC1=YSIDE-1*(YSIDE>0):TIC2=YSIDE+1*(YSIDE<319)
  75. 350 FY=INT(Y2/YIN)*YIN
  76. 360 YV=(Y2-FY)/(Y2-Y1)*159:IF YV>159 THEN 400
  77. 370 PLOT TIC1,YV:DRAWTO TIC2,YV
  78. 380 FY=FY-YIN:GOTO 360
  79. 390 REM *** GRAPH FUNCTION ***
  80. 400 PRINT CHR$(125):LIST 20,40
  81. 410 TRAP 510
  82. 420 C=0:FLAG=1
  83. 430 FOR X=X1 TO X2 STEP (X2-X1)/319
  84. 440   EXEC F_X
  85. 450   IF FLAG THEN PLOT C,(Y2-FUNCTION)/(Y2-Y1)*159:FLAG=0:GOTO 470
  86. 460   DRAWTO C,(Y2-FUNCTION)/(Y2-Y1)*159
  87. 470   C=C+1
  88. 480 NEXT X
  89. 490 POKE 752,0:GOTO 110
  90. 500 REM *** ERROR HANDLER ***
  91. 510 TRAP 510:FLAG=1
  92. 520 GOTO 470
  93. 530 PROC F_X2
  94. 540   X=X-CHANGE:EXEC F_X:YTEMP=FUNCTION
  95. 550   X=X+2*CHANGE:EXEC F_X
  96. 560   FUNCTION=(FUNCTION-YTEMP)
  97. 570 ENDPROC 
  98. 580 # BEGIN
  99. 590 GRAPHICS 0
  100. 600 ? "CLS":LIST 20,50
  101. 610 CHANGE=1E-06
  102. 620 ? :? "Input a (1) for F(x)=0 you give (x)"
  103. 630 ? "Input a (2) for F(x)=0 you give range"
  104. 640 ? "Input a (3) for F'(x)=0 "
  105. 650 ? "Input a (4) to plot the function"
  106. 660 GET TEMP:TRAP 600:TEMP=VAL(CHR$(TEMP))
  107. 670 TRAP 40000:IF TEMP<1 OR TEMP>4 THEN 600
  108. 680 ON TEMP EXEC FUNCT_0,RANGE1,FUNCT_1
  109. 690 IF TEMP=4 THEN 60
  110. 700 END 
  111. 710 PROC FUNCT_0
  112. 720   INPUT "What is your starting X";X1:X0=999999
  113. 730   ? "CLS":? :? :LIST 20,50
  114. 740   EXEC FUNCT
  115. 750   ? :? " FUNCTION=0 @ X = ";X0
  116. 760 ENDPROC 
  117. 770 PROC FUNCT_1
  118. 780   ? "CLS":? :? :LIST 20,50
  119. 790   INPUT "Input the range of (X) to search.     Xmin, Xmax";XMIN,XMAX
  120. 791   X=XMIN:EXEC F_X2:Y2=FUNCTION
  121. 792   X=XMAX:EXEC F_X2
  122. 793   IF Y2>0 AND FUNCTION>0 THEN GO# BAD_INPUT
  123. 794   IF Y2<0 AND FUNCTION<0 THEN GO# BAD_INPUT
  124. 795   IF XMAX<=XMIN THEN GO# BAD_INPUT
  125. 796   YMAX=FUNCTION
  126. 797   IF YMAX=0 THEN X=XMAX:FUNCTION=0:GOTO 810
  127. 800   EXEC FUNCT2
  128. 810   ? :? " SLOPE= 0  @ X = ";X
  129. 820 ENDPROC 
  130. 821 # BAD_INPUT
  131. 822 ? "Xmax is not greater than Xmin, or the slope is in the same direction at     both points"
  132. 823 PAUSE 200:GOTO 780
  133. 830 PROC FUNCT
  134. 840   REPEAT 
  135. 850     X0=X1
  136. 860     X=X1:EXEC F_X:Y=FUNCTION
  137. 870     X=X1+CHANGE:X2=X:EXEC F_X:Y2=FUNCTION
  138. 880     X=X1-CHANGE:X3=X:EXEC F_X:Y3=FUNCTION
  139. 890     X1=X1-(Y/((Y2-Y3)/(X2-X3)))
  140. 900   UNTIL ABS(X1-X0)<CHANGE
  141. 910 ENDPROC 
  142. 920 PROC NONE
  143. 930   ? "NOT YET IMPLEMENTED"
  144. 940 ENDPROC 
  145. 950 PROC RANGE1
  146. 960   ? "CLS":? :LIST 20,30
  147. 970   INPUT "Input the range to search for roots     Xmin, Xmax";XMIN,XMAX
  148. 980   XCHANGE=(XMAX-XMIN)/100
  149. 990   XTEMP=XMIN
  150. 1000   WHILE XTEMP<=XMAX
  151. 1010     XMIN=XTEMP:XTEMP=XTEMP+XCHANGE
  152. 1020     X=XMIN:EXEC F_X:Y=FUNCTION
  153. 1030     X=XTEMP:EXEC F_X
  154. 1040     IF Y>=0 AND FUNCTION>=0 THEN 1080
  155. 1050     IF Y<=0 AND FUNCTION<=0 THEN 1080
  156. 1060     X1=(XMIN+XTEMP)/2:EXEC FUNCT
  157. 1070     ? :? " FUNCTION=0 @ X = ";X
  158. 1080   WEND 
  159. 1090 ENDPROC 
  160. 1100 PROC FUNCT2
  161. 1110   CHANGE2=(XMAX-XMIN)/2
  162. 1120   WHILE CHANGE2>1E-08
  163. 1130     X=XMIN+CHANGE2:EXEC F_X2:CHANGE2=CHANGE2/2
  164. 1140     IF FUNCTION<0 AND YMAX>0 THEN XMIN=XMIN+2*CHANGE2
  165. 1150     IF FUNCTION>0 AND YMAX<0 THEN XMIN=XMIN+2*CHANGE2
  166. 1160     IF FUNCTION=0 THEN CHANGE2=0
  167. 1170   WEND 
  168. 1180 ENDPROC 
  169.