Class ThomasSolver

java.lang.Object
net.finmath.finitedifference.solvers.ThomasSolver

public final class ThomasSolver extends Object
Utility class providing an implementation of the Thomas algorithm for solving a tridiagonal linear system.

The method solves a system of the form

[ d0  u0   0   ...                ] [x0]   [r0]
[ l1  d1  u1   0   ...            ] [x1] = [r1]
[  0  l2  d2  u2   0   ...        ] [x2]   [r2]
[              ...                ] [...]  [...]
[          ... l(n-1) d(n-1)      ] [xn]   [rn]
where:
  • lower[i] contains the sub-diagonal entry for row i,
  • diag[i] contains the main diagonal entry for row i,
  • upper[i] contains the super-diagonal entry for row i,
  • rhs[i] contains the right-hand side entry for row i.

By convention, lower[0] is unused and may be set to any value, and upper[n-1] is unused by the backward substitution step.

This solver runs in linear time and is intended for non-singular tridiagonal systems. No validation of input sizes or pivot values is performed.

Author:
Alessandro Gnoatto
  • Method Details

    • solve

      public static double[] solve(double[] lower, double[] diag, double[] upper, double[] rhs)
      Solves a tridiagonal linear system using the Thomas algorithm.

      The input arrays represent the three diagonals of the tridiagonal matrix and the right-hand side vector. All arrays are expected to have identical length n, where n >= 1.

      The algorithm consists of a forward elimination phase followed by a backward substitution phase.

      Note: The caller must provide arrays of consistent length and a non-singular tridiagonal system.

      Parameters:
      lower - The lower diagonal of the system matrix. Entry lower[i] represents the coefficient below the main diagonal in row i. The value lower[0] is not used.
      diag - The main diagonal of the system matrix. Entry diag[i] represents the diagonal coefficient in row i.
      upper - The upper diagonal of the system matrix. Entry upper[i] represents the coefficient above the main diagonal in row i. The value upper[n-1] is not used in the final row.
      rhs - The right-hand side vector of the linear system.
      Returns:
      The solution vector x satisfying the tridiagonal system.