MATH 164, Spring 2001 Due Date: Name(s): Extra Project 10.2b: Euler's Method Objective To investigate Euler's method. Narrative If you have not already done so, read Section 10.2 of the text. The key ideas you should take away from this section are: 1. Not all differential equations can be solved in closed form. There are techniques, however, such as Euler's Method which allow you to obtain the approximate value of a solution at a given point. 2. For small values of h we can approximate f (x) = lim h0 f(x + h) - f(x) h f(x + h) - f(x) h . (1) 3. Given an interval [a, b] and an integer N, if xn = a + nh, where n = 0, . . . , N and h = (b - a)/N, then equation (1) implies that f (xn) f(xn+1) - f(xn) h or f(xn+1) f(xn) + hf (xn), or, letting yn = f(xn), yn+1 = yn + hf (xn). (2) Task a) Type the command lines below into Maple in the order in which they are listed. These commands produce the direction field associated to the differential equation y = x + y. > # Project 10.2b: Euler's Method > restart: with(DEtools): > y0 := y(x); y1 := diff(y(x),x); > dfieldplot(y1 = x+y0,y0,x=-4..4,y=-4..4); b) Continue by typing the following command lines into Maple in the order in which they are listed. These commands solve y = x + y with the initial condition y(0) = 1, analytically, and evaluate this solution when x = 1. > dsolve({y1 = x+y0,y(0)=1},y0); > evalf(subs(x=1,%)); c) Continue by typing the following command line into Maple. This command produces the direction field associated to the differential equation y = x + y at a finer scale. > dfieldplot(y1 = x+y0,y0,x=0..1,y=1..4); d) Continue by typing the following command lines into Maple in the order in which they are listed. These commands apply Euler's Method (equation (2)) to y = x + y assuming that a = 0, b = 1, and N = 10. (That is, they use equation (2) to approximate y(1) if y = x + y and y(0) = 1 using N = 10 steps.) > a := 0.0; b := 1.0; N := 10; > x.0 := a; y.0 := 1.0; h := (b-a)/N; > for n from 0 to N-1 do y.(n+1) := y.n + h * (x.n + y.n ): x.(n+1) := x.n + h: print(n, x.(n+1), y.(n+1)); od; Note the discrepancy between the analytically computed value of y(1) and the numerical value computed with Euler's Method. e) Repeat part (d) using N = 100 subintervals. (The easiest way to do this is to copy and paste the lines you typed in part (d), to change N from 10 to 100, and then to "re-Enter" the commands.) Note how much closer the numerical value computed with Euler's Method is to the exact value (which we computed analytically). At this point, make a hard-copy of your typed input and Maple's responses (both text and graphics). Then, ... f) On the direction field you produced in part (c), use the data you generated in part (d) to draw the sequence of line segments from (xn, yn) to (xn+1, yn+1), n = 0, . . . , 9, which graphically embodies Euler's Method. Comments 1. In this project, we solved a differential equation analytically, graphically, and numerically, and were able to compare our solutions. In many cases, it is difficult -- or even impossible -- to solve a differential equation analytically, and in this case the only alternatives are graphical and numerical solutions. 2. While Euler's Method is good for illustrating the general approach to numerically solving differential equations, it does not generally yield extremely accurate results. Other numerical techniques exist, and these are studied in courses on Numerical Analysis.