Transcript Document

CS416 - Mathematical Modelling & Prediction

Lecturers

– Douglas Leith, Robert Shorten

Assessment

work. – By final exam. No marked lab or tutorial

Tutorials

– dates and times to be announced. Tutorials will be organised to run as each section of the course is completed.

Web

– www.hamilton.ie/cs416/ Hamilton Institute Mathematical Modelling and Prediction 1

Topic of this course: modelling for decision support

- Predictive models almost always underly decision making in high performance systems

What is mathematical modelling ?

• The development and solution of a set of mathematical equations that describe a real situation to an acceptable level of accuracy.

• Used in order to predict what would happen in a real situation Note: We are interested here in quantitative rather than purely qualitative/descriptive models.

We seek models for decision support. In this course we are not seeking “true” models, but models which are “good enough” for the task at hand.

Hamilton Institute Mathematical Modelling and Prediction 2

Modelling as an Abstraction

Example.

Consider modelling an ideal gas Volume, V Pressure, P Temperature, T Related by model, PV=T Increasing level of detail. What level of detail should we use in our model ?

Each molecule has position (x,y,z) and velocity (u,v,w) Hamilton Institute Each molecule consists of atoms. Each atom consist of other particles … Mathematical Modelling and Prediction 3

Modelling as an Abstraction

Selecting the appropriate level of abstraction/detail is a key part of modelling. Strongly application dependent and something of an “art”. Not dealt with in detail in this course, but we do note that it is linked to what we are able to observe/measure as well as to the purpose for which the model is intended.

- because when assessing a model against the real system we cannot decide between models which generate the same predicted observations Hamilton Institute Mathematical Modelling and Prediction 4

Example – A simple population model (the “logistic map”)

Let N i be the population in year i A crude model for population growth is that N i =aN i-1 When a>1, the population increases (unboundedly) each year. When a<1, the population decreases each year until it reaches zero (extinction).

This is obviously an oversimplification. We need to account for overcrowding and limited resources i.e. we expect the value of parameter a to vary with the population N.

Now have N i =a(N i-1 )N i-1 Lets assume that a(N)=  (1-N) for N in the interval [0,1] See www.hamilton.ie/cs416/logisticmap.htm for arguments in support of this choice.

Hamilton Institute Mathematical Modelling and Prediction 5

Example – A simple population model (the “logistic map”)

N i =  (1-N i-1 )N i-1 “Logistic Map” Note that this is a very much simplified model. Are these simplifications justified ? That is, how “good” is this model.

-depends on what we want to use it for.

-can compare predictions of model with observed behaviour to validate model/establish accuracy. Availability of observations places fundamental limit on quality of model.

What can we use the model for ?

The structure of the model reflects our understanding of the structure of the system -a model organises our experiences and observations We can solve the model equations to make predictions - decision support Hamilton Institute Mathematical Modelling and Prediction 6

Example – A simple population model (the “logistic map”)

We can solve the model equations to make predictions … Graphical Solution N i 1 0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0 0 Hamilton Institute 0.1

0.2

N N i i =N =  i-1 (1-N i-1 )N 0.3

0.4

0.5

N i-1 0.6

0.7

0.8

0.9

1 Mathematical Modelling and Prediction i-1 with  =2 7

Example – A simple population model (the “logistic map”)

With  =2, a stationary point exists to which all solutions in interval [0,1] are eventually attracted.

NB: “stationary point” = “equilibrium point” = “steady-state solution” This is not always the case. For example, consider when  =3.75

N i Hamilton Institute 1 0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0 0 The population never settles down to a constant value 0.1

0.2

0.3

0.4

0.5

N i-1 0.6

0.7

0.8

0.9

1 Mathematical Modelling and Prediction 8

Example: Server with buffer/queue Queue length, q. Service rate, B packets/s.

