Math & ScienceTrigonometric functions

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
yago
Posts: 29
Joined: Sat Dec 13, 2008 6:40 pm

Trigonometric functions

Post by yago »

That's no problem for me to plot the sinx, cosx and tanx using PsTricks (pstricks-add) in a reasonable way, but I don't know the code to plot the cotanx, secx and cosecx. This is the code and the graph for senx:

Code: Select all

\psset{xunit=\pstRadUnit,trigLabels=true}
\begin{pspicture}(-0.5,-1.25)(3.5,1.25)
\psaxes[dx=0.75,labels=none,trigLabelBase=2]{->}(0,0)(-0.5,-1.5)(3.5,1.5)
\put(-0.5,1.5){\itshape{Y}}
\put(3.5,0.2){\itshape{X}}
\put(0.7,1.1){\itshape{A}}
\put(-0.4,0.1){\itshape{O}}
\put(1.6,0.1){\itshape{B}}
\put(2.3,-1.3){\itshape{C}}
\put(2.8,0.1){\itshape{D}}
\put(-0.6,0.9){+1} \put(-0.5,-1.1){-1}
\uput[dl](0.8,0){$\frac{\pi}2$}
\uput[dr](1.2,0){$\pi$}
\uput{-0.6ex}[310](2.22,0){$\frac{3}{2}{\pi}$}
\uput{-0.6ex}[310](3,0){$2\pi$}
\psplot[xunit=0.5cm,linecolor=black,linewidth=1pt]{0}{\psPiTwo}{x RadtoDeg sin}
\psline[linestyle=dotted,linecolor=black,linewidth=1pt](0,1)(0.785,1) \psline[linestyle=dotted,linecolor=black,linewidth=1pt](0.75,0)(0.75,1) \psline[linestyle=dotted,linecolor=black,linewidth=1pt](2.25,0)(2.25,-1)
\end{pspicture}
Thanks for your help.
Attachments
curva_seno.pdf
(5.49 KiB) Downloaded 480 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Trigonometric functions

Post by localghost »

Looking at the definitions of these trigonometric functions, I see no problem in plotting them with pstricks [1]. I'm not sure if it is supported, but you may take a look at pst-func and pst-math. Taking the cot(x) as example, you only have to take the reciprocal of tan(x).

Code: Select all

\psplot[algebraic,xunit=0.5cm,linewidth=1pt]{0}{\psPiTwo}{tan(x)}
If there is a cot(x) expression possible, try this with the right domain. As seen above, notation of functions is simplified by using the algbraic option for the \psplot command. See the manual of pstricks-add for further information. For other functions it may be similar. If not, you can give the functions in algebraic notation as they are defined with according domains [1].

[1] Trigonometric functions - Wikipedia, the free encyclopedia


Best regards
Thorsten¹
yago
Posts: 29
Joined: Sat Dec 13, 2008 6:40 pm

Re: Trigonometric functions

Post by yago »

Thank you very much for your help. With this code I have the tan plot perfectly:

