【发布时间】:2016-06-08 19:24:43
【问题描述】:
我已经使用 MATLAB 中的函数 lsqlin 在直线通过 (x0,y0) 的约束下将一条直线拟合到具有 68 个样本的数据集。我怎样才能找到这个的置信区间?
我的代码(Source):
我从一个 mat 文件中导入包含 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 );
【问题讨论】:
标签: matlab constraints curve-fitting confidence-interval