
Ich versuche, eine einfache Funktion darzustellen: y = sqrt(x+4)-2
:
\begin{tikzpicture}
\begin{axis}[
xlabel=$x$,
ylabel={$y$},
axis x line=center, axis y line=center
]
\addplot[domain=-5:5,
color=red] {sqrt(x+4)-2};
\end{axis}
\end{tikzpicture}
Ich bekomme:
Der minimale Y-Wert sollte bei x = -4 -2 sein, aber ich erhalte -1,5. Wie ist das? Danke!
Antwort1
- Die Definition
domain=-5:5
erfordert, dasspgfplots
darunter-4
komplexe Funktionen gezeichnet werden, was aber nicht möglich ist. Sinnvoll ist daher, dass die untere Domänengrenze bei liegt-4
. - Die Tangente zur Funktion
x=-4
ist orthogonal, daher ist die Standardanzahl der Stichproben zu klein, um einer Funktionsänderung zu folgen.
Die einfachste Lösung ist
\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel=$x$,
ylabel={$y$},
axis lines=center,
%samples=400% for more smuth curve
]
\addplot[domain=-4:5, color=red] {sqrt(x+4)-2};
\end{axis}
\end{tikzpicture}
\end{document}
was gibt
Antwort2
Sie benötigen keine große Anzahl von Stichproben, wenn Sie sich nur darüber im Klaren sind, dass das, was Sie zeichnen, eine umgedrehte Parabel ist.
\documentclass[margin=3pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel=$x$,
ylabel={$y$},
axis lines=center]
\addplot[domain=-2:1.5, color=red] ({(x+2)^2-4},{x});
\end{axis}
\end{tikzpicture}
\end{document}