Create a magic square matrix for a given odd integer - MATLAB Cody - MATLAB Central

Problem 44450. Create a magic square matrix for a given odd integer

Difficulty:Rate

A magic square of size 'N' is a matrix that satisfies the following criterias:

  1. Dimension - NxN
  2. Matrix should contain ALL the numbers between 1 to N^2
  3. 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

62.86% Correct | 37.14% Incorrect
Last Solution submitted on Feb 14, 2025

Problem Comments

Solution Comments

Show comments
LLMs with MATLAB updated to support the latest OpenAI Models
Large Languge model with MATLAB, a free add-on that lets you access...
2
3

Problem Recent Solvers38

Suggested Problems

Community Treasure Hunt

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

Start Hunting!
Go to top of page