MATLAB: Lsqnonneg

lsqnonneg()

Can I solve [x] in the relation [C]*[x]=[d] using x= lsqnonneg(C,d);? Vector dimensions are as follows C(5×2), d(5×1). If not please suggest me better way.
Thank you,

Best Answer

x = C\d;
EDIT: The least squares estimate for x is
xhat = (C'*C)\(C'*d);
You can estimate the error in the fit as follows:
n = length(d);
s2 = norm(x-xhat)^2/(n-2); %estimated variance of the data
covar = s2*inv(C'*C); %covariance matrix for the components of xhat
xerr = sqrt(diag(covar)) %standard errors for xhat components
Related Question