如何使用pspicture
绘制函数的绘制过程?y = a sin(bx)
我尝试了以下代码,但非常繁琐。a = 1,2,3,4
b = 1,2,3,4
-2π ≤ x ≤ 2π
\documentclass[a4paper]{article}
\usepackage{pstricks,amsmath,amssymb,pst-plot,pst-math}
\begin{document}
\begin{pspicture}(-5,-2)(5,5)
\psaxes(0,0)(-5,-2)(5,5)
\psplot[algebraic,plotpoints=200,linecolor=violet]{-6.28319}{6.28319}{sin(x)}
\psplot[algebraic,plotpoints=200,linecolor=blue]{-6.28319}{6.28319}{2*sin(x)}
\psplot[algebraic,plotpoints=200,linecolor=green]{-6.28319}{6.28319}{3*sin(x)}
\psplot[algebraic,plotpoints=200,linecolor=red]{-6.28319}{6.28319}{4*sin(x)}
\psplot[algebraic,plotpoints=200,linecolor=violet]{-6.28319}{6.28319}{sin(2*x)}
\psplot[algebraic,plotpoints=200,linecolor=blue]{-6.28319}{6.28319}{2*sin(2*x)}
\psplot[algebraic,plotpoints=200,linecolor=green]{-6.28319}{6.28319}{3*sin(2*x)}
\psplot[algebraic,plotpoints=200,linecolor=red]{-6.28319}{6.28319}{4*sin(2*x)}
\psplot[algebraic,plotpoints=200,linecolor=violet]{-6.28319}{6.28319}{sin(3*x)}
\psplot[algebraic,plotpoints=200,linecolor=blue]{-6.28319}{6.28319}{2*sin(3*x)}
\psplot[algebraic,plotpoints=200,linecolor=green]{-6.28319}{6.28319}{3*sin(3*x)}
\psplot[algebraic,plotpoints=200,linecolor=red]{-6.28319}{6.28319}{4*sin(3*x)}
\psplot[algebraic,plotpoints=200,linecolor=violet]{-6.28319}{6.28319}{sin(4*x)}
\psplot[algebraic,plotpoints=200,linecolor=blue]{-6.28319}{6.28319}{2*sin(4*x)}
\psplot[algebraic,plotpoints=200,linecolor=green]{-6.28319}{6.28319}{3*sin(4*x)}
\psplot[algebraic,plotpoints=200,linecolor=red]{-6.28319}{6.28319}{4*sin(4*x)}
\end{pspicture}
\end{document}
答案1
\documentclass[a4paper]{article}
\usepackage{pstricks,pst-plot,multido}
\begin{document}
\begin{pspicture}(-7,-4)(7,5)
\psaxes(0,0)(-6.5,-4)(6.5,5)
\psset{plotpoints=200,algebraic}
\multido{\iA=1+1}{4}{%
\psplot[linecolor=violet]{-6.28319}{6.28319}{sin(\iA*x)}%
\psplot[linecolor=blue]{-6.28319}{6.28319}{2*sin(\iA*x)}%
\psplot[linecolor=green]{-6.28319}{6.28319}{3*sin(\iA*x)}
\psplot[linecolor=red]{-6.28319}{6.28319}{4*sin(\iA*x)}}
\end{pspicture}
\end{document}
答案2
有TwoPi
(在 Postscript 中)和\psPiTwo
(在 TeX 中)来替换文字6.28319
。
\documentclass[pstricks]{standalone}
\usepackage{pst-plot,multido}
\psset{plotpoints=1000,algebraic}
\begin{document}
\begin{pspicture}(-6.5,-4.5)(6.5,4.5)
\psframe*(-6.5,-4.5)(6.5,4.5)
\multido{\iA=1+1}{4}{%
\psplot[linecolor=white]{TwoPi neg}{TwoPi}{sin(\iA*x)}
\psplot[linecolor=blue]{TwoPi neg}{TwoPi}{2*sin(\iA*x)}
\psplot[linecolor=green]{TwoPi neg}{TwoPi}{3*sin(\iA*x)}
\psplot[linecolor=red]{TwoPi neg}{TwoPi}{4*sin(\iA*x)}}
\color{lightgray}%
\psaxes[linecolor=lightgray](0,0)(-\psPiTwo,-4.2)(\psPiTwo,4.2)
\end{pspicture}
\end{document}