
暗黙の関数をプロットしようとしました。同じエラー メッセージが繰り返し表示されます: 「未定義の変数: 設定」。
前もって感謝します。
\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}
答え1
図では、f(x, y) = x/(2\sqrt{x +y}) +\sqrt{x +y} +2x
値 20 に対応する関数のレベル曲線を見ることができます。質問者の目標は、100 のレベル曲線を表すことであったことに注意してください。
解は、y
の関数として得られる計算に基づいていますx
(主に二次方程式を解く)。もちろん、 のドメインを与える正の条件がありますx
。図は、pgfplots ではなく、TikZ に基づいています。コマンドを機能させる方法がわかりませんcontour
。
描画される関数は、 およびtmpM
と名付けられtmpP
、そのように導入されます。関数によって境界が計算される 2 つの区間の和集合上に描画されますxLIni
(つまり、左区間の初期 x)。
以下のコードには、レベル カーブの\a
値に対応する 10 に設定された変数があります。2*\a
述べる。関係する数値はすぐに大きくなりすぎます。このため、単位はグローバルに変更する必要があります (を参照[x=6.7pt, y=.1pt]
)。
コード
\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}
答え2
構文を使用する場合はgnuplot
set
、オプションを使用して呼び出す必要がありますraw gnuplot
。
gnuplot
でサポートされていないことをするためにraw が本当に必要な場合を除き、以下に示すように から をpgfplots
使用することをお勧めします。プロットする関数はgnuplot
pgfplots
数式構文ではpgfplots
、^
の代わりにを使用する必要があります**
。
編集: Gnuplot ではwrite18
(外部コマンド) を有効にする必要があります。 を使用してコンパイルします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}
を使ってコンパイルcontour lua
を完全にバイパスすることもできます。等高線図の詳細については、gnuplot
lualatex
pgfplots
マニュアルpgfplots
。