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

MatLab Use the matrix 40x10 to write a script file that performs the following t

ID: 3625683 • Letter: M

Question

MatLab

Use the matrix 40x10 to write a script file that performs the following tasks.

A

B

C

D

E

F

G

H

I

J

1           

9

4

2

9

2

9

8

1

1

10

2

7

5

10

8

3

9

5

1

8

1

3

7

1

6

1

1

8

7

8

4

5

4

2

4

9

3

4

9

7

5

3

10

5

0

1

8

8

1

7

2

5

0

3

6

0

4

5

9

10

3

6

6

6

2

7

1

0

2

5

4

9

2

6

7

2

8

5

1

10

8

1

5

8

4

8

0

9

5

8

9

5

7

5

8

7

3

3

10

7

4

3

2

4

1

2

7

9

0

11

3

1

10

9

9

4

5

8

8

2

12

2

3

4

5

1

9

1

9

9

7

13

2

8

10

5

4

4

6

3

2

7

14

5

4

9

3

4

10

4

9

8

5

15

5

7

6

1

3

3

6

6

1

4

16

4

8

9

4

1

6

9

9

7

1

17

4

9

1

3

2

3

9

0

7

1

18

4

0

4

2

10

8

3

6

1

2

19

7

8

7

2

4

2

6

1

9

7

20

5

4

8

4

1

5

4

5

5

3

21

3

4

4

3

3

2

5

2

7

1

22

3

2

4

4

10

1

4

8

10

5

23

1

2

2

8

5

8

9

3

9

10

24

3

5

8

7

2

5

5

0

10

3

25

2

6

7

10

8

8

9

9

5

7

26

1

3

6

5

0

0

3

6

1

7

27

7

10

3

2

1

6

4

4

0

1

28

7

4

7

9

8

2

2

3

3

9

29

1

3

6

2

8

8

8

1

8

7

30

9

2

7

9

9

6

4

4

4

1

31

1

4

7

8

5

2

5

7

8

4

32

7

5

3

4

9

3

2

10

8

6

33

0

9

0

6

1

5

5

4

1

9

34

6

8

3

3

7

7

0

0

6

3

35

9

8

1

4

1

4

1

9

8

5

36

7

2

5

3

9

5

3

4

10

3

37

5

4

7

0

2

4

7

1

4

10

38

8

5

7

8

7

6

10

0

2

10

39

6

4

1

5

0

9

1

1

9

2

40

4

2

9

7

4

5

1

7

1

4

1. Read the matrix from the file. Let us call this matrix (X).

2. Compute the sum of the third column of X.

3. Dot product of the first and the last rows of X.

4. Use the last six values of the fourth row of X in order to create and display a 6x6 diagonal matrix, call it (Z).

5. Compute the inverse matrix of Z.

6. Partition X into two 20x10 matrices, say A and B, where A has only odd numbered rows and B has only even numbered rows. That is, A contains 1st, 3rd, 5th, …. rows of X, while B contains 2nd, 4th, 6th,… rows of X.

7. Compute the sum of all the elements of A.

8. Compute the sum of all the elements of B.

9. Create 20x10 matrix, say C, where(i,j) elements is

    -1 = if A(i,j) < B(i,j)

     0 = if A(i,j) = B(i,j)

     1 = Otherwise

10. Find the median of the 10th row of X.





A

B

C

D

E

F

G

H

I

J





1           

9

4

2

9

2

9

8

1

1

10





2

7

5

10

8

3

9

5

1

8

1





3

7

1

6

1

1

8

7

8

4

5





4

2

4

9

3

4

9

7

5

3

10





5

0

1

8

8

1

7

2

5

0

3





6

0

4

5

9

10

3

6

6

6

2





7

1

0

2

5

4

9

2

6

7

2





8

5

1

10

8

1

5

8

4

8

0





9

5

8

9

5

7

5

8

7

3

3





10

7

4

3

2

4

1

2

7

9

0





11

3

1

10

9

9

4

5

8

8

2





12

2

3

4

5

1

9

1

9

9

7





13

2

8

10

5

4

4

6

3

2

7





14

5

4

9

3

4

10

4

9

8

5





15

5

7

6

1

3

3

6

6

1

4





16

4

8

9

4

1

6

9

9

7

1





17

4

9

1

3

2

3

9

0

7

1





18

4

0

4

2

10

8

3

6

1

2





19

7

8

7

2

4

2

6

1

9

7





20

5

4

8

4

1

5

4

5

5

3





21

3

4

4

3

3

2

5

2

7

1





22

3

2

4

4

10

1

4

8

10

5





23

1

2

2

8

5

8

9

3

9

10





24

3

5

8

7

2

5

5

0

10

3





25

2

6

7

10

8

8

9

9

5

7





26

1

3

6

5

0

0

3

6

1

7





27

7

10

3

2

1

6

4

4

0

1





28

7

4

7

9

8

2

2

3

3

9





29

1

3

6

2

8

8

8

1

8

7





30

9

2

7

9

9

6

4

4

4

1





31

1

4

7

8

5

2

5

7

8

4





32

7

5

3

4

9

3

2

10

8

6





33

0

9

0

6

1

5

5

4

1

9





34

6

8

3

3

7

7

0

0

6

3





35

9

8

1

4

1

4

1

9

8

5





36

7

2

5

3

9

5

3

4

10

3





37

5

4

7

0

2

4

7

1

4

10





38

8

5

7

8

7

6

10

0

2

10





39

6

4

1

5

0

9

1

1

9

2





40

4

2

9

7

4

5

1

7

1

4

Explanation / Answer

xmatrix.txt is a data file in the same directory as your script file (I eliminated the numbers of the rows and the letters of the columns). I haven't double-checked any answers, but each part got an answer and looked at a glance somewhat correct. Feel free to double check by hand. Hope this helps! %Part 1: Read the matrix from the file X_MAT = load ('xmatrix.txt'); %Part 2: Compute the sum of the third column of X col_3 = X_MAT(:,3); sum_col3 = sum(col_3); %Part 3: Dot product of the first and last rows of X row_1 = X_MAT(1,:); row_40 = X_MAT(40,:); product = row_1.*row_40; %Part 4: Use the last six values of the fourth row of X in order to create a %6x6 diagonal matrix, call it (Z) row_4 = X_MAT(4,5:10); Z_MAT = diag(row_4); %Part 5: Compute the transpose of matrix Z Z_INV = inv(Z_MAT); %Part 6: Partition X into two 20x10 matrices, say A and B, %where A has only odd numbered rows and B has only even numbered rows. %That is, A contains 1st, 3rd, 5th, …. rows of X, while B contains 2nd, %4th, 6th,… rows of X. A_MAT = X_MAT(1:2:39,:); B_MAT = X_MAT(2:2:40,:); %Part 7: Compute the sum of A sum_A = sum(A_MAT); %Part 8: Compute the sum of B sum_B = sum(B_MAT); %Part 9: Create 20x10 matrix, say C, where(i,j) elements is % -1 = if A(i,j)