SlideShare una empresa de Scribd logo
1 de 19
Descargar para leer sin conexión
www.openeering.com
powered by
MODELING IN SCILAB: PAY ATTENTION TO THE RIGHT
APPROACH – PART 2
In this tutorial we show how to model a physical system described by ODE using
Xcos environment. The same model solution is also described in Scilab and Xcos
+ Modelica in two other tutorials.
Level
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
LHY Tutorial Xcos www.openeering.com page 2/19
Step 1: The purpose of this tutorial
In Scilab there are three different approaches (see figure) for modeling
a physical system which is described by Ordinary Differential Equations
(ODE).
For showing all these capabilities we selected a common physical
system, the LHY model for drug abuse. This model is used in our
tutorials as a common problem to show the main features of each
strategy. We are going to recurrently refer to this problem to allow the
reader to better focus on the Scilab approach rather than on mathematical
details.
In this second tutorial we show, step by step, how the LHY model problem
can be implemented in the Xcos environment. The sample code can be
downloaded from the Openeering web site.
1 Standard Scilab
Programming
2 Xcos Programming
3 Xcos + Modelica
Step 2: Model description
The considered model is the LHY model used in the study of drug abuse.
This model is a continuous-time dynamical system of drug demand for two
different classes of users: light users (denoted by ) and heavy users
(denoted by ) which are functions of time . There is another state in
the model that represents the decaying memory of heavy users in the
years (denoted by ) that acts as a deterrent for new light users. In
other words the increase of the deterrent power of memory of drug abuse
reduces the contagious aspect of initiation. This approach presents a
positive feedback which corresponds to the fact that light users promote
initiation of new users and, moreover, it presents a negative feedback
which corresponds to the fact that heavy users have a negative impact on
initiation. Light users become heavy users at the rate of escalation
and leave this state at the rate of desistance . The heavy users leave
this state at the rate of desistance .
LHY Tutorial Xcos www.openeering.com page 3/19
Step 3: Mathematical model
The mathematical model is a system of ODE (Ordinary Differential
Equation) in the unknowns:
 , number of light users;
 , number of heavy users;
 , decaying of heavy user years.
The initiation function contains a “spontaneous” initiation and a
memory effect modeled with a negative exponential as a function of the
memory of year of drug abuse relative to the number of current light users.
The problem is completed with the specification of the initial conditions
at the time .
The LHY equations system (omitting time variable for sake of simplicity) is
{
̇
̇
̇
where the initiation function is
{ }
The LHY initial conditions are
{
LHY Tutorial Xcos www.openeering.com page 4/19
Step 4: Problem data
(Model data)
: the annual rate at which light users quit
: the annual rate at which light users escalate to heavy use
: the annual rate at which heavy users quit
: the forgetting rate
(Initiation function)
: the number of innovators per year
: the annual rate at which light users attract non-users
: the constant which measures the deterrent effect of heavy use
: the maximum rate of generation for initiation
(Initial conditions)
: the initial simulation time;
: Light users at the initial time;
: Heavy users at the initial time;
: Decaying heavy users at the initial time.
Model data
Initiation function
Initial conditions
LHY Tutorial Xcos www.openeering.com page 5/19
Step 5: Xcos programming – introduction
Xcos is a free graphical editor and simulator based on Scilab that helps
people to model physical systems (electrical, mechanical, automotive,
hydraulics, …) using a graphical user interface based on a block diagram
approach. It includes explicit and implicit dynamical systems and both
continuous and discrete sub-systems.
This toolbox is particularly useful in control theory, digital and signal
processing and model-based design for multidomain simulation, especially
when continuous time and discrete time components are interconnected.
As an example of a Xcos diagram, we show on the right a Xcos model of
a RLC electric circuit with its graphical output. The first output is relative to
the voltage across the capacitor element, while the second one is relative
to the current through the voltage generator.
LHY Tutorial Xcos www.openeering.com page 6/19
Step 6: Xcos programming – getting started
Xcos environment can be started from Scilab Console typing
--> xcos
or clicking on the button in the Scilab menu bar.
The command starts two windows:
 the palette browser that contains all Xcos available blocks
grouped by categories;
 an editor window where the user can drag blocks from the
palette browser for composing new schemes.
All Xcos files end with extension “.zcos”. In previous versions of Scilab all
Xcos files end with extension “.xcos”.
LHY Tutorial Xcos www.openeering.com page 7/19
Step 7: Xcos programming – block types
In Xcos the main object is a block that can be used in different models
and projects.
A Xcos block is an element characterized by the following features:
input/output ports; input/output activations ports; continuous/discrete time
states; …
Xcos blocks contain several type of links:
 Regular links that transmit signals through the blocks ports
(black triangle);
 Activation links that transmit activation timing information
through the block ports (red triangle);
 Implicit links, see tutorial Xcos + Modelica (black square).
The user should connect only ports of the same type.
Block configuration can be specified from the input mask by double-
clicking on the block.
Step 8: Roadmap
In this tutorial we describe how to construct the LHY model and simulate it
in Xcos. We :
 provide a description of all the basic blocks used for the LHY
model;
 provide a description of the simulation menu;
 provide a description of how to edit a model;
 construct the LHY scheme;
 test the program and visualize the results.
Descriptions Steps
Basic blocks 9-16
Simulation menu 17-19
Editing models 20-22
Scheme construction 23-27
Test and visualize 28
LHY Tutorial Xcos www.openeering.com page 8/19
Step 9:The integral block
Palette: Continuous time systems / INTEGRAL_m
Purpose: The output of the block y(t) is the integral of the input u(t)
at the current time step t .
In our simulation we use this block to recover the variable L(t) starting
from its derivative L’(t). The initial condition can be specified in the
input mask.
Hint: Numerically it is always more robust using the integral block instead
of the derivative block.
The integral block
Step 10: The sum block
Palette: Math operations / BIGSOM_f
Purpose: The output of the block y(t) is the sum with sign of the input
signals. The sign of the sum can be specified from the input mask with
“+1” for “+” and “-1” for “-”.
The sum block
Step 11: The gain block
Palette: Math operations / GAINBLK_f
Purpose: The output of the block y(t) is the input signal u(t)
multiplied by the gain factor. The value of the gain constant can be
specified from the input mask.
The gain block
LHY Tutorial Xcos www.openeering.com page 9/19
Step 12: The expression block
Palette: User defined functions / EXPRESSION
Purpose: The output of the block y is a mathematical combination of
the input signals u1,u2,…,uN (max 8). The name, u, followed by a
number, is mandatory. More precisely, u1 represents the first input port
signal, u2 represents the second input port signal, and so on.
Note that constants that appear in the expression must first be defined in
the “context menu” before their use.
The expression block
Step 13: The clock block
Palette: Sources / CLOCK_c
Purpose: This block generates a regular sequence of time events with a
specified period and starting at a given initialization time. We use this
block to activate the scope block (see next step) with the desired
frequency.
The clock block
Step 14: The scope block
Palette: Sinks / CSCOPE
Purpose: This block is used to display the input signal (also vector of
signals) with respect to the simulation time. For a better visualization it
may be necessary to specify the scope parameters like ymin, ymax
values.
The scope block
LHY Tutorial Xcos www.openeering.com page 10/19
Step 15: The multiplexer block
Palette: Signal routing / MUX
Purpose: This block merges the input signals (maximum 8) into a unique
vector output signal. We use this block for plotting more signals in the
same windows. The number of input ports can be specified from the input
mask.
The multiplexer block
Step 16: The annotation block
Palette: Annotations palette / TEXT_f
Purpose: This block permits to add comments to the scheme. Comments
can also be in LaTex coding. This block can be also called by a double
click of the mouse on the scheme.
Examples of LaTex code are $L$ for generating L and $dot L$ for
generating L’(t).
The annotation block
Step 17: The simulation starting time
Each Xcos simulation starts from the initial time 0 and ends at a
specified final time.
The ending simulation time should be specified in the
"Simulation/Setup" menu in the "Final integration time"
field.
Simulation starting time is 0 !
LHY Tutorial Xcos www.openeering.com page 11/19
Step 18: Set simulation parameters
The simulation parameters such as the “final integration time” and solver
tolerances can be specified from the “set parameters” dialog in the
"Simulation/Setup" menu.
Step 19: Set Context
The model constants used in the block definitions can be entered in the
“simulation set context”. This menu is available from the
"Simulation/Set Context" menu.
In our simulation we set here all the model constants and the initial
conditions, such that it is easier to change the model value for a new
simulation since all the constants are available in an unique place.
LHY Tutorial Xcos www.openeering.com page 12/19
Step 20: Editing the model : Align blocks
Here we report some hints to improve the visual quality of the connections
between blocks. The first step is to drag some elements in the diagram
and align them.
To make a selection:
 Left-click where you want to start your selection;
 Hold down your left mouse button and drag the mouse until you
have highlighted the area you want;
or
 Left-click of the mouse over the element you want;
 Ctrl + Left-click on elements that you want to select;
To align elements:
 Right-click of the mouse and select: Format -> Align Blocks
-> Center.
(before)
(after)
LHY Tutorial Xcos www.openeering.com page 13/19
Step 21: Editing the model : intermediate points
You can link elements specifying the path using a mouse click on
intermediate points.
Starting configuration
Intermediate path
Final path
LHY Tutorial Xcos www.openeering.com page 14/19
Step 22: Editing the model
The same if you want to link elements to an already existing path (start
from the element port and draw the path you want). Click with the mouse
at the right position although the visualization is not correct.
Starting configuration
Intermediate path
Final path
LHY Tutorial Xcos www.openeering.com page 15/19
Step 23: Make the LHY scheme
Set the “Final integration time” to 50 in the "Simulation/Setup" menu;
In our simulation we modify the value of the “Final integration time” to 50
because the initial time in Xcos is 0, which corresponds to the year 1970
of our model. This means that 50 corresponds to the year 2020 of our
model.
Step 24: Make the LHY scheme
Set the model constants in the "Simulation/Set Context" menu.;
tau = 5e4; // Number of innovators per year
(initiation)
s = 0.61; // Annual rate at which light users
attract non-users (initiation)
q = 3.443; // Constant which measures the deterrent
effect of heavy users (initiation)
smax = 0.1; // Upper bound for s effective
(initiation)
a = 0.163; // Annual rate at which light users quit
b = 0.024; // Annual rate at which light users
escalate to heavy use
g = 0.062; // Annual rate at which heavy users quit
delta = 0.291; // Forgetting rate
// Initial conditions
Tbegin = 1970; // Initial time
Tend = 2020; // Final time
Tstep = 0.5; // Time step
L0 = 1.4e6; // Light users at the initial time
H0 = 0.13e6; // Heavy users at the initial time
Y0 = 0.11e6; // Decaying heavy user at the initial
time
LHY Tutorial Xcos www.openeering.com page 16/19
Step 25: Make the LHY scheme
Drag integration blocks and specify for each blocks the appropriate initial
conditions.
Add also some annotations.
LHY Tutorial Xcos www.openeering.com page 17/19
Step 26: Make the LHY scheme
Add:
 Three sum blocks;
 Three integral blocks;
 Four gain blocks with the appropriate constants;
 A multiplexer block (4 ports: );
 A scope block (ymin = 0, ymax = 9e+6, Refresh period =
50);
 A clock block (Period=0.5, Initiation = 0).
Connect the blocks as shown in the figure. For a more readable diagram it
is better to comment blocks and connections using annotation blocks as
reported in the figure.
Step 27: Make the LHY scheme
Add:
 One expression block (with two inputs and the Scilab expression
tau + max(smax,s*exp(-q*u2/u1))*u1);
LHY Tutorial Xcos www.openeering.com page 18/19
Step 28: Running and testing
Click on the menu button .
Step 13: Exercise #1
Modify the main program file such that it is possible to write data to Scilab
environment and plot data from Scilab.
Hint:
Use the block in “Sinks” “To workspace” as reported on the right.
LHY Tutorial Xcos www.openeering.com page 19/19
Step 14: Concluding remarks and References
In this tutorial we have shown how the LHY model can be implemented in
Scilab/Xcos
On the right-hand column you may find a list of references for further
studies.
1. Scilab Web Page: Available: www.scilab.org.
2. Openeering: www.openeering.com.
3. D. Winkler, J. P. Caulkins, D. A. Behrens and G. Tragler, "Estimating
the relative efficiency of various forms of prevention at different
stages of a drug epidemic," Heinz Research, 2002.
http://repository.cmu.edu/heinzworks/211/.
Step 15: Software content
To report a bug or suggest some improvement please contact Openeering
team at the web site www.openeering.com.
Thank you for your attention,
Manolo Venturin
------------------------
LHY MODEL IN SCILAB/XCOS
------------------------
--------------
Main directory
--------------
ex1.xcos : Solution of the exercise
LHY_Tutorial_Xcos.xcos : Main xcos program
license.txt : The license file

Más contenido relacionado

La actualidad más candente

Scilabisnotnaive
ScilabisnotnaiveScilabisnotnaive
Scilabisnotnaivezan
 
graphics programming in java
graphics programming in javagraphics programming in java
graphics programming in javaAbinaya B
 
Introduction to Control systems in scilab
Introduction to Control systems in scilabIntroduction to Control systems in scilab
Introduction to Control systems in scilabScilab
 
Applet and graphics programming
Applet and graphics programmingApplet and graphics programming
Applet and graphics programmingsrijavel
 
Simple Scala DSLs
Simple Scala DSLsSimple Scala DSLs
Simple Scala DSLslinxbetter
 
Instrumentation and measurements
Instrumentation and measurementsInstrumentation and measurements
Instrumentation and measurementsTuba Tanveer
 
Aeraulic toolbox for Xcos
Aeraulic toolbox for XcosAeraulic toolbox for Xcos
Aeraulic toolbox for XcosScilab
 
Procedure to create_the_calculator_application java
Procedure to create_the_calculator_application javaProcedure to create_the_calculator_application java
Procedure to create_the_calculator_application javagthe
 
KEVIN MERCHANT DOCUMENT
KEVIN MERCHANT DOCUMENTKEVIN MERCHANT DOCUMENT
KEVIN MERCHANT DOCUMENTtejas1235
 
Matlab-Data types and operators
Matlab-Data types and operatorsMatlab-Data types and operators
Matlab-Data types and operatorsLuckshay Batra
 
Virtual Method Table and accident prevention
Virtual Method Table and accident preventionVirtual Method Table and accident prevention
Virtual Method Table and accident preventionAndrey Karpov
 
Intro to Matlab programming
Intro to Matlab programmingIntro to Matlab programming
Intro to Matlab programmingAhmed Moawad
 
Final project report
Final project reportFinal project report
Final project reportssuryawanshi
 
Java Graphics
Java GraphicsJava Graphics
Java GraphicsShraddha
 
222066369 clad-study-guide
222066369 clad-study-guide222066369 clad-study-guide
222066369 clad-study-guidehomeworkping9
 

La actualidad más candente (19)

Scilabisnotnaive
ScilabisnotnaiveScilabisnotnaive
Scilabisnotnaive
 
graphics programming in java
graphics programming in javagraphics programming in java
graphics programming in java
 
Introduction to Control systems in scilab
Introduction to Control systems in scilabIntroduction to Control systems in scilab
Introduction to Control systems in scilab
 
Applet and graphics programming
Applet and graphics programmingApplet and graphics programming
Applet and graphics programming
 
Simple Scala DSLs
Simple Scala DSLsSimple Scala DSLs
Simple Scala DSLs
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
Instrumentation and measurements
Instrumentation and measurementsInstrumentation and measurements
Instrumentation and measurements
 
Aeraulic toolbox for Xcos
Aeraulic toolbox for XcosAeraulic toolbox for Xcos
Aeraulic toolbox for Xcos
 
Procedure to create_the_calculator_application java
Procedure to create_the_calculator_application javaProcedure to create_the_calculator_application java
Procedure to create_the_calculator_application java
 
KEVIN MERCHANT DOCUMENT
KEVIN MERCHANT DOCUMENTKEVIN MERCHANT DOCUMENT
KEVIN MERCHANT DOCUMENT
 
Matlab-Data types and operators
Matlab-Data types and operatorsMatlab-Data types and operators
Matlab-Data types and operators
 
Virtual Method Table and accident prevention
Virtual Method Table and accident preventionVirtual Method Table and accident prevention
Virtual Method Table and accident prevention
 
Mmc manual
Mmc manualMmc manual
Mmc manual
 
Intro to Matlab programming
Intro to Matlab programmingIntro to Matlab programming
Intro to Matlab programming
 
Layout manager
Layout managerLayout manager
Layout manager
 
Ch3
Ch3Ch3
Ch3
 
Final project report
Final project reportFinal project report
Final project report
 
Java Graphics
Java GraphicsJava Graphics
Java Graphics
 
222066369 clad-study-guide
222066369 clad-study-guide222066369 clad-study-guide
222066369 clad-study-guide
 

Similar a Modeling an ODE: 3 different approaches - Part 2

Xcos for very beginners
Xcos for very beginnersXcos for very beginners
Xcos for very beginnersScilab
 
Control system-toolbox-in-scilab
Control system-toolbox-in-scilabControl system-toolbox-in-scilab
Control system-toolbox-in-scilabsundar79
 
Customizing Xcos with new Blocks and Palette
Customizing Xcos with new Blocks and PaletteCustomizing Xcos with new Blocks and Palette
Customizing Xcos with new Blocks and PaletteScilab
 
Simulink Presentation.ppt
Simulink Presentation.pptSimulink Presentation.ppt
Simulink Presentation.ppthodeeeeee1
 
Network Planning and Optimization
Network Planning and OptimizationNetwork Planning and Optimization
Network Planning and OptimizationEM Legacy
 
Modeling and Simulation of an Active Disturbance Rejection Controller Based o...
Modeling and Simulation of an Active Disturbance Rejection Controller Based o...Modeling and Simulation of an Active Disturbance Rejection Controller Based o...
Modeling and Simulation of an Active Disturbance Rejection Controller Based o...IJRES Journal
 
Matlab simulink introduction
Matlab simulink introductionMatlab simulink introduction
Matlab simulink introductionAmeen San
 
AN IMPROVED DECISION SUPPORT SYSTEM BASED ON THE BDM (BIT DECISION MAKING) ME...
AN IMPROVED DECISION SUPPORT SYSTEM BASED ON THE BDM (BIT DECISION MAKING) ME...AN IMPROVED DECISION SUPPORT SYSTEM BASED ON THE BDM (BIT DECISION MAKING) ME...
AN IMPROVED DECISION SUPPORT SYSTEM BASED ON THE BDM (BIT DECISION MAKING) ME...ijmpict
 
EC6612 VLSI Design Lab Manual
EC6612 VLSI Design Lab ManualEC6612 VLSI Design Lab Manual
EC6612 VLSI Design Lab Manualtamil arasan
 
Hands-on-OpenIPSL.org using OpenModelica!
Hands-on-OpenIPSL.org using OpenModelica!Hands-on-OpenIPSL.org using OpenModelica!
Hands-on-OpenIPSL.org using OpenModelica!Luigi Vanfretti
 
CSCI-383 Lecture 3-4: Abstraction
CSCI-383 Lecture 3-4: AbstractionCSCI-383 Lecture 3-4: Abstraction
CSCI-383 Lecture 3-4: AbstractionJI Ruan
 
EFFICIENT IMPLEMENTATION OF 16-BIT MULTIPLIER-ACCUMULATOR USING RADIX-2 MODIF...
EFFICIENT IMPLEMENTATION OF 16-BIT MULTIPLIER-ACCUMULATOR USING RADIX-2 MODIF...EFFICIENT IMPLEMENTATION OF 16-BIT MULTIPLIER-ACCUMULATOR USING RADIX-2 MODIF...
EFFICIENT IMPLEMENTATION OF 16-BIT MULTIPLIER-ACCUMULATOR USING RADIX-2 MODIF...VLSICS Design
 
cscript_controller.pdf
cscript_controller.pdfcscript_controller.pdf
cscript_controller.pdfVcTrn1
 

Similar a Modeling an ODE: 3 different approaches - Part 2 (20)

Xcos for very beginners
Xcos for very beginnersXcos for very beginners
Xcos for very beginners
 
Control system-toolbox-in-scilab
Control system-toolbox-in-scilabControl system-toolbox-in-scilab
Control system-toolbox-in-scilab
 
Customizing Xcos with new Blocks and Palette
Customizing Xcos with new Blocks and PaletteCustomizing Xcos with new Blocks and Palette
Customizing Xcos with new Blocks and Palette
 
Simulink Presentation.ppt
Simulink Presentation.pptSimulink Presentation.ppt
Simulink Presentation.ppt
 
Simulink
SimulinkSimulink
Simulink
 
Network Planning and Optimization
Network Planning and OptimizationNetwork Planning and Optimization
Network Planning and Optimization
 
Modeling and Simulation of an Active Disturbance Rejection Controller Based o...
Modeling and Simulation of an Active Disturbance Rejection Controller Based o...Modeling and Simulation of an Active Disturbance Rejection Controller Based o...
Modeling and Simulation of an Active Disturbance Rejection Controller Based o...
 
Sliding door
Sliding doorSliding door
Sliding door
 
Matlab simulink introduction
Matlab simulink introductionMatlab simulink introduction
Matlab simulink introduction
 
LSTM_public.pdf
LSTM_public.pdfLSTM_public.pdf
LSTM_public.pdf
 
AN IMPROVED DECISION SUPPORT SYSTEM BASED ON THE BDM (BIT DECISION MAKING) ME...
AN IMPROVED DECISION SUPPORT SYSTEM BASED ON THE BDM (BIT DECISION MAKING) ME...AN IMPROVED DECISION SUPPORT SYSTEM BASED ON THE BDM (BIT DECISION MAKING) ME...
AN IMPROVED DECISION SUPPORT SYSTEM BASED ON THE BDM (BIT DECISION MAKING) ME...
 
EC6612 VLSI Design Lab Manual
EC6612 VLSI Design Lab ManualEC6612 VLSI Design Lab Manual
EC6612 VLSI Design Lab Manual
 
Simulink
SimulinkSimulink
Simulink
 
Computer Networks Omnet
Computer Networks OmnetComputer Networks Omnet
Computer Networks Omnet
 
Mini Project- ROM Based Sine Wave Generator
Mini Project- ROM Based Sine Wave GeneratorMini Project- ROM Based Sine Wave Generator
Mini Project- ROM Based Sine Wave Generator
 
Hands-on-OpenIPSL.org using OpenModelica!
Hands-on-OpenIPSL.org using OpenModelica!Hands-on-OpenIPSL.org using OpenModelica!
Hands-on-OpenIPSL.org using OpenModelica!
 
CSCI-383 Lecture 3-4: Abstraction
CSCI-383 Lecture 3-4: AbstractionCSCI-383 Lecture 3-4: Abstraction
CSCI-383 Lecture 3-4: Abstraction
 
EFFICIENT IMPLEMENTATION OF 16-BIT MULTIPLIER-ACCUMULATOR USING RADIX-2 MODIF...
EFFICIENT IMPLEMENTATION OF 16-BIT MULTIPLIER-ACCUMULATOR USING RADIX-2 MODIF...EFFICIENT IMPLEMENTATION OF 16-BIT MULTIPLIER-ACCUMULATOR USING RADIX-2 MODIF...
EFFICIENT IMPLEMENTATION OF 16-BIT MULTIPLIER-ACCUMULATOR USING RADIX-2 MODIF...
 
Lab03
Lab03Lab03
Lab03
 
cscript_controller.pdf
cscript_controller.pdfcscript_controller.pdf
cscript_controller.pdf
 

Más de Scilab

Statistical Analysis for Robust Design
Statistical Analysis for Robust DesignStatistical Analysis for Robust Design
Statistical Analysis for Robust DesignScilab
 
Electric motor optimization
Electric motor optimizationElectric motor optimization
Electric motor optimizationScilab
 
Asteroidlanding - Scilab conference 2019 Keynote
Asteroidlanding - Scilab conference 2019 KeynoteAsteroidlanding - Scilab conference 2019 Keynote
Asteroidlanding - Scilab conference 2019 KeynoteScilab
 
Faster Time to Market using Scilab/XCOS/X2C for motor control algorithm devel...
Faster Time to Market using Scilab/XCOS/X2C for motor control algorithm devel...Faster Time to Market using Scilab/XCOS/X2C for motor control algorithm devel...
Faster Time to Market using Scilab/XCOS/X2C for motor control algorithm devel...Scilab
 
Scilab and Xcos for Very Low Earth Orbits satellites modelling
Scilab and Xcos for Very Low Earth Orbits satellites modellingScilab and Xcos for Very Low Earth Orbits satellites modelling
Scilab and Xcos for Very Low Earth Orbits satellites modellingScilab
 
X2C -a tool for model-based control development and automated code generation...
X2C -a tool for model-based control development and automated code generation...X2C -a tool for model-based control development and automated code generation...
X2C -a tool for model-based control development and automated code generation...Scilab
 
A Real-Time Interface for Xcos – an illustrative demonstration using a batter...
A Real-Time Interface for Xcos – an illustrative demonstration using a batter...A Real-Time Interface for Xcos – an illustrative demonstration using a batter...
A Real-Time Interface for Xcos – an illustrative demonstration using a batter...Scilab
 
Aircraft Simulation Model and Flight Control Laws Design Using Scilab and XCos
Aircraft Simulation Model and Flight Control Laws Design Using Scilab and XCosAircraft Simulation Model and Flight Control Laws Design Using Scilab and XCos
Aircraft Simulation Model and Flight Control Laws Design Using Scilab and XCosScilab
 
Scilab for real dummies j.heikell - part3
Scilab for real dummies j.heikell - part3Scilab for real dummies j.heikell - part3
Scilab for real dummies j.heikell - part3Scilab
 
Scilab for real dummies j.heikell - part 2
Scilab for real dummies j.heikell - part 2Scilab for real dummies j.heikell - part 2
Scilab for real dummies j.heikell - part 2Scilab
 
Scilab for real dummies j.heikell - part 1
Scilab for real dummies j.heikell - part 1Scilab for real dummies j.heikell - part 1
Scilab for real dummies j.heikell - part 1Scilab
 
Multiobjective optimization and Genetic algorithms in Scilab
Multiobjective optimization and Genetic algorithms in ScilabMultiobjective optimization and Genetic algorithms in Scilab
Multiobjective optimization and Genetic algorithms in ScilabScilab
 
Scilab optimization workshop
Scilab optimization workshop Scilab optimization workshop
Scilab optimization workshop Scilab
 
INRA @ Scilab Conference 2018
INRA @ Scilab Conference 2018INRA @ Scilab Conference 2018
INRA @ Scilab Conference 2018Scilab
 
Qualcomm @ Scilab Conference 2018
Qualcomm @ Scilab Conference 2018Qualcomm @ Scilab Conference 2018
Qualcomm @ Scilab Conference 2018Scilab
 
Sanofi @ Scilab Conference 2018
Sanofi @ Scilab Conference 2018Sanofi @ Scilab Conference 2018
Sanofi @ Scilab Conference 2018Scilab
 
University of Applied Science Esslingen @ Scilab Conference 2018
University of Applied Science Esslingen @ Scilab Conference 2018University of Applied Science Esslingen @ Scilab Conference 2018
University of Applied Science Esslingen @ Scilab Conference 2018Scilab
 
DLR @ Scilab Conference 2018
DLR @ Scilab Conference 2018DLR @ Scilab Conference 2018
DLR @ Scilab Conference 2018Scilab
 
Fraunhofer IIS @ Scilab Conference 2018
Fraunhofer IIS @ Scilab Conference 2018Fraunhofer IIS @ Scilab Conference 2018
Fraunhofer IIS @ Scilab Conference 2018Scilab
 
Arcelormittal @ Scilab Conference 2018
Arcelormittal @ Scilab Conference 2018Arcelormittal @ Scilab Conference 2018
Arcelormittal @ Scilab Conference 2018Scilab
 

Más de Scilab (20)

Statistical Analysis for Robust Design
Statistical Analysis for Robust DesignStatistical Analysis for Robust Design
Statistical Analysis for Robust Design
 
Electric motor optimization
Electric motor optimizationElectric motor optimization
Electric motor optimization
 
Asteroidlanding - Scilab conference 2019 Keynote
Asteroidlanding - Scilab conference 2019 KeynoteAsteroidlanding - Scilab conference 2019 Keynote
Asteroidlanding - Scilab conference 2019 Keynote
 
Faster Time to Market using Scilab/XCOS/X2C for motor control algorithm devel...
Faster Time to Market using Scilab/XCOS/X2C for motor control algorithm devel...Faster Time to Market using Scilab/XCOS/X2C for motor control algorithm devel...
Faster Time to Market using Scilab/XCOS/X2C for motor control algorithm devel...
 
Scilab and Xcos for Very Low Earth Orbits satellites modelling
Scilab and Xcos for Very Low Earth Orbits satellites modellingScilab and Xcos for Very Low Earth Orbits satellites modelling
Scilab and Xcos for Very Low Earth Orbits satellites modelling
 
X2C -a tool for model-based control development and automated code generation...
X2C -a tool for model-based control development and automated code generation...X2C -a tool for model-based control development and automated code generation...
X2C -a tool for model-based control development and automated code generation...
 
A Real-Time Interface for Xcos – an illustrative demonstration using a batter...
A Real-Time Interface for Xcos – an illustrative demonstration using a batter...A Real-Time Interface for Xcos – an illustrative demonstration using a batter...
A Real-Time Interface for Xcos – an illustrative demonstration using a batter...
 
Aircraft Simulation Model and Flight Control Laws Design Using Scilab and XCos
Aircraft Simulation Model and Flight Control Laws Design Using Scilab and XCosAircraft Simulation Model and Flight Control Laws Design Using Scilab and XCos
Aircraft Simulation Model and Flight Control Laws Design Using Scilab and XCos
 
Scilab for real dummies j.heikell - part3
Scilab for real dummies j.heikell - part3Scilab for real dummies j.heikell - part3
Scilab for real dummies j.heikell - part3
 
Scilab for real dummies j.heikell - part 2
Scilab for real dummies j.heikell - part 2Scilab for real dummies j.heikell - part 2
Scilab for real dummies j.heikell - part 2
 
Scilab for real dummies j.heikell - part 1
Scilab for real dummies j.heikell - part 1Scilab for real dummies j.heikell - part 1
Scilab for real dummies j.heikell - part 1
 
Multiobjective optimization and Genetic algorithms in Scilab
Multiobjective optimization and Genetic algorithms in ScilabMultiobjective optimization and Genetic algorithms in Scilab
Multiobjective optimization and Genetic algorithms in Scilab
 
Scilab optimization workshop
Scilab optimization workshop Scilab optimization workshop
Scilab optimization workshop
 
INRA @ Scilab Conference 2018
INRA @ Scilab Conference 2018INRA @ Scilab Conference 2018
INRA @ Scilab Conference 2018
 
Qualcomm @ Scilab Conference 2018
Qualcomm @ Scilab Conference 2018Qualcomm @ Scilab Conference 2018
Qualcomm @ Scilab Conference 2018
 
Sanofi @ Scilab Conference 2018
Sanofi @ Scilab Conference 2018Sanofi @ Scilab Conference 2018
Sanofi @ Scilab Conference 2018
 
University of Applied Science Esslingen @ Scilab Conference 2018
University of Applied Science Esslingen @ Scilab Conference 2018University of Applied Science Esslingen @ Scilab Conference 2018
University of Applied Science Esslingen @ Scilab Conference 2018
 
DLR @ Scilab Conference 2018
DLR @ Scilab Conference 2018DLR @ Scilab Conference 2018
DLR @ Scilab Conference 2018
 
Fraunhofer IIS @ Scilab Conference 2018
Fraunhofer IIS @ Scilab Conference 2018Fraunhofer IIS @ Scilab Conference 2018
Fraunhofer IIS @ Scilab Conference 2018
 
Arcelormittal @ Scilab Conference 2018
Arcelormittal @ Scilab Conference 2018Arcelormittal @ Scilab Conference 2018
Arcelormittal @ Scilab Conference 2018
 

Último

Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
Intro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdfIntro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdfrs7054576148
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdfSuman Jyoti
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01KreezheaRecto
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 

Último (20)

Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Intro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdfIntro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdf
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 

Modeling an ODE: 3 different approaches - Part 2

  • 1. www.openeering.com powered by MODELING IN SCILAB: PAY ATTENTION TO THE RIGHT APPROACH – PART 2 In this tutorial we show how to model a physical system described by ODE using Xcos environment. The same model solution is also described in Scilab and Xcos + Modelica in two other tutorials. Level This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
  • 2. LHY Tutorial Xcos www.openeering.com page 2/19 Step 1: The purpose of this tutorial In Scilab there are three different approaches (see figure) for modeling a physical system which is described by Ordinary Differential Equations (ODE). For showing all these capabilities we selected a common physical system, the LHY model for drug abuse. This model is used in our tutorials as a common problem to show the main features of each strategy. We are going to recurrently refer to this problem to allow the reader to better focus on the Scilab approach rather than on mathematical details. In this second tutorial we show, step by step, how the LHY model problem can be implemented in the Xcos environment. The sample code can be downloaded from the Openeering web site. 1 Standard Scilab Programming 2 Xcos Programming 3 Xcos + Modelica Step 2: Model description The considered model is the LHY model used in the study of drug abuse. This model is a continuous-time dynamical system of drug demand for two different classes of users: light users (denoted by ) and heavy users (denoted by ) which are functions of time . There is another state in the model that represents the decaying memory of heavy users in the years (denoted by ) that acts as a deterrent for new light users. In other words the increase of the deterrent power of memory of drug abuse reduces the contagious aspect of initiation. This approach presents a positive feedback which corresponds to the fact that light users promote initiation of new users and, moreover, it presents a negative feedback which corresponds to the fact that heavy users have a negative impact on initiation. Light users become heavy users at the rate of escalation and leave this state at the rate of desistance . The heavy users leave this state at the rate of desistance .
  • 3. LHY Tutorial Xcos www.openeering.com page 3/19 Step 3: Mathematical model The mathematical model is a system of ODE (Ordinary Differential Equation) in the unknowns:  , number of light users;  , number of heavy users;  , decaying of heavy user years. The initiation function contains a “spontaneous” initiation and a memory effect modeled with a negative exponential as a function of the memory of year of drug abuse relative to the number of current light users. The problem is completed with the specification of the initial conditions at the time . The LHY equations system (omitting time variable for sake of simplicity) is { ̇ ̇ ̇ where the initiation function is { } The LHY initial conditions are {
  • 4. LHY Tutorial Xcos www.openeering.com page 4/19 Step 4: Problem data (Model data) : the annual rate at which light users quit : the annual rate at which light users escalate to heavy use : the annual rate at which heavy users quit : the forgetting rate (Initiation function) : the number of innovators per year : the annual rate at which light users attract non-users : the constant which measures the deterrent effect of heavy use : the maximum rate of generation for initiation (Initial conditions) : the initial simulation time; : Light users at the initial time; : Heavy users at the initial time; : Decaying heavy users at the initial time. Model data Initiation function Initial conditions
  • 5. LHY Tutorial Xcos www.openeering.com page 5/19 Step 5: Xcos programming – introduction Xcos is a free graphical editor and simulator based on Scilab that helps people to model physical systems (electrical, mechanical, automotive, hydraulics, …) using a graphical user interface based on a block diagram approach. It includes explicit and implicit dynamical systems and both continuous and discrete sub-systems. This toolbox is particularly useful in control theory, digital and signal processing and model-based design for multidomain simulation, especially when continuous time and discrete time components are interconnected. As an example of a Xcos diagram, we show on the right a Xcos model of a RLC electric circuit with its graphical output. The first output is relative to the voltage across the capacitor element, while the second one is relative to the current through the voltage generator.
  • 6. LHY Tutorial Xcos www.openeering.com page 6/19 Step 6: Xcos programming – getting started Xcos environment can be started from Scilab Console typing --> xcos or clicking on the button in the Scilab menu bar. The command starts two windows:  the palette browser that contains all Xcos available blocks grouped by categories;  an editor window where the user can drag blocks from the palette browser for composing new schemes. All Xcos files end with extension “.zcos”. In previous versions of Scilab all Xcos files end with extension “.xcos”.
  • 7. LHY Tutorial Xcos www.openeering.com page 7/19 Step 7: Xcos programming – block types In Xcos the main object is a block that can be used in different models and projects. A Xcos block is an element characterized by the following features: input/output ports; input/output activations ports; continuous/discrete time states; … Xcos blocks contain several type of links:  Regular links that transmit signals through the blocks ports (black triangle);  Activation links that transmit activation timing information through the block ports (red triangle);  Implicit links, see tutorial Xcos + Modelica (black square). The user should connect only ports of the same type. Block configuration can be specified from the input mask by double- clicking on the block. Step 8: Roadmap In this tutorial we describe how to construct the LHY model and simulate it in Xcos. We :  provide a description of all the basic blocks used for the LHY model;  provide a description of the simulation menu;  provide a description of how to edit a model;  construct the LHY scheme;  test the program and visualize the results. Descriptions Steps Basic blocks 9-16 Simulation menu 17-19 Editing models 20-22 Scheme construction 23-27 Test and visualize 28
  • 8. LHY Tutorial Xcos www.openeering.com page 8/19 Step 9:The integral block Palette: Continuous time systems / INTEGRAL_m Purpose: The output of the block y(t) is the integral of the input u(t) at the current time step t . In our simulation we use this block to recover the variable L(t) starting from its derivative L’(t). The initial condition can be specified in the input mask. Hint: Numerically it is always more robust using the integral block instead of the derivative block. The integral block Step 10: The sum block Palette: Math operations / BIGSOM_f Purpose: The output of the block y(t) is the sum with sign of the input signals. The sign of the sum can be specified from the input mask with “+1” for “+” and “-1” for “-”. The sum block Step 11: The gain block Palette: Math operations / GAINBLK_f Purpose: The output of the block y(t) is the input signal u(t) multiplied by the gain factor. The value of the gain constant can be specified from the input mask. The gain block
  • 9. LHY Tutorial Xcos www.openeering.com page 9/19 Step 12: The expression block Palette: User defined functions / EXPRESSION Purpose: The output of the block y is a mathematical combination of the input signals u1,u2,…,uN (max 8). The name, u, followed by a number, is mandatory. More precisely, u1 represents the first input port signal, u2 represents the second input port signal, and so on. Note that constants that appear in the expression must first be defined in the “context menu” before their use. The expression block Step 13: The clock block Palette: Sources / CLOCK_c Purpose: This block generates a regular sequence of time events with a specified period and starting at a given initialization time. We use this block to activate the scope block (see next step) with the desired frequency. The clock block Step 14: The scope block Palette: Sinks / CSCOPE Purpose: This block is used to display the input signal (also vector of signals) with respect to the simulation time. For a better visualization it may be necessary to specify the scope parameters like ymin, ymax values. The scope block
  • 10. LHY Tutorial Xcos www.openeering.com page 10/19 Step 15: The multiplexer block Palette: Signal routing / MUX Purpose: This block merges the input signals (maximum 8) into a unique vector output signal. We use this block for plotting more signals in the same windows. The number of input ports can be specified from the input mask. The multiplexer block Step 16: The annotation block Palette: Annotations palette / TEXT_f Purpose: This block permits to add comments to the scheme. Comments can also be in LaTex coding. This block can be also called by a double click of the mouse on the scheme. Examples of LaTex code are $L$ for generating L and $dot L$ for generating L’(t). The annotation block Step 17: The simulation starting time Each Xcos simulation starts from the initial time 0 and ends at a specified final time. The ending simulation time should be specified in the "Simulation/Setup" menu in the "Final integration time" field. Simulation starting time is 0 !
  • 11. LHY Tutorial Xcos www.openeering.com page 11/19 Step 18: Set simulation parameters The simulation parameters such as the “final integration time” and solver tolerances can be specified from the “set parameters” dialog in the "Simulation/Setup" menu. Step 19: Set Context The model constants used in the block definitions can be entered in the “simulation set context”. This menu is available from the "Simulation/Set Context" menu. In our simulation we set here all the model constants and the initial conditions, such that it is easier to change the model value for a new simulation since all the constants are available in an unique place.
  • 12. LHY Tutorial Xcos www.openeering.com page 12/19 Step 20: Editing the model : Align blocks Here we report some hints to improve the visual quality of the connections between blocks. The first step is to drag some elements in the diagram and align them. To make a selection:  Left-click where you want to start your selection;  Hold down your left mouse button and drag the mouse until you have highlighted the area you want; or  Left-click of the mouse over the element you want;  Ctrl + Left-click on elements that you want to select; To align elements:  Right-click of the mouse and select: Format -> Align Blocks -> Center. (before) (after)
  • 13. LHY Tutorial Xcos www.openeering.com page 13/19 Step 21: Editing the model : intermediate points You can link elements specifying the path using a mouse click on intermediate points. Starting configuration Intermediate path Final path
  • 14. LHY Tutorial Xcos www.openeering.com page 14/19 Step 22: Editing the model The same if you want to link elements to an already existing path (start from the element port and draw the path you want). Click with the mouse at the right position although the visualization is not correct. Starting configuration Intermediate path Final path
  • 15. LHY Tutorial Xcos www.openeering.com page 15/19 Step 23: Make the LHY scheme Set the “Final integration time” to 50 in the "Simulation/Setup" menu; In our simulation we modify the value of the “Final integration time” to 50 because the initial time in Xcos is 0, which corresponds to the year 1970 of our model. This means that 50 corresponds to the year 2020 of our model. Step 24: Make the LHY scheme Set the model constants in the "Simulation/Set Context" menu.; tau = 5e4; // Number of innovators per year (initiation) s = 0.61; // Annual rate at which light users attract non-users (initiation) q = 3.443; // Constant which measures the deterrent effect of heavy users (initiation) smax = 0.1; // Upper bound for s effective (initiation) a = 0.163; // Annual rate at which light users quit b = 0.024; // Annual rate at which light users escalate to heavy use g = 0.062; // Annual rate at which heavy users quit delta = 0.291; // Forgetting rate // Initial conditions Tbegin = 1970; // Initial time Tend = 2020; // Final time Tstep = 0.5; // Time step L0 = 1.4e6; // Light users at the initial time H0 = 0.13e6; // Heavy users at the initial time Y0 = 0.11e6; // Decaying heavy user at the initial time
  • 16. LHY Tutorial Xcos www.openeering.com page 16/19 Step 25: Make the LHY scheme Drag integration blocks and specify for each blocks the appropriate initial conditions. Add also some annotations.
  • 17. LHY Tutorial Xcos www.openeering.com page 17/19 Step 26: Make the LHY scheme Add:  Three sum blocks;  Three integral blocks;  Four gain blocks with the appropriate constants;  A multiplexer block (4 ports: );  A scope block (ymin = 0, ymax = 9e+6, Refresh period = 50);  A clock block (Period=0.5, Initiation = 0). Connect the blocks as shown in the figure. For a more readable diagram it is better to comment blocks and connections using annotation blocks as reported in the figure. Step 27: Make the LHY scheme Add:  One expression block (with two inputs and the Scilab expression tau + max(smax,s*exp(-q*u2/u1))*u1);
  • 18. LHY Tutorial Xcos www.openeering.com page 18/19 Step 28: Running and testing Click on the menu button . Step 13: Exercise #1 Modify the main program file such that it is possible to write data to Scilab environment and plot data from Scilab. Hint: Use the block in “Sinks” “To workspace” as reported on the right.
  • 19. LHY Tutorial Xcos www.openeering.com page 19/19 Step 14: Concluding remarks and References In this tutorial we have shown how the LHY model can be implemented in Scilab/Xcos On the right-hand column you may find a list of references for further studies. 1. Scilab Web Page: Available: www.scilab.org. 2. Openeering: www.openeering.com. 3. D. Winkler, J. P. Caulkins, D. A. Behrens and G. Tragler, "Estimating the relative efficiency of various forms of prevention at different stages of a drug epidemic," Heinz Research, 2002. http://repository.cmu.edu/heinzworks/211/. Step 15: Software content To report a bug or suggest some improvement please contact Openeering team at the web site www.openeering.com. Thank you for your attention, Manolo Venturin ------------------------ LHY MODEL IN SCILAB/XCOS ------------------------ -------------- Main directory -------------- ex1.xcos : Solution of the exercise LHY_Tutorial_Xcos.xcos : Main xcos program license.txt : The license file