# Determinant of a matrix with different cases for its entries [closed]

I am beginner in mathematica. I have the following question:

Assume we have a matrix and some of its entries are nonzero and we know which one are. But the nonzero entries can be three different values and we want to calculate the determinant of the matrix for all different cases. How can I do that?

Thank you.

## closed as off-topic by Daniel Lichtblau, MarcoB, anderstood, Sektor, CoolwaterJan 2 '18 at 13:17

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question cannot be answered without additional information. Questions on problems in code must describe the specific problem and include valid code to reproduce it. Any data used for programming examples should be embedded in the question or code to generate the (fake) data must be included." – Daniel Lichtblau, MarcoB, anderstood, Sektor, Coolwater
If this question can be reworded to fit the rules in the help center, please edit the question.

• Have a look at SparseArray and Det. If the matrix is very large, the LU-decomposition provided by LinearSolve might help. Moreover, how large is the matrix (number of rows/columns and number of nonzero entries)? – Henrik Schumacher Dec 30 '17 at 16:50

Det is always zero

 mat = ConstantArray[0, {5, 5}]

Thread[{mat[[1, 2]], mat[[1, 4]], mat[[2, 3]], mat[[2, 5]],
mat[[3, 1]], mat[[3, 4]], mat[[4, 4]], mat[[5, 2]]} =
RandomChoice[{a, b, c}, 8]]

MatrixForm@mat

Det[mat]

• This seems to be a comment on the earlier answer by @Henrik-Schumacher – bbgodfrey Dec 30 '17 at 18:02

Here a test example with a SparseArray that is actually dense. For large matrices, Det might be not the best choice (I am not sure, probably, Det is already implemented very cleverly. An alternative can be obtained from the LU factorization provided by LinearSolve.

n = 12;
SeedRandom[123];
A = SparseArray[RandomReal[{-1, 1}, {n, n}]];

sol = LinearSolve[A];
det = Times[
Times @@ Diagonal[sol["getU"]],
Times @@ Diagonal[sol["getL"]]
]
Det[A]


-1.86164

-1.86164

Edit

In your particular case, you can build the matrix with your desired sparsity pattern but with arbitrary symbolic values a[1], ... ,a[8] as follows:

pat = {{1, 2}, {1, 4} , {2, 3}, {2, 5}, {3, 1} , {3, 4}, {4, 4}, {5, 2}};
vals = Array[a, Length[pat]];
A = SparseArray[pat -> vals, {5, 5}]


Mathematica tells us that a matrix with this sparsity pattern cannot be invertible; its determinant is always zero:

Det[A]


0

• Thank you all. I think i asked my question ambiguous. The matrix is not huge. – A. Mpi Dec 30 '17 at 17:05
• Okay, then Det should do the job. – Henrik Schumacher Dec 30 '17 at 17:10
• Thank you all. I think i asked my question ambiguous. The matrix is not huge. Assume we have a 5 by 5 matrix and the entries (1,2) (1,4) (2,3) (2,5) (3,1) (3,4) (4,4) (5,2) are nonzero and the values of these entries can be a,b or c. I want to calculate Det of these matrices for all cases that can happen for nonzero entries. Thank you – A. Mpi Dec 30 '17 at 17:12