error running getting started code
조회 수: 2 (최근 30일)
이전 댓글 표시
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
답변 (2개)
Jatin
2024년 9월 19일
편집: Jatin
2024년 9월 19일
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
Steven Lord
2024년 9월 19일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear Algebra에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!