ch2 - Ex - Solutions For Continuous-Time Signals and Systems Michael D. Adams

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15
At a glance
Powered by AI
The key takeaways are about different types of signals, signal transformations, and common MATLAB functions for signal processing.

Signals can be even, odd, or neither even nor odd based on their behavior under time reversal.

Signals can be transformed through operations like time shifting, time scaling, amplitude shifting and amplitude scaling.

1

Chapter 1

Continuous-Time Signals and Systems


(Chapter 2)

2.1 Identify the time and/or amplitude transformations that must be applied to the signal x(t) in order to obtain each
of the signals specified below. Choose the transformations such that time shifting precedes time scaling and
amplitude scaling precedes amplitude shifting. Be sure to clearly indicate the order in which the transformations
are to be applied.
(a) y(t) = x(2t − 1);
(b) y(t) = x( 12 t + 1);
(c) y(t) = 2x(− 12 t + 1) + 3;
(d) y(t) = − 12 x(−t + 1) − 1; and
(e) y(t) = −3x(2[t − 1]) − 1.

Solution.

(e) To obtain y(t) from x(t), we apply the following transformations: 1) time shift by 2 (i.e., shift to the right
by 2), 2) time scale by 2 (i.e., compress horizontally by 2), 3) amplitude scale by −3 (i.e., expand vertically by
3 and invert), and 4) amplitude shift by −1 (i.e., shift down by 1).

2.3 Given the signal x(t) shown in the figure below, plot and label each of the following signals:
(a) x(t − 1);
(b) x(2t);
(c) x(−t);
(d) x(2t + 1); and
(e) 41 x(− 12 t + 1) − 21 .

Version: 2014-05-08 Copyright 2014


c Michael D. Adams
2 Continuous-Time Signals and Systems (Chapter 2)

x(t)

t
−3 −2 −1 1 2 3

−1

−2

−3

Solution.

(a) (b)
x(t − 1) x(2t)
2 2

1 1

t t
−1 1 2 3 −2 −1 1 2

−1 −1

−2 −2

(c) (d)
x(−t) x(2t + 1)
2
2

1 1

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

−1 −1

−2
−2

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

(e)
1
− 12 t + 1 − 21

4x

1
2

t
−4 −2 2 4 6 8

··· − 21 ···
−1

2.4 Determine whether each of the following functions is even, odd, or neither even nor odd:
(a) x(t) = t 3 ;
(b) x(t) = t 3 |t|;

(c) x(t) = t 3 ;
(d) x(t) = (cos 2π t)(sin 2π t);
(e) x(t) = e j2π t ; and
(f) x(t) = 12 [et + e−t ].
Solution. (a) From the definition of x(t), we have

x(−t) = (−t)3
= −t 3
= −x(t).

Since x(t) = −x(−t) for all t, x(t) is odd.


(e) From the definition of x(t), we have

x(−t) = e− j2π t
= cos(−2π t) + j sin(−2π t)
= cos 2π t − j sin 2π t.

Thus, we can clearly see that x(−t) 6= x(t) and x(−t) 6= −x(t). Therefore, x(t) is neither even nor odd.
(f) From the definition of x(t), we have

x(−t) = 21 [e−t + e−(−t) ]


= 12 [et + e−t ]
= x(t).

Thus, we can clearly see that x(−t) = x(t) for all t. Therefore, x(t) is even.

2.5 Prove each of the following assertions:


(a) The sum of two even signals is even.
(b) The sum of two odd signals is odd.
(c) The sum of an even signal and an odd signal is neither even nor odd.
(d) The product of two even signals is even.
(e) The product of two odd signals is even.
(f) The product of an even signal and an odd signal is odd.
Solution.

Version: 2014-05-08 Copyright 2014


c Michael D. Adams
4 Continuous-Time Signals and Systems (Chapter 2)

(a) Let y(t) = x1 (t) + x2 (t) where x1 (t) and x2 (t) are even. From the definition of y(t), we have

