I am trying to integrate dy3dt = @(t,y) -41*(y - t) + 1; over [0, 1] with h = 0.05 using backward Euler. The initial condition, y(0) is 1.
yvals3 = [1]; %inital condition
dy3dt = @(t,y) -41*(y - t) + 1;
for t = 0:0.05:0.95;
index = round(t*20 + 1); %convert t into index of the last step
oldy = yvals3(index);
newy1 = oldy + h.*dy3dt(t, oldy);
newy2 = oldy + h.*dy3dt(t+ 0.05, newy1);
yvals3 = [yvals3; newy2];
end
tvals3 = 0:0.05:1;
When I graph tvals3 and yvals3, I am getting an unusual exponential graph, so my approach is probably incorrect. Any insight on how to implement this using fzero?