Function Repository Resource:

Cofactor

Source Notebook

Get a cofactor of a matrix

Contributed by: Wolfram Staff

ResourceFunction["Cofactor"][m,{i,j}]

gives the (i,j) cofactor of the square matrix m.

Details

The (i,j) cofactor of a square matrix is, up to a change in sign, equal to the determinant of the matrix obtained by deleting the ith row and jth column.

Examples

Basic Examples (2) 

Here is the (1, 2) cofactor of a 3×3 matrix:

In[1]:=
ResourceFunction["Cofactor"][( {
   {0, 0, 0},
   {1, 0, 10},
   {10, 0, 1}
  } ), {1, 2}]
Out[1]=

The positively signed cofactor of the top left-hand corner of an array:

In[2]:=
ResourceFunction["Cofactor"][\!\(\*
TagBox[
RowBox[{"Array", "[", 
RowBox[{"C", ",", 
RowBox[{"{", 
RowBox[{"5", ",", "5"}], "}"}]}], "]"}],
Function[BoxForm`e$, 
MatrixForm[BoxForm`e$]]]\), {5, 5}] == Det[Array[C, {4, 4}]]
Out[2]=

Scope (4) 

Define a random 4×4 matrix:

In[3]:=
rm = RandomInteger[{0, 10}, {4, 4}];
MatrixForm[rm]
Out[3]=

Here is its determinant:

In[4]:=
Det[rm]
Out[4]=

Expand the determinant along the first row:

In[5]:=
Table[rm[[1, j]] ResourceFunction["Cofactor"][rm, {1, j}], {j, 1, Length[rm]}]
Out[5]=

Adding up gives the determinant again:

In[6]:=
Total[%]
Out[6]=

Properties and Relations (7) 

A 3×3 matrix:

In[7]:=
m = {{15, 3, 4}, {3, 15, 11}, {-2, 1, 7}};

Compute its cofactor matrix using the resource function CofactorMatrix:

In[8]:=
cm = ResourceFunction["CofactorMatrix"][m]
Out[8]=

The (i,j) cofactor is equal to the (i,j)th element of the cofactor matrix:

In[9]:=
i = 2; j = 3;
{ResourceFunction["Cofactor"][m, {i, j}], cm[[i, j]]}
Out[10]=

Compute its adjugate:

In[11]:=
adj = Adjugate[m]
Out[11]=

The (i,j) cofactor is equal to the (j,i)th element of the adjugate:

In[12]:=
i = 2; j = 3;
{ResourceFunction["Cofactor"][m, {i, j}], adj[[j, i]]}
Out[13]=

Compute its matrix of minors:

In[14]:=
mm = Minors[m]
Out[14]=

The (i,j) cofactor is, up to a change in sign, equal to the (n-i+1,n-j+1)th element of the matrix of minors:

In[15]:=
n = Length[m];
i = 2; j = 3;
{ResourceFunction["Cofactor"][m, {i, j}], (-1)^(i + j)
   mm[[n - i + 1, n - j + 1]]}
Out[17]=

Publisher

George Beck

Version History

  • 1.0.1 – 31 January 2022
  • 1.0.0 – 05 July 2019

Related Resources

License Information