如何在 pstricks 中创建两个任意函数的动画卷积这
答案1
XeLaTeX
包中的 Javascript可能存在问题animate
。在这种情况下使用latex->dvips->ps2pdf
\documentclass{article}
\usepackage{pst-plot,animate}
\begin{document}
\begin{animateinline}[controls,autoplay,
begin={\psset{unit=2}\begin{pspicture*}(-2.2,-0.5)(2.2,5.5)},
end={\end{pspicture*}}]{8}
% % Generate frames for -2 ... 2
\multiframe{40}{rA=-2.0+0.1}{%
\rput(0,3){%
\psaxes[Dy=0.5,dy=0.5,ticksize=-4pt 0,subticks=5](0,0)(-2,0)(2,1)[$\tau$,0][$f$,90]
\psline[linecolor=red,linewidth=1pt](-0.5,0)(-0.5,1)(0.5,1)(0.5,0)
\psline[linecolor=green,linewidth=1pt,strokeopacity=0.5]%
(!\rA\space -0.5 add 0)(!\rA\space -0.5 add 1)(!\rA\space 0.5 add 1)(!\rA\space 0.5 add 0)%
}%
\ifdim\rA pt>-1pt
\psplot[linecolor=blue]{-1}{\rA\space dup 1 gt {pop 1} if}{x dup 0 gt { neg } if 1 add }
\fi
\psline[linecolor=green,linestyle=dashed](\rA,0)(\rA,4.5)
\psaxes[Dy=0.5,dy=0.5,ticksize=-4pt 0,subticks=5](0,0)(-2,0)(2,1)[$t$,0][,0]
\rput(0,2){$\displaystyle f*g=\int\limits_{-\infty}^{\infty} f(\tau)g(t-\tau)\mathrm{d}\tau$}
}
\end{animateinline}
\end{document}
如果你想使用\psConv
然后替换
\ifdim\rA pt>-1pt
\psplot[linecolor=blue]{-1}{\rA\space dup 1 gt {pop 1} if}{x dup 0 gt { neg } if 1 add }
\fi
和
\psConv[plotpoints=100,Simpson=1000,linecolor=red]{-2}{\rA}(-10,10)%
{abs 0.5 le {1} {0} ifelse}{abs 0.5 le {1} {0} ifelse}%
当然,还要加载包pst-func
。我将 pdf 转换为 gif,使用了:
convert -delay 50 -loop 0 -density 300 -scale 300 -alpha remove <file>.pdf <file>.gif