Sei sulla pagina 1di 9

Linear Control System 2016-EE-113

c=
LAB# 7
10 5
Objective:
Generate a Matlab code to find the state d=
space model from the transfer function of a
0
system and vice versa. Also find the transition
Task 1b
matrix.
Code
Theory n=[10 5];
d=[1 5 6];
State space model is a differential equation
[a,b,c,d]=tf2ss(n,d);
model but the equation are always written in [n,d]=ss2tf(a,b,c,d);
a specific format so for the conversion of the G=tf(n,d)
transfer function to state variable model use
inverse laplace transform. The state variable Result
model, or state model is expressed as n first
Transfer function:
order coupled differential equations. These
10 s + 5
equations preserve the system’s input and
-------------
output relationships s^2 + 5 s + 6
Ẋ(t) = time derivate of X(t)
Task 1c
X(t) = state variable Code
syms s
U(t) = input vector
a=[-5 -6;1 0];
Y(t)= output vector i=eye(2);
r=i*s;
A=system matrix r1=r-a;
r2=inv(r1);
B=input matrix result=ilaplace(r2);
pretty(result)
C= output matrix Result
D=transition matrix +- -+
| 3 2 6 6 |
Task 1a | -------- - --------, -------- - -------- |
| exp(3 t) exp(2 t) exp(3 t) exp(2 t) |
Code | |
| 1 1 3 2 |
| -------- - --------, -------- - -------- |
n=[10 5]; | exp(2 t) exp(3 t) exp(2 t) exp(3 t) |
d=[1 5 6]; +- -+
[a,b,c,d]=tf2ss(n,d)
Result Task 1d
a=
Code
-5 -6 syms s
1 0 a=[-5 -6;1 0];
b=[1;0];
b= c=[10 5];
d=0;
1 i=eye(2);
0 r=i*s;
r1=r-a;

SIR SYED UNIVERSITY OF ENGINERING AND TECHNOLOGY Page 1


Linear Control System 2016-EE-113

r2=inv(r1); result=ilaplace(r2);
r3=r2*b; pretty(result)
r4=c*r3;
result=r4+d; Result
pretty(result)
+- -+
Result | cos(t), -sin(t) |
10 s 5 | |
------------ + ------------ | sin(t), cos(t) |
2 2 +- -+
s +5s+6 s +5s+6
Task 2a Task 2d
Code
Code
n1=[1 0 0];
syms s
d1=[1 0 1];
a=[0 -1;1 0];
[a1,b1,c1,d1]=tf2ss(n1,d1)
b=[1;0];
c=[0 -1];
Result d=1;
a1 = i=eye(2);
0 -1 r=i*s;
1 0 r1=r-a;
b1 = r2=inv(r1);
1 r3=r2*b;
0 r4=c*r3;
c1 = result=r4+d;
pretty(result)
0 -1
Result
d1 = 1
1 1 - ------
Task 2b 2
s +1

Code
Task 3a
n1=[1 0 0];
d1=[1 0 1]; Code
[a1,b1,c1,d1]=tf2ss(n1,d1) n2=[6];
[n1,d1]=ss2tf(a1,b1,c1,d1); d2=[1 2];
G=tf(n1,d1) [a2,b2,c2,d2]=tf2ss(n2,d2)

Result Result
Transfer function: a2 =
s^2 -2
------- b2 =
s^2 + 1
1
Task 2c c2 =
Code
syms s 6
a=[0 -1;1 0]; d2 =
i=eye(2);
r=i*s; 0
r1=r-a;
r2=inv(r1);

SIR SYED UNIVERSITY OF ENGINERING AND TECHNOLOGY Page 2


Linear Control System 2016-EE-113

Task 3b 2
Code s +9s+8
a2=[0 2;-2 -5];
b2=[0;1]; Task 4a
c2=[1 0]; Code
d2=[0]; syms m b k
[n,d]=ss2tf(a2,b2,c2,d2) n=[1];
d=[m b k];
Result [A,B,C,D]=tf2ss(n,d)

