Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

3

Chapter 2

Continuous-Time Linear-Time Invariant


Systems (Chapter 3)

3.1 Using graphical methods, for each pair of signals x(t) and h(t) given in the figures below, compute the convo-
lution y(t) = x(t) ∗ h(t).

x(t) h(t)
2 2

1
1 1

t t
−1 0 1 2 3 −1 0 1 2 3
(a)

h(t)
2
x(t)
1 1

− 21
t 1 t
−1 1 −1 2 1

−1
−1

−2

(b)

Version: 2014-05-08 Copyright 2014


c Michael D. Adams
4 Continuous-Time Linear-Time Invariant Systems (Chapter 3)

x(t) h(t)

2 1

t
−1 1
t −1
0 1
(c)

h(t)
x(t) 2

1
1
t
0 1 2 3
t
−1 0
(d)

h(t)

x(t)
1

1
t
−1 1
t
0 1 2
−1

(e)

x(t) h(t)
5 5
4 4
3 3
2 2
1 1
t t
−3 −2 −1 0 1 2 −2 −1 0
(f)

Solution.

(c)

Copyright 2014
c Michael D. Adams Version: 2014-05-08
5

x(τ )
2
h(t − τ )
1

τ
t −1 t t +1 1
x(τ ) −1

2 (e)

x(τ )
τ
2
1 h(t − τ )
(a) 1

τ
h(τ ) t −1 t t +1 1
−1
1
(f)
τ
−1 1
x(τ )
−1 2
h(t − τ )
1
(b)
τ
t −1 t 1 t +1
h(−τ )
−1
1
(g)
τ
−1 1
x(τ )
−1
2
h(t − τ )

(c) 1

τ
t −1 1 t t +1
h(t − τ ) −1

1
(h)
τ
t −1 t t +1 x(τ )
−1 2
h(t − τ )
(d) 1

τ
1 t −1 t t +1
−1

(i)

First, we consider the case of t < −1. From Figure (e), we can see that

x(t) ∗ h(t) = 0.

Version: 2014-05-08 Copyright 2014


c Michael D. Adams
6 Continuous-Time Linear-Time Invariant Systems (Chapter 3)

Second, we consider the case of −1 ≤ t < 0. From Figure (f), we can see that

Z t+1
x(t) ∗ h(t) = (−2)d τ
0
= [−2τ ]|t+1
0
= −2t − 2.

Third, we consider the case of 0 ≤ t < 1. From Figure (g), we can see that

Z t Z 1
x(t) ∗ h(t) = 2d τ + (−2)d τ
0 t
= [2τ ]|t0 + [−2τ ]|t1
= 2t + (−2 − [−2t])
= 4t − 2.

Fourth, we consider the case of 1 ≤ t < 2. From Figure (h), we can see that

Z 1
x(t) ∗ h(t) = 2d τ
t−1
= [2τ ]|t−1
1

= 2 − [2t − 2]
= 4 − 2t.

Lastly, we consider the case of t > 2. From Figure (i), we can see that

x(t) ∗ h(t) = 0.

Combining the above results, we have



−2t − 2 for −1 ≤ t < 0

4t − 2 for 0 ≤ t < 1
x(t) ∗ h(t) =


4 − 2t for 1 ≤ t < 2

0 otherwise.

(d)

Copyright 2014
c Michael D. Adams Version: 2014-05-08
7

2
x(τ )
h(t − τ )
1
x(τ )
τ
1 t t +1 1 2 3
(e)
τ
1 2 3
h(t − τ )
(a) 2

x(τ )
h(τ ) 1
2
τ
t 1 t +1 2 3
1 (f)

τ h(t − τ )
−1 0 2
(b)
1
x(τ )
h(−τ )
τ
2 1 t 2 t +1 3
(g)
1
h(t − τ )
2
τ
0 1 x(τ )
(c) 1

2 τ
h(t − τ ) 1 2 t 3 t +1
(h)

τ
2 h(t − τ )
t t +1 x(τ )
(d) 1

τ
1 2 3 t t +1
(i)

First, we consider the case of t < 0. From Figure (e), we can see that

x(t) ∗ h(t) = 0.

Version: 2014-05-08 Copyright 2014


c Michael D. Adams
8 Continuous-Time Linear-Time Invariant Systems (Chapter 3)

Second, we consider the case of 0 ≤ t < 1. From Figure (f), we can see that
Z t+1
x(t) ∗ h(t) = 2d τ
1
= [2τ ]|t+1
1
= 2t + 2 − [2]
= 2t.

Third, we consider the case of 1 ≤ t < 2. From Figure (g), we can see that
Z 2 Z t+1
x(t) ∗ h(t) = 2d τ + 2(−τ + 3)d τ
t 2
= [2τ ]|t2 + [−τ + 6τ ]|t+1
2
2

= 4 − 2t + [−(t + 1)2 + 6t + 6] − [−4 + 12]


= 4 − 2t − (t 2 + 2t + 1) + 6t + 6 − 8
= −t 2 + 2t + 1.

Fourth, we consider the case of 2 ≤ t < 3. From Figure (h), we can see that
Z 3
x(t) ∗ h(t) = 2(−τ + 3)d τ
t
= [−τ 2 + 6τ ]|t3
= −9 + 18 − (−t 2 + 6t)
= 9 + t 2 − 6t
= t 2 − 6t + 9.

Last, we consider the case of t > 3. From Figure (i), we can see that

x(t) ∗ h(t) = 0.

Combining the above results, we have




2t for 0 ≤ t < 1
−t 2 + 2t + 1

for 1 ≤ t < 2
x(t) ∗ h(t) = 2
t − 6t + 9
 for 2 ≤ t < 3


0 otherwise.

3.2 For each pair of signals x(t) and h(t) given below, compute the convolution y(t) = x(t) ∗ h(t).
(a) x(t) = eat u(t) and h(t) = e−at u(t) where a is a nonzero real constant;
(b) x(t) = e− jω0 t u(t) and h(t) = e jω0 t u(t) where ω0 is a strictly positive real constant;
(c) x(t) = u(t − 2) and h(t) = u(t + 3);
(d) x(t) = u(t) and h(t) = e−2t u(t − 1);
(e) x(t) = u(t − 1) − u(t − 2) and h(t) = et u(−t).

Solution.

Copyright 2014
c Michael D. Adams Version: 2014-05-08
9

(a) We have

y(t) = x(t) ∗ h(t)


Z ∞
= x(τ )h(t − τ )d τ
−∞
Z ∞
= eaτ u(τ )e−a(t−τ ) u(t − τ )d τ
−∞
Z ∞
= eaτ u(τ )e−at eaτ u(t − τ )d τ
−∞
Z ∞
= e−at e2aτ u(τ )u(t − τ )d τ
−∞
Z t
= e−at e2aτ d τ for t ≥ 0
0
−at 1 2aτ t
= e [ 2a e ]|0 for a 6= 0
1 −at 2aτ t
= 2a e [e ]|0
1 −at 2at
= 2a e [e − 1]
[e − e−at ].
1 at
= 2a

Thus, we have that


