V tomto praktiku si předvedeme určení neznámé veličiny $C(T)$ definované jako součin $$C(T) = A(T) \, B(T),$$ přičemž veličiny $A(T)$, $B(T)$ jsme určili měřením. Určíme zároveň směrnici závislosti veličiny $C$ na $T$.
jsme si trochu nešikovně zapsali do dvou csv souborů (data1.csv
a data2.csv
):
In [1]:
ls
In [2]:
!cat data1.csv
In [3]:
!cat data2.csv
In [4]:
import pandas
In [5]:
data1 = pandas.read_csv('data1.csv')
data1
Out[5]:
In [6]:
data2 = pandas.read_csv('data2.csv')
data2
Out[6]:
In [7]:
data = pandas.concat([data1, data2])
data
Out[7]:
In [8]:
data = data.sort_values('T')
data
Out[8]:
In [9]:
import numpy
data = data.groupby('T').aggregate(numpy.average)
data
Out[9]:
In [10]:
import matplotlib.pyplot
%matplotlib inline
matplotlib.pyplot.rcParams['figure.autolayout'] = False
matplotlib.pyplot.rcParams['figure.figsize'] = 9, 5
matplotlib.pyplot.rcParams['axes.labelsize'] = 25
matplotlib.pyplot.rcParams['axes.titlesize'] = 25
matplotlib.pyplot.rcParams['font.size'] = 25
matplotlib.pyplot.rcParams['lines.linewidth'] = 2.0
matplotlib.pyplot.rcParams['lines.markersize'] = 12
matplotlib.pyplot.rcParams['legend.fontsize'] = 25
matplotlib.pyplot.rcParams['text.usetex'] = True
matplotlib.pyplot.rcParams['text.latex.unicode'] = True
matplotlib.pyplot.rcParams['font.family'] = "serif"
matplotlib.pyplot.rcParams['font.serif'] = "cm"
matplotlib.pyplot.rcParams['xtick.major.pad'] = 10.0
matplotlib.pyplot.rcParams['ytick.major.pad'] = 10.0
matplotlib.pyplot.rcParams['text.latex.preamble'] = r"\usepackage{subdepth}, \usepackage{type1cm}"
matplotlib.pyplot.plot(data.index, data['A'], 'o', label='A')
matplotlib.pyplot.legend(loc='best')
matplotlib.pyplot.show()
matplotlib.pyplot.plot(data.index, data['B'], 'o', label='B')
matplotlib.pyplot.legend()
matplotlib.pyplot.show()
In [11]:
data = data[data.index != 23.0]
data
Out[11]:
In [12]:
matplotlib.pyplot.plot(data.index, data['A'], 'o', label='A')
matplotlib.pyplot.legend(loc='best')
matplotlib.pyplot.show()
matplotlib.pyplot.plot(data.index, data['B'], 'o', label='B')
matplotlib.pyplot.legend()
matplotlib.pyplot.show()
In [13]:
data['C'] = data['A'] * data['B']
data
Out[13]:
In [14]:
matplotlib.pyplot.plot(data.index, data['C'], 'o', label='C')
matplotlib.pyplot.legend(loc='best')
matplotlib.pyplot.show()
In [15]:
data.loc[15:18]
Out[15]:
In [16]:
import scipy.optimize
def f(x, C0, C1):
return C0 * x + C1
data1 = data.loc[15:18]
data2 = data.loc[19:]
matplotlib.pyplot.plot(data.index, data['C'], 'o', label='measurement')
popt, pcov = scipy.optimize.curve_fit(f, data1.index, data1['C'])
y = f(data1.index, popt[0], popt[1]) # y = C0 * x + C1
matplotlib.pyplot.plot(data1.index, y, label=r'$C_0 = {:0.3f}$'.format(popt[0]))
popt, pcov = scipy.optimize.curve_fit(f, data2.index, data2['C'])
y = f(data2.index, popt[0], popt[1]) # y = C0 * x + C1
matplotlib.pyplot.plot(data2.index, y, label=r'$C_0 = {:0.3f}$'.format(popt[0]))
popt, pcov = scipy.optimize.curve_fit(f, data.index, data['C'])
y = f(data.index, popt[0], popt[1]) # y = C0 * x + C1
matplotlib.pyplot.plot(data.index, y, label=r'$C_0 = {:0.3f}$'.format(popt[0]));
matplotlib.pyplot.legend(loc='best')
matplotlib.pyplot.savefig('fiser.pdf')
matplotlib.pyplot.savefig('fiser.png')
In [17]:
ls