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!
    6 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
    Tianlan Yang
 le 18 Mar 2021
  
    
    
    
    
    Commenté : Tianlan Yang
 le 18 Mar 2021
            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
0 commentaires
Réponse acceptée
  Walter Roberson
      
      
 le 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.
Plus de réponses (0)
Voir également
Catégories
				En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

