LECTURE 7: INTEGRATING FACTOR AND EULER’S METHOD MINGFENG ZHAO September 17, 2014 To solve an exact equation M (x, y) + N (x, y) y 0 = 0: 1) Compute My (x, y) and Nx (x, y) 2) By checking My = Nx to say M (x, y) + N (x, y) y 0 = 0 is exact. 3) Since M (x, y) + N (x, y) y 0 = 0 is exact, then there exists some φ(x, y) such that φx (x, y) = M (x, y), and φy (x, y) = N (x, y). 4) Since φx (x, y) = M (x, y), then Z φ(x, y) = M (x, y) dx + f (y). 5) Since φy (x, y) = N (x, y), take the partial derivative with respect to y on the both sides of φ(x, y) = Z M (x, y) dx + f (y), then Z N (x, y) = φy (x, y) = My (x, y) dx + f 0 (y). 6) Compute f (y), that is, Z Z f (y) = N (x, y) − My (x, y) dx dy. 7) Write down the solution: Z φ(x, y) = My (x, y) dx + Z Z N (x, y) − My (x, y) dx dy = C. Example 1. Solve y(3x2 y + y 2 ) + y(2x3 + 3xy) y 0 = 0. Let M (x, y) = y(3x2 y + y 2 ) = 3x2 y 2 + y 3 and N (x, y) = y(2x3 + 3xy) = 2x3 y + 3xy 2 , then ∂M (x, y) = 6x2 y + 3y 2 , ∂y and ∂N (x, y) = 6x2 y + 3y 2 . ∂x So y(3x2 y + y 2 ) + y(2x3 + 3xy) y 0 = 0 is exact. That is, there exists some φ(x, y) such that φx (x, y) = y(3x2 y + y 2 ), and φy (x, y) = y(2x3 + 3xy). 1 2 MINGFENG ZHAO Since φx (x, y) = ey (3x2 y + y 2 ), then Z φ(x, y) = y(3x2 y + y 2 ) dx + f (y) = x3 y 2 + xy 3 + f (y). Take the partial derivative with respect to y, since φy (x, y) = y(2x3 + 3xy), then y(2x3 + 3xy) = φy (x, y) = 2x3 y + 3xy 2 + f 0 (y). So f 0 (y) = 0, then we can take f (y) = 0. So the solution to y(3x2 y + y 2 ) + y(2x3 + 3xy) y 0 = 0 is: x3 y 2 + xy 3 = C . Question 1. How can we solve for the general differential equation M (x, y) + N (x, y) y 0 = 0 which may not be exact? In general, consider differential equation: M (x, y) + N (x, y) y 0 = 0. Multiply some function µ(x, y) on both sides of equation: [µM ] + [µN ] y 0 = 0. If the above equation is exact (in this case, we call µ integrating factor), that is, ∂(µM ) ∂(µN ) = . ∂y ∂x By the product rule, we get µMy + M µy = µNx + N µx . We have the following two special cases: I. If µ(x) is a function of x, tha is, µy ≡ 0, then µMy = µNx + N µx . That is, µ satisfies µx = µ · My − Nx . N In this case, we only need M y − Nx is a function of x. N Hence µ=e R My −Nx N dx . LECTURE 7: INTEGRATING FACTOR AND EULER’S METHOD 3 II. If µ(y) is a function of y, tha is, µx ≡ 0, then µMy + M µy = µNx . That is, µ satisfies Nx − My . M µy = µ · In this case, we only need Nx − M y is a function of y. M So we get µ=e R Nx −My M dy . Remark 1. In homework and exams, we only consider µ is a function of only x. In this case, to solve the general differential equation: M (x, y) + N (x, y) y 0 = 0: My (x, y) − Nx (x, y) . N (x, y) 2) Understand the meaning of the integrating factor µ: 1) Compute My (x, y), Nx (x, y) and [µM ] + [µN ] y 0 = 0 is exact, that is, ∂(µN ) ∂(µM ) = . ∂y ∂x 3) Take the integrating factor: R µ(x) = e My −Nx N dx 4) Solve the exact equation: (µM ) + (µN ) y 0 = 0. Example 2. Solve Let M (x, y) = y2 + 2yex + (y + ex )y 0 = 0. 2 y2 + 2yex and N (x, y) = y + ex , then 2 My (x, y) = y + 2ex , and Nx (x, y) = ex . Then My − Nx = y + 2ex − ex = y + ex = N. So M y − Nx =1 N is a function of x. Then we can take the integrating factor µ(x) = e R x dx = ex . 4 MINGFENG ZHAO That is, we get an exact equation: e x y2 + 2yex 2 y2 + 2yex , 2 + ex (y + ex ) y 0 = 0. Then there exists some φ(x, y) such that φx = e x x Since φx = e and φy = ex (y + ex ). y2 x + 2ye , then 2 2 Z y y2 x x φ= e + 2ye dx + f (y) = ex + ye2x + f (y). 2 2 Take the partial derivative with respect to y, since φy = N , then we get ex (y + ex ) = N (x, y) = φy (x, y) = yex + e2x + f 0 (y). Then f 0 (y) = 0. So we can take f (y) = 0. Hence the solution to y2 + 2yex + (y + ex )y 0 = 0 is: 2 y2 x e + e2x y = C . 2 Example 3. Solve y 0 + p(x)y = q(x). Rewrite the equation: [p(x)y − q(x)] + y 0 = 0. Let M (x, y) = p(x)y − q(x) and N (x, y) = 1, then My = p(x), and Nx = 0. So M y − Nx = p(x) N is a function of x. Then we can take the integrating factor µ(x) = e R p(x) dx . That is, we get an exact equation: e R p(x) dx [p(x)y − q(x)] + e R p(x) dx y 0 = 0. LECTURE 7: INTEGRATING FACTOR AND EULER’S METHOD 5 Then there exists some φ(x, y) such that φx = e Since φy = e R p(x) dx R p(x) dx [p(x)y − q(x)], and φy = e R p(x) dx . , then R p(x) dx φ(x, y) = ye + g(x). Take the partial derivative with respect to x, we get R e p(x) dx R [p(x)y − q(x)] = φx = ye p(x) dx · p(x) + g 0 (x). So g 0 (x) = −q(x)e R p(x) dx . That is, Z g(x) = − R p(x) dx . R p(x) dx = 0. q(x)e So we get R ye p(x) dx Z − q(x)e Hence, the general solution to y 0 + p(x)y = q(x) is: y=e − R p(x) dx Z · R q(x)e p(x) dx dx . Numerical methods: Euler’s method Consider the initial value problem: y 0 = f (x, y), y(x0 ) = y0 . Euler’s method: Given the initial condition y(x0 ) = y0 and the step size h, compute the point (xk+1 , yk+1 ) from the previous point (xk , yk ) as follows: 1) Use the differential equation to compute the slope f (xk , yk ). 2) Calculate the next point (xk+1 , yk+1 ) using the formula xk+1 = xk + h yk+1 = yk + hf (xk , yk ) 6 MINGFENG ZHAO Let xk = x0 + kh, and x1 = x0 + h y1 = y0 + hf (x0 , y0 ) x2 = x1 + h y2 = y1 + hf (x1 , y1 ) x3 = x2 + h .. . y3 = y2 + hf (x2 , y2 ) .. . xk+1 = xk + h .. . yk+1 = yk + hf (xk , yk ) .. . Example 4. Use Euler’s method to approximate y(3), where y 0 = y2 , y(0) = 1. 3 If h = 1, then k xk yk f (xk , yk ) 0 0 1 1 3 1 1 4 3 16 27 2 2 52 27 2704 2187 3 3 6916 2187 ≈ 3.16232 dy = 2y − 1, y(0) = 1, h = 0.1. Approximate the solution over the interval 0 ≤ t ≤ 0.5. dx We should compute 5 interactions of Euler’s method: Example 5. k xk yk f (xk , yk ) 0 0 1 1 1 0.1 1.1 1.2 2 0.2 1.22 1.44 3 0.3 1.364 1.73 4 0.4 1.537 2.07 5 0.5 1.744 Department of Mathematics, The University of British Columbia, Room 121, 1984 Mathematics Road, Vancouver, B.C. Canada V6T 1Z2 E-mail address: mingfeng@math.ubc.ca