\psset{xunit=\pstRadUnit,trigLabels=true}
\begin{pspicture}*(-0.5,-1.5)(3.8,2)
\psaxes[dx=0.75,labels=none,ticks=x,trigLabels,trigLabelBase=2]{->}(0,0)(-0.5,-2)(3.8,2)
\put(-0.4,1.6){\itshape{Y}}
\put(3.5,0.1){\itshape{X}}
\put(-0.4,-0.3){\itshape{O}}
\put(0.2,1.6){\itshape{M}}
\put(0.9,1.6){\itshape{A}}
\put(1.2,-1.5){\itshape{N}}
\put(1.7,1.6){$N'$}
\put(2.4,1.6){\itshape{B}}
\put(0.4,-1.5){$A'$}
\put(1.9,-1.5){$B'$}
\put(2.7,-1.5){$M'$}
\put(2.8,0.1){\itshape{D}}
\rput(1.2,-2.2){\small\bfseries{Figura 2.11}}
\uput[dl](0.8,0){$\frac{\pi}2$}
\uput[dr](1.4,0){$\pi$}
\uput{-0.6ex}[310](2.2,0){$\frac{3}{2}{\pi}$}
\uput{-0.6ex}[310](3,0){$2\pi$}
\psplot[xunit=0.5cm,linecolor=black,linewidth=1pt]{0}{\psPiTwo}{x RadtoDeg sin x RadtoDeg cos div}
\end{pspicture}

But for the cotan (that's is cos(x)/sen(x)) and with this code, I receive a lot of errors:

\psset{xunit=\pstRadUnit,trigLabels=true}
\begin{pspicture}*(-0.5,-1.5)(3.8,2)
\psaxes[dx=0.75,labels=none,ticks=x,trigLabels,trigLabelBase=2]{->}(0,0)(-0.5,-2)(3.8,2)
\put(-0.4,1.6){\itshape{Y}}
\put(3.5,0.1){\itshape{X}}
\put(-0.4,-0.3){\itshape{O}}
\put(0.2,1.6){\itshape{M}}
\put(0.9,1.6){\itshape{A}}
\put(1.2,-1.5){\itshape{N}}
\put(1.7,1.6){$N'$}
\put(2.4,1.6){\itshape{B}}
\put(0.4,-1.5){$A'$}
\put(1.9,-1.5){$B'$}
\put(2.7,-1.5){$M'$}
\put(2.8,0.1){\itshape{D}}
\rput(1.2,-2.2){\small\bfseries{Figura 2.11}}
\uput[dl](0.8,0){$\frac{\pi}2$}
\uput[dr](1.4,0){$\pi$}
\uput{-0.6ex}[310](2.2,0){$\frac{3}{2}{\pi}$}
\uput{-0.6ex}[310](3,0){$2\pi$}
\psplot[xunit=0.5cm,linecolor=black,linewidth=1pt]{0}{\psPiTwo}{x RadtoDeg cos x RadtoDeg sin div}
\end{pspicture}

I have try with the inverse of the tan (cot(x)=1/tan(x)) with that:

{x RadtoDeg tan -1 mul}, or
{x RadtoDeg tan neg 1 mul}

But the curve goes to zero in (0,0), (pi,0) and (2pi,0), like the tan. And the cotan goes to zero at (pi/2,0), (3pi/2,0), ...

And also the code with the alegbraic option for psplot:

\psplot[algebraic,xunit=0.5cm,linecolor=black,linewidth=1pt]{0}{\psPiTwo}{cos(x)/sen(x)}

With no results but a lot of errors. Thank you.
yago
Posts: 29
Joined: Sat Dec 13, 2008 6:40 pm

Trigonometric functions

Post by yago »

Finally, the solution was to plot the cotan(x) function with the commands \readdata and \listplot from pstricks (pst-math, pstricks-add). The angles data in data files are in radians from zero to 360 sexagesimal degrees with skips of ten degrees, except near the asymptotic points (0, 180, 360) where the cotan(x) value is not calculated but the values of cotan(x) for angles of five degrees before and after the asymptotic points. This is the code:

Code: Select all

\psset{yunit=0.5cm,xunit=\pstRadUnit,trigLabels=true}
\begin{pspicture}*(-0.5,-4.1)(3.5,4)
\psaxes[dx=0.75,ticks=x,labels=none,trigLabelBase=2]{->}(0,0)(-0.5,-4.1)(3.5,4)
\put(-0.4,1.6){\itshape{Y}}
\put(3.3,0.1){\itshape{X}}
\put(-0.3,-0.3){$0$}
\put(0.2,1.6){$+\infty$}
\put(1.8,1.6){$+\infty$}
\put(0.8,-1.8){$-\infty$}
\put(2.4,-1.8){$-\infty$}
\uput[dl](0.8,0){$\frac{\pi}2$}
\uput[dr](1.2,0){$\pi$}
\uput{-0.6ex}[250](2.22,0){$\frac{3}{2}{\pi}$}
\uput{-0.6ex}[230](3,0){$2\pi$}
\readdata{\cotangenteI}{C:/lyx/cotangenteI.dat}
\listplot[plotstyle=curve,xunit=0.5cm,linecolor=black,linewidth=1pt]{\cotangenteI}
\readdata{\cotangenteII}{C:/lyx/cotangenteII.dat}
\listplot[plotstyle=curve,xunit=0.5cm,linecolor=black,linewidth=1pt]{\cotangenteII}
\psline[linecolor=black,linewidth=0.5pt](1.5,-4)(1.5,4)
\psline[linecolor=black,linewidth=0.5pt](3,-4)(3,4)
\end{pspicture}
\caption{Cotangentoide}
\vspace{-10pt}
\legend{\footnotesize{Puntos de inflexión en $\dfrac{\pi}{2}$ y $\dfrac{3}{2}\pi$.\\Saltos de $+\infty$ a $-\infty$ en cero, $\pi$ y $2\pi$.}}

And the two data files:

cotangenteI.dat:

Code: Select all

0.0872664626 11.430052302751
0.174532925199 5.671281819633
0.349065850399 2.747477419456
0.523598775598 1.732050807571
0.698131700798 1.191753592593
0.872664625997 0.839099631177
1.047197551197 0.577350269189
1.221730476396 0.363970234266
1.396263401596 0.176326980708
1.570796326795 0
1.745329251994 -0.176326980708
1.919862177194 -0.363970234266
2.094395102393 -0.577350269189
2.268928027593 -0.839099631178
2.443460952792 -1.191753592595
2.617993877992 -1.732050807571
2.792526803191 -2.747477419456
2.967059728391 -5.671281819633
3.05432619099 -11.430052302751

cotangenteII.dat:

Code: Select all

3.22885911619 11.430052302751
3.316125578789 5.671281819633
3.490658503989 2.747477419449
3.665191429188 1.732050807568
3.839724354388 1.191753592593
4.014257279587 0.839099631177
4.188790204787 0.577350269189
4.363323129986 0.363970234266
4.537856055186 0.176326980708
4.712388980385 0
4.886921905584 -0.176326980708
5.061454830784 -0.363970234267
5.235987755983 -0.57735026919
5.410520681183 -0.839099631178
5.585053606382 -1.191753592595
5.759586531582 -1.732050807571
5.934119456781 -2.747477419456
6.108652381981 -5.671281819633
6.19591884458 -11.430052302751
Post Reply