fix inv warning in matlab
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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
2019년 7월 28일
0 개 추천
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
2019년 7월 28일
It means that instead of using
b=inv(A'*A)*A'*y;
I should use
b=A\y
Walter Roberson
2019년 7월 28일
Yup.
NA
2019년 7월 28일
so if I have this
di=sum((r*inv(sig)).*r,2);
should be change to
di=sum((r/(sig)).*r,2);
Is it correct?
Walter Roberson
2019년 7월 28일
That looks strange to me, seeing as it has both a matrix multiply by r ( * operator) and an element-by-element multiplication by r ( .* operator) . But if the * and .* are both correct, then yes, r/sig .* r
NA
2019년 8월 1일
I have this
RR = WW - HH * inv(HH' * WWInv * HH) * HH';
Can I change it to this one?
RR = WW - HH * (HH' * WWInv * HH)\ HH';
Yes, but you should be questioning why you are doing that.
Provided that HH and WWInv are square matrices, then
inv(HH' * WWInv * HH)
equals
inv(HH)*inv(WWInv) * inv(HH')
You then right-multiply by HH' so
inv(HH)*inv(WWInv) * inv(HH') * HH'
and you group the last two together and the inv(HH') will cancel the HH, leaving
inv(HH)*inv(WWInv)
The name suggests that inv(WWInv) would probably be an existing variable named WW, so you could probably instead be using
RR = WW - HH \ WW
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
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개)
카테고리
도움말 센터 및 File Exchange에서 Mathematics에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
