function y=LambertW2(x)
% LAMBERTW2 second implementation of the LambertW function 
%   y=LambertW2(x) computes the solution of x=y+exp(y) using
%   Newton's method

f=@(y) y+exp(y); fs=@(y) 1+exp(y);
tol=1e-12;
ya=1; yn=0;
while abs(ya-yn)>=tol
  ya=yn;
  yn=ya-(f(ya)-x)/fs(ya);
end
y=yn;