Hello everyone & welcome to MATLAB tutorial brought to you
by MATLABHelper. In this video tutorial
we will see Tridiagonal System in MATLAB
Certain matrix have a particular structure
that can be exploited to develop efficient solution
scheme
for example a bandit matrix is
square matrix that has all elements equal to 0
with exception of a band central
on the main diagonal
A tridiagonal system has a bandwidth of
3 and can be expressed generally
as this equation
where f are the diagonal components
e are the sub diagonal vectors
and g are the super
diagonal components; r in this equation
are known as right hand side vector
consider a problem; solve the following tridiagonal system
uses the given equation
theoretically the first step involve transforming
the matrix to upper triangular form
this is done by multiplying the first equation
by the factor e2/f1
and subtracting the result from second equation
it is as shown in equation
defined the value of f2 and r2
in the next step
we use back substitution to generate
the final solution
in which x4 is r4/f4
and then we find
x3, x2 and x1 using
a standard formula (r(n)-g(n)x(n+1)) / f(n)
so we get the final solution
now let us write a code
we write a function x = Tridiag(e,f,g,r)
where the inputs e are the
sub diagonal vectors; f is the diagonal vector
g is the super diagonal vector
and r is the right hand side vector
output is stored in x which is
a solution vector
we define n as length of f
which is our diagonal vector
which is also the dimension of matrix
next we apply forward elimination
as we see in the theoretical part
in forward elimination use the factor
e(k)/f(k-1)
we define that and find the value
for f(k) and r(k)
where the value of k is from 2 to n
n is the length of diagonal vector
next for back substitution
we know x(n) = r(n) / f(n)
and then we implement a for loop
to find x3, x2 and x1
to display the value of x(n)
we implement another for loop
with i from 1 to length of x
and we use fprintf to print the value
let us get the results
in command window first we define
e, f, g, and r from the given problem
so e from the given problem is 0 -1 -1 -1
f is 2.04 2.04 2.04 2.04
which are the diagonal components
similarly we define g and r
now we call tridiagonal function
Tridiag(e,f,g,r)
and here are the results
x1 = 65.96
x2 = 93
x3 = 124.53
x4 = 159.47
we compare this result with theoretical
value and we see
all the results to be same
hope you enjoyed the video
don't forget to hit the like button
also subscribe to our channel for updates
on more such videos
thank you
