- What if you flip row indices of U (and c), and flip column indices of U (and row indices of x)?
- What an upper triangular matrix U become after flip once in each directions like above?

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

13 views (last 30 days)

Show older comments

Hi,

I am learning LU factorization using MATLAB. I am following up this strategy:

- LU factorization of a matrix A means for a lower triangular matrix L and an upper triangular matrix U, A = LU
- 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 Comments

Bruno Luong
on 18 Aug 2022

Edited: Bruno Luong
on 18 Aug 2022

Here is your U matrix

U =[ 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)

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.

### Answers (0)

### See Also

### Categories

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!