1 / 52

Intro to modeling

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.

pmalley
Download Presentation

Intro to modeling

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Intro to modeling April 22 2011

  2. Part of the course:Introduction to biological modeling • Intro to modeling • Intro to biological modeling (Floor) • Modeling oscillators (Rob)

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

  4. Example: Heating of water

  5. 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

  6. Initial parameter values From scientific literature. Decide which one(s) will be estimated from the experimental data.

  7. Fit the experimental data with the model

  8. 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

  9. How precise are the estimated parameters? We can look at the sum of squares surface:

  10. Why modeling? • Simulate the system • Estimate parameters • Control the system

  11. 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)

  12. What’s a model?

  13. Types of models • Deterministic • Non-deterministic • Probabilistic • Discrete • Continuous (in time) (in variable values)

  14. How do we build a model? White box: First principles Grey box Black box: Measurements

  15. Modeling techniques in biology • Boolean • Bayesian • Differential Equations • Ordinary (ODE) • Partial (PDE) • Delay (DDE) • …

  16. ODEs • Rate of change One or more dependent variables Order One independent variable

  17. True or false? TRUE Only valid when x is the independent variable.

  18. Are these ODEs? Dependent; First order YES Independent Dependent; Third order YES Independent

  19. How to solve ODEs? General Solution Particular Solution

  20. How to solve ODEs? • Analytical or • Numerical solution • Euler • ode45

  21. Analytical solution Solve:

  22. Numerical solution The basis is Taylor’s series expansion:

  23. Taylor’s series example 1

  24. Taylor’s series example 2

  25. Euler’s method Under which condition is this valid?

  26. Euler’s method Solution in one time-step: Solution in multiple time-steps. Iterate:

  27. Example

  28. What does it have to do with my ODE model? Model Step Initial value Time step

  29. 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.

  30. 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)

  31. Model Re-write in state-space form: • State variables(x): terms with derivative • Parameters(p): constants • Input(u): what‘s left

  32. From paper to MATLAB Identify state variables, parameters, inputs. Define equations and parameter values. Define initial values, call functions, plot results.

  33. Example: an irreversible reaction

  34. Now the language details…

  35. 0 0.1 0.2 … 1 time = 20 30 0 x0 =

  36. 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

  37. 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

  38. 0 0.1 0.2 … 1 t = x1 x2 x3 x = t0 t1 t2 t3 11x3 … t10

  39. 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

  40. From paper to MATLAB Identify state variables, parameters, inputs. Define equations and parameter values. Define initial values, call functions, plot results.

  41. Break

  42. 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.

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

  44. Hands-on Tutorial

  45. Your turn! I. Biological system: Irreversible reaction (15 min)

  46. Your turn! I. Physical system: Greenhouse temperature (30 min)

  47. Homework III. Biological system: Bioreactor

More Related