## Topic 14.4: Multiple-Step Methods (Maple)

Introduction Notes Theory HOWTO Examples Engineering Error Questions Matlab Maple

Given the IVP y(1)(t = t y(t) - t2 + 1 with y(a) = 3, to approximate y(b) with n steps, we can do:

### Euler's Method

```h := (b - a)/n;
for i from 0 to n do
t[i] := a + i*h;
end;
y[0] := 3;
f := (t, y) -> t*y - t^2 + 1;
for i from 1 to n do
y[i] := y[i - 1] + h*f(t[i - 1], y[i - 1]);
end do;
y[n];   # approximation
```

### Heun's Method

```h := (b - a)/n;
for i from 0 to n do
t[i] := a + i*h;
end;
y[0] := 3;
f := (t, y) -> t*y - t^2 + 1;
for i from 1 to n do
K[0] := f(t[i - 1], y[i - 1]);
K[1] := f(t[i - 1] + h, y[i - 1] + h*K[0]);
y[i] := y[i - 1] + h*(K[0] + K[1])/2;
end do;
y[n];   # approximation
```

### 4th-order Runge Kutta

```h := (b - a)/n;
for i from 0 to n do
t[i] := a + i*h;
end;
y[0] := 3;
f := (t, y) -> t*y - t^2 + 1;
for i from 1 to n do
K[0] := f(t[i - 1], y[i - 1]);
K[1] := f(t[i - 1] + h/2, y[i - 1] + h/2*K[0]);
K[2] := f(t[i - 1] + h/2, y[i - 1] + h/2*K[1]);
K[3] := f(t[i - 1] + h, y[i - 1] + h*K[2]);
y[i] := y[i - 1] + h*(K[0] + 2*K[1] + 2*K[2] + K[3])/6;
end do;
y[n];   # approximation
```