AlexUA
September 7, 2015, 2:58pm
1
As the title suggests, I have some problems with a TMatrixD that does not behave completely as I like it. It needs to be inverted and as a test I can simply multiply the inverse with the original. Please find the matrix, its inverse and the product below.
How can I calculate the inverse with full efficiency?
Any help you can provide is most welcome!
Cheers,
Alex
TMatrixD mInvertCovariance = (*mCovariance);
mInvertCovariance.Invert();
mCovariance->Print();
mInvertCovariance.Print();
mInvertCovariance *= (*mCovariance);
mInvertCovariance.Print();
22x22 matrix is as follows
| 4 | 5 | 6 | 7 | 8 |
4 | 3.594e+11 -3.334e+11 -7.897e+10 6.194e+10 -1.415e+11
5 | 1.825e+11 -6.708e+10 -4.285e+10 7.096e+08 -3.88e+10
6 | 1.347e+11 -1.527e+11 -3.196e+10 3.08e+10 -6.076e+10
7 | 8.151e+10 -8.084e+10 -1.985e+10 1.263e+10 -3.206e+10
8 | 3.467e+10 -3.969e+10 -8.241e+09 6.134e+09 -1.507e+10
9 | 2.136e+10 -1.819e+10 -5.213e+09 2.654e+09 -7.544e+09
10 | 1.297e+10 -8.868e+09 -3.059e+09 4.481e+08 -3.743e+09
11 | 9.336e+09 -9.19e+09 -2.452e+09 1.349e+09 -3.568e+09
12 | 5.866e+09 -4.513e+09 -1.245e+09 4.522e+08 -1.929e+09
13 | 4.291e+09 -3.785e+09 -1.18e+09 5.164e+08 -1.495e+09
14 | 2.131e+09 -2.679e+09 -4.507e+08 4.236e+08 -1.009e+09
15 | 1.252e+09 -1.868e+09 -2.626e+08 3.093e+08 -6.763e+08
16 | 8.869e+08 -1.656e+09 -1.736e+08 2.963e+08 -5.793e+08
17 | 3.428e+08 -1.158e+09 -4.327e+07 2.172e+08 -3.752e+08
18 | 1.125e+08 -1.074e+09 1.343e+07 2.261e+08 -3.308e+08
19 | 2.24e+08 -5.798e+08 -4.072e+07 1.048e+08 -1.914e+08
20 | 1.086e+08 -4.903e+08 -1.136e+07 9.434e+07 -1.543e+08
21 | -1.834e+07 -4.229e+08 2.567e+07 8.97e+07 -1.237e+08
22 | 5.011e+07 -2.376e+08 -9.344e+06 5.045e+07 -7.476e+07
23 | 6.179e+07 -1.43e+08 -1.298e+07 2.222e+07 -4.636e+07
24 | 7.538e+07 -1.109e+08 -1.617e+07 1.615e+07 -3.94e+07
25 | 2.791e+07 -7.829e+07 -3.755e+06 1.369e+07 -2.573e+07
| 9 | 10 | 11 | 12 | 13 |
4 | 4.522e+10 2.716e+10 5.227e+08 5.365e+08 6.34e+09
5 | 3.003e+10 9.121e+09 1.332e+08 -3.521e+09 1.943e+09
6 | 1.324e+10 1.194e+10 -5.731e+08 1.093e+09 2.255e+09
7 | 1.138e+10 6.071e+09 -3.924e+08 2.865e+08 1.136e+09
8 | 5.417e+09 2.591e+09 -1.375e+08 3.425e+08 5.401e+08
9 | 2.983e+09 1.504e+09 -9.071e+07 -3.86e+07 2.758e+08
10 | 2.647e+09 6.42e+08 -1.033e+07 -8.349e+07 1.533e+08
11 | 1.242e+09 7.116e+08 -9.057e+07 2.337e+07 1.019e+08
12 | 1.161e+09 3.114e+08 2.776e+07 -1.538e+07 9.585e+07
13 | 5.357e+08 3.239e+08 -5.335e+07 -8.345e+06 3.593e+07
14 | 3.852e+08 1.524e+08 5.043e+06 3.3e+07 4.284e+07
15 | 2.313e+08 9.684e+07 2.086e+06 3.07e+07 2.74e+07
16 | 1.683e+08 7.695e+07 2.994e+06 3.485e+07 2.356e+07
17 | 9.464e+07 3.712e+07 4.883e+06 3.45e+07 1.587e+07
18 | 4.873e+07 2.756e+07 5.308e+06 3.889e+07 1.401e+07
19 | 5.034e+07 2.216e+07 8.092e+05 1.52e+07 7.39e+06
20 | 3.313e+07 1.454e+07 1.555e+06 1.575e+07 6.178e+06
21 | 1.794e+07 6.055e+06 3.449e+06 1.777e+07 5.742e+06
22 | 7.018e+06 9.146e+06 -4.55e+05 7.383e+06 2.425e+06
23 | 1.57e+07 5.203e+06 -1.221e+05 3.54e+06 1.605e+06
24 | 1.593e+07 5.298e+06 5.77e+04 1.828e+06 1.541e+06
25 | 8.099e+06 2.463e+06 4.216e+05 2.205e+06 1.139e+06
| 14 | 15 | 16 | 17 | 18 |
4 | 1.914e+09 3.5e+09 -2.416e+09 6.485e+08 -1.561e+09
5 | 1.02e+09 9.244e+08 -8.929e+08 6.035e+08 -4.813e+08
6 | 5.646e+08 1.438e+09 -9.239e+08 1.164e+08 -6.614e+08
7 | 3.683e+08 7.732e+08 -5.907e+08 1.493e+08 -3.865e+08
8 | 1.671e+08 3.771e+08 -2.952e+08 6.769e+07 -1.882e+08
9 | 9.83e+07 1.795e+08 -1.399e+08 4.362e+07 -9.034e+07
10 | 7.48e+07 9.761e+07 -9.793e+07 4.639e+07 -5.346e+07
11 | 3.468e+07 8.212e+07 -6.432e+07 1.499e+07 -4.389e+07
12 | 3.837e+07 5.238e+07 -4.68e+07 2.033e+07 -2.543e+07
13 | 1.381e+07 3.259e+07 -2.602e+07 6.577e+06 -1.839e+07
14 | 1.284e+07 2.693e+07 -2.118e+07 5.124e+06 -1.275e+07
15 | 7.468e+06 1.814e+07 -1.406e+07 2.672e+06 -8.604e+06
16 | 5.571e+06 1.58e+07 -1.183e+07 1.545e+06 -7.326e+06
17 | 3.026e+06 1.089e+07 -8.146e+06 5.166e+05 -4.922e+06
18 | 1.747e+06 9.798e+06 -6.822e+06 -3.851e+05 -4.248e+06
19 | 1.498e+06 5.339e+06 -4.033e+06 3.132e+05 -2.5e+06
20 | 9.949e+05 4.473e+06 -3.299e+06 5.032e+04 -2.033e+06
21 | 6.415e+05 3.918e+06 -2.785e+06 -1.871e+05 -1.653e+06
22 | 1.991e+05 1.999e+06 -1.321e+06 -1.761e+05 -9.209e+05
23 | 3.791e+05 1.291e+06 -1.066e+06 1.367e+05 -6.462e+05
24 | 4.595e+05 1.073e+06 -8.92e+05 1.994e+05 -5.297e+05
25 | 2.536e+05 7.58e+05 -5.927e+05 7.25e+04 -3.458e+05
| 19 | 20 | 21 | 22 | 23 |
4 | -5.416e+07 -3.291e+08 5.319e+07 -2.822e+07 -7.143e+06
5 | 2.607e+07 -2.314e+08 1.797e+07 -8.775e+06 -7.911e+06
6 | -4.643e+07 -4.252e+07 2.211e+07 -1.126e+07 -1.712e+06
7 | -1.326e+07 -4.489e+07 1.084e+07 -5.837e+06 -1.347e+06
8 | -4.957e+06 -2.24e+07 4.576e+06 -2.685e+06 -2.837e+05
9 | -2.522e+06 -1.36e+07 2.72e+06 -1.413e+06 -4.909e+05
10 | 2.328e+06 -1.652e+07 1.144e+06 -7.176e+05 -3.384e+05
11 | -2.016e+06 -1.79e+06 1.199e+06 -6.142e+05 -1.657e+05
12 | 9.951e+05 -9.269e+06 6.142e+05 -3.929e+05 -1.293e+05
13 | -9.998e+05 -249.1 5.317e+05 -2.52e+05 -1.001e+05
14 | -1.013e+05 -2.48e+06 2.845e+05 -1.867e+05 -1578
15 | -1.334e+05 -1.326e+06 1.767e+05 -1.21e+05 1.3e+04
16 | -1.652e+05 -9.518e+05 1.406e+05 -1.018e+05 2.515e+04
17 | -8.558e+04 -6.017e+05 6.77e+04 -6.349e+04 3.617e+04
18 | -1.43e+05 -3.051e+05 5.063e+04 -5.421e+04 4.571e+04
19 | -6.076e+04 -2.318e+05 3.868e+04 -3.199e+04 1.441e+04
20 | -5.185e+04 -1.664e+05 2.545e+04 -2.521e+04 1.741e+04
21 | -3.079e+04 -1.759e+05 1.193e+04 -2.005e+04 2.252e+04
22 | -6.397e+04 5.023e+04 1.509e+04 -1.163e+04 7895
23 | -7761 -5.655e+04 8278 -7409 3279
24 | -996.7 -8.673e+04 9306 -6885 844.9
25 | -788.3 -5.816e+04 4578 -4445 2230
| 24 | 25 |
4 | 7.919e+05 4.97e+06
5 | 4.876e+05 1.965e+06
6 | -2.341e+05 2.096e+06
7 | 7.994e+04 1.308e+06
8 | 1.225e+05 6.167e+05
9 | 1.236e+04 3.156e+05
10 | 9.018e+04 1.967e+05
11 | -1.639e+04 1.554e+05
12 | 5.406e+04 8.574e+04
13 | -1.776e+04 6.863e+04
14 | 1.91e+04 3.935e+04
15 | 1.265e+04 2.592e+04
16 | 1.157e+04 2.101e+04
17 | 1.112e+04 1.285e+04
18 | 1.006e+04 9968
19 | 4389 6935
20 | 4378 5214
21 | 5308 3520
22 | 837.1 2407
23 | 1141 1905
24 | 901.4 1636
25 | 875.2 923.6
| 4 | 5 | 6 | 7 | 8 |
4 | 4748 -1.058e+04 565.3 -3.132e+04 -3.919e+04
5 | 1452 -663.3 8400 1.864e+04 2.064e+04
6 | 1.182e+04 -5.815e+04 -4.913e+04 -1.594e+05 -9.21e+04
7 | -6822 -389.7 -3.297e+04 -96.15 -2.968e+05
8 | -3282 -1.777e+04 2.36e+04 -1.47e+04 -1.773e+04
9 | -4.649e+04 2.33e+05 5.709e+04 1.087e+05 4.858e+05
10 | -4.668e+04 1.06e+05 2774 7.343e+05 -2.115e+05
11 | 1.4e+05 -1.832e+05 4.232e+05 1.028e+05 -4.504e+05
12 | 4.372e+04 9.503e+04 2.886e+05 1.854e+05 1.372e+06
13 | -6.152e+04 -4.465e+05 -5.038e+04 -1.034e+06 1.244e+06
14 | 1.385e+06 -4.508e+06 -3.922e+06 -3.041e+06 -8.302e+06
15 | -2.63e+05 4.047e+05 1.395e+06 1.113e+06 4.338e+06
16 | -1.121e+05 -1.289e+04 -2.57e+05 7.923e+05 2.093e+06
17 | 7.791e+05 -5.552e+06 -2.487e+06 2.135e+06 -7.912e+06
18 | -1.136e+06 2.018e+06 4.711e+05 3.399e+06 7.058e+06
19 | 2.941e+06 -4.998e+07 -1.308e+07 -3.344e+07 -7.728e+07
20 | 1.661e+06 -1.605e+07 -7.302e+06 -8.395e+06 5.957e+06
21 | -3.729e+06 -2.411e+07 1.153e+08 6.837e+07 3.372e+08
22 | 2.503e+07 3.73e+07 1.916e+08 2.625e+08 -4.065e+08
23 | 3.934e+07 -1.863e+08 -5.807e+07 3.109e+08 -7.193e+08
24 | -3.615e+08 1.054e+09 2.205e+08 2.28e+09 2.414e+09
25 | 2.48e+08 -1.595e+09 2.627e+08 -1.664e+09 -2.378e+09
| 9 | 10 | 11 | 12 | 13 |
4 | 9303 3437 4621 -6.809e+04 2.873e+05
5 | -4.515e+04 6.827e+04 -2.352e+05 4.373e+05 1.485e+05
6 | 3.92e+05 -3.35e+04 1.131e+06 -1.56e+06 -8.736e+05
7 | 5.014e+05 -4.078e+05 -8.526e+05 4.151e+06 2.689e+06
8 | -1.102e+04 5.378e+04 4.356e+05 -7.828e+05 -4.845e+05
9 | -1.914e+05 -3.158e+05 -2.954e+06 5.512e+06 5.472e+06
10 | 1.104e+06 -4.846e+05 -6.419e+06 1.232e+07 7.123e+06
11 | 3.666e+05 2.479e+06 -8.551e+06 3.034e+07 2.695e+07
12 | -2.213e+06 1.463e+06 -1.21e+06 -6.817e+06 -8.935e+06
13 | -3.063e+06 4.346e+06 2.212e+07 -6.114e+07 -5.507e+07
14 | 3.468e+07 -2.043e+07 -2.757e+07 1.608e+08 1.072e+08
15 | -2.803e+06 -3.446e+05 -4.22e+06 1.413e+07 2.38e+07
16 | -5.459e+06 5.518e+06 1.23e+06 -1.619e+07 -8.781e+06
17 | 2.601e+06 4.613e+06 2.614e+07 1.35e+07 -9.403e+07
18 | 2.33e+05 -7.811e+06 -1.547e+07 6.684e+07 8.329e+06
19 | 2.481e+08 8.48e+07 4.021e+08 -4.809e+08 -1.156e+09
20 | 6.589e+07 -6.383e+06 3.225e+07 3.559e+08 2.37e+06
21 | -1.067e+09 5.024e+08 2.024e+09 -2.415e+09 -5.705e+09
22 | -6.883e+08 -6.271e+08 -1.385e+09 9.019e+09 5.093e+09
23 | 6.215e+08 2.21e+08 -5.043e+09 1.124e+10 7.13e+09
24 | -7.087e+09 -3.352e+09 -2.078e+09 1.213e+10 -5.824e+08
25 | -1.92e+09 1.012e+10 3.565e+10 -5.738e+10 -5.187e+10
| 14 | 15 | 16 | 17 | 18 |
4 | 6.743e+05 4.535e+05 7.777e+05 -2.465e+05 -1.082e+05
5 | -1.534e+06 -3.756e+05 -2.125e+06 -7.988e+05 -4.145e+06
6 | 7.331e+06 -3.305e+05 6.371e+06 1.958e+06 2.129e+07
7 | -4.484e+06 -9.814e+05 -4.92e+06 2.531e+06 -1.825e+07
8 | 2.991e+06 -1.403e+06 2.153e+06 -8.574e+05 3.378e+05
9 | -3.23e+07 5.033e+06 -2.839e+07 9.77e+06 -4.471e+07
10 | -3.207e+07 5.377e+06 -5.112e+07 -5.871e+06 -6.735e+07
11 | -6.791e+07 -5.051e+07 -9.585e+07 8.43e+06 -2.051e+08
12 | -6.955e+06 -1.817e+07 -1.657e+07 4.633e+06 -3.453e+07
13 | 1.853e+08 5.68e+07 1.391e+08 -2.184e+07 2.664e+08
14 | 2.591e+07 -1.851e+08 -2.197e+08 1.672e+08 -4.674e+08
15 | -1.858e+08 -3.372e+07 -1.699e+08 2.487e+08 -8.619e+07
16 | 2.342e+07 7.554e+07 8.906e+07 2.438e+07 -7.552e+07
17 | 5.514e+08 -2.745e+08 1.894e+08 6.828e+07 1.556e+09
18 | -2.404e+08 7.475e+07 -4.968e+08 3.753e+08 -4.142e+07
19 | 6.175e+09 3.487e+08 5.156e+09 -2.334e+09 5.934e+08
20 | 1.172e+09 -4.522e+08 -6.909e+08 -2.432e+08 -1.439e+09
21 | 2.145e+09 -1.688e+09 8.603e+09 -1.26e+10 6.416e+09
22 | -3.748e+10 -3.443e+08 -3.14e+10 1.421e+10 -5.807e+10
23 | -1.798e+10 9.769e+09 -1.505e+10 -1.2e+10 -1.804e+10
24 | -4.93e+10 4.341e+10 -8.948e+10 -9.577e+10 -1.868e+11
25 | 2.224e+11 -4.319e+10 1.966e+11 -3.765e+10 2.699e+11
| 19 | 20 | 21 | 22 | 23 |
4 | -2.477e+06 3.853e+04 -3.464e+05 -7.173e+06 8.087e+06
5 | 1.071e+06 -6.761e+04 3.762e+06 1.867e+07 2.105e+06
6 | 1.189e+07 -2.601e+05 -1.108e+07 -9.424e+07 -6.811e+07
7 | -9.885e+06 3.702e+06 1.562e+07 1.297e+08 -4.04e+07
8 | 1.318e+06 7.898e+06 2.744e+06 -4.969e+07 7.628e+06
9 | 2.471e+07 7.3e+05 2.156e+07 3.026e+08 -1.754e+08
10 | -1.327e+08 6.254e+07 8.001e+07 5.22e+08 2.997e+07
11 | -1.595e+08 1.257e+08 3.613e+08 6.215e+08 5.368e+08
12 | -4.007e+07 4.721e+07 -9.099e+06 -1.993e+07 3.32e+08
13 | 1.831e+08 -4.124e+07 -3.421e+08 -1.747e+09 -1.021e+08
14 | -6.102e+08 2.587e+08 9.444e+07 2.794e+09 -6.345e+08
15 | 2.174e+08 -5.275e+08 2.566e+08 -3.524e+08 -4.613e+08
16 | -3.563e+08 1.234e+08 -1.321e+08 3.222e+08 -8.333e+08
17 | 1.332e+08 8.111e+08 -8.78e+08 -4.416e+09 -6.777e+08
18 | -1.262e+08 -6.596e+08 -4.196e+08 3.5e+09 -2.87e+09
19 | -1.725e+10 -2.097e+09 2.166e+09 -1.772e+10 3.838e+10
20 | -4.112e+09 1.911e+09 3.597e+09 5.761e+09 -1.593e+09
21 | 1.794e+10 -7.945e+09 -1.388e+09 -1.247e+11 1.126e+11
22 | -4.896e+09 -1.585e+10 4.818e+10 1.533e+11 2.099e+11
23 | -2.034e+10 3.397e+09 -3.792e+10 2.567e+11 7.882e+10
24 | -2.379e+11 1.179e+11 2.619e+11 1.118e+12 -2.828e+11
25 | 6.828e+10 -4.313e+10 -9.365e+10 -2.608e+12 4.738e+11
| 24 | 25 |
4 | 1.408e+07 -1.129e+07
5 | -1.344e+07 5.211e+07
6 | 2.35e+08 -4.295e+08
7 | -8.095e+07 1.592e+08
8 | 1.298e+07 -4.07e+07
9 | -3.926e+08 1.083e+09
10 | -4.893e+08 1.224e+09
11 | -1.404e+09 2.254e+09
12 | 2.024e+08 2.425e+08
13 | 1.806e+09 -5.302e+09
14 | 1.519e+09 1.038e+09
15 | -1.107e+09 5.974e+09
16 | -7.128e+08 1.29e+09
17 | 1.559e+10 -3.98e+10
18 | -3.057e+09 1.175e+10
19 | 1.675e+10 -1.145e+11
20 | 3.462e+09 -2.421e+10
21 | 2.356e+10 -1.148e+11
22 | -3.431e+11 1.105e+12
23 | -2.845e+11 5.193e+11
24 | -1.864e+12 4.128e+12
25 | 2.215e+12 -6.052e+12
| 4 | 5 | 6 | 7 | 8 |
4 | 2.062 0.375 -0.07031 0.09375 -0.6875
5 | 0.25 -1 0.1562 -0.125 -0.25
6 | 0 0 1.75 -2 0
7 | -1.5 -10 1.125 0.75 0
8 | -0.25 0.5 0 0.375 0.625
9 | -4 -16 -2 6 -8
10 | 24 -80 2 -4 -8
11 | -80 0 11 4 40
12 | 11 -24 -8.75 5 -3
13 | -64 64 8 -16 80
14 | -104 -496 12 6 -100
15 | 32 -64 4 16 0
16 | -8 -16 1 4 -16
17 | -256 0 64 0 256
18 | -64 -256 24 32 64
19 | -2560 1024 -512 256 512
20 | -256 -2304 112 192 -512
21 | 512 1.024e+04 384 1280 3072
22 | 0 0 1024 2048 8192
23 | 1.434e+04 -8192 -4864 0 -2048
24 | 1.638e+04 -6.554e+04 8192 8192 1.638e+04
25 | 6.554e+04 1.966e+05 8192 1.638e+04 -3.277e+04
| 9 | 10 | 11 | 12 | 13 |
4 | 0.1094 0.0625 -0.008789 0.01172 0
5 | 0.3125 0 0.003906 0.04688 -0.007812
6 | -0.5 0 -0.03125 0 0.0625
7 | 0.75 -0.25 -0.03906 0.1875 0.0625
8 | 0.125 0 -0.01953 0.01562 -0.01562
9 | 3 1 0.125 0 0.25
10 | 2 2.5 0.0625 -0.5 0.75
11 | 8 -5 1.625 1 -0.5
12 | 1.25 0.5 0 1.75 0.2188
13 | 16 -10 2 -2 0
14 | 13 -2 0.625 8 4
15 | -8 2 -0.5 4 0
16 | 2 -1 0.0625 1 1.5
17 | 0 -32 6 -32 -8
18 | -16 0 0 0 0
19 | -640 -192 -32 96 0
20 | 32 56 2 40 28
21 | -1280 -768 56 64 -16
22 | 1024 0 64 512 256
23 | 5632 1536 -224 -512 128
24 | 0 -2048 512 0 1024
25 | -2.458e+04 -8192 -1536 0 3072
| 14 | 15 | 16 | 17 | 18 |
4 | -0.004395 0.007812 -0.01074 0.002563 -0.001953
5 | 0.001953 0.007812 -0.003906 0.002441 0
6 | -0.01562 -0.125 -0.09375 -0.003906 0
7 | 0 0.0625 -0.04688 -0.009766 0.02344
8 | 0.001953 -0.003906 -0.003906 0.003906 0.009766
9 | 0.125 0.125 -0.25 0.0625 -0.1875
10 | 0.125 0.25 -0.25 0.0625 -0.125
11 | -0.25 0 0.25 -0.0625 0
12 | 0.1016 0.1875 0.0625 0.03711 -0.04688
13 | -0.5 -1.5 0 0 0.5
14 | 2.219 3.375 -3 -0.0625 -0.5625
15 | 0.25 1 0.5 -0.125 0
16 | 0.0625 0.125 1.25 0.03125 0.25
17 | -2 -4 4 0.5 2
18 | -0.5 0 -1 -0.75 1.5
19 | -16 -16 32 4 24
20 | 3 28 -4 1.25 -5
21 | -20 -80 8 -8 56
22 | 64 256 0 32 -64
23 | 32 128 -64 48 -64
24 | 0 512 0 0 -512
25 | -512 -512 -512 192 512
| 19 | 20 | 21 | 22 | 23 |
4 | -2.098e-05 0.0001221 9.155e-05 -6.104e-05 2.289e-05
5 | 0.000145 -0.0009766 6.104e-05 -0.0001221 3.052e-05
6 | -0.001038 -0.003906 0 0.0002441 0
7 | 0.001099 0 -0.0001221 -0.0004883 -0.0001831
8 | -0.0009651 0 0.0003052 -6.104e-05 4.578e-05
9 | 0.005737 0.007812 0.001953 -0.0009766 0
10 | 0.002441 -0.01562 0.0009766 -0.003906 -0.001465
11 | 0.02441 0.01562 -0.005859 -0.005859 0.007812
12 | -0.001129 -0.005859 0.008301 -0.001465 0.0004272
13 | -0.002441 -0.1875 -0.01953 0 0.003906
14 | -0.03882 -0.02344 0.0166 0.00293 0.01074
15 | -0.02051 0.0625 0.007812 -0.003906 0.001953
16 | 0.004883 -0.0625 0.00293 0 0
17 | 0.02344 0 -0.0625 0 0.01562
18 | -0.01953 0 -0.01562 0.02344 -0.003906
19 | -0.07812 4 -0.0625 0.0625 0.0625
20 | -0.2812 1 0.1406 -0.07812 0.07812
21 | -2.578 5 1.125 0.5625 -0.09375
22 | 3.25 0 -2 1 0.5
23 | -5.312 8 2 -2 -0.25
24 | 19 -64 4 4 6
25 | -11 64 0 16 -4
| 24 | 25 |
4 | -3.815e-06 2.48e-05
5 | 0 -1.526e-05
6 | 0 6.104e-05
7 | -3.052e-05 3.052e-05
8 | -7.629e-06 5.341e-05
9 | 0.0002441 0.0001221
10 | 0.0004883 0.0002441
11 | 0.001465 -0.0007324
12 | 3.052e-05 0.0007019
13 | 0 -0.001953
14 | 0.001099 -0.001221
15 | 0 0.0009766
16 | 0.0007324 0
17 | 0 0
18 | 0.001953 -0.005859
19 | -0.03125 0.01562
20 | 0.01172 0.01562
21 | -0.0625 -0.09375
22 | 0.25 0
23 | -0.1875 0.0625
24 | 1 0
25 | -2 1
moneta
September 29, 2015, 4:20pm
2
Hi,
Have you tried other decompositions ?
See root.cern.ch/how/how-invert-matrix
Also what is the condition number of the matrix ?
Lorenzo
Check also the User’s Guide for explanation of condition number:
root.cern.ch/root/htmldoc/guide … ion-number
and also have a look at
tutorials/matrix/invertMatrix.C
tobi_s
October 7, 2015, 12:28pm
4
Since your matrix carries “Covariance” in its name, I assume that it is symmetric and positive-definite. In that case you should be using a Cholesky decomposition (TDecompChol is ROOT’s implementation) to calculate the inverse.
In an ideal world
one formulates the problem such that one never inverts matrices. Instead, one uses the decompositions to solve linear 1D problems, and
one doesn’t use the covariance matrices for calculations but their square roots (these are the matrices corresponding to the triangular matrix H in the definition of the Cholesky decomposition, C=HH^t), as the square roots are better conditioned in general. Most formulas that typically appear can be decomposed into formulas on square roots
E.g., in the matrix generalization of the Pythagorean theorem which goes like
C3 = C1+C2 with H1, H2, H3 the corresponding square roots, i.e. this equation is equivalent to
H3 H3^t=H1 H1^t + H2 H2^t, which we can rewrite as (sorry for the awkward notation with the double transpose, but I don’t see a LaTeX input option which would allow me to write columns; the objects in parentheses are block matrices; th dot denotes matrix multiplication)
H1 H1^t + H2 H2^t = (H1^t,H2^t) . (H1^t,H2^t)^t
Now (H1^t,H2^t)^t can be brought into upper triangle form (a triangle of the same dimensions as H1, followed by an equal number of zero rows) by an orthogonal transformation O, O^t = O^-1. Call the triangle H3. That is (I’m wrting the transposed because I cannot write columns)
(H1^t,H2^t) = (H3^t, 0).O^t,
and thus
H1 H1^t + H2 H2^t = (H3^t, 0).O^t.O.(H3^t,0)^t = H3^t.H3,
and we have obtained the square root of C3 using square roots only (notice how the dimensionality magically reduces in the second equality, first the orthogonal transformation pops away, then the zero entries do the rest). In practice the orthogonal transformation needs not be calculated explicitly, one can calculate H3 directly using a sequence of householder transformations. Finally, if one needs inverses somewhere, inverting triangular matrices is dirt cheap.
Another example would be a similarity transformation (say, error propagation with a Jacobian): instead of J.C.J^t one calculates J.H (or, if need be, the triangular J.H.O with O an orthogonal transformation).
Sorry for indulging, but I found this a very satisfying extension of my knowledge of linear algebra
Hi Tobi,
Thanks for that nice explanation.
Each TDecomp{Chol,LU,QR,SVD,…) has a “Solve” method that calculates the solution
of a linear equation without inverting the matrix !
Actually, the Invert() method of the decomposition class uses Solve with a unit matrix.
-Eddy
tobi_s
October 8, 2015, 9:05am
6
[quote=“Eddy Offermann”]Each TDecomp{Chol,LU,QR,SVD,…) has a “Solve” method that calculates the solution
of a linear equation without inverting the matrix !
Actually, the Invert() method of the decomposition class uses Solve with a unit matrix.[/quote]Hi Eddy,
absolutely, it’s good that you point this out. Just to clarify (to our audience ), what I was trying to say was that actually calculating the inverse is wasteful in most all circumstances, because one usually is interested in a vector, and not the inverse matrix itself. E.g. in a typical linear problem
A x = b
the solution is (existence of the inverse provided)
x = A^-1 b
But of course, one never needs to calculate A^-1. Once the matrix is decomposed one simply solves one time, instead of actually evaluating the second equation. Doing that would involve solving once for each column of the (inverse) matrix (i.e. “[one] uses Solve with a unit matrix”), followed by the matrix multiplication. Of course this is more expensive and numerically less stable because of the superfluous intermediate calculation. Similar considerations extend to least-squares problems.