# Automatic differentiation of complex valued functions

**URL:** <https://discourse.julialang.org/t/automatic-differentiation-of-complex-valued-functions/30263>\
**Category:** Numerics\
**Tags:** question, zygote, forwarddiff, complex-numbers\
**Created:** [October 24, 2019, 8:33am UTC](https://discourse.julialang.org/t/automatic-differentiation-of-complex-valued-functions/30263 "2019-10-24T08:33:24Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [October 24, 2019, 8:58am UTC](https://discourse.julialang.org/t/automatic-differentiation-of-complex-valued-functions/30263/3 "2019-10-24T08:58:07Z")

</div>

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

```julia
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))

```

---

_[View the full topic](https://discourse.julialang.org/t/automatic-differentiation-of-complex-valued-functions/30263)._
