clear; % declare function for the rate function f=inline('10*(1-y)*y','t','y'); % and the exact solution yexact=inline('1/(1-0.2*exp(-10*t))','t'); % Now set the step size (try 0.25 and 0.05) % one will be commented out h=0.25; %h=0.25; % % Make a vector of "t" values t=0:h:10; % find out how many times steps we are computing n=10/h + 1 n=length(t); % % Now set the initial conditions % here yexact is just filled in...meaning there is no computation y1(1)=1.25; % Euler yex(1)=1.25; % Exact for j=2:n y1(j) = y1(j-1) + h*f(t(j-1),y1(j-1)); yex(j) = yexact(t(j)); end % plot figure; plot(t,y1,'b',t,yex,'r--');