Qurak

Linear algebra matrix computations least squares solutions

Tutorial 11 steps, run in order in one session. Every step was executed against the engine and the output below is what it produced.

Step 1
A = {{1., 2.}, {5., 6.}, {4.5, 6.}};
B = {5., 6., 8.};
LinearSolve[A, B]
Output
LinearSolve[{{1., 2.}, {5., 6.}, {4.5, 6.}}, {5., 6., 8.}]
Step 2
A = {{1., 2.}, {2., 4.}, {3., 6.}};
B = {5., 6., 8.};
MatrixRank[A]
Output
1
Step 3
X = PseudoInverse[A].B
Output
{0.5857142857142857, 1.1714285714285715}
Step 4
A.X
Output
{2.928571428571429, 5.857142857142858, 8.785714285714285}
Step 5
data = {{0.2, 4.59}, {0.4, 5.05}, {0.6, 6.2}, {0.8, 6.6}, {1., 7.4}};

No output - this step sets something up for the next one.

Step 6
plot1 = ListPlot[ data, PlotStyle -> PointSize[0.02]]
Output
-Graphics-
Step 7
xData = data[[All, 1]];
yData = data[[All, 2]];

No output - this step sets something up for the next one.

Step 8
mat = Transpose[ {Table[1, {Length[xData]}], xData}];
mat//MatrixForm
Output
MatrixForm[{{1, 0.2}, {1, 0.4}, {1, 0.6}, {1, 0.8}, {1, 1.}}]
Step 9
PseudoInverse[mat].yData
Output
{3.8170000000000015, 3.585}
Step 10
sol = FindFit[data, α + β x, {α, β}, x]
Output
{α -> 3.8169999997513093, β -> 3.5849999944044773}
Step 11
Plot[ (α + β x) /. sol, {x, 0, 1}, Epilog -> First[plot1]]
Output
-Graphics-

Functions used

Related recipes

All recipes · Function reference · Use this from an MCP client