フィルターのクリア

two-step Adams Moulton method

37 ビュー (過去 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 Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by