Graham
Graham

Reputation: 1084

Lambert W function implementation in Java

I'm working on a project and have found myself in a situation where I need a function to be able to get at least an approximation of the value of W(x), the Lambert W function, where x can be any real number. I'm working in Java. I couldn't find any implementations of W in java when I searched. I am willing to code up the implementation myself if need be, but I am unsure of how that would be done right now. Any pushes in the right direction would be much appreciated.

Upvotes: 8

Views: 3794

Answers (2)

Ricky Bobby
Ricky Bobby

Reputation: 7608

The lambert function is the reciprocal function of g(w) = w*exp(w) it verifies:

W(z)eW(z) = z.

A good way to evaluate W(z) on a given z would be to use newton raphson method :

to solve : f(Y)= Yexp(Y) - z = 0.

you will find Y = W(z) with the method

You would have to find and implementation in java of the method yourself.

Hope it helps

below an illustration from wikipedia of the method:

enter image description here

Upvotes: 3

tskuzzy
tskuzzy

Reputation: 36446

Take a look at this page: http://mathworld.wolfram.com/LambertW-Function.html

It lists an approximation for z>3 as well as a series expansion for the function.

You can also use Newton's method and Halley's method to approximate the function: http://en.wikipedia.org/wiki/Lambert_W_function#Numerical_evaluation

Upvotes: 6

Related Questions