• API
• FAQ
• Tools
• Archive
daily pastebin goal
0%
SHARE
TWEET

# Chemistry analysis code (Python)

RudolfJelin Mar 24th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import statistics                                               # pre-define some functions (ignore)
2. import math
3.
4. def apprx(x):                                                   # whenever apprx() is called
5.     return round(x,5-int(math.log(x)))                          # round the number to to 5 digits
6.
7. list1 = [[400,0.5,400,537],[800,0.5,400,678],[1200,0.5,400,300],[400,0.25,400,680],[400,0.125,400,165],[400,0.5,800,421],[400,0.5,1200,302]]
8.                                                                 # list of 7 lists corresponding to equations a-g;
9.                                                                 # each in format [propanone,I2,H+,time] 7 times over
10.
11. length = len(list1)                                             # number of experiment equations (to be used later)
12.
13.
14. for x in range(-10,11):                                         # for each possible combination of orders w.r.t. (e.g. x,y,z)
15.     for y in range(-10,11):                                     #  - set to an abritrarily large range
16.         for z in range(-10,11):                                 #  - only whole numbers
17.
18.             k = [None]*length                                   # prepare a list for the results of each equation a-g
19.
20.             for e in range (0,length):                          # try each equation
21.                 conc_x = list1[e][0]                            # obtain concentration of propane
22.                 conc_y = list1[e][1]                            # obtain concentration of I2
23.                 conc_z = list1[e][2]                            # obtain concentration of H+
24.
25.                 rate_x = conc_x ** x                            # calculate [propanone] ^ x (rate w.r.t propanone)
26.                 rate_y = conc_y ** y                            # calculate [I2] ^ y  (rate w.r.t I2)
27.                 rate_z = conc_z ** z                            # calculate [H+] ^ z  (rate w.r.t H+)
28.
29.                 leftside = 1/list1[e][3]                        # rate α 1/time -> longer time = lower rate; left side of equation = 1/time
30.                 rightside = rate_x*rate_y*rate_z                # product of rates (right side of equation)
31.
32.                 k[e] = leftside / rightside                     # rate = rates w.r.t * k --> k = rate / rates w.r.t.
33.                                                                 # (end loop; remember value of k for this combination of x,y,z; start again with a new equation)
34.
35.             kaverage = sum(k)/len(k)                            # average value of k (for this combination of x,y,z)
36.             error = statistics.stdev(k)                         # the standard deviation of k (for this combination of x,y,z)
37.
38.             relativeerror = error/kaverage                      # relative error
39.
40.             if error/kaverage < 0.5:                            # if error is smaller then 0.5 ("50%")
41.                 print("\trel.err.", apprx(relativeerror), "\tfor values", x, y, z)
42.                                                                 # write down values of relative error and x,y,z
43.
44.                                                                 # (start again with a different set of coefficients)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top