Packets arrive at times t 0 ,t 1 ,t 2 ,… Ignoring servicing of packets just now, when a packet arrives we have q(t n )=min(q(t n-1 )+1, q max ) Now, interval between two packets is t n -t n-1 . During this interval  B(t n -t n-1 )  the queue. The queue size cannot fall below zero. So, we have as our model packets are serviced i.e. removed from Q=min(q(t n-1 )+1  B(t n -t n-1 )  q(t n )=max(Q,0) , q max ) Hamilton Institute Mathematical Modelling and Prediction 9

Example: Server with buffer/queue and acknowledgement Now let’s model the behaviour of the source. Suppose we have one source and that it sends a new packet in response to the server signalling that it has finished servicing a packet. Also suppose that its time T for the packet to travel from the source to the queue.

1. Send first packet at time t 0.

2. Packet arrives at queue at time t o +T 3. Service rate is B packets/s, so at time t 4. Send second packet – time is now t 1 =t 0 o +T+1/B server signals that packet has been serviced.

+T+1/B 5. Packet arrives at queue at time t o +2T+1/B Queue now doesn’t overflow, but server is idle for time T between packets arriving. Can we do better ?

Hamilton Institute Mathematical Modelling and Prediction 10

Example: Server with buffer/queue and congestion control Additive increase/multiplicative decrease congestion control (AIMD).

Define a new variable W, the number of packets sent at each acknowledgement. Suppose also that the queue signals when it’s length exceeds a threshold, q max .

•while q

, W is reset to W/2.

Our model becomes: t n = t n-1 +1/B t n-1 +T+1/B when q(t n-1 )>0 when q(t n-1 )=0 Q=min(q(t n-1 )+  W(t n-1 )  q(t n )=max(Q,0)  B(t n -t n-1 )  , q max ) W(t n )= W(t n-1 )+1 Hamilton Institute W(t n-1 )/2 when q(t n )

Example: Server with buffer/queue and congestion control Sending rate adapts to maintain full queue (server never idle), with almost no dropped packets 10 9 8 7 6 5 4 3 2 1 0 0 20 queue size, q(t) sending rate, w(t) 40 packets dropped 60 80 120 140 160 180 200 Hamilton Institute Mathematical Modelling and Prediction 12

Example: Server with buffer/queue and congestion control What if now have a second source ? Source 1 Source 2 Would like first source to reduce its sending rate so as to allow second source to successfully send packets – dynamic resource allocation .

Fair sharing  halve its sending rate and source 2 take up the slack … source 1 should roughly Hamilton Institute Mathematical Modelling and Prediction 13

Example: Server with buffer/queue and congestion control Two sources, both using AIMD. Source 2 becomes inactive after 100s.

10 9 8 7 6 queue size, q(t) 5 2 1 4 3 0 0 20 sending rate, w sending rate, w 40 60 2 (t) 80 100 time, t 120 140 1 (t) 160 180 200 Hamilton Institute Mathematical Modelling and Prediction 14

Example: Vehicle transmission Engine torque, T H Shaft torque, T L Force, F T L =NT H , N is gearbox ratio Force exerted by wheel is  T L R , with  friction coeff, R radius of wheel Air creates drag force  v, with v the velocity of vehicle Newton’s Law: Force = mass*acceleration F=  NT H R  v=m a Noting that a=dv/dt, we have the following model for the speed of the vehicle.

m dv/dt=  NT H R  v Hamilton Institute Mathematical Modelling and Prediction 15

Example: Vehicle transmission Suppose the vehicle has two gears, N 1 and N 2 . The gear used is selected by an automatic transmission. The model is then m dv/dt=  N 1 T H R  v in gear 1  N 2 T H R  v in gear 2 + a model of the the decision making process used by the automatic transmission.

Hamilton Institute Mathematical Modelling and Prediction 16

Course Outline How do we derive a model for a system ?

How do we extract information from it (esp. how do we obtain quantitative solutions and analyse their properties) ?

- this course is structured around these questions.

