Ask Your Question

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

asked 2013-11-11 23:38:09 -0500

gundamlh gravatar image

updated 2013-11-12 02:01:56 -0500

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 05:49:49 -0500

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 05:56:42 -0500 )edit

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

kcrisman gravatar imagekcrisman ( 2013-11-12 10:01:59 -0500 )edit

answered 2013-11-11 23:50:10 -0500

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 02:05:40 -0500 )edit

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

tmonteil gravatar imagetmonteil ( 2013-11-12 02:32:12 -0500 )edit

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

tmonteil gravatar imagetmonteil ( 2013-11-12 02:35:31 -0500 )edit

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

kcrisman gravatar imagekcrisman ( 2013-11-12 03:10:16 -0500 )edit

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

gundamlh gravatar imagegundamlh ( 2013-11-12 03:17:44 -0500 )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


Asked: 2013-11-11 23:38:09 -0500

Seen: 269 times

Last updated: Nov 12 '13