0

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. ;-) Commented Aug 12, 2015 at 10:32

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

5 Comments

thanks for your kind reply. Although I define dummy variables, I get error like this - (set dummy h, k, l; "./script-curveFitting.sh", line 108: ';' expected).
additional info: The values for # h, k, l and I given at the beginning of my post is the data set I use for this code. The file "cavendish.data" contains these values.
I get the error you desribed only when using old gnuplot versions. Which version do you use?
sorry for late reply . . I use Version 4.6 patchlevel 4 .
As already explained above you need at least version 5.0 to do fitting with more than 2 variables.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.