説明

参考文献

lsq 関数はLApack 関数 DGELSY (実行列の場合)および
ZGELSY (複素行列の場合)に基づいています.

例

//Build the datax=(1:10)';y1=3*x+4.5+3*rand(x,'normal');y2=1.8*x+0.5+2*rand(x,'normal');plot2d(x,[y1,y2],[-2,-3])//Find the linear regression A=[x,ones(x)];B=[y1,y2];X=lsq(A,B);y1e=X(1,1)*x+X(2,1);y2e=X(1,2)*x+X(2,2);plot2d(x,[y1e,y2e],[2,3])//Difference between lsq(A,b) and A\bA=rand(4,2)*rand(2,3);//a rank 2 matrixb=rand(4,1);X1=lsq(A,b)X2=A\b[A*X1-b,A*X2-b]//the residuals are the same