two-step Adams Moulton method

37 次查看(过去 30 天)
POLLY
POLLY 2019-2-4
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

回答(2 个)

Torsten
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.

Muhammad Sinan
Muhammad Sinan 2021-3-22
Hi @POLLY!
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!

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by