Using the improved Euler (Huen) method, determine the approximate solution y (t) of the following starting problem:
1 view (last 30 days)
Show older comments
Using the improved Euler (Huen) method, determine the approximate solution y (t) of the following starting problem:
dy / dt = y * e ^ 5t, y (0) = 1; t; [0, 0.5]
for time steps: h = ½; h = ¼; h = 1/8; h = 1/16; h = 1/32;
Then solve the above differential equation using the separated variables method. Compare the obtained numerical results on the graph with the exact solution y (t). Calculate the global error en for each of the time steps h and determine on this basis the order of the improved Euler (Huen) method. I have to solve it in Matlab, but I have problem with doing the script. If anyone would provide me to simple code for the solution, it would be really helpfull for me. Thank you for all the answers and tips :)
4 Comments
Answers (1)
Torsten
on 28 May 2021
Edited: Jan
on 28 May 2021
Untested !
function main
H = [1/2 ,1/4,1/8,1/16,1/32];
t0 = 0;
t1 = 0.5;
y0 = 1;
f = @(t,y) y*exp(5*t);
for i= 1:numel(H)
h = H(i);
t = (t0:h:t1).' ;
N = numel(t);
y = zeros(N,1);
y(1) = y0;
for j = 2:N
yhelp = y(j-1) + h*f(t(j-1),y(j-1));
y(j) = 0.5*y(j-1) + 0.5*(yhelp + h*f(t(j),yhelp));
end
T{i} = t;
Y{i} = y;
end
plot(T,Y)
end
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!