MATRIX COFACTOR
이전 댓글 표시
I need to know a function to calculate the cofactor of a matrix, thank a lot!
댓글 수: 7
Quilee Simeon
2018년 8월 21일
cofactor matrix for a matrix A is just det(A)*inv(A)
Zoe Herrick
2018년 9월 14일
편집: Walter Roberson
2018년 9월 15일
det(A)*inv(A) gives the adjugate or classical adjoint of matrix A which is the Transpose of the cofactor matrix.
This wiki article gives a brief layout of this:
Franco Salcedo Lópezz
2019년 11월 14일
Here I leave this code, I hope it helps. Regards..
function v = adj(M,i,j)
t=length(M);
v=zeros(t-1,t-1);
ii=1;
ban=0;
for k=1:t
jj=1;
for m=1:t
if ( (i~=k)&&(j~=m) )
v(ii,jj)=M(k,m);
jj++;
ban=1;
endif
endfor
if(ban==1)ii++;ban=0;endif
endfor
Walter Roberson
2020년 2월 6일
ii++ is not valid MATLAB though. And endif and endfor are not MATLAB either.
Fernando Salinas
2020년 11월 10일
I wrote this in GNU/Octave but I guess it should work on MATLAB
function cofactor = matrizCofactores(A)
[rows, cols] = size(A);
if rows == cols
for i = 1 : rows,
for j = 1 : cols,
Menor = A;
Menor(i,:) = [];
Menor(:,j) = [];
if mod((i+j),2) == 0
cofactor(i,j) = det(Menor);
else
cofactor(i,j) = -det(Menor);
endif
endfor
endfor
endif
endfunction
Natasha St Hilaire
2021년 10월 7일
What is "menor" short for?
Walter Roberson
2021년 10월 8일
I suspect that the English word would be "minor". The Spanish word "menor" can be translated as English "minor" in some situations.
채택된 답변
추가 답변 (2개)
Dr. Murtaza Ali Khan
2019년 9월 28일
A = [
2 4 1
4 3 7
2 1 3
]
detA = det(A)
invA = inv(A)
cofactorA = transpose(detA*invA)
댓글 수: 2
Franco Salcedo Lópezz
2019년 11월 14일
편집: Franco Salcedo Lópezz
2019년 11월 14일
Here I leave this code, I hope it helps. Regards
function v = adj(M,i,j)
t=length(M);
v=zeros(t-1,t-1);
ii=1;
ban=0;
for k=1:t
jj=1;
for m=1:t
if ( (i~=k)&&(j~=m) )
v(ii,jj)=M(k,m);
jj++;
ban=1;
endif
endfor
if(ban==1)ii++;ban=0;endif
endfor
Walter Roberson
2021년 10월 11일
This is not MATLAB code. It might be Octave.
Francisco Trigo
2020년 2월 6일
0 개 추천
The matrix confactor of a given matrix A can be calculated as det(A)*inv(A), but also as the adjoint(A). And this strange, because in most texts the adjoint of a matrix and the cofactor of that matrix are tranposed to each other. But in MATLAB are equal. I found a bit strange the MATLAB definition of the adjoint of a matrix.
댓글 수: 1
Zuhri Zuhri
2021년 9월 28일
adjoint matrix is the transpose of the cofactor matrix so the above result is correct
카테고리
도움말 센터 및 File Exchange에서 Performance and Memory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!