# Simple trigonometric equation

I am a beginner and I am reading the page Basic Algebra and Calculus of the Tutorial where there is the following example

theta = var('theta')
solve(cos(theta)==sin(theta), theta)


and there is no solution, but a human being and other systems, like Mathematica, are able to solve this simple equation. So I suppose there is a way to solve it with Sage. Can you show me how?

edit retag close merge delete

Sort by ยป oldest newest most voted

Using the keyword argument algorithm='sympy' leads to more success:

sage: solve(cos(theta)==sin(theta), theta, algorithm='sympy')
[ImageSet(Lambda(_n, 2*_n*pi + 5*pi/4), Integers),
ImageSet(Lambda(_n, 2*_n*pi + pi/4), Integers)]

more

1

Other possibilities :

sage: solve(((sin(theta)==cos(theta))/cos(theta)).trig_reduce(), theta)
[theta == 1/4*pi]


which is harder and incomplete,

sage: solve(sin(theta)==cos(theta), theta, to_poly_solve=True)
[theta == 1/4*pi + pi*z1971]


which is

• more concise, and

but uses an undeclared and implicitly integer-valued variable.

HTH,

If you have Mathematica (or the Wolfram engine) installed, you can also try :

sage: mathematica.Solve(sin(theta)==cos(theta), theta)
{{theta -> ConditionalExpression[(-3*Pi)/4 + 2*Pi*C[1],
Element[C[1], Integers]]},
{theta -> ConditionalExpression[Pi/4 + 2*Pi*C[1], Element[C[1], Integers]]}}


Other Sage-usable solvers do not solve this explicitly.

( 2023-08-05 16:38:55 +0200 )edit

Very interesting suggestions. When I use Mathematica (which I have) it results in the following errror:

ValueError: The mathematica session in which this object was defined is no longer running.

( 2023-08-05 17:38:04 +0200 )edit