强制Mathematica在非结构化张量网格上进行插值

bar*_*ter 4 interpolation wolfram-mathematica

此列表是一个简单的函数,如果您将每个点{{x,y},z}视为数字,则将2D点映射到数字f[x,y]=z

{ 
 {{1,3},9}, {{1,4},16}, 
 {{2,4},8}, {{2,5},10} 
} 
Run Code Online (Sandbox Code Playgroud)

我现在想要一个f[x,y]为任何内插/外推的函数{x,y}.

Mathematica拒绝这样做:

Interpolation[{{{1,3},9}, {{1,4},16},{{2,4},8}, {{2,5},10}},  
 InterpolationOrder->1] 
Run Code Online (Sandbox Code Playgroud)

插值:: 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}] 
Run Code Online (Sandbox Code Playgroud)

FunctionInterpolation :: nreal:
16在{x,y} = {1, - }附近,该函数未计算为实数.5 FunctionInterpolation :: nreal:
17在{x,y} = {1, - }附近,该函数未计算为实数.5 FunctionInterpolation :: nreal:
18在{x,y} = {1, - }附近,该函数未计算为实数.5 General :: stop:在此计算过程中,将抑制FunctionInterpolation :: 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)))))) 
Run Code Online (Sandbox Code Playgroud)

另一个"明显"的想法(内插插值函数本身)也不起作用.

Mic*_*lat 6

如果多项式插值是可以接受的, InterpolatingPolynomial你想要做什么(这里data是您点的名单上):

In[63]:= InterpolatingPolynomial[data, {x, y}]

Out[63]= -24 + x (12 - 5 y) + 12 y

In[64]:= f[2, 3]

Out[64]= 6
Run Code Online (Sandbox Code Playgroud)

你也可以用Fit做最小二乘上的第二个参数中指定的功能的线性组合拟合:

In[65]:= Fit[Flatten /@ data, {1, x, y}, {x, y}]

Out[65]= 4.75 - 8. x + 4.5 y
Run Code Online (Sandbox Code Playgroud)

当然,拟合函数可能无法精确插值数据点.如果这样的拟合是可接受的,则FindFit可以适用于您指定的任何(线性或非线性)模型函数:

In[72]:= FindFit[Flatten/@data, x y (a Sin[x] + b Cos[y]) + c, {a,b,c}, {x,y}]

Out[72]= {a -> -0.683697, b -> 0.414257, c -> 15.3805}
Run Code Online (Sandbox Code Playgroud)

HTH!