=================================================================== : CURVEFIT: A Public Domain Program by T. S. Cox to fit values : : of X and Y to 25 different equations. Version 1.01 : : The IBM BASIC or BASICA version of this program was : : developed on July 29, 1985 at the same time as : : 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. : : : : : : 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: As written, this program will only handle : : 100 values for X and Y. This is an artifact : : from the CP/M 80 implementation and can be : : greatly expanded for the IBM system =================================================================== =================================================== | CURVE-FITTING BY Thomas S. Cox Version 1.01 | | Your Choices are: Revised July 29, 1985 | | | | 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 | =================================================== 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: Converse of step 6. Writes over any data that might have been present. A data file may be prepared from a Comma Separted Data file that various programs use. Format for data file is: X,Y CR/LF. 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. 12. PRT COEFFICIENTS: Prints equation coefficients (A, B, C, and Coefficent of Determination. Also shows the Coefficient of Determination corrected for degrees of freedom. NOTE: Best fit is based on the value of the Corrected Coefficient of Determination. ======================================================================== | 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 | | | | | ======================================================================== 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 July 29, 1985. D Programs revised on July 29, 1985. G(1-X(I)) R(62)=R(62)+LOG(Y(I))*LOG(1-X(I)) R(63)=R(63)+(LOG(X(I)))/X(I)