MATLAB Questions and Answers Part-14

1. We can generate the summation of a series, formed with a character, using ________
a) symsum
b) sum
c) symssum
d) int

Answer: a
Explanation: The in-built command to find the summation of a series generated due to a character is symsum. Since our function uses symbolic characters, we need to express our function within the symsum command to get the summation.

2. If the result of our summation is Infinity, what will MATLAB show?
a) Infinity
b) Nan
c) Inf
d) Error

Answer: c
Explanation: The sum function is inbuilt in MATLAB. It has been developed so that if the summation of our given series becomes infinite, it will return a Inf as an output.

3. What will be the output of the following code?
sin(symsum(k^2,1,Inf));
a) Nan
b) Inf
c) Error
d) Output is suppressed

Answer: d
Explanation: There is no error. MATLAB will first compute the expression within the sin() which will yield Inf. Thereafter, sin(Inf) is computed which is shown as Nan.

4. How does MATLAB get the symbolic character in the function, if it is not mentioned in symsum() command?
a) It cannot
b) It uses symvar()
c) It uses symsvar()
d) It uses symbvar()

Answer: b
Explanation: If we don’t specify our symbolic variable which is in our function, the symsum() command uses the symvar() command. This command returns the set of all symbolic variables present in the function. In this way, the symsum command will continue in the execution of generating summation.

5. The sum() command cannot do ____________
a) Infinite summation
b) Numeric summation
c) Long summation
d) signed summation

Answer: a
Explanation: The sum command always takes the total set of numbers to add. Since we cannot define a vector which extends up to Infinity, the sum() command cannot perform Infinite summation.

6. To calculate the sum of only absolute variables in a series, we use _________
a) sum(abs())
b) abssum()
c) sumabs()
d) abs(sum())

Answer: c
Explanation: sumabs() is a pre-defined function in MATLAB. It will select the absolute values from a series and find the summation of those values only. sum(abs()) will convert all the values in the series to their absolute values. abs(sum()) will give the absolute value of the summation.

7. What is the output of the following code?
sumsqr([1 2; NaN 4])
a) 21
b) Nan
c) Error
d) Inf

Answer: a
Explanation: Since Nan signifies not a number, the sumsqr() command will ignore it and generate the sum of squares of all the finite valued inputs. Hence, the answer is not Nan or Inf but 21. There is no error. So, Output is 21

8. What is the output of the following code:
sumsqr([Inf Inf; Inf Inf])
a) Inf
b) Nan
c) 0
d) Error

Answer: c
Explanation: The sumsqr only selects those values which are finite. Since we have not given any finite input to our argument matrix, the sumsqr() command will find the sum of 0 finite values. This leads to showing an output 0.

9. What is the output of the following code?
sumabs([Inf Inf; Inf Inf])
a) Inf
b) 0
c) Nan
d) Error

Answer: b
Explanation: The sumabs selects finite values amongst a given series. Since we have not given any finite input to our argument matrix, the sumabs() command cannot find values to add up This leads to showing an output 0. It won’t show Inf in spite of the fact that abs(Inf) shows Inf. There is no error.

10. To find the absolute value of the sum of squares of numbers in a series, we use_________
a) abs(sumsqr())
b) sumsqr()
c) sumsqr(abs())
d) abs(sqrsum())

Answer: a
Explanation: The command sumsqr () finds the sum of squares of finite variables in a series. If we give sumsqr(abs()), it will convert all the values in the series to absolute values so we won’t get the true sum of the series. sumsqr() will only give the sum of all the values in the series