Effacer les filtres
Effacer les filtres

help with magic matrix

8 vues (au cours des 30 derniers jours)
asaf omer
asaf omer le 4 Juil 2019
Commenté : KALYAN ACHARJYA le 4 Juil 2019
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 commentaire
KALYAN ACHARJYA
KALYAN ACHARJYA le 4 Juil 2019
For me its takes little time, try it, concept is here

Connectez-vous pour commenter.

Réponses (1)

Chirag Nighut
Chirag Nighut le 4 Juil 2019
Modifié(e) : Chirag Nighut le 4 Juil 2019
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

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Tags

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by