## Triangular decomposition of a covariance matrix
B <- matrix(c(1, -2, 0, 1,
0, 1, 0, 1,
0, 0, 1, 0,
0, 0, 0, 1), 4, 4, byrow=TRUE)
B
D <- diag(c(3, 1, 2, 1))
S <- B %*% D %*% t(B)
triDec(S)
solve(B)
Run the code above in your browser using DataLab