250+ TOP MCQs on Syntax Error – 1 and Answers

MATLAB Multiple Choice Questions on “Syntax Error – 1”.

1. What is the error in the following?

a) None
b) “”
c) Parentheses
d) No such command
Answer: b
Clarification: The input to the input command should be within ‘’ and not “”. Double-inverted commas will lead to a syntactical error in MATLAB.

2. What is the error in the following code?

a) None
b) {}
c) The : operator
d) Cannot be determined
Answer: a
Clarification: MATLAB won’t give any error. but the loop will only run once because we have a syntactical error while defining the conditions for the loop.

3. What is the output of the following code?

a) NaN
b) Inf
c) Syntactical Error
d) Logical error
Answer: c
Clarification: The input to the limit command should be within parentheses. But here, the input is given within []. This leads to an error in MATLAB.

4. What is the output of the following code?

a) Error due to space after 2
b) Error due to {}
c) Syntactical Error
d) 2
Answer: c
Clarification: The input to the length function has to be within a parentheses. We don’t see the parentheses here, and we’ll find that this leads to an error in MATLAB.

5. What is the output of the following code?

a) e
b) exp(1)
c) Syntactical Error
d) Cannot be determined
Answer: c
Clarification: The correct syntax would be to simply state the limiting value as Inf. This is for new versions of MATLAB. The above code would result in a syntactical error.

  250+ TOP MCQs on Laplace Transform – 1 and Answers

6. What is the output of the following code?

a) Error
b) 10
c) { 10 }
d) Logical Error
Answer: a
Clarification: The sum function doesn’t work on cellular arrays. So the vector A is to be placed within [] to avoid this kind of error.

7. What is the output of the following code?

limit({sin(x)/x},x,Inf,right)

a) 0
b) Inf
c) Syntactical error
d) Error due to inconsistency in approaching limit
Answer: c
Clarification: There is syntactical error in the above code snippet. The input, right, should be within a pair of single inverted commas. If that was so, there is still error due to inconsistency in approaching the limiting value because we cannot approach positive Infinity from it’s right hand side.

8. What is the output of the following code?

a) 2
b) Logical Error
c) 1
d) Syntactical Error
Answer: d
Clarification: Since the mean command uses the sum command, it also cannot accept cellular arrays as input since this input will go to the sum command first. Hence, the above code will give a syntactical error. Now, if we had given the input, within parentheses, within []- the output would’ve been 2 only.

9. What is the output of the following code?

det({1 2 3; 4 5 6; 7 8 9})

a) 0
b) Syntactical Error
c) A very small value
d) Cannot be determined
Answer: b
Clarification: The input to the det command cannot be a cellular array. Since we have given the vector within {}, it results in an error. The output would have been very small value if the mtrix was given within [].

  250+ TOP MCQs on Functions and Expressions and Answers

10. What is the output of the following code?

a) A cellular vector of dimension 1*2
b) A vector of dimension 1*2
c) A matrix of dimension 1*2
d) Error
Answer: d
Clarification: To create a vector, one needs to give the elements within [] and not within parentheses. Hence, the above code will result in a syntactical error.

11. What is the output of the following code?

a) Syntactical Error
b) Undefined roots
c) -2,-1
d) Cannot be determined
Answer: a
Clarification: The input to the roots command has to be within parentheses. Here, it’s given within [] so it’ll result in a syntactical error. If the input was given within parentheses, the output would’ve been -2,-1.

12. What is the output of the following code?

a) x + 2x + 3x2
b) x3 + 2x2 + x
c) Error
d) Cannot be determined
Answer: c
Clarification: The input to the poly command has to be within parentheses. If the input is a vector, one can define the vector, prior to giving it as an input, or give the input like poly([1 2 3]).

13. What is the output of the following code?

a) Syntactical error due to []
b) Syntactical Error due to {}
c) Logical Error
d) [1/2,1,3]
Answer: b
Clarification: The answer would’ve been d. But the input to the polyint command is a cellular array and this results in a syntactical error. But firstly, the input to the polyint command should be within parentheses. But here, the input is within [] which is the first error MATLAB finds.

  250+ TOP MCQs on Integration and Answers

14. What is the output of the following command?

>> x={1 2 3};
>> t=[1 2 3];
>> plot(x,t)

a) plots a ramp function
b) plots r(t)-r(t-3)
c) Error due to plot
d) Error due to x
Answer: d
Clarification: In the above code, x is a cellular array. It will create an error in the working of the plot command since the plot command cannot plot values in cellular arrays. Hence, there is a syntactical error while defining x for the plot command.

15. The input to the polar command is not necessary to be within parentheses.
a) True
b) False
Answer: b
Clarification: The polar command is pre-defined in MATLAB and it only takes inputs within a parentheses only. Hence, the above statement is false.

Scroll to Top