|
|
import matplotlib.pyplot as pltfrom scipy.optimize import curve_fitimport numpy as numpy
#Fitting funtiondef func(x, a, b) return a*np.exp(b*x) #return a*x+b
#Experimental x and y data pointsxData = np.array([1,2,3,4,5])yData = np.array([1, 9, 50, 300, 1500])
#Plot experimental data pointsplt.plot(xData, yData, 'bo', label='experimeatal-data')
# Initial guess for the parameters#initialGuess = [1, 0, 1, 0]
#Perform the curve-fitpopt, pcov = curve_fit(func, xData, yData, initialGuess)print(popt)
#x values for the fitted functionxFit = np.arange(0.0, 5.0, 0.01)
#Plot the fitted functionplt.plot(xFit, func(xFit, *popt), 'r', label= 'fit params: a= %5.3f, b=%5.3f' %tuple(popt))
plt.xlabel('x')plt.ylabel('y')plt.legend()plt.show()
|