Global error and local error of euler method

26 vues (au cours des 30 derniers jours)
Erm
Erm le 28 Jan 2023
Commenté : Torsten le 29 Jan 2023
The local error is proportional to h^2. I did not understand the relationship between the h and the error. Is it as h increase the error increase? Also the global error is proportional to h , how is that?
  1 commentaire
Torsten
Torsten le 29 Jan 2023
These questions are answered in every standard book about the numerical treatment of ordinary differential equations.

Connectez-vous pour commenter.

Réponses (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov le 28 Jan 2023
Yes, error increase if h step size increases. See this simple example:
dy = y(t) with y(0) = 3;
y(n+1) =y(n)+h*f(t(n), y(n));
from the givend ICs: f(t(0), y(0)) = 3, and therefore, y(1+1) = y(1)+h*3; Let's see in simulation:
h=0.1; % Case 1
f=@(t,y)y; % from the given exercise dy = y(t) and thus f(t,y) = dy;
t=0:h:5;
y(1)=3; % Initial Condition
for ii=2:numel(t) % calculations
y(ii) = y(ii-1)+h*f(t(ii-1),y(ii-1));
end
t=t.';
Solution = array2table(t);
Solution.Y = y.';
plot(t, y, 'r-', 'DisplayName', 'Case 1: h=0.1'), hold on
% Analytical solution:
syms t y(t)
Sol=dsolve(diff(y(t), t)==y, y(0)==3);
Sol_yt = vectorize(Sol)
Sol_yt = '3.*exp(t)'
t=(0:h:5).';
Sol = (eval(Sol_yt));
Error = abs(Sol)-Solution.Y; % Error = Analytical solution - Numerical Solution
Solution.Error=Error
Solution = 51×3 table
t Y Error ___ ______ ________ 0 3 0 0.1 3.3 0.015513 0.2 3.63 0.034208 0.3 3.993 0.056576 0.4 4.3923 0.083174 0.5 4.8315 0.11463 0.6 5.3147 0.15167 0.7 5.8462 0.19511 0.8 6.4308 0.24586 0.9 7.0738 0.30497 1 7.7812 0.37362 1.1 8.5594 0.45315 1.2 9.4153 0.54507 1.3 10.357 0.65108 1.4 11.392 0.7731 1.5 12.532 0.91332
Case1 = [t, Error];
clearvars y
h = 0.5; % Case 2
f=@(t,y)y; % from the given exercise dy = y(t) and thus f(t,y) = dy;
t=0:h:5;
y(1)=3; % Initial Condition
for ii=2:numel(t) % calculations
y(ii) = y(ii-1)+h*f(t(ii-1),y(ii-1));
end
plot(t, y, 'b-', 'DisplayName', 'Case 2: h=0.5'), grid on
t=t.';
Solution = array2table(t);
Solution.Y = y.';
t=(0:h:5).';
Sol = (eval(Sol_yt));
Error = abs(Sol)-Solution.Y; % Error = Analytical solution - Numerical Solution
Solution.Error=Error
Solution = 11×3 table
t Y Error ___ ______ _______ 0 3 0 0.5 4.5 0.44616 1 6.75 1.4048 1.5 10.125 3.3201 2 15.188 6.9797 2.5 22.781 13.766 3 34.172 26.085 3.5 51.258 48.089 4 76.887 86.908 4.5 115.33 154.72 5 173 272.24
Case2 = [t, Error];
clearvars y Solution
h = 1; % Case 3
f=@(t,y)y; % from the given exercise dy = y(t) and thus f(t,y) = dy;
t=0:h:5;
y(1)=3; % Initial Condition
for ii=2:numel(t) % calculations
y(ii) = y(ii-1)+h*f(t(ii-1),y(ii-1));
end
plot(t, y, 'k-', 'DisplayName', 'Case 3: h=1')
legend('show', 'location', 'NW')
xlabel('time')
ylabel('Solution, y(t)')
t=t.';
Solution = array2table(t);
Solution.Y = y.';
t=(0:h:5).';
Sol = (eval(Sol_yt));
Error = abs(Sol)-Solution.Y; % Error = Analytical solution - Numerical Solution
Solution.Error=Error
Solution = 6×3 table
t Y Error _ __ ______ 0 3 0 1 6 2.1548 2 12 10.167 3 24 36.257 4 48 115.79 5 96 349.24
Case3 = [t, Error];
figure
plot(Case1(:,1), Case1(:,2), 'r'), hold on
plot(Case2(:,1), Case2(:,2), 'b')
plot(Case3(:,1), Case3(:,2), 'k'), grid on
legend('Case1: h=0.1', 'Case2: h=0.5', 'Case3: h=1', 'location', 'NW')
xlabel('time')
ylabel('Error')

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by