Using the improved Euler (Huen) method, determine the approximate solution y (t) of the following starting problem:

1 vue (au cours des 30 derniers jours)
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 commentaires
Walter Roberson
Walter Roberson le 28 Mai 2021
Torsten answered the question. It is too late to delete it now.

Connectez-vous pour commenter.

Réponses (1)

Torsten
Torsten le 28 Mai 2021
Modifié(e) : Jan le 28 Mai 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

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by