Solution to Homework Assignment 1 - Purdue School of ...skoskie/ECE382/ECE382_f08/ECE... ·...
Transcript of Solution to Homework Assignment 1 - Purdue School of ...skoskie/ECE382/ECE382_f08/ECE... ·...
ECE382/ME482 Spring 2008 Homework 1 Solution September 22, 2008 1
Solution to Homework Assignment 1
1. (Review) Consider the system with transfer function
G(s) =Y (s)
R(s)=
30
s3 + 10s2 + 31s + 30. (1)
(a) For input r(t) = δ(t), t ≥ 0, find the corresponding output y(t) using partial fractionexpansions and inverse Laplace transforms. Then use Matlab to obtain the solutionand plot the solution on the interval t = [0, 2].
(b) Repeat for r(t) = u(t), t ≥ 0.
(c) Repeat for r(t) = t, t ≥ 0.
Note: In this course you must always label your plot properly using Matlab commandstitle, xlabel, and ylabel.
Solution: We consider three different inputs, which I will label as follows:
r1(t) = δ(t) R1(s) = 1r2(t) = u(t) R2(s) = 1/sr3(t) = t R3(s) = 1/s2
(2)
Let’s call the corresponding outputs y1(t), y2(t), y3(t).
Then
Y1(s) = G(s)R1(s) =30
s3 + 10s2 + 31s + 30. (3)
The denominator factors as (s + 2)(s + 3)(s + 5), which I could obtain using the Matlabcommand roots([1 10 31 30]) or by trial and error, noting that if the roots are integersthey must be factors of 30.
Taking the partial fraction expansion we have
Y1(s) =30
s3 + 10s2 + 31s + 30=
a
s + 2+
b
s + 3+
c
s + 5(4)
which implies that
30 = a(s2 + 8s + 15) + b(s2 + 7s + 10) + c(s2 + 5s + 6) (5)
or
0 = (a + b + c)s2 (6)
0 = (8a + 7b + 5c)s (7)
30 = 15a + 10b + 6c. (8)
This is equivalent to the linear equation
00
30
=
1 1 18 7 5
15 10 6
abc
, (9)
ECE382/ME482 Spring 2008 Homework 1 Solution September 22, 2008 2
which has solution
abc
=
1 1 18 7 5
15 10 6
−1
00
30
, (10)
or[
a b c]
=[
10 −15 5]
. (11)
Then
Y1(s) =30
s3 + 10s2 + 31s + 30
=10
s + 2+
−15
s + 3+
5
s + 5(12)
so inverse transforming,
y1(t) = 10e−2t − 15e−3t + 5e−5t, t ≥ 0. (13)
Repeating the process for y2(t) we find
Y2(s) = G(s)R2(s)
=
(
30
s3 + 10s2 + 31s + 30
) (
1
s
)
. (14)
The denominator factors as (s + 2)(s + 3)(s + 5)s.
Taking the partial fraction expansion we have
Y2(s) =
(
30
s3 + 10s2 + 31s + 30
) (
1
s
)
=a
s + 2+
b
s + 3+
c
s + 5+
d
s(15)
which implies that
30 = as(s2 + 8s + 15) + bs(s2 + 7s + 10) + cs(s2 + 5s + 6) + d(s3 + 10s2 + 31s + 30) (16)
or
0 = (a + b + c + d)s3 (17)
0 = (8a + 7b + 5c + 10d)s2 (18)
0 = (15a + 10b + 6c + 31d)s (19)
30 = 30d. (20)
This is equivalent to the linear equation
000
30
=
1 1 1 18 7 5 10
15 10 6 310 0 0 30
abcd
, (21)
ECE382/ME482 Spring 2008 Homework 1 Solution September 22, 2008 3
which has solution
abcd
=
1 1 1 18 7 5 10
15 10 6 310 0 0 30
−1
000
30
(22)
or[
a b c d]
=[
−5 5 −1 1]
. (23)
Then
Y2(s) =30
s4 + 10s3 + 31s2 + 30s(24)
=−5
s + 2+
5
s + 3+
−1
s + 5+
1
s(25)
so inverse transforming,
y2(t) = −5e−2t + 5e−3t − e−5t + 1, t ≥ 0. (26)
Finally, repeating the process for y3(t) we find
Y3(s) = G(s)R3(s) =
(
30
s3 + 10s2 + 31s + 30
) (
1
s2
)
. (27)
The denominator factors as (s + 2)(s + 3)(s + 5)s2.
To obtain the partial fraction expansion we use the residue command as follows:
>> [r,p,k] = residue(30,[1 10 31 30 0 0])
r =
0.2000
-1.6667
2.5000
-1.0333
1.0000
p =
-5.0000
-3.0000
-2.0000
0
0
k =
ECE382/ME482 Spring 2008 Homework 1 Solution September 22, 2008 4
[]
Thus
Y3(s) =30
s5 + 10s4 + 31s3 + 30s2=
1/5
s + 2+
−5/3
s + 3+
5/2
s + 5+
−1 − 3/100
s+
1
s2(28)
so inverse transforming we have, to four decimal places,
y3(t) =5
2e−2t +
−5
3e−3t +
1
5e−5t − 1.0333 + t, t ≥ 0. (29)
To obtain the plots we use a Matlab script such as the following. (I did the calculationstwo ways to show the agreement between the results.)
%%%
%%% Problem 1, Homework 1
%%%
t = [0:.01:10]’;
%%% First the solutions we calculated analytically.
for index = 1:1001,
y1a(index) = 10*exp(-2*t(index)) - 15*exp(-3*t(index)) + 5*exp(-5*t(index));
y2a(index) = -5*exp(-2*t(index)) + 5*exp(-3*t(index)) - exp(-5*t(index)) + 1;
y3a(index) = 5/2*exp(-2*t(index)) + -5/3*exp(-3*t(index)) + ...
1/5* exp(-5*t(index)) - 1.0333 + t(index);
end
%%% Next the solutions calculated using Matlab.
gnum = 30; gden = [1 10 31 30];
sys = tf(gnum,gden);
y1b = impulse(sys,t);
u2 = ones(size(t));
y2b = lsim(sys,u2,t); %%% or equivalently y2b = step(sys,t);
g3num = 30; g3den = [1 10 31 30 0];
sys3 = tf(g3num,g3den);
y3b = step(sys3,t);
figure(1)
subplot(2,1,1)
plot(t,y1a,’b’,t,y1b’,’r’)
title(’Problem 1 Comparison of Analytical and Numerical Solutions’)
xlabel(’t’)
ECE382/ME482 Spring 2008 Homework 1 Solution September 22, 2008 5
ylabel(’Impulse Response y_1’)
legend(’Analytical’,’Numerical’)
grid
subplot(2,1,2)
plot(t,y1a-y1b’)
xlabel(’t’)
ylabel(’Error (analytical - numerical)’)
grid
print -depsc figure1
figure(2)
subplot(2,1,1)
plot(t,y2a,’b’,t,y2b’,’r’)
title(’Problem 1 Comparison of Analytical and Numerical Solutions’)
xlabel(’t’)
ylabel(’Step Response y_2’)
legend(’Analytical’,’Numerical’)
grid
subplot(2,1,2)
plot(t,y2a-y2b’)
xlabel(’t’)
ylabel(’Error (analytical - numerical)’)
grid
print -depsc figure2
figure(3)
subplot(2,1,1)
plot(t,y3a,’b’,t,y3b’,’r’)
title(’Problem 1 Comparison of Analytical and Numerical Solutions’)
xlabel(’t’)
ylabel(’Ramp Response y_3’)
legend(’Analytical’,’Numerical’)
grid
subplot(2,1,2)
plot(t,y3a-y3b’)
xlabel(’t’)
ylabel(’Error (analytical - numerical)’)
grid
print -depsc figure3
and we obtain the results
2. (Review) Consider an input r(t) = t, t ≥ 0 applied to a system with transfer function G(s).The corresponding output is y(t) = e−3t − 2e−2t + e−t − 2. Find G(s).
Solution: We know that G(s) = Y (s)/R(s). Thus we just need to take Laplace transforms
ECE382/ME482 Spring 2008 Homework 1 Solution September 22, 2008 6
0 1 2 3 4 5 6 7 8 9 100
0.2
0.4
0.6
0.8Problem 1 Comparison of Analytical and Numerical Solutions
t
Impu
lse
Res
pons
e y 1
0 1 2 3 4 5 6 7 8 9 10−20
−15
−10
−5
0
5x 10
−15
t
Err
or (
anal
ytic
al −
num
eric
al)
AnalyticalNumerical
ECE382/ME482 Spring 2008 Homework 1 Solution September 22, 2008 7
0 1 2 3 4 5 6 7 8 9 100
0.2
0.4
0.6
0.8
1Problem 1 Comparison of Analytical and Numerical Solutions
t
Ste
p R
espo
nse
y 2
0 1 2 3 4 5 6 7 8 9 10−10
−5
0
5x 10
−15
t
Err
or (
anal
ytic
al −
num
eric
al)
AnalyticalNumerical
ECE382/ME482 Spring 2008 Homework 1 Solution September 22, 2008 8
0 1 2 3 4 5 6 7 8 9 100
2
4
6
8
10Problem 1 Comparison of Analytical and Numerical Solutions
t
Ram
p R
espo
nse
y 3
0 1 2 3 4 5 6 7 8 9 103.3333
3.3333
3.3333
3.3333
3.3333x 10
−5
t
Err
or (
anal
ytic
al −
num
eric
al)
AnalyticalNumerical
ECE382/ME482 Spring 2008 Homework 1 Solution September 22, 2008 9
of r(t) and y(t).
R(s) = L[r(t)] =1
s2(30)
Y (s) = L[y(t)] =1
s + 3− 2
s + 2+
1
s + 1− 2
s(31)
=−2(s3 + 6s2 + 10s + 6)
s(s + 1)(s + 2)(s + 3)(32)
so
G(s) =−2s(s3 + 6s2 + 10s + 6
(s + 1)(s + 2)(s + 3). (33)
Notice that this is an improper transfer function (order of numerator greater than orderof denominator).
I used Matlab as shown below to help with some of the algebra.
>> [1 3 2 0]-2*[1 4 3 0]+[1 5 6 0] - 2*conv([1 3 2],[1 3])
ans =
-2 -12 -20 -12
3. (Review) Consider the initial value problem (IVP) consisting of the differential equation
y + 6y + 3y = u, (34)
where u(t) is the unit step function, and the initial conditions
y(0) = 0 and y(0) = 0. (35)
(a) Find the solution ya(t) analytically.
(b) Find the solution yb(t) using Matlab.
(c) Using the subplot command, plot in the upper half of the space ya(t) and yb(t) onthe same graph; and plot in the lower half the difference ya(t) − yb(t). (This errorshould be very small.)
(d) Remember to properly label the graphs.
Solution:
ECE382/ME482 Spring 2008 Homework 1 Solution September 22, 2008 10
(a) Taking the Laplace transform of 34, we obtain
Ya(s) = G(s)U(s) =1
s(s2 + 6s + 3), (36)
then factor the denominator so we can do a partial fraction expansion. Using theformula for the roots of a second order equation we find that
s2 + 6s + 3 = (s + 3 +√
6)(s + 3 −√
6). (37)
The partial fraction expansion is then
Ya(s) =1
s(s2 + 6s + 3)=
A
s+
B
s + 3 +√
6+
C
s + 3 −√
6(38)
where A = 1/3, B = 3/8, and C = −0.3708 to four decimal places according tothe Matlab calculations shown below. (I could work it out by hand but it would betedious and not very informative.)
>> a = 1;
>> b = [1 6 3 0];
>> [r,p,k]=residue(a,b)
r =
0.0375
-0.3708
0.3333
p =
-5.4495
-0.5505
0
k =
[]
Thus, again rounding to four decimal places, we obtain
Ya(s) =1/3
s+
−0.3708
s + 0.5505+
0.375
s + 5.4495. (39)
Taking the inverse Laplace transform to get ya(t) yields
ya(t) =1
3− 0.3708e−0.5505t + 0.375e−5.4495t, t ≥ 0. (40)
Parts (b), (c), and (d) are very similar to what I provided for Problem 1, so I willnot include them here.
ECE382/ME482 Spring 2008 Homework 1 Solution September 22, 2008 11
4. (Section 2.3) Suppose that
y(r, θ) = mr2 + mℓr cos θ − mℓ2 sin θ. (41)
Find the first order linear approximation to y(r, θ) near the operating point (r, θ) = (r0, θ0).
Note that the function y is declared to be a function of two variables: r, and θ. Thereforem and ℓ are constants.
Solution: Taylor’s formula for the linear approximation near the point (r0, θ0) is
y(r, θ) ∼= y(r0, θ0) +∂y
∂r
∣
∣
∣
∣
(r0,θ0)(r − r0) +
∂y
∂θ
∣
∣
∣
∣
(r0,θ0)(θ − θ0) (42)
The partial derivatives evaluated at the point (r0, θ0) are
∂y
∂r
∣
∣
∣
∣
(r0,θ0)= 2mr0 + mℓ cos θ0, (43)
and∂y
∂θ
∣
∣
∣
∣
(r0,θ0)= −mℓr0 sin θ0 − mℓ2 cos θ0. (44)
Thus
y(r, θ) ∼= mr20 + mℓr0 cos θ0 − mℓ2 sin θ0 +
(2mr0 + mℓ cos θ0)(r − r0) +
(−mℓr0 sin θ0 − mℓ2 cos θ0)(θ − θ0). (45)
I could simplify this equation further by expanding all of the products and rearranging toobtain y(r, θ) = a(r, θ)r + b(r, θ)θ + c where the constants r0 and θ0 would be parameters(as opposed to variables) of the functions a, b, and the constant c. I would ordinarilysimplify, but in this case I found that the result provided little additional insight.
ECE382/ME482 Spring 2008 Homework 1 Solution September 22, 2008 12
5. (Section 2.6) Consider the transfer function blocks that we reduced in lecture on 8/28. (Ifyou have the 11th edition, the diagram is in Figure 2.26 on p. 75.) Delete block H2. Adda new negative feedback loop H4 from the output of G2 to the leftmost summer. Insert inthe forward path from the input to this summer a block G5.
You are given that
G1(s) =1
s + 1(46)
G2(s) =s
s2 + 2(47)
G3(s) =1
s2(48)
G4(s) = 1 (49)
G5(s) = 4 (50)
H1(s) = 50 (51)
H3(s) =s2 + 2
s3 + 14(52)
H4(s) =4s + 2
s2 + 2s + 1. (53)
(a) Find the transfer function from R(s) to Y (s).
Solution:
We can reduce the two inner feedback loops as shown below.
1 + G1G2H4
R(s)
R(s)
G4G3
H1
H3
G2G1G5+
++
−
− Y(s)
G1G2 G3G4
1 − G3G4H1
Y(s)
H3
G5+
−
H4
Figure 1: Problem 5: Block diagram and first simplification step.
It will be easier to do the final reduction step if we simplify the two large blocks now.Let
B1(s) =
(
G1(s)G2(s)
1 + G1(s)G2(s)H4(s)
)
(54)
ECE382/ME482 Spring 2008 Homework 1 Solution September 22, 2008 13
=
s(s+1)(s2+2)
1 + s(4s+2)(s+1)(s2+2)(s+1)2
(55)
=s(s + 1)3(s2 + 2)
(s + 1)(s2 + 2) ((s + 1)3(s2 + 2) + s(4s + 2))(56)
=s(s + 1)2
s5 + 3s4 + 5s3 + 11s2 + 8s + 2. (57)
>> conv([1 3 3 1],[1 0 2]) + [0 0 0 5 2 0]
ans =
1 3 5 11 8 2
Similarly let
B2(s) =
(
G3(s)G4(s)
1 − G3(s)G4(s)H1(s)
)
(58)
=1s2
1 − 50s2
(59)
=1
s2 − 50. (60)
Then the forward path of the last feedback loop has transfer function
B1(s)B2(s) =s(s + 1)2
(s2 − 50)(s5 + 3s4 + 4s3 + 11s2 + 8s + 2)(61)
and feedback path H3(s). Finally,
Y (s)
R(s)=
G5(s)B1(s)B2(s)
1 + B1(s)B2(s)H3(s)(62)
=4s(s + 1)2(s3 + 14)
(s10 + 3s9 − 45s8 − 125s7 − 200s6 − 1177s5 − 2344s4 − 3485s3 − 7668s2 − 559s − 1400).(63)
I used Matlab command conv to multiply polynomials
>> anum = conv(4*[1 2 1 0],[1 0 0 14])
anum =
4 8 4 56 112 56 0
>> test = conv(conv([1 5 3 11 8 2],[1 0 -50]),[1 0 0 14])
test =
Columns 1 through 5
ECE382/ME482 Spring 2008 Homework 1 Solution September 22, 2008 14
1 5 -47 -225 -72
Columns 6 through 10
-1206 -3746 -2088 -7672 -5600
Column 11
-1400
>> aden = conv(conv([1 5 3 11 8 2],[1 0 -50]),[1 0 0 14]) + [ 0 0 0 0 0 conv([1 2 1
aden =
Columns 1 through 5
1 5 -47 -225 -72
Columns 6 through 10
-1205 -3744 -2085 -7668 -5598
Column 11
-1400
>> roots(anum)
ans =
0
1.2051 + 2.0872i
1.2051 - 2.0872i
-2.4101
-1.0000
-1.0000
>> roots(aden)
ans =
7.0709
-7.0716
-4.7831
1.2049 + 2.0866i
1.2049 - 2.0866i
ECE382/ME482 Spring 2008 Homework 1 Solution September 22, 2008 15
-2.4107
0.2760 + 1.4580i
0.2760 - 1.4580i
-0.3837 + 0.2066i
-0.3837 - 0.2066i
We find that the transfer function is
Y (s)
R(s)=
s(s + 1)2
(s + 2.5443)(s2 − 0.3789s + 3.9583)(s2 + 0.8346s + 0.1986)(64)
(b) Find the closed loop poles and zeros . (Use Matlab if necessary.)
Solution: See above.
(c) Let H1(s) = H3(s) = H4(s) = 0 and find the transfer function from R(s) to Y (s).
Solution: The open loop transfer function is just the product of the Gi, namely
4s
s2(s + 1)(s2 + 2)=
4
s(s + 1)(s2 + 2). (65)
(d) Find the poles and zeros of this open loop transfer function.
Solution:
Clearly the poles are 0, −1,√
2, −√
2.
ECE382/ME482 Spring 2008 Homework 1 Solution September 22, 2008 16
6. (Section 2.7)
Create a signal flow graph for the closed loop system of the previous problem. Use Mason’sformula to compute the transfer function from R(s) to Y (s). (If it does not match thatyou found in the previous problem, you need to find and correct your mistakes.)
L3
−H3
G3 G41
G1
−H4
G2
G5
R Y
L1
L2
H1
Figure 2: Problem 6: Signal Flow Graph.
Solution: A drawing of the signal flow graph corresponding to the block diagram is givenin Figure 2. There is a single path from R(s) to Y (s), namely P1 = G1G2G3G4G5. Thereare three loops:
L1 = −G1G2G3G4H3 (66)
L2 = −G1G2H4 (67)
L3 = G3G4H1. (68)
(Any other possible loop would encounter some node twice.) Every loop touches the pathso ∆1 = 1. L2 and L3 are non-touching loops so the graph determinant is
∆ = 1 − L1 − L2 − L3 + L2L3 = 1 + G1G2G3G4H3 + G1G2H4 − G3G4H1. (69)
Then the closed loop transfer function is
Y (s)
R(s)=
G1G2G3G4G5
1 + G1G2G3G4H3 + G1G2H4 − G3G4H1 − G1G2H4G3G4H1(70)
Here’s the transcript of a Maple session that shows that the resulting transfer function isidentical.
> # ECE382 HW1
> #
> restart:
> #
> # Problem 4
> y := m*r^2+m*l*r*cos(theta) - m*l^2*sin(theta);
y := m r2 + m l r cos(θ) − m l2 sin(θ)
ECE382/ME482 Spring 2008 Homework 1 Solution September 22, 2008 17
> dydr := diff(y,r);
dydr := 2m r + m l cos(θ)
> dydth := diff(y,theta);
dydth := −m l r sin(θ) − m l2 cos(θ)> yapp := subs({r=r0,theta= theta0},y) + subs({theta =
> theta0,r=r0},dydr)*(r-r0) + subs({theta =
> theta0,r=r0},dydth)*(theta-theta0);
yapp := m r0 2 + m l r0 cos(θ0) − m l2 sin(θ0) + (2m r0 + m l cos(θ0)) (r − r0 )
+ (−m l r0 sin(θ0) − m l2 cos(θ0)) (θ − θ0)> collect(yapp,{r,theta});
(−m l r0 sin(θ0) − m l2 cos(θ0)) θ + (2m r0 + m l cos(θ0)) r + m r0 2 + m l r0 cos(θ0)
− m l2 sin(θ0) − (2m r0 + m l cos(θ0)) r0 − (−m l r0 sin(θ0) − m l2 cos(θ0)) θ0
> #Problem 5
> G1 := 1/(s+1);
G1 :=1
s + 1> G2 := s/(s^2+2);
G2 :=s
s2 + 2> G3 := 1/s^2;
G3 :=1
s2
> G4 := 1;
G4 := 1
> G5 := 4;
G5 := 4
> H1 := 50;
H1 := 50
> H3 := (s^2+2)/(s^3+14);
H3 :=s2 + 2
s3 + 14> H4 := (4*s+2)/(s+1)^2;
H4 :=4 s + 2
(s + 1)2
> G1*G2/(1+G1*G2*H4);
ECE382/ME482 Spring 2008 Homework 1 Solution September 22, 2008 18
s
(s + 1) (s2 + 2) (1 +s (4 s + 2)
(s + 1)3 (s2 + 2))
> B1 := simplify(G1*G2/(1+G1*G2*H4));
B1 :=(s + 1)2 s
s5 + 5 s3 + 3 s4 + 11 s2 + 8 s + 2> G3*G4/(1-G3*G4*H1);
1
s2 (1 − 50
s2)
> B2 := simplify(G3*G4/(1-G3*G4*H1));
B2 :=1
s2 − 50> G5*B1*B2/(1+B1*B2*H3);
4 (s + 1)2 s/
((s5 + 5 s3 + 3 s4 + 11 s2 + 8 s + 2) (s2 − 50)
(1 +(s + 1)2 s (s2 + 2)
(s5 + 5 s3 + 3 s4 + 11 s2 + 8 s + 2) (s2 − 50) (s3 + 14)))
> B3 := simplify(G5*B1*B2/(1+B1*B2*H3));
B3 := 4 s (s + 1)2 (s3 + 14)/(s10 − 125 s7 − 45 s8 − 1177 s5 − 200 s6 − 3485 s3 + 3 s9
− 2344 s4 − 7668 s2 − 5598 s − 1400)> B3d := denom(B3);
B3d := s10 − 125 s7 − 45 s8 − 1177 s5 − 200 s6 − 3485 s3 + 3 s9 − 2344 s4 − 7668 s2
− 5598 s − 1400
> #Problem 6
> P := G1*G2*G3*G4*G5;
P :=4
(s + 1) s (s2 + 2)> L1 := -G1*G2*G3*G4*H3;
L1 := − 1
(s + 1) s (s3 + 14)> L2 := -G1*G2*H4;
L2 := − s (4 s + 2)
(s + 1)3 (s2 + 2)> L3 := G3*G4*H1;
L3 :=50
s2
> Grdet := 1 - L1 - L2 - L3 + L2*L3;
Grdet := 1 +1
(s + 1) s (s3 + 14)+
s (4 s + 2)
(s + 1)3 (s2 + 2)− 50
s2− 50 (4 s + 2)
(s + 1)3 s (s2 + 2)> sfg := simplify(P/Grdet);
ECE382/ME482 Spring 2008 Homework 1 Solution September 22, 2008 19
sfg := 4 s (s + 1)2 (s3 + 14)/(s10 − 125 s7 − 45 s8 − 1177 s5 − 200 s6 − 3485 s3 + 3 s9
− 2344 s4 − 7668 s2 − 5598 s − 1400)> simplify(B3-sfg);
0