This set of MATLAB Multiple Choice Questions & Answers (MCQs) focuses on “Solving Equations”.
1. What is the syntax to solve simultaneous equations easily?
b) sol[“equation-1” “equation-2”];
Explanation: To solve equations simultaneously, we need to place the equations within the pre-defined MATLAB function ‘solve’ as string arguments within a pair of single inverted commas and separated by a comma. The function sol can also be used but the syntax within the third bracket is same. So, solve[‘equation-1’,‘equation-2’]; is correct.
2. An employer has to minimize the number of lines in a program while writing the code for a purpose. If the purpose is to find the root of the following equation, which function is to be used?
Explanation: The function polyval() returns the value of a dependent variable by taking arguments of the independent variable. ‘sol’ returns the values in a vector form but does not display the exact values. If we use ‘solve’, we have to write the entire equation in a string. ‘roots()’ allows the user to only insert the coefficients of the polynomial and it will return the roots of the equation formed by the coefficients entered.
Output: roots([1 -4 3] ans=1 3
3. What is the difference between sqrt(10) and sqrt(sym(10))?
a) There is no difference
b) sqrt(sym(10)) is incorrect
c) There is no function as sqrt
d) sqrt(10) returns exact value while sqrt(sym(10)) returns 10(1/2)
Explanation: ‘sqrt()’ is a predefined function used to find a square root of large numbers to reduce the complexity of equation. sqrt(sym(10)) introduces 10 as a symbolic object to the MATLAB workspace.
Thus it will return 10(1/2) as a symbolic expression and won’t divulge the exact root. This helps often to reduce an equation before increasing program complexity in MATLAB.
4. The solve command can do which of the following things?
a) Produce the exact solution
b) Produce a symbolic solution
c) Produces exact roots
d) Produces complex roots
Explanation: The solve function is an inbuilt function to generate the solutions of one or more than one equations. But the result is always produced in symbolic form. So, even if the answer contains the value of square root of 5, solve will return the value as sqrt(sym(5)).
5. What should be the output for the following code?
d) fzero is not a function
Explanation: While introducing the function within fzero, there should be a zero crossing point near the value where we expect a solution. But in the above code, it is observable that there are no zero crossing points near 5. Thus MATLAB will return an error in computation which is a NaN value that has disrupted the process of the function fzero().
6. A student has to find the solution of an equation cos(x)=1/2. She has to write the program such that exact values are shown at output. Which of the following codes would help her?
a) syms x;eqn = cos(x) == 1/2;vpa( solve(eqn,x))
b) syms x;eqn = cos(x) == 1/2;solve(eqn,x)
d) syms x;eqn = cos(x) = 1/2;vpa(solve(eqn,x))
Explanation: To find the exact value of non-integer constants, we use the function ‘vpa()’. MATLAB won’t understand sin(x)=1 as an equation until we initialise x as a symbolic variable. syms x;eqn = cos(x) == 1/2;vpa( solve(eqn,x)) would’ve generated the same answer but it has 3 lines while vpa(solve(‘cos(x)=1/2’)) has only 1 line. Once we introduce the variable x as a string, MATLAB understands that it is a symbolic object.
Output: syms x;eqn = cos(x) == 1/2;vpa( solve(eqn,x)) ans = -1.0471975511965977461542144610932 1.0471975511965977461542144610932
7. Find the error in the following code?
Predicted output: (b + (b2 - 4*a*c)(1/2))/(2*a) (b - (b2 - 4*a*c)(1/2))/(2*a) Code: solve (b*x2 + c*x + a == 0) Present output: -(c + (c2 - 4*a*b)(1/2))/(2*b) -(c - (c2 - 4*a*b)(1/2))/(2*b)
a) Predicted output is same as present output after math magic
b) solve(a*x2 + b*x + c == 0)
c) vpa(solve(a*x2 – b*x + c == 0))
d) solve(a*x2 – b*x + c == 0)
Explanation: MATLAB returns variables in the order we enter them. Now, both option (a*x2 + b*x + c == 0) and (a*x2 – b*x + c == 0) are okay but the predicted output is returned in symbolic form. We see that 1⁄2 is written as 0.5. Thus vpa is not to be written in the line of code, since it returns exact values and not symbolic values.
8. Which program can help to solve the following differential equation?
a) syms y(t) a;equn = diff(y,t)==b*y;cnd=y(0)==5;ySol(t)=dsolve(equn,cnd)
b) syms y(t) a;eqn = diff(y,t) == a*y;ySol(t) = dsolve(eqn,(y(0)=5);
c) syms y(t) a;eqn=diff(y,t)=a*y;cond=y(0)==5 sol(t)=dsolve(eqn,cond);
d) sym y(t) a; eqn=diff(y,t)==a*y;cond=y(0)==5;sol(eqn,cond);
Explanation: To solve an ordinary differential equation using MATLAB, we use the syntax dsolve(eqn,cond). The cond variable has to be written in the format ‘cond= indep variable(instant for condition)== conditional value. This cond has to be predefined before applying it in the dsolve function.
9. What happens if dsolve does not return any numerical solution?
a) The equations have no solution
b) The equations have a trivial solution
c) The equations have infinite no. of solutions
d) The equation has to be solve separately
Explanation: We have to solve the differentiation numerically. To do it in MATLAB, we need to use ode45 after converting the differential equation to a system of first order differential equation.
10. If solve does not return any solution, what does it imply?
a) The equation has no definite solution
b) The equation has a solution for a specific interval
c) The equation may be solvable but the function ‘solve’ cannot produce a solution
d) There is no function ‘solve’
Explanation: It may so happen that an equation may not be solvable but due to some mistake, the function solve0 has encountered an argument which is an equation whose Left hand side could never be equal to the right hand side. It may also happen that some separate solution is present but the function cannot produce the solutions. We need to check separately for such cases by applying some other methods of solving equations though, generally, this does not happen.
Sanfoundry Global Education & Learning Series – MATLAB.
To practice all areas of MATLAB, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Apply for Electrical & Electronics Engineering Internship
- Apply for Electronics & Communication Engineering Internship
- Practice Electrical & Electronics Engineering MCQs
- Check MATLAB Books
- Apply for MATLAB Internship