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
0 件のコメント
回答 (1 件)
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.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!