520 likes | 535 Views
Learn how to solve ODE models in MATLAB. Example: Heating of water. Understand the math behind modeling, different types of models, building models, solving ODEs analytically and numerically, and using the ode45 function in MATLAB. Includes hands-on tutorial.
E N D
Intro to modeling April 22 2011
Part of the course:Introduction to biological modeling • Intro to modeling • Intro to biological modeling (Floor) • Modeling oscillators (Rob)
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.
Manual estimation of the parameters P1 = 1 P2 = 1 SS = 350 P1 = 1.1 P2 = 3 SS = 55 P1 = 1.13 P2 = 4 SS = 12
How precise are the estimated parameters? 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)
Types of models • Deterministic • Non-deterministic • Probabilistic • Discrete • Continuous (in time) (in variable values)
How do we build a model? White box: First principles Grey box Black box: Measurements
Modeling techniques in biology • Boolean • Bayesian • Differential Equations • Ordinary (ODE) • Partial (PDE) • Delay (DDE) • …
ODEs • Rate of change One or more dependent variables Order One independent variable
True or false? TRUE Only valid when x is the independent variable.
Are these ODEs? Dependent; First order YES Independent Dependent; Third order YES Independent
How to solve ODEs? General Solution Particular Solution
How to solve ODEs? • Analytical or • Numerical solution • Euler • ode45
Analytical solution Solve:
Numerical solution The basis is Taylor’s series expansion:
Euler’s method Under which condition is this valid?
Euler’s method Solution in one time-step: Solution in multiple time-steps. Iterate:
What does it have to do with my ODE model? Model Step Initial value 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) Put it here if more info will be passed. Mandatory. Always put in the same order.
What do we need to use ode45? • Model • Parameter(s) values • Input(s) values • Independent variable (time) values = to, tf and Δt • Initial values of dependant variable(s)
Model Re-write in state-space form: • State variables(x): terms with derivative • Parameters(p): constants • 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.
0 0.1 0.2 … 1 time = 20 30 0 x0 =
0.5 Magic word: Function 0 0.1 0.2 … 1 time = 0.02 p = t0 t1 t2 t3 … t10 dxdt = x1 20 30 0 x0 = x2 x3 3x11
Summary: model function data Row vector IN Row vector 0 0.1 0.2 … 1 time = x1 x2 x3 dxdt = t0 20 30 0 x0 = t1 Matrix OUT t2 t3 11x3 … t10
0 0.1 0.2 … 1 t = x1 x2 x3 x = t0 t1 t2 t3 11x3 … t10
Summary: script data Row vector IN Row vector 0 0 0.1 0.1 0.2 0.2 … … 1 1 time = t = Row vector x1 x2 x3 x = t0 20 30 0 Matrix x0 = OUT t1 t2 t3 11x3 … t10
From paper to MATLAB Identify state variables, parameters, inputs. Define equations and parameter values. Define initial values, call functions, plot results.
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 (;)
Your turn! I. Biological system: Irreversible reaction (15 min)
Your turn! I. Physical system: Greenhouse temperature (30 min)
Homework III. Biological system: Bioreactor