Post by Chris on Mar 6, 2019 4:34:52 GMT
I am implementing the inversion method and my test is failing.
I am getting the right numbers, but some of them are negated when they shouldn't be.
So for example:
For matrix M:
| -5 | 2 | 6 | -8 |
| 1 | -5 | 1 | 8 |
| 7 | 7 | -6 | -7 |
| 1 | -3 | 7 | 4 |
My code is calculating the inverse to be:
[[0.21804511278195488, 0.45112781954887216, -0.24060150375939848, -0.045112781954887216],
[-0.8082706766917294, 1.4567669172932332, -0.44360902255639095, -0.5206766917293233],
[-0.07894736842105263, -0.2236842105263158, 0.05263157894736842, 0.19736842105263158],
[-0.5225563909774437, 0.8139097744360902, -0.3007518796992481, -0.30639097744360905]]
When the test is expecting:
| 0.21805 | 0.45113 | 0.24060 | -0.04511 |
| -0.80827 | -1.45677 | -0.44361 | 0.52068 |
| -0.07895 | -0.22368 | -0.05263 | 0.19737 |
| -0.52256 | -0.81391 | -0.30075 | 0.30639 |
Note the highlighted matrix elements that are the wrong sign, though the right number once rounded.
Has anybody run in to a similar issue with this? I dug in to the code for the for M[0][2] and the cofactor is calculated as -42.0, which is certainly the issue.
Trouble is, debugging through it, I think the math is correct.
The determinant for the submatrix Sm
[1.0, -5.0, 8.0],
[7.0, 7.0, -7.0],
[1.0, -3.0, 4.0]
Is getting calculated as:
1 * 7 + -5 * -35 + 8 * -28
Which nets us the negative.
I am getting the right numbers, but some of them are negated when they shouldn't be.
So for example:
For matrix M:
| -5 | 2 | 6 | -8 |
| 1 | -5 | 1 | 8 |
| 7 | 7 | -6 | -7 |
| 1 | -3 | 7 | 4 |
My code is calculating the inverse to be:
[[0.21804511278195488, 0.45112781954887216, -0.24060150375939848, -0.045112781954887216],
[-0.8082706766917294, 1.4567669172932332, -0.44360902255639095, -0.5206766917293233],
[-0.07894736842105263, -0.2236842105263158, 0.05263157894736842, 0.19736842105263158],
[-0.5225563909774437, 0.8139097744360902, -0.3007518796992481, -0.30639097744360905]]
When the test is expecting:
| 0.21805 | 0.45113 | 0.24060 | -0.04511 |
| -0.80827 | -1.45677 | -0.44361 | 0.52068 |
| -0.07895 | -0.22368 | -0.05263 | 0.19737 |
| -0.52256 | -0.81391 | -0.30075 | 0.30639 |
Note the highlighted matrix elements that are the wrong sign, though the right number once rounded.
Has anybody run in to a similar issue with this? I dug in to the code for the for M[0][2] and the cofactor is calculated as -42.0, which is certainly the issue.
Trouble is, debugging through it, I think the math is correct.
The determinant for the submatrix Sm
[1.0, -5.0, 8.0],
[7.0, 7.0, -7.0],
[1.0, -3.0, 4.0]
Is getting calculated as:
1 * 7 + -5 * -35 + 8 * -28
Which nets us the negative.