Parameterized plots

As a math teacher, I have to explain how parameters affect the graph of a function. By putting the "tikzpicture" inside a LaTeX macro, it is very easy and fast to create multiple graphs by modifying only the parameters and calling the macro.


parameterized-plots

Edit and compile if you like:

% under Creative Commons attribution license.
% A work by Yves Delhaye
% Requires GNUPLOT and shell-escape enabled
\documentclass{minimal}
\usepackage{tikz}
\usepackage[active,tightpage]{preview}
\setlength\PreviewBorder{0pt}%
\usetikzlibrary{arrows,shapes}
\usepackage{xifthen}
\begin{document}
% Macros for cst. They have to be redefined each time. See inside document
\newcommand{\cA}{1}% Cste . fct
\newcommand{\cB}{0}% Cste + fct
\newcommand{\cC}{1}% Cste . var
\newcommand{\cD}{0}% Cste + var
%LaTeX Macro for drawing fct with pgf/tikz. Define once, use many!
\newcommand{\FctAss}{
\begin{tikzpicture}[domain=0:8]
\pgfmathparse{0.1+\cA*1.1 +\cB} \pgfmathresult \let\maxY\pgfmathresult% evaluate maxY
\pgfmathparse{-0.1-\cA*1.1 +\cB} \pgfmathresult \let\minY\pgfmathresult% evaluate minY
\pgfmathparse{\maxY < 1} \pgfmathresult \let\BmaxY\pgfmathresult% What if maxY < 1? Then set Boolean to 1
\ifthenelse{\equal{\BmaxY}{1.0}}{%
\pgfmathparse{1.2} \pgfmathresult \let\maxY\pgfmathresult% Correct maxY to have correct graph
}{}
\pgfmathparse{\minY > 0} \pgfmathresult \let\BminY\pgfmathresult% What if minY > 0? Then set Boolean to 1
\ifthenelse{\equal{\BminY}{1.0}}{%
\pgfmathparse{0} \pgfmathresult \let\minY\pgfmathresult% Correct minY to have correct graph
}{}
% DRAW the graph of the function from here on
\draw[very thin,color=gray] (-0.1,\minY) grid (7.9,\maxY);% GRID use minY & maxY
\draw[->] (-0.2,0) -- (8.2,0) node[right] {$x$};
\draw[->] (0,\minY) -- (0,\maxY) node[above] {$f(x)$};% y axis use minY & maxY too
\draw[smooth,samples=200,color=blue] plot function{(\cA)* (cos((\cC)*x+(\cD))) + \cB}
node[right] {$f(x) = \cA{} . cos(\cC{} . x + \cD{}) + \cB{}$};
% units for cartesian reference frame
\foreach \x in {0,1}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Click to download: parameterized-plots.texparameterized-plots.pdf
Open in Overleaf: parameterized-plots.tex