y(−t) = x1 (−t) + x2 (−t).

Since x1 (t) and x2 (t) are even, we have that x1 (−t) = x1 (t) and x2 (−t) = x2 (t). So, we can simplify the above
expression for y(t) as

y(−t) = x1 (t) + x2 (t)


= y(t).

Thus, y(t) = y(−t). Therefore, y(t) is even.


(c) Let y(t) = x1 (t) + x2 (t), where x1 (t) and x2 (t) are even and odd signals, respectively. From the definition of
y(t), we have

y(−t) = x1 (−t) + x2 (−t).

Since x1 (t) is even, x1 (−t) = x1 (t). Similarly, since x2 (t) is odd, x2 (−t) = −x2 (t). Using these observations,
we can simplify the above expression for y(t) as

y(−t) = x1 (t) + [−x2 (t)]


= x1 (t) − x2 (t).

Clearly, y(−t) 6= y(t) and y(−t) 6= −y(t). Thus, y(t) is neither even nor odd.
(f) Let y(t) = x1 (t)x2 (t), where x1 (t) and x2 (t) are even and odd signals, respectively. From the definition of
y(t), we have

y(−t) = x1 (−t)x2 (−t).

Since x1 (t) is even, x1 (−t) = x1 (t). Similarly, since x2 (t) is odd, x2 (−t) = −x2 (t). Using these observations,
we can simplify the above expression for y(t) as

y(−t) = x1 (t)[−x2 (t)]


= −x1 (t)x2 (t)
= −y(t).

Thus, we have that y(t) = −y(−t). Therefore, y(t) is odd.

2.8 Suppose h(t) is a causal signal and has the even part he (t) given by

he (t) = t[u(t) − u(t − 1)] + u(t − 1) for t > 0.

Find h(t) for all t.


Solution.
We have that

for t > 0: he (t) = t[u(t) − u(t − 1)] + u(t − 1)


= tu(t) + (−t + 1)u(t − 1).

Since he (t) is even, we can deduce that

for t < 0: he (t) = he (−t)


= (−t)u(−t) + (t + 1)u(−t − 1).

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

Let ho (t) denote the odd part of h(t). Since h(t) is causal and h(t) = he (t) + ho (t), we know that
for t < 0: ho (t) = −he (t).
Using this observation, we can deduce that
for t < 0: ho (t) = −he (t)
= −[(−t)u(−t) + (t + 1)u(−t − 1)]
= (t)u(−t) + (−t − 1)u(−t − 1).
Since ho (t) is odd, we have that
for t > 0: ho (t) = −ho (−t)
= −[(−t)u(t) + (t − 1)u(t − 1)]
= tu(t) + (−t + 1)u(t − 1).
Therefore, we can conclude that
h(t) = he (t) + ho (t)
= [tu(t) + (−t + 1)u(t − 1)] + [tu(t) + (−t + 1)u(t − 1)]
= (2t)u(t) + (2 − 2t)u(t − 1).

2.9 Determine whether each of the signals given below is periodic. If the signal is periodic, find its fundamental
period.
(a) x(t) = cos 2π t + sin 5t;
(b) x(t) = [cos(4t − π3 )]2 ;
(c) x(t) = e j2π t + e j3π t ; and
(d) x(t) = 1 + cos 2t + e j5t .
Solution.
(a) Let T1 and T2 denote the periods of cos 2π t and sin 5t, respectively. We have
2π 2π
T1 = 2π = 1 and T2 = 5 .

Since T1 /T2 is irrational, x(t) is not periodic.


(b) Since cos 4t − π3 is periodic and the square of a periodic function is periodic, x(t) is periodic. From the


definition of x(t), we can write


x(t) = cos2 4t − π3

i2
= 21 e j(4t−π /3) + e− j(4t−π /3)
h 

= 41 e j(4t−π /3)(2) + 2 + e− j(4t−π /3)(2)


h i

= 41 e j(8t−2π /3) + e− j(8t−2π /3) + 2


