Math 132 Lab 3: Differential Equations Instructions. Follow the directions in each part of the lab. The lab report is due Monday, April 19. You need only hand in these pages. Answer each lab question in the space provided. Part I: Slope Fields In this part of the lab you will use the program DFIELD, by John Polking, to investigate the qualitative behavior of some differential equations. To access the program, open a web browser and go to the following address: http://math.rice.edu/~dfield/dfpp.html Next, click on the button that says DFIELD 2004.1 to start the applet. Several windows should open. One window shows the plot of a slope field. Click on any point in the screen to plot the solution which passes through that point. Another window shows the differential equation, in the form x = f(t, x), along with the range of t and x values that will appear in the slope field plot. The unknown function here is x(t), so x means. To change the equation, just enter the new dt f(t, x) on the right hand side of the equation. You may also change x to y and t to x if you prefer to use the notation in our text. 1. Plot the slope field for dt = tx 1 over the domain 2 t 2, 4 x 4. Plot the solution that satisfies the initial condition x(0) = 1. Question 1. For this solution, what is x(1), approximately? What is lim t x(t)? Solution. x(1) 0.25 and lim t x(t) = Plot the solution that satisfies the initial condition x(0) = 2. Question 2. For this solution, what is x(1), approximately? What is lim t x(t)? Solution. x(1) 1.88 and lim t x(t) = + 1
2. Plot the slope field for dt = t3 t 2 + 1 over the domain 2 t 2, 4 x 4. Plot several solutions. Question 3. How are the solution curves related to one another? What feature of the differential equation explains this relationship? (Hint: Can you find the exact solution?) Solution. The solutions all differ by a constant. This is because the right hand side of the equation does not depend on y. The solutions can be found by integrating, to get x(t) = 1t4 1 4 3 t3 + t + C. 3. The differential equation = 0.1x(60 x) 50 dt is a model for the growth of a population (e.g. fish in a pond) which is being harvested (e.g. people fishing). Plot its slope field for 0 t 4 and 0 x 80. Plot several solutions. Question 4. How do the solutions behave as t? In particular, do they go to + or, or level off at some value? How does this behavior depend on the initial condition (t 0, x 0 )? Interpret your findings in terms of the population. Solution. If x 0 > 10 the solution approaches 50 as t. If x 0 < 10, the solution approaches as t. This means that an initial population of less than 10 will become extinct, while an initial population of greater than 10 will survive and eventually level off at 50 in the long run. 2
Part II: Euler s Method In this part of the lab, you will investigate the error in Euler s method. Given an initial value problem dy = f(x, y) y(x 0 ) = y 0 and a step size x, recall that Euler s method proceeds by setting x 1 = x 0 + x x 2 = x 1 + x. y 1 = y 0 + f(x 0, y 0 ) x y 2 = y 1 + f(x 1, y 1 ) x. This can be implemented in Maple as follows. First, enter the step size and the function f(x, y). For example, if we want x = 0.2 and f(x, y) = x + y, type :=0.2; f:=(x,y)->x+y; Next, enter the initial condition. For example, if the initial condition is y(0) = 1, type x[0]:=0; y[0]:=1; Next define the values x 1, x 2, etc. One way to do this is to type x[1]:=x[0]+; x[2]:=x[1]+; and so on. Another is to use a loop. Suppose we want to define x 1 through x 5 all at once. We would then type for i from 1 to 5 do x[i]:=x[i-1]+ end do; Likewise, there are two ways to define the values y 1, y 2, etc. One at a time, y[1]:=y[0]+f(x[0],y[0])*; y[2]:=y[1]+f(x[1],y[1])*; or all at once in a loop for i from 1 to 5 do y[i]:=y[i-1]+f(x[i-1],y[i-1])* end do; You should obtain the following results: k x k y k 0 0.0 1 1 0.2 1.2 2 0.4 1.48 3 0.6 1.856 4 0.8 2.3472 5 1.0 2.97664 3
This table forms an approximate solution of the initial value problem dy = x + y y(0) = 1 on the interval 0 x 1. We will now compare this approximation with the exact solution. Question 5. Verify that y = 2e x x 1 is the exact solution of the initial value problem above. Solution. Since dy = 2ex 1 and x + y = 2e x 1, y satisfies the differential equation. Since y(0) = 2 1 = 1, y also satisfies the initial condition. Now let s plot the Euler approximation and the exact solution. To plot the Euler approximation, we need to put the x and y coordinates in a nice form for Maple to use. Type z:=[seq([x[i],y[i]],i=0..5)]; Now we can plot these points: with(plots); plot(z,style=point); Now let s compare this with the exact solution. First, we give this plot a name: plot1:=plot(z,style=point); Now we do the same with the exact solution, and then display them together. plot2:=plot(2*exp(x)-x-1,x=0..1); display(plot1,plot2); WOW! Now let s compute the error in the approximation at the right endpoint x = 1. The exact value is y(1) = 2e 2 = 3.43656, so the error is E = 3.43656 2.97664 = 0.45992 You will now investigate how the error changes as x is decreased. 4
Question 6. Repeat the procedure above (plotting optional), using x = 0.1 and x = 0.05. Fill in the tables below with the results. x = 0.1 x = 0.05 k x k y k 0 0 1 1 0.1 1.1 2 0.2 1.22 3 0.3 1.362 4 0.4 1.5282 5 0.5 1.72102 6 0.6 1.943122 7 0.7 2.1974342 8 0.8 2.48717762 9 0.9 2.815895382 10 1.0 3.187484920 k x k y k k x k y k 0 0 1 11 0.55 1.870678716 1 0.05 1.05 12 0.6 1.991712652 2 0.1 1.105 13 0.65 2.121298285 3 0.15 1.16525 14 0.7 2.259863199 4 0.2 1.2310125 15 0.75 2.407856359 5 0.25 1.302563125 16 0.8 2.565749177 6 0.3 1.380191281 17 0.85 2.734036636 7 0.35 1.464200845 18 0.9 2.913238468 8 0.4 1.554910887 19 0.95 3.103900391 9 0.45 1.652656431 20 1.0 3.306595411 10 0.5 1.757789253 Question 7. Use the results from of the previous question to calculate the error at x = 1. Put your results in the table below. x 0.2 0.1 0.05 Error at x = 1 0.45992 0.24908 0.12997 Question 8. What happens (approximately) to the error each time x is halved? Solution. The error is halved. 5