Dustin Wortmann
Dustin Wortmann

Reputation: 33

Confirmation required: gnuplot does not change intital fit values

after using gnuplot for years and experiencing many user-related issues, I thought I'd finally know how to fit a function to a dataset. Today I tried to fit a simple

y = m * x² + b 

function. However, gnuplot did not change my 'm' value. It does change 'b' to the correct value however. I have my dataset uploaded and here is my gnuplot script with which I'm trying to fit, maybe someone can reproduce this on his machine and confirm, that it is not a fault of my computer but some kind of faulty code in the script, or it may even be a bug (I highly doubt that).

set xtics 0.000001
set format x '%10.1E'
set xrange [0:2E-07]
#fit
f(x)=a*(x**2)+b
a=380812
b=1
fit [0:2E-07] f(x) 'GDAMitte1.txt' using ($1+7.6E-06):2 via a,b

plot 'GDAMitte1.txt' using ($1+7.6E-06):2, f(x)

I've pasted the dataset here: http://www.heypasteit.com/clip/29LU

I'd be very thankful for an answer to that, even if it's just a confirmation, that it doesn't fit on your machine as well. Thank you.

Btw: The initial value I've set is pretty much the one it has to be after the fit, but it's not as exact of course. Should be good enough though for gnuplot to get where to go to.

Upvotes: 0

Views: 457

Answers (1)

Karl
Karl

Reputation: 2187

This is because two parameters are of greatly different magnitude, check help fit tips.

You should replace the function with one that has a prefactor built in:

f(x) = a *1e5 * (x**2)+b
a=3.8 # instead of 380000
b=1
fit ....

From gnuplot version 5.0 on, gnuplot by default internally prescales all parameters, so this problem with calculating the residuals should no longer occur for any function, provided your initial values are not off too much.

Upvotes: 3

Related Questions