pgfplots(Takagi 함수)를 사용한 플로팅 함수 관련 문제

pgfplots(Takagi 함수)를 사용한 플로팅 함수 관련 문제

나는 합산될 때 다음을 구성하는 단계 함수를 플롯하려고 합니다.다카기 기능. 첫 번째 단계 함수의 그래프는 그대로 유지되지만 두 번째 단계 함수의 그래프는 실패합니다. 아래 MWE를 참조하세요(첫 번째는 검은색, 두 번째는 빨간색). 어떻게 고치나요?

\documentclass[border=5mm]{standalone}
\usepackage{amsmath,amssymb}
\usepackage{pgfplots}

\tikzset{
declare function={Floor(\x)=round(\x-0.5);},
declare function={Ceil(\x)=round(\x+0.5);},
declare function={Distance(\x)=min(\x-Floor(\x),Ceil(\x)-x);},
}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
legend style={at={(0.5,-0.2)},anchor=north}
]

\addplot [
mark=none,
domain=0.0001:2,
samples=500,
smooth,
thick,black,
] {Distance(x)};
\addlegendentry{$x\mapsto \varphi(x)
  :=\min\{x-\lfloor x\rfloor,\lceil x\rceil-x\}
:=\operatorname{dist}(x,\mathbb{Z})$}

\addplot [
mark=none,
domain=0.00001:2,
samples=500,
smooth,
thick,red,
] {Distance(2*x)/2};
\addlegendentry{$x\mapsto \frac{1}{2}\varphi(2x)$}
\end{axis}
\end{tikzpicture}
\end{document} 

여기에 이미지 설명을 입력하세요

답변1

\x함수 정의의 마지막 부분에 백슬래시를 잊어버렸습니다 Distance. 그리고 주석에서 언급했듯이 은(는) pgfmath이미 정의되어 floor있으므로 ceil직접 정의할 필요가 없습니다.

\documentclass[border=5mm]{standalone}
\usepackage{amsmath,amssymb}
\usepackage{pgfplots}

\tikzset{
declare function={Distance(\x)=min(\x-floor(\x),ceil(\x)-\x);},
}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
legend style={at={(0.5,-0.2)},anchor=north}
]

\addplot [
mark=none,
domain=0.0001:2,
samples=500,
smooth,
thick,black,
] {Distance(x)};
\addlegendentry{$x\mapsto \varphi(x)
  :=\min\{x-\lfloor x\rfloor,\lceil x\rceil-x\}
:=\operatorname{dist}(x,\mathbb{Z})$}

\addplot [
mark=none,
domain=0.00001:2,
samples=500,
smooth,
thick,red,
] {Distance(2*x)/2};
\addlegendentry{$x\mapsto \frac{1}{2}\varphi(2x)$}
\end{axis}
\end{tikzpicture}
\end{document} 

여기에 이미지 설명을 입력하세요

관련 정보