Warum liefert A^(-1)*b keine Warnung aber A\b bzw. inv(A)*b schon wenn A singulär ist?

1 回表示 (過去 30 日間)
Elisabeth
Elisabeth 2025 年 5 月 15 日
回答済み: Harald 2025 年 5 月 15 日
Hallo,
Matrix A ist singulär.
Wie unterscheiden sich beim Berechnen der Inversen von A die Methode A^(-1)*b von den Methoden inv(A)*b und A\b ? Gibt es außerdem einen Unterschied zwischen Methode inv(A)*b und Methode A\b?
LisaB
A = [1 -1; 0 0]
A = 2×2
1 -1 0 0
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
b = [-0.5; -0.5]
b = 2×1
-0.5000 -0.5000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
x = A^(-1)*b % keine Warnung
x = 2×1
-Inf -Inf
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
x = A\b % Warnung
Warning: Matrix is singular to working precision.
x = 2×1
-Inf -Inf
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
x = inv(A)*b % Warnung
Warning: Matrix is singular to working precision.
x = 2×1
-Inf -Inf
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

採用された回答

Harald
Harald 2025 年 5 月 15 日
Hallo,
laut Dokumentation: "X^(-1) is equivalent to inv(X)". Warum das eine eine Warnung wirft und das andere nicht, kann ich auch nicht beantworten.
Zwischen A\b und inv(A)*b ist der Unterschied, dass im ersten Fall die Inverse nicht explizit berechnet wird, sondern "nur" das Gleichungssystem A*x = b gelöst wird. Im Algorithms-Bereich der Doku siehst du, wie das wann gemacht wird:
A\b ist schneller (wird natürlich erst bei größeren Matrizen deutlich) und liefert tendenziell genauere Ergebnisse.
rng(0)
A = rand(10000);
b = rand(10000,1);
tic; x1 = A\b; toc
Elapsed time is 2.670614 seconds.
tic; x2 = inv(A)*b; toc
Elapsed time is 5.151322 seconds.
res1 = norm(A*x1 - b)
res1 = 7.1242e-10
res2 = norm(A*x2 - b)
res2 = 1.7215e-09
Viele Grüße,
Harald

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!