Local and Global Truncation errors for Euler's method

14 次查看(过去 30 天)
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