Skip to content
Advertisement

curve_fit of a summation of functions

For my bachelor’s thesis I need to fit a Generalized Maxwell Function. The function goes as follows:

enter image description here

I get the data (x,y) from a .csv file and use it to curve_fit.

Currently I’m working on a 1st order fit (so i filled the formula in with N = 1 to make it easier for myself). I don’t know how to add extra parts of the summation to my function and fit all the extra parameters as well. I know that N will have a maximum value of 10.

JavaScript

This is some sample data. Sample data

This is the fixed result (after help from SO). Result of the fit

Advertisement

Answer

Rheology! I did my PhD thesis on this, and I fitted many Maxwell models. Here’s my recommendations to you.

First, are both G’ and G” of interest to you, or only G”? I typically had to fit both, and, for better results, the relaxation times and moduli had to be the same on both G’ and G”, so I think you have to change your approach to consider this.

Second, I think that a package like lmfit is better to do this because you have more control over the minimization function.

Third, since n is an integer, I think you have to evaluate your models at n=1, n=2, …, n=10 and check the standard errors of your parameters. Too much is overfitting and too little is underfitting. Can’t really automate this I think.

Let’s first construct some toy data.

JavaScript

Here’s the graph.

Initial

Next, let’s create the parameters to use lmfit.

JavaScript

Then, let’s define the minimization function considering both G’ and G”.

JavaScript

Lastly, let’s call the minimization function. With this approach, you can’t use a varying n, so you have to vary it yourself.

JavaScript

Let’s see the result with n=2.

JavaScript

n=2

n=3 is a perfect fit, so I won’t show it. Here’s the output report of the fit, with lmfit.report_fit(res).

JavaScript

Now, you have to iterate through the other possible n, check the fit parameters and determine which is ideal.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement