Question: MATLAB Quesion: Directions: You are given a section of code (the main program) that calls another function in the same M-File. You must create the

MATLAB Quesion:

Directions: You are given a section of code (the "main program") that calls another function in the same M-File. You must create the function that is called by the main program on your own, but turn in both the main program (given) and the function that you write in the same M-File (you only turn in one M-File per problem). Thus, for each problem you will need to put both the main program and the function you create in the same M-File.

A magic square of order n is an arrangement of n2 numbers, usually distinct integers, in a square, such that the n numbers in all rows, all columns, and both diagonals sum to the same constant. Create a function called magicsq( )that creates a magic square of order n, where n is an odd integer greater than or equal to 3. The function will return as output an nxn array to the main program. You may NOT use the built-in function magic( ) for this problem. You must create your own algorithm in the function magicsq( ). The methodology for creating an odd magic square of order n can be found here. The main program that calls the function magicsq( ) is the following:

% NAME, ID#

% Homework 6, Problem 3

% This program will create an nxn magic square for any odd n>=3

clear; clc;

n=7; % test several odd values of n

magicarray = magicsq(n)

Thanks! will give a thumbs up.

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!