Mathematica 中的奇怪 Sin[x] 图

发布于 2024-10-10 12:19:28 字数 524 浏览 1 评论 0原文

我在 Mathematica 7 中随机绘制了一个 Sin[x] 函数,如下所示:

https://i.sstatic.net /hizGw.png

请注意大约 x = -100 处的可见缺陷。

这是缺陷部分的放大图,清楚地表明 Mathematica 由于某种原因在这些点之间使用了低得多的分辨率:

mesh

有人知道为什么会发生这种情况以及为什么只在 x = -100 时发生?

注意:同样的情况发生在 Wolfram Alpha< /a>,顺便说一下。

I randomly plotted a Sin[x] function in Mathematica 7 and this is what it shows:

https://i.sstatic.net/hizGw.png

Note the visible defect at approximately x = -100.

Here is a zoom of the defect part, clearly showing that Mathematica for some reason uses a much lower resolution between the points there:

mesh

Anybody know why this happens and why only at x = -100?

Note: same happens in Wolfram Alpha, by the way.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

相守太难 2024-10-17 12:19:28

简短答案:默认绘图精度不足以满足该函数的要求,因此请按如下方式增加它

Plot[Sin[x], {x, -42 Pi, 42 Pi}, PlotPoints -> 100]

长答案:Plot 的工作原理是在有限的点集上评估函数,并用直线连接这些点。您可以使用以下命令查看 Plot 使用的点

Plot[Sin[x], {x, -42 Pi, 42 Pi}, Mesh -> All, PlotStyle -> None, 
 MeshStyle -> Black]

情节

您可以看到,对于您的函数,计算函数的点“错过了峰值”并引入了较大的近似误差。用于选取点位置的算法非常简单,当两个峰的间距比 PlotRange/PlotPoints 更近时,可能会发生这种情况。

Plot 从 50 个等距点开始,然后在最多 MaxRecursion 阶段中插入额外的点。如果您针对 MaxRecursion 的各种设置绘制区域,您可以看到这个“洞”是如何出现的。

plot1 = Plot[Sin[x], {x, -42 Pi, 42 Pi}, PlotPoints -> 100, 
   PlotStyle -> LightGray];
Table[plot2 = 
   Plot[Sin[x], {x, -42 Pi, 42 Pi}, Mesh -> All, MeshStyle -> Thick, 
    PlotStyle -> Red, MaxRecursion -> k]; 
  Show[plot1, plot2, PlotRange -> {{-110, -90}, {-1, 1}}, 
   PlotLabel -> ("MaxRecursion " <> ToString[k])], {k, 0, 
   5}] // GraphicsColumn

情节

根据 Stan Wagon 的 Mathematica 书籍,如果两条新线段之间的角度超过 5 度,Plot 会决定是否在两个连续点之间添加一个额外的点。在这种情况下,绘图的初始点定位很不幸,并且细分不符合该标准。您可以看到,在孔的中心插入单个评估点将产生几乎相同的绘图。

增加角度的方法用于通过使用Refinement选项来决定何时细分(我从书上得到的,但产品中似乎没有记录)

plot1 = Plot[Sin[x], {x, -42 Pi, 42 Pi}, PlotPoints -> 100, 
   PlotStyle -> LightGray];
Show[plot1, 
 Plot[Sin[x], {x, -42 Pi, 42 Pi}, Mesh -> All, MeshStyle -> Thick, 
  PlotStyle -> Red, MaxRecursion -> 3, 
   Method -> {Refinement -> {ControlValue -> 4 \[Degree]}}], 
 PlotRange -> {{-110, -90}, {-1, 1}}]

在这里你可以看到增加它从默认值 5 起 1 度修复了该孔。

plot

Short answer: default plotting accuracy is not sufficient for that function, so increase it as follows

Plot[Sin[x], {x, -42 Pi, 42 Pi}, PlotPoints -> 100]

Long answer: Plot works by evaluating the function at a finite set of points, and connecting those points by straight lines. You can see the points used by Plot using the following command

Plot[Sin[x], {x, -42 Pi, 42 Pi}, Mesh -> All, PlotStyle -> None, 
 MeshStyle -> Black]

plot

You can see that for your function, the points where the function was evaluated "missed the peak" and introduced a large approximation error. The algorithm used to pick locations of points is very simple and this situation might happen when two peaks are spaced more closely together than PlotRange/PlotPoints.

Plot starts with 50 equally spaced points and then inserts extra points in up to MaxRecursion stages. You can see how this "hole" appears if you plot the region for various settings of MaxRecursion.

plot1 = Plot[Sin[x], {x, -42 Pi, 42 Pi}, PlotPoints -> 100, 
   PlotStyle -> LightGray];
Table[plot2 = 
   Plot[Sin[x], {x, -42 Pi, 42 Pi}, Mesh -> All, MeshStyle -> Thick, 
    PlotStyle -> Red, MaxRecursion -> k]; 
  Show[plot1, plot2, PlotRange -> {{-110, -90}, {-1, 1}}, 
   PlotLabel -> ("MaxRecursion " <> ToString[k])], {k, 0, 
   5}] // GraphicsColumn

plot

According to Stan Wagon's Mathematica book, Plot decides whether to add an extra point halfway between two consecutive points if the angle between two new line segments would be more than 5 degrees. In this case, plot got unlucky with initial point positioning and subdivision does not meet that criterion. You can see that inserting a single evaluation point in the center of the hole will produce almost identically looking plot.

The way to increase the angle used to decide when to subdivide by using Refinement option (I got it from the book, but it doesn't seem to be documented in product)

plot1 = Plot[Sin[x], {x, -42 Pi, 42 Pi}, PlotPoints -> 100, 
   PlotStyle -> LightGray];
Show[plot1, 
 Plot[Sin[x], {x, -42 Pi, 42 Pi}, Mesh -> All, MeshStyle -> Thick, 
  PlotStyle -> Red, MaxRecursion -> 3, 
   Method -> {Refinement -> {ControlValue -> 4 \[Degree]}}], 
 PlotRange -> {{-110, -90}, {-1, 1}}]

Here you can see that increasing it by 1 degree from default 5 fixes the hole.

plot

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文