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.

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
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
 

Tìm kiếm

Back
Top