SAINT LOUIS UNIVERSITY
SCHOOL OF ENGINEERING AND ARCHITECTURE
DEPARTMENT OF ELECTRICAL ENGINEERING
MP 1
Solving Systems of Linear Equation using Doolittle’s LU (Lower-Upper)
Factorization through MATLAB
GERONIMO, RODOLFO D. 03 FEB 2024
GABRIEL, EDREIAN LOUIE
ENGR. JAMF
Introduction:
The objective of this activity is to demonstrate how MATLAB
can be used to solve numerical methods for differential
equations. Specifically, the focus will be on methods like
Euler’s Method, Runge-Kutta, and others commonly used in
computational mathematics to approximate the solutions of
ordinary differential equations (ODEs). These methods are
pivotal in engineering, physics, and other applied sciences
where exact analytical solutions to ODEs may not always be
available or practical.
Background Information: Numerical methods are techniques
used to approximate solutions to mathematical problems that
cannot be solved analytically. In the case of ODEs, methods like
Euler’s and Runge-Kutta allow for approximations of the solution
curve of a differential equation at discrete points. These
techniques are particularly useful for complex systems where
finding exact solutions is difficult. Euler’s method, for
instance, is a simple first-order method that estimates the
value of the dependent variable at the next time step, based on
its value at the current step and the rate of change.
Program Development: The MATLAB program was developed to
implement numerical methods for solving differential equations.
The program follows a modular approach, with each method
(Euler’s, Runge-Kutta) implemented in separate functions. These
functions take in the differential equation, the initial
condition, and other parameters such as step size and number of
iterations, and return the solution at each time step. Key
MATLAB commands used include for loops for iteration, plot for
graphing the results, and ode45 for comparison with MATLAB’s
built-in solver.
Key Commands:
for: Used for looping through time steps.
plot: Plots the solution at each step.
ode45: MATLAB’s built-in ODE solver for comparison with the
numerical methods implemented in the program.
input: Collects user inputs for the differential equation,
initial conditions, etc.
Reference:
Kincaid, D. & Cheney, W. (2017). Numerical Analysis: Mathematics
of Scientific Computing (7th ed.). Brooks/Cole.
Burden, R. L., & Faires, J. D. (2010). Numerical Analysis (9th
ed.). Cengage Learning.
MATLAB Documentation. (n.d.). ode45: Runge-Kutta method.
Retrieved from
https://www.mathworks.com/help/matlab/ref/ode45.html
MATLAB CODE:
% Created by Geronimo & Gabriel
% Doolittle's Method for solving any nxn system of linear equations
% Ask the user to input the size of the system
MP1VAR1 = input('Enter the size of the system (n): ');
% Ask the user to input the coefficient matrix A
MP1VARA = input(['Enter the elements of the coefficient matrix A as an '
num2str(MP1VAR1) 'x' num2str(MP1VAR1) ' matrix (e.g., [1 1 1; 1 2 2; 1 2 3]):
']);
% Ask the user to input the constant vector b
MP1VARB = input(['Enter the elements of the constant vector b as a column
vector of size ' num2str(MP1VAR1) ' (e.g., [5; 6; 8]): ']);
% Initialize L and U matrices
MP1VARL = eye(MP1VAR1); % MP1VARL is initialized as an identity matrix
MP1VARU = zeros(MP1VAR1); % MP1VARU is initialized as a zero matrix
% Perform Doolittle's decomposition
for MP1VARK = 1:MP1VAR1
% Solve for the MP1VARK-th row of MP1VARU
MP1VARU(MP1VARK,MP1VARK:MP1VAR1) = MP1VARA(MP1VARK,MP1VARK:MP1VAR1) -
MP1VARL(MP1VARK,1:MP1VARK-1) * MP1VARU(1:MP1VARK-1,MP1VARK:MP1VAR1);
% Solve for the MP1VARK-th column of MP1VARL
for MP1VARI = MP1VARK+1:MP1VAR1
MP1VARL(MP1VARI,MP1VARK) = (MP1VARA(MP1VARI,MP1VARK) -
MP1VARL(MP1VARI,1:MP1VARK-1) * MP1VARU(1:MP1VARK-1,MP1VARK)) /
MP1VARU(MP1VARK,MP1VARK);
end
end
% Solve for Y from LY = b
MP1VARY = MP1VARL \ MP1VARB;
% Solve for X from UX = Y
MP1VARX = MP1VARU \ MP1VARY;
% Display the results
disp('LOWER = ');
disp(MP1VARL);
disp('UPPER = ');
disp(MP1VARU);
disp('VECTOR = ');
disp(MP1VARX);
APPENDICES:
SAMPLE OUTPUT #1:
SAMPLE OUTPUT #2:
SAMPLE OUTPUT #3: