필터 지우기
필터 지우기

help with magic matrix

조회 수: 8 (최근 30일)
asaf omer
asaf omer 2019년 7월 4일
댓글: KALYAN ACHARJYA 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
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 7월 4일
For me its takes little time, try it, concept is here

댓글을 달려면 로그인하십시오.

답변 (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에서 Matrix Indexing에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by