Inverse matrix in Matlab very different to Excel

3 次查看(过去 30 天)
Replicating calculations carried out in Excel in Matlab in order to learn. Inverting the matrix below gave a very different answer in Matlab to excel.
Original Matrix:
1322252 0 2010 -1006
0 1322252 1006 2010
2010 1006 4 0
-1006 2010 0 4
Inverted Matrix using inv(matrix)
1.68867574048431e-05 5.0821976835258e-21 -0.00848559559593365 0.00424701948731803
5.0821976835258e-21 1.68867574048431e-05 -0.00424701948731803 -0.00848559559593364
-0.00848559559593365 -0.00424701948731803 5.58213718801715 -1.28379263845227e-15
0.00424701948731803 -0.00848559559593364 -1.28379263845227e-15 5.58213718801714
Inverted Matrix using Excel
1.68868e-05 -1.34343e-20 -0.008485596 0.004247019
2.82121e-20 1.68868e-05 -0.004247019 -0.008485596
-0.008485596 -0.004247019 5.582137188 -6.91897e-15
0.004247019 -0.008485596 6.91897e-15 5.582137188
Inverting the below matrix did work as expected (same answer in Excel and Matlab)
419 163 1 0
-163 419 0 1
586 340 1 0
-340 586 0 1
  1 个评论
Jeremy
Jeremy 2019-12-10
This is probably a case of different methods and/or numerical tolerances. The results are approximately the same, 5.0821976835258e-21 and -1.34343e-20 are both essentially zero

请先登录,再进行评论。

采纳的回答

Fabio Freschi
Fabio Freschi 2019-12-10
The answer is not very different. As Jeremy commented, the results are similar a part from numerical tolerances. You can verify yourself comparing the matrices. In the following I load your matrices (note that excel data have less digits):
A1 = [ 1.68867574048431e-05 5.0821976835258e-21 -0.00848559559593365 0.00424701948731803
5.0821976835258e-21 1.68867574048431e-05 -0.00424701948731803 -0.00848559559593364
-0.00848559559593365 -0.00424701948731803 5.58213718801715 -1.28379263845227e-15
0.00424701948731803 -0.00848559559593364 -1.28379263845227e-15 5.58213718801714];
A2 = [ 1.68868e-05 -1.34343e-20 -0.008485596 0.004247019
2.82121e-20 1.68868e-05 -0.004247019 -0.008485596
-0.008485596 -0.004247019 5.582137188 -6.91897e-15
0.004247019 -0.008485596 6.91897e-15 5.582137188];
Then you can compare the two matrices entry-by-entry:
A1-A2
ans =
-4.2595e-11 1.8516e-20 4.0407e-10 4.8732e-10
-2.3130e-20 -4.2595e-11 -4.8732e-10 4.0407e-10
4.0407e-10 -4.8732e-10 1.7150e-11 5.6352e-15
4.8732e-10 4.0407e-10 -8.2028e-15 1.7140e-11
And you can see the errors are "small" in absolute value (the largest difference is at the 10th digit)
As a global index you can use the (relative) norm of the matrices
norm(A1-A2)/norm(A1)
ans =
1.1581e-10
  2 个评论
Rosie G
Rosie G 2019-12-10
Thank you so much for your fast reply, and I feel very foolish now!
Fabio Freschi
Fabio Freschi 2019-12-10
No problem, sometimes obvious things slip under the radar!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by