Imports System
Module LambertW
Function LAMBERT(x As Double) As Double
Dim Wx, Wxcont, L, Lprim, Lsec As Double
If x < -Math.Exp(-1) Then
Console.WriteLine("Invalid Argument!")
Exit Function
End If
Wx = 1
Do Until Math.Abs(Wxcont - Wx) < 0.000000001
Wxcont = Wx
L = Wx * Math.Exp(Wx) - x
Lprim = Math.Exp(Wx) * (Wx + 1)
Lsec = Math.Exp(Wx) * (Wx + 2)
Wx = Wx - L / (Lprim - (L * Lsec / (2 * Lprim)))
Loop
LAMBERT = Wx
End Function
Sub Main()
Console.WriteLine(LAMBERT(-1.0 / Math.Exp(1.0)))
End Sub
End Module
SW1wb3J0cyBTeXN0ZW0KCk1vZHVsZSBMYW1iZXJ0VwoJRnVuY3Rpb24gTEFNQkVSVCh4IEFzIERvdWJsZSkgQXMgRG91YmxlCgkJRGltIFd4LCBXeGNvbnQsIEwsIExwcmltLCBMc2VjIEFzIERvdWJsZQoJCUlmIHggPCAtTWF0aC5FeHAoLTEpIFRoZW4KCQkJQ29uc29sZS5Xcml0ZUxpbmUoIkludmFsaWQgQXJndW1lbnQhIikKCQkJRXhpdCBGdW5jdGlvbgoJCUVuZCBJZgoJCVd4ID0gMQoJCURvIFVudGlsIE1hdGguQWJzKFd4Y29udCAtIFd4KSA8IDAuMDAwMDAwMDAxCgkJCVd4Y29udCA9IFd4CgkJCUwgPSBXeCAqIE1hdGguRXhwKFd4KSAtIHgKCQkJTHByaW0gPSBNYXRoLkV4cChXeCkgKiAoV3ggKyAxKQoJCQlMc2VjID0gTWF0aC5FeHAoV3gpICogKFd4ICsgMikKCQkJV3ggPSBXeCAtIEwgLyAoTHByaW0gLSAoTCAqIExzZWMgLyAoMiAqIExwcmltKSkpCgkJTG9vcAoJCUxBTUJFUlQgPSBXeAoJRW5kIEZ1bmN0aW9uCglTdWIgTWFpbigpCgkJQ29uc29sZS5Xcml0ZUxpbmUoTEFNQkVSVCgtMS4wIC8gTWF0aC5FeHAoMS4wKSkpCglFbmQgU3ViCkVuZCBNb2R1bGU=