How to get the cofactor matrix of any given square matrix (singular or non singular)?

150 visualizaciones (últimos 30 días)
Even if the order of matrix is 3x3,4x4 or higher and especially when determinant=0 and we can't use inv().

Respuesta aceptada

John D'Errico
John D'Errico el 24 de Ag. de 2022
Editada: John D'Errico el 24 de Ag. de 2022
The matrix of cofactors is moderately well posed, even when the matrix is itself singular. Of course, what you would do with it is your choice. But the simple answer is to just use loops, since each element of the matrix of cofactors is itself just a lower order determaint. But why, when we already have adjoint? For example, the 4x4 magic square produced by magic:
A = magic(4)
A = 4×4
16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1
rank(A)
ans = 3
While it is a magic square, the matrix is itself singular. So we coiuld not use the determinant of the matrix itself. However, you can just use the adjoint function.
help adjoint
ADJOINT Adjoint of the square matrix A. X = ADJOINT(A) computes a matrix X of the same dimensions as A such that A*X = det(A)*eye(n) = X*A, where n is the number of rows of A. Example: X = adjoint(hilb(5)) See also SYM/ADJOINT, DET, INV, RANK. Documentation for adjoint doc adjoint Other functions named adjoint sym/adjoint
format short g
adjoint(A)
ans = 4×4
1.0e+00 * -136 -408 408 136 -408 -1224 1224 408 408 1224 -1224 -408 136 408 -408 -136
If A were in fact non-singular, for example:
B = hilb(3)
B = 3×3
1 0.5 0.33333 0.5 0.33333 0.25 0.33333 0.25 0.2
rank(B)
ans =
3
adjoint(B)
ans = 3×3
0.0041667 -0.016667 0.013889 -0.016667 0.088889 -0.083333 0.013889 -0.083333 0.083333
We can see that for the non-singular matrix B, the adjoint divided by the determinant does produce an "inverse".
inv(B) - adjoint(B)/det(B)
ans = 3×3
1.0e+00 * 1.954e-14 -7.1054e-14 4.9738e-14 -8.5265e-14 3.6948e-13 -2.8422e-13 7.4607e-14 -3.1264e-13 1.9895e-13
Would you want to use this to compute the inverse? Of course not. You never want to use the determinant to do virtually anything.

Más respuestas (0)

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by