%EB%A5%BC%20%EC%82%AC%EC%9A%A9%ED%95%9C%20%ED%94%8C%EB%A1%9C%ED%8C%85%20%ED%95%A8%EC%88%98%20%EA%B4%80%EB%A0%A8%20%EB%AC%B8%EC%A0%9C.png)
나는 합산될 때 다음을 구성하는 단계 함수를 플롯하려고 합니다.다카기 기능. 첫 번째 단계 함수의 그래프는 그대로 유지되지만 두 번째 단계 함수의 그래프는 실패합니다. 아래 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}