You are on page 1of 4

Tridiagonal Matrix Problems

In numerical uid mechanics it is very common that the solution of a problem, once discretized, lies in the inversion of a tri-diagonal matrix. This is because the discretization results in an algebraic problem, the solution of a set on N linear algebraic equations in N unknowns. Typically these equations are neighbour equations, linking the value of the dependent variable T (I) to its neighbours T (I 1), T (I + 1) , and if there is more than one space dimension, to the other neighbours. This every-way linkage is most clearly seen when the
2

operator (the Laplacian operator - diusion opera-

tor - smoothing operator) is present in the equation, but can also arise from the discretisation of other types of terms in the dierential equations. Only when higher-order computational molecules are employed to reduce truncation error (a relatively rare event, since it necessitates provision of special algorithms at interior points adjacent to boundaries, and the same objective, reduced error, can be achieved simply by reducing the grid interval), or when higher than second order spatial derivatives appear, does the regional inuence upon T (I) extend beyond its immediate neighbours. The implication of this is that when elliptic equations are discretised to yield an implicit algorithm (all values T (1), T (2), ...T (I 1), T (I), T (I + 1),...T (N ) interdependent), the resulting set of N equations in N unknowns constitutes a tridiagonal matrix inversion problem. An example will best show this. Consider the elliptic (ie. jury type)

equation
2

T =

2T = S(x) , x [0, 1] x2

(1)

subject to boundary conditions T (0) = 0, T (1) = 1. The discretization equation is: T (I + 1) + T (I 1) 2 T (I) = S(I) x2 and we will set x = 1/3 and employ only two interior points: We have four equations: (2)

1 T(1) 1 T(1) 0 T(1) 0 T(1)

+ 0 T(2) + 0 T(3) + 0 T(4) = 0 - 2 T(2) + 1 T(3) + 0 T(4) = x2 S(2) + 1 T(2) - 2 T(3) + 1 T(4) = x2 S(3) + 0 T(2) + 0 T(3) + 1 T(4) = 1

1 0 0 0 1 2 1 0 In matrix form this is AIJ TJ = DI where AIJ is the matrix A = 0 1 2 1 0 0 0 1 You can see the tridiagonal structure. Note that if we had imposed the condition T /x = 0 at x = 0 and x = 1, leading to T (1) = T (2) and T (3) = T (4) the matrix elements A12 and A43 would be -1 instead of 0, and on the rhs D4 = 0 instead of 1. To solve such tridiagonal matrix problems we use a tridiagonal matrix algorithm.

A TDMA Algorithm in C
Consider that the neighbour equations have been written in the general form: a[i] t[i] = b[i] t[i + 1] + c[i] t[i 1] + d[i], for i = m, m + 1, ...n (3)

where t[] is the dependent variable, the a[], b[], c[] are the neighbour-inuence coecients, and the d[] are the everything else terms. There are n m + 1 equations in n m + 1 unknowns. In the following C function, p[] and q[] are used for intermediate storage.

void tdma(m,n,a,b,c,d,t) int m,n; float a[],b[],c[],d[],t[]; { int k; float denom; float p[20],q[20]; p[m]=b[m]/a[m];q[m]=d[m]/a[m]; for(j=m+1;j<=n;++j){ denom=a[j]-c[j]*p[j-1]; p[j]=b[j]/denom; q[j]=(d[j]+c[j]*q[j-1])/denom; } t[n]=q[n]; for(k=1;k<=n-m;++k){ 3

j=n-k; t[j]=p[j]*t[j+1]+q[j]; } return(); }

You might also like