two-step Adams Moulton method

조회 수: 27 (최근 30일)
POLLY
POLLY 2019년 2월 4일
답변: Muhammad Sinan 2021년 3월 22일
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에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by