aboutsummaryrefslogtreecommitdiffstats
path: root/Part 1/Good Code/heun_methodforerror.m
blob: ed3827145b4a9c8900f8b8a9d470d6e7b7592394 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
function [y, t] = heun_methodforerror(f,a,b,ya,n)
h = (b - a) / n;
halfh = h / 2;
y(1,:) = ya;
t(1) = a;
for i = 1 : n
    t(i+1) = t(i) + h;
    g = f(t(i),y(i,:));
    z = y(i,:) + h * g;
    y(i+1,:) = y(i,:) + halfh * ( g + f(t(i+1),z) );
end;

%func,t0,tf,i0,step_size