Question: Write a function that uses this method, iterating through a matrix, to create a magic square of size n,where n is an odd number equal

Write a function that uses this method, iterating through a matrix, to create a magic square of size n,where n is an odd number equal to or greater than 3.

*** USING MATLAB****

****MUST USE SIAMESE METHOD***

Start by making a matrix using the zeros() command, and create a for loop using iterator i. Initialize x and y, and iterate through the loop as follows:

The goal here is to create bounds to contain the incrementing of the magic square. You can do this by making two position variables x and y as part of a loop with iterator i. You will start at x position(n-1)/2 + 1 and y position as 1. Place a 1 there. Move upward and to the right, subtracting 1 fromy and adding 1 to x. If there is a number there (i.e. if the number in that position is nonzero - use an ifstatement here), move back, and move one square down instead. If there is a number there, move down until an empty space is reached. If the edge of the square is reached - use an if statement here too -then wrap around to the opposite edge of the square.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!