help with magic matrix
8 ビュー (過去 30 日間)
古いコメントを表示
hola,
magic matrix is a matrix that the sum of every row and every column and the main secondery diagonal is simmilar.
i need to write a function that gets a number n and return a squre magic matrix in this size if there is one and otherwise returns the number 0.
1 件のコメント
回答 (1 件)
Chirag Nighut
2019 年 7 月 4 日
編集済み: Chirag Nighut
2019 年 7 月 4 日
It is proved that there exist magic squares for any n >=3 (cf. L.Bieberbach).
function ret = getMagicMatrix()
prompt = 'Enter n ';
n = input(prompt)
if n<3
ret = 0;
return;
end
ret = magic(n);
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Operating on Diagonal Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!