
我有一個完全整流的正弦波,我試圖在其上放置鋸齒波形式,如下圖所示,
我最初有一個混亂的解決方案,但它不是很好,我有一個 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}