This is documentation for Mathematica 5, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)

Documentation / Mathematica / Add-ons & Links / Standard Packages / LinearAlgebra /


There are many numerical techniques for working with matrices of specific forms. Often these routines are far more efficient than the general case. Frequently, the best way to get an efficient general routine is to reduce the problem systematically to a special case that can be solved efficiently.

In addition, special forms of matrices often come up naturally in solving certain classes of problems. One very useful special type of matrix is the tridiagonal. In these matrices all elements are zero except for elements on the main, super-, and subdiagonal. More precisely, if . Tridiagonal matrices occur in a wide variety of applications, such as the construction of certain splines and the solution of boundary value problems.

Solving matrix equations with tridiagonal matrices.

This loads the package.

In[1]:= <<LinearAlgebra`Tridiagonal`

This defines the list that will give the nonzero diagonals of a matrix.

In[2]:= {a, b, c} =
{{7, 1, 11}, {4, 8, 2, 12}, {5, 9, 3}}


Here is the matrix m constructed from the list.

In[3]:= m = Table[Switch[
j-i, -1, a[[j]], 0, b[[j]], 1,
c[[j-1]], _, 0], {i, 4}, {j, 4}]


This displays the matrix using MatrixForm.

In[4]:= MatrixForm[%]


This gives the vector x that solves the equation m.x == {2, 3, 4, 5}.

In[5]:= TridiagonalSolve[a, b, c, {2, 3, 4, 5}]


TridiagonalSolve uses Gaussian elimination and back substitution. No pivoting is done. If a pivot happens to be zero, this introduces an Infinity. If the matrix is diagonally dominate, which is the case in certain applications, no pivoting is necessary.

You can solve equations containing real and complex numbers as well as symbolic quantities.

In[6]:= TridiagonalSolve[
{2.2, 5.2},
{4.3, 3.22, 2.1},
{8.1 + I, 3.4},
{1, 2.3 I , 3}]