DEPARTMENT OF MECHATRONICS ENGINEERING
UNIVERSITY OF ENGINEERING & TECHNOLOGY, PESHAWAR
                                  MtE 350L Numerical Method
           Student Name: Mian Sayaf Ali Shah Reg. No: 18PWMCT0612
           Lab Tittle: LU Decomposition Method
           Lab No: 6
                                              LAB REPORT RUBRICS:
                         Excellent (4)         Proficient (3)       Basic (2)         Below Basic
                                                                                                        Student’s
Criteria                                                                              (1)
                                                                                                          Score
                                               Report is mostly     Report is
                          Report is as per
                                               as per the           disorganized
                         the guidelines.                                            Sections/Steps
To organize the lab                            guidelines and       and follows
                         All                                                         are not ordered
report and practice                            most                 some guidelines
                         sections/steps are                                          and Report is
the writing skills as                          sections/steps are   but most of the
                         clearly organized                                           not as per the
per the guidelines                             ordered well but     guidelines are
                         in a logical                                                guidelines
                                               requires minor       missing
                         order.
                                               improvements.
                       The report
                      completely
                                                                    The report
                      discusses the                                                    The report is
                                               The report           discusses the lab
To discuss the actual required task in                                                totally
                                               discusses the        work but have
task                  own words with                                                  irrelevant to
                                               required task        irrelevant
                      some relevant                                                   the lab work
                                                                    information
                      additional
                      information
                                               Calculations and
                         Calculations and                           Most data and
                                               data analysis were
                         data analyses                              observations
                                               performed
                         were                                       were recorded     Calculations
To perform                                     accurately, but
                         performed                                  adequately, but   and data
calculations and                               minor errors were
                         clearly,                                   with several      analyses of lab
data analysis                                  made both in
                         concisely, and                             significant       were missing
                                               calculations and
                         accurately, with                           errors or
                                               in applying
                         correct units.                             omissions.
                                               correct units
                         Graphs, if
                         necessary, were                            Graphs, if         Major
To present results                             Graphs, if
                         drawn accurately                           necessary, were   components of
in the form of                                 necessary, were
                         and neatly and                             drawn but         lab were
graphs                                         drawn adequately
                         were clearly                               inadequately.     missing
                         labelled.
         Numerical Methods
                     Lab Report # 6
            LU Decomposition Method
Submitted by: Mian Sayaf Ali Shah(18PWMCT0612)
           Submitted to: Dr. Shahzad Anwar
                           Section: A
             Submission Date (December 22, 2020)
      DEPARTMENT OF MECHATRONICS ENGINEERING
    University of Engineering and Technology, Peshawar, Pakistan
Objective:
   To know about the LU decomposition method
   To write the code for the LU decomposition method.
   To solve the system of linear equations and determine the roots using LU decomposition.
Software:
   MATLAB
Theory:
Basically, we do computations and visualization in MATLAB. In this lab, we did the
computations. We learn how to write the matrices in MATLAB and perform the arithmetic
operations on matrices. We learn how to find roots of system of linear of equations by using
the LU decomposition method in MATLAB. In LU decomposition method, the matrix is
transformed into lower and triangular matrix, there are two methods in LU decomposition
which are Croute’s method and Doolittle’s method. In lower triangular matrix we take diagonal
elements unity in Doolittle’s methods. In croute’s method we take diagonal elements of upper
matrix as unity. Three steps are necessary for LU decomposition. LU decomposition method
is used to solve the system of linear equations.
                                        A = [L][U]
                                          [L]Y=B
                                          [U]X=Y
Post Lab Tasks:
Write down the MATLAB Code for the following Equation using LU decomposition method
                                    4x1-2x2+5x3=10
                                    0x1-2x2+5x3=12
                                 -5x1+10x2+15x3=-20
MATLAB Code:
A=[4 -2 5;0 -2 5;-5 10 15];
A=[4 -2 5;0 -2 5;-5 10 15];
[L,U] = lu(A)
y=[10;12;-20];
x1=inv(A)*y
x2=A\y
x3=U\(L\(P*y))
Results:
                              Figure 1 Result of Task 1
Croute’s Method:
MATLAB Code:
function[L U]=LU_crout(A)
m=length(A);
L=zeros(size(A));
U=zeros(size(A));
L(:,1)=A(:,1);
U(1,:)=A(1,:)/L(1,1);
U(1,1)=1;
for k=2:m
for j=2:m
    for i=j:m
        L(i,j)=A(i,j)-dot(L(i,1:j-1),U(1:j-1,j));
    end
    U(k,j)=(A(k,j)-dot(L(k,1:k-1),U(1:k-1,j)))/L(k,k);
end
end
Result:
                          Figure 3 Result of Croute’s method
Doolittle’s Method:
A=input('Enter the square matrix to be factorized              ');
[m,n]=size(A);
if m~=n
    disp('Matrix must be square')
    beep
end
U=zeros(m);
L=zeros(m);
for j=1:m
    L(j,j)=1;
end
for j=1:m
    U(1,j)=A(1,j);
end
for i=2:m
    for j=1:m
        for k=1:i-1
            s1=0;
            if k==1
                s1=0;
            else
            for p=1:k-1
                s1=s1+L(i,p)*U(p,k);
            end
            end
            L(i,k)=(A(i,k)-s1)/U(k,k);
           end
         for k=i:m
             s2=0;
           for p=1:i-1
               s2=s2+L(i,p)*U(p,k);
             end
             U(i,k)=A(i,k)-s2;
           end
    end
end
disp('The matrix to be decomposed is')
A
disp('The Lower Triangular Matrix is')
L
disp('The Upper Triangular Matrix is')
U
Result:
                                Figure 3 Result of Doolittle’s method
Conclusion:
After performing this lab, we come to know about the computations in MATLAB and basic
operations that we did on matrices in MATLAB. We write the code for Gauss elimination
method to determine the roots of system of linear equations. We successfully determine the
roots of equations by transforming the matrix into reduce echelon form and then use the back
substitution.