1 Second Order Ordinary Differential Equations 1.1 The harmonic oscillator Consider an ideal pendulum as shown below. θ l Fr mg l θ is the angular acceleration θ is the angular velocity A point mass m is suspended on a pendulum of length l. It is subject to a restoring force F r that can be expressed as F r = mg sinθ. Using Newton s law Force = mass acceleration we obtain mg sinθ = ml θ. For small angles θ we can substitute sinθ θ and obtain θ + g l θ = 0. Putting y θ and x t the ODE can also be written as y + ky = 0 and describes a harmonic oscillator with a restoring force that is proportional to y. It is one of the most fundamental examples of a second order ODE with constant coefficients. 1.1 February 2010
The general solution is given as y(x) = A sin( kx) + B cos( kx) In order to obtain a unique solution we need to specify two initial conditions (or boundary conditions). We could for example say that we require y(0) = 0, y (0) = 1. This means that the oscillator starts from the zero position (y(0) = 0) with a nonzero velocity (y (0) = 1). To solve for the constants A and B we write down y(0) = A sin 0 + B cos 0 = B = 0 y (x) = A k cos( kx) assuming B = 0 y (0) = A k cos 0 = A k = 1 We obtain the particular solution y(x) = 1 k sin( kx). 1.2 Motion with constant acceleration Consider a motion with constant acceleration a. It can be described by d 2 y dt = a or ÿ = a 2 where a is acceleration, t is time and y is position. This can simply be integrated twice: integrating once gives where u is initial velocity, ẏ = at + u, 1.2 February 2010
and then again gives where b is the initial position. y = 1 2 at2 + ut + b We again see that we need to specify two conditions in order to obtain a unique solution, e.g. the initial velocitiy u and the initial position b. 1.3 Homogeneous 2nd order ODEs Unlike constant acceleration, most 2nd order ODEs cannot be solved by integrating twice. The general form for a linear 2nd order ODE is p(x) d2 y dx + q(x)dy + r(x)y = f(x) 2 dx If f(x) = 0 the equation is homogeneous If f(x) 0 the equation is inhomogeneous (or non-homogeneous) If p(x), q(x) and r(x) are all constants, the equation is with constant coefficients N.B. q(x) and/or r(x) can be zero, but p(x) 0 otherwise the equation would not be 2nd order! 1.3 February 2010
1.4 Superposition of Solutions The important fact about linear homogeneous differential equations is that, if y 1 (x) and y 2 (x) are solutions, so is Ay 1 (x) + By 2 (x) (where A and B are constants). In physics this is called the principle of superposition. We will be making great use of this fact. To see this. Let y 1 (x) and y 2 (x) be solutions of the ODE, i.e. p(x)y 1 + q(x)y 1 + r(x)y 1 = 0 p(x)y 2 + q(x)y 2 + r(x)y 2 = 0 Multiply 1st equation by A and add B times the 2nd equation p(x)(ay 1 + By 2 ) + q(x)(ay 1 + By 2 ) + r(x)(ay 1 + By 2 ) = 0 since A and B are constant this can be expressed as p(x)(ay 1 +By 2 ) +q(x)(ay 1 +By 2 ) +r(x)(ay 1 +By 2 ) = 0 which implies that is also a solution of the ODE. Ay 1 + By 2 1.4 February 2010
1.5 Constant Coefficient 2nd Order ODEs We now restrict our attention to homogeneous ODEs of second order with constant coefficients. These are equations of the form a d2 y dx + bdy + cy = 0, 2 dx with the coefficients a, b and c being constants. It turns out that solutions to these linear equations when the coefficients are constants can almost always be written as exponentials. So for the equation above, try the function y = e λx dy dx = d 2 y λeλx, dx = 2 λ2 e λx and see what you get by substituting in: Factorizing this: aλ 2 e λx + bλe λx + ce λx = 0 e λx( aλ 2 + bλ + c ) = 0. Now e λx 0 so for y = e λx to be a solution λ must satisfy the auxiliary equation: good lecture break aλ 2 + bλ + c = 0. 1.5 February 2010
Solving the auxiliary equation aλ 2 + bλ + c = 0 gives two roots: λ 1 = b + b 2 4ac 2a and λ 2 = b b 2 4ac 2a There may be two real roots, two complex roots (necessarily complex conjugates), or one repeated real root. The case that you get is dependent on the discriminant b 2 4ac. There are correspondingly three types of solution: (1). b 2 4ac > 0: The two roots λ 1 and λ 2 are real and distinct. The general solution is y = Ae λ 1x + Be λ 2x. (2). b 2 4ac = 0: Repeated roots λ 1 = λ 2 (call this λ). The general solution is y = (Ax + B) e λx. (3). b 2 4ac < 0: The roots are complex conjugates, say λ 1 = α + iβ and λ 2 = α iβ, and the general solution is y = e αx( A cos βx + B sinβx ). Notice that all these general solutions have two constants of integration (A and B) In practice, if initial conditions (or boundary conditions) are given then the final step is to substitute this information into the general solution to find A and B. 1.6 February 2010
Case (1) 2 distinct real roots: This means that both y = e λ 1x and y = e λ 2x are solutions. Any linear combination of solutions to a homogeneous linear equation is also a solution, giving the following general solution (the solution with constants A and B not known): y = Ae λ 1x + Be λ 2x. If suitable initial or boundary conditions are known, the constants can be determined. ODE: d 2 y dx + dy 2 dx 2y = 0 auxiliary eqn: λ 2 + λ 2 = 0 Solutions: λ 1 = 1, λ 2 = 2 General solution: y = Ae x + Be 2x 25 180 250 160 20 140 200 15 120 A=0,B=3 100 150 A=1,B=4 10 5 A=3,B=0 A=2,B=0 A=1,B=0 80 A=0,B=2 60 40 A=0,B=1 20 100 A=2,B=2 50 A=1,B=1 0 2 1.5 1 0.5 0 0.5 1 1.5 2 0 2 1.5 1 0.5 0 0.5 1 1.5 2 0 2 1.5 1 0.5 0 0.5 1 1.5 2 Solution curves for various (A, B) for y = Ae x + Be 2x Note that depending on the initial conditions (which determine the values of A and B) there are a variety of curves which satisfy the differential equation d2 y + dy 2y = 0. dx 2 dx 1.7 February 2010
Case (2) repeated real roots λ 1 = λ 2 = λ: As in (1) y = Ae λx will be a solution. However, we need 2 constants, because it s a second order equation. Go back to the original equation and substitute y = xe λx and you will find that it also satisfies the ODE. Adding the two solutions gives the following general solution: An example of this is y = Axe λx + Be λx = (Ax + B)e λx ODE: d 2 y dx 2 2dy dx + y = 0 auxiliary eqn: λ 2 2λ + 1 = (λ 1) 2 = 0 Solution: λ = 1 General solution: y = (A + Bx) e x 25 20 15 A=1, B=1 10 5 0 5 A=1, B= 1 A= 1, B=1 10 2 1.5 1 0.5 0 0.5 1 1.5 2 Solution curves for various (A, B) for y = (A + Bx)e x 1.8 February 2010
Case (3) 2 complex conjugate roots λ 1 = α + iβ, λ 2 = α iβ: We obtain the general solution y = Ce (α+iβ)x + De (α iβ)x = e αx (Ce iβx + De iβx ). Using Eulers relation e iβx = cos βx + i sinβx this becomes y(x) = e αx (A cosβx + B sinβx), where A = C + D and B = (C D)i. An example is ODE: d 2 y dx 2 + 2dy dx + 2y = 0 auxiliary eqn: λ 2 + 2λ + 2 = 0 Solution: λ = 1 ± i General solution: y = e x (A cos x + B sinx) 10 8 A= 1,B= 1 6 4 A=1, B= 1 2 0 2 4 A= 1, B=1 6 8 A=1, B=1 10 2 1.5 1 0.5 0 0.5 1 1.5 2 Solution curves for various (A, B) for y = e x (Acos x + B sinx) 1.9 February 2010
Hyperbolic Solutions In cases where b = 0 and λ 1, λ 2 are real, the answer can be expressed as hyperbolic functions, for example: ODE: d 2 y dx 4y = 0 2 auxiliary eqn: λ 2 4 = 0 Solution: λ = ±2, General solution: y = Ae 2x + Be 2x. Using the fact that coshx + sinhx = e x and coshx sinhx = e x we can rewrite the general solution as: y = A(cosh 2x + sinh 2x) + B(cosh 2x sinh 2x) = (A + B) cosh 2x + (A B) sinh 2x = C cosh 2x + D sinh 2x where C and D are constants. 1.10 February 2010
1.6 Study of a damped harmonic oscillator We consider the ODE of a damped oscillator. y + dy + ky = 0, where d describes the damping and k describes the restoring force of the oscillator. With the ansatz y = e λx we have to solve λ 2 + dλ + k = 0 to determine λ. We obtain the solutions λ 1,2 = d ± d 2 4k. 2 In the following we always use the initial conditions y(0) = 1, y (0) = 0 which corresponds to a pendulum whose initial displacement is equal to one and is released from rest. 1.6.1 The overdamped case Assume that d 2 4k > 0, i.e. there are two real and distinct solutions λ 1 and λ 2. For the ODE we obtain the general solution which has no oscillations. y(x) = Ae λ 1x + Be λ 2x, 1.11 February 2010
To compute A and B we substitute the initial conditions and obtain y(0) = A + B = 1 y (0) = Aλ 1 + Bλ 2 = 0. We get and B = λ 1 λ 1 λ 2, A = λ 2 λ 1 λ 2 y(x) = 1 λ 1 λ 2 (λ 1 e λ 2x λ 2 e λ 1x ). 1 0.9 0.8 0.7 d 2 4k > 0 y(0) = 1 y (0) = 0 0.6 y(x) 0.5 0.4 0.3 0.2 0.1 0 0 1 2 3 4 5 6 7 8 9 10 x Figure 1: Plot of the solution for d = 2.1, k = 1. with initial condition y (0) < 0 this can pass through the equilibrium position, but only once 1.12 February 2010
1.6.2 The critically damped case If d 2 = 4k we get a repeated real root λ = d/2 and a solution y 1 = e λx We can find a second solution of the form differentiating out y 2 = u(x)y 1 y 2 = u y 1 + uy 1 y 2 = u y 1 + 2y 1 u + uy 1 and substituting into the original ode y + dy + ky = 0 to get u y 1 + (2y 1 + dy 1 )u + (y 1 + dy 1 + ky 1 )u = 0 Now since λ = d/2 2y 1 + dy 1 = 2λe λx + de λx = 0, and since y 1 is a solution of the ODE y 1 + dy 1 + ky 1 = 0 which implies the unknown function satisfies u = 0 Integrating twice wrt x implies u = Ax + B 1.13 February 2010
In this case the general solution is therefore y(x) = Ae λx + Bxe λx. Substituting the initial conditions leads to y(0) = A = 1, y (0) = λa + B = 0 B = λ It follows that y(x) = e λx (1 λx). 1 0.9 d 2 = 4k 0.8 0.7 0.6 y(x) 0.5 0.4 0.3 0.2 0.1 0 0 1 2 3 4 5 6 7 8 9 10 x Figure 2: Plot of the solution for d = 2, k = 1. critical damping returns the pendulum close to the equilibrium position in the fastest time, without oscillating if y (0) = 0 1.14 February 2010
1.6.3 The underdamped case Assume that d 2 4k < 0 so there are two complex conjugate roots λ 1,2 = α ± iβ The solution is therefore of the form y = Ce (α+iβ)x + De (α iβ)x y = e αx (Ce iβx + D iβx ) Using Eulers relation e iβx = cos βx + i sinβx y = e αx (C cos βx + ic sinβx + D cosβx id sinβx) y = e αx ((C + D) cosβx + i(c D) sinβx) Defining A = C + D, B = i(c D) We have the general solution y(x) = e αx (A cosβx + B sinβx). Substituting the initial conditions leads to y(0) = A = 1 y (0) = αa + Bβ = 0. It follows that y(x) = e αx (cosβx α β sinβx). 1.15 February 2010
1.2 1 d 2 < 4k 0.8 0.6 y(x) 0.4 0.2 0 0.2 0 1 2 3 4 5 6 7 8 9 10 x Figure 3: Plot of the solution for d = 1.9, k = 1. 1 d 2 < 4k For small d 0.5 y(x) 0 0.5 0 1 2 3 4 5 6 7 8 9 10 x Figure 4: Plot of the solution for d = 0.5, k = 1. 1.16 February 2010
1.7 Inhomogeneous ODEs with Constant Coefficients Previously we have considered solutions of linear homogeneous ODEs, often called unforced differential equations a d2 y dx 2 + bdy dx + cy = 0 Differential equations arising from physical systems will often have additional terms which represent some input to the physical system - often called a forcing term. These have the following form: a d2 y dx + bdy + cy = f(x) 2 dx where a, b and c are constants. Here y represents the output of the system and f(x) would be some external input. 1.17 February 2010
1.8 Solution Method (1) Find the general solution y c to the corresponding homogeneous equation: a d2 y c dx + bdy c 2 dx + cy c = 0 y c is called the complementary function (i) solve auxiliary equation aλ 2 + bλ + c = 0 for roots λ 1,2 (ii) determine whether solution is case 1, 2 or 3 b 2 > 4ac y c = A exp(λ 1 x) + B exp(λ 2 x) b 2 = 4ac y c = (Ax + B) exp(λx) b 2 < 4ac y c = exp(αx)[a cos(βx) + B sin(βx)] (2) Find any solution y p to the inhomogeneous equation: a d2 y p dx + bdy p 2 dx + cy p = f(x) y p is a particular integral or particular solution (3) Add y c and y p to give the general solution: y = y c + y p y is the general solution of the inhomogeneous equation we started with. (We can do this because the equations are linear and thus the principle of superposition applies) (4) Now (and only now!) substitute initial conditions or boundary conditions if known. 1.18 February 2010
The form of the particular solution y p will depend on the form of f(x) and will normally be a similar type of function (i.e. if f(x) is a polynomial of degree two, it is likely y p will be also). 1.9 Example Solve the inhomogeneous equation, y + y 2y = 4x. Auxiliary equation for the complementary function is which has solutions λ 2 + λ 2 = 0 λ 1 = 2, λ 2 = 1 two real distinct roots so complementary function y c is y c = Ae 2x + Be x. To find a particular integral we use some (clever) guess work, but for now just notice that y = 2x 1 satisfies the differential equation, so put y p = 2x 1. The general solution is therefore y = y c + y p = Ae 2x + Be x 2x 1. 1.19 February 2010
Finding the particular integral y p The Method of Undetermined Coefficients (a) Write a function of the same form as f(x) but with unknown constants, for example: f(x) trial solution a constant y p = m x 2 + 1 y p = mx 2 + nx + k a polynomial of order n y p = polynomial of order n ae hx y p = me hx a cosωx + b sinωx y p = m cosωx + n sinωx (NB: a or b may be zero, m, n, k and h are constants.) (b) First check that your proposed y p is not a solution to the homogeneous equation. If it is, then multiply by x and try again. (c) To find the coefficients (m, n, k, h,... ) substitute the trial solution into the differential equation and solve. 1.20 February 2010
Example 1 Find the general solution of the ODE d 2 y dx 2 + 2dy dx where y(0) = 0 and dy dx (0) = 1. (i) First find y c : The auxiliary equation is + 2y = sin 2x λ 2 + 2λ + 2 = 0, so λ = 1 ± i and the complementary function is y c = e x (A cosx + B sinx). (ii) Now find y p : (a) Try y p = m cos 2x + n sin 2x (b) This is not a solution to the homogeneous equation so we can proceed. (c) Calculate derivatives y p = 2m sin 2x + 2n cos 2x y p = 4m cos 2x 4n sin 2x 1.21 February 2010
(d) substitute y p and its derivatives into the original ODE: ( 4m cos 2x 4n sin 2x) + 2( 2m sin 2x + 2n cos 2x) + 2(m cos 2x + n sin 2x) = sin 2x gathering cos and sin terms together (4n 2m) cos 2x + ( 2n 4m) sin 2x = sin 2x Comparing coefficients 4n 2m = 0, 2n 4m = 1 gives m = 1/5, n = 1/10 and y p = 1 5 1 cos 2x sin 2x 10 (iii) The general solution is therefore: y = y c + y p = e x (A cos x + B sinx) 1 5 1 cos 2x sin 2x 10 good lecture break 1.22 February 2010
Recall y = e x (A cos x + B sinx) 1 5 1 cos 2x sin 2x 10 (iv) As we are given initial conditions, we now find A and B. y(0) = e 0 (A cos 0 + B sin 0) 1 5 cos 0 1 10 sin 0 = 0 A 1/5 = 0, A = 1/5 The derivative of y is y = e x [(B A) cos x (A + B) sinx)]+ 2 5 sin 2x 1 cos 2x 5 y (0) = e 0 [(B A) cos 0 (A + B) sin 0)]+ 2 5 sin 0 1 cos 0 = 1. 5 gathering coefficients of cos and sin B A 1/5 = 1, B 1/5 1/5 = 1, B = 7/5, giving the final answer: ( 1 y = e x 5 cos x + 7 ) 5 sinx 1 1 cos 2x sin 2x 5 10 for the initial conditions given. 1.23 February 2010
Example 2 Find the general solution of (i) Find y c : d 2 y dx 2 + 3dy dx + 2y = e x. Auxiliary equation: λ 2 + 3λ + 2 = 0, so λ = 2, or λ = 1 (ii) Find y p : (a) Try y p = me x y c = Ae 2x + Be x (b) This is a solution to the homogeneous equation and so will not work. Try y p = mxe x instead. (c) Calculate derivatives y p = e x (m mx) y p = e x (mx 2m) (d) Substitute into the differential equation gives e x (mx 2m) + 3e x (m mx) + 2e x mx = e x and simplifying gives e x [mx 2m + 3m 3mx + 2mx] = e x 1.24 February 2010
Cancelling e x mx 2m + 3m 3mx + 2mx = 1 m = 1 and the particular integral is y p = xe x. (iii) The general solution is therefore: y = y c + y p = Ae 2x + Be x + xe x NB The method of undetermined coefficients doesn t always work e.g. d 2 y dx + 3dy + 2y = lnx. 2 dx Try y p = a lnx, y p = a x, y p = a x 2, NO CANCELLATION. 1.25 February 2010
1.10 Inhomogeneous ODEs and Superposition As previously stated, the principle of superposition allows us to simply add solutions of linear equations to obtain new solutions. As an example consider the following: Find the solutions of each of the following ODEs: y + 3y + 2y = 4e 2x (1) y + 3y + 2y = cos(2x) (2) y + 3y + 2y = 4e 2x + cos(2x) (3) Note: Complimentary function y c is the same for each ODE. The corresponding homogeneous equation is: Auxiliary equation is roots are y c + 3y c + 2y c = 0 λ 2 + 3λ + 2 = 0 λ 1,2 = 3 ± 9 8 = 1, 2 2 so the complimentary function is y c = Ae x + Be 2x 1.26 February 2010
Particular solutions y p Case 1 Try y p = Ce 2x which not a solution of the homogenous form so we may continue. y I = 2Ce2x y I = 4Ce2x Substituting these into ODE (1) gives: 4Ce 2x + 6Ce 2x + 2Ce 2x = 4e 2x 4C + 6C + 2C = 4 C = 1 3 We now have the general solution: y = Ae x + Be 2x + 1 3 e2x Case 2 The forcing term is cos(2x) so we will assume y p = D sin(2x) + E cos(2x) Differentiating the trial solution twice yields: y p = 2D cos 2x 2E sin 2x y p = 4D sin 2x 4E cos 2x Substituting into ODE (2) gives: 4D sin 2x 4E cos 2x + 6D cos 2x 6E sin 2x... + 2D sin 2x + 2E cos 2x = cos 2x 1.27 February 2010
Gathering coefficients of sin 2x : 2D 6E = 0 cos 2x : 6D 2E = 1 This is a matrix equation for (D, E) T, i.e. ( ) 2 6 0 6 2 1 Row elimination Back substitution ( 2 6 0 0 20 1 ) E = 1/20, D = 3/20 We thus have the general solution Case 3: y = Ae x + Be 2x + 3 1 sin 2x cos 2x 20 20 Finding the general solution here is easy since we already know the previous two solutions. We can again use the principle of superposition to simply add the previous particular solutions. The general solution is therefore: y = Ae x + Be 2x + 1 3 e2x + 3 20 sin 2x 1 cos 2x 20 1.28 February 2010
1.11 Nonlinear Second Order Differential Equations There is NO general solution of the nonlinear 2nd order ODE y = f(x, y, y ), but there are some very useful special cases. Case 1: Equation with y missing y = f(x, y ), (4) In this case let z = y and equation (4) becomes z = f(x, z), which is a first order ODE, where you can apply the methods from the first semester. Example Substituting z = y gives xy + y = x z + z x = 1 which is a linear first order ODE use Integrating Factor ( ) 1 I.F. = exp x dx = exp(lnx) = x, d dx (xz) = x xz = 1 2 x2 + C Substituting z = y yields a first order ODE y = 1 2 x + C x This can be integrated directly to give y = 1 4 x2 + C lnx + D 1.29 February 2010
Case 2: Equation with x missing y = f(y, y ), (5) In this case let z = y and using the chain rule d 2 y dx = dz 2 dx = dz dy dy dx = zdz dy so equation (5) becomes z dz = f(y, z) dy which is again a first order ODE. Example yy (y ) 2 = 0 Putting z = y and using the chain rule, implies that yz dz dy = z2 Note that z = 0 y = C is a solution, as well as that obtained by solving the ODE dz dy = z y which is both separable and homogeneous dz dy = z y. It has solution z = By dy dx = By 1 dy y dx = B which integrates to y = A exp(bx) 1.30 February 2010