pgfplots: 無限の値を持つ曲線を 1 つの addplot としてプロットする方法

pgfplots: 無限の値を持つ曲線を 1 つの addplot としてプロットする方法


acos(7/x)+acos(-2/x)+acos(5/x)-piプロットしたいですdomain=-20:20

私は自分自身に問いかける、これを次のようにプロットできるだろうか1つ曲線(異なるドメインを持つ 2 つの曲線としてではありません)。

だから私は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}

関連情報