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!

2 views (last 30 days)
Here is the function:
function [] = eluinv(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')
%comparing the reduced row echelon forms of each
if closetozeroroundoff(rref(U)) == closetozeroroundoff(rref(A))
disp('U is an echelon form of A')
disp('Something is wrong')
%if is invertible, code will continue and inversion will occur
if rank(A) ~= min(size(A))
sprintf('A is not invertible')
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')
disp('LU factorization does not work for me?')

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)


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!