In [1]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from scipy.optimize import curve_fit as cf

In [18]:
pulse_spacing = np.array([200, 225, 250, 300, 350, 400, 450, 700, 800, 1000, 1500, 1800, 2200, 2500])
amplitudes = np.array([5.08, 4.92, 4.88, 4.60, 4.48, 4.40, 4.28, 4.28, 4.28, 3.92, 3.4, 3.04, 2.80, 2.60])


#pulse_spacing = np.array([200, 225, 250, 700, 800, 1000, 1500, 1800, 2200, 2500])
# amplitudes = np.array([5.08, 4.92, 4.88, 4.28, 4.28, 3.92, 3.4, 3.04, 2.80, 2.60])

In [19]:
plt.title("CuSO$_4$ 0.1 M Preliminary T2 Measurement")
plt.errorbar(pulse_spacing, amplitudes, xerr = 3, yerr= 0.1, fmt = "o")
plt.xlabel("Pulse Spacing ($\mu$s)")
plt.ylabel("Amplitude (mV)");



In [20]:
def exp(t, A, b):
    return A*np.exp(-t/b)

In [21]:
popt, pcov = cf(exp, pulse_spacing, amplitudes, p0=[5.0, 1200])

In [22]:
plt.plot(pulse_spacing, exp(pulse_spacing, *popt), 'b--', label='Fit of A$e^{-t/b}$')
plt.title("CuSO$_4$ 0.1 M Preliminary T2 Measurement")
plt.errorbar(pulse_spacing, amplitudes, xerr = 3, yerr= 0.1, fmt = "o", color = "g", label = "Data")
plt.xlabel("Pulse Spacing ($\mu$s)")
plt.ylabel("Amplitude (mV)")
plt.legend();



In [23]:
popt


Out[23]:
array([    5.11568802,  3633.17086041])

In [24]:
plt.hist(exp(pulse_spacing, *popt)-amplitudes, 12)
plt.title("Histogram of Residuals from Exponential Fit")
plt.xlabel("Difference Between Fit and Data")
plt.ylabel("Counts");



In [25]:
print("T2 = {}  microseconds".format(round(popt[1], 2)))


T2 = 3633.17  microseconds

In [ ]: