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

What will be the outputs of the program? Explain. If the statement \'b = reshape

ID: 3764069 • Letter: W

Question

What will be the outputs of the program? Explain. If the statement 'b = reshape (a,1, m*n)' as shown below, is inserted to convert the 'a' matrix to a row vector 'b' using the reshape command. Complete the rest of the script file using the 'b' vector so that the output is same as in (i). prod = 2; sum = 10; a - [2 1 1 5; 4 8 6 7; 8 9 10 11]; (n,m) = size(a); b = reshape(a, 1, m*n); % insert code here that uses the b-vector to produce the same output as in part (i) using the 'disp' statements disp (['Product2 = num2str(prod)J); disp (('Sum10=', num2str(sum)]); What will be the output of the MATLAB script provided below: x = 3; a= 10; while (x

Explanation / Answer

a)

%Code:

prod=2;
sum=10;
a=[2 1 1 5;4 8 6 7;8 9 10 11];
[n,m]=size(a);
b=reshape(a,1,m*n);
prod=prod+prod(b);
sum=sum+ sum(b);
disp(['product2=' num2str(prod)]);
disp(['sum10=' num2str(sum)])

=========================================================

b)

ans: a=40

Reason:

Iteration 1: x is 3 and this is less than 8.

So

x= x+2.5 => 3+2.5=> 5.5

a= a*2 = 10*2 => 20

Iteration 2: x is 5.5 and this is less than 8.

So

x=x+2.5=>5.5+2.5 =>8

a= 20*2 = 20*2 => 40

Iteration 3: x is 8 and condition x<8 will not hold. So stop

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