residual = zeros(length(cvec))
creates an array of Float64 which is not Dual type. create the vector as zeros(eltype(cvec), length(cvec))
residual = zeros(length(cvec))
creates an array of Float64 which is not Dual type. create the vector as zeros(eltype(cvec), length(cvec))