Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In a chemical reaction, one molecule of A combines with one molecule of B to for

ID: 3603354 • Letter: I

Question

In a chemical reaction, one molecule of A combines with one molecule of B to form one molecule of the chemical C. It is found that the concentration y(t) of C at time t is the solution to the Initial Value Problem (IVP) y'-k(a - y)(b-y) th (0)-0; where k is a positive constant and a and b are the initial concentrations of A and B, respectively. Find the solution for the concentration y(t) of C in the time interval [0, 20] using Matlab and hand calculations for k-0.01, a-70 millimoles/litre, and b-50 millimoles/litre To find solution using Matlab you are required to perform the following tasks: * 1. Write a function fun ode.m in which you define your ordinary differential equation (1) (Refer to an example in Week 10 Example.zip) 2. Write another function in which you will solve equation (1) defined in fun ode.m (a) By using Euler's method (function euler.m is available in week10.zip) with At -2s and M=1 s. (b) By using Heun's Method (you will need to modify euler.m to implement Heun's method) with At -2s. (c) By using ode45 Matlab function based on Runge-Kutta method with M-2s (d) Compare results obtained in (a), (b) and (c) with the exact solution yt) 350e7-5e by plotting the solutions on the same graph (e) Find the percentage errors for the results obtained in (a), (b) and (c) by comparing with the exact solution and plot them on separate graph. Comment on accuracy of the methods. In calculation of the error exclude initial point t-0 * To find solution using hand calculations you are required to perform the following 3. use Euler's method with ?1-2s over [0 4] and compare your solution with results 4.use Heun's method with At-ls over [0 4] and compare your solution with results tasks: obtained using Matlab function in 2(a) obtained using Matlab function in 2(b)

Explanation / Answer

##PROBLEM 1-1 (1/1 point) ##Suppose x = "pi" and y = "pie". The line of code x, y = y, ##x will swap the values of x and y, resulting in x = "pie" and y = "pi". ## ##True True - correct ##False ##PROBLEM 1-2 (1 point possible) ##Suppose x is an integer in the following code: ##def f(x): ## while x > 3: ## f(x+1) ## ##For any value of x, all calls to f are guaranteed to never terminate. ##True ##False True - correct ##PROBLEM 1-3 (1/1 point) ##A Python program always executes every line of code written at least once. ##True ##False - correct ##PROBLEM 1-4 (1 point possible) ##Suppose you have two different functions that each assign a variable called x. Modifying x in one function means you always modify x in the other function for any x. ##True ##False - correct ##PROBLEM 1-5 (1 point possible) ##Assume a break statement is executed inside a function. The function call will always terminate without executing any remaining code inside that function. ##True ##False - correct ##PROBLEM 1-6 (1/1 point) ##Let d be a dictionary. If d[a] == d[b] then a == b. ## ##True ##False - correct ##PROBLEM 1-7 (1/1 point) ##Suppose you run the following code: ##def f(L): ## L.append(4) ##x = [1,2,3] ##f(x) ## ##The variableL is an alias for the variable x. ##True True - correct ##False ##PROBLEM 1-8 (1/1 point) ##A program that keeps running and does not stop is an example of a syntax error. ## ##True ##False - correct ##PROBLEM 1-9 (1/1 point) ##A recursive algorithm must always have at least one base case. ## ##True True - correct ##False ##PROBLEM 1-10 (1/1 point) ##Any number that can be represented as a decimal fraction can be represented exactly in floating point representation in Python. ## ##True ##False - correct ##PROBLEM 2-1 (1/1 point) ##What data type is the object myst: ## ##myst = ( { 1: [1,1], 2: [2,2]}, { 'a': ['a',1], 'b': ['b',2] } ) ##tuple tuple - correct ##list ##dictionary ##None of the above ##PROBLEM 2-2 (1/1 point) ##Which of the following is true? ## ##Testing a program and debugging a program are the same thing. ## ##Testing compares program output to the expected output. ##Debugging is a process to study the events leading up to an error. - correct ## ##Testing checks that there is no input on which the program crashes. ## ##Testing is typically done by putting try-except blocks around pieces of code. ## ##PROBLEM 2-3 (1 point possible) ##Assume the statement s[1024] = 3 does not produce an error message. This implies: ## ##type(s) can be str ##type(s) can be tuple ##type(s) can be list ##All of the above - incorrect ##PROBLEM 2-4 (1/1 point) ##Choose the item from the list of potential responses that best matches: "specification" ## ##abstraction abstraction - correct ##mutation ##indentation ##induction ##PROBLEM 2-5 (1/1 point) ##Choose the item from the list of potential responses that best matches: [:] ## ##keyword ##mutation ##cloning cloning - correct ##black box testing ##PROBLEM 3-1 (2 points possible) ##Examine the following code snippet: ##stuff = ["iBoy", "iGirl", "iQ", "iC","iPaid","iPad"] - correct ##stuff = ("iBoy", "iGirl", "iQ", "iC","iPaid","iPad")- correct ##stuff = [ ( "iBoy", "iGirl", "iQ", "iC","iPaid","iPad") ] ##stuff = ( [ "iBoy", "iGirl", "iQ", "iC","iPaid","iPad" ], ) ##stuff = "iPad" ##stuff = 'iPad' ##for thing in stuff: ## if thing == 'iPad': ## print "Found it" ##PROBLEM 3-2 (3 points possible) ##The following Python code is supposed to compute the square of an integer by using successive additions. ##def Square(x): ## return SquareHelper(abs(x), abs(x)) ## ##def SquareHelper(n, x): ## if n == 0: ## return 0 ## return SquareHelper(n-1, x) + x ##Not considering recursion depth limitations, what is the wrong with this implementation of procedure Square? Check all that apply. ## ##It is going to return a wrong value. ##The term Square is a reserved Python keyword. ##Function names cannot start with a capital letter. ##The function is never going to return anything. ##Python has arbitrary precision arithmetic. ##This function will not work for negative numbers. ##The call SquareHelper(abs(x), abs(x)) won't work because you can't have abs(x) as both parameters. ##Nothing is wrong; the code is fine as-is. ##PROBLEM 4 (10 points possible) ##Write a simple procedure, myLog(x, b), that computes the logarithm of a number x relative to a base b. ##For example, if x = 16 and b = 2, then the result is 4 - because 24=16. ##If x = 15 and b = 3, then the result is 2 - because 32 is the largest power of 3 less than 15. ## ##In other words, myLog should return the largest power of b such that b to that power ##is still less than or equal to x. ## ##x and b are both positive integers; ##b is an integer greater than or equal to 2. ##Your function should return an integer answer. def myLog(x, b): ''' x: a positive integer b: a positive integer; b >= 2 returns: log_b(x), or, the logarithm of x relative to a base b. ''' exp = 2 result = 0 if x > b: while result