目前我正在尝试绘制 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。
我目前的图表:
最佳答案
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}]
关于graph - 如何输入函数以便正确绘制图形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47327849/