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

FOR MATLAB Create the following matrices, and use them in the exercises that fol

ID: 3751874 • Letter: F

Question

FOR MATLAB

Create the following matrices, and use them in the exercises that follow:

A = [ 15   3   22

3     8     5

14     3    8 ]

B = [ 1 5 6]

C = [12    18    5    2]

1. Extract the first two columns from matrix A.

2. Extract the last two columns from matrix A.

3. Extract the last row from matrix A

4. Extract the following sub-matrix x from matrix A

X= [ 15 3

3 8]

5. Compute the sum of the third row matrix A.

6. Compute the sum of the first column from matrix A.

7. Create a matrix called D from the third column of matrix A.

8. Combine matrix B and D to create matrix E, a two-dimensional matrix with three rows and two columns

9. Combine matrix B and matrix D to create matrix F, a one-dimensional matrix with six rows and one column

10. Create a matrix G from matrix A and the first three elements of matrix C, with four rows and three columns.

11. Create a matrix H with the first element equal to A1, 3, the second element equal to C1,2 and the third element equal to B2,1

12. Find the largest and the smallest element in each column of matrix A and their indices.

13. Sort each column in matrix A to create a new matrix J.

14. Transpose the matrix A and create the following matrix K

K = [ 15 3 22

3 8 5

14 3 8

15 3 14

3 8 3

22 5 8]

Explanation / Answer

Here are the required commands

A = [15 3 22; 3 8 5; 14 3 8];

B = [1; 5; 6];

C = [12 18 5 2];

%% 1

% Extract the first two columns of A

A(:, 1:2)

%% 2

% Extract the last two columns of A

A(:, end-1:end);

%% 3

% Extract the last row from matrix A

A(end, :);

%% 4

X = A(1:2, 1:2);

%% 5

% Compute the sum of third row of matrix A

sum(A(3, :));

%% 6

% Compute the sum of first column of matrix A

sum(A(:, 1));

%% 7

% Create matrix D from third column of A

D = A(:, 3);

%% 8

% Combine B and D to create E with 3 rows, 2 columns

E = [B; D]

%% 9

% Combine B and D to create F with six rows and one column

F = [B D]

%% 10

% Create G from A and first three elements of C, with four rows and three

% columns

G = [A; C(1:3)]

%% 11

% Create H with first element A(1,3) second element C(1,2) and third

% element B(2,1)

H = [A(1,3) C(1,2) B(2,1)]

%% 12

% Find largest and smallest element in each column of matrix A and their

% indices

[min, indmin] = min(A)

%% 13

% Sort A to create J

J = sort(A)

%% 14

% Transpose A and Create K

K = [A; A']