필터 지우기
필터 지우기

solving is magic function

조회 수: 2 (최근 30일)
KayLynn
KayLynn 2013년 10월 17일
댓글: Azzi Abdelmalek 2013년 10월 18일
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
Azzi Abdelmalek 2013년 10월 17일
Create a magic matrix with magic function then use isequal to compare your two matrices
  댓글 수: 2
Walter Roberson
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
Azzi Abdelmalek 2013년 10월 18일
Ok, I ignore it

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2013년 10월 17일
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
Azzi Abdelmalek 2013년 10월 18일
편집: Azzi Abdelmalek 2013년 10월 18일
sum(A,1) ans sum(A,2) are equal and constant

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Hypothesis Tests에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by