% This matlab script demonstrates the fan of local solutions % of the DE dy/dx = -y, y(0) = 2, solved by Euler's method % on [0,1] with a stepsize of 1/4. % Usage: >> fan % Requires: EulerFixH, dfun xspan = [0 1]; y0 = 2; nsteps = 4; [x,y] = EulerFixH('dfun',xspan,y0,nsteps); % Get the computed solution plot(x,y,'wx',x,y,'r--') % Plot as a red dashed line colors = 'cbmg'; hold on for k = 1:nsteps xloc = linspace(x(k),1); % Get each local solution yloc = y(k)*exp(-(xloc-x(k))); % on a fine mesh plot(xloc,yloc,colors(k)) % Plot as a solid line end xlabel('X'), ylabel('Y') title('Computed Solution and Local Solutions Over 4 Steps')