118
Modeling and Simulation with ODE (MSE) Massimo Fornasier Fakult¨ at f¨ ur Mathematik Technische Universit¨ at M¨ unchen [email protected] http://www-m15.ma.tum.de/ Johann Radon Institute (RICAM) ¨ Osterreichische Akademie der Wissenschaften [email protected] http://hdsparse.ricam.oeaw.ac.at/ Department of Mathematics Technische Universit¨ at M¨ unchen Lecture 6

Modeling and Simulation with ODE (MSE)

  • Upload
    others

  • View
    9

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Modeling and Simulation with ODE (MSE)

Modeling and Simulation with ODE (MSE)

Massimo Fornasier

Fakultat fur MathematikTechnische Universitat [email protected]://www-m15.ma.tum.de/

Johann Radon Institute (RICAM)Osterreichische Akademie der Wissenschaften

[email protected]://hdsparse.ricam.oeaw.ac.at/

Department of MathematicsTechnische Universitat Munchen

Lecture 6

Page 2: Modeling and Simulation with ODE (MSE)

Why are you here?In this course we shall provides the rudiments (the basics!) of thenumerical solution of differential equations, i.e, equations involvingthe derivatives of a (possibly) multivariate functionu : Ω ⊂ Rd → R:

F (x1, . . . , xd , u(x),∂

∂x1u(x), . . . ,

∂xdu(x),

∂2

∂x1∂x1,

∂2

∂x1∂x2, . . . ,

∂2

∂x1∂xd, . . . ) = 0.

Often one of the variables indicates the time, e.g., x1 = t, and theequation governs a phenomena which evolves in time:

∂u

∂t+ F (x , u,Du,D2u, . . . ) = 0.

Differential equations were for thefirst time formulated in the 17th

century by I. Newton (1671) and byG.W. Leibniz (1676).

Page 3: Modeling and Simulation with ODE (MSE)

Just old boring stuff?

Yes, of course!?But also NO, because the history did not stop ...

used by Euler, Maxwell, Boltzmann, Navier, Stokes, Einstein,Prandtl, Schrodinger, Pauli, Dirac,Turing, Black&Scholes ...........

I provide an important modeling tool for the physical sciences,theoretical chemistry, biology, socio-economic sciences,engineering sciences ....

I accessible to numerical simulations

Page 4: Modeling and Simulation with ODE (MSE)

For instance ...Fourier in Theorie analytique de la chaleur (1822) formulated and solvedanalytically the equation governing the heat conduction in homogenous media:

∂u

∂t(t, x)− α

„∂2u

∂x21

(t, x) +∂2u

∂x22

(t, x) +∂2u

∂x23

(t, x)

«= 0.

A similar equation is studied by Fornasier and March in 2007 to recolor ancientItalian frescoes from fragments:

See Restoration of color images by vector valued BV functions and variationalcalculus (M. Fornasier and R. March), SIAM J. Appl. Math., Vol. 68 No. 2,2007, pp. 437-460.

http://www.ricam.oeaw.ac.at/people/page/fornasier/SIAM_Fornasier_

March_067187.pdf

Page 5: Modeling and Simulation with ODE (MSE)

Illustrations of differential equations and some of their(modern) applications

Reference: P. A. Markowich, Applied Partial Differential Equations - A Visual

Approach, Springer, 2006

Slides: http:

//homepage.univie.ac.at/peter.markowich/galleries/vortrag.pdf

I Gas dynamics Boltzmann equationI Fluid/gas dynamics: Navier-Stokes/Euler EquationsI Kinetic modeling of granular flowsI Chemotaxis and formation of biological patternsI Semiconductor modelingI Free boundary problems and interfacesI Reaction-diffusion equationsI Monge-Kantorovich optimal transportationI Wave equationsI Digital image processingI Socio-Economic modeling

Page 6: Modeling and Simulation with ODE (MSE)

From partial differential equations to ordinary differentialequations

As we shall see in the course of this lecture, several partialdifferential equations (PDE) can be reduced, after discretization ofthe space variable, to a system of ordinary differential equations(ODE):

∂u

∂t+ F (t, x , u,Du,D2u, . . . ) = 0⇒ u′h(t) + Fh(u(t)) = 0,

where h is a space discretization parameter.

The first part of this course is dedicated to the use of ODE formodeling physical and engineering problems, while the second partof the course is dedicated to their numerical solution by some ofthe most relevant numerical methods.

Page 7: Modeling and Simulation with ODE (MSE)

Program of the course in a nutshell

Modeling by ODE:

I First-order ODEs

I Second-order linear ODEs

I Higher-oder linear ODEs

I Systems of ODEs

Numerical methods for ODE:

I forward Euler method

I theta method

I Adams methods and more general multi-step methods

I Runge-Kutta methods

I stability and stiffness

I Backward differentiation formulae

Page 8: Modeling and Simulation with ODE (MSE)

References for this course

Besides the slides provided after the lecture online ...Books:

K11 E. Kreyszig, Advanced Engineering Mathematics, 10th Edition, JohnWiley & Sons, Inc., 2011

I09 A. Iserles, A First Course in the Numerical Analysis of DifferentialEquations (2nd ed.), Cambridge University Press, 2009.

QSG10 A. Quarteroni, F. Saleri, P. Gervasio, Scientific Computing with Matlaband Octave (3rd ed.), Springer, 2010.

Lecture notes:

F13 M. Fornasier, Numerik der gewohnlichen Differentialgleichungen,http://www-m3.ma.tum.de/foswiki/pub/M3/NumerikDG13/WebHome/

Numerik_2013-08-04.pdf (password required)

All you find at the webpage of the course:

http://www-m15.ma.tum.de/Allgemeines/ModelingSimulation

Page 9: Modeling and Simulation with ODE (MSE)

References do not mean ...

How does a book work? ...

Page 10: Modeling and Simulation with ODE (MSE)

References do not mean ...

that you do not come to the lecture and think to be smart ...

’cause I will NOT let you escape ...

At the end there will be the exam ... and I’ll be waiting for youthere (REMEMBER IT!) ...you better show up! (just a friendly - Italian - invitation not toskip the lectures :-) !)

Page 11: Modeling and Simulation with ODE (MSE)

Just the classical email from the “smart” student ...

Sehr geehrter Herr Prof. Fornasier,mein Name ist [SmartStudentName]. Gestern habe ich die Prufung in”Numerisches Programmieren II (CSE)” geschrieben. Ich habe extrem viel furdiese Prufung gelernt, da ich mich vor allem in PDEs spezialisieren mochte undim nachsten Semester auch “Numerik der PDEs” bei Prof.[ReallySmartProfName] horen werde. Mich zieht es innerhalb von CSE auchimmer mehr in Richtung Numerik und daher investiere ich viel Kraft in diesesThema. Ich habe mich mit wirklich allen Satzen, Beweisen und auch denThemen nach FEM (hyp./par. PDEs, die Sie nicht mehr behandelt haben) undauch daruber hinaus mit dem Buch von Iserles, “PDEs” von Lawrence Evansund weiterer Literatur beschaftigt und bin der Meinung, dass ich fur einenCSE-Studenten viel mehr Wissen als erforderlich besitze und vieleZusammenhange sehr gut verstanden habe.An dieser Stelle mochte ich meinen Unmut uber die gestrige Prufungausdrucken. Ich hatte bereits in NP1 eine 1.0 und dies war auch gestern meinZiel. Vermutlich habe ich nun gar nicht bestanden oder wenn, dann vielleichthochstens mit einer 4.0.[...]

Vielen herzlichen Dank.

Eh, eh, eh! He has NOT attended the lecture!

Page 12: Modeling and Simulation with ODE (MSE)

Let’s start ... why ODE?

As just mentioned, ODE comes often after the space discretizationof PDE.

But ODE have their own dignity and relevance, since, actually,PDE can be derived as the “limit” of sytems of ODE governing theevolution of particles driven by Newton laws:

F = m · a.

Hence, ODE ⇒ PDE ⇒ ODE.

Page 13: Modeling and Simulation with ODE (MSE)

Particle systemsBesides in physics, large particle systems arise in many modernapplications:

Image halftoning via variational

dithering.

Dynamical data analysis: R. palustris

protein-protein interaction network.

Large Facebook “friendship” network

Computational chemistry: molecule

simulation.

Page 14: Modeling and Simulation with ODE (MSE)

Social dynamics

We consider large particle systems ofform:

xi = vi ,

vi =∑N

j=1 H(xj − xi , vj − vi ),

Several“social forces” encoded in theinteraction kernel H:

I Repulsion-attraction

I Alignment

I ...

Possible noise/uncertainty by addingstochastic terms.

Patterns related to different balance of

social forces.

Understanding how superposition of re-iterated binary “socialforces” yields global self-organization.

Page 15: Modeling and Simulation with ODE (MSE)

An example inspired by nature

Mills in nature and in our simulations.

J. A. Carrillo, M. Fornasier, G. Toscani, and F. Vecil, Particle, kinetic,

