Solving trig functions



  Daniel Dalton daniel.dalton47 at gmail.com
http://www.math.utexas.edu/pipermail/maxima/2012/028392.html
wrote:

 Hi,
I need to solve trig functions on maxima and get all solutions for a
given domain. For example,
sin(x) = 1/2
In the domain of [-2*%pi, 2*%pi].
Currently with maxima I can only get the solution in the first quadrant
- %pi/6.
Does anyone know how to do this or have any idea of some reliable code I
could write for my own function definition to find the rest of the
angles?
Thank you very much.
Dan

see also Barton Willis
http://www.math.utexas.edu/pipermail/maxima/2012/028393.html


 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 Solve sin(x)=1/2 in the domain of [-2*%pi, 2*%pi].

(%i2) trigsolve(sin(x)=1/2,-2*%pi,2*%pi);
(%o2) {-(11*%pi)/6,-(7*%pi)/6,%pi/6,(5*%pi)/6}
(%i3) float(%), numer;
(%o3)
{-5.759586531581287,-3.665191429188092,0.5235987755983,2.617993877991494}
(%i4) wxplot2d([sin(x)-1/2], [x,-2*%pi,2*%pi])$
(%t4)  << Graphics >>

 Example 2 solve cos(x)-sin(3*x)=0

(%i2) eq:cos(x)-sin(3*x)=0$
(%i3) cos(x)-cos(y)=-2*sin(1/2*x+1/2*y)*sin(1/2*x-1/2*y)$
(%i4) subst(y=3*x-%pi/2,%),expand;
(%o4) cos(x)-sin(3*x)=2*sin(x-%pi/4)*sin(2*x-%pi/4)
(%i5) eq1:sin(x-%pi/4)=0$
(%i6) eq2:sin(2*x-%pi/4)=0$
(%i7) S1:trigsolve(eq1,-%pi,%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 $
(%o7) {-(3*%pi)/4,%pi/4}
(%i8) S2:trigsolve(eq2,-%pi,%pi);
(%o8) {-(7*%pi)/8,-(3*%pi)/8,%pi/8,(5*%pi)/8}
(%i9) S:union(S1,S2);
(%o9) {-(7*%pi)/8,-(3*%pi)/4,-(3*%pi)/8,%pi/8,%pi/4,(5*%pi)/8}
(%i10) float(%), numer;
(%o10)
{-2.748893571891069,-2.356194490192345,-1.178097245096172,0.39269908169872,0.78539816339745,1.963495408493621}

 Answer: x=a+2*%pi*k, where a - any from S, k - any integer

(%i11) plot2d([cos(x)-sin(3*x)], [x,-%pi,%pi])$

Thanks for your comments

Aleksas D