-
Notifications
You must be signed in to change notification settings - Fork 2
/
adams_moulton.m
26 lines (22 loc) · 1.02 KB
/
adams_moulton.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
function y = adams_moulton(vdp1,x,h,y0)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
n = length(x);
y = zeros(n,1);
y(1,:) = y0;
for i = 2:n
if i == 2
y(i,:) = y(i-1,:) + (h/24)*(55*vdp1(x,y(i-1,:)))';
y(i,:) = y(i-1,:) + (h/24)*(9*vdp1(x,y(i,:)) + 19*vdp1(x,y(i-1,:)))';
elseif i == 3
y(i,:) = y(i-1,:) + (h/24)*(55*vdp1(x,y(i-1,:)) - 59*vdp1(x,y(i-2,:)))';
y(i,:) = y(i-1,:) + (h/24)*(9*vdp1(x,y(i,:)) + 19*vdp1(x,y(i-1,:)) - 5*vdp1(x,y(i-2,:)))';
elseif i == 4
y(i,:) = y(i-1,:) + (h/24)*(55*vdp1(x,y(i-1,:)) - 59*vdp1(x,y(i-2,:)) + 37*vdp1(x,y(i-3,:)))';
y(i,:) = y(i-1,:) + (h/24)*(9*vdp1(x,y(i,:)) + 19*vdp1(x,y(i-1,:)) - 5*vdp1(x,y(i-2,:)) + vdp1(x,y(i-3,:)))';
else
y(i,:) = y(i-1,:) + (h/24)*(55*vdp1(x,y(i-1,:)) - 59*vdp1(x,y(i-2,:)) + 37*vdp1(x,y(i-3,:)) - 9*vdp1(x,y(i-4,:)))';
y(i,:) = y(i-1,:) + (h/24)*(9*vdp1(x,y(i,:)) + 19*vdp1(x,y(i-1,:)) - 5*vdp1(x,y(i-2,:)) + vdp1(x,y(i-3,:)))';
end
end
end