Ask Your Question
1

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()    
e^(I*th)    
sage: e^(I*th).simplify_exp()    
e^(I*th)    
sage: e^(I*th).simplify_full()   
e^(I*th)        

----------


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
1

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

Shashank gravatar image

Look at this answer http://ask.sagemath.org/question/148/...

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

th=var('th')
f=cos(th)+I*sin(th)
sageobj(f._maxima_().exponentialize())
edit flag offensive delete link more

Comments

1

Thanks! sage: f.maxima_methods().exponentialize() and http://trac.sagemath.org/ticket/10038

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
1

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

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

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

Comments

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
1

No, you can convert in both directions by being explicit, see [this ask answer](http://ask.sagemath.org/question/3134/complex-rectangular-to-polar#4231)

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

@kcrismanhttp://trac.sagemath.org/ticket/13061 .. 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

Stats

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

Seen: 1,075 times

Last updated: Nov 12 '13