fork download
  1. Imports System
  2.  
  3. Module LambertW
  4. Function LAMBERT(x As Double) As Double
  5. Dim Wx, Wxcont, L, Lprim, Lsec As Double
  6. If x < -Math.Exp(-1) Then
  7. Console.WriteLine("Invalid Argument!")
  8. Exit Function
  9. End If
  10. Wx = 1
  11. Do Until Math.Abs(Wxcont - Wx) < 0.000000001
  12. Wxcont = Wx
  13. L = Wx * Math.Exp(Wx) - x
  14. Lprim = Math.Exp(Wx) * (Wx + 1)
  15. Lsec = Math.Exp(Wx) * (Wx + 2)
  16. Wx = Wx - L / (Lprim - (L * Lsec / (2 * Lprim)))
  17. Loop
  18. LAMBERT = Wx
  19. End Function
  20. Sub Main()
  21. Console.WriteLine(LAMBERT(-1.0 / Math.Exp(1.0)))
  22. End Sub
  23. End Module
Success #stdin #stdout 0.02s 26888KB
stdin
Standard input is empty
stdout
-0.999999994200611