# How to solve Lambert W function?

**URL:** https://discourse.julialang.org/t/how-to-solve-lambert-w-function/52538
**Category:** Numerics
**Tags:** question
**Created:** [December 28, 2020, 9:04pm UTC](https://discourse.julialang.org/t/how-to-solve-lambert-w-function/52538 "2020-12-28T21:04:03Z")
**Posts on this page:** 1
**Showing post:** 18

<div class="post-metadata">

### Author: ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)
#### Post date: [December 29, 2020, 3:48pm UTC](https://discourse.julialang.org/t/how-to-solve-lambert-w-function/52538/18 "2020-12-29T15:48:07Z")

</div>

I ran the following:

```julia
function ricky(x, k, r, I)
  for i in 1:I
    q = 1-x/k
    y = x * exp(r*q)
    x = y
  end
  return y
end
y = ricky(50000, 2.2*10^7, 0.47, 2)
# a given population increases from 50 000 to 79 914.30 between to and t1
# now, let's invert it
using LambertW
x = -(k/r)*lambertw(-r*exp(-r)*y/k)
julia> x
49999.99999999999

```

which looks pretty good to me…  
Thank you!

---

_[View the full topic](https://discourse.julialang.org/t/how-to-solve-lambert-w-function/52538)._
