Top Banner
Intro to modeling April 22 2011
52

Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

Dec 14, 2015

Download

Documents

Silas Harrod
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

Intro to modeling

April 22 2011

Page 2: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

Part of the course:Introduction to biological modeling

1. Intro to modeling2. Intro to biological modeling (Floor)3. Modeling oscillators (Rob)

Page 3: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

Today’s goal: Learn how to solve ODE models in MATLAB

Page 4: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

Example: Heating of water

Page 5: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

Set the model

• dTw/dt = Rate of change of temperature of the water [°C s-1]

• Tw = Temperature of the water [°C]

• Th = Temperature of the heater [°C]

• Ta = Temperature of the air [°C]

• c1 = Heat transfer coefficient 1 [s-1]

• c2 = Heat transfer coefficent 2 [s-1]

• We will measure Tw

Page 6: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

Initial parameter values

• From scientific literature.• Decide which one(s) will be estimated from

the experimental data.

Page 7: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

Fit the experimental data with the model

Page 8: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

0 50 100 150 200 250 30010

20

30

40

50

60

70

80

inpu

t u

p = [0.00029 0.00023]

0 50 100 150 200 250 30023.5

24

24.5

25

25.5

26

26.5

27

time

out

pu

t y

and

z (

--)

0 50 100 150 200 250 30010

20

30

40

50

60

70

80

inpu

t u

p = [0.000137 -0.00102]

0 50 100 150 200 250 30023.5

24

24.5

25

25.5

26

26.5

27

time

out

pu

t y

and

z (

--)

0 50 100 150 200 250 30010

20

30

40

50

60

70

80

inpu

t u

p = [0.00015 0.0001]

0 50 100 150 200 250 30023.5

24

24.5

25

25.5

26

26.5

27

time

outp

ut y

and

z (

--) P1 = 1

P2 = 1SS = 350

P1 = 1.1P2 = 3SS = 55

P1 = 1.13P2 = 4SS = 12

Manual estimation of the parameters

Page 9: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

How precise are the estimated parameters?

2.42.5

2.62.7

2.82.9

x 10-4 -2.4

-2.35-2.3

-2.25-2.2

-2.15-2.1

-2.05-2

x 10-4

2.6

2.8

3

3.2

3.4

3.6

3.8

4

4.2

p2

sum of squares surface

p1

We can look at the sum of squares surface:

Page 10: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

Why modeling?

• Simulate the system• Estimate parameters• Control the system

Page 11: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

Menu

The math behind modeling (45 min)

Break (5 min)

A few words about programming (10 min)

Hands-on tutorial (45 min)

What’s next (5 min)

Page 12: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

What’s a model?

Page 13: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

Types of models

• Deterministic • Non-deterministic • Probabilistic

• Discrete• Continuous

(in time)

(in variable values)

Page 14: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

Grey box

How do we build a model?

White box:First principles

Black box:Measurements

Page 15: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

Modeling techniques in biology

• Boolean• Bayesian• Differential Equations

– Ordinary (ODE)– Partial (PDE)– Delay (DDE)

• …

Page 16: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

ODEs

• Rate of change

One independent variable

One or more dependent variablesOrder

Page 17: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

True or false?

TRUE

Only valid when x is the independent variable.

Page 18: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

Are these ODEs?

YES

Independent

Dependent; First order

YES

Independent

Dependent; Third order

Page 19: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

How to solve ODEs?

General Solution Particular Solution

Page 20: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

How to solve ODEs?

• Analytical or

• Numerical solution

– Euler

– ode45

Page 21: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

Analytical solutionSolve:

Page 22: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

Numerical solution

The basis is Taylor’s series expansion:

Page 23: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

Taylor’s series example 1

Page 24: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

Taylor’s series example 2

Page 25: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

Euler’s method

Under which condition is this valid?

Page 26: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

Euler’s method

Solution in multiple time-steps. Iterate:

Solution in one time-step:

Page 27: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

Example

# Time steps 1 5

f(x)

Page 28: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

What does it have to do with my ODE model?

Model

Initial value

Step

Time step

Page 29: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

ode45• ODE solver in MATLAB• Uses information from the fourth and fifth derivative• How to use it:

[t,x] = ode45(@function, time, x0, [], *)

*You can pass whatever, for example the parameters (p) and/or the inputs (u)

Mandatory. Always put in the same order.

Put it here if more info will be passed.

Page 30: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

What do we need to use ode45?

i. Modelii. Parameter(s) valuesiii. Input(s) valuesiv. Independent variable (time) values = to, tf

and Δtv. Initial values of dependant variable(s)

Page 31: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

Model

Re-write in state-space form:1.State variables(x): terms with derivative2.Parameters(p): constants3.Input(u): what‘s left

Page 32: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

From paper to MATLAB

Identify state variables, parameters, inputs.

Define equations and parameter values.

Define initial values, call functions, plot

results.

Page 33: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

Example: an irreversible reaction

Page 34: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.
Page 35: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.
Page 36: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.
Page 37: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

Now the language details…

Page 38: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

20x0 = 30 0

0time = 0.1 0.2 … 1

Page 39: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

0.5p = 0.02

Magic word: Function

20x0 = 30 0

0time = 0.1 0.2 … 1

dxdt =

3x11

t0 t1 t2

x1

x2

x3

t3 … t10

Page 40: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

20x0 = 30 0

0time = 0.1 0.2 … 1

IN

OUTdxdt =

11x3

x1 x2 x3

t0

t1

t2

t3

… t10

Summary: model function data

Row vector

Row vector

Matrix

Page 41: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

0t = 0.1 0.2 … 1

x =

11x3

x1 x2 x3

t0

t1

t2

t3

… t10

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

5

10

15

20

25

30

Page 42: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

Summary: script data

20x0 = 30 0

0time = 0.1 0.2 … 1

IN

OUTx =

11x3

x1 x2 x3

t0

t1

t2

t3

… t10

0t = 0.1 0.2 … 1

Row vector

Row vector

Matrix

Row vector

Page 43: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

From paper to MATLAB

Identify state variables, parameters, inputs.

Define equations and parameter values.

Define initial values, call functions, plot

results.

Page 44: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

Break

Page 45: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

A few words about programming

All programs run in a defined ‘vertical’ way.

MATLAB is an interpreted language.Errors can be found at any time.

Read the errors messages.Most errors are in manipulation of row/column

vectors.

Page 46: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

A few words about programming

• Shell/command line = type commands interactively

• Scripts (.m) = save commands • Functions (.m) = define a command. Give

same name to the function and the file.• Variables

– Any word/letter that stores data– They remain after the program ends

• Semicolon (;)

Page 47: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

Hands-on Tutorial

Page 48: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

Your turn!

I. Biological system: Irreversible reaction (15 min)

Page 49: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

Your turn!

I. Physical system: Greenhouse temperature (30 min)

Page 50: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

HomeworkIII. Biological system: Bioreactor

Page 51: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.

What’s next

Learn/Teach:Introduction to biological modeling (Floor)Modeling oscillators (Rob)

Reproduce modeling by Danino et al. 2010:MATLAB 7.0Team: Brendan, Floor, Rob, Dorett, Mariana, ...

May 6th presentation

Page 52: Intro to modeling April 22 2011. Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.