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!