Wrong symbolic solution for trigonometry
Ältere Kommentare anzeigen
syms x
solve(sin(x)/cos(x)==-3.0)
and
syms x
solve(tan(x)==-3.0)
Produces different result instead of Wolfwram and ti-89 who produces same result for these operations.
4 Kommentare
Both are solutions, only written more or less complicated:
syms x
sol1 = double(solve(sin(x)/cos(x)==-3.0))
tan(sol1)
sol1(2) + pi
and
syms x
sol2 = double(solve(tan(x)==-3.0))
tan(sol2)
Boris
am 7 Nov. 2023
Torsten
am 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
am 7 Nov. 2023
Bearbeitet: John D'Errico
am 7 Nov. 2023
No. Both solutions returned are absolutely valid.
syms x
xsol = solve(sin(x)/cos(x)==-3.0)
vpa(sin(xsol)./cos(xsol))
vpa(xsol)
Now, compare that result to
atan(-3) + [pi,0]
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
Akzeptierte Antwort
Weitere Antworten (1)
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)
format long
double(s1)
syms x
s2 = solve(tan(x)==-3.0)
double(s2)
14 Kommentare
syms x
solve(tan(x) == -3,'returnconditions',true)
On problems with infinitely many solutions, solve returns one solution if you just ask for a solution. 'returnconditions" gets solve to try to generate the complete family of solution, as it did here. On polynomial problems, it is sometimes able to return all solutons, but this is not a polynomial, even though any school kid SHOULD be able to give the complete solution locus. So you need to push it to get the complete set of solutions.
Torsten
am 7 Nov. 2023
Why do you say "wrong" ? All solutions x from the symbolic toolbox so far satisfy tan(x) = -3.
Steven Lord
am 8 Nov. 2023
MATLAB may not return the answer you expected. That does not mean the answer MATLAB returned is incorrect.
If you asked me "What number, when squared, equals 4?" the answer you may expect is 2. But -2 is an equally valid answer.
Boris
am 8 Nov. 2023
Torsten
am 8 Nov. 2023
As @Steven Lord says: If you have the equation x^2 = 4 and one tool gives you the solution x = 2 and another the solution x = 2 or x = -2, then neither tool is wrong. The solution of the first tool is incomplete, but not wrong.
Boris
am 8 Nov. 2023
Because all angles of the form angles = k*pi - atan(3) for k integer lead to tan(angles) = -3:
k = -5:5;
angles = k*pi - atan(3)
tan(angles)
Boris
am 8 Nov. 2023
Because it most probably uses two different methods to solve it.
In the first case, it can directly apply the atan function and returns atan(-3).
In the second case, it maybe squares the equation and uses sin(x)^2 + cos(x)^2 = 1 to get a quadratic equation either in sin(x) or cos(x). And a quadratic usually has two solutions. But this is speculation - I don't have insight into the internals of the symbolic toolbox.
Hi @Boris
The second one is the application of the inverse function.
The first one, MATLAB probably rearranges the equation

syms x
xsol = solve(sin(x) + 3*cos(x) == 0)
xsol = double(xsol)
y = @(x) sin(x) + 3*cos(x);
fplot(y, [-1.5 2]), hold on
plot(xsol(1), 0, 'x', 'markersize', 12, 'linewidth', 3), grid on
plot(xsol(2), 0, 'o', 'markersize', 12, 'linewidth', 3)
Torsten
am 8 Nov. 2023
This looks better than my guess. Thank you, Sam.
Boris
am 8 Nov. 2023
syms x
eqn = sin(x)/cos(x)==-3.0
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)
simplify(sol.x, 'steps', 500)
sol.conditions
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
Kategorien
Mehr zu Symbolic Math Toolbox finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!









