Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Knowledge Discovery In Databases

Authors: Animesh Adhikari, Jhimli Adhikari

1st Edition

3319132121, 9783319132129

More Books

Students also viewed these Databases questions

Question

2. What do you believe is at the root of the problem?

Answered: 1 week ago