2
$\begingroup$

I need to calculate the minor of a matrix. I am going to use Mathematica example here,

(mat = Table[i^2 + i j + j^3, {i, 4}, {j, 4}]) // MatrixForm;

Minors[mat, 3, Identity] // MatrixForm;

Minors[mat] // MatrixForm;

Since I am going to calculate the minors of big matrices and I only need to know the diagonal elements, is there a way just to calculate the diagonal elements in minor matrix?

$\endgroup$
1
  • $\begingroup$ Can't you use Diagonal instead of Identity in your second example ? $\endgroup$ Feb 28, 2015 at 21:59

2 Answers 2

4
$\begingroup$

Update: You can also use Part

Det[mat[[#, #]]] & /@ Reverse[Subsets[Range[Length@mat] , {3}]]
(* {-36, -288, -252, -24} *)

Grid[{MatrixForm@#, Det@#} & /@ (mat[[#, #]] & /@ 
    Reverse[Subsets[Range[Length@mat] , {3}]]), Dividers -> All]

enter image description here

Determinants of 2X2 submatrices on the diagonal:

Grid[{MatrixForm@#, Det@#} & /@ (mat[[#, #]] & /@ 
    Reverse[Subsets[Range[Length@mat] , {2}]]), Dividers -> All]

enter image description here


Original post:

mat = Table[i^2 + i j + j^3, {i, 4}, {j, 4}]

Det[Drop[mat, {#}, {#}]] & /@ Range[Length@mat]
{-36, -288, -252, -24}

Timings for random 100X100 real and integer matrices:

tstmat = RandomReal[100, {100, 100}];
(res1 = Det[Drop[tstmat, {#}, {#}]] & /@ Range[Length@tstmat]); // AbsoluteTiming // First
(* 0.156253 *)
(res2 = Diagonal@Minors[tstmat]); // AbsoluteTiming // First
(* 1.596787 *)
res1 == Reverse@res2
(* True *)

tstmat2 = RandomInteger[100, {100, 100}];
(res1 = Det[Drop[tstmat2, {#}, {#}]] & /@ Range[Length@tstmat2]); // AbsoluteTiming // First
(* 1.234382 *)
(res2 = Diagonal@Minors[tstmat2]); // AbsoluteTiming // First
(* 125.368340 *)
res1 == Reverse@res2
(* True *)
$\endgroup$
3
  • $\begingroup$ Hi Kguler, Thanks for replying me back, it seems a efficient way, I am trying to apply it for my own program where I need to calculate the Minors[mat,k] where k changes from zero to the size of mat. Where k=3, i will get what you have described above, but for k=2, now the Minors matrix becomes 6x6 matrix(4!/(2! (4 - 2)!)). How I can I use Drop function to avoid calculating the off-diagonal element of minors? $\endgroup$
    – setareh
    Mar 9, 2015 at 22:49
  • 1
    $\begingroup$ @setareh, please see the update. $\endgroup$
    – kglr
    Mar 10, 2015 at 8:52
  • $\begingroup$ Hi kguler, I am trying to use this method to run my code, $\endgroup$
    – setareh
    Apr 5, 2015 at 17:44
1
$\begingroup$
Diagonal @ Minors[mat]

(* {-24, -252, -288, -36} *)

$\endgroup$
1
  • 2
    $\begingroup$ "Since I am going to calculate the minors of big matrices and I only need to know the diagonal elements, is there a way just to calculate the diagonal elements in minor matrix?" — Surely, performance is an issue here. $\endgroup$
    – rm -rf
    Feb 28, 2015 at 22:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.