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

Problem 2: (a) Create the following matrix and put the answer in p2a. Use MATLAB

ID: 3595849 • Letter: P

Question

Problem 2: (a) Create the following matrix and put the answer in p2a. Use MATLAB built-in functions discussed in class. 001 00 0 01 0 0 010100 10 1 0 10 001 1 0 0 0 1 1 0 001 1 0 0 0 1 010100 1 0 1 0 00100 0 01 00 0 10100 1 0 1 0 100 01 1 00 0 1 (b) Sum alelements on the fifth row of the matrix in part (a) and put the answer in c) Sum all elements on the two diagonals of the matrix in part (a) and put the answer (d) Sum all elements of the matrix in part (a) and put the answer in p2d p2b in p2c (e) How many elements of the matrix in part (a) are zero? Put the answer in p2e

Explanation / Answer

Here is the code :

% a) create matrix
p2a = [1 0 0 0 1 1 0 0 0 1;0 1 0 1 0 0 1 0 1 0;0 0 1 0 0 0 0 1 0 0;0 1 0 1 0 0 1 0 1 0;1 0 0 0 1 1 0 0 0 1;1 0 0 0 1 1 0 0 0 1;0 1 0 1 0 0 1 0 1 0;0 0 1 0 0 0 0 1 0 0;0 1 0 1 0 0 1 0 1 0;1 0 0 0 1 1 0 0 0 1]

% b) sum(p2a,2) returns sum of rows , we need sum of 5th row
p2b = sum(p2a,2)(5)

% c) trace will return sum of diagnol , flip will flip the matrix (to take sum of second diagnol)
p2c = trace(p2a) + trace(flip(p2a))

% d) sum of all the elements of matrix
p2d = sum(sum(p2a))

% e) p2a(:)==0 checks if zero or not for each cell , we take sum of this to get total zeroes
p2e = sum(p2a(:)==0)


Output :

p2a =

1 0 0 0 1 1 0 0 0 1
0 1 0 1 0 0 1 0 1 0
0 0 1 0 0 0 0 1 0 0
0 1 0 1 0 0 1 0 1 0
1 0 0 0 1 1 0 0 0 1
1 0 0 0 1 1 0 0 0 1
0 1 0 1 0 0 1 0 1 0
0 0 1 0 0 0 0 1 0 0
0 1 0 1 0 0 1 0 1 0
1 0 0 0 1 1 0 0 0 1

p2b = 4
p2c = 20
p2d = 36
p2e = 64

**If you have any query , please feel free to comment with details.
**Happy leaning :)

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