【问题标题】:How to input function so it can be graphed correctly如何输入函数以便正确绘制图形
【发布时间】:2018-04-29 21:13:58
【问题描述】:

目前我正在尝试绘制 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。

我现在的图表:

我希望的图表:

【问题讨论】:

    标签: graph wolfram-mathematica trigonometry taylor-series


    【解决方案1】:
    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}]
    

    或者,更实用的风格。

    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}]
    

    【讨论】:

    • 虽然这是一个很好的解决方案,但我正在寻找一种方法来将迭代器 n 包含在最终解决方案中,并试图避免使用 Apply 和 Plus(只想使用 Manipulate 和表和绘图子函数)。
    • 添加了Manipulate,并通过使用Sum避免了ApplyPlus
    【解决方案2】:

    我想你知道你可以使用内置的Series..

    Manipulate[m = n;
     Show[{
       Plot[Sin[x], {x, -10, 10}, PlotRange -> {-5, 5}, 
        PlotStyle -> {Thick, Red}],
       Plot[Evaluate[
         Accumulate[List @@ Normal@Series[Sin[x], {x, 0, m}]]], {x, -10, 10}]}],
        {{n, 3}, 3, 25, 2}]
    

    【讨论】:

      猜你喜欢
      • 2021-10-30
      • 2023-02-01
      • 2021-10-13
      • 1970-01-01
      • 2020-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-05
      相关资源
      最近更新 更多