Problem 44450. Create a magic square matrix for a given odd integer
A magic square of size 'N' is a matrix that satisfies the following criterias:
- Dimension - NxN
- Matrix should contain ALL the numbers between 1 to N^2
- Sum of all rows or columns or diagonals should be same
E.g: N=3
Output: (Sum of Row1 elem, Sum of Col1 elem, Sum of main diagonal elem, sum of anti-diagonal elem)
15, 15, 15, 15
(Note that row/col/diag/anti-diag sum should be same)
Solution Stats
Problem Comments
-
2 Comments
It looks like we don't actually need to create a magic square for this problem. We just need to figure out what the magic sum would be.
The test suite needs to be improved. It's a good problem, and building an odd magic square is not that hard, but to avoid cheating the function magic should be prohibited and the test suite should require and test the returned matrix.
Solution Comments
Show commentsProblem Recent Solvers34
Suggested Problems
-
Return the 3n+1 sequence for n
8033 Solvers
-
Sort a list of complex numbers based on far they are from the origin.
5492 Solvers
-
Getting the indices from a vector
8691 Solvers
-
Basics: 'Find the eigenvalues of given matrix
402 Solvers
-
Calculate the Number of Sign Changes in a Row Vector (No Element Is Zero)
600 Solvers
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!