Computational(LAB-7)
Computational(LAB-7)
: 07
Objectives:
1. To understand and apply LU decomposition for solving systems of linear equations
using MATLAB.
2. To find the inverse of a matrix using LU decomposition method in MATLAB.
3. To compare manual and MATLAB-built LU results for verifying accuracy.
Theory:
LU decomposition is a method in linear algebra used to solve systems of linear equations and
to find the inverse of a matrix. In this method, a square matrix A is broken into two simpler
matrices: a Lower triangular matrix (L) and an Upper triangular matrix (U), so that A = L × U.
This makes complex matrix operations easier and faster.
A lower triangular matrix has all zeros above its main diagonal, while an upper triangular matrix
has all zeros below the main diagonal. Once a matrix is written as LU, it becomes easier to solve
problems step by step using forward and backward substitution.
This method is useful when you need to solve many equations with the same matrix A but
different b values. You decompose A once, and reuse L and U each time.
LU decomposition can also be used to find the inverse of a matrix (A⁻¹). Instead of doing direct
inversion, we solve AX = I, where I is the identity matrix. Each column of the identity matrix
gives one equation, and solving all gives us the inverse matrix.
LU decomposition is very helpful in engineering and science because it saves time and avoids
complex calculations. It works only if A is a square and non-singular matrix (its determinant is
not zero). This method is reliable and widely used in real-world applications.
MATLAB Code:
MATLAB Code for LU Decomposition Method & Matrix Inversion:
A = [2 1 1; 3 2 3; 1 4 9];
B = [10; 18; 16];
n = 3;
% LU Decomposition
L = eye(n);
U = A;
for i = 1:n-1
for j = i+1:n
L(j,i) = U(j,i)/U(i,i);
U(j,:) = U(j,:) - L(j,i)*U(i,:);
end
end
% Display Results
disp('L ='); disp(L);
disp('U ='); disp(U);
disp('Solution x ='); disp(x);
disp('Inverse of A ='); disp(invA);
Result:
Discussion:
In this experiment, we solved a system of three linear equations and found the inverse of a matrix using
LU decomposition, both manually and with MATLAB. The results from our manual steps matched
MATLAB’s output, showing that our understanding was correct. LU decomposition helped break the
matrix into two simpler parts, making calculations easier. We also learned that forward and backward
substitution is faster and more stable than directly solving the full system. MATLAB made the process
quicker and reduced chances of mistakes, especially for large systems. This method is very useful when
solving many equations with the same matrix. However, LU decomposition works best when the matrix
does not need pivoting. Overall, this experiment showed that LU decomposition is a simple and reliable
method that is widely used in engineering and science to solve matrix problems efficiently.