I am trying to use Optim to find parameters of a vector valued function using the Nelder-Mead algorithm, but open to considering other algorithms or packages. The problem is to find parameters of a function by minimizing the sum of squares. I am getting the error message below.
Any ideas on what is wrong with the code below or any other algorithms/packages that will be more suitable?
using Optim
function curvefunc(T, beta0, beta1, beta2, beta3, lambda0, lambda1)
xp1 = (1 - exp.(-T ./ lambda0)) ./ (T ./ lambda0)
xp2 = alpha1 - exp.(-T ./ lambda0)
xp3 = (1 - exp.(-T ./ lambda1)) ./ (T ./ lambda1) - exp.(-T ./ lambda1)
return beta0 + beta1*xp1 + beta2*xp2 + beta3*xp3
end
function curvfit(T, Data)
result = Optim.optimize(sum((curvefunc(T, Data, beta0, beta1, beta2, beta3, lambda0, lambda1)-Data).^2),zeros(6), NelderMead())
end
T = [0.5, 1.0, 2.0, 3.0, 4.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0]
Data = [0.011, 0.013, 0.016, 0.019, 0.021, 0.026, 0.03, 0.035, 0.037, 0.038, 0.04]
This gives the following error message:
curvfit(T, Data)
ERROR: MethodError: no method matching curvefunc(::Vector{Float64}, ::Vector{Float64}, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64)
Closest candidates are:
curvefunc(::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any)