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

Polytechnic University of Puerto Rico Software Applications SP 18 MATLAB Exam Pr

ID: 2293709 • Letter: P

Question

Polytechnic University of Puerto Rico Software Applications SP 18 MATLAB Exam Problem 1 Generate any square matrix of odd dimensions (3x3, 5x5, 7x7, etc) with the following pattern of zeros and ones Vectorize the code as much as possible. . Demonstrate your code to the instructor before leaving the exam. . The dimensions of the matrix are entered by the user . Use a MATLAB function or a MATLAB script. . Your code should work in general. Example: 0 1 0 1 0 Problem 2 Generate any square matrix of even dimesions (4x4, 6x6, 8x8, etc) with the following pattern of zeros and ones, which looks like the letter Z. . Vectorize the code as much as possible. . Demonstrate your code to the instructor before leaving the exam The dimensions of the matrix are entered by the user. e Use a MATLAB function or a MATLAB script. e Your code should work in general. Example:

Explanation / Answer

probelm 1:

clc;
clear all;
close all;

m=input('enter the value of rows :');

n=input('enter the values of columns:');
if m==n

z=mod(m,2);

if z~=0
a=zeros(m,n);
% odd rows have to be filled with ones
for i=1:2:m
for n1=1:n
a(i,n1)=1;
  
end
end
% even rows have to be filled with alternate ones

for j=2:2:m
for n2=2:2:n
a(j,n2)=1;
end
end
disp(a);
else
disp('the entered matrix dimension is not odd');

end
else
disp('the matrix is not square matrix');
end

problem 2:

clc;
clear all;
close all;

m=input('enter the value of rows :');

n=input('enter the values of columns:');
if m==n

z=mod(m,2);

if z==0
a=zeros(m,n);
% first row and last row have to be filled with ones
for n1=1:n
a(1,n1)=1;
a(m,n1)=1;
end
% since first row and last row are filled with ones
%remaining have to be filled
%remove 2 from total number of rows for the remaining number
k=m-2;
for i=1:k
a(1+i,n-i)=1;

end
disp(a);
else
disp('the entered matrix is not even');

end
else
disp('the matrix is not square');
end