FIRST-ORDER ORDINARY DIFFERENTIAL EQUATIONS III: Numerical and More Analytic Methods David Levermore Department of Mathematics University of Maryland

Similar documents
Math 246, Spring 2011, Professor David Levermore

FIRST-ORDER ORDINARY DIFFERENTIAL EQUATIONS II: Graphical and Numerical Methods David Levermore Department of Mathematics University of Maryland

First In-Class Exam Solutions Math 246, Professor David Levermore Tuesday, 21 February log(2)m 40, 000, M(0) = 250, 000.

First In-Class Exam Solutions Math 246, Professor David Levermore Thursday, 20 September 2018

Consistency and Convergence

Solutions of the Sample Problems for the First In-Class Exam Math 246, Fall 2017, Professor David Levermore

First-Order Ordinary Differntial Equations II: Autonomous Case. David Levermore Department of Mathematics University of Maryland.

19 February Contents General Guidelines Tanks and Mixtures Loans Motion Population Dynamics 9

Solution. Your sketch should show both x and y axes marked from 5 to 5 and circles of radius 1, 3, and 5 centered at the origin.

Solution. It is evaluating the definite integral r 1 + r 4 dr. where you can replace r by any other variable.

FIRST-ORDER ORDINARY DIFFERENTIAL EQUATIONS I: Introduction and Analytic Methods David Levermore Department of Mathematics University of Maryland

FIRST-ORDER SYSTEMS OF ORDINARY DIFFERENTIAL EQUATIONS III: Autonomous Planar Systems David Levermore Department of Mathematics University of Maryland

ORDINARY DIFFERENTIAL EQUATION: Introduction and First-Order Equations. David Levermore Department of Mathematics University of Maryland

ORDINARY DIFFERENTIAL EQUATIONS: Introduction and First-Order Equations. David Levermore Department of Mathematics University of Maryland

First-Order Ordinary Differntial Equations: Classification and Linear Equations. David Levermore Department of Mathematics University of Maryland

Initial value problems for ordinary differential equations

Scientific Computing with Case Studies SIAM Press, Lecture Notes for Unit V Solution of

Chapter 6 - Ordinary Differential Equations

Numerical Differential Equations: IVP

8.7 MacLaurin Polynomials

2tdt 1 y = t2 + C y = which implies C = 1 and the solution is y = 1

8.5 Taylor Polynomials and Taylor Series

Lecture Notes to Accompany. Scientific Computing An Introductory Survey. by Michael T. Heath. Chapter 9

Euler s Method, cont d

ODE Runge-Kutta methods

HIGHER-ORDER LINEAR ORDINARY DIFFERENTIAL EQUATIONS IV: Variable Coefficient Nonhomogeneous Case

EXAMPLE OF ONE-STEP METHOD

Separable First-Order Equations

Scientific Computing: An Introductory Survey

CS 450 Numerical Analysis. Chapter 9: Initial Value Problems for Ordinary Differential Equations

Mathematics for chemical engineers. Numerical solution of ordinary differential equations

Ordinary Differential Equations

3 Algebraic Methods. we can differentiate both sides implicitly to obtain a differential equation involving x and y:

MATH 353 LECTURE NOTES: WEEK 1 FIRST ORDER ODES

Chapter 11 ORDINARY DIFFERENTIAL EQUATIONS

Ordinary Differential Equations II

NUMERICAL SOLUTION OF ODE IVPs. Overview

INTRODUCTION TO COMPUTER METHODS FOR O.D.E.

Taylor series. Chapter Introduction From geometric series to Taylor polynomials

Applied Math for Engineers

Homework and Computer Problems for Math*2130 (W17).

Explicit One-Step Methods

Lecture Notes on Numerical Differential Equations: IVP

13 Implicit Differentiation

Final Exam Sample Problems, Math 246, Spring 2018

Graded Project #1. Part 1. Explicit Runge Kutta methods. Goals Differential Equations FMN130 Gustaf Söderlind and Carmen Arévalo

First Order Differential Equations Lecture 3

Numerical differentiation

Ordinary Differential Equations II

Integration of Ordinary Differential Equations

Math Numerical Analysis Homework #4 Due End of term. y = 2y t 3y2 t 3, 1 t 2, y(1) = 1. n=(b-a)/h+1; % the number of steps we need to take

Higher Order Taylor Methods

Slope Fields: Graphing Solutions Without the Solutions

Math 252 Fall 2002 Supplement on Euler s Method

Lecture 4: Numerical solution of ordinary differential equations

Series Solutions. 8.1 Taylor Polynomials

4 Exact Equations. F x + F. dy dx = 0

Ordinary Differential Equations

5. Hand in the entire exam booklet and your computer score sheet.

Review for the First Midterm Exam

HIGHER-ORDER LINEAR ORDINARY DIFFERENTIAL EQUATIONS. David Levermore Department of Mathematics University of Maryland.

Fourth Order RK-Method

Numerical Analysis Exam with Solutions

4 Partial Differentiation

HIGHER-ORDER LINEAR ORDINARY DIFFERENTIAL EQUATIONS IV: Laplace Transform Method David Levermore Department of Mathematics University of Maryland

Week 4: Differentiation for Functions of Several Variables

Math 308 Week 8 Solutions

REVIEW OF DIFFERENTIAL CALCULUS

Math 111: Calculus. David Perkinson

19. TAYLOR SERIES AND TECHNIQUES

FORTRAN 77 Lesson 7. Reese Haywood Ayan Paul

A Brief Introduction to Numerical Methods for Differential Equations

Numerical Methods - Initial Value Problems for ODEs

Infinite series, improper integrals, and Taylor series

IES Parque Lineal - 2º ESO

Solutions to Final Exam Sample Problems, Math 246, Spring 2011

Mon Jan Improved acceleration models: linear and quadratic drag forces. Announcements: Warm-up Exercise:

Lecture for Week 2 (Secs. 1.3 and ) Functions and Limits

Chapter 8. Numerical Solution of Ordinary Differential Equations. Module No. 1. Runge-Kutta Methods

UCLA Math 135, Winter 2015 Ordinary Differential Equations

Initial value problems for ordinary differential equations

z x = f x (x, y, a, b), z y = f y (x, y, a, b). F(x, y, z, z x, z y ) = 0. This is a PDE for the unknown function of two independent variables.

First order di erential equations

Computational Techniques Prof. Dr. Niket Kaisare Department of Chemical Engineering Indian Institute of Technology, Madras

f(x 0 + h) f(x 0 ) h slope of secant line = m sec

Principles of Scientific Computing Local Analysis

Multistep Methods for IVPs. t 0 < t < T

HIGHER-ORDER LINEAR ORDINARY DIFFERENTIAL EQUATIONS IV: Laplace Transform Method. David Levermore Department of Mathematics University of Maryland

Department of Applied Mathematics and Theoretical Physics. AMA 204 Numerical analysis. Exam Winter 2004

MORE APPLICATIONS OF DERIVATIVES. David Levermore. 17 October 2000

Review for Final Exam, MATH , Fall 2010

MATH The Chain Rule Fall 2016 A vector function of a vector variable is a function F: R n R m. In practice, if x 1, x n is the input,

Introduction to Initial Value Problems

2 Numerical Methods for Initial Value Problems

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

