We can describe a linear system dynamics using differential equations or using transfer functions. In this post, we will learn how to
1.) Transform an ordinary differential equation to a transfer function.
2.) Simulate the system response to different control inputs using MATLAB.
The video accompanying this post is given below.
We have explained that the dynamics of a large number of second-order systems can be generically represented as mass-spring-damper systems. Consequently, in this post we consider a generic mass-spring-damper system
In our previous post, we have explained how to derive a differential equation describing the system dynamics. The system dynamics has the following form:
(1)
where is the displacement from the equilibrium point, is mass, is a damping coefficient, is a spring constant, is a control input constant, is a disturbance constant, is a control force, and is a disturbance constant. For simplicity, we will write (1) as follows
(2)
Let us introduce the following notation. If is a time-domain variable then its Laplace transform is denoted by , where is a complex variable. Similarly, Laplace transforms of and are denoted by and . Let us recall an important Laplace transform relation. If is the -th derivative of , then
(3)
where is the initial condition and first, second, …, and -th derivative of evaluated at . Applying this rule to (2), we obtain
(4)
In order to define a transfer function, we need to set the initial condition and all of its derivatives to zero. Under this assumption from (4), we have
(5)
or
(6)
where is a transfer function from the control force to the displacement
(7)
and is the transfer function from the disturbance force to the displacement
(8)
In control systems, we often use two ways for representing transfer functions. Both ways are based on the factorization of polynomials in denominators. Let us recall the completition of squares from calculus. How to factorize the following polynomial?
(9)
Well, we can use the completition of squares trick. We can write
(10)
Next, using the following fact , we can write
(11)
On the other hand, the solutions of the quadratic equation are
(12)
From the last two equations, we conclude that we can factorize the polynomial (9), by computing its zeros and , and then writting
(13)
Let us now use these insigths to factorize the transfer function (7) and (8). First, we compute zeros of the denominator
(14)
and consequently, we can write
(15)
and
(16)
These transfer function representations are important since they directly reveal the system poles. Next, we explain another way for expressing the transfer function. Namely, we can write
(17)
By substituting (14) in (17), we obtain
(18)
where and and . Similarly, we obtain
(19)
where .
These forms of transfer function representations are important since they enable us to easily read the system steady-state gains and .
There are at least two ways for defining transfer functions in MATLAB. Here is the first way.
% define system parameters
% mass
m=10
% damping
kd=1
% spring constant
ks=100
% control force constant
b=1
% disturbance constant
c=0.1
% Defining transfer functions
% control to position transfer function
% numerator
num1=[b/m];
% denominator
den1=[1 kd/m ks/m]
W1=tf(num1,den1)
% disturbance to position transfer function
% numerator
num2=[c/m];
den2=[1 kd/m ks/m]
W2=tf(num2,den2)
% compute poles of transfer functions
pole(W1)
% check the computations, these should be poles
s1=(-(kd/m)+sqrt( (kd/m)^2 -4*(ks/m) ))/2
s2=(-(kd/m)-sqrt( (kd/m)^2 -4*(ks/m) ))/2
Here is the second method relying on the MATLAB symbolic toolbox.
% another way for defining transfer functions
tau1= 1/(-s1);
tau2= 1/(-s2);
A=b/ks;
B=c/ks;
s = tf('s');
W1_other_form=A/((tau1*s+1)*(tau2*s+1))
W2_other_form=B/((tau1*s+1)*(tau2*s+1))
pole(W2_other_form)
pole(W2)
Next, we compute step responses of the two transfer functions. The code is given below.
% compute the system step response
% define the simulation time
simulation_time=0:0.1:100;
y1=step(W1,simulation_time)
figure(1)
plot(simulation_time,y1)
y2=step(W2,simulation_time)
figure(2)
plot(simulation_time,y2)
The two computed step responses are given in figures below.
We can observe that both simulated step responses approximately end at the values that correspond to the steady-state gains of the system. Namely, in the case of , we have
(20)
where . In our case and this value matches the results shown in Figure 2. The similar conclusion can be derived for the case of .