Sep-25-2020, 01:34 PM
Curve fitting and plotting
import numpy as np from scipy.optimize import curve_fit import matplotlib.pyplot as plt x = [20,40,80,160] # nr of beads (N) y = [66.7,193,549,1555] # simulation data ree2 def ree(x, a, v): # ree = a*N**v return a*x**v popt, pcov = curve_fit(ree, x, y) # solves variable a and v a,v = popt # v here is 2v plt.title('High temperature polymer size') plt.xlabel('nr of beads (N)') plt.ylabel('r2/a2') plt.yscale("log") plt.xscale("log") plt.plot(x, y , "*",c='black') # plots discrete points plt.grid(True,which="both",ls="-") xrange = np.array([10,100,1000]) yrange = a*xrange**v plt.plot(xrange, yrange,c='black') # plots solution of curve fit print("Parameter v is", popt[1]/2)