8.1 Introduction. Consider the initial value problem (IVP):

2.2 Separable Equations

Lecture 42 Determining Internal Node Values

Physics 584 Computational Methods

Sometimes the domains X and Z will be the same, so this might be written:

Transcription:

FIRST-ORDER ORDINARY DIFFERENTIAL EQUATIONS III: Numerical and More Analytic Methods David Levermore Department of Mathematics University of Maryland 30 September 0 Because the presentation of this material in lecture will differ from that in the book, I felt that notes that closely follow the lecture presentation might be appreciated. Contents 8. First-Order Equations: Numerical Methods 8.. Numerical Approximations 8.. Explicit and Implicit Euler Methods 3 8.3. Explicit One-Step Methods Based on Taylor Approximation 4 8.3.. Explicit Euler Method Revisited 4 8.3.. Local and Global Errors 4 8.3.3. Higher-Order Taylor-Based Methods not covered) 5 8.4. Explicit One-Step Methods Based on Quadrature 6 8.4.. Explicit Euler Method Revisited Again 6 8.4.. Runge-Trapezoidal Method 7 8.4.3. Runge-Midpoint Method 9 8.4.4. Runge-Kutta Method 0 8.4.5. General Runge-Kutta Methods not covered) 9. Exact Differential Forms and Integrating Factors 9.. Implicit General Solutions 5 9.. Exact Differential Forms 6 9.3. Integrating Factors 0 0. Special First-Order Equations and Substitution 0.. Linear Argument Equations not covered) 5 0.. Dilation Invariant Equations not covered) 6 0.3. Bernoulli Equations not covered) 7 0.4. Substitution not covered) 9

8. First-Order Equations: Numerical Methods 8.. Numerical Approximations. Analytic methods are either difficult or impossible to apply to many first-order differential equations. In such cases direction fields might be the only graphical method that we have covered that can be applied. However, it can be very hard to understand how any particular solution behaves from the direction field of its governing equation. If one is interested in understanding how a particular solution behaves it is often easiest to use numerical methods to construct accurate approximations to the solution. These approximations can then be graphed much as we would an explicit solution. Suppose we are interested in the solution Y t) of the initial-value problem 8.) dt = ft, y), yt I) = y I, over the time interval [t I, t F ] i.e. for t I t t F. Here t I is called the initial time while t F is called the final time. A numerical method selects times {t n } N n=0 such that and computes values {y n } N n=0 such that t I = t 0 < t < t < < t N < t N = t F, y 0 = Y t 0 ) = y I, y n approximates Y t n ) for n =,,, N. For good numerical methods, these approximations will improve as N increases. So for sufficiently large N we can plot the points {t n, y n )} N n=0 in the t, y)-plane and connect the dots to get an accurate picture of how Y t) behaves over the time interval [t I, t F ]. Here we will introduce a few basic numerical methods in simple settings. The numerical methods used in software packages such as MATLAB are generally far more sophisticated than those we will stu here. They are however built upon the same fundamental ideas as the simpler methods we will stu. Throughout this section we will make the following two basic simplifications. We will employ uniform time steps. This means that given N we set 8.) h = t F t I N, and t n = t I + nh for n = 0,,, N, where h is called the time step. We will employ one-step methods. This means that given ft, y) and h the value of y n+ for n = 0,,, N will depend only on y n. Sophisticated software packages use methods in which the time step is chosen adaptively. In other words, the choice of t n+ will depend on the behavior of recent approximations for example, on t n, y n ) and t n, y n ). Employing uniform time steps will greatly simplify the algorithms, and thereby simplify the programming we you have to do. If you do not like the way a run looks, you will simply try again with a larger N. Similarly, sophisticated software packages will sometimes use so-called multi-step methods for which the value of y n+ for n = m, m+,, N will depend on y n, y n,, and y n m for some positive integer m. Employing one-step methods will again simplify the algorithms, and thereby simplify the programming you will have to do.

8.. Explicit and Implicit Euler Methods. The simplest and least accurate) numerical methods are the Euler methods. These can be derived many ways. Here we give a simple approach based on the definition of the derivative through difference quotients. If we start with the fact that Y t + h) Y t) lim = Y t) = ft, Y t)), h 0 h then for small positive h we have Y t + h) Y t) ft, Y t)). h Upon solving this for Y t + h) we find that Y t + h) Y t) + hft, Y t)). If we let t = t n above so that t + h = t n+ ) this is equivalent to Y t n+ ) Y t n ) + hft n, Y t n )). Because y n and y n+ approximate Y t n ) and Y t n+ ) respectively, this suggests setting 8.3) y n+ = y n + hft n, y n ) for n = 0,,, N. This so-called Euler method was introduced by Leonhard Euler in 768. Alternatively, we could have started with the fact that Y t) Y t h) lim h 0 h Then for small positive h we have = Y t) = ft, Y t)). Y t) Y t h) ft, Y t)). h Upon solving this for Y t h) we find that Y t h) Y t) hft, Y t)). If we let t = t n+ above so that t h = t n ) this is equivalent to Y t n+ ) hft n+, Y t n+ )) Y t n ). Because y n and y n+ approximate Y t n ) and Y t n+ ) respectively, this suggests setting 8.4) y n+ hft n+, y n+ ) = y n for n = 0,,, N. This method is called the implicit Euler or backward Euler method. It is called the implicit Euler method because equation 8.4) implicitly relates y n+ to y n. It is called the backward Euler method because the difference quotient upon which it is based steps backward in time from t to t h). In contrast, the Euler method 8.3) sometimes called the explicit Euler or forward Euler method because it gives y n+ explicitly and because the difference quotient upon which it is based steps forward in time from t to t + h). The implicit Euler method can be very inefficient unless equation 8.4) can be explicitly solved for y n+. This can be done when ft, y) is a fairly simple function if y. For example, it can be done when ft, y) is linear or quadratic in either y or y. However, there are equations for which the implicit Euler method will outperform the explicit Euler method. 3

4 8.3. Explicit One-Step Methods Based on Taylor Approximation. The explicit or forward) Euler method can be understood as the first in a sequence of explicit methods that can be derived from the Taylor approximation formula. 8.3.. Explicit Euler Method Revisited. The explicit Euler method can be derived from the first-order Taylor approximation, which is also known as the tangent line approximation. This approximation states that if Y t) is twice continuously differentiable then 8.5) Y t + h) = Y t) + hy t) + Oh ). Here the Oh ) means that the remainder vanishes at least as fast as h as h tends to zero. It is clear from 8.5) that for small positive h we have Y t + h) Y t) + hy t). Because Y t) satisfies 8.), this is the same as Y t + h) Y t) + hft, Y t)). If we let t = t n above so that t + h = t n+ ) this is equivalent to Y t n+ ) Y t n ) + hft n, Y t n )). Because y n and y n+ approximate Y t n ) and Y t n+ ) respectively, this suggests setting 8.6) y n+ = y n + hft n, y n ) for n = 0,,, N, which is exactly the Euler method 8.3). 8.3.. Local and Global Errors. One advantage of viewing the Euler method through the tangent line approximation 8.5) is that we gain some understanding of how its error behaves as we increase N, the number of time steps or what is equivalent by 8.), as we decrease h, the time step. The Oh ) term in 8.5) represents the local error, which is error the approximation makes at each step. Roughly speaking, if we halve the time step h then by 8.5) the local error will reduce by a factor of one quarter, while by 8.) the number of steps N we must take to get to a prescribed time say t F ) will double. If we assume that errors add which is often the case) then the error at t F will reduce by a factor of one half. In other words, doubling the number of time steps will reduce the error by about a factor of one half. Similarly, tripling the number of time steps will reduce the error by about a factor of one third. Indeed, it can be shown but we will not do so) that the error of the explicit Euler method is Oh) over the interval [t I, t F ]. The best way to think about this is that if we take N steps and the error made at each step is Oh ) then we can expect that the acummulation of the local errors will lead to a global error of Oh )N. Because 8.) states that hn = t F t I, which is a number that is independent of h and N, we see that global error of the explicit Euler method is Oh). This was shown by Cauchy in 84. Moreover, it can be shown that the error of the implicit Euler method behaves the same way. Global error is a more meaningful concept than local error because it tells us how fast a method converges over the entire interval [t I, t F ]. Therefore we identify the order of a method by the order of its global error. In particular, methods like the Euler methods with global errors of Oh) are first-order methods. By reasoning similar to that given in the previous paragraph, methods whose local error is Oh m+ ) will have a global error of Oh m+ )N = Oh m ) and thereby are m th -order methods.

