# Solving LU factorization's backward and forward Solve with for loops

12 views (last 30 days)
aliza mustafa on 18 Aug 2022
Edited: Bruno Luong on 18 Aug 2022
Hi,
I am learning LU factorization using MATLAB. I am following up this strategy:
1. LU factorization of a matrix A means for a lower triangular matrix L and an upper triangular matrix U, A = LU
2. I got the L and U by following method:
[L,U,P] = lu(A);
A_Check = P'*L*U;
3. Then I used the backslash command to solve the system LUx = b.
b_Pb = P*b; % Permuation (move rows of b)
c_Lb = L \ b_Pb; % Forward Solve
x_PLU = U \ c_Lb; % Backward Solve
4. Using for loops, I have complete the forward solve to find c_Lb:
% ~ FORWARD SOLVE ~
% Here I have used b_Pb instead of b.
c(1) = b_Pb(1)/L(1,1);
for i = 2:length(c)
known_values = 0; %Firstly I sum all the known values in a row.
for j = 1:i-1
known_values = known_values + L(i,j)*c(j); % For the first loop, this is simply c(1) multiplied by L(2,1).
end % subtract the known values from the right hand side.
% then divide the the coefficient of the ith component of c to find % c(i).
c(i) = (b_Pb(i) - known_values)/L(i,i);
end
% ~ END FORWARD SOLVE ~
Now I have to write the backwards solve involving U, c, and solving for the x value in which I need help.
(((Nota Bene: c = [3.0000; -1.2500; -1.5000]
U =[ 4.0000 8.0000 1.0000; 0 -1.0000 -0.7500; 0 0 -2.5000]
And the final value of x is expected to be: x = [-1.0000; 0.8000; 0.6000] )))))
Any help will be really appreciated. Thanks :)
##### 3 CommentsShow 1 older commentHide 1 older comment
aliza mustafa on 18 Aug 2022
Sorry but can you please elaborate a bit more
Bruno Luong on 18 Aug 2022
Edited: Bruno Luong on 18 Aug 2022
U =[ 4.0000 8.0000 1.0000; 0 -1.0000 -0.7500; 0 0 -2.5000]
U = 3×3
4.0000 8.0000 1.0000 0 -1.0000 -0.7500 0 0 -2.5000
I then flip row and columns of U
LL = U(end:-1:1,end:-1:1)
LL = 3×3
-2.5000 0 0 -0.7500 -1.0000 0 1.0000 8.0000 4.0000
Does it looks like L? Yes, but you know how to solve L*c = b, so you know how to solve to solve LL*cc = bb. Up to you to figure out what is cc and bb.
I can't give more hint than that, otherwise I just sove the whole thing for you.