Skip to content
Advertisement

Using curve_fit to a function defined by indefinite integral in Python

I’m trying to make a code to fit 2 curves with 5 parameters to real data. They are shown here:

enter image description here

The first curve only depends on a,b and gamma. So I decided to use curve_fit once to these 3 (which works) and then use it again on the second curve to adjust the last two alpha and k_0.

Problem is that the second is defined by this indefinite integral and i can’t code it properly. I have tried to treat x as a symbol and integrate using sym.integrate and just integrate normally with quad. Neither worked. In the second case, I get “ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()” in “mortes” function.

JavaScript

Advertisement

Answer

The upper bound of an integral (integrate.quad) has to be a float, not an array as your x (argument of mortes()):

In this way it should work:

JavaScript

p.s. Elegant editions of the code style are more than welcomed (like allowing passing an array to upper and lower bounds of integrate.quad ).

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