What is the value of X at the end of this MATLAB code X2 for

What is the value of X at the end of this MATLAB code? X=2; for X = [X, 2*X]; end 2. X= [2 4 6 8] X= [2 4 4 8 4 8 8 16] X= [2 4 6 8 16] X= [2 4 6 4 8] X= [2 4 4 4 8]

Solution

The value of X is:

X=

2    4    4    8    4    8    8   16

Correct Answer is:- B

----------------------

Explanation :-

Execute this Code on matlab compiler:-

X=2;
for i=-1:-1:-3
{
X=[X, 2*X];
fprintf(\'value of x: %d\ \', X);
}
end
X

-----------------------------------------------------------------

Initially X=2, now it for loop execute three times(i=-1,-2,-3)

Steps (1). for i=-1, X= 2 and X=[X, 2*X] so X= 2 4

Step (2) for i=-2 , X=4 and X=[X, 2*X] so X= 4, 8

Step (3) for i=-3 and X=[X,2*X] will be 4    8    8   16 (here X=[4, 4*2] will be 4 8 and X=[8, 8*2] will be 8 16)

---------------------------------------------------------------------------------------------------------------------

If you have any query, please feel free to ask.

Thanks a lot.

 What is the value of X at the end of this MATLAB code? X=2; for X = [X, 2*X]; end 2. X= [2 4 6 8] X= [2 4 4 8 4 8 8 16] X= [2 4 6 8 16] X= [2 4 6 4 8] X= [2 4

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site