Higher-order methods are more complicated than the explicit Euler method. The hope is that this cost is overcome by the fact that its error improves faster as you increase N or what is equivalent by 8.), as you decrease h. For example, if we halve the time step h of a fourth-order method then the global error will reduce by a factor of /6. Similarly, tripling the number of time steps will reduce the error by about a factor of /8. 8.3.3. Higher-Order Taylor-Based Methods. The second-order Taylor approximation states that if Y t) is thrice continuously differentiable then 8.7) Y t + h) = Y t) + hy t) + h Y t) + Oh 3 ). Here the Oh 3 ) means that the remainder vanishes at least as fast as h 3 as h tends to zero. It is clear from 8.7) that for small positive h one has 8.8) Y t + h) Y t) + hy t) + h Y t). Because Y t) satisfies 8.), we see by the chain rule from multivariable calculus that Y t) = d dt Y t) ) = d dt ft, Y t)) = tft, Y t)) + Y t) y ft, Y t)) = t ft, Y t)) + ft, Y t)) y ft, Y t)). Hence, equation 8.8) is the same as ) Y t + h) Y t) + hft, Y t)) + h t ft, Y t)) + ft, Y t)) y ft, Y t)). If we let t = t n above so that t + h = t n+ ) this is equivalent to ) Y t n+ ) Y t n ) + hft n, Y t n )) + h t ft n, Y t n )) + ft n, Y t n )) y ft n, Y t n )). Because y n and y n+ approximate Y t n ) and Y t n+ ) respectively, this suggests setting ) y n+ = y n + hft n, y n ) + 8.9) h t ft n, y n ) + ft n, y n ) y ft n, y n ) for n = 0,,, N. We call this the second-order Taylor-based method. Remark. We can generalize our derivation of the second-order Taylor-based method by using the m th -order Taylor approximation to derive an explicit numerical method whose error is Oh m ) over the interval [t I, t F ] a so-called m th -order method. However, the formulas for these methods grow in complexity. For example, the third-order method is ) y n+ = y n + hft n, y n ) + h t ft n, y n ) + ft n, y n ) y ft n, y n ) 8.0) + [ 6 h3 tt ft n, y n ) + ft n, y n ) yt ft n, y n ) + ft n, y n ) yy ft n, y n ) ) ] + t ft n, y n ) + ft n, y n ) y ft n, y n ) y ft n, y n ) for n = 0,,, N. This complexity of these methods makes them far less practical for general algorithms than the next class of methods we will stu. 5

6 8.4. Explicit One-Step Methods Based on Quadrature. The starting point for our next class of methods will be the Fundamental Theorem of Calculus specifically, the fact Y t + h) Y t) = Because Y t) satisfies 8.), this becomes 8.) Y t + h) = Y t) + t+h t t+h t Y s) ds. fs, Y s)) ds. In 895 Carl Runge proposed using quadrature rules numerical integration) to construct approximations to the definite integral above in the form 8.) t+h t fs, Y s)) ds = Kh, t, Y t)) + Oh m+ ), where m is some positive integer. The key point here is that Kh, t, Y t)) depends on Y t), but does not depend on Y s) for any s t. When approximation 8.) is placed into 8.) we obtain Y t + h) = Y t) + Kh, t, Y t)) + Oh m+ ). If we let t = t n above so that t + h = t n+ ) this is equivalent to Y t n+ ) = Y t n ) + Kh, t n, Y t n )) + Oh m+ ). Because y n and y n+ approximate Y t n ) and Y t n+ ) respectively, this suggests setting 8.3) y n+ = y n + Kh, t n, y n ) for n = 0,,, N, Hence, every approximation of the form 8.) yields the m th -order explicit one-step method 8.3) for approximating solutions of 8.). Here we will present methods associated with four basic quadrature rules that are covered in most calculus courses: the left-hand rule, the trapezoidal rule, the midpoint rule, and the Simpson rule. 8.4.. Explicit Euler Method Revisited Again. The left-hand rule approximates the definite integral on the left-hand side of 8.) as t+h t fs, Y s)) ds = hft, Y t)) + Oh ). This approximation is alrea in the form 8.) with Kh, t, y) = hft, y). Method 8.3) thereby becomes y n+ = y n + hft n, y n ) for n = 0,,, N, which is exactly the explicit Euler method 8.3). In practice, the explicit Euler method is implemented by initializing y 0 = y I and then for n = 0,, N cycling through the instructions f n = ft n, y n ), y n+ = y n + hf n, where t n = t I + nh. Example. Let Y t) be the solution of the initial-value problem dt = t + y, y0) =. Use the explicit Euler method with h =. to approximate Y.).

7 Solution. We initialize t 0 = 0 and y 0 =. The explicit Euler method then gives f 0 = ft 0, y 0 ) = 0 + = y = y 0 + hf 0 = +. =. f = ft, y ) =.) +.) =.0 +. =. y = y + hf =. +.. =. +. =. Therefore Y.) y =.. The explicit Euler method is implemented by the following MATLAB function M-file. function [t,y] = EulerExplicitf, ti, yi, tf, N) t = zerosn +, ); y = zerosn +, ); t) = ti; y) = yi; h = tf - ti)/n; for j = :N tj + ) = tj) + h; yj + ) = yj) + h*ftj), yj)); end Remark. There are some things you should notice. First, tj) is t j and yj) is y j, the approximation of yt j ). In particular, yj) is not the same as Y j), which denotes the solution Y t) evaluated at t = j. You must pay attention to the font in which a letter is written!) The shift of the indices by one is needed because indexed variables in MATLAB begin with the index. In particular, t) and y) denote the initial time t 0 and value y 0. Consequently, all subsequent indices are shifted too, so that t) and y) denote t and y, t3) and y3) denote t and y, etc. 8.4.. Runge-Trapezoidal Method. The trapezoidal rule approximates the definite integral on the left-hand side of 8.) as t+h t fs, Y s)) ds = h [ ft, Y t)) + ft + h, Y t + h)) ] + Oh 3 ). This approximation is not in the form 8.) because of the Y t + h) on the right-hand side. If we approximate this Y t + h) by the explicit Euler method then we obtain t+h t fs, Y s)) ds = h [ ft, Y t)) + f t + h, Y t) + hft, Y t)) )] + Oh 3 ). This approximation is in the form 8.) with Method 8.3) thereby becomes Kh, t, y) = h [ ft, y) + f t + h, y + hft, y) )]. y n+ = y n + h [ ftn, y n ) + f t n+, y n + hft n, y n ) )] for n = 0,,, N. The book calls this the improved Euler method. However, that name is sometimes used for other methods by other books and is not very descriptive. Rather, we will call this the Runge-trapezoidal method because it was proposed by Runge based on the trapeziodal rule.

