# Automatic Differentiation: Second-order partial derivatives w.r.t. different arguments

**URL:** https://discourse.julialang.org/t/automatic-differentiation-second-order-partial-derivatives-w-r-t-different-arguments/109108
**Category:** Modelling & Simulations
**Created:** [January 22, 2024, 4:13pm UTC](https://discourse.julialang.org/t/automatic-differentiation-second-order-partial-derivatives-w-r-t-different-arguments/109108 "2024-01-22T16:13:27Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Tengrath](https://avatars.discourse-cdn.com/v4/letter/t/c77e96/32.png) [@Tengrath](https://discourse.julialang.org/u/Tengrath)
#### Post date: [January 22, 2024, 4:13pm UTC](https://discourse.julialang.org/t/automatic-differentiation-second-order-partial-derivatives-w-r-t-different-arguments/109108/1 "2024-01-22T16:13:27Z")

</div>

I’m interested in calculating second order partial derivatives w.r.t. to different arguments \partial k\_j \partial x\_i f.  
Consider

```julia
function f(x,k)
    return @. k * x^2
end

```

Calculation of second-order derivatives w.r.t. the same variable \partial x\_j \partial x\_i works well by a combination of **ForwardDiff.jl** and **Zygote.jl**.  
A naive approach to get \partial k\_j \partial x\_i f

```julia
der(x,k) = ForwardDiff.jacobian((x)->f(x,k), x)
Zygote.jacobian(der, x, k)

```

fails as Zygote apparently cannot deal with closures

> ┌ Warning: `ForwardDiff.jacobian(f, x)` within Zygote cannot track gradients with respect to `f`,  
> │ and `f` appears to be a closure, or a struct with fields (according to `issingletontype(typeof(f))`).  
> │ typeof(f) = var"#75#76"{Vector{Float64}}  
> └ @ Zygote ~/.julia/packages/Zygote/WOy6z/src/lib/forward.jl:150

Is there any workaround? Can this be achieved by (combinations) of other AD frameworks?
