Inverse matrix in Matlab very different to Excel

조회 수: 5 (최근 30일)
Rosie G
Rosie G 2019년 12월 10일
댓글: Fabio Freschi 2019년 12월 10일
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에서 Data Import from MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by