Error "Matrix dimention must agree"
2 views (last 30 days)
Here is the function:
function [L,U] = eluinv(A)
[L,U] = lu(A);
if closetozeroroundoff(A,7) == closetozeroroundoff(L*U,7)
disp('Yes, I have got LU factorization')
if closetozeroroundoff(rref(U),7) == closetozeroroundoff(rref(A),7)
disp('U is an echelon form of A')
disp('Something is wrong')
if rank(A) ~= max(size(A))
sprintf('A is not invertible')
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;
disp('Yes, LU factorization works for calculating the inverses')
disp('LU factorization does not work for me?!')
Cris LaPierre on 18 Mar 2021
Edited: Cris LaPierre on 18 Mar 2021
The error message is telling you what the issue is. You are trying to compare two matrices that do not have the same number of elements.
The left side of your comparison is 3x3 while the right side is 4x3. See this documentation page for more.
This is because the result of lu is two different sized matrices.
A = [1 1 4; 0 -4 0; -5 -1 -8; 2 3 -1];
[L,U] = lu(A)