从图中识别 Mathematica 插值函数(不是 Hermite)
我正在对 Mathematica 如何进行列表插值进行逆向工程:
(* Fortunately, Mathematica WILL interpolate an arbitrary list *)
tab = Table[a[i], {i,1,100}]
f = Interpolation[tab]
(* get the coefficient of each term by setting others to zero *)
Plot[{f[42+x] /. {a[42] -> 0, a[43] ->0, a[44] -> 0, a[41] -> 1}},
{x,0,1}]
Plot[{f[42+x] /. {a[41] -> 0, a[43] ->0, a[44] -> 0, a[42] -> 1}},
{x,0,1}]
Plot[{f[42+x] /. {a[42] -> 0, a[41] ->0, a[44] -> 0, a[43] -> 1}},
{x,0,1}]
Plot[{f[42+x] /. {a[42] -> 0, a[43] ->0, a[41] -> 0, a[44] -> 1}},
{x,0,1}]
(* above is neither Hermite, nor linear, though some look close *)
(* these are available at oneoff.barrycarter.info/STACK/ *)
Table[f[42+x] /. {a[42] -> 0, a[43] ->0, a[44] -> 0, a[41] -> 1},
{x,0,1, 1/100}] >> /home/barrycarter/BCINFO/ONEOFF/STACK/coeff41.txt
Table[f[42+x] /. {a[41] -> 0, a[43] ->0, a[44] -> 0, a[42] -> 1},
{x,0,1, 1/100}] >> /home/barrycarter/BCINFO/ONEOFF/STACK/coeff42.txt
Table[f[42+x] /. {a[41] -> 0, a[42] ->0, a[44] -> 0, a[43] -> 1},
{x,0,1, 1/100}] >> /home/barrycarter/BCINFO/ONEOFF/STACK/coeff43.txt
Table[f[42+x] /. {a[41] -> 0, a[42] ->0, a[43] -> 0, a[44] -> 1},
{x,0,1, 1/100}] >> /home/barrycarter/BCINFO/ONEOFF/STACK/coeff44.txt
编辑:谢谢,whuber!这正是我想要的。作为参考,系数为(按顺序):
(x-2)*(x-1)*x/-6
(x-2)*(x-1)*(x+1)/2
x*(x+1)*(x-2)/-2
(x-1)*x*(x+1)/6
I'm reverse-engineering how Mathematica does list interpolation:
(* Fortunately, Mathematica WILL interpolate an arbitrary list *)
tab = Table[a[i], {i,1,100}]
f = Interpolation[tab]
(* get the coefficient of each term by setting others to zero *)
Plot[{f[42+x] /. {a[42] -> 0, a[43] ->0, a[44] -> 0, a[41] -> 1}},
{x,0,1}]
Plot[{f[42+x] /. {a[41] -> 0, a[43] ->0, a[44] -> 0, a[42] -> 1}},
{x,0,1}]
Plot[{f[42+x] /. {a[42] -> 0, a[41] ->0, a[44] -> 0, a[43] -> 1}},
{x,0,1}]
Plot[{f[42+x] /. {a[42] -> 0, a[43] ->0, a[41] -> 0, a[44] -> 1}},
{x,0,1}]
(* above is neither Hermite, nor linear, though some look close *)
(* these are available at oneoff.barrycarter.info/STACK/ *)
Table[f[42+x] /. {a[42] -> 0, a[43] ->0, a[44] -> 0, a[41] -> 1},
{x,0,1, 1/100}] >> /home/barrycarter/BCINFO/ONEOFF/STACK/coeff41.txt
Table[f[42+x] /. {a[41] -> 0, a[43] ->0, a[44] -> 0, a[42] -> 1},
{x,0,1, 1/100}] >> /home/barrycarter/BCINFO/ONEOFF/STACK/coeff42.txt
Table[f[42+x] /. {a[41] -> 0, a[42] ->0, a[44] -> 0, a[43] -> 1},
{x,0,1, 1/100}] >> /home/barrycarter/BCINFO/ONEOFF/STACK/coeff43.txt
Table[f[42+x] /. {a[41] -> 0, a[42] ->0, a[43] -> 0, a[44] -> 1},
{x,0,1, 1/100}] >> /home/barrycarter/BCINFO/ONEOFF/STACK/coeff44.txt
EDIT: Thanks, whuber! That did exactly what I wanted. For reference, the coefficients are (in order):
(x-2)*(x-1)*x/-6
(x-2)*(x-1)*(x+1)/2
x*(x+1)*(x-2)/-2
(x-1)*x*(x+1)/6
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据文档,插值器是分段多项式。这有点模糊,所以这里有一些东西需要调查。
您可以通过实验确定插值器是数据的线性函数。所有可能数据的良好基础由以下形式的向量组成:{1,0,...,0}, {0,1,0,...,0}, ..., {0,..., 0,1}。为此,让我们构建一个微小的函数来生成这些长度为 $n$ 的向量:
您可以通过尝试一些像这样的示例来确认线性度,其中系数 $a$ 和 $b$ 作用于 $i^\text{ th}$ 和 $j^\text{th}$ 长度为 $n$ 的基向量:
只有一条曲线,因为这两个函数是叠加的。
建立线性关系后,分析 $n$ 基本向量上的插值器值就足够了。您可以通过微分来确定多项式的次数。默认情况下,次数为 3,但您可以使用“InterpolatingOrder”参数进行修改。以下代码将使用长度为 $n$ 的数据的所有基向量,绘制由插值器的导数得出的明显分段常数曲线表,用于插值阶数 1 到 ioMax:
输出显示中断发生在整数值处参数的长度为 $n$ 的数据和度为 $d$ 的插值器最多有 $nd$ 个不同的段。这些信息应该可以帮助您完成大部分工作。
According to the documentation the interpolator is piecewise polynomial. That's a little vague, so there is something to be investigated here.
You can establish experimentally that the interpolator is a linear function of the data. A nice basis for all possible data consists of vectors of the form {1,0,...,0}, {0,1,0,...,0}, ..., {0,...,0,1}. To this end, let's build a tiny function to produce these vectors of length $n$:
You can confirm the linearity by trying some examples like this one, with coefficients $a$ and $b$ acting on the $i^\text{th}$ and $j^\text{th}$ basis vectors of length $n$:
There will be but a single curve because the two functions are superimposed.
Having established the linearity, it will suffice to analyze the interpolator's values on the $n$ basis vectors. You can determine the degrees of the polynomials by differentiation. By default the degree is 3, but you can modify that with the "InterpolatingOrder" parameter. The following code will plot a table of obviously piecewise constant curves resulting from the derivatives of the interpolator for interpolating orders 1 through ioMax, using all the basis vectors for data of length $n$:
The output shows that the breaks occur at the integer values of the argument and that there are at most $n-d$ distinct segments for data of length $n$ and an interpolator of degree $d$. This information should get you most of the way there.