1
votes

I am currently trying to use gnuplot to fit the a simple data set using the beneath commands, however I am having no luck despite including good initial guesses.

Commands:

gnuplot> f(x) = 1/(2*pi) * 1/m1 * 1/(b + x**2)**(-3/2)
gnuplot> m1 = 150
gnuplot> m2 = 17
gnuplot> fit f(x) "data.txt" using 1:2 via m1, m2

Data (x:y):

2   1.2643E-05
3   7.90515E-06
4   5.67976E-06
5   4.70381E-06
6   3.65957E-06
7   2.69824E-06
8   2.06054E-06
9   1.52311E-06
10  1.0627E-06
11  7.88733E-07
12  5.89984E-07
13  4.70111E-07
14  3.62744E-07
15  2.48113E-07
16  1.84463E-07
17  1.28446E-07
18  1.09519E-07
19  9.40524E-08
20  8.20673E-08

However gnuplot returns m1 = 2.45e14 and m2 = 3.64e9 which are simply incorrect and huge compared to the (roughly correct) initial values

I have tried using the exact same data set and fitting function in KaleidaGraph (demo version) which does return correct results (as per below picture) and could use this if gnuplot will not work, however I would prefer to use gnuplot as I will be able to automate the process for many data files then as I do not believe that KaleidaGraphs has a command line terminal.

KaleidaGraph fit

Does anyone know why gnuplot is returning such wild values?

(If it helps I'm using Windows 8.1 x64)

Many thanks for all help, James

1

1 Answers

3
votes

Two things: Gnuplot does integer division, so you must use 3/2.0 to get the correct exponent.

Second, the function in gnuplot is not the same as the one used in KaleidaGraph: The exponent must be positive (3/2.0) and you must use m2 where you have b:

f(x) = 1/(2*pi) * 1/m1 * 1/(m2 + x**2)**(3/2.0)
m1 = 150
m2 = 17
fit f(x) "data.txt" using 1:2 via m1,m2

That gives:

...
Final set of parameters            Asymptotic Standard Error
=======================            ==========================

m1              = 127.11           +/- 11.31        (8.898%)
m2              = 18.1347          +/- 1.54         (8.492%)