Chapter 11 - Least-Squares Fits and Pseudoinverses

Section 11.2 - Fits and Pseudoinverses

Example 11.2.1

S={{415,13.25},{372,13.85},{391,13.60},{428,13.15},{403,13.65},{350,14.05},{362,13.90},{410,13.20},{385,13.60},{434,13.00},{465,12.75},{380,13.65}};

PlotS = ListPlot[S,PlotMarkers->{"+",Medium},Axes->True,AxesOrigin->{300,12}]

(A=Join[Drop[S,{},{2}],Table[{1},{i,1,12}],2])//MatrixForm

B =Drop[S, {}, {1}];

PseudoInv[x_]:=Inverse[Transpose[x].x].Transpose[x];

Y=Flatten[PseudoInv[A].B]

LinePlot=Plot[Y[[1]] x+Y[[2]],{x,300,500},PlotStyle->Red];

Show[PlotS,LinePlot,PlotRange->All]

Example 11.2.2

S={{0,925},{2,1005},{4,1135},{6,1215},{8,1345},{10,1265},{12,1130},{14,975},{16,795}};

PlotS=ListPlot[S,PlotMarkers->{"+", Medium},Axes->True,AxesOrigin->{-1,790}]

(A=Table[{((S[[i,1]])^2),S[[i,1]],1},{i,1,9}])//MatrixForm

(B=Drop[S,{},{1}])//MatrixForm

Y=Flatten[N[PseudoInv[A].B]]

ParabolaPlot=Plot[Y[[1]] (t^2)+Y[[2]] t+Y[[3]],{t,0,22},PlotStyle->Red];

Show[PlotS,ParabolaPlot,AxesOrigin->{0,0},PlotRange->All]

Example 11.2.3

S={{0,17.83},{.5,17.71},{1,17.56},{1.5,17.60},{2,17.65},{2.5,17.55},{3,17.52},{3.5,17.58},{4,17.60},{4.5,17.47},{5,17.44},{5.5,17.61},{6,17.69}};

PlotS=ListPlot[S,PlotMarkers->{"+", Medium},Axes->True,AxesOrigin->{-0.2,17.4}]

(A=Chop[N[Table[{1,Cos[2π/7 S[[i,1]]],Cos[4π/7 S[[i,1]]],Cos[6π/7 S[[i,1]]],Sin[2π/7 S[[i,1]]],Sin[4π/7 S[[i,1]]],Sin[6π/7 S[[i,1]]]},{i,1,13}]]])//MatrixForm

B=Drop[S,{},{1}];

Y=Flatten[N[PseudoInv[A].B]]

SinCosPlot=Plot[Y[[1]]+Y[[2]] Cos[2π/7 t]+Y[[3]] Cos[4π/7 t]+Y[[4]] Cos[6π/7 t]+Y[[5]] Sin[2π/7 t]+Y[[6]] Sin[4π/7 t]+Y[[7]] Sin[6π/7 t],{t,0,7},PlotStyle->Red];

Show[PlotS,SinCosPlot]

Example 11.2.7

W1=Wronskian[{Cos[t],Sin[t],Cos[2 t],Sin[2 t]},t]

W2=Wronskian[{Cos[t],Sin[t],Cos[2 t],Sin[2 t],2Sin[t]-Cos[2 t]},t]