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, 09 Jul 2021 16:35:33 +0200Simplification of arctan2(f1,f2) expressions.https://ask.sagemath.org/question/57939/simplification-of-arctan2f1f2-expressions/Why doesn't `arctan2(sqrt(a^2 + r^2)*sin(phi)*sin(th), sqrt(a^2 + r^2)*cos(phi)*sin(th))` simplify to phi or at least `arctan2(sin(phi),cos(phi))`?AlanTStaffordFri, 09 Jul 2021 16:35:33 +0200https://ask.sagemath.org/question/57939/Complex argument of an algebraic numberhttps://ask.sagemath.org/question/9497/complex-argument-of-an-algebraic-number/This question is closely related to [that question here](http://ask.sagemath.org/question/1945/complex-argument-of-a-symbolic-expression). Basically I'd like to know whether there is a way to compute an *accurate symbolic expression* for the argument of an algebraic number.
That argument will in general not be an algebraic number itself, which seems to cause a lot of headache along the way. The following all fail, sometimes in rather spectacular backtracing ways:
sage: z = QQbar(3 + 2*I)
sage: z.arg()
AttributeError: 'AlgebraicNumber' object has no attribute 'arg'
sage: atan2(imag(z), real(z))
TypeError: Illegal initializer for algebraic number
sage: atan2(SR(imag(z)), SR(real(z)))
TypeError: Illegal initializer for algebraic number
sage: atan2(AA(imag(z)), AA(real(z)))
TypeError: Illegal initializer for algebraic number
I know a few cases which will work.
sage: atan2(QQ(imag(z)), QQ(real(z)))
arctan(2/3)
This however will break if the real or imaginary part were to contain any square roots.
sage: CC(z).arg()
0.588002603547568
This will give me a numeric approximation. I know I can get that approximation to arbitrary precision, but it's still not exact.
I have the impression that `atan2` attempts to turn its result into an algebraic number, which will fail horribly. I would expect that result to contain an unevaluated call to `atan2` instead, for the cases where the argument is not an algebraic number. Can this be done?MvGFri, 02 Nov 2012 12:42:21 +0100https://ask.sagemath.org/question/9497/atan2 bug?https://ask.sagemath.org/question/8146/atan2-bug/The following generated an error, what am I doing wrong?
Tst = 256
phi_p = 0.0
dF= pi
State = var('State')
x = 1 - 2 * State / Tst
ps_a=phi_p+4.0*dF*x
ps_b=phi_p+3.0*dF*x
ps_c=phi_p+2.0*dF*x
ps_d=phi_p+1.0*dF*x
ps_e=phi_p+0.0*dF*x
ps_f=phi_p-1.0*dF*x
ps_g=phi_p-2.0*dF*x
ps_h=phi_p-3.0*dF*x
ps_i=phi_p-4.0*dF*x
px = (cos(ps_a)/2+cos(ps_b)+cos(ps_c)+cos(ps_d)+cos(ps_e)+cos(ps_f)+cos(ps_g)+cos(ps_h)+cos(ps_i)/2)
py = (sin(ps_a)/2+sin(ps_b)+sin(ps_c)+sin(ps_d)+sin(ps_e)+sin(ps_f)+sin(ps_g)+sin(ps_h)+sin(ps_i)/2)
ps_pc= (atan2 (py, px))
rfs_pc=sqrt(px*px+py*py)/8
amp = (rfs_pc*cos(ps_pc))
This Breaks:
AmpP =[amp(State=r).n() for r in srange(Tst)]
This works, but I need "amp " in another place and it returns the same error.
AmpP =[((rfs_pc(State=r)).n()*cos(ps_pc(State=r))).n() for r in srange(Tst)]
mhfreyThu, 02 Jun 2011 16:54:18 +0200https://ask.sagemath.org/question/8146/