Can someone solve this Error for me? Thank you

1 次查看(过去 30 天)
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(n)];
ueye = [U eye(n)];
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),7),zeros(size(A)))
disp('Yes, LU factorization works for calculating the inverses')
else
disp('LU factorization does not work for me?!')
end
end

回答(1 个)

KSSV
KSSV 2021-3-18
Replace lines:
leye = [L eye(n)];
ueye = [U eye(n)];
with:
leye = [L eye(size(L,1))];
ueye = [U eye(size(U,1))];
  2 个评论
Tianlan Yang
Tianlan Yang 2021-3-18
That works. However, there exist another mistake. Can you help solve this as well?
KSSV
KSSV 2021-3-18
This error is clear, if you want to find the inverse of a matrix, the matrix should be a square matrix.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by