It works fine for me. Since you don’t give example data, I generated some:
fx(x) = 1.5 - 1.3 / (1. + (x/0.7)^1.3)
xdata = range(0,3,length=50)
ydata = fx.(xdata).*(1 .+0.1randn(50))
Next, doing model fitting:
julia> @. H(x,p) = p - (p-p) / ( 1. + (x/p)^p )
julia> Hfit = LsqFit.curve_fit(H,xdata,ydata,[1.,0.,0.5,1.],lower=[0.,0.,0.,1.])
julia> par = coef(Hfit)
julia> plot!(xdata,x-> par - (par-par)/(1+(x/par)^par),label="fitted model",legend=:bottomright)
Of course, if you have negative elements in
xdata, you will have problems as
x/p will be negative, and raising this to a number that is not an even integer will produce a complex number.
Another problem is that you allow
p to have zero as lower bound, hence allows the fitting algorithm to divide by zero in
So, I’d check the minimal value in
xdata, and change the lower value of
1e-2 or something.
You do indicate that
xdata contains concentrations, which should be positive at the outset. Maybe there are some errors in the measurements so that some of them are (slightly) negative??