%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% LSSCLS subroutine
% Constrained linear problems
% (solve the least-square problem of Ax = b subject to Cx = d)
% 
%   b:   qx1     matrix
%   A:   qxn     matrix, q > n
%   W:   qxq     matrix, the weight function
%   d:   (ell)x1 matrix
%   C:   (ell)xn matrix, (ell) < n
%   q:   dimension of function phi
%   n:   number of design variables
%   ell: number of constraints
% 
% Jean-François Gauthier : 12-15-06
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function[dx] = LSSCLS(b,A,W,d,C,q,n,ell,ODA)

% First let's find L and x0
[L,x0] = Lk_dx0(C,d,ell,n);

% Since V is (qxq), A is (qxn) and L is (nx(n-l)), then VAL is (qx(n-l))
V     = chol(W);
VAL   = V*A*L;
VbAx0 = V*(b-A*x0);

u  = LSSLS(VbAx0,VAL,q,n,ODA);

dx = x0 + L*u;          % (nx1) + (nx(n-l))x((n-l)x1) = (nx1)