0

我有三个向量,一个是 X 位置,另一个是 Y 位置,第三个是 af(x, y)。我想找到代数表达式插值多项式(使用 matlab),因为稍后我将在 AMPL 中的优化问题中使用结果。据我所知,没有任何函数可以返回插值多项式。

我试过https://la.mathworks.com/help/matlab/ref/griddedinterpolant.html,但这个函数只给出了某些点的插值。

我还尝试了https://la.mathworks.com/help/matlab/ref/triscatteredinterp.html,如Matlab 中二维插值的函数形式中所建议的那样,但输出不是多项式的系数。我看不到它,它似乎被锁定在一个奇怪的变量中。

这是我用来测试我在做什么的一个小程序:

close all
clear
clc

[X,Y] = ndgrid(1:10,1:10);
V = X.^2 + 3*(Y).^2;
F = griddedInterpolant(X,Y,V,'cubic');
[Xq,Yq] = ndgrid(1:0.5:10,1:0.5:10);
Vq = F(Xq,Yq);
mesh(Xq,Yq,Vq)
figure
mesh(X, Y, V)

我想要一个输出,而不是返回网格点的值,而是返回它用于计算所述值的任何内容。我知道它可以用https://reference.wolfram.com/language/ref/InterpolatingPolynomial.html在数学中完成,所以我觉得 matlab 做不到很奇怪。

4

1 回答 1

3

fit如果您有曲线拟合工具箱,则可以使用。

如果不是这种情况,您可以使用简单的回归,如果我以您的为例:

% The example data
[X,Y] = ndgrid(1:10,1:10);
V = X.^2 + 3*(Y).^2;

% The size of X
s = size(X(:),1);

% Let's suppose that you want to fit a polynome of degree 2.
% Create all the possible combination for a polynome of degree 2
%        cst     x     y     x^2       y^2       x*y
A = [ones(s,1), X(:), Y(:), X(:).^2, Y(:).^2, X(:).*Y(:)]

% Then using mldivide
p = A\V(:)

% We obtain:

p = 
    0  % cst
    0  % x
    0  % y
    1  % x^2
    3  % y^2
    0  % x*y
于 2019-09-30T16:31:19.187 回答