Assume there to be some function $k_{t+1} = f(k_t)$. Is there any smarter way to plot a path starting from $k_0$, doing $n$ steps? Thanks in advance.
\documentclass[
paper=A4,
fontsize=12pt,
parskip=half+,
numbers=ddot,
]
{scrbook}
\usepackage{tkz-euclide}
\usepackage{tikz}
\usetikzlibrary{shapes, arrows, shapes.geometric,positioning,intersections,shapes,decorations, arrows.meta, calc, plotmarks}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{arrows.meta}
\usepackage[T1]{fontenc}
\usetikzlibrary{hobby}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{compat=1.10}
\usepgfplotslibrary{patchplots}
\pgfplotsset{compat=newest}
\usetkzobj{all}
\usepackage{amsmath}
\usepackage{amssymb}
% see: https://tex.stackexchange.com/questions/256883/telling-tikz-to-continue-the-previously-drawn-path-with-a-line-to-operation
\tikzset{%
from end of path/.style={
insert path={
\pgfextra{%
\expandafter\pgfprocesspathextractpoints%
\csname tikz@intersect@path@name@#1\endcsname%
\pgfpointlastonpath%
\pgfgetlastxy\lastx\lasty
}
(\lastx,\lasty)
}}}
\begin{document}
\begin{minipage}[t]{\pdfpagewidth}
%%Tikzpicture
\begin{tikzpicture}[>=latex,x=1pt, y=1pt]
\begin{axis}[
axis lines=center,
xtick=\empty,
ytick=\empty,
xlabel={$k_t$},
ylabel={$k_{t+1}$},
xlabel style={below},
ylabel style={left},
xmin=0,
xmax=10,
ymin=0,
ymax=10,
axis equal image
]
\xdef\start{1};
\coordinate[] (kzero) at (axis cs: \start,0);
%% Functions
\addplot[color=black,mark=none, domain=0:8.5, name path global=linear]{x};
\addplot[color=red,mark=none, domain=0:8.5, samples=500, name path global=red]{x + 0.1*x*(x-4)*(x-8)};
% (k_0,0) -> (k_0, f(k_0))
\draw[->, color=red] (axis cs: \start, 0) -- (axis cs: \start, {\start + 0.1*\start*(\start-4)*(\start-8)});
% (k_0, f(k_0)) -> (f(k_0), f(k_0))
\draw[->, color=red] (axis cs: \start, {\start + 0.1*\start*(\start-4)*(\start-8)}) -- (axis cs: {\start + 0.1*\start*(\start-4)*(\start-8)}, {\start + 0.1*\start*(\start-4)*(\start-8)});
% (f(k_0), f(k_0) -> (f(k_0), f(f(k_0)))
\draw[->, color=red] (axis cs: {\start + 0.1*\start*(\start-4)*(\start-8)}, {\start + 0.1*\start*(\start-4)*(\start-8)}) -- (axis cs: {\start + 0.1*\start*(\start-4)*(\start-8)}, {(\start + 0.1*\start*(\start-4)*(\start-8)) + 0.1*(\start + 0.1*\start*(\start-4)*(\start-8))*((\start + 0.1*\start*(\start-4)*(\start-8))-4)*((\start + 0.1*\start*(\start-4)*(\start-8))-8)});
% ...
\end{axis}
\node[color=red, below right, from end of path=red] {$k_{t+1} = f(k_t)$};
\node[color=red, below] at (kzero) {$k_0$};
\end{tikzpicture}
\end{minipage}
\end{document}
Which produces the following plot:
To be more precise, I'd like to substitute:
% (k_0,0) -> (k_0, f(k_0))
...
% (k_0, f(k_0)) -> (f(k_0), f(k_0))
...
% (f(k_0), f(k_0) -> (f(k_0), f(f(k_0)))
with something like:
k_0 = \start;
for(i = 1; i<n; i++){
\draw[->, color=red] (k_i-1, f(k_i-1)) -- (f(k_i-1), f(k_i-1));
\draw[->, color=red] (f(k_i-1), f(k_i-1)) -- (f(k_i-1), f(f(k_i-1)));
k_i = f(k_i);
}



