
why solve function does not return answer?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
syms b
eq1 = 1/tan(b);
sol=solve(eq1)
the equation above should give answer pi/2 or pi/2+n*pi
but solve doesnt give the answer...
What is the problem with my code?
0 Commenti
Risposte (1)
Rushil
il 18 Feb 2025
Hi there
The solve function is used to find explicit values where a given equation is satisfied. In the problem, we have the following equation:
eq1 = 1/tan(b);
This means that you would require “tan(b)” to take on an infinite value, which is not directly solvable in the typical sense. Since the solver sees the “tan(b)” function, it may realize that “tan(b)==inf” is an asymptote, and may not be able to find the solution.
A workaround is to consider a function that is not asymptotic at the expected solution. The equation can be rewritten using cos or cot functions, which are easier to deal with since they are not asymptotic at
.
syms b
eq1 = cot(b); % or cos(b) since cot(b)=cos(b)/sin(b)
sol = solve(eq1,'ReturnConditions', true)
Changing the definition of “1/tan(b)” to “cot(b)” resolves the problem, even though both are equivalent. This is because the solver must deal with asymptotes in the former and can avoid them in the latter. Below are plots of the tan and cot functions which illustrate asymptotic behaviour.

Hope it clarifies the problem
larush
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!