vertopal.com_05-Lin-1
vertopal.com_05-Lin-1
img
• The mass conservation law, the system's representation of this plant is given by the
following expressions:
d h1
A1 =F 1 ( t ) − F2 ( t )
dt
F ( t )=F 2 ( t ) + Fu ( t )
• Knowing that the linear characteristic of the valve is usually given as ( F 2 ( t )=x ( t ) / K ) at
the tank's exit, one can easily come to the following set of equations:
dx 1 1
=− x ( t ) + F 1 ( t )=a x ( t ) +b u 1 ( t )
dt A1 K A1
1
F= x ( t ) + Fu ( t )=c x ( t )+ d u 2 ( t )
K
• Eq.eq1 - eq2 is the first order differential equation and the output of interest is given
as the sum of two flows, that is F=F 2 ( t )+ F u ( t ). We observe that Eqs.eq1-eq2 are
1
written in the state space form Σ s= ( a , b , c , d ) =( A , B , C , D ) where ¿, B=b= ,
A1
1
C=c= , D=d=1). We also recall that every first order differential equation with
K
constant coefficient can be solved by transforming it in its integral form.
{ )
t
x ( t 0 ) +∫ e a (t − τ ) b u ( τ ) d τ +d u2 (t )
a (t − t 0 )
y (t) ¿ c e
t0
• These equations provide the response of the system Eq.eq1-eq2, for example, if F 1 ( t )
and F 2 ( t ) (that is u1 ( t ) =F1 ( t ) , and u2 ( t ) =F2 ( t )) are known functions, we can obtain
the continuous time evolution of the output flow F , see
http://www.youtube.com/watch?v=A5Ak75iG8OI
−2 t
• Let us assume that we know the input function u1 ( t ) =e and hence we can solve for
the expression in Eq.eq5. Therefore, we have:
import numpy as np
import math
a = -0.5
b = 1
t0=0
x0=1
N=len(t)
X=np.zeros(N)
for i in range(len(t)):
X[i]= np.exp(a*t[i])
#matplotlib inline
import matplotlib.pyplot as plt
plt.plot(t, X)
plt.xlabel('t')
plt.ylabel('X')
#plt.xlim([x.min(), x.max()])
so finally we obtain
1
x (t )=b e
at
{1 −e (− a −2 )t )= b {e a t −e −2 t )
a+ 2 a+2
By plotting the input contribution of the overall response we obtain:
import numpy as np
import math
a = -0.5
b = 1
t0=0
x0=0
t, h = np.linspace(t0, 7, 100, retstep=True) # Note the optional
argument to get the stepsize.
N=len(t)
X=np.zeros(N)
for i in range(len(t)):
X[i]= b/(a+2)*(np.exp(a*t[i])-np.exp(-2*t[i]))
#matplotlib inline
import matplotlib.pyplot as plt
plt.plot(t, X)
plt.xlabel('t')
plt.ylabel('X')
#plt.xlim([x.min(), x.max()])
• Finally, the overall response contains the zero-initial condition response and zero-input
response. By addition of these two parts one can obtain the overall response of the
system.
import numpy as np
import math
a = -0.5
b = 1
t0=0
x0=1
N=len(t)
X=np.zeros(N)
for i in range(len(t)):
X[i]= np.exp(a*t[i])+ b/(a+2)*(np.exp(a*t[i])-np.exp(-2*t[i]))
#matplotlib inline
import matplotlib.pyplot as plt
plt.plot(t, X)
plt.xlabel('t')
plt.ylabel('X')
#plt.xlim([x.min(), x.max()])
• In the previous section we consider the known well behaved exponential expression for
the input. However, we might consider that the input is not given in the form of the
exponential function and therefore, we need to perform numerical integration. We
consider that the input is given by data or by some other than exponential function of
time.
– In particular, we can look at the expression for the input in the following form:
t
at
x (t )=e ∫ e− a τ u ( τ ) d τ=e a t A
t0
• Hence the classical way to compute the area under the integral curve is to use the
trapezoid method. It is known that the area of a trapezoid is A=0.5∗w i d t h∗( x t + x t ),
0
−at
where x t =e u ( t 0 ) and x (t )=e− a t u ( t ) . In this example, we have four trapezoids to
0
0
• To make this easier to compute, we need a few new ideas. First, it would be
convenient to know how many elements are in the array t.
len(t)
Second, we need to know how to compute the area of a trapezoid defined by the points in t and
x. The area of the first trapezoid is defined by:
u=np.zeros(len(t))
u[0]=np.sin(t[0])
u[1]=np.sin(t[1])
0.5 * (np.exp(-a*t[0])*u[0] + np.exp(-a*t[1])*u[1]) * (t[1] - t[0])
1.108085424235269
• What we would like to do is to loop over each trapezoid, compute the area, and
accumulate it in a variable. Here is how we use a for loop to iterate from a value starting
at 1 to the length of the array t. Note that although the length is 5, the last value of i is 4.
The loop goes up to, but not including the last value of the range.
for i in range(1, len(t)):
print(i)
1
2
3
4
area=area*np.exp(a*t[len(t)-1])
area
#print(f'The estimated area is {area}.')
#print(f'The exact area is {1 / 3 * (x[-1]**3 - x[0]**3)}')
0.18191438104702873
• The trapezoid method is an approximation of the integral. In this case the straight
lines connecting the points overestimate the value of the function, and so the area
under this curve is overestimated.
Exercise: Increase the number of points slowly and see how the estimate converges
to the exact value.
numpy.trapz
• It is somewhat tedious to write the loop above, making sure you get the indexing right,
etc. The trapezoid method is defined in numpy. See the help for how to use it:
np.trapz
print(x)
print(range(3))
for i in range(2,len(t)+1):
#print(x[0:i])
A[i-1]=np.trapz(x[0:i],t[0:i])
for i in range(len(A)):
F[i]=A[i]*np.exp(a*t[i])
print(F)
#matplotlib inline
import matplotlib.pyplot as plt
plt.xkcd()
plt.plot(t, F)
plt.xlabel('t')
plt.ylabel('F')
#plt.xlim([x.min(), x.max()])
ẋ ( t )= A x ( t ) +B u ( t )
y ( t )=C x (t ) + D u ( t )
– The integral expression for the solution of the system of first order
differential equations is given as:
t
x ( t 0 ) +∫ e
A (t − t 0 ) A ( t −τ )
x (t ) ¿ e B u (τ ) d τ
t0
y (t) ¿ C x (t)+D u (t )
– By the same argument of having time to be integrated from some initial time
t 0=0 to current time t , we obtain:
T
x (t ) ¿ e x ( 0 ) +∫ e
At A ( t − τ)
B u ( τ )d τ
0
x (t ) ¿ Φ ( t , 0 ) x ( 0 )+ Γ (t ) u ( t )
where the matrices Φ and Γ are given as:
At
Φ ( t , 0) ¿ e
t
Γ (t) ¿ ∫ e A (t −τ ) B u ( τ ) d τ
0
– As it can be seen from the above expressions the overall state response
contains initial condition contribution associated with the so called state
A (t −t )
transition matrix Φ ( t , t 0 ) =e and input contribution where input is
0
convolved with the state transition matrix. Therefore, the calculation of the
matrix Φ ( t , t 0 ) becomes central in solving the above system evolution.
ẋ ( t ) ¿
[ 00 10) x ( t ) +[ 01) u ( t )
y (t) ¿ [1 0 ) x ( t )
• In the case of the system without the presence of the force, one obtains the following
solution for the linear system dynamics, where vector x (t )= [ x 1 ( t ) x 2 ( t ) ), with x 1 ( t )
being position and x 2 ( t ) being velocity are physical states of the system:
x (t )=e A t x ( 0 )=Φ ( t , 0 ) x ( 0 )
and therefore the calculation of Φ ( t ,0 ) is given as:
A t (A t )
[ )[ ) [ )
2 2
At 1 0 0 t 1 t
Φ=e ¿ I+ + +⋯= + +⋯=
1! 2! 0 1 0 0 0 1
so the solution is given as:
[ ) [ )[ )
x1 ( t )
x2 ( t )
x (0 )
=1 t 1
0 1 x2( 0 )
Remark: In general, if the matrix A is given as a full matrix, we must calculate the entire series
expansion, which is not feasible. Therefore, this procedure is applied only in the case when
higher order terms in the above expression vanish.
ẋ ( t ) ¿
[ −11 00) x ( t ) +[ 10) u ( t )
y (t) ¿ [0 1 ) x ( t )
The Laplace transform method gives, Φ by using Laplace transform, $\
Phi=e^{At}={\cal L}^{-1}\left\{(sI-A)^{-1}\right\}$, so once obtains:
[ )
1
0
[ [
−1
(sI− A)
−1
¿
s+1 0
−1 s ) =
1 s 0
s ( s +1 ) 1 s +1
=
s+1
1 ) 1
s ( s +1 ) s
[ )[ )[ ) [ )∫ [ )[ )
t
x1 ( t ) e −t 0 x1 ( 0) e −t 0 eτ 0 1
= −t + −t τ u (τ )d τ
x2 ( t ) 1− e 1 x 2 ( 0 ) 1 −e 1 0 1 −e 1 0
so that
[ )[ )[ ) [ )[ )
t τ
x1 ( t ) e −t 0 x1 ( 0) e −t 0 e u (τ )
x2 ( t )
=
1− e −t +
1 x 2 ( 0 ) 1 −e −t
1
∫ ( 1 −e τ ) u ( τ ) dτ
0
Finally, we learned how to integrate any input contribution in the overall response
of the system to the input function u ( t ).
Summary
• We explored a linear analytic methods of finding a solution to the linear system and we
also provided numerical solution to the forced system response with the most general
input setting
– We provide some examples of finding state transition matrix and how to calculate
input and state response contribution