6

In want to draw this function with pgfplots: f(x,y) = 1-(1-(1+y)^(-x))/x*y. When compiling, I get some error message about z buffer reoderings. I already played around a bit and ist seems to me the problem is that one variable (x) is in the exponent. So I broke it down to the simple function (1+y)^(x) and the problem still arises. Is there a way to plot this function type with pgfplots or is it just not possible?

\documentclass{scrartcl}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot3[surf] {(1+y)^(x)};
%\addplot3[surf] {1-(1-(1+y)^(-x))/(x*y)};
\end{axis}
\end{tikzpicture}
\end{document}

Edit: Just to show what it should look like: enter image description here

meep.meep
  • 16,905

2 Answers2

7

This is because of a divide by zero in your original function at x=0,y=0, which yields a nan that throws PGFplots off track. You can remove nans by adding the key restrict z to domain*=-inf:inf:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[restrict z to domain=-inf:inf]
\addplot3[surf] {1-(1-(1+y)^(-x))/(x*y)};
\end{axis}
\end{tikzpicture}
\end{document}
Jake
  • 232,450
  • Thank you. I am aware of the dividing by zero problem and already tried to set xmin,ymin in the axis options accordingly as I only need positive values. However, this just gave me more error messages. I guess, I'll just plot it another way. – meep.meep Mar 06 '12 at 09:58
  • Note that xmin,ymin will still cause the problem: they only restrict the axis range, not the range in which samples will be taken. Consider using samples=min:max and samples y=min:max to reduce the sampled range. – Christian Feuersänger Mar 06 '12 at 18:33
5

You could rewrite the function as exp((x)*ln((1+y))):

enter image description here

Your original function can be written as

\addplot3[surf] {1-(1-(exp((-x)*ln(1+y))))/(x*y)};

and yields:

enter image description here

\documentclass{scrartcl}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
  \addplot3[surf] {exp((x)*ln((1+y)))};
  %\addplot3[surf] {1-(1-(1+y)^(-x))/(x*y)};
\end{axis}
\end{tikzpicture}
\end{document}
Peter Grill
  • 223,288