two-step Adams Moulton method
34 次查看(过去 30 天)
显示 更早的评论
Hello,
I want to use two-step Adams Moulton method to solve ODE. The code is given below.
Running this I have problems with dimensions.
Any help is greatly aprecciated.
Thank you
% initialize
f = inline('y/x-y^2/x^2','x','y');
xrange=[1,2];
h=0.1;
x=1:h:2;
n = (xrange(2)-xrange(1))/h;
y(1) = 1;
% generate starting estimates using Runge-Kutta
for i = 1
k1 = f(x(i), y(i));
k2 = f(x(i) + h/2, y(i) + h/2*k1);
k3 = f(x(i) + h/2, y(i) + h/2*k2);
k4 = f(x(i) + h, y(i) + h*k3);
y(i+1) = y(i) + h/6*(k1 + 2*k2 + 2*k3 + k4);
x(i+1) = x(i) + h;
end
% iterate
for i = 3:n+1
% Adams-Moulton -- *correct*
y(i) = y(i-1) + h/12*(5*f(x(i),y(i)) + 8*f(x(i-1),y(i-1))- f(x(i-2),y(i-2)));
end
0 个评论
回答(2 个)
Torsten
2019-2-5
In the Adams-Moulton formula, y(i) appears on both sides of the equation. This means that the Adams-Moulton method is implicit. You will have to solve the equation
y(i) - (y(i-1) + h/12*(5*f(x(i),y(i)) + 8*f(x(i-1),y(i-1))- f(x(i-2),y(i-2)))) = 0
in the unknown y(i) in order to get the correct value (e.g. using MATLAB's "fzero").
Best wishes
Torsten.
0 个评论
Muhammad Sinan
2021-3-22
The only things need to correct is the discretization in iteration, here is the code
% iterate
for i = 3:length(n)-1
% Adams-Moulton -- *correct*
y(i) = y(i-1) + h/12*(5*f(x(i),y(i)) + 8*f(x(i-1),y(i-1))- f(x(i-2),y(i-2)));
end
Check it, if any thing goes wrong comment here.
Thank you!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!