Trigonometric equations



 To finding all solutions of trigonometric equation eq
 from interval [a, b] we define function "trigsolve":

(%i1) trigsolve(eq,a,b):=block([s,i,ats,algebraic],
algebraic:true,
to_poly_solve([eq], [x],'simpfuncs =
['rootscontract,'expand,'radcan,'nicedummies]),
s:makelist(rhs(part(%%,k)[1]),k,1,length(%%)),
ats:[],
for i:1 thru length(s) do
(makelist(ev(s[i],%z0=k),k,-10,10),
ats:append(ats,%%)),
sublist(ats,lambda([e],e>=a and e<=b and
float(ev(abs(lhs(eq)-rhs(eq)),x=e))<ratepsilon)),
sort(%%), setify(%%)
)$

 Example 1  sin(x)=1/2

(%i2) S:trigsolve(sin(x)=1/2,0,2*%pi);

to_poly_solve: to_poly_solver.mac is obsolete; I'm loading
to_poly_solve.mac instead.
Loading maxima-grobner $Revision: 1.6 $ $Date: 2009-06-02 07:49:49 $
(%o2) {%pi/6,(5*%pi)/6}
 Answer: x=a+2*%pi*k, where a - any from S, k - any integer

 Example 2  sin(x)-sqrt(3)*cos(x)=0
(%i3) S:trigsolve(sin(x)-sqrt(3)*cos(x)=0,0,2*%pi);
(%o3) {%pi/3,(4*%pi)/3}
 Answer: x=a+2*%pi*k, where a - any from S, k - any integer

 Example 3  sin(x)+cos(x)=1/2

 See p. 17 of
http://www.informatik.uni-leipzig.de/~graebe/skripte/esr05.pdf
Solving equation sin(x)+cos(x)=1/2 with Maple, Mathematica nad Mupad

(%i4) S:trigsolve(sin(x)+cos(x)=1/2,0,2*%pi);
(%o4) {atan(sqrt(7)/3-4/3)+2*%pi,%pi-atan(sqrt(7)/3+4/3)}
 Answer: x=a+2*%pi*k, where a - any from S, k - any integer

 Test of solution:
(%i5) float(S);
(%o5) {1.994827366285637,5.859154267688846}
(%i6) wxplot2d([sin(x)+cos(x)-1/2], [x,0,2*%pi])$
(%t6)  << Graphics >>

 Example 4  cos(x)-sin(3*x)=0

(%i7) eq:cos(x)-sin(3*x)=0$
(%i8) cos(x)-cos(y)=-2*sin(1/2*x+1/2*y)*sin(1/2*x-1/2*y)$
(%i9) subst(y=3*x-%pi/2,%),expand;
(%o9) cos(x)-sin(3*x)=2*sin(x-%pi/4)*sin(2*x-%pi/4)
(%i10) eq1:sin(x-%pi/4)=0$
(%i11) eq2:sin(2*x-%pi/4)=0$
(%i12) S1:trigsolve(eq1,0,2*%pi);
(%o12) {%pi/4,(5*%pi)/4}
(%i13) S2:trigsolve(eq2,0,2*%pi);
(%o13) {%pi/8,(5*%pi)/8,(9*%pi)/8,(13*%pi)/8}
(%i14) S:union(S1,S2);
(%o14) {%pi/8,%pi/4,(5*%pi)/8,(9*%pi)/8,(5*%pi)/4,(13*%pi)/8}
 Answer: x=a+2*%pi*k, where a - any from S, k - any integer

 Test of solution:
(%i15) float(S);
(%o15)
{0.39269908169872,0.78539816339745,1.963495408493621,3.534291735288517,3.926990816987241,5.105088062083414}
(%i16) wxplot2d([cos(x)-sin(3*x)], [x,0,2*%pi])$
(%t16)  << Graphics >>

 best

A.Domarkas