MATLAB Multiple Choice Questions on “Solving Equations”.
1. What is the syntax to solve simultaneous equations easily?
a) solve[“equation-1”,”equation-2”];
b) sol[“equation-1” “equation-2”];
c) sol[‘equation-1’‘equation-2’];
d) solve[‘equation-1’,‘equation-2’];
Answer: d
Clarification: 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?
x2-4x+3=0
a) polyval()
b) solve[]
c) sol[]
d) roots([])
Answer: d
Clarification: 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)
Answer: d
Clarification: ‘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
Answer: b
Clarification: 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?
t=linspace(0,10);fzero(inline('t+t2'), 5);
a) Nan
b) -0.000000000000000000000000117191203927370461282452866337
c) -1.1719e-25
d) fzero is not a function
Answer: a
Clarification: 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)
c) vpa(solve(‘cos(x)=1/2’))
d) syms x;eqn = cos(x) = 1/2;vpa(solve(eqn,x))
Answer: c
Clarification: 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
