# ForwardDiff for functions of several (vector) variables?

**URL:** https://discourse.julialang.org/t/forwarddiff-for-functions-of-several-vector-variables/22918
**Category:** Modelling & Simulations
**Tags:** question
**Created:** [April 8, 2019, 12:58pm UTC](https://discourse.julialang.org/t/forwarddiff-for-functions-of-several-vector-variables/22918 "2019-04-08T12:58:40Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![zdenek\_hurak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zdenek_hurak/32/53118_2.png) [@zdenek\_hurak](https://discourse.julialang.org/u/zdenek_hurak)
#### Post date: [April 8, 2019, 12:58pm UTC](https://discourse.julialang.org/t/forwarddiff-for-functions-of-several-vector-variables/22918/1 "2019-04-08T12:58:40Z")

</div>

Is it possible to use ForwardDiff for functions of several variables? In particular, consider a scalar function L( **x** , **u** ) of two vector variables **x** and **u**. I want to compute the gradient of L() with respect to **x**.

From the documentation it appears that currently ForwardDiff can only compute derivatives and gradients for functions of a single (vector) variable. Any way?

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [April 8, 2019, 1:11pm UTC](https://discourse.julialang.org/t/forwarddiff-for-functions-of-several-vector-variables/22918/2 "2019-04-08T13:11:49Z")

</div>

Pass `x -> L(x, u)` to ForwardDiff.

---

<div class="post-metadata">

### Author: ![zdenek\_hurak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zdenek_hurak/32/53118_2.png) [@zdenek\_hurak](https://discourse.julialang.org/u/zdenek_hurak)
#### Post date: [April 10, 2019, 1:42pm UTC](https://discourse.julialang.org/t/forwarddiff-for-functions-of-several-vector-variables/22918/3 "2019-04-10T13:42:17Z")

</div>

Many thanks. Besides having my question answered, I think that I am now significantly closer to understanding anonymous functions in Julia.
