Tikz: 윤곽선 gnuplot을 사용한 암시적 함수 플롯

Tikz: 윤곽선 gnuplot을 사용한 암시적 함수 플롯

암시적 함수를 플롯하려고 했습니다. "정의되지 않은 변수: 설정"이라는 동일한 오류 메시지가 계속 나타납니다.

미리 감사드립니다.

\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에 대한 수준 곡선을 나타내는 것이었습니다.

이 솔루션은 (주로 2차 방정식을 푸는) y함수로 산출되는 일부 계산을 기반으로 합니다 . x물론 에 대한 영역을 제공하는 긍정의 조건이 있습니다 x. 그림은 pgfplots가 아닌 TikZ를 기반으로 합니다. 명령이 작동하도록 하는 방법을 모르겠습니다 contour.

그려진 함수에는 이름이 지정 tmpM되고 tmpP소개됩니다. 함수 xLIni(즉, 왼쪽 구간의 초기 x) 에 의해 경계가 계산되는 두 구간의 합집합에 그려집니다 .

아래 코드에는 \a10으로 설정된 변수가 있습니다. 이는 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사용하는 것이 좋습니다 . 플롯할 함수는 다음과 같아야 합니다.gnuplotpgfplots수학 구문 에서는 대신에 를 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완전히 우회 할 수도 있습니다 . 등고선도 에 대한 자세한 내용은 다음을 참조하세요.gnuplotlualatexpgfplots매뉴얼pgfplots.

관련 정보