• Introduce taxonomy of models model structures. . It turns out that most systems can be modelled using a fairly small set of • Study solutions, esp. numerical solutions/simulations • Can derive models from observations first principles or learn model from (or more usually by a combination of both approaches). We will not cover first principles modelling as very application specific. But will introduce machine learning approaches (including probabilistic reasoning ideas).

Hamilton Institute Mathematical Modelling and Prediction 17

A taxonomy of mathematical models

•Difference Equations •Differential Equations •Hybrid •Linear •Nonlinear •Time-invariant •Time-varying Can combine these two classifications e.g. linear differential equations Other aspects of models can also be usefully classified, but not pursued here.

Especially deterministic/stochastic models – stochastic models not covered in this course.

Hamilton Institute Mathematical Modelling and Prediction 18

A taxonomy of mathematical models

•Difference Equations •Differential Equations •Hybrid Simple Example of a Difference Equation: y(k) = a y(k-1), k=1,2,… This is equivalent to the (infinite) set of equations: y(1)=ay(0) y(2)=ay(1) y(3)=ay(2) etc.

If have observations of y(0), y(1), etc, then this defines a relation between these observations. If y(1), y(2) etc are unknown, the equations can be solved to find them.

Hamilton Institute Mathematical Modelling and Prediction 19

Difference Equations

Logistic Map is another example of a difference equation y(k)=  (1-y(k-1))y(k-1), k=1,2,… Can also include an external input u in the difference equation, e.g.

y(k) = a y(k-1)+bu(k-1), k=1,2,… This is equivalent to the (infinite) set of equations: y(1)=ay(0)+bu(0) y(2)=ay(1)+bu(1) y(3)=ay(2)+bu(2) etc.

Hamilton Institute Mathematical Modelling and Prediction 20

Difference Equations Definition: Suppose there is a defined sequence of values y(k), k=0,1,2,… (e.g. representing values observed at equally-spaced time points). A difference equation is an equation relating the value y(k) to other values y(i), i  k.

A difference equation is said to be causal when y(k) is related to values y(i) with i

i.e. y(k)=f(y(k-1),y(k-2),…,y(k-n), u(k-1),u(k-2),…,u(k-m)) where m,n are some constants.

u is an external input NB: We write y(k)=f(y(k-1),y(k-2),…) but could equally well write this as y(k+1)=f(y(k),y(k-1),…), and this is often done.

Hamilton Institute Mathematical Modelling and Prediction 21

Difference Equations A difference equation is said to be linear RHS is a linear function when the function f on the i.e y(k)=a 1 (k)y(k-1) + a 2 (k) y(k-2)+…+a n (k) y(k-n) +b 1 (k) u(k-1)+b 2 (k) u(k-2)+…+b m (k) u(k-m)) where a 1 (k), a 2 (k), …,a n (k) and b 1 (k),b vary with time), the model is said to be 2 (k), …, b m (k) are time varying parameters. When these parameters are constants (do not linear time-invariant .

•Difference Equations •Differential Equations •Hybrid + Linear Time-Invariant Difference Equations •Linear •Nonlinear •Time-invariant •Time-varying Hamilton Institute Mathematical Modelling and Prediction 22

Difference Equations A solution to a difference equation is a function y(k) that satisfies the equation. Solutions are readily derived by recursion.

e.g. for y(k)=ay(k-1) we have that y(1)=ay(0) y(2)=ay(1)=a 2 y(0) y(3)=ay(2)=a 3 y(0) etc.

i.e. a solution is y(k)=a k y(0) NB: We need to specify y(0) in order to solve this equation. This is called the initial condition for the equation. We need to specify both the equation and its initial condition in order to define a solution .

Hamilton Institute Mathematical Modelling and Prediction 23

Difference Equations – Initial Conditions More generally, y(k)=f(y(k-1),y(k-2),…,y(k-n), u(k-1),u(k-2),…,u(k-m)) We assume that the input values u(k) are defined beforehand. We must also specify y(0), y(1), …, y(n-1) in order to define a solution – in general the initial condition must specify n values.

Hamilton Institute Mathematical Modelling and Prediction 24

Difference Equations – Existence & Uniqueness of Solutions •Note that a difference equation need not have any solution.

e.g. y(k) 2 =-(1+y(k-1) 2 ) has no solution since y(k) 2 can never be negative.

•Also, even when a solution exists, it need not be unique i.e. there may exist many solutions.

e.g. sin y(k) = y(k-1) Generally, however, a model of a physical system can be expected to possess a solution which is unique.

Hamilton Institute Mathematical Modelling and Prediction 25

Difference Equations – Solutions to Linear Time-Invariant Models Recall that linear time-invariant difference equations have the form y(k)=a 1 y(k-1) + a 2 y(k-2)+…+a n y(k-n) +b 1 u(k-1)+b 2 u(k-2)+…+b m u(k-m)) Consider the simplest system y(k)=ay(k-1) “first-order system” We have that y(1)=ay(0) y(2)=ay(1)=a 2 y(0) y(3)=ay(2)=a 3 y(0) etc So the solution is y(k)=a k y(0) . Note that the solution behaves as an exponential – we can rewrite it as y(k)=exp(k loga)y(0) •For a<1, y(k)  0 as k  •For a>1, y(k)  as k  - system is said to be - system is said to be stable unstable •For a=1, solution neither grows of decays - system is said to be critically stable Hamilton Institute Mathematical Modelling and Prediction 26

