MATLAB。如何通过插值得到二维多项式
我们得到一个nxn数据。近似函数。 例如如果给我们2(1,1),3(1,2),4(2,1),5(2,2)MATLAB。如何通过插值得到二维多项式,matlab,2d,multinomial,Matlab,2d,Multinomial,我们得到一个nxn数据。近似函数。 例如如果给我们2(1,1),3(1,2),4(2,1),5(2,2) 然后我们必须将二维多项式插值为$0*x*y+y+2*x-1$。这个问题可以表示为一组线性方程组,使用函数求解这些方程非常简单 让我用您包含的示例来说明这一点 % from the given example in = [... 1,1; 1,2; 2,1; 2,2]; out = [... 2; 3; 4; 5]; % c
然后我们必须将二维多项式插值为$0*x*y+y+2*x-1$。这个问题可以表示为一组线性方程组,使用函数求解这些方程非常简单 让我用您包含的示例来说明这一点
% from the given example
in = [...
1,1;
1,2;
2,1;
2,2];
out = [...
2;
3;
4;
5];
% compute the variable terms in the polynomial
x = in(:,1);
y = in(:,2);
xy = x .* y;
c = ones(size(out)); % constant
% compute the coefficients of the polynomial
p = [xy,y,x,c] \ out;
% result: [0; 1; 2; -1]
语句p=[xy,y,x,c]\out
计算问题过度约束时的最佳系数(最小二乘误差)(即不存在精确满足所有方程的解)。但是,如果方程的数量与变量的数量一样多(如本例中,由于4个输入-输出对,有4个方程,并且有4个系数需要估计),那么可以通过p=inv([xy,y,x,c])*out
简单地计算系数