h i

= 41 [2 cos(8t − 2π /3) + 2]
= 21 cos(8t − 2π /3) + 21 .

Thus, the period T of x(t) is T = 8 = π4 .
(c) Let T1 and T2 denote the periods of e j2π t and e j3π t , respectively. We have
2π 2π T1 1
T1 = 2π = 1, T2 = 3π = 23 , and = = 3.
T2 2/3 2
Since T1 /T2 is rational, x(t) is periodic. The period T of x(t) is T = 2T1 = 2.

Version: 2014-05-08 Copyright 2014


c Michael D. Adams
6 Continuous-Time Signals and Systems (Chapter 2)

2.10 Evaluate
R∞
the following
 integrals:
(a) −∞ sin 2t + π4 δ (t)dt;
[cos τ ]δ (τ + π )d τ ;
Rt
(b) R −∞

(c) −∞ x(t)δ (at − b)dt where a and b are real constants and a 6= 0;
(d) R 02 e j2t δ (t − 1)dt; and
R

(e) −∞ t
δ (τ )d τ .
Solution.
(a) From the sifting property of the unit-impulse function, we have
Z ∞
sin 2t + π4 δ (t)dt = sin 2t + π4 t=0
  
−∞
= sin π4


= √1 .
2

(b) From the sifting property of the unit-impulse function, we have


