intro to modeling april 22 2011. part of the course: introduction to biological modeling 1.intro to...

52
Intro to modeling April 22 2011

Upload: silas-harrod

Post on 14-Dec-2015

219 views

Category:

Documents


0 download

TRANSCRIPT

Intro to modeling

April 22 2011

Part of the course:Introduction to biological modeling

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

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

Example: Heating of water

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

Initial parameter values

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

the experimental data.

Fit the experimental data with the model

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

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:

Why modeling?

• Simulate the system• Estimate parameters• Control the system

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)

What’s a model?

Types of models

• Deterministic • Non-deterministic • Probabilistic

• Discrete• Continuous

(in time)

(in variable values)

Grey box

How do we build a model?

White box:First principles

Black box:Measurements

Modeling techniques in biology

• Boolean• Bayesian• Differential Equations

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

• …

ODEs

• Rate of change

One independent variable

One or more dependent variablesOrder

True or false?

TRUE

Only valid when x is the independent variable.

Are these ODEs?

YES

Independent

Dependent; First order

YES

Independent

Dependent; Third order

How to solve ODEs?

General Solution Particular Solution

How to solve ODEs?

• Analytical or

• Numerical solution

– Euler

– ode45

Analytical solutionSolve:

Numerical solution

The basis is Taylor’s series expansion:

Taylor’s series example 1

Taylor’s series example 2

Euler’s method

Under which condition is this valid?

Euler’s method

Solution in multiple time-steps. Iterate:

Solution in one time-step:

Example

# Time steps 1 5

f(x)

What does it have to do with my ODE model?

Model

Initial value

Step

Time step

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.

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)

Model

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

From paper to MATLAB

Identify state variables, parameters, inputs.

Define equations and parameter values.

Define initial values, call functions, plot

results.

Example: an irreversible reaction

Now the language details…

20x0 = 30 0

0time = 0.1 0.2 … 1

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

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

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

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

From paper to MATLAB

Identify state variables, parameters, inputs.

Define equations and parameter values.

Define initial values, call functions, plot

results.

Break

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.

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 (;)

Hands-on Tutorial

Your turn!

I. Biological system: Irreversible reaction (15 min)

Your turn!

I. Physical system: Greenhouse temperature (30 min)

HomeworkIII. Biological system: Bioreactor

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