Module: MoreMath::Lambert
- Defined in:
- lib/more_math/lambert.rb
Overview
Provides the Lambert W function implementation for solving equations of the form x * e^x = y
The Lambert W function is a special function that solves the implicit equation x * e^x = y for x in terms of y. It has applications in various fields including combinatorics, physics, and engineering problems involving exponential growth and decay.
Instance Method Summary collapse
-
#lambert_w(y, epsilon = 1E-16) ⇒ Float
Calculates the principal branch of the Lambert W function (W₀).
Instance Method Details
#lambert_w(y, epsilon = 1E-16) ⇒ Float
Calculates the principal branch of the Lambert W function (W₀).
The Lambert W function solves the equation: x * e^x = y
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/more_math/lambert.rb', line 30 def lambert_w(y, epsilon = 1E-16) # Handle special cases return 0.0 if y.zero? return Float::INFINITY if y.infinite? return -1.0 if (y - -1.0 / Math::E).abs < epsilon return 0 / 0.0 if y <= -1.0 / Math::E # Define the function f(x) = x * e^x - y func = ->(x) { x * Math.exp(x) - y } solver = MoreMath::NewtonBisection.new(&func) solver.solve(nil, 1 << 16, epsilon) end |