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

1. Write a program in script file that will create a 5x5 matrix as per the follo

ID: 2085380 • Letter: 1

Question

1. Write a program in script file that will create a 5x5 matrix as per the following rules: if the
sum of the row index and column index is even AND exactly divisible by 4, the value of
the element is the product of the row index and the column index; if the sum of the row
index and the column index is odd and exactly divisible by 3, the value of the element is
the row index minus the column index; otherwise, the value is zero.
For example, row 1 and column 3 element should be 3, row 1 and column 1 element should
be 0, and row 1 and column 2 element should be -1, and so on.

2. Write a script file to determine the sum of the series by (i) using a for loop and (ii) using
method of arrays

Explanation / Answer

Ans) Here I assuming that script file needed is on MATLAB as is in many cases,so my solution is in MATLAB script ,as algorithm is same you can fit that to any software you want

1 Ans)

MATLAB scrpit

============================================


% 'i' is index for rows in matrix
% 'j' is index for columns in matrix
% 'M' is Matrix

for i=1:5
  
for j=1:5
  
if mod((i+j),2)==0 && mod((i+j),4)==0 %check for even and divisible by 4
  
M(i,j)=i*j;
  
elseif mod((i+j),2)~=0 && mod((i+j),3)==0 %check for odd and divisible by 3
M(i,j)=i-j;
  
else
M(i,j)=0;
end
  
end
  
  
end
M

======================================================================

Result in command window

==================

>> script1

M =

0 -1 3 0 0
1 4 0 0 0
3 0 0 0 15
0 0 0 16 -1
0 0 15 1 0

>>

==================================================

2)Ans

Let us assume that series is in array S and below code follows

MATLAB SCRIPT

===================================

S=[1 2 3 4 5 6 7];%sample series
sum1=0;
for i=1:length(S) %using for loop
sum1=sum1+S(i);
end
sum1

sum2=sum(S);%Using array method
sum2

==========================

RESULT IN COMMAND WINDOW

==================

>> script1

sum1 =

28


sum2 =

28

====================================================

Only 1 question per post will be answered but I answered two

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote