BM LabI Lecture Notes

Embed Size (px)

Citation preview

  • 8/13/2019 BM LabI Lecture Notes

    1/5

    What can we do with this software?Berkeley Madonna is program to numerically solve systems of ordinary differential

    equations (ODEs) and difference equations.NOW, OPEN AN EXAMPLE BERKELEY MADONNA FILE..........

    1 Windows in the Berkeley Madonna (BM)

    It uses various kinds of windows to represent your model including equation, flowchart,parameter, graph, datasets, sliders and notes windows.

    1.1 The Equation Window

    The equation window is used to edit model equations. The equation window canbe displayed by choosing Model Equations.

    Changes made to your equations do not take effect until your model has beenrecompiled. When it recompiles, all runs in memory are discarded.

    If BM finds an error when compiling your equations, an error message is displayedand the suspect text will be selected in the equation window.

    1.2 Parameter Window

    The parameter window allows you to change the parameters in the model aswell as the integration method (can also be changed by Compute Integra-tion Method) without recompiling your model. To access it from the menu:

    Parameters Parameter Window. BM displays an asterisk (*) next to the name of each parameter that has been

    changed from its default value. You can return them to the original value usingReset.

    BM defines a set of built-in system parameters that exist in every model suchas STARTTIME, STOPTIME, DT, etc.

    1

    Introduction to Berkeley Madonna: Lab

  • 8/13/2019 BM LabI Lecture Notes

    2/5

    1.3 Graph Window

    When the model is run for the first time BM automatically creates a graphwindow. The title indicates the run number and the variables plotted on the Xand Y axes.

    If Overlay Plots is off, each subsequent run will replace the data from theprevious run. If you turn it on, subsequent runs will be added to the graphwindow.

    You can always lock a graph by selecting the Lockbutton from the graph icons.With this feature the contents of a graph is preserve while you can still run yourmodel for new graphs.

    ChoosingGraph Choose Variablescan help you to specify which variablesare plotted in the Y axis. By default, BM plots TIME on the X axis, but youcan always change this in theChoose Variables dialog.

    You can also create multiple graph windows by first opening an empty graphwindow and adding variables (use Graph menu for this).

    1.4 Using Graph Buttons

    The buttons in the top-left corner of the graph window perform different func-tions.

    For example theRun button, runs the model once. Same as choosing Run fromtheModelorCompute menus.

    You can print, save a graph or table by activating its window and choosingappropriate action from the File menu.

    2 Running Models

    2.1 Single Run

    The simplest way to run your model is to click the Run button in the equation,parameter, or graph windows. Or, choose it fromModelorCompute menu.

    2.2 Sliders

    To create sliders: Parameters Define Sliders. In the dialog, select a parameterand add it to the sliders list by clicking Add. Select linear or logarithmic scaling andadjust the minimum, maximum, and increment or multiplier for the slider.

    2

  • 8/13/2019 BM LabI Lecture Notes

    3/5

    2.3 Batch Runs

    B-M can automatically run your model multiple times while optionally varying a spec-ified parameter. For this choose Parameters Batch Runs.

    Specify the parameter you want to vary.

    Specify the number of runs, betwenn 2 and 1000.

    Specify the parameter to take for first and last run (Initial Value and FinalValue).

    Identify the series type. How the parameter should be varied, according to aarithmetic or geometric series?

    How B-M should process the runs: keep runs separate (all runs), compute mean(single run) or compute mean +

    SD (mean, mean-SD and mean+SD).

    2.4 Parameter Plot

    The Parameter Plot feature enables you to plot the result of each run as a singledata point over a range of parameter values.To perform a parameter plot, choose Pa-rameters Parameter Plot. The independent variable in a parameter plot is theparameter in your model rather than TIME, this is a parameter plot graph window.

    2.5 Floating-Point Exceptions

    If you get a floating-point exception when running your model, it means some numericaloperation resulted in an error. Exceptions include division by zero, numerical overflow,taking the square root of a negative number, etc.

    3 Equation Syntax

    To display a summary of B-M equation syntax, choose HelpEquation Help.

    3.1 Basic Syntax

    B-M models consist of a list of equations. Most equations are of the form:

    variable=expression

    Variables names consit of one or more characters. You may use letters (A-Z), digits(0-9), and underscore ( ) in variable names. However variable names must not beginwith a digit. It can be anything as long as it does not clash with any B-M built-infunction (see list at the end). Comparison between variable names are case-insensitive.

    3

  • 8/13/2019 BM LabI Lecture Notes

    4/5

    For example, the names Mtbi, MTBI, and mtbi all refer to the same variable.

    Expressions use standard infix notation. That is, arithmetic and relational opera-tors are placed between their two operands:

    result = a + b * cresult = (a + b) * c

    You can place comments anywhere in the equations by enclosing them in curlybrackets. For example:

    {This is a sine wave}result = a * SIN(x)

    B-M also recognizes single-line comments beginning with the semicolon character. Forexample:

    a = ... ; define a

    3.2 Differential Equations

    Equation like shown above simply assign the value of the expression on the right-handside to the variable on the left-hand side. Such equations are referred as formulas.

    Ordinary differential equations (known as reservoirs) are defined by two equa-

    tions: an initializer equation and an integrator equation. The initializer equationdetermines the initial value of the reservoir. The integrator equation determines howmuch the reservoirs value increases or decreases during each time step (also known asthe inflow or out flow).

    Form of initializer syntax; each initializes reservoir R to an initial value denoted by...:

    R(STARTTIME) = ...INIT R = ...

    INIT (R) =...

    The following three forms of integrator syntax are also functionally identical; eachdefines a net flow into the reservoir R denoted by ...:

    d / dt (R) = ...R = ...

    FLOW R = ...

    4

  • 8/13/2019 BM LabI Lecture Notes

    5/5

    4 Applications

    BM can be used for Curve Fitting and estimating model parameters. The Sensi-tivityfeature computes the sensitivity of variables in your model to changes in one ormore parameters.

    Exercises

    Exercise 1: A basic SI Rmodel is give by:

    dS

    dt = N SI

    N S, (1)dI

    dt =

    SI

    N (+)I, (2)

    dR

    dt = IR, (3)

    whereN=S+I+ R is the total population of the system.

    1. Run the model with the parameters = 0.01, = 0.4 and = 0.3 and initialconditions S0 = 999, I0 = 1 and R0 = 0. Change the Scale and Labels so you

    can be familiar with them.

    2. Change the value of the parameters using the Parameter Window and orDefine Sliders. Use 0<