Difference Equations – Solutions to Linear Time-Invariant Models Also, rate of convergence/divergence varies with the value of a 1 0.9

0.8

0.7

y(k) 0.6

0.5

0.4

0.3

0.2

a=0.75

a=0.95

0.1

0 0 Hamilton Institute a=0.25

5 10 15 20 k 25 30 35 40 Mathematical Modelling and Prediction 27

Difference Equations – Solutions to Linear Time-Invariant Models Consider now y(k)=a 1 y(k-1) + a 2 y(k-2) “second-order system” By analogy to the first-order case, try a solution of the form y(k)=  k y(0) where  is some (as yet unknown) constant. Then we need,  k i.e.  k y(0)=a 1  k-1 y(0)+a 2 - a 1  k-1 - a 2  k-2 = 0  k-2 y(0) Dividing through by  k-2 gives  2 - a 1  - a 2  = 0 i.e.  = a 1 /2  (a 1 2 +4a 2 )/2 We can work this through to derive an explicit solution. We won’t do this though. Observe that the situation where a 1 2 +4a 2 < 0 (and so  is complex valued) looks like its going to be different from when a 1 2 +4a 2 < 0 (and so  is real valued).

Hamilton Institute Mathematical Modelling and Prediction 28

Difference Equations – Solutions to Linear Time-Invariant Models Consider now y(k)=a 1 y(k-1) + a 2 y(k-2) “second-order system” 1 0.8

0.6

y(k) 0.4

0.2

a 1 (a =1,a 1 2 2 +4a =-0.2

2 =+0.2) a 1 2 +4a 2 < 0 “underdamped” a 1 2 +4a 2 > 0 “overdamped” 0 -0.2

a 1 =1,a 2 =-0.5

(a 1 2 +4a 2 =-1) -0.4

0 Hamilton Institute 2 4 6 8 10 k 12 14 16 18 20 Mathematical Modelling and Prediction 29

Difference Equations – Solutions to Linear Time-Invariant Models 1 1 0.8

a 1 =1,a 2 =-0.5

0.8

0.6

a 1 =1,a 2 =-0.75

0.6

0.4

y(k) 0.4

0.2

y(k) 0.2

0 -0.2

0 -0.4

-0.2

-0.6

-0.4

0 2 4 6 8 k 10 12 14 16 18 20 -0.8

0 5 10 15 k 20 25 30 35 1 0.8

0.6

0.4

y(k) 0.2

0 -0.2

-0.4

-0.6

-0.8

a 1 =1,a 2 =-0.95

1 0.8

0.6

0.4

y(k) 0.2

0 -0.2

-0.4

-0.6

-0.8

a 1 =1,a 2 =-1 -1 0 40 60 20 Hamilton Institute 80 100 120 140 180 200 -1 0 5 10 15 20 25 30 35 160 Mathematical Modelling and Prediction 40 45 50 30

Difference Equations – Solutions to Linear Time-Invariant Models NOTE:  = a 1 /2  (a 1 2 +4a 2 )/2 Similarly to first-order case, •For |  |<1, y(k)  0 as k  •For |  |>1, y(k)  as k  - system is - system is stable unstable •For |  |=1, solution neither grows of decays – system is critically stable When called  is real valued, system is critically damped overdamped (with special case when a 1 2 +4a 2 =0) -solution to system is the sum of pure exponentials When  is complex valued, system is underdamped -solution to system is oscillatory, with envelope that decays exponentially for stable systems, grows exponentially for unstable systems.

Hamilton Institute Mathematical Modelling and Prediction 31

Difference Equations – Equilibria of Linear Time-Invariant Models For stable systems , the solution converges to a final value as k  . This is called the equilibrium called stationary point or point of the system (also steady-state value).

Linear time-invariant difference equation: y(k)=a 1 y(k-1) + a 2 y(k-2)+…+a n y(k-n) +b 1 u(k-1)+b 2 u(k-2)+…+b m u(k-m)) When the input u is zero, at an equilibrium point y  have: y  =a 1 y  +a 2 y  +…+a n y  i.e. y  =0 we must When input is non-zero, the equilibrium point will depend on the input. E.g. say u(k)=u, a constant value. Then y  =a 1 y  +a 2 y  +…+a n y  +b 1 u+b 2 u+…+b m u i.e. y  = u (b 1 +b 2 +…+b m )/(a 1 +a 2 +…+a n ) Hamilton Institute Mathematical Modelling and Prediction 32

Difference Equations – Solutions to Nonlinear Models For linear difference equations, in qualitative terms only a small number of types of solution can exist (stable, unstable, overdamped, underdamped etc).

For nonlinear difference equations, the situation is much richer.

e.g. depending on the value of the parameter  , the Logistic Map y(k)=  (1-y(k-1))y(k-1) not only has solutions which are stable and unstable but also has steady oscillatory solutions solutions (complex oscillations) and - these are both types of chaotic equilibrium solution which do not have just a single value y  .

Hamilton Institute Mathematical Modelling and Prediction 33

y(k) Difference Equations – y(k)=  (1-y(k-1))y(k-1) 0.5

0.45

0.4

 =1 “stable” 1 0.9

 =3.5 “steady oscillation/limit cycle” 0.8

0.35

0.3

y(k) 0.7

0.25

0.6

0.2

0.7

0.6

y(k) 0.5

0.4

0.3

0.2

0.1

0 0 0.15

0.1

0.05

0 0 1 0.9

0.8

10 20 30 60 70 80 90 100 0.5

0.4

0.3

0 40 k 50 10  =3.9

“complex oscillation” 20 30 40 60 70 80 90 k 50 100 0 -1000 -2000 -3000 -4000 y(k) -5000 -6000 -7000 -8000 -9000 -10000 0 10 10 20 20 30 40 50 k 60 70 80 30  =4.1

“unstable” 40 60 70 50 k 80 90 90 100 100 Hamilton Institute Mathematical Modelling and Prediction 34

So far have concentrated on difference equations. But physical systems are usually described by differential equations.

Recall Newton’s law: F(t) = m a(t) Force = mass x acceleration We obtain velocity by integrating the acceleration i.e.  o t z Conversely, acceleration is obtained by differentiating velocity i.e. ( )  dt Hamilton Institute Mathematical Modelling and Prediction 35

f(x) 0 x o x The derivative df/dx of a curve f(x) at a point x o to the curve at x o .

is just the tangent Higher-order derivatives are obtained recursively dx 2  d dt F dy H I K d n dx  n 1 y  1  d dt F n d y H n I K Hamilton Institute Mathematical Modelling and Prediction 36

f(x) 0 x o x z

f x

area under the curve between 0 and x o .

o is just the Hamilton Institute Mathematical Modelling and Prediction 37

Differential Equations A simple example is dy(t)/dt = ay(t) Verify that the solution to this differential equation is: y(t)=exp(at) y(0) -compare with the first-order difference equation y(k)=ay(k-1) which has solution y(k)=a k y(0)=exp(k log(a)) y(0).

Hamilton Institute Mathematical Modelling and Prediction 38

Differential Equations Another example:

dt

2 

sin y dy dt

cos t

Can also include an external input u in the differential equation, e.g.

dy(t)/dt = a y(t)+bu(t) Definition: Suppose there is a function y(t) defined on an interval [t o ,t 1 ]. A differential equation is an equation relating the value y(t) to some of its derivatives.

In general, a differential equation is of the form: dt n  G , dy dt , dt 2 ,  , d dt n n  1 y  1 du dt , dt 2 ,  , dt m I K Hamilton Institute Mathematical Modelling and Prediction 39

Differential Equations A differential equation is said to be linear RHS is a linear function n i.e

dt

n  

a

2

dt

 when the function f on the

dt

2

a

n

d

n  1

y t dt

n  1

+ b

1 

b

2

dt b

m  1

dt

m where a 1 (t), a 2 (t), …,a n (t) and b time), the model is said to be 1 (t),b 2 (t), …, b m (t) are time-varying parameters. When these parameters are constants (do not vary with linear time-invariant .

•Difference Equations •Differential Equations •Hybrid •Linear •Nonlinear •Time-invariant •Time-varying Hamilton Institute + Linear Time-Invariant Differential Equations Mathematical Modelling and Prediction 40

Differential Equations A solution to a differential equation is a function y(t) that satisfies the equation. E.g. the solution to dy(t)/dt = ay(t) is y(t)=exp(at) y(0) Similarly to difference equations, we need to specify the initial condition both the equation and its initial condition in order to define a solution .

y(0) in order to solve this equation i.e. we need to specify E.g. the differential equation: 

0 dt

2 has general solution of the form y(t)=A+Bt where A,B are some constants. To find the values of these constants we use y(0)=A, dy(0)/dt=B Hamilton Institute Mathematical Modelling and Prediction 41

Differential Equations Also, similarly to the difference equation y(k)=ay(k-1), the solution to dy(t)/dt = ay(t) is y(t)=exp(at) y(0) i.e.

•For a<0, y(t)  0 as t  •For a>0, y(t)  as t  - system is said to be - system is said to be stable unstable •For a=0, y(t)=y(0) - system is said to be critically stable Similarly to the second-order linear difference equation, the second order linear differential equation 2

d y dt

2  

a

2

dy dt

exhibits overdamped, underdamped and critically damped responses depending on the values of a 1 and a 2 .

Hamilton Institute Mathematical Modelling and Prediction 42

Second-order Linear Differential Equation

dt

2  

a

2

dy dt

0.7

0.6

0.5

0.4

y(t) 0.3

0.2

0.1

0 -0.1

a 1 =-0.7,a 2 =-0.75

0.8

0.6

0.4

y(t) 0.2

1 0 -0.2

-0.4

a 1 =-0.29,a 2 =-0.93

-0.2

0 2 4 6 8 time, t 12 14 16 -0.6

0 5 10 30 35 1 0.8

0.6

0.4

y(t) 0.2

0 -0.2

-0.4

-0.6

-0.8

15 20 25 time, t -1 0 50 a 1 =-0.05,a Hamilton Institute 100 150 2 =-1 1 0.8

0.6

0.4

y(t) 0.2

0 -0.2

-0.4

-0.6

-0.8

a 1 =0,a 2 =-1 200 250 -1 0 10 15 20 25 30 5 Mathematical Modelling and Prediction 35 40 40 43

Compare with 2 nd order difference eqn y(k)=a 1 y(k-1) + a 2 y(k-2) 1 1 0.8

a 1 =1,a 2 =-0.5

0.8

0.6

a 1 =1,a 2 =-0.75

0.6

0.4

y(k) 0.4

0.2

y(k) 0.2

0 -0.2

0 -0.4

-0.2

-0.6

-0.4

0 2 4 6 8 k 10 12 14 16 18 20 -0.8

0 5 10 15 k 20 25 30 35 1 0.8

0.6

0.4

y(k) 0.2

0 -0.2

-0.4

-0.6

-0.8

a 1 =1,a 2 =-0.95

1 0.8

0.6

0.4

y(k) 0.2

0 -0.2

-0.4

-0.6

-0.8

a 1 =1,a 2 =-1 -1 0 40 60 20 Hamilton Institute 80 100 120 140 180 200 -1 0 5 10 15 20 25 30 35 160 Mathematical Modelling and Prediction 40 45 50 44

Linear difference and differential equations are closely related.

NOTE: This is generally only true for exhibits chaos).

