# TikZ + PGF function Plotting: Is there a max(a,b) function?

I am trying to plot a function with TikZ and PGF. This function contains a max operator (returning the greater value of the given two parameters).

I want to do the following:

\documentclass[
headsepline,
parskip=full-
]{scrreprt}

\usepackage{tikz}
\usetikzlibrary{matrix,fadings,calc,positioning,decorations.pathreplacing,arrows}
\usetikzlibrary{calc,trees,positioning,arrows,chains,shapes.geometric,decorations.pathreplacing,decorations.pathmorphing,shapes,matrix,shapes.symbols,shapes} %für die Schemata
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[xlabel=$x$, ylabel=$y$]

% function that should use the max(a,b) function
\addplot [domain=0:90, samples=90]{max{0,1-x/20}};
\addlegendentry{test function}

\end{axis}
\end{tikzpicture}
\end{document}


I am using MikTex and when I compile the above I get the following error message:

PGF Math: Sorry, an internal routine of the floating point unit]'.
(in 'max{0,1-x/20}'). ... samples=90]{max{0,1-x/20}};


Because I cant find any reference to the max function I assume it does not even exist. What am I doing wrong or how can I immitate this behaviour?

• Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 Jan 11 '15 at 17:33
• Ok I just edited my inital post. – Crine Jan 11 '15 at 17:42

## 1 Answer

Yes, max is there, but you have to put its arguments in round brackets

max(a,b)


or even

max(a,b,c,d,e) \documentclass[
headsepline,
parskip=full-
]{scrreprt}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}
\begin{tikzpicture}
\begin{axis}[xlabel=$x$, ylabel=$y$]

% function that should use the max(a,b) function
\addplot [domain=0:90, samples=90] {max(0,1-x/20)};
\addlegendentry{test function}

\end{axis}
\end{tikzpicture}
\end{document}