Euler s method for solving a differential equation (approximately) Department of Mathematics, UW - Madison March 4, 2013
A chemical reaction A B A B A A A chemical reactor contains two kinds of molecules, A and B
A chemical reaction A B A B A A A chemical reactor contains two kinds of molecules, A and B Whenever an A and B molecule bump into each other the B turns into an A: A + B 2A
A chemical reaction A B A B A A A chemical reactor contains two kinds of molecules, A and B Whenever an A and B molecule bump into each other the B turns into an A: A + B 2A As the reaction proceeds, all B gets converted to A How long does this take?
Reaction rate for A+B 2A The total number of molecules (A and B) stays constant
Reaction rate for A+B 2A The total number of molecules (A and B) stays constant Let s call x(t) the fraction of all molecules that at time t are of type A: amount of A x(t) = amount of A + amount of B
Reaction rate for A+B 2A The total number of molecules (A and B) stays constant Let s call x(t) the fraction of all molecules that at time t are of type A: amount of A x(t) = amount of A + amount of B Then 0 x(t) 1, and the fraction of all molecules in the reactor which (at time t) are of type B is 1 x(t)
Reaction rate for A+B 2A The total number of molecules (A and B) stays constant Let s call x(t) the fraction of all molecules that at time t are of type A: amount of A x(t) = amount of A + amount of B Then 0 x(t) 1, and the fraction of all molecules in the reactor which (at time t) are of type B is 1 x(t) Every time a reaction takes place, the ratio x(t) increases, so dx is proportional to the reaction rate
Reaction rate for A+B 2A Chemistry tells us that dx = K amount of A amount of B = Kx(1 x)
Reaction rate for A+B 2A Chemistry tells us that dx = K amount of A amount of B = Kx(1 x) K is a proportionality constant, which depends on the particular kind of molecules A and B in this reaction You would have to measure it to find its value
Reaction rate for A+B 2A Chemistry tells us that dx = K amount of A amount of B = Kx(1 x) K is a proportionality constant, which depends on the particular kind of molecules A and B in this reaction You would have to measure it to find its valuethis is a calculus class, so let s assume K = 1
Solving dx = x(1 x) We have to solve the diffeq dx = x(1 x) The solution will have an arbitrary constant ( C ) If we know what x(0) is then we can compute C
Solving dx = x(1 x) We have to solve the diffeq dx = x(1 x) The solution will have an arbitrary constant ( C ) If we know what x(0) is then we can compute C So (as an example) let s try to solve the following problem:
Solving dx = x(1 x) We have to solve the diffeq dx = x(1 x) The solution will have an arbitrary constant ( C ) If we know what x(0) is then we can compute C So (as an example) let s try to solve the following problem: Suppose the tank initially holds 2% A and 98% B,
Solving dx = x(1 x) We have to solve the diffeq dx = x(1 x) The solution will have an arbitrary constant ( C ) If we know what x(0) is then we can compute C So (as an example) let s try to solve the following problem: Suppose the tank initially holds 2% A and 98% B, x(0) = 002
Solving dx = x(1 x) We have to solve the diffeq dx = x(1 x) The solution will have an arbitrary constant ( C ) If we know what x(0) is then we can compute C So (as an example) let s try to solve the following problem: Suppose the tank initially holds 2% A and 98% B, x(0) = 002 Then what is the fraction of A molecules at time t?
Solving dx = x(1 x) We have to solve the diffeq dx = x(1 x) The solution will have an arbitrary constant ( C ) If we know what x(0) is then we can compute C So (as an example) let s try to solve the following problem: Suppose the tank initially holds 2% A and 98% B, x(0) = 002 Then what is the fraction of A molecules at time t? x(t) =?
Summary of the problem We are going to solve an initial value problem:
Summary of the problem We are going to solve an initial value problem: Find x(t) if you know dx = x(1 x) } {{} diffeq, holds for t>0 and x(0) = 002 }{{} initial value
Summary of the problem We are going to solve an initial value problem: Find x(t) if you know dx = x(1 x) } {{} diffeq, holds for t>0 and x(0) = 002 }{{} initial value The solution is x(t) = (to be explained later this hour) 1 1 + 49e t
Leonhard e πi + 1 = 0 Euler (1707-1783)
Solving dx = x(1 x) Euler s idea:
Solving dx = x(1 x) Euler s idea: I can t solve the equation because I don t know what dx pick a small number h > 0 and say that is So dx x(t + h) x(t) h
Solving dx = x(1 x) Euler s idea: I can t solve the equation because I don t know what dx pick a small number h > 0 and say that is So dx The diffeq then becomes x(t + h) x(t) h x(t + h) x(t) h x(t)(1 x(t))
Solving dx = x(1 x) Euler s idea: I can t solve the equation because I don t know what dx pick a small number h > 0 and say that is So dx The diffeq then becomes x(t + h) x(t) h x(t + h) x(t) h x(t)(1 x(t)) If you know x(t) and h then you can solve this equation for x(t + h)
Solving dx = x(1 x) has as solution x(t + h) x(t) h x(t)(1 x(t)) x(t + h) x(t) + h x(t)(1 x(t))
Solving dx = x(1 x) has as solution x(t + h) x(t) h x(t)(1 x(t)) x(t + h) x(t) + h x(t)(1 x(t)) Example (t = 0): If we know x(0), then this equation allows us to compute x(0 + h) = x(h)
Solving dx = x(1 x) has as solution x(t + h) x(t) h x(t)(1 x(t)) x(t + h) x(t) + h x(t)(1 x(t)) Example (t = 0): If we know x(0), then this equation allows us to compute x(0 + h) = x(h) Example (t = h): Knowing x(h) you can find x(h + h) = x(2h)
Solving dx = x(1 x) has as solution x(t + h) x(t) h x(t)(1 x(t)) x(t + h) x(t) + h x(t)(1 x(t)) Example (t = 0): If we know x(0), then this equation allows us to compute x(0 + h) = x(h) Example (t = h): Knowing x(h) you can find x(h + h) = x(2h), And then x(2h + h) = x(3h),
Solving dx = x(1 x) has as solution x(t + h) x(t) h x(t)(1 x(t)) x(t + h) x(t) + h x(t)(1 x(t)) Example (t = 0): If we know x(0), then this equation allows us to compute x(0 + h) = x(h) Example (t = h): Knowing x(h) you can find x(h + h) = x(2h), And then x(2h + h) = x(3h), x(3h + h) = x(4h), etc
Euler s (approximate) solution Pick a small number h > 0, and compute x(h) = x(0) + h x(0)[1 x(0)]
Euler s (approximate) solution Pick a small number h > 0, and compute x(h) = x(0) + h x(0)[1 x(0)] x(2h) = x(h) + h x(h)[1 x(h)]
Euler s (approximate) solution Pick a small number h > 0, and compute x(h) = x(0) + h x(0)[1 x(0)] x(2h) = x(h) + h x(h)[1 x(h)] x(3h) = x(2h) + h x(2h)[1 x(2h)]
Euler s (approximate) solution Pick a small number h > 0, and compute x(h) = x(0) + h x(0)[1 x(0)] x(2h) = x(h) + h x(h)[1 x(h)] x(3h) = x(2h) + h x(2h)[1 x(2h)] x(4h) = x(3h) + h x(3h)[1 x(3h)]
Euler s (approximate) solution Pick a small number h > 0, and compute x(h) = x(0) + h x(0)[1 x(0)] x(2h) = x(h) + h x(h)[1 x(h)] x(3h) = x(2h) + h x(2h)[1 x(2h)] x(4h) = x(3h) + h x(3h)[1 x(3h)]
Euler s (approximate) solution Pick a small number h > 0, and compute x(h) = x(0) + h x(0)[1 x(0)] x(2h) = x(h) + h x(h)[1 x(h)] x(3h) = x(2h) + h x(2h)[1 x(2h)] x(4h) = x(3h) + h x(3h)[1 x(3h)] Now let s choose h = 02 and x(0) = 002, and compute x(02), x(04), x(06), x(08), x(10),
Doing the calculations Doing all these calculations is a drag of course How did Euler do this? By hand!! (and with a lot of patience)
Doing the calculations Doing all these calculations is a drag of course How did Euler do this? By hand!! (and with a lot of patience) How do we do this in the 21st century? With a computer
Doing the calculations Doing all these calculations is a drag of course How did Euler do this? By hand!! (and with a lot of patience) How do we do this in the 21st century? With a computer For more complicated diffeqs one should learn to program a computer, but for the example we ve been looking at you can get Excel (or some other spreadsheet program like Open Office) to compute and plot the solutions
What the spreadsheet computed Here are the numbers, and graphs The exact solution is x(t) = 1/(1 + 49e t ) Solving x'=x(1-x) by Euler's method h t x(t) x'(t) exact solution 02 0 0020000 0019600 0020000 02 02 0023920 0023348 0024320 02 04 0028590 0027772 0029546 02 06 0034144 0032978 0035853 02 08 0040740 0039080 0043446 02 1 0048556 0046198 0052559 02 12 0057795 0054455 0063458 02 14 0068686 0063968 0076434 02 16 0081480 0074841 0091803 02 18 0096448 0087146 0109894 02 2 0113877 0100909 0131037 02 22 0134059 0116087 0155537 02 24 0157277 0132541 0183649 02 26 0183785 0150008 0215545 02 28 0213786 0168082 0251276 02 3 0247403 0186195 0290734 02 32 0284642 0203621 0333628 02 34 0325366 0219503 0379465 02 36 0369266 0232909 0427558 02 38 0415848 0242918 0477061 02 4 0464432 0248735 0527019 02 42 0514179 0249799 0576441 02 44 0564138 0245886 0624380 02 46 0613316 0237160 0669999 02 48 0660748 0224160 0712628 02 5 0705580 0207737 0751790 02 52 0747127 0188928 0787208 02 54 0784913 0168825 0818791 02 56 0818678 0148445 0846600 02 58 0848367 0128641 0870815 02 6 0874095 0110053 0891696 02 62 0896105 0093101 0909552 02 64 0914725 0078003 0924713 02 66 0930326 0064820 0937508 02 68 0943290 0053494 0948249 02 7 0953989 0043894 0957229 02 72 0962768 0035846 0964708 02 74 0969937 0029159 0970920 02 76 0975769 0023644 ("$!!!!!# ("!!!!!!#!"'!!!!!#!"&!!!!!#!"%!!!!!#!"$!!!!!#!"!!!!!!#!# (# $# )# %# *# &# +# '#,-/# 0,12#3456748#
Point and click on-line diffeq solver There are several graphical on-line solvers for differential equations If you go to this web page: http://virtualmathmuseumorg/ode/1o1d-massaction you can see graphs of the solution to our equation dx = x(1 x)