linear equations. Nonlinear equations seem to be fundamentally different, e.g. chaos can exist in first-order difference equations (such as the logistic map), but not in first-order differential equations (we need to go to at least third order to find a differential equation which Recall definition of derivative:   

dt

h

lim

 0

h ) h

This suggests that a derivative might be approximated by the finite difference:  

h ) dt h

 Euler approximation . We expect that as h is made smaller, the accuracy of the approximation improves.

Hamilton Institute Mathematical Modelling and Prediction 45

Consider the first-order linear differential equation: 

dt

and now replace the exact derivative by its Euler approximation. We have 

h h )

  i.e. y(t+h)=y(t)+ha 1 (t)y(t) Considering the time instants kh, k=0,1,2,… we have y((k+1)h)=y(kh)+ha 1 (kh)y(kh) which we can write as y(k+1)=y(k)+ha 1 (k)y(k) We have converted our first-order differential equation into a first order difference equation. This conversion is only approximate, but the approximation becomes arbitrarily accurate as h is made small.

Hamilton Institute Mathematical Modelling and Prediction 46

More generally, a linear differential equation: 

dt

n 

a

2

dt

dt

2

a

n

d

n  1

y t dt

n  1

+ b

1 

b

2

dt b

m  1

dt

m can be approximated by a linear difference equation of the same order.

Impulse Response 0.7

Example 0.6

0.5

0.4

dt

2

( )

  

.

(

dt 0

2 )

0.3

0.2

0.1

0 -0.1

-0.2

0 Hamilton Institute 5 10 15 20 25 Time (sec) Mathematical Modelling and Prediction 47

Example – car braking (ABS) Hamilton Institute Mathematical Modelling and Prediction 48

Example – car braking (ABS) Inertia of car: m dv/dt = -F x Inertia of wheel: J dw/dt = rF x – T b m mass of car V velocity of car J rotational inertia of wheel w rotational velocity of wheel r radius of wheel F x tyre friction force T b braking torque 1.4

 (  ) 1.2

1 Tyre friction force F x model 0.8

F x = F z  (  )  (  ) = 1.28(1-e -24  ) – 0.52   = (v-wr)/v “wheel slip” F z is vertical force (weight) of car Hamilton Institute 0.6

0.4

0.2

0 0 0.1

0.2

0.3

0.4

 0.5

0.6

0.7

Mathematical Modelling and Prediction 0.8

0.9

1 49

Hybrid Systems •Difference Equations •Differential Equations •Hybrid What are hybrid systems ? Mixture of discrete event systems and differential/difference equations.

Discrete event systems (automata) + Differential/ Difference Equations = Logic, software, hardware, switches; Collisions; Communication networks; Physical processes Etc.

