Class ThomasSolver
java.lang.Object
net.finmath.finitedifference.solvers.ThomasSolver
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 rowi,diag[i]contains the main diagonal entry for rowi,upper[i]contains the super-diagonal entry for rowi,rhs[i]contains the right-hand side entry for rowi.
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 Summary
Modifier and TypeMethodDescriptionstatic double[]solve(double[] lower, double[] diag, double[] upper, double[] rhs) Solves a tridiagonal linear system using the Thomas algorithm.
-
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, wheren >= 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. Entrylower[i]represents the coefficient below the main diagonal in rowi. The valuelower[0]is not used.diag- The main diagonal of the system matrix. Entrydiag[i]represents the diagonal coefficient in rowi.upper- The upper diagonal of the system matrix. Entryupper[i]represents the coefficient above the main diagonal in rowi. The valueupper[n-1]is not used in the final row.rhs- The right-hand side vector of the linear system.- Returns:
- The solution vector
xsatisfying the tridiagonal system.
-