MATLAB: Trigonometric equation thestery

equationoutput

Can someone please explain the different results:
syms x
eqn = 2*cos(2*x) – 2*cos(-2*x + 60) == 0;
soln = solve(eqn,x)
OUTPUT
soln =
15
——- AND (using the identity: cos(α – β) = cos(α) cos(β) + sin(α) sin(β)) ——-
syms x
eqn = 2*cos(2*x) – 2*(0.5*cos(2*x) + (sin(2*x)*0.8660)) == 0;
soln = solve(eqn,x)
OUTPUT
soln = -(log(-(499956/249989 + 866000i/249989)^(1/2)/2)*1i)/2 -(log((499956/249989 + 866000i/249989)^(1/2)/2)*1i)/2
Thanks,
Oz

Best Answer

First, you need to understand that sqrt(3)/2 is NOT 0.8660. There is a difference. Small errors like that will often be significant.
Second, you need to recognize that sin and cos are written to work in RADIANS. This is true of most programming languages. So, while 60 may mean 60 degrees to you, MATLAB will generally interpret it in the form of 60 radians.
So, IF 60 is intended to be in the form of radians, then we have:
sin(60)
ans =
-0.30481
cos(60)
ans =
-0.95241
However, since you seem to have substituted 1/2 for cos(60), I can only assume that you intended the number 60 to be in degrees.
Substituting the identity you used, we get:
soln = solve(2*cos(2*x) - 2*(cos(-2*x)*1/2 - sin(-2*x)*sqrt(3)/2) == 0,x)
soln =
-(log(- 3^(1/2)/2 - 1i/2)*1i)/2
-(log(3^(1/2)/2 + 1i/2)*1i)/2
That may not look like 15 degrees to you, but...
rad2deg(double(soln))
ans =
-75 + 1.6214e-71i
15 + 1.6214e-71i
Feel free to ignore the imaginary part, that is 71 powers of 10 smaller than the real part. It is zero.
So there is no mystery at all. Apparently the symbolic toolbox was intelligent enough that it saw your original equation with the number 60 inside a trig function, and realized that you must be working in degrees.