hydrodynamic models of swarming, within the book “Mathematical modeling

of collective behavior in socio-economic and life-sciences”, Birkhauser (Eds.

Lorenzo Pareschi, Giovanni Naldi, and Giuseppe Toscani), 2010.

http://www.ricam.oeaw.ac.at/people/page/fornasier/bookfinal.pdf

Page 16: Modeling and Simulation with ODE (MSE)

The genearal ODEOur goal is to use equations of the type

y ′ = f (t, y), t ≥ t0, y(t0) = y0, (1)

for modeling and then for simulation. (In the previous modeling,yi = (xi , vi ) and f (t, y)i = (vi ,

∑Nj=1 H(xj − xi , vj − vi )).)

I f is a map of [t0,∞)× Rd to Rd and the initial conditiony0 ∈ Rd is a given vector

I f is “nice”, obeying, in a given vector norm, the Lipschitzcondition

‖f (t, x)− f (t, y)‖ ≤ λ‖x − y‖, ∀x , y ∈ Rd , t ≥ t0 (2)

Here λ > 0 is a real constant that is independent of thechoice of x and y . In this case we say that f is a Lipschitzcontinuous function.

I Subject to (2), it is possible to prove that the ODE system(1) possesses a unique solution (see, for instance [Theorem3.5, F13] pag. 52).

Page 17: Modeling and Simulation with ODE (MSE)

Just an idea of the proof of existence and uniqueness(Picard 1890, Lindelof 1894)

Actually (1) can be rewritten by integration

y(t) = y0 +

∫ t

t0

f (s, y(s))ds = g(y)(t). (3)

Hence, a solution y(t) is a fixed point trajectory of the equationy = g(y). How can one solve fixed point equations? Well, if gwere a contraction, i.e., g is a Lipschitz continuous function withLipschitz constant 0 < Λ < 1, then the iteration

yn+1 = g(yn), n ≥ 0 (4)

converges always to the unique fixed point!

Page 18: Modeling and Simulation with ODE (MSE)

Graphical interpretation and mathematical explanation

Indeed, assume that such fixed point y exists then

‖y−yn+1‖∗ = ‖g(y)−g(yn)‖∗ ≤ Λ‖y−yn‖∗ ≤ Λn‖y−y0‖∗ → 0, n→∞,

because Λ < 1. The tricky part of the proof is to show that thereexists a fixed point and that there exists always a norm ‖ · ‖∗ whichmakes g a contraction as soon as f is Lipschitz continuous.

Page 19: Modeling and Simulation with ODE (MSE)

Did you noticed that ...... what we wrote in (4) is actually an ALGORITHM?!

OMG! Really, an ALGORITHM?!

... is it a bad thing?!Actually, no, that’s what you are here for! Or, perhaps yes ... Ohwell, nevertheless, an ALGORITHM!

For the brave student: if you find out a way to discretize (4) and a way of

properly “scaling” the equation so that the iteration always converges on a

finite set of time point t0 < t1 < · < tn, then let me know! Actually this course

is (IMPLICITLY) all about this!

Page 20: Modeling and Simulation with ODE (MSE)

From Picard-Lindelof back to Euler: “greed is good!”Instead of solving globally the fixed point equation (3) by amultitude of iterations (4), we may consider the simpler idea ofsolving it locally, step by step, by iterating the approximation

y(t) = y0+

∫ t

t0

f (s, y(s))ds ≈ y(t0)+(t−t0)f (t0, y(t0)), for t ≈ t0.

(5)Given a sequence t0, t1 = t0 + h, t2 = t0 + 2h, ... , where h > 0 isa time step, we denote by yn a numerical estimate of the exactsolution y(tn), n = 0, 1, . . . . Motivated by (5), we choose

y1 = y0 + hf (t0, y0).

If h is small, it should not be that wrong! But then, why not tocontinue, assuming that we did not that bad before, at t2, t3 andso on. In general, we obtain the recursive scheme

yn+1 = yn + hf (tn, yn), (6)

the celebrated Euler method.

Page 21: Modeling and Simulation with ODE (MSE)

Graphical interpretationConsider the Euler method applied to the logistic equation

y ′ = y(1− y), y(0) =1

10,

with step h = 1:

It’s clear that at each step we produce an error, but our goal is not to avoid

any (numerical error)! (Eventually nobody is perfect!) Our final goal is to have

a practical method that approximates the analytic solution with increasing

accuracy (i.e., decreasing error) the more computational effort we do.

Page 22: Modeling and Simulation with ODE (MSE)

Yes, but what hell is this logistic equation? Is it justmathematical nonsense?!

The logistic equation is a model

OMG! Really, a MODEL?!

of population growth first published by Pierre Verhulst (1845,1847). Its solution is the function

y(t) =1

1 + e−t, t ∈ R.

Try it out and check that y ′(t) = y(t)(1− y(t)) (Exercise)!

Page 23: Modeling and Simulation with ODE (MSE)

Yes, but what hell is this logistic equation? Is it justmathematical nonsense?!

The logistic function finds applications in a range of fields, including artificialneural networks, biology, especially ecology, biomathematics, chemistry,demography, economics, geoscience, mathematical psychology, probability,sociology, political science, and statistics.In population dynamics one describes the growth of the population P(t) by

dP(t)

dt= rP(t)

„1− P(t)

K

«.

The term rP(t) on the right-hand side tells that for r > 0 the larger is thepopulation the stronger the growth will be (he, he, he) ... however the negativeterm − r

KP(t)2 instead indicates the drop of the population due to - interacting

- competition. This antagonistic effect is called the bottleneck, and is modeledby the value of the parameter K > 0. By setting y = P(t)

Kone obtains

y ′(t) = ry(t)(1− y(t)),

which for r = 1 is just our equation.

Page 24: Modeling and Simulation with ODE (MSE)

How to implement Euler’s method in MATLAB

Try out Euler’s method on the logistic equation:

f = @(t,x) x.*(1-x); [t,yy]=ode45(f,[0:5],1/10); y(1)=1/10;h=1; for n=1:5, y(n+1)=y(n)+h*y(n)*(1-y(n)); end,plot([0:5],y,’r*-’,[0:5],yy,’b’) h=1/2; for n=1:10,y(n+1)=y(n)+h*y(n)*(1-y(n)), end, hold on,plot([0:0.5:5],y,’g-*’)

Page 25: Modeling and Simulation with ODE (MSE)

Convergence of a numerical method

Assume that h > 0 is variable and h→ 0. On each grid t0,t1 = t0 + h, t2 = t0 + 2h, ... we associate a different numericalsequence yn = yn,h, n = 0, 1, . . . , bt∗/hc (not necessarily producedby the Euler method!).

A method is said to be convergent if, for every ODE (1) with aLipschitz function f and every t∗ > 0 it is true that

limh→0

maxn=0,1,...,bt∗/hc

‖yn,h − y(tn)‖ = 0,

where bαc ∈ Z is the integer part of α ∈ R.

Convergence means that, for every Lipschitz function,the numerical solution tends to the true solution as thegrid becomes increasingly fine.

Page 26: Modeling and Simulation with ODE (MSE)

Convergence of the Euler method

TheoremThe Euler method (6) is convergent

Proof. (For this proof we assume that the Taylor expansion of f has uniformlybounded coefficients, i.e., f is analytic, implying that y is analytic as well.) Letus consider the error en,h = yn − y(tn). We shall prove limh→0 ‖en,h‖ = 0.Taylor expansion of y(t)

y(tn+1) = y(tn) + hy ′(tn) +O(h2) = y(tn) + hf (tn, y(tn)) +O(h2).

Subtracting this equation to (6), we obtain

en+1,h = en,h + h[f (tn, yn)− f (tn, y(tn))] +O(h2).

Triangle inequality and (2) imply

‖en+1,h‖ ≤ ‖en,h‖+ h‖f (tn, yn)− f (tn, y(tn))‖+ ch2

≤ (1 + hλ)‖en,h‖+ ch2.

By induction over this estimate we get

‖en,h‖ ≤c

λh[(1 + hλ)n − 1], n = 0, 1, . . .

Page 27: Modeling and Simulation with ODE (MSE)

Convergence of the Euler method continues ...

We notice now that 1 + ξ ≤ eξ for all ξ > 0, hence (1 + hλ) ≤ ehλ and(1 + hλ)n ≤ ehnλ. But n = 0, 1, . . . , bt∗/hc and n ≤ t∗/h, implying

(1 + hλ)n ≤ et∗λ

and‖en,h‖ ≤

h c

λ(et∗λ − 1)

i· h. (7)

Sinceh

(et∗λ − 1)i

is independent of n and h, it follows

limh→0

max0≤nh≤t∗

‖en,h‖ = 0.

The error bound in (7) tells us that actually Euler’s methodconverges with order q = 1 since it decays as O(hq). However,letus stress that the constant

[cλ(et∗λ − 1)

]is by far over-pessimistic

and should not be used for numerical puroposes (it’s justtheoretical!).

Page 28: Modeling and Simulation with ODE (MSE)

Beyond logistic equation?

Other applications of ODEs (extracted from the book [K11])

Page 29: Modeling and Simulation with ODE (MSE)

First oder ODEs

We shall consider first-order ODEs. Such equations contain onlythe first derivative y ′ and may contain y and any given functionsof x . Hence we can write them as

F (x , y , y ′) = 0,

or often in the explicit form

y ′ = f (x , y),

as we already got used to read it. Example: x−3y ′ − 4y2 = 0 isimplicit and y ′ = 4y2x3 is its explicit form.

Page 30: Modeling and Simulation with ODE (MSE)

Solution of a ODE

A solution y = y(x) of a ODE is a differentiable function definedon an real interval [a, b], with −∞ ≤ a < b ≤ +∞ which formallyfulfills the equation

y ′(x) = f (x , y(x)),

at every x ∈ (a, b). Example: y(x) = c/x is a solution of theequation

xy ′ = −y .

Indeed, differentiate y(x) = c/x to get y ′(x) = −c/x2. Multiplythe latter by x and obtain xy ′(x) = −c/x = −y(x)!

Page 31: Modeling and Simulation with ODE (MSE)

Solution by direct calculus

One trivial version of ODE is the one where there is no dependenceon y on the right-hand side, i.e.,

y ′ = f (x , y) = f (x).

But then, by integration we get

y(x) =

∫ x

x0

f (ξ)dξ + y(x0),

where y(x0) is an unknown value! Hence

y =

∫f (ξ)dξ + c ,

is a family of possible solutions. Example: y ′(x) = cos(x) hassolutions y(x) = sin(x) + c .

Page 32: Modeling and Simulation with ODE (MSE)

Family of solutions

Page 33: Modeling and Simulation with ODE (MSE)

Linear first order equation

The functiony(x) = ecx , (8)

has derivativey ′(x) = cecx = cy(x).

Hence the exponential function (8) is actually a solution of theequation

y ′ = cy ,

where the right-had side f (x , y) = cy is a linear function in y .

Page 34: Modeling and Simulation with ODE (MSE)

Some terminology

We see that each ODE in these examples has a solution thatcontains an arbitrary constant c. Such a solution containing anarbitrary constant c is called a general solution of the ODE.

Geometrically, the general solution of an ODE is a family ofinfinitely many solution curves, one for each value of the constantc . If we choose a specific c we obtain what is called a particularsolution of the ODE. A particular solution does not contain anyarbitrary constants.

Page 35: Modeling and Simulation with ODE (MSE)

Initial value problems

In most cases the unique solution of a given problem, hence aparticular solution, is obtained from a general solution by an initialcondition y(x0) = y0, with given values x0 and y0, that is used todetermine a value of the arbitrary constant c .Example: Solve the initial value problem

y ′ = 3y , y(0) = 5.7.

The general solution is given by

y(x) = ce3x .

We need to detemine c . The we plug y(0) = 5.7 = ce30 = c.Hence, c = 5.7 and

y(x) = 5.7e3x .

Page 36: Modeling and Simulation with ODE (MSE)

Radioactivity. Exponential DecayPhysical Information. Experiments show that at each instant aradioactive substance decomposes and is thus decaying in timeproportional to the amount of substance present: if y(t) is theamount of radioactive substance at the time t, we have

y ′ = −ky ,

where the constant k is positive, so that, because of the minus, wedo get decay. The value of k is known from experiments forvarious radioactive substances (e.g., k = 1.4× 10−11 sec−1,approximately, for radium 226

88 Ra).

Exponential decay of a radioactive substance

Page 37: Modeling and Simulation with ODE (MSE)

Geometrical interpretation

The equationy ′ = f (x , y),

has a simple geometric interpretation. From calculus you know thatthe derivative y ′(x) of y(x) is the slope of y(x). Hence a solutioncurve that passes through a point (x0, y0) must have, at that point,the slope y ′(x0) equal to the value of f at that point; that is,

y ′(x0) = f (x0, y0).

Page 38: Modeling and Simulation with ODE (MSE)

Geometrical interpretationThis gives a direction field (or slope field) into which you can thenfit (approximate) solution curves. This may reveal typicalproperties of the whole family of solutions. The figure below showsa direction field for the ODE

y ′ = y + x .

Direction field of y ′ = y + x , with three approximate solution curves passing

through (0, 1), (0, 0), (0,−1), respectively

Page 39: Modeling and Simulation with ODE (MSE)

Separable ODEs. ModelingMany practically useful ODEs can be reduced to the form

g(y)y ′ = f (x) (9)

by purely algebraic manipulations. Then we can integrate on bothsides with respect to x , obtaining∫

g(y)y ′dx =

∫f (x)dx + c . (10)

On the left we can switch to y as the variable of integration. Bycalculus, y ′dx = dy , so that∫

g(y)dy =

∫f (x)dx + c . (11)

If f and g are continuous functions, the integrals exist, and byevaluating them we obtain a general solution. This method ofsolving ODEs is called the method of separating variables, and (9)is called a separable equation.

Page 40: Modeling and Simulation with ODE (MSE)

Example 1

The ODE y ′ = 1 + y2 because it can be written

1

1 + y2dy = dx ,

By integration we obtain arctan y = x + c or y = tan(x + c). It isvery important to introduce the constant of integrationimmediately when the integration is performed! If we wrotearctan y = x , then y = tan x , and then introduced c , we wouldhave obtained y = tan x + c , which is not a solution (whenc 6= 0). Verify this.

Page 41: Modeling and Simulation with ODE (MSE)

Example 2

The ODE y ′ = (x + 1)e−xy2 is separable; we obtainy−2dy = (x + 1)e−xdx . By integration

−y−1 = −(x + 2)e−x + c, y(x) =1

(x + 2)e−x − c.

Page 42: Modeling and Simulation with ODE (MSE)

Example 3. Initial value problem (IVP): the bell-shapedfunction

Solvey ′ = −2xy , y(0) = 1.8.

Solution: by separation of variables

1

ydy = −2xdx ,

and by integrationln(y) = −x2 + c ,

ory = ce−x2

,

where c = e c . This is the general solution. From the initialcondition we have 1.8 = y(0) = c . Hence the IVP has solutiony(x) = 1.8e−x2

.

Page 43: Modeling and Simulation with ODE (MSE)

Otzi: my grangrangranfather!

Otzi: the iceman well-preserved natural mummy

of a Chalcolithic (Copper Age) man from about XXX BC

In September 1991 the famous Iceman (Oetzi), a mummy from theNeolithic period of the Stone Age found in the ice of the OetztalAlps (hence the name “Oetzi”) in Southern Tyrolia near theAustrian-Italian border (like me!), caused a scientific sensation.When did Oetzi approximately live and die if the ratio of carbon 14

6C to carbon 12

6 C in this mummy is 52.5% of that of a livingorganism?

Page 44: Modeling and Simulation with ODE (MSE)

Physical facts

In the atmosphere and in living organisms, the ratio of radioactivecarbon 14

6 C (made radioactive by cosmic rays) to ordinary carbon126 C is constant. When an organism dies, its absorption of 14

6 C bybreathing and eating terminates. Hence one can estimate the ageof a fossil by comparing the radioactive carbon ratio in the fossilwith that in the atmosphere. To do this, one needs to know thehalf-life of 14

6 C, which is 5715 years (CRC Handbook of Chemistryand Physics, 83rd ed., Boca Raton: CRC Press, 2002, page 1152,line 9).

Page 45: Modeling and Simulation with ODE (MSE)

Mathematical modelingRadioactive decay is governed by the ODE y ′ = ky . By separationand integration (where t is the time and y0 is the initial ratio of146 C to 12

6 C)

dy

y= kdt, ln(|y |) = kt + c , y = y0ekt , (y0 = ec).

Next we use the half-life H = 5715 to determine k. When t = H,half of the original substance is still present. Thus

y0ekH = 0.5y0, ekH = 0.5, k =ln 0.5

H= −0.693

5715= −0.0001213.

Finally, we use the ratio 52.5% for determining the time t whenOetzi died (actually, was killed),

ekt = e−0.0001213t = 0.525, t =ln(0.525)

−0.0001213= 5312.

Answer: About 5300 years ago!!!

Page 46: Modeling and Simulation with ODE (MSE)

Heating an office

Suppose that in winter the daytime temperature in a certain officebuilding is maintained at 20C . The heating is shut off at 22. andturned on again at 6. On a certain day the temperature inside thebuilding at 2 was found to be 18C . The outside temperature was4C at 22 and had dropped to −6C by 6. What was thetemperature inside the building when the heat was turned on at 6?

Page 47: Modeling and Simulation with ODE (MSE)

Heating an office

Physical information. Experiments show that the time rate ofchange of the temperature T of a body B (which conducts heatwell, for example, as a copper ball does) is proportional to thedifference between T and the temperature of the surroundingmedium (Newton’s law of cooling).

