=================================================================== : CURVEFIT: A Public Domain Program by T. S. Cox to fit values : : of X and Y to 25 different equations. Version 2.04 : : The IBM BASIC or BASICA version of this program was : : revised on December 06, 1985 at the same time as the : : CP/M MBASIC version. : : : : The author may be contacted at: : : 102 Evergreen Street Easley, SC 29640 : : : : : : Based on equations listed in: : : CURVE FITTING FOR PROGRAMMABLE CALCULATORS : : by: William M. Kolb : : Published by: IMTEC P. O. Box 1402 Bowie MD 20716 : : : : DISCLAIMER: Although effort has been taken to insure accurate : : answers are obtained when using this program, the : : USER assumes all risks when using this program. : : Good practice dictates that sample data should be : : used to determine the validity of calculations : : performed by this program. : : : : Copies of this program are not to be sold for profit but may be : : copied freely. The author welcomes any comments. : : : : REQUIREMENTS: The program file is supplied as an ASCII file. : : : : ACCURACY: Double precison routines are used to insure : : accuracy. No exponentiation routines are used. : : : : COMMENTS: There are no special characters used in this program.: : The program was originally written for a CP/M 80 : : system. : : : : This implementation supports positive, negative and : : zero values for X and Y. 100 points for CP/M : : systems and 255 for IBM systems are allowed. : : : : A printer may be used with this program. Questions : : are located throughout program for this function. : : : : For equations 2 and 9, R squared is not computed. : : No formula was given in the reference source. : : : : Note: Latest revison will automatically DELETE : : null lines that are created at the top of a : : LOTUS 1-2-3 .PRN file. : : | =================================================================== =================================================== | CURVE-FITTING BY Thomas S. Cox Version 2.04 | | (C) 1985 Revised December 06, 1985 | | | | YOUR CHOICES ARE | | 1. ENTER NEW DATA | | 2. ADD DATA POINTS TO PREVIOUS DATA | | 3. DELETE OR CHANGE DATA POINTS | | 4. CALCULATE EQUATION COEFFICIENTS | | 5. PREDICT VALUE OF Y, GIVEN X | | 6. STORE RAW DATA (X AND Y POINTS) TO DISK | | 7. LOAD RAW DATA FROM DISK | | 8. EXIT FROM PROGRAM (TO BASIC) | | 9. LIST X AND Y DATA POINTS ENTERED | | 10. LIST SUMS AND SUMS OF SQUARES | | 11. PRINT (TO SCREEN) EQUATIONS FITTED * | | 12. PRINT EQUATION COEFFICIENTS A, B, C | | ENTER NUMBER (1-12) OF YOUR CHOICE | | For Best Accuracy, Limit X and Y < +/-10000 | =================================================== The above menu is the main program menu and the choices (1-12) are explained below: 1. ENTER NEW DATA: Clears out any previously entered data to prepare for new data entry. 2. ADD DATA POINTS: Add data to previously entered data. Must use choice 4 (Calculate equation coefficients) to update coefficients to reflect newly added data. 3. DELETE OR CHANGE: Self-explanatory. Can change or delete any data points. Again, must use choice 4 to update coefficients. 4. CALCULATE COEFF: Recalculates required sums and sums of squares for equation coefficients. 5. PREDICT Y FROM X: For the 25 equations fitted, allows entry of a range of values for X. From this, values of Y are calcualted. 6. STORE TO DISK: Stores X and Y raw data to disk. Equation coefficients are not stored. Neither are the sums or sums of squares. 7. LOAD DATA: Writes over any date already present. Can use a Comma Separated data file, LOTUS or SuperCalc .PRN files, or files created by this program. Preferred data format is: X(), Y() CR/LF to terminate line. 8. PROGRAM EXIT: EXITS to BASIC. 9. LIST DATA: Lists values of X and Y as entered. 10. LIST SUMS: Lists all sums and sums of squares. 11. EQS FITTED: Shows on the screen the equations fitted and a brief description of the type of the equation. Because of space limitations, shorter version in CP/M program. 12. PRT COEFFICIENTS: Prints equation coefficients (A, B, C, and Coefficent of Determination. Also shows the Coefficient of Determination corrected for degrees of freedom. ======================================================================== | EQUATIONS FITTED USING THIS PROGRAM | |======================================================================= | 1. Y=A+B*X STR. LINE 2. Y=B*X LINE THRU ORG. | | 3. Y=1/(A+B*X) REC. STR LINE 4. Y=A+B*X+C/X LIN AND RECIP. | | 5. Y=A+B/X HYPERBOLA 6. Y=X/(A*X+B) RECIP HYPERBOLA | | 7. Y=A+B/X+C/X*X 2ND ORD HYP 8. Y=A+B*X+C*X*X PARABOLA | | 9. Y=A*X+B*X*X PAR AT ORIGIN 10. Y=A*X^B POWER | | 11. Y=A*B^X MOD. POWER 12. Y=B^(1/X) ROOT | | 13. Y=A*X^(B*X) SUPER GEOMET. 14. Y=A*X^(B/X) MOD GEOMETRIC | | 15. Y=A*e^(B*X) EXPONENTIAL 16. Y=A*e^(B/X) MOD EXPONENTIAL | | 17. Y=A+B*ln(X) LOGARITHMIC 18. Y=1/(A+B*ln(X)) RECIP LOG | | 19. Y=A*B^X*X^C HOERL FUNCTION 20. Y=A*B^(1/X)*X^C MOD HOERL | | 21. Y=A*e^((X-B)/2) NORMAL 22. Y=A*e^((ln(X)-B)^2/C) LOG NORMAL| | 23. Y=A*X^B*(1-X)^C BETA 24. Y=A*(X/B)^C*e^(X/B) GAMMA | | 25. Y=1/(A*(X+B)^2+C) CAUCHY | | | | CURVES 19 & 24 AND CURVES 12 & 16 ARE ESSENTIALLY IDENTICAL | ======================================================================== BRIEF EXPLANATION OF EQUATIONS: 1. Straight Line 2. Straight Line through the Origin 3. Reciprocal of Straight Line 4. Combined Linear and Reciprocal 5. Hyperbola 6. Reciprocal of a Hyperbola 7. Second Order Hyperbola 8. Parabola 9. Parabola Through Origin 10. Power 11. Modified Power 12. Root (Modification of Modified Power) 13. Super Geometric 14. Modified Geometric 15. Exponential 16. Modified Exponential (Similar to Root) 17. Logarithmic 18. Reciprocal of Logarithmic 19. Hoerl's Equation 20. Modified Hoerl's Equation 21. Normal Distribution (Gaussian) 22. Log Normal 23. Beta Distribution (X must be between zero and one) 24. Gamma Distribution 25. Cauchy Distribution EDITORIAL COMMENT: For a full explanation of the equations used in this program and some excellent graphs showing the shapes of curves described by these equations, highly recommend the reference source listed previously: I have no interest in the reference source except that I have found it to be very good. The reference source has programs specifically for the HP-41CV and includes barcode for a program to fit 19 of the 25 equations in this program. Again, the reference is: CURVE FITTING FOR PROGRAMMABLE CALCULATORS by William M. Kolb Published by: IMTEC P. O. Box 1402 Bowie, Maryland 20716 LISTING OF SUMS AND SUMS OF SQUARES (DEFINITION) The array R() is used to hold these values. The contents are: R(16)=R(16)+X(I) R(17)=R(17)+X(I)*X(I) R(18)=R(18)+Y(I) R(19)=R(19)+Y(I)*Y(I) R(20)=R(20)+X(I)*Y(I) R(21)=I R(22)=R(22)+(1/X(I)) R(23)=R(23)+(1/(X(I)*X(I))) R(24)=R(24)+(1/(Y(I))) R(25)=R(25)+(1/(Y(I)*Y(I))) R(26)=R(26)+(1/(Y(I)*X(I))) R(27)=I R(28)=R(28)+LOG(X(I)) R(29)=R(29)+(LOG(X(I)))^2 R(30)=R(30)+(LOG(Y(I))) R(31)=R(31)+(LOG(Y(I)))^2 R(32)=R(32)+(LOG(X(I)))*(LOG(Y(I))) R(33)=I R(34)=R(34)+(X(I)/Y(I)) R(35)=R(35)+(Y(I)/X(I)) R(36)=R(36)+(X(I)^2)*Y(I) R(37)=R(37)+(X(I)^2)/Y(I) R(38)=R(38)+(Y(I)/X(I)^2) R(39)=R(39)+X(I)*Y(I)^2 R(40)=R(40)+X(I)^3 R(41)=R(41)+1/(X(I)^3) R(42)=R(42)+Y(I)^3 R(43)=R(43)+X(I)^4 R(44)=R(44)+1/(X(I)^4) R(45)=R(45)+LOG(X(I))/X(I) R(46)=R(46)+X(I)*LOG(Y(I)) R(47)=R(47)+LOG(Y(I))/X(I) R(48)=R(48)+X(I)*LOG(X(I)) R(49)=R(49)+(X(I)*LOG(X(I)))^2 R(50)=R(50)+X(I)*LOG(X(I))*LOG(Y(I)) R(51)=R(51)+Y(I)*LOG(X(I)) R(52)=R(52)+LOG(X(I))/Y(I) R(53)=R(53)+((LOG(X(I))/X(I)))^2 R(54)=R(54)+X(I)^2*LOG(Y(I)) R(55)=R(55)+(LOG(X(I)))^3 R(56)=R(56)+(LOG(X(I)))^4 R(57)=R(57)+(LOG(X(I))^2)*LOG(Y(I)) R(58)=R(58)+(LOG(Y(I))*LOG(X(I)))/X(I) R(59)=R(59)+LOG(1-X(I)) R(60)=R(60)+(LOG(1-X(I)))^2 R(61)=R(61)+LOG(X(I))*LOG(1-X(I)) R(62)=R(62)+LOG(Y(I))*LOG(1-X(I)) R(63)=R(63)+(LOG(X(I)))/X(I) REM * END OF SUMMATION LOOP * NOTE: R(1) THROUGH R(15) ARE NOT USED Programs revised on December 06, 1985. Additional Comments (8/22/85) The MBASIC and OBASIC versions for use with CP/M are essentially identical except that the OBASIC version requires that a statement be inserted at about line 2 clearing space for string storage. CLEAR 4000 should be sufficient. Note: Because of formatting differences, particularly in the Print Using and TAB commands between MBASIC and OBASIC, the OBASIC specific version, CURFITOB.BAS was developed. To gain program space, the MBASIC and OBASIC versions have used various shortcuts such as using constants, etc. instead of using the obvious equations. Since space is much more available in the IBM BASIC or GWBASIC version, these shortcuts were not necessary and were not used. BASICA has the built-in ability to calculate double precision transcendental functions if BASICA is entered with the command BASICA/D. To insure accuracy, this is highly recommended. For the MBASIC and OBASIC programs, double precision calculations are done by using a subroutine starting at line 60000. This series of subroutines is based on information in a 1978 Radio Shack publication (LEVEL II DOUBLE PRECISION SUBROUTINE PROGRAM), catalog number 26-1704 dated 1978. For the MBASIC and OBASIC versions, the variable CL$ is used for holding the CLEAR SCREEN code. For many computers, this will be CHR$(26). This is known to work for KAYPRO and ADM-3A. For BASICA the command is CLS. NOTE: Although the sums and sums of squares and the coeficients A, B, and C and the correlation coefficients and corrected correlation coefficients are calculated to double precison accuracy in both the MBASIC and OBASIC versions, the predictions are only calculated to single precison wherever logs or exponentials are concerned. This is due to limited memory space. For the BASICA (IBM) version, assuming that the /D option is used, ALL calculations are double precision. Because of the double precison accuracy used, program execution is relatively slow. Execution speed is about ten times faster if double precison is not used. OBASIC will terminate program execution if there is a math error causing division by zero, overflow, etc. MBASIC and BASICA will print an error message on the screen and continue. Relevant Files on the Distribution Disk include: CURVEFIT.BAS IBM or BASICA implementation in ASCII format If CP/M version, MBASIC implementation CURVE???.XRF Cross Reference listing of variables CURVEFIT ???=CPM or IBM depending on version used CURVEFIT.IBM Not included on the 12/25/85 F.O.G. Submission CURFITOB.BAS Not included on the 12/25/85 F.O.G. Submission CURVEXXY.TXT This document CURVEFIT.EXE Compiled version for IBM. Not on this disk. BASLIST .BAS Basic Program Listing program. Lists in 'Pretty' format. BASICLST.EXE Compiled Version for IBM. Not on this disk. BASLIST .COM Compiled Version for CP/M BASICLST.XRF Cross Reference Listing for BASICLST.BAS. Not included. NOTE: For the CP/M versions, the BASIC listing program names are: BASLIST .BAS The MBASIC implemetation with all options BASLIST .XRF Cross Reference Listing. Not on this disk. BASLIST .COM Compiled Version BASLIST2.BAS Includes top and bottom reference line BASLIST2.COM Compiled Version ===================================================================== LAST MINUTE NOTE: The program file CURVEFIT.IBM has the clearest presentation of formulas used as no shortcuts were taken to gain memory in that version. File might also be called CURVEIBM.BAS ================================================================== Additional Comments 11/25/85 Major revisons include: 1. Ability to read data generated by text editor, SuperCalc or LOTUS print files. 2. Error trapping for improper file names. 3. Ability to display coefficients for A, B, and R^2 with all digits--without having everything show in Scientific notation. NOTE: Best curve fit is based on highest value for Corrected R^2. Compiled programs BASICLST.EXE and CURVEFIT.EXE do not require BASIC or BASICA. The BASICLST program will also be usable for ASCII text files. BASLIST.COM and BASLIST2.COM do not require MBASIC. More Comments 11/30/85 IBM version revised to accomodate 255 data points. Previously limited to 100. All versions will automatically delete null entries when reading data file from disk. Particularly useful when using LOTUS 1-2-3 .PRN file. All versions now have option of skipping output of coefficients after they have been calculated using option 4. Coefficients can still be viewed at any time by using option 12. CP/M version shortened somewhat by using a common subroutine for displaying the message "Press to CONTINUE". The OBASIC version has not been updated. It remains the August 1985 version. Will consider updating as far as possible if there are sufficient requests to do so. Since OBASIC is generally considered obsolete, MBASIC version will be the CP/M version that is updated from here on out. I intend for the OBASIC version to remain static in its current version. The only real advantage of the OBASIC version is that it requires less space in memory because OBASIC is a shorter program than MBASIC. When using option 8 of the compiled IBM version, exit is to operating system rather than to BASIC. When using data from a LOTUS 1-2-3 .PRN file, make sure that the file is created using the "AS-DISPLAYED" option. ================================================================= REVISION 2.04 December 6, 1985. Changed lines 20067 and 20068 to have X=0.0001 and Y=0.0001 if zero is input for X or Y. This prevents an Overflow situation and allows the compiled IBM version to operate correctly. ==================== End (As of 12/06/85) ======================== o operate correctly. ==================== End (As of 12/06/85) ======