Multiplying by inverse of a matrix

조회 수: 48 (최근 30일)
JPF
JPF 2020년 11월 27일
댓글: JPF 2020년 11월 27일
Hello,
I want to calculate where α is a scalar (it's for calculating the estimated variance of a parameter). Using
alpha*inv(X'X)
gives the correct results but (a) Matlab suggest not doing so (although the backward slash gives the wrong results) and (b) I've always avoided multiplying by the inverse of a matrix due to potential inaccuracy.
Is there a better way?
Thank you
  댓글 수: 2
J. Alex Lee
J. Alex Lee 2020년 11월 27일
can you give example values of alpha and X?
JPF
JPF 2020년 11월 27일
For example,
alpha = 0.5;
X = [0.6 0.9; 0.9 0.5];
For this I obtain
alpha\(X'*X) = [2.34 2; 2 2.2]
alpha*inv(X'*X) = [2.04 -1.9; -1.9 2.2]

댓글을 달려면 로그인하십시오.

채택된 답변

James Tursa
James Tursa 2020년 11월 27일
편집: James Tursa 2020년 11월 27일
You are essentially "dividing" by the X'*X quantity, so that is what needs to appear on the "bottom" of the slash. E.g.,
>> alpha = 0.5;
>> X = [0.6 0.9; 0.9 0.5];
>> alpha*inv(X'*X)
ans =
2.0377 -1.9031
-1.9031 2.2491
>> (X'*X)\eye(2)*alpha
ans =
2.0377 -1.9031
-1.9031 2.2491
>> alpha*eye(2)/(X'*X)
ans =
2.0377 -1.9031
-1.9031 2.2491
Or you can think of it this way. Start with this definition:
inv(X'*X) * (X'*X) = eye(2)
and solve for the inverse:
inv(X'*X) = eye(2)/(X'*X)
Similarly, starting with this definition:
(X'*X) * inv(X'*X) = eye(2)
yields
inv(X'*X) = (X'*X)\eye(2)
Then just multiply by alpha.
  댓글 수: 1
JPF
JPF 2020년 11월 27일
That's great, thank you. I was thrown off by Matlab's recommendation that I just used the backward slash.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by