Filter löschen
Filter löschen

solving is magic function

2 Ansichten (letzte 30 Tage)
KayLynn
KayLynn am 17 Okt. 2013
Kommentiert: Azzi Abdelmalek am 18 Okt. 2013
How to write a function that will take a matrix m as an input and return true only if M is a magic square

Antworten (2)

Azzi Abdelmalek
Azzi Abdelmalek am 17 Okt. 2013
Create a magic matrix with magic function then use isequal to compare your two matrices
  2 Kommentare
Walter Roberson
Walter Roberson am 17 Okt. 2013
Bearbeitet: Walter Roberson am 17 Okt. 2013
Note: as magic() generates randomly, you will need to generate all of the magic squares of that size and compare each of them to the original matrix.
Azzi Abdelmalek
Azzi Abdelmalek am 18 Okt. 2013
Ok, I ignore it

Melden Sie sich an, um zu kommentieren.


Walter Roberson
Walter Roberson am 17 Okt. 2013
One test: calculate the mean of the numbers in the array. If it is not an integer, the array cannot be a magic square.
Another test: an array which is square and has all elements identical is a magic square.
A third test: magic squares are always two dimensional, not vectors and not three or more dimensions.
  1 Kommentar
Azzi Abdelmalek
Azzi Abdelmalek am 18 Okt. 2013
Bearbeitet: Azzi Abdelmalek am 18 Okt. 2013
sum(A,1) ans sum(A,2) are equal and constant

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by