Ask Your Question
2

Simple trigonometric equation

asked 2023-08-04 22:34:13 +0200

enzotib gravatar image

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-08-05 15:53:18 +0200

eric_g gravatar image

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)]
edit flag offensive delete link more

Comments

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

  • already translated in Sage

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.

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 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.
enzotib gravatar imageenzotib ( 2023-08-05 17:38:04 +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: 2023-08-04 22:34:13 +0200

Seen: 96 times

Last updated: Aug 05 '23