tFinal = 2;N = 33;h=tFinal/N;t=linspace(0,tFinal,N+1);y=zeros(1,N+1);yExact=9./(3*t-1+10*exp(t*-3));y(0) = 1;for n=1:N y(n+1) = y(n) + h * y(n)*(3-t(n)*y(n));endplot(t,y,'-'); xlabel('t'); ylabel('y'); title('2nd Part') ;hold allplot(t,yExact,'bx');error100= abs(y(N+1)-yExact(N+1));fprintf('The error of N equaling 33 is %f.\n',error100);
Array indices must be positive integers or logical values.
Best Answer