
完全に整流された正弦波があり、その上に下の画像のように鋸歯状波形を配置しようとしています。
最初は乱雑な解決策を考えていましたが、あまり良くありませんでした。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
これは、ループを鋸歯状波形の直線近似で使用する場合の 1 つの解決策です。
線が正弦波に侵入せずに曲線に接するようにしたい場合は、垂直線を削除し、\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}