back to top
Getting Started
Introduction
Setting up BlockImporter
Initialization
Importing a Simple System
Simplifying the Model
Building Differential Equations and Simulating the Model
Available Resources
This document is intended for beginner users of BlockImporter. It gives an overview and through an example explains how to work with BlockImporter. The example illustrates how to import a system, simplify the equations, and simulate them in Maple. For details, see the help page on BlockImporter.
BlockImporter requires that the following components be set up correctly.
Maple-MATLAB® link
MATLAB and Simulink
For details, see the BlockImporter,setup help page.
withBlockImporter
BuildDE,Import,PrintSummary,SimplifyModel
We would like to import a simple Simulink model. This model is located in the BlockImporter data directory. The following command will return the location of this data directory.
datadir≔BlockImporter:-DataDirectory
/usr/local/share/maple/15/toolbox/BlockImporter/data
This directory contains the model file (example.mdl) and an initialization script (example_init.m). The initialization script contains the definition of two parameters, a1 and a2, that must be defined before the model can be executed.
To import the model, we call the Import function, and give it the name of the model that we want to import. In our case the model is called example. Optionally, we also pass in the name of the initialization script, and the directory where the model is located. The function will return a data structure with the imported equations, and we will assign it to the variable sys.
sys≔Importexample, path=datadir, init=example_init,inplace=true:
The import command makes a copy of the model and calls it temp_example, and adds numerical IDs to all the blocks in the model. These IDs correspond to the variable names in the extracted equations.
The variable sys contains the representation of the model, and is represented as a record data structure, which contains the following fields.
blockeqs: list of the equations extracted from the model
sys:-equations
u10,1,1=y2,1,1,u2,2,1=y3,1,1,u2,1,1=y4,1,1,u8,1,1=y6,1,1,u9,1,1=y7,1,1,u4,1,1=y8,1,1,u3,1,1=y8,1,1,u11,1,1=y9,1,1,u9,2,1=y10,1,1,u5,1,1=y11,1,1,u8,2,1=y11,1,1,y2,1,1=u2,1,1+u2,2,1,y3,1,1=u3,1,1,D⁡x4,1=u4,1,1,y4,1,1=x4,1,SinkScope,5,1,1=u5,1,1,y6,1,1=SourceStep,6,1,y7,1,1=SourceStep,7,1,y8,1,1=u8,1,1−u8,2,1,y9,1,1=u9,1,1+u9,2,1,D⁡x10,1=u10,1,1−K0,a1⁢x10,1,y10,1,1=x10,1,D⁡x11,1=u11,1,1−K0,a2⁢x11,1,y11,1,1=x11,1
initialeqs: list of initial equations
sys:-initialeqs
x4,1⁡0=0,x10,1⁡0=0,x11,1⁡0=0
statevars: list of state variables
sys:-statevars
x4,1,x10,1,x11,1
inputvars: list of input variables
sys:-inputvars
SourceStep,6,1,SourceStep,7,1
outputvars: list of output variables
sys:-outputvars
SinkScope,5,1,1
sourceeqs: list of source equations for the input sources
sys:-sourceeqs
SourceStep,6,1={0t<11otherwise,SourceStep,7,1={0t<40.1otherwise
parameters: list of constant parameters
sys:-parameters
K0,a1=2.,K0,a2=1.
notes: list of any notes generated during the import
sys:-notes
procs: procedure required to implement some of the blocks (for example lookup). Note that this field is a table, rather than a list.
evalsys:-procs
table
A convenient procedure, PrintSummary, displays all the fields of this data structure.
PrintSummarysys
The structure that has been imported from the model contains over 20 equations; however, many of these equations are of the trivial form a=b. We can simplify the total number of equations with the SimplifyModel command, and store the result in the sys2 data structure, using the same internal format.
sys2 ≔ SimplifyModelsys
record⁡equations,initialeqs,inputvars,notes,outputvars,parameters,procs,sourceeqs,statevars
The summary of this model reveals that the simplified model contains significantly fewer equations.
PrintSummarysys2
The equations that are contained in the data structure imported from Simulink are not differential equations, and therefore are not suitable to simulate the system using the dsolve command. To convert the structure to a suitable form, we use the BuildDE command, and assign the result to the variable deq.
deq ≔ BuildDEsys2
record⁡equations,initialeqs,known,outputvars,parameters,sourceeqs
The result is a list of objects.
equations: set of differential equations with the parameters left in the symbolic form
deq:-equations
ⅆⅆt⁢x4,1⁡t=SourceStep,6,1⁡t−SinkScope,5,1,1⁡t,ⅆⅆt⁢x10,1⁡t=x4,1⁡t+ⅆⅆt⁢x4,1⁡t−K0,a1⁢x10,1⁡t,ⅆⅆt⁢x11,1⁡t=SourceStep,7,1⁡t+x10,1⁡t−K0,a2⁢x11,1⁡t,SinkScope,5,1,1⁡t=x11,1⁡t
initialeqs: list of initial conditions
deq:-initialeqs
sourceeqs: list of the source equations
deq:-sourceeqs
SourceStep,6,1⁡t={0t<11otherwise,SourceStep,7,1⁡t={0t<40.1otherwise
deq:-outputvars
SinkScope,5,1,1⁡t
parameters: list of parameter values
deq:-parameters
known: set of procedures in the differential equations
deq:-known
To simulate the model, we substitute the source equations into the differential equations, add the initial conditions, and pass the equations to the dsolve procedure, which returns a simulation procedure.
sol≔dsolveevalevaldeq:-equations, deq:-parameters,deq:-sourceeqs, deq:-initialeqs, numeric
procx_rkf45_dae...end proc
The time domain solution can be plotted.
plotsodeplotsol,t,deq:-outputvars1, 0..10,gridlines=true;
The following resources are available.
BlockImporter Overview lists all the available commands
BlockImporter Tour highlights the BlockImporter features and showcases a number of examples
Download Help Document