8 In practice, the Runge-trapezoidal method is implemented by initializing y 0 = y I and then for n = 0,, N cycling through the instructions f n = ft n, y n ), f n+ = ft n+, ỹ n+ ), ỹ n+ = y n + hf n, y n+ = y n + h[f n + f n+ ], where t n = t I + nh. Example. Let yt) be the solution of the initial-value problem dt = t + y, y0) =. Use the Runge-trapezoidal method with h =. to approximate y.). Solution. We initialize t 0 = 0 and y 0 =. The Runge-trapezoidal method then gives f 0 = ft 0, y 0 ) = 0 + = ỹ = y 0 + hf 0 = +. =. f = ft, ỹ ) =.) +.) =.04 +.44 =.48 y = y 0 + h[ f 0 + f ] = +. +.48) = +..48 =.48 We then have y.) y =.48. Remark. Notice that two steps of the explicit Euler method with h =. gave y.)., while one step of the Runge-trapezoidal method with h =. gave y.).48, which is much closer to the exact value. As these two calculations required roughly the same computational effort, this shows the advantange of using the second-order method. The Runge-trapezoidal method is implemented by the following MATLAB function M-file. function [t,y] = RungeTrapf, ti, yi, tf, N) t = zerosn +, ); y = zerosn +, ); t) = ti; y) = yi; h = tf - ti)/n; hhalf = h/; for j = :N tj + ) = tj) + h; fnow = ftj), yj)); yplus = yj) + h*fnow; fplus = ftj + ), yplus); yj + ) = yj) + hhalf*fnow + fplus); end Remark. Here tj) and yj) have the same meaning as they did in the M-file for the explicit Euler method. In particular, we have the same shift of the indices by one. Here we have introduced the so-called working variables fnow, yplus, and fplus to temporarily hold the values of f j, ỹ j, and f j during each cycle of the loop. These values do not have to be saved, and so are overwritten with each new cycle. Here we have isolated the function evaluations for fnow and fplus into two separate lines. This is good coding practice that makes adaptations easier. For example, you can replace the function calls to ft,y) by explicit formulas in those two lines without touching the rest of the coding.

8.4.3. Runge-Midpoint Method. The midpoint rule approximates the definite integral on the left-hand side of 8.) as t+h t fs, Y s)) ds = hf t + h, Y t + h)) + Oh 3 ). This approximation is not in the form 8.) because of the Y t + h) on the right-hand side. If we approximate this Y t + h) by the explicit Euler method then we obtain t+h t fs, Y s)) ds = hf t + h, Y t) + hft, Y t))) + Oh 3 ). This approximation is in the form 8.) with Method 8.3) thereby becomes Kh, t, y) = hf t + h, y + hft, y)). y n+ = y n + hf t n+, y n + hft n, y n ) ) for n = 0,,, N. The text calls this the modified Euler method. However, that name is sometimes used for other methods by other books and is not very descriptive. Rather, we will call this the Runge-midpoint method because it was proposed by Runge based on the midpoint rule. In practice, the Runge-midpoint method is implemented by initializing y 0 = y I and then for n = 0,, N cycling through the instructions f n+ where t n = t I + nh and t n+ f n = ft n, y n ), = ft n+, y n+ ), = t I + n + )h. Remark. The half-integer subscripts on t n+ y n+ = y n + hf n, y n+ = y n + hf n+, y n+, and f n+, indicate that those variables are associated with the time t = t n + h, which is halfway between the times t n and t n+. While it may seem strange at first, this notational device is a han way to help keep track of the meanings of different variables. Example. Let yt) be the solution of the initial-value problem dt = t + y, y0) =. Use the Runge-midpoint method with h =. to approximate y.). Solution. We initialize t 0 = 0 and y 0 =. Then the Runge-midpoint method gives f 0 = ft 0, y 0 ) = 0 + = y = y 0 + hf 0 = +. =. f = ft, y ) =.) +.) =.0 +. =., y = y 0 + hf = +..) = +.44 =.44. We then have y.) y =.44. Remark. Notice that the Runge-trapezoidal method gave y.).48 while the Rungemidpoint method gave y.).44. The results are about the same because both methods are second-order. Here the Runge-trapezoidal method gave a better approximation. For other problems the Runge-midpoint method might give a better approximation. 9

0 The Runge-midpoint method is implemented by the following MATLAB function M-file. function [t,y] = RungeMidf, ti, yi, tf, N) t = zerosn +, ); y = zerosn +, ); t) = ti; y) = yi; h = tf - ti)/n; hhalf = h/; for j = :N thalf = tj) + hhalf; tj + ) = tj) + h; fnow = ftj), yj)); yhalf = yj) + hhalf*fnow; fhalf = fthalf, yhalf); yj + ) = yj) + h*fhalf; end Remark. Here tj) and yj) have the same meaning as they did in the M-file for the explicit Euler method. In particular, we have the same shift of the indices by one. Here we have introduced the working variables fnow, thalf, yhalf, and fhalf to temporarily hold the values of f j, t j, y j, and f j during each cycle of the loop. These values do not have to be saved, and so are overwritten with each new cycle. 8.4.4. Runge-Kutta Method. The Simpson rule approximates the definite integral on the left-hand side of 8.) as t+h t fs, Y s)) ds = h 6[ ft, Y t)) + 4f t + h, Y t + h)) + f t + h, Y t + h) )] + Oh 5 ). This approximation is not in the form 8.) because of the Y t + h) and Y t + h) on the right-hand side. If we approximate these with the explicit Euler method as we did before then we will degrade the local error to Oh 3 ). We would like to find an approximation that is consistent with the Oh 5 ) local error of the Simpson rule. In 90 Wilhelm Kutta found such an approximation, which led to the so-called Runge-Kutta method. We will not give a derivation of this method here. Such derivations can be found in numerical analysis books. In practice the Runge-Kutta method is implemented by initializing y 0 = y I and then for n = 0,, N cycling through the instructions f n+ f n+ f n = ft n, y n ), = ft n+, ỹ n+ ), ), = ft n+, y n+ f n+ = ft n+, ỹ n+ ), ỹ n+ y n+ = y n + hf n, = y n + h f n+,, ỹ n+ = y n + hf n+ y n+ = y n + h[ f 6 n + f n+ + f n+ + f ] n+, where t n = t I + nh and t n+ = t I + n + )h. Remark. The Runge-Kutta method requires four evaluations of ft, y) to advance each time step, whereas the second-order methods each required only two. Therefore it requires roughly twice as much computational work per time step as those methods.

