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

Let 17 24 1 8 15 23 5 7 1416 z 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9 Perform t

ID: 3707018 • Letter: L

Question

Let 17 24 1 8 15 23 5 7 1416 z 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9 Perform the following operations in the order given: a) (6 pts.) Divide column 2 by v3. b) (6 pts.) Add the elements of the third row to the elements in the fifth row (the third row remains c) d) unchanged) (6 pts.) Multiply the elements of the first column by the corresponding elements of the fourth column and place the result in the first column. (6 pts.) Set the diagonal elements to 2. (6 pts.) Print the matrix z either row-wise or column-wise e)

Explanation / Answer

(a)

% divide second column by sqrt(3)
x( : , 2 ) = x( : , 2 ) / sqrt(3);

(b)

% get the dimensions of x
[ m , n ] = size(x);

% add the third row to fifth row

for j = 1 : n

   

    x(5 , j) = x(5 , j) + x(3 , j);

   

end

(c)

% multiply the element of first column with the element of fourth column

for i = 1 : m

   

    x( i , 1 ) = x( i , 1 ) * x( i , 4 );

   

end

(d)

% set the diagonal elements to 2

for i = 1 : m

   

    for j = 1 : n

       

        % if current element is diagonal element

        if i == j || i == m - j + 1

           

           x( i , j ) = 2;

           

        end

       

    end

   

end

(e)

for i = 1 : m

   

    fprintf('Row %d : ' , i);

   

    for j = 1 : n

       

        fprintf('%d ', x(i,j));

       

    end

   

    fprintf(' ');

   

end

Complete Code

x = [ 17 24 1 8 15 ; 23 5 7 14 16 ; 4 6 13 20 22 ; 10 12 19 21 3 ; 11 18 25 2 9 ];

% divide second column by sqrt(3)

x( : , 2 ) = x( : , 2 ) / sqrt(3);

% get the dimensions of x

[ m , n ] = size(x);

% add the third row to fifth row

for j = 1 : n

   

    x(5 , j) = x(5 , j) + x(3 , j);

   

end

% multiply the element of first column with the element of fourth column

for i = 1 : m

   

    x( i , 1 ) = x( i , 1 ) * x( i , 4 );

   

end

% set the diagonal elements to 2

for i = 1 : m

   

    for j = 1 : n

       

        % if current element is diagonal element

        if i == j || i == m - j + 1

           

           x( i , j ) = 2;

           

        end

       

    end

   

end

for i = 1 : m

   

    fprintf('Row %d : ' , i);

   

    for j = 1 : n

       

        fprintf('%d ', x(i,j));

       

    end

   

    fprintf(' ');

   

end

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