0% found this document useful (0 votes)
2 views

vertopal.com_05-Lin-1

The document discusses the analytic and numerical solutions of linear scalar systems, particularly in the context of chemical engineering applications. It presents equations governing mass conservation in a tank system, explores the transformation of first-order differential equations into integral forms, and illustrates numerical integration methods such as the trapezoid method. Additionally, it introduces the concept of systems of linear differential equations and their state space representation.

Uploaded by

geraldedemidiong
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

vertopal.com_05-Lin-1

The document discusses the analytic and numerical solutions of linear scalar systems, particularly in the context of chemical engineering applications. It presents equations governing mass conservation in a tank system, explores the transformation of first-order differential equations into integral forms, and illustrates numerical integration methods such as the trapezoid method. Additionally, it introduces the concept of systems of linear differential equations and their state space representation.

Uploaded by

geraldedemidiong
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

• KEYWORDS: Linear scalar system, Linear Systems

Analytic and Numerical Solution of Linear Scalar and


System of Equations
• Let us consider a typical simple physical system that is frequently present in
chemical engineering. The flow of the tank F 2 ( t ) is added to another flow F u ( t ) to
generate a desired flow F ( t ), see Figure:

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.

• The integral form of above equation is calculated by the procedure of completing a


total differential in Eq.eq1
− at t t
m u lt i p l y b y e
ẋ (t )=a x ( t )+ b u1 (t )

e
− at
[ ẋ ( t ) − a x ( t ) )=e− a t b u1 (t ) →∫ ddt [ x ( t ) e − at ) d t=∫ e− a τ b u1 ( τ ) d τ
t0 t0

so that the integral is evaluated between some t 0 and given t ;


t t
=∫ e ∫ e − a τ b u1 ( τ ) d τ
−a t − a t0 −aτ a ( t − t 0) at
x (t ) e − x (t 0) e b u1 ( τ ) d τ → x (t )=e x ( t0 ) + e
t0 t0
• The final integral form of the solution of the first order differential equation with
constant coefficients is:
t
x ( t 0 ) +∫ e
a( t − t 0 ) a( t − τ )
x (t ) ¿ e b u1 ( τ ) d τ
t0

{ )
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

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]= 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()])

Text(0, 0.5, 'X')


• We observe that the entire response of the system Eq.eq5 contains the contribution
associated with the initial condition and the contribution associated with the input.
Therefore, in the case when only input is present we need to solve the following
expression
t
x (t )=∫ e
a ( t − τ)
b u1 ( τ ) d τ
t0

which leads to the following solution


t t t
x (t )=∫ b e
a( t − τ ) − 2 τ
d τ=b e
at
∫ e (− a −2 ) τ d τ=b e a t −a1−2 ∫ e (−a − 2) τ d ( −a − 2 ) τ
t0 t0 t0

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()])

Text(0, 0.5, 'X')

• 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

t, h = np.linspace(t0, 5, 5, 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]= 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()])

Text(0, 0.5, 'X')

• 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

compute the areas of. We also specify u ( t )=s in ( t )

• 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 = 0.0 # variable we will accumulate the area in

for i in range(1, len(t)):


x1 = (np.exp(-a*t[i-1])*u[i-1])
x2 = (np.exp(-a*t[i])*u[i])
width = t[i] - t[i - 1]
area += 0.5 * width * (x1 + x2) # increment the area variable

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

<function numpy.trapz(y, x=None, dx=1.0, axis=-1)>

• Now, we can perform the integration with just one line:


import numpy as np
t = np.linspace(0, 10, 50)
x = np.exp(-a*t)*np.sin(t)
(len(t))
A=np.zeros(len(t))
F=np.zeros(len(t))

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()])

[ 0. 0.22444028 0.48678709 0.78053621 1.09590511


1.4196533 1.73506078 2.02210181 2.25784808 2.41713001
2.47347677 2.40034379 2.17262258 1.76840967 1.1709918
0.37098203 -0.63148177 -1.82458847 -3.18289005 -4.6656776
-6.21586729 -7.75957565 -9.20656483 -10.4517291 -11.37777286
-11.8591959 -11.76765278 -10.97868911 -9.37977921 -6.8794975
-3.41755292 1.02469527 6.41373593 12.65402608 19.57944112
26.9468482 34.43265304 41.63319171 48.06981563 53.19943971
56.43118395 57.14953118 54.74414433 48.64613648 38.37016876
23.56127474 4.04478881 -20.12279002 -48.60471173 -80.73989169]
range(0, 3)
[ 0. 0.0206804 0.07785097 0.16551576 0.27676464
0.40402598
0.53935016 0.67471166 0.80231712 0.91490609 1.00603192
1.07031085
1.10362876 1.10329686 1.06814968 0.99858115 0.89651716
0.7653256
0.60966751 0.4352955 0.24880757 0.05736659 -0.13160297 -
0.31072866
-0.47300094 -0.61206851 -0.72250598 -0.80004261 -0.84174285 -
0.84613113
-0.81325575 -0.74468929 -0.64346549 -0.5139553 -0.36168727 -
0.1931196
-0.01537363 0.16406051 0.33763353 0.49804931 0.63856675
0.75327867
0.83735622 0.88724863 0.90082987 0.8774864 0.81814205
0.72521924
0.60253803 0.45515712]

Text(0, 0.5, 'F')


• The trapezoid method is only exact for subintegral function which are lines. For
everything else, it is an approximation. For functions (or regions) that are concave up, the
trapezoid method will over-estimate the integral, and for regions that are concave down,
the method will underestimate the true integral.

Systems of Linear Differential Equations


• The above content demonstrates how one can find the solution to the forced (e.g.
input is present) scalar differential equation by analytic and numerical
methods. However, in many cases modeling framework leads to the system of
differential equations and therefore one wants to examine the associated procedure
when it comes to obtaining the solution. Hence, for the system we have the
following representation:
– Let us consider a generalization of the system given by Eq.eq1. The state space
representation is given in the vector and matrix forms, where the state vector
x (t )= [ x 1 ( t ) , x 2 ( t ) ,⋯ , x n ( t ) ) ′ is the 1 ×n vector, the output vector
y ( t ) =[ y 1 ( t ) , y2 ( t ) , ⋯ , y m ( t ) ) ′ is the 1 ×m vector, and the matrices A,B,C,D are of
appropriate dimensions, while the input vector u ( t ) is a scalar. Therefore, we
have:

ẋ ( 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.

– In order to calculate state transition matrix (which is exponential function),


one can look at the series expansion expression which is the simplest
possible way to compute the state transition matrix. Hence,
¿

Example: Moving Cart-double integrator system


img

• Consider a unidirectional moving cart frequently present in the process industry


with mass M , and built-in motor that moves the cart by force u ( t ). Under reasonable
assumptions that elastic force is negligible and that the cart is moving without
friction along the track, the Newton's Second law provides the expression M ẍ =u ( t ) ,
which is a double integrator system given by:

ẋ ( 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.

Example: DC electric motor model


• An electric DC motor model admits the following continuous state-space
description:

ẋ ( 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

$$\begin{array}{ccc}\Phi&=&e^{At}={\cal L}^{-1}\left\{(sI-A)^{-1}\right\}=\left[ \begin{array}


{cc}e^{-t}& 0\\\ 1-e^{-t}& 1\end{array}\right]\end{array}$$

Hence, the system response can be written as:

[ )[ )[ ) [ )∫ [ )[ )
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

You might also like