Inverse matrix in Matlab very different to Excel

2 Ansichten (letzte 30 Tage)
Rosie G
Rosie G am 10 Dez. 2019
Kommentiert: Fabio Freschi am 10 Dez. 2019
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 Kommentar
Jeremy
Jeremy am 10 Dez. 2019
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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Fabio Freschi
Fabio Freschi am 10 Dez. 2019
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 Kommentare
Rosie G
Rosie G am 10 Dez. 2019
Thank you so much for your fast reply, and I feel very foolish now!
Fabio Freschi
Fabio Freschi am 10 Dez. 2019
No problem, sometimes obvious things slip under the radar!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by