
Quero desenhar uma reta numérica em [0,1] de modo que os nós sejam colocados em números definidos pela regra de Bayes (ou qualquer função específica). Portanto, para um valor inicial de x' (especificado por mim), quero que o programa coloque nós em cada nó subsequente x, onde x= x'/((1+x')*0.5) e assim por diante até um máximo x de 1. Aqui está um MWE que desenvolvi em outro post semelhante:
\begin{tikzpicture}
\begin{axis}[
axis x line=middle,
axis y line=none,
width=\textwidth,
xmin=0,xmax=1,
xtick={0,1},
xticklabels={$0$,$1$},
xlabel=$\beta$
]
\addplot[samples at={1,...,100},only marks,mark size=0.5,blue] (x/((1+x)*0.5),0);
\end{axis}
\end{tikzpicture}
Agora, não quero que ele seja executado usando amostras, mas sim com um valor inicial (que eu possa especificar) e depois suba para outros números até que x atinja 1.
Além disso, quero identificar esses nós para poder desenhar setas curvas entre esses números para indicar saltos.
Tentei várias abordagens, mas não consegui fazer com que o TikZ plotasse números específicos dessa sequência de acordo com uma fórmula com um valor inicial. É claro que posso facilmente resolver tudo separadamente e depois plotá-lo, mas não quero usar esse método feio de força bruta.
Qualquer ajuda será apreciada. Desde já, obrigado :)
Responder1
Eu acho que isso é algo parecido com o que você quer. O valor inicial é definido em pontos, com a \setlength
instrução. Usei 0,99pt no loop while, porque o valor nunca chega a 1.
O código tem muitos comentários, pergunte se algo não está claro ou me avise se entendi mal.
\documentclass{article}
\usepackage{tikz}
\usepackage{ifthen} % for whiledo
% set initial value
\newlength\MyX
\setlength\MyX{0.1pt}
% counter for giving a different name to each node
\newcounter{XCnt}
\setcounter{XCnt}{1}
% for convenience
\newcommand\XScale{200}
\newcommand\XMax{1}
\begin{document}
Diagram using the values set up in preamble:
\begin{center}
\begin{tikzpicture}
\draw[gray, very thin,|-stealth] (0,0) node[below] {$0$} -- (\XMax*\XScale pt,0) node[below] {$\XMax$};
% basic while loop
\whiledo{\lengthtest{\MyX<0.99pt}}{%
%draw filled node at x-position given by the \MyX length
\node [inner sep=0pt,minimum size=2pt,fill,circle] (n-\theXCnt) at (\MyX*\XScale,0) {};
% calculate new length
\pgfmathsetlengthmacro{\MyX}{\MyX/((1+\MyX)*0.5)}
% add 1 to the naming counter
\stepcounter{XCnt}
% to see the values of \MyX in the log, not necessary
\typeout{\MyX}
}
% one example to show that the nodes can be referenced
\draw [red,latex-latex] (n-1) to[bend left] (n-4);
\end{tikzpicture}
\end{center}
Then a second diagram, with slightly different equation, different initial value and scale:
\begin{center}
% set different initial value
\setlength\MyX{0.02pt}
% reset node naming counter
\setcounter{XCnt}{1}
% change scale, if necessary
\renewcommand\XScale{50}
\renewcommand\XMax{4}
\begin{tikzpicture}
\draw[gray, very thin,-stealth] (0,0) -- (\XMax*\XScale pt+3mm,0); % +3mm to extend the line a bit
% draw tick marks:
\foreach \x in {0,...,\XMax}
\draw [gray,very thin] (\x*\XScale pt,3pt) -- +(0,-6pt) node[below]{$\x$};
\whiledo{\lengthtest{\MyX<3.999pt}}{% note changed limit
\node [inner sep=0pt,minimum size=2pt,fill,circle] (n-\theXCnt) at (\MyX*\XScale,0) {};
\pgfmathsetlengthmacro{\MyX}{\MyX/((1+\MyX)*0.2)}
\stepcounter{XCnt}
\typeout{\MyX}
}
% one example to show that the nodes can be referenced
\draw [red,latex-latex] (n-1) to[bend left] (n-4);
\end{tikzpicture}
\end{center}
\end{document}