1
在MATLAB中使用函數lsqlin的線條通過(x0,y0)的約束下,我已經擬合了一個包含68個樣本的數據集的直線。我怎樣才能找到這個置信區間?MATLAB中約束條件下的線性曲線擬合的置信區間
我的代碼(Source):
我導入包含x和y矢量從墊文件,其中還包含約束x0和y0的值的數據集。
n = 1; % Degree of polynomial to fit
V(:,n+1) = ones(length(x),1,class(x)); %V=Vandermonde matrix for 'x'
for j = n:-1:1
V(:,j) = x.*V(:,j+1);
end
d = y; % 'd' is the vector of target values, 'y'.
% There are no inequality constraints in this case, i.e.,
A = [];b = [];
% We use linear equality constraints to force the curve to hit the required point. In
% this case, 'Aeq' is the Vandermoonde matrix for 'x0'
Aeq = x0.^(n:-1:0);
% and 'beq' is the value the curve should take at that point
beq = y0;
%%
[p, resnorm, residual, exitflag, output, lambda] = lsqlin(V, d, A, b, Aeq, beq);
%%
% We can then use POLYVAL to evaluate the fitted curve
yhat = polyval(p, x);