这是我目前的代码:
% Rest of document omitted brevity...
\subsection*{f(x) = cosec(x)}
\begin{tikzpicture}
\begin{axis}[every axis plot post/.append style={
mark=none,
domain=0:360,
samples=500,
smooth}, % All plots: 50 samples, smooth, no marks
axis x line=middle,
axis y line=center,
xmin=0,
xmax=360,
ymin=-1,
ymax=1,
enlargelimits=upper] % extend the axes a bit to the right and top
\addplot {1 / sin(x)};
\end{axis}
\end{tikzpicture}
% Rest of document omitted brevity...
这对我来说看起来是正确的,但是,当我尝试编译时,我得到:C:/Users/Todd/Dropbox/Homework/Notes/A-level_Maths/Core 3/Graphs/Graphs.tex:111: Dimension too large. [\end{axis}]
当我更改\addplot {1 / sin(x)};
文档时\addplot {sin(x)};
,编译没有任何问题。我做错了什么?
答案1
关于您要实现的目标的一些评论:
deg(x)
考虑通过-pgfplots 函数使用度作为三角函数的参数。- 使用后,应重新调整轴的定义
deg(x)
域和范围。x
- 不要忘记
\pgfplotsset{compat=1.7}
文档的序言。=) - 使用
cosec(x)
函数代替1 / sin(x)
。
最后我们得到(包括所有内容,包装在standalone
):
\documentclass{standalone}
\usepackage[english]{babel}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}
\begin{document}
\begin{tikzpicture}
\begin{axis}[every axis plot post/.append style={
mark=none,
domain=0:10,
samples=500,
smooth}, % All plots: 50 samples, smooth, no marks
axis x line=middle,
axis y line=center,
xmin=0,
xmax=10,
ymin=-10,
ymax=10,
enlargelimits=upper] % extend the axes a bit to the right and top
\addplot {cosec(deg(x))};
\end{axis}
\end{tikzpicture}
\end{document}
结果如下:
答案2
问题在于x=k*pi
,1/sin(x)
未定义(或者正如您的错误所暗示的“太大”,因为包以数字方式绘制它)。您可以使用以下方法解决此问题restrict y to domain
:
\begin{tikzpicture}
\begin{axis}[every axis plot post/.append style={
restrict y to domain=-10:10,
mark=none,
domain=-360:360,
samples=500,
smooth}, % All plots: 50 samples, smooth, no marks
axis x line=middle,
axis y line=center,
xmin=-360,
xmax=360,
ymin=-10,
ymax=10,
enlargelimits=upper] % extend the axes a bit to the right and top
\addplot {1/sin(x)};
\end{axis}
\end{tikzpicture}