사인파 PGF 플롯 위에 톱니파 파형 그리기

사인파 PGF 플롯 위에 톱니파 파형 그리기

아래 이미지와 같이 톱니파 형태를 위에 배치하려고 하는 완전히 정류된 정현파가 있습니다.

여기에 이미지 설명을 입력하세요

원래는 지저분한 솔루션이 있었지만 별로 좋지 않았습니다. 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까지 이어지는 톱니파가 발생함 ).01

\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}

관련 정보