' <<< PLOT.BAS >>> ' This program was written by J. V. Brancik of Univ. N. S. W. with intention to provide students (or anyone) ' with a simple program to plot experimantal data and do some basic manipulation (like linear regression analysis). ' The whole program consists of three sub-programs which are chained (called) together. The sub-programs are: ' PLOT.bas, PLOT01.bas, and PLOT02.bas. The source code is for Microsoft Basic Compiler BASCOM, version 5.3. ' The spline functions and regression analysis subroutines are based on various Hewlett-Packard publications. ' PLOT.bas: ' -------- ' Program to enter experimental data and, when required, calculate spline functions and linear regression coefficients, ' and then to chain complimentary programs PLOT01.BAS and PLOT02.BAS, which will plot the data and required functions ' on the graphics screen or on the HP or FACIT plotter. The data file created by this sub-program are as follows: ' PLOT.$$$ - ' is a data file which contains data entered (experimental poins), and which is random access, rec. length 4 bytes ' (real numbers), max. 40 x and y data pairs. ' PLOT.FLG - ' is a data file which contains information shared between the chaining programs (flags). It is random access, rec. ' length 2 byte there are 12 records (integers). ' PLOT02.DAT - ' contains function points for the spline functions, rec. length is 4 bytes (real numbers), there are four sections; ' each section has 400 recs., first conatins x values for complimentary second and third and fourth sections, which ' contain y values of f(x), f'(x), and f''(x). ' PLOT03.DAT - ' is similar to the preceeding one, but contains nine sections; first contains x values common to all other sections, ' second to nineth contain f(x) values of corresponding eight regression models. File PLOT03.DOC is a sequential file ' containing data on regression coefficients and regression models. ' Dimensions DIM A(80),D(8,5),G%(12),S(1),S%(1),X(240),Y(8,400):' exptl data pairs, regression coeffs, flags, min/max, from/to, ' x-values are stored in a(2*i-1), y-values are stored in a(2*i), where i is the x,y-pair number ' regresion coefficients are in D(i,j), where ' 1<=i<=8 is the model number, 1<=j<=5 is the coefficient's number, i.e. j=1 for coeff. A, =2 for coeff. B, =3 for ' coeff. C, =4 for coeff. of determination, =5 for the standard error of the estimate ' g%(i) are the flags ' s(i) are the x-min and x-max for the regression functions ' s%(i) are the first and the last data pair to be read ' x(i) are temporay variable array for data entry and calculation of coefficients ' y(i,j) are points for regression or spline functions, where i is the model number and 1<=j<=400 are function values ' clear temporary data file (set all entries to 0, file is random access, data stored as REAL, i. e. 4 byte storage) OPEN"R",#1,"PLOT.$$$",4:FIELD#1,4 AS R$:J=0:Q$=MKS$(J):FOR I%=1 TO 640:LSET R$=Q$:PUT#1,I%:NEXT:CLOSE ' explanation of the records: A(2*i-1) is X value, A(2*i) is complimentary Y value for 1<=i<=40, where i is counter ' of X,Y data pairs. The file contents is as follows ' record no. | content | record no. | content | record no. | content ' 1 to 80 - set no.1 x,y-pairs 81 to 160 - set no.2 x,y-pairs 161 to 240 - set no.3 x,y-pairs ' 241 to 320 - set no.4 x,y-pairs 321 to 400 - set no.5 x,y-pairs 401 to 480 - set no.6 x,y-pairs ' 481 to 560 - set no.5 x,y-pairs 561 to 640 - set no6. x,y-pairs ' Note that the starting position of a new set is always FIXED (multiples of 80) even when you use less than 40 ' of x,y-pairs for each data set. GOTO 2350:' to where the Main Section of this program is located ' Subroutine section ' ================== ' Subroutines to handle screen editing functions of the Televideo terminal (change to suit your terminal) ' 1<= M% <=24 is the row number and 1<= N% <=80 is the column number 1000 PRINT CHR$(27)CHR$(42):RETURN:' clear the whole screen 1100 PRINT CHR$(27)CHR$(61)CHR$(M%+31)CHR$(N%+31);:RETURN:' cursor addressing (set cursor position) 1110 GOSUB 1100:PRINT CHR$(27)CHR$(84):GOSUB 1100:RETURN:' clear to the end of line from the current cursor position 1120 GOSUB 1100:PRINT CHR$(27)CHR$(89):GOSUB 1100:RETURN:' clear to the end of screen from the current cursor position ' Subroutine to open file for random access, FL%=rec length, F$=filename 1200 OPEN"R",#1,F$,FL%:FIELD#1,FL% AS R$:RETURN ' Subroutine to record flag values (file PLOT.FLG, random access, data stored as INTEGERs, i. e. 2 bytes storage) 1230 FL%=2:F$="PLOT.FLG":GOSUB 1200:G%(0)=G%(3)+4+(FLG%=1):FOR J%=0 TO G%(3)+4:LSET R$=MKI$(G%(J%)):PUT#1,J%+1:NEXT CLOSE:RETURN:' get filename and rec length, set no of recs to read, write all flag that have been used in routines ' explanation of records: ' g(0) - no. of records to read from this file, ' g(1) - which option to plot: ' 1 = points connected (if required) by a line (8 sets of experimental data allowed) ' 2 = spline functions plot (only one set of experimental data allowed) ' 3 = regression analysis (only one set of experimental data allowed) ' 4 = user's function plot (8 sets of data experimental data and any nnumber of user defined functions points ' (calculated by the user and stored in a file) ' g(2) - where to plot: ' 1 = graphics screen (Microangelo or compatible) ' 2 = graphics plotter (Hewlett-Packard or any plotter using HPGL) ' 3 = just experimental data entry for user defined function plot ' g(3) - number of experimental data sets (max 8) ' g(4) - number of x,y-pairs for set no.1 (max 40) ' g(5) .... g(11) - number of x,y-pairs for set no.2 ... 8 ' Subroutine to record the experimental data into a temporary file PLOT.$$$ (random access, rec length=4, 640 recs) 1250 FL%=4:F$="PLOT.$$$":GOSUB 1200:FOR I%=1 TO 2*G%(3+G%(3)):LSET R$=MKS$(X(I%)):PUT#1,I%+(G%(3)-1)*80:NEXT CLOSE:RETURN:' get filename, set rec length, open file, write after each set of data entry ' Subroutine to display the Main Menu (a bit of cosmetics but nothing spectracular - not enough memory) 1300 GOSUB 1000:M%=1:N%=28:GOSUB 1100:PRINT"<<< Plotting Program >>>":M%=3:N%=36:GOSUB 1100:PRINT"MAIN MENU":M%=5 N%=28:GOSUB 1100:PRINT"Select from the following:":M%=6:GOSUB 1100:PRINT STRING$((26),45):M%=8:N%=5:GOSUB 1100 PRINT"1. Plot experimental points":M%=10:GOSUB 1100:PRINT"2. Plot experimental points and draw a smooth":M%=11 N%=8:GOSUB 1100:PRINT"curve through the points using spline functions":M%=13:N%=5:GOSUB 1100 PRINT"3. Plot experimental points, do linear regression":M%=14:N%=8:GOSUB 1100 PRINT"analysis and draw a regression line or curve":M%=16:N%=5:GOSUB 1100 PRINT"4. Plot user defined function through":M%=17:N%=8:GOSUB 1100:PRINT"experimental points":M%=19:N%=5 GOSUB 1100:PRINT"5. Exit this program" 1310 M%=21:N%=1:GOSUB 1110:INPUT"Type the number of your selection: ",A$:A=VAL(A$):IF A<1 OR A>5 THEN 1310 IF A=5 THEN END ELSE G%(1)=INT(A):M%=5:N%=1:GOSUB 1120:M%=7:N%=5:GOSUB 1100:PRINT"1. Plot on the Graphics Screen" M%=9:GOSUB 1100:PRINT"2. Plot on the plotter" 1320 M%=21:N%=1:GOSUB 1110:INPUT"Type the number of your selection: ",A$:A=VAL(A$):IF A<1 OR A>2 THEN 1320 G%(2)=INT(A):RETURN ' Subroutine to display header for the data entry (a bit of cosmetics, too) '1500 RETURN:' if linker complaines about memory shortage then comment-out the lot below 1500 M%=1:N%=1:GOSUB 1110:PRINT"<";F1$;">":' clear first line, display header, F1$=filename, F2$=process name IF G%(1)=1 THEN A$="Plot of experimental points":N%=INT(40-(LEN(A$))/2):GOSUB 1100:PRINT A$ IF G%(1)=2 THEN A$="Plot spline functions":N%=INT(40-(LEN(A$))/2):GOSUB 1100:PRINT A$ IF G%(1)=3 THEN A$="Plot regression function":N%=INT(40-(LEN(A$))/2):GOSUB 1100:PRINT A$ IF G%(1)=4 THEN A$="Plot user defined function":N%=INT(40-(LEN(A$))/2):GOSUB 1100:PRINT A$ N%=INT(78-LEN(F2$)):GOSUB 1100:PRINT"<";F2$;">":RETURN ' Subroutine to get input (source) of experimental data 1510 F2$="data entry":GOSUB 1500:M%=2:N%=1:GOSUB 1120:' display header, FLG%=0 for data entry and =1 for no data entry FLG%=0:M%=5:N%=28:GOSUB 1100:PRINT"Select from the following:":M%=6:N%=28:GOSUB 1100:PRINT STRING$((26),45) M%=8:N%=8:GOSUB 1100:PRINT"1. Keyboard data entry":M%=9:GOSUB 1100:PRINT"2. Data entry from a data file" IF G%(1)=4 THEN M%=11:GOSUB 1100:PRINT"Press ENTER for no data entry":' option for user defined function plot only 1520 M%=21:N%=1:GOSUB 1110:INPUT"The number of your selection: ",A$:A=VAL(A$):' get the user's response IF A=0 AND G%(1)=4 THEN FLG%=1:G%(2)=3:RETURN:' for no data entry (user function plot) IF A<1 OR A>2 THEN 1520:' get proper answer, DE%=1 for keyboard, =2 for data file DE%=A:IF DE%=1 THEN F1$="PLOT.$$$":GOSUB 1500:' temp data file (to store entered exptl data) G%(3)=G%(3)+1:ON DE% GOSUB 1600,1730:RETURN:' to keyboard or data-file routine ' Subroutine to enter data from the keyboard 1600 M%=2:N%=1:GOSUB 1120:' cls, ask for no. of data pairs, G%(3)=no. of sets, G%(3+i)=no. of data pairs 1610 M%=21:N%=1:GOSUB 1110:PRINT"How many data pairs for plot no.";G%(3);:INPUT": ",A:IF A<1 OR A>40 THEN 1610 G%(G%(3)+3)=INT(A):IF G%(3)>1 THEN 1620 ELSE 1640:' if multiplot the x's could be the same 1620 G%=0:M%=21:N%=1:GOSUB 1110:INPUT"Are the x's from the previous set (Y/N)? ",A$:IF A$="Y" THEN G%=1:GOTO 1640 IF A$<>"Y" THEN IF A$<>"N" THEN 1620:' g%=+1 for the same x's, -1 for the same y's, 0 for new entry 1630 GOSUB 1110:INPUT"Are the y's from the previous set (Y/N)? ",A$:IF A$="Y" THEN G%=-1:GOTO 1640 IF A$<>"Y" THEN IF A$<>"N" THEN 1630 1640 FOR J%=1 TO G%(G%(3)+3):X%=2*J%-1:Y%=2*J%:IF G%=0 THEN 1650 ELSE 1660:' set the x and y entries counters 1650 PRINT"X(";J%;:INPUT") =",X(X%):PRINT"Y(";J%;:INPUT") =",X(Y%):GOTO 1700:' when both x and y entered 1660 IF G%=1 THEN 1670 ELSE 1680:' when x's would be the same, skip the entry but show the previous set x entry 1670 PRINT"X(";J%;") =";X(X%):PRINT"Y(";J%;:INPUT") =",X(Y%):GOTO 1700:' enter only y's 1680 IF G%=-1 THEN 1690 ELSE 1700:' when y's would be the same, skip the entry but show the previous set y entry 1690 PRINT"X(";J%;:INPUT") =",X(X%):PRINT"Y(";J%;") =";X(Y%):' enter only x's 1700 NEXT:FOR J%=1 TO 4:PRINT:NEXT:' make some room on the screen 1710 F1$="PLOT.$$$":F2$="keyboard entry":GOSUB 1500:' print header again 1720 M%=21:N%=1:GOSUB 1110:INPUT"Review and correct the data (Y/N)? ",A$:IF A$<>"Y" THEN IF A$<>"N" THEN 1720 IF A$="Y" THEN GOSUB 1780:GOTO 1710:' back to review and correct the data GOSUB 1250:RETURN:' write data to the temporary file ' Subroutine to enter data from user's data file 1730 M%=2:N%=1:GOSUB 1120:' clear screen, ask for the name of the data file 1740 M%=21:N%=1:GOSUB 1110:LINE INPUT"The name of the INPUT data file: ",A$:IF A$="" THEN 1740:' is there an entry? 1750 M%=21:N%=1:GOSUB 1120:INPUT"Start with the pair no.: ",S%(0):M%=22:N%=1:GOSUB 1110 INPUT"Finish with the pair no.: ",S%(1):S%=S%(1)-S%(0):G%(G%(3)+3)=S%+1:c%=1:IF S%<1 OR S%>40 THEN 1750 F$=A$:FL%=4:GOSUB 1200:FOR J%=S%(0) TO S%(1):GET#1,(2*j%-1):q$=r$:X(2*c%-1)=CVS(q$):' read rec for x, GET#1,(2*j%):q$=r$:X(2*c%)=CVS(q$):c%=C%+1:NEXT:CLOSE:' increase counter, read rec. for y, go for next pair or close 1760 F1$=F$:F2$="data from file":GOSUB 1500:' display header 1770 M%=21:N%=1:GOSUB 1120:INPUT"Review and correct the data (Y/N)? ",A$:IF A$<>"Y" THEN IF A$<>"N"THEN 1770 IF A$="Y" THEN GOSUB 1780:FOR J%=1 TO 4:PRINT:NEXT:GOTO 1760:' view the data before recording into DF GOSUB 1250:RETURN:' record the data into the program DF ' Subroutine to correct the data entered 1780 F1$="PLOT.$$$":F2$="data review":GOSUB 1500:M%=2:N%=1:GOSUB 1120:PRINT"Type the correct data or press RETURN!" FOR J%=1 TO G%(G%(3)+3):X%=2*J%-1:Y%=2*J%:PRINT"X(";G%(3);",";J%;") =";X(X%);:INPUT A$ IF A$="" THEN 1790 ELSE X(X%)=VAL(A$):' change x if wrong 1790 PRINT"Y(";G%(3);",";J%;") =";X(Y%);:INPUT A$ IF A$="" THEN 1800 ELSE X(Y%)=VAL(A$):' change y if wrong 1800 NEXT:FOR J%=1 TO 4:PRINT:NEXT:RETURN ' Subroutine to calculate spline function coefficients ' Deatiled explanation of this sub is in following references: ' (usually found in undergraduate collections of Univ. libraries) ' A. Ralston and H. S. Wilf: Mathematical Methods for Digital Computers, John Wiley & Sons eds., N. Y. (1967) ' T. N. E. Greville; Theory and Applications of Spline Functions, Acad. Press publ., N. Y. (1969) ' NOTE should be taken here that the first and the second derivatives refer to the spline function; there are other ' methods how to draw a smooth line through a set of data which may differ from the spline curve. Thus, for the ' data points fitting the equation y=x^2, when using spline function the first derivative is not necessarily ' y'=2x and the second one is not necessarily y''=2. The user can compare the curves drawn by the regression ' and spline functions. 2100 X(0)=1E-3:A%=G%(4):X(4*A%+1)=0:X(5*A%)=0:B%=0:C=4*(2-SQR(3)):' set tolerance, no. of data pairs, counters 2110 B%=B%+1:Z%=3*A%+B%:X(Z%-A%)=X(2*B%+1)-X(2*B%-1):X(Z%)=(X(2*B%+2)-X(2*B%))/X(Z%-A%):IF B%>1 THEN 2120 ELSE 2110 2120 X(Z%+A%)=2*(X(Z%)-X(Z%-1))/(X(Z%-A%-1)+X(Z%-A%)):X(2*A%+Z%)=3*(X(A%+Z%))/2:IF (A%-1)>B% THEN 2110 2130 X=0:B%=2:' reset the counters (of points) 2140 Z%=4*A%+B%:Y=X(Z%+1):Y=C*(((Y-X(Z%-1))/(1+X(Z%-2*A%)/X(Z%-2*A%-1))-Y)/2-X(Z%)+X(Z%+A%)):IF ABS(Y)>X THEN X=ABS(Y) 2150 X(Z%)=X(Z%)+Y:B%=B%+1:IF B%<>A% THEN 2140 ELSE IF X(0)<=X THEN 2130:' count the area for the integral 2160 C=0:B%=1:' reset the counters for the calcn. of coeffs. 2170 Z%=4*A%+B%:Y=X(Z%-2*A%):C=Y*(X(2*B%)+X(2*B%+2))/2+(Y^3)*(X(Z%)+X(Z%+1))/24+C:B%=B%+1:IF A%=B% THEN 2180 ELSE 2170 2180 B%=1:' reset the counter again for other coeffs. 2190 Z%=4*A%+B%:X(Z%-2*A%)=(X(Z%+1)-X(Z%))/X(Z%-2*A%):Z%=Z%-2*A%:B%=B%+1:IF B%=A% THEN 2200 ELSE 2190 2200 B%=1:X=X(1):X(0)=(X(2*A%-1)-X(1))/400:H=C:FOR J%=1 TO 400:GOSUB 2240:B%=1:X=X+X(0):NEXT:RETURN:'for points to plot ' Subroutine to calculate spline functions points for plotting the spline curve ' this sub is called by sub 2100 for each one of 400 points - see line 2200 2240 IF B%>A% THEN 2290 ELSE IF A%<>B% THEN 2260 ELSE 2250 2250 Z=X-X(2*A%-1):IF A%=B% THEN 2290 ELSE IF Z<>0 THEN 2290 ELSE IF Z=0 THEN 2280 2260 Y=X-X(2*B%-1):Z=X-X(2*B%+1):IF Y<0 OR Z>=0 THEN 2270 ELSE 2280 2270 B%=B%+1:GOTO 2240 2280 C=X(4*A%+B%)+Y*X(2*A%+B%):Y(3,J%)=C:C=(X(4*A%+B%)+X(4*A%+B%+1)+C)/6:Y=X(2*B%)+Y*X(3*A%+B%)+C*Y*Z Q=X(3*A%+B%)+(X-X(2*B%-1)+Z)*C+Z*(X-X(2*B%-1))*X(2*A%+B%)/6:Y(2,J%)=Q:Y(1,J%)=Y:Y(0,J%)=X 2290 RETURN ' Subroutine to record all the calculated data; x, f(x), f'(x), f''(x), PLOT02.DAT, direct access, REAL numbers 2300 F$="PLOT02.DAT":FL%=4:GOSUB 1200:FOR I%=1 TO 400:LSET R$=MKS$(Y(0,I%)):PUT#1,I%:NEXT:L%=401:' x's are common FOR I%=1 TO 3:FOR K%=1 TO 400:LSET R$=MKS$(Y(I%,K%)):PUT#1,L%:L%=L%+1:NEXT:NEXT:close:RETURN:' rec. set by set ' Subroutine to read data from the experimental data file (temporary file) 2310 F$="PLOT.$$$":FL%=4:GOSUB 1200:C%=0:FOR I%=1 TO 2*G%(4):GET#1,I%:X(I%)=CVS(R$):IF X(I%)<=1E-37 THEN C%=1 NEXT:CLOSE:RETURN:' read the data, check for negative numbers or zeros ' Subroutine to calculate all sums for all regression functions (takes a while for 40 x,y-pairs) ' This sub is based upon the following reference: ' N. R. Draper and H. Smith: Applied Regression Analysis, John Wiley & Sons publ., N.Y., 1st ed. (1966), 2nd ed. (1981) ' NOTE - any other book on the regression analysis would suit as well 2320 A=G%(4):FOR I%=1 TO G%(4):X%=2*I%-1:Y%=2*I%:A(14)=A(14)+X(X%)*X(Y%):A(15)=A(15)+X(Y%)/X(X%) A(16)=A(16)+1/(X(X%)*X(Y%)):A(17)=A(17)+X(Y%)*SQR(X(X%)):A(18)=A(18)+X(X%)*LOG(X(Y%)) A(19)=A(19)+LOG(X(X%))*LOG(X(Y%)):A(20)=A(20)+X(Y%)*LOG(X(X%)):A(21)=A(21)+X(X%):A(22)=A(22)+1/X(X%) A(23)=A(23)+SQR(X(X%)):A(24)=A(24)+LOG(X(X%)):A(25)=A(25)+X(X%)^2:A(26)=A(26)+1/(X(X%)^2) A(27)=A(27)+(LOG(X(X%)))^2:A(28)=A(28)+X(Y%):A(29)=A(29)+1/X(Y%):A(30)=A(30)+LOG(X(Y%)):A(31)=A(31)+1/(X(Y%)^2) A(32)=A(32)+X(Y%)^2:A(33)=A(33)+X(X%)^3:A(34)=A(34)+(LOG(X(Y%)))^2:A(35)=A(35)+X(X%)^4:A(36)=A(36)+X(Y%)*X(X%)^2 NEXT:FOR I%=1 TO 7:A(10)=A(13+I%):B=21-(I%=2)-(I%=3)-2*(I%=4)-3*(I%=6)-3*(I%=7):A(11)=A(B) B=25-(I%=2)-(I%=3)-2*(I%=6)-2*(I%=7)+4*(I%=4):A(12)=A(B):B=28-(I%=3)-2*(I%=5)-2*(I%=6):A(13)=A(B) B=32+(I%=3)-2*(I%=5)-2*(I%=6):A(7)=A(B):B=A*A(10)-A(11)*A(13):D(I%,2)=B/(A*A(12)-A(11)^2) D(I%,1)=(A(13)-D(I%,2)*A(11))/A:D(I%,5)=SQR(ABS((A(12)-D(I%,1)*A(7)-D(I%,2)*A(10))/A)) D(I%,4)=(D(I%,1)*A(13)+D(I%,2)*A(10)-(A(13)^2)/A)/(A(7)-(A(13)^2)/A):IF I%=5 OR I%=6 THEN D(I%,1)=EXP(D(I%,1)) NEXT:A(37)=A*A(25)-A(21)^2:A(38)=A*A(36)-A(25)*A(28):A(39)=A*A(33)-A(21)*A(25):A(40)=A*A(14)-A(21)*A(28) A(41)=A*A(35)-A(25)^2:A(42)=A(37)*A(38)-A(39)*A(40):D(8,3)=A(42)/(A(37)*A(41)-A(39)^2) D(8,2)=(A(40)-D(8,3)*A(39))/A(37):D(8,1)=(A(28)-D(8,3)*A(25)-D(8,2)*A(21))/A D(8,4)=(D(8,1)*A(28)+D(8,2)*A(14)+D(8,3)*A(36)-A(28)^2/A)/(A(32)-A(28)^2/A):' d(i,1)=A, d(i,2)=B, d(i,3)=C D(8,5)=SQR(ABS((A(32)-D(8,1)*A(28)-D(8,2)*A(14)-D(8,3)*A(36))/(A-3))):' d(i,4)=dtmn coeff, d(i,5)=std err RETURN ' Subroutine to calculate regression function points to be plotted (using coeffs already calculated) 2330 X(0)=(S(1)-S(0))/400:X=S(0):FOR I%=1 TO 400:X=X+X(0):Y(0,I%)=X:Y(1,I%)=D(1,1)+D(1,2)*X:Y(5,I%)=D(5,1)*EXP(D(5,2)*X) IF X>1E-37 THEN Y(2,I%)=D(2,1)+D(2,2)/X:' x must be > 10^-38 IF X>1E-37 THEN Y(3,I%)=1/(D(3,1)+D(3,2)/X):' x (and y) must be > 10^-38 IF X>1E-37 THEN Y(4,I%)=D(4,1)+D(4,2)*SQR(X):' x can be >=0 IF X>1E-37 THEN Y(7,I%)=D(7,1)+D(7,2)*LOG(X):' x must be > 10^-38 Y(6,I%)=D(6,1)*X^D(6,2):Y(8,I%)=D(8,1)+D(8,2)*X+D(8,3)*X*X NEXT:RETURN ' Subroutine to record all functions points and all coefficients ' Two data files are used here: ' PLOT03.DAT - direct access, binary, REAL numbers, 1600 records, 4 bytes each ' PLOT03.DOC - sequential, ascii, variable length, delimited by CR/LF sequence 2340 F$="PLOT03.DAT":FL%=4:GOSUB 1200:L%=1:FOR I%=0 TO 8:FOR J%=1 TO 400:LSET R$=MKS$(Y(I%,J%)):PUT#1,L%:L%=L%+1 NEXT:NEXT:FOR I%=1 TO 8:FOR J%=1 TO 5:LSET R$=MKS$(D(I%,J%)):PUT#1,L%:L%=L%+1:NEXT:NEXT:CLOSE:' write the coeffs OPEN"O",#1,"PLOT03.DOC":' sequential file to record regression coeffs, coeff of detdn, std err of the estimate A$="Y ="+STR$(D(1,1))+" + "+STR$(D(1,2))+" * X; r^2 ="+STR$(D(1,4))+", S ="+STR$(D(1,5)):WRITE#1,A$ A$="Y = "+STR$(D(2,1))+" + "+STR$(D(2,2))+" * (1/X); r^2 ="+STR$(D(2,4))+", S ="+STR$(D(2,5)):WRITE#1,A$ A$="(1/Y) = "+STR$(D(3,1))+" + "+STR$(D(3,2))+" * (1/X); r^2 ="+STR$(D(3,4))+", S ="+STR$(D(3,5)):WRITE#1,A$ A$="Y ="+STR$(D(4,1))+" + "+STR$(D(4,2))+" * X^(1/2); r^2 ="+STR$(D(4,4))+", S ="+STR$(D(4,5)):WRITE#1,A$ A$="Y ="+STR$(D(5,1))+" + EXP("+STR$(D(5,2))+" * X); r^2 ="+STR$(D(5,4))+", S ="+STR$(D(5,5)):WRITE#1,A$ A$="Y ="+STR$(D(6,1))+" * X^("+STR$(D(6,2))+"); r^2 ="+STR$(D(6,4))+", S ="+STR$(D(6,5)):WRITE#1,A$ A$="Y ="+STR$(D(7,1))+" + "+STR$(D(7,2))+" * LN(X); r^2 ="+STR$(D(7,4))+", S ="+STR$(D(7,5)):WRITE#1,A$ A$="Y ="+STR$(D(8,1))+" + "+STR$(D(8,2))+" * X +"+STR$(D(8,3))+" * X^2; r^2="+STR$(D(8,4))+", S ="+STR$(D(8,5)) WRITE#1,A$:CLOSE:RETURN ' The Main Section of the program ' =============================== 2350 GOSUB 1300:' display the Main menu and get the options 2360 GOSUB 1510:IF G%(1)=1 THEN 2370:' max 8 sets of data for experimental points plot only IF G%(1)=2 OR G%(1)=3 THEN 2380:' spline functions or regression analysis only one set of experimental data IF G%(1)=4 THEN IF G%(2)<3 THEN 2370 ELSE 2380:' if user's function (up to 8 sets of experimental data allowed) 2370 IF G%(3)>7 THEN 2380 ELSE M%=21:N%=1:GOSUB 1120:PRINT"Another set (no.";G%(3)+1;:INPUT") to enter (Y/N)? ",A$ IF A$="Y" THEN 2360:' back for more data IF A$="N" THEN 2380:' to record the data and then exit GOTO 2370:' note that answers should be in CAPs 2380 GOSUB 1250:GOSUB 1230:' data entry finishes here, write flags and exptl data into data files IF G%(1)=1 THEN CHAIN"PLOT01.COM":' plot points IF G%(1)=2 THEN GOSUB 2500:CHAIN"PLOT01.COM":' do spline functions routine IF G%(1)=3 THEN GOSUB 2600:CHAIN"PLOT01.COM":' do family regression routine IF G%(1)=4 THEN CHAIN"PLOT01.COM":' plot user function ' spline routine calls 2500 F2$="calculating":GOSUB 1500:M%=2:N%=1:GOSUB 1120:GOSUB 2310:GOSUB 2100:GOSUB 2300:RETURN ' regression routine calls 2600 GOSUB 1000:FL%=4:F$="PLOT.$$$":F2$="regression models":GOSUB 2310:IF C%=1 THEN 2610 ELSE 2620:' cls, rd exptl data ' data should be larger then 10^-38 or else! 2610 M%=7:N%=1:GOSUB 1100:PRINT"Cannot proceed with calculations because your experimental data contain zero" M%=8:GOSUB 1100:PRINT"or negative number. The program will return to the main menu, where you can" M%=9:GOSUB 1100:PRINT"do corrections.":M%=21:GOSUB 1120:INPUT"Press ENTER to continue!",A$ 2620 M%=1:N%=1:GOSUB 1500:M%=21:N%=1:GOSUB 1120:INPUT"X(MIN) = ",A$:S(0)=VAL(A$):IF S(0)<=1E-37 THEN 2620 M%=22:N%=1:GOSUB 1110:INPUT"X(MAX) = ",A$:S(1)=VAL(A$):IF S(1)-S(0)<=0 THEN 2620 M%=5:N%=1:GOSUB 1120:PRINT"Calculating all the sums ...":GOSUB 2320:M%=5:N%=1:GOSUB 1120 PRINT"Calculating regression coefficients ...":GOSUB 2330:M%=5:N%=1:GOSUB 1120:PRINT"Recording calculated data ..." GOSUB 2340:RETURN:' write data (points and coeffs) END