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

8 vues (au cours des 30 derniers jours)
aliza mustafa
aliza mustafa le 18 Août 2022
Modifié(e) : Bruno Luong le 18 Août 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 commentaires
aliza mustafa
aliza mustafa le 18 Août 2022
Sorry but can you please elaborate a bit more
Bruno Luong
Bruno Luong le 18 Août 2022
Modifié(e) : Bruno Luong le 18 Août 2022
Here is your U matrix
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.

Connectez-vous pour commenter.

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by