function euler(f, tspan, x0)
# number of steps
= length(tspan)
steps
# allocate space
= zeros(length(x0), steps)
x
# initial state
:,1] .= x0
x[
# iterate
for k in 2:steps
# time discretization
= tspan[k] - tspan[k-1]
dt
# step
:,k] .= x[:,k-1] + f(x[:,k-1], tspan[k-1]) * dt
x[
end
return x
end
euler (generic function with 1 method)