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...
Asked
Active
Viewed 2,823 times
0
-
4You 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 Answers
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
-
Thank you! i will try to do a little more research to see if i can come up with a more specific problem! – user1068253 Nov 28 '11 at 21:00