Automatic differentiation of complex valued functions

One trick is to decompose to real and imaginary parts, then reassemble:

import ForwardDiff
function f(x)
    y = complex(x[1], x[2]) * exp(complex(x[3], x[4]))
    vcat(real.(y), imag.(y))
end
ForwardDiff.jacobian(f, ones(4))
2 Likes