Wrong or Unexpected Output

MATLAB

This set of MATLAB Multiple Choice Questions & Answers (MCQs) focuses on “Wrong or Unexpected Output”.

1. What is the output of the following code?

cos(pi/2)

a) 0
b) Close to 0
c) less than 0
d) Undefined

2. What is the output of the following code?

sprintf(“5%”)

a) “5”
b) “5%”
c) 5
d) 5%

3. Why isn’t the answer 10.230?

>> sprintf("%1.3d", 10.23)
 ans = 
       "1.023e+01"

a) We’ve used %d
b) We’ve used “”
c) Character arrays are like this
d) Undefined answer

4. How many times will the loop run?

for i={1:.1:5}
p=p+1;
end

a) 50
b) Infinite
c) 0
d) 1

5. What is the output of the following code?

A=[1 2 3 0; 4 5 6 8; 1 2 3 4; 1 3 4 5 ; 4 0 0 0 ];
length(A)

a) 5
b). 4
c) 5*4
d) 4*5

6. What will be the result after we press Return?

>> input('Ro !')
Ro ! Ho !

a) ans= Ho !
b) Error
c) No such command named input
d) Cannot be determined

7. A student wants to find the following limit
 but he writes the following code
limit(1-cos(2*x)/x^2,x,0)
What will he get?
a) a2/2!
b) a2/2
c) Error
d) -Inf

8. How long will ‘Hola !’ get printed?

>>input(‘Hola !’)
Hola !

a) Until a value is given as an input
b) Until a character is given as an input
c) Until anything is given as an input
d) Once

9. What is the output of the following code?

syms x
limit(1/-x,x,-0)

a) NaN
b) Inf
c) 0
d) Syntactical error

10. Why did the following happen?

>> p
p = 
    "10"
>> p+1
ans = 
     "101"

a) p is a character array
b) p is binary
c) Error
d) Cannot be determined

11. Why di the following happen?

>> sprintf("   %   ")
ans = 
     "  "

a) Error
b) % is not recognized
c) % is an operator
d) Cannot be determined

12. What is the output of the following code?

det([1 2 3; 4 5 6; 7 8 9])

a) Error
b). 0
c) -0
d) A very small value

13. What is the output of the following code?

 >> { 1 2}
 ans = 
   1*2 cell array
     [1]   [2]
>> ans+{3 4}

a) { 1 2 3 4}
b)

     { 1 2
       3 4}

c) { 4 6}
d) Error

14. What is the output of the following code?

tf2zp({1 2}, {2 1})

a) 0
b) Returns the zeros and poles of the transfer function (s+2)/(2s+1)
c) Syntactical Error
d) Logical Error

15. What is the output of the following code?

syms ‘t’,’p’;

a) Both t and p are defined as symbolic
b) Only t gets defined as symbolic
c) Only p gets defined as symbolic
d) Nothing happens

Leave a Reply

Your email address will not be published. Required fields are marked *