In Chemistry we often need to analyse several experimental runs using the same methods.
An example we will use is analysing Kinetic Measurements, this will be familiar to you from CHEM0019 where you recorded methylene blue and ascorbic acid reaction rates.
We will construct a script that can load and analyse this data.
We will take the data in the form of concentration versus time for a reaction system measured at different temperatures. For each temperature we will calculate the rate coefficient.
We will then use all the rate coefficients to determine the Energy of Activation.
Learning Outcomes¶
Handling multiple data sets
Data analysis on multiple data sets
Combining resultsExercise¶
Part 1¶
Write a script that will load the following five data files (data_700, data_730, data_760, data_790, data_810). It should then determine the rate coefficient for each data set based on the following equation:
To do this we will need to first manipulate the data loaded from the files so that it a follows a straight line, and then determine the gradient.
The following code will fit a straight line to two variables x and y, and report the slope, intercept and error in each.
import numpy as np
from scipy import stats
#Fit straight line
results = stats.linregress(x, y)
print("a0 = {0}".format(results.slope))
print("a1 = {0}".format(results.intercept))
print("Error in a0 = {0}".format(results.intercept_stderr))
print("Error in a1 = {0}".format(results.stderr))
print("R coefficient = {0}".format(results.rvalue))Hints:
Don’t just jump in and code, write a plan.
Don’t try to do all the files in one go, get your code working for just one file, then loop.
Part 2¶
Now you have the 5 rate coefficients we will solve the Arrenhius equation
Adapt your script so that it calculates the Activation Energy for the reaction under study.
Hint: Look at the file name and the file headers, useful information has been put there for the analysis.
Part 3¶
In Part 2 we solved the linearised Arrenhius equation, as is commonly taught in undergraduate courses. However, this can introduce errors to the fit. Instead, we can fit the exponential form of the Arrenhius equation.
The following code defines a function to fit to the data, and uses the curve_fit function from the scipy library to determine the fit parameters and and .
import numpy as np
from scipy.optimize import curve_fit
def exp_func(x,A,B):
return A*e**-B
#Fit the function exp_func to the data
(A,B) = curve_fit(exp_func, x, y)
print("A = {0}".format(A))
print("B = {0}".format(B))Adapt your script so that it calculates the Activation Energy for the reaction under study