Page 48: Modeling and Simulation with ODE (MSE)

Heating an office

Newton’s law:dT

dt= k(T − TA).

Unfortunately we do NOT know TA, external temperature, which is a functionof time. Then we decide to approximate it to the mean TA ≈ 4−6

2= −1. Hence

dT

T + 1= kdt, ln |T + 1| = kt + C , T (t) = −1 + cekt .

We choose 22 as time t = 0. Then the given initial condition T (0) = 20. Bysubstitution

20 = T (0) = −1 + cek0 = −1 + c c = 21.

Now we determine k. T (4) = 18 at 2 where t = 4 is 2 in the morning.

18 = T (4) = −1 + 21e4k ,19

21= e4k , k =

1

4ln(0.90) = −0.025.

Hence

T (t) = −1 + 21e−0.025t , T (8) = −1 + 21e−0.025×8 ≈ 16.3C .

Page 49: Modeling and Simulation with ODE (MSE)

Leaking tank

It concerns the outflow of water from a cylindrical tank with a holeat the bottom. You are asked to find the height of the water in thetank at any time if the tank has diameter 2 m, the hole hasdiameter 1 cm, and the initial height of the water when the hole isopened is 2.25 m. When will the tank be empty?

Page 50: Modeling and Simulation with ODE (MSE)

Leaking tank

Physical information. Under the influence of gravity the outflowingwater has velocity

v(t) = 0.600√

2gh(t) (Torricelli’s law),

where h(t) is the height of the water above the hole at time t, andg = 980cm/sec2 is the acceleration of gravity at the surface of theearth.

Page 51: Modeling and Simulation with ODE (MSE)

Leaking tank

To get an equation, we relate the decrease in water level h(t) to the outflow.The volume ∆V of the outflow during a short time ∆t is

∆V = Av∆t, A is the area of the hole

and it has to be equal to the change ∆V ∗ of volume in the tank, given by

∆V ∗ = −B∆h,

where B is the cross-sectional area of the tank and ∆h is the decrease of theheight h(t) of the water. Hence, by Torricelli’s law

−B∆h = Av∆t, or∆h

∆t= −A

Bv = −A

B0.600

p2gh(t).

By letting ∆t → 0 we obtain the wonderful ODE

dh

dt= −A

B0.600

p2gh = −26.56

A

B

√h.

Page 52: Modeling and Simulation with ODE (MSE)

Leaking tank

This is our model, a first-order ODE, which is actually separable.A/B is constant. Separation and integration gives

dh√h

= −26.56A

Bdt, 2

√h(t) = c − 26.56

A

Bt.

Dividing by 2 and squaring gives h(t) = (c − 13.28At/B)2.Inserting 13.28A/B = 0.000332 yields the general solution

h(t) = (c − 0.000332t)2.

The initial height h(0) = 225cm and c2 = 225 or c = 15, thus theparticular solution is

h(t) = (15− 0.000332t)2.

Hence h(t) = 0 for t = 45181 sec or t ≈ 12.6 hours.

Page 53: Modeling and Simulation with ODE (MSE)

Extended method: reduction to separable form

Certain nonseparable ODEs can be made separable bytransformations that introduce for y a new unknown function. Wediscuss this technique for a class of ODEs of practical importance,namely, for equations

y ′ = f(y

x

),

where f is a differentiable function. The form of the ODE suggeststhe introduction of a new variable function u = y/x . By productrule y ′ = u′x + u. Substitution into the equation leads to

u′x + u = f (u), ordu

f (u)− u=

dx

x,

if f (u)− u 6= 0.

Page 54: Modeling and Simulation with ODE (MSE)

ExampleSolve

2xyy ′ = y 2 − x2.

Solution. To get the usual explicit form we divide by 2xy and obtain

y ′ =y 2 − x2

2xy=

y

2x− x

2y.

By using the subsitution y = ux we obtain

u′x + u =u

2− 1

2um

2udu

1 + u2= −dx

x.

By integration we get

ln(1 + u2) = − ln |x |+ c = ln1

|x | + c.

By applying the exponentials on both sides we get

1 + u2 = c/x or 1 + (y/x)2 = c/x .

Multiplying by x2 both sides yeilds

x2 + y 2 = cx , or“

x − c

2

”2

+ y 2 =c2

4.

Page 55: Modeling and Simulation with ODE (MSE)

Graphical interpretation

This general solution represents a family of circles passing throughthe origin with centers on the x-axis.

Page 56: Modeling and Simulation with ODE (MSE)

Second-Order Linear ODE

A second-order ODE is called linear if it can be written

y ′′ + p(x)y ′ + q(x)y = r(x),

and nonlinear if it cannot be written in this form. The distinctivefeature of this equation is that it is linear in y and its derivatives,whereas the functions p, q, and r on the right may be any givenfunctions of x . If the equation begins with, say, f (x)y ′′, thendivide by f (x) to have the standard form with y ′′ as the first term.

Page 57: Modeling and Simulation with ODE (MSE)

(Non)homogenous equations

If r(x) ≡ 0 (that is, r(x) = 0 for all x considered; read “r(x) isidentically zero”), then the equation reduces to

y ′′ + p(x)y ′ + q(x)y = 0

and is called homogeneous. If r(x) 6= 0, then the equation iscalled nonhomogeneous. An example of a nonhomogeneouslinear ODE is

y ′′ + 25y = e−x cos x ,

and a homogeneous linear ODE is

xy ′′ + y ′ + xy = 0 ⇒ y ′′ + y ′/x + y = 0

Finally, an example of a nonlinear ODE is

y ′′y + y ′2

= 0.

The functions p and q are called the coefficients of the ODEs.

Page 58: Modeling and Simulation with ODE (MSE)

Solutions

Solutions are defined similarly as for first-order ODEs. A functiony(x) is called a solution of a (linear or nonlinear) second-orderODE on some open interval I if y is defined and twicedifferentiable throughout that interval and is such that the ODEbecomes an identity if we replace the unknown y, the derivative y ′,and the second derivative y ′′.

Page 59: Modeling and Simulation with ODE (MSE)

Homogeneous Linear ODEs: Superposition PrincipleLinear ODEs have a rich solution structure. For the homogeneousequation the backbone of this structure is the superpositionprinciple or linearity principle, which says that we can obtainfurther solutions from given ones by adding them or by multiplyingthem with any constants. Example: The functions y = cos x andy = sin x are both solutions of the homogeneous linear ODE

y ′′ + y = 0

for all x. Verify this by differentiation and substitution:(cos x)′′ = − cos x and similarly (sin x)′′ = − sin x! However, dueto the linearity of the equations any other function of the type

y(x) = c1 cos x + c2 sin x

is again a solution of the equation!!! Indeed

(c1 cos x+c2 sin x)′′ = c1(cos x)′′+c2(sin x)′′ = −(c1 cos x+c2 sin x).

Page 60: Modeling and Simulation with ODE (MSE)

Homogeneous Linear ODEs: Superposition Principle

In this example we have obtained from y1(= cos x) and y2(= sin x)a function of the form

y = c1y1 + c2y2

(c1, c2 arbitrary constants). This is called a linear combination ofy1 and y2. In terms of this concept we can now formulate theresult suggested by our example, often called the superpositionprinciple or linearity principle.

Page 61: Modeling and Simulation with ODE (MSE)

Fundamental Theorem for the Homogeneous Linear ODE

TheoremFor a homogeneous linear ODE, any linear combination of twosolutions on an open interval I is again a solution on I . Inparticular, for such an equation, sums and constant multiples ofsolutions are again solutions.

Proof.Let y1 and y2 be solutions of

y ′′ + p(x)y ′ + q(x)y = 0

on I . Then by substituting y = c1y1 + c2y2 and its derivatives into the equation,and using the familiar rule (y = c1y1 + c2y2)′ = c1y ′1 + c2y ′2, etc., we get

y ′′ + p(x)y ′ + q(x)y

= (c1y1 + c2y2)′′ + p(x)(c1y1 + c2y2)′ + q(x)(c1y1 + c2y2)

= c1y ′′1 + c2y ′′2 + p(x)(c1y ′1 + c2y ′2) + q(x)(c1y1 + c2y2)

= c1y ′′1 + p(x)c1y ′1 + q(x)c1y1| z :=0

+ c2y ′′2 + p(x)c2y ′2 + q(x)c2y2| z :=0

= 0.

Page 62: Modeling and Simulation with ODE (MSE)

Caution!

Don’t forget that this highly important theorem holds forhomogeneous linear ODEs only but does not hold fornonhomogeneous linear or nonlinear ODEs, as the followingexample illustrates. Verify by substitution that the functionsy = 1 + cos x and y = 1 + sinx are solutions of thenonhomogeneous linear ODE

y ′′ + y = 1,

but their sum is not a solution.

Page 63: Modeling and Simulation with ODE (MSE)

Also nonlinearity breaks the superposition principle!

