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

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

ID: 3630497 • Letter: C

Question

Create the following matrices, and use them in the exercises that follow: A = B = [1 5 6] C = [12 18 5 2] Create a matrix D from the third column of matrix A Combine matrix B and matrix D to create matrix E, a two-dimensional matrix with three rows and two columns Combine matrix B and matrix D to create matrix F, a one-dimensional matrix with six rows and one column. Create matrix G from the first and third columns of matrix A, matrix B, and the transpose of matrix C. Create matrix H from the second row of matrix A, matrix C, the third row of matrix A, and the transpose of matrix B. Create matrix K = by deleting elements In matrix A. Using a function discussed in class, create a matrix of zeros the some size as each of the matrices A-K using variables A-K as parameters in your function. Repeat by creating a matrix of ones the same size as each of the matrices A-K. MATLAB has a matrix function called magic(n) which creates an nxn square matrix where the sum of every element in every row, every column, and the two diagonals are all equal to each other. Create a 5times5 magic matrix (matrix A) and an 8times8 magic matrix (matrix Z). For each one: Find the sum of each row and set the sum of row x to the variable row_x Find the sum of each column and set the sum of column x to the variable column_x Find the sum of each diagonal and set the sum of diagonal left-to right x to the variable diagonal_lr, and the sum of diagonal right-to left x to the variable diagonal_rl. (Hint - the function fliptr(A) flips a matrix into its mirror image from left to right).

Explanation / Answer

a)

function createD()

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

for i=1:3

    D(i)=A(i,3);

end

D=D';

D

End

Output:

A =

    15     3    22

     3     8     5

    14     3    82

D =

    22

     5

    82

b)

function createE()

B=[1; 5; 6]

D=[22; 5; 82]

E=[B D]

End

Output:

B =

     1

     5

     6

D =

    22

     5

    82

E =

     1    22

     5     5

     6    82

c)

function createF()

B=[1; 5; 6]

D=[22; 5; 82]

F=[B; D]

end

Output:

>>createF()

B =

     1

     5

     6

D =

    22

     5

    82

F =

     1

     5

     6

    22

     5

    82

d)

function createG()

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

for i=1:3

    D(i)=A(i,1);

end

D=D';

for i=1:3

    E(i)=A(i,3);

end

E=E';

B=[1; 5; 6]

C=[12 18 5];

C=C';

C

G=[D E C]

end

Output:

>>createG()

A =

    15     3    22

    3     8     5

    14     3    82

B =

     1

     5

     6

C =

    12

    18

     5

G =

    15    22    12

     3     5    18

    14    82     5

e)

function createH()

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

for i=1:3

    D(i)=A(2,i);

end

D

C=[12 18 5];

for i=1:3

    E(i)=A(3,i);

end

E

B=[1; 5; 6];

B=B';

B

H=[D; C; E; B]

end

Output:

>>createH()

A =

    15     3    22

     3     8     5

    14     3    82

D =

     3     8     5

E =

    14     3    82

B =

     1     5     6

H =

     3     8    5

    12    18     5

    14     3    82

     1     5     6

function createK()

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

K=[A(1,1) A(1,3); A(3,1) A(3,3)]

end

Output:

>> createK()

A =

    15     3    22

     3     8     5

    14     3    82

K =

    15    22

    14    82

I hope this would help you

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