我有一个完全整流的正弦波,我试图在其上放置一个锯齿波,如下图所示,
我最初有一个混乱的解决方案,但它不是很好,我有一个 tex 正弦波,我试图将它放在下面。
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
domain=0:1.5*360,
samples=4*360,
xtick=\empty,
width=10cm, height=4cm,
ymin=0,
enlarge x limits=false
]
\addplot [densely dashed] {abs(sin(x))};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
您可以使用1 - 1/(3*180)*mod(x+90,180)
绘制锯齿波。mod(x,180)
重复每个180
单位,1/(3*180)
缩放值(将导致从到的1/180
锯齿波)。0
1
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
domain=0:1.5*360,
samples=4*360,
xtick=\empty,
width=10cm, height=4cm,
ymin=0,
enlarge x limits=false
]
\addplot [densely dashed] {abs(sin(x))};
\addplot [very thick] {1-1/(3*180)*mod(x+90,180)};
\end{axis}
\end{tikzpicture}
\end{document}
答案2
这是一种可能的解决方案,其中foreach
循环与锯齿波形的线近似一起使用。
如果希望线与曲线接触而不穿透正弦波,则删除垂直线并将\arch
定义更改为 60
代码
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\def\arch{90}
\begin{tikzpicture}
\begin{axis}[
domain=0:1.5*360,
samples=360,
xtick={0,90,180,270,360,450,540},
width=10cm, height=5cm,
ymin=0, ymax=1.5, xmin=0,
enlarge x limits=false
]
\addplot [densely dashed] {abs(sin(x))};
% draw the rectified line approximation via foreach skill
\foreach \i/\j in {-1/0,1/2,3/4}{
\addplot [thick,domain=\i*90:{\j*90+\arch}]
{1-0.001*(x-\i*90)};
\addplot[thick] coordinates{(\i*90,1)(\i*90,{1-0.001*(\j*90+\arch-\i*90)})}; % remove this line if the vertical line is undesired and change arch to 90
}
\node[coordinate, pin =above:{\parbox{2cm}{\tiny Voltage Simplified by Approximation}}] at (axis cs: 180,0.9) {};
\end{axis}
\end{tikzpicture}
\end{document}