(
[cos τ ]|τ =−π for t > −π
Z t
[cos τ ]δ (τ + π )d τ =
−∞ 0 for t < −π
(
cos(−π ) for t > −π
=
0 for t < −π
(
−1 for t > −π
=
0 for t < −π
= −u(t + π ).

(c) We use a change of variable. Let λ = at so that t = λ /a and d λ = adt. Performing the change of variable
and simplifying yields

 ∞ x λ δ (λ − b) 1 d λ for a > 0
R   
Z ∞
−∞ a a
x(t)δ (at − b)dt = R −∞  
λ
∞ x a δ (λ − b) a d λ
1

−∞  for a < 0
 1 ∞ x λ δ (λ − b)d λ
 R  
a −∞ a  for a > 0
= ∞ λ

a −∞ x a δ (λ − b)d λ
− 1
R
for a < 0
Z ∞  
1
= |a| x λa δ (λ − b)d λ
−∞

x λa
h  i
1
= |a|

λ =b
1
x ab .

= |a|

(d) Since the nonzero part of δ (t − 1) is contained on the interval [0, 2], we can deduce from the sifting property
that
Z 2
e j2t δ (t − 1)dt = e j2t t=1
 
0
= e j2 .

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

(e) We have
Z t
(
1 for t > 0
δ (τ )d τ =
−∞ 0 for t < 0
= u(t).

2.11 Suppose that we have the signal x(t) shown in the figure below. Use unit-step functions to find a single expres-
sion for x(t) that is valid for all t.
x(t)

t
−3 −2 −1 0 1 2 3

Solution.
We have
x(t) = [t + 2][u(t + 2) − u(t)] + [−t + 2][u(t) − u(t − 1)] + [1][u(t − 1) − u(t − 2)]
= [t + 2]u(t + 2) + [−t − 2 − t + 2]u(t) + [t − 2 + 1]u(t − 1) + [−1]u(t − 2)
= (t + 2)u(t + 2) + (−2t)u(t) + (t − 1)u(t − 1) + (−1)u(t − 2).

2.12 Determine whether the system with input x(t) and output y(t) defined by each of the following equations is
linear:
x(τ )d τ ;
R t+1
(a) y(t) = t−1
(b) y(t) = ex(t) ;
(c) y(t) = Even{x(t)}; and
(d) y(t) = x2 (t).
Solution.
(a) Let y1 (t), y2 (t), and y3 (t) denote the responses of the system to the inputs x1 (t), x2 (t), and a1 x1 (t) + a2 x2 (t),
respectively, where a1 and a2 are complex constants. If y3 (t) = a1 y1 (t) + a2 y2 (t) for all x1 (t), x2 (t), a1 , and a2 ,
then the system is linear. We have
Z t+1
y1 (t) = x1 (τ )d τ ,
t−1
Z t+1
y2 (t) = x2 (τ )d τ , and
t−1
Z t+1
y3 (t) = [a1 x1 (τ ) + a2 x2 (τ )]d τ
t−1
Z t+1 Z t+1
= a1 x1 (τ )d τ + a2 x2 (τ )d τ
t−1 t−1
Z t+1 Z t+1
= a1 x1 (τ )d τ + a2 x2 (τ )d τ
t−1 t−1
= a1 y1 (t) + a2 y2 (t).

Version: 2014-05-08 Copyright 2014


c Michael D. Adams
8 Continuous-Time Signals and Systems (Chapter 2)

Since y3 (t) = a1 y1 (t) + a2 y2 (t), the system is linear.


(c) Let y1 (t), y2 (t), and y3 (t) denote the responses of the system to the inputs x1 (t), x2 (t), and a1 x1 (t) + a2 x2 (t),
respectively, where a1 and a2 are complex constants. If y3 (t) = a1 y1 (t) + a2 y2 (t) for all x1 (t), x2 (t), a1 , and a2 ,
then the system is linear. We have

y1 (t) = 12 [x1 (t) + x1 (−t)],


y2 (t) = 12 [x2 (t) + x2 (−t)], and
y3 (t) = 21 [(a1 x1 (t) + a2 x2 (t)) + (a1 x1 (−t) + a2 x2 (−t))]
= 12 [a1 x1 (t) + a1 x1 (−t) + a2 x2 (t) + a2 x2 (−t)]
= 12 a1 [x1 (t) + x1 (−t)] + 21 a2 [x2 (t) + x2 (−t)]
= a1 y1 (t) + a2 y2 (t).

Since y3 (t) = a1 y1 (t) + a2 y2 (t), the system is linear.


(d) Let y1 (t), y2 (t), and y3 (t) denote the responses of the system to the inputs x1 (t), x2 (t), and a1 x1 (t) + a2 x2 (t),
respectively, where a1 and a2 are complex constants. If y3 (t) = a1 y1 (t) + a2 y2 (t) for all x1 (t), x2 (t), a1 , and a2 ,
then the system is linear. We have

y1 (t) = x12 (t)


y2 (t) = x22 (t)
y3 (t) = [a1 x1 (t) + a2 x2 (t)]2
= a21 x12 (t) + 2a1 a2 x1 (t)x2 (t) + a22 x22 (t)
6= a1 y1 (t) + a2 y2 (t).

Since y3 (t) 6= a1 y1 (t) + a2 y2 (t), the system is not linear.

2.13 Determine whether the system with input x(t) and output y(t) defined by each of the following equations is time
invariant:
(a) y(t) = dtd x(t);
(b) y(t) = Even{x(t)};
(c) y(t) = Rtt+1 x(τ − α )d τ where α is a constant;
R

(d) y(t) = −∞ x(τ )x(t − τ )d τ ;
(e) y(t) = x(−t); and
x(τ )d τ .
R 2t
(f) y(t) = −∞
Solution.
(a) Let y1 (t) and y2 (t) denote the responses of the system to the inputs x1 (t) and x2 (t) = x1 (t −t0 ), respectively,
where t0 is a constant. If y2 (t) = y1 (t − t0 ) for all x1 (t) and t0 , then the system is time invariant. (Note that
d d
dt x2 (t) = dt x1 (t − t0 ).) We have

d
y1 (t) = dt x1 (t),
d
y2 (t) = dt x2 (t)
d
= dt x1 (t − t0 ), and
d 
y1 (t − t0 ) = dv x1 (v) v=t−t0

d
= dt x1 (t − t0 )
= y2 (t).

Since y2 (t) = y1 (t − t0 ), the system is time invariant.

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

(c) Let y1 (t) and y2 (t) denote the responses of the system to the inputs x1 (t) and x2 (t) = x1 (t −t0 ), respectively,
where t0 is a constant. If y2 (t) = y1 (t − t0 ) for all x1 (t) and t0 , then the system is time invariant. We have
Z t+1
y1 (t) = x1 (τ − α )d τ and
t
Z t+1
y2 (t) = x2 (τ − α )d τ
t
Z t+1
= x1 (τ − α − t0 )d τ .
t

Now, we apply a change of variable. Let λ = τ − t0 so that τ = λ + t0 and d λ = d τ . Applying this change of
variable yields
Z t+1−t0
y2 (t) = x1 (λ − α )d λ
t−t0
= y1 (t − t0 ).

Since y2 (t) = y1 (t − t0 ), the system is time invariant.


(e) Let y1 (t) and y2 (t) denote the responses of the system to the inputs x1 (t) and x2 (t) = x1 (t −t0 ), respectively,
where t0 is a constant. If y2 (t) = y1 (t − t0 ) for all x1 (t) and t0 , then the system is time invariant. We have

y1 (t) = x1 (−t),
y2 (t) = x2 (−t)
= x1 (−t − t0 ), and
y1 (t − t0 ) = x1 (−[t − t0 ])
= x1 (−t + t0 )
6= y2 (t).

Since y2 (t) 6= y1 (t − t0 ), the system is not time invariant.

2.14 Determine whether the system with input x(t) and output y(t) defined by each of the following equations is
causal and/or memoryless:
x(τ )d τ ;
R 2t
(a) y(t) = −∞
(b) y(t) = Odd{x(t)};
(c) y(t) = x(t − 1) + 1;
(d) y(t) = R t∞ x(τ )d τ ; and
R

(e) y(t) = −∞ t
x(τ )δ (τ )d τ .
Solution. If the output y(t) at t = t0 for any arbitrary t0 depends only on the input x(t) for t ≤ t0 , then the system
is causal. If the output y(t) at t = t0 for any arbitrary t0 depends only on the input x(t) at t = t0 , then the system
is memoryless.
(a) From the equation
Z 2t
y(t) = x(τ )d τ ,
−∞

we can see that y(t)|t=t0 depends on x(t) for −∞ < t ≤ 2t0 . Therefore, the system is not causal (since 2t0 > t0
for any positive t0 ) and the system is not memoryless.
(c) We have

y(t) = x(t − 1) + 1.

Version: 2014-05-08 Copyright 2014


c Michael D. Adams
10 Continuous-Time Signals and Systems (Chapter 2)

Consider y(t)|t=t0 . This quantity depends on x(t) for t = t0 −1. Therefore, the system is causal (since t0 −1 < t0 )
and the system is not memoryless (since t0 − 1 6= t0 ).
(e) We have
Z t
y(t) = x(τ )δ (τ )d τ
−∞
Z t
= x(0)δ (τ )d τ
−∞
Z t
= x(0) δ (τ )d τ
−∞
= x(0)u(t).

Consider y(t)|t=t0 . If t0 > 0, this quantity depends on x(t) for t = 0. Otherwise, this quantity does not depend
on x(t) at all. Therefore, the system is causal, since y(t0 ) only depends on x(t) for t ≤ t0 ). Also, the system is
not memoryless (since for t0 > 0, y(t0 ) depends on x(t) for t 6= t0 ).

2.15 Determine whether the system with input x(t) and output y(t) defined by each of the equations given below is
invertible. If the system is invertible, specify its inverse.
(a) y(t) = x(at − b) where a and b are real constants and a 6= 0;
(b) y(t) = ex(t) ;
(c) y(t) = Even{x(t)} − Odd{x(t)}; and
(d) y(t) = dtd x(t).
Solution. A system is invertible if any two distinct inputs always produce distinct outputs.
(a) We have

y(t) = x(at − b).

Now, we employ a change of variable. Let λ = at − b so that t = a1 [λ + b]. Since we are told that a 6= 0, we do
not need to worry about division by zero. Applying the change of variable yields

y( a1 [λ + b]) = x(λ ),

or alternatively,

x(t) = y( a1 [t + b]).

Thus, we have found the inverse system. Therefore, the system is invertible (since we have just found its
inverse).
(c) We have

y(t) = Even{x(t)} − Odd{x(t)}


= 12 [x(t) + x(−t)] − 12 [x(t) − x(−t)]
= 21 x(t) + 12 x(−t) − 21 x(t) + 12 x(−t)
= x(−t).

So, y(t) = x(−t). Thus, we have x(t) = y(−t). Therefore, the system is invertible (since we have just found the
inverse, namely x(t) = y(−t)).
(d) Consider an input x1 (t) of the form

x1 (t) = A

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

where A is a constant. Such an input will always yield the output y1 (t) given by
d
y1 (t) = dt x1 (t)
d
= dt A
= 0.
Therefore, any constant input will produce the same output (namely, an output of zero). Since distinct inputs
yield the same output, the system is not invertible.
2.16 Determine whether the system with input x(t) and output y(t) defined by each of the equations given below is
BIBO stable.
(a) y(t) = tt+1 x(τ )d τ ;
R

(b) y(t) = 21 x2 (t) + x(t); and


(c) y(t) = 1/x(t). R R
[Hint for part (a): For any function f (x), ab f (x)dx ≤ ab | f (x)| dx.]

Solution. A system is BIBO stable if its response y(t) to any bounded input x(t) is always bounded. That is,
|x(t)| ≤ A ⇒ |y(t)| ≤ B,
where A and B are finite constants.
(a) Suppose that |x(t)| ≤ A < ∞ (i.e., x(t) is bounded by A). Taking the absolute value of both sides of the
input-output equation for the system, we obtain
Z t+1
x(τ )d τ .

|y(t)| =

t

Using the fact that αβ f (x)dx ≤ αβ | f (x)| dx, we can write


R R

Z t+1
|y(t)| ≤ |x(τ )| d τ
t
Z t+1
≤ Ad τ
t
= [Aτ ]|t+1
t
= A(t + 1) − At
=A
< ∞.
Thus, we have that
|x(t)| ≤ A < ∞ ⇒ |y(t)| ≤ A < ∞.
Therefore, the system is BIBO stable.
(b) Suppose that x(t) is bounded as
|x(t)| ≤ A.
Then, we have
y(t) ≤ 12 A2 + A
< ∞.
Therefore, a bounded input always yields a bounded output, and the system is BIBO stable.
(c) Consider the input x(t) = 0. This will produce the output y(t) = 1
0 = ∞. Since a bounded input produces an
unbounded output, the system is not BIBO stable.

Version: 2014-05-08 Copyright 2014


c Michael D. Adams
12 Continuous-Time Signals and Systems (Chapter 2)

2.19 Given the signals x1 (t) and x2 (t) shown in the figures below, express x2 (t) in terms of x1 (t).

x1 (t) x2 (t)

3 3

2 2

1 1

t t
−3 −2 −1 0 1 2 3 − 43 − 24 − 14 0 1
4
2
4
3
4
(a) (b)

Solution.
We observe that x2 (t) is simply a time-shifted, time-scaled, and time-reversed version of x1 (t). More specif-
ically, x2 (t) is generated from x1 (t) through the following transformations (in order): 1) time shifting by 1,
2) time scaling by 4, and 3) time reversal. Thus, we have

