什么数学方法适用于 2d 到 2d 函数的插值?
所以我们有一个
12,32
24,12
...
长度为 2xN 的矩阵和另一个
44,32
44,19
...
长度为 2xN 的矩阵,并且有一些函数 f(x, y) 返回 z[1], z[2]。我们得到的 2 个矩阵代表 x、y 和 z[1]、z[2] 的已知值对。在这种情况下有什么帮助的插值公式?
So we have a matrix like
12,32
24,12
...
with length 2xN and another
44,32
44,19
...
with length 2xN and there is some function f(x, y) that returns z[1], z[2]. That 2 matrices that we were given represent known value pairs for x,y and z[1],z[2]. What are interpolation formulas that would help in such case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你解决一个返回值的问题,你可以通过插值找到两个函数
f_1(x,y)
和f_2(x,y)
,并将你的函数组成为f(x, y) = [f_1(x,y), f_2(x,y)]
。只需选择适合您的问题的任何方法来求解插值函数即可。对于二维的实际插值问题,有很多方法可以处理。如果您需要简单,则可以使用线性插值。如果您可以使用分段函数,则可以使用贝塞尔曲线或样条曲线。或者,如果数据是均匀的,您可以使用简单的多项式插值(嗯,在二维中不是很简单,但足够简单)。
编辑:更多信息和一些链接。
使用双线性插值(wikipedia)可以实现分段解决方案。
对于多项式插值,如果您的数据在网格上,您可以使用以下算法(我找不到它的参考,它来自内存)。
如果数据点位于
k
byl
网格上,请按如下方式重写多项式:这里,每个系数
cx_i(x)
也是一个l 次多项式。第一步是通过对网格的每一行或每一列进行插值来找到k
个l
次多项式。完成此操作后,您将拥有l
系数集(或者,l
多项式)作为每个cx_i(x)
的插值点多项式为cx_i(x0)
,cx_i(x1)
, ...,cx_i(xl)
(总共为 l*k点)。现在,您可以使用上述常量作为插值点来确定这些多项式,从而得到结果f(x,y)
。同样的方法也适用于贝塞尔曲线或样条曲线。唯一的区别是您使用控制点而不是多项式系数。您首先获得一组将生成数据点的样条曲线,然后对这些中间曲线的控制点进行插值以获得曲面曲线的控制点。
让我添加一个例子来阐明上述算法。让我们有以下数据点:
我们首先拟合两个多项式:一个用于数据点 (0,0) 和 (0,1),另一个用于 (1, 0) 和 (1, 1):
现在,我们插值当我们垂直读取这些多项式系数时,我们需要两个多项式。 1 在 0 和 1 处评估为 1;另一个在 0 处计算结果为 1,在 1 处计算结果为 3:
如果我们将它们组合成
f(x,y)
,我们会得到:If you solve the problem for one return value, you can find two functions
f_1(x,y)
andf_2(x,y)
by interpolation, and compose your function asf(x, y) = [f_1(x,y), f_2(x,y)]
. Just pick any method for solving the interpolation function suitable for your problem.For the actual interpolation problem in two dimensions, there are a lot of ways you can handle this. If simple is what you require, you can go with linear interpolation. If you are OK with piecewise functions, you can go for bezier curves, or splines. Or, if data is uniform, you could get away with a simple polynomial interpolation (well, not quite trivial when in 2D, but easy enough).
EDIT: More information and some links.
A piecewise solution is possible using Bilinear interpolation (wikipedia).
For polynomial interpolation, if your data is on a grid, you can use the following algorithm (I cannot find the reference for it, it is from memory).
If the data points are on a
k
byl
grid, rewrite your polynomial as follows:Here, each coefficient
cx_i(x)
is also a polynomial of degreel
. The first step is to findk
polynomials of degreel
by interpolating each row or column of the grid. When this is done, you havel
coefficient sets (or, in other words,l
polynomials) as interpolation points for eachcx_i(x)
polynomials ascx_i(x0)
,cx_i(x1)
, ...,cx_i(xl)
(giving you a total of l*k points). Now, you can determine these polynomials using the above constants as the interpolation points, which give you the resultingf(x,y)
.The same method is used for bezier curves or splines. The only difference is that you use control points instead of polynomial coefficients. You first get a set of splines that will generate your data points, and then you interpolate the control points of these intermediate curves to get the control points of the surface curve.
Let me add an example to clarify the above algorithm. Let's have the following data points:
We start by fitting two polynomials: one for data points (0,0) and (0,1), and another for (1, 0) and (1, 1):
Now, we interpolate in the other direction to determine the coefficients.When we read these polynomial coefficients vertically, we need two polynomials. One evaluates to 1 at both 0 and 1; and another that evaluates to 1 at 0, and 3 at 1:
If we combine these into
f(x,y)
, we get: