在 Mathematica 中,ListPlot 使用什么插值函数?

发布于 2024-09-26 04:20:45 字数 1159 浏览 7 评论 0原文

[下面的屏幕截图]

我使用 ListPlot 通过一些数据点绘制一条平滑的线。但我希望能够处理绘图的一阶和二阶导数,所以我想我应该使用插值创建一个实际的“函数”。但正如你在图片中看到的那样,它并不顺利。当我做 Plot[Interpolation[...]...] 时,出现一些奇怪的尖峰。我想知道 ListPlot 如何获得它的插值函数,以及如何使用 Interpolation[] 或其他方法获得相同的东西。

谢谢,
Rob

这是一些用于复制/粘贴的文本:

myPoints = {{0.,3.87},{1.21,4.05},{2.6,4.25},{4.62,4.48},{7.24,4.73},{9.66,4.93},
{12.48,5.14},{14.87,5.33},{17.34,5.55},{19.31,5.78},{20.78,6.01},{22.08,6.34},
{22.82,6.7},{23.2,7.06},{23.41,7.54},{23.52,8.78},{23.59,9.59},{23.62,9.93},
{23.72,10.24},{23.88,10.56},{24.14,10.85},{24.46,11.05},{24.81,11.2},
{25.73,11.44},{27.15,11.63}}

ListPlot[myPoints, Joined -> True, Mesh -> Full] 

Plot[Interpolation[myPoints][x], {x, 0, 27.2}] 

最后一个有尖峰。

编辑...

Gleno pointed out that my List plot is linear.  But what about when both have 
InterpolationOrder -> 3?
ListPlot[myPoints, Joined -> True, Mesh -> Full, InterpolationOrder -> 3]
Plot[Interpolation[myPoints, InterpolationOrder -> 3][x], {x, 0, 27.2}]

Mathematica ListPlot 屏幕截图

[Screenshot below]

I was using ListPlot to draw a smooth line through some data points. But I want to be able to work with the 1st and 2nd derivative of the plot, so I thought I'd create an actual "function" using Interpolation. But as you can see in the picture, it's not smooth. There are some strange spikes when I do Plot[Interpolation[...]...]. I'm wondering how ListPlot get's it's interpolated function, and how I can get the same thing, using Interpolation[] or some other method.

thanks,
Rob

Here is some text for copy/paste:

myPoints = {{0.,3.87},{1.21,4.05},{2.6,4.25},{4.62,4.48},{7.24,4.73},{9.66,4.93},
{12.48,5.14},{14.87,5.33},{17.34,5.55},{19.31,5.78},{20.78,6.01},{22.08,6.34},
{22.82,6.7},{23.2,7.06},{23.41,7.54},{23.52,8.78},{23.59,9.59},{23.62,9.93},
{23.72,10.24},{23.88,10.56},{24.14,10.85},{24.46,11.05},{24.81,11.2},
{25.73,11.44},{27.15,11.63}}

ListPlot[myPoints, Joined -> True, Mesh -> Full] 

Plot[Interpolation[myPoints][x], {x, 0, 27.2}] 

The last one has spikes.

Edit...

Gleno pointed out that my List plot is linear.  But what about when both have 
InterpolationOrder -> 3?
ListPlot[myPoints, Joined -> True, Mesh -> Full, InterpolationOrder -> 3]
Plot[Interpolation[myPoints, InterpolationOrder -> 3][x], {x, 0, 27.2}]

Mathematica ListPlot Screenshot

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

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

发布评论

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

评论(3

夏夜暖风 2024-10-03 04:20:45

也许更容易:

interp = Interpolation[myPoints, InterpolationOrder -> 2, Method -> "Spline"]

(*Now let's plot the function and its derivative*)
Show[ListPlot@myPoints, 
     Plot[{interp'[x], interp[x]}, 
          {x, Min[First /@ myPoints], Max[First /@ myPoints]}, PlotRange -> All]]

在此处输入图像描述

在“感兴趣区域”中:

Show[Plot[{interp'[x], interp[x]}, {x, 23, 24}], ListPlot@myPoints]

在此处输入图像描述

如果您想要连续的二阶导数,只需增加插值阶数,如下所示:

interp = Interpolation[myPoints, InterpolationOrder -> 3, Method -> "Spline"];
Show[Plot[{interp'[x], interp[x]}, {x, 23, 24}], ListPlot@myPoints]

在此处输入图像描述

Perhaps easier:

interp = Interpolation[myPoints, InterpolationOrder -> 2, Method -> "Spline"]

(*Now let's plot the function and its derivative*)
Show[ListPlot@myPoints, 
     Plot[{interp'[x], interp[x]}, 
          {x, Min[First /@ myPoints], Max[First /@ myPoints]}, PlotRange -> All]]

enter image description here

In the "region of interest":

Show[Plot[{interp'[x], interp[x]}, {x, 23, 24}], ListPlot@myPoints]

enter image description here

If you want a continuous second derivative, just increase the interpolation order like this:

interp = Interpolation[myPoints, InterpolationOrder -> 3, Method -> "Spline"];
Show[Plot[{interp'[x], interp[x]}, {x, 23, 24}], ListPlot@myPoints]

enter image description here

少女七分熟 2024-10-03 04:20:45

我相信ListPlot用于插值的方法是将每个坐标作为列表索引的函数进行插值。类似下面的内容看起来很像 ListPlot[...,InterpolationOrder->3] 的输出:

With[{
  xyInterpolation=Interpolation[#,InterpolationOrder->3]&/@Transpose[myPoints]},
  ParametricPlot[Through[xyInterpolation[i]],{i,1,Length[myPoints]}]
]

从这样的插值中,您应该能够通过隐式微分获取导数,例如 dx/ dy == (dx/dt)/(dy/dt)。很高兴在一个可能会让一些数学家呕吐的地方炫耀这个符号:)

I believe that the method used by ListPlot for interpolation is to interpolate each coordinate as a function of the list index. Something like the following looks a lot like the output from ListPlot[...,InterpolationOrder->3]:

With[{
  xyInterpolation=Interpolation[#,InterpolationOrder->3]&/@Transpose[myPoints]},
  ParametricPlot[Through[xyInterpolation[i]],{i,1,Length[myPoints]}]
]

From such an interpolation you should be able to grab your derivatives via implicit differentiation, e.g. dx/dy == (dx/dt)/(dy/dt). A delight to flaunt that notation in a place where it might make some mathematicians puke :)

jJeQQOZ5 2024-10-03 04:20:45

很抱歉让您失望,但答案很简单。 ListLinePlot / ListPlot 只是绘制一条直线

Plot[Interpolation[myPoints, InterpolationOrder -> 1][x], {x, 0, 27.2}]

Mathematicagraphics

产生同样的不hacky线路。应用二阶插值和使用样条曲线也可能取得不同程度的成功。

Plot[Interpolation[myPoints, InterpolationOrder -> 2, Method -> "Spline"][x], {x, 0, 27.2}]

Mathematica 图形

Sorry to dissapoint you, but the answer is very simple. ListLinePlot / ListPlot just draws a straight line

Plot[Interpolation[myPoints, InterpolationOrder -> 1][x], {x, 0, 27.2}]

Mathematica graphics

produces the same un-hacky line. You may also have varying deress of success applying second order interpolation and using Splines.

Plot[Interpolation[myPoints, InterpolationOrder -> 2, Method -> "Spline"][x], {x, 0, 27.2}]

Mathematica graphics

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