mahmoud fathy mahmoud fathy - 7 months ago 61
R Question

solve complex number equation in R

I am getting an equation with this form

exp(az) = 1 + cz

which I wanna solve for z,

where c is a complex number, so expectedly z is complex also.
I cannot figure out how to solve an equation involving complex number in R.

I hope anybody can help me


Wolfram Alpha can get a solution in terms of the Lambert W function (which it calls the ProductLog function):

enter image description here

The emdbook package (among others) has an implementation of the Lambert W function. (In order to make this work I had to fix a bug, so you can't use the CRAN implementation. Instead, install the latest version from Github: library(devtools); install_github("bbolker/emdbook") ...

sfun <- function(a,c) {
    w <- lambertW(-a/c*exp(-a/c))


a <- 2+1i; c <- 1+1i
(z <- sfun(a,c))
## [1] -0.1686391-0.2337278i

Check answer:

## [1] 0+5.551115e-17i

This is zero to within expected numeric tolerance ...