Rep:CPlusPlusVsMyDataPolyfit
Appearance
import numpy as np
from matplotlib import pylab as pl
import matplotlib.pyplot as plt
def get_data_HC_vs_T(x):
data_C = np.loadtxt('H:/ImperialChem-Year3CMPExpt-master/C++_data/' + str(x) +'x' + str(x) + '.dat')
T = data_C[:,0]
C = data_C[:,5]/x**2
return T, C
T, C = get_data_HC_vs_T(2)
fit = np.polyfit(T, C, 10) # fit a third order polynomial
T_min = np.min(T)
T_max = np.max(T)
T_range = np.linspace(T_min, T_max, 1000) #generate 1000 evenly spaced points between T_min and T_max
fitted_C_values = np.polyval(fit, T_range) # use the fit object to generate the corresponding values of C
pl.plot(T_range, fitted_C_values, label = str(2) + 'x' + str(2) + 'polyfit')
pl.plot(T, C, label = str(2) + 'x' + str(2))
plt.legend()
pl.title('Heat Capacity vs Tempurature')
pl.xlabel('Tempurature')
pl.ylabel('Heat Capacity')
pl.show()