%% Obtain Residuals from Nonnegative Least Squares
% Call lsqnonneg with outputs to obtain the solution, residual norm, and residual vector.
% Prepare a C matrix and d vector for the problem \min ||Cx-d||.

C = [0.0372    0.2869
     0.6861    0.7071
     0.6233    0.6245
     0.6344    0.6170];

d = [0.8587
     0.1781
     0.0747
     0.8405];

%
% Obtain the solution and residual information.

 [x,resnorm,residual] = lsqnonneg(C,d)

%
% Verify that the returned residual norm is the square of the norm of the returned residual vector.

 norm(residual)^2

% Copyright 2012 The MathWorks, Inc.