Local and Global Truncation errors for Euler's method
12 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Torsten
on 8 Mar 2022
Moved: Joel Van Sickel
on 2 Dec 2022
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.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!