help with magic matrix

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 comentario

KALYAN ACHARJYA
KALYAN ACHARJYA el 4 de Jul. de 2019
For me its takes little time, try it, concept is here

Iniciar sesión para comentar.

Respuestas (1)

Chirag Nighut
Chirag Nighut el 4 de Jul. de 2019
Editada: Chirag Nighut el 4 de Jul. de 2019

0 votos

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

Categorías

Más información sobre Linear Algebra en Centro de ayuda y File Exchange.

Productos

Versión

R2018a

Etiquetas

Preguntada:

el 4 de Jul. de 2019

Comentada:

el 4 de Jul. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by