Wolfram Research

Function Repository Resource:

Cofactor (1.0.0) current version: 1.0.1 »

Source Notebook

Get a cofactor of a matrix

Contributed by: Wolfram Staff

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

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

Examples

Basic Examples

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[{"m", ",", 
RowBox[{"{", 
RowBox[{"5", ",", "5"}], "}"}]}], "]"}],
Function[BoxForm`e$, 
MatrixForm[BoxForm`e$]]]\), {5, 5}] == Det@Array[m, {4, 4}]
Out[2]=

Scope

Define a random 4×4 matrix:

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

Here is its determinant:

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

Expand the determinant along the first row:

In[5]:=
rm[[1, #]] ResourceFunction["Cofactor"][rm, {1, #}] & /@ Range@4
Out[5]=

Adding up gives the determinant again:

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

Version History

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

Related Resources

License Information