Modifying systems


Built-in models enable to build fast predefined models to use later in simulations.

Modifying using the setter functions

It is possible to set the content of the fields “input”, “output”, “states”, as well as the field “params”.

Here is a simple model

>> name = 'sys';
>> timestep = 0;
>> amats = cell(3,3);
>> bmats = cell(3,3);
>> cmats = cell(3,3);
>> dmats = cell(3,3);
>> amats{1,1} = -(sym('OMEGA'));
>> amats{2,2} = -2;
>> amats{3,3} = [0 1 ; -0.05 -0.01];
>> amats{3,1} = [-1;-3];
>> bmats{1,1} = 1;
>> bmats{2,2} = 2;
>> bmats{3,3} = 3*eye(2);
>> cmats{1,1} = 1;
>> cmats{2,2} = 1;
>> cmats{3,3} = eye(2);
>> dmats{1,3} = [6 6];
>> dmats{2,1} = 6;
>> dmats{3,2} = [6;6];
>> sys = ssm(plist( ...
'amats',amats, 'bmats',bmats, 'cmats',cmats, 'dmats',dmats, ...
'timestep',timestep, 'name',name));
>> sys.setParams(plist({'OMEGA', 'system frequency'}, 2))
M: running ssm/ssm
M: running ssmFromDescription
M: running validate
M: running ssm/setParams
M: running display
------ ssm/1 -------
amats: { [1x1] [] [] 
[] [1x1] [] 
[2x1] [] [2x2] } [3x3]
mmats: { [1x1] [] [] 
[] [1x1] [] 
[] [] [2x2] } [3x3]
bmats: { [1x1] [] [] 
[] [1x1] [] 
[] [] [2x2] } [3x3]
cmats: { [1x1] [] [] 
[] [1x1] [] 
[] [] [2x2] } [3x3]
dmats: { [] [] [1x2] 
[1x1] [] [] 
[] [2x1] [] } [3x3]
timestep: 0
inputs: [1x3 ssmblock]
1 : input 1 | input 1 > 1 []
2 : input 2 | input 2 > 1 []
3 : input 3 | input 3 > 1 [], input 3 > 2 []
states: [1x3 ssmblock]
1 : state 1 | state 1 > 1 []
2 : state 2 | state 2 > 1 []
3 : state 3 | state 3 > 1 [], state 3 > 2 []
outputs: [1x3 ssmblock]
1 : output 1 | output 1 > 1 []
2 : output 2 | output 2 > 1 []
3 : output 3 | output 3 > 1 [], output 3 > 2 []
params: (OMEGA=2) [1x1 plist]
version: $Id$
Ninputs: 3
inputsizes: [1 1 2]
Noutputs: 3
outputsizes: [1 1 2]
Nstates: 3
statesizes: [1 1 2]
Nparams: 1
isnumerical: false
hist: ssm.hist [1x1 history]
procinfo: (empty-plist) [1x1 plist]
plotinfo: (empty-plist) [1x1 plist]
name: sys
description: 
mdlfile: 
UUID: 227fd0a2-1de0-4e01-855f-d0548e1eb1ff
--------------------



In then we set the names and descriptions of the input blocks, the names, descriptions and units of the port variables:

>> sys.setBlockNames(plist('field', 'inputs', 'blocks', [1 2 3], 'names', {'myinput1','myinput2','myinput3'} ));
>> sys.setBlockDescriptions(plist('field', 'inputs', 'blocks', {'myinput1'}, 'descriptions',{'myinput1 description'} ));
>> sys.setPortNames(plist('field', 'inputs', 'block', {'myinput3'}, 'ports', [1 2], 'names',{'my port 3-1' 'my port 3-2'} ));
>> sys.setPortDescriptions(plist('field', 'inputs', 'block', {'myinput3'}, 'ports', [1 2], 'descriptions',{'first description' 'second description'} ));
>> sys.setPortUnits(plist('field', 'inputs', 'block', {'myinput3'}, 'ports', [1 2], 'units', [unit('kg m^-2') unit('m')] ));
>> sys.inputs
M: running ssm/setBlockNames
M: running ssm/setBlockDescriptions
M: running ssm/setPortNames
------ ssmport/1 -------
name: my port 3-1
units: [] [1x1 unit]
description: 
version: $Id$
------------------------
------ ssmport/2 -------
name: my port 3-2
units: [] [1x1 unit]
description: 
version: $Id$
------------------------
M: running ssm/setPortDescriptions
------ ssmport/1 -------
name: my port 3-1
units: [] [1x1 unit]
description: first description
version: $Id$
------------------------
------ ssmport/2 -------
name: my port 3-2
units: [] [1x1 unit]
description: second description
version: $Id$
------------------------
M: running ssm/setPortUnits
------ ssmblock/1 -------
name: myinput1
ports: input 1 > 1 [] [1x1 ssmport]
description: myinput1 description
version: $Id$
-------------------------
------ ssmblock/2 -------
name: myinput2
ports: input 2 > 1 [] [1x1 ssmport]
description: 
version: $Id$
-------------------------
------ ssmblock/3 -------
name: myinput3
ports: my port 3-1 [kg m^(-2)], my port 3-2 [m] [1x2 ssmport]
description: 
version: $Id$
-------------------------

Modifying the parameter values

Once the parameter field “params” is set, one may want to set or modify (like in an optimizer) the parameter values. This is done by the functions “*Parameters.m”. The function setParameters takes two inputs ('setnames' and 'setvalues') which are the names of the parameters to modify and the values assigned to them.

>> sys.params
>> sys.setParameters('OMEGA', 0.002);
>> sys.params
----------- plist 01 -----------
n params: 1
---- param 1 ----
key: OMEGA
val: 2
desc: system frequency
-----------------
description: 
UUID: 84ff1ed8-eee2-406c-89d8-7e6e703d36dd
--------------------------------
M: running setParameters
M: running ssm/ssm
----------- plist 01 -----------
n params: 1
---- param 1 ----
key: OMEGA
val: 0.002
desc: system frequency
-----------------
description: 
UUID: 84ff1ed8-eee2-406c-89d8-7e6e703d36dd
--------------------------------

The function subsParameterskeep and Parameters substitute numerical values to the symbolic expressions, using a list of the parameters to substitute (or its complementary). All parameters substituted are removed from the “params” field. The call <system>.keepParameters substitues all the parameters. The field isnumerical is then set to 1, unless a parameter in the matrices was forgotten in the params field.

>> sys.keepParameters;
>> sys.params
>> sys.isNumeric

M: running keepParameters
----------- plist 01 -----------
n params: 0
description: 
UUID: 84ff1ed8-eee2-406c-89d8-7e6e703d36dd
--------------------------------
ans =
1

Modifying the inputs/states/outputs

Les us first build a simple system constituted of four parallel 1st order systems.

>> name = 'sys';
>> timestep = 0;
>> amats = {diag([-1 -2 -3 -4])};
>> bmats = {diag([1 2 0 0])};
>> cmats = {[diag([1 0 3 0]) ; [0 0 0 0 ]]};
>> dmats = {[diag([0 0 0 0]) ; [0 0 0 0 ]]};
>> sys = ssm(plist( ...
'amats',amats, 'bmats',bmats, 'cmats',cmats, 'dmats',dmats, ...
'timestep',timestep, 'name',name));
It is possible to obtain the structural realization of the system using sMinReal. This function deletes states which are either not observable or controllable. However, there may still exist such linear combinations of states.
The process only modify the states, here the 2nd and 4rt states disappear since they are not observable, and the 3rd and 4th disappear since they are not controllable.
>> sys.sMinReal
M: running ssm/ssm
M: running ssmFromDescription
M: running validate
M: running ssm/sMinReal
M: running display
------ ssm/1 -------
amats: { [1x1] } [1x1]
mmats: { [1x1] } [1x1]
bmats: { [1x4] } [1x1]
cmats: { [5x1] } [1x1]
dmats: { [] } [1x1]
timestep: 0
inputs: [1x1 ssmblock]
1 : input 1 | input 1 > 1 [], input 1 > 2 [], input 1 > 3 [], input 1 > 4 []
states: [1x1 ssmblock]
1 : state 1 | state 1 > 1 []
outputs: [1x1 ssmblock]
1 : output 1 | output 1 > 1 [], output 1 > 2 [], output 1 > 3 [], output 1 > 4 [], output 1 > 5 []
params: (empty-plist) [1x1 plist]
version: $Id$
Ninputs: 1
inputsizes: 4
Noutputs: 1
outputsizes: 5
Nstates: 1
statesizes: 1
Nparams: 0
isnumerical: true
hist: ssm.hist [1x1 history]
procinfo: (empty-plist) [1x1 plist]
plotinfo: (empty-plist) [1x1 plist]
name: sys
description: 
mdlfile: 
UUID: 349cd9c4-ad91-4151-b542-63d34b01bed8
--------------------

Then we can work on the input/outputs to simplify the model.

The user must specify which block variable he want to keep, and three syntaxes are allowed.

This syntax is also used for any converter to select the inputs and outputs in the ssm.

It is important to note that this removes lines and columns in the system's matrices, but no parameters are removed. So second order parameters that should be remove (by setting them to a neutral value) must be taken care of separately.

>> sys.simplify(plist('inputs', {[1 2]} , 'states', 'ALL' , 'outputs', { 'output 1 > 1' 'output 1 > 4'}))
M: running ssm/simplify
M: running ssm/ssm
M: running ssm/simplify
M: running display
------ ssm/1 -------
amats: { [1x1] } [1x1]
mmats: { [1x1] } [1x1]
bmats: { [1x2] } [1x1]
cmats: { [2x1] } [1x1]
dmats: { [] } [1x1]
timestep: 0
inputs: [1x1 ssmblock]
1 : input 1 | input 1 > 1 [], input 1 > 2 []
states: [1x1 ssmblock]
1 : state 1 | state 1 > 1 []
outputs: [1x1 ssmblock]
1 : output 1 | output 1 > 1 [], output 1 > 4 []
params: (empty-plist) [1x1 plist]
version: $Id$
Ninputs: 1
inputsizes: 2
Noutputs: 1
outputsizes: 2
Nstates: 1
statesizes: 1
Nparams: 0
isnumerical: true
hist: ssm.hist [1x1 history]
procinfo: (empty-plist) [1x1 plist]
plotinfo: (empty-plist) [1x1 plist]
name: sys
description: 
mdlfile: 
UUID: 8e55110a-eb07-44d2-aaee-4f839a5fb155
--------------------



©LTP Team