Engee documentation
Notebook

Array of models with one variable parameter

This example shows how to create a one-dimensional array of transfer functions. One parameter of the transfer function varies from model to model in the array. You can use such an array to study the effect of varying parameters on your model, for example, for sensitivity analysis.

In [ ]:
import Pkg
Pkg.add("ControlSystems")
In [ ]:
using ControlSystems
s = tf('s');

Create an array of transfer functions representing the following low pass filter at three values of cutoff frequency $a$.

$$ F\left( s \right) = \frac{a}{{s + a}} $$

Create transfer function models representing a filter with cutoff frequencies $a$ = 3, 5, and 7.

In [ ]:
a = [3, 5, 7]

F_array = [ tf([a[i]],[1,a[i]]) for i=1:length(a) ]
Out[0]:
3-element Vector{TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}}}:
 TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}}
  3
-----
s + 3

Continuous-time transfer function model
 TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}}
  5
-----
s + 5

Continuous-time transfer function model
 TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}}
  7
-----
s + 7

Continuous-time transfer function model

The inclusion method allows us to create a vector of transfer functions with a variable parameter.

Let us construct a Bode diagram for F_array.

In [ ]:
bodeplot(F_array)
Out[0]:

When you use analysis commands such as bodeplot for an array of models, the resulting plot shows the response of each model in the array. In this way, you can see the range of responses resulting from parameter changes.

The models from the vector can be combined to produce a MIMO system.

Converting an array of systems into a multidimensional system

We can create a diagonal multidimensional system from the vector of systems using the function append. The result is a system with three inputs and three outputs.

In [ ]:
P1 = append(F_array[1], F_array[2], F_array[3])
Out[0]:
TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}}
Input 1 to output 1
  3
-----
s + 3

Input 1 to output 2
0
-
1

Input 1 to output 3
0
-
1

Input 2 to output 1
0
-
1

Input 2 to output 2
  5
-----
s + 5

Input 2 to output 3
0
-
1

Input 3 to output 1
0
-
1

Input 3 to output 2
0
-
1

Input 3 to output 3
  7
-----
s + 7

Continuous-time transfer function model

Another function array2mimo allows to create a system with one input and three outputs.

In [ ]:
P2 = array2mimo(F_array)
Out[0]:
TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}}
Input 1 to output 1
  3
-----
s + 3

Input 1 to output 2
  5
-----
s + 5

Input 1 to output 3
  7
-----
s + 7

Continuous-time transfer function model

To go back to the array of systems or to get a vector from a MIMO system, you can apply the function getindex.

In [ ]:
sys_array = getindex.(Ref(P2), 1:P2.ny, (1:P2.nu)')
Out[0]:
3×1 Matrix{TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}}}:
 TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}}
  3
-----
s + 3

Continuous-time transfer function model
 TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}}
  5
-----
s + 5

Continuous-time transfer function model
 TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}}
  7
-----
s + 7

Continuous-time transfer function model

Conclusion

We have looked at how to create an array of models with a changing parameter.We also learnt what functions allow you to go from an array to a MIMO system and back again.