Setting to reproduce my Minimal Working Example
I have the following matrix
K <- matrix(c(1.250000e+00, 3.366892e-07, 4.641930e-10, 1.455736e-08, 1.049863e-06,
3.366892e-07, 1.250000e+00, 5.482775e-01, 8.606555e-01, 9.776887e-01,
4.641930e-10, 5.482775e-01, 1.250000e+00, 8.603413e-01, 4.246732e-01,
1.455736e-08, 8.606555e-01, 8.603413e-01, 1.250000e+00, 7.490100e-01,
1.049863e-06, 9.776887e-01, 4.246732e-01, 7.490100e-01, 1.250000e+00), nrow=5)
and the following vector
y <- matrix(c(39.13892, 12.34428, 12.38426, 14.71951, 10.52160), nrow=5)
Problem
I want to calculate the product between the inverse of K
and the vector y
.
Naive Method - It works
The naive method works (I have a way of checking, but doesn't matter here)
solve(K) %*% y
[,1]
[1,] 31.3111308
[2,] 3.0620869
[3,] 3.7383357
[4,] 6.6257060
[5,] 0.7820081
Cholesky Decomposition - Fails
However the "clever" method fails. I use cholesky decomposition which gives me an upper triangular matrix. Then I solve the system L z = y
by backward substitution and the system L^T x = L^{-1} y
by forward substitution.
L <- chol(K) ## upper triangular
forwardsolve(t(L), backsolve(L, y))
[,1]
[1,] 31.31112
[2,] -14.16259
[3,] 9.84534
[4,] 39.67900
[5,] 33.54842
What is happening? This matrix K
and this vector 'y` are just an example. It happens with many other similar vectors and matrices. Why?