Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help solve this MATLAB program. To clarify, there shouldn\'t be any graph

ID: 3890552 • Letter: P

Question

Please help solve this MATLAB program.

To clarify, there shouldn't be any graphs involved with this (The last person who answered completely missed the point of the question). See below for some test inputs and what you should get for outputs:

Test Cases:

[out1] = spellCheck(['QCDN'; 'FLKI'; 'JHGM'; 'EOPB'])

out1 => 1

[out1] = spellCheck(['RTE','AQO','MNP','DSX'])

out1 => 0

[out1] = spellCheck('A')

out1 => 1

Function Name: spellCheck Inputs 1. (char) An NxM array of characters Outputs 1. (logical) A logical representing whether the array is a magic square Banned Functions: diag() unique(), trace(), eye(), magic() Background It is up to you to help Ron complete his Charms homework. He needs to identify which spells are real, and which ones are made up. The trick is, all of the best spells can be rearranged into an array such that the ascii values will make a magic square! 27615 1-15 43815 As a reminder, a magic square is a matrix of numbers where the rows, columns, and diagonals all add up to the same number. Ron is able to rearrange the letters from the spell into an array, but since he is a wizard and he has no coding experience, he is counting on you to examine the arrays to figure out if they are magic or not. Function Description Write a function in MATLAB that takes in an array of characters and checks whether the corresponding ASCIl values create a magic square by outputting a logical. Remember the key aspects to check for a magic square 1) the array must be square 2) all elements must be unique 3) all columns and rows add to the same number 4) both diagonals add to the same number as the rows and columns Notes: A 1x1 matrix is a magic square Hints Think about how you can use linear indexing to get the diagonal of the matrix without using any of the banned functions

Explanation / Answer

function [status] = spellCheck (A)
dimension=size(A);
status=false;
matrix=[];
for i=1:dimension(1);
a=string_splitter(A(i,:));
matrix=[matrix;a];
end
dim_matrix=size(matrix);

if(dim_matrix(1)==dim_matrix(2))
if(dim_matrix(1)==1)
status=true;
end
if(string_unique(matrix))
if(sum_matrix(matrix))
status=true;
end
end
end
endfunction

function [w] = string_splitter(word)
w=[];
for i=1:length(word)
w=[w,double(word(i))];
end

endfunction

function [status] = string_unique(matrix)
array=matrix(:);
dimension=size(array);
status=true;
for i=1:dimension(1)
for j=1:i-1
if(array(i)==array(j))
status=false;
break;
end
end
end

end

function [status] = sum_matrix(A)
status=false;

dimension=size(A);

prev_r_sum=sum(A(1,:));
row_sum=prev_r_sum;
row_sum_status=true;
for i=2:dimension(1)
row_sum=sum(A(i,:));
if(prev_r_sum!=row_sum)
row_sum_status=false;
break;
end
end

column_status=true;
prev_c_sum=sum(A(1,:));
column_sum=prev_c_sum;
for i=2:dimension(2)
column_sum=sum(A(:,i));
if(prev_c_sum!=column_sum)
column_status=false;
break;
end
end

diagonal_sum_1=0;
diagonal_sum_2=0;
for i=1:dimension(1)
diagonal_sum_1=diagonal_sum_1+A(i,i);
diagonal_sum_2=diagonal_sum_2+A(i,dimension(1)-i+1);
end

if(row_sum_status)
if(column_status)
if(diagonal_sum_1==diagonal_sum_2)
if(diagonal_sum_1==column_sum)
status=true;
end
end
end

end

end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote