Chaps18.mw


Maple Text Commands for Chapter 18 - SIMULATION

Simulation using MapleSim® and Simulink®.

The MapleSim Connectivity Toolbox - Please note that you must have MATLAB® 2007b or later and Simulink® 7.0 or later to run the following commands in Maple. Several Simulink models are displayed in Chapter 18 of the book.

You can download working Simulink model files here: 

    http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=2374&objectType=file 

 

Example 1. Build a Simulink block for the ode, where u(t) represents the input of the block and i(t) is the output. In this case i(t) is the current in a series resistor-inductor electrical circuit. 

>

restart:with(DynamicSystems):with(Connectivity):
sys1:=[diff(i(t),t)+a*i(t)=b*u(t)];
params:=[a=0.2,b=5]:
sys2:=DiffEquation(sys1,[u(t)],[i(t)]);
ResponsePlot(sys2,Step(),parameters=params);

 

`:=`(sys1, [`+`(diff(i(t), t), `*`(a, `*`(i(t)))) = `*`(b, `*`(u(t)))]) 

 

module () export de, inputcount, outputcount, statecount, sampletime, discrete, systemname, inputvariable, outputvariable, statevariable, systemtype, ModulePrint; end module 

 

Plot_2d

 

The following commands create an S-function, called “MyTransferFunction”, and makes it available in the Simulink library.

>

(CSFcn,MBlock):=Simulink(sys2,sys2:-inputvariable,sys2:-outputvariable,"MyTransferFunction",parameters=params):

SaveCode(“MyTransferFunction”,cSFcn,extension=”c”,interactive=true):

SaveCode(“MyTransferFunction”,MBlock,extension=”m”,interactive=true):

 

Example 2. Build a Simulink block for the ode, where u(t) represents the input of the block and y(t) is the output.  

>

with(Connectivity);
par:=[m=5,b=2,k=3];
ic:=[y(0)=2,(D(y))(0)=0];
de:=m*(diff(y(t),t,t))+b*(diff(y(t),t))+k*y(t)=u(t);
sys1:=DynamicSystems:-DiffEquation(de,inputvariable=[u(t)],outputvariable=[y(t)]);
ResponsePlot(sys1,Step(),parameters=par);

 

[[[Typesetting:-mi( 

 

`:=`(par, [m = 5, b = 2, k = 3]) 

 

`:=`(ic, [y(0) = 2, (D(y))(0) = 0]) 

 

`:=`(de, `+`(`*`(m, `*`(diff(y(t), t, t))), `*`(b, `*`(diff(y(t), t))), `*`(k, `*`(y(t)))) = u(t)) 

 

module () export de, inputcount, outputcount, statecount, sampletime, discrete, systemname, inputvariable, outputvariable, statevariable, systemtype, ModulePrint; end module 

 

Plot_2d

 

Please see the Connectivity Toolbox Help pages for more detailed information. 

Example 3. Build a Simulink block for the two ode's: 

 

 

 

 

where u[1](t), represent two inputs of the block and y[1](t) and are the two outputs.  

>

par:=[m=5,b=2,k=3];
ic:=[y1(0)=2,(D(y1))(0)=0,y2(0)=2,(D(y2))(0)=0];
de:=[m*(diff(y1(t),t,t))+b*(diff(y1(t)+y2(t),t))+k*y1(t)=u1(t),m*(diff(y2(t),t,t))+b*(diff(y1(t),t))+k*y2(t)=u2(t)];
sys2:=DynamicSystems:-DiffEquation(de,inputvariable=[u1(t),u2(t)],outputvariable=[y1(t),y2(t)]);
ResponsePlot(sys2,[Step(),2*Step()],parameters=par);

 

`:=`(par, [m = 5, b = 2, k = 3]) 

 

`:=`(ic, [y1(0) = 2, (D(y1))(0) = 0, y2(0) = 2, (D(y2))(0) = 0]) 

 

`:=`(de, [`+`(`*`(m, `*`(diff(y1(t), t, t))), `*`(b, `*`(`+`(diff(y1(t), t), diff(y2(t), t)))), `*`(k, `*`(y1(t)))) = u1(t), `+`(`*`(m, `*`(diff(y2(t), t, t))), `*`(b, `*`(diff(y1(t), t))), `*`(k, `*`...
`:=`(de, [`+`(`*`(m, `*`(diff(y1(t), t, t))), `*`(b, `*`(`+`(diff(y1(t), t), diff(y2(t), t)))), `*`(k, `*`(y1(t)))) = u1(t), `+`(`*`(m, `*`(diff(y2(t), t, t))), `*`(b, `*`(diff(y1(t), t))), `*`(k, `*`... 

 

module () export de, inputcount, outputcount, statecount, sampletime, discrete, systemname, inputvariable, outputvariable, statevariable, systemtype, ModulePrint; end module 

 

Plot_2d

 

Please see the Connectivity Toolbox Help pages for more detailed information. 

 

 MapleSim

Please note that you must have Maple 12.0.2 or later to run MapleSim models.

Example 13.  An acausal representation of an electrical RL circuit:

Chaps18_25.jpg

Example 13.  A causal representation of an electrical RL circuit:

Chaps18_26.jpg

Example 14. Causal and acausal representations of a mass-spring damper (from the MapleSim Help pages):

Chaps18_27.jpg

Example 15. The Rössler system:

Chaps18_28.jpg

 

End of Chapter 18 Commands