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

조회 수: 1 (최근 30일)
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

댓글을 달려면 로그인하십시오.

답변 (1개)

Torsten
Torsten 2021년 5월 28일
편집: Jan 2021년 5월 28일
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

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by