To fit the non-linear function with other data, I am trying to use the ‘LsqFit.curve_fit’ which was introduced by the following link: GitHub - JuliaNLSolvers/LsqFit.jl: Simple curve fitting in Julia
here is toy example:
using DelimitedFiles, Plots, Serialization, Transducers, Match, LsqFit, Dierckx
#meta=deserialize("meta_SPS.bin");
meta=rand(55,27,150) #same type with real meta
#Fv_NOC=deserialize("Fv_NOC.bin");
Fv_NOC=rand(200,3,55) #same type with real meta
meta_start=395; meta_end=400; meta_div=trunc(Int,((meta_end-meta_start)*100)); #
meta_cal=LinRange(meta_start,meta_end,meta_div);
I_sharp=Array{Float64,2}(undef,150,27);
I_broad=zeros(Float64, meta_div)
obs_metaq=LinRange(394,402,205); obs_Iq=LinRange(100,1000,205);
function OTrans(meta, meta_shift, Holn, Fv_NOC, p)
Translation=p
for brazera=1:27;
for J1=1:150
I_sharp[J1,brazera]=(1/(meta[J1,brazera,numb_v].-meta_shift[numb_v])^4)*Holn[J1,brazera]*exp(-2.2/Translation)
I_broad.+= I_sharp[J1,brazera].*exp.(-2 .*( meta_cal .-(meta[J1,brazera,numb_v])).^2)
end
end
return I_broad
end
interpolation=Spline1D(obs_metaq, obs_Iq, k=1)
Int_Iq=interpolation(meta_cal) #Finding query points
p0=Float64.([300])
fit=LsqFit.curve_fit(OTrans,meta_cal,Int_Iq,p0)
I made a code similar to the example introduced, but it didn’t work leaving an error like the following message:
ERROR: MethodError: no method matching OTrans(::LinRange{Float64, Int64}, ::Vector{Float64})
Closest candidates are:
OTrans(::Any) at Toy_example.jl:48
Stacktrace:
[1] (::LsqFit.var"#18#20"{typeof(OTrans), LinRange{Float64, Int64}, Vector{Float64}})(p::Vector{Float64})
How can I get this to work? or any other method?