1000 GOSUB 1300:PRINT" <<< FUNCTION PLOT EXAMPLE >>>":PRINT:PRINT:PRINT 1010 PRINT"Purpose:":PRINT:PRINT" An example of plotting user defined function using the PLOT program.":PRINT:PRINT 1020 PRINT"Method:":PRINT:PRINT" Up to eight different functions or, one function with up to eight diffe-" 1030 PRINT" rent sets of coefficients, can be entered. We have chosen one function," 1040 PRINT" quadratic, and we will allow the user to change coefficients of this" 1050 PRINT" function. The user should examine the source code to get an idea of" 1060 PRINT" the structure of the file PLOT04.DAT.":GOSUB 1340 1070 ' Dimensions 1080 DIM Y(8,400):' that is all we need here for our example 1090 GOSUB 1300:PRINT:PRINT"Example functions is: F(X) = A*X^2 + B*X + C":PRINT 1100 M%=6:N%=1:GOSUB 1330:INPUT" X(MIN) = ",A$:X1=VAL(A$):' get the minimum 1110 M%=7:GOSUB 1320:INPUT" X(MAX) = ",A$:X2=VAL(A$):' get the maximum 1120 DX=(X2-X1)/400:FOR I%=1 TO 8:' calculate the increment 1130 M%=9:GOSUB 1320:PRINT"Set number:";I% 1140 M%=10:N%=1:GOSUB 1320:INPUT" Coefficient A = ",A$:A=VAL(A$):' get the first coeff 1150 M%=11:N%=1:GOSUB 1320:INPUT" Coefficient B = ",A$:B=VAL(A$):' get the second coeff 1160 M%=12:N%=1:GOSUB 1320:INPUT" Coefficient C = ",A$:C=VAL(A$):' get the third coeff 1170 X=X1:J%=1:GOSUB 1390:FOR J%=2 TO 400:X=X+DX:GOSUB 1390:NEXT:NEXT:' calculate points (all 8 sets) 1180 X=X1:I%=0:J%=1:Y(I%,J%)=X:FOR J%=2 TO 400:X=X+DX:Y(I%,J%)=X:NEXT:GOSUB 1360:' and lastly calc all x's, write to file 1190 GOSUB 1300:M%=22:N%=1:INPUT"Review the data? (Y/N) ",A$:IF A$<>"Y" THEN IF A$<>"N" THEN 1190 1200 IF A$="N" THEN END:' we finish here if nothing else required 1210 GOSUB 1300:FOR I%=1 TO 400:' display record by record, E to exit 1220 M%=2:N%=2:GOSUB 1320:PRINT"X(";I%;") = ";Y(0,I%):M%=3:GOSUB 1320:PRINT" F1(X(";I%;")) = ";Y(1,I%) 1230 M%=4:GOSUB 1320:PRINT" F2(X(";I%;")) = ";Y(2,I%):M%=5:GOSUB 1320:PRINT" F3(X(";I%;")) = ";Y(3,I%) 1240 M%=6:GOSUB 1320:PRINT" F4(X(";I%;")) = ";Y(4,I%):M%=7:GOSUB 1320:PRINT" F5(X(";I%;")) = ";Y(5,I%) 1250 M%=8:GOSUB 1320:PRINT" F6(X(";I%;")) = ";Y(6,I%):M%=9:GOSUB 1320:PRINT" F7(X(";I%;")) = ";Y(7,I%) 1260 M%=10:GOSUB 1320:PRINT" F8(X(";I%;")) = ";Y(8,I%) 1270 M%=22:N%=1:GOSUB 1320:INPUT"Press ENTER to continue, E to exit. ",A$:IF A$="E" THEN I%=400 1280 NEXT:GOTO 1190:' end of scanning routine, back to the "Review? (Y/N)" 1290 ' Subroutines to handle screen editing functions of the Televideo terminal (change to suit your terminal) 1300 PRINT CHR$(27)CHR$(42):RETURN:' clear the whole screen 1310 PRINT CHR$(27)CHR$(61)CHR$(M%+31)CHR$(N%+31);:RETURN:' cursor addressing (set cursor position) 1320 GOSUB 1310:PRINT CHR$(27)CHR$(84):GOSUB 1310:RETURN:' clear to the end of line from the current cursor position 1330 GOSUB 1310:PRINT CHR$(27)CHR$(89):GOSUB 1310:RETURN:' clear to the end of screen from the current cursor position 1340 M%=22:N%=1:GOSUB 1330:INPUT"Press ENTER to continue. ",A$:RETURN 1350 ' Subroutine to write all the functions points into the PLOT04.DAT file 1360 OPEN"R",#1,"PLOT04.DAT",4:FIELD#1,4 AS R$:L%=1:FOR I%=0 TO 8:FOR J%=1 TO 400 1370 LSET R$=MKS$(Y(I%,J%)):PUT#1,L%:L%=L%+1:NEXT:NEXT:CLOSE:RETURN 1380 ' Subroutine to calculate points for the user defined function 1390 Y(I%,J%)=A*X*X+B*X+C:RETURN 1400 END