我想将其写入\addplot
函数图形中,但总是出现错误,可能吗?
$f(x)=\frac{x^{2}+5}{x-1}$
\documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning,shapes,fit,calc}
\usepackage{pgfplots}
\pgfplotsset{compat = newest} % specify to the compiler that we are working with the
\begin{document}
\begin{tikzpicture}
\begin{axis}[]
\addplot[red, thick]{\frac{x^{2}+5}{x-1}};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
你尝试在绘图命令中使用 LaTeX 语法,但不起作用;请尝试
\documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning,shapes,fit,calc}
\usepackage{pgfplots}
\pgfplotsset{compat = newest} % specify to the compiler that we are working with the
\begin{document}
\begin{tikzpicture}
\begin{axis}[]
\addplot[smooth, samples=250, domain=-5:0.5, red, thick]{(x^2+5)/(x-1)};
\addplot[smooth, samples=250, domain=1.5:5, red, thick]{(x^2+5)/(x-1)};
\end{axis}
\end{tikzpicture}
\end{document}
产生
(由于您的函数在 1 处有一个极点,因此我在这里将图分成两部分。)