Having trouble working out the bugs in my Improved Euler's Method code. I previously had trouble with the normal Euler's method code, but I figured it out.
Euler's Method (working code):
syms t yh=0.01;N=200;y(1)=1;t(1)=0;for n=1:N k1=1-t(n)+4*y(n); y(n+1)=y(n)+h*k1; t(n+1)=t(n)+h;endplot(t,y)
And here is my attempt at Improved Euler's Method:
h=0.01;N=200;y(1)=1;t(1)=0;for n=1:N k1=1-t(n)+4*y(n); k2=1-t(n+1)+4*(y(n)+h*k1); y(n+1)=y(n)+(h/2)*(k1+k2); t(n+1)=t(n)+h;endplot(t,y)
The error message that pops up is "Index exceeds the number of array elements (1)." I'm rather new at MATLAB, and don't know what this means, can someone help me rework this? Thank you!
Best Answer