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.Fri, 02 Nov 2012 14:36:07 +0100Complex argument of a symbolic expressionhttps://ask.sagemath.org/question/9496/complex-argument-of-a-symbolic-expression/I was a bit surprised that simply entering a complex number and asking for its argument doesn't seem to work. Not even in the case where all numbers are known and algebraic, even integers:
(2+3*I).arg()
AttributeError: 'sage.symbolic.expression.Expression' object has no attribute 'arg'
I found out that in order to compute the argument, I'll have to manually cast my number from the symbolic ring into some complex field, e.g.
sage: CC(2+3*I).arg()
0.982793723247329
But I believe that this should work without me having to think too much about the type system. It should even work for completely symbolic expressions, as stuff like `real_part`, `imag_part` and `atan2` are all symbolic functions which may be returned in their unevaluated form if evaluation is not possible.
Is there some other way to compute the complex argument, which I missed so far, ans which works for symbolic expressions as well as elements of a complex number field?Fri, 02 Nov 2012 12:22:32 +0100https://ask.sagemath.org/question/9496/complex-argument-of-a-symbolic-expression/Answer by Shashank for <p>I was a bit surprised that simply entering a complex number and asking for its argument doesn't seem to work. Not even in the case where all numbers are known and algebraic, even integers:</p>
<pre><code>(2+3*I).arg()
AttributeError: 'sage.symbolic.expression.Expression' object has no attribute 'arg'
</code></pre>
<p>I found out that in order to compute the argument, I'll have to manually cast my number from the symbolic ring into some complex field, e.g.</p>
<pre><code>sage: CC(2+3*I).arg()
0.982793723247329
</code></pre>
<p>But I believe that this should work without me having to think too much about the type system. It should even work for completely symbolic expressions, as stuff like <code>real_part</code>, <code>imag_part</code> and <code>atan2</code> are all symbolic functions which may be returned in their unevaluated form if evaluation is not possible.</p>
<p>Is there some other way to compute the complex argument, which I missed so far, ans which works for symbolic expressions as well as elements of a complex number field?</p>
https://ask.sagemath.org/question/9496/complex-argument-of-a-symbolic-expression/?answer=14222#post-id-14222Yeah you are right (2+3*I).arg() does not work, but arg(2+3*I) works.
But if you want a answer of the form 0.9827 you need arg(2+3*I).n()Fri, 02 Nov 2012 14:36:07 +0100https://ask.sagemath.org/question/9496/complex-argument-of-a-symbolic-expression/?answer=14222#post-id-14222