fix inv warning in matlab
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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 日
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';
Walter Roberson
2019 年 8 月 2 日
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
