0
votes

I am trying to fit some data using gnuplot.

Here is the data (variables h, k,l and I):

#h  k   l   I

2   1   1   7807
2   2   0   9664
3   2   1   6042
4   0   0   1394
3   3   2   1358
4   2   0   4896

### Function
I(h,k,l) = M * (F * ( (sin(A*pi*sqrt(h*h+k*k+l*l)*L))/(A*2*pi*sqrt(h*h+k*k+l*l)) ))^2

### Initial values
M=1
F=0.5
A=1
L=1

### Fitting 
fit I(h,k,l) "cavendish.data" using 1:2:3 via M, F, A, L

I want to determine the constants M,F,A and L from this fitting.

When I run this code I get message undefined variable: h

How can I could determine the variables. Thanks in advance.

1
You don't have three variables, but one: the quadratic mean of h,k,l, that you should move from I(h,k,l) to the using statement. And your initial values seem to be way off, the fit converges far away on something that does not look very cystallographic. ;-) - Karl

1 Answers

1
votes

Try using a recent version of gnuplot (>= 5.0), which supports fit commands with more than two variables (see release notes). Also note, that the power operator in gnuplot is ** and not ^.

You're example has to be changed slightly to work:

### Function
I(h,k,l) = M * (F * ((sin(A*pi*sqrt(h*h+k*k+l*l)*L))/(A*2*pi*sqrt(h*h+k*k+l*l)) ))**2

### Initial values
M=1.0
F=0.5
A=1.0
L=1.0

### Fitting
set dummy h, k, l
fit I(h,k,l) "cavendish.data" using 1:2:3:4 via M, F, A, L