First time here? Check out the FAQ!

Ask Your Question
2

complex expand

asked 0 years ago

Ishihama gravatar image

I am a newbie in Sage. I would like to do complex-expand (Mathematica command) in Sage. Please tell me how to implement? Say, there is a function like (1/(a+b.I)), I wish to symbolical output (a-b.I)/(a^2+b^2). Here, we regard a and b as real numbers. thanks in advance for help

Preview: (hide)

3 Answers

Sort by » oldest newest most voted
0

answered 0 years ago

eric_g gravatar image

Use z.simplify_rectform(None).factor():

sage: a, b = var('a b', domain='real')
sage: z = 1/(a + I*b)
sage: z.simplify_rectform(None)
a/(a^2 + b^2) - I*b/(a^2 + b^2)
sage: z.simplify_rectform(None).factor()
(a - I*b)/(a^2 + b^2)

Note that z.simplify_rectform(None) is a shortcut for z.simplify_rectform(complexity_measure=None). Type z.simplify_rectform? for more details.

Preview: (hide)
link

Comments

Hey, I didn't know that.

Thank you !

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 0 years ago )
0

answered 0 years ago

c.p. gravatar image

updated 0 years ago

Hi, welcome. Don't know how far the next works, but while nobody answers, consider:

var('x,y',domain=RR)
def csimp(complex_poly):    
    if type(imag_part(denominator(complex_poly))) == sage.symbolic.expression.Expression:
        return numerator(complex_poly)\
         *(conjugate(denominator(complex_poly)))/(norm(denominator(complex_poly))^2)
    else:
        return (complex_poly)

csimp(1/z) # (x - I*y)/(x^2 + y^2)^2
Preview: (hide)
link
0

answered 0 years ago

Emmanuel Charpentier gravatar image

Running :

var("a, b", domain="real")
z=1/(a+I*b)
(z.real()+I*z.imag()).factor()

prints :

(a - I*b)/(a^2 + b^2)

See this Sagecell example.

HTH,

Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 0 years ago

Seen: 182 times

Last updated: Jul 10 '24