Felipe Tavares' Avatar

Integrators: Adams Bashforth

February 25, '21

Integrators are little pieces of code which approximate numeric solutions to differential equations. In this short series I’ll share some Julia code for a few of them.

The Adams-Bashforth integrator takes as input a time step h, previous value y and previous derivative values as yy.

function ∇(yy, i=1, p=1)
    local n = length(yy)

    if i > 1
        ∇(yy, i-1, p)-∇(yy, i-1, p+1)
    else
        yy[n-p+1]-yy[n-p]
    end
end

function J(yy)
    local table = [ 1/2, 5/12, 3/8, 251/720, 95/288, 19087/60480, 5257/17280, 1070017/3628800 ]
    local sum = yy[length(yy)]

    for i  1:length(yy)-1
        if i > length(table)
            break
        end

        sum += table[i]∇(yy, i)
    end

    sum
end

function integrator(yy, y, h)
    y + h*J(yy)
end