error running getting started code
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
When I run the code from teh learning module "getting started" to muiltiply the matrix by it's inverse I do not get the example output.
"p = a*inv(a)
p = 3×3
1.0000 0.0000 -0.0000
0 1.0000 -0.0000
0 0.0000 1.0000"
Instead I get a warning and p = infinite values:
"a =
1 3 5
2 4 6
7 8 9
>> p=a*inv(a)
Warning: Matrix is singular to working precision.
p =
Inf Inf Inf
Inf Inf Inf
Inf Inf Inf"
WHy is this happening?
0 Commenti
Risposte (2)
Jatin
il 19 Set 2024
Modificato: Jatin
il 19 Set 2024
The warning "Matrix is singular to working precision" occurs when the matrix you're trying to invert, is close to being singular or is singular. A singular matrix is one that does not have an inverse, which can happen when its determinant is zero.
The formula for the inverse of a matrix involves dividing the cofactor matrix by the determinant of the matrix. When the matrix is singular, this operation essentially becomes division by zero, leading to "inf" values.
For example, the determinant of the matrix used in your case.
a = [1 3 5; 2 4 6; 7 8 9];
det(a)
The matrix used in MATLAB's inv documentation is different, with a non-zero determinant. As a result, performing the operation "a*inv(a)" does not produce the warning.
I hope this answers your question.
0 Commenti
Steven Lord
il 19 Set 2024
If you're using this matrix:
a = [1 3 5
2 4 6
7 8 9];
the warning is correct. The matrix you've provided is singular; it has no inverse. One way to see this is to note that the second column of the matrix is 0.5 times the first column plus 0.5 times the third column.
secondColumn1 = a(:, 2);
secondColumn2 = 0.5*a(:, 1) + 0.5*a(:, 3);
isequal(secondColumn1, secondColumn2)
I'm guessing the 'learning module "getting started" ' used a different matrix, one that is invertible. For example here's one with a nice pattern that is invertible:
A = [1 3 6; 2 5 8; 4 7 9]
invA = inv(A)
format longg
A*invA % Should be close to the 3-by-3 identity matrix
0 Commenti
Vedere anche
Categorie
Scopri di più su Linear Algebra in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!