I need to plot several functions in PGFPlots, and each function I plot is actually the same main function minus the function evaluated at some point x. Instead of hard-coding the value of the function for each x, I was wondering if there's a way to define a function, and then evaluate such function at x. So far the code I have is:
\documentclass{article}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{amsmath}
\usepackage{mathptmx} % Use the Adobe Times Roman as the default text font together with math symbols from the Symbol, Chancery and Computer Modern fonts
\usepackage{tikz} % Required for drawing custom shapes
\usepackage{pgfplots}
\usetikzlibrary{plotmarks, calc, spy, pgfplots.polar, external}
\usepgflibrary{shapes.geometric}
\begin{document}
% add and edit tikz figure here:
\begin{tikzpicture}[scale=1]
\begin{axis}
\addplot + [mark=none, domain=0:2, samples=70] { (x^0.65 + sin(1.5*pi*x)))/2};
\addplot + [mark=none, domain=0:4, samples=70] { (x^0.65 + sin(1.5*pi*x)) - (2^0.65 + sin(1.5*pi*2))))/2};
\addplot + [mark=none, domain=2:6, samples=70] { (x^0.65 + sin(1.5*pi*x)) - (4^0.65 + sin(1.5*pi*4))))/2};
\addplot + [mark=none, domain=4:8, samples=70] { (x^0.65 + sin(1.5*pi*x)) - (6^0.65 + sin(1.5*pi*6))))/2};
\addplot + [mark=none, domain=6:10, samples=70] { (x^0.65 + sin(1.5*pi*x)) - (8^0.65 + sin(1.5*pi*8))))/2};
\addplot + [mark=none, domain=8:12, samples=70] { (x^0.65 + sin(1.5*pi*x)) - (10^0.65 + sin(1.5*pi*10)))/2};
\addplot + [mark=none, domain=10:13, samples=70] { (x^0.65 + sin(1.5*pi*x)) - (12^0.65 + sin(1.5*pi*12))))/2};
\end{axis}
\end{tikzpicture}
\end{document}
Best Answer
As Torbjørn T. already mentioned in his comment below the question, this can be done using
declare function
.Please note the comments in the code!