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

1. Write the MATLAB commands which will accomplish the following tasks. Each par

ID: 2249115 • Letter: 1

Question

1. Write the MATLAB commands which will accomplish the following tasks. Each part is independent. Upper-case variables indicate matrices and lower-case variables indicate row or column vectors. Assume matrices and vectors needed for the tasks exist and are of appropriate sizes. (a) create the matrix and vector 1 23 4 5 A=110 9 8 7 6 12 14 16 18 20 b-7 2 37 11 (b) create a matrix E which in which the first two rows are equal to the first two rows of C, the third row is equal to d, and the fourth row is equal to the third row of C (c) in the second row of matrix J set everything except the first column to zero (d) obtain the number of rows and columns of the matrix K and assign the results to the variables nrows and ncols (e) create the matrix D in which the first three rows is equal to the first three rows of Q and the last row is equal to f () create variable x which is equal to the determinant of matrix M (g) calculate E (bG(Gb where b' indicates the transpose of b

Explanation / Answer

clc
%part a
A=[1 2 3 4 5 ;10 9 8 7 6;12 14 16 18 20]
b=[7 2 37 11]
%part b
C=[1 2 3;2 3 5;4 5 7]
d=[1 0 1];
E=[C(1:2,:);d;C(3,:)]
%part c
J=[1 2 4 8;5 6 8 9;9 8 7 3];
J(2,2:4)=0
%part d
K=[1 2 5 7;2 1 3 4;5 6 7 9]
[nrows,ncols]=size(K)
%part e
Q=[1 2;3 4;5 6];
f=[9 8];
D=[Q;f]
%part f
M=[1 0 0;0 1 0;0 0 1];
x=det(M)
%part g
G=[1 2 5 7;2 1 4 5;3 4 7 6;4 5 7 8];
E=(b*G^-1)*(G^-1*b')
%part h
zeros(96,177);

%result

A =

1 2 3 4 5
10 9 8 7 6
12 14 16 18 20


b =

7 2 37 11


C =

1 2 3
2 3 5
4 5 7


E =

1 2 3
2 3 5
1 0 1
4 5 7


J =

1 2 4 8
5 0 0 0
9 8 7 3


K =

1 2 5 7
2 1 3 4
5 6 7 9


nrows =

3


ncols =

4


D =

1 2
3 4
5 6
9 8


x =

1


E =

403.5789