Question
explain please
What is the value of X at the end of this MATLAB c
0 0
Add a comment Improve this question Transcribed image text
Answer #1

*********************program**************************

octave:1> x=2

x = 2

octave:2> for i=-1:-1:-3

> > x=[x,2*x]

> > end

***********************output****************************

x =

   2   4

x =

   2   4   4   8

x =

    2    4    4    8    4    8    8   16

******************************explaination*************************

initial x value=2

for loop starts from -1 till it reaches to -3 by incrementing -1 step at a time

so, for expression                     x=[x , 2*x]

i value

X value

Expression x=[ x, 2*x]

Output

-1

2

                     =[2,2*2]     

[2,4]

-2

4

                      =[4,2*4]

[4,8]

-3

8

                     =[8,2*8]

[8,16]

Finally answer will be:

x =

    2    4    4    8    4    8    8   16

Add a comment
Answer #2

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\n', 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.

Add a comment
Know the answer?
Add Answer to:
explain please What is the value of X at the end of this MATLAB code? X=2;...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT