# Can someone help me figure out what this TiKZ code does?

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}

\begin{document}
\newcommand{\xmax}{14}
\newcommand{\fmin}{(pi/3)}
\newcommand{\fmax}{(2*pi)}
\begin{tikzpicture}[domain=0:\xmax, samples=500]

\draw[ultra thick, red] plot (\x, {sin(deg(exp(ln(\fmin)+\x/\xmax*(ln(\fmax)-ln(\fmin)))*\x))} );

\end{tikzpicture}
\end{document}


I would understand if LaTeX repeat the code below this statement many times.

• this is begin of picture in which is drawn some function on defined domain. function is determined in 500 points. – Zarko Dec 18 '18 at 9:20
• ok, I've adde all the code. So you can see the function. what does the domain mean? And what does "determined in 500 points" mean? – RenatoP Dec 18 '18 at 9:28
• The domain is the range of the x values to be used for your plot. The samples=500 argument instructs the plot to be done with 500 points in the given domain (this may be used for smoothing the output). – epR8GaYuh Dec 18 '18 at 9:33
• variable is \x ..., please read documentation for tikz,: TikZ & PGF manual v3.0.1a, page 326: 22 Plots of Functions – Zarko Dec 18 '18 at 9:47
• I think we already had this. exp(ln(\fmin)+\x/\xmax*(ln(\fmax)-ln(\fmin)))=\fmin*(\fmax/\fmin)^(\x/\xmax), so this is a function that equals \fmin at \x=0 and \fmax at \x=\xmax and has a power law interpolation in between. I really believe you should go the other way: make some requirements and try to find a function that satisfies them. If you cannot find such a function, you can still ask for help. – user121799 Dec 18 '18 at 16:11

## 1 Answer

I will simply add comments in the code that will hopefully explain everything

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
% define some constants
\newcommand{\xmax}{14}
\newcommand{\fmin}{(pi/3)}
\newcommand{\fmax}{(2*pi)}

% begin a tikzpicture that will pass the options domain and samples with the given value to each command inside of it.
\begin{tikzpicture}[domain=0:\xmax, samples=500]

% Use the plot command from tikz on the given function.
% the function will be evaluated between 0 < x < 500 as these were the borders specified in the domain-option
% in total 500 equidistant points of this function will be calculated as this was the value for the samples option
% Every calculated point will be connected to its neighbours which will raise the impression
% that the function was indeed plotted continuously and not for discrete values only.
% You will see what I mean when you set samples to a low value like 5 or something like that.
% In total the function will be evaluated 500 times. Every time \x is set to the respective value and it is up to the code to actually draw a point.
% This is done by the normal coordinate specification in which \x is used as the x-coordinate and the result of the function as the y-coordinate.
% This results in a normal (<number>,{<mathematical expression>}) syntax for coordinates
\draw[ultra thick, red] plot (\x, {sin(deg(exp(ln(\fmin)+\x/\xmax*(ln(\fmax)-ln(\fmin)))*\x))} );

\end{tikzpicture}
\end{document}