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.Thu, 13 Sep 2018 10:31:38 +0200Is there a sage command to compute complex numbers?https://ask.sagemath.org/question/43617/is-there-a-sage-command-to-compute-complex-numbers/ I trying to have sage compute the sqrt(1/z) and 1/sqrt(z) of the complex expression z = 1+ I. Is there a sage command that will execute this?Sat, 08 Sep 2018 02:16:57 +0200https://ask.sagemath.org/question/43617/is-there-a-sage-command-to-compute-complex-numbers/Comment by vdelecroix for <p>I trying to have sage compute the sqrt(1/z) and 1/sqrt(z) of the complex expression z = 1+ I. Is there a sage command that will execute this?</p>
https://ask.sagemath.org/question/43617/is-there-a-sage-command-to-compute-complex-numbers/?comment=43624#post-id-43624What did you try up to now? We will be able to guide if you provide some information about why you are failing to do it.Sun, 09 Sep 2018 17:02:54 +0200https://ask.sagemath.org/question/43617/is-there-a-sage-command-to-compute-complex-numbers/?comment=43624#post-id-43624Answer by Sébastien for <p>I trying to have sage compute the sqrt(1/z) and 1/sqrt(z) of the complex expression z = 1+ I. Is there a sage command that will execute this?</p>
https://ask.sagemath.org/question/43617/is-there-a-sage-command-to-compute-complex-numbers/?answer=43626#post-id-43626I get:
sage: z = 1 + I
sage: sqrt(1/z)
sqrt(-1/2*I + 1/2)
If you want the real and imaginary parts, you may do:
sage: s = sqrt(1/z)
sage: s.real().simplify()
1/4*2^(3/4)*sqrt(sqrt(2) + 2)
sage: s.imag().simplify()
-1/4*2^(3/4)*sqrt(-sqrt(2) + 2)
Sun, 09 Sep 2018 20:56:39 +0200https://ask.sagemath.org/question/43617/is-there-a-sage-command-to-compute-complex-numbers/?answer=43626#post-id-43626Answer by Emmanuel Charpentier for <p>I trying to have sage compute the sqrt(1/z) and 1/sqrt(z) of the complex expression z = 1+ I. Is there a sage command that will execute this?</p>
https://ask.sagemath.org/question/43617/is-there-a-sage-command-to-compute-complex-numbers/?answer=43641#post-id-43641A couple things to complete the (exact) answer of Sebastien
* `sqrt(1/z)` will give you **ONE** solution of the equation `t^2==1/(1+I)`. There are two :
sage: solve(t^2==1/(1+I),t)
[t == -sqrt(-1/2*I + 1/2), t == sqrt(-1/2*I + 1/2)]
* You may have a better grasp of the meaning of the answer(s) by asking `maxima.polarform(sqrt(1/z))` and `maxima.polarform(1/sqrt(z))` respectively :
sage: maxima.polarform(sqrt(1/z))
%e^-((%i*%pi)/8)/2^(1/4)
sage: maxima.polarform(1/sqrt(z))
%e^-((%i*%pi)/8)/2^(1/4)
HTH,
Tue, 11 Sep 2018 17:31:17 +0200https://ask.sagemath.org/question/43617/is-there-a-sage-command-to-compute-complex-numbers/?answer=43641#post-id-43641Comment by Iguananaut for <p>A couple things to complete the (exact) answer of Sebastien</p>
<ul>
<li><p><code>sqrt(1/z)</code> will give you <strong>ONE</strong> solution of the equation <code>t^2==1/(1+I)</code>. There are two :</p>
<p>sage: solve(t^2==1/(1+I),t)</p>
<p>[t == -sqrt(-1/2<em>I + 1/2), t == sqrt(-1/2</em>I + 1/2)]</p></li>
<li><p>You may have a better grasp of the meaning of the answer(s) by asking <code>maxima.polarform(sqrt(1/z))</code> and <code>maxima.polarform(1/sqrt(z))</code> respectively :</p>
<p>sage: maxima.polarform(sqrt(1/z))</p>
<p>%e^-((%i*%pi)/8)/2^(1/4)</p>
<p>sage: maxima.polarform(1/sqrt(z))</p>
<p>%e^-((%i*%pi)/8)/2^(1/4)</p></li>
</ul>
<p>HTH,</p>
https://ask.sagemath.org/question/43617/is-there-a-sage-command-to-compute-complex-numbers/?comment=43651#post-id-43651Yikes. That output format for `maxima.polarform` is pretty ugly (I understand it's standard for maxima). Does Sage not have a simple `polarform()` function to put a complex number in polar form using a normal symbolic expression?Wed, 12 Sep 2018 17:42:56 +0200https://ask.sagemath.org/question/43617/is-there-a-sage-command-to-compute-complex-numbers/?comment=43651#post-id-43651Comment by Iguananaut for <p>A couple things to complete the (exact) answer of Sebastien</p>
<ul>
<li><p><code>sqrt(1/z)</code> will give you <strong>ONE</strong> solution of the equation <code>t^2==1/(1+I)</code>. There are two :</p>
<p>sage: solve(t^2==1/(1+I),t)</p>
<p>[t == -sqrt(-1/2<em>I + 1/2), t == sqrt(-1/2</em>I + 1/2)]</p></li>
<li><p>You may have a better grasp of the meaning of the answer(s) by asking <code>maxima.polarform(sqrt(1/z))</code> and <code>maxima.polarform(1/sqrt(z))</code> respectively :</p>
<p>sage: maxima.polarform(sqrt(1/z))</p>
<p>%e^-((%i*%pi)/8)/2^(1/4)</p>
<p>sage: maxima.polarform(1/sqrt(z))</p>
<p>%e^-((%i*%pi)/8)/2^(1/4)</p></li>
</ul>
<p>HTH,</p>
https://ask.sagemath.org/question/43617/is-there-a-sage-command-to-compute-complex-numbers/?comment=43652#post-id-43652(FWIW I was able to implement this as `abs(z)*exp(arg(z)*I, hold=True)` (without the hold it does some deeply unhelpful "simplification"); seems like it would be a worthwhile built-in to have, or at least a method of complex numbers)Wed, 12 Sep 2018 17:51:46 +0200https://ask.sagemath.org/question/43617/is-there-a-sage-command-to-compute-complex-numbers/?comment=43652#post-id-43652Comment by eric_g for <p>A couple things to complete the (exact) answer of Sebastien</p>
<ul>
<li><p><code>sqrt(1/z)</code> will give you <strong>ONE</strong> solution of the equation <code>t^2==1/(1+I)</code>. There are two :</p>
<p>sage: solve(t^2==1/(1+I),t)</p>
<p>[t == -sqrt(-1/2<em>I + 1/2), t == sqrt(-1/2</em>I + 1/2)]</p></li>
<li><p>You may have a better grasp of the meaning of the answer(s) by asking <code>maxima.polarform(sqrt(1/z))</code> and <code>maxima.polarform(1/sqrt(z))</code> respectively :</p>
<p>sage: maxima.polarform(sqrt(1/z))</p>
<p>%e^-((%i*%pi)/8)/2^(1/4)</p>
<p>sage: maxima.polarform(1/sqrt(z))</p>
<p>%e^-((%i*%pi)/8)/2^(1/4)</p></li>
</ul>
<p>HTH,</p>
https://ask.sagemath.org/question/43617/is-there-a-sage-command-to-compute-complex-numbers/?comment=43656#post-id-43656+1 for implementing a kind of `polarform` function in Sage.Thu, 13 Sep 2018 10:31:38 +0200https://ask.sagemath.org/question/43617/is-there-a-sage-command-to-compute-complex-numbers/?comment=43656#post-id-43656