using XLSX, DataFrames, LsqFit
df = DataFrame(XLSX.readtable("SMB.xlsx","平衡吸附量", infer_eltypes = true))
function Com_Langmuir(p, x)
Ha, bA, bC, Hc = p
CA = @view x[:, 1]
CC = @view x[:, 2]
@. qA = Ha*CA / (1 + bA*CA + bC*CC)
@. qC = Hc*CC / (1 + bA*CA + bC*CC)
vcat(qA, qC) #返回一个列向量
end
xdata = [df.CA df.CC]
ydata = vcat(df.qA_303K, df.qC_303K)
p0 = [1.983, 0.0067, 0.1951, 1.61]
ret = curve_fit(Com_Langmuir, xdata, ydata, p0)
ERROR: BoundsError: attempt to access 4-element Vector{Float64} at index [1:4, 2]
Stacktrace:
[1] throw_boundserror(A::Vector{Float64}, I::Tuple{Base.Slice{Base.OneTo{Int64}}, Int64}) @ Base .\abstractarray.jl:737
[2] checkbounds
@ .\abstractarray.jl:702 [inlined]
[3] view
@ .\subarray.jl:184 [inlined]
[4] Com_Langmuir(p::Matrix{Float64}, x::Vector{Float64})
@ Main e:\06325\Julialang\test.jl:30
[5] #18
@ C:\Users\admin\.julia\packages\LsqFit\OglWj\src\curve_fit.jl:139 [inlined]
[6] lmfit(f::LsqFit.var"#18#20"{…}, p0::Vector{…}, wt::Vector{…}; autodiff::Symbol, kwargs::@Kwargs{})
@ LsqFit C:\Users\admin\.julia\packages\LsqFit\OglWj\src\curve_fit.jl:69
[7] lmfit
@ C:\Users\admin\.julia\packages\LsqFit\OglWj\src\curve_fit.jl:54 [inlined]
[8] curve_fit(model::typeof(Com_Langmuir), xdata::Matrix{…}, ydata::Vector{…}, p0::Vector{…}; inplace::Bool, kwargs::@Kwargs{})
@ LsqFit C:\Users\admin\.julia\packages\LsqFit\OglWj\src\curve_fit.jl:140
[9] curve_fit(model::Function, xdata::Matrix{Float64}, ydata::Vector{Float64}, p0::Vector{Float64})
@ LsqFit C:\Users\admin\.julia\packages\LsqFit\OglWj\src\curve_fit.jl:123
[10] top-level scope
@ e:\06325\Julialang\test.jl:42
Some type information was truncated. Use `show(err)` to see complete types.
In this function,there is two variables: CA & CC, both are vectors, what syntax should I use?