Verify by substitution that the functions y = x2 and y = 1 aresolutions of the nonlinear ODE

y ′′y − xy ′ = 0,

but their sum is not a solution!!

Page 64: Modeling and Simulation with ODE (MSE)

Initial value problems

For a second-order homogeneous linear ODE, an initial valueproblem consists of the equation and two initial conditions

y(x0) = K0, y ′(x0) = K1.

These conditions prescribe given values of the solution and its firstderivative (the slope of its curve) at the same given x0 in the openinterval considered. The conditions are used to determine the twoarbitrary constants c1 and c2 in a general solution

y = c1y1 + c2y2

of the ODE; here, y1 and y2 are suitable solutions of the ODE.This results in a unique solution, passing through the point(x0,K0) with K1 as the tangent direction (the slope) at that point.That solution is again called a particular solution of the ODE.

Page 65: Modeling and Simulation with ODE (MSE)

Examples

Solve the initial value problem

y ′′ + y = 0, y(0) = 3.0, y ′(0) = −0.5.

Solution. General solution. The functions cos x and sin x are solutions of theODE and

y = c1 cos x + c2 sin x .

be a general solution. Particular solution. We need the derivativey ′ = −c1 sin x + c2 cos x . From this and the initial values we obtain, sincecos 0 = 1 and sin 0 = 0,

y(0) = c1 = 3.0,

andy ′(0) = c2 = −0.5.

This gives as the solution of our initial value problem the particular solution

y = 3.0 cos x − 0.5 sin x .

Page 66: Modeling and Simulation with ODE (MSE)

Linear independence!

Our choice of y1 and y2 was “independent” enough to satisfy bothinitial conditions. Now let us take instead two proportionalsolutions y1 = cos x and y2 = k cos x , so that

y = c1 cos x + c2(k cos x) = C cos x

where C = c1 + c2k . We are no longer able to satisfy two initialconditions with only one arbitrary constant C . Consequently, indefining the concept of a general solution, we must excludeproportionality and we need linear independence of two solutions!

Page 67: Modeling and Simulation with ODE (MSE)

Linear space structure

DefinitionA general solution of an ODE

y ′′ + p(x)y ′ + q(x)y = 0

on an open interval I is a solution y = c1y1 + c2y2 in which y1 andy2 are solutions of the equation on I that are not proportional, andc1 and c2 are arbitrary constants. These y1, y2 are called a basis(or a fundamental system) of solutions of the equation on I . Aparticular solution on I is obtained if we assign specific values to c1

and c2.

Page 68: Modeling and Simulation with ODE (MSE)

Linear space structure

Actually, we can reformulate our definition of a basis by using aconcept of general importance. Namely, two functions y1 and y2

are called linearly independent on an interval I where they aredefined if

k1y1(x) + k2y2(x) = 0

everywhere on I implies k1 = 0 and k2 = 0. And y1 and y2 arecalled linearly dependent on I if k1y1(x) + k2y2(x) = 0 also holdsfor some constants k1, k2 not both zero.

Definition (Basis reformulated)

A basis of solutions on an open interval I is a pair of linearlyindependent solutions on I .

Page 69: Modeling and Simulation with ODE (MSE)

Example

Verify by substitution that y1 = ex and y2 = e−x are solutions ofthe ODE y ′′ + y = 0. Then solve the initial value problem

y ′′ − y ′ = 0, y(0) = 6, y ′(0) = −2.

Solution. As (e±x)′ = ±ex it is easily shown that (e±x)′′ − e±x = 0. They are

not proportional, ex/e−x = e2x 6= const. Hence ex , e−x form a basis for all x .

The rest is just as before by finding c1 and c2 of y = c1ex + c2e−x by the given

initial conditions. The final answer is y = 2ex + 4e−x . This is the particular

solution satisfying the two initial conditions.

Page 70: Modeling and Simulation with ODE (MSE)

Reduction of the order

It happens quite often that one solution can be found byinspection or in some other way. Then a second linearlyindependent solution can be obtained by solving a first-order ODE.This is called the method of reduction of order.

Page 71: Modeling and Simulation with ODE (MSE)

ExampleFind a basis of solutions of the ODE

(x2 − x)y ′′ − xy ′ + y = 0.

Solution. Inspection shows that y1 = x is a solution because y ′1 = 1 andy ′′1 = 0, so that the first term vanishes identically and the second and thirdterms cancel. The idea of the method is to substitute

y = uy1 = ux , y ′ = u′x + u, y ′′ = u′′x + 2u.

into the ODE. This gives

(x2 − x)(u′′x + 2u′)− x(u′x + u) + ux = 0.

ux and xu cancel and we are left with an ODE, which we divide by x , order,and simplify to obtain

(x2 − x)u′′ + (x − 2)u′ = 0.

This ODE is of first order in v = u′, namely, (x2 − x)v ′ + (x − 2)v = 0!Separation of variables and integration now gives

dv

v= − x − 2

x2 − xdx = (

1

x − 1− 2

x)dx , ln |v | = ln |x − 1| − 2 ln |x | = ln

|x − 1|x2

.

Page 72: Modeling and Simulation with ODE (MSE)

Example continued ...

We need no constant of integration because we want to obtain a particularsolution; similarly in the next integration. Taking exponents and integratingagain, we obtain

v =x − 1

x2=

1

x− 1

x2, u =

Zvdx = ln |x |+ 1

x,

hence y2 = ux = x ln |x |+ 1. Since y1 = x and y2 = ux = x ln x + 1 are linearly

independent (their quotient is not constant), we have obtained a basis of

solutions, valid for all positive x .

Page 73: Modeling and Simulation with ODE (MSE)

The general methodIn this example we applied reduction of order to a homogeneous linear ODE

y ′′ + p(x)y ′ + q(x)y = 0.

We assume a solution y1 on an open interval I to be known and want to find abasis. For this we need a second linearly independent solution y2 on I . To gety2, we substitute

y = y2 = uy1, y ′ = u′y1 + u′y1, y ′′ = u′′y1 + 2u′y ′1 + uy ′′,

in the equation, obtaining

u′′y1 + u′(2y ′1 + py1) + u (y ′′1 + py ′1 + qy1)| z :=0

= 0.

Hence, for v = u′ we obtain

v ′ + v2y ′1 + py1

y1= 0,

which can be solved by separation of variables!

dv

v= −2y ′1 + py1

y1dx , ln |v | = −2 ln |y1| −

Zpdx or v =

1

y 21

eR

pdx .

Hence, the desired second solution y2 = uy1 = y1

Rvdx . As the quotient

y2/y1 = u =R

vdx cannot be constant because v > 0, y1 and y2 are a basis for

the space of solutions!

Page 74: Modeling and Simulation with ODE (MSE)

Homogeneous Linear ODEs with Constant Coefficients

We shall now consider second-order homogeneous linear ODEswhose coefficients a and b are constant,

y ′′ + ay ′ + by = 0.

These equations have important applications in mechanical andelectrical vibrations. To solve it, we recall that the solution of thefirst-order linear ODE with a constant coefficient k

y ′ + ky = 0,

isy(x) = ce−kx .

Page 75: Modeling and Simulation with ODE (MSE)

Solution strategy

This gives us the idea to try with solutions of the type y(x) = eλx ,for which

y ′(x) = λeλx , y ′′(x) = λ2eλx ,

hence(λ2 + aλ+ b)eλx = 0, ∀x

and λ is a solution of the characteristic equationλ2 + aλ+ b = 0. From algebra we know that the roots are

λ± =1

2(−a±

√a2 − 4b),

leading to two solutions

y1(x) = eλ+x , y2(x) = eλ−x

Page 76: Modeling and Simulation with ODE (MSE)

CasesWe have three cases

I a2 − 4b > 0: two distict real roots;I a2 − 4b = 0: one double root;I a2 − 4b < 0: two conjugate complex roots;

In the first case, we have that

y(x) = c1y1(x) + c2y2(x),

is the general solution of the equation, since y1 and y2 are certainly notproportional. In the second case, λ = −a/2 and there is only one solution giveny1(x) = e−a/2x . In order to obtain a second solution needed for a basis, we usethe order reduction technique. So we consider y2 = uy1. Plugging this into theequation we obtain, as we already computed

u′′y1 + u′(2y ′1 + ay1) = 0.

Now notice that actually 2y ′1 + ay1 = 0! In fact y1(x) = e−a/2x , hencey ′1(x) = − a

2y1(x). We are left with

u′′y1 = 0, or u′′ = 0, or u(x) = c1x + c2.

Hence, y2(x) = xy1 and a general solution of the equation is

y(x) = (c1 + xc2)e−a/2x .

Page 77: Modeling and Simulation with ODE (MSE)

Short introduction to complex numbers

Complex numbers are introduced to give meaning to situationswhere the square root of a negative number has to be considered.This happens, for instance, when one considers the discriminant ofa second order polynomial equation ax2 + bx + c = 0

∆ = b2 − 4ac,

