# Wrong symbolic solution for trigonometry

5 views (last 30 days)
Boris on 7 Nov 2023
Commented: Walter Roberson on 8 Nov 2023
syms x
solve(sin(x)/cos(x)==-3.0)
ans =
and
syms x
solve(tan(x)==-3.0)
ans =
Produces different result instead of Wolfwram and ti-89 who produces same result for these operations.
Torsten on 7 Nov 2023
Both are correct as you can see when tan is applied to the results.
As you can see from the calculation, -log(-sqrt(-16/5-12/5*i)/2)*i equals atan(-3) in the interval [0 pi], -log(sqrt(-16/5-12/5*i)/2)*i equals atan(-3) in the interval [-pi 0].
John D'Errico on 7 Nov 2023
Edited: John D'Errico on 7 Nov 2023
No. Both solutions returned are absolutely valid.
syms x
xsol = solve(sin(x)/cos(x)==-3.0)
xsol =
vpa(sin(xsol)./cos(xsol))
ans =
vpa(xsol)
ans =
Now, compare that result to
atan(-3) + [pi,0]
ans = 1×2
1.8925 -1.2490
As you can see, both are perfectly valid, mathematically correct solutions.
solve generated two solutions as it was used there, probably because sin(x)/cos(x) can reduce to an implicit quadratic polynomial problem. So it looks like solve did the transformation, then solved the resulting quadratic, with the result being two valid solutions from the general solution locus:
atan(-3) + k*pi

Walter Roberson on 8 Nov 2023
syms x
sol = solve(sin(x)/cos(x)==-3.0)
sol =
sola = rewrite(sol, 'atan')
sola =
simplify(sola, 'steps', 100)
ans =
simplify(sola, 'steps', 5000)
ans =
At the moment I do not know why it is able to identify atan(3) in the first row at the bottom, but not identify atan(3) in the second row, even though with steps 100 it was able to identify that the two are the same except + pi for one of them.

Les Beckham on 7 Nov 2023
It looks like your second solve construct only returns one of the solutions. Someone who knows the symbolic toolbox better than I do may be able to explain why.
syms x
s1 = solve(sin(x)/cos(x)==-3.0)
s1 =
format long
double(s1)
ans = 2×1
1.892546881191539 -1.249045772398254
syms x
s2 = solve(tan(x)==-3.0)
s2 =
double(s2)
ans =
-1.249045772398254
Boris on 8 Nov 2023
@Torsten @Sam Chak thank you for clarification.
Walter Roberson on 8 Nov 2023
syms x
eqn = sin(x)/cos(x)==-3.0
eqn =
LS = lhs(eqn);
RS = rhs(eqn);
fplot([LS, RS], [-2*pi 2*pi])
Each intersection of a blue line with the red line is a solution. You can see that there are an infinite number of solutions.
sol = solve(eqn, 'returnconditions', true)
sol = struct with fields:
x: [2×1 sym] parameters: k conditions: [2×1 sym]
simplify(sol.x, 'steps', 500)
ans =
sol.conditions
ans =
Infinite number of solutions π apart.
MATLAB probably could have generated the unified series but that does not mean it was wrong to generate the forms that it did generate. It is a common approach to analyze in terms of full cycles

### Categories

Find more on Numeric Solvers in Help Center and File Exchange

R2023b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!