Qurak

Linear algebra matrix computations least squares solutions

Tutorial 11 stappen, op volgorde uitgevoerd in één sessie. Elke stap is tegen de engine uitgevoerd en de uitvoer hieronder is wat hij opleverde.

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

Geen uitvoer - deze stap zet iets klaar voor de volgende.

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

Geen uitvoer - deze stap zet iets klaar voor de volgende.

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

Gebruikte functies

Gerelateerde recepten

Alle recepten · Functiereferentie · Gebruik dit vanuit een MCP-client