questions about solving a linear equations ( \ vs pinv vs least-square)
9 次查看(过去 30 天)
显示 更早的评论
I wonder why the answer with using \ is different to solutions with pinv or least-square.
X = [13.5, 6.75, 6.75;6.75,6.75,0;6.75,0,6.75];
y = [0.62;0.31;0.31];
X\y % [-0.0791, 0.125, 0.125]
pinv(X) * y % [0.0306, 0.0153, 0.0153]
pinv(X * X') * X' * y % [0.0306, 0.0153, 0.0153]
I use MatLab R2016a in Windows 7 SP1 64bit.
0 个评论
回答(1 个)
Massimo Zanetti
2016-10-12
编辑:Massimo Zanetti
2016-10-12
Your matrix X has full rank, so the difference between the two methods shouldn't be so high. Running it on my pc I indeed obtain:
X = [13.5, 6.75, 6.75;6.75,6.75,0;6.75,0,0]
y = [0.62;0.31;0.31];
format long
a1=X\y
a2=pinv(X)*y
a1 =
0.045925925925926
0
0
a2 =
0.045925925925926
0.000000000000000
-0.000000000000000
They are the same. Differences among the two methods show up when the matrix X has not full rank. Then, if y does not belong to R(X), the range space of X, then pinv method returns the orthogonal projection of y onto R(X). While other methods triggered by \ operator return different approximations, depending on which one is triggered. The collection of methods that \ can trigger (depending on properties of matrix X) is listed here (bottom of the page):
2 个评论
Massimo Zanetti
2016-10-12
编辑:Massimo Zanetti
2016-10-12
Then your matrix
X = [13.5, 6.75, 6.75;6.75,6.75,0;6.75,0,6.75]
is exactly rank(X)=2, so rank is NOT FULL (any row is a linear combination of the other two). Fore instance, row1=row2+row3.
As a consequence the solutions of the two methods are different, because of what I sayd before.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!