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提供されたコマンドはコンパイルすらされないため、何を達成したいのか推測する必要がありました。PGFplots では、次のように分数を記述できます1/(x^2)

ジェイクの答えに対するマシューのコメントこの質問x=1キー を使用すると、に漸近線を描くことができますvasymptote=1。多くのサンプルを使用せずにプロットを確実に切り捨てるには (オレンジ色の曲線)、 が のdomain少し前で終了するようにを指定して、2 つの部分を別々にプロットします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)};

最初のものは実際の関数をプロットし、2 番目のものは座標を使用して垂直線を描画します。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}

関連情報