Local and Global Truncation errors for Euler's method

14 ビュー (過去 30 日間)
Paul Toepp
Paul Toepp 2022 年 3 月 8 日
移動済み: Joel Van Sickel 2022 年 12 月 2 日
I have coded the following for a Euler's method in Matlab but I am not sure how to incorporate Local and global truncation errors into the code if someone can help.
a = 0;
b = 1;
h = 0.25; % step size
x = a:h:b; % the range of x
y = zeros(size(x)); % allocate the result y
y(1) = 1; % the initial y value
n = numel(y); % the number of y values
% The loop to solve the DE
for i=1:n-1
f = ((x(i)^2)-1)*y(i);
y(i+1) = y(i) + h * f
end

回答 (1 件)

Torsten
Torsten 2022 年 3 月 8 日
移動済み: Joel Van Sickel 2022 年 12 月 2 日
Just apply the definitions.
Local truncation error at (t_n,y_n):
|y_(n+1) - y(t_(n+1))|
where y(t_(n+1)) is the exact solution to the problem
dy/dt = f(t,y), y(t_n) = y_n
at
t = t_(n+1)
Global truncation error:
|y_num(b) - y(b)|
where y(b) is the value of the exact solution to the problem
dy/dt = f(t,y), y(a) = y0
and y_num(b) is the approximate solution obtained by the numerical method.
Hint: The exact solution to your problem can easily be obtained by separation of variables.

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by