Matrices and Determinants with Mathematica

The determinant of a matrix is a good check (you could almost say the good check) for whether a matrix can be inverted.
Recall that we generally have a set of equations of some form [M]*[x] = [k] that we want to solve for a set of answers [x].
We recall that the solution to this equation is generally written [x] = (([M])^(-1))*[k], so step one to solving it is to find (([M])^(-1)). 
So, forgetting for now about [k] altogether, let’s just look at [M] and (([M])^(-1)) . Here’s an [M]:

M1=(({{2, 3, 5}, {4, 6, 10}, {3, -2, 3}}));Det[M1]

We see that for this matrix, the determinant is zero. That’s a tip-off that the equations it represents are not linearly independent. In fact, casual inspection reveals that row 2 is just 2*(row 1), so we really only have two unique equations here.
That’s true regardless of whether k2 = 2*k1; if it is, then these rows are identical, and if it’s not, then these two rows are contradictory. Either way, no problem involving this matrix can be solved. 
We can try to compute the inverse:

Inverse[M1]

You can see that we get an error. We can contrast this with a very similar matrix that has only one component different:

M2=(({{2, 3, 5}, {4, 6, 9}, {3, -2, 3}}));Print["The determinant of M2 is ",Det[M2] ]

Print["The inverse of M2 is = ((Subscript[M, 2])^(-1))=",N[Inverse[M2]//MatrixForm,5]]

Here’s a quick example “problem” (OK, it’s just some numbers, so you could argue that it’s just an example exercise, not an example problem).

M3=(({{1, 3, -2, 1}, {3, 3, -1, -1}, {2, -2, 1, 1}, {-1, 1, -1, 2}}));k3=(({{4}, {0}, {-7}, {5}}));
(* See if an inverse even exists  *)
Print["The Determinant of M3 is ", Det[M3]]
M3inv=Inverse[M3]; (* Compute inverse... *)
x3 =N[M3inv.k3,2]; (* Calculate actual answers *)
Print["The solutions [(Subscript[x, 3])] of [M3].[(Subscript[x, 3])]=[(Subscript[k, 3])] are [(Subscript[x, 3])]=",x3//MatrixForm ]

We can check the answer easily by seeing whether [M3]*[x3] actually does equal [k3]:

kcheck=M3.x3;
Print["The computed check is (Subscript[k, 3]) = ",kcheck //MatrixForm//N," where the original (Subscript[k, 3]) was ", 1.0 k//MatrixForm]

You can see that this matches the [(Subscript[k, 3])] vector that we expected.

Determinants of larger Matrices

The textbook outlines a tedious method for determining matrices of "large" matrices . For me, "large" means anything bigger than 3 x 3. It works by making multiple sub - matrices that are each one row smaller than the matrix you are working on, then finding and combining their determinants along with some of the other elements of the matrix . For example, starting with this matrix [M], I' ll make 4 submatrices called "array", each of which consists of a portion of [M] taken from the lower 3 rows, and skipping one of the columns . Subscripts use double - square brackets, and are in [[row, column]] format :

M=(({{1, 2, 3, 2}, {5, 2, 1, 3}, {4, 3, 2, 1}, {5, 2, 3, 5}}));array[1]=(({{2, 1, 3}, {3, 2, 1}, {2, 3, 5}}));(* skips row 1 and column 1 *)
array[2]=(({{5, 1, 3}, {4, 2, 1}, {5, 3, 5}}));(* skips row 1 and column 2 *)
array[3]=(({{5, 2, 3}, {4, 3, 1}, {5, 2, 5}}));(* skips row 1 and column 3 *)
array[4]=(({{5, 2, 1}, {4, 3, 2}, {5, 2, 3}}));(* skips row 1 and column 4 *)
Print["Mathematica says that the determinant is ",Det[M] ] 
B1=M[[1,1]]*Det[array[1]]*(((-1))^0); 
B2=M[[1,2]]*Det[array[2]]*(((-1))^1);
B3=M[[1,3]]*Det[array[3]]*(((-1))^2);
B4=M[[1,4]]*Det[array[4]]*(((-1))^3);
Print["The 'long' method results in a determinant of ", B1+B2+B3+B4 ]

So, more compactly, for the matrix M, the “long” method says that we could find the determinant by this procedure (assuming you’ve already made all the little subarrays somehow):

detM=(∑_(i=1)^4)(((-1))^(i-1))*M[[1,i]]*Det[array[i]]