1) Create the following matrices, and use them in the exercises that follow: 15
ID: 3587274 • Letter: 1
Question
1) Create the following matrices, and use them in the exercises that follow: 15 3 22 A 3 8 5 B=15 C=[12 18 5] 14 3 82 a) Create a matrix D from the third column of matrix A b) Combine matrix B and matrix D to create matrix E, a two-dimensional matrix with three rows and two columns c) Combine matrix B and matrix D to create matrix F, a one-dimensional matrix with six rows and one column. d) Create matrix G from the first and third columns of matrix A, matrix B, and the transpose of matrix C. e) Create matrix H from the second row of matrix A, matrix C, the third row of matrix A, and the transpose of matrix B. 15 22 14 82 g by deleting elements in matrix A. f) Create matrix B) Create matrix M 3 8 5] by deleting rows in matrix A. 15 22 h) Create matrix N=| 3 5 | by addressing two columns in matrix A . 14 82 i) Using a function discussed in class, create a matrix of zeros the same size as each of the matrices A-N using variables A-N as parameters in your function. Repeat by creating a matrix of ones the same size as each of the matrices A-N.Explanation / Answer
clc
clear all
A = [15 3 22;
3 8 5;
14 3 82];
B = [1; 5; 6];
C = [12 18 5];
% (a) Solution
D = A(:, 3)
% (b) solution
E = [B D]
% (c) solution
F = [B; D]
% (d) solution
G = [A(:, 1) A(:, 3) B C']
% (e) solution
H = [A(2, :); A(3, :); B']
% (f) solution
K = A;
K(:, 2) = [];
K(2, :) = []
% (g) solution
M = A;
M(1, :) = [];
M(2, :) = []
% (h) solution
N = [A(:, 1) A(:, 3)]
% (i) solution
A = zeros(3, 3)
B = zeros(3, 1)
C = zeros(1, 3)
[row, col] = size(D);
D = zeros(row, col)
[row, col] = size(E);
E = zeros(row, col)
[row, col] = size(F);
F = zeros(row, col)
[row, col] = size(G);
G = zeros(row, col)
[row, col] = size(H);
H = zeros(row, col)
[row, col] = size(K);
K = zeros(row, col)
[row, col] = size(M);
M = zeros(row, col)
[row, col] = size(N);
N = zeros(row, col)
OUTPUT
D =
22
5
82
E =
1 22
5 5
6 82
F =
1
5
6
22
5
82
G =
15 22 1 12
3 5 5 18
14 82 6 5
H =
3 8 5
14 3 82
1 5 6
K =
15 22
14 82
M =
3 8 5
N =
15 22
3 5
14 82
A =
0 0 0
0 0 0
0 0 0
B =
0
0
0
C =
0 0 0
D =
0
0
0
E =
0 0
0 0
0 0
F =
0
0
0
0
0
0
G =
0 0 0 0
0 0 0 0
0 0 0 0
H =
0 0 0
0 0 0
0 0 0
K =
0 0
0 0
M =
0 0 0
N =
0 0
0 0
0 0
>>
1) Matlab Codeclc
clear all
A = [15 3 22;
3 8 5;
14 3 82];
B = [1; 5; 6];
C = [12 18 5];
% (a) Solution
D = A(:, 3)
% (b) solution
E = [B D]
% (c) solution
F = [B; D]
% (d) solution
G = [A(:, 1) A(:, 3) B C']
% (e) solution
H = [A(2, :); A(3, :); B']
% (f) solution
K = A;
K(:, 2) = [];
K(2, :) = []
% (g) solution
M = A;
M(1, :) = [];
M(2, :) = []
% (h) solution
N = [A(:, 1) A(:, 3)]
% (i) solution
A = zeros(3, 3)
B = zeros(3, 1)
C = zeros(1, 3)
[row, col] = size(D);
D = zeros(row, col)
[row, col] = size(E);
E = zeros(row, col)
[row, col] = size(F);
F = zeros(row, col)
[row, col] = size(G);
G = zeros(row, col)
[row, col] = size(H);
H = zeros(row, col)
[row, col] = size(K);
K = zeros(row, col)
[row, col] = size(M);
M = zeros(row, col)
[row, col] = size(N);
N = zeros(row, col)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.