Hello,

I have been trying Julia out today. In particular, I have been playing 
around with fitting some data with LsqFit.

However, it's not working as well as I would have hoped.

Here is the code and the two data files and the output figure are attached:

using LsqFit
using PyPlot

model(x, p) = p[1]./x + p[2]./x.^2

xdata = readdlm("gridx.dat")
ydata = readdlm("F1.dat")

fit = curve_fit(model, xdata[1:end], ydata[1:end], [0.5, 0.5])
println(fit.param)
errors = estimate_errors(fit, 0.95)
println(errors)


plot(xdata,ydata,color="blue")
xlim(0,120)
plot(xdata,model(xdata, fit.param),color="green")
savefig("lsq.png")


Playing around with the model itself does do something. For example, as 
this code is basically just the one from the readme file of LsqFit, I tried:

model(x, p) = p[1]*exp(-x.*p[2])

which is used there. It does fit somewhat better but not quite. I ran the 
same thing in Mathematica and obtained:

p[1]: 0.229263
p[2]: -0.0949777

which gets most of the curve right. Am I missing something in trying to fit 
this curve to the data or are there any particular tricks to use with 
curve_fit that I should know about?

Best regards,
Helgi

Attachment: F1.dat
Description: Binary data

Attachment: gridx.dat
Description: Binary data

Reply via email to