which might happen to be negative (for instance fora = b = c = 1). To solve this issue one artifically introduces a newnumber, called the imaginary identity, indicated by the letter i andcorresponding to the square root of −1:

i :=√−1 or i2 := −1

Hence√−10 =

√10√−1 =

√10i . In general, a complex number

is a number that can be expressed in the form a + bi , where a andb are real numbers and i is the imaginary unit. In this expression, ais the real part and b is the imaginary part of the complex number.

Page 78: Modeling and Simulation with ODE (MSE)

How do we operate on complex numbers?Complex numbers are actually vectors expressed in the two dimensional realspace spanned by the basis

1, i,hence they can be identified with the Euclidean plane.

Identification of the complex number a + bi with a vector on the plane

Hence, one operates on complex numbers as they were vectors according to thefollowing addition rule

(a1 + b1i) + (a2 + b2i) = (a1 + a2) + (b1 + b2)i .

Multiplication follows by applying the distributive property and rememberingthat i2 = −1

(a1 + b1i)(a2 + b2i) = a1a2 + (a1b2 + a2b1)i − b1b2.

Page 79: Modeling and Simulation with ODE (MSE)

Exponentials of complex numbers: Euler formula

We shall show that

ea+ib = ea(cos b + i sin b). (12)

If b = 0 (hence the number is real) then cos 0 = 1 and sin 0 = 0and the identity holds. If a = 0 then we have by Maclaurin series

ea+ib = e ib = 1 + (ib) +(ib)2

2!+

(ib)3

3!+

(ib)4

4!+ . . .

= 1− b2

2!+

b4

4!− · · ·+ i

(b − (b)3

3!+

(b)5

5!+ . . .

)= cos b + i sin b.

The identity (12) is called the Euler formula.

Page 80: Modeling and Simulation with ODE (MSE)

Complex representations of cos and sin

By using the Euler formula we find new ways of writing cos andsin. We note that e−it = cos(−t) + i sin(−t) = cos t − i sin t, sothat by addition and subtraction of this and Euler’s formula,

cos t =1

2(e it + e−it), sin t =

1

2i(e it − e−it).

Page 81: Modeling and Simulation with ODE (MSE)

Cases continued ...In the third case the roots are complex

λ± = −a

2± iω,

where ω2 = b − 14a2. Then the solutions

y1 = e−a/2x cos(ωx), y2 = e−a/2x sin(ωx)

turn out to be linearly independent! Hence in this case the general solution isgiven by

y(x) = e−a/2x(c1 cos(ωx) + c2 sin(ωx)).

But how these solutions are derived? From Euler formulae iξ = (cos(ξ) + i sin(ξ)) we obtain

cos ξ =1

2(e iξ + e−iξ), sin(ξ) =

1

2(e iξ − e−iξ).

Henceeλ+x = e(− a

2+iω)x = e(− a

2x)(cos(ωx) + i sin(ωx)),

eλ−x = e(− a2−iω)x = e(− a

2x)(cos(ωx)− i sin(ωx)).

Adding these functions and multiplying by 12

gives us y1, while substracting the

second from the first and multiplying by 12i

gives us y2.

Page 82: Modeling and Simulation with ODE (MSE)

Example

Solve the initial value problem

y ′′ + 0.4y ′ + 9.04y = 0, y(0) = 0, y ′(0) = 3.

Solution. General solution. The characteristic equation is λ2 + 0.4λ+ 9.04 = 0.It has the roots −0.2± 3i . Hence ω = 3, and a general solution is

y(x) = e−0.2x(A cos 3x + B sin 3x).

Particular solution. The first initial condition gives y(0) = A = 0. Theremaining expression is y = Be−0.2x sin 3x . We need the derivative (chain rule!)

y ′ = B(−0.2e−0.2x sin 3x + 3e−0.2x cos 3x).

From this and the second initial condition we obtain y ′(0) = 3B = 3. HenceB = 1. Our solution is

y = e−0.2x sin 3x .

Page 83: Modeling and Simulation with ODE (MSE)

Typical damped oscillation

The Figure shows y and the curves of e−0.2x and −e−0.2x

(dashed), between which the curve of y oscillates. Such “dampedvibrations” (with x = tbeing time) have important mechanical andelectrical applications.

Page 84: Modeling and Simulation with ODE (MSE)

Summary

Page 85: Modeling and Simulation with ODE (MSE)

ModelingLinear ODEs with constant coefficients have importantapplications in mechanics and in electrical circuits.

Now we model and solve a basic mechanical system consisting of amass on an elastic spring (a so-called “massspring system”), whichmoves up and down.

Page 86: Modeling and Simulation with ODE (MSE)

Mass-spring systems

We take an ordinary coil spring that resists extension as well ascompression. We suspend it vertically from a fixed support andattach a body at its lower end, for instance, an iron ball. We lety = 0 denote the position of the ball when the system is at rest(Fig. b). Furthermore, we choose the downward direction aspositive, thus regarding downward forces as positive and upwardforces as negative. We now let the ball move, as follows. We pullit down by an amount y > 0 (Fig. c). This causes a spring force

F = −ky Hooke’s law,

proportional to the stretch. The minus sign indicates that F1

points upward, against the displacement.

Page 87: Modeling and Simulation with ODE (MSE)

Motiong driven by the force

The motion of our massspring system is determined by Newtonssecond law

my ′′ = F or my ′′ + ky = 0.

This is a homogeneous linear ODE with constant coefficients, withgeneral solution

y(t) = A cos(ω0t) + B sin(ω0t), ω0 =

√k

m.

This motion is called a harmonic oscillation. Its frequency isf = ω0/(2π) Hertz (= cycles>sec). The frequency f is called thenatural frequency of the system.

Page 88: Modeling and Simulation with ODE (MSE)

Solutions

Page 89: Modeling and Simulation with ODE (MSE)

Damping

To our model m′′ = −ky we now add a damping force

F1 = −cy ′,

obtaining my ′′ = −ky − cy ′; thus the ODE of the damped mass-spring system is

my ′′ + cy ′ + ky = 0.

We assume this damping force to be proportional to the velocityy ′. This is generally a good approximation of friction effects forsmall velocities.

Page 90: Modeling and Simulation with ODE (MSE)

Solution

The ODE (5) is homogeneous linear and has constant coefficients.Hence we can solve it by the methods we just saw. Thecharacteristic equation is

λ2 +c

mλ+

k

mλ = 0.

By the usual formula for the roots of a quadratic equation weobtain

λ± = −α± β := − c

2m± 1

2m

√c2 − 4mk

Page 91: Modeling and Simulation with ODE (MSE)

Damping ...

It is now interesting that depending on the amount of dampingpresent whether a lot of damping, a medium amount of dampingor little damping three types of motions occur, respectively:

Page 92: Modeling and Simulation with ODE (MSE)

OverdampingIf the damping constant c is so large that c2 > 4mk , then thecorresponding general solution ofis

y(t) = c1e−(α−β)t + c2e−(α+β)t

Both exponents are negative because β2 = α2 − k/m < α2 andα, β > 0.

Page 93: Modeling and Simulation with ODE (MSE)

Critical dampingCritical damping is the border case between nonoscillatory motions(Case I) and oscillations (Case III). It occurs if the characteristicequation has a double root, that is, if c2 = 4mk , so that β = 0.Then the corresponding general solution of is

y(t) = (c1 + c2t)e−αt .

Page 94: Modeling and Simulation with ODE (MSE)

UnderdumpingCase III. Underdamping This is the most interesting case. It occursif the damping constant c is so small c2 < 4mk . Then β in is nolonger real but pure imaginary, say,

β = iω.

Hence the corresponding general solution is

y(t) = e−αt(Acosωt + Bsinωt) = Ce−αt cos(ωt − δ),

where C 2 = A2 + B2 and tan δ = B/A. This represents dampedoscillations.

Page 95: Modeling and Simulation with ODE (MSE)

Existence and uniquenessWe shall discuss the general theory of homogeneous linear ODEs

y ′′ + p(x)y ′ + q(x)y = 0, (13)

with continuous, but otherwise arbitrary, variable coefficients p andq. We are concerned with the existence and form of a generalsolution as well as its uniqueness of initial value problemsconsisting of such an ODE and two initial conditions

y(x0) = K0, y ′(x0) = K1, (14)

with given x0,K0,K1. The two main results will state that such aninitial value problem always has a solution which is unique, andthat a general solution

y = c1y1 + c2y2

includes all solutions.Notice that no such theory was needed for constant-coefficientequations because everything resulted explicitly from ourcalculations!!!

Page 96: Modeling and Simulation with ODE (MSE)

Existence and uniqueness

TheoremIf p(x) and q(x) are continuous functions on some open intervalI ⊂ R and x0 is in I , then the initial value problem consisting of(13) and (14) has a unique solution y(x) on the interval I.

No existence proof (it can be done by using the Picard-Lindelofiteration strategy). We address the uniqueness proof.

Page 97: Modeling and Simulation with ODE (MSE)

