Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import statistics # pre-define some functions (ignore)
- import math
- def apprx(x): # whenever apprx() is called
- return round(x,5-int(math.log(x))) # round the number to to 5 digits
- 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]]
- # list of 7 lists corresponding to equations a-g;
- # each in format [propanone,I2,H+,time] 7 times over
- length = len(list1) # number of experiment equations (to be used later)
- for x in range(-10,11): # for each possible combination of orders w.r.t. (e.g. x,y,z)
- for y in range(-10,11): # - set to an abritrarily large range
- for z in range(-10,11): # - only whole numbers
- k = [None]*length # prepare a list for the results of each equation a-g
- for e in range (0,length): # try each equation
- conc_x = list1[e][0] # obtain concentration of propane
- conc_y = list1[e][1] # obtain concentration of I2
- conc_z = list1[e][2] # obtain concentration of H+
- rate_x = conc_x ** x # calculate [propanone] ^ x (rate w.r.t propanone)
- rate_y = conc_y ** y # calculate [I2] ^ y (rate w.r.t I2)
- rate_z = conc_z ** z # calculate [H+] ^ z (rate w.r.t H+)
- leftside = 1/list1[e][3] # rate α 1/time -> longer time = lower rate; left side of equation = 1/time
- rightside = rate_x*rate_y*rate_z # product of rates (right side of equation)
- k[e] = leftside / rightside # rate = rates w.r.t * k --> k = rate / rates w.r.t.
- # (end loop; remember value of k for this combination of x,y,z; start again with a new equation)
- kaverage = sum(k)/len(k) # average value of k (for this combination of x,y,z)
- error = statistics.stdev(k) # the standard deviation of k (for this combination of x,y,z)
- relativeerror = error/kaverage # relative error
- if error/kaverage < 0.5: # if error is smaller then 0.5 ("50%")
- print("\trel.err.", apprx(relativeerror), "\tfor values", x, y, z)
- # write down values of relative error and x,y,z
- # (start again with a different set of coefficients)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement