Discussion

TrigSolve can find an entire set of solutions for a small class of trigonometric equations consisting of Sin[a x + b]^p, Cos[a x + b]^p, and Tan[a x + b]^p. TrigSolve has three options (each of them can be True or False). Here is a brief explanation of the options.

Simplifications performed by TrigSolve can take a long time, to skip them you can use Simplified -> False.

If you want numerical values of the solutions, you can use Symbolic -> False, it is much faster to compute and still gives the solutions with regard to the period.

If you set SamePeriod -> True, TrigSolve can give, for example, such a set of solutions (in these solutions the C[i] are integers):
\(TraditionalForm
      \`{{x -> 2  π\ C[1]}, {x -> π\/2 + 2  π\ C[1]}, {
          x -> π + 2  π\ C[1]}}\), this way can be convenient to substitute values for C[i] later. With the default setting of SamePeriod -> False, the solution set above would look like this: \(TraditionalForm
      \`{{x -> π\ C[2]}, {x -> π\/2 + 2  π\ C[1]}}\).

Function Definition

\(Clear[TrigSolve]
\)\(Options[TrigSolve] = 

      	{Simplified -> True, SamePeriod -> False, Symbolic -> True}; 


    TrigSolve[equat_Equal, x_Symbol, opts___?OptionQ] := 
      Module[
		{gcd, coeff, eq, sols, 
			simpl, samet, symb}, 


        		{simpl, samet, symb} = {Simplified, SamePeriod, Symbolic} /. 
            Flatten[{opts, Options[TrigSolve]}]; 
		
		
        coeff = Cases[eq = equat, 
				f_[k_.  x + b_. ] -> k, 
            Infinity]; 
		gcd = GCD\ @@\ coeff; 
		
        If[gcd == 0 || Head[gcd] === GCD, 
			Return[{}]]; 
		
        eq = eq /. x -> x/gcd; 
		
        eq = TrigToExp\ /@\ eq /. 
				
            Exp[k_\ x + b_. ] -> x^\((k/I)\) Exp[b]; 
		
        sols = \(If[symb, Solve, NSolve]\)[
				eq, x]; 
		
        If[Head[sols] =!= List, 
			Return[{}]]; 
		
        sols = Union[sols] /. 

            				{x -> y_} -> {x -> \(-I\)\ Log[y] + 2  Pi\ C[1]}; 
		
        If[\(! samet\), 
			
          sols = sols //. 

              					{a___, {x -> y1_.  + T_\ C[i_]}, 
                    b___, {x -> y2_.  + T_\ C[i_]}, c___} /; 
						
                  Abs[N[y1 - y2]] == N[T/2] :> 

                						{
                  a, {x -> 
                      If[Abs[N[y1]] < Abs[N[y2]], 

                          																y1, y2] + 

                        													T/2  C[i + 1]}, 

                  							b, c}]; 
		
        sols = sols /. {x -> y_} -> {x -> y/gcd}; 
		
        If[symb && simpl, 
			
          sols = Map[Expand[FullSimplify[#]]&, 
					sols, {3}]]; 
		
        sols]\)

Examples

TrigSolve[Sin[x + (π/6)] == Cos[x - (π/4)], x]

TrigSolve[Cos[2  x] + Sin[x] Cos[3  x] == 1/2, x]

TrigSolve[Sin[x] + Cos[(x/2)] == 0, x]

TrigSolve[Tan[x] == Cot[x], x]

TrigSolve[2  Sin[(x/2) + (π/6)]^2 == (3/2), x]

TrigSolve[(((Sin[x]/(1 + Cos[x])))^2) == 3, x]

Copyright © 1998, Maxim Rytin