solving is magic function
이전 댓글 표시
How to write a function that will take a matrix m as an input and return true only if M is a magic square
답변 (2개)
Azzi Abdelmalek
2013년 10월 17일
0 개 추천
Create a magic matrix with magic function then use isequal to compare your two matrices
댓글 수: 2
Walter Roberson
2013년 10월 17일
편집: Walter Roberson
2013년 10월 17일
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
2013년 10월 18일
Ok, I ignore it
Walter Roberson
2013년 10월 17일
0 개 추천
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
Azzi Abdelmalek
2013년 10월 18일
편집: Azzi Abdelmalek
2013년 10월 18일
sum(A,1) ans sum(A,2) are equal and constant
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!