function leb = wamleb(deg,wam,cmesh,rect);

% by Alvise and Marco Vianello, University of Padova
% October 30, 2014

% computes the Lebesgue constant of least-squares polynomial fitting   
% at wam, using the control mesh cmesh

if isempty(rect)
both=[wam;cmesh];
rect=[min(both(:,1)) max(both(:,1)) min(both(:,2)) max(both(:,2))];    
end

[Q,R1,R2]=wamdop(deg,wam,rect);
DOP=wamdopeval(deg,R1,R2,cmesh,rect);
leb=norm(Q*DOP',1);

end 


