Loading [MathJax]/jax/output/HTML-CSS/jax.js
Ask Your Question
0

Minimal determinant of a matrix with varied entries

asked 6 years ago

LukeC93 gravatar image

updated 6 years ago

I would like Sage to tell me to minimal value of the determinant of a matrix when a vary some entries over a set range.

For example, say with the 4x4 matrix A (sorry for weird layout, I can't get the Latex code to work properly?):

0 1 i j

1 0 1 k

0 1 0 1

0 0 1 0

I'd like to know, for i,j,k0,±1, what the smallest non-trivial determinant is, and for which combination(s) of i,j,k this is for.

I'm still pretty new to Sage, so I'm a bit unsure of how to do this effectively, if it is at all possible to do this?

Side note: I know I could of course write

sage A.determinant()

and this would give me the value of the determinant in terms of i,j,k. And in this example that would likely be much easier.

The idea is that I'd like to do this with larger matrices (that aren't as nice as this), more variables, etc. It would obviously be nicer to have have Sage simply compute the smallest determinant and give the corresponding values for the variables than me have to plug it in.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered 6 years ago

rburing gravatar image

updated 6 years ago

Do you mean something like this?

min_det = infinity
min_params = []
import itertools
for (i,j,k) in itertools.product([0,-1,1], repeat=3):
    M = Matrix(ZZ, [[0,1,i,j], [1,0,1,k], [0,1,0,1], [0,0,1,0]])
    M_det = M.determinant()
    if M_det == min_det:
        min_params.append((i,j,k))
    elif M_det != 0 and M_det < min_det:
        min_det = M_det
        min_params = [(i,j,k)]
print 'Minimal nontrivial determinant:', min_det
print 'Sets of parameters with this determinant:', min_params

Output:

Minimal nontrivial determinant: 1
Sets of parameters with this determinant: [(0, 0, 0), (0, 0, -1), (0, 0, 1), (-1, 0, 0), (-1, 0, -1), (-1, 0, 1), (1, 0, 0), (1, 0, -1), (1, 0, 1)]
Preview: (hide)
link

Comments

Yes, that's very much what I'm after - thank you! Couple of questions so I can check I understand the code:

Why do we set min_det = infinity What does this do / mean exactly?

Say I wanted to see the minimal value which was larger than a set number (say 1); presumably I would change the zero in this part of the code to a 1:

elif M_det != 0 and M_det < min_det:

(I know the matrix I've used isn't the best example for checking that!)

LukeC93 gravatar imageLukeC93 ( 6 years ago )
1

The variable min_det contains the minimal determinant found so far. It should be initialized to something large enough so that it will be overwritten immediately. To find the minimal determinant larger than x you should include this condition in the conditional, i.e. elif M_det != 0 and M_det > x and M_det < min_det:. If x0 then the first condition can be omitted: elif M_det > x and M_det < min_det:.

rburing gravatar imagerburing ( 6 years ago )
1

Amazing; that makes sense and works perfectly for what I'm after. Thank you again!

LukeC93 gravatar imageLukeC93 ( 6 years ago )

You're welcome!

rburing gravatar imagerburing ( 6 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 6 years ago

Seen: 364 times

Last updated: Feb 08 '19