Hello everybody!
I figured out the answer! Python’s scipy.optimize.curve_fit sets the array of initial parameters to ones if not supplied. LsqFit on the other hand does not try to determine the parameters automagically and thus needs them passed in. SciPy sets the initial parameters all to ones if not passed, so if I set the initial parameters to ones in Julia as well, I get the exact same fit. So the new code looks like -
function fit_terminal_velocity(data::CSV.File)
# Create base model with random initial parameters
p0 = ones(2)
model(t, p) = p[1] .* tanh.(p[2]/p[1] .* t)
# We are fitting v(t), so lets get those values
# We also want to go from t = 0 to t = t_max
t = data.t .- minimum(data.t)
y = data.y
v = diff(y) ./ diff(t)
tv = t[1:end-1]
fitted_model = lsqfit.curve_fit(model, v, tv, p0)
return fitted_model, model
end
(changed rand(2) to ones(2))
Solved!