Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Zoom in to see code pictures Please help me with this. I am trying to understand my coding homework. I have supplied all the proper

Zoom in to see code pictures

image text in transcribed

image text in transcribed

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Please help me with this. I am trying to understand my coding homework. I have supplied all the proper documents. I will give thumbs up and also I saw another solution on chegg that I believe was incorrect. So please do not copy that solution. Thanks!

def main(): print('Homework 1 - SP21: An exercise in data processing.') # list the experimental temperatures TData=[] #experiment 1 TData.append([174.9, 175.4, 175.7, 177.8, 178.3, 179, 176.8, 173.8, 175.1, 174.9, 179.2, 168.4, 177.1, 180.2, 177.2, 167.5, 173.4, 174.5, 178.3, 176.4, 173.6, 171.4, 174.9, 172.6, 173.8, 175, 181.6, 175.4, 173.4, 174.3]) #experiment 2 TData.append([177.1, 174.6, 173.7, 181.2, 176.3, 174, 175.3, 177, 171.8, 176.4, 174.6, 176.2, 174.4, 175.1, 164.8, 176.7, 177.2, 178.5, 174.4, 175.5, 178.3, 179.6, 177.2, 172.6, 175, 175.4, 176.3, 175.1, 173.3, 178.6]) #experiment 3 TData.append([179.3, 174, 169.1, 174.1, 176.8, 174.5, 177.2, 176.4, 174.7, 173, 175, 172.4, 177.6, 175, 174.5, 172.5, 181.5, 174.8, 179.3, 175.4, 172.4, 170.1, 170, 175.9, 178.9, 178.5, 178.1, 168.5, 178.8, 174.1]) TAvg=175.0 #expected temperature in degrees C TStDev=3.0 #Expected standard deviation of temperature CLow=169.0 #lower limit for clamp function (test) CHigh=181.0 #upper limit for clamp function (test) #output for part a) print('a)') print('Clamp(185, {:.1f}, {:.1f})={}'.format(CLow,CHigh, ClampInclusive(185, CLow, CHigh))) #ClampInclusive should return true print('Clamp(165, {:.1f}, {:.1f})={}'.format(CLow,CHigh, ClampInclusive(165, CLow, CHigh))) #ClampInclusive should return true print('Clamp(180, {:.1f}, {:.1f})={}'.format(CLow,CHigh, ClampInclusive(180, CLow, CHigh))) #ClampInclusive should return false #remove outlier data from the experimentally collected temperatures TRefined=RemoveOutliers(TData, TAvg, TStDev) #output for part b) print(' b)') i=0 for r in TRefined: n=len(TData[i-1])-len(r) print('Experiment {:d} had {:d} outliers'.format(i+1, n)) print('Refined experiment {:d} data ={}'.format(i+1,r)) i+=1 #output for part c) print(' c)') i=0 stats=[] for r in TRefined: stats.append(SampleEstimators(r)) print('Experiment {:d} stats: Mean = {:.1f}, StDev = {:.1f}'.format(i+1,stats[i][0],stats[i][1])) i+=1 P=11 #frequency factor EA=3500 #activation energy #output for part d print(' d)') i=1 for r in stats: rates=ReactionRate(stats[i-1],P,EA) print('Experiment {:d} Rates: Min = {:.2f}, Max = {:.2f}, Avg = {:.2f}'.format(i,rates[0],rates[1], rates[2])) i+=1 main()
We are analyzing data read from a thermocouple that measures the temperature in a chemical reactor (i.e., a round bottom flask or beaker) that is being heated to cause an endothermic (i.e., absorbs heat) reaction. The reaction rate varies with temperature and, due to environmental conditions beyond our control, the temperature of the reactor varies somewhat over time. The functions described below are intended to a.) determine if a value lies between a minimum and maximum, b.) remove "outlier" temperatures from sets of data collected during individual experiments, c.) calculate the sample mean and standard deviation of temperature for each experiment, and d.) calculate the maximum, minimum and average reaction rate predicted for each experiment. To Do: You should write four different functions in addition to a function named main() which you can simply copy from the HW1-Stem.py on Canvas. All of your code should be in a single Python file named HW1- SP21.py. You will test your functions using the particular numerical values given in the main() function. When we grade your assignment, we will run your program with those given numerical values, looking for correct answers. Then we will change the numerical values (including changing the SIZES of the arrays) and look for correct answers for those modified values as well. We will only use numerical values and array sizes that make sense. We will not be testing your program to see how it handles bad data. In this assignment, you must use: variables, loops, if statements, your own function definitions and function calls. You must include reasonable comments in your code. For now, you may not use any of the powerful functions available in python modules, with one exception: you may import functions from the math module. a) Write a function defined as: Lef ClampInclusive (val, minval, maxval): val: is a floating point number minval, maxval: are the minimum and maximum values the val can have. return Te: where I is a boolean (True or False) indication of val is between minval and maxval (inclusive) b) Write a function defined as: lef Removeoutliers (vals, mean, stdev): vals a list of lists (i.e., 2-D-matrix) containing temperatures read from a thermocouple. Each list is the result of an experiment and may contain outlier data. meant the average temperature read by the thermocouple over time stdeve the standard deviation of data read by the thermocouple return trimmed where trimmed is a list of lists (i.e., 2-D matrix) where each row contains the temperature data considered valid by being within 2*stde of the mean. c) Write a function defined as: SampleEstimators (vals): valst an array (list) containing temperature readings. return stats: stats is a list containing the sample estimators of the mean and standard deviation of the temperature readings d) Write a function defined as: ReactionRate (T, P, EA NSt Dev=2): is a list containing the average and standard deviation of the temperature for a reaction in C. : is a reaction rate coefficient in mol/min-1 EA is the activation energy for the reaction in kJ/mol NSEDev: is the number of standard deviations from the mean for which we want to calculate the maximum and minimum reaction rates according to the formula: Rate = P.elp where R = 8.3145 J/mol-K return RateRange: where RateRange is a list of the minimum, maximum and average reaction rates we can expect from the given distribution of temperature. Use HW1-stem.py as a starting point to test the four functions defined above. When you upload your program, it must include defined main function and call to main(). An additional requirement of this homework is that you understand EVERY LINE of this main program. If you don't understand something, Google it or ASK Dr. Smay or the TA. Correct Output: Homework 1 - SP21: An exercise in data processing. Clamp(185, 169.0, 181.0)=True Clamp(165, 169.0, 181,0)=True Clamp(180, 169.0, 181.0)=False b) Experiment I had 3 outliers Refined experiment 1 data={174.9, 175.4, 175.7, 177.8, 178.3, 179, 176.8, 173.8, 175.1, 174.9, 179.2, 177.1, 180.2, 177.2, 173.4, 174.5, 178.3, 176.4, 173.6, 171.4, 174.9, 172.6, 173.8, 175, 175.4, 173.4, 174.3] Experiment 2 had 2 outliers Refined experiment 2 data ={177.1, 174.6, 173.7, 176.3, 174, 175.3, 177, 171.8, 176.4, 174.6, 176.2, 174.4, 175.1, 176.7, 177.2, 178.5, 174.4, 175.5, 178.3, 179.6, 177.2, 172.6, 175, 175.4, 176.3, 175.1, 173.3, 178.6] Experiment 3 had 2 outliers Refined experiment 3 data =[179.3, 174, 169.1, 174.1, 176.8, 174.5, 177.2, 176.4, 174.7, 173, 175, 172.4, 177.6, 175, 174.5, 172.5, 174.8, 179.3, 175.4, 172.4, 170.1, 170, 175.9, 178.9, 178.5, 178.1, 178.8, 174.1] a) c) Experiment 1 stats: Mean = 175.6, StDev = 2.2 Experiment 2 stats: Mean = 175.7, StDev = 1.9 Experiment 3 stats: Mean = 175.1, StDev = 2.8 d) Experiment 1 Rates: Min = 4.26, Max = 4.34, Avg = 4.30 Experiment 2 Rates: Min = 4.27, Max = 4.34, Avg = 4.30 Experiment 3 Rates: Min = 4.25, Max = 4.35, Avg = 4.30 def main(: print('Homework 1 - SP21: An exercise in data processing.') # list the experimental temperatures TData=[] #experiment 1 TData.append([174.9, 175.4, 175.7, 177.8, 178.3, 179, 176.8, 173.8, 175.1, 174.9, 179.2, 168.4, 177.1, 180.2, 177.2, m.167.5, 173.4, 174.5, 178.3, 176.4, 173.6, 171.4, 174.9, 172.6, 173.8, 175, 181.6, 175.4, 173.4, 174.3]) #experiment...2 TData.append([177.1, 174.6, 173.7, 181.2, 176.3, 174, 175.3, 177, 171.8, 176.4, 174.6, 176.2, 174.4, 175.1, 164.8, 176.7. 177.2, 178.5, 174.4, 175.5, 178.3, 179.6, 177.2, 172.6, 175, 175.4, 176.3, 175.1, 173.3, 178.6]) #experiment TData.append([179.3, 174, 169.1, 174.1, 176.8, 174.5, 177.2, 176.4, 174.7, 173, 175, 172.4, 177.6, 175, 174.5, 172.5, 181.5, 174.8, 179.3, 175.4, 172.4, 170.1, 170, 175.9, 178.9, 178.5, 178.1, 168.5, 178.8, 174.1]) TAvg=175.0 #expected temperature in degrees TSGDev=3.0 #Expected standard deviation of temperature Clow=169.0 #Lower limit for clamp function(test). CHigh=181.0#upper limit for clamp function (test) #output forbartma). print('a') print('Clamp (185, {:.1f}, {:.18})={}'.format(Clow,CHigh, ClampInclusive (185, CLow, CHigh)))#lampInclusive should return true print('Clamp (165, {:.18}, {:.1f})={}'.format(CLow, CHigh, ClampInclusive (165, Clow, CHigh))) #ClampInclusive should return true print('Clamp (180, {:.1f}, {:.18})={}'.format(CLow,CHigh, ClampInclusive (180, CLOW, CHigh))) #ClampInclusive should return false #remove outlier data from the experimentally collected temperatures TRefined=RemoveOutliers (TData, Tavg, IstDev) #output for part b). print(' b)') i=0 for r in TRefined: n=len (TData[i-1])-len(r) print('Experiment {:d} had {:d} outliers'.format(i+1, n)) print('Refined experiment {:d} data ={}'.format(i+1,1)) i+=1 #output for part c). print(" c)') i=0 stats=[] for r in TRefined: stats.append(SampleEstimators(r)) print('Experiment {:d} stats: Mean = {:.1f}, StDev = {:.17}'.format(i+1, stats[i][0), stats[i][1])) i+=1 P=11 #frequencymfactor. EA=3500 #activation energy P=11 #frequency factor. EA=3500 #activation energy #output forbart print(" d)') i=1 for r in stats: rates ReactionRate(stats[i-1] P EA) print('Experiment {:d} Rates: Min = {:.28), Max = {:.2f}, Avg = {:.2f}'.format(i rates[0], rates[1], rates[2])) i+=1 main We are analyzing data read from a thermocouple that measures the temperature in a chemical reactor (i.e., a round bottom flask or beaker) that is being heated to cause an endothermic (i.e., absorbs heat) reaction. The reaction rate varies with temperature and, due to environmental conditions beyond our control, the temperature of the reactor varies somewhat over time. The functions described below are intended to a.) determine if a value lies between a minimum and maximum, b.) remove "outlier" temperatures from sets of data collected during individual experiments, c.) calculate the sample mean and standard deviation of temperature for each experiment, and d.) calculate the maximum, minimum and average reaction rate predicted for each experiment. To Do: You should write four different functions in addition to a function named main() which you can simply copy from the HW1-Stem.py on Canvas. All of your code should be in a single Python file named HW1- SP21.py. You will test your functions using the particular numerical values given in the main() function. When we grade your assignment, we will run your program with those given numerical values, looking for correct answers. Then we will change the numerical values (including changing the SIZES of the arrays) and look for correct answers for those modified values as well. We will only use numerical values and array sizes that make sense. We will not be testing your program to see how it handles bad data. In this assignment, you must use: variables, loops, if statements, your own function definitions and function calls. You must include reasonable comments in your code. For now, you may not use any of the powerful functions available in python modules, with one exception: you may import functions from the math module. a) Write a function defined as: Lef ClampInclusive (val, minval, maxval): val: is a floating point number minval, maxval: are the minimum and maximum values the val can have. return Te: where I is a boolean (True or False) indication of val is between minval and maxval (inclusive) b) Write a function defined as: lef Removeoutliers (vals, mean, stdev): vals a list of lists (i.e., 2-D-matrix) containing temperatures read from a thermocouple. Each list is the result of an experiment and may contain outlier data. meant the average temperature read by the thermocouple over time stdeve the standard deviation of data read by the thermocouple return trimmed where trimmed is a list of lists (i.e., 2-D matrix) where each row contains the temperature data considered valid by being within 2*stde of the mean. c) Write a function defined as: SampleEstimators (vals): valst an array (list) containing temperature readings. return stats: stats is a list containing the sample estimators of the mean and standard deviation of the temperature readings d) Write a function defined as: ReactionRate (T, P, EA NSt Dev=2): is a list containing the average and standard deviation of the temperature for a reaction in C. : is a reaction rate coefficient in mol/min-1 EA is the activation energy for the reaction in kJ/mol NSEDev: is the number of standard deviations from the mean for which we want to calculate the maximum and minimum reaction rates according to the formula: Rate = P.elp where R = 8.3145 J/mol-K return RateRange: where RateRange is a list of the minimum, maximum and average reaction rates we can expect from the given distribution of temperature. Use HW1-stem.py as a starting point to test the four functions defined above. When you upload your program, it must include defined main function and call to main(). An additional requirement of this homework is that you understand EVERY LINE of this main program. If you don't understand something, Google it or ASK Dr. Smay or the TA. Correct Output: Homework 1 - SP21: An exercise in data processing. Clamp(185, 169.0, 181.0)=True Clamp(165, 169.0, 181,0)=True Clamp(180, 169.0, 181.0)=False b) Experiment I had 3 outliers Refined experiment 1 data={174.9, 175.4, 175.7, 177.8, 178.3, 179, 176.8, 173.8, 175.1, 174.9, 179.2, 177.1, 180.2, 177.2, 173.4, 174.5, 178.3, 176.4, 173.6, 171.4, 174.9, 172.6, 173.8, 175, 175.4, 173.4, 174.3] Experiment 2 had 2 outliers Refined experiment 2 data ={177.1, 174.6, 173.7, 176.3, 174, 175.3, 177, 171.8, 176.4, 174.6, 176.2, 174.4, 175.1, 176.7, 177.2, 178.5, 174.4, 175.5, 178.3, 179.6, 177.2, 172.6, 175, 175.4, 176.3, 175.1, 173.3, 178.6] Experiment 3 had 2 outliers Refined experiment 3 data =[179.3, 174, 169.1, 174.1, 176.8, 174.5, 177.2, 176.4, 174.7, 173, 175, 172.4, 177.6, 175, 174.5, 172.5, 174.8, 179.3, 175.4, 172.4, 170.1, 170, 175.9, 178.9, 178.5, 178.1, 178.8, 174.1] a) c) Experiment 1 stats: Mean = 175.6, StDev = 2.2 Experiment 2 stats: Mean = 175.7, StDev = 1.9 Experiment 3 stats: Mean = 175.1, StDev = 2.8 d) Experiment 1 Rates: Min = 4.26, Max = 4.34, Avg = 4.30 Experiment 2 Rates: Min = 4.27, Max = 4.34, Avg = 4.30 Experiment 3 Rates: Min = 4.25, Max = 4.35, Avg = 4.30 def main(: print('Homework 1 - SP21: An exercise in data processing.') # list the experimental temperatures TData=[] #experiment 1 TData.append([174.9, 175.4, 175.7, 177.8, 178.3, 179, 176.8, 173.8, 175.1, 174.9, 179.2, 168.4, 177.1, 180.2, 177.2, m.167.5, 173.4, 174.5, 178.3, 176.4, 173.6, 171.4, 174.9, 172.6, 173.8, 175, 181.6, 175.4, 173.4, 174.3]) #experiment...2 TData.append([177.1, 174.6, 173.7, 181.2, 176.3, 174, 175.3, 177, 171.8, 176.4, 174.6, 176.2, 174.4, 175.1, 164.8, 176.7. 177.2, 178.5, 174.4, 175.5, 178.3, 179.6, 177.2, 172.6, 175, 175.4, 176.3, 175.1, 173.3, 178.6]) #experiment TData.append([179.3, 174, 169.1, 174.1, 176.8, 174.5, 177.2, 176.4, 174.7, 173, 175, 172.4, 177.6, 175, 174.5, 172.5, 181.5, 174.8, 179.3, 175.4, 172.4, 170.1, 170, 175.9, 178.9, 178.5, 178.1, 168.5, 178.8, 174.1]) TAvg=175.0 #expected temperature in degrees TSGDev=3.0 #Expected standard deviation of temperature Clow=169.0 #Lower limit for clamp function(test). CHigh=181.0#upper limit for clamp function (test) #output forbartma). print('a') print('Clamp (185, {:.1f}, {:.18})={}'.format(Clow,CHigh, ClampInclusive (185, CLow, CHigh)))#lampInclusive should return true print('Clamp (165, {:.18}, {:.1f})={}'.format(CLow, CHigh, ClampInclusive (165, Clow, CHigh))) #ClampInclusive should return true print('Clamp (180, {:.1f}, {:.18})={}'.format(CLow,CHigh, ClampInclusive (180, CLOW, CHigh))) #ClampInclusive should return false #remove outlier data from the experimentally collected temperatures TRefined=RemoveOutliers (TData, Tavg, IstDev) #output for part b). print(' b)') i=0 for r in TRefined: n=len (TData[i-1])-len(r) print('Experiment {:d} had {:d} outliers'.format(i+1, n)) print('Refined experiment {:d} data ={}'.format(i+1,1)) i+=1 #output for part c). print(" c)') i=0 stats=[] for r in TRefined: stats.append(SampleEstimators(r)) print('Experiment {:d} stats: Mean = {:.1f}, StDev = {:.17}'.format(i+1, stats[i][0), stats[i][1])) i+=1 P=11 #frequencymfactor. EA=3500 #activation energy P=11 #frequency factor. EA=3500 #activation energy #output forbart print(" d)') i=1 for r in stats: rates ReactionRate(stats[i-1] P EA) print('Experiment {:d} Rates: Min = {:.28), Max = {:.2f}, Avg = {:.2f}'.format(i rates[0], rates[1], rates[2])) i+=1 main

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Administration

Authors: Adam Jorgensen, Bradley Ball

1st Edition

111885926X, 9781118859261

More Books

Students also viewed these Databases questions

Question

Find the derivative of y= cos cos (x + 2x)

Answered: 1 week ago

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago