On 8/7/10 12:25 PM, tontaube wrote:
Hello everybody!
Can I do calculations with complex numbers that are defined only by
symbols? Let's say I'd like to do the following:
sage: var("R1 X1 R2 X2")
sage: Z1 = R1 + X1*i
sage: Z2 = R2 + X2*i
sage: Z = Z1 + Z2
sage: print Z
sage: Z.imag()
R1 + R2 + I*X1 + I*X2
real_part(X1) + real_part(X2) + imag_part(R1) + imag_part(R2)
Now the imaginary part delivered by Z.imag() should be (X1 + X2)I.
This is only true if your R1, R2, X1, and X2 variables are real, right?
Then you have to tell Sage that, using the "domain" keyword of the
var() function:
sage: var("R1 X1 R2 X2", domain=RR)
sage: Z1 = R1 + X1*i
sage: Z2 = R2 + X2*i
sage: Z = Z1 + Z2
sage: imag(Z)
X1 + X2
sage: real(Z)
R1 + R2
Thanks,
Jason
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org