summaryrefslogtreecommitdiff
path: root/50/DEPENDENCIES/adamsbashforth3.sci
blob: dfc65961f480d72ca63add8465c8fdf311eeaf6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function [u,t] = adamsbashforth3(u0,t0,tn,h,f)

//adamsbashforth3 3rd order method solving ODE
//  du/dt = f(u,t), with initial 
//conditions u=u0 at t=t0.  The 
//solution is obtained for t = [t0:h:tn]
//and returned in u

umaxAllowed = 1e+100;

t = [t0:h:tn]; u = zeros(t); n = length(u); u(1) = u0;
for j = 1:n-2
if j<3 then
      k1=h*f(t(j),u(j));
    k2=h*f(t(j)+h,u(j)+k1);
	u(j+1) = u(j) + (k2+k1)/2;
end;  
   
if j>=2 then
    	u(j+2) = u(j+1) + (h/12)*(23*f(t(j+1),u(j+1))-16*f(t(j),u(j))+5*f(t(j-1),u(j-1)));
end;
end;
endfunction