deval.RdEvaluate solution of a differential equation solver.
deval(x, y, xp, idx = NULL)Determines where the points xp lie within the vector x
and interpolates linearly.
An length(xp)-by-length(idx) matrix of values at points
xp.
The interpolation is linear only for the moment.
## Free fall: v' = -g - cw abs(v)^1.1, cw = 1.6 drag coefficien
f <- function(t, y) -9.81 + 1.6*abs(y)^1.1
sol <- rk4(f, 0, 10, 0, 100)
# speed after 0.5, 1, 1.5, 2 seconds
cbind(c(0.5,1,1.5,2), -deval(sol$x, sol$y, c(0.5, 1, 1.5, 2)))
#> [,1] [,2]
#> [1,] 0.5 3.272267
#> [2,] 1.0 4.507677
#> [3,] 1.5 4.953259
#> [4,] 2.0 5.112068
# 0.5 3.272267 m/s
# 1.0 4.507677
# 1.5 4.953259
# 2.0 5.112068
# plot(sol$x, -sol$y, type="l", col="blue"); grid()