function dirf(ng)
% dirf(ng) plots the slope field (for dimension=1) or the vector
% field (for dimension=2) for the currently specified example.
% A grid using ng points both vertically and horizontally is used,
% covering the ranges obtained from the current axis setting.

global dimension eqn_name parameter

ax=axis;
tg=linspace(ax(1),ax(2),ng);
xg=linspace(ax(3),ax(4),ng);
[X,T]=meshgrid(xg,tg);
DX=zeros(ng);
DT=ones(ng);

if dimension==1
for i=1:ng
	for j=1:ng
		DX(i,j)=feval(eqn_name,tg(i),xg(j));
	end
end
elseif dimension==2
for i=1:ng
	for j=1:ng
		v=feval(eqn_name,0,[tg(i),xg(j)]);
		DT(i,j)=v(1);
		DX(i,j)=v(2);
	end
end
else
	disp('dirf only works for dimensions 1 or 2.')
	return
end
quiver(T,X,DT,DX,'k')
axis(ax)
titles
% M. Day, June 4, 2005; May 6, 2012
