MATLAB Questions and Answers – Algebra

«
»

This set of MATLAB Multiple Choice Questions & Answers (MCQs) focuses on “Algebra”.

1. What is the difference between syms ‘x’ and sym ‘x’?
a) there is no difference, they are the same functions
b) they are equivalent
c) syms ‘x’ makes the declaration long lasting while sym ‘x’ makes the declaration short lasting
d) syms ‘x’ makes the symbol short lasting while sym ‘x’ makes the declaration long lasting
View Answer

Answer: c
Explanation: sym ‘x’ makes the declaration short lasting. If it is assigned to a variable, x say, the function is equivalent to syms ‘x’. This makes syms ‘x’ long lasting.
advertisement

2. What is the nature of the arrangement of the coefficients to store the following expression in MATLAB?

y= 3x5 + x2 + 6

a) y=[3,0,0,1,0,6]
b) y=[3,1,6]
c) y=[3;0;0;1;0;6]
d) y=[6,0,1,0,0,3]
View Answer

Answer: a
Explanation: To enter the co-efficient of a polynomial, the variable terms are arranged in descending order of the power of the variable. It cannot be a column vector. If the descending order is not consecutive, one has to put 0 within the row vector to indicate that the co-efficient of the missing order is zero.
advertisement
advertisement

3. In the function vpa(‘981’,10), why do we put 981 within inverted commas?
a) We can choose to not put the value within a pair of single inverted comma
b) We do it so that we don’t get an approximated value
c) We do it to get the exact value as MATLAB computes exact values, of numerical expressions, when declared within a string
d) We do it to get a floating-point approximated value, approximated to 14 digits
View Answer

Answer: c
Explanation: Variable precision arithmetic in MATLAB is perfected by computing exact values and exact values are evaluated if the numerical expression is within a string. By not placing the pair of inverted commas, we get a floating point approximated value.

4. How would you simplify log(x20) – log(x13) – log(x7) in MATLAB? (Assume x is defined as a string variable)
a) simplify(log(x20)-log(x13)–log(x7));
b) log(x20) – log(x13) – log(x7)
c) simplify(log(x20)-log(x13)–log(x7),’IgnoreAnalyticConstraints’,true)
d) simplify(log(x20)-log(x13)–log(x7))
View Answer

Answer: c
Explanation: Option simplify(log(x20)-log(x13)–log(x7),’IgnoreAnalyticConstraints’,true) would evaluate to 0. The cases are used to produce a greater simplified expression for a polynomial. simplify(log(x20)-log(x13)–log(x7)) does not give any different output but the expression itself. Option log(x20) – log(x13) – log(x7) is incorrect since the powers should be represented as log(x20) in MATLAB.
advertisement

5. What happens if we don’t assign a variable to an expression which evaluates a numerical value?
a) MATLAB shows error
b) Nothing happens
c) The evaluated values are assigned to a variable ans automatically
d) Depends on the numerical value
View Answer

Answer: c
Explanation: This is common for MATLAB. The evaluated numerical values are assigned to a variable ans if there is no body in the right hand side of a numerical expression. So the options MATLAB shows error is false.

6. MATLAB sees a ________ ordered variable as a vector of dimension n*1.
a) nth, (n+2)th
b) nth, (n+3)th
c) (n-1)th, nth
d) nth, (n-1)th
View Answer

Answer: c
Explanation: The row vector which consists of the co-efficients of variables of a (n-1)th ordered polynomial in descending order is an nx1 vector where the last term is a constant term of the expression. The rest of the options are incorrect by the above statement.
advertisement

7. What will be the output for the below block of code?

	P=[1 3 2]; r=roots(P);

a) r=[-2,-2]
b) r=[-2 -1]
c) There is an error in the code
d)

   r = -2
       -1
View Answer
Answer: d
Explanation: The function roots(p) generate a column vector, and not a row vector, containing the roots of a polynomial. So option a and b cannot be the answer and there is no error in the code. The answer is option d.
Output:

   r = -2
       -1
 
 

advertisement

8. Name the functions used, for multiplication and division of two polynomials in MATLAB.
a) conv() and deconv()
b) mult() and div()
c) conv() and div()
d) mult and div
View Answer

Answer: a
Explanation: Multiplication in a time domain is convolution in a frequency domain. This is the reason for the existence of MATLAB functions conv(), for multiplication of signals, and deconv() for division of signals. There are no functions like mult() and div().

9. How can the formulation of polynomial be done from its roots?
a) poly(r), r is a row vector, containing the roots of the polynomial
b) poly([roots as a coloumn vector])
c) poly([roots as a row vector])
d) poly([roots in descending order as a coloumn vector])
View Answer

Answer: b
Explanation: To find the roots, one has to store the given roots in a 1*n column vector, say p, and then extract the co-efficients of the polynomial by typing poly(p). This would return the co-efficients of the polynomial in descending order from left to right.

10. The function to evaluate the value of a polynomial,l for a constant value of the independent variable(say a) in the polynomial is ______
a) poly(p,a), p is a row vector
b) polyder(p)
c) polyint(p)
d) polyval(c,a), c is a row vector
View Answer

Answer: d
Explanation: polyder(p)and polyint(p) produces the differentiation and integration of the polynomial p. Polyval(c,a) is the correct form of the function to evaluate the value of a polynomial whose independent variable is a. The value of a has to be provided first before writing the function.

Sanfoundry Global Education & Learning Series – MATLAB.

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

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

advertisement
advertisement
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter