Lecture 6 - State-Space Systems in Matlab: (T) A (T) + B (T) X X U C + D y X U
Lecture 6 - State-Space Systems in Matlab: (T) A (T) + B (T) X X U C + D y X U
Lecture 6
ae2204 Aerospace Systems and Control Theory
One of the obvious advantages of a state-space representation is that it can describe systems with multiple
inputs and multiple outputs (MIMO). When working with Matlab or Python, a state-space description of a
system is often the preferred starting point for controller design and analysis. The system to be controlled is
modelled as a state-space system, and as additional control loops are tuned, the state-space system is
extended to include these control loops.
The first step is of course getting a system into Matlab or Python, and that is easiest when the system is
given.
˙
x (t) = A x (t) + B u (t)
− − −
y = C x + Du
− − −
Right, A, B, C and D.
OK, so let's enter a state-space system, and start with entering the a, b, c and d matrices. Matlab variant first:
a = [ 0 1 0 ; ...
-0.0071 -0.111 0.12; ...
0 0.07 -0.3]
b = [ 0 ; -0.095; 0.072]
c = [ 1 0 0 ]
d = [ 0 ]
Remember the three dots for Matlab ...? These indicate that the statement continues on the next line. Now
the Python variant:
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 1/33
6/30/2020 Practicon Exercise System TU Delft
import numpy as np
from control.matlab import *
a = np.matrix(""" 0 1 0 ;
-0.0071 -0.111 0.12;
0 0.07 -0.3""")
b = np.matrix(""" 0 ; -0.095; 0.072""")
c = np.matrix(""" 1 0 0 """)
d = np.matrix(""" 0 """)
T
This, incidentally, is the state-space equation for a submarine. The state vector contains: x = [θ, q, α] .
−
Here θ is the pitch attitude of the submarine, q is the pitch rate (rotation rate around its y axis), α is the angle
of attack (angle between the nose and the velocity vector). The input vector has one element, the elevator
(control surface) deflection u = [δe ] . You can imagine that without this information, your set of state matrices
−
is essentially useless, so always document what you are doing!
Creating a state-space system is simple, and exactly the same for both Matlab and Python:
sys = ss(a, b, c, d)
As long as you do not specify a time step as 5th parameter, Matlab will assume that you are creating a
continuous-time system. If you enter a time step as 5th parameter, Matlab assumes you are entering a
discrete-time system. For a discrete-time system, the state equation changes to:
With Δt as the time step for the discrete-time system. However, in this course we will only discuss
continuous-time systems.
Of course, the dimensions of the matrices you enter must fit; B must have as many rows as A, A must be a
square matrix, C must have as many columns as A, and the D matrix must have as many columns as B and as
many rows as C.
If you make a mistake there, Matlab will spit out something like the following:
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 2/33
6/30/2020 Practicon Exercise System TU Delft
>
The fun of a state-space system begins when you have multiple inputs or outputs. Now we have attitude of
the submarine as output, but in this system, it is of interest also to look at the pitch rate, the angle of attack
and particularly the climb or descent angle, γ .
γ = θ − α
θ
⎡ ⎤
⎢ q ⎥
y = ⎢ ⎥
− ⎢ α⎥
⎣ ⎦
γ
For the last element in the output vector we use the relationship outlined above, and since θ and α are part of
the state vector, a new c matrix can be defined:
In Python variant:
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 3/33
6/30/2020 Practicon Exercise System TU Delft
Here the mass m is 3.5 [kg], the damping coefficient b = 9[Ns/m] and the spring coefficient is
k = 60[N/m] . The input is the force on the mass, as outputs the position y, the velocity dy/dt and the
My suggested approach is to take a piece of paper, write down the differential equations governing this
system, convert them to a state-space form and enter that in Matlab or Python.
Note: to enter the numerical matrix values, enter them as you would in Matlab, or as you would enter them in
a Python matrix, e.g.
A = [ 1 0; 0 4]
or
Your answer
Enter the A, B, C and D matrices of this state-space system
A = [ 0 1; -17.1428 -2.5714 ]
B = [ 0 ; 0.2857 ]
C = [ 1 0; 0 1; -17.1428 -2.5714 ]
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 4/33
6/30/2020 Practicon Exercise System TU Delft
D = [ 0; 0; 0.2857 ]
B = [ 0.28571429;
0.0 ]
C = [ 0.0, 1.0;
1.0, 0.0;
-2.5714286, -17.142857 ]
D = [ 0.0;
0.0;
0.28571429 ]
Explanation / script
ÿ m = F − bẏ − ky
Apparently you can calculate the acceleration of the mass. You can set this equal to the derivative of a
state vector element; ÿ = x˙1 , or ẏ = x1 . You can use the above equation for both the state equation,
and for the output equation.
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 5/33
6/30/2020 Practicon Exercise System TU Delft
Now, at this point you have ẏ = x1 in the state vector. In the equation given above, you see that you
need y to calculate ÿ . And since you already have its derivative (ẏ = x1 ), you can simply add y = x2
to the state vector.
Feedback
Very good, a perfect score.
Simple Newtonian mechanics tells you that:
ÿ m = F − bẏ − ky
In order to put an element in the state vector x , it must be possible to calculate its derivative with the
−
elements in the state vector and the input vector. The velocity of the mass, ẏ can be put in the state vector
because we can calculate its derivative (i.e., the derivative of ẏ , being ÿ ) with the equation given above. This
calculation uses F (in the input vector), y and ẏ , that both must be in the state vector.
˙1
x −b/m −k/m x1 1/m
˙
x = [ ] = [ ][ ] + [ ] u
− −
˙2
x 1 0 x2 0
0 1 0
⎡ ⎤ ⎡ ⎤
y = ⎢ 1 0 ⎥ x + ⎢ 0 ⎥ u
− − −
⎣ ⎦ ⎣ ⎦
−b/m −k/m 1/m
Note that the last equation simply copies the first line of the state equation; acceleration of the mass is also
calculated there.
Note that this can be done in many more variations; x1 and x2 may be interchanged, and other variants are
possible.
The solution in Matlab then becomes (note that this is only one of the infinitely many example solutions
possible):
clear
% parameter values
m = 3.5
b = 9
k = 60
% matrices
A = [ -b/m -k/m; 1 0]
B = [ 1/m; 0]
C = [ 0 1; 1 0; -b/m -k/m]
D = [ 0; 0; 1/m]
% system
sys = ss(A, B, C, D)
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 6/33
6/30/2020 Practicon Exercise System TU Delft
import numpy as np
from control.matlab import *
# parameter values
m = 3.5
b = 9
k = 60
# matrices
A = np.matrix([[ -b/m, -k/m], [ 1, 0]])
B = np.matrix([[ 1/m], [ 0]])
C = np.matrix([[ 0, 1], [ 1, 0], [ -b/m, -k/m]])
D = np.matrix([[ 0], [ 0], [ 1/m]])
# to continue, and make the system
sys = ss(A, B, C, D)
clear
% parameter values
m = 3.5
b = 9
k = 60
% matrices
A = [ -b/m -k/m; 1 0]
B = [ 1/m; 0]
C = [ 0 1]
D = [ 0 ]
% system
sys = ss(A, B, C, D)
import numpy as np
from control.matlab import *
# parameter values
m = 3.5
b = 9
k = 60
# matrices
A = np.matrix([[ -b/m, -k/m], [ 1, 0]])
B = np.matrix([[ 1/m], [ 0]])
C = np.matrix([[ 0, 1]])
D = np.matrix([[ 0]])
# system
sys = ss(A, B, C, D)
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 7/33
6/30/2020 Practicon Exercise System TU Delft
You might notice that in comparison with the model answer for the previous question, the C and D matrices
are now only one row; this state-space system only has the position as output. This is quite common,
depending on what outputs you want to study, you can trim or adapt the C and D matrices.
You can get a response to an initial condition, an initial state of the state-space system. The state vector of
T
the model solution given above contains the velocity and position of the mass as states; x = [ẏ , y] . Try
−
to calculate and plot the response to an initial state of ẏ = 1 and y = 0, with the input F = 0. Calculate and
plot this response, plot only the position. Try to figure out the time step you need for this (look at the
eigenfrequencies, as discussed in the introduction).
If you look at the plot, you see that the system response oscillates several times before the output returns to
zero. The frequency of this oscillation is called the "damped eigenfrequency". Zoom in if necessary, and
determine the oscillation period of the system, i.e. the duration of a single oscillation.
Your answer
What is the oscillation period (in seconds) of the response? 1.596485
When using python and control, the lsim command in the control.matlab module can do the trick. In this
case enter:
Feedback
Very good, a perfect score.
The command initial calculates the response to initial conditions. The first element of our example solution
for the state equation (in your solution it might be the second) contains the velocity.
This gives the system from the previous question, with only the position as output:
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 8/33
6/30/2020 Practicon Exercise System TU Delft
clear
% parameter values
m = 3.5
b = 9
k = 60
% matrices
A = [ -b/m -k/m; 1 0]
B = [ 1/m; 0]
C = [ 0 1]
D = [ 0]
% system
sys = ss(A, B, C, D)
x0 = [1; 0]
t = 0:0.01:20;
y = initial(sys, x0, t);
plot(t, y)
Since you need the accuracy for your answer, pick a fairly precise time step. 0.01 [s] should do it.
import numpy as np
from control.matlab import *
from matplotlib.pyplot import plot, show
# parameter values
m = 3.5
b = 9
k = 60
# matrices
A = np.matrix([[ -b/m, -k/m], [ 1, 0]])
B = np.matrix([[ 1/m], [ 0]])
C = np.matrix([[ 0, 1]])
D = np.matrix([[ 0]])
# system
sys = ss(A, B, C, D)
Verify that what you see in the plot matches what you can expect from the assignment; you should be able to
see that the derivative is ẏ (0) = 1 (from the slope!), and y(0) = 0 .
Now read off the period. See the example plot for that (NOTE that this plot is only an example, it might have
been generated with different parameters!) The frequency with which the system oscillates is called the
damped eigenfrequency. This will return in Lecture 7.
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 9/33
6/30/2020 Practicon Exercise System TU Delft
Resonance
Now, I have an additional thing for you to find out. You have (I hope) observed that the system's response to
an initial condition looks like a decaying sine function. What would happen if we "excite" the system, by also
giving it a sine function as input?
Create two sine functions as input, one of a frequency 3.9357078 radians per second (corresponding to the
solution from the previous question), and one with a slightly lower frequency of 3.7197762 [rad/s], use an
amplitude of 1 for the sine functions. Take at least 20 seconds, calculate the response of the system and plot.
Then determine the amplitude of the sine function you get out of the system.
Note that the response has to start up, this is called the "transient", but you see that after some (simulated)
time the sine response achieves a constant amplitude.
Your answer
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 10/33
6/30/2020 Practicon Exercise System TU Delft
What is the amplitude of the response to the sine function with a frequency
0.02786
of 3.9357078 [rad/s]?
What is the amplitude of the response to the sine function with a frequency
0.02823
of 3.7197762 [rad/s]?
Feedback
Very good, a perfect score.
Now, I hope you observed that the strongest response to a sine signal occurred for sine signals with a slightly
lower frequency than the "damped eigenfrequency", the frequency by which the system naturally oscillates
when excited.
This second, slightly lower, frequency was the "resonance frequency", if you feed the system with a sine
signal it responds strongest to a sine signal at that frequency. This will come back in Lecture 11.
Now, in case you did not manage to (completely) get the correct responses out, an example script.
clear
% parameter values
m = 3.5
b = 9.0
k = 60.0
% matrices
A = [ -b/m -k/m; 1 0]
B = [ 1/m; 0]
C = [ 0 1]
D = [ 0]
% system
sys = ss(A, B, C, D)
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 11/33
6/30/2020 Practicon Exercise System TU Delft
import numpy as np
from control.matlab import *
from matplotlib.pyplot import plot, show
# parameter values
m = 3.5
b = 9.0
k = 60.0
# matrices
A = np.matrix([[ -b/m, -k/m], [ 1, 0]])
B = np.matrix([[ 1/m], [ 0]])
C = np.matrix([[ 0, 1]])
D = np.matrix([[ 0]])
# system
sys = ss(A, B, C, D)
w1 = 3.9357078
w2 = 3.7197762
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 12/33
6/30/2020 Practicon Exercise System TU Delft
Now is a good time to experiment a little. What would happen to the system's response if you increase (for
example double) the mass m of the block? And what happens if you increase the stiffnes k? And what
happens if you increase the damping b?
Your answer
When the stiffness is increased, the oscillations of the initial condition response have a shorter period.
When the damping is increased, oscillations of the initial condition response die out earlier.
When the mass is increased, the oscillations of the initial condition response have a larger period.
Feedback
Very good, a perfect score.
I guess again that the handywork should not be a problem. Here is a file with the Matlab commands to plot all
these figures
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 13/33
6/30/2020 Practicon Exercise System TU Delft
clear
% parameter values
m = 3
b = 6
k = 20
% matrices
A = [ -b/m -k/m; 1 0]
B = [ 1/m; 0]
% C and D to only plot position
C = [ 0 1]
D = [ 0]
% base system
sys = ss(A, B, C, D)
% increased mass
m = 2*m; A = [ -b/m -k/m; 1 0]; B = [ 1/m; 0]; m = m / 2;
sys_2m = ss(A, B, C, D)
% increased stiffness
k = 2*k; A = [ -b/m -k/m; 1 0]; B = [ 1/m; 0]; k = k / 2;
sys_2k = ss(A, B, C, D)
% increased damping
b = 2*b; A = [ -b/m -k/m; 1 0]; B = [ 1/m; 0]; b = b / 2;
sys_2b = ss(A, B, C, D)
% responses
x0 = [1; 0]
t = 0:0.01:10;
y = initial(sys, x0, t);
y_2m = initial(sys_2m, x0, t);
y_2k = initial(sys_2k, x0, t);
y_2b = initial(sys_2b, x0, t);
% plotting
figure; plot(t', [y y_2m])
figure; plot(t', [y y_2k])
figure; plot(t', [y y_2b])
You can observe that increasing the mass makes oscillations in the response slower, increasing the stiffness
makes the oscillations faster, and increasing the damping makes the oscillations die out more quickly.
Python variant:
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 14/33
6/30/2020 Practicon Exercise System TU Delft
import numpy as np
from control.matlab import *
from matplotlib.pyplot import plot, show, figure, title
# parameter values
m = 3.0
b = 9.0
k = 60.0
# matrices
A = np.matrix([[ -b/m, -k/m], [ 1, 0]])
B = np.matrix([[ 1/m], [ 0]])
C = np.matrix([[ 0, 1]])
D = np.matrix([[ 0]])
# base system
sys = ss(A, B, C, D)
# increased mass
m = 2*m;
A = [[ -b/m, -k/m], [ 1, 0]]
B = [[ 1/m], [ 0]]
m = m / 2;
sys_2m = ss(A, B, C, D)
# increased stiffness
k = 2*k
A = [[ -b/m, -k/m], [ 1, 0]]
B = [[ 1/m], [ 0]]
k = k / 2;
sys_2k = ss(A, B, C, D)
# increased damping
b = 2*b
A = [[ -b/m, -k/m], [ 1, 0]]
B = [[ 1/m], [ 0]]
b = b / 2;
sys_2b = ss(A, B, C, D)
x0 = [1, 0]
y, tdum = initial(sys, X0=x0, T=t)
y_2m, tdum = initial(sys_2m, X0=x0, T=t)
y_2k, tdum = initial(sys_2k, X0=x0, T=t)
y_2b, tdum = initial(sys_2b, X0=x0, T=t)
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 15/33
6/30/2020 Practicon Exercise System TU Delft
In the above case, we converted a single-input, single output state-space system to a transfer function. Such
a system fits in a single transfer function. What happens if we convert a multi-input, multi-output state-space
model to transfer function form?
It appears that h is still of type tf, so, a transfer function. By looking at h.num and h.den you can see that
Matlab gives a "cell array", with two rows, one row for each output, and three columns, one column per input.
In most cases however, we want to look at a single-input, single-output transfer function. How do we select a
single output and a single input from h?
There are of course several ways to do this. One is selecting the proper elements from h.num and h.den, and
using these in a tf call in Matlab:
Another method is more dashing. Think of h as a 2 rows (two outputs) by 3 columns (3 inputs) transfer
function matrix. If you pre-multiply that with a 2 column, one row transfer function, you get a single output,
three input transfer function matrix, so one row and 3 columns. And a simple matrix can substitute for a
"transfer function" that consists of only a gain:
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 16/33
6/30/2020 Practicon Exercise System TU Delft
In other words, it works just like matrix multiplication. The equivalent with normal matrix multiplication would
be:
>> m = [ 1 2 3; ...
4 5 6]
m =
1 2 3
4 5 6
>> firstrow = [1 0] * m
firstrow =
1 2 3
So, now to get the first output in response to (for example) the second input as a single transfer function from
h, we can do:
h11 = [1 0] * h * [0; 1; 0]
The nice thing about this method is that it also functions for a state-space system. Apply these multiplications
and you get a single-input, single output state-space system, that is equivalent to h11. I suggest you try and
check this:
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 17/33
6/30/2020 Practicon Exercise System TU Delft
h = tf(sys)
print h
print h.__class__
In Python:
Now you saw that a multi-input, multi-output state-space system can be converted into a multi-input, multi-
output transfer function. Matlab makes "single" transfer function object, that has a cell array with numerator
polynomials, and a cell array with denominator polynomials. However, Matlab functions equally well with a
matrix of (individual) transfer functions. So you can do:
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 18/33
6/30/2020 Practicon Exercise System TU Delft
When you convert this to state-space, it creates a state-space system with one input and two outputs. Matlab
is clever enough to see that the denominators of the two transfer functions in h2 are the same, and efficiently
combine these transfer functions in the A matrix.
Enter the following state-space system with two outputs and one input, and convert it to two different transfer
functions, one giving the first system output, and the other giving the second system output.
A = [ -1.9 0 0; ...
0.4 -1.2 -5.0; ...
0 1 0]
B = [ 0.3; 0; 0]
C = [ 0 1 0; ...
0.1 0 1]
D= zeros(2,1)
A = [ [ -1.9, 0, 0 ],
[ 0.4, -1.2, -5.0],
[ 0, 1, 0 ] ]
B = [ [0.3 ], [0 ], [0 ] ]
C = [ [0, 1, 0 ],
[0.1, 0, 1 ]]
D= [ [0],
[0] ]
Your answer
What is the order of the numerator of the first transfer function? 1
What is the value of the real pole of the transfer functions? -1.9
What is the value of the real pole of the transfer functions? -1.9
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 19/33
6/30/2020 Practicon Exercise System TU Delft
Explanation / script
A = [ -1.9 0 0; ...
0.4 -1.2 -5.0; ...
Feedback
Try to figure out what went wrong!
The procedure for this is pretty straightforward, use tf to convert the state-space system, inspect it and
determine the roots of the transfer function.
A = [ [-2, 0, 0 ],
[ 0.4, -1.2, -5.0],
[ 0, 1, 0 ] ]
B = [ [0.3 ], [0 ], [0 ] ]
C = [ [0, 1, 0 ],
[0.1, 0, 1 ]]
D= [ [0],
[0] ]
sys = ss(A, B, C, D)
H = tf(sys)
print(H)
roots(H.den[0][0])
You can see that the denominators of the two transfer functions are identical, while the numerators are
different. Matlab converts the state-space system to a set of transfer functions, one for each input-output
combination. Switching the rows in the C matrix will produce similar output, only with the numerators
switched.
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 20/33
6/30/2020 Practicon Exercise System TU Delft
When the D-matrix contains non-zero elements, this is called "direct feedthrough". Signals in the input vector
u are then directly added to the output vector y .
− −
Can you guess what happens to the numerators of the transfer functions if the D matrix contains non-zero
elements?
Take the following transfer function, and convert it into a state-space system. The state-space system should
have two outputs, one is the output of the transfer function, and the second output is the derivative of the first
output.
2
b0 + b1 s + b2 s
H (s) =
2 3
a0 + a1 s + a2 s + a3 s
Here:
b0 = 0.2
b1 = 0.1
b2 = 0.5
a0 = 2.3
a1 = 6.3
a2 = 3.6
a3 = 1.0
Your answer
Enter the A, B, C and D matrices of this state-space system
A=[ 0 0 -1.1500; 1.0000 0 -3.1500; 0 2.0000 -3.6000]
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 21/33
6/30/2020 Practicon Exercise System TU Delft
C=[ 002 ]
D = [ 0 0.5 ]
B = [ -0.85522796;
-0.096781514;
0.14737188 ]
D = [ 0.0;
0.5 ]
Explanation / script
b0 = 0.2;
b1 = 0.1;
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 22/33
6/30/2020 Practicon Exercise System TU Delft
Feedback
Try to figure out what went wrong!
The procedure for this is quite simple. First enter the transfer function. Then to get also the velocity out, a set
of transfer functions needs to be converted, note that by multiplying a function by s in the Laplace domain, so
H (s) ∗ s, is equivalent to differentiation in the time domain. By putting the transfer functions in a vector, and
then converting, Matlab nicely combines the two transfer functions into a single state-space system. I would
advise you to always check the conversion; a 3rd order transfer function should result in a 3rd order state-
space system, and thus a 3 by 3 A matrix.
You might see a difference between the model output given below, and the answer you got; state-space
systems can be created in infinitely many ways. As a safety check, you can verify that the A matrix
eigenvalues are equal to the transfer function poles:
eig(sys.A)
roots(h.den{1})
Python variant:
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 23/33
6/30/2020 Practicon Exercise System TU Delft
# convert to state-space
sys = ss(H)
print(eig(sys.A)[0])
print(h.pole())
Consider the following example of the control of a single axis with a satellite attitude control system for a rigid-
body satellite:
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 24/33
6/30/2020 Practicon Exercise System TU Delft
The attitude of a satellite is controlled with a reaction wheel. This wheel generates a torque Tw on the
satellite, and, obeying Newton's third law, the torque on the wheel will be −Tw . As the torque wheel exerts a
torque on the satellite, it will also increase its own momentum hw . From the diagram you can see that
momentum is nothing more than integrated torque!
This system has two inputs; one is the reference attitude for the satellite, and the other is a disturbing torque
on the satellite. Several signals in this system are of interest as output signals; first of all there is the output
from the controller (ycntrl ), which is in the form of a command to the torque wheel. Then there is the actual
torque on the satellite. It is also interesting to know the state of the torque wheel, observing the signal hw
which is the momentum currently stored in the torque wheel. Finally, one would like to know the attitude of the
satellite (θ ) and the error signal (θc − θ) is an important measure for the performance of our controller.
To create a state-space system for this diagram, it is best to work with the individual transfer functions,
transform these to state-space systems, and then combine these.
K (s + 0.01)
Hc (s) =
s
You may observe that the order of the numerator is equal to the order of the denominator. Conversion of a
transfer function into a state-space system is discussed in Chapter 3 of Nise's book, and that includes cases
where order of the numerator and denominator are equal. However, that is a recipe that must be learned by
heart. We can also take a simple a simple approach, and re-write the transfer function as a new transfer
function where the numerator order m is smaller than the denominator order n, and a simple gain:
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 25/33
6/30/2020 Practicon Exercise System TU Delft
In this diagram, for the transfer function of the part of the controller that we just split off (K 0.01/s), the order
of the numerator is smaller than the order of the denominator, and this transfer function can be easily
converted to a state-space system.
Let's gather some fodder for the state equation; the new block with the gain $K$ only contains an algebraic
relation, and does not end up in the state equation. If we call the output of the new block with the transfer
function for part of the controller we just created x1 , then the derivative of x1 is given by:
ẋ 1 = 0.01K (θc − θ)
Call the output of the −1/s block in the reaction wheel assembly x2 = hw , then:
−1
ẋ 2 = (x 1 + K (θc − θ) + x 2 )
τ
˙
The satellite dynamics are second order; this needs two states, x3 = θ :
1 1
ẋ 3 = (T d + (x 1 + K (θc − θ) + x 2 ))
I2 τ
ẋ 4 = x 3
⎡ 0 0 0 −0.01K ⎤ ⎡ 0.01K 0 ⎤
⎢ −1/τ −1/τ 0 K /τ ⎥ ⎢ −K /τ 0 ⎥
x = ⎢
˙ ⎢
⎥ x + ⎢
⎥ ⎢
⎥ u
⎥
− ⎢ 1/(τ I ) − ⎥−
2
1/(τ I2 ) 0 −K /(τ I2 ) ⎥ ⎢ K /(τ I )
2
1/I2
⎣ ⎦ ⎣ ⎦
0 0 1 0 0 0
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 26/33
6/30/2020 Practicon Exercise System TU Delft
ycntrl 1 0 0 −K K 0
⎡ ⎤ ⎡ ⎤ ⎡ ⎤
This can be entered in Matlab or Python as four matrices (A, B, C and D matrix), and then a state-space
system can be created with ss. This is left as an exercise to you.
If you do enter the matrices, and inspect the resulting system, you will find that one of the eigenvalues is zero.
That eigenvalue is associated with the reaction wheel spinning up. Try testing the system with a step input,
and you will see that it oscillates quite a lot before settling to a new position, it definitely needs some further
tuning!
Your answer
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 27/33
6/30/2020 Practicon Exercise System TU Delft
B = [ 0.6000, 1.0000;
0, 0;
0, 0 ]
C = [ 2.8000, 0, 1.0000 ]
D=[0, 0 ]
B = [ 0.6, 1.0;
0.0, 0.0;
0.0, 0.0 ]
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 28/33
6/30/2020 Practicon Exercise System TU Delft
D = [ 0, 0 ]
Explanation / script
K1 = 2.8;
K2 = 1.7;
Feedback
You scored top marks! Great!
Define the first state variable as the output of the first integrator (seen from left to right), the second state
variable as the output of the block with , and the third state variable as the output of the last integrator in the
row.
Thus:
% fill in variables
K1 = 2.8
K2 = 1.7
K3 = 2.5
K4 = 0.6
A = [ 0 , -K4*K2, -K4*K3; ...
1 , -1 , 0 ; ...
0 , 1 , 0 ]
B = [ K4 1; ...
0 0; ...
0 0]
C = [K1 0 1]
D = [0 0]
% and create the system
sys = ss(A, B, C, D)
Or in Python:
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 29/33
6/30/2020 Practicon Exercise System TU Delft
# fill in variables
K1 = 2.8
K2 = 1.7
K3 = 2.5
K4 = 0.6
Creating a state-space model of this block diagram is also possible using Append and Connect. Using the
following notation:
Note that when using this method, a dummy system (sys8) must be added to process the final summation
point.
In Matlab:
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 30/33
6/30/2020 Practicon Exercise System TU Delft
% Define s variable
s=tf([1,0],[1]);
% fill in variables
K1 = 2.8
K2 = 1.7
K3 = 2.5
K4 = 0.6
% Define systems; the appended system type will the type of the first system
% given. If the following systems do not have a proper form they will be
% transformed automatically
sys1 = ss(K4 * (s/s)); % Multiply with s/s to 'trick' the control module into thinking K4 is
sys2 = ss(1/s);
sys3 = ss(1/(s+1));
sys4 = ss(1/s);
sys5 = K1; % Will be transformed by the append function
sys6 = K2;
sys7 = K3;
sys8 = 1; % Add dummy sys8 in order to sum y4 and y5
sys = append(sys1,sys2,sys3,sys4,sys5,sys6,sys7,sys8);
Q = [1 -6 -7;... % u1 = -y6 - y7
2 1 0;... % u2 = y1
3 2 0;... % u3 = y2
4 3 0;... % u4 = y3
5 2 0;... % u5 = y2
6 3 0;... % u6 = y3
7 4 0;... % u7 = y3
8 4 5]; % u8 = y4 + y5
Or in Python:
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 31/33
6/30/2020 Practicon Exercise System TU Delft
# Define s variable
s=tf([1,0],[1])
# fill in variables
K1 = 2.8
K2 = 1.7
K3 = 2.5
K4 = 0.6
# Define systems; the appended system type will the type of the first system
# given. If the following systems do not have a proper form they will be
# transformed automatically
sys1 = ss(K4 * (s/s)) # Multiply with s/s to 'trick' the control module into thinking K4 is
sys2 = ss(1/s)
sys3 = ss(1/(s+1))
sys4 = ss(1/s)
sys5 = K1 # Will be transformed by the append function
sys6 = K2
sys7 = K3
sys8 = 1 # Add dummy sys8 in order to sum y4 and y5
sys = append(sys1,sys2,sys3,sys4,sys5,sys6,sys7,sys8)
Q = np.matrix([[1,-6,-7], # u1 = -y6 - y7
[2, 1, 0], # u2 = y1
[3, 2, 0], # u3 = y2
[4, 3, 0], # u4 = y3
[5, 2, 0], # u5 = y2
[6, 3, 0], # u6 = y3
[7, 3, 0], # u7 = y3
[8, 4, 5]]) # u8 = y4 + y5
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 32/33
6/30/2020 Practicon Exercise System TU Delft
The state-space representation is a very efficient way of representing system models in CACSD packages
like Matlab.
For simple control systems, you can simply have parallel state space systems by summing them (``+''), put
them in series with multiplication (``*''), or apply the feedbackcommand for feedback loops.
For simple gains, constants or matrices with constants can be used instead of (and mixed with) state-space
systems. In many cases, a (constant) feedback matrix is appropriate, with the number of columns matching
the size of the systems output vector being fed back, and the number of rows matching the size of the input
vector.
When combining sub-systems into a larger system, always try to check your work. You can use the
knowledge that the poles of a transfer function correspond to the eigenvalues of the A matrix of the same
system in state-space form.
In Lecture 8 the construction of more complex state-space system will come back, when we use append and
connect, to flexibly connect any number of state-space systems, representing for example your controller(s),
the actuators, system dynamics and sensors in your control system.
https://practicon.lr.tudelft.nl/practicon/index.html?extauth=1 33/33