我需要绘制 x、-x、x^2、-x^2、sin(1/x)、x*sin(1/x)、x^2*sin(1/x) 和 sin(1/x)。但包含 sin(1/x) 的函数看起来有点糟糕。我该如何修复它。我也不知道如何标记图形(在曲线 y=sin(1/x) 旁边写上 y=sin(1/x)。
\documentclass{article}
\usepackage{pstricks-add}
\usepackage{pst-func}
\begin{document}
\begin{pspicture}*(-5,-2)(5,2)
\SpecialCoor % For label positionning
\psaxes[labels=y,Dx=\pstPI2]{->}(0,0)(-5,-2)(5,2)
\uput[-90](!PI 0){$\pi$} \uput[-90](!PI neg 0){$-\pi$} 5 \uput[-90](!PI 2 div 0){$\frac{\pi}2$}
\uput[-90](!PI 2 div neg 0){$-\frac{\pi}2$}
\psplot[linewidth=1.5pt,linecolor=blue,algebraic]{-5}{5}{sin(1/x)}
\psplot[linewidth=1.5pt,linecolor=red,algebraic]{-5}{5}{x*sin(1/x)}
\psplot[linewidth=1.5pt,linecolor=green,algebraic]{-5}{5}{x^2*sin(1/x)}
\psplot[algebraic,linestyle=dashed]{-5}{5}{x}
\psplot[algebraic,linestyle=dashed]{-5}{5}{-x}
\psplot[algebraic,linestyle=dashed]{-5}{5}{x^2}
\psplot[algebraic,linestyle=dashed]{-5}{5}{-x^2}
\end{pspicture}
\end{document}
答案1
我认为使用当前工具不会获得更好的结果。以下所有函数始终使用相同的单位:
\documentclass[pstricks, margin=5pt]{standalone}
\usepackage{pstricks-add}
\begin{document}
\def\xLeft{-0.5} \def\xRight{0.5}
\psset{xunit=8,yunit=2}
\begin{pspicture}(\xLeft,-1.2)(0.55,1.3)
\psaxes[trigLabels,trigLabelBase=6,dx=2\pstRadUnit,subticks=4,ticksize=-2pt 2pt,
labelFontSize=\scriptstyle,Dy=0.5]{->}(0,0)(\xLeft,-1.1)(\xRight,1.2)
\psset{algebraic,linewidth=0.5\pslinewidth}
\psplot[linestyle=dashed]{\xLeft}{\xRight}{x}
\psplot[linestyle=dashed]{\xLeft}{\xRight}{-x}
\psplot[linestyle=dashed]{\xLeft}{\xRight}{x^2}
\psplot[linestyle=dashed]{\xLeft}{\xRight}{-x^2}
%
\psplot[linecolor=blue,plotpoints=500]{\xLeft}{-0.07}{sin(1/x)}
\psplot[linecolor=blue,VarStep,VarStepEpsilon=1.e-8]{-0.07}{-0.001}{sin(1/x)}
\psplot[linecolor=blue,VarStep,VarStepEpsilon=1.e-8]{0.001}{0.07}{sin(1/x)}
\psplot[linecolor=blue,plotpoints=500]{0.07}{\xRight}{sin(1/x)}
%
\psplot[linecolor=red,VarStep,VarStepEpsilon=1.e-9]{\xLeft}{\xRight}{x*sin(1/x)}
%
\psplot[linecolor=green,VarStep,VarStepEpsilon=1.e-9]{\xLeft}{\xRight}{x^2*sin(1/x)}
\end{pspicture}
\end{document}
如果您希望它与 Spivak 所得到的类似,那么对不同的曲线使用不同的单位(从数学角度来看这是错误的):
\documentclass[pstricks, margin=5pt]{standalone}
\usepackage{pst-plot}
\begin{document}
\def\xLeft{-0.5} \def\xRight{0.5}
\psset{xunit=8,yunit=2}
\begin{pspicture}(\xLeft,-1.2)(0.55,1.3)
\psaxes[labels=x,trigLabels,trigLabelBase=6,dx=2\pstRadUnit,subticks=4,ticksize=-2pt 2pt,
labelFontSize=\scriptstyle,Dy=0.5]{->}(0,0)(\xLeft,-1.1)(\xRight,1.2)
\psset{algebraic,linewidth=0.5\pslinewidth}
%
\psplot[linecolor=blue!50,VarStep,VarStepEpsilon=1.e-8]{\xLeft}{-0.01}{sin(1/x)}
\psplot[linecolor=blue!50,VarStep,VarStepEpsilon=1.e-8]{0.01}{\xRight}{sin(1/x)}
%
\psplot[yunit=3,linecolor=red,VarStep,VarStepEpsilon=1.e-9]{\xLeft}{\xRight}{x*sin(1/x)}
\psplot[yunit=3,linestyle=dashed]{\xLeft}{\xRight}{x}
\psplot[yunit=3,linestyle=dashed]{\xLeft}{\xRight}{-x}
%
\psplot[yunit=8,linecolor=green,VarStep,VarStepEpsilon=1.e-9]{\xLeft}{\xRight}{x^2*sin(1/x)}
%
\psplot[yunit=8,linestyle=dashed]{\xLeft}{\xRight}{x^2}
\psplot[yunit=8,linestyle=dashed]{\xLeft}{\xRight}{-x^2}
\end{pspicture}
\end{document}
答案2
为了正确绘制这些函数,您可以使用参数VarStep
。pstricks-add
文档甚至有一个绘图示例sin(1/x)
(第 24.4 节 x 的倒数的正弦)。
sin(1/x)
为了跳过 0,您必须分割情节:
\documentclass[pstricks, margin=5pt]{standalone}
\usepackage{pstricks-add}
\usepackage{pst-func}
\begin{document}
\begin{pspicture}*(-5,-2.2)(5,2)
\psaxes[labels=y,Dx=\pstPI2]{->}(0,0)(-5,-2)(5,2)
\uput[-90](!PI 0){$\pi$}\uput[-90](!PI neg 0){$-\pi$}\uput[-90](!PI 2 div 0){$\frac{\pi}2$}
\uput[-90](!PI 2 div neg 0){$-\frac{\pi}2$}
%
\psset{algebraic, VarStep, VarStepEpsilon=0.000001, linejoin=1}
%
\psplot[linestyle=dashed]{-5}{5}{x}
\psplot[linestyle=dashed]{-5}{5}{-x}
\psplot[linestyle=dashed]{-5}{5}{x^2}
\psplot[linestyle=dashed]{-5}{5}{-x^2}
%
\psplot[linecolor=blue]{-5}{-0.04}{sin(1/x)}
\psplot[linecolor=blue]{0.04}{5}{sin(1/x)}
%
\psplot[linecolor=red]{-5}{5}{x*sin(1/x)}
%
\psplot[linecolor=green]{-5}{5}{x^2*sin(1/x)}
\end{pspicture}
\end{document}
答案3
画出这些曲线是不可能的,因为它们无限振荡到零(事实上,它们是无法绘制的连续可微函数的典型例子)。我们能得到的最好结果是在不包含零的范围内的图形。
Spivak 的图很好地展示了函数的行为,但它们并不是精确的图形。此外,在同一幅图中表示所有这些函数非常复杂,因为这些曲线需要不同的尺度。
此外,重要的点不是 π 的有理倍数,而是它的倒数,例如 1/π(因为正弦函数的周期为 2π,所以函数 (x^n)\sin (1/x) 在区间 [1/(nπ),1/((n+2)π)] 内产生波浪)。
这是我的解决方案(新版本),使用我的包xpicture
。我们将在 [1/(nπ),1/((n+1)π)] 类型的区间中绘制函数。
此外,我们改变了轴之间的纵横比,因为波的高度很快就变为零。
\documentclass{standalone}
\usepackage{xpicture,ifthen}
\begin{document}
\COMPOSITIONfunction{\SINfunction}{\RECIPROCALfunction}{\F} % F(x)=sin(1/x)
\PRODUCTfunction{\IDENTITYfunction}{\F}{\G} % G(x)=x sin(1/x)
\PRODUCTfunction{\IDENTITYfunction}{\G}{\H} % H(x)=x^2sin(1/x)
% Command \grafic plots the three functions for x in [#1,#2]
\newcommand{\grafic}[2]{%
\pictcolor{blue}
\ifthenelse{\lengthtest{#1 pt > 0.064 pt}}{% the xpicture algorithm, applied to F(x)=sin x,
% fails for x<1/5\pi\approx 0.064
% because tangents are too vertical
\pictcolor{green}
\PlotFunction[12]\F{#1}{#2}
\PlotFunction[12]\F{-#2}{-#1}}{}
\pictcolor{blue}
\PlotFunction[12]\G{#1}{#2}
\PlotFunction[12]\G{-#2}{-#1}
\pictcolor{red}
\PlotFunction[12]\H{#1}{#2}
\PlotFunction[12]\H{-#2}{-#1}}
\setlength\unitlength{2cm}
\referencesystem(0,0)(5,0)(0,1) % Change aspect ratio to 5:1
\fbox{\begin{Picture}(-1.1,-1.1)(1.1,1.1)
\cartesianaxes(-1,-1)(1,1)
\linethickness{1pt}
\pictcolor{cyan}
\PlotFunction{\IDENTITYfunction}{-1}{1}
\pictcolor{gray}
\PlotFunction{\SQUAREfunction}{-1}{1}
{\changereferencesystem(0,0)(1,0)(0,-1) % This is a trick to draw -x and -x^2 without defining them.
\pictcolor{cyan}
\PlotFunction{\IDENTITYfunction}{-1}{1}
\pictcolor{gray}
\PlotFunction{\SQUAREfunction}{-1}{1}}
\newcounter{iteracio}
\setcounter{iteracio}{1}
\COPY1\maxim
\whiledo{\value{iteracio}<10}{% % Loop to print functions between 1,1/\pi,1/2\pi,...
\MULTIPLY{\value{iteracio}}\numberPI\minim
\DIVIDE1\minim\minim
\grafic{\minim}{\maxim}
\COPY\minim\maxim
\stepcounter{iteracio}}
% Add tics in x-axis at 1/\pi, 2/\pi
\DIVIDE{1}{\numberPI}{\inversePI}
\DIVIDE{1}{\numberHALFPI}{\twoinversePI}
\printxticlabel{\inversePI}{1/\pi}
\printxticlabel{\twoinversePI}{2/\pi}
\end{Picture}}
\end{document}