Uniqueness proofProof. Define y(x) = y1(x)− y2(x) and clearly y(x0) = 0 = y ′(x0). Set

z(x) = y(x)2 + y ′(x)2.

We have z ′ = 2yy ′ + 2y ′y ′′ and by y ′′ = −p(x)y ′ − q(x)y we obtain

z ′ = 2yy ′ − 2py ′2 − 2qyy ′. (15)

As (y ± y ′)2 = y 2 ± 2yy ′ + y ′2 ≥ 0 we have z = y 2 + y ′

2 ≥ 2|yy ′|. From (15)we obtain

z ′ ≤ z + 2|p|y ′2 + |q|z ≤ z + 2|p|z + |q|z = (1 + 2|p|+ |q|)| z :=h

z = hz

A similar estimate is obtained for −z ′ to arrive to z ′ ≤ hz , z ′ ≥ −hz . DenoteF1 = e−

Rh(x)dx and F2 = e

Rh(x)dx and

(F1z)′ = (F1z ′ + F ′1z) = F1z ′ − F1hz = F1(z ′ − hz) ≤ 0, (F2z)′ ≥ 0.

Hence F1z is nonincreasing and F2z is nondecreasing and for x ≥ x0

(F1z)(x) ≤ (F1z)(x0) = 0, (F2z)(x) ≥ (F2z)(x0) = 0.

As F1 > 0 and F2 > 0 we obtain

z ≤ 0, z ≥ 0, or z = y 2 + y ′2 ≡ 0, x ≥ x0,

hence y1(x) = y2(x) for x ≥ x0. Similar argument for x < x0.

Page 98: Modeling and Simulation with ODE (MSE)

Linear Dependence and Independence of SolutionsTwo functions y1 and y2 are called linearly independent on aninterval I where they are defined if

k1y1(x) + k2y2(x) = 0

everywhere on I implies k1 = 0 and k2 = 0. And y1 and y2 arecalled linearly dependent on I if k1y1(x) + k2y2(x) = 0 also holdsfor some constants k1, k2 not both zero.

TheoremLet the ODE have continuous coefficients p(x) and q(x) on anopen interval I . Then two solutions y1 and y2 of (13) on I arelinearly dependent on I if and only if their “Wronskian”

W (y1, y2) = y1y ′2 − y2y ′1

is 0 at some x0 in I . Furthermore, if W = 0 at an x = x0 in I , thenW = 0 on the entire I ; hence, if there is an x1 in I at which W isnot 0, then y1, y2 are linearly independent on I .

Page 99: Modeling and Simulation with ODE (MSE)

Proof of the theorem(a) Let y1 and y2 be linearly dependent on I . Then y1 = ky2 and

W (y1, y2) = y1y ′2 − y2y ′1 = ky2y ′2 − y2ky ′2 = 0.

(b) Assume now W (y1, y2) = 0 at some x = x0 and we show that y1 and y2 arelinearly dependent on I . Consider the linear system

k1y1(x0) + k2y2(x0) = 0

k1y ′1(x0) + k2y ′2(x0) = 0

in the unknown k1, k2. Multiply the first equation by y ′2 and the second by −y2

and add the resulting equations, to obtain

0 = k1W (y1(x0), y2(x0)).

Multiply the first equation by −y ′1 and the second by y1 and add the resultingequations, to obtain

0 = k2W (y1(x0), y2(x0)).

If W were not 0 at x0, we could divide by W and conclude that k1 = k2 = 0. If

W (y1(x0), y2(x0)) = 0 then there exist k1 and k2, not both zero, solving the

system. Setting y = k1y1 + k2y2, we have that y is again a solution of (13) and

y(x0) = y ′(x0) = 0. Since the solution y∗ ≡ 0 is also a solution and there is

uniqueness, we have y∗ = y ≡ 0, i.e., y1 and y2 are mutually proportional.

Page 100: Modeling and Simulation with ODE (MSE)

Proof of the theorem ...

We show the last statement of the theorem. (c) Assume that W (x0) = 0, thenby (b) y1 and y2 are linearly dependent and by (a) W ≡ 0. Hence in the caseof linear dependence it cannot happen that W (x1) 6= 0 at an x1 in I . If it doeshappen, it thus implies linear independence as claimed.

Page 101: Modeling and Simulation with ODE (MSE)

Wronskian determinant

Students familiar with second-order determinants may have noticedthat

W (y1, y2) =

∣∣∣∣ y1 y2

y ′1 y ′2

∣∣∣∣ = y1y ′2 − y2y ′1.

This determinant is called the Wronskian of two solutions y1 andy2 of (13). Note that its four entries occupy the same positions asin the linear system of the proof!

Page 102: Modeling and Simulation with ODE (MSE)

Example of application

1 .The functions y1 = cos(ωx) and y2 = sin(ωx) are solutions ofy ′′ + ω2y = 0. Their Wronskian is

W (cos(ωx), sin(ωx)) =

∣∣∣∣ cos(ωx) sin(ωx)−ω sin(ωx) ω cos(ωx)

∣∣∣∣ = ω.

The solutions are linearly independent if and only if ω 6= 0.

2. A general solution of y ′′ − 2y ′ + y = 0 on any interval isy = (c1 + c2x)ex . (Verify!). The corresponding Wronskian is not0, which shows linear independence of ex and xex on any interval.Namely,

W (ex , xex) = e2x 6= 0.

Page 103: Modeling and Simulation with ODE (MSE)

Existence of general solutions

TheoremIf p(x) and q(x) are continuous on an open interval I , then (13)has a general solution on I .

Proof. By the the existence and uniqueness theorem for initial value problems

(13) has a solution y1 satisfying y1(x0) = 1 and y ′1(x0) = 0, and another one y2

such that y2(x0) = 0 and y ′2(x0) = 1. Consequently W (y1, y2)(x0) = 1 6= 0,

hence y1 and y2 are linearly independent and y = c1y1 + c2y2 is the constructed

general solution.

Page 104: Modeling and Simulation with ODE (MSE)

Exhausting all solutions!

TheoremIf the ODE (13) has continuous coefficients p(x) and q(x) on someopen interval I , then every solution y = Y (x) on I is of the form

Y (x) = C1y1(x) + C2y2(x)

where y1, y2 is any basis of solutions of (13) on I and C1, C2 aresuitable constants.Proof. Consider now the linear system

k1y1(x0) + k2y2(x0) = Y (x0)

k1y ′1(x0) + k2y ′2(x0) = Y ′(x0)

with unknowns k1 and k2. This system has unique solutions since its

(Wronskian) determinant W (y1, y2)(x0) 6= 0 does not vanish, being y1 and y2

linearly indepedent. Let us now define y∗(x) = k1y1(x) + k2y2(x) the

corresponding solution, such that y∗(x0) = Y (x0) and y∗′(x0) = Y ′(x0). Being

y∗ also a solution with the same initial values, and the solutions unique (!) we

have Y ≡ y∗.

Page 105: Modeling and Simulation with ODE (MSE)

Nonhomogeneous second order linear equationsWe consider the theory of the solution of

y ′′ + p(x)y ′ + q(x)y = r(x), (16)

for r 6= 0. We shall see that a “general solution” of it is the sum ofa general solution of the corresponding homogeneous ODE,

y ′′ + p(x)y ′ + q(x)y = 0, (17)

and a “particular solution” of (16).

DefinitionA general solution of the nonhomogeneous ODE (16) on an openinterval I is a solution of the form

y(x) = yh(x) + yp(x);

here, yh = c1y1 + c2y2 is a general solution of the homogeneousODE (17) on I and yp is any solution of (16) on I containing noarbitrary constants. A particular solution of (16) on I is a solutionobtained by assigning specific values to c1 and c2 in yh.

Page 106: Modeling and Simulation with ODE (MSE)

Nonhomogeneous and homogeneous solutions

Theorem

(a) The sum of a particular solution yp of (16) and a solution yh

of (17) is again a particular solution of (16);

(b) The difference of two particular solutions of (16) is a solutionof (17).

Proof. (a) Let L[y ] := y ′′ + p(x)y ′ + q(x)y the differentialoperator governing the equations. This operator is linear in y .Hence, L[yp + yh] = L[yp] + L[yh] = r + 0 = r . Hence, yp + yh is aparticular solution of (16). (b) Let y1

p and y2p two particular

solutions of (16) and yh = y1p − y2

p . ThenL[yh] = L[y1

p − y2p ] = L[y1

p ]− L[y2p ] = r − r = 0. Hence yh is a

solution of (17).

Page 107: Modeling and Simulation with ODE (MSE)

Exhausting all the solutions

TheoremIf the coefficients p(x), q(x), and the function r(x) in (16) arecontinuous on some open interval I , then every solution of (16) onI is obtained by assigning suitable values to the arbitrary constantsc1 and c2 in a general solution of (16) on I .

