Function adas.xxtrisol

def xxtrisol(a, b, c, rhs)

Solves the tridiagonal systems of linear equations.

Parameters

a : float
vector of sub-diagonal elements.
b : float
vector of diagonal elements.
c : float
vector of super-diagonal elements.
rhs : float
vector of right hand side elements.

Returns

result : float
solution vector.

Notes

The specification of the input is based on the Numerical Recipes (tridag) and IDL (trisol) way of specifying the tri-diagonal matrix.

  [b0 c0 0 ...           ] [u0]   [r0]
  [a0 b1 c1 0 ...        ] [ :]   [ :]
  [ 0 a1 b2 c2 0 ...     ] [  ] = [  ]
  [                      ] [  ]   [  ]
  [ ...  0 an-1 bn-1 cn-1] [ :]   [ :]
  [        ... 0 an-1 bn ] [un]   [rn]

Pure python code.

References

Coding hints from:

http://jean-pierre.moreau.pagesperso-orange.fr/Fortran/tridiag_f90.txt http://userpages.irap.omp.eu/~bdintrans/docs/tridag.py

Version History

  • Martin O'Mullane, 29-03-2019
    • First version

Example

For the tridiagonal matrix system of equations,

  [-4.0  1.0  0.0  0.0] [u0]     [ 6.0]
  [ 2.0 -4.0  1.0  0.0] [u1]  =  [-8.0]
  [ 0.0  2.0 -4.0  1.0] [u2]     [-5.0]
  [ 0.0  0.0  2.0 -4.0] [u3]     [ 8.0]

the exact solution is u = [-1.0, 2.0, 2.0, -1.0]

>>> import adas as adas
>>> a=[0.0, 2.0, 2.0, 2.0]
>>> b=[-4.0, -4.0, -4.0, -4.0]
>>> c=[1.0, 1.0, 1.0, 0.0]
>>> rhs=[6.0, -8.0, -5.0, 8.0]
>>> adas.xxtrisol(a, b, c, rhs)
array([-1.,  2.,  2., -1.])