# Solving complex equation 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?

edit retag close merge delete

Sort by » oldest newest most voted
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.

more

@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.

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.

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.

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.