x2 (t) = x1 (−4t − 1).

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

Chapter 9

MATLAB (Appendix E)

E.101 Indicate whether each of the following is a valid MATLAB identifier (i.e., variable/function name):
(a) 4ever
(b) $rich$
(c) foobar
(d) foo_bar
(e) _foobar
Solution.
(a) A MATLAB identifier cannot begin with a numeric character. Thus, 4ever is not a valid identifier.
(b) A MATLAB identifier cannot contain the $ character. Thus, $rich$ is not a valid identifier.
(c) The name foobar is a valid identifier.
(d) The name foo_bar is a valid identifier.
(e) A MATLAB identifier cannot begin with an underscore character. Thus, _foobar is not a valid identifier.

E.102 Let TC , TF , and TK denote the temperature measured in units of Celsius, Fahrenheit, and Kelvin, respectively.
Then, these quantities are related by

TF = 95 TC + 32 and
TK = TC + 273.15.

Write a program that generates a temperature conversion table. The first column of the table should contain the
temperature in Celsius. The second and third columns should contain the corresponding temperatures in units
of Fahrenheit and Kelvin, respectively. The table should have entries for temperatures in Celsius from −50 to
50 in steps of 10.
Solution.
The temperature conversion table can be produced with the following code:

Listing 9.1: temperature_conversion_table.m


