Hello I am in a basic numerical methods class and our teacher has given us an algorithm which can compute the inverse of a matrix other than using MATLAB's built in library function.
A = [1 2 4; 1 3 9; 1 4 16]; b = [7; 13; 21]; [L, U, P] = lu(A); n = 3; X = zeros(n,n); for i=1:n e = zeros(n,1); e(i) = 1; X(:,i) = U\(L\(P*e)) end
I am a bit new to MATLAB, so I Am a bit unsure as to what this code is actually doing to find the inverse. I naively set n = 3 because it was the only value i could find to get the algorithm to work.
Now I know this algorithm finds the LU factorization of A then uses the \ operator repeatedly.
what I do not understand is what x = zeros(n,n) what is the point of this line as well as the inner for loop
e = zeros(n,1); //creates a 3 x 1 matrix of zeroes? e(i) = 1; //No idea what this line is doing X(:,i) = U\(L\(P*e))
As for the last line of the for loop, This is the repeated "\" operation but I have no idea what the X(:,i) stands for as well as well using "\" by P*e
Could someone help me understand this algorithm better? Because I am only understanding fragments of it at the moment.