1

I need to plot the function y = sec(x)/exp(tan(x)) however the code I used (which I've pasted below) only produces a straight line.

\begin{center}
\begin{tikzpicture}
\begin{axis}[xlabel={$x$},ylabel={$y$},
   axis equal,axis lines=middle,
   width=12cm,height=7cm,
   xmin=-1.6,xmax=1.6,
   ymin=-1,ymax=2,
   yticklabel=\empty,xticklabel=\empty,
   ytick=\empty,xtick=\empty]
\addplot[color=red,domain=-1.57:1.57,samples=100] {sec(x)/(exp(tan(x))};
\end{axis}
\end{tikzpicture}
 \end{center}

I've tried individual functions. exp(x) worked, but tan(x) and sec(x) both similarly returned a straight line. Any help or guidance would be greatly appreciated!

  • 1
    The trigonometric functions in pgf assume degrees as input, so you need trig format plots=rad in the axis options (or trig format=rad, which affects not only plots see the pgfplots manual), or convert to degrees with deg(x), or use the r postfix as in Luis' answer. – Torbjørn T. Aug 7 at 8:26
2

Maybe sec and tan are not being calculated in the correct way. Try something like sec((x)r) as in the following example (I changed the domain because -1.5to 1.5 gives numbers too big)

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}

\begin{center}
\begin{tikzpicture}
\begin{axis}[xlabel={$x$},ylabel={$y$},
   axis equal,axis lines=middle,
   width=12cm,height=7cm,
   xmin=-1.6,xmax=1.6,
   ymin=-1,ymax=2,
   yticklabel=\empty,xticklabel=\empty,
   ytick=\empty,xtick=\empty]
\addplot[color=red,domain=-1.3:1.3,samples=100] {sec((x)r)/(exp(tan((x)r))};
\end{axis}
\end{tikzpicture}
 \end{center}
 
\end{document}

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.