pgfplots를 사용하여 유리함수와 수직선 그래프 그리기

pgfplots를 사용하여 유리함수와 수직선 그래프 그리기

TikZ에게 유리함수에 대한 그래프를 그리도록 지시하는 코드를 원합니다 y=(x^{2}+5x+6)/(x^{2}+2x-3). 을 사용해 보았습니다 addplot[very thin,blue]{frac(x^{2}+5x+6)/(x^{2}+2x-3)}. 이 그래프에는 수직 점근선 x = 1이 있습니다. 화살촉이 있는 점선으로 이 선을 그리는 코드는 무엇입니까?

\documentclass[10pt]{amsart}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}


\begin{document}

\hspace*{\fill}
\begin{tikzpicture}
\begin{axis}[axis equal image,
          xmax=8,ymax=7,
          axis lines=middle,
          restrict y to domain=-7:7,
          enlargelimits={abs=1cm},
          axis line style={latex-latex},
          ticklabel style={fill=white},
          ytick=\empty,
          xtick={-3}
          %xlabel=$x$,ylabel=$y$,
]
\addplot[domain=-10:10,mark=none,samples=10] {frac{x + 2}{x - 1} node [above left, yshift=3pt]{$\scriptstyle{y}=\frac{x^{2}+5x+6}{x^{2}+2x-3}$};
\draw [fill=white] (-3,0) circle [radius=1.5pt];
\end{axis}
\end{tikzpicture}
\hspace{\fill}

\end{document}

답변1

내 버전의 PGFplots에서는 \addplot제공한 명령이 컴파일조차 되지 않으므로 달성하려는 목표를 추측해야 했습니다. PGFplot에서는 다음과 같이 분수를 작성할 수 있습니다 1/(x^2).

Jake의 답변에 대한 Matthew의 의견과 함께이 질문x=1키를 사용하여 점근선을 그릴 수 있습니다 vasymptote=1. 많은 샘플(주황색 곡선)을 사용하지 않고 플롯을 안정적으로 자르려면 두 부분을 별도로 플롯하여 domain약간 앞에서 끝나는 부분 x=1(검은색 곡선)을 지정하면 됩니다.

일부 곡선

\documentclass[10pt]{amsart}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}

\pgfplotsset{vasymptote/.style={
    before end axis/.append code={
        \draw[densely dashed] ({rel axis cs:0,0} -| {axis cs:#1,0})
        -- ({rel axis cs:0,1} -| {axis cs:#1,0});
    }
}}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    axis equal image,
    axis lines=middle,
    xmin=-10,xmax=10,
    ymin=-10,ymax=10,
    enlargelimits={abs=1cm},
    axis line style={latex-latex},
    ticklabel style={fill=white},
    ytick={-10,10},
    xtick={-3,-10,10},
    vasymptote=1,
]
% This doesn't clip to y=-10:10 nicely
% because there are too few samples near the asymptote:
\addplot[very thick, orange, domain=-10:10,samples=200, restrict y to domain=-10:10]
    {(x^2+5*x+6)/(x^2+2*x-3)};

% Draw the two parts separately with individual domains:
\addplot[samples=50,domain=-10:1-0.27] {(x^2+5*x+6)/(x^2+2*x-3)};
\addplot[samples=50,domain=1+0.33:10]  {(x^2+5*x+6)/(x^2+2*x-3)};

\draw [fill=white] (-3,0) circle [radius=1.5pt]; % What is this?
\end{axis}
\end{tikzpicture}
\end{document}

답변2

plotpoints=14*(2^n)+1Mark Wibrow의 솔루션은 (음수가 아닌 정수의 경우 ) 영구적인 재앙을 생성합니다 n.

따라서 이러한 문제를 극복하기 위해 다음 솔루션을 사용할 수 있습니다(그저 재미로).

\documentclass[pstricks,border=20pt,12pt]{standalone}
\usepackage{pst-plot}
\def\f{(x+2)/(x-1)}

\begin{document}
\begin{psgraph}[algebraic,plotpoints=1000,Dy=5,Dx=2]{->}(0,0)(-11,-30)(11,35){20cm}{20cm}
    \psset{linecolor=red}
    \psplot{-10}{0.9}{\f}
    \psplot{1.1}{10}{\f}
    \psset{linestyle=dashed,linecolor=blue}
    \psline(1,-30)(1,35)
    \psline(-11,1)(11,1)
\end{psgraph}
\end{document}

여기에 이미지 설명을 입력하세요

답변3

재미로 PSTricks를 사용해보세요 :O

\documentclass[pstricks,border=5]{standalone}
\usepackage{pst-plot}
\begin{document}
\psset{xunit=20pt,yunit=20pt}
\begin{pspicture}*(-7.5,-7.5)(7.5,7.5)
  \psgrid[gridlabels=0,gridcolor=gray!25,subgridcolor=gray!10](-7,-7)(7,7)
  \psaxes[labels=none,ticksize=-2pt 2pt]{<->}(0,0)(-7,-7)(7,7)[$x$,-90][$y$,0]
  \psplot[linecolor=blue,plotstyle=line,algebraic, yMaxValue=7,plotpoints=1000]
      {-7}{7}{(x^2+5*x+6)/(x^2+2*x-3)} 
  \psline[linestyle=dashed](1,-7)(1,7)
  \rput(4.5,4){$\displaystyle f(x)=\frac{x^2+5x+6}{x^2+2x-3}$}
\end{pspicture}
\end{document} 

여기에 이미지 설명을 입력하세요

답변4

필요한 것은 몇 가지 addplot 명령뿐입니다.

  \addplot[domain=-10:10,samples=1000]
  {(x^2+5*x+6)/(x^2+2*x-3)};
  \addplot[dashed, purple, latex-latex]
  coordinates{(1,-6) (1,6)};

첫 번째는 실제 함수를 그려야 하고, 두 번째는 좌표를 사용하여 수직선을 그립니다. 이 옵션은 양쪽 끝에 화살촉을 latex-latex추가합니다 . latex양쪽 끝에 화살촉을 원하지 않으면 적절한 latex. 수직선을 더 길게 하려면 좌표에서 -6과 6을 더 큰 값으로 바꾸십시오. -15와 15.

전체 예는 다음과 같습니다.

\begin{tikzpicture}
\begin{axis}[axis equal image,
          xmin=-8, xmax=8,
          ymin=-7, ymax=7,
          axis lines=middle,
          restrict y to domain=-10:10,
          enlargelimits={abs=1cm},
          axis line style={-latex},
          ytick=\empty,
          xtick={-3},
          %xlabel=$x$,ylabel=$y$,
  ]
  \addplot[domain=-10:10,samples=1000]
  {(x^2+5*x+6)/(x^2+2*x-3)};
  \addplot[dashed, purple, latex-latex]
  coordinates{(1,-6) (1,6)};
\end{axis}
\end{tikzpicture}

관련 정보