0% found this document useful (0 votes)
245 views

Computational Methods: Test Program For Chasing Method Developed in Matlab

The document describes a test program developed in Matlab to solve a system of linear equations using the chasing method. The test program considers a 10x10 tridiagonal matrix A with specified elements and a 10x1 column vector d. The chasing method is applied by factorizing the tridiagonal matrix A as L*R and then solving the system in two steps: first solving L*y = d for y, then solving R*x = y for x. The results of the test program are compared to using Matlab's built-in solving functions and the computation times are reported.

Uploaded by

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

Computational Methods: Test Program For Chasing Method Developed in Matlab

The document describes a test program developed in Matlab to solve a system of linear equations using the chasing method. The test program considers a 10x10 tridiagonal matrix A with specified elements and a 10x1 column vector d. The chasing method is applied by factorizing the tridiagonal matrix A as L*R and then solving the system in two steps: first solving L*y = d for y, then solving R*x = y for x. The results of the test program are compared to using Matlab's built-in solving functions and the computation times are reported.

Uploaded by

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

Computational Methods

(MATH600807)

Assignment-2
Test Program for Chasing Method Developed in
Matlab

Submitted By
Mujtaba Mujahid, Phd Scholar
Student id: 4119999176
Nuclear Safety and Operation Lab (NUSOL)
Department of Nuclear Science and Technology

Date of Submission
November 29, 2020
Table of Contents

1 Problem Formulation ....................................................................................................................... 2


2 Chasing Method .............................................................................................................................. 2
3 Matlab Code .................................................................................................................................... 3
4 Results ............................................................................................................................................. 4
5 Comments ....................................................................................................................................... 5

Page 1 of 5
1 Problem Formulation
Here the Test example is considered such that the coefficient matrix A be the 10 × 10 tridiagonal
matrix given by ai,i = 2, ai,i-1 = -1, ai-1,i = -1, for each i = 2; · · · ; 9, and a1,1 = a10,10 = 2; a1,2 = a10,9
= -1. Assume d be the ten-dimensional column vector given by d1 = d10 = 1 and di = 0, for each i
= 2, 3 · · · , 9. This problem will be solved with the help of Chasing Method as described below.

2 Chasing Method
If the coefficient matrix A = (aij) has a special structure, such as aij = 0 for all pairs
(i,j) satisfying |i – j| > 1. Thus, in the ith row, only ai,i-1; ai,i; ai,i+1 can be different
from 0.
Let be the system of tridiagonal matrix represented as

Where the invertible matrix A has the form

with the condition |b1|>|c1|, |bi| >= |ai| +|ci| for i= 2,……n-1 and |bn|>|an|. The pivoting technique
will not be applied since bi| >= |ai| +|ci|.
The Dolittle factorization applied to solve the tridiagonal system is known as Chasing method. A
tridiagonal matrix is factorized by dolittle method as

The equation 𝐴𝑥 = 𝑑 can now be written as

Page 2 of 5
𝑳𝑹𝒙 = 𝒅

Firstly from the equation 𝐿𝑦 = 𝑑, the value of y is calculated. In the end the value of x will be
calculated from the equation 𝑅𝑥 = 𝑦.

3 Matlab Code
The Matlab code for the Test Example described in Section1
%The following code is written by Mujtaba Mujahid, Phd Scholar
%Student id: 4119999176
%Nuclear Safety and Operation Lab (NUSOL)
%Assignment #2: Test Program for Chasing Method

% Test Example : Here the Test example is considered such that the coefficient matrix A be the
10 × 10 tridiagonal matrix given by ai,i = 2, ai,i-1 = -1, ai-1,i = -1, for each i = 2; · · · ; 9, and a1,1 =
a10,10 = 2; a1,2 = a10,9 = -1. Assume d be the ten-dimensional column vector given by d1 = d10 = 1
and di = 0, for each i = 2, 3 · · · , 9.

clc
clear all
A= zeros (10,10); %Initializing Matrix A as a zero matrix of 10*10
D= ones (10,1); %Initializing Matrix D as a ones matrix of 10*1
[n,~]= size(A); %n represents the number of rows in matrix A

%% Assigning the values to Matrix A, Matrix D, a(i),b(i),c(i)


A(1,1)=2; A(10,10)=2; A(1,2)=-1; A(10,9)=-1;
for i =2:1:10
A(i,i)=2; % Assigning the values to the Tridiagonal elements of matrix A
A(i,i-1)=-1;
A(i-1,i)=-1;

End

for i=2:1:9
D(i)=0; % Assigning the values to the Matrix D
end
for k=2:1:n
a(k)=-1;
end
for m=1:1:n-1
c(m)=-1;
end
for k=1:1:n
b(k)=2;
r(k)=0;

Page 3 of 5
Y(k)=0;
End
%% Solving the Test Example using In-built functions

f = linsolve(A,D); %In-built Function


z = mldivide(A,D); %In-built Function

%% To caluclate the values of Y


r(1)=b(1);
Y(1)=D(1);
for i=2:1:n
l(i)= a(i)/r(i-1);
Y(i)= D(i)-l(i)*Y(i-1);
r(i)= b(i)-l(i)*c(i-1);
end
%% To calulate the values of X
x(n)= Y(n)/r(n);
for i =n-1:-1:1
x(i)=(Y(i)-c(i)*x(i+1))/(r(i));
end

4 Results
The results of the above mentioned example is tabulated below
Test Example Result using Result Result using
Matrices General using Mldivide
Algorithm of Linsolve function in
Gaussian function in Matlab
Elimination Matlab
scripted in
Matlab

z=
x= f=

Page 4 of 5
5 Comments

The Test Program of Chasing Method developed in Matlab has the following characteristics
1) First of all using For Loops, The matrix A and D has been assigned values
2) Then the value of values of tridiagonal has been stored in vector a(i), b(i) and c(i)
3) From the equation 𝐿𝑦 = 𝑑, the value of y is calculated and after that the value of x will
be calculated from the equation 𝑅𝑥 = 𝑦.
4) The result of the test program developed in Matlab is compared with the in-built
functions (Linsolve & Mldivide) and it is presented in Section 4.
5) The total Computation Time (Elapsed time) found (using tic toc commands) from the
inbuilt function (f = linsolve (A,D)) is approximately 0.0134 sec.
6) The total Computation Time (Elapsed time) found (using tic toc commands) from the
inbuilt function (f = mldivide (A,D)) is approximately 0.0166 sec.
7) The total Computation Time (Elapsed time) found (using tic toc commands) from the test
program developed in Matlab using the Chasing Method is approximately 0.0357 sec.
8) The total Computation Time (Elapsed time) using the test program is more than the
computation time of in-built functions because in the test program, the data from the
tridiagonal was fetched and stored in the variables a(i), b(i) and c(i), so it took some extra
time.

Page 5 of 5

You might also like