如何在 PSTricks 中写出 sinx 的泰勒级数?

如何在 PSTricks 中写出 sinx 的泰勒级数?
\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-plot,xfp}
\begin{document}

\begin{pspicture}[algebraic,plotpoints=500](-1,-3)(12,3)

\psclip{\psframe[fillstyle=solid,fillcolor=white,linestyle=none](-1,-2)(11,2)}
\psplot[linecolor=cyan]{0}{11}{sin(x)}
\psplot[linecolor=cyan!50!pink]{0}{3.2}{x-(x^3)/6} %n=3
\psplot[linecolor=cyan!50!yellow]{0}{4.3}{x-(x^3)/6+(x^5)/120} %n=5
\psplot[linecolor=cyan!50!red]{0}{4.3}{x-(x^3)/6+(x^5)/120-(x^7)/5040} % n=7
\psplot[linecolor=cyan!50!blue]{0}{5.75}{x-(x^3)/6+(x^5)/120-(x^7)/5040+(x^9)/362880} % n=9
\psplot[linecolor=green]{0}{6}{x-(x^3)/6+(x^5)/120-(x^7)/5040+(x^9)/362880-(x^11)/39916800} % n=11
\psplot[linecolor=orange]{0}{6.75}{x-(x^3)/6+(x^5)/120-(x^7)/5040+(x^9)/362880-(x^11)/39916800+(x^13)/6227020800} % n=13
\psplot[linecolor=pink]{0}{7.75}{x-(x^3)/6+(x^5)/120-(x^7)/5040+(x^9)/362880-(x^11)/39916800+%
    (x^13)/6227020800-(x^15)/\fpeval{fact(15)}} % n=15
\psplot[linecolor=blue]{0}{8.2}{x-(x^3)/6+(x^5)/120-(x^7)/5040+(x^9)/362880-(x^11)/39916800+%
    (x^13)/6227020800-(x^15)/\fpeval{fact(15)}+(x^17)/\fpeval{fact(17)}} % n=17
\psplot[linecolor=red]{0}{9.1}{x-(x^3)/6+(x^5)/120-(x^7)/5040+(x^9)/362880-(x^11)/39916800+%
    (x^13)/6227020800-(x^15)/\fpeval{fact(15)}+%
    (x^17)/\fpeval{fact(17)}-(x^19)/\fpeval{fact(19)}} % n=19
\psplot{0}{10.1}{x-(x^3)/6+(x^5)/120-(x^7)/5040+(x^9)/362880-(x^11)/39916800+%
    (x^13)/6227020800-(x^15)/\fpeval{fact(15)}+%
    (x^17)/\fpeval{fact(17)}-(x^19)/\fpeval{fact(19)}+(x^21)/\fpeval{fact(21)}} % n=21
\endpsclip
%%%
\uput[-90](3,-2){$n=3$}
\uput[-90](4.2,-2){$n=7$}
\uput[-90](6,-2){$n=11$}
\uput[-90](7.7,-2){$n=15$}
\uput[-90](9.2,-2){$n=19$}
\uput[-90](10.5,-1){$y=sin\,x$}
%%%
\uput[90](4,2){$n=5$}
\uput[90](5.3,2){$n=9$}
\uput[90](6.6,2){$n=13$}
\uput[90](8,2){$n=17$}
\uput[90](9.8,2){$n=21$}
%%
\psaxes[showorigin=false,arrowinset=.2,arrowsize=.2,%
        xsubticks=2,xsubticksize=1,ticksize=0 7pt,Dx=2]%
{->}(0,0)(-0.9,-2.5)(11,2.5)[$x$,-90][$y$,180]
        \end{pspicture}
\end{document}

在此处输入图片描述

如何在 PSTricks 中写出泰勒级数y=sinx

这意味着该\psplot命令只需写一次,如下所示:

\psRegisterList of color...
\definition of (1) (see image)
\multido{\iA=3+2}{10}{\psplot...}

在此处输入图片描述

答案1

我把简单的颜色设置留给你。用纯 PostScript 代码绘制函数要容易得多。然后建立一个和就很容易了:

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-plot,pst-tools}
\begin{document}

\begin{pspicture}[plotpoints=500](-1,-3)(12,3)
\psclip{\psframe[fillstyle=solid,fillcolor=white,linestyle=none](-1,-2)(11,2)}
\multido{\iA=1+1}{10}{%
  \psplot{0}{10}[/iA \iA\space def ]{
      /yVal x def  % value x^1/1!
      1 1 iA % i=1,...,n
        { /iter exch def % save loop variable (is on stack)
          iter dup add 1 add % 2n + 1 
          dup                % 2n+1 2n+1
          x exch             % 2n+1 x 2n+1
          exp                % 2n+1 x^(2n+1)
          exch               % x^(2n+1) 2n+1
          factorial div -1 iter exp mul 
          yVal add /yVal exch def } for
      yVal    
  }%
}
\psplot[algebraic]{0}{11}{sin(x)}
\endpsclip
    %%%
\uput[-90](3,-2){$n=3$}   \uput[-90](4.2,-2){$n=7$}
\uput[-90](6,-2){$n=11$}  \uput[-90](7.7,-2){$n=15$}
\uput[-90](9.2,-2){$n=19$}\uput[-90](10.5,-1){$y=\sin x$}
    %%%
\uput[90](4,2){$n=5$}     \uput[90](5.3,2){$n=9$}
\uput[90](6.6,2){$n=13$}  \uput[90](8,2){$n=17$}
\uput[90](9.8,2){$n=21$}    %%
\psaxes[showorigin=false,arrowinset=.2,arrowsize=.2,%
    xsubticks=2,xsubticksize=1,ticksize=0 7pt,Dx=2]%
    {->}(0,0)(-0.9,-2.5)(11,2.5)[$x$,-90][$y$,180]
\end{pspicture}
\end{document}

在此处输入图片描述

相关内容