# Calculation of a Jacobian of a set of complex functions in Julia

**URL:** <https://discourse.julialang.org/t/calculation-of-a-jacobian-of-a-set-of-complex-functions-in-julia/38356>\
**Category:** General Usage\
**Tags:** question, package, forwarddiff\
**Created:** [April 28, 2020, 8:05am UTC](https://discourse.julialang.org/t/calculation-of-a-jacobian-of-a-set-of-complex-functions-in-julia/38356 "2020-04-28T08:05:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![fermion4](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fermion4/32/17160_2.png) [@fermion4](https://discourse.julialang.org/u/fermion4)\
**Post date:** [April 28, 2020, 8:05am UTC](https://discourse.julialang.org/t/calculation-of-a-jacobian-of-a-set-of-complex-functions-in-julia/38356/1 "2020-04-28T08:05:50Z")

</div>

I want to calculate the numerical Jacobian of complex functions using the Julia ForwardDiff package.

```julia
using ForwardDiff

f(θ,i,u) = [1im *i * exp(-1im * θ), 1im * u * exp(-1im * θ)] # Complex Current and Voltage

z = [1,1,1]
ForwardDiff.jacobian(x -> f(x[1],x[2],x[3]), z)

```

But when I run this simple example I get the following result:

```julia
2×3 Array{Complex{Dual{ForwardDiff.Tag{var"#138#139",Int64},Float64,3}},2}:
Dual{ForwardDiff.Tag{var"#138#139",Int64}}(0.0,0.0,0.0,0.0) + Dual{ForwardDiff.Tag{var"#138#139",Int64}}(0.0,0.0,0.0,0.0)im
...

```

I am not really sure what happend there. When I use a real function for the Jacobian I get the expected output.

```julia
f(θ,i,u) = [i * exp(-θ), u * exp(-θ)]

z = [10,1,1]
ForwardDiff.jacobian(x -> f(x[1],x[2],x[3]), z)

2×3 Array{Float64,2}:
 -4.53999e-5 4.53999e-5 0.0       
 -4.53999e-5 0.0 4.53999e-5

```

Then after reading: [Automatic differentiation of complex valued functions](https://discourse.julialang.org/t/automatic-differentiation-of-complex-valued-functions/30263), I am surprised that the complex function worked at all…
