
Ich habe versucht, eine implizite Funktion zu zeichnen. Ich erhalte immer dieselbe Fehlermeldung: „Undefinierte Variable: festgelegt“.
Dank im Voraus.
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{pgfplots.fillbetween}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title={Implicit Function Plot},
xlabel={$x$},
ylabel={$y$},
xmin=0, xmax=50,
ymin=0, ymax=50,
view={0}{90}, %
]
\addplot3[
thick,
contour gnuplot={levels={0}, labels=false}, % Adjust 'levels' as needed
samples=50, % Increase for higher resolution
samples y=50, % Explicitly defining samples y for clarity
domain=0:50,
domain y=0:50,
]
gnuplot {
set contour base;
set cntrparam levels discrete 0;
unset surface;
set view map;
splot -1/2*(x+y)**(-1/2)*x + 100 - (x+y)**(1/2) - 2*x;
};
\end{axis}
\end{tikzpicture}
\end{document}
Antwort1
In der Abbildung sehen wir die Niveaukurve für die Funktion, f(x, y) = x/(2\sqrt{x +y}) +\sqrt{x +y} +2x
die dem Wert 20 entspricht. Beachten Sie, dass das Ziel des Fragestellers darin bestand, die Niveaukurve für 100 darzustellen.
Die Lösung basiert auf einigen Berechnungen, die y
als Funktion von ergeben x
(hauptsächlich das Lösen quadratischer Gleichungen). Natürlich gibt es eine Positivitätsbedingung, die die Domäne für angibt x
. Die Zeichnung basiert auf TikZ und nicht auf pgfplots. Ich weiß nicht, wie ich den Befehl zum Laufen bringe contour
.
Die gezeichneten Funktionen werden benannt tmpM
und tmpP
als solche eingeführt; sie werden auf der Vereinigungsstelle zweier Intervalle gezeichnet, deren Grenzen durch die Funktionen berechnet werden xLIni
(d. h. das anfängliche x des linken Intervalls), ...
Im untenstehenden Code gibt es eine Variable \a
, die auf 10 gesetzt ist; das entspricht dem Wert 2*\a
für die Niveaukurve.
Anmerkung.Da die Zahlen sehr schnell zu groß werden, müssen die Einheiten global angepasst werden (siehe [x=6.7pt, y=.1pt]
).
Der Code
\documentclass[11pt, margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{math}
\begin{document}
\tikzmath{%
function xLIni(\c) {%
return {\c -2*\c};
};
function xLEnd(\c) {%
return {(2*\c +1/2 -pow(2*\c +1/4, .5))/2};
};
function xRIni(\c) {%
return {(2*\c +1/2 +pow(2*\c +1/4, .5))/2};
};
function xREnd(\c) {%
return {\c +2*\c};
};
function tmpM(\t, \c) {%
\tmp = (\t -\c)*(\t -\c) -\t/2;
return {2*\tmp -\t/2 -2*(\t -\c)*pow(\tmp, .5)};
};
function tmpP(\t, \c) {%
\tmp = (\t -\c)*(\t -\c) -\t/2;
return {2*\tmp -\t/2 +2*(\t -\c)*pow(\tmp, .5)};
};
}
\begin{tikzpicture}[x=6.7pt, y=.1pt,
evaluate={\a = 10; \b = int(\a*\a); \cst = int(2*\a);}]
\draw[->] ({xLIni(\a) -1}, 0) -- ({xREnd(\a) +1}, 0) node[above] {$x$};
\draw[->] (0, -.2) -- (0, {1.7*xREnd(\a)*xREnd(\a)}) node[left] {$y$};
\draw (\a, 0) -- +(0, 20) -- +(0, -20) node[below] {$\a$};
\draw (0, \b) -- +(.3, 0) -- +(-.3, 0) node[left] {$\b$};
\begin{scope}[every path/.style={%
blue, very thick, variable=\t, samples=100
}]
\draw[domain={xLIni(\a)}:{xLEnd(\a)}] plot (\t, {tmpM(\t, \a)});
\draw[domain={xLIni(\a)}:{xLEnd(\a)}] plot (\t, {tmpP(\t, \a)});
\draw[domain={xRIni(\a)+.05}:{xREnd(\a)}] plot (\t, {tmpP(\t, \a)});
\draw[domain={xRIni(\a)+.05}:{xREnd(\a)}] plot (\t, {tmpM(\t, \a)});
\end{scope}
\end{tikzpicture}
\end{document}
Antwort2
Möchte man die gnuplot
set
Syntax nutzen, muss man diese mit der raw gnuplot
Option aufrufen.
Sofern Sie raw nicht wirklich gnuplot
für Dinge benötigen, die von nicht unterstützt werden pgfplots
, empfehle ich die Verwendung gnuplot
von innerhalb pgfplots
, wie unten gezeigt. Beachten Sie, dass die darzustellende Funktionin der pgfplots
mathematischen Syntax, d. h. Sie müssen ^
anstelle von verwenden **
.
BEARBEITEN: Gnuplot muss write18
(externe Befehle) aktivieren. Kompilieren mit pdflatex --shell-escape file.tex
.
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{pgfplots.fillbetween}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title={Implicit Function Plot},
xlabel={$x$},
ylabel={$y$},
xmin=0, xmax=50,
ymin=0, ymax=50,
view={0}{90}, %
]
\addplot3[
thick,
contour gnuplot={levels={0,10,20,30}, labels=false},
samples=100,
samples y=100,
domain=0:50,
domain y=0:50,
]{-1/2*(x+y)^(-1/2)*x + 100 - (x+y)^(1/2) - 2*x};
\end{axis}
\end{tikzpicture}
\end{document}
Sie können auch verwenden, contour lua
um die Kompilierung vollständig zu umgehen und gnuplot
stattdessen die Funktion zu verwenden lualatex
. Weitere Einzelheiten zu pgfplots
Konturdiagrammen finden Sie unterdas pgfplots
Handbuch.