# How to find second and third derivative using ForwardDiff

**URL:** <https://discourse.julialang.org/t/how-to-find-second-and-third-derivative-using-forwarddiff/20964>\
**Category:** New to Julia\
**Created:** [February 19, 2019, 3:51am UTC](https://discourse.julialang.org/t/how-to-find-second-and-third-derivative-using-forwarddiff/20964 "2019-02-19T03:51:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)\
**Post date:** [February 19, 2019, 3:51am UTC](https://discourse.julialang.org/t/how-to-find-second-and-third-derivative-using-forwarddiff/20964/1 "2019-02-19T03:51:21Z")

</div>

How do I find the second and third derivative using ForwardDiff

I can find the first derivative 14.0 at x = 1.0 using the following

```julia
using ForwardDiff

f(x) = 7*x^2
result = ForwardDiff.derivative(f,1.0)
println( "first derivative is ",result )

```

---

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [February 19, 2019, 4:33am UTC](https://discourse.julialang.org/t/how-to-find-second-and-third-derivative-using-forwarddiff/20964/2 "2019-02-19T04:33:11Z")

</div>

```julia
ForwardDiff.derivative(x -> ForwardDiff.derivative(f, x), 1.0)

```

---

<div class="post-metadata">

**Author:** ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)\
**Post date:** [February 19, 2019, 5:56am UTC](https://discourse.julialang.org/t/how-to-find-second-and-third-derivative-using-forwarddiff/20964/3 "2019-02-19T05:56:30Z")

</div>

> [@tkoolen](#):
>
> ForwardDiff.derivative(x -\> ForwardDiff.derivative(f, x), 1.0)

It works thank you.

```julia
using ForwardDiff

f(x) = 7*x^3
result = ForwardDiff.derivative(f,1.0)
println( "first derivative is ",result )
result2 = ForwardDiff.derivative(x -> ForwardDiff.derivative(f, x), 1.0)
println( "second derivative is ",result2 )

```

Output

```julia
Starting Julia...
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _ | |
  | | |_| | | | (_| | | Version 1.0.3 (2018-12-18)
 _/ |\ ___|_|_|\__ _| | Official https://julialang.org/ release
|__/ |

first derivative is 21.0
second derivative is 42.0

```
