Hello, I am trying to use a for loop to solve an ODE by way of Euler's method. I have a loop that works for a single step size h = 0.05, but I was wondering if I can get the loop to run with h = [0.05 0.1 0.2], and then plot the three different outputs? Here is the code that I have so far, loops confuse me so any help is greatly appreciated.
y0 = 0;t0 = 0;tf = 1;h = 0.05;f = @(t,y) y^2 + 1;y = y0;y_1 = y;for t = t0:h:tf-h yp = f(t,y); y = y + h*yp; y_1 = [y_1 ; y];endx = 0:h:1;plot(x,y_1)
Best Answer