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
![](https://aleksandarhaber.com/wp-content/uploads/2020/11/mass_spring-1-1024x301.png)
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
![Rendered by QuickLaTeX.com x](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-ede05c264bba0eda080918aaa09c4658_l3.png)
![Rendered by QuickLaTeX.com m](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-6b41df788161942c6f98604d37de8098_l3.png)
![Rendered by QuickLaTeX.com k_{d}](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-517ede4593a3b137f2b3a254c9e86417_l3.png)
![Rendered by QuickLaTeX.com k_{s}](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-3dffb7a2d6ba65735b67098a7f155dbf_l3.png)
![Rendered by QuickLaTeX.com b](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-f56d50c26583f9a035ff6b4e3c0ca5c0_l3.png)
![Rendered by QuickLaTeX.com c](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-41a04eeea923a1a0c28094a8a4680525_l3.png)
![Rendered by QuickLaTeX.com F](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-2510519bbe1660dfdffb4195c7287343_l3.png)
![Rendered by QuickLaTeX.com D](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-4b9ef1bbd23fd1b198de883813285620_l3.png)
(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
![Rendered by QuickLaTeX.com x(0), x^{(1)}(0),\ldots,x^{(n-1)}(0)](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-4ceb209e65dfb4f9a78f4bdf34ebe2f4_l3.png)
![Rendered by QuickLaTeX.com n](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-b170995d512c659d8668b4e42e1fef6b_l3.png)
![Rendered by QuickLaTeX.com x(t)](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-5fdd870f5a4b1b070c7d28c0b60eeb31_l3.png)
![Rendered by QuickLaTeX.com t=0](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-b7b41acc5cb99fb07aaa07b445eb2483_l3.png)
(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
![Rendered by QuickLaTeX.com W_{1}(s)](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-1e761b3d67e4c3fb68f9df9d96dc5f6e_l3.png)
(7)
and
![Rendered by QuickLaTeX.com W_{2}(s)](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-fca3b13d186e5a9332dc24c4380ea890_l3.png)
(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
![Rendered by QuickLaTeX.com p^{2}-q^{2}=(p-q)(p+q)](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-2785458bf15c6a7a07820dab9223e0da_l3.png)
(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
![Rendered by QuickLaTeX.com s_{1}](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-83e6829cf634f6f115ad2c6cc9160a29_l3.png)
![Rendered by QuickLaTeX.com s_{2}](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-d7725868afc713f34eb814c852ab4845_l3.png)
(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
![Rendered by QuickLaTeX.com A=\frac{b}{k_{s}}](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-483b5290643230bbeb3295bbbb4964ec_l3.png)
![Rendered by QuickLaTeX.com \tau_{1}=\frac{-1}{\tilde{s}_{1}}](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-0c31b7dfb908dca6e0f6b08a2744b9b7_l3.png)
![Rendered by QuickLaTeX.com \tau_{2}=\frac{-1}{\tilde{s}_{2}}](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-b57fdf6194d7105debd5d51868580605_l3.png)
(19)
where
![Rendered by QuickLaTeX.com B=\frac{c}{k_{s}}](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-9faf44bc5a3ebabf96b5477cb4057a3f_l3.png)
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.
![](https://aleksandarhaber.com/wp-content/uploads/2020/11/step1.png)
![](https://aleksandarhaber.com/wp-content/uploads/2020/11/step2.png)
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
![Rendered by QuickLaTeX.com A=\frac{b}{k_{s}}](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-483b5290643230bbeb3295bbbb4964ec_l3.png)
![Rendered by QuickLaTeX.com A=0.01](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-269f7575e9cbe74efadbf080e734f86e_l3.png)
![Rendered by QuickLaTeX.com W_{2}](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-9b9f5ff487bc6c46955077a3980124e1_l3.png)