
노드가 베이즈 규칙(또는 특정 함수)에 의해 정의된 숫자에 배치되도록 [0,1]에 수직선을 그리고 싶습니다. 따라서 x'(내가 지정한)의 초기 값에 대해 프로그램이 모든 후속 노드 x에 노드를 배치하기를 원합니다. 여기서 x= x'/((1+x')*0.5) 등이 최대값까지 계속됩니다. x/1. 다음은 제가 다른 유사한 게시물에서 고안한 MWE입니다.
\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}
이제는 샘플을 사용하는 대신 초기 값(지정할 수 있음)에서 실행한 다음 x가 1에 도달할 때까지 다른 숫자까지 작업하기를 원합니다.
또한 점프를 나타내기 위해 이 숫자 사이에 곡선 화살표를 그릴 수 있도록 이러한 노드를 식별하고 싶습니다.
여러 가지 접근 방식을 시도했지만 TikZ가 초기 값이 있는 공식에 따라 이러한 시퀀스의 특정 숫자를 플롯하는 데 성공하지 못했습니다. 물론 모든 것을 개별적으로 쉽게 해결한 다음 플롯할 수 있지만 이 추악한 무차별 대입 방법을 사용하고 싶지 않습니다.
도움을 주시면 감사하겠습니다. 미리 감사드립니다 :)
답변1
나는 이것이 당신이 원하는 것과 같다고 생각합니다. 초기값은 문과 함께 포인트 단위로 설정됩니다 \setlength
. 값이 1에 도달하지 않기 때문에 while 루프에서 0.99pt를 사용했습니다.
코드에 댓글이 너무 많아서 불분명한 부분이 있으면 물어보고, 제가 잘못 이해한 부분은 알려주세요.
\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}