Why there is an error in my code after I type "[L,U] = eluinv(A);"? ( the error is that too many output arguments ) Thank you!

4 views (last 30 days)
Here is the function:
function [] = eluinv(A)
[~,n]=size(A);
[L,U] = lu(A);
format compact
%have to round to supress extra zeroes
if (closetozeroroundoff(A) == closetozeroroundoff(round(L * U)))
disp('Yes, I have got LU factorization')
end
%comparing the reduced row echelon forms of each
if closetozeroroundoff(rref(U)) == closetozeroroundoff(rref(A))
disp('U is an echelon form of A')
else
disp('Something is wrong')
end
%if is invertible, code will continue and inversion will occur
if rank(A) ~= min(size(A))
sprintf('A is not invertible')
invA=[];
return
else
eyeForL = [L eye(n)];
eyeForU = [U eye(n)];
aux = rref(eyeForL);
aux2 = rref(eyeForU);
invL = aux(:,(n+1):size(aux,2));
invU = aux2(:,(n+1):size(aux2,2));
invA = invU*invL;
P = inv(A);
if (closetozeroroundoff(invA - P) == zeros(size(A)))
disp('Yes, LU factorization works for calculating the inverses')
else
disp('LU factorization does not work for me?')
end
end

Accepted Answer

Walter Roberson
Walter Roberson on 18 Mar 2021
function [] = eluinv(A)
You declared that eluinv() does not return any values.
[L,U] = eluinv(A)
When you call a function and assign the output to variable names, MATLAB never looks inside the function to see if it can find variables with the same name to return the values of. Output in MATLAB is strictly positional. The first output location will be assigned the value of the first variable mentioned in the [] on the left side of the = in the function statement.

More Answers (0)

Categories

Find more on Linear Algebra in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!