% Plot the following signal:
% For       t <= -1,  x(t) = 0
% For  -1 < t <=  0,  x(t) = cos(pi t/2)
% For   0 < t <=  1,  x(t) = exp(-t)
% For   1 < t,        x(t) = 0

% Plot over interval -2 to 2 in order to
% show all regions of interest

% From -2 to -1, x(t) = 0
% Only need endpoints since it is straight
t1 = [-2 -1];
x1 = [0 0];

% From -1 to 0, x(t) = cos(pi t/2)
% Need enough points to show curved line
t2 = -1:0.01:0;
x2 = cos(pi*t2/2);

% From 0 to 1, x(t) = exp(-t)
% Need enough points to show curved line
t3 = 0:0.01:1;
x3 = exp(-t3);

% From 1 to 2, x(t) = 0
% Only need endpoints since it is straight
t4 = [1 2];
x4 = [0 0];

% Combine vectors into one long vector
t = [t1 t2 t3 t4];
x = [x1 x2 x3 x4];

% Plot
plot(t,x);
axis([-2 2 -2 2])
grid
xlabel('t (seconds)');
ylabel('x(t)');
print -dpsc2 ex.ps
