function dirfield(t,x,y,f) % usage dirfield(t,x,y,f) % description: this function plots a direction field with x and y % as x-y coordinates for the grid, t the time and f the name of the % function f(t,x,y) for the direction vectors.It also sets hold on. m = length(x); n = length(y); [xx,yy]=meshgrid(x,y); uu = xx; vv = yy; for ii=1:n for jj=1:m vtmp = feval(f,t,[xx(ii,jj);yy(ii,jj)]); xxrhs(ii,jj)=vtmp(1); yyrhs(ii,jj)=vtmp(2); end end quiver(xx,yy,xxrhs,yyrhs); hold on;