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

3. Create matrices with zeros, eye, ones, and triu: Create the following matrice

ID: 3110629 • Letter: 3

Question

3. Create matrices with zeros, eye, ones, and triu: Create the following matrices with the help of the matrix generation functions zeros, eye, ones and triu. See the on-line help on these functions if required (i.e. help eye) 2 0 0 3 3 3 0 0 4 4 4 M 0 2 0 N 0 3 3 0 0 4 4 4 0 0 2 0 0 3 4. Create a big matrix with submatrices: The following matrix Giscreated by putting matrices A, B, and C from Exercise 1, on its diagonal and inserting 2 x 2 zeros matrices and 2 x 2 identity matrices in the appropriate position. Create the matrix using submatrices A, B, C, zeros and eye (that is, you are not allowed to enter the numbers explicitly). 1 2 1 0 0 0 3 6 0 1 0 0 0 0 2 1 0 G 0 0 1 4 0 1 1 0 0 0 -2 1 0 1 0 0 3 2 2016 Stefania Tracogna, SoMSS, ASU MATLAB sessions: Laboratory 1 5. Manipulate a matrix: Do the following operations on matrix G created above in Problem 4. (a) Extract the first 3 x 3 submatrix from G and store it in the matrix H, that is, create a matrix H a 3 6 0. 0 0 2

Explanation / Answer

3.

clear all;

close all;

clc;

m = 2 * eye(3,3);

n = zeros(2);

x = 3 * ones(3);

p = triu(x);

q = 4 * ones(2,3);

disp('M = ');

disp(m);

disp('N = ');

disp(n);

disp('P = ');

disp(p);

disp('Q = ');

disp(q);

4.

clear all;

close all;

clc;

a = [1,2;3,6];

b = [2,-3; 1,4];

c = [-2,1; 3,2];

i = eye(2);

z = zeros(2);

g = [a,i,z; z,b,i; i,z,c];

disp('G = ');

disp(g);

5.a.

h = g(1:3,1:3);

disp('H = ');

disp(h);

5.b.

e = h;

e(3,3) = 5;

disp('E = ');

disp(e);

5.c.

f = h;

f(2,:) = [];

disp('F = ');

disp(f);

5.d.

g(:,:) returns all the elements of the matrix g and is displayed in the same format (m X n) as the matrix is declared.

g(:) returns all the elements of the matrix g and is displayed in the same format (m*n X 1) such that all the elements of the matrix is displayed column wise i.e., first column is displayed and the second column below the first one and so on.

5.e.

g(8)

ans =

     6

g(16)

ans =

     1

Eighth element and sixteenth element of the matrix g are displayed.

The matrices are traversed column wise.

5.f.

g(10,1)

Index exceeds matrix dimensions.

This message appears because the dimension of matrix g is 6 X 6.

5.g.

g(g>2)

ans =

     3

     6

     4

     3

We obtain all values that are greater than 2 from the matrix g.

g(g>2) = 50

g =

     1     2     1     0     0     0

    50    50     0     1     0     0

     0     0     2    -3     1     0

     0     0     1    50     0     1

     1     0     0     0    -2     1

     0     1     0     0    50     2

The matrix g updated with all values that are greater than 2 in the matrix g with 50.

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