1 @c -*- mode: texinfo -*-
4 * Introduction to trigtools::
5 * Functions and Variables for trigtools::
9 @node Introduction to trigtools, Functions and Variables for trigtools, Package trigtools, Package trigtools
10 @center @titlefont{Trigtools Package}
12 @center @b{Aleksas Dormarkas}
13 @center @email{aleksasd873@@gmail.com}
14 @center @email{aleksas.domarkas@@mif.vu.lt}
15 @center December 1, 2013
17 @section Introduction to trigtools
18 We use open-source computer algebra system(CAS) maxima 5.31.2.
19 The trigtools package@footnote{This is a conversion by hand of the original ``trigtools-doc.pdf'' file in ``share/contrib/trigtools'', by Raymond Toy. See the pdf for the definitive version.} contains commands that help you work with
20 trigonometric expessions. List of functions in trigtools package:
27 @item @mref{trigfactor}
28 @item @mref{trigsolve}
29 @item @mref{trigvalue}
31 @item @mref{atan_contract}
35 @node Functions and Variables for trigtools, References, Introduction to trigtools, Package trigtools
36 @section Functions and Variables for trigtools
39 * Convert to sin and cos::
40 * Convert to Trignometric Functions::
41 * Convert to Hyperbolic Functions::
42 * Factor Sums of sin and cos Functions::
43 * Solve Trignometric Equations::
44 * Evaluation of Trignometric Functions::
45 * Contract atan Functions::
48 @node Convert to sin and cos, Convert to Trignometric Functions, Functions and Variables for trigtools, Functions and Variables for trigtools
49 @subsection Convert to sin and cos
52 @deffn {Function} c2sin (@var{x})
54 @deffnx {Function} c2cos (@var{x})
55 The function c2sin converts the expression
56 m4_math(<<<a\cos x + b\sin x>>>, <<<@math{a*cos(x)+b*sin(x)}>>>)
58 m4_mathdot(<<<r\sin(x+\phi)>>>, <<<@math{r*sin(x+phi)}>>>)
60 The function c2cos converts the expression
61 m4_math(<<<a\cos x + b\sin x>>>, <<<@math{ a*cos(x)+b*sin(x)}>>>)
63 m4_mathdot(<<<r\cos(x-\phi)>>>, <<<@math{r*cos(x-phi)}>>>)
67 (%i1) load("trigtools")$
68 (%i2) c2sin(3*sin(x)+4*cos(x));
70 (%o2) 5 sin(x + atan(-))
72 (%i3) trigexpand(%),expand;
73 (%o3) 3 sin(x) + 4 cos(x)
76 (%i4) c2cos(3*sin(x)-4*cos(x));
78 (%o4) - 5 cos(x + atan(-))
82 (%i5) trigexpand(%),expand;
83 (%o5) 3 sin(x) - 4 cos(x)
86 (%i6) c2sin(sin(x)+cos(x));
88 (%o6) sqrt(2) sin(x + ---)
91 (%i7) trigexpand(%),expand;
93 (%i8) c2cos(sin(x)+cos(x));
95 (%o8) sqrt(2) cos(x - ---)
98 (%i9) trigexpand(%),expand;
103 Example. Solve trigonometric equation
107 (%i10) eq:3*sin(x)+4*cos(x)=2;
108 (%o10) 3 sin(x) + 4 cos(x) = 2
111 (%i11) plot2d([3*sin(x)+4*cos(x),2],[x,-%pi,%pi]);
113 @center @image{figures/trigtools-1,5in,,plot1}
115 (%i12) eq1:c2sin(lhs(eq))=2;
117 (%o35) 5 sin(x + atan(-)) = 2
119 (%i13) solvetrigwarn:false$
120 (%i14) solve(eq1)[1]$ x1:rhs(%);
122 (%o15) asin(-) - atan(-)
124 (%i16) float(%), numer;
125 (%o39) - 0.5157783719341241
126 (%i17) eq2:c2cos(lhs(eq))=2;
128 (%o17) 5 cos(x - atan(-)) = 2
129 (%i18) solve(eq2,x)[1]$ x2:rhs(%);
131 (%o19) atan(-) + acos(-)
133 (%i20) float(%), numer;
134 (%o20) 1.802780589520693
138 (%o44) [asin(-) - atan(-), atan(-) + acos(-)]
143 m4_mathcomma(<<<x = x_1 + 2\pi k>>>,<<<x = x1 + 2*%pi*k>>>)
144 m4_mathcomma(<<<x_1 = \sin^{-1}{2\over 5} - \tan^{-1}{4\over
145 3}>>>, <<<x1 = asin(2/5)-atan(4/3)>>>)
147 m4_mathcomma(<<<x_1 = \tan^{-1}{3\over 4} + \cos^{-1}{2\over 5}>>>,
148 <<<x1 = atan(3/4)+acos(2/5)>>>)
149 for @math{k} any integer.
153 @node Convert to Trignometric Functions, Convert to Hyperbolic Functions, Convert to sin and cos, Functions and Variables for trigtools
154 @subsection Convert to Trignometric Functions
157 @deffn {Function} c2trig (@var{x})
158 The function c2trig (convert to trigonometric) reduce expression with hyperbolic functions
159 sinh, cosh, tanh, coth to trigonometric expression with sin, cos, tan, cot.
167 (%i1) load(trigtools)$
168 (%i2) sinh(x)=c2trig(sinh(x));
169 cosh(x)=c2trig(cosh(x));
170 tanh(x)=c2trig(tanh(x));
171 coth(x)=c2trig(coth(x));
172 (%o2) sinh(x) = - %i sin(%i x)
173 (%o3) cosh(x) = cos(%i x)
174 (%o4) tanh(x) = - %i tan(%i x)
175 (%o5) coth(x) = %i cot(%i x)
178 @item see @url{http://www.math.utexas.edu/pipermail/maxima/2013/034585.html}
183 (%o7) cos(p) cosh(q) - %i sin(p) sinh(q)
192 (%i10) trigexpand(%);
193 (%o10) %i cos(a) sinh(b) + sin(a) cosh(b)
200 (%i12) cos(a*%i+b*%i);
201 (%o12) cos(%i b + %i a)
202 (%i13) trigexpand(%);
203 (%o13) sinh(a) sinh(b) + cosh(a) cosh(b)
205 (%o14) cos(%i b + %i a)
213 (%i16) trigexpand(%);
215 (%o16) ---------------------
216 1 - %i tan(a) tanh(b)
220 (%o217) tan(%i b + a)
229 (%i19) trigexpand(%);
230 (- %i cot(x) coth(y)) - 1
231 (%o19) -------------------------
240 @node Convert to Hyperbolic Functions, Factor Sums of sin and cos Functions, Convert to Trignometric Functions, Functions and Variables for trigtools
241 @subsection Convert to Hyperbolic Functions
244 @deffn {Function} c2hyp (@var{x})
245 The function c2hyp (convert to hyperbolic) convert expression with exp function
246 to expression with hyperbolic functions sinh, cosh.
252 (%o6) sinh(x) + cosh(x)
253 (%i7) c2hyp(exp(x)+exp(x^2)+1);
255 (%o7) sinh(x ) + cosh(x ) + sinh(x) + cosh(x) + 1
256 (%i8) c2hyp(exp(x)/(2*exp(y)-3*exp(z)));
258 (%o8) ---------------------------------------------
259 2 (sinh(y) + cosh(y)) - 3 (sinh(z) + cosh(z))
264 @node Factor Sums of sin and cos Functions, Solve Trignometric Equations, Convert to Hyperbolic Functions, Functions and Variables for trigtools
265 @subsection Factor Sums of sin and cos Functions
268 @deffn {Function} trigfactor (@var{x})
269 The function trigfactor factors expresions of
271 m4_mathdot(<<<\pm \sin x \pm \cos y>>>, <<<+-sin(x)+-cos(y)>>>)
278 (%i2) trigfactor(sin(x)+cos(x));
280 (%o2) sqrt(2) cos(x - ---)
283 (%o3) sin(x) + cos(x)
289 (%i4) trigfactor(sin(x)+cos(y));
291 (%o4) 2 cos(- - - + ---) cos(- + - - ---)
296 (%o5) cos(y) + sin(x)
302 (%i6) trigfactor(sin(x)-cos(3*y));
304 (%o6) 2 sin(--- - - + ---) sin(--- + - - ---)
307 (%o7) sin(x) - cos(3 y)
312 (%i8) trigfactor(-sin(5*x)-cos(3*y));
313 3 y 5 x %pi 3 y 5 x %pi
314 (%o8) - 2 cos(--- - --- + ---) cos(--- + --- - ---)
317 (%o9) (- cos(3 y)) - sin(5 x)
323 (%i10) sin(alpha)+sin(beta)=trigfactor(sin(alpha)+sin(beta));
324 beta alpha beta alpha
325 (%o10) sin(beta) + sin(alpha) = 2 cos(---- - -----) sin(---- + -----)
329 (%o78) sin(beta) + sin(alpha) = sin(beta) + sin(alpha)
334 (%i12) sin(alpha)-sin(beta)=trigfactor(sin(alpha)-sin(beta));
335 beta alpha beta alpha
336 (%o12) sin(alpha) - sin(beta) = - 2 sin(---- - -----) cos(---- + -----)
342 (%i13) cos(alpha)+cos(beta)=trigfactor(cos(alpha)+cos(beta));
343 beta alpha beta alpha
344 (%o80) cos(beta) + cos(alpha) = 2 cos(---- - -----) cos(---- + -----)
351 (%i14) cos(alpha)-cos(beta)=trigfactor(cos(alpha)-cos(beta));
352 beta alpha beta alpha
353 (%o14) cos(alpha) - cos(beta) = 2 sin(---- - -----) sin(---- + -----)
360 (%i15) trigfactor(3*sin(x)+7*cos(x));
361 (%o15) 3 sin(x) + 7 cos(x)
365 (%o16) sqrt(58) sin(x + atan(-))
369 (%i17) trigexpand(%),expand;
370 (%o17) 3 sin(x) + 7 cos(x)
376 (%i18) trigfactor(sin(2*x));
378 (%i19) trigexpand(%);
379 (%o19) 2 cos(x) sin(x)
385 @node Solve Trignometric Equations, Evaluation of Trignometric Functions, Factor Sums of sin and cos Functions, Functions and Variables for trigtools
386 @subsection Solve Trignometric Equations
389 @deffn {Function} trigsolve (@var{x})
390 The function trigsolve find solutions of trigonometric equation from
392 m4_mathdot(<<<[a,b)>>>, <<<[a, b)>>>)
398 (%i38) eq:eq:3*sin(x)+4*cos(x)=2;
399 (%o38) 3 sin(x) + 4 cos(x) = 2
401 (%i39) plot2d([3*sin(x)+4*cos(x),2],[x,-%pi,%pi]);
403 @center @image{figures/trigtools-2,5in,,plot2}
406 (%i40) sol:trigsolve(eq,-%pi,%pi);
407 2 sqrt(21) 12 2 sqrt(21) 12
408 (%o40) @{atan(---------- - --), %pi - atan(---------- + --)@}
410 (%i41) float(%), numer;
411 (%o41) @{- 0.5157783719341241, 1.802780589520693@}
415 m4_math(<<<x = \tan^{-1}\left({2\sqrt{21}\over 5} - {12\over
416 5}\right) + 2\pi k>>>, <<<x = atan((2*sqrt(21))/5-12/5)+2*%pi*k>>>)
418 m4_mathcomma(<<<x = \pi - \tan^{-1}\left({2\sqrt{21}\over 5} +
419 {12\over 5}\right) + 2\pi k>>>,
420 <<<x=%pi-atan((2*sqrt(21))/5+12/5)+2*%pi*k>>>)
421 @math{k} -- any integer.
425 (%i6) eq:cos(3*x)-sin(x)=sqrt(3)*(cos(x)-sin(3*x));
426 (%o6) cos(3 x) - sin(x) = sqrt(3) (cos(x) - sin(3 x))
427 (%i7) plot2d([lhs(eq)-rhs(eq)], [x,0,2*%pi])$
429 @center @image{figures/trigtools-3,5in,,plot3}
433 We have 6 solutions from [0, 2*pi].
435 (%i8) plot2d([lhs(eq)-rhs(eq)], [x,0.2,0.5]);
437 @center @image{figures/trigtools-4,5in,,plot4}
439 (%i9) plot2d([lhs(eq)-rhs(eq)], [x,3.3,3.6]);
441 @center @image{figures/trigtools-5,5in,,plot4}
443 (%i10) trigfactor(lhs(eq))=map(trigfactor,rhs(eq));
445 (%o15) - 2 sin(x + ---) sin(2 x - ---) = 2 sqrt(3) sin(x - ---) sin(2 x - ---)
447 (%i11) factor(lhs(%)-rhs(%));
448 4 x + %pi 4 x - %pi 8 x - %pi
449 (%o11) - 2 (sin(---------) + sqrt(3) sin(---------)) sin(---------)
453 Equation is equivalent to
456 (%i12) L:factor(rhs(%)-lhs(%));
457 4 x + %pi 4 x - %pi 8 x - %pi
458 (%o12) 2 (sin(---------) + sqrt(3) sin(---------)) sin(---------)
462 (%i13) eq1:part(L,2)=0;
464 (%o13) sin(---------) + sqrt(3) sin(---------) = 0
468 (%i14) eq2:part(L,3)=0;
470 (%o14) sin(---------) = 0
473 (%i15) S1:trigsolve(eq1,0,2*%pi);
475 (%o15) @{---, ------@}
477 (%i16) S2:trigsolve(eq2,0,2*%pi);
478 %pi 5 %pi 9 %pi 13 %pi
479 (%o16) @{---, -----, -----, ------@}
481 (%i17) S:listify(union(S1,S2));
482 %pi %pi 5 %pi 13 %pi 9 %pi 13 %pi
483 (%o17) [---, ---, -----, ------, -----, ------]
485 (%i18) float(%), numer;
486 (%o18) [0.2617993877991494, 0.3926990816987241, 1.963495408493621,
487 3.403392041388942, 3.534291735288517, 5.105088062083414]
491 m4_mathcomma(<<<x = a + 2\pi k>>>, <<<x = a+2*%pi*k>>>)
492 where @math{a} any from @math{S}, @math{k} any integer.
496 (%i19) eq:8*cos(x)*cos(4*x)*cos(5*x)-1=0;
497 (%o19) 8 cos(x) cos(4 x) cos(5 x) - 1 = 0
500 (%o20) 2 cos(10 x) + 2 cos(8 x) + 2 cos(2 x) + 1 = 0
503 Left side is periodic with period
504 m4_mathdot(<<<T=\pi>>>, <<<T=%pi>>>)
506 We have 10 solutions from [0, pi].
508 (%i21) plot2d([lhs(eq),rhs(eq)],[x,0,%pi]);
510 @center @image{figures/trigtools-6,5in,,plot6}
512 (%i22) x4:find_root(eq, x, 1.3, 1.32);
513 (%o22) 1.308996938995747
514 (%i23) x5:find_root(eq, x, 1.32, 1.35);
515 (%o23) 1.346396851538483
516 (%i24) plot2d([lhs(eq),0], [x,1.3,1.35], [gnuplot_preamble, "set grid;"]);
518 @center @image{figures/trigtools-7,5in,,plot7}
522 Equation we multiply by
523 m4_mathpunc(:, <<<2\sin x\cos 2x>>>, <<<2*sin(x)*cos(2*x)>>>)
527 (%i25) eq*2*sin(x)*cos(2*x);
528 (%o25) 2 sin(x) cos(2 x) (8 cos(x) cos(4 x) cos(5 x) - 1) = 0
529 (%i26) eq1:trigreduce(%),expand;
530 (%o26) sin(13 x) + sin(x) = 0
532 (%i27) trigfactor(lhs(eq1))=0;
533 (%o27) 2 cos(6 x) sin(7 x) = 0
536 (%i28) S1:trigsolve(cos(6*x),0,%pi);
537 %pi %pi 5 %pi 7 %pi 3 %pi 11 %pi
538 (%o28) @{---, ---, -----, -----, -----, ------@}
542 (%i29) S2:trigsolve(sin(7*x),0,%pi);
543 %pi 2 %pi 3 %pi 4 %pi 5 %pi 6 %pi
544 (%o29) @{0, ---, -----, -----, -----, -----, -----@}
549 We remove solutions of
550 m4_math(<<<\sin x = 0>>>, <<<sin(x)=0>>>)
552 m4_mathdot(<<<\cos 2x = 0>>>, <<<cos(2*x) = 0>>>)
555 (%i30) S3:trigsolve(sin(x),0,%pi);
557 (%i31) S4:trigsolve(cos(2*x),0,%pi);
559 (%o31) @{---, -----@}
563 We find 10 solutions from
564 m4_mathpunc(:,<<<[0, \pi]>>>,<<<[0, %pi]>>>)
568 (%i32) union(S1,S2)$ setdifference(%,S3)$ setdifference(%,S4);
569 %pi %pi 2 %pi 5 %pi 3 %pi 4 %pi 7 %pi 5 %pi 6 %pi 11 %pi
570 (%o34) @{---, ---, -----, -----, -----, -----, -----, -----, -----, ------@}
571 12 7 7 12 7 7 12 7 7 12
575 %pi %pi 2 %pi 5 %pi 3 %pi 4 %pi 7 %pi 5 %pi 6 %pi 11 %pi
576 (%o35) [---, ---, -----, -----, -----, -----, -----, -----, -----, ------]
577 12 7 7 12 7 7 12 7 7 12
581 (%i37) float(S), numer;
582 (%o37) [0.2617993877991494, 0.4487989505128276, 0.8975979010256552,
583 1.308996938995747, 1.346396851538483, 1.79519580205131, 1.832595714594046,
584 2.243994752564138, 2.692793703076966, 2.879793265790644]
587 m4_mathcomma(<<<x = a + 2\pi k>>>, <<<x = a+2*%pi*k>>>)
588 where @math{a} any from @math{S}, @math{k} any integer.
593 @node Evaluation of Trignometric Functions, Contract atan Functions, Solve Trignometric Equations, Functions and Variables for trigtools
594 @subsection Evaluation of Trignometric Functions
597 @deffn {Function} trigvalue (@var{x})
598 The function trigvalue compute values of
600 {m\pi\over n}>>>, <<<sin(m*%pi/n)>>>)
602 {m\pi\over n}>>>, <<<cos(m*%pi/n)>>>)
604 {m\pi\over n}>>>, <<<tan(m*%pi/n)>>>)
607 {m\pi\over n}>>>, <<<cot(m*%pi/n)>>>)
612 @deffn {Function} trigeval (@var{x})
613 The function trigeval compute values of expressions with
615 {m\pi\over n}>>>, <<<sin(m*%pi/n)>>>)
617 {m\pi\over n}>>>, <<<cos(m*%pi/n)>>>)
619 {m\pi\over n}>>>, <<<tan(m*%pi/n)>>>)
622 {m\pi\over n}>>>, <<<cot(m*%pi/n)>>>)
628 @item Values of trignometric functions
630 (%i1) load(trigtools)$
632 (%i2) trigvalue(sin(%pi/10));
638 (%i3) trigvalue(cos(%pi/10));
640 (%o3) -----------------
645 (%i4) trigvalue(tan(%pi/10));
647 (%o4) -------------------
650 (%i5) float(%), numer;
651 (%o5) 0.3249196962329063
652 (%i6) float(tan(%pi/10)), numer;
653 (%o6) 0.3249196962329063
654 (%i7) trigvalue(cot(%pi/10));
655 (%o7) sqrt(2 sqrt(5) + 5)
656 (%i8) float(%), numer;
657 (%o8) 3.077683537175254
658 (%i9) float(cot(%pi/10)), numer;
659 (%o9) 3.077683537175254
660 (%i10) trigvalue(sin(%pi/32));
661 sqrt(2 - sqrt(sqrt(sqrt(2) + 2) + 2))
662 (%o10) -------------------------------------
664 (%i11) trigvalue(cos(%pi/32));
665 sqrt(sqrt(sqrt(sqrt(2) + 2) + 2) + 2)
666 (%o11) -------------------------------------
668 (%i12) trigvalue(cos(%pi/256));
669 sqrt(sqrt(sqrt(sqrt(sqrt(sqrt(sqrt(2) + 2) + 2) + 2) + 2) + 2) + 2)
670 (%o12) -------------------------------------------------------------------
672 (%i13) trigvalue(cos(%pi/60));
673 sqrt(sqrt(sqrt(2) sqrt(3) sqrt(sqrt(5) + 5) + sqrt(5) + 7) + 4)
674 (%o13) ---------------------------------------------------------------
678 (%i14) trigvalue(sin(%pi/60));
679 sqrt(4 - sqrt(sqrt(2) sqrt(3) sqrt(sqrt(5) + 5) + sqrt(5) + 7))
680 (%o14) ---------------------------------------------------------------
685 (%i15) trigvalue(sin(%pi/18));
691 (%i16) trigvalue(sin(%pi/20));
692 sqrt(4 - sqrt(2) sqrt(sqrt(5) + 5))
693 (%o16) -----------------------------------
703 (%i18) eq:'diff(y,x,5)+2*y=0;
715 (%o19) y = C5 %e sin(2 sin(-----) x)
720 + C4 %e cos(2 sin(-----) x)
725 + C3 %e sin(2 sin(-----) x)
730 + C2 %e cos(2 sin(-----) x) + C1 %e
734 (%i20) sol:trigeval(%);
738 2 sqrt(sqrt(5) + 5) x
739 (%o20) y = C3 %e sin(-------------------)
745 2 sqrt(sqrt(5) + 5) x
746 + C2 %e cos(-------------------)
752 2 sqrt(5 - sqrt(5)) x
753 + C5 %e sin(-------------------)
759 2 sqrt(5 - sqrt(5)) x - 2 x
760 + C4 %e cos(-------------------) + C1 %e
764 (%i21) subst(sol,eq)$
770 @item n-th root of complex number
772 Example. Find the 4-th roots of %i
774 (%i24) solve(x^4=%i,x);
776 (%o24) [x = (- 1) %i, x = - (- 1) , x = - (- 1) %i, x = (- 1) ]
780 (%o25) [x = %i cos(---) - sin(---), x = (- %i sin(---)) - cos(---),
783 x = sin(---) - %i cos(---), x = %i sin(---) + cos(---)]
788 sqrt(sqrt(2) + 2) %i sqrt(2 - sqrt(2))
789 (%o26) [x = -------------------- - -----------------,
791 sqrt(2 - sqrt(2)) %i sqrt(sqrt(2) + 2)
792 x = (- --------------------) - -----------------,
794 sqrt(2 - sqrt(2)) sqrt(sqrt(2) + 2) %i
795 x = ----------------- - --------------------,
797 sqrt(2 - sqrt(2)) %i sqrt(sqrt(2) + 2)
798 x = -------------------- + -----------------]
804 @node Contract atan Functions, , Evaluation of Trignometric Functions, Functions and Variables for trigtools
805 @subsection Contract atan Functions
807 @anchor{atan_contract}
808 @deffn {Function} atan_contract (@var{r})
809 The function atan_contract(r) contracts atan functions. We
811 m4_mathdot(<<<|r| < {\pi\over 2}>>>, <<<abs(r)<%pi/2>>>)
815 (%i1) load(trigtools)$
821 (%i2) atan_contract(atan(x)+atan(y));
822 (%o2) atan(y) + atan(x)
823 (%i3) assume(abs(atan(x)+atan(y))<%pi/2)$
824 (%i4) atan(x)+atan(y)=atan_contract(atan(x)+atan(y));
826 (%o4) atan(y) + atan(x) = atan(-------)
832 (%i5) atan(1/3)+atan(1/5)+atan(1/7)+atan(1/8)$ %=atan_contract(%);
834 (%o6) atan(-) + atan(-) + atan(-) + atan(-) = ---
838 @item Machin's formulae
840 (%i7) 4*atan(1/5)-atan(1/239)=atan_contract(4*atan(1/5)-atan(1/239));
842 (%o7) 4 atan(-) - atan(---) = ---
846 @item see @url{http://en.wikipedia.org/wiki/Machin-like_formula}
848 (%i8) 12*atan(1/49)+32*atan(1/57)-5*atan(1/239)+12*atan(1/110443)$
851 (%o9) 12 atan(--) + 32 atan(--) - 5 atan(---) + 12 atan(------) = ---
858 @node References, , Functions and Variables for trigtools, Package trigtools
862 @item @url{http://maxima.sourceforge.net}