Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
    
Possibly related to: Is plotting exponential graphs a known source of bugs in TikZ? –  Peter Grill Mar 5 '12 at 18:49
add comment

2 Answers

up vote 6 down vote accepted

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}
share|improve this answer
    
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 6 '12 at 9: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 6 '12 at 18:33
add comment

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}
share|improve this answer
    
Could you perhaps tell me how to change my original function accordingly? Logarithms are not my strong point. –  meep.meep Mar 5 '12 at 19:36
    
@meep.meep: Done, but that is more of a math question than a TeX question. –  Peter Grill Mar 5 '12 at 22:21
    
I'll accept Jakes answer because it has additional informaton on how to restrict a domain. But thank you for your help. –  meep.meep Mar 6 '12 at 9:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.