n= Result
0 0 2.0000 A=
[ -b/m, -k/m]
d= [ 1, 0]
1 5 4
B=
Task 3c 1
Code 0
syms s
n=[10 0]; C=
d=[1 2]; [ 0, 1/m]
[a3,b3,c3,d3]=tf2ss(n,d);
i=eye(2); D=
r=i*s; 0
r1=r-a3;
r2=inv(r1); Task 4b
result=ilaplace(r2);
Code
pretty(result)
a5=[-b/m -k/m;1 0];
Result
+- -+
b5=[1;0];
| 1 1 | c5=[0,1/m];
| ---------- + 1/2, ---------- - 1/2 | d5=0;
| 2 exp(4 t) 2 exp(4 t) |
| |
[n,d]=ss2tf(a5,b5,c5,d5)
| 1 1 | Result
| ---------- - 1/2, ---------- + 1/2 |
| 2 exp(4 t) 2 exp(4 t) |
If the input expression contains a symbolic
+- -+ variable, use the VPA function instead.
Task 3d
Task 4c
Code
Code
n=[7];
syms s
d=[1 9 8];
a5=[-b/m -k/m;1 0];
[a4,b4,c4,d4]=tf2ss(n,d);
i=eye(2);
i=eye(2);
r=i*s;
r=i*s;
r1=r-a5;
r1=r-a4;
r2=inv(r1);
r2=inv(r1);
result=ilaplace(r2);
r3=r2*b4;
pretty(result)
r4=c4*r3;
result=r4+d4;
pretty(result) Result
+- -+
| / / 2 \1/2 \ |
| | |b | | |
Result | / / 2 \1/2 \ | t | -- - k m | | |
7 | | |b | | | \4 / | |
| | t | -- - k m | | b sinh| ----------------- | |
------------ | | \4 / | \ m / |
| cosh| ----------------- | - --------------------------- |

SIR SYED UNIVERSITY OF ENGINERING AND TECHNOLOGY Page 3


Linear Control System 2016-EE-113

| \ m / / 2 \1/2 / 2 1/2 \ |
| |b | | t (4 k m - b ) | |
d=
| 2 | -- - k m | 2 k sin| ----------------- | |
| \4 / \ 2m / |
| -------------------------------------------------------, - ---------------------------- | 1.0000 13.0000 33.0000 18.0000
| /bt\ /bt\ 2 1/2 |
| exp| --- | exp| --- | (4 k m - b ) |
| \2m/ \2m/ | n2 =
| |
| | 0 1.0000 12.0000 11.0000
| / / 2 \1/2 \ |
| | |b | | |
0 3.0000 24.0000 4.0000
| / / 2 \1/2 \ | t | -- - k m | | |
| | |b | | | \4 / | |
| | t | -- - k m | | b sinh| ----------------- | | d=
| | \4 / | \ m / |
| cosh| ----------------- | + --------------------------- |
| / 2 1/2 \ \ m / / 2 \1/2 | 1.0000 13.0000 33.0000 18.0000
| | t (4 k m - b ) | |b | |
| 2 m sin| ----------------- | 2 | -- - k m | | Task 5b
| \ 2m / \4 / |
| ----------------------------, ------------------------------------------------------- | Code
| /bt\ 2 1/2 /bt\ |
| exp| --- | (4 k m - b ) exp| --- | |
| \2m/ \2m/ |
syms s
+- -+ A=[0 1 0;-2 -4 1;0 5 -9];
B=[0 0;1 1;2 2];
Task 4d C=[1 1 0;0 1 1];
Code D=[0 0;0 0];
i=eye(3);
syms s
r=i*s;
a5=[-b/m -k/m;1 0];
r1=r-A;
b5=[1;0];
r2=inv(r1);
c5=[0 1/m];
r3=r2*B;
d5=0;
r4=C*r3;
i=eye(2);
result=r4+D;
r=i*s;
pretty(result)
r1=r-a5;
r2=inv(r1);
r3=r2*b5;
Result
r4=c5*r3;
result=r4+d5;
pretty(result)

Result
1
--------------
2
ms +bs+k

Task 5a

Code
A=[0 1 0;-2 -4 1;0 5 -9];
B=[0 0;1 1;2 2];
C=[1 1 0;0 1 1];
D=[0 0;0 0];
[n1,d]=ss2tf(A,B,C,D,1)
[n2,d]=ss2tf(A,B,C,D,2)
Result
n1 =
0 1.0000 12.0000 11.0000
0 3.0000 24.0000 4.0000

SIR SYED UNIVERSITY OF ENGINERING AND TECHNOLOGY Page 4


Linear Control System 2016-EE-113

