all solutions of trigonometric equations

65 views
Skip to first unread message

Matteo

unread,
Mar 9, 2011, 10:01:35 AM3/9/11
to sympy
Hello! With sympy 0.6.7 how can I obtain (with solve, maybe) all
solutions of a simple trigonometric equation like 'cos(x)=0' (I mean:
x=1/2*pi+n*pi, with n Integer)?

Thanks!!
Matteo

Aaron S. Meurer

unread,
Mar 9, 2011, 2:13:26 PM3/9/11
to sy...@googlegroups.com
Hi.

Unfortunately, solve currently does not have that implemented.

In [66]: solve(cos(x), x)
Out[66]:
⎡π⎤
⎢─⎥
⎣2⎦

You could trick it into giving you the solutions you want by doing something like

In [67]: solve(cos(x - n*pi), x)
Out[67]:
⎡π + 2⋅π⋅n⎤
⎢─────────⎥
⎣ 2 ⎦

but that only works if you know ahead of time that the solutions are periodic with period n*pi.

But I think we should implement it in solve to be able to return the kind of solutions that you want.

Aaron Meurer

Chris Smith

unread,
Mar 9, 2011, 9:44:09 PM3/9/11
to sy...@googlegroups.com
Aaron S. Meurer wrote:
> Hi.
>
> Unfortunately, solve currently does not have that implemented.
>

Part of the problem is that the user shouldn't have to know if multiple solutions (in terms of a parameter n)are necessary, so they shouldn't have to send in an auxiliary variable (n)...but then if the solution has such a parameter, it (being a dummy) is not easily accessible by the user. This is the place where the polys12 'pure' comes in. When you get a solution that has `pi/2 + pure*pi` you will know how to replace and manipulate `pure` as it will be a singleton...or something.

/c

Matteo

unread,
Mar 11, 2011, 2:21:20 AM3/11/11
to sympy
Hello!
Thanks for reply. The only thing that I have in mind to generalize a
method to discover periodic solutions is to convert simple
trigonometric functions in exp/ln expressions with Eulero formulas:

$cos(x)=\frac{e^{ix}+e^{-ix}}{2}$
$sin(x)=\frac{e^{ix}-e^{-ix}}{2i}$

with 'i' imaginary unit, and 'x' a real value (if I'm right, 'x' must
be real). So, one could solve the equation with a substitution of
variables, like $w=e^{ix}$, and finally solve the equation for 'x',
but one could also to know that the equation $e^{ix}=e^{ia}$, with 'a'
real, has infinite solutions like $x=a+2n\pi$ with 'n' Integer ($e^{ia}
$ is periodic). I will try to search if sympy has some conversions
rules from trig to exp formulas, and maybe viceversa.

Matteo

Chris Smith

unread,
Mar 11, 2011, 3:12:57 AM3/11/11
to sy...@googlegroups.com
Matteo wrote:
>> I will try to search if sympy has some
>> conversions rules from trig to exp formulas, and maybe viceversa.
>>

h[2] >>> cos(2*x).rewrite(exp)
exp(-2*I*x)/2 + exp(2*I*x)/2

Christophe BAL

unread,
Mar 11, 2011, 6:47:23 AM3/11/11
to sy...@googlegroups.com
Hello.

trigonometric functions in exp/ln expressions with Eulero formulas:

$cos(x)=\frac{e^{ix}+e^{-ix}}{2}$
$sin(x)=\frac{e^{ix}-e^{-ix}}{2i}$

with 'i' imaginary unit, and 'x' a real value (if I'm right, 'x' must
be real).

No. For every complex number z, we have  cos z = (exp(iz) + exp(-iz)) / 2  and  sin(x) = (exp(iz) - exp(-iz)) / (2i).

The idea of using Euler's formulae is good because this will give polynomial equations to solve. Then you will have to implement the method to solve exp(iZ)  = W for W the solutions of the polynomial equations verified by exp(iZ) . If iZ and W are complex numbers there are no genral solutions (seek for the complex logarithm to know the reason).

Indeed here if we are working with real trigonometric functions, we'll be only interest by the complex W corresponding to points on the trigonometric circle, ie verifying abs(W) = 1.
This complex numbers are the only ones that give a real solution Z = arg W [2 pi].

There one pitfull : if  kx = arg W [2 pi] , thenyou will have to send  x = arg W [2 pi/k] .

Christophe.
Reply all
Reply to author
Forward
0 new messages