Answered step by step
Verified Expert Solution
Question
1 Approved Answer
TASK 2 OBJECTIVE: Write a function to check whether a 2-D matrix is a magic square. The MATLAB function magic(N) constructs an NN magic square.
TASK 2 OBJECTIVE: Write a function to check whether a 2-D matrix is a magic square. The MATLAB function magic(N) constructs an NN magic square. magic(3) ans = 3 5 7 The "magical" property of a magic square is that it contains the integers 1 to N2 exactly once each and every row, column, and diagonal has the same sum 841+6-15 3+5+7-15 4+9+2-15 8+3+4=15 1+5+9=15 6+7+2=15 8+5+2-15 6+5+4-15 Now it's your turn. Write a function (verifv magic.m) that take as input a square matrix anc computes the sum of each row, column, and diagonal of the matrix to determine whether the input is a magic square. If the input is not a square matrix, use the error function to display an error message and abort the function. The output of the function should be a logical value indicating whether or not the input is a magic square: logical true for a magic square, logical false for a muggle square. Example: >> verify magicmagic(3)) ans = >> verify magiclf1 2 3;456;789]) ans = 0
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started