Skip to contents

This function solves a tridiagonal system of equations of the form $$Ax = b$$ where the matrix \(A\) has the entries \(D_1, D_2, \dots, D_N\) on the main diagonal, \(L_2, L_3, \dots, L_N\) on the lower diagonal, and \(U_1, U_2, \dots, U_{N-1}\) on the upper diagonal.

Usage

solve_double_sweep(U, L, D, b)

Arguments

U

Upper diagonal entries. Even though the matrix only uses \(U_1\dots U_{N-1}\), you need to supply a full vector of length \(N\). The last element will be ignored.

L

Lower diagonal entries. Even though the matrix only uses \(L_2\dots L_N\), you need to supply a full vector of length \(N\). The first element will be ignored.

D

Main diagonal entries

b

Right-hand side vector

Value

A vector of solutions

Details

For more details on the double sweep method, see the vignette vignette("diffusion")

Examples

U <- c(1, 2, 3, NA)
L <- c(NA, 4, 5, 6)
D <- c(7, 8, 9, 10)
b <- c(11, 12, 13, 14)
solve_double_sweep(U, L, D, b)
#> [1] 1.4940867 0.5413929 0.8462549 0.8922470