# TikZ - How to plot composed function of type x(t) = cos(t+ cos(t)) without pgfplots?

I'm trying to plot a graph of a composed function in form x(t) = cos(t+ cos(t)) using only TikZ without PGFplots, but the result is incorrect.

(source: mrak.cz)

The used code is:

\documentclass{standalone}
\usepackage{tikz}

\begin{document}

% PM signál
\begin{tikzpicture}[font=\tiny]
% Vykreslení os
\draw[->] (-0.1, 0) -- (2.5, 0) node[below] {$t$~[s]}; % Vodorovná osa
\draw[->] (0, -1.5) -- (0, 1.5) node[left] {$u_{PM}(t)$~[V]}; % Svislá osa
% Vykreslení bodů na osách
\foreach \xx in {0,...,2}
\draw (\xx, -0.1) node[below, fill=white]{\xx} -- (\xx, 0.1);
\foreach \yy in {-1,...,1}
\draw (-0.1, \yy) node[left, fill=white]{\yy} -- (0.1, \yy);
% Vykreslení funkcí
\draw [variable=\t, domain=0:2, samples=401, smooth, red] plot (\t, {cos(2*pi*10*\t + pi*cos(2*pi*1*\t r) r)}); % "r" v argumentu kosinu znamená, že argument je v radiánech
\end{tikzpicture}

\end{document}


The expected result (using PGFplots) is as follows:

(source: mrak.cz)

Used code is:

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest, compat/show suggested version=false} % http://tex.stackexchange.com/questions/81899/what-does-running-in-backwards-compatibility-mode-mean-and-what-should-i-fix-t

\begin{document}
% PM signál
\begin{tikzpicture}[font=\tiny]
\begin{axis}[
name=PMsignal,
axis lines=center,
x label style={at={(axis description cs:1.05,0.5)}, anchor=north},
y label style={at={(axis description cs:-0.1,1)}, anchor=north},
xlabel={$t$~[s]},
ylabel={$u_{PM}(t)$~[V]},
xmin=0, xmax=2,
ymin=-1.5, ymax=1.5,
]
\addplot[variable=t, domain=0:2, samples=401, thick, no markers, red] {cos(2*pi*10*t + pi*cos(2*pi*1*t))};
\end{axis}
\end{tikzpicture}

\end{document}


Am I doing something wrong or TikZ just can not plot those types of functions?

• The r operator has the same priority than multiplications and divisions. So, 2 + 3 r is equal to 2 + (3 r). You may use parentheses : (2 + 3) r... Aug 17, 2016 at 9:05

you have misamtch in \cos argument, it should be

cos((2*pi*10*\t + pi*cos(2*pi*\t r)) r)


(observe parenthesis):

\documentclass{standalone}
\usepackage{tikz}

\begin{document}

% PM signál
\begin{tikzpicture}[font=\tiny]
% Vykreslení os
\draw[->] (-0.1, 0) -- (2.5, 0) node[below] {$t$~[s]}; % Vodorovná osa
\draw[->] (0, -1.5) -- (0, 1.5) node[left] {$u_{PM}(t)$~[V]}; % Svislá osa
% Vykreslení bodů na osách
\foreach \xx in {0,...,2}
\draw (\xx, -0.1) node[below, fill=white]{\xx} -- (\xx, 0.1);
\foreach \yy in {-1,...,1}
\draw (-0.1, \yy) node[left, fill=white]{\yy} -- (0.1, \yy);
% Vykreslení funkcí
\draw [variable=\t,domain=0:2,samples=401,smooth,red]
plot (\t,{cos((2*pi*10*\t + pi*cos(2*pi*\t r)) r)});
\end{tikzpicture}

\end{document}

• What is the meaning of the "r" apres the cos? Feb 21, 2017 at 13:42
• @R.Falque, angle units are radians. Feb 21, 2017 at 13:50
• @Zarko, thanks that make lots of sense now haha Feb 21, 2017 at 13:53