function [t,y] = impeuler(f,tspan,y0,N)
y(:,n+1) = y(:,n) + (h/2)*(f(t(n),y(:,n)) + f(t(n+h),y(:,n) + h*f(t(n),y(:,n))));
The code above is an improved euler's method that I was told to create. All variables above the for loop create the values they are supposed to, as I displayed all of them to the terminal and none had an error.
Though the for loop when processed returns the error,
Array indices must be positive integers or logical values.
Error in impeuler (line 29)
y(:,n+1) = y(:,n) + (h/2)*(f(t(n),y(:,n)) + f(t(n+h),y(:,n) + h*f(t(n),y(:,n))));
I'm not seeing how any of the arrays managed to get any of their indices to zero or below. What is causing the array index to try and go negative or illogical?