Polynomial regression: Difference between revisions

→‎{{header|PARI/GP}}: alternate code due to Bill Allombert
(GP -- thanks to Bill Allombert for pointing out polinterpolate)
(→‎{{header|PARI/GP}}: alternate code due to Bill Allombert)
Line 523:
 
=={{header|PARI/GP}}==
[http://mathworld.wolfram.com/LagrangeInterpolatingPolynomial.html Lagrange interpolating polynomial]:
<lang parigp>polinterpolate([0,1,2,3,4,5,6,7,8,9,10],[1,6,17,34,57,86,121,162,209,262,321])</lang>
Output:
<pre>3*x^2 + 2*x + 1</pre>
 
Least-squares fit:
<lang parigp>V=[1,6,17,34,57,86,121,162,209,262,321]~;
M=matrix(#V,3,i,j,(i-1)^(j-1));Polrev(matsolve(M~*M,M~*V))</lang>
Output:
<pre>3*x^2 + 2*x + 1</pre>