Tikz cosine function plot without pgf

plottikz-calctikz-pgf

I am trying to plot a function with cosine and exp. It can plot the exp part but not the cosine. I have tried cos, \cos, cosine, \cosine none work. This code used to work for 3 months ago maybe something got updated meanwhile?

\documentclass[tikz]{standalone}
\usepackage{tikz}
\usepackage{calculus}
\usepackage{calc}
\usetikzlibrary{calc,angles,quotes}
\definecolor{dblue}{RGB}{47,122,154} 
\definecolor{lblue}{RGB}{83, 201, 250}
\begin{document}
\begin{tikzpicture}
  \draw[->, line width  = 0.3mm] (0, 0) -- (15, 0) node[right] {$t$};
  \draw[->, line width = 0.3mm] (0, -2.5) -- (0, 2.5) node[above] {$ $};


\draw[dblue, line width = 0.5mm, domain=0:15, variable=\x, dblue] plot ({\x}, {2*cos(\x*8)*exp(-\x/4)});

\draw[lblue, line width = 0.5mm, domain=0:15, variable=\x, lblue] plot ({\x}, {2*exp(-\x/4)});

\end{tikzpicture}
\end{document}

The output I used to get 3 months ago:
enter image description here

Best Answer

You need to tell Tikz to recalculate the value for the cos() function into degrees by using deg(). You can also say cos(\x*8 r) to specify that the argument is in radians.

To make the curve smooth, you can use the options samples and smooth for the cosine curve.

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\definecolor{dblue}{RGB}{47, 122, 154} 
\definecolor{lblue}{RGB}{83, 201, 250}

\begin{document}
\begin{tikzpicture}
  \draw[->, line width=0.3mm] (0, 0) -- (15, 0) node[right] {$t$};
  \draw[->, line width=0.3mm] (0, -2.5) -- (0, 2.5) node[above] {};

  \draw[dblue, line width=0.5mm, domain=0:15, variable=\x, dblue, samples=200, smooth] plot ({\x}, {2*cos(deg(\x*8))*exp(-\x/4)});

  \draw[lblue, line width=0.5mm, domain=0:15, variable=\x, lblue] plot ({\x}, {2*exp(-\x/4)});

\end{tikzpicture}
\end{document}

enter image description here