# Error using ForwardDiff

**URL:** https://discourse.julialang.org/t/error-using-forwarddiff/5339
**Category:** Numerics
**Created:** [August 11, 2017, 10:13pm UTC](https://discourse.julialang.org/t/error-using-forwarddiff/5339 "2017-08-11T22:13:59Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![vgdev](https://avatars.discourse-cdn.com/v4/letter/v/47e85d/32.png) [@vgdev](https://discourse.julialang.org/u/vgdev)
#### Post date: [August 11, 2017, 10:13pm UTC](https://discourse.julialang.org/t/error-using-forwarddiff/5339/1 "2017-08-11T22:13:59Z")

</div>

Hi, I am new to ForwardDiff. However, I get an error which i cant understand why occurs.

```julia
function get_rho(a)
  return sqrt(2.0*a+1.0)/(a+1.0)
end
@time ForwardDiff.gradient(a ->get_rho(a), -0.43)

```

From the code above I get the following error:

> MethodError: Cannot `convert` an object of type Float64 to an object of type ForwardDiff.GradientConfig  
> This may have arisen from a call to the constructor ForwardDiff.GradientConfig(…),  
> since type constructors fall back to convert methods.  
> gradient(::##23#24, ::Float64) at gradient.jl:6  
> include\_string(::String, ::String) at loading.jl:515  
> include\_string(::String, ::String, ::Int64) at eval.jl:30  
> include\_string(::Module, ::String, ::String, ::Int64, ::Vararg{Int64,N} where N) at eval.jl:34  
> (::Atom.##49#52{String,Int64,String})() at eval.jl:50  
> withpath(::Atom.##49#52{String,Int64,String}, ::String) at utils.jl:30  
> withpath(::Function, ::String) at eval.jl:38  
> macro expansion at eval.jl:49 [inlined]  
> (::Atom.##48#51{Dict{String,Any}})() at task.jl:80

Any help with this, will be highly appreciated 🙂

---

<div class="post-metadata">

### Author: ![aaowens](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aaowens/32/12101_2.png) [@aaowens](https://discourse.julialang.org/u/aaowens)
#### Post date: [August 11, 2017, 10:32pm UTC](https://discourse.julialang.org/t/error-using-forwarddiff/5339/2 "2017-08-11T22:32:20Z")

</div>

`gradient` is for multivariate functions. You can use `derivative`. Also, the anonymous function is unnecessary here.  
This works:

```julia
julia> @time ForwardDiff.derivative(get_rho, -0.43)
  0.000007 seconds (5 allocations: 176 bytes)
3.537160173048399

```
