强制 Mathematica 在非结构化张量网格上进行插值
该列表是一个简单的函数,它将 2D 点映射到数字,如果 你将每个 {{x,y},z}
视为 f[x,y]=z
{
{{1,3},9}, {{1,4},16},
{{2,4},8}, {{2,5},10}
}
我现在想要一个可以插值/外推 f[x ,y]
对于任何 {x,y}
。
Mathematica 拒绝这样做:
Interpolation[{{{1,3},9}, {{1,4},16},{{2,4},8}, {{2,5},10}},
InterpolationOrder->1]
插值::indim: 坐标不位于结构化上 张量积网格。
我明白为什么(Mathematica 想要一个“矩形”域),但是 强制 Mathematica 创建插值的最简单方法是什么?
这不起作用:
f[1,3]=9; f[1,4]=16; f[2,4]=8; f[2,5]=10;
g=FunctionInterpolation[f[x,y],{x,1,2},{y,3,5}]
函数插值::nreal:
16 在 {x, y} = {1, --} 附近,函数没有 评估为实数。 5 函数插值::nreal:
17 在 {x, y} = {1, --} 附近,函数没有 评估为实数。 5 函数插值::nreal:
18 在 {x, y} = {1, --} 附近,函数没有 评估为实数。 5 General::stop:进一步输出 函数插值::nreal 在此计算过程中将被抑制。
即使您忽略上面的警告,评估 g 也会给出错误
g[1.5,4] // FortranForm
f(1.5,4) + 0.*(-9.999999999999991*(f(1.4,4) - f(1.5,4)) +
- 0.10000000000000009*
- (9.999999999999991*
- (9.999999999999991*(f(1.4,4) - f(1.5,4)) +
- 4.999999999999996*(-f(1.4,4) + f(1.6,4))) +
- 0.5000000000000006*
- (-10.000000000000014*
- (-3.333333333333333*(f(1.3,4) - f(1.6,4)) -
- 4.999999999999996*(-f(1.4,4) + f(1.6,4))) -
- 9.999999999999991*
- (9.999999999999991*(f(1.4,4) - f(1.5,4)) +
- 4.999999999999996*(-f(1.4,4) + f(1.6,4))))))
另一个“明显”的想法(插值插值函数 他们自己)也不起作用。
This list is a simple function that maps a 2D point to a number, if
you regard each {{x,y},z}
as f[x,y]=z
{
{{1,3},9}, {{1,4},16},
{{2,4},8}, {{2,5},10}
}
I now want a function that interpolates/extrapolates f[x,y]
for any {x,y}
.
Mathematica refuses to do this:
Interpolation[{{{1,3},9}, {{1,4},16},{{2,4},8}, {{2,5},10}},
InterpolationOrder->1]
Interpolation::indim: The
coordinates do not lie on a structured
tensor product grid.
I understand why (Mathematica wants a "rectangular" domain), but
what's the easiest way to force Mathematica to create an interpolation?
This doesn't work:
f[1,3]=9; f[1,4]=16; f[2,4]=8; f[2,5]=10;
g=FunctionInterpolation[f[x,y],{x,1,2},{y,3,5}]
FunctionInterpolation::nreal:
16 Near {x, y} = {1, --}, the function did not
evaluate to a real number.
5 FunctionInterpolation::nreal:
17 Near {x, y} = {1, --}, the function did not
evaluate to a real number.
5 FunctionInterpolation::nreal:
18 Near {x, y} = {1, --}, the function did not
evaluate to a real number.
5 General::stop: Further output of
FunctionInterpolation::nreal
will be suppressed during this calculation.
Even if you ignore the warnings above, evaluating g gives errors
g[1.5,4] // FortranForm
f(1.5,4) + 0.*(-9.999999999999991*(f(1.4,4) - f(1.5,4)) +
- 0.10000000000000009*
- (9.999999999999991*
- (9.999999999999991*(f(1.4,4) - f(1.5,4)) +
- 4.999999999999996*(-f(1.4,4) + f(1.6,4))) +
- 0.5000000000000006*
- (-10.000000000000014*
- (-3.333333333333333*(f(1.3,4) - f(1.6,4)) -
- 4.999999999999996*(-f(1.4,4) + f(1.6,4))) -
- 9.999999999999991*
- (9.999999999999991*(f(1.4,4) - f(1.5,4)) +
- 4.999999999999996*(-f(1.4,4) + f(1.6,4))))))
The other "obvious" idea (interpolating interpolating functions
themselves) doesn't work either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果多项式插值可接受,则
InterpolatingPolynomial
会执行您的操作想要(其中data
是上面的要点列表):您还可以使用
Fit
对第二个参数中指定的函数的线性组合进行最小二乘拟合:当然,拟合函数可能无法精确地插值您的数据点。如果这种拟合是可以接受的,
FindFit
可以拟合到您指定的任何(线性或非线性)模型函数:HTH!
If polynomial interpolation is acceptable,
InterpolatingPolynomial
does what you want (wheredata
is your list of points above):You could also use
Fit
to do least-squares fitting on the linear combination of functions specified in the second argument:Of course, a fitted function may not exactly interpolate your data points. If such fitting is acceptable though,
FindFit
can fit to any (linear or non-linear) model function you specify:HTH!
请使用我的包!
http://library.wolfram.com/infocenter/MathSource/7760/
Please use my package!
http://library.wolfram.com/infocenter/MathSource/7760/
不幸的是,多项式太不稳定,但线性函数却不然
够扭动的。我相信正确的模型是几条线段,
但它们都有不同的坡度。
这是一个可怕的解决方法,可以满足我的要求。
Unfortunately, polynomials are too wiggly, but linear functions aren't
wiggly enough. I believe the correct model is several line segments,
but they'll all have different slopes.
Here's a hideous workaround that does what I want.