# Multivariate Rootfinding: problem with NLsolve (dual numbers not applicable for a function I am using)

**URL:** <https://discourse.julialang.org/t/multivariate-rootfinding-problem-with-nlsolve-dual-numbers-not-applicable-for-a-function-i-am-using/27844>\
**Category:** General Usage\
**Created:** [August 22, 2019, 1:49pm UTC](https://discourse.julialang.org/t/multivariate-rootfinding-problem-with-nlsolve-dual-numbers-not-applicable-for-a-function-i-am-using/27844 "2019-08-22T13:49:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![IljaK91](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iljak91/32/44301_2.png) [@IljaK91](https://discourse.julialang.org/u/IljaK91)\
**Post date:** [August 22, 2019, 1:49pm UTC](https://discourse.julialang.org/t/multivariate-rootfinding-problem-with-nlsolve-dual-numbers-not-applicable-for-a-function-i-am-using/27844/1 "2019-08-22T13:49:35Z")

</div>

Hi there,

I have a multivariate rootfinding problem, where one of the functions utilizes `QuantEcon.jl`’s `qnwnorm` which generates the nodes for the Gauss-Hermite quadrature. However, using `NLsolve` on one of the parameters that is an input to `qnwnorm` throws an error, as `qnwnorm` tries to transform the dual number to a `Float64`, which fails.

A admittedly contrived MWE would be something like this:

```julia
using QuantEcon, NLsolve

function f!(res, x)
    nodes, weights = qnwnorm(10,x[1],1)
    res[1] = x[1] + x[2] - 3.5
    res[2] = mean(nodes) - 1
    return res
end

nlsolve(f!, [1., 1.], autodiff = :forward)

```

which throws

```julia
MethodError: no method matching Float64(::ForwardDiff.Dual{ForwardDiff.Tag{typeof(f!),Float64},Float64,2})
Closest candidates are:
  Float64(::Real, !Matched::RoundingMode) where T<:AbstractFloat at rounding.jl:194
  Float64(::T<:Number) where T<:Number at boot.jl:718
  Float64(!Matched::Int8) at float.jl:60
  ...

```

Is there a different solver/package in Julia that can handle these kinds of problems?

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [August 22, 2019, 2:30pm UTC](https://discourse.julialang.org/t/multivariate-rootfinding-problem-with-nlsolve-dual-numbers-not-applicable-for-a-function-i-am-using/27844/2 "2019-08-22T14:30:08Z")

</div>

You chopped off the important parts of the error message, so it’s hard to know what’s going on here. But it looks like it’s your function which isn’t AD-compatible, so turn off AD. No change of a rootfinding library would fix that because it’s based on the functions you’re using in `f!`.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [August 22, 2019, 8:25pm UTC](https://discourse.julialang.org/t/multivariate-rootfinding-problem-with-nlsolve-dual-numbers-not-applicable-for-a-function-i-am-using/27844/3 "2019-08-22T20:25:09Z")

</div>

Also consider using one of my all-time favourite packages [GitHub - JuliaApproximation/FastGaussQuadrature.jl: Julia package for Gaussian quadrature](https://github.com/JuliaApproximation/FastGaussQuadrature.jl)