Hybrid system Hamilton Institute Mathematical Modelling and Prediction 50

Example: Server with congestion control (differential equation version of scheme discussed in lecture one).

 is just ,  another way of writing dq/dt, dr/dt Hamilton Institute Mathematical Modelling and Prediction 51

Hybrid Systems Example – Bouncing ball Consider the vertical motion of a ball in a gravitational field with uniform acceleration g. Let x 1 be the height of the ball and x 2 its velocity. Then when x 1  0 we have dx 1 /dt=x 2 dx 2 /dt=-g just another way of writing dx 1  , /dt, dx  2 /dt Bouncing ball equations “Switched differential equation” Hamilton Institute Height vs time Mathematical Modelling and Prediction 52

Hybrid Systems - Solutions of Hybrid Equations We obtain the solution to a switched equation by piecing together the solutions obtained in each mode. The piecing together is done such that the x 1 , x 2 are continuous.

Hamilton Institute Mathematical Modelling and Prediction 53

Hybrid Systems - Solutions of Hybrid Equations What can go wrong ?

1. Problems in continuous evolution •Existence •Uniqueness 2. Problems in the hybrid execution •Chattering •Zeno Hamilton Institute Mathematical Modelling and Prediction 54

Hybrid Systems - Solutions of Hybrid Equations: Chattering Hamilton Institute Mathematical Modelling and Prediction 55

Hybrid Systems - Solutions of Hybrid Equations: Chattering Note that chattering solutions do not always completely “stop”. Often, the system continues to evolve in a so-called sliding mode .

-1 w  0 dw/dt= 1 w<0 dv/dt=-v v Solution “slides” along the surface w=0 0 w Hamilton Institute Mathematical Modelling and Prediction 56

Hybrid Systems - Solutions of Hybrid Equations: Zeno Execution Hybrid Systems Zeno execution =  is infinite, but execution does not extend to t=+  Hamilton Institute Mathematical Modelling and Prediction 57

Hybrid Systems - Solutions of Hybrid Equations: Similarly to difference and differential equations, hybrid systems can be classified as being stable , unstable etc.

Various definitions of stability are used, but all involve the solution decaying to an equilibrium solution as time  .

The presence of switching in hybrid systems can sometimes lead to unexpected behaviour….

Hamilton Institute Mathematical Modelling and Prediction 58

Hybrid Systems – Instability arising from switching An example of decision-making and instability a Hamilton Institute c b “Car in the desert scenario” Mathematical Modelling and Prediction 59

Hybrid Systems - Instability arising from switching System 1: Stable linear time-invariant differential equation: dx 1 /dt=dx 2 /dt dx 2 /dt=-2dx 1 /dt-0.2dx

2 /dt 1 +b 1 c T 1 6 4 -2 -4 2 0 -6 -6 Hamilton Institute -4 -2 0 X 1 2 4 6 Mathematical Modelling and Prediction 60

Hybrid Systems - Instability arising from switching System 2: Stable linear time-invariant differential equation: dx 1 /dt=2dx 2 /dt dx 2 /dt=-3dx 1 /dt-0.2dx

2 /dt 2 +b 2 c T 2 6 -2 -4 -6 -6 4 2 0 -4 Hamilton Institute -2 0 X 1 2 4 6 Mathematical Modelling and Prediction 61

Hybrid Systems - Instability arising from switching Switching between system 1 and system 2.

6 4 2 0 -2 -4 -6 -6 Hamilton Institute -4 -2 0 X 1 x 0 * 2 4 6 Mathematical Modelling and Prediction 62

Course Outline • Introduce taxonomy of models. It turns out that most systems can be modelled using a fairly small set of model structures. • Study solutions, esp. numerical solutions/simulations • Can derive models from observations first principles or learn model from (or more usually by a combination of both approaches). We will not cover first principles modelling as very application specific. But will introduce machine learning approaches (including probabilistic reasoning ideas).

Hamilton Institute Mathematical Modelling and Prediction 63