home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / graphics / basplot.lbr / PLOT04.BZS / PLOT04.BAS
Encoding:
BASIC Source File  |  1991-06-25  |  3.4 KB  |  43 lines

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