# Mixed partials

**URL:** <https://discourse.julialang.org/t/mixed-partials/69068>\
**Category:** Performance\
**Tags:** question, forwarddiff\
**Created:** [October 1, 2021, 6:39pm UTC](https://discourse.julialang.org/t/mixed-partials/69068 "2021-10-01T18:39:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![prittjam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/prittjam/32/21267_2.png) [@prittjam](https://discourse.julialang.org/u/prittjam)\
**Post date:** [October 1, 2021, 6:39pm UTC](https://discourse.julialang.org/t/mixed-partials/69068/1 "2021-10-01T18:39:12Z")

</div>

Suppose that I have a scalar function of multiple variables, e.g., z = f(x,y)

How can I compute mixed partials using ForwardDiff? E.g., suppose that I want

d^2f/dxdy

The case for the hessian, it is clear, e.g.,

d^2f/dx^2

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [October 1, 2021, 9:29pm UTC](https://discourse.julialang.org/t/mixed-partials/69068/2 "2021-10-01T21:29:11Z")

</div>

You can use `ForwardDiff.hessian` for this.

```julia
julia> using ForwardDiff

julia> f(x, y) = (x + 2y)^2 * (x - y)
f (generic function with 1 method)

julia> ForwardDiff.hessian(((x, y),) -> f(x,y), [1,2])
2×2 Matrix{Int64}:
 18 6
  6 -48

```
