Basic MATLAB Questions and Answers on “Evaluation – 2”.
1. What is the output of the following code?
feval[‘round’,123.12]
a) 123
b) 123.12
c) 123.1
d) Error
Answer: d
Clarification: The input arguments to the feval command cannot be given within [], it should be included within parentheses. Hence, an error will be returned. If the input was within parentheses, the output would’ve been 123 only.
2. The feval command can evaluate __________
a) A single command
b) Multiple commands
c) Multiple functions
d) No such function exists
Answer: a
Clarification: The input string argument to the feval command should contain only 1 command. If we give multiple commands to be evaluated, it will give an error.
3. The eval command can evaluate __________
a) A single function
b) Only a single command
c) The function does not exist
d) Multiple commands
Answer: d
Clarification: The eval command can evaluate multiple commands at the same time and show their answer but it cannot assign to variables.
4. The input to the eval command is given using [].
a) True
b) False
Answer: b
Clarification: The input argument to the feval command is given within parentheses. Hence, MATLAB will return an error if we use [].
5. The input to the evalc command is given using {}.
a) True
b) False
Answer: b
Clarification: The input argument to the evalc command is given within parentheses. Hence, MATLAB will return an error if we use {}.
6. What is the value of ans from the following code?
feval(‘sin(0),cos(0),123’)
a) 123
b) 0,1,123
c) Error
d) 0
Answer: a
Clarification: The value of ans will keep changing after every expression gets evaluated in the string argument. So the final expression is 123 which will be the last value assigned to the ans variable.
Output: 123
7. What is the output of the following code?
a) Syntactical Error
b) Symbolic error
c) ‘1/s2‘
d) 1/s2
Answer: b
Clarification: There is an error in the following code. It would’ve simply evaluated the laplace transform of t which is 1/s2 but t is not defined as symbolic. Hence, MATLAB will return an error.
8. Which function gets disabled while using evalc()?
a) diary
b) sin
c) inf
d) round
Answer: a
Clarification: The diary command gets disabled when we try to use the evalc command in MATLAB. The commands sin and round work just fine while Inf is not a function.
9. How much does the precision change while finding sin(x) using evalc and eval?
a) 10%
b) 2%
c) 20%
d) No change
Answer: d
Clarification: The purpose of both the commands is simply to make the commands, provided in the input argument, work. They do not hamper the precision with which the commands evaluate a value.
basic questions and answers on ,
