Local and Global Truncation errors for Euler's method

조회 수: 13 (최근 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 CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by