graph - 如何输入函数以便正确绘制图形

标签 graph wolfram-mathematica trigonometry taylor-series

目前我正在尝试绘制 sin(x) 函数和一个名为 myPolys 的函数,该函数是 sin(x) 的泰勒多项式,因为它等于

myPolys = 
Table[Table[(-1)^((j - 1)/2) x^j/Factorial[j], {j, 1, h, 2}], {h, 1, 
      19, 2}];

如何使用操作来绘制两个函数的图表,以便绘制 myPolys 的每个部分的图表

到目前为止我的图形代码:

Manipulate[Plot[{Sin[x], myPolys[[n]]}, {x, -10, 10}, 
PlotRange -> {-5, 5}], {n, 1, Length[myPolys], 1}];

目前,对于 n 的每次迭代,myPolys 被绘制为单独的图表 x 然后 x & -(x^3)/3!然后是 x & -(x^3)/3! & x^5/5! (所有内容均在同一图表中单独绘制)

我想要实现的图表是,对于 n=1 sin(x) 应该绘制,并且应该绘制来自 myPoly 的 x,对于 n=2 它继续并绘制 x-(x^3/3!) (而不是分别绘制 n=2、x 和 -x^3/3!)依此类推,直到 n 达到 10。

我目前的图表:

enter image description here

我希望得到的图表: enter image description here

最佳答案

myPolys = Table[Sum[(-1)^((j - 1)/2) x^j/Factorial[j],
    {j, 1, h, 2}], {h, 1, 19, 2}];

Manipulate[Plot[{Sin[x], Evaluate@Take[myPolys, n]},
  {x, -10, 10}, PlotRange -> {-5, 5}], {n, 1, Length[myPolys], 1}]

enter image description here

或者,采用更实用的风格。

Clear[myPolys]

myPolys[n_] := Table[Sum[(-1)^((j - 1)/2) x^j/Factorial[j],
   {j, 1, h, 2}], {h, 1, 2 n - 1, 2}]

Manipulate[Plot[{Sin[x], Evaluate@myPolys[n]},
  {x, -10, 10}, PlotRange -> {-5, 5}], {n, 1, 10, 1}]

还有传说。

myLabels[n_] := Table[Sum[(-1)^((j - 1)/2) x^j/ToString[j] <> "!",
   {j, 1, h, 2}], {h, 1, 2 n - 1, 2}] 

Manipulate[Plot[{Sin[x], Evaluate@myPolys[n]},
  {x, -10, 10}, PlotRange -> {-5, 5},
  PlotLegends -> Placed[PointLegend[
     Rest@Array[ColorData[97], n + 1], HoldForm /@ myLabels[n],
     LegendMarkers -> {"\[Tilde]", 30}], Left]], {n, 1, 10, 1}]

enter image description here

关于graph - 如何输入函数以便正确绘制图形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47327849/

相关文章:

javascript - 通过 tan 从比率获得度数

graphics - 填充 Graphics3D 对象

python - 最小化循环迭代的多变量函数

javascript - 仅 vis graph2d y 轴整数

python - matplotlib:我可以使用辅助字体来丢失字形吗?

wolfram-mathematica - 如何在 Mathematica 中找到调色板?

c - C 中的三角函数

vhdl - 我的 VHDL 正弦函数生成器出了什么问题?

algorithm - 我们真的需要 Dijkstra 算法中顶点的 "visited or not"信息吗?

graph - 您如何找到与文档匹配的最具体的 "filter"? (确定用户适合的分割市场)