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

Online Help

All Products    Maple    MapleSim


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

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

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.

• 

Maple-MATLAB® link

• 

MATLAB and Simulink

For details, see the BlockImporter,setup help page.

Initialization

withBlockImporter

BuildDE,Import,PrintSummary,SimplifyModel

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

 

datadirBlockImporter:-DataDirectory

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

 

sysImportexample, 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,Dx4,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,1u8,2,1,y9,1,1=u9,1,1+u9,2,1,Dx10,1=u10,1,1K0,a1x10,1,y10,1,1=x10,1,Dx11,1=u11,1,1K0,a2x11,1,y11,1,1=x11,1

(4.2)

initialeqs: list of initial equations

sys:-initialeqs

x4,10=0,x10,10=0,x11,10=0

(4.3)

statevars: list of state variables

sys:-statevars

x4,1,x10,1,x11,1

(4.4)

inputvars: list of input variables

sys:-inputvars

SourceStep,6,1,SourceStep,7,1

(4.5)

outputvars: list of output variables

sys:-outputvars

SinkScope,5,1,1

(4.6)

sourceeqs: list of source equations for the input sources

sys:-sourceeqs

SourceStep&comma;6&comma;1&equals;&lcub;0t<11otherwise&comma;SourceStep&comma;7&comma;1&equals;&lcub;0t<40.1otherwise

(4.7)

parameters: list of constant parameters

sys:-parameters

K0&comma;a1&equals;2.&comma;K0&comma;a2&equals;1.

(4.8)

notes: list of any notes generated during the import

sys:-notes

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

evalsys:-procs

table

(4.10)

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

PrintSummarysys

K0&comma;a1&equals;2.&comma;K0&comma;a2&equals;1.

(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&equals;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

recordequations&comma;initialeqs&comma;inputvars&comma;notes&comma;outputvars&comma;parameters&comma;procs&comma;sourceeqs&comma;statevars

(5.1)

 

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

 

PrintSummarysys2

K0&comma;a1&equals;2.&comma;K0&comma;a2&equals;1.

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

 

deq  BuildDEsys2

recordequations&comma;initialeqs&comma;known&comma;outputvars&comma;parameters&comma;sourceeqs

(6.1)

 

The result is a list of objects.

 

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

deq:-equations

&DifferentialD;&DifferentialD;tx4&comma;1t&equals;SourceStep&comma;6&comma;1tSinkScope&comma;5&comma;1&comma;1t&comma;&DifferentialD;&DifferentialD;tx10&comma;1t&equals;x4&comma;1t&plus;&DifferentialD;&DifferentialD;tx4&comma;1tK0&comma;a1x10&comma;1t&comma;&DifferentialD;&DifferentialD;tx11&comma;1t&equals;SourceStep&comma;7&comma;1t&plus;x10&comma;1tK0&comma;a2x11&comma;1t&comma;SinkScope&comma;5&comma;1&comma;1t&equals;x11&comma;1t

(6.2)

initialeqs: list of initial conditions

deq:-initialeqs

x4&comma;10&equals;0&comma;x10&comma;10&equals;0&comma;x11&comma;10&equals;0

(6.3)

sourceeqs: list of the source equations

deq:-sourceeqs

SourceStep&comma;6&comma;1t&equals;&lcub;0t<11otherwise&comma;SourceStep&comma;7&comma;1t&equals;&lcub;0t<40.1otherwise

(6.4)

outputvars: list of output variables

deq:-outputvars

SinkScope&comma;5&comma;1&comma;1t

(6.5)

parameters: list of parameter values

deq:-parameters

K0&comma;a1&equals;2.&comma;K0&comma;a2&equals;1.

(6.6)

known: set of procedures in the differential equations

deq:-known

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

 

soldsolveevalevaldeq:-equations&comma; deq:-parameters&comma;deq:-sourceeqs&comma; deq:-initialeqs&comma; numeric

procx_rkf45_dae...end proc

(6.8)

 

The time domain solution can be plotted.

 

plotsodeplotsol&comma;t&comma;deq:-outputvars1&comma; 0..10&comma;gridlines&equals;true&semi;

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