help with magic matrix

8 次查看(过去 30 天)
asaf omer
asaf omer 2019-7-4
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 个)

Chirag Nighut
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

类别

Help CenterFile Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息

标签

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by