1.

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))The question was asked in homework.My enquiry is from Solving Equations topic in portion MATLAB Basics of MATLAB

Answer»

The CORRECT answer is (c) vpa(solve(‘cos(x)=1/2’))

The explanation is: 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.



Discussion

No Comment Found

Related InterviewSolutions