什么数学方法适用于 2d 到 2d 函数的插值?

发布于 2024-12-10 06:06:13 字数 226 浏览 0 评论 0原文

所以我们有一个

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 技术交流群。

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

发布评论

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

评论(1

百思不得你姐 2024-12-17 06:06:13

如果你解决一个返回值的问题,你可以通过插值找到两个函数f_1(x,y)f_2(x,y),并将你的函数组成为f(x, y) = [f_1(x,y), f_2(x,y)]。只需选择适合您的问题的任何方法来求解插值函数即可。

对于二维的实际插值问题,有很多方法可以处理。如果您需要简单,则可以使用线性插值。如果您可以使用分段函数,则可以使用贝塞尔曲线或样条曲线。或者,如果数据是均匀的,您可以使用简单的多项式插值(嗯,在二维中不是很简单,但足够简单)。


编辑:更多信息和一些链接。

使用双线性插值(wikipedia)可以实现分段解决方案。

对于多项式插值,如果您的数据在网格上,您可以使用以下算法(我找不到它的参考,它来自内存)。

如果数据点位于 k by l 网格上,请按如下方式重写多项式:

f(x,y) = cx_1(x)*y^(k-1) + cx_2(x)*y^(k-2) + ... + cx_k(x)

这里,每个系数 cx_i(x) 也是一个l 次多项式。第一步是通过对网格的每一行或每一列进行插值来找到 kl 次多项式。完成此操作后,您将拥有 l 系数集(或者,l 多项式)作为每个 cx_i(x) 的插值点多项式为 cx_i(x0), cx_i(x1), ..., cx_i(xl) (总共为 l*k点)。现在,您可以使用上述常量作为插值点来确定这些多项式,从而得到结果 f(x,y)

同样的方法也适用于贝塞尔曲线或样条曲线。唯一的区别是您使用控制点而不是多项式系数。您首先获得一组将生成数据点的样条曲线,然后对这些中间曲线的控制点进行插值以获得曲面曲线的控制点。


让我添加一个例子来阐明上述算法。让我们有以下数据点:

0,0 => 1
0,1 => 2
1,0 => 3
1,1 => 4

我们首先拟合两个多项式:一个用于数据点 (0,0) 和 (0,1),另一个用于 (1, 0) 和 (1, 1):

f_0(x) = x + 1
f_1(x) = x + 3

现在,我们插值当我们垂直读取这些多项式系数时,我们需要两个多项式。 1 在 0 和 1 处评估为 1;另一个在 0 处计算结果为 1,在 1 处计算结果为 3:

cy_1(y) = 1
cy_2(y) = 2*y + 1

如果我们将它们组合成 f(x,y),我们会得到:

f(x,y) = cy_1(y)*x + cy_2(y)
       = 1*x + (2*y + 1)*1
       = x + 2*y + 1

If you solve the problem for one return value, you can find two functions f_1(x,y) and f_2(x,y) by interpolation, and compose your function as f(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 by l grid, rewrite your polynomial as follows:

f(x,y) = cx_1(x)*y^(k-1) + cx_2(x)*y^(k-2) + ... + cx_k(x)

Here, each coefficient cx_i(x) is also a polynomial of degree l. The first step is to find k polynomials of degree l by interpolating each row or column of the grid. When this is done, you have l coefficient sets (or, in other words, l polynomials) as interpolation points for each cx_i(x) polynomials as cx_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 resulting f(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:

0,0 => 1
0,1 => 2
1,0 => 3
1,1 => 4

We start by fitting two polynomials: one for data points (0,0) and (0,1), and another for (1, 0) and (1, 1):

f_0(x) = x + 1
f_1(x) = x + 3

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:

cy_1(y) = 1
cy_2(y) = 2*y + 1

If we combine these into f(x,y), we get:

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