Remark. Notice that because y n Y t n ), we see that ỹ n+ y n+ Y t n + h), Y t n + h), ỹ n+ Y t n + h), f n+ f n+ f n f t n, Y t n ) ) f t n + h, Y t n + h)), f t n + h, Y t n + h)), f n+ f t n + h, Y t n + h) ), y n+ Y t n ) + h 6[ ftn, Y t n )) + 4f t n + h, Y t n + h)) + f t n + h, Y t n + h) )]. The Runge-Kutta method thereby looks consistant with the Simpson rule approximation. This argument does not show that the Runge-Kutta method is fourth order, but it is. Example. Let yt) be the solution of the initial-value problem dt = t + y, y0) =. Use the Runge-Kutta method with h =. to approximate y.). Solution. We initialize t 0 = 0 and y 0 =. The Runge-Kutta method then gives f 0 = ft 0, y 0 ) = 0 + = ỹ f y f = y 0 + hf 0 = +. =. = ft, ỹ ) =.) +.) =.0 +. =. = y 0 + h f = +.. =. = ft, y ) =.) +.) =.0 +.58884 =.68884 ỹ = y 0 + hf = +..68884 = +.57768 =.57768 f = ft, ỹ ) =.) +.57768).04 +.56694557 =.60694557 y = y 0 + h[ f 6 0 + f + f + f ] +.033333333 [ +. +.68884 +.60694557 ]. We then have y.) y.58377. Of course, you would not be expected to carry out such arithmetic calculations to nine decimal places on an exam. Remark. One step of the Runge-Kutta method with h =. yielded the approximation y.).58377. This is more accurate than the approximations we had obtained with either second-order method. However, that is not a fair comparison because the Runge- Kutta method required roughly twice the computational work. A better comparison would be with the approximation produced by two steps of either second-order method with h =.. Remark. You will not be required to memorize the Runge-Kutta method. You also will not be required to carry out one step of it on an exam or quiz because, as the above example illustrates, the arithmetic gets messy even for fairly simple differential equations. However, you should understand the implications of it being a fourth-order method namely, the relationship between its error and time step h. You also should be able to recognize the Runge-Kutta method if it is presented to you in MATLAB code.

The Runge-Kutta method is implemented by the following MATLAB function M-file. function [t,y] = RungeKuttaf, ti, yi, tf, N) t = zerosn +, ); y = zerosn +, ); t) = ti; y) = yi; h = tf - ti)/n; hhalf = h/; hsixth = h/6; for j = :N thalf = tj) + hhalf; tj + ) = tj) + h; fnow = ftj), yj)); yhalfone = yj) + hhalf*fnow; fhalfone = fthalf, yhalfone); yhalftwo = yj) + hhalf*fhalfone; fhalftwo = fthalf, yhalftwo); yplus = yj) + h*fhalftwo; fplus = ftj + ), yplus); yj + ) = yj) + hsixth*fnow + *fhalfone + *fhalftwo + fplus); end Remark. Here tj) and yj) have the same meaning as they did in the M-file for the explicit Euler method. In particular, we have the same shift of the indices by one. Here we have introduced the working variables fnow, thalf, yhalfone, fhalfone, yhalftwo, fhalftwo, yplus, and fplus to temporarily hold the values of f j, t j, ỹ j, f j, y j, f j, ỹ j, and f j. 8.4.5. General Runge-Kutta Methods. All the methods presented in this section are members of the family of general Runge-Kutta methods. The MATLAB command ode45 uses the Dormand-Prince method, which is another member of this Runge-Kutta family that was discovered in 980! The Runge-Kutta family continues to be enlarged by new methods, some of which might replace the Dormand-Prince method in future versions of MATLAB. An introduction to these modern methods requires a graduate course in numerical analysis. Here we have the more modest goal of introducing those family members presented by Wilhelm Kutta in his 90 paper. Carl Runge had described just a few methods in his 895 paper, including the Runge trapezoid and midpoint methods. In 900 Karl Heun presented a family of methods that included all those studied by Runge as special cases. Heun characterized the computational effort of these methods by how many evaluations of ft, y) are needed to compute Kh, t, y). We say a method that requires s evaluations of ft, y) is an s-stage method. The explicit Euler method, for which Kh, t, y) = hft, y), is the only one-stage method. Heun considered the family of two-stage methods in the form 8.4a) Kh, t, y) = α 0 k 0 + α k, with α 0 + α =, where k 0 and k are given by two evaluations of ft, y) as 8.4b) k 0 = hft, y), k = hft + βh, y + βk 0 ), for some β > 0. Heun showed that a two-stage method 8.4) is second-order for any ft, y) if and only if α 0 = β, α = β.

These include the Runge trapeziodal method, which is given by α 0 = α = and β =, and the Runge midpoint method, which is given by α 0 = 0, α =, and β =. Heun also showed that no two-stage method 8.4) is third-order for any ft, y). Remark. Second-order, two-stage methods are often called Heun methods in recognition of his work. Of these Heun favored the method given by α 0 =, α 4 = 3, and β =, which is 4 3 third order in the special case when y f = 0. Heun also considered families of three- and four-stage methods in his 900 paper. However in 90 Kutta introduced families of s-stage methods that where more general when s 3. For example, Kutta considered the family of three-stage methods in the form 8.5a) Kh, t, y) = α 0 k 0 + α k + α k, with α 0 + α + α =, where k 0, k, and k are given by three evaluations of ft, y) as 8.5b) k 0 = hft, y), k = hft + β h, y + γ 0 k 0 ), with β = γ 0, k = hft + β h, y + γ 0 k 0 + γ k ), with β = γ 0 + γ. Kutta showed that a three-stage method 8.5) is second-order for any ft, y) if and only if α β + α β = ; and is third-order for any ft, y) if and only if in addition α β + α β = 3, α γ β = 6. Kutta also showed that no three-stage method 8.5) is fourth-order for any ft, y). Heun had shown the analogus results restricted to the case γ 0 = 0. He favored the third-order method given by α 0 = 4, α = 0, α = 3 4, β = γ 0 = 3, β = γ = 3, γ 0 = 0, which is the third-order method requiring the fewest arithmetic operations. Kutta favored the third-order method given by α 0 = 6, α = 3, α = 6, β = γ 0 =, β =, γ 0 =, γ =, which agrees with the Simpson rule in the special case when y f = 0. Similarly, Kutta considered the family of four-stage methods in the form 8.6a) Kh, t, y) = α 0 k 0 + α k + α k + α 3 k 3, with α 0 + α + α + α 3 =, where k 0, k, k, and k 3 are given by four evaluations of ft, y) as 8.6b) k 0 = hft, y), k = hft + β h, y + γ 0 k 0 ), with β = γ 0, k = hft + β h, y + γ 0 k 0 + γ k ), with β = γ 0 + γ, k 3 = hft + β 3 h, y + γ 30 k 0 + γ 3 k + γ 3 k ), with β 3 = γ 30 + γ 3 + γ 3. Kutta showed that a four-stage method 8.6) is second-order for any ft, y) if and only if α β + α β + α 3 β 3 = ; is third-order for any ft, y) if and only if in addition α β + α β + α 3β 3 = 3, α γ β + α 3 γ3 β + γ 3 β ) = 6 ; 3

