Filter löschen
Filter löschen

There are two errors in my code. Can someone know how to edit it to maker it run? Thank you!

1 Ansicht (letzte 30 Tage)
Here is the function:
function [L,U] = eluinv(A)
[~,n]=size(A);
[L,U] = lu(A);
format compact
if closetozeroroundoff(A,7) == closetozeroroundoff(L*U,7)
disp('Yes, I have got LU factorization')
end
if closetozeroroundoff(rref(U),7) == closetozeroroundoff(rref(A),7)
disp('U is an echelon form of A')
else
disp('Something is wrong')
end
if rank(A) ~= min(size(A))
sprintf('A is not invertible')
invA=[];
return
else
leye = [L eye(size(L,1))];
ueye = [U eye(size(U,1))];
invLech = rref(leye);
invUech = rref(ueye);
invL = invLech(:,(n+1):size(invLech,2));
invU = invUech(:,(n+1):size(invUech,2));
invA = invU*invL;
if isequal(closetozeroroundoff(invA-inv(A)),zeros(size(A)))
disp('Yes, LU factorization works for calculating the inverses')
else
disp('LU factorization does not work for me?!')
end
end

Akzeptierte Antwort

Cris LaPierre
Cris LaPierre am 18 Mär. 2021
The error message appears to show the reason for the error. Your matrix A must be square (3x3 or 4x4) in order to use inv.
if isequal(closetozeroroundoff(invA-inv(A)),zeros(size(A)))
^^^^^^ % Error is here
  3 Kommentare
Cris LaPierre
Cris LaPierre am 18 Mär. 2021
Your criteria do not check if the matrix is square. Perhaps you want this instead?
rank(A) ~= max(size(A))

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Sparse Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by