display ( sprintf ( ’% -8s % -8s % -8s ’, ’ Celsius ’, ’ Fahrenheit ’, ’ Kelvin ’));
for celsius = -50 : 10 : 50
fahrenheit = 9 / 5 * celsius + 32;
kelvin = celsius + 273.15;
display ( sprintf ( ’ %8.2 f %8.2 f %8.2 f ’, celsius , fahrenheit , kelvin ));
end

The code produces the following output:

Version: 2014-05-08 Copyright 2014


c Michael D. Adams
28 MATLAB (Appendix E)

Listing 9.2: Output of temperature conversion program


Celsius Fahrenheit Kelvin
-50.00 -58.00 223.15
-40.00 -40.00 233.15
-30.00 -22.00 243.15
-20.00 -4.00 253.15
-10.00 14.00 263.15
0.00 32.00 273.15
10.00 50.00 283.15
20.00 68.00 293.15
30.00 86.00 303.15
40.00 104.00 313.15
50.00 122.00 323.15

E.106 Suppose that the vector v is defined by the following line of code:
v = [0 1 2 3 4 5]
Write an expression in terms of v that yields a new vector of the same dimensions as v, where each element t
of the original vector v has been replaced by the given quantity below. In each case, the expression should be
as short as possible.
(a) 2t − 3;
(b) 1/(t + 1);
(c) t 5 − 3; and
(d) |t| + t 4 .
Solution.
(a) 2 * v - 3
(b) 1 ./ (v + 1)
(c) v .ˆ 5 - 3
(d) abs(v) + v .ˆ 4
E.107 (a) Write a function called unitstep that takes a single real argument t and returns u(t), where
(
1 if t ≥ 0
u(t) =
0 otherwise.

(b) Modify the function from part (a) so that it takes a single vector argument t = [ t1 t2 ... tn ]T (where n ≥ 1 and
t1 ,t2 , . . . ,tn are real) and returns the vector [ u(t1 ) u(t2 ) ... u(tn ) ]T . Your solution must employ a looping construct
(e.g., a for loop).
(c) With some ingenuity, part (b) of this problem can be solved using only two lines of code, without the need
for any looping construct. Find such a solution. [Hint: In MATLAB, to what value does an expression like
“[-2 -1 0 1 2] >= 0” evaluate?]
Solution.
(a) This problem can be solved with code such as that shown below.
Listing 9.3: unitstep1.m
function x = unitstep (t)

if t >= 0
x = 1;
else
x = 0;
end

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

(b) This problem can be solved with code such as that shown below.

Listing 9.4: unitstep2.m


function x = unitstep (t)

% Create a vector of zeros with the same size as the input vector.
x = zeros ( size (t ));

% Correctly set the elements in the result vector that should be one.
m = length (x );
for i = 1 : m

if t(i) >= 0
x(i) = 1;
end

end

(c) This problem can be solved with code such as that shown below.

Listing 9.5: unitstep3.m


function x = unitstep (t)

x = (t >= 0);

Version: 2014-05-08 Copyright 2014


c Michael D. Adams

You might also like