2017-01-23 56 views

回答

0

这个问题可以表示为一组线性方程组,这些方程组使用mldivide函数来解决这些问题是微不足道的。

让我用你包含的例子来说明这一点。

% 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

相关问题