Example 5.2.1

This notebook contains a manipulation which illustrates Example 5.2.1 of the text.  This example illustrates the cofactor expansion of a matrix along any row or column (along with the resultant arithmetic if you want).  The computation is shown for a single level of recursion - that is, a 4×4 determinent is broken down into 4 3×3 determinants, which are then done immediately if you want to see the computation to its end.

The reason for only going down a single level is that in general an n×n determinant invovles breaking the computation into n! small determinants (where the "small" determinants are 1×1 determinants, which are easy).  As n grows, n! gets extremely large, which means the computations you would get would be too long to follow easily.

If you do want to see a computation done with all of its parts, you can use the second copy of the manipulation to break down any part further (below, the second copy of the manipulation shows how to break down the first 3×3 determinant in the original).

DeletedMatrix[mat_,{i_,j_}]:= Transpose[Drop[ Transpose[ Drop[mat,{i}]],{j}]];

RowExpansion1[mat_, i_]:= Block[ {n,j,row},
 n=Length[mat];
row=Table[ {Superscript[-1, StringJoin[ToString[i],"+",ToString[j]]]," × ", mat[[i,j]],  " × ","Det[",MatrixForm[DeletedMatrix[mat,{i,j}]],"] + "},{j,1,n}];
Return[ Row[Join[Delete[Flatten[row],-1],{"]"} ]]]
];

RowExpansion2[mat_, i_]:= Block[ {n,j,row},
 n=Length[mat];
row=Table[ {(-1)^(i+j)," × ", mat[[i,j]],  " × ",Det[DeletedMatrix[mat,{i,j}]]," + "},{j,1,n}];
Return[ Row[Join[ {"= "},Delete[Flatten[row],-1]]]]
];

RowExpansion3[mat_, i_]:= Block[ {n,j,row},
 n=Length[mat];
row=Table[ {(-1)^(i+j) mat[[i,j]]Det[DeletedMatrix[mat,{i,j}]]," + "},{j,1,n}];
Return[ Row[Join[ {"= "},Delete[Flatten[row],-1]]]]
];

ColumnExpansion3[mat_, i_]:= Block[ {n,j,row},
 n=Length[mat];
row=Table[ {(-1)^(i+j) mat[[j,i]]Det[DeletedMatrix[mat,{j,i}]]," + "},{j,1,n}];
Return[ Row[Join[ {"= "},Delete[Flatten[row],-1]]]]
];

ColumnExpansion1[mat_, i_]:= Block[ {n,j,row},
 n=Length[mat];
row=Table[ {Superscript[-1, StringJoin[ToString[i],"+",ToString[j]]]," × ", mat[[j,i]],  " × ","Det[",MatrixForm[DeletedMatrix[mat,{j,i}]],"] + "},{j,1,n}];
Return[ Row[Join[Delete[Flatten[row],-1],{"]"} ]]]
];

ColumnExpansion2[mat_, i_]:= Block[ {n,j,row},
 n=Length[mat];
row=Table[ {(-1)^(i+j)," × ", mat[[j,i]],  " × ",Det[DeletedMatrix[mat,{j,i}]]," + "},{j,1,n}];
Return[ Row[Join[{"= "},Delete[Flatten[row],-1]]]]
];

DetPresent[m_, rc_, i_,expandflag_]:=
Block[{rawoutput},
If[ Dimensions[m][[1]]≠ Dimensions[m][[2]], Return["The given matrix is not square, no determinant can be done. "]];
If[ !IntegerQ[i]|| i<1|| i>Length[m], Return["Invalid row/column number"]];
rawoutput=Column[ {
Row[ {"For the matrix ", MatrixForm[m], " and an expansion along ", If[ rc==1, "row ", "column "], i, ", we have the determinant is"}],
If[rc==1, RowExpansion1[m,i],ColumnExpansion1[m,i]],
If[expandflag, If[rc==1,RowExpansion2[m,i],ColumnExpansion2[m,i]]," "],
If[expandflag, If[rc==1,RowExpansion3[m,i],ColumnExpansion3[m,i]]," "],
If[expandflag, Row[ {"= ",Det[m]}]," "]
}];
Return[rawoutput]
]

Manipulate[ DetPresent[m,rc,p,expand],{{m,(({{-9, 5, 0, 2}, {4, -1, 3, 7}, {6, -2, 0, -8}, {1, 10, -4, 11}})), "Matrix"}, ControlType->InputField, FieldSize->{12,5}}, {{rc,1,"Row or column expansion "},{1->"Row", 2->"Column"}},{{p,1,"Along row/column # "}},{{expand,False, "Continue the computation? "}, {True,False}}, SaveDefinitions->True]