pgfplots: So zeichnen Sie eine Kurve mit unendlichem Wert als ein Addplot

pgfplots: So zeichnen Sie eine Kurve mit unendlichem Wert als ein Addplot


acos(7/x)+acos(-2/x)+acos(5/x)-piIch möchte über plotten domain=-20:20.

Ich frage mich, ob ich das so darstellen kann,einsKurve(nicht als zwei Kurven mit unterschiedlichen Domänen).

Also wähle ich unbounded coords=jump(wieHier),
\addplot[red, domain=-20:20] {f(x)}; % works not :(
aber er gibt den Fehler! Missing number, treated as zero.

Gibt es eine Möglichkeit?

Bildbeschreibung hier eingeben

\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}

Antwort1

acosist nicht definiert, wenn der Absolutwert seines Arguments größer als 1 ist. Sie können eine „regularisierte“ Version definieren, die z. B. nachgibt, infwenn das Argument keinen Sinn ergibt.

\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}

Bildbeschreibung hier eingeben

Antwort2

Sie können ein parametrisches Diagramm verwenden. Das Problem besteht darin, dass f(-m)und f(m)NICHT unendlich sind, sodass die Linie interpoliert wird.

\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}

verwandte Informationen