%% Inspect the Result of Nonnegative Least Squares
% Request all output arguments to examine the solution and solution process after lsqnonneg finishes.
% 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];

%
% Solve the problem, requesting all output arguments.

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

% exitflag is 1, indicating a correct solution.
% x(1) = 0, and the corresponding lambda(1) \neq 0, showing the correct duality. Similarly, x(2) > 0, and the corresponding lambda(2) = 0.
% Copyright 2012 The MathWorks, Inc.