pretty(result)
Lab Assignment
Task 1a Result
+- -+
| / 1/2 \ |
Code | 1/2 | 42769 t | |
| / 1/2 \ 97 42769 sinh| ---------- | / 1/2 \ |
| | 42769 t | \ 20 / 1/2 | 42769 t | |
n=[15 10.5]; | cosh| ---------- | - ------------------------------ 1668 42769 sinh| ---------- |
d=[1 9.7 83.4]; |
| \ 20 / 42769 \ 20 / |
[a,b,c,d]=tf2ss(n,d) | ---------------------------------------------------, -------------------------------- |
| / 97 t \ / 97 t \ |
| exp| ---- | 42769 exp| ---- | |
Result | \ 20 / \ 20 / |
| |
| / 1/2 \ |
a= | 1/2 | 42769 t | |
| / 1/2 \ / 1/2 \ 97 42769 sinh| ---------- | |
| 1/2 | 42769 t | | 42769 t | \ 20 / |
-9.7000 -83.4000 | 20 42769 sinh| ---------- | cosh| ---------- | + ------------------------------
|
1.0000 0 | \ 20 / \ 20 / 42769 |
| ------------------------------, --------------------------------------------------- |
| / 97 t \ / 97 t \ |
b= | 42769 exp| ---- | exp| ---- | |
| \ 20 / \ 20 / |
+- -+

1
0 Task 1d

c= Code
syms s
15.0000 10.5000 a=[-9.7 -83.4;1 0];
b=[1;0];
d= c=[15 10.5];
d=0;
0 i=eye(2);
Task 1b r=i*s;
Code r1=r-a;
r2=inv(r1);
n=[15 10.5]; r3=r2*b;
d=[1 9.7 83.4]; r4=c*r3;
[a,b,c,d]=tf2ss(n,d); result=r4+d;
[n,d]=ss2tf(a,b,c,d); pretty(result)
G=tf(n,d)
Result
Result
150 s 105
Transfer function: ------------------ + ------------------
15 s + 10.5 2 2
10 s + 97 s + 834 10 s + 97 s + 834
------------------
s^2 + 9.7 s + 83.4 Task 2a
Code
Task 1c
n1=[1 10 5];
Code d1=[1 5 6];
syms s [a1,b1,c1,d1]=tf2ss(n1,d1)
a=[-9.7 83.4;1 0];
i=eye(2);
Result
r=i*s;
a1 =
r1=r-a;
r2=inv(r1); -5 -6
result=ilaplace(r2); 1 0

SIR SYED UNIVERSITY OF ENGINERING AND TECHNOLOGY Page 5


Linear Control System 2016-EE-113

b1 = c=[5 -1];
d=1;
1 i=eye(2);
0 r=i*s;
r1=r-a;
r2=inv(r1);
r3=r2*b;
c1 =
r4=c*r3;
result=r4+d;
5 -1 pretty(result)
d1 =
Result
1
Task 2b
5s 1
------------ - ------------ + 1
Code 2 2
n1=[1 10 5]; s +5s+6 s +5s+6
d1=[1 5 6];
[a1,b1,c1,d1]=tf2ss(n1,d1) Task 3a
[n1,d1]=ss2tf(a1,b1,c1,d1); Code
G=tf(n1,d1)
n2=[1];
d2=[1 3 2];
Result [a2,b2,c2,d2]=tf2ss(n2,d2)
Transfer function:
s^2 + 10 s + 5 Result
-------------- a2 =
s^2 + 5 s + 6
-3 -2
Task 2c 1 0
Code
syms s b2 =
a=[-5 -6;1 0];
i=eye(2); 1
r=i*s; 0
r1=r-a;
r2=inv(r1);
c2 =
result=ilaplace(r2);
pretty(result)
0 1

Result
d2 =
+- -+
0
| 3 2 6 6 | Task 3b
| -------- - --------, -------- - -------- |
| exp(3 t) exp(2 t) exp(3 t) exp(2 t) | Code
| | a2=[0 1;0 0];
| 1 1 3 2 |
| -------- - --------, -------- - -------- |
b2=[0;10];
| exp(2 t) exp(3 t) exp(2 t) exp(3 t) | c2=[1 0];
+- -+ d2=[0];
[n,d]=ss2tf(a2,b2,c2,d2)
Task 2d
Code Result
syms s n=
a=[-5 -6;1 0];
b=[1;0]; 0 0 10.0000

SIR SYED UNIVERSITY OF ENGINERING AND TECHNOLOGY Page 6


Linear Control System 2016-EE-113

r=i*s;
d= r1=r-a4;
r2=inv(r1);
1 0 0 r3=r2*b4;
r4=c4*r3;
result=r4+d4;
Task 3c pretty(result)
Code
syms s Result
n=[2 0 1]; +- -+
d=[2 1 0 1]; | 87 (s + 5) 87 |
[a3,b3,c3,d3]=tf2ss(n,d); | -------------, - ------------ |
| 10 s (s + 10) 2 s (s + 10) |
i=eye(3); | |
r=i*s; | 87 87 (s + 5) |
r1=r-a3; | - ------------, ------------- |
| 2 s (s + 10) 10 s (s + 10) |
r2=inv(r1); +- -+
result=ilaplace(r2); Task 4a
pretty(result)
Code
syms m b k
Result n=[1 k];
d=[m b k];
[A,B,C,D]=tf2ss(n,d)
Result

