fix inv warning in matlab

3 次查看(过去 30 天)
I use this code:
b=inv(A'*A)*A'*y;
Matlab gives warning. never use inv to solve linear system
How can I fix it?

采纳的回答

Walter Roberson
Walter Roberson 2019-7-28
b=inv(A'*A)*A'*y;
Multiply both sides on the left by A'*A :
(A'*A) * b = (A'*A) * inv(A'*A) * A' * y
and for any invertable matrix, X * inv(X) is the identity matrix so (A'*A) * inv(A'*A) cancels out to identity, so
(A'*A) * b = A' * y
Multiply both sides on the left by inv(A'):
inv(A') * A' * A * b = inv(A') * A' * y
and inv(A') * A' cancels to the identity on both sides, so
A * b = y
Multiply by inv(A) on the left on both sides:
inv(A) * A * b = inv(A) * y
inverse cancels to identity, so
b = inv(A) * y
Now use the \ operator:
b = A \ y;
The above mathematics might not strictly apply if A is not a square matrix.
  8 个评论
NA
NA 2019-8-2
Thank you. But
RR = WW - HH * inv(HH' * WWInv * HH) * HH';
RR = WW - HH *inv(HH)*inv(WWInv)
RR = 0
Walter Roberson
Walter Roberson 2019-8-2
Yes, I missed the HH pre-multiplier, but Yes, that logic appears correct. If you try it with actual random matrices, you will find that RR is 0 to within round-off error (e.g., for rand(15,15) all of the entries come out with absolute value less than 1E-13

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Linear Algebra 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by