clear
close all
echo on

% Problem Set A, #4

% a)

% We use ezplot in this part.

% The presence of the pause command causes the "program" to pause
% after the plot. Strike any key to proceed to the next plot.

ezplot('3*x + 2', [-5 5])
title 'Figure 4.1'
pause
print -deps figA4-1
% This graph appears in Figure 4.1.

% b)

ezplot('x^2 + x - 1', [-5 5])
title 'Figure 4.2'
pause
print -deps figA4-2
% This graph appears in Figure 4.2.

% c)

ezplot('sin(x)', [0 4*pi])
title 'Figure 4.3'
pause
print -deps figA4-3
% This graph appears in Figure 4.3.

% d)

% We try fplot here, and we use axis to give a reasonable scale.

fplot('tan(x)', [-pi/2 pi/2])
axis([-pi/2 pi/2 -10 10])
title 'Figure 4.4i'
pause
print -deps figA4-4i
% This graph appears in Figure 4.4i.

% We see that the curve is not smooth. Let's try ezplot.

ezplot('tan(x)', [-pi/2 pi/2])
title 'Figure 4.4ii'
pause
print -deps figA4-4ii
% This graph appears in Figure 4.4ii.

% Next let's use plot. We start by making a vector of x-values. Note that we 
% use an interval just slightly inside [-pi, pi] in order to avoid the 
% singularity in tan(x) at +-pi.

x = -1.51:0.01:1.51;
plot(x, tan(x))
title 'Figure 4.4iii'
pause
print -deps figA4-4iii
% This graph appears in Figure 4.4iii.

% e)

ezplot('exp(-x^2)', [-2 2])
title 'Figure 4.5'
pause
print -deps figA4-5
% This graph appears in Figure 4.5.

echo off
