This set of MATLAB Multiple Choice Questions & Answers (MCQs) focuses on “Syntax Error – 1”.

1. What is the error in the following?

input(“pop”)

a) None

b) “”

c) Parentheses

d) No such command

View Answer

Explanation: 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?

for i={1: 10} p=a+1 end

a) None

b) {}

c) The : operator

d) Cannot be determined

View Answer

Explanation: 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?

limit[1/x,0]

a) NaN

b) Inf

c) Syntactical Error

d) Logical error

View Answer

Explanation: 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?

length{ 1 2 }

a) Error due to space after 2

b) Error due to {}

c) Syntactical Error

d) 2

View Answer

Explanation: 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?

limit((1 + 1/n)^n,n=Inf)

a) e

b) exp(1)

c) Syntactical Error

d) Cannot be determined

View Answer

Explanation: 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.

6. What is the output of the following code?

A={1 2 3 4} sum(A)

a) Error

b) 10

c) { 10 }

d) Logical Error

View Answer

Explanation: 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

View Answer

Explanation: 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?

mean({1 2 3})

a) 2

b) Logical Error

c) 1

d) Syntactical Error

View Answer

Explanation: 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

View Answer

Explanation: 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 [].

10. What is the output of the following code?

(1 2);

a) A cellular vector of dimension 1*2

b) A vector of dimension 1*2

c) A matrix of dimension 1*2

d) Error

View Answer

Explanation: 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?

p=[1 3 2]; roots[p];

a) Syntactical Error

b) Undefined roots

c) -2,-1

d) Cannot be determined

View Answer

Explanation: 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?

poly[ 1 2 3]

a) x + 2x + 3x^{2}

b) x^{3} + 2x^{2} + x

c) Error

d) Cannot be determined

View Answer

Explanation: 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?

polyint[{1 2 3}]

a) Syntactical error due to []

b) Syntactical Error due to {}

c) Logical Error

d) [1/2,1,3]

View Answer

Explanation: 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.

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

View Answer

Explanation: 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

View Answer

Explanation: The polar command is pre-defined in MATLAB and it only takes inputs within a parentheses only. Hence, the above statement is false.

**Sanfoundry Global Education & Learning Series – MATLAB.**

To practice all areas of MATLAB, __here is complete set of 1000+ Multiple Choice Questions and Answers__.

**Next Steps:**

- Get Free Certificate of Merit in MATLAB
- Participate in MATLAB Certification Contest
- Become a Top Ranker in MATLAB
- Take MATLAB Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

**Related Posts:**