Proof. Let y∗ be a solution of (16). Certainly, by previous resultswe know that there exist general solutions yh = c1y1 + c2y2 of (17)and there exists a particular solution yp of (16) (by a constructionwhich we will show in the following). Hence by the previoustheorem we have that Y = y∗ − yp is again a solution of thehomogeneous equation (17). As

Y (x0) = y∗(x0)− yp(x0), Y ′(x0) = y∗′(x0)− y ′p(x0),

Y is particular solution (17) obtained by assigning suitable valuesto c1, c2 in yh. Hence, y∗ = Y + yp.

Page 108: Modeling and Simulation with ODE (MSE)

Method of Undetermined Coefficients

To solve the nonhomogeneous ODE or an initial value problem for(16), we have to solve the homogeneous ODE (17) and find anysolution yp of (16) and sum them up. But, how can we find asolution yp of (16)? One method is the so-called method ofundetermined coefficients. More precisely, the method ofundetermined coefficients is suitable for linear ODEs with constantcoefficients a and b

y ′′ + ay ′ + by = r(x) (18)

when r(x) is an exponential function, a power of x , a cosine orsine, or sums or products of such functions. These functions havederivatives similar to r(x) itself. This gives the idea.

Page 109: Modeling and Simulation with ODE (MSE)

Method of Undetermined Coefficients

Choice Rules for the Method of Undetermined Coefficients

(a) Basic Rule. If r(x) in (18) is one of the functions in the first column inthe Table, choose yp in the same line and determine its undeterminedcoefficients by substituting yp and its derivatives into (18).

(b) Modification Rule. If a term in your choice for yp happens to be asolution of the homogeneous ODE corresponding to (18), multiply thisterm by x (or by x2 if this solution corresponds to a double root of thecharacteristic equation of the homogeneous ODE).

(c) Sum Rule. If r(x) is a sum of functions in the first column of the Table,choose for yp the sum of the functions in the corresponding lines of thesecond column.

Page 110: Modeling and Simulation with ODE (MSE)

Comments on the rules

The Basic Rule applies when r(x) is a single term. TheModification Rule helps in the indicated case, and to recognizesuch a case, we have to solve the homogeneous ODE first. TheSum Rule follows by noting that the sum of two solutions of (18)with r = r1 and r = r2 (and the same left side!) is a solution of(18) with r = r1 + r2. (Verify!) The method is self-correcting. Afalse choice for yp or one with too few terms will lead to acontradiction. A choice with too many terms will give a correctresult, with superfluous coefficients coming out zero.

Page 111: Modeling and Simulation with ODE (MSE)

Example: Application of the Basic Rule (a)Solve the initial value problem

y ′′ + y = 0.001x2, y(0) = 0, y ′(0) = 1.5

Solution. Step 1. General solution of the homogeneous ODE. The ODEy ′′ + y = 0 has the general solution yh = A cos x + B sin x . Step 2. Solution ypof the nonhomogeneous ODE. We first try yp = Kx2. Then y ′′p = 2K . Bysubstitution, 2K + Kx2 = 0.001x2. For this to hold for all x , the coefficient ofeach power of x (x2 and x0) must be the same on both sides; thus K = 0.001and 2K = 0, a contradiction. The second line in the Table suggests the choiceyp = K2x2 + K1x + K0. Then

y ′′p + yp = 2K2 + K2x2 + K1x + K0 = 0.001x2.

Equating the coefficients of x2, x1, x0 on both sides, we have K2 = 0.001,K1 = 0, 2K2 + K0 = 0. Hence K0 = −2K2 = −0.002. This givesyp = 0.001x2 − 0.002, and

y = yh + yp = A cos x + B sin x + 0.001x2 − 0.002.

Step 3. The solution of the initial value problem goes as usual to identify A

and B.

Page 112: Modeling and Simulation with ODE (MSE)

Example: Application of the Modification Rule (b)Solve the initial value problem

y ′′ + 3y ′ + 2.25y = −10e−1.5x , y(0) = 1, y ′(0) = 0.

Solution. Step 1. General solution of the homogeneous ODE. Thecharacteristic equation of the homogeneous ODE isλ2 + 3λ+ 2.25 = (λ+ 1.5)2 = 0. Hence the homogeneous ODE has thegeneral solution

yh = (c1 + c2x)e−1.5x . Verify it!.

Step 2. Solution yp of the nonhomogeneous ODE. The function e−1.5x on theright would normally require the choice Ce−1.5x . But we see from yh that thisfunction is a solution of the homogeneous ODE, which corresponds to a doubleroot of the characteristic equation. Hence, according to the Modification Rulewe have to multiply our choice function by x2. That is, we choose

yp = Cx2e−1.5x .

By substitution in the equation, this gives C = −5. Hence the given ODE hasthe general solution

y = yh + yp = (c1 + c2x)e−1.5x − 5x2e−1.5x .

Step 3. The solution of the initial value problem is done as usual to determine

c1 and c2 from the initial conditions.

Page 113: Modeling and Simulation with ODE (MSE)

Example: Application of the Sum Rule (c)Solve the initial value problem

y ′′+ 2y ′+ 0.75y = 2 cos x−0.25 sin x + 0.09x , y(0) = 2.78, y ′(0) = −0.43.

Solution. Step 1. General solution of the homogeneous ODE. Thecharacteristic equation of the homogeneous

λ2 + 2λ+ 0.75 = (λ+ 1/2)(λ+ 3/2) = 0

which gives the general solution yh = c1e−x/2 + c2e−3x/2. Step 2. Particularsolution of the nonhomogeneous ODE. We write yp = yp1 + yp2 and, followingthe Table, (c) and (b),

yp1 = K cos x + M sin x

andyp2 = K1x + K0.

By substitution in the equation we obtain K = 0, M = 1, and K1 = 0.12,K0 = −0.32. Hence a general solution of the ODE is

y = c1e−x/2 + c2e−3x/2 + sin x + 0.12x − 0.32.

Step 3. The solution of the initial value problem goes as usual to identify c1

and c2.

Page 114: Modeling and Simulation with ODE (MSE)

Forced oscillators and electrical circuits

Applications of these methods for the solution of the equationsgoverning forced oscillators and electrical circuits will be presentednext week in the exercises.

Page 115: Modeling and Simulation with ODE (MSE)

Solution by Variation of Parameters

The method of variation of parameters and is credited toLagrange. Lagrange’s method gives a particular solution yp of

y ′′ + p(x)y ′ + q(x)y = r(x), (19)

for r 6= 0, of the form

yp(x) = −y1

∫y2r

Wdx + y2

∫y1r

Wdx (20)

where y1, y2 form a basis of solutions of the correspondinghomogeneous ODE

y ′′ + p(x)y ′ + q(x)y = 0, (21)

and W is the Wronskian of y1, y2.

Page 116: Modeling and Simulation with ODE (MSE)

Example

Solve the nonhomogeneous ODE

y ′′ + y = sec x =1

cos x.

Solution A basis of solutions of the homogeneous ODE on any interval isy1 = cos x , y2 = sin x . This gives the Wronskian

W (y1, y2) = cos x cos x − sin x(− sin x) = 1.

From (??), choosing zero constants of integration, we get the particularsolution of the given ODE

yp = − cos x

Zsin x sec xdx + sin x inf cos x sec xdx = cos x ln | cos x |+ x sin x .

We obtain the answer

y = yh + yp = (c1 + ln | cos x |) cos x + (c2 + x) sin x .

Page 117: Modeling and Simulation with ODE (MSE)

How can one get the Lagrange’s formula?

The idea is to start from a general solution

yh(x) = c1y1(x) + c2y2(x)

of the homogeneous ODE on an open interval I and to replace theconstants (“the parameters”) c1 and c2 by functions u(x) andv(x); We shall determine u and v so that the resulting function

yp(x) = u(x)y1(x) + v(x)y2(x)

is a particular solution of the nonhomogeneous ODE. Now yp mustsatisfy (19), but we need a second condition as well to determinethe two unknowns u, v . Indeed, our calculation will show that wecan determine u and v such that yp satisfies(19) and u and vsatisfy as a second condition the equation

u′y1 + v ′y2 = 0.

Page 118: Modeling and Simulation with ODE (MSE)

ComputationBy considering the latter equation one derives

y ′p = u′y1 + v ′y2 + uy ′1 + vy ′2 = uy ′1 + vy ′2.

An additional differentiation gives

y ′′p = u′y ′1 + uy ′′1 + v ′y ′2 + vy ′′2 .

By substitution into the equation we get

u(y ′′1 + py ′1 + qy1) + v(y ′′2 + py ′2 + qy2) + u′y ′1 + v ′y ′2 = r .

Since y1, y2 are solutions of the homog. equ. we get

u′y ′1 + v ′y ′2 = r ,

which, together withu′y1 + v ′y2 = 0,

is a linear system in the unknowns u′, v ′. This sytems is solvable forW (y1, y2) 6= 0 and has the solutions

u′ = −y2r

W, v ′ =

y1r

W, or u = −

Zy2r

Wdx , v =

Zy1r

Wdx .