Ask Your Question
0

How do I solve cos(2*t)==sin(t)

asked 2020-07-05 20:22:18 +0100

lolora gravatar image

updated 2020-07-05 20:23:10 +0100

I tried solving

solve(cos(2*t)==sin(t),t)

I got

[cos(2*t) == sin(t)]

But this shouldn't be the value. I know from the graphs that the value is numeric.

I have also noticed that sagemath is not good for solving trig identities. Is this true?

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
1

answered 2020-07-07 17:57:21 +0100

Emmanuel Charpentier gravatar image

updated 2020-07-08 12:45:50 +0100

EDIT : Sympy can do that. See below.

Not directly in Sage or packages included in Sage :

sage: var("t")
t
sage: Sol=solve(cos(2*t)==sin(t), t, to_poly_solve=True)
sage: Sol
[t == -1/2*pi - 2*pi*z0, t == 1/6*pi + 2/3*pi*z1]

We have to declare the integer constants:

sage: var("z0, z1", domain="integer")
(z0, z1)
sage: assumptions()
[z0 is integer, z1 is integer]

However, neither Maxima nor Sympy can use the domain constraint to find the relevant solutions. For the first solution :

sage: solve([Sol[0].rhs()>=0, Sol[0].rhs()<=pi/2], z0)
[[(-1/2) < z0, z0 < (-1/4)], [z0 == (-1/2)], [z0 == (-1/4)]]
sage: solve([Sol[0].rhs()>=0, Sol[0].rhs()<=pi/2], z0, algorithm="sympy", domain=
....: "integer")
[[(-1/2) <= z0, z0 <= (-1/4)]]

and Sage has no direct way to find that the intersection of these intervals (both [-1/2 -1/4] with $\mathbb{N}$ is the empty set.

For the second solution:

sage: solve([Sol[1].rhs()>=0, Sol[1].rhs()<=pi/2], z1)
[[(-1/4) < z1, z1 < (1/2)], [z1 == (-1/4)], [z1 == (1/2)]]
sage: solve([Sol[1].rhs()>=0, Sol[1].rhs()<=pi/2], z1, algorithm="sympy", domain=
....: "integer")
[[(-1/4) <= z1, z1 <= (1/2)]]

The admissible set of solutions for z1 is, in both cases, [-1/4 1/2], whose intersection with $\mathbb{N}$ (that Sage cannot directly compute) is {0}, giving us the solution :

sage: Sol[1].subs(z1==0)
t == 1/6*pi

Note that this is one case where Mathematica can do the job more efficiently:

sage: mathematica.Solve([cos(2*t)==sin(t), t>=0, t<=pi/2], t)
{{t -> Pi/6}}

In Sage, objects representing infinite sets are available. One might try to play with them to obtain "better" representations of the solutins, but this is not (yet) implemented.

EDIT : Sympy can do that, but using sympy's sets, whoch are not (yet) backtranslatable to Sage's Sets :

 t=var("t")
Eq=cos(2*t)==sin(t)
import sympy
SS=solve(Eq, t, algorithm="sympy"); SS

[ImageSet(Lambda(_n, 2*_n*pi + 3*pi/2), Integers),
 ImageSet(Lambda(_n, 2*_n*pi + 5*pi/6), Integers),
 ImageSet(Lambda(_n, 2*_n*pi + pi/6), Integers)]

Note that tis solution is a lis of sympy objects, not directly backtranslatable to sage:

[type(u) for u in SS]
[<class 'sympy.sets.fancysets.ImageSet'>,
 <class 'sympy.sets.fancysets.ImageSet'>,
 <class 'sympy.sets.fancysets.ImageSet'>]

S1=reduce(lambda a,b:a.union(b), SS,
          sympy.EmptySet).intersection(sympy.Interval(0,pi/2))

This solution is again a sympy set, not directly backtranslatable to Sage :

S1
FiniteSet(pi/6)
S1._sage_()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-173-5ca5ebb7fb66> in <module>()
----> 1 S1._sage_()

AttributeError: 'FiniteSet' object has no attribute '_sage_'

A wokaround is to manually backtranslate :

Sol=Set([u._sage_() for u in S1.args]) ; Sol
{1/6*pi}

HTH,

edit flag offensive delete link more
0

answered 2020-07-05 21:17:44 +0100

eric_g gravatar image

Indeed, the default algorithm used by Sage is not capable to find the solutions, but SymPy succeeds:

sage: t = var('t')
sage: solve(cos(2*t) == sin(t), t, algorithm='sympy')
[ImageSet(Lambda(_n, 2*_n*pi + 3*pi/2), Integers),
 ImageSet(Lambda(_n, 2*_n*pi + 5*pi/6), Integers),
 ImageSet(Lambda(_n, 2*_n*pi + pi/6), Integers)]
edit flag offensive delete link more

Comments

How can I add an interval, to arrive at one answer here. My answer should be between 0, pi/2

lolora gravatar imagelolora ( 2020-07-06 00:59:35 +0100 )edit
0

answered 2020-07-05 23:00:12 +0100

curios_mind gravatar image

You could try

var('t')
solve(cos(2*t)==sin(t),t,to_poly_solve='force')

which gives [t == -1/2*pi - 2*pi*z24, t == 1/6*pi + 2/3*pi*z25]

Z's are integers.

edit flag offensive delete link more

Comments

How can I add an interval, to arrive at one answer here. My answer should be between 0, pi/2

lolora gravatar imagelolora ( 2020-07-06 01:00:07 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-07-05 20:22:18 +0100

Seen: 488 times

Last updated: Jul 08 '20