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, 12 Nov 2013 17:01:59 +0100How to convert "cos(th)+i*sin(th)" to "e^(i*th)"?https://ask.sagemath.org/question/10727/how-to-convert-costhisinth-to-eith/This question is perhaps trivial but annoying. I don't expect a quick answer.
The following are all I have tried.
----------
sage: th = var('th')
----------
sage: e^(I*th).simplify_trig()
e^(I*th)
sage: e^(I*th).simplify_exp()
e^(I*th)
sage: e^(I*th).simplify_full()
e^(I*th)
----------
sage: f = cos(th) + I*sin(th)
sage: f.simplify_trig()
I*sin(th) + cos(th)
sage: f.simplify_exp()
I*sin(th) + cos(th)
sage: f.simplify_full()
I*sin(th) + cos(th)
----------
Thanks for your patience in advance!
Tue, 12 Nov 2013 06:38:09 +0100https://ask.sagemath.org/question/10727/how-to-convert-costhisinth-to-eith/Answer by tmonteil for <p>This question is perhaps trivial but annoying. I don't expect a quick answer.</p>
<p>The following are all I have tried.</p>
<hr/>
<pre><code>sage: th = var('th')
----------
sage: e^(I*th).simplify_trig()
e^(I*th)
sage: e^(I*th).simplify_exp()
e^(I*th)
sage: e^(I*th).simplify_full()
e^(I*th)
----------
sage: f = cos(th) + I*sin(th)
sage: f.simplify_trig()
I*sin(th) + cos(th)
sage: f.simplify_exp()
I*sin(th) + cos(th)
sage: f.simplify_full()
I*sin(th) + cos(th)
</code></pre>
<hr/>
<p>Thanks for your patience in advance!</p>
https://ask.sagemath.org/question/10727/how-to-convert-costhisinth-to-eith/?answer=15688#post-id-15688Note that if you indent you code by 4 spaces, then it will be displayed nicely.
That said, i do not know how to to the conversion automatically. What is clear is that Maxima "knows" that those two quantities are equal:
sage: th = var('th')
sage: f = cos(th) + I*sin(th)
sage: g = e^(I*th)
sage: f == g
cos(th) + I*sin(th) == e^(I*th)
sage: bool(f == g)
True
I do not know how to do the conversion automatically. The best i can is:
sage: g.real_part().full_simplify()
cos(th)
sage: g.imag_part().full_simplify()
sin(th)
Tue, 12 Nov 2013 06:50:10 +0100https://ask.sagemath.org/question/10727/how-to-convert-costhisinth-to-eith/?answer=15688#post-id-15688Comment by kcrisman for <p>Note that if you indent you code by 4 spaces, then it will be displayed nicely.</p>
<p>That said, i do not know how to to the conversion automatically. What is clear is that Maxima "knows" that those two quantities are equal:</p>
<pre><code>sage: th = var('th')
sage: f = cos(th) + I*sin(th)
sage: g = e^(I*th)
sage: f == g
cos(th) + I*sin(th) == e^(I*th)
sage: bool(f == g)
True
</code></pre>
<p>I do not know how to do the conversion automatically. The best i can is:</p>
<pre><code>sage: g.real_part().full_simplify()
cos(th)
sage: g.imag_part().full_simplify()
sin(th)
</code></pre>
https://ask.sagemath.org/question/10727/how-to-convert-costhisinth-to-eith/?comment=16729#post-id-16729I think that Maxima's `rectform` might be useful here - it might even be in Sage now?Tue, 12 Nov 2013 10:10:16 +0100https://ask.sagemath.org/question/10727/how-to-convert-costhisinth-to-eith/?comment=16729#post-id-16729Comment by tmonteil for <p>Note that if you indent you code by 4 spaces, then it will be displayed nicely.</p>
<p>That said, i do not know how to to the conversion automatically. What is clear is that Maxima "knows" that those two quantities are equal:</p>
<pre><code>sage: th = var('th')
sage: f = cos(th) + I*sin(th)
sage: g = e^(I*th)
sage: f == g
cos(th) + I*sin(th) == e^(I*th)
sage: bool(f == g)
True
</code></pre>
<p>I do not know how to do the conversion automatically. The best i can is:</p>
<pre><code>sage: g.real_part().full_simplify()
cos(th)
sage: g.imag_part().full_simplify()
sin(th)
</code></pre>
https://ask.sagemath.org/question/10727/how-to-convert-costhisinth-to-eith/?comment=16727#post-id-16727Looking at rectform() source code, we can do:
sage: f.maxima_methods().polarform().full_simplify()
e^(I*arctan2(sin(th), cos(th)))
This is not optimal, but kind of approaching.
Tue, 12 Nov 2013 10:59:50 +0100https://ask.sagemath.org/question/10727/how-to-convert-costhisinth-to-eith/?comment=16727#post-id-16727Comment by tmonteil for <p>Note that if you indent you code by 4 spaces, then it will be displayed nicely.</p>
<p>That said, i do not know how to to the conversion automatically. What is clear is that Maxima "knows" that those two quantities are equal:</p>
<pre><code>sage: th = var('th')
sage: f = cos(th) + I*sin(th)
sage: g = e^(I*th)
sage: f == g
cos(th) + I*sin(th) == e^(I*th)
sage: bool(f == g)
True
</code></pre>
<p>I do not know how to do the conversion automatically. The best i can is:</p>
<pre><code>sage: g.real_part().full_simplify()
cos(th)
sage: g.imag_part().full_simplify()
sin(th)
</code></pre>
https://ask.sagemath.org/question/10727/how-to-convert-costhisinth-to-eith/?comment=16730#post-id-16730No, you can convert in both directions by being explicit, see [this ask answer](http://ask.sagemath.org/question/3134/complex-rectangular-to-polar#4231)Tue, 12 Nov 2013 09:35:31 +0100https://ask.sagemath.org/question/10727/how-to-convert-costhisinth-to-eith/?comment=16730#post-id-16730Comment by tmonteil for <p>Note that if you indent you code by 4 spaces, then it will be displayed nicely.</p>
<p>That said, i do not know how to to the conversion automatically. What is clear is that Maxima "knows" that those two quantities are equal:</p>
<pre><code>sage: th = var('th')
sage: f = cos(th) + I*sin(th)
sage: g = e^(I*th)
sage: f == g
cos(th) + I*sin(th) == e^(I*th)
sage: bool(f == g)
True
</code></pre>
<p>I do not know how to do the conversion automatically. The best i can is:</p>
<pre><code>sage: g.real_part().full_simplify()
cos(th)
sage: g.imag_part().full_simplify()
sin(th)
</code></pre>
https://ask.sagemath.org/question/10727/how-to-convert-costhisinth-to-eith/?comment=16731#post-id-16731The indentation is for ask.sagemath only, note related to Sage.Tue, 12 Nov 2013 09:32:12 +0100https://ask.sagemath.org/question/10727/how-to-convert-costhisinth-to-eith/?comment=16731#post-id-16731Comment by gundamlh for <p>Note that if you indent you code by 4 spaces, then it will be displayed nicely.</p>
<p>That said, i do not know how to to the conversion automatically. What is clear is that Maxima "knows" that those two quantities are equal:</p>
<pre><code>sage: th = var('th')
sage: f = cos(th) + I*sin(th)
sage: g = e^(I*th)
sage: f == g
cos(th) + I*sin(th) == e^(I*th)
sage: bool(f == g)
True
</code></pre>
<p>I do not know how to do the conversion automatically. The best i can is:</p>
<pre><code>sage: g.real_part().full_simplify()
cos(th)
sage: g.imag_part().full_simplify()
sin(th)
</code></pre>
https://ask.sagemath.org/question/10727/how-to-convert-costhisinth-to-eith/?comment=16728#post-id-16728@kcrisman http://trac.sagemath.org/ticket/13061 .. Yes, it works, but not the other round. The polar form is more convenient and intuitive.Tue, 12 Nov 2013 10:17:44 +0100https://ask.sagemath.org/question/10727/how-to-convert-costhisinth-to-eith/?comment=16728#post-id-16728Comment by gundamlh for <p>Note that if you indent you code by 4 spaces, then it will be displayed nicely.</p>
<p>That said, i do not know how to to the conversion automatically. What is clear is that Maxima "knows" that those two quantities are equal:</p>
<pre><code>sage: th = var('th')
sage: f = cos(th) + I*sin(th)
sage: g = e^(I*th)
sage: f == g
cos(th) + I*sin(th) == e^(I*th)
sage: bool(f == g)
True
</code></pre>
<p>I do not know how to do the conversion automatically. The best i can is:</p>
<pre><code>sage: g.real_part().full_simplify()
cos(th)
sage: g.imag_part().full_simplify()
sin(th)
</code></pre>
https://ask.sagemath.org/question/10727/how-to-convert-costhisinth-to-eith/?comment=16732#post-id-16732Thanks! Does it mean that we can only convert it automatically from exp() to cos(), sin() , but cannot the other way round? PS, "indent the code by 4 spaces" muss I modify some initial/default configuration file of SAGE?Tue, 12 Nov 2013 09:05:40 +0100https://ask.sagemath.org/question/10727/how-to-convert-costhisinth-to-eith/?comment=16732#post-id-16732Comment by gundamlh for <p>Note that if you indent you code by 4 spaces, then it will be displayed nicely.</p>
<p>That said, i do not know how to to the conversion automatically. What is clear is that Maxima "knows" that those two quantities are equal:</p>
<pre><code>sage: th = var('th')
sage: f = cos(th) + I*sin(th)
sage: g = e^(I*th)
sage: f == g
cos(th) + I*sin(th) == e^(I*th)
sage: bool(f == g)
True
</code></pre>
<p>I do not know how to do the conversion automatically. The best i can is:</p>
<pre><code>sage: g.real_part().full_simplify()
cos(th)
sage: g.imag_part().full_simplify()
sin(th)
</code></pre>
https://ask.sagemath.org/question/10727/how-to-convert-costhisinth-to-eith/?comment=16726#post-id-16726if we restrict th in (0,pi/2), we can possibly get the final answer.Tue, 12 Nov 2013 12:00:11 +0100https://ask.sagemath.org/question/10727/how-to-convert-costhisinth-to-eith/?comment=16726#post-id-16726Answer by Shashank for <p>This question is perhaps trivial but annoying. I don't expect a quick answer.</p>
<p>The following are all I have tried.</p>
<hr/>
<pre><code>sage: th = var('th')
----------
sage: e^(I*th).simplify_trig()
e^(I*th)
sage: e^(I*th).simplify_exp()
e^(I*th)
sage: e^(I*th).simplify_full()
e^(I*th)
----------
sage: f = cos(th) + I*sin(th)
sage: f.simplify_trig()
I*sin(th) + cos(th)
sage: f.simplify_exp()
I*sin(th) + cos(th)
sage: f.simplify_full()
I*sin(th) + cos(th)
</code></pre>
<hr/>
<p>Thanks for your patience in advance!</p>
https://ask.sagemath.org/question/10727/how-to-convert-costhisinth-to-eith/?answer=15689#post-id-15689Look at this answer http://ask.sagemath.org/question/148/complex-exponentialtrigonometric
You need to convert sage object to maxima object and then exponentialize
th=var('th')
f=cos(th)+I*sin(th)
sageobj(f._maxima_().exponentialize())
Tue, 12 Nov 2013 12:49:49 +0100https://ask.sagemath.org/question/10727/how-to-convert-costhisinth-to-eith/?answer=15689#post-id-15689Comment by kcrisman for <p>Look at this answer <a href="http://ask.sagemath.org/question/148/complex-exponentialtrigonometric">http://ask.sagemath.org/question/148/...</a></p>
<p>You need to convert sage object to maxima object and then exponentialize</p>
<pre><code>th=var('th')
f=cos(th)+I*sin(th)
sageobj(f._maxima_().exponentialize())
</code></pre>
https://ask.sagemath.org/question/10727/how-to-convert-costhisinth-to-eith/?comment=16723#post-id-16723Thanks, @Shashank - I had completely forgotten about that ticket!Tue, 12 Nov 2013 17:01:59 +0100https://ask.sagemath.org/question/10727/how-to-convert-costhisinth-to-eith/?comment=16723#post-id-16723Comment by gundamlh for <p>Look at this answer <a href="http://ask.sagemath.org/question/148/complex-exponentialtrigonometric">http://ask.sagemath.org/question/148/...</a></p>
<p>You need to convert sage object to maxima object and then exponentialize</p>
<pre><code>th=var('th')
f=cos(th)+I*sin(th)
sageobj(f._maxima_().exponentialize())
</code></pre>
https://ask.sagemath.org/question/10727/how-to-convert-costhisinth-to-eith/?comment=16725#post-id-16725Thanks! sage: f.maxima_methods().exponentialize() and http://trac.sagemath.org/ticket/10038Tue, 12 Nov 2013 12:56:42 +0100https://ask.sagemath.org/question/10727/how-to-convert-costhisinth-to-eith/?comment=16725#post-id-16725