First time here? Check out the FAQ!

Ask Your Question
2

Solving complex equation

asked 13 years ago

Juanlu001 gravatar image

I was trying to solve the following equation over the complex numbers: sin(z) + cos(z) = 2

In Sage:

sage: z = var('z')
sage: solve(sin(z) + cos(z) == 2, z)
[sin(z) == -cos(z) + 2]

Obviously, that's not what I want. Wolfram|Alpha yields the two solutions in multiple forms: http://www.wolframalpha.com/input/?i=cos%28z%29+%2B+sin%28z%29+%3D%3D+2

Can this be done in Sage?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
6

answered 13 years ago

kcrisman gravatar image
sage: solve(sin(x)+cos(x)==2,x,to_poly_solve=True)
[x == 1/4*pi + 2*pi*z6 - I*log(-1/2*(sqrt(2) - 2)*sqrt(2)), x == 1/4*pi + 2*pi*z8 - I*log(sqrt(2) + 1)]

Note that one gets a family of solutions because these are multi-valued inverses.

The to_poly_solve option still is not documented in the global solve?, but will show up if you do x.solve?. Apologies for not having done this.

Preview: (hide)
link

Comments

@kcrisman, In addition to documenting the `to_poly_solve` option for the built-in `solve`, would it also make sense to have `solve` print a message to the user with the suggestion to try the option when an implicit solution is returned? I guess this depends on if it's easy to detect an implicit solution vs. an explicit one.

benjaminfjones gravatar imagebenjaminfjones ( 13 years ago )

That wouldn't be too hard to do. We basically do this already with `to_poly_solve`, in order to make sure we don't use it and then miss "real" solutions that would get caught. You just check if the variable is on both sides :) Can you open a ticket for this and cc: me? We've gotten so many bug reports on this over the years it's insane.

kcrisman gravatar imagekcrisman ( 13 years ago )

That worked, thanks!

Juanlu001 gravatar imageJuanlu001 ( 13 years ago )

In this context, `z6` refers to an integer parameter in the solution. There are infinitely many solutions to the equation and they all differ by integer multiples of 2*pi.

benjaminfjones gravatar imagebenjaminfjones ( 13 years ago )

Sorry, I thought I made that clear - thanks for spelling it out explicitly to lurkers. Same goes for z8, of course, and they won't always look the same, depends on how much you've used Maxima that session already.

kcrisman gravatar imagekcrisman ( 13 years ago )

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 13 years ago

Seen: 2,615 times

Last updated: Apr 14 '11