0

For a project i am supposed to write my own function that will do the same thing as the magic function in matlab. I am obviously not asking anyone to write out my problem but if somebody could give me any ideas of how i could start it or example code it would be much appreciated! I am completely lost on how to start this one...

false
  • 10,264
  • 13
  • 101
  • 209
user1068253
  • 51
  • 1
  • 2
  • 3
  • 4
    You can check out how Matlab does it by typing `edit magic` in the command prompt. That should at least give you an idea of where to start. – aganders3 Nov 28 '11 at 19:58

2 Answers2

1

This is often great advice:

If a problem is too hard, try solving an easier one to begin with.

Try to write code to generate a 2 by 2 magic square? Then try 3 by 3. Then 4 by 4. Can you see how to generalise?

Richie Cotton
  • 118,240
  • 47
  • 247
  • 360
0

I guess you already thought about it, but the usual good source of information is wikipedia: https://en.wikipedia.org/wiki/Magic_square#Types_and_construction

It explains different ways of making magic squares.

Oli
  • 15,935
  • 7
  • 50
  • 66