How to find second and third derivative using ForwardDiff

#1

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

using ForwardDiff

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

#2
ForwardDiff.derivative(x -> ForwardDiff.derivative(f, x), 1.0)
3 Likes

#3

It works thank you.

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

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
0 Likes