0% found this document useful (0 votes)
149 views3 pages

Thomas Algorithm

The Thomas algorithm is an efficient method for solving tridiagonal matrix systems. It involves rewriting the matrix system as Mx=r in the form of LUx=r, where L is a lower triangular matrix and U is an upper triangular matrix. The algorithm consists of two stages: 1) The matrix is decomposed into M=LU form through a series of row operations, converting the system to Ux=ρ. 2) The converted system Ux=ρ is then solved for x in an upwards sweep, starting from the last row. Through successive row operations, the matrix is transformed into an upper triangular form, allowing the system of equations to be efficiently solved from bottom to top in two swe
Copyright
© Attribution Non-Commercial (BY-NC)
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)
149 views3 pages

Thomas Algorithm

The Thomas algorithm is an efficient method for solving tridiagonal matrix systems. It involves rewriting the matrix system as Mx=r in the form of LUx=r, where L is a lower triangular matrix and U is an upper triangular matrix. The algorithm consists of two stages: 1) The matrix is decomposed into M=LU form through a series of row operations, converting the system to Ux=ρ. 2) The converted system Ux=ρ is then solved for x in an upwards sweep, starting from the last row. Through successive row operations, the matrix is transformed into an upper triangular form, allowing the system of equations to be efficiently solved from bottom to top in two swe
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 3

Tridiagonal Matrices: Thomas Algorithm

W. T. Lee
MS6021, Scientific Computation, University of Limerick
The Thomas algorithm is an efficient way of solving tridiagonal matrix systems. It is based on LU decomposition in which the matrix system M x = r is rewritten as LU x = r where L is a lower triangular matrix and
U is an upper triangular matrix. The system can be efficiently solved by setting U x = and then solving first
L = r for and then U x = for x. The Thomas algorithm consists of two steps. In Step 1 decomposing the
matrix into M = LU and solving L = r are accomplished in a single downwards sweep, taking us straight
from M x = r to U x = . In step 2 the equation U x = is solved for x in an upwards sweep.
I. STAGE 1

In the first stage the matrix equation M x = r is converted


to the form U x = . Initially the matrix equation looks like:
b1
a2

0
0
0

c1
b2
a3
0
0
0

0
c2
b3
a4
0
0

0
0
c3
b4
a5
0

0
0
0
c4
b5
a6


0
x1
r1
0 x2 r2

0 x3 r3
=
0 x4 r4
c5 x5 r5
x6
r6
b6

Row 2 a2 x1 +
b2 x2 +c2 x3 = r2
a2 1 x 2
= a2 1
a2 Row 1 a2 x1 +
New Row 2
(b2 a2 1 ) x2 +c2 x3 = r2 a2 1
Divide through by (b2 a2 1 ) to get
x1 +

c2
r2 a2 1
x2 =
b2 a 2 1
b2 a 2 1

We can rewrite this as


x2 + 2 x3 = 2 ,

2 =

c2
,
b2 a 2 1

2 =

r2 a2 1
.
b2 a 2 1

Row 1

1
0

0
0

b1 x1 + c1 x2 = r1
Divide through by b1
x1 +

c1
r1
x2 =
b1
b1

1
1
a3
0
0
0

0
2
b3
a4
0
0

0
0
c3
b4
a5
0

0
0
0
c4
b5
a6


0
x1
1

0 x2 2


0 x3 r3
=

0
x4 r4

c5 x5 r5
b6
x6
r6

Rewrite:
x1 + 1 x2 = 1 ,

1
a2

0
0
0

1
b2
a3
0
0
0

0
c2
b3
a4
0
0

0
0
c3
b4
a5
0

1 =

0
0
0
c4
b5
a6

c1
,
b1

1 =

r1
b1


0
x1
1
0 x2 r2

0 x3 r3
=
0 x4 r4
c5 x5 r5
b6
r6
x6

Row 2.

Row 3.
a3 x2 + b3 x3 + c3 x4 = r3
Use a3 times row 2 of the matrix to eliminate the first term
a3 (x2 + 2 x3 = 2 )
Row 3 a3 x2 +
b3 x3 +c3 x4 = r3
a3 Row 2 a3 x2 +
a3 2 x 3
= a3 2
New Row 3
(b3 a3 2 ) x3 +c3 x4 = r3 a3 2
Divide through by (b3 a3 2 ) to get

a2 x1 + b2 x2 + c2 x3 = r2
x2 +
Use a2 times row 1 of the matrix to eliminate the first term
a2 (x1 + 1 x2 = 1 )

We can rewrite this as


x3 + 3 x4 = 3 ,

http://www3.ul.ie/wlee;

[email protected]

c3
r3 a3 2
x3 =
b3 a 3 2
b3 a 3 2

3 =

c3
,
b3 a 3 2

3 =

r3 a3 2
.
b3 a 3 2

1
0

0
0

1
1
0
0
0
0

0
2
1
a4
0
0

0
0
3
b4
a5
0

0
0
0
c4
b5
a6


0
x1
1
x
0
2 2

0 x3 3
=

0
x4 r4

c5 x5 r5
r6
b6
x6

Row 4.

1
0

0
0

1
1
0
0
0
0

0
2
1
0
0
0

0
0
3
1
0
0

0
0
0
4
1
a6


0
x1
1
x
0
2 2

0 x3 3
=

0
x4 4

5 x5 5
x6
b6
r6

Row 6
a4 x3 + b4 x4 + c4 x5 = r4

