I'm using R to try and find the largest possible determinant that a symmetric 3x3 matrix, all of whose entries lie in the set of integers {1,2,3,4,5,6} can have?
Any ideas how I'd go about this?
I'm using R to try and find the largest possible determinant that a symmetric 3x3 matrix, all of whose entries lie in the set of integers {1,2,3,4,5,6} can have?
Any ideas how I'd go about this?
There are six degrees of freedom in selecting the elements in a 3x3 symmetric matrix (3 main-diagonal entries and 3 off-diagonal entries). Each of these can take 6 different values, for a grand total of 46,656 possible matrices. We can just brute force check all the determinants:
get.det = function(x) {
det(matrix(c(x[1], x[2], x[3], x[2], x[4], x[5], x[3], x[5], x[6]), nrow=3))
}
vals = expand.grid(1:6, 1:6, 1:6, 1:6, 1:6, 1:6)
dets = apply(vals, 1, get.det)
vals[which.max(dets),]
# Var1 Var2 Var3 Var4 Var5 Var6
# 6691 1 6 6 1 6 1
So your matrix is:
[1 6 6
6 1 6
6 6 1]
with determinant 325.
I'm a little slower off the mark than @josilber, reach the same conclusion (my answer is a little bit more general)
d <- 3
n <- d*(d+1)/2
xx <- do.call(expand.grid,replicate(n,1:n,simplify=FALSE))
Construct symmetric matrix:
mm <- matrix(nrow=d,ncol=d) ## define once, outside loop
m <- function(x) {
mm[lower.tri(mm,diag=TRUE)] <- unlist(x)
mm[upper.tri(mm)] <- t(mm)[upper.tri(mm)]
mm
}
Get list of matrices:
library(plyr)
mList <- alply(xx,1,m,.progress="text")
Get determinants for each matrix:
detvec <- laply(mList,det)
Find the maximum:
max(detvec) ## 325
mList[[which.max(detvec)]]
Just for fun:
plot(table(detvec))
The mathematical guess/conjecture is whether the max-det matrix is always the matrix with 1 on the diagonal and n
on the off-diagonal, or whether this depends on the matrix being odd vs. even ... and how to prove this.