curve fitting exponential function python

232 Views Asked by At

I need to apply curve fitting (look at the graph). However, I am struggling to find the initial parameters based on a visual (looking at the plot). So how do I now which value to pick for a, b or c. Do you have any doc that I could read?

graph

I am trying to implement this equation:

def func(t, a, b, c):   
    t0 = new_time[maximum_force_index]
    return a*np.exp(-b*(t-t0))+c

as well as curve fitting

popt, pcov = curve_fit(func, t, f)
1

There are 1 best solutions below

3
JJacquelin On

Note that your model equation y = a * exp(-b * (t-t0)) + c is not well written because the four parameters a, b, t0 , c are not independent.

y = a * exp(-b * (t-t0)) + c = A * exp(-b*t) + c where A = a * exp(b * t0) which is a relationship between the parameters likely to cause trouble in nonlinear regression.

They are only three independant parameters. Better choose the equation model y = a *exp(-b * x) + c or equivalently y = exp(-b * (x-t0)) + c with a = exp(b * t0).

If you have some difficulties to guess initial values of the parameters in order to start an iterative nonlinear regression you can use another method which isn't iterative and doesn't requires initial values.

The general principle is explained in https://fr.scribd.com/doc/14674814/Regressions-et-equations-integrales

Un example of numerical calculus is shown below.

In order to make the example easier to copy and reproduce only 20 points where taken among your points. Moreover without your data on numerical form the points where taken by graphical scanning from the figure published in the question. This is not accurate and will probably not give good results.

The page below is the screen copy of the page from MathCad sofware.

enter image description here

You could proceed on the same manner with your full data. The values that you will get could be used as very good initial values for any usual nonlinear regression software.

Be carefull with the notations a, b, c, which are not the same above than the notations in your question.

IN ADDITION :

A better fitting is obtained with an equation model made of two exponentials.

enter image description here

Blue curve : Fitted function.

Red points : Comming from scanning the pixels (2399 points) on the graph pubished by Magdalena Rodríguez in the question.

Equivalent equation (same blue curve) :

enter image description here