I have a code that converts a matrix into its upper form and lower form counterparts.
I want to use this M file script in another M file script, where I take the L and U matrices for this new script that will take these L and U and use them to find the inverse of the matrix.
The problem is when I call the function, I can't use anything from the function I am calling.
Ie: I have the code:
function [L, U] = LU_decomp(A)A=input('Enter the square matrix to be factorized ');[m,n]=size(A);if m~=n disp('Matrix must be square')endU=zeros(m);L=zeros(m);for j=1:m L(j,j)=1;endfor j=1:m U(1,j)=A(1,j);endfor i=2:m for j=1:m for k=1:i-1 s1=0; if k==1 s1=0; else for p=1:k-1 s1=s1+L(i,p)*U(p,k); end end L(i,k)=(A(i,k)-s1)/U(k,k); end for k=i:m s2=0; for p=1:i-1 s2=s2+L(i,p)*U(p,k); end U(i,k)=A(i,k)-s2; end endenddisp('The matrix to be decomposed is')Adisp('The Lower Triangular Matrix is')Ldisp('The Upper Triangular Matrix is')U
So when a matrix is entered, it is split into its L and U form.
Now I have this other script:
function A =inverse(A)LU_decomp(A)LU
I haven't completed the code for the inverse yet, but f I try the above script, entering in the matrix I want to use, LU_decomp calculates L and U forms, but then if I am trying using L and U in the body of my inverse script, L and U will be unrecognized. Why is this?Am I not calling the function correctly? (I'd rather split this up into two separate m-files than keep it in one.)
Best Answer