Yes, you can use it but see Matt J's warning about using bounded constraints. [estParams,~,residual,~,~,~,jacobian] = lsqnonlin();
CI = nlparci(estParams,residual,'jacobian',jacobian);
An alternative is to calculate the covariance matrix to calculate the confidence intervals directly (shown below). There are typically very small differences in the results between the two methods.
lastwarn('');
alpha = 0.05;
df = length(residual) - numel(estParams);
crit = tinv(1-alpha/2,df);
covm = inv(jacobian'*jacobian) * var(residual);
[~, warnId] = lastwarn;
covmIdx = sub2ind(size(covm),1:size(covm,1),1:size(covm,2));
CI = nan(numel(estParams),2);
if ~strcmp(warnId, 'MATLAB:nearlySingularMatrix')
CI(:,1) = estParams - crit * sqrt(covm(covmIdx));
CI(:,2) = estParams + crit * sqrt(covm(covmIdx));
end
Best Answer