Trying to make an Adams-Bashforth method with Richardson error estimate
3 次查看(过去 30 天)
显示 更早的评论
%This program solves the initial value problem
% y' = f(x,y), x0 <= x<= b, y(x0)=y0
%Initializing vaiables
%f'(x,y)=
f = @(x,y) cos(y).^2; %derivative in question
g = @(x) atan(x); %this is the actual solution
x0 = 0; %initial value of x
x_end = 10; %end of approximation
h = 0.1; %size of decimal place (0.1,0.001,etc
y0=0; %initial value of y
n = fix((x_end-x0)/h)+1;
x = linspace(x0,x_end,n);
y = zeros(n,1);
y(1) = y0;
f1 = f(x(1),y(1));
y(2) = y(1)+h*f1;
%need to add error
for i = 3:n
f2 = f(x(i-1),y(i-1));
y(i) = y(i-1)+h*(3*f2-f1)/2;
f1 = f2;
fprintf('%5.4f %11.8f\n', x(i), y(i));
plot(x(i),y(i),'b.'); grid on;
fplot(g,[x0,x_end]);
xlabel('x values'); ylabel('y values');
hold on;
end
I'm not sure how I would add the Richardson error to this code. I see the formula in my textbook, but don't understand how I would make it work. . Like I don't really know what that means. I understand the AB method for solving DefEqs, but not ther errors
1 个评论
回答(1 个)
Mayank Sengar
2023-1-12
编辑:Mayank Sengar
2023-1-12
for understand Richardson expoitation, here is the pseudocode for it:
There is also a generalized Richardson extrapolation routine in file exchange: https://www.mathworks.com/matlabcentral/fileexchange/24388-richardson-extrapolation
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!