home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!dtix!darwin.sura.net!mips!sdd.hp.com!hpscdc!hplextra!hpl-opus!hpnmdla!frankh
- From: frankh@hpnmdla.sr.hp.com (Frank Hamlin)
- Newsgroups: comp.sys.atari.8bit
- Subject: Re: Math Progs for the 8-bit
- Message-ID: <800016@hpnmdla.sr.hp.com>
- Date: 13 Aug 92 15:21:24 GMT
- References: <9208120111.AA20305@nettlerash.berkeley.edu>
- Organization: Hewlett-Packard, Santa Rosa, CA
- Lines: 162
-
- > In comp.sys.atari.8bit, bp112@cleveland.Freenet.Edu (Steven C. Lin) writes:
- >
- >
- > >In a previous article, frankh@hpnmdla.sr.hp.com (Frank Hamlin) says:
- >
- > >Or you could let BASIC do it for you, and the program becomes trivial.
- > >About 5 years ago my son was learning to graph, so I wrote such a program
- > >that finds mins, max, differentiates, finds mins & max of the
- > >differential, and plots the equation. I haven't done anything with the
- > >Atari in over 3 years, so I do not know if I still have this. If I find
- > >it, I will post the program.
- > >
- > I too have written programs that find the DEFINITE integral and/or NUMERIC
- > derivative of a function at a certain point. But, from what I have seen
- > of Derive/Mathematica type programs (which the original post refered to),
- > they are able to find the INDEFINITE integral and/or the indefinite (is
- > that the right term?) derivitive, that is, the function that expresses the
- > int. or der., not just the answer... But if all you want is the numeric
- > answers, or a function grapher, yes, Atari BASIC will do the job with not
- > very much problem at all!
- >
- > Steve Lin
- > bp112@cleveland.freenet.edu
- > --
-
- This program will not give you a function that expresses the int. or
- der., but it plots the function, gives the roots, and gives the mins
- and maxs. DEFINITE integral and/or NUMERIC derivative of a function at
- a certain point would be easy to add. I just put this together so my
- son would have fun with plotting. The program was written in TURBO
- BASIC. I stole the plotting section from another program. The equation
- being solved in in line 30
-
-
-
- 10 GO# BEGIN
- 20 PROC F_X:REM FUNCTION in 21-49
- 30 FUNCTION=4*X^5-13*X^4+18*X^2-3
- 50 ENDPROC
- 60 GRAPHICS 0
- 70 REM *** GRAPHING PROGRAM ***
- 80 REM *** INITIAL CONSTANTS ***
- 90 X1=-20:X2=20:Y1=-10:Y2=10:XIN=1:YIN=1
- 100 LIST 20,50
- 110 PRINT "WINDOW (X1,X2,Y1,Y2)";
- 120 TRAP 150
- 130 INPUT X1,X2,Y1,Y2
- 140 IF X2-X1=0 OR Y2-Y1=0 THEN 110
- 150 PRINT CHR$(125);"INTERVAL (X AXIS,YAXIS)";
- 160 TRAP 190
- 170 INPUT XIN,YIN
- 180 IF XIN<=0 OR YIN<=0 THEN 150
- 190 GRAPHICS 8:SETCOLOR 2,8,4:SETCOLOR 1,0,14:COLOR 1:POKE 752,1
- 200 REM *** DRAW AXES ***
- 210 XTOP=Y2/(Y2-Y1)*159
- 220 IF Y2<0 THEN XTOP=0
- 230 IF Y1>0 THEN XTOP=159
- 240 YSIDE=ABS(X1)/(X2-X1)*319
- 250 IF X1>0 THEN YSIDE=0
- 260 IF X2<0 THEN YSIDE=319
- 270 PLOT 0,XTOP:DRAWTO 319,XTOP:PLOT YSIDE,0:DRAWTO YSIDE,159
- 280 REM *** DRAW TIC MARKS ***
- 290 TIC1=XTOP-1*(XTOP>0):TIC2=XTOP+1*(XTOP<159)
- 300 FX=INT(X2/XIN)*XIN
- 310 XV=(FX-X1)/(X2-X1)*319:IF XV<0 THEN 340
- 320 PLOT XV,TIC1:DRAWTO XV,TIC2
- 330 FX=FX-XIN:GOTO 310
- 340 TIC1=YSIDE-1*(YSIDE>0):TIC2=YSIDE+1*(YSIDE<319)
- 350 FY=INT(Y2/YIN)*YIN
- 360 YV=(Y2-FY)/(Y2-Y1)*159:IF YV>159 THEN 400
- 370 PLOT TIC1,YV:DRAWTO TIC2,YV
- 380 FY=FY-YIN:GOTO 360
- 390 REM *** GRAPH FUNCTION ***
- 400 PRINT CHR$(125):LIST 20,40
- 410 TRAP 510
- 420 C=0:FLAG=1
- 430 FOR X=X1 TO X2 STEP (X2-X1)/319
- 440 EXEC F_X
- 450 IF FLAG THEN PLOT C,(Y2-FUNCTION)/(Y2-Y1)*159:FLAG=0:GOTO 470
- 460 DRAWTO C,(Y2-FUNCTION)/(Y2-Y1)*159
- 470 C=C+1
- 480 NEXT X
- 490 POKE 752,0:GOTO 110
- 500 REM *** ERROR HANDLER ***
- 510 TRAP 510:FLAG=1
- 520 GOTO 470
- 530 PROC F_X2
- 540 X=X-CHANGE:EXEC F_X:YTEMP=FUNCTION
- 550 X=X+2*CHANGE:EXEC F_X
- 560 FUNCTION=(FUNCTION-YTEMP)
- 570 ENDPROC
- 580 # BEGIN
- 590 GRAPHICS 0
- 600 ? "CLS":LIST 20,50
- 610 CHANGE=1E-06
- 620 ? :? "Input a (1) for F(x)=0 you give (x)"
- 630 ? "Input a (2) for F(x)=0 you give range"
- 640 ? "Input a (3) for F'(x)=0 "
- 650 ? "Input a (4) to plot the function"
- 660 GET TEMP:TRAP 600:TEMP=VAL(CHR$(TEMP))
- 670 TRAP 40000:IF TEMP<1 OR TEMP>4 THEN 600
- 680 ON TEMP EXEC FUNCT_0,RANGE1,FUNCT_1
- 690 IF TEMP=4 THEN 60
- 700 END
- 710 PROC FUNCT_0
- 720 INPUT "What is your starting X";X1:X0=999999
- 730 ? "CLS":? :? :LIST 20,50
- 740 EXEC FUNCT
- 750 ? :? " FUNCTION=0 @ X = ";X0
- 760 ENDPROC
- 770 PROC FUNCT_1
- 780 ? "CLS":? :? :LIST 20,50
- 790 INPUT "Input the range of (X) to search. Xmin, Xmax";XMIN,XMAX
- 791 X=XMIN:EXEC F_X2:Y2=FUNCTION
- 792 X=XMAX:EXEC F_X2
- 793 IF Y2>0 AND FUNCTION>0 THEN GO# BAD_INPUT
- 794 IF Y2<0 AND FUNCTION<0 THEN GO# BAD_INPUT
- 795 IF XMAX<=XMIN THEN GO# BAD_INPUT
- 796 YMAX=FUNCTION
- 797 IF YMAX=0 THEN X=XMAX:FUNCTION=0:GOTO 810
- 800 EXEC FUNCT2
- 810 ? :? " SLOPE= 0 @ X = ";X
- 820 ENDPROC
- 821 # BAD_INPUT
- 822 ? "Xmax is not greater than Xmin, or the slope is in the same direction at both points"
- 823 PAUSE 200:GOTO 780
- 830 PROC FUNCT
- 840 REPEAT
- 850 X0=X1
- 860 X=X1:EXEC F_X:Y=FUNCTION
- 870 X=X1+CHANGE:X2=X:EXEC F_X:Y2=FUNCTION
- 880 X=X1-CHANGE:X3=X:EXEC F_X:Y3=FUNCTION
- 890 X1=X1-(Y/((Y2-Y3)/(X2-X3)))
- 900 UNTIL ABS(X1-X0)<CHANGE
- 910 ENDPROC
- 920 PROC NONE
- 930 ? "NOT YET IMPLEMENTED"
- 940 ENDPROC
- 950 PROC RANGE1
- 960 ? "CLS":? :LIST 20,30
- 970 INPUT "Input the range to search for roots Xmin, Xmax";XMIN,XMAX
- 980 XCHANGE=(XMAX-XMIN)/100
- 990 XTEMP=XMIN
- 1000 WHILE XTEMP<=XMAX
- 1010 XMIN=XTEMP:XTEMP=XTEMP+XCHANGE
- 1020 X=XMIN:EXEC F_X:Y=FUNCTION
- 1030 X=XTEMP:EXEC F_X
- 1040 IF Y>=0 AND FUNCTION>=0 THEN 1080
- 1050 IF Y<=0 AND FUNCTION<=0 THEN 1080
- 1060 X1=(XMIN+XTEMP)/2:EXEC FUNCT
- 1070 ? :? " FUNCTION=0 @ X = ";X
- 1080 WEND
- 1090 ENDPROC
- 1100 PROC FUNCT2
- 1110 CHANGE2=(XMAX-XMIN)/2
- 1120 WHILE CHANGE2>1E-08
- 1130 X=XMIN+CHANGE2:EXEC F_X2:CHANGE2=CHANGE2/2
- 1140 IF FUNCTION<0 AND YMAX>0 THEN XMIN=XMIN+2*CHANGE2
- 1150 IF FUNCTION>0 AND YMAX<0 THEN XMIN=XMIN+2*CHANGE2
- 1160 IF FUNCTION=0 THEN CHANGE2=0
- 1170 WEND
- 1180 ENDPROC
-