back to top
Setting up BlockImporter
Importing a Simple System
Simplifying the Model
Building Differential Equations and Simulating the Model
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.
MATLAB and Simulink
For details, see the BlockImporter,setup help page.
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.
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
initialeqs: list of initial equations
statevars: list of state variables
inputvars: list of input variables
outputvars: list of output variables
sourceeqs: list of source equations for the input sources
parameters: list of constant parameters
notes: list of any notes generated during the import
procs: procedure required to implement some of the blocks (for example lookup). Note that this field is a table, rather than a list.
A convenient procedure, PrintSummary, displays all the fields of this data structure.
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
The summary of this model reveals that the simplified model contains significantly fewer equations.
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
The result is a list of objects.
equations: set of differential equations with the parameters left in the symbolic form
initialeqs: list of initial conditions
sourceeqs: list of the source equations
parameters: list of parameter values
known: set of procedures in the differential equations
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
The time domain solution can be plotted.
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
What kind of issue would you like to report? (Optional)