Determinant of integer matrices

Is there a version of the det function in R2020a that alway gives determinant 0 for small singular integer matrices?

4 Comments

How do you define "small singular integer matrices"?
Dimension up to 12, say, and entries in the the range of int16.
And it should work without prior knowledge whether the entries are integer or not. Probably asking too much...
And it should work without prior knowledge whether the entries are integer or not. Probably asking too much...
No, one of hte answers below meets that requirement.

Sign in to comment.

Answers (2)

Matt J
Matt J on 23 Apr 2021
Edited: Matt J on 23 Apr 2021
Since you know A is an integer matrix, can't you just do,
d=round(det(A));

3 Comments

Really? I think you know better than that.
A = randi(10000,[9,10]);
A(end+1,:) = randi(10,[1,9])*A
A = 10×10
7497 6537 3766 5435 6184 2118 8828 660 9586 60 2625 7298 1858 3753 2128 6116 6665 6097 1171 6181 4201 9389 2306 563 469 2373 6495 9084 6352 7278 4551 2328 473 1825 2714 9621 6912 2014 1297 749 6129 8679 366 2376 7082 9962 6923 973 9156 2987 7305 8702 3769 464 4308 2063 3823 9903 1631 1128 5562 7922 9924 7919 7386 1701 5237 7835 4508 1626 5970 6851 6672 3816 9832 6891 8857 125 8615 2747 4450 2480 796 952 7442 297 2936 6709 6181 1343 312385 377671 167438 160969 317909 266940 355565 242591 321677 137992
A is purely integer.
We know that A is singular, since the last row is an integer linear combination of the first 9 rows, A is composed of purely integer entries.
det(A)
ans = 8.2795e+23
Will rounding the determinant prove successful?
round(det(A))
ans = 8.2795e+23
It does not look like 0 to me.
Admittedly, the question was about "small" matrices. But the above seems small to me. Is it? At what point does it become small?
OK. Well, maybe the A(i,j) are supposed to be "small" in mangitude as well...
A = randi(3,29,30);
A(end+1,:) = round(rand(1,29)*2-1)*A
A = 30×30
2 3 2 3 2 1 1 2 2 2 1 1 1 3 3 2 3 2 1 3 3 1 2 2 1 1 1 3 3 2 1 3 3 2 2 3 1 1 2 1 1 2 3 3 2 2 2 2 2 1 1 1 2 2 2 2 1 1 1 1 1 2 3 1 1 1 3 3 1 1 1 2 2 1 1 3 2 3 2 1 3 3 2 1 1 2 3 1 2 3 3 1 2 1 2 3 3 1 1 1 1 1 1 1 1 2 2 2 1 2 3 3 1 2 2 1 2 3 1 2 3 2 2 1 1 1 3 1 2 1 2 1 2 1 2 2 1 3 2 3 1 3 3 3 3 2 2 3 3 1 1 3 1 3 1 3 1 1 1 2 2 2 2 1 1 3 1 2 2 3 3 1 2 2 1 1 1 1 1 3 3 1 1 3 3 3 3 1 1 1 1 3 1 3 1 1 3 2 1 3 1 3 2 3 2 1 2 1 3 3 3 2 3 3 3 1 3 1 1 1 3 2 3 2 3 3 3 1 3 1 3 2 2 1 3 3 1 3 2 3 2 3 3 3 3 1 2 2 1 3 1 2 3 3 2 1 1 1 3 1 2 3 3 3 3 1 3 3 2 1 3 2 1 2 2 3 1 1 3 2 3 1 2 3 3 1 3 1 1 3 1 2 1 2 3 2 2 3 1 2
rank(A)
ans = 29
det(A)
ans = 0.5894
round(det(A))
ans = 1
Ok, I guess it works, some of the time. But not this one.
If the matrix is truly tiny, well yes.
A = magic(4)
A = 4×4
16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1
rank(A)
ans = 3
det(A)
ans = 5.1337e-13
round(det(A))
ans = 0
But you really cannot trust that rounding the determinant will work unless things are truly tiny.

Sign in to comment.

Matt J
Matt J on 23 Apr 2021
Edited: Matt J on 23 Apr 2021
This might work,
A = randi(10000,[9,10]);
A(end+1,:) = randi(10,[1,9])*A;
determinant=double(det(sym(A)))
determinant = 0

Categories

Find more on Linear Algebra in Help Center and File Exchange

Products

Release

R2020a

Asked:

on 23 Apr 2021

Commented:

on 23 Apr 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!