Majkl
Majkl

Reputation: 1

Fitting exponential function in GNUPLOT

I have a problem fitting an exponentional function f(x)= Aexp(-bx)sin(2pi*x/T + phi) + S

data

it kept being a straight line then I tried giving it some values for A, b, T, phi, S and it became something closer to the data but still shite

Upvotes: 0

Views: 274

Answers (2)

JJacquelin
JJacquelin

Reputation: 1705

The non-linear regression calculus is iterative starting from "guessed" initial values of the parameters. Especially when the model involves sinusoidal functions the key point is to start with guessed values close enough to the correct values which are not known.

Probably your difficulty is to guess good enough values (or the difficulty of the software to try some initial good enough values).

A non-conventional method which is not iterative and which doesn't need initial values is explained in this paper : https://fr.scribd.com/doc/14674814/Regressions-et-equations-integrales. The application of this method in the present case is shown below :

enter image description here

enter image description here

If more accuracy is wanted one have to try a non-linear regression (with an available software). Using the numerical values of the parameters found above as inital values increases the chances of good convergence.

Upvotes: 0

DanielTuzes
DanielTuzes

Reputation: 2754

Multidimensional fitting is very non-trivial and algorithms often fail on this one. Try to help the algorithm by giving a better initial guess. You can also try to fit variables 1 by 1, e.g., the average S first, then the periodic length, then this 2 together, etc.

Please also provide how you tried to fit the function and which version of Gnuplot you used. If the 3rd column consists of 0s and you provided it as error values for fit in Gnuplot v4, fit completely fails.

On this given set of data, using a bad guess, the fit fails. But a better guess can succeed:

f(x)=A*exp(-b*x)*sin(2.*pi*x/T+phi)+S

    A = 40.
    b = 1/500.
    T = 400.
    phi = 1.
    S = 170.

f_bad_guess(x) = 40. * exp(-x/500.) * sin(2.*pi*x/150+3.) + 170.
f_good_guess(x) = 40. * exp(-x/500.) * sin(2.*pi*x/400+1.) + 170.

fit f(x) "data.txt" via A,b,T,phi,S

p "data.txt" t "data", f(x) t "fitted function", f_good_guess(x) t "good initial guess set manually", f_bad_guess(x) t "bad initial guess set manually"

enter image description here

Upvotes: 1

Related Questions