The m=n case: polynomial interpolation

Definition. The polynomial interpolant of data 𝒟={(xi,yi),i=1,,m} with xixj if ij is a polynomial of degree m-1

pm-1(x)=c0+c1x++cm-1xm-1

that satisfies the conditions pm-1(xi)=yi, i=1,,m.

m=3; x=(0:m-1)./m; c0=2; c1=3; c2=-5; yex=c0.+c1*x.+c2*x.^2;
A=ones(m,3); A[:,2]=x[:]; A[:,3]=x[:].^2; QR=qr(A); Q=QR.Q[:,1:3]; R=QR.R[1:3,1:3];
c = R\(transpose(Q)*yex)

[ 2.0 2.9999999999999987 -4.999999999999999 ] (3)

Note that the coefficients used to generate the data are recovered exactly.