1 3REM C U R F I T
  2 4 REM MODIFIED FEB 6,1975
  3 5 PRINT
  4 6 PRINT "C U R F I T"
  5 7 PRINT
  6 12 PRINT "DO YOU WANT INSTURCTIONS?  (YES OR NO)"
  7 13 INPUT Q1$
  8 14 IF Q1$ = "YES" THEN 20
  9 15 IF Q1$ = "yes" THEN 20
 10 16 IF Q1$ = "no" THEN 700
 11 17 IF Q1$ = "NO" THEN 700
 12 18 PRINT "ANSWER EITHER ""YES"" OR ""NO"""
 13 19 GO TO 12
 14 20 PRINT "LINE NUMBERS 50-699 ARE FREE FOR USE AS DATA STATEMENTS, AS REQUIRED"
 15 22 PRINT "ALL VALUES FOR ONE VARIABLE ARE GIVE IN DATA STATEMENTS, FOLLOWED BY"
 16 24 PRINT "ALL VALUES FOR A SECOND VARIABLE, AND SO ON."
 17 26 PRINT "THE WAY TO ARRANGE INPUT IS TO PUT ALL VALUES OF VARIABLE 1 AT LINES"
 18 28 PRINT "100-199, ALL FOR VARIABLE 2 AT LINES 200-299, ECT."
 19 30 PRINT
 20 31 PRINT " CURFIT ACCEPTS UP TO 200 OBSERVATIONS ON TWO VARIABLES. THE DATA FOR"
 21 32 PRINT " THE DEPENDENT VARIABLE (Y) IS SUPPLIED FIRST, FOLLOWED BY THE"
 22 33 PRINT " DATA FOR THE INDEPENDENT VARIABLE (X)."
 23 34 PRINT
 24 35 STOP
 25 700DATA1E38,1E38
 26 701DATA0,0
 27 702 REM
 28 703PRINT
 29 704READP
 30 705DIMX(200),Y(200),U(200),V(200),A(6),B(6),C(6),S(6),F(6)
 31 706IFP=1E38THEN911
 32 707FORK=1TO6
 33 708LETF(K)=1
 34 709NEXTK
 35 710RESET
 36 711PRINT
 37 712PRINT"PLEASE SPECIFY THE NUMBER OF VALUES (N) GIVEN AS DATA"
 38 713PRINT"FOR THE TWO INPUT VARIABLES, AND THE OUTPUT CODE (D)."
 39 714PRINT"(D=1 IF OUTPUT IS TO BE IN ORDER OF INCREASING VALUES"
 40 715PRINT"OF THE INDEPENDENT VARIABLE, ELSE D=0).  N,D = ";
 41 716INPUTN,D
 42 717PRINT
 43 718FORI=1TON
 44 719READY(I)
 45 720NEXTI
 46 721FORI=1TON
 47 722READX(I)
 48 723NEXTI
 49 724READX,Y
 50 725 IF X < 1E38  THEN  916
 51 726 IF Y < 1E38  THEN  916
 52 727PRINT
 53 728PRINT
 54 730 PRINT " L E A S T   S Q U A R E S   C U R V E   F I T"
 55 731PRINT
 56 732 PRINT"CURVE TYPE","  INDEX  OF","        A","       B"
 57 733PRINT" ","DETERMINATION"
 58 734PRINT
 59 735FORI=1TO6
 60 736FORI1=1TO6
 61 737LETS(I1)=0
 62 738NEXTI1
 63 739GOSUB844
 64 740IF(I-5)*(I-6)=0THEN755
 65 741IF(I-2)*(I-3)=0THEN748
 66 742FORJ=1TON
 67 743LETV(J)=Y(J)
 68 744GOSUB822
 69 745NEXTJ
 70 746IFI=1THEN765
 71 747GOTO776
 72 748FORJ=1TON
 73 749IFY(J)<=0THEN762
 74 750LETV(J)=LOG(Y(J))
 75 751GOSUB822
 76 752NEXTJ
 77 753IFI=3THEN770
 78 754GOTO765
 79 755FORJ=1TON
 80 756IFY(J)=0THEN762
 81 757LETV(J)=1/Y(J)
 82 758GOSUB822
 83 759NEXTJ
 84 760IFI=6THEN776
 85 761GOTO765
 86 762PRINT"CAN'T FIT"
 87 763LETF(I)=0
 88 764GOTO783
 89 765FORJ=1TON
 90 766LETU(J)=X(J)
 91 767GOSUB825
 92 768NEXTJ
 93 769GOTO781
 94 770FORJ=1TON
 95 771IFX(J)<=0THEN762
 96 772LETU(J)=LOG(U(J))
 97 773GOSUB825
 98 774NEXTJ
 99 775GOTO781
