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

1 view (last 30 days)
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>

Accepted Answer

Harald
Harald on 15 May 2025
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

More Answers (0)

Community Treasure Hunt

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

Start Hunting!