在 LaTeX 中绘制大型函数

在 LaTeX 中绘制大型函数

我想使用该pgfplots包绘制一个具有相当大值的函数。该函数表示为(1375*(801-2.96*x)/(x*(18-0.1*x)

我目前拥有的代码是:

\begin{tikzpicture}
\begin{axis}[ xlabel={$x$}, ylabel={$C$}
,samples=200, grid, thick
,xmin=0, xmax=200, ymin=0, ymax=2000
,legend pos=outer north east
]
\addplot+[no marks] {(1375*(801-2.96*x)/(x*(18-0.1*x)};
\addlegendentry{$C(x)$} 
\end{axis}
\end{tikzpicture}

当我尝试呈现 PDF 时,它会生成一个错误:

"! Dimension too large.<recently read> \pgf@yy \end{axis}"

答案1

欢迎使用 TeX-SE!可以通过指定域并进行以下操作来消除此问题ymax 更大。(我还加了unbounded coords=jump。)

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ xlabel={$x$}, ylabel={$C$}
,samples=200, grid, thick,unbounded coords=jump,
,xmin=0,xmax=200, ymin=0,ymax=20000,
,legend pos=outer north east
]
\addplot+[no marks,domain=0:200] {(1375*(801-2.96*x)/(x*(18-0.1*x))};
\addlegendentry{$C(x)$} 
\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

甚至ymax=2300可以起作用,但这会删去大部分情节。

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ xlabel={$x$}, ylabel={$C$}
,samples=200, grid, thick,unbounded coords=jump,
,xmin=0,xmax=200, ymin=0,ymax=2300,
,legend pos=outer north east
]
\addplot+[no marks,domain=0:200] {(1375*(801-2.96*x)/(x*(18-0.1*x))};
\addlegendentry{$C(x)$} 
\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

您可以保留ymax使用restrict y to domain=0:2000,但效果不太好,因为一些延伸会被切掉。

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ xlabel={$x$}, ylabel={$C$}
,samples=501, grid, thick,unbounded coords=jump,
,xmin=0,xmax=200, ymin=0,ymax=2000,
,legend pos=outer north east
]
\addplot+[no marks,domain=0:200,restrict y to domain=0:2000] {(1375*(801-2.96*x)/(x*(18-0.1*x))};
\addlegendentry{$C(x)$} 
\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容