(
1 at
2a [e − e−at ] for t ≥ 0
y(t) =
0 otherwise
= 1 at
2a [e − e−at ]u(t).

(c) We have

y(t) = x(t) ∗ h(t)


Z ∞
= x(τ )h(t − τ )d τ
−∞
Z ∞
= u(τ − 2)u(t − τ + 3)d τ
−∞
Z t+3
= dτ for t ≥ −1
2
= [τ ]|t+3
2
= t +3−2
= t + 1.

Thus, we have that


(
t + 1 for t ≥ −1
y(t) =
0 otherwise
= [t + 1]u(t + 1).

Version: 2014-05-08 Copyright 2014


c Michael D. Adams
10 Continuous-Time Linear-Time Invariant Systems (Chapter 3)

(d) We have
Z ∞
x(t) ∗ h(t) = x(τ )h(t − τ )d τ
−∞
Z ∞
= u(τ )e−2(t−τ ) u(t − τ − 1)d τ
−∞

e−2t 0t−1 e2τ d τ


( R
for t > 1
=
0 otherwise
Z t−1
= [u(t − 1)]e−2t e2τ d τ
0

 t−1
= [u(t − 1)]e−2t
1
2e

0
 2τ  t−1
= 21 [u(t − 1)]e−2t e
0
= 21 [u(t − 1)]e−2t [e2t−2 − 1]
= 21 [u(t − 1)][e−2 − e−2t ]
= [− 12 e−2t + 21 e−2 ]u(t − 1).

(e) We have
Z ∞
x(t) ∗ h(t) = x(τ )h(t − τ )d τ
−∞
Z ∞
= [u(τ − 1) − u(τ − 2)]et−τ u(−[t − τ ])d τ .
−∞
In order to evaluate the above integral, we can see that there are three cases to consider: i) t < 1, ii) 1 ≤ t < 2,
and iii) t ≥ 2. First, we consider the case of t < 1. We have
Z 2
x(t) ∗ h(t) = et−τ u(τ − t)d τ
1
Z 2
= et−τ (1)d τ
1
Z 2
= et e−τ d τ
1
= et −e−τ 1
  2

= et [−e−2 + e−1 ]
= et [e−1 − e−2 ]
= et−1 − et−2 .
Second, we consider the case of 1 ≤ t < 2. We have
Z 2
x(t) ∗ h(t) = et−τ u(τ − t)d τ
1
Z 2
= et−τ (1)d τ
t
Z 2
= et e−τ d τ
t
= et −e−τ t
  2

= et [−e−2 + e−t ]
= 1 − et−2 .

Copyright 2014
c Michael D. Adams Version: 2014-05-08
11

Third, we consider the case of t ≥ 2. We have


Z 2
x(t) ∗ h(t) = et−τ u(τ − t)d τ
1
Z 2
= et−τ (0)d τ
1
= 0.

Combining these results, we have



t−1 t−2
e − e
 for t < 1
x(t) ∗ h(t) = 1 − et−2 for 1 ≤ t < 2

0 for t ≥ 2.

3.3 Let y(t) = x(t) ∗ h(t). Given that


Z ∞
v(t) = x(−τ − b)h(τ + at)d τ ,
−∞

where a and b are constants, express v(t) in terms of y(t).


Solution.
From the definition of v(t), we have
Z ∞
v(t) = x(−τ − b)h(τ + at)d τ .
−∞

Now, we employ a change of variable. Let λ = −τ − b so that τ = −λ − b and d τ = −d λ . Applying this


change of variable and simplifying, we obtain
Z −∞
v(t) = x(λ )h([−λ − b] + at)(−1)d λ
Z∞∞
= x(λ )h(at − b − λ )d λ
−∞
Z ∞
= x(λ )h([at − b] − λ )d λ
−∞
= [x(ρ ) ∗ h(ρ )]|ρ =at−b
= y(at − b).

Therefore, we have that v(t) = y(at − b).

3.4 Consider the convolution y(t) = x(t) ∗ h(t). Assuming that the convolution y(t) exists, prove that each of the
following assertions is true:
(a) If x(t) is periodic then y(t) is periodic.
(b) If x(t) is even and h(t) is odd, then y(t) is odd.
Solution.
(a) From the definition of convolution, we have

y(t) = x(t) ∗ h(t)


Z ∞
= x(τ )h(t − τ )d τ .
−∞

Version: 2014-05-08 Copyright 2014


c Michael D. Adams
12 Continuous-Time Linear-Time Invariant Systems (Chapter 3)

Suppose that x(t) is periodic with period T . Then, we have x(t) = x(t + T ) and we can rewrite the above integral
as
Z ∞
y(t) = x(τ + T )h(t − τ )d τ .
−∞

Now, we employ a change of variable. Let λ = τ + T so that τ = λ − T and d λ = d τ . This yields


Z ∞
y(t) = x(λ )h(t − [λ − T ])d λ
−∞
Z ∞
= x(λ )h(t + T − λ )d λ
−∞
Z ∞
= x(λ )h([t + T ] − λ )d λ
−∞
= [x(v) ∗ h(v)]|v=t+T
= y(v)|v=t+T
= y(t + T ).

Therefore, y(t) is periodic with period T .

3.7 Find the impulse response of the LTI system characterized by each of the equations below. In each case, the
input and output of the system are denoted as x(t) and y(t), respectively.
Z t+1
(a) y(t) = x(τ )d τ ;
Z−∞

(b) y(t) = x(τ + 5)eτ −t+1 u(t − τ − 2)d τ ;
Z −∞
t
(c) y(t) = x(τ )v(t − τ )d τ and
Z−∞
t
(d) y(t) = x(τ )d τ .
t−1
Solution.
(a) Let h(t) denote the impulse response of the system.
Z t+1
h(t) = δ (τ )d τ
−∞
(
1 for t > −1
=
0 for t < −1
= u(t + 1).

(b) Let h(t) denote the impulse response of the system.


Z ∞
h(t) = δ (τ + 5)eτ −t+1 u(t − τ − 2)d τ
−∞
−5−t+1
=e u(t − [−5] − 2)
−t−4
=e u(t + 3).

(c) Let h(t) denote the impulse response of the system. We have
Z t
h(t) = δ (τ )v(t − τ )d τ .
−∞

Copyright 2014
c Michael D. Adams Version: 2014-05-08
13

Now, we employ a change of variable. Let λ = τ − t so that τ = λ + t and d λ = d τ . Applying this change of
variable, we obtain
Z 0
h(t) = δ (λ + t)v(t − [λ + t])d λ
−∞
Z 0
= δ (λ + t)v(−λ )d λ .
−∞

From the equivalence property of the unit-impulse function, we can write


Z 0
h(t) = δ (λ + t)v(t)d λ
−∞
Z 0
= v(t) δ (λ + t)d λ
−∞
= v(t)u(t).

3.8 Consider the system with input x(t) and output y(t) as shown in the figure below. Suppose that the systems H1 ,
H2 , and H3 are LTI systems with impulse responses h1 (t), h2 (t), and h3 (t), respectively.

x(t) y(t)
H1 H2 +

H3

(a) Find the impulse response h(t) of the overall system in terms of h1 (t), h2 (t), and h3 (t).
(b) Determine the impulse response h(t) in the specific case that

h1 (t) = δ (t + 1), h2 (t) = δ (t), and h3 (t) = δ (t).

Solution.
(a) Let v(t) denote the output of the system H1 . From the block diagram, we have

v(t) = x(t) ∗ h1 (t)


y(t) = v(t) ∗ [h2 (t) + h3 (t)] + x(t).

Combining these equations yields

y(t) = v(t) ∗ [h2 (t) + h3 (t)] + x(t)


= [x(t) ∗ h1 (t)] ∗ [h2 (t) + h3 (t)] + x(t)
= x(t) ∗ [h1 (t) ∗ [h2 (t) + h3 (t)]] + x(t)
= x(t) ∗ [h1 (t) ∗ h2 (t) + h1 (t) ∗ h3 (t)] + x(t) ∗ δ (t)
= x(t) ∗ [h1 (t) ∗ h2 (t) + h1 (t) ∗ h3 (t) + δ (t)].

Therefore, we have

h(t) = h1 (t) ∗ h2 (t) + h1 (t) ∗ h3 (t) + δ (t).

Version: 2014-05-08 Copyright 2014


c Michael D. Adams
14 Continuous-Time Linear-Time Invariant Systems (Chapter 3)

(b) Substituting the given expression for h1 (t), h2 (t), and h3 (t) into the expression for h(t), we obtain

h(t) = δ (t + 1) ∗ δ (t) + δ (t + 1) ∗ δ (t) + δ (t)


= δ (t + 1) + δ (t + 1) + δ (t)
= 2δ (t + 1) + δ (t).

3.9 Consider a LTI system whose response to the signal x1 (t) = u(t) − u(t − 1) is the signal y1 (t). Determine the
response y2 (t) of the system to the input x2 (t) shown in the figure below in terms of y1 (t).

x2 (t)

t
−3 −2 −1 1 2 3

−1

−2

−3

Solution.
First, we express x2 (t) in terms of x1 (t). This yields

x2 (t) = 2x1 (t + 2) + x1 (t + 1) + x1 (t) − 2x1 (t − 1).

Then, we observe that the system is LTI. This implies that

2x1 (t + 2) + x1 (t + 1) + x1 (t) − 2x1 (t − 1) → 2y1 (t + 2) + y1 (t + 1) + y1 (t) − 2y1 (t − 1).

Therefore, we have

y2 (t) = 2y1 (t + 2) + y1 (t + 1) + y1 (t) − 2y1 (t − 1).

3.10 Suppose that we have the system shown in the figure below with input x(t) and output y(t). This system is
formed by the interconnection of two LTI systems with the impulse responses h1 (t) and h2 (t).

x(t) y(t)
h1 (t) h2 (t)

For each pair of h1 (t) and h2 (t) given below, find the output y(t) if the input x(t) = u(t).
(a) h1 (t) = δ (t) and h2 (t) = δ (t);
(b) h1 (t) = δ (t + 1) and h2 (t) = δ (t + 1);
(c) h1 (t) = e−3t u(t) and h2 (t) = δ (t).

Copyright 2014
c Michael D. Adams Version: 2014-05-08
15

Solution. Let h(t) denote the impulse response of the overall system.
(b) We have

h(t) = h1 (t) ∗ h2 (t)


= δ (t + 1) ∗ δ (t + 1)
Z ∞
= δ (τ + 1)δ (t − τ + 1)d τ
−∞
= δ (t + 2).

The output y(t) is given by

y(t) = x(t) ∗ h(t)


= u(t) ∗ δ (t + 2)
= u(t + 2).

(c) First, we calculate the impulse response h(t) of the system. We have that

h(t) = h1 (t) ∗ h2 (t)


= [e−3t u(t)] ∗ δ (t)
= e−3t u(t).

x(τ )h(t − τ )d τ . By drawing graphs of x(τ ) and
R
Now, we compute the convolution y(t) = x(t) ∗ h(t) = −∞
h(t − τ ) and applying the appropriate logic, we conclude that there are two cases to consider for the computation
of y(t): t < 0 and t ≥ 0. In the case that t < 0, we have that y(t) is trivially zero. So, we now consider the case
that t ≥ 0. For t ≥ 0, we have that y(t) is given by

y(t) = x(t) ∗ h(t)


= h(t) ∗ x(t)
Z ∞
= e−3τ u(τ )u(t − τ )d τ
−∞
Z t
= e−3τ d τ for t > 0
0
= [− 31 e−3τ ]|t0
= − 13 [e−3t − 1]
= − 13 e−3t + 13 .

Thus, we have that


(
− 13 e−3t + 13 for t ≥ 0
y(t) =
0 for t < 0
= [− 13 e−3t + 31 ]u(t).

3.12 Consider the LTI systems with the impulse responses given below. Determine whether each of these systems is
causal and/or memoryless.
(a) h(t) = (t + 1)u(t − 1);
(b) h(t) = 2δ (t + 1);
(c) h(t) = ωπc sinc ωct;

Version: 2014-05-08 Copyright 2014


c Michael D. Adams
16 Continuous-Time Linear-Time Invariant Systems (Chapter 3)

(d) h(t) = e−4t u(t − 1);


(e) h(t) = et u(−1 − t);
(f) h(t) = e−3|t| ; and
(g) h(t) = 3δ (t).
Solution.
A LTI system with impulse response h(t) is memoryless if h(t) = 0 for all t 6= 0. Therefore, the systems in (a),
(b), (c), (d), (e), and (f) all have memory, while the system in (g) is memoryless.
A LTI system with impulse response h(t) is causal if h(t) = 0 for all t < 0. Therefore, the systems in (a), (d),
and (g) are causal, while the systems in (b), (c), (e), and (f) are not causal.

3.13 Consider the LTI systems with the impulse responses given below. Determine whether each of these systems is
BIBO stable.
(a) h(t) = eat u(−t) where a is a strictly positive real constant;
(b) h(t) = (1/t)u(t − 1);
(c) h(t) = et u(t);
(d) h(t) = δ (t − 10);
(e) h(t) = rectt; and
(f) h(t) = e−|t| .
Solution.
(a) A LTI system with impulse response h(t) is BIBO stable if and only if h(t) is absolutely integrable. From
the given h(t), we have
Z ∞ Z ∞
eat u(−t) dt

|h(t)| dt =
−∞ −∞
Z ∞
= eat u(−t)dt
−∞
Z 0
= eat dt
−∞
1 at
 0
= ae

−∞
for a 6= 0
1
 at  0
= a e −∞
1
= a [1 − 0]
1
= a
< ∞.

Therefore, the system is BIBO stable.


(b) A LTI system with impulse response h(t) is BIBO stable if and only if h(t) is absolutely integrable. From
the given h(t), can write
Z ∞ Z ∞
1 u(t − 1) dt

|h(t)| dt = t
−∞ −∞
Z ∞
1
= t u(t − 1)dt
−∞
Z ∞
1
= t dt
1
= [lnt]|∞
1
= ln ∞ − ln 1
= ∞.

Therefore, the system is not BIBO stable.

Copyright 2014
c Michael D. Adams Version: 2014-05-08
17

(c) A LTI system with impulse response h(t) is BIBO stable if and only if h(t) is absolutely integrable. From
the given h(t), we can write
Z ∞ Z ∞
et u(t) dt

|h(t)| dt =
−∞ −∞
Z ∞
= et u(t)dt
−∞
Z ∞
= et dt
0
= [et ]|∞
0
= ∞.

Therefore, the system is not BIBO stable.


(f) A LTI system with impulse response h(t) is BIBO stable if and only if h(t) is absolutely integrable. From
the given h(t), we can write
Z ∞ Z ∞
−|t|
|h(t)| dt = e dt
−∞ −∞
Z ∞
= e−|t| dt
−∞
Z 0 Z ∞
= e−|t| dt + e−|t| dt
−∞ 0
Z 0 Z ∞
= et dt + e−t dt
−∞ 0
= [et ]|0−∞ + [−e−t ]|∞
0
= 1+1
=2
< ∞.

Therefore, the system is BIBO stable.

3.14 Suppose that we have two LTI systems with impulse responses

h1 (t) = 21 δ (t − 1) and h2 (t) = 2δ (t + 1).

Determine whether these systems are inverses of one another.


Solution.
These systems are inverses if h1 (t) ∗ h2 (t) = δ (t). We have
Z ∞
h1 (t) ∗ h2 (t) = h1 (τ )h2 (t − τ )d τ
−∞
Z ∞
2 δ (τ − 1)2δ (t − τ + 1)d τ
1
=
−∞
Z ∞
= δ (τ − 1)δ (t − τ + 1)d τ
−∞
= δ (t).

Therefore, the systems are inverses of one another.

Version: 2014-05-08 Copyright 2014


c Michael D. Adams
31

Chapter 9

MATLAB (Appendix E)

E.103 Let F(ω ) denote the complex-valued function of the real variable ω given by

1
F(ω ) = .
jω + 1

Write a program to plot |F(ω )| and arg F(ω ) for ω in the interval [−10, 10]. Use subplot to place both plots
on the same figure.

Solution.

w = linspace ( -10 , 10 , 500);


f = (j * w + 1) .ˆ ( -1);
subplot (2 , 1, 1);
plot (w , abs (f ));
title ( ’ Magnitude ’);
xlabel ( ’\ omega ’);
ylabel ( ’|F (\ omega )| ’);
subplot (2 , 1, 2);
plot (w , unwrap ( angle (f )));
title ( ’ Argument ’);
xlabel ( ’\ omega ’);
ylabel ( ’arg F (\ omega ) ’);

Version: 2014-05-08 Copyright 2014


c Michael D. Adams
32 MATLAB (Appendix E)

Magnitude
1

0.8

|F(ω)| 0.6

0.4

0.2

0
−10 −8 −6 −4 −2 0 2 4 6 8 10
ω

Argument
1.5

0.5
arg F(ω)

−0.5

−1

−1.5
−10 −8 −6 −4 −2 0 2 4 6 8 10
ω

E.108 In this problem, we consider an algorithm for generating an ordered list of n points in the plane {p0 , p1 , . . . , pn−1 }.
The first point p0 is chosen as the origin (i.e., p0 = [ 0 0 ]T ), with the remaining points being given by the formula
i−1  
cos θ sin θ

i
pi = pi−1 + .
− sin θ cos θ 0

(a) Using MATLAB, write a function called drawpattern that takes n and θ as input arguments (in that order)
with θ being specified in degrees, and then computes and plots the points {p0 , p1 , . . . , pn−1 } connected by
straight lines (i.e., draw a line from p0 to p1 , p1 to p2 , p2 to p3 , and so on). When performing the plotting, be
sure to use axis(’equal’) in order to maintain the correct aspect ratio for the plot. For illustrative purposes,
the plots produced for two sets of θ and n values are shown in Figure 9.1.
(b) Generate the plots obtained by invoking drawpattern with n = 100 and θ set to each of the following
values: 89◦ , 144◦ , and 154◦ . [Note: In MATLAB, the sin and cos functions take values in radians, not
degrees.]
Solution.
(a) The drawpattern function can be implemented using the code below.

Listing 9.1: drawpattern.m


function drawpattern (n , theta )

% Convert from degrees to radians.


t = theta * pi / 180;

% Generate the list of points.


p = [0 0] ’;
x = p ’;
for i = 1 : (n - 1)

Copyright 2014
c Michael D. Adams Version: 2014-05-08
33

40 40

30 30

20 20

10 10

0 0

−10 −10

−20 −20

−30 −30

−40 −40

−50
−60 −40 −20 0 20 40 60 −60 −40 −20 0 20 40 60

(a) (b)

Figure 9.1: Sample plots obtained from drawpattern. (a) θ = 90◦ and n = 100; (b) θ = 166◦ and n = 100.

p = p + [ cos (t) sin (t ); -sin (t) cos (t )] ˆ (i - 1) * [i 0] ’;


x = [x; p ’];
end

% Plot the list of points.


plot (x(: , 1) , x(: , 2));
axis ( ’ equal ’);

% Print the plot to a file.


% eval(sprintf(’print -dps data/drawpattern_%d_%d.ps’, theta, n))

(b) The plots obtained with the drawpattern function are shown below.

Version: 2014-05-08 Copyright 2014


c Michael D. Adams
34 MATLAB (Appendix E)

50
50

40 40

30 30

20
20

10
10

0
0
−10
−10
−20

−20
−30

−40 −30

−50 −40
−60 −40 −20 0 20 40 60 −40 −20 0 20 40 60

θ = 89◦ , n = 100 θ = 144◦ , n = 100

40

30

20

10

−10

−20

−30

−40

−50 −40 −30 −20 −10 0 10 20 30 40 50

θ = 154◦ , n = 100

Copyright 2014
c Michael D. Adams Version: 2014-05-08

You might also like