% 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 % x0 = 0; y0 = 2; xfinal = 1; nsteps = 4; [x,y] = Euler('dfun',x0,y0,xfinal,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')