Ask Your Question
2

complex expand

asked 2024-07-10 00:17:06 +0100

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

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
0

answered 2024-07-10 17:29:44 +0100

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.

edit flag offensive delete link more

Comments

Hey, I didn't know that.

Thank you !

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2024-07-10 17:36:26 +0100 )edit
0

answered 2024-07-10 08:39:44 +0100

c.p. gravatar image

updated 2024-07-10 09:33:56 +0100

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
edit flag offensive delete link more
0

answered 2024-07-10 08:36:26 +0100

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,

edit flag offensive delete link more

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: 2024-07-10 00:17:06 +0100

Seen: 167 times

Last updated: Jul 10