123456789 What is the maximum value of the determinant of a 3x3 matrix?

Source: Internet
Author: User
123456789 How is arithmetic equal to 1? -Abccsss's answer
Assume that each number can occur only once.

Reply content:

Mathematica Code

More Concise
Det/@N@Range@9~Permutations~{9}~ArrayReshape~{9!,3,3}//Max


The above uses MATLAB brute force to crack (enumeration kind of case), not the output determinant of the same other situation, seemingly basic seconds out.
Max_det = 0;Init_perm = Reshape(1:9, [3, 3]);all_perms = perms(1:9); for I = 1:size(all_perms, 1)    Matrix = all_perms(I, :);    Matrix = Reshape(Matrix, [3, 3]);    Det_value = Det(Matrix);        if Det_value > Max_det        Max_det = Det_value;        Init_perm = Matrix;    End    End
list = Permutations[range[9], {9}]; List = Permutations[range[9], {9}];
Matrix = partition[#, 3] &/@ list;
Answer = Det/@ matrix;
m = Max[answer];
pos = Flatten[position[answer, M]];
matrix[[#]] &/@ pos A python version with no technical level of violence max ...

import itertoolsimport timedef max_matrix():begin = time.time()elements = [1, 2, 3, 4, 5, 6, 7, 8, 9]maxdet = 0maxmat = []for i in itertools.permutations(elements, 9):det = i[0] * i[4] * i[8] + i[1] * i[5] * i[6] + i[2] * i[3] * i[7] - i[2] * i[4] * i[6] - i[1] * i[3] * i[8] - i[0] * i[5] * i[7]if(det > maxdet):maxdet = detmaxmat = []for j in range(0, 9):maxmat.append(i[j])print "|" + str(maxmat[0]) + " " + str(maxmat[1]) + " " + str(maxmat[2]) + "|"print "|" + str(maxmat[3]) + " " + str(maxmat[4]) + " " + str(maxmat[5]) + "| = " + str(maxdet)print "|" + str(maxmat[6]) + " " + str(maxmat[7]) + " " + str(maxmat[8]) + "|"end = time.time()print str(end - begin) + 's used.'if __name__ == '__main__':max_matrix()
The title should be changed to 1 2 3 ... n^2 the maximum value of the nth-order determinant. And finding the time complexity of the optimal solution is meaningful. C++:
#include 
     #includeusing namespace STD;int ans, a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};int Main() {   Do    ans = Max(ans, a[0] * (a[4] * a[8] - a[5] * a[7]) +                   a[1] * (a[5] * a[6] - a[3] * a[8]) +                   a[2] * (a[3] * a[7] - a[4] * a[6]));   while (next_permutation(a, a + 9));  printf("%d\ n", ans);}
To rearrange the answers to yellow.
9 4 2
3 8 6
5 1 7

It's easy to see the idea.
1. All numbers are sorted by size on the diagonal of-1. (i.e.: 987 on a diagonal, 654 in one, 321 in one) it is easy to see that this is the way to make the most positive value.
2. For the inverse diagonal, excluding the sum of any two numbers other than the main diagonal, and the larger the product, the smaller the corresponding main diagonal element. (That is, the maximum value of the three product is minimized, and the maximum result is then matched to the smallest number)

However, the above method is limited to 1~9 's 3x3 matrix, which is not necessarily applicable for other matrices.
Because obviously this method requires both positive and negative diagonal lines (or parallel to the diagonal), the 4x4 determinant begins to turn ...

Then, I feel there are three loopholes, one is greedy law does not necessarily guarantee the maximum, also not necessarily ensure that the reverse of the smallest, not necessarily to ensure that the difference between positive and negative to the largest. (not all are loopholes, there may be a permanent establishment)
But I feel that for a 3x3 nonnegative matrix, greed can get the maximum value in most cases.

PS: Tried a lot of groups, it is the solution, and then try a group [1 2 3 4 5 6 7 8 100], obviously the answer has changed, because 100 of the weight than 8 and 7 too much, so negative when the direct 2 and 1 to 100. Then this proves that the greedy method does not sometimes get the maximum value. I've got python,c and MMA code in front of me, I'm going to get matlab.
P=perms(1:9);[N,~]=size(P);Z=Zeros(N,1); for I=1:N    Z(I)=Det(Reshape(P(I,:),3,3));EndMax(Z)ID=Find(Z==Max(Z)); for I=1:length(ID)    disp(Reshape(P(ID(I),:),3,3));End
For the third order of the exhaustive, it can be simpler to use the DET function:
P = Reshape(perms(1:9),'',3,3);M = Max(sum(prod(P,2),3)-sum(prod(P,3),2));
The language of the topic is less of a Mathematica, I'll do it.
Direct 9! results saved just front, 0 optimized
Det[Partition[#, 3]] & /@ Permutations[Range[9]] // Max412
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.