Solving stochastic differential equations (SDEs) is the similar to
ODEs. To solve an SDE, you use diffeqr::sde.solve
and give
two functions: f
and g
, where
du = f(u,t)dt + g(u,t)dW_t
<- diffeqr::diffeq_setup()
de <- function(u,p,t) {
f return(1.01*u)
}<- function(u,p,t) {
g return(0.87*u)
}<- 1/2
u0 <- list(0.0,1.0)
tspan <- de$SDEProblem(f,g,u0,tspan)
prob <- de$solve(prob)
sol <- as.data.frame(t(sapply(sol$u,identity)))
udf ::plot_ly(udf, x = sol$t, y = sol$u, type = 'scatter', mode = 'lines') plotly