# 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?

edit retag close merge delete

1

What 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.

Sort by » oldest newest most voted

A 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/2I + 1/2), t == sqrt(-1/2I + 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,

more

Yikes. 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?

1

(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)

1

+1 for implementing a kind of polarform function in Sage.

I 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)

more