pgfplots: 하나의 addplot으로 무한한 값을 갖는 곡선을 그리는 방법

pgfplots: 하나의 addplot으로 무한한 값을 갖는 곡선을 그리는 방법


acos(7/x)+acos(-2/x)+acos(5/x)-pi나는 음모 를 꾸미고 싶다 domain=-20:20.

나는 이것을 다음과 같이 플롯할 수 있는지 스스로에게 묻습니다.하나곡선(다른 도메인을 가진 두 개의 곡선이 아님)

그래서 나는 unbounded coords=jump(예를 들어여기)
\addplot[red, domain=-20:20] {f(x)}; % works not :(
그러나 그는 오류를 제공합니다! Missing number, treated as zero.

가능성이 있나요?

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

\documentclass[margin=5pt, tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[
trig format=rad, 
declare function={
a=7;    
b=-2;    
c=5;
f(\x)=acos(a/\x)+acos(b/\x)+acos(c/\x)-pi;
m=max(a,b,c);
},
]
\begin{axis}[
axis lines=middle, 
samples=222,
xmin=-20, 
unbounded coords=jump,
]
\addplot[blue, domain = m:20] {f(x)}; % works :)

%\addplot[red, domain=-20:20] {f(x)}; % works not :(
\end{axis}
\end{tikzpicture}
\end{document}

답변1

acos인수의 절대값이 1보다 큰 경우 정의되지 않습니다. 예를 들어 inf인수가 의미가 없는 경우 결과를 산출하는 "정규화된" 버전을 정의할 수 있습니다.

\documentclass[margin=5pt, tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[
trig format=rad, 
declare function={
a=7;    
b=-2;    
c=5;
Acos(\x)=(abs(\x)>1?inf:acos(max(-1,min(1,\x))));
f(\x)=Acos(a/\x)+Acos(b/\x)+Acos(c/\x)-pi;
m=max(a,b,c);
},
]
\begin{axis}[
axis lines=middle, 
samples=222,
xmin=-20, 
unbounded coords=jump,
]
%\addplot[blue, domain = m:20] {f(x)}; % works :)

\addplot[red, domain=-20:20] {f(x)}; % works :)
\end{axis}
\end{tikzpicture}
\end{document}

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

답변2

파라메트릭 플롯을 사용할 수 있습니다. 문제는 무한 f(-m)하지 f(m)않기 때문에 선이 보간된다는 것입니다.

\documentclass[margin=5pt, tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[
trig format=rad, 
declare function={
a=7;    
b=-2;    
c=5;
f(\x)=acos(a/\x)+acos(b/\x)+acos(c/\x)-pi;
m=max(a,b,c);
g(\t)=ifthenelse(\t>0,\t+m,\t-m);
}]
\begin{axis}[
variable=t, domain=-20:20, no markers,
axis lines=middle, 
samples=222,% overkill
xmin=-20, 
xmax=20,
unbounded coords=jump
]
\addplot[blue,coordinate] ({g(t)},{f(g(t))});
\end{axis}
\end{tikzpicture}
\end{document}

관련 정보