BlockImporter/Tour/GettingStarted - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Home : Support : Online Help : BlockImporter/Tour/GettingStarted

 Getting Started

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

Setting up BlockImporter

BlockImporter requires that the following components be set up correctly.

 • MATLAB and Simulink

For details, see the BlockImporter,setup help page.

Initialization

$\mathrm{with}\left(\mathrm{BlockImporter}\right)$

 $\left[{\mathrm{BuildDE}}{,}{\mathrm{Import}}{,}{\mathrm{PrintSummary}}{,}{\mathrm{SimplifyModel}}\right]$ (3.1)

Importing a Simple System

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.

$\mathrm{datadir}≔\mathrm{BlockImporter}:-\mathrm{DataDirectory}\left(\right)$

 ${"/usr/local/share/maple/15/toolbox/BlockImporter/data"}$ (4.1)

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.



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

$\mathrm{sys}:-\mathrm{equations}$

 $\left[{{u}}_{{10}{,}{1}{,}{1}}{=}{{y}}_{{2}{,}{1}{,}{1}}{,}{{u}}_{{2}{,}{2}{,}{1}}{=}{{y}}_{{3}{,}{1}{,}{1}}{,}{{u}}_{{2}{,}{1}{,}{1}}{=}{{y}}_{{4}{,}{1}{,}{1}}{,}{{u}}_{{8}{,}{1}{,}{1}}{=}{{y}}_{{6}{,}{1}{,}{1}}{,}{{u}}_{{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{{K}}_{{0}{,}{"a1"}}{}{{x}}_{{10}{,}{1}}{,}{{y}}_{{10}{,}{1}{,}{1}}{=}{{x}}_{{10}{,}{1}}{,}{\mathrm{D}}{}\left({{x}}_{{11}{,}{1}}\right){=}{{u}}_{{11}{,}{1}{,}{1}}{-}{{K}}_{{0}{,}{"a2"}}{}{{x}}_{{11}{,}{1}}{,}{{y}}_{{11}{,}{1}{,}{1}}{=}{{x}}_{{11}{,}{1}}\right]$ (4.2)



initialeqs: list of initial equations

$\mathrm{sys}:-\mathrm{initialeqs}$

 $\left[{{x}}_{{4}{,}{1}}{}\left({0}\right){=}{0}{,}{{x}}_{{10}{,}{1}}{}\left({0}\right){=}{0}{,}{{x}}_{{11}{,}{1}}{}\left({0}\right){=}{0}\right]$ (4.3)



statevars: list of state variables

$\mathrm{sys}:-\mathrm{statevars}$

 $\left[{{x}}_{{4}{,}{1}}{,}{{x}}_{{10}{,}{1}}{,}{{x}}_{{11}{,}{1}}\right]$ (4.4)



inputvars: list of input variables

$\mathrm{sys}:-\mathrm{inputvars}$

 $\left[{{\mathrm{Source}}}_{{\mathrm{Step}}{,}{6}{,}{1}}{,}{{\mathrm{Source}}}_{{\mathrm{Step}}{,}{7}{,}{1}}\right]$ (4.5)



outputvars: list of output variables

$\mathrm{sys}:-\mathrm{outputvars}$

 $\left[{{\mathrm{Sink}}}_{{\mathrm{Scope}}{,}{5}{,}{1}{,}{1}}\right]$ (4.6)



sourceeqs: list of source equations for the input sources

$\mathrm{sys}:-\mathrm{sourceeqs}$

 $\left[{{\mathrm{Source}}}_{{\mathrm{Step}}{,}{6}{,}{1}}{=}{{}\begin{array}{cc}{0}& {t}{<}{1}\\ {1}& {\mathrm{otherwise}}\end{array}{,}{{\mathrm{Source}}}_{{\mathrm{Step}}{,}{7}{,}{1}}{=}{{}\begin{array}{cc}{0}& {t}{<}{4}\\ {0.1}& {\mathrm{otherwise}}\end{array}\right]$ (4.7)



parameters: list of constant parameters

$\mathrm{sys}:-\mathrm{parameters}$

 $\left[{{K}}_{{0}{,}{"a1"}}{=}{2.}{,}{{K}}_{{0}{,}{"a2"}}{=}{1.}\right]$ (4.8)



notes: list of any notes generated during the import

$\mathrm{sys}:-\mathrm{notes}$

 $\left[{}\right]$ (4.9)



procs: procedure required to implement some of the blocks (for example lookup).  Note that this field is a table, rather than a list.

$\mathrm{eval}\left(\mathrm{sys}:-\mathrm{procs}\right)$

 ${\mathrm{table}}\left(\left[{}\right]\right)$ (4.10)





A convenient procedure, PrintSummary, displays all the fields of this data structure.



$\mathrm{PrintSummary}\left(\mathrm{sys}\right)$

 $\left[{{K}}_{{0}{,}{"a1"}}{=}{2.}{,}{{K}}_{{0}{,}{"a2"}}{=}{1.}\right]$ (4.11)



Simplifying the Model

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.

 ${\mathrm{record}}{}\left({\mathrm{equations}}{,}{\mathrm{initialeqs}}{,}{\mathrm{inputvars}}{,}{\mathrm{notes}}{,}{\mathrm{outputvars}}{,}{\mathrm{parameters}}{,}{\mathrm{procs}}{,}{\mathrm{sourceeqs}}{,}{\mathrm{statevars}}\right)$ (5.1)

The summary of this model reveals that the simplified model contains significantly fewer equations.

$\mathrm{PrintSummary}\left(\mathrm{sys2}\right)$

 $\left[{{K}}_{{0}{,}{"a1"}}{=}{2.}{,}{{K}}_{{0}{,}{"a2"}}{=}{1.}\right]$ (5.2)

Building Differential Equations and Simulating the Model

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.

 ${\mathrm{record}}{}\left({\mathrm{equations}}{,}{\mathrm{initialeqs}}{,}{\mathrm{known}}{,}{\mathrm{outputvars}}{,}{\mathrm{parameters}}{,}{\mathrm{sourceeqs}}\right)$ (6.1)

The result is a list of objects.

equations: set of differential equations with the parameters left in the symbolic form

$\mathrm{deq}:-\mathrm{equations}$

 $\left[\frac{{ⅆ}}{{ⅆ}{t}}{}{{x}}_{{4}{,}{1}}{}\left({t}\right){=}{{\mathrm{Source}}}_{{\mathrm{Step}}{,}{6}{,}{1}}{}\left({t}\right){-}{{\mathrm{Sink}}}_{{\mathrm{Scope}}{,}{5}{,}{1}{,}{1}}{}\left({t}\right){,}\frac{{ⅆ}}{{ⅆ}{t}}{}{{x}}_{{10}{,}{1}}{}\left({t}\right){=}{{x}}_{{4}{,}{1}}{}\left({t}\right){+}\frac{{ⅆ}}{{ⅆ}{t}}{}{{x}}_{{4}{,}{1}}{}\left({t}\right){-}{{K}}_{{0}{,}{"a1"}}{}{{x}}_{{10}{,}{1}}{}\left({t}\right){,}\frac{{ⅆ}}{{ⅆ}{t}}{}{{x}}_{{11}{,}{1}}{}\left({t}\right){=}{{\mathrm{Source}}}_{{\mathrm{Step}}{,}{7}{,}{1}}{}\left({t}\right){+}{{x}}_{{10}{,}{1}}{}\left({t}\right){-}{{K}}_{{0}{,}{"a2"}}{}{{x}}_{{11}{,}{1}}{}\left({t}\right){,}{{\mathrm{Sink}}}_{{\mathrm{Scope}}{,}{5}{,}{1}{,}{1}}{}\left({t}\right){=}{{x}}_{{11}{,}{1}}{}\left({t}\right)\right]$ (6.2)



initialeqs: list of initial conditions

$\mathrm{deq}:-\mathrm{initialeqs}$

 $\left[{{x}}_{{4}{,}{1}}{}\left({0}\right){=}{0}{,}{{x}}_{{10}{,}{1}}{}\left({0}\right){=}{0}{,}{{x}}_{{11}{,}{1}}{}\left({0}\right){=}{0}\right]$ (6.3)



sourceeqs: list of the source equations

$\mathrm{deq}:-\mathrm{sourceeqs}$

 $\left[{{\mathrm{Source}}}_{{\mathrm{Step}}{,}{6}{,}{1}}{}\left({t}\right){=}{{}\begin{array}{cc}{0}& {t}{<}{1}\\ {1}& {\mathrm{otherwise}}\end{array}{,}{{\mathrm{Source}}}_{{\mathrm{Step}}{,}{7}{,}{1}}{}\left({t}\right){=}{{}\begin{array}{cc}{0}& {t}{<}{4}\\ {0.1}& {\mathrm{otherwise}}\end{array}\right]$ (6.4)



outputvars: list of output variables

$\mathrm{deq}:-\mathrm{outputvars}$

 $\left[{{\mathrm{Sink}}}_{{\mathrm{Scope}}{,}{5}{,}{1}{,}{1}}{}\left({t}\right)\right]$ (6.5)



parameters: list of parameter values

$\mathrm{deq}:-\mathrm{parameters}$

 $\left[{{K}}_{{0}{,}{"a1"}}{=}{2.}{,}{{K}}_{{0}{,}{"a2"}}{=}{1.}\right]$ (6.6)



known: set of procedures in the differential equations

$\mathrm{deq}:-\mathrm{known}$

 $\left\{{}\right\}$ (6.7)



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.

 ${\mathbf{proc}}\left({\mathrm{x_rkf45_dae}}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{...}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (6.8)

The time domain solution can be plotted.

${}$

Available Resources

The following resources are available.

 • BlockImporter Overview lists all the available commands
 • BlockImporter Tour highlights the BlockImporter features and showcases a number of examples