I'm writing about fixed point and I would like to do this image in tikz without the labels.

enter image description here

Is there any way to define a function f such x --> x*(4-x) and a recursion

\draw (0,4) -- (0,0) -- (4,0);
\draw[dashed] (0,0) -- (4,4);
\draw[smooth,samples=100,domain=0:4] plot(\x,{(\x)*(4.0-(\x))});
\draw[dotted,->] (0.04,0) -- (0.04,f(0.04));
\foreach n \in {1,2,3,4,5}
\draw[dotted,->] (f^n(0.04),f^{n+1}(0.04))--(f^{n+1}(0.04),f^{n+1}(0.04)); 

Edit Thanks to Andrew for the correction in the function f.


You can use \pgfmathparse (or \pgfmathsetmacro as below) to recursively compute your function as you run through the pgf \foreach loop. of course, you need to "save" the previous value as you go.

Your question seems to be using both the functions x(4-x) and x(4-x)/2, so I have stuck with the first one. It's very sensitive on the initial value of course:

enter image description here

Here is the code:

\tikzset{% style to put arrow head in middle of line
  ->-/.style={decoration={markings, mark=at position 0.5 with {\arrow{stealth}}},

    \draw[thin,->] (0,0) -- (4.5,0);
    \draw[thin,->] (0,0) -- (0,4.5);
    \draw[dashed] (0,0) -- (4,4);
    \draw[blue,thick,smooth,samples=100,domain=0:4] plot(\x,{(\x)*(4.0-(\x))});
    \def\fn{0.2}% initial value
    \foreach \n in {1,...,8} {
      \pgfmathsetmacro\fnn{\fn*(4-\fn)}% compute the next value
      \xdef\fn{\fnn}% save value - need \xdef to force expansion

  • oh, so sorry, I'm going to edit, it is only x*(4-x) – Luis Felipe Oct 16 '16 at 22:35
  • 1
    @LuisFelipe I just noticed your arrow heads were centered so I have added this. – user30471 Oct 16 '16 at 22:43
  • wirh some math, the image is better for f(x)=2.7*x*(1-x) for 0<x<1 and for fn=0.04 – Luis Felipe Oct 16 '16 at 22:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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