100 776FORJ=1TON
101 777IFX(J)=0THEN762
102 778LETU(J)=1/X(J)
103 779GOSUB825
104 780NEXTJ
105 781GOSUB886
106 782PRINTC(I),A(I),B(I)
107 783NEXTI
108 784IFD<>1THEN786
109 785GOSUB829
110 786PRINT
111 787PRINT
112 788PRINT
113 789PRINT"DETAILS FOR";
114 790INPUTI
115 791LETK=I
116 792LETD1=D
117 793PRINT
118 794IFF(I)=1THEN798
119 795GOSUB844
120 796PRINT" COULD NOT BE FIT."
121 797GOTO786
122 798GOSUB862
123 799IF(I-1)*(I-5)*(I-6)<>0THEN810
124 800FORJ=1TON
125 801LETY=A(I)+B(I)*X(J)
126 802IFI=1THEN806
127 803LETY=1/Y
128 804IFI=5THEN806
129 805LETY=X(J)*Y
130 806GOSUB901
131 807NEXTJ
132 808LETD=D1
133 809GOTO786
134 810FORJ=1TON
135 811IFI=2THEN817
136 812IFI=3THEN815
137 813LETY=A(4)+B(4)/X(J)
138 814GOTO818
139 815LETY=A(3)*(X(J)^B(3))
140 816GOTO818
141 817LETY=A(2)*EXP(B(2)*X(J))
142 818GOSUB901
143 819NEXTJ
144 820LETD=D1
145 821GOTO786
146 822LETS(5)=S(5)+V(J)^2
147 823LETS(3)=S(3)+V(J)
148 824RETURN
149 825LETS(1)=S(1)+U(J)
150 826LETS(2)=S(2)+U(J)^2
151 827LETS(4)=S(4)+U(J)*V(J)
152 828RETURN
153 829FORI=1TON-1
154 830LETM=I
155 831FORJ=I+1TON
156 832IFX(M)<=X(J)THEN834
157 833LETM=J
158 834NEXTJ
159 835IFM=ITHEN842
160 836LETP=X(M)
161 837LETQ=Y(M)
162 838LETX(M)=X(I)
163 839LETY(M)=Y(I)
164 840LETX(I)=P
165 841LETY(I)=Q
166 842NEXTI
167 843RETURN
168 844LETK=I
169 845IFK=1THEN860
170 846IFK=2THEN858
171 847IFK=3THEN856
172 848IFK=4THEN854
173 849IFK=5THEN852
174 850PRINT"6. Y=X/(A+B*X) ";
175 851RETURN
176 852PRINT"5. Y=1/(A+B*X) ";
177 853RETURN
178 854PRINT"4. Y=A+(B/X)",
179 855RETURN
180 856PRINT"3. Y=A*(X^B)",
181 857RETURN
182 858PRINT"2. Y=A*EXP(B*X)";
183 859RETURN
184 860PRINT"1. Y=A+(B*X)",
185 861RETURN
186 862PRINT"   ";
187 863GOSUB845
188 864PRINT" IS A";
189 865IFK=1THEN870
190 866IFK=2THEN872
191 867IFK=3THEN874
192 868PRINT" HYPERBOLIC";
193 869GOTO875
194 870PRINT" LINEAR";
195 871GOTO875
196 872PRINT"N EXPONENTIAL";
197 873GOTO875
198 874PRINT" POWER";
199 875PRINT" FUNCTION.  THE RESULTS"
200 876IFK=1THEN878
201 877PRINT"      OF A LEAST-SQUARES FIT OF ITS LINEAR TRANSFORM"
202 878IFD<>1THEN880
203 879PRINT"      (SORTED IN ORDER OF ASCENDING VALUES OF X)"
204 880PRINT"      ARE AS FOLLOWS:"
205 881PRINT
206 882 PRINT "       X-ACTUAL       Y-ACTUAL    Y-CALC      PCT DIFFER"
207 883PRINT
208 884RETURN
209 885PRINT
210 886LETB=(N*S(4)-S(1)*S(3))/(N*S(2)-(S(1)^2))
211 887LETA=(S(3)-B*S(1))/N
212 888LETS1=S(5)-(S(3)^2)/N
213 889LETS2=(B^2)*(S(2)-(S(1)^2)/N)
214 890LETC(I)=S2/S1
215 891IF(I-1)*(I-4)*(I-5)=0THEN898
216 892IF(I-2)*(I-3)=0THEN896
217 893LETA(6)=B
218 894LETB(6)=A
219 895RETURN
220 896LETA(I)=EXP(A)
221 897GOTO899
222 898LETA(I)=A
223 899LETB(I)=B
224 900RETURN
225 901PRINTX(J),Y(J),Y,
226 902LETD=Y(J)-Y
227 903LETD=.1*SGN(D)*INT(1000*ABS(D/Y))
228 904IFD<0THEN909
229 905IFD>0THEN908
230 906PRINT"      0"
231 907RETURN
232 908PRINT"       ";
233 909PRINTD
234 910RETURN
235 911 PRINT
236 912 PRINT " DATA STATEMENTS ARE REQUIRED, SEE INSTRUCTIONS."
237 914 PRINT
238 915 STOP
239 916 PRINT
240 917 PRINT"CHECK INPUT"
241 9999 END