ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 07 Jul 2020 17:57:21 +0200How do I solve cos(2*t)==sin(t)https://ask.sagemath.org/question/52344/how-do-i-solve-cos2tsint/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?Sun, 05 Jul 2020 20:22:18 +0200https://ask.sagemath.org/question/52344/how-do-i-solve-cos2tsint/Answer by eric_g for <p>I tried solving </p>
<blockquote>
<p>solve(cos(2*t)==sin(t),t)</p>
</blockquote>
<p>I got </p>
<blockquote>
<p>[cos(2*t) == sin(t)]</p>
</blockquote>
<p>But this shouldn't be the value. I know from the graphs that the value is numeric.</p>
<p>I have also noticed that sagemath is not good for solving trig identities. Is this true?</p>
https://ask.sagemath.org/question/52344/how-do-i-solve-cos2tsint/?answer=52346#post-id-52346Indeed, 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)]
Sun, 05 Jul 2020 21:17:44 +0200https://ask.sagemath.org/question/52344/how-do-i-solve-cos2tsint/?answer=52346#post-id-52346Comment by lolora for <p>Indeed, the default algorithm used by Sage is not capable to find the solutions, but SymPy succeeds:</p>
<pre><code>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)]
</code></pre>
https://ask.sagemath.org/question/52344/how-do-i-solve-cos2tsint/?comment=52351#post-id-52351How can I add an interval, to arrive at one answer here. My answer should be between 0, pi/2Mon, 06 Jul 2020 00:59:35 +0200https://ask.sagemath.org/question/52344/how-do-i-solve-cos2tsint/?comment=52351#post-id-52351Answer by curios_mind for <p>I tried solving </p>
<blockquote>
<p>solve(cos(2*t)==sin(t),t)</p>
</blockquote>
<p>I got </p>
<blockquote>
<p>[cos(2*t) == sin(t)]</p>
</blockquote>
<p>But this shouldn't be the value. I know from the graphs that the value is numeric.</p>
<p>I have also noticed that sagemath is not good for solving trig identities. Is this true?</p>
https://ask.sagemath.org/question/52344/how-do-i-solve-cos2tsint/?answer=52349#post-id-52349You 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.
Sun, 05 Jul 2020 23:00:12 +0200https://ask.sagemath.org/question/52344/how-do-i-solve-cos2tsint/?answer=52349#post-id-52349Comment by lolora for <p>You could try</p>
<pre><code>var('t')
solve(cos(2*t)==sin(t),t,to_poly_solve='force')
</code></pre>
<p>which gives <code>[t == -1/2*pi - 2*pi*z24, t == 1/6*pi + 2/3*pi*z25]</code></p>
<p>Z's are integers.</p>
https://ask.sagemath.org/question/52344/how-do-i-solve-cos2tsint/?comment=52352#post-id-52352How can I add an interval, to arrive at one answer here. My answer should be between 0, pi/2Mon, 06 Jul 2020 01:00:07 +0200https://ask.sagemath.org/question/52344/how-do-i-solve-cos2tsint/?comment=52352#post-id-52352Answer by Emmanuel Charpentier for <p>I tried solving </p>
<blockquote>
<p>solve(cos(2*t)==sin(t),t)</p>
</blockquote>
<p>I got </p>
<blockquote>
<p>[cos(2*t) == sin(t)]</p>
</blockquote>
<p>But this shouldn't be the value. I know from the graphs that the value is numeric.</p>
<p>I have also noticed that sagemath is not good for solving trig identities. Is this true?</p>
https://ask.sagemath.org/question/52344/how-do-i-solve-cos2tsint/?answer=52371#post-id-52371**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 `Set`s :
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,Tue, 07 Jul 2020 17:57:21 +0200https://ask.sagemath.org/question/52344/how-do-i-solve-cos2tsint/?answer=52371#post-id-52371