|
Define LibPub nafit(x,y,m)=
Prgm
:aa:=newMat(m+1,m+1)
:b:=newMat(1,m+1)
:For i,1,m+1
: For j,1,m+1
: aa[i,j]:=det(sum((x .^ (i+j-2))))
: EndFor
: b[1,i]:=det(sum((x .^ (i-1) .* y)))
:EndFor
:a:=(aa^(−1)*b)
:Disp a
:setMode(1,20)
:a_:=approx(a)
:Disp a_
:Disp "y=",a[1,1]
:For n,2,m+1
:Disp "+",a[1,n],"x^",n-1
:EndFor
:Disp "y=",a_[1,1]
:For n,2,m+1
:Disp "+",a_[1,n],"x^",n-1
:EndFor
:EndPrgm |
|