MethodError: no method matching Float64(::ForwardDiff.Dual{ForwardDiff.Tag{DifferentiationInterface.FixTail{…}, Float64}, Float64, 3})

Welcome to the Julia Discourse!

This error occurs when you are trying to autodiff a function that has not been written in a way that autodiff can use. In this case, the error should be arising from one of the V[i] = ... lines. This happens because V = zeros(9)::Vector{Float64}. ForwardDiff works by replacing real numbers (like Float64) with ForwardDiff.Dual numbers. The assignment of a Dual to a Float64 fails and so you get this error.

In this case, I would suggest you try replacing the array V with V = zeros(eltype(dx), 9)so that the array has an appropriate element type. Even better (in this case), you might replace V with individual variables (i.e., V1 = k[1], V2 = (k[2]*K[1]^n[1])/(K[1]^n[1]+x[3]^n[1]), …) since there’s no need for these to be an array.

4 Likes