Trying to make an Adams-Bashforth method with Richardson error estimate
3 views (last 30 days)
Show older comments
%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 Comment
Answers (1)
Mayank Sengar
on 12 Jan 2023
Edited: Mayank Sengar
on 12 Jan 2023
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 Comments
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!