A=
[ -b/m, -k/m]
[ 1, 0]

B=

1
0
C=

[ 1/m, k/m]

D=

0
Task 4b
Code
syms b m k
A=[-b/m -k/m;1 0];
B=[1;0];
C=[1/m,k/m];
D=0;
[n,d]=ss2tf(A,B,C,D)
Task 3d Result
If the input expression contains a symbolic
Code variable, use the VPA function instead.
n=[8.7];
Task 4c
d=[1 5];
[a4,b4,c4,d4]=tf2ss(n,d); Code
i=eye(2); syms s

SIR SYED UNIVERSITY OF ENGINERING AND TECHNOLOGY Page 7


Linear Control System 2016-EE-113

a5=[-b/m -k/m;1 0]; A=[0 -2 0;1 -4 5;0 1 -9];


i=eye(2); B=[0 1;2 0;1 2];
r=i*s; C=[1 0 1;1 1 0];
r1=r-a5; D=[0 0;0 0];
r2=inv(r1); [n1,d]=ss2tf(A,B,C,D,1)
result=ilaplace(r2); [n2,d]=ss2tf(A,B,C,D,2)
pretty(result)
Result
Result
+- -+ n1 =
| / / 2 \1/2 \ |
| | |b | | |
| / / 2 \1/2 \ | t | -- - k m | | | 0 1.0000 2.0000 -44.0000
| | |b | | | \4 / | |
| | t | -- - k m | | b sinh| ----------------- | | 0 2.0000 19.0000 -46.0000
| | \4 / | \ m / |
| cosh| ----------------- | - --------------------------- |
| \ m / / 2 \1/2 / 2 1/2 \ | d=
| |b | | t (4 k m - b ) | |
| 2 | -- - k m | 2 k sin| ----------------- | |
| \4 / \ 2m / |
| -------------------------------------------------------, - ---------------------------- | 1.0000 13.0000 33.0000 18.0000
| /bt\ /bt\ 2 1/2 |
| exp| --- | exp| --- | (4 k m - b ) |
| \2m/ \2m/ | n2 =
| |
| |
| / / 2 \1/2 \ | 0 3.0000 21.0000 16.0000
| | |b | | |
| / / 2 \1/2 \ | t | -- - k m | | | 0 1.0000 24.0000 20.0000
| | |b | | | \4 / | |
| | t | -- - k m | | b sinh| ----------------- | |
| | \4 / | \ m / | d=
| cosh| ----------------- | + --------------------------- |
| / 2 1/2 \ \ m / / 2 \1/2 |
| | t (4 k m - b ) | |b | |
| 2 m sin| ----------------- | 2 | -- - k m | | 1.0000 13.0000 33.0000 18.0000
|
|
\ 2m /
----------------------------,
\4 / |
------------------------------------------------------- |
Task 5b
| /bt\ 2 1/2 /bt\ | Code
| exp| --- | (4 k m - b ) exp| --- | |
| \2m/ \2m/ |
+- -+ syms s
Task 4d A=[0 -2 0;1 -4 5;0 1 -9];
Code B=[0 1;2 0;1 2];
syms s C=[1 0 1;1 1 0];
a5=[-b/m -k/m;1 0]; D=[0 0;0 0];
b5=[1;0]; i=eye(3);
c5=[1/m k/m]; r=i*s;
d5=0; r1=r-A;
i=eye(2); r2=inv(r1);
r=i*s; r3=r2*B;
r1=r-a5; r4=C*r3;
r2=inv(r1); result=r4+D;
r3=r2*b5; pretty(result)
r4=c5*r3;
result=r4+d5;
pretty(result)
Result

Result
k s
-------------- + --------------
2 2
ms +bs+k ms +bs+k
Task 5a

Code

SIR SYED UNIVERSITY OF ENGINERING AND TECHNOLOGY Page 8


Linear Control System 2016-EE-113

Conclusion:
In control engineering, a state-space
representation is a mathematical model
of a physical system as a set of input,
output and state variables related by first-
order differential equations or difference
equations. State variables are variables
whose values evolve through time in a
way that depends on the values they have
at any given time and also depends on the
externally imposed values of input
variables. Output variables’ values depend
on the values of the state variables.

SIR SYED UNIVERSITY OF ENGINERING AND TECHNOLOGY Page 9

Potrebbero piacerti anche