Chapter 11 - Least-Squares Fits and Pseudoinverses

Section 11.1 - Pseudoinverse to a Nonsquare Matrix and Almost Solving an Overdetermined Linear System

Commands before Example 11.1.1

(A={{a,b,c}})//MatrixForm

Det[Transpose[A].A]

(A={{a,b,c},{d,e,f}})//MatrixForm

Det[Transpose[A].A]

(A={{a,b,c,d},{e,f,g,h},{i,j,k,l}})//MatrixForm

Det[Transpose[A].A]

(A={{a,b,c,d},{e,f,g,h}})//MatrixForm

Det[Transpose[A].A]

Example 11.1.1

A={{-5,2,-9},{7,1,3},{8,-4,0},{-6,10,-3}};

(pseudoA=Inverse[Transpose[A].A].Transpose[A])//MatrixForm

B={{-11},{6},{1},{5}};

(Y=pseudoA.B)//MatrixForm

RowReduce[Join[A,B,2]]//MatrixForm

N[A.Y]//MatrixForm

N[(A.Y-B)]//MatrixForm

N[Norm[A.Y-B]]

(Soln1=RowReduce[Drop[Join[A,B,2],{1},{}]][[All,4]])//MatrixForm

N[(Y-Soln1)]//MatrixForm

(Soln2=RowReduce[Drop[Join[A,B,2],{2},{}]][[All,4]])//MatrixForm

N[(Y-Soln2)]//MatrixForm

(Soln3=RowReduce[Drop[Join[A,B,2],{3},{}]][[All,4]])//MatrixForm

N[(Y-Soln3)]//MatrixForm

(Soln4=RowReduce[Drop[Join[A,B,2],{4},{}]][[All,4]])//MatrixForm

N[(Y-Soln4)]//MatrixForm

X={x,y,z};

(Planes=A.X-B)//MatrixForm

PlanePlots=ContourPlot3D[Evaluate[Flatten[Planes]],{x,-4,4},{y,-4,4},{z,-4,4},Mesh-> None,ContourStyle->{{Red},{Blue},{Yellow},{Brown}}];

YPlot=Graphics3D[{White,Sphere[Flatten[Y],0.6]}];

Show[PlanePlots,YPlot]

Example 11.1.2

Eqns={2 x-y==-7,-5 x-2 y==13,3 x+3 y==-6};

Solve[Eqns,{x,y}]

A={{2,-1},{-5,-2},{3,3}};B={{-7},{13},{-6}};

(pseudoA=Inverse[Transpose[A].A].Transpose[A])//MatrixForm

(IntersectPt=pseudoA.B)//MatrixForm

IntersectPlot=Graphics[{Black,Thickness[0.005],Circle[Flatten[IntersectPt],0.1]}];

LinePlots=ContourPlot[Evaluate[Eqns],{x,-5,0},{y,-2,3},ContourStyle->{{Red,Thickness[0.01]},{Black,Thickness[0.01]},{Blue,Thickness[0.01]}},PlotRange->All,Axes->True,Frame->False];

Show[LinePlots,IntersectPlot]