Quantcast
Viewing all articles
Browse latest Browse all 14185

Error while treating data with curve_fit : " RuntimeError: Optimal parameters not found: The maximum number of function evaluations is exceeded."

I have to do an homework on Python, and I'm getting the error :

RuntimeError: Optimal parameters not found: The maximum number of function evaluations is exceeded." while treating data.

So, I just understand that it was coming from the function curve_fit. But I can't understand what is wrong with my data.

Here is the program :

%matplotlib inline# Packagesimport numpy as npimport matplotlib.pyplot as pltfrom scipy.optimize import curve_fitimport pandas as pdimport csvplt.rcParams.update({'font.size': 12})## Birch-Murnaghan EOSdef BM(V,K0,Kp0,V0):    return 3/2*K0*((V0/V)**(7/3)-(V0/V)**(5/3))*(1-3/4*(4-Kp0)*((V0/V)**(2/3)-1))data = pd.read_excel("data1.xlsx")P = data['P'].to_numpy()V = data['V'].to_numpy()popt, pcov = curve_fit(BM, V, P, p0 = [100,4,200],bounds=(0,np.inf))K0 = popt[0]Kp0 = popt[1]V0 = popt[2]print('Fitted parameters:')print('K0=',K0, 'GPa')print('Kp0=',Kp0)print('V0=',V0)V_fit = np.linspace(135,175,500)plt.plot(V,P,'d',color='tab:blue')plt.plot(V_fit,BM(V_fit,*popt),color='tab:blue')plt.grid(True)plt.xlabel('V ()')plt.ylabel('P (Gpa)')

And the data I have to fit :

Data 1 with high temperature samples, Name : DataHT

P;V26,53;149,342573528,52;147,56872131;147,766779943,17;142,445548943,48;142,226488343,9;141,196916445,11;141,850781145,9;141,757037147,49;140,846366448,33;140,808186649,51;140,669427249,59;140,50661649,59;140,784371754,33;138,9670569

Data 2 with high temperature samples, Name : DataLT

P;V32,55;149,444513645,81;143,968544952,88;142,889576856,14;141,488746747,34;144,470003251,52;143,159580534,88;150,135042548,72;143,932747157,53;141,383125255,73;142,169059837,46;149,731737440,26;150,2580983

I understood that I have to change the Name of the data file I import, but I don't get why do I get an error.


Viewing all articles
Browse latest Browse all 14185

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>