Generate a tridiagonal matrix with upperDiag as superdiagonal, lowerDiag as subdiagonal and mainDiag as diagonal.

tridiag(mainDiag, upperDiag, lowerDiag)

Arguments

mainDiag

Diagonal of tridiagonal matrix.

upperDiag

Superdiagonal of tridiagonal matrix. Must have length length(mainDiag) - 1.

lowerDiag

Subdiagonal of tridiagonal matrix. Must have length length(mainDiag) - 1.

Value

Tridiagonal matrix.

Examples

set.seed(987) mainDiag <- sample(100:110, size = 6, replace = TRUE) upperDiag <- sample(10:20, size = 5, replace = TRUE) lowerDiag <- sample(1:10, size = 5, replace = TRUE) tridiag(mainDiag, upperDiag, lowerDiag)
#> [,1] [,2] [,3] [,4] [,5] [,6] #> [1,] 105 14 0 0 0 0 #> [2,] 4 110 13 0 0 0 #> [3,] 0 2 106 19 0 0 #> [4,] 0 0 4 106 17 0 #> [5,] 0 0 0 2 108 12 #> [6,] 0 0 0 0 7 102