4 and is fourth-order for any ft, y) if and only if in addition α β 3 + α β 3 + α 3 β 3 3 = 4, α γ β + α 3 γ3 β + γ 3 β ) =, α β γ β + α 3 β 3 γ3 β + γ 3 β ) = 8, α 3γ 3 γ β = 4, β 3 =. Kutta also showed that no four-stage method 8.6) is fifth-order for any ft, y). Heun had shown the analogus results restricted to the case γ 0 = γ 30 = γ 3 = 0. Kutta favored the classical Runge-Kutta method presented in the previous subsection, which is given by α 0 = 6, α = 3, α = 3, α 3 = 6, β = γ 0 =, β = γ =, γ 0 = 0, β 3 = γ 3 =, γ 30 = γ 3 = 0. This is the fourth-order method that both requires the fewest arithmetic operations and is consistant with the Simpson rule. More generally, Kutta considered the family of s-stage methods in the form s 8.7a) Kh, t, y) = α j k j, j=0 with s α j =, where k j for j = 0,, s are given by s evaluations of ft, y) as 8.7b) k 0 = hft, y), ) j j k j = hf t + β j h, y + γ ji k i, with β j = γ ji, for j =,, s. i=0 Kutta showed that no five-stage method 8.7) is fifth-order for any ft, y). This result was surprising because for s =,, 3, and 4 there were s-stage methods that were s th -order. Kutta then characterized those six-stage methods 8.7) that are fifth-order for any ft, y). We will not give the conditions he found here. Remark. Programmable electrionic computers were invented over fifty years after Runge, Heun, and Kutta carried out their work. Early numerical computations had less precision than they do today. Higher-order methods suffer from round-off error more than lowerorder methods. Because round-off error is larger on machines with less precision, there was little advantage to using higher-order methods on early machines. As machines became more precise, the classical Runge-Kutta method became widely used to solve differential equations because it offers a nice balance between order and round-off error. Remark. Perhaps the most important development in Runge-Kutta methods since their invention is embedded methods, which first appeared in 957. These methods maintain a prescribed error tolerance for an m th -order Runge-Kutta method by selecting a different h for each time step based on an error estimate made with a related m+) th -order Runge-Kutta method. By related we mean that the two methods are built from the same evaluations of ft, y), so that they can be computed almost simultaniously. The MATLAB command ode45 uses an embedded fourth-order/fifth-order method. Originally it used the Fehlberg embedded method, which was invented in 969. Currently it uses the Dormand-Prince embedded method, which was invented in 980. This method might be replaced by a higherorder embedded method as machines become faster and have smaller round-off error. j=0 i=0

5 9. Exact Differential Forms and Integrating Factors 9.. Implicit General Solutions. Consider a first-order ordinary equation in the form 9.) = fx, y), dx where fx, y) is continuously differentiable over a region R of the xy-plane. Our basic existence and uniqueness theorem then insures that for every point x I, y I ) within the interior of R there exists a unique solution y = Y x) of the differential equation 9.) that satisfies the initial condition Y x I ) = y I for so long as x, Y x)) remains within the interior of R. Let us ask the following question. When are the solutions of the differential equation 9.) determined by an equation of the form 9.) Hx, y) = c where c is some constant? This means that we seek a function Hx, y) defined over the interior of R such that the unique solution y = Y x) of the differential equation 9.) that satisfies the initial condition Y x I ) = y I is also the unique solution y = Y x) that satisfies 9.3) Hx, y) = Hx I, y I ), Y x I ) = y I. Such an Hx, y) is called an integral of 9.). Because every solution of 9.) that lies within the interior of R can be obtained in this way, we call relation 9.) an implicit general solution of 9.) over R. The question can now be recast as When does 9.) have an integral? This question is easily answered if we assume that all functions involved are as differentiable as we need. Suppose that an integral Hx, y) exists, and that y = Y x) is a solution of differential equation 9.). Then Hx, Y x)) = Hx I, Y x I )), where x I is any point in the interval of definition of Y. By differentiating this equation with respect to x we find that x Hx, Y x)) + Y x) y Hx, Y x)) = 0. Therefore, wherever y Hx, Y x)) 0 we see that Y x) = xhx, Y x)) y Hx, Y x)). For this to hold for every solution of 9.), we must have or equivalently dx = xhx, y) y Hx, y), 9.4) fx, y) = xhx, y) y Hx, y), wherever y Hx, y) 0. The question then arises as to whether we can find an Hx, y) such that 9.4) holds for any given fx, y)? It turns out that this cannot always be done. In this section we explore how to seek such an Hx, y).

6 9.. Exact Differential Forms. The starting point is to recast equation 9.) in a so-called differential form 9.5) Mx, y) dx + Nx, y) = 0, where Mx, y) and Nx, y) are continuously differentiable over a region R in the xy-plane and Mx, y) fx, y) = Nx, y). There is not a unique way to do this. Just pick one that looks natural. If you are lucky then there will exist a function Hx, y) such that 9.6) x Hx, y) = Mx, y), y Hx, y) = Nx, y). When this is the case the differential form 9.5) is said to be exact over the region R. Leonhard Euler showed that there is a simple test you can apply to find out if you are lucky. It derives from the fact that mixed partials commute namely, the fact that for any Hx, y) that is twice continously differentiable over R we have y x Hx, y) ) = x y Hx, y) ). This fact implies that if 9.6) holds for such an Hx, y) then Mx, y) and Nx, y) satisfy y Mx, y) = y x Hx, y) ) = x y Hx, y) ) = x Nx, y). In other words, if the differential form 9.5) is exact then Mx, y) and Nx, y) satisfy 9.7) y Mx, y) = x Nx, y). Euler showed that whenever R has no holes the converse holds too. Namely, if the differential form 9.5) satisfies 9.7) for every x, y) in R then it is exact i.e. there exists an Hx, y) such that 9.6) holds. Moreover, the problem of finding Hx, y) is reduced to finding two primitives. We illustrate this fact with examples. Example. Solve the initial-value problem dx + ex y + x y + e x = 0, y0) = 0. Solution. Express this equation in the differential form Because e x y + x) dx + y + e x ) = 0. y e x y + x) = e x = x y + e x ) = e x, this differential form satisfies 9.7) everywhere in the xy-plane and thereby is exact. Therefore we can find Hx, y) such that 9.8) x Hx, y) = e x y + x, y Hx, y) = y + e x. You can now integrate either equation, and plug the result into the other equation to obtain a second equation to integrate. If we first integrate the first equation in 9.8) then we find that Hx, y) = e x y + x) dx = e x y + x + hy).

