N = 10;h=tFinal/N;t=linspace(0,tFinal,N+1); % type 'help linspace' to see how this works
y=zeros(1,N+1);yExact=9/((3.*t-1+10.*exp(-3.*t)));y(0) = 1; % setting the initial condition
for n=1:N y(n+1) = y(n) + h * y(n)*(3-t*y(n));endplot(t,y,t,yExact,'--')xlabel('t'); ylabel('y'); title('Look, ma! I solved another ODE in MATLAB!');
error10= abs(y(N+1)-yExact(N+1));
Best Answer