a6 x5 + b6 x6 = r6

Use a4 times row 3 of the matrix to eliminate the first term

Use a6 times row 5 to eliminate the first term.

a4 (x3 + 3 x4 = 3 )

a6 x5 + a6 5 x6 = a6 5

b4 x4 +c4 x5 = r4
Row 4 a4 x3 +
a4 Row 3 a4 x3 +
a4 3 x 4
= a4 3
New Row 4
(b4 a4 3 ) x4 +c4 x5 = r4 a4 3

Resulting in
(b6 a6 5 ) x6 = r6 a6 5
Divide through by b6 a6 5 to get

Divide through by (b4 a4 3 ) to get

x6 = 6 ,

c4
r4 a4 3
x3 +
x4 =
b4 a 4 3
b4 a 4 3
We can rewrite this as
x4 + 4 x5 = 4 ,

1
0

0
0

1
1
0
0
0
0

4 =

0
2
1
0
0
0

0
0
3
1
a5
0

c4
,
b4 a 4 3

0
0
0
4
b5
a6

4 =

r4 a4 3
.
b4 a 4 3


0
x1
1
x
0
2 2

0 x3 3
=

0
x4 4

c5 x5 r5
b6
x6
r6

1
0

0
0

1
1
0
0
0
0

0
2
1
0
0
0

0
0
3
1
0
0

6 =

0
0
0
4
1
0

r6 a6 5
b6 a 6 5


0
x1
1
x
0
2 2

0 x3 3
=

0
x4 4
5 x5 5
1

x6

At this point the matrix has been reduced to upper diagonal


form, so our equations are in the form U x = .
II. STAGE 2

Row 5.
a5 x4 + b5 x5 + c5 x6 = r5
Use a5 times row 4 of the matrix to eliminate the first term

The matrix equation is now in a form which is trivial to


solve for x. We start with the last row and work our way up.
The final equation is already solved
x6 = 6 .

a5 (x4 + 4 x5 = 4 )
b5 x5 +c5 x6 = r5
Row 5 a5 x4 +
a5 Row 4 a5 x4 +
a5 4 x 5
= a5 4
New Row 5
(b5 a5 4 ) x5 +c5 x6 = r5 a5 4
Divide through by (b5 a5 4 ) to get
x4 +

c5
r5 a5 4
x5 =
b5 a 5 4
b5 a 5 4

We can rewrite this as


x5 + 5 x6 = 5 ,

5 =

c5
,
b5 a 5 4

5 =

r5 a5 4
.
b5 a 5 4

1
0

0
0

1
1
0
0
0
0

0
2
1
0
0
0

0
0
3
1
0
0

0
0
0
4
1
0


0
x1
1
x
0
2 2

0 x3 3
=

0
x4 4
5 x5 5
1

x6

3
Row 5: x5 + 5 x6 = 5 .
Rearrange to get: x5 = 5 5 x6 .

1
0

0
0

1
1
0
0
0
0

0
2
1
0
0
0

0
0
3
1
0
0

0
0
0
4
1
0

Row 1: x1 + 1 x2 = 1 .
Rearrange to get: x1 = 1 1 x2 .


0
x1
1
x
0
2
2

0 x3 3
=

0
x4 4
5 x5 5
1

x6

Row 4: x4 + 4 x5 = 4 .
Rearrange to get: x4 = 4 4 x5 .

1
0

0
0

1
1
0
0
0
0

0
2
1
0
0
0

0
0
3
1
0
0

0
0
0
4
1
0


0
x1
1
x
0
2
2

0 x3 3
=

0
x4 4
5 x5 5
1

x6

At this point x, the solution to the matrix equation, is fully


determined.
III. IN PRACTICE

1
0

0
0

1
1
0
0
0
0

0
2
1
0
0
0

0
0
3
1
0
0

0
0
0
4
1
0


0
x1
1
x
0
2
2

0 x3 3
=

0
x4 4
5 x5 5
1

x6

Row 3: x3 + 3 x4 = 3 .
Rearrange to get: x3 = 3 3 x4 .

1
0

0
0

1
1
0
0
0
0

0
2
1
0
0
0

0
0
3
1
0
0

0
0
0
4
1
0


0
x1
1

0
x2 2

0 x3 3
=

0
x4 4

5 x5 5
1
6
x6

Row 2: x2 + 2 x3 = 2 .
Rearrange to get: x2 = 2 2 x3 .

1
0

0
0

1
1
0
0
0
0

0
2
1
0
0
0

0
0
3
1
0
0

0
0
0
4
1
0


0
x1
1

0 x2 2


0 x3 3
=

0
x4 4

5 x5 5
6
1
x6

The Thomas algorithm is used because it is fast and because tridiagonal matrices often occur in practice. (This argument is slightly circular because people often manipulate
the problems they are working on to reduce them to solving a
tridiagonal matrix problem.) Although it is rare, the algorithm
can be unstable if bi ai i1 is zero or numerically zero for
any i. This will occur if the tridiagonal matrix is singular, but
in rare cases can occur if it is non-singular. The condition for
the algorithm to be stable is
kbi k > kai k + kci k
for all i. The matrix problems which result from the discretisation of partial differential equations nearly all satisfy this
criterion.
If the algorithm is numerically unstable then you must rearrange the equations: known as pivoting. Standard LU decomposition algorithms for full or banded matrices include
pivoting. (But first you should check to make sure you have
not made a mistake in formulating the problem.)

You might also like