rem Arbitrary Function Regression cls print print "Arbitrary Function Regression" print "program will fit data to a general curve supplied in program" print "an example is: y=a(1)+a(2)*x" print "place the equation in the subroutine 'function'" print "you must provide guesses for the coefficients a1...an" print "you must specify a max error (start with something large like .1)" print dim a(5) dim d(5) dim x(50) dim y(50) rem data entry input "desired max error? ";r input "number of coefficients (a1...an)? ";m print for i=1 to m print "estimate of a(";i;")= "; input " ";a1 a(i)=a1 d(i)=a(i)/10 next i print input "number of points to input? ";n for i=1 to n print "x(";i;")= "; input " ";x1 print "y(";i;")= "; input " ";y1 x(i)=x1 y(i)=y1 next i print [fleap] for k=1 to m [eleap] gosub [curve] r1=r8 n7=0 n8=0 d=d(k) a(k)=a(k)+d gosub [curve] r2=r8 if r1>r2 then goto [aleap] end if d=-1*d a(k)=a(k)+d r9=r1 r1=r2 r2=r9 [aleap] n7=n7+1 n8=n8+1 a(k)=a(k)+d gosub [curve] r3=r8 rem these values can be used for troubleshooting rem print rem print "R1 = ";r1 rem print "R2 = ";r2 rem print "R3 = ";r3 rem print rem for l=1 to m rem print "a(";l;" = ";a(l) rem next l rem print if r3>r2 then goto [bleap] end if r1=r2 r2=r3 if r1=r2 and r2=r3 then goto [cleap] end if if n8<10 then goto [aleap] end if d(k)=d(k)*10 goto [eleap] [bleap] a(k)=a(k)-d*(1/(1+(r1-r2)/(r3-r2))+.5) d(k)=d(k)*n7/5 next k if r8