Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01....

39
Introduction to Simulation WS01/02 - L 02 1/39 Graham Horton Modelling with ODEs 24.10.01

Transcript of Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01....

Page 1: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 1/39 Graham Horton

Modelling with ODEs

24.10.01

Page 2: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton

Motivation and Goals

• Motivation:– Ordinary Differential Equations (ODEs) are very

important in all branches of Science and Engineering– ODEs form the basis for the simulation of almost all

continuous phenomena

• Goals:– To introduce ODEs– To give some examples of how to build simple ODE

models

Page 3: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 3/39 Graham Horton

Continuous Processes

• Continuous processes occur everywhere.• Here, we are interested in cases with discrete variables• Some examples:

– An object falling to the ground– The motion of the planets orbiting the sun– The current and voltage in an electrical circuit– The level of alcohol in my blood on January 1st– The populations of a predator and its prey (!)

• In almost all cases, the relationships between the variablesare defined by an ODE

Page 4: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 4/39 Graham Horton

Ordinary Differential Equations

• An Ordinary Differential Equation (ODE) describes the rateof change of a quantity y as a function of its current valueand the time t :

• In addition, we usually know the value of y(0):

),( tyfdtdy =

0)0( yy =

Page 5: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 5/39 Graham Horton

Initial Value Problems

• Given an ordinary differential equation ...

• ... and an initial condition ...

• ... find

),( tyfdtdy =

0)0( yy =

)(ty

Page 6: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 6/39 Graham Horton

Example for an IVP

• Differential equation and initial condition:

• Solution:

1)0(

2

=

=

y

tdtdy

1)( 2 += tty

Page 7: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 7/39 Graham Horton

Example for an IVP

• Differential equation and initial condition:

• Solution:

0)0(

)1(

=

−=

y

ydtdy λ

tety λ−−=1)(

Page 8: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 8/39 Graham Horton

Example for an IVP

• Differential equation and initial condition:

• Solution:

0)0(

)cos(

=

−= −

y

ytedtdy t

)sin()( tety t−=

Page 9: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 9/39 Graham Horton

Example for an IVP

• A system of two differential equations and initial conditions:

• Solution:

)cos()( ),sin()( ttvttu ==

1)0( ,0)0(

,

==

−==

vu

udtdvv

dtdu

Page 10: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 10/39 Graham Horton

Solving ODEs

• We were able to solve all these examples analytically

• These were therefore special cases

• Usually, there is no analytic solution for systems of ODEs

• We are forced to use numerical methods to perform the

integration

• The numerical integration of ODEs forms the most

important part of continuous simulation

• We will look at this next week

Page 11: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 11/39 Graham Horton

Balance Equations

• Most ODEs are balance equations• A balance equation basically says:

Change = Increase - Decrease

• Example: ODE for the amount of water x in a tank:

O l/s

I l/sdx/dt = I - O

Page 12: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 12/39 Graham Horton

A Falling Object

• Consider dropping an object from a certain height• We will develop a model for the object's location and speed

• Variables:– p(t) : distance fallen at time t. (Units [m])– v(t) : velocity of object at time t. (Units [m/s])

Page 13: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 13/39 Graham Horton

Effect of Gravity

• The Earth exerts a force F on the object. (Units [N])• Let the mass of the object be m. (Units [kg])

• Newton's law (F = m · a) states that Force = Mass · Acceleration

• Therefore, a = F /m

• Parameters:– a : acceleration due to gravity. (Units [m/s/s])

Page 14: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 14/39 Graham Horton

A Falling Object

• The situation at time t:

p meters

v meters per secondF Newtons

Mass m

Page 15: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 15/39 Graham Horton

The Model

• Acceleration is the rate of change of velocity: dv/dt = g = 9,81 [m/s/s]

• Velocity is the rate of change of position: dp/dt = v

• At time t =0 we define: p(0) = 0 v(0) = 0

Page 16: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 16/39 Graham Horton

Simulation Results

• Simulation results:

Page 17: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 17/39 Graham Horton

Wind Resistance

• We have assumed that the object is falling in a vacuum• Now let us consider wind resistance• The standard physical model states:

– The force due to wind resistance is proportional to thesquare of the velocity

• We obtain

dv/dt = g - a · v 2

for some constant a with units [1/m]

Page 18: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 18/39 Graham Horton

Wind Resistance

• Result for a = 0.0033 (skydiver):

Terminal velocity≈ 56 m/s

Page 19: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 19/39 Graham Horton

Population Biology

• Consider the population x of some animal species

• Assume for the moment...– No deaths– Infinite space and food supply

• The birth rate is proportional to the current population:

dx/dt = a · x

• The solution of this ODE is

x = eax

• We have exponential population growth0

5

1 0

1 5

20

25

30

0 0. 5 1 1 . 5

Page 20: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 20/39 Graham Horton

Population Biology

• Now let us add deaths to the model• The death rate is also proportional to the current population• This gives

dx/dt = a · x - b · x = (a - b) · x• If a > b, we still have exponential population growth• We can just set c = a - b to obtain dx/dt = c · x

Page 21: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 21/39 Graham Horton

The Logistic Equation

• Now assume a limited food supply• As the population increases, food per capita goes down• This leads to decreasing birth and increasing death rates• This is called crowding or competition

• One solution is to use the logistic equation

dx/dt = c · x - d · x2

• We will achieve steady state when x = c / d• This is an assumption which works well in practice

Page 22: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 22/39 Graham Horton

The Logistic Equation

• Simulated solutions for c = 0.5, 1.0 and 2.0:

Page 23: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 23/39 Graham Horton

Predator-Prey Models

• Consider an area in which hares and foxes live

• Denote the population of hares by h and of foxes by f

• Observations show:

– Foxes must eat hares in order to survive

– Hares have an unlimited supply of food

• Without foxes, hares multiply according to dh/dt = a · h

• Without hares to eat, foxes die according to df /dt = -b · f

Page 24: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 24/39 Graham Horton

Lotka-Volterra Equations

• The probability of a meeting is proportional to h · f

• The increase in foxes is d · h · f

• The rate at which hares are eaten is c · h · f

• The resulting equations are:

• These are the famous Lotka-Volterra equations

fhchadtdh ⋅⋅−⋅= fhdfb

dtdf ⋅⋅+⋅−=

Page 25: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 25/39 Graham Horton

Lotka-Volterra Equations

• Simulation results forparameters

– h (0) = 400

– f (0) = 37

– a = 0.175

– b = 0.125

– c = d = 0.001

– 0 < t < 150

Page 26: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 26/39 Graham Horton

Lotka-Volterra Equations

• State space representation: Plot h (t ) against f (t )

Page 27: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 27/39 Graham Horton

Lynxes and Hares

• From the records of the Hudson Bay Company• Number of lynx and hare skins purchased 1845-1935

Page 28: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 28/39 Graham Horton

Another Example

• Petri-dish populations of the bacteria

– Paramecium Aurelia (predator)

– Saccharomices Exiguns (prey)

Page 29: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 29/39 Graham Horton

The Gypsy Moth

• The Gypsy moth is a pest

• Its larvae eats the leavesof the larch

• This defoliates and oftenkills the tree

Page 30: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 30/39 Graham Horton

The Gypsy Moth

• Population of Gypsy moths in the Engadin 1954 - 1976:

0

50

100

150

200

250

300

350

1954 1959 1964 1969 1974

Year

Popu

latio

n

Page 31: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 31/39 Graham Horton

The Gypsy Moth

• This looks very much like half of the Lotka-Volterrasimulation result:

• Have we proved that the Gypsy moth is part of apredator-prey relationship?

0

50

100

150

200

250

300

350

1954 1959 1964 1969 1974

Year

Popu

latio

n

Page 32: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 32/39 Graham Horton

Chaos

• Chaotic behaviour is a (relatively) new discovery in ODEs• Discovered by Edward Lorenz in the early 60s• Three equations from meteorology• Discovered by accident• "Chaos" in physics means...

"Sensitive dependence oninitial conditions"

• The "Butterfly Effect" zcyxdtdz

yxbzxdtdy

xyadtdx

⋅−⋅=

−⋅+⋅−=

−⋅= )(

Page 33: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 33/39 Graham Horton

Types of Behaviour

• What can the long-term behaviour of a system look like?

• Explosion:

– One or more values becomes infinite

• Steady-state / stationary

– Nothing changes

• Periodic

– Values repeat indefinitely

• Chaotic

– Finite, non-stationary, non-periodic

Page 34: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 34/39 Graham Horton

Lorenz's Equations

• Solution in the time domain:

Page 35: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 35/39 Graham Horton

The Lorenz Attractor

• Simulation result ("Lorenz attractor"):

Page 36: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 36/39 Graham Horton

The Lorenz Attractor

• Simulation result in the x-y, x-z and y-z planes:

Page 37: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 37/39 Graham Horton

Three Species

• Now let us build a new three-species predator-prey model:– Species z preys on species x and y– There is crowding between x and y

yzxzzdtdz

yzyxyydtdy

xzxyxxdtdx

0005.0005.0

001.0001.00015.0

01.0001.0001.0

2

2

++−=

−−−=

−−−=

Page 38: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 38/39 Graham Horton

Three Species

• The three-species result in a non-periodic 3-D state space:

Page 39: Modelling with ODEsisggraham/its_01/lectures/02-ModellingODEs-1.pdfModelling with ODEs 24.10.01. Introduction to Simulation WS01/02 - L 02 2/39 Graham Horton Motivation and Goals •Motivation:

Introduction to Simulation WS01/02 - L 02 39/39 Graham Horton

The Last Slide

• An ODE is an equation of the form dy/dt = f (y,t)• Almost all continuous processes are described by ODEs• These are thus very important in simulation• There is a 2+2 SWS course "Kontinuierliche Simulation"• ODEs are usually a type of balance equation:

– Change = Increase - Decrease

• Next week:– How to solve ODEs