0% found this document useful (0 votes)
2 views4 pages

NM-Lab 011 LU Factorization Manual

LU factorization is a method for decomposing a square matrix into a lower triangular matrix L and an upper triangular matrix U, facilitating the solution of linear equations. The process involves forward and backward substitution to solve the system efficiently, especially when dealing with multiple right-hand side vectors. The document outlines the MATLAB procedure for executing LU factorization, including initialization and computation steps.

Uploaded by

Naeem Hanif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

NM-Lab 011 LU Factorization Manual

LU factorization is a method for decomposing a square matrix into a lower triangular matrix L and an upper triangular matrix U, facilitating the solution of linear equations. The process involves forward and backward substitution to solve the system efficiently, especially when dealing with multiple right-hand side vectors. The document outlines the MATLAB procedure for executing LU factorization, including initialization and computation steps.

Uploaded by

Naeem Hanif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Lab# 11

LU Factorization on MATLAB
Introduction to LU Factorization
LU factorization, or LU decomposition, in numerical methods is a technique for decomposing a square
matrix A into the product of two triangular matrices: a lower triangular matrix L and an upper triangular
matrix U, such that A = LU. This factorization is useful for solving systems of linear equations and
inverting matrices.

Explanation:
Decomposition:

The core idea is to express a given matrix A as the product of two simpler matrices, L and U, where:

L (Lower Triangular Matrix): A matrix with all entries below the main diagonal being zero, and usually
with 1s along the main diagonal.

U (Upper Triangular Matrix): A matrix with all entries above the main diagonal being zero.

Purpose:

LU factorization is particularly helpful for solving systems of linear equations of the form Ax = b. By
factoring A into L and U, the system Ax = b becomes LUx = b.

Solving the System:

Forward Substitution: First, solve Ly = b for y (forward substitution). Since L is lower triangular, this
involves solving the system one row at a time.

Backward Substitution: Then, solve Ux = y for x (backward substitution). Since U is upper triangular, this
involves solving the system one row at a time, working from the last row to the first.

Efficiency:

LU factorization can be more efficient than directly solving the original system of equations, especially
when solving multiple systems with the same coefficient matrix A but different right-hand side vectors b.
The L and U matrices are computed only once, and then the forward and backward substitutions are
performed for each new b.

Procedure to Execute LU Factorization on MATLAB


The procedure to execute the LU factorization on MATLAB is as,
Step 1: Introduction to input matrices
A = input('Enter a coefficient Matrix: ');
B = input('Enter a source Vector: ');
N = length(B);
L = zeros(N, N);
U = zeros(N, N);
Step 2: Initialize first element
L(1,1) = sqrt(A(1,1));
U(1,1) = L(1,1);

Step 3: Initialize first row and column


for a = 2:N
L(a,1) = A(a,1) / L(1,1);
U(1,a) = A(1,a) / L(1,1);
end

Step 3: Perform LU decomposition


for i = 2:N
for j = i:N
% Diagonal elements
if i == j
sum_LU = 0;
for k = 1:i-1
sum_LU = sum_LU + L(i,k) * U(k,i);
end
L(i,i) = sqrt(A(i,i) - sum_LU);
U(i,i) = L(i,i);
else
% Lower triangular matrix
sum_LU = 0;
for k = 1:i-1
sum_LU = sum_LU + L(j,k) * U(k,i);
end
L(j,i) = (A(j,i) - sum_LU) / L(i,i);

% Upper triangular matrix


sum_LU = 0;
for k = 1:i-1
sum_LU = sum_LU + L(i,k) * U(k,j);
end
U(i,j) = (A(i,j) - sum_LU) / L(i,i);
end
end
end

disp('L ='); disp(L);


disp('U ='); disp(U);

Step 4: Forward substitution


Y = zeros(N,1);
Y(1) = B(1) / L(1,1);
for k = 2:N
Y(k) = (B(k) - L(k,1:k-1) * Y(1:k-1)) / L(k,k);
end

disp('Y ='); disp(Y);

Step 5: Backward substitution


X = zeros(N,1);
X(N) = Y(N) / U(N,N);
for k = N-1:-1:1
X(k) = (Y(k) - U(k,k+1:N) * X(k+1:N)) / U(k,k);
end

disp('X ='); disp(X);

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy