Следующий код в Юлии строит кривую Лоренца, а затем использует функцию curve_fit для определения параметров.
using LsqFit
model(x,p)=p[1] ./(p[1]^2 .+(x .-p[2]).^2)
#Test values
p0=[10,50]
tdata=range(-150,stop=150,length=300)
ydata = model(tdata, p0)
fit=curve_fit(model,tdata,ydata,p0)
В этом случае результат должен быть точным, поскольку я использую модель для вычисления значений y, а затем передаю эти точные значения y в функцию curve_fit. Тем не менее, Джулия возвращает ошибку:
InexactError: Int64(NaN)
Int64(::Float64) at float.jl:710
x_of_nans(::Array{Int64,1}, ::Type{T} where T) at NLSolversBase.jl:60
x_of_nans(::Array{Int64,1}) at NLSolversBase.jl:60
NLSolversBase.OnceDifferentiable(::Function, ::Function, ::Function, ::Array{Int64,1}, ::Array{Float64,1}, ::Array{Float64,2}; inplace::Bool) at oncedifferentiable.jl:229
NLSolversBase.OnceDifferentiable(::Function, ::Function, ::Function, ::Array{Int64,1}, ::Array{Float64,1}, ::Array{Float64,2}) at oncedifferentiable.jl:225
NLSolversBase.OnceDifferentiable(::NLSolversBase.var"#ff!#1"{LsqFit.var"#18#20"{typeof(model),StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}},Array{Float64,1}}}, ::Array{Int64,1}, ::Array{Float64,1}, ::Array{Float64,2}, ::Symbol, ::ForwardDiff.Chunk{2}) at oncedifferentiable.jl:147
NLSolversBase.OnceDifferentiable(::Function, ::Array{Int64,1}, ::Array{Float64,1}, ::Array{Float64,2}, ::Symbol) at oncedifferentiable.jl:96
NLSolversBase.OnceDifferentiable(::Function, ::Array{Int64,1}, ::Array{Float64,1}, ::Array{Float64,2}; inplace::Bool, autodiff::Symbol) at oncedifferentiable.jl:28
(::Core.var"#Type##kw")(::NamedTuple{(:inplace, :autodiff),Tuple{Bool,Symbol}}, ::Type{NLSolversBase.OnceDifferentiable}, ::Function, ::Array{Int64,1}, ::Array{Float64,1}, ::Array{Float64,2}) at oncedifferentiable.jl:26
(::Core.var"#Type##kw")(::NamedTuple{(:inplace, :autodiff),Tuple{Bool,Symbol}}, ::Type{NLSolversBase.OnceDifferentiable}, ::Function, ::Array{Int64,1}, ::Array{Float64,1}) at oncedifferentiable.jl:26
lmfit(::LsqFit.var"#18#20"{typeof(model),StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}},Array{Float64,1}}, ::Array{Int64,1}, ::Array{Float64,1}; autodiff::Symbol, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at curve_fit.jl:63
lmfit(::Function, ::Array{Int64,1}, ::Array{Float64,1}) at curve_fit.jl:61
curve_fit(::typeof(model), ::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}, ::Array{Float64,1}, ::Array{Int64,1}; inplace::Bool, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at curve_fit.jl:115
curve_fit(::Function, ::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}, ::Array{Float64,1}, ::Array{Int64,1}) at curve_fit.jl:106
top-level scope at mcconnel_simulation.jl:71
Почему функция curve_fit не может решить этот простой случай?