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

2 Ansichten (letzte 30 Tage)
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 Kommentare

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Torsten
Torsten am 28 Mai 2021
Bearbeitet: Jan am 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

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by