rem Polynomial Regression For Two Variables cls print print "Polynomial Regression for Two Variables" print print "where x and y are the independent variables" print "and d is the dependent variable" print dim d(50) dim x(50) dim y(50) dim z(50) dim a(9,10) rem data entry input "Number of points to input? ";n [dleap] input "Use keyboard (k) or read from data (d)? ";c$ if c$="k" then for i=1 to n print "x(";i;")= "; input " ";x1 print "y(";i;")= "; input " ";y1 print "d(";i;")= "; input " ";d1 x(i)=x1 y(i)=y1 d(i)=d1 print next i end if if c$="d" then for i=1 to n read x1,y1,d1 x(i)=x1 y(i)=y1 d(i)=d1 next i else goto [dleap] end if rem zero the program variables for k=1 to 50 z(k)=0 next k for k=1 to 9 for l=1 to 10 a(k,l)=0 next l next k rem load matrix for j=1 to n gosub [matrix] for k=1 to 9 for l=1 to 9 a(k,l)=a(k,l)+z(k)*z(l) next l next j rem solve for coefficients for k=1 to 9 p=a(k,k) a(k,k)=1 if p=0 then print "Zero Diagonal - no solution" end end if for l=k+1 to 10 a(k,l)=a(k,l)/p next l m=1 [bleap] if m=k then goto [aleap] end if r=a(m,k) for l=1 to 10 a(m,l)=a(m,l)-r*a(k,l) next l a(m,k)=0 [aleap] m=m+1 if m=10 then goto [cleap] end if goto [bleap] [cleap] next k rem print coefficients print print "Coefficients a1 to a9 are:" print for k=1 to 9 print "a(";k;")= ";a(k,10) next k print rem Calculate the standard deviation q=0 for j=1 to n gosub [matrix] dc=0 for k=1 to 9 dc=dc+a(k,10)*z(k) next k q=q+(dc-d(j))^2 next j r=(q/n)^.5 print "standard deviation= ";r rem estimate y coordinate [again] d=0 print print "Interpolation (enter x=q to end program) "; input "x= ";x1$ if x1$="q" then end end if input "y= ";y1 x1=val(x1$) x(50)=x1 y(50)=y1 j=50 gosub [matrix] for k=1 to 9 d=d+a(k,10)*z(k) next k print "d= ";d goto [again] [matrix] z(1)=1 z(2)=x(j) z(3)=x(j)^2 z(4)=y(j) z(5)=y(j)^2 z(6)=x(j)*y(j) z(7)=z(3)*y(j) z(8)=z(5)*x(j) z(9)=z(3)*z(5) return data .8,1400,873 data .8,1600,877 data .8,1800,888 data .8,2000,904 data 1.2,1400,1076 data 1.2,1600,1072 data 1.2,1800,1070 data 1.2,2000,1076 data 1.6,1400,1253 data 1.6,1600,1245 data 1.6,1800,1239 data 1.6,2000,1235 data 2.0,1400,1409 data 2.0,1600,1399 data 2.0,1800,1391 data 2.0,2000,1386