Ask Your Question

How to convert "cos(th)+i*sin(th)" to "e^(i*th)"?

asked 2013-11-12 06:38:09 +0200

gundamlh gravatar image

updated 2013-11-12 09:01:56 +0200

This question is perhaps trivial but annoying. I don't expect a quick answer.

The following are all I have tried.

sage: th = var('th')


sage: e^(I*th).simplify_trig()    
sage: e^(I*th).simplify_exp()    
sage: e^(I*th).simplify_full()   


sage: f = cos(th) + I*sin(th)    
sage: f.simplify_trig()    
I*sin(th) + cos(th)    
sage: f.simplify_exp()    
I*sin(th) + cos(th)    
sage: f.simplify_full()    
I*sin(th) + cos(th)

Thanks for your patience in advance!

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2013-11-12 12:49:49 +0200

Shashank gravatar image

Look at this answer

You need to convert sage object to maxima object and then exponentialize

edit flag offensive delete link more



Thanks! sage: f.maxima_methods().exponentialize() and

gundamlh gravatar imagegundamlh ( 2013-11-12 12:56:42 +0200 )edit

Thanks, @Shashank - I had completely forgotten about that ticket!

kcrisman gravatar imagekcrisman ( 2013-11-12 17:01:59 +0200 )edit

answered 2013-11-12 06:50:10 +0200

tmonteil gravatar image

Note that if you indent you code by 4 spaces, then it will be displayed nicely.

That said, i do not know how to to the conversion automatically. What is clear is that Maxima "knows" that those two quantities are equal:

sage: th = var('th')
sage: f = cos(th) + I*sin(th)
sage: g = e^(I*th)
sage: f == g
cos(th) + I*sin(th) == e^(I*th)
sage: bool(f == g)

I do not know how to do the conversion automatically. The best i can is:

sage: g.real_part().full_simplify()
sage: g.imag_part().full_simplify()
edit flag offensive delete link more


Thanks! Does it mean that we can only convert it automatically from exp() to cos(), sin() , but cannot the other way round? PS, "indent the code by 4 spaces" muss I modify some initial/default configuration file of SAGE?

gundamlh gravatar imagegundamlh ( 2013-11-12 09:05:40 +0200 )edit

The indentation is for ask.sagemath only, note related to Sage.

tmonteil gravatar imagetmonteil ( 2013-11-12 09:32:12 +0200 )edit

No, you can convert in both directions by being explicit, see [this ask answer](

tmonteil gravatar imagetmonteil ( 2013-11-12 09:35:31 +0200 )edit

I think that Maxima's `rectform` might be useful here - it might even be in Sage now?

kcrisman gravatar imagekcrisman ( 2013-11-12 10:10:16 +0200 )edit

@kcrisman .. Yes, it works, but not the other round. The polar form is more convenient and intuitive.

gundamlh gravatar imagegundamlh ( 2013-11-12 10:17:44 +0200 )edit

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


Asked: 2013-11-12 06:38:09 +0200

Seen: 872 times

Last updated: Nov 12 '13