function [ W ] = RealW( z )
%REALW Lambert W of z by chebfun integration
%   Testing chebfun quadrature
lim = pi;
v = chebfun( 'x', [-lim,lim] );
vcotv = chebfun( 'x*cot(x)', [-lim,lim], 'splitting', 'on', 'blowup', 'on' );
vcscv = chebfun( 'x*csc(x)', [-lim,lim], 'splitting', 'on', 'blowup', 'on' );
y = ((1-vcotv).^2 + v.^2)./( z + vcscv.*exp(-vcotv) );
W = z.*sum( y )/(2*pi);
% RealW(1) at one point yielded the error message:
%??? Error using ==> chebfun.exp at 9
%chebfun cannot handle exponential blowups
%
%Error in ==> RealW at 8
%y = ((1-v.*cotv).^2 + v.^2)./( z + v.*cscv.*exp(-v.*cotv) );

end

