user1763328
user1763328

Reputation: 311

Fitting exponent with gnuplot

I am trying to fit the beneath data to the form - I am most interested in 'c' (I know that c ≈ 1/8, b ≈ 3) but would like to extract all these values from the data.

Formula:

y = a*(x-b)**c

Values.txt:

# "values.txt"
2.000000e+00    6.058411e-04
2.200000e+00    5.335520e-04 
2.400000e+00    3.509583e-03
2.600000e+00    1.655943e-03
2.800000e+00    1.995418e-03
3.000000e+00    9.437851e-04
3.200000e+00    5.516159e-04
3.400000e+00    6.765981e-04
3.600000e+00    3.860859e-04
3.800000e+00    2.942881e-04
4.000000e+00    5.039975e-04
4.200000e+00    3.962199e-04
4.400000e+00    4.659717e-04
4.600000e+00    2.892683e-04
4.800000e+00    2.248839e-04
5.000000e+00    2.536980e-04

I have tried using the following commands in gnuplot however I am not meaningful results

f(x) = a*(x-b)**c
b = 3
c = 1/8
fit f(x) "values.txt" via a,b,c

Does anyone know the best way to extract these values? I would rather not provide initial guesses for 'b' & 'c' if possible.

Thanks, J

Upvotes: 1

Views: 2226

Answers (1)

Miguel
Miguel

Reputation: 7627

The main problem with your fitting function is finding b. You can express your equation as a linear function in log(x-b), after which the fitting is trivial:

b = 3
f(x) = c0 + c1 * x
fit f(x) "values.txt" using (log($1-b)):(log($2)) via c0, c1
a = exp(c0)
c = c1

As you see, you need to provide b but do not need initial guesses for the other parameters because it's a trivial linear fit.

Now, I would suggest that you provide a series of values of b and check how good the fitting is for each value. gnuplot gives you the error in the fitting parameter. Then you can plot the overall error (error_c0 + error_c1) as a function of b and figure out for which b the error is minimum. About the optimum b the curve error_c0 + error_c1 vs b should be quadratic and have the minimum at b_opt. Then run the fitting as in the code above with this b = b_opt and get a and c.

Upvotes: 3

Related Questions