diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /macros/generic/trigonometry |
Initial commit
Diffstat (limited to 'macros/generic/trigonometry')
-rw-r--r-- | macros/generic/trigonometry/README.txt | 3 | ||||
-rw-r--r-- | macros/generic/trigonometry/trigonometry.tex | 206 |
2 files changed, 209 insertions, 0 deletions
diff --git a/macros/generic/trigonometry/README.txt b/macros/generic/trigonometry/README.txt new file mode 100644 index 0000000000..c183b6e8ca --- /dev/null +++ b/macros/generic/trigonometry/README.txt @@ -0,0 +1,3 @@ +The file "Trigonometry.tex" is released under the Knuthian Licence, the current CTAN entry for which reads along the following lines (amendments to grammar and spelling made in the following text) -- + +"This software is copyright and you are explicitly granted a licence which allows you, the “user” of the software, to copy, distribute and/or modify the software, provided only that if you modify and then re-distribute the software it must be with a different name to that of the original software."
\ No newline at end of file diff --git a/macros/generic/trigonometry/trigonometry.tex b/macros/generic/trigonometry/trigonometry.tex new file mode 100644 index 0000000000..ecf51eaeae --- /dev/null +++ b/macros/generic/trigonometry/trigonometry.tex @@ -0,0 +1,206 @@ +%= = = = = = = = = = = = = T R I G O N O M E T R Y . T E X = = = = = = = = = + +%%% Trigonometry.TeX: (as published in TeXhax Digest, September 1989) +%%% Philip Taylor, Royal Holloway and Bedford New College, University of London + +%%% Routines to calculate the sine of an angle expressed in radians. +%%% So far as I can tell, the results are accurate to four places +%%% of decimals, for arguments in the range -pi/2 .. pi/2, except +%%% for `ridiculously small' arguments, which cannot be accurately represented. + +%%% The routines for cosine and tangent are left to the reader ... + +%%% After a call to \Sin (<angle>), the result is available for typesetting +%%% or boxing, and may also be extracted from the control-sequence \sine. + +%%% Grouping is used to hide most things, but the following csnames are +%%% globally defined: + +%%% \nodimen, \n@dimen, \product, \sine, \term, \t@rm, \Term + +\newif \ifdebug %%% turn me on to see TeX hard at work ... + +\def \term #1{{x^{#1} \over #1!}} +The power series expansion for $\sin$ is: +$$ \sin x = x - \term3 + \term5 - \term7 + \cdots$$ +\indent and for $\cos$ is: +$$ \cos x = 1 - \term2 + \term4 - \term6 + \cdots$$ + +\let \then = \relax +\chardef \letter = 11 +\chardef \other = 12 +\def \radian {pt } +\let \radians = \radian +\let \dimensionlessunit = \radian +\let \dimensionlessunits = \dimensionlessunit +\def \internalunit {sp } +\let \internalunits = \internalunit +\newif \ifstillconverging +\def \Message #1{\ifdebug \then \message {#1} \fi} + +{ %%% Things that need abnormal catcodes %%% + \catcode `\@ = \letter + \gdef \nodimen {\expandafter \n@dimen \the \dimen} + \gdef \term #1 #2 #3% + {\edef \t@ {\the #1}%%% freeze parameter 1 (count, by value) + \edef \t@@ {\expandafter \n@dimen \the #2\radian}% + %%% freeze parameter 2 (dimen, by value) + \t@rm {\t@} {\t@@} {#3}% + } + \gdef \t@rm #1 #2 #3% + {{% + \count 0 = 0 + \dimen 0 = 1 \dimensionlessunit + \dimen 2 = #2\relax + \Message {Calculating term #1 of \nodimen 2}% + \loop + \ifnum \count 0 < #1 + \then \advance \count 0 by 1 + \Message {Iteration \the \count 0 \space}% + \Multiply \dimen 0 by {\dimen 2}% + \Message {After multiplication, term = \nodimen 0}% + \Divide \dimen 0 by {\count 0}% + \Message {After division, term = \nodimen 0}% + \repeat + \Message {Final value for term #1 of + \nodimen 2 \space is \nodimen 0}% + \xdef \Term {#3 = \nodimen 0 \radians}% + \aftergroup \Term + }} + \catcode `\p = \other + \catcode `\t = \other + \gdef \n@dimen #1pt{#1} %%% throw away the ``pt'' +} + +\def \Divide #1by #2{\divide #1 by #2} %%% just a synonym + +\def \Multiply #1by #2%%% allows division of a dimen by a dimen + {{%%% should really freeze parameter 2 (dimen, passed by value) + \count 0 = #1\relax + \count 2 = #2\relax + \count 4 = 65536 + \Message {Before scaling, count 0 = \the \count 0 \space and + count 2 = \the \count 2}% + \ifnum \count 0 > 32767 %%% do our best to avoid overflow + \then \divide \count 0 by 4 + \divide \count 4 by 4 + \else \ifnum \count 0 < -32767 + \then \divide \count 0 by 4 + \divide \count 4 by 4 + \else + \fi + \fi + \ifnum \count 2 > 32767 %%% while retaining reasonable accuracy + \then \divide \count 2 by 4 + \divide \count 4 by 4 + \else \ifnum \count 2 < -32767 + \then \divide \count 2 by 4 + \divide \count 4 by 4 + \else + \fi + \fi + \multiply \count 0 by \count 2 + \divide \count 0 by \count 4 + \xdef \product {#1 = \the \count 0 \internalunits}% + \aftergroup \product + }} + +\def \Sin (#1)% + {{% + \dimen 0 = #1 \radian + \dimen 2 = 3.1415926535897963 \radian %%% a well-known constant + \divide \dimen 2 by 2 %%% we only deal with -pi/2 : pi/2 + \ifdim \dimen 0 > \dimen 2 + \then \message {Sin: argument (\nodimen 0) too large + --- use range reduction}% + \xdef \sine {<undefined>}% + \else \ifdim \dimen 0 < - \dimen 2 + \then \message {Sin: argument (\nodimen 0) too large + --- use range reduction}% + \xdef \sine {<undefined>}% + \else \Message {Sin: calculating Sin of \nodimen 0}% + \count 0 = 1 %%% see power-series expansion for sine + \dimen 2 = 1 \radian %%% ditto + \dimen 4 = 0 \radian %%% ditto + \loop + \ifnum \dimen 2 = 0 %%% then we've done + \then \stillconvergingfalse + \else \stillconvergingtrue + \fi + \ifstillconverging %%% then calculate next term + \then \term {\count 0} {\dimen 0} {\dimen 2}% + \advance \count 0 by 2 + \count 2 = \count 0 + \divide \count 2 by 2 + \ifodd \count 2 %%% signs alternate + \then \advance \dimen 4 by \dimen 2 + \else \advance \dimen 4 by -\dimen 2 + \fi + \repeat + \xdef \sine {\nodimen 4}% + \fi + \fi + \aftergroup \sine + }} + +%%% What follows is just a demonstration of the \Sin function + +$$ +\def \rule {\noalign {\hrule}} +\def \SIN (#1){&&\Sin (#1)&\cr\noalign{\message {The sine of #1 is \sine}}} +\mathcode `\- = 32768 %%% just a bodge to improve alignment +\let \minus = - +\begingroup +\catcode `\- = \active +\gdef -{\llap{\minus}} +\endgroup +\vbox {\offinterlineskip +\halign +{\vrule #& \qquad \hfil $#$ & \vrule # & \qquad $#$ \hfil & \vrule # \strut \cr + \rule + &\omit {\hfil $x$ \hfil} && \omit {\hfil $\sin x$ \hfil} & \cr + \rule + \SIN (-1.6) + \SIN (-1.5) + \SIN (-1.4) + \SIN (-1.3) + \SIN (-1.2) + \SIN (-1.1) + \SIN (-1.0) + \SIN (-0.9) + \SIN (-0.8) + \SIN (-0.7) + \SIN (-0.6) + \SIN (-0.5) + \SIN (-0.4) + \SIN (-0.3) + \SIN (-0.2) + \SIN (-0.1) + \SIN (-0.01) + \SIN (-0.001) + \SIN (-0.0001) + \SIN (0) + \SIN (0.0001) + \SIN (0.001) + \SIN (0.01) + \SIN (0.1) + \SIN (0.2) + \SIN (0.3) + \SIN (0.4) + \SIN (0.5) + \SIN (0.6) + \SIN (0.7) + \SIN (0.8) + \SIN (0.9) + \SIN (1.0) + \SIN (1.1) + \SIN (1.2) + \SIN (1.3) + \SIN (1.4) + \SIN (1.5) + \SIN (1.6) + \rule} +} +$$ +\end + |