Calculus Research Lab 3: Differential Equations!

2,136 views

Published on

Published in: Education, Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,136
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
39
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Calculus Research Lab 3: Differential Equations!

  1. 1. Introductory Differential Equations using SAGE David Joyner 11-22-2007
  2. 2. There are some things which cannotbe learned quickly, and time, which is all we have,must be paid heavily for their acquiring.They are the very simplest things,and because it takes a man’s life to know themthe little new that each man gets from lifeis very costly and the only heritage he has to leave. Ernest Hemingway(From A. E. Hotchner, Papa Hemingway, Random House, NY, 1966)
  3. 3. Contents1 First order differential equations 1 1.1 Introduction to DEs . . . . . . . . . . . . . . . . . . . . . . . 1 1.2 Initial value problems . . . . . . . . . . . . . . . . . . . . . . . 10 1.3 First order ODEs - separable and linear cases . . . . . . . . . 15 1.4 Isoclines and direction fields . . . . . . . . . . . . . . . . . . . 24 1.5 Numerical solutions - Euler’s method and improved Euler’s method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 1.6 Newtonian mechanics . . . . . . . . . . . . . . . . . . . . . . . 38 1.7 Application to mixing problems . . . . . . . . . . . . . . . . . 442 Second order differential equations 49 2.1 Linear differential equations . . . . . . . . . . . . . . . . . . . 50 2.2 Linear differential equations, continued . . . . . . . . . . . . . 57 2.3 Undetermined coefficients method . . . . . . . . . . . . . . . . 63 2.3.1 Annihilator method . . . . . . . . . . . . . . . . . . . . 72 2.4 Variation of parameters . . . . . . . . . . . . . . . . . . . . . . 74 2.5 Applications of DEs: Spring problems . . . . . . . . . . . . . . 79 2.5.1 Part 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 2.5.2 Part 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 2.5.3 Part 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 2.6 Applications to simple LRC circuits . . . . . . . . . . . . . . . 93 2.7 The power series method . . . . . . . . . . . . . . . . . . . . . 99 2.7.1 Part 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 2.7.2 Part 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 2.8 The Laplace transform method . . . . . . . . . . . . . . . . . 112 2.8.1 Part 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 2.8.2 Part 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 vii
  4. 4. 3 Systems of first order differential equations 127 3.1 An introduction to systems of DEs: Lanchester’s equations . . 128 3.2 The Gauss elimination game and applications to systems of DEs133 3.3 Eigenvalue method for systems of DEs . . . . . . . . . . . . . 149 3.4 Electrical networks using Laplace transforms . . . . . . . . . . 1594 Introduction to partial differential equations 165 4.1 Introduction to separation of variables . . . . . . . . . . . . . 165 4.2 Fourier series, sine series, cosine series . . . . . . . . . . . . . . 172 4.3 The heat equation . . . . . . . . . . . . . . . . . . . . . . . . 183 4.4 The wave equation in one dimension . . . . . . . . . . . . . . 195
  5. 5. Preface The vast majority of this book comes from lecture notes I have been typingup over the years for a could on differential equations with boundary valueproblems at the USNA. Though the USNA is a government institution andofficial work-related writing is in the public domain, I typed and polishedso much of this at home during the night and weekends that I feel I havethe right to claim copyright over this work. The DE course has used variouseditions of the following three books (in order of most common use to leastcommon use) at various times: • Dennis G. Zill and Michael R. Cullen, Differential equations with Boundary Value Problems, 6th ed., Brooks/Cole, 2005. • R. Nagle, E. Saff, and A. Snider, Fundamentals of Differential Equations and Boundary Value Problems, 4th ed., Addison/Wesley, 2003. • W. Boyce and R. DiPrima, Elementary Differential Equations and Boundary Value Problems, 8th edition, John Wiley and Sons, 2005.You may see some similarities but, for the most part, I have taught things abit differently and tried to impart this in these notes. Time will tell if thereare any improvements. A new feature to this book is the fact that every section has at least oneSAGE exercise. SAGE is FOSS (free and open source software), available onthe most common computer platforms. Royalties for the sales of this book(if it ever makes it’s way to a publisher) will go to further development ofSAGE . This book is free and open source. It is licensed under the Attribution-ShareAlike Creative Commons license, http: // creativecommons. org/ licenses/by-sa/ 3. 0/ , or the Gnu Free Documentation License (GFDL), http:// www. gnu. org/ copyleft/ fdl. html , at your choice.
  6. 6. Acknowledgments In a few cases I have made use of the excellent (public domain!) lecturenotes by Sean Mauch,Sean Mauch, Introduction to methods of Applied Mathematics,http://www.its.caltech.edu/~sean/book/unabridged.html I some cases, I have made use of the material on Wikipedia, this includesboth discussion and in a few cases, diagrams or graphics. This material islicensed under the GFDL or the Attribution-ShareAlike Creative Commonslicense. In any case, the amount used here probably falls under the “fair use”clause. Software used: Most graphics was created using SAGE (http://www.sagemath.org/) andGIMP http://www.gimp.org/ by the author. The circuit diagrams werecreated using Dia http://www.gnome.org/projects/dia/ and GIMP http://www.gimp.org/ by the author. A few spring diagrams were taken fromWikipedia. Of course, LaTeX was used for the typesetting. Many thanks tothe developers of these programs for these free tools.
  7. 7. Intro... If people do not believe that mathematics is simple, it is only because they do not realize how complicated life is. - John von NeumannTo be written ...
  8. 8. Chapter 1First order differentialequations1.1 Introduction to DEs But there is another reason for the high repute of mathe- matics: it is mathematics that offers the exact natural sciences a certain measure of security which, without mathematics, they could not attain. - Albert Einstein Motivation Roughly speaking, a differential equation is an equation involving the deriva-tives of one or more unknown functions. In calculus (differential, integral and vector), you’ve studied ways of ana-lyzing functions. You might even have been convinced that functions youmeet in applications arise naturally from physical principles. As we shallsee, differential equations arise naturally from general physical principles. Inmany cases, the functions you met in calculus in applications to physics wereactually solutions to a “natural” differential equation.Example 1.1.1. Consider a falling body of mass m on which exactly 3 forcesact: 1
  9. 9. • gravitation, Fgrav , • air resistance, Fres , • an external force, Fext = f (t), where f (t) is some given function. 6 Fres Fgrav mass m ?Let x(t) denote the distance fallen from some fixed initial position. Thevelocity is denoted by v = x′ and the acceleration by a = x′′ . We choosean orientation so that downwards is positive. In this case, Fgrav = mg,where g > 0 is the gravitational constant. We assume that air resistance isproportional to velocity (a common assumption in physics), and write Fres =−kv = −kx′ , where k > 0 is a “friction constant”. The total force, Ftotal , isby hypothesis, Ftotal = Fgrav + Fres + Fext ,and, by Newton’s 2nd Law1 , Ftotal = ma = mx′′ .Putting these together, we have mx′′ = ma = mg − kx′ + f (t),or mx′′ + mx′ = f (t) + mg.This is a differential equation in x = x(t). It may also be rewritten as adifferential equation in v = v(t) = x′ (t) as 1 “Force equals mass times acceleration.” http://en.wikipedia.org/wiki/Newtons_law
  10. 10. mv ′ + kv = f (t) + mg.This is an example of a “first order differential equation in v”, which meansthat at most first order derivatives of the unknown function v = v(t) occur. In fact, you have probably seen solutions to this in your calculus classes, atleast when f (t) = 0 and k = 0. In that case, v ′ (t) = g and so v(t) = g dt =gt + C. Here the constant of integration C represents the initial velocity. Differential equations occur in other areas as well: weather prediction (moregenerally, fluid-flow dynamics), electrical circuits, the heat of a homogeneouswire, and many others (see the table below). They even arise in problemson Wall Street: the Black-Scholes equation is a PDE which models the pric-ing of derivatives [BS-intro]. Learning to solve differential equations helpsunderstand the behaviour of phenomenon present in these problems. phenomenon description of DE weather Navier-Stokes equation [NS-intro] a non-linear vector-valued higher-order PDE falling body 1st order linear ODE motion of a mass attached Hooke’s spring equation to a spring 2nd order linear ODE [H-intro] motion of a plucked guitar string Wave equation 2nd order linear PDE [W-intro] Battle of Trafalger Lanchester’s equations system of 2 1st order DEs [L-intro], [M-intro], [N-intro] cooling cup of coffee Newton’s Law of Cooling in a room 1st order linear ODE population growth logistic equation non-linear, separable, 1st order ODEUndefined terms and notation will be defined below, except for the equationsthemselves. For those, see the references or wait until later sections whenthey will be introduced2 . Basic Concepts: Here are some of the concepts to be introduced below: 2 Except for the Navier-Stokes equation, which is more complicated and might take ustoo far afield.
  11. 11. • dependent variable(s), • independent variable(s), • ODEs, • PDEs, • order, • linearity, • solution. It is really best to learn these concepts using examples. However, here arethe general definitions anyway, with examples to follow. The term “differential equation” is sometimes abbreviated DE, for brevity. Dependent/independent variables: Put simply, a differential equationis an equation involving derivatives of one of more unknown functions. Thevariables you are differentiating with respect to are the independent vari-ables of the DE. The variables (the “unknown functions”) you are differenti-ating are the dependent variables of the DE. Other variables which mightoccur in the DE are sometimes called “parameters”. ODE/PDE: If none of the derivatives which occur in the DE are partialderivatives (for example, if the dependent variable/unknown function is afunction of a single variable) then the DE is called an ordinary differentialequation of PDE. If some of the derivatives which occur in the DE arepartial derivatives then the DE is a partial differential equation or PDE. Order: The highest total number of derivatives you have to take in theDE is it’s order. Linearity: This can be described in a few different ways. First of all, a DEis linear if the only operations you perform on its terms are combinations ofthe following: • differentiation with respect to independent variable(s), • multiplication by a function of the independent variable(s).
  12. 12. Another way to define linearity is as follows. A linear ODE having inde-pendent variable t and the dependent variable is y is an ODE of the form a0 (t)y (n) + ... + an−1 (t)y ′ + an (t)y = f (t),for some given functions a0 (t), . . . , an (t), and f (t). Here dn y(t) y (n) = y (n) (t) = dtndenotes the n-th derivative of y = y(t) with respect to t. The terms a0 (t),. . . , an (t) are called the coefficients of the DE and we will call the termf (t) the non-homogeneous term or the forcing function. (In physicalapplications, this term usually represents an external force acting on thesystem. For instance, in the example above it represents the gravitationalforce, mg.) Solution: An explicit solution to a DE having independent variable t andthe dependent variable is x is simple a function x(t) for which the DE is truefor all values of t. Here are some examples:Example 1.1.2. Here is a table of examples. As an exercise, determinewhich of the following are ODEs and which are PDEs. DE indep vars dep vars order linear? mx′′ + kx′ = mg t x 2 yes falling body mv ′ + kv = mg t v 1 yes falling body 2 k ∂ u = ∂u ∂x2 ∂t t, x u 2 yes heat equation mx′′ + bx′ + kx = f (t) t x 2 yes spring equation P P ′ = k(1 − K )P t P 1 no logistic population equation 2 2 k ∂ u = ∂ 2u ∂x2 ∂ t t, x u 2 yes wave equation T ′ = k(T − Troom ) t T 1 yes Newton’s Law of Cooling x′ = −Ay, y ′ = −Bx, t x, y 1 yes Lanchester’s equations
  13. 13. Remark: Note that in many of these examples, the symbol used for theindependent variable is not made explicit. For example, we are writing x′when we really mean x′ (t) = x(t) . This is very common shorthand notation dtand, in this situation, we shall usually use t as the independent variablewhenever possible.Example 1.1.3. Recall a linear ODE having independent variable t and thedependent variable is y is an ODE of the form a0 (t)y (n) + ... + an−1 (t)y ′ + an (t)y = f (t),for some given functions a0 (t), . . . , an (t), and f (t). The order of this DE isn. In particular, a linear 1st order ODE having independent variable t andthe dependent variable is y is an ODE of the form a0 (t)y ′ + a1 (t)y = f (t),for some a0 (t), a1 (t), and f (t). We can divide both sides of this equation bythe leading coefficient a0 (t) without changing the solution y to this DE. Let’sdo that and rename the terms: y ′ + p(t)y = q(t),where p(t) = a1 (t)/a0 (t) and q(t) = f (t)/a0 (t). Every linear 1st order ODEcan be put into this form, for some p and q. For example, the falling bodyequation mv ′ +kv = f (t)+mg has this form after dividing by m and renamingv as y. P What does a differential equation like mx′′ + kx′ = mg or P ′ = k(1 − K )P 2u 2uor k ∂ 2 = ∂ 2 t really mean? In mx′′ + kx′ = mg, m and k and g are given ∂x ∂constants. The only things that can vary are t and the unknown functionx = x(t).Example 1.1.4. To be specific, let’s consider x′ + x = 1. This means for allt, x′ (t) + x(t) = 1. In other words, a solution x(t) is a function which, whenadded to its derivative you always get the constant 1. How many functionsare there with that property? Try guessing a few “random” functions: • √ Guess x(t) = sin(t). Compute (sin(t))′ + sin(t) = cos(t) + sin(t) = 2 sin(t + π ). x′ (t) + x(t) = 1 is false. 4
  14. 14. • Guess x(t) = exp(t) = et . Compute (et )′ + et = 2et . x′ (t) + x(t) = 1 is false. • Guess x(t) = exp(t) = t2 . Compute (t2 )′ + t2 = 2t + t2 . x′ (t) + x(t) = 1 is false. • Guess x(t) = exp(−t) = e−t . Compute (e−t )′ +e−t = 0. x′ (t)+x(t) = 1 is false. • Guess x(t) = exp(t) = 1. Compute (1)′ +1 = 0+1 = 1. x′ (t)+x(t) = 1 is true.We finally found a solution by considering the constant function x(t) = 1.Here a way of doing this kind of computation with the aid of the computeralgebra system SAGE : SAGEsage: t = var(’t’)sage: de = lambda x: diff(x,t) + x - 1sage: de(sin(t))sin(t) + cos(t) - 1sage: de(exp(t))2*eˆt - 1sage: de(tˆ2)tˆ2 + 2*t - 1sage: de(exp(-t))-1sage: de(1)0Note we have rewritten x′ + x = 1 as x′ + x − 1 = 0 and then plugged variousfunctions for x to see if we get 0 or not. Obviously, we want a more systematic method for solving such equationsthan guessing all the types of functions we know one-by-one. We will get tothose methods in time. First, we need some more terminology. IVP: A first order initial value problem (abbreviated IVP) is a problemof the form
  15. 15. x′ = f (t, x), x(a) = c,where f (t, x) is a given function of two variables, and a, c are given constants.The equation x(a) = c is the initial condition. Under mild conditions of f , an IVP has a solution x = x(t) which is unique.This means that if f and a are fixed but c is a parameter then the solutionx = x(t) will depend on c. This is stated more precisely in the followingresult.Theorem 1.1.1. (Existence and uniqueness) Fix a point (t0 , x0 ) in the plane.Let f (t, x) be a function of t and x for which both f (t, x) and fx (t, x) = ∂f∂x (t,x)are continuous on some rectangle a < t < b, c < x < d,in the plane. Here a, b, c, d are any numbers for which a < t0 < b andc < x0 < d. Then there is an h > 0 and a unique solution x = x(t) for which x′ = f (t, x), for all t ∈ (t0 − h, t0 + h),and x(t0 ) = x0 . This is proven in §2.8 of Boyce and DiPrima [BD-intro], but we shall notprove this here. In most cases we shall run across, it is easier to constructthe solution than to prove this general theorem.Example 1.1.5. Let us try to solve x′ + x = 1, x(0) = 1.The solutions to the DE x + x = 1 which we “guessed at” in the previous ′example, x(t) = 1, satisfies this IVP. Here a way of finding this slution with the aid of the computer algebrasystem SAGE : SAGEsage: t = var(’t’)sage: x = function(’x’, t)sage: de = lambda y: diff(y,t) + y - 1sage: desolve_laplace(de(x(t)),["t","x"],[0,1])’1’
  16. 16. (The command desolve_laplace is a DE solver in SAGE which uses a specialmethod involving Laplace transforms which we will learn later.) Just as anillustration, let’s try another example. Let us try to solve x′ + x = 1, x(0) = 2.The SAGE commands are similar: SAGEsage: t = var(’t’)sage: x = function(’x’, t)sage: de = lambda y: diff(y,t) + y - 1sage: desolve_laplace(de(x(t)),["t","x"],[0,2])’%eˆ-t+1’age: solnx = lambda s: RR(eval(soln.replace("ˆ","**"). replace("%","").replace("t",str(s))))sage: solnx(3)1.04978706836786sage: P = plot(solnx,0,5)sage: show(P)The plot is given below. Figure 1.1: Solution to IVP x′ + x = 1, x(0) = 2.
  17. 17. Exercise: Verify the, for any constant c, the function x(t) = 1 + ce−t solvesx′ + x = 1. Find the c for which this function solves the IVP x′ + x = 1,x(0) = 3.. Solve this (a) by hand, (b) using SAGE .1.2 Initial value problemsA 1-st order initial value problem, or IVP, is simply a 1-st order ODEand an initial condition. For example, x′ (t) + p(t)x(t) = q(t), x(0) = x0 ,where p(t), q(t) and x0 are given. The analog of this for 2nd order linearDEs is this: a(t)x′′ (t) + b(t)x′ (t) + c(t)x(t) = f (t), x(0) = x0 , x′ (0) = v0 ,where a(t), b(t), c(t), x0 , and v0 are given. This 2-nd order linear DE andinitial conditions is an example of a 2-nd order IVP. In general, in an IVP,the number of initial conditions must match the order of the DE.Example 1.2.1. Consider the 2-nd order DE x′′ + x = 0.(We shall run across this DE many times later. As we will see, it representsthe displacement of an undamped spring with a unit mass attached. The termharmonic oscillator is attached to this situation [O-ivp].) Suppose we knowthat the general solution to this DE is x(t) = c1 cos(t) + c2 sin(t),for any constants c1 , c2 . This means every solution to the DE must be of thisform. (If you don’t believe this, you can at least check it it is a solution bycomputing x′′ (t)+x(t) and verifying that the terms cancel, as in the followingSAGE example. Later, we see how to derive this solution.) Note that thereare two degrees of freedom (the constants c1 and c2 ), matching the order ofthe DE. SAGEsage: t = var(’t’)
  18. 18. sage: c1 = var(’c1’)sage: c2 = var(’c2’)sage: de = lambda x: diff(x,t,t) + xsage: de(c1*cos(t) + c2*sin(t))0sage: x = function(’x’, t)sage: soln = desolve_laplace(de(x(t)),["t","x"],[0,0,1])sage: soln’sin(t)’sage: solnx = lambda s: RR(eval(soln.replace("t","s")))sage: P = plot(solnx,0,2*pi)sage: show(P)This is displayed below. Now, to solve the IVP x′′ + x = 0, x(0) = 0, x′ (0) = 1.the problem is to solve for c1 and c2 for which the x(t) satisfies the initialconditions. The two degrees of freedom in the general solution matching thenumber of initial conditions in the IVP. Plugging t = 0 into x(t) and x′ (t),we obtain0 = x(0) = c1 cos(0) + c2 sin(0) = c1 , 1 = x′ (0) = −c1 sin(0) + c2 cos(0) = c2 .Therefore, c1 = 0, c2 = 1 and x(t) = sin(t) is the unique solution to the IVP. Figure 1.2: Solution to IVP x′′ + x = 0, x(0) = 0, x′ (0) = 1. Here you see the solution oscillates, as t gets larger.
  19. 19. Another example,Example 1.2.2. Consider the 2-nd order DE x′′ + 4x′ + 4x = 0.(We shall run across this DE many times later as well. As we will see, itrepresents the displacement of a critially damped spring with a unit massattached.) Suppose we know that the general solution to this DE is x(t) = c1 exp(−2t) + c2 texp(−2t) = c1 e−2t + c2 te−2t ,for any constants c1 , c2 . This means every solution to the DE must be ofthis form. (Again, you can at least check it is a solution by computing x′′ (t),4x′ (t), 4x(t), adding them up and verifying that the terms cancel, as in thefollowing SAGE example.) SAGEsage: t = var(’t’)sage: c1 = var(’c1’)sage: c2 = var(’c2’)sage: de = lambda x: diff(x,t,t) + 4*diff(x,t) + 4*xsage: de(c1*exp(-2*t) + c2*t*exp(-2*t))4*(c2*t*eˆ(-2*t) + c1*eˆ(-2*t)) + 4*(-2*c2*t*eˆ(-2*t)+ c2*eˆ(-2*t) - 2*c1*eˆ(-2*t)) + 4*c2*t*eˆ(-2*t)- 4*c2*eˆ(-2*t) + 4*c1*eˆ(-2*t)sage: de(c1*exp(-2*t) + c2*t*exp(-2*t)).expand()0sage: desolve_laplace(de(x(t)),["t","x"],[0,0,1])’t*%eˆ-(2*t)’sage: P = plot(t*exp(-2*t),0,pi)sage: show(P)The plot is displayed below. Now, to solve the IVP x′′ + 4x′ + 4x = 0, x(0) = 0, x′ (0) = 1.we solve for c1 and c2 using the initial conditions. Plugging t = 0 into x(t)and x′ (t), we obtain
  20. 20. 0 = x(0) = c1 exp(0) + c2 · 0 · exp(0) = c1 , 1 = x′ (0) = c1 exp(0) + c2 exp(0) − 2c2 · 0 · exp(0) = c1 + c2 .Therefore, c1 = 0, c1 + c2 = 1 and so x(t) = t exp(−2t) is the unique solutionto the IVP. Here you see the solution tends to 0, as t gets larger. Figure 1.3: Solution to IVP x′′ + 4x′ + 4x = 0, x(0) = 0, x′ (0) = 1. Suppose, for the sake of argument, that I lied to you and told you thegeneral solution to this DE is x(t) = c1 exp(−2t) + c2 exp(−2t) = c1 (e−2t + c2 e−2t ),for any constants c1 , c2 . (In other words, the “extra t factor” is missing.)Now, if you try to solve for the constant c1 and c2 using the initial conditionsx(0) = 0, x′ (0) = 1 you will get the equations c1 + c2 = 0 −2c1 − 2c2 = 1.These equations are impossible to solve! You see from this that you musthave a correct general solution to insure that you can solve your IVP. One more quick example.Example 1.2.3. Consider the 2-nd order DE
  21. 21. x′′ − x = 0.Suppose we know that the general solution to this DE is x(t) = c1 exp(t) + c2 exp(−t) = c1 e−t + c2 e−t ,for any constants c1 , c2 . (Again, you can check it is a solution.) The solution to the IVP x′′ − x = 0, x(0) = 0, x′ (0) = 1, tis x(t) = e +e . (You can solve for c1 and c2 yourself, as in the examples −t 2above.) This particular function is also called a hyperbolic cosine func-tion, denoted cosh(t). The hyperbolic trig functions have many properties analogous to the usualtrig functions and arise in many areas of applications [H-ivp]. For example,cosh(t) represents a catenary or hanging cable [C-ivp]. SAGEsage: t = var(’t’)sage: c1 = var(’c1’)sage: c2 = var(’c2’)sage: de = lambda x: diff(x,t,t) - xsage: de(c1*exp(-t) + c2*exp(-t))0sage: desolve_laplace(de(x(t)),["t","x"],[0,0,1])’%eˆt/2-%eˆ-t/2’sage: P = plot(eˆt/2-eˆ(-t)/2,0,3)sage: show(P) Here you see the solution tends to infinity, as t gets larger. Exercise: The general solution to the falling body problem mv ′ + kv = mg,is v(t) = mg + ce−kt/m . If v(0) = v0 , solve for c in terms of v0 . Take km = k = v0 = 1, g = 9.8 and use SAGE to plot v(t) for 0 < t < 1.
  22. 22. Figure 1.4: Solution to IVP x′′ − x = 0, x(0) = 0, x′ (0) = 1.1.3 First order ODEs - separable and linear casesSeparable DEs: We know how to solve any ODE of the form y ′ = f (t),at least in principle - just integrate both sides3 . For a moregeneral type of ODE, such as y ′ = f (t, y),this fails. For instance, if y ′ = t + y then integrating both sidesgives y(t) = dy dt = y ′ dt = t + y dt = t dt + y(t) dt = dt 3 Recall y ′ really denotes dy , so by the fundamental theorem of calculus, y = dy dt = dt dt ′ y dt = f (t) dt = F (t) + c, where F is the “anti-derivative” of f and c is a constant ofintegration.
  23. 23. t22+ y(t) dt. So, we have only succeeded in writing y(t) in termsof its integral. Not helpful. However, there is a class of ODEs where this idea works, withsome slight modification. If the ODE has the form g(t) y′ = , (1.1) h(y)then it is called separable4 . To solve a separable ODE: dy g(t)(1) write the ODE (1.1) as dt = h(y) ,(2) “separate” the t’s and the y’s: h(y) dy = g(t) dt,(3) integrate both sides: h(y) dy = g(t) dt + C I’ve added a “+C” to emphasize that a constant of inte- gration must be included in your anwser (but only on one side of the equation). The answer obtained in this manner is called an “implicit so-lution” of (1.1) since it expresses y implicitly as a function oft.Example 1.3.1. Are the following ODEs separable? If so, solvethem. 4 It particular, any separable DE must be first order.
  24. 24. (a) (t2 + y 2 )y ′ = −2ty,(b) y ′ = −x/y, y(0) = −1,(c) T ′ = k · (T − Troom ), where k < 0 and Troom are constants,(d) ax′ + bx = c, where a = 0, b = 0, and c are constants(e) ax′ + bx = c, where a = 0, b, are constants and c = c(t) is not a constant.(f ) y ′ = (y − 1)(y + 1), y(0) = 2.(g) y ′ = y 2 + 1, y(0) = 1.Solutions:(a) not separable,(b) y dy = −x dx, so y 2 /2 = −x2 /2 + c, so x2 + y 2 = 2c. This is the general solution (note it does not give y explicitly as a function of x, you will have to solve for y algebraically to get that). The initial conditions say when x = 0, y = 1, so 2c = 02 + 12 = 1, which gives c = 1/2. Therefore, x2 + y 2 = 1, which is a circle. That is not a function so cannot be the solution √ want. The solution is either √ we y = 1−x 2 or y = − 1 − x2 , but which one? Since √ y(0) = −1 (note the minus sign) it must be y = − 1 − x2 . dT(c) T −Troom= kdt, so ln |T − Troom | = kt + c (some constant c), so T − Troom = Cekt (some constant C), so T = T (t) = Troom + Cekt .
  25. 25. dx(d) dt = (c−bx)/a = − a (x− c ), so b b dx x− c b = − a dt, so ln |x− c | = b b b − a t + C, where C is a constant of integration. This is the implicit general solution of the DE. The explicit general b solution is x = c + Be− a t , where B is a constant. b The explicit solution is easy find using SAGE : SAGE sage: a = var(’a’) sage: b = var(’b’) sage: c = var(’c’) sage: t = var(’t’) sage: x = function(’x’, t) sage: de = lambda y: a*diff(y,t) + b*y - c sage: desolve_laplace(de(x(t)),["t","x"]) ’c/b-(a*c-x(0)*a*b)*%eˆ-(b*t/a)/(a*b)’(e) If c = c(t) is not constant then ax′ +bx = c is not separable. dy 1(f ) (y−1)(y+1)= dt so 2 (ln(y − 1) − ln(y + 1)) = t + C, where C is a constant of integration. This is the “general (implicit) solution” of the DE. Note: the constant functions y(t) = 1 and y(t) = −1 are also solutions to this DE. These solutions cannot be ob- tained (in an obvious way) from the general solution. The integral is easy to do using SAGE : SAGE sage: y = var(’y’) sage: integral(1/((y-1)*(y+1)),y) log(y - 1)/2 - (log(y + 1)/2)
  26. 26. Now, let’s try to get SAGE to solve for y in terms of t in12 (ln(y − 1) − ln(y + 1)) = t + C: SAGEsage: C = var(’C’)sage: solve([log(y - 1)/2 - (log(y + 1)/2) == t+C],y)[log(y + 1) == -2*C + log(y - 1) - 2*t]This is not working. Let’s try inputting the problem in adifferent form: SAGEsage: C = var(’C’)sage: solve([log((y - 1)/(y + 1)) == 2*t+2*C],y)[y == (-eˆ(2*C + 2*t) - 1)/(eˆ(2*C + 2*t) - 1)]This is what we want. Now let’s assume the initial condi-tion y(0) = 2 and solve for C and plot the function. SAGEsage: solny=lambda t:(-eˆ(2*C+2*t)-1)/(eˆ(2*C+2*t)-1)sage: solve([solny(0) == 2],C)[C == log(-1/sqrt(3)), C == -log(3)/2]sage: C = -log(3)/2sage: solny(t)(-eˆ(2*t)/3 - 1)/(eˆ(2*t)/3 - 1)sage: P = plot(solny(t), 0, 1/2)sage: show(P)
  27. 27. This plot is shown below. The solution has a singularity at t = ln(3)/2 = 0.5493.... Figure 1.5: Plot of y ′ = (y − 1)(y + 1), y(0) = 2, for 0 < t < 1/2.. dy(g) = dt so arctan(y) = t + C, where C is a constant of y 2 +1 integration. The initial condition y(0) = 1 says arctan(1) = C, so C = π . Therefore y = tan(t + π ) is the solution. 4 4 A special subclass of separable ODEs is the class of automo-mous ODEs, which have the form y ′ = f (y),where f is a given function (i.e., the slope y only depends onthe value of the dependent variable y). The cases (c), (d), (f),and (g) above are examples. Linear 1st order DEs: The bottom line is that we want to solve any problem of theform
  28. 28. x′ + p(t)x = q(t), (1.2)where p(t) and q(t) are given functions (which, let’s assume,aren’t too horrible). Every first order linear ODE can be writ-ten in this form. Examples of DEs which have this form: FallingBody problems, Newton’s Law of Cooling problems, Mixingproblems, certain simple Circuit problems, and so on. There are two approaches • “the formula”, • the method of integrating factors.Both lead to the exact same solution.“The Formula”: The general solution to (1.2) is p(t) dt e q(t) dt + C x= , (1.3) e p(t) dtwhere C is a constant. The factor e p(t) dt is called the inte-grating factor and is often denoted by µ. This formula wasapparently first discovered by Johann Bernoulli [F-1st].Example 1.3.2. Solve xy ′ + y = ex . x 1 1We rewrite this as y ′ + x y = ex . Now compute µ = e x dx =eln(x) = x, so the formula gives x x ex dx + C ex dx + C ex + C y= = = . x x x Here is one way to do this using SAGE :
  29. 29. SAGEsage: t = var(’t’)sage: x = function(’x’, t)sage: de = lambda y: diff(y,t) + (1/t)*y - exp(t)/tsage: desolve(de(x(t)),[x,t])’(%eˆt+%c)/t’ p(t) dt“Integrating factor method”: Let µ = e . Multiply bothsides of (1.2) by µ: µx′ + p(t)µx = µq(t).The product rule implies that (µx)′ = µx′ + p(t)µx = µq(t).(In response to a question you are probably thinking now: No,this is not obvious. This is Bernoulli’s very clever idea.) Nowjust integrate both sides. By the fundamental theorem of calcu-lus, µx = (µx)′ dt = µq(t) dt.Dividing both side by µ gives (1.3).
  30. 30. Exercise: (a) Use SAGE ’s desolve command to solve tx′ + 2x = et /t.(b) Use SAGE to plot the solution to y ′ = y 2 − 1, y(0) = −2.
  31. 31. 1.4 Isoclines and direction fieldsRecall from vector calculus the notion of a two-dimensional vec-tor field: F (x, y) = (g(x, y), h(x, y)). To plot F , you simplydraw the vector F (x, y) at each point (x, y). The idea of the direction field (or slope field) associated tothe first order ODE y ′ = f (x, y), y(a) = c, (1.4)is similar. At each point (x, y) you plot a vector having slopef (x, y). For example, the vector field plot of F (x, y) = (1, f (x, y))or F (x, y) = (1, f (x, y))/ 1 + f (x, y)2 (which is a unit vector). A related notion are the isoclines of the ODE. An isocline of(1.4) is a level curve of the function z = f (x, y): {(x, y) | f (x, y) = m},where the given constant m is called the slope of the isocline. Interms of the ODE, this curve represents the collection of pointsat which the solution has slope m. In terms of the directionfield of the ODE, it represents the collection of points where thevectors have slope m. How to draw the direction field of (1.4) by hand: • Draw several isoclines, making sure to include one which contains the point (a, c). (You may want to draw these in pencil.) • On each isocline, draw “hatch marks” or “arrows” along the line each having slope m.
  32. 32. This is a crude direction field plot. The plot of arrows formyour direction field. The isoclines, having served their useful-ness, can safely be ignored or erased.Example 1.4.1. The direction field, with three isoclines, for y ′ = 5x + y − 5, y(0) = 1,is given by the following graph: Figure 1.6: Plot of y ′ = 5x + y − 5, y(0) = 1, for −1 < x < 1.The isoclines are the curves (coincidentally, lines) of the form5x + y − 5 = m. (They are green bands in the above plot.) Theseare lines of slope −5, not to be confused with the fact that itrepresents an isocline of slope m. The above example can be solved explicitly. (Indeed, y =−5x + ex solves y ′ = 5x + y − 5, y(0) = 1.) In the next example,such an explicit solution is (as far as I know), not possible.Therefore, a numerical approximation plays a more importantrole.
  33. 33. Example 1.4.2. The direction field, with three isoclines, for y ′ = x2 + y 2 , y(0) = 3/2,is given by the following graph:Figure 1.7: Direction field and solution plot of y ′ = x2 + y 2 , y(0) = 3/2, for−3 < x < 3.The isoclines are the concentric circles x2 + y 2 = m. (They aregreen in the above plot.) The plot above was obtained using SAGE ’s interface with Max-ima, and the plotting package Openmath (SAGE includes bothMaxima and Openmath). : SAGEsage: maxima.eval(’load("plotdf")’)sage: maxima.eval(’plotdf(xˆ2+yˆ2,[trajectory_at,0,0], [x,-3,3],[y,-3,3])’)This gave the above plot. (Note: the plotdf command goes onone line; for typographical reasons, it was split in two.)
  34. 34. There is also a way to draw these direction fields using SAGE . SAGEsage: pts = [(-2+i/5,-2+j/5) for i in range(20) for j in range(20)] # square [-2,2]x[-2,2]sage: f = lambda p:p[0]ˆ2+p[1]ˆ2sage: arrows = [arrow(p, (p[0]+0.02,p[1]+(0.02)*f(p)), width=1/100, rgbcolor=(0,0,1)) for p in pts]sage: show(sum(arrows))This gives the plot below. Figure 1.8: Direction field for y ′ = x2 + y 2 , y(0) = 3/2, for −2 < x < 2.Exercise: Using SAGE , plot the direction field for y ′ = x2 − y 2 .
  35. 35. 1.5 Numerical solutions - Euler’s method and improved Euler’s method Read Euler: he is our master in everything. - Pierre Simon de Laplace Leonhard Euler was a Swiss mathematician who made signifi-cant contributions to a wide range of mathematics and physicsincluding calculus and celestial mechanics (see [Eu1-num] and[Eu2-num] for further details). The goal is to find an approximate solution to the problem y ′ = f (x, y), y(a) = c, (1.5)where f (x, y) is some given function. We shall try to approxi-mate the value of the solution at x = b, where b > a is given.Sometimes such a method is called “numerically integrating(1.5)”. Note: the first order DE must be in the form (1.5) or themethod described below does not work. A version of Euler’smethod for systems of 1-st order DEs and higher order DEs willalso be described below. Euler’s method Geometric idea: The basic idea can be easily expressed ingeometric terms. We know the solution, whatever it is, must gothrough the point (a, c) and we know, at that point, its slope is
  36. 36. m = f (a, c). Using the point-slope form of a line, we concludethat the tangent line to the solution curve at (a, c) is (in (x, y)-coordinates, not to be confused with the dependent variable yand independent variable x of the DE) y = c + (x − a)f (a, c).In particular, if h > 0 is a given small number (called the in-crement) then taking x = a+h the tangent-line approximationfrom calculus I gives us: y(a + h) ∼ c + h · f (a, c). =Now we know the solution passes through a point which is“nearly” equal to (a + h, c + h · f (a, c). We now repeat thistangent-line approximation with (a, c) replaced by (a + h, c +h · f (a, c). Keep repeating this number-crunching at x = a,x = a + h, x = a + 2h, ..., until you get to x = b. Algebraic idea: The basic idea can also be explained “alge-braically”. Recall from the definition of the derivative in calculus1 that y(x + h) − y(x) y ′ (x) ∼ = , hh > 0 is a given and small. This an the DE together givef (x, y(x)) ∼ y(x+h)−y(x) . Now solve for y(x + h): = h y(x + h) ∼ y(x) + h · f (x, y(x)). =If we call h·f (x, y(x)) the “correction term” (for lack of anythingbetter), call y(x) the “old value of y”, and call y(x+h) the “newvalue of y”, then this approximation can be re-expressed
  37. 37. ynew = yold + h · f (x, yold ). Tabular idea: Let n > 0 be an integer, which we call thestep size. This is related to the increment by b−a h= . nThis can be expressed simplest using a table. x y hf (x, y) a c hf (a, c) . . a + h c + hf (a, c) . . . a + 2h . . . . b ??? xxx The goal is to fill out all the blanks of the table but the xxxentry and find the ??? entry, which is the Euler’s methodapproximation for y(b).Example 1.5.1. Use Euler’s method with h = 1/2 to approxi-mate y(1), where y ′ − y = 5x − 5, y(0) = 1. Putting the DE into the form (1.5), we see that here f (x, y) =5x + y − 5, a = 0, c = 1. x y hf (x, y) = 5x+y−5 2 0 1 −2 1/2 1 + (−2) = −1 −7/4 1 −1 + (−7/4) = −11/4
  38. 38. so y(1) ∼ − 11 = −2.75. This is the final answer. = 4 Aside: For your information, y = ex − 5x solves the DE andy(1) = e − 5 = −2.28.... Here is one way to do this using SAGE : SAGEsage: x,y=PolynomialRing(QQ,2,"xy").gens()sage: eulers_method(5*x+y-5,1,1,1/3,2) x y h*f(x,y) 1 1 1/3 4/3 4/3 1 5/3 7/3 17/9 2 38/9 83/27sage: eulers_method(5*x+y-5,0,1,1/2,1,method="none")[[0, 1], [1/2, -1], [1, -11/4], [3/2, -33/8]]sage: pts = eulers_method(5*x+y-5,0,1,1/2,1,method="none")sage: P = list_plot(pts)sage: show(P)sage: P = line(pts)sage: show(P)sage: P1 = list_plot(pts)sage: P2 = line(pts)sage: show(P1+P2)
  39. 39. The plot is given below. Figure 1.9: Euler’s method with h = 1/2 for x′ + x = 1, x(0) = 2. Improved Euler’s method Geometric idea: The basic idea can be easily expressed ingeometric terms. As in Euler’s method, we know the solutionmust go through the point (a, c) and we know its slope thereis m = f (a, c). If we went out one step using the tangent lineapproximation to the solution curve, the approximate slope tothe tangent line at x = a + h, y = c + h · f (a, c) would bem′ = f (a+h, c+h·f (a, c)). The idea is that instead of using m =f (a, c) as the slope of the line to get our first approximation, usem+m′ 2 . The “improved” tangent-line approximation at (a, c) is: m + m′ f (a, c) + f (a + h, c + h · f (a, c))y(a+h) ∼ c+h· = = c+h· . 2 2(This turns out to be a better apprpximation than the tangent-line approximation y(a + h) ∼ c + h · f (a, c) used in Euler’s =
  40. 40. method.) Now we know the solution passes through a point ′which is “nearly” equal to (a + h, c + h · m+m ). We now repeat 2this tangent-line approximation with (a, c) replaced by (a+h, c+h · f (a, c). Keep repeating this number-crunching at x = a,x = a + h, x = a + 2h, ..., until you get to x = b. Tabular idea: The integer step size n > 0 is related to theincrement by b−a h= , nas before. The improved Euler method can be expressed simplest using atable. h m+m = h f (x,y)+f (x+h,y+h·f (x,y)) ′ x y 2 2 f (a,c)+f (a+h,c+h·f (a,c)) a c h 2 f (a,c)+f (a+h,c+h·f (a,c)) . .a+h c+h 2 . . .a + 2h . . . . b ??? xxx The goal is to fill out all the blanks of the table but the xxxentry and find the ??? entry, which is the improved Euler’smethod approximation for y(b).Example 1.5.2. Use the improved Euler’s method with h = 1/2to approximate y(1), where y ′ − y = 5x − 5, y(0) = 1.
  41. 41. Putting the DE into the form (1.5), we see that here f (x, y) =5x + y − 5, a = 0, c = 1. We first compute the “correctionterm”: h f (x,y)+f (x+h,y+h·f (x,y)) = 5x+y−5+5(x+h)+(y+h·f (x,y))−5 2 4 5x+y−5+5(x+h)+(y+h·(5x+y−5)−5 = 4 = (1 + h )5x + (1 + h )y − 5 2 2 2 = 25x/4 + 5y/4 − 5. ′ x y h m+m = 25x+5y−10 2 4 0 1 −15/8 1/2 1 + (−15/8) = −7/8 −95/64 1 −7/8 + (−95/64) = −151/64so y(1) ∼ − 151 = −2.35... This is the final answer. = 64 Aside: For your information, this is closer to the exact valuey(1) = e − 5 = −2.28... than the “usual” Euler’s method approx-imation of −2.75 we obtained above. Euler’s method for systems and higher order DEs We only sketch the idea in some simple cases. Consider theDE y ′′ + p(x)y ′ + q(x)y = f (x), y(a) = e1 , y ′ (a) = e2 , and the system ′ y1 = f1 (x, y1 , y2 ), y1 (a) = c1 , ′ y2 = f2 (x, y1 , y2 ), y2 (a) = c2 .
  42. 42. We can treat both cases after first rewriting the DE as a system:create new variables y1 = y and let y2 = y ′ . It is easy to see that ′ y1 = y2 , y1 (a) = e1 , ′ y2 = f (x) − q(x)y1 − p(x)y2 , y2 (a) = e2 . Tabular idea: Let n > 0 be an integer, which we call thestep size. This is related to the increment by b−a h= . nThis can be expressed simplest using a table. x y1 hf1 (x, y1 , y2 ) y2 hf2 (x, y1 , y2 ) a e1 hf1 (a, e1 , e2 ) e2 hf2 (a, e1 , e2 ) . . . . a + h e1 + hf1 (a, e1 , e2 ) . e1 + hf1 (a, e1 , e2 ) . . . a + 2h . . . . b ??? xxx xxx xxx The goal is to fill out all the blanks of the table but the xxxentry and find the ??? entries, which is the Euler’s methodapproximation for y(b).Example 1.5.3. Using 3 steps of Euler’s method, estimate x(1),where x′′ − 3x′ + 2x = 1, x(0) = 0, x′ (0) = 1 First, we rewrite x′′ − 3x′ + 2x = 1, x(0) = 0, x′ (0) = 1, as asystem of 1st order DEs with ICs. Let x1 = x, x2 = x′ , so ′ x1 = x2 , x1 (0) = 0, ′ x2 = 1 − 2x1 + 3x2 , x2 (0) = 1.
  43. 43. This is the DE rewritten as a system in standard form. (Ingeneral, the tabular method applies to any system but it must bein standard form.) Taking h = (1 − 0)/3 = 1/3, we have t x1 x2 /3 x2 (1 − 2x1 + 3x2 )/3 0 0 1/3 1 4/3 1/3 1/3 7/9 7/3 22/9 2/3 10/9 43/27 43/9 xxx 1 73/27 xxx xxx xxxSo x(1) = x1 (1) ∼ 73/27 = 2.7.... Here is one way to do this using SAGE : SAGEsage: RR = RealField(sci_not=0, prec=4, rnd=’RNDU’)sage: t, x, y = PolynomialRing(RR,3,"txy").gens()sage: f = y; g = 1-2*x+3*ysage: L = eulers_method_2x2(f,g,0,0,1,1/3,1,method="none")sage: L[[0, 0, 1], [1/3, 0.35, 2.5], [2/3, 1.3, 5.5], [1, 3.3, 12], [4/3, 8.0, 24]]sage: eulers_method_2x2(f,g, 0, 0, 1, 1/3, 1) t x h*f(t,x,y) y h*g(t,x,y) 0 0 0.35 1 1.4 1/3 0.35 0.88 2.5 2.8 2/3 1.3 2.0 5.5 6.5 1 3.3 4.5 12 11sage: P1 = list_plot([[p[0],p[1]] for p in L])sage: P2 = line([[p[0],p[1]] for p in L])sage: show(P1+P2)
  44. 44. The plot of the approximation to x(t) is given below.Figure 1.10: Euler’s method with h = 1/3 for x′′ − 3x′ + 2x = 1, x(0) = 0,x′ (0) = 1.Exercise: Use SAGE and Euler’s method with h = 1/3 for thefollowing problems: (a) Find the approximate values of x(1) and y(1) where x′ = x + y + t, x(0) = 0, y ′ = x − y, y(0) = 0, (b) Find the approximate value of x(1) where x′ = x2 + t2 ,x(0) = 1.
  45. 45. 1.6 Newtonian mechanicsWe briefly recall how the physics of the falling body problemleads naturally to a differential equation (this was already men-tioned in the introduction and forms a part of Newtonian me-chanics [M-mech]). Consider a mass m falling due to gravity.We orient coordinates to that downward is positive. Let x(t)denote the distance the mass has fallen at time t and v(t) itsvelocity at time t. We assume only two forces act: the force dueto gravity, Fgrav , and the force due to air resistence, Fres . Inother words, we assume that the total force is given by Ftotal = Fgrav + Fres .We know that Fgrav = mg, where g > 0 is the gravitationalconstant, from high school physics. We assume, as is commonin physics, that air resistance is proportional to velocity: Fres =−kv = −kx′ (t), where k ≥ 0 is a constant. Newton’s secondlaw [N-mech] tells us that Ftotal = ma = mx′′ (t). Putting theseall together gives mx′′ (t) = mg − kx′ (t), or k v ′ (t) + v(t) = g. (1.6) mThis is the differential equation governing the motion of a fallingbody. Equation (1.6) can be solved by various methods: separa-tion of variables or by integrating factors. If we assume v(0) = v0is given and if we assume k > 0 then the solution is mg mg −kt/m v(t) = + (v0 − )e . (1.7) k kIn particular, we see that the limiting velocity is vlimit = mg . k
  46. 46. Example 1.6.1. Wile E. Coyote (see [W-mech] if you haven’tseen him before) has mass 100 kgs (with chute). The chute isreleased 30 seconds after the jump from a height of 2000 m. Theforce due to air resistence is given by Fres = −kv, where 15, chute closed, k= 100, chute open. Find(a) the distance and velocity functions during the time when the chute is closed (i.e., 0 ≤ t ≤ 30 seconds),(b) the distance and velocity functions during the time when the chute is open (i.e., 30 ≤ t seconds),(c) the time of landing,(d) the velocity of landing. (Does Wile E. Coyote survive the impact?)soln: Taking m = 100, g = 9.8, k = 15 and v(0) = 0 in (1.7),we find 196 196 − 3 t v1 (t) = − e 20 . 3 3This is the velocity with the time t starting the moment theparachutist jumps. After t = 30 seconds, this reaches the ve-locity v0 = 196 − 196 e−9/2 = 64.607.... The distance fallen is 3 3 t x1 (t) = 0 v1 (u) du 196 3 = 3 t + 3920 e− 20 t 9 − 3920 9 . 13720 3920 −9/2After 30 seconds, it has fallen x1 (30) = 9 + 9 e =1529.283... meters.
  47. 47. Taking m = 100, g = 9.8, k = 100 and v(0) = v0 , we find 49 833 196 −9/2 v2 (t) = + e−t − e . 5 15 3This is the velocity with the time t starting the moment WileE. Coyote opens his chute (i.e., 30 seconds after jumping). Thedistance fallen is t x2 (t) = 0 v2 (u) du + x1 (30) 49 833 −t = 5 t − 15 e + 196 e−t e−9/2 3 + 71099 45 + 3332 9 e−9/2 .
  48. 48. Now let us solve this using SAGE . SAGEsage: RR = RealField(sci_not=0, prec=50, rnd=’RNDU’)sage: t = var(’t’)sage: v = function(’v’, t)sage: m = 100; g = 98/10; k = 15sage: de = lambda v: m*diff(v,t) + k*v - m*gsage: desolve_laplace(de(v(t)),["t","v"],[0,0])’196/3-196*%eˆ-(3*t/20)/3’sage: soln1 = lambda t: 196/3-196*exp(-3*t/20)/3sage: P1 = plot(soln1(t),0,30,plot_points=1000)sage: RR(soln1(30))64.607545559502This solves for the velocity before the coyote’s chute is opened,0 < t < 30. The last number is the velocity Wile E. Coyote istraveling at the moment he opens his chute. SAGEsage: t = var(’t’)sage: v = function(’v’, t)sage: m = 100; g = 98/10; k = 100sage: de = lambda v: m*diff(v,t) + k*v - m*gsage: desolve_laplace(de(v(t)),["t","v"],[0,RR(soln1(30))])’631931*%eˆ-t/11530+49/5’sage: soln2 = lambda t: 49/5+(631931/11530)*exp(-(t-30)) + soln1(30) - (631931/11530) - 49/5sage: RR(soln2(30))64.607545559502sage: RR(soln1(30))64.607545559502sage: P2 = plot(soln2(t),30,50,plot_points=1000)sage: show(P1+P2)This solves for the velocity after the coyote’s chute is opened, t >
  49. 49. 30. The last command plots the velocity functions together as asingle plot. (You would see a break in the graph if you omittedthe SAGE ’s plot option ,plot_points=1000. That is becausethe number of samples taken of the function by default is notsufficient to capture the jump the function takes at t = 30.) Theterms at the end of soln2 were added to insure x2 (30) = x1 (30). Next, we find the distance traveled at time t: SAGEage: integral(soln1(t),t)3920*eˆ(-(3*t/20))/9 + 196*t/3sage: x1 = lambda t: 3920*eˆ(-(3*t/20))/9 + 196*t/3sage: RR(x1(30))1964.8385851589This solves for the distance the coyote traveled before the chutewas open, 0 < t < 30. The last number says that he has goneabout 1965 meters when he opens his chute. SAGEsage: integral(soln2(t),t)49*t/5 - (631931*eˆ(30 - t)/11530)sage: x2 = lambda t: 49*t/5 - (631931*eˆ(30 - t)/11530) + x1(30) + (631931/11530) - 49*30/5sage: RR(x2(30.7))1999.2895090436sage: P4 = plot(x2(t),30,50)sage: show(P3+P4)(Again, you see a break in the graph because of the round-offerror.) The terms at the end of x2 were added to insure x2 (30) =x1 (30). You know he is close to the ground at t = 30, and going
  50. 50. quite fast (about 65 m/s!). It makes sense that he will hit theground soon afterwards (with a large puff of smoke, if you’veseen the cartoons), even though his chute will have slowed himdown somewhat. The graph of the velocity 0 < t < 50 is in Figure 1.11. Noticehow it drops at t = 30 when the chute is opened. The graph ofthe distance fallen 0 < t < 50 is in Figure 1.12. Notice how itslows down at t = 30 when the chute is opened. Figure 1.11: Velocity of falling parachutist. The time of impact is timpact = 30.7.... This was found numer-ically by a “trial-and-error” method of solving x2 (t) = 2000. The velocity of impact is v2 (timpact ) ≈ 37 m/s.Exercise: Drop an object with mass 10 kgs from a height of2000 m. Suppose the force due to air resistence is given byFres = −10v. Find the velocity after 10 seconds using SAGE .Plot this velocity function for 0 < t < 10.
  51. 51. Figure 1.12: Distance fallen by a parachutist.1.7 Application to mixing problemsSuppose that we have two chemical substances where one issoluable in the other, such as salt and water. Suppose that wehave a tank containing a mixture of these substances, and themixture of them is poured in and the resulting “well-mixed”solution pours out through a value at the bottom. (The term“well-mixed” is used to indicate that the fluid being poured inis assumed to instantly dissolve into a homogeneous mixture themoment it goes into the tank.) The crude picture looks like this: Assume for concreteness that the chemical substances are saltand water. Let • A(t) denote the amount of salt at time t, • FlowRateIn = the rate at which the solution pours into the tank,
  52. 52. Figure 1.13: Solution pours into a tank, mixes with another type of solution.and then pours out. • FlowRateOut = the rate at which the mixture pours out of the tank, • Cin = “concentration in” = the concentration of salt in the solution being poured into the tank, • Cout = “concentration out” = the concentration of salt in the solution being poured out of the tank, • Rin = rate at which the salt is being poured into the tank = (FlowRateIn)(Cin ), • Rout = rate at which the salt is being poured out of the tank = (FlowRateOut)(Cout ).Remark 1.7.1. Some things to make note of:
  53. 53. • If FlowRateIn = FlowRateOut then the “water level” of the tank stays the same. • We can determine Cout as a function of other quantities: A(t) Cout = , T (t) where T (t) denotes the volume of solution in the tank at time t. • The rate of change of the amount of salt in the tank, A′ (t), more properly could be called the “net rate of change”. If you think if it this way then you see A′ (t) = Rin − Rout . Now the differential equation for the amount of salt arises fromthe above equations: A(t) A′ (t) = (FlowRateIn)Cin − (FlowRateOut) . T (t)Example 1.7.1. Consider a tank with 200 liters of salt-watersolution, 30 grams of which is salt. Pouring into the tank is abrine solution at a rate of 4 liters/minute and with a concentra-tion of 1 grams per liter. The “well-mixed” solution pours outat a rate of 5 liters/minute. Find the amount at time t. We know A(t) A(t)A′ (t) = (FlowRateIn)Cin −(FlowRateOut) = 4−5 , A(0) = 30. T (t) 200 − tWriting this in the standard form A′ + pA = q, we have µ(t)q(t) dt + C A(t) = , µ(t)
  54. 54. 1where µ = e p(t) dt = e−5 200−t dt = (200 − t)−5 is the “integratingfactor”. This gives A(t) = 200 − t + C · (200 − t)5 , where theinitial condition implies C = −170 · 200−5 . Here is one way to do this using SAGE : SAGEsage: t = var(’t’)sage: A = function(’A’, t)sage: de = lambda A: diff(A,t) + (5/(200-t))*A - 4sage: desolve(de(A(t)),[A,t])’(%c-1/(t-200)ˆ4)*(t-200)ˆ5’This is the form of the general solution. (SAGE uses Maximaand %c is Maxima’s notation for an arbitrary constant.) Let usnow solve this general solution for c, using the initial conditions. SAGEsage: c = var(’c’)sage: solnA = lambda t: (c - 1/(t-200)ˆ4)*(t-200)ˆ5sage: solnA(t)(c - (1/(t - 200)ˆ4))*(t - 200)ˆ5sage: solnA(0)-320000000000*(c - 1/1600000000)sage: solve([solnA(0) == 30],c)[c == 17/32000000000]sage: c = 17/32000000000sage: solnA(t)(17/32000000000 - (1/(t - 200)ˆ4))*(t - 200)ˆ5sage: P = plot(solnA(t),0,200)sage: show(P)
  55. 55. Figure 1.14: A(t), 0 < t < 200, A′ = 4 − 5A(t)/(200 − t), A(0) = 30.Exercise: Now use SAGE to solve the same problem but withthe same flow rate out as 4 liters/min (so the “water level” in thetank is constant). Find and plot the solution A(t), 0 < t < 200.
  56. 56. Chapter 2Second order differentialequations 49
  57. 57. 2.1 Linear differential equationsWe want to describe the form a solution to a linear ODE cantake. Before doing this, we introduce two pieces of terminology. • Suppose f1 (t), f2 (t), . . . , fn (t) are given functions. A lin- ear combination of these functions is another fucntion of the form c1 f1 (t) + c2 f2 (t) + . . . , +cn fn (t), for some constants c1 , ..., cn . For example, 3 cos(t)−2 sin(t) is a linear combination of cos(t), sin(t). • A linear ODE of the form y (n) + b1 (t)y (n−1) + ... + bn−1 (t)y ′ + bn (t)y = f (t), (2.1) is called homogeneous if f (t) = 0 (i.e., f is the 0 function) and otherwise it is called non-homogeneous. The following result describes the general solution to a linearODE.Theorem 2.1.1. Consider a linear ODE having of the form(2.1), for some given continuous functions b1 (t), . . . , bn (t), andf (t). Then the following hold. • There are n functions y1 (t), . . . , yn (t) (called fundamen- tal solutions), each satisfying the homogeneous ODE y (n) + b1 (t)y (n−1) + ... + bn−1 (t)y ′ + bn (t)y = 0, 1 ≤ i ≤ n, (2.2)
  58. 58. such that every solution to (2.2) is a linear combination of these functions y1 , . . . , yn . • Suppose you know a solution yp (t) (a particular solution) to (2.1). Then every solution y = y(t) (the general solu- tion) to the DE (2.1) has the form y(t) = yh (t) + yp (t), (2.3) where yh (the “homogeneous part” of the general solution) is a linear combination yh (t) = c1 y1 (t) + y2 (t) + ... + cn yn (t), for some constants ci , 1 ≤ i ≤ n. • Conversely, every function of the form (2.3), for any con- stants ci for 1 ≤ i ≤ n, is a solution to (2.1).Example 2.1.1. Recall the example in the introduction wherewe looked for functions solving x′ + x = 1 by “guessing”. Thefunction xp (t) = 1 is a particular solution to x′ + x = 1. Thefunction x1 (t) = e−t is a fundamental solution to x′ + x = 0.The general solution is therefore x(t) = 1 + c1 e−t , for a constantc1 .Example 2.1.2. The charge on the capacitor of an RLC elec-trical circuit is modeled by a 2-nd order linear DE [C-linear]. Series RLC Circuit notations: • E = E(t) - the voltage of the power source (a battery or other “electromotive force”, measured in volts, V)
  59. 59. • q = q(t) - the current in the circuit (measured in coulombs, C) • i = i(t) - the current in the circuit (measured in amperes, A) • L - the inductance of the inductor (measured in henrys, H) • R - the resistance of the resistor (measured in ohms, Ω); • C - the capacitance of the capacitor (measured in farads, F) The charge q on the capacitor satisfies the linear IPV: 1 Lq ′′ + Rq ′ + q = E(t), q(0) = q0 , q ′ (0) = i0 . C Figure 2.1: RLC circuit.Example 2.1.3. Recall the example in the introduction wherewe looked for functions solving x′ + x = 1 by “guessing”. Thefunction xp (t) = 1 is a particular solution to x′ + x = 1. Thefunction x1 (t) = e−t is a fundamental solution to x′ + x = 0.The general solution is therefore x(t) = 1 + c1 e−t , for a constantc1 .
  60. 60. Example 2.1.4. The displacement from equilibrium of a massattached to a spring is modeled by a 2-nd order linear DE [O-ivp]. SSpring-mass notations: • f (t) - the external force acting on the spring (if any) • x = x(t) - the displacement from equilibrium of a mass attached to a spring • m - the mass • b - the damping constant (if, say, the spring is immersed in a fluid) • k - the spring constant. The displacement x satisfies the linear IPV: mx′′ + bx′ + kx = f (t), x(0) = x0 , x′ (0) = v0 . Figure 2.2: spring-mass model.
  61. 61. Notice that each general solution to an n-th order ODE hasn “degrees of freedom” (the arbitrary constants ci ). Accordingto this theorem, to find the general solution of a linear ODE,we need only find a particular solution yp and n fundamentalsolutions y1 (t), . . . , yn (t).Example 2.1.5. Let us try to solve x′ + x = 1, x(0) = c,where c = 1, c = 2, and c = 3. (Three different IVP’s, threedifferent solutions, find each one.) The first problem, x′ + x = 1 and x(0) = 1, is easy. Thesolutions to the DE x′ + x = 1 which we “guessed at” in theprevious example, x(t) = 1, satisfies this. The second problem, x′ + x = 1 and x(0) = 2, is not so simple.To solve this (and the third problem), we really need to knowwhat the form is of the “general solution”. According to the theorem above, the general solution x has theform x = xp + xh . In this case, xp (t) = 1 and xh (t) = c1 x1 (t) =c1 e−t , by an earlier example. Therefore, every solution to theDE above is of the form x(t) = 1 + c1 e−t , for some constant c1 .We use the initial condition to solve for c1 : • x(0) = 1: 1 = x(0) = 1 + c1 e0 = 1 + c1 so c1 = 0 and x(t) = 1. • x(0) = 2: 2 = x(0) = 1 + c1 e0 = 1 + c1 so c1 = 1 and x(t) = 1 + e−t . • x(0) = 3: 3 = x(0) = 1 + c1 e0 = 1 + c1 so c1 = 2 and x(t) = 1 + 2e−t .
  62. 62. Here is one way to use SAGE to solve for c1 . (Of course, youcan do this yourself, but this shows you the SAGE syntax forsolving equations. Type solve? in SAGE to get more details.)We use SAGE to solve the last IVP discussed above and then toplot the solution. SAGEsage: t = var(’t’)sage: c1 = var(’c1’)sage: solnx = lambda t: 1+c1*exp(-t)sage: solnx(0)c1 + 1sage: solve([solnx(0) == 3],c1)[c1 == 2]sage: c_1 = solve([solnx(0) == 3],c1)[0].rhs()sage: c_12sage: solnx1 = lambda t: 1+c*exp(-t)sage: plot(solnx1(t),0,2)Graphics object consisting of 1 graphics primitivesage: P = plot(solnx1(t),0,2)sage: show(P)sage: P = plot(solnx1(t),0,5)sage: show(P)This plot is shown below.
  63. 63. Figure 2.3: Solution to IVP x′ + x = 1, x(0) = 3.Exercise: Use SAGE to solve and plot the solution to x′ + x = 1and x(0) = 2.
  64. 64. 2.2 Linear differential equations, continuedTo better describe the form a solution to a linear ODE cantake, we need to better understand the nature of fundamentalsolutions and particular solutions. Recall that the general solution to y (n) + b1 (t)y (n−1) + ... + bn−1 (t)y ′ + bn (t)y = f (t),has the form y = yp + yh , where yh is a linear combination offundamental solutions. For example, the general solution to thespring-mass equation x′′ + x = 1has the form x = x(t) = 1 + c1 cos(t) + c2 sin(t) for the displace-ment from the equilibrium position. Suppose we are also given ninitial conditions y(x0 ) = a0 , y ′ (x0 ) = a1 , . . . , y (n−1) (x0 ) = an−1 .For example, we could impose the initial position and initialvelocity on the mass: x(0) = x0 and x′ (0) = v0 . Of course,no matter what x0 and v0 are are given, we want to be able tosolve for the coefficients c1 , c2 in x(t) = 1 + c1 cos(t) + c2 sin(t)to obtain a unique solution. More generally, we want to be ableto solve an n-th order IVP and obtain a unique solution. A fewquestions arise. • How do we know this can be done? • How do we know that there isn’t a linear combination of fundamental solutions which isn’t 0 (i.e., the zero function)? The complete answer actually involves methods from linearalgebra which go beyond this course. The basic idea though
  65. 65. is not hard to understand and it involves what is called “theWronskian1 ” [W-linear]. We’ll have to explain what this meansfirst. If f1 (t), f2 (t), . . . , fn (t) are given n-times differentiablefunctions then their fundamental matrix is the matrix   f1 (t) f2 (t) . . . fn (t) ′ ′ ′  f1 (t) f2 (t) . . . fn (t)  Φ = Φ(f1 , ..., fn ) =  . . . .    . . . . . .  (n−1) (n−1) (n−1) f1 (t) f2 (t) . . . fn (t)The determinant of the fundamental matrix is called the Wron-skian, denoted W (f1 , ..., fn ). The Wronskian actually helps usanswer both questions above simultaneously.Example 2.2.1. Take f1 (t) = sin2 (t), f2 (t) = cos2 (t), andf3 (t) = 1. SAGE allows us to easily compute the Wronskian: SAGEsage: SR = SymbolicExpressionRing()sage: MS = MatrixSpace(SR,3,3)sage: Phi = MS([[sin(t)ˆ2,cos(t)ˆ2,1], [diff(sin(t)ˆ2,t),diff(cos(t)ˆ2,t),0], [diff(sin(t)ˆ2,t,t),diff(cos(t)ˆ2,t,t),0]])sage: Phi[ sin(t)ˆ2 cos(t)ˆ2 1][ 2*cos(t)*sin(t) -2*cos(t)*sin(t) 0][2*cos(t)ˆ2 - 2*sin(t)ˆ2 2*sin(t)ˆ2 - 2*cos(t)ˆ2 0]sage: Phi.det()0 1 Josef Wronski was a Polish-born French mathemtician who worked in many differentareas of applied mathematics and mechanical engineering [Wr-linear].
  66. 66. Here Phi.det() is the determinant of the fundamental matrixPhi. Since it is zero, this means W (sin(t)2 , cos(t)2 , 1) = 0.(Note: the above entry for Phi should all be on one line. Fortypographical reasons, we have spread it out to 3 lines.) Theentries for the symbolic expression ring SR and the 3 × 3 ma-trix space MS above are used to construct the matrix Phi havingsymbolic entries.
  67. 67. We try one more example: SAGEsage: SR = SymbolicExpressionRing()sage: MS = MatrixSpace(SR,2,2)sage: Phi = MS([[sin(t)ˆ2,cos(t)ˆ2], [diff(sin(t)ˆ2,t),diff(cos(t)ˆ2,t)]])sage: Phi[ sin(t)ˆ2 cos(t)ˆ2][ 2*cos(t)*sin(t) -2*cos(t)*sin(t)]sage: Phi.det()-2*cos(t)*sin(t)ˆ3 - 2*cos(t)ˆ3*sin(t)This means W (sin(t)2 , cos(t)2 ) = −2 cos(t) sin(t)3 −2 cos(t)3 sin(t),which is non-zero. If there are constants c1 , ..., cn , not all zero, for which c1 f1 (t) + c2 f2 (t) · · · + cn fn (t) = 0, for all t, (2.4)then the functions fi (1 ≤ i ≤ n) are called linearly depen-dent. If the functions fi (1 ≤ i ≤ n) are not linearly dependentthen they are called linearly independent (this definition isfrequently seen for linearly independent vectors [L-linear] butholds for functions as well). This condition (2.4) can be inter-preted geometrically as follows. Just as c1 x + c2 y = 0 is a linethrough the origin in the plane and c1 x + c2 y + c3 z = 0 is a planecontaining the origin in 3-space, the equation c1 x1 + c2 x2 · · · + cn xn = 0,is a “hyperplane” containing the origin in n-space with coordi-nates (x1 , ..., xn ). This condition (2.4) says geometrically that
  68. 68. the graph of the space curve r(t) = (f1 (t), . . . , fn (t)) lies en-tirely in this hyperplane. If you pick n functions “at random”then they are “probably” linearly independent, because “ran-dom” space curves don’t lie in a hyperplane. But certainly notall collections of functions are linearly independent.Example 2.2.2. Consider just the two functions f1 (t) = sin2 (t),f2 (t) = cos2 (t). We know from the SAGE computation in theexample above that these functions are linearly independent. SAGEsage: P = parametric_plot((sin(t)ˆ2,cos(t)ˆ2),0,5)sage: show(P)The SAGE plot of this space curve r(t) = (sin(t)2 , cos(t)2 ) isgiven below. It is obviously not contained in a line through theorigin, therefore making it geometrically clear that these func-tions are linearly independent. The following two results answer the above questions.Theorem 2.2.1. (Wronskian test) If f1 (t), f2 (t), . . . , fn (t)are given n-times differentiable functions with a non-zero Wron-skian then they are linearly independent. As a consequence of this theorem, and the SAGE computationin the example above, f1 (t) = sin2 (t), f2 (t) = cos2 (t), are lin-early independent.Theorem 2.2.2. Given any homogeneous n-th linear ODE y (n) + b1 (t)y (n−1) + ... + bn−1 (t)y ′ + bn (t)y = 0,with differentiable coefficients, there always exists n solutionsy1 (t), ..., yn (t) which have a non-zero Wronskian.
  69. 69. Figure 2.4: Parametric plot of (sin(t)2 , cos(t)2 ). The functions y1 (t), ..., yn (t) in the above theorem are calledfundamental solutions. We shall not prove either of these theorems here. Please see[BD-intro] for further details.Exercise: Use SAGE to compute the Wronskian of (a) f1 (t) = sin(t), f2 (t) = cos(t), (b) f1 (t) = 1, f2 (t) = t, f3 (t) = t2 , f4 (t) = t3 .Check that (a) y1 (t) = sin(t), y2 (t) = cos(t) are fundamental solutions for ′′y + y = 0, (d) y1 (t) = 1, y2 (t) = t, y3 (t) = t2 , y4 (t) = t3 are fundamentalsolutions for y (4) = y ′′′′ = 0.
  70. 70. 2.3 Undetermined coefficients methodThe method of undetermined coefficients [U-uc] can be used tosolve the following type of problem.PROBLEM: Solve ay ′′ + by ′ + cy = f (x), (2.5)where a = 0, b and c are constants and x is the independentvariable. (Even the case a = 0 can be handled similarly, thoughsome of the discussion below might need to be slightly modified.)Where we must assume that f (x) is of a special form. More-or-less equivalent is the method of annihilating operators[A-uc] (they solve the same class of DEs), but that method willbe discussed separately. For the moment, let us assume f (x) has the form a1 · p(x) ·ea2 x · cos(a3 x), or a1 · p(x) · ea2 x · sin(a3 x), where a1 , a2 , a3 areconstants and p(x) is a polynomial.Solution: • Find the “homogeneous solution” yh to ay ′′ + by ′ + cy = 0, yh = c1 y1 + c2 y2 . Here y1 and y2 are determined as follows: let r1 and r2 denote the roots of the characteristic polynomial aD2 + bD + c = 0. – r1 = r2 real: set y1 = er1 x , y2 = er2 x . – r1 = r2 real: if r = r1 = r2 then set y1 = erx , y2 = xerx . – r1 , r2 complex: if r1 = α + iβ, r2 = α − iβ, where α and β are real, then set y1 = eαx cos(βx), y2 = eαx sin(βx).
  71. 71. • Compute f (x), f ′ (x), f ′′ (x), ... . Write down the list of all the different terms which arise (via the product rule), ignoring constant factors, plus signs, and minus signs: t1 (x), t2 (x), ..., tk (x). If any one of these agrees with y1 or y2 then multiply them all by x. (If, after this, any of them still agrees with y1 or y2 then multiply them all again by x.) • Let yp be a linear combination of these functions (your “guess”): yp = A1 t1 (x) + ... + Ak tk (x). This is called the general form of the particular solu- tion. The Ai ’s are called undetermined coefficients. • Plug yp into (2.5) and solve for A1 , ..., Ak . • Let y = yh + yp = yp + c1 y1 + c2 y2 . This is the general solution to (2.5). If there are any initial conditions for (2.5), solve for then c1 , c2 now.Diagramatically: Factor characteristic polynomial ↓ Compute yh
  72. 72. ↓Compute the general form of the particular, yp ↓ Compute the undetermined coefficients ↓ Answer: y = yh + yp .
  73. 73. ExamplesExample 2.3.1. Solve y ′′ − y = cos(2x). • The characteristic polynomial is r2 − 1 = 0, which has ±1 for roots. The “homogeneous solution” is therefore yh = c1 ex + c2 e−x . • We compute f (x) = cos(2x), f ′ (x) = −2 sin(2x), f ′′ (x) = −4 cos(2x), ... . They are all linear combinations of f1 (x) = cos(2x), f2 (x) = sin(2x). None of these agrees with y1 = ex or y2 = e−x , so we do not multiply by x. • Let yp be a linear combination of these functions: yp = A1 cos(2x) + A2 sin(2x). ′′ • You can compute both sides of yp − yp = cos(2x): (−4A1 cos(2x) − 4A2 sin(2x)) − (A1 cos(2x) + A2 sin(2x)) = cos(2x). Equating the coefficients of cos(2x), sin(2x) on both sides gives 2 equations in 2 unknowns: −5A1 = 1 and −5A2 = 0. Solving, we get A1 = −1/5 and A2 = 0. 1 • The general solution: y = yh + yp = c1 ex + c2 e−x − 5 cos(2x).Example 2.3.2. Solve y ′′ − y = x cos(2x). • The characteristic polynomial is r2 − 1 = 0, which has ±1 for roots. The “homogeneous solution” is therefore yh = c1 ex + c2 e−x . • We compute f (x) = x cos(2x), f ′ (x) = cos(2x)−2x sin(2x), f ′′ (x) = −2 sin(2x)− 2 sin(2x) − 2x cos(2x), ... . They are all linear combinations of f1 (x) = cos(2x), f2 (x) = sin(2x), f3 (x) = x cos(2x), .f4 (x) = x sin(2x). None of these agrees with y1 = ex or y2 = e−x , so we do not multiply by x.
  74. 74. • Let yp be a linear combination of these functions: yp = A1 cos(2x) + A2 sin(2x) + A3 x cos(2x) + A4 x sin(2x). ′′ • In principle, you can compute both sides of yp − yp = x cos(2x) and solve for the Ai ’s. (Equate coefficients of x cos(2x) on both sides, equate coefficients of cos(2x) on both sides, equate coefficients of x sin(2x) on both sides, and equate coefficients of sin(2x) on both sides. This gives 4 equations in 4 unknowns, which can be solved.) You will not be asked to solve for the Ai ’s for a problem this hard.Example 2.3.3. Solve y ′′ + 4y = x cos(2x). • The characteristic polynomial is r2 + 4 = 0, which has ±2i for roots. The “homogeneous solution” is therefore yh = c1 cos(2x) + c2 sin(2x). • We compute f (x) = x cos(2x), f ′ (x) = cos(2x)−2x sin(2x), f ′′ (x) = −2 sin(2x)− 2 sin(2x) − 2x cos(2x), ... . They are all linear combinations of f1 (x) = cos(2x), f2 (x) = sin(2x), f3 (x) = x cos(2x), .f4 (x) = x sin(2x). Two of these agree with y1 = cos(2x) or y2 = sin(2x), so we do multiply by x: f1 (x) = x cos(2x), f2 (x) = x sin(2x), f3 (x) = x2 cos(2x), .f4 (x) = x2 sin(2x). • Let yp be a linear combination of these functions: yp = A1 x cos(2x) + A2 x sin(2x) + A3 x2 cos(2x) + A4 x2 sin(2x). ′′ • In principle, you can compute both sides of yp + 4yp = x cos(2x) and solve for the Ai ’s. You will not be asked to solve for the Ai ’s for a problem this hard. More generally, suppose that you want to solve ay ′′ +by ′ +cy =f (x), where f (x) is a sum of functions of the above form. Inother words, f (x) = f1 (x) + f2 (x) + ... + fk (x), where each fj (x)
  75. 75. is of the form c · p(x) · eax · cos(bx), or c · p(x) · eax · sin(bx), wherea, b, c are constants and p(x) is a polynomial. You can proceedin either one of the following ways. 1. Split up the problem by solving each of the k problems ay ′′ + by ′ + cy = fj (x), 1 ≤ j ≤ k, obtaining the solution y = yj (x), say. The solution to ay ′′ + by ′ + cy = f (x) is then y = y1 + y2 + .. + yk (the superposition principle). 2. Proceed as in the examples above but with the following slight revision: • Find the “homogeneous solution” yh to ay ′′ + by ′ = cy = 0, yh = c1 y1 + c2 y2 . • Compute f (x), f ′ (x), f ′′ (x), ... . Write down the list of all the different terms which arise, ignoring constant factors, plus signs, and minus signs: t1 (x), t2 (x), ..., tk (x). • Group these terms into their families. Each family is determined from its parent(s) - which are the terms in f (x) = f1 (x) + f2 (x) + ... + fk (x) which they arose form by differentiation. For example, if f (x) = x cos(2x) + e−x sin(x) + sin(2x) then the terms you get from differ- entiating and ignoring constants, plus signs and minus signs, are x cos(2x), x sin(2x), cos(2x), sin(2x), (from x cos(2x)), e−x sin(x), e−x cos(x), (from e−x sin(x)),
  76. 76. and sin(2x), cos(2x), (from sin(2x)). The first group absorbes the last group, since you can only count the different terms. Therefore, there are only two families in this example: {x cos(2x), x sin(2x), cos(2x), sin(2x)} is a “family” (with “parent” x cos(2x) and the other terms as its “children”) and {e−x sin(x), e−x cos(x)} is a “family” (with “parent” e−x sin(x) and the other term as its “child”). If any one of these terms agrees with y1 or y2 then multiply the entire family by x. In other words, if any child or parent is “bad” then the entire family is “bad”. (If, after this, any of them still agrees with y1 or y2 then multiply them all again by x.) • Let yp be a linear combination of these functions (your “guess”): yp = A1 t1 (x) + ... + Ak tk (x). This is called the general form of the particular solution. The Ai ’s are called undetermined coeffi- cients. • Plug yp into (2.5) and solve for A1 , ..., Ak . • Let y = yh + yp = yp + c1 y1 + c2 y2 . This is the general solution to (2.5). If there are any initial conditions for (2.5), solve for then c1 , c2 last - after the undetermined coefficients.Example 2.3.4. Solve y ′′′ − y ′′ − y ′ + y = 12xex .
  77. 77. We use SAGE for this. SAGEsage: x = var("x")sage: y = function("y",x)sage: R.<D> = PolynomialRing(QQ, "D")sage: f = Dˆ3 - Dˆ2 - D + 1sage: f.factor() (D + 1) * (D - 1)ˆ2sage: f.roots() [(-1, 1), (1, 2)]So the roots of the characteristic polynomial are 1, 1, −1, whichmeans that the homogeneous part of the solution is yh = c1 ex + c2 xex + c3 e−x . SAGEsage: de = lambda y: diff(y,x,3) - diff(y,x,2) - diff(y,x,1) + ysage: c1 = var("c1"); c2 = var("c2"); c3 = var("c3")sage: yh = c1*eˆx + c2*x*eˆx + c3*eˆ(-x)sage: de(yh) 0sage: de(xˆ3*eˆx-(3/2)*xˆ2*eˆx) 12*x*eˆxThis just confirmed that yh solves y ′′′ − y ′′ − y ′ + 1 = 0. Usingthe derivatives of F (x) = 12xex , we generate the general formof the particular: SAGEsage: F = 12*x*eˆx
  78. 78. sage: diff(F,x,1); diff(F,x,2); diff(F,x,3) 12*x*eˆx + 12*eˆx 12*x*eˆx + 24*eˆx 12*x*eˆx + 36*eˆxsage: A1 = var("A1"); A2 = var("A2")sage: yp = A1*xˆ2*eˆx + A2*xˆ3*eˆxNow plug this into the DE and compare coefficients of like termsto solve for the undertermined coefficients: SAGEsage: de(yp) 12*x*eˆx*A2 + 6*eˆx*A2 + 4*eˆx*A1sage: solve([12*A2 == 12, 6*A2+4*A1 == 0],A1,A2) [[A1 == -3/2, A2 == 1]]Finally, lets check if this is correct: SAGEsage: y = yh + (-3/2)*xˆ2*eˆx + (1)*xˆ3*eˆxsage: de(y) 12*x*eˆxExercise: Using SAGE , solve y ′′′ − y ′′ + y ′ − y = 12xex .(Hint: You may need to replace sage: R.<D> = PolynomialRing(QQ, "D")by sage: R.<D> = PolynomialRing(CC, "D").)
  79. 79. 2.3.1 Annihilator methodPROBLEM: Solve ay ′′ + by ′ + cy = f (x). (2.6) We assume that f (x) is of the form c · p(x) · eax · cos(bx), orc · p(x) · eax · sin(bx), where a, b, c are constants and p(x) is apolynomial. soln: • Write the ODE in symbolic form (aD2 + bD + c)y = f (x). • Find the “homogeneous solution” yh to ay ′′ + by ′ = cy = 0, yh = c 1 y1 + c 2 y2 . • Find the differential operator L which annihilates f (x): Lf (x) = 0. The following table may help. function annihilator k x Dk+1 xk eax (D − a)k+1 xk eαx cos(βx) (D2 − 2αD + α2 + β 2 )k+1 xk eαx sin(βx) (D2 − 2αD + α2 + β 2 )k+1 • Find the general solution to the homogeneous ODE, L · (aD2 + bD + c)y = 0. • Let yp be the function you get by taking the solution you just found and subtracting from it any terms in yh . • Solve for the undetermined coefficients in yp as in the method of undetermined coefficients.
  80. 80. ExampleExample 2.3.5. Solve y ′′ − y = cos(2x). • The DE is (D2 − 1)y = cos(2x). • The characteristic polynomial is r2 − 1 = 0, which has ±1 for roots. The “homogeneous solution” is therefore yh = c1 ex + c2 e−x . • We find L = D2 + 4 annihilates cos(2x). • We solve (D2 + 4)(D2 − 1)y = 0. The roots of the characteristic polynomial (r2 + 4)(r2 − 1) are ±2i, ±1. The solution is y = A1 cos(2x) + A2 sin(2x) + A3 ex + A4 e−x . • This solution agrees with yh in the last two terms, so we guess yp = A1 cos(2x) + A2 sin(2x). ′′ • Now solve for A1 and A2 as before: Compute both sides of yp −yp = cos(2x), (−4A1 cos(2x) − 4A2 sin(2x)) − (A1 cos(2x) + A2 sin(2x)) = cos(2x). Next, equate the coefficients of cos(2x), sin(2x) on both sides to get 2 equa- tions in 2 unknowns. Solving, we get A1 = −1/5 and A2 = 0. • The general solution: y = yh + yp = c1 ex + c2 e−x − 1 cos(2x). 5
  81. 81. 2.4 Variation of parametersConsider an ordinary constant coefficient non-homogeneous 2ndorder linear differential equation, ay ′′ + by ′ + cy = F (x)where F (x) is a given function and a, b, and c are constants. (Forthe method below, a, b, and c may be allowed to depend on theindependent variable x as well.) Let y1 (x), y2 (x) be fundamentalsolutions of the corresponding homogeneous equation ay ′′ + by ′ + cy = 0.The method of variation of parameters is originally attributedto Joseph Louis Lagrange (1736-1813) [L-var]. It starts by as-suming that there is a particular solution in the form yp (x) = u1 (x)y1 (x) + u2 (x)y2 (x),where u1 (x), u2 (x) are unknown functions [V-var]. In general, the product rule gives (f g)′ = f ′ g + f g ′ , (f g)′′ = f ′′ g + 2f ′ g ′ + f g ′′ , (f g)′′′ = f ′′′ g + 3f ′′ g ′ + 3f ′ g ′′ + f g ′′′ ,and so on, following Pascal’s triangle, 1 1 1
  82. 82. 1 2 1 1 3 3 1,and so on.
  83. 83. Using SAGE , this can be check as follows: SAGEsage: t = var(’t’)sage: x = function(’x’, t)sage: y = function(’y’, t)sage: diff(x(t)*y(t),t)x(t)*diff(y(t), t, 1) + y(t)*diff(x(t), t, 1)sage: diff(x(t)*y(t),t,t)x(t)*diff(y(t), t, 2) + 2*diff(x(t), t, 1)*diff(y(t), t, 1) + y(t)*diff(x(t), t, 2)sage: diff(x(t)*y(t),t,t,t)x(t)*diff(y(t), t, 3) + 3*diff(x(t), t, 1)*diff(y(t), t, 2) + 3*diff(x(t), t, 2)*diff(y(t), t, 1) + y(t)*diff(x(t), t, 3)By assumption, yp solves the ODE, so ′′ ′ ayp + byp + cyp = F (x).After some algebra, this becomes: a(u′1 y1 + u′2 y2 )′ + a(u′1 y1 + u′2 y2 ) + b(u′1 y1 + u′2 y2 ) = F. ′ ′If we assume u′1 y1 + u′2 y2 = 0then we get massive simplification: a(u′1 y1 + u2 y2 ) = F. ′ ′ ′Cramer’s rule says that the solution to this system is 0 y2 y1 0 det ′ det ′ F (x) y2 y1 F (x) u′1 = , u′2 = . y1 y2 y1 y2 det ′ ′ det ′ ′ y1 y2 y1 y2

×