rem Nth Order Regression cls print print "Nth Order Regression" print "will fit data to a curve" print "y=c+a1*x+a2*x^2...+an*x^n" print dim a(13) dim r(7,8) dim t(8) rem data entry input "degree of equation? ";d input "number of points to input? ";n a(1)=n for i=1 to n print print "x(";i;")= "; input " ";x print "y(";i;")= "; input " ";y for j=2 to (2*d+1) a(j)=a(j)+x^(j-1) next j for k=1 to d+1 r(k,d+2)=t(k)+y*x^(k-1) t(k)=t(k)+y*x^(k-1) next k t(d+2)=t(d+2)+y^2 next i for j=1 to d+1 for k=1 to d+1 r(j,k)=a(j+k-1) next k next j for j=1 to d+1 k=j [cleap] if r(k,j)<>0 then goto [aleap] end if k=k+1 if k<=d+1 then goto cleap end if print print "SORRY, NO UNIQUE SOLUTION!" end [aleap] for i=1 to d+2 s=r(j,i) r(j,i)=r(k,i) r(k,i)=s next i z=1/r(j,j) for i=1 to d+2 r(j,i)=z*r(j,i) next i for k=1 to d+1 if k=j then goto [bleap] end if z= -1*r(k,j) for i=1 to d+2 r(k,i)=r(k,i)+z*r(j,i) next i [bleap] next k next j print print "constant= ";r(1,d+2) for j=1 to d print "degree ";j;" coefficient= ";r(j+1,d+2) next j print p=0 for j=2 to d+1 p=p+r(j,d+2)*(t(j)-a(j)*t(1)/n) next j q=t(d+2)-t(1)^2/n z=q-p i=n-d-1 j=p/q print "coeff of determination (r^2)= ";j print "coeff of correlation= ";j^.5 if i>0 then print "standard error estimate= ";(z/i)^.5 end if print rem "estimate y coordinate" [again] p=r(1,d+2) print print "Interpolation (enter x=q to end program) "; input "x= ";x$ if x$="q" then end end if x=val(x$) for j=1 to d p=p+r(j+1,d+2)*x^j next j print "y= ";p goto [again]