Mathematica 中的奇怪 Sin[x] 图
我在 Mathematica 7 中随机绘制了一个 Sin[x] 函数,如下所示:
请注意大约 x = -100
处的可见缺陷。
这是缺陷部分的放大图,清楚地表明 Mathematica 由于某种原因在这些点之间使用了低得多的分辨率:
有人知道为什么会发生这种情况以及为什么只在 x = -100
时发生?
注意:同样的情况发生在 Wolfram Alpha< /a>,顺便说一下。
I randomly plotted a Sin[x] function in Mathematica 7 and this is what it shows:
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:
Anybody know why this happens and why only at x = -100
?
Note: same happens in Wolfram Alpha, by the way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简短答案:默认绘图精度不足以满足该函数的要求,因此请按如下方式增加它
长答案:
Plot
的工作原理是在有限的点集上评估函数,并用直线连接这些点。您可以使用以下命令查看Plot
使用的点您可以看到,对于您的函数,计算函数的点“错过了峰值”并引入了较大的近似误差。用于选取点位置的算法非常简单,当两个峰的间距比 PlotRange/PlotPoints 更近时,可能会发生这种情况。
Plot
从 50 个等距点开始,然后在最多MaxRecursion
阶段中插入额外的点。如果您针对MaxRecursion
的各种设置绘制区域,您可以看到这个“洞”是如何出现的。根据 Stan Wagon 的 Mathematica 书籍,如果两条新线段之间的角度超过 5 度,
Plot
会决定是否在两个连续点之间添加一个额外的点。在这种情况下,绘图的初始点定位很不幸,并且细分不符合该标准。您可以看到,在孔的中心插入单个评估点将产生几乎相同的绘图。增加角度的方法用于通过使用
Refinement
选项来决定何时细分(我从书上得到的,但产品中似乎没有记录)在这里你可以看到增加它从默认值 5 起 1 度修复了该孔。
Short answer: default plotting accuracy is not sufficient for that function, so increase it as follows
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 byPlot
using the following commandYou 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 toMaxRecursion
stages. You can see how this "hole" appears if you plot the region for various settings ofMaxRecursion
.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)Here you can see that increasing it by 1 degree from default 5 fixes the hole.