Here we are integrating with respect to x while treating y as a constant. The function hy) is the constant of integration. We plug this expression for Hx, y) into the second equation in 9.8) to obtain e x + h y) = y Hx, y) = y + e x. This reduces to h y) = y. Notice that this equation for h y) only depends on y. Take hy) = y, so that Hx, y) = e x y+x +y is an integral of the differential equation. Therefore an implicit general solution is The initial condition y0) = 0 implies that Therefore The quadratic formula then yields Hx, y) = e x y + x + y = c. c = e 0 0 + 0 + 0 = 0. y + e x y + x = 0. y = ex + e x 4x, where the positive square root is taken so that solution satisfies the initial condition. This is a solution wherever e x > 4x. Alternative Solution. If we first integrate the second equation in 9.8) then we find that Hx, y) = y + e x ) = y + e x y + hx). Here we are integrating with respect to y while treating x as a constant. The function hx) is the constant of integration. We plug this expression for Hx, y) into the first equation in 9.8) to obtain e x y + h x) = x Hx, y) = e x y + x. This reduces to h x) = x. Notice that this equation for h x) only depends on x. Taking hx) = x, so Hx, y) = e x y + x + y, we see that a general solution satisfies e x y + x + y = c. Because this is the same relation for a general solution that we had found previously, the evaluation of c is done as before. The points to be made here are the following: In principle you can integrate either equation in 9.7) first. If you integrate with respect to x first then the constant of integration hy) will depend on y and the equation for h y) should only depend on y. If you integrate with respect to y first then the constant of integration hx) will depend on x and the equation for h x) should only depend on x. In either case, if your equation for h involves both x and y you have made a mistake! Sometimes the differential equation will be given to you alrea in differential form. In that case, use that form as the starting point. Example. Give an implicit general solution to the differential equation xy + y + e x ) dx + x y + x) = 0. 7

8 Solution. Because y xy + y + e x ) = xy + = x x y + x) = xy +. this differential form satisfies 9.7) everywhere in the xy-plane and thereby is exact. Therefore we can find Hx, y) such that x Hx, y) = xy + y + e x, y Hx, y) = x y + x. By integrating the second equation you obtain Hx, y) = x y + x) = x y + xy + hx). When we plug this expression for Hx, y) into the first equation we obtain xy + y + h x) = x Hx, y) = xy + y + e x, which yields h x) = e x. Notice that this only depends on x!) Take hx) = e x, so that Hx, y) = x y + xye x. Therefore an implicit general solution is x y + xy + e x = c. In the last example we could just as easily have integrated the equation for x Hx, y) first and plugged the resulting expression into the equation for y Hx, y). The next example shows that it can be helpful to first integrate whichever equation for Hx, y) is easier to integrate. Example. Give an implicit general solution to the differential equation x cosx)e y + x sinx)e y + e x cosy) ) dx + x sinx)e y e x siny) ) = 0. Solution. Because y x cosx)e y + x sinx)e y + e x cosy) ) = x cosx)e y + x sinx)e y e x siny), x x sinx)e y e x siny) ) = x cosx)e y + x sinx)e y e x siny), this differential form satisfies 9.7) and thereby is exact. Therefore we can find Hx, y) such that x Hx, y) = x cosx)e y + x sinx)e y + e x cosy), y Hx, y) = x sinx)e y e x siny). Now notice that it is more apparent how to integrate the bottom equation in y than how to integrate the top equation in x. Recall that integrating terms like x cosx) requires two integration-by-parts.) So integrating the bottom equation we obtain x Hx, y) = sinx)e y e x siny) ) = x sinx)e y + e x cosy) + hx). When we plug this expression for Hx, y) into the top equation we obtain x cosx)e y +x sinx)e y +e x cosy)+h x) = x Hx, y) = x cosx)e y +x sinx)e y +e x cosy), which yields h x) = 0. Taking hx) = 0, so that Hx, y) = x sinx)e y + e x cosy), we see that a general solution is given by x sinx)e y + e x cosy) = c.

Remark. Of course, had you seen that x cosx) + x sinx) is the derivative of x sinx) then you could have just as easily started by integrating the x Hx, y) equation with respect to x in the previous example. But such insights do not always arrive when you need them. We will now derive formulas for Hx, y) in terms of definite integrals that apply whenever R is a rectangle in the xy-plane and x I, y I ) is any point that lies within the interior of R. These formulas will encode the two steps given above. They thereby show that those steps can always be carried out in this setting. We consider a differential form 9.9) Mx, y) dx + Nx, y) = 0, where Mx, y) and Nx, y) are continuously differentiable over R and satisfy 9.0) y Mx, y) = x Nx, y). Now seek Hx, y) such that 9.) x Hx, y) = Mx, y), y Hx, y) = Nx, y). By integrating the first equation with respect to x we obtain Hx, y) = x x I Mr, y) dr + hy). When we plug this expression for Hx, y) into the second equation, use 9.0) to assert that y Mr, y) = r Nr, y), and apply the First Fundamental Theorem of Calculus, we obtain Nx, y) = y Hx, y) = = x x I y Mr, y) dr + h y) x x I r Nr, y) dr + h y) = Nx, y) Nx I, y) + h y). This yields h y) = Nx I, y), which only depends on y because x I is a number. Let hy) = y y I Nx I, s) ds. An implicit general solution of 9.9) thereby is Hx, y) = c, where Hx, y) is given by Hx, y) = x x I Mr, y) dr + y y I Nx I, s) ds. Notice that Hx I, y I ) = 0. If the second equation in 9.) had been integrated first then we would have found that an implicit general solution of 9.9) is Hx, y) = c, where Hx, y) is given by Hx, y) = x x I Mr, y I ) dr + y y I Nx, s) ds. The above formulas give two expressions for the same function Hx, y). Rather than memorize these formulas, I strongly recommend that you simply learn the steps underlying them. Remark. In the two examples given previously the rectange R was the entire xy-plane. This will be the case whenever Mx, y) and Nx, y) appearing in the differential form 9.9) are continuously differentiable over the entire xy-plane and satisfy 9.0). 9

0 Remark. Our recipe for separable equations can be viewed as a special case of our recipe for exact differential forms. Consider the separable first-order ordinary differential equation dx = fx)gy). It can be put into the differential form fx) dx gy) = 0. This differential form is exact because ) y fx) = 0 = x gy) Therefore we can find Hx, y) such that Indeed, we find that = 0. x Hx, y) = fx), y Hx, y) = gy). Hx, y) = Fx) Gy), where F x) = fx) and G y) = gy). Therefore an implicit general solution is Fx) Gy) = c. This is precisely the recipe for solving separable equations that we derived earlier. 9.3. Integrating Factors. Suppose you had considered the differential form 9.) Mx, y) dx + Nx, y) = 0, and found that is not exact. Just because you were unlucky the first time, do not give up! Recall that this differential form has the same solutions as any differential form in the form 9.3) Mx, y)µx, y) dx + Nx, y)µx, y) = 0, where µx, y) any nonzero function. Indeed, both 9.) and 9.3) are differential forms associated with the first-order differential equation dx = fx, y), where fx, y) = Mx, y) Nx, y) = Mx, y)µx, y) Nx, y)µx, y). Therefore we can seek a nonzero function µx, y) that makes the differential form 9.3) exact! This means that µx, y) must satisfy y [ Mx, y)µx, y) ] = x [ Nx, y)µx, y) ]. Expanding the above partial derivatives using the product rule, we see that µ must satisfy 9.4) Mx, y) y µ + [ y Mx, y)]µ = Nx, y) x µ + [ x Nx, y)]µ. This is a first-order linear partial differential equation for µ. Finding its general solution is equivalent to finding the general solution of the original ordinary differential equation. Fortunately, we do not need this general solution. All we need is one nonzero solution. Such a µ is called an integrating factor for the differential form 9.).

A trick that sometimes yields a solution of 9.4) is to assume either that µ is only a function of x, or that µ is only a function of y. When µ is only a function of x then y µ = 0 and 9.4) reduces to the first-order linear ordinary differential equation dµ dx = ymx, y) x Nx, y) µ. Nx, y) This equation will be consistent with our assumption that µ is only a function of x when the fraction on its right-hand side is independent of y. In that case we can integrate the equation to find the integrating factor µx) = e Ax), where A x) = ymx, y) x Nx, y) Nx, y) Similarly, when µ is only a function of y then x µ = 0 and 9.4) reduces to the first-order linear ordinary differential equation dµ = xnx, y) y Mx, y) µ. Mx, y) This equation will be consistent with our assumption that µ is only a function of y when the fraction on its right-hand side is independent of x. In that case we can integrate the equation to find the integrating factor µy) = e By), where B y) = xnx, y) y Mx, y) Mx, y) This will be the only method for finding integrating factors that we will use in this course. Remark. Rather than memorize the above formulas for µx) and µy) in terms of primitives, I strongly recommend that you simply follow the steps by which they were derived. Namely, you seek an integrating factor µ that satisfies y [Mx, y) µ] = x [Nx, y) µ]. You then expand the partial derivatives using the product rule as Mx, y) y µ + [ y Mx, y)] µ = Nx, y) x µ + [ x Nx, y)] µ, and combine the µ terms. If the resulting equation reduces to an equation that only depends on x when you set y µ = 0 then there is an integrating factor µx). On the other hand, if the equation reduces to an equation that only depends on y when you set x µ = 0 then there is an integrating factor µy). We will illustrate this approach with the following examples. Example. Give an implicit general solution to the differential equation e x + y 3 ) dx + 3y = 0. Solution. This differential form is not exact because y e x + y 3 ) = 3y x 3y ) = 0. Therefore we seek an integrating factor µ such that y [e x + y 3 )µ] = x [3y )µ]. Expanding the partial derivatives using the product rule gives e x + y 3 ) y µ + 3y µ = 3y x µ...

Notice that if y µ = 0 then this equation reduces to µ = x µ, whereby µx) = e x is an integrating factor. See how easy that was!) Because e x is an integrating factor, we know that e x + y 3 )e x dx + 3y e x = 0 is exact. Of course, you should check that this is exact. If it is not then you made a mistake in finding µ!) Therefore we can find Hx, y) such that x Hx, y) = e x + y 3 e x, y Hx, y) = 3y e x. By intgrating the second equation we see that Hx, y) = y 3 e x + hx). When this expression for Hx, y) is plugged into the first equation we obtain y 3 e x + h x) = x Hx, y) = e x + y 3 e x, which yields h x) = e x. Upon taking hx) = e x, so that Hx, y) = y 3 e x + e x, a general solution satisfies y 3 e x + e x = c. In this case the general solution can be given explicitly as y = ce x e x ) 3, where c is an arbitrary constant. Example. Give an implicit general solution to the differential equation xy dx + x e y ) = 0. Solution. This differential form is not exact because y xy) = x x x e y ) = 4x. Therefore we seek an integrating factor µ such that y [xy)µ] = x [x e y )µ]. Expanding the partial derivatives using the product rule gives Combining the µ terms then yields xy y µ + xµ = x e y ) x µ + 4xµ. xy y µ = x e y ) x µ + xµ. Notice that if x µ = 0 then this equation reduces to y y µ = µ, whereby µy) = y is an integrating factor. See how easy that was!) Because y is an integrating factor, we know that Therefore we can find Hx, y) such that xy dx + x e y )y = 0 is exact. x Hx, y) = xy, y Hx, y) = x y e y y. By intgrating the first equation we see that Hx, y) = x y +hy). When this expression for Hx, y) is plugged into the second equation we obtain x y + h y) = y Hx, y) = x y e y y,

which yields h y) = e y y. Upon taking hy) = e y y), so that Hx, y) = x y +e y y), a general solution satisfies x y + e y y) = c. In this case we cannot solve for y explicitly. Remark. Sometimes it might not be evident whether we should set y µ = 0 or x µ = 0 when searching for the integrating factor µ. The next example illustrates such a case. Example. Give an implicit general solution to the differential equation 4xy + 3y 3 ) dx + x + 3xy ) = 0. Solution. This differential form is not exact because y 4xy + 3y 3 ) = 4x + 9y x x + 3xy ) = x + 3y. Therefore we seek an integrating factor µ such that Expanding the partial derivatives gives y [4xy + 3y 3 )µ] = x [x + 3xy )µ]. 4xy + 3y 3 ) y µ + 4x + 9y )µ = x + 3xy ) x µ + x + 3y )µ. Combining the µ terms yields 4xy + 3y 3 ) y µ + x + 6y )µ = x + 3xy ) x µ. At this point it might not be evident whether we should set y µ = 0 or x µ = 0. However, the picture becomes clear once we notice that x + 3y ) is a common factor of the last two terms. Hence, if we set y µ = 0 then this becomes x + 3y )µ = x + 3y )x x µ, which reduces to µ = x x µ. This yields the integrating factor µ = x. Because x is an integrating factor, the differential form Therefore we can find Hx, y) such that 4xy + 3y 3 )x dx + x + 3xy )x = 0 is exact. x Hx, y) = 4x 3 y + 3x y 3, y Hx, y) = x 4 + 3x 3 y. Integrating the first equation with respect to x yields whereby Hx, y) = x 4 y + x 3 y 3 + hy), y Hx, y) = x 4 + 3x 3 y + h y). Plugging this expression for y Hx, y) into the second equation gives x 4 + 3x 3 y + h y) = x 4 + 3x 3 y, which yields h y) = 0. Taking hy) = 0, an implicit general solution is therefore given by x 4 y + x 3 y 3 = c. 3 Solving for y explicitly requires the cubic formula, which you are not expected to know.

4 Remark. Integrating factors for the linear equations can be viewed as a special case of the foregoing method. Consider the linear first-order ordinary differential equation + ax)y = fx). dx It can be put into the differential form ) ax)y fx) dx + = 0. This differential form is generally not exact because when ax) 0 we have y ax)y fx) ) = ax) x = 0. Therefore we seek an integrating factor µ such that y [ ax)y fx) ) µ ] = x µ. Expanding the partial derivatives by the product rule gives ax)y fx) ) y µ + ax)µ = x µ. Notice that if y µ = 0 then this equation reduces to ax)µ = x µ, whereby an integrating factor is µx) = e Ax) where A x) = ax). Because e Ax) is an integrating factor, we know that Therefore we can find Hx, y) such that e Ax) ax)y fx) ) dx + e Ax) = 0 is exact. x Hx, y) = e Ax) ax)y fx) ), y Hx, y) = e Ax). By intgrating the second equation we see that Hx, y) = e Ax) y+hx). When this expression for Hx, y) is plugged into the first equation we obtain e Ax) ax)y + h x) = x Hx, y) = e Ax) ax)y fx) ), which yields h x) = e Ax) fx). Therefore a general solution is Hx, y) = c with Hx, y) given by Hx, y) = e Ax) y Bx), where A x) = ax) and B x) = e Ax) fx). This can be solved to obtain the explicit general solution y = e Ax) c + e Ax) Bx). This is equivalent to the recipe for solving linear equations that we derived previously.