这个问题是个有约束的拟合问题,本质上可以看作最优化。你可以简单考虑求解x1,x2 和 x3使得估计出的y值和真实的y值之间的误差最小。因此可以用最小二乘法构造一个简单的目标函数:
min_{x1, x2, x3} sum (y - y_est)^2
s.t. x1 in [2.2, 2.6], x2 in [1.0, 1.1], x3 in [1.2, 1.5]
程序为:
data = [20.14027 10.36194 68.85648 0.9548
30.04382 9.228103 59.94872 0.8488
20.70396 9.972546 68.2548 0.5312
10.9118 8.906443 78.83921 0.1939
16.16368 8.701604 73.94192 0.4638
24.99884 11.25222 63.0682 0.9011
27.0438 8.727725 62.93112 0.3134
10.13315 9.271956 79.46367 0.3904
38.76561 11.31157 49.36698 1.1113
48.32206 12.56811 38.61983 1.3347];
b = data(:,1);
c = data(:,2);
d = data(:,3);
y = data(:,4);
f = @(x) sum((x(1)*b + x(2)*c + x(3)*d - y).^2);
x0 = [2.2;1.0;1.3]; %initial value
LB = [2.2;1.0;1.2];
UB = [2.6;1.1;1.5];
[x,fval] = fmincon(f, x0, [], [], [], [], LB, UB);
str = ['x1=', num2str(x(1)),', x2=', num2str(x(2)),', x3=', num2str(x(3))];
disp(str);