我正在尝试绘制此函数,但它应该在每个 k*pi 上趋于无穷大,但它甚至不像正确的图。我做错了什么吗?
\begin{tikzpicture}
\begin{axis}[
axis lines = center,
xmin=-2*pi,xmax=2*pi,
xlabel = $x$,
ylabel = {$g(x)$},
xtick={0,1.57,3.14,4.71,6.28,-1.57,-3.14,-4.71,-6.28},
xticklabels={$0$, $\frac{\pi}{2}$,$\pi$,$\frac{3}{2}\pi$,$2\pi$, $-\frac{\pi}{2}$,$-\pi$,$-\frac{3}{2}\pi$,$-2\pi$},
]
\addplot [
domain=-10:10,
samples=100,
color=red,
]
{abs(((sin(deg(x+(pi/4))^2)/(cos(deg((x+(pi)/2)))))};
\end{axis}
\end{tikzpicture}
它应该是这样的
答案1
欢迎!括号设置得有点不妥,我添加了unbounded coords=jump
,还调整了域以适应xmin
和max
。结果看起来像目标屏幕截图。
\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines = center,
xmin=-2*pi,xmax=2*pi,
xlabel = $x$,
ylabel = {$g(x)$},
xtick={0,1.57,3.14,4.71,6.28,-1.57,-3.14,-4.71,-6.28},
xticklabels={$0$, $\frac{\pi}{2}$,$\pi$,$\frac{3}{2}\pi$,$2\pi$, $-\frac{\pi}{2}$,$-\pi$,$-\frac{3}{2}\pi$,$-2\pi$},
unbounded coords=jump,ymax=5
]
\addplot [
domain=-2*pi:2*pi,
samples=221,
color=red,
]
{abs(pow(sin(deg(x+pi/4)),2)/(cos(deg(x+pi/2))))};
\end{axis}
\end{tikzpicture}
\end{document}
还请注意,此处发布的代码预计以 开头\documentclass
并以 结尾\end{document}
。
或者使用从-10
到的域名10
。
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines = center,
xmin=-10,xmax=10,
xlabel = $x$,
ylabel = {$g(x)$},
xtick={0,1.57,3.14,4.71,6.28,-1.57,-3.14,-4.71,-6.28},
xticklabels={$0$, $\frac{\pi}{2}$,$\pi$,$\frac{3}{2}\pi$,$2\pi$, $-\frac{\pi}{2}$,$-\pi$,$-\frac{3}{2}\pi$,$-2\pi$},
unbounded coords=jump,ymax=5
]
\addplot [
domain=\pgfkeysvalueof{/pgfplots/xmin}:\pgfkeysvalueof{/pgfplots/xmax},
samples=401,
color=red,
]
{abs(pow(sin(deg(x+pi/4)),2)/(cos(deg(x+pi/2))))};
\end{axis}
\end{tikzpicture}
\end{document}
请注意,在选择时必须小心谨慎samples
。