ODESolverFactory helps to create a solver given only the name as string

ODESolverFactory generic

This is a factory method that creates an ODESolver using a name.

ODESolverFactory constructor

ODESolverFactory(...)

createODESolver(object, ...)

# S4 method for ODESolverFactory
createODESolver(object, ode, solverName, ...)

# S4 method for ANY
ODESolverFactory(...)

Arguments

...

additional parameters

object

an solver object

ode

an ODE object

solverName

the desired solver as a string

See also

Other ODESolver helpers: ODESolver-class

Other ODESolver helpers: ODESolver-class

Examples

# This example uses ODESolverFactory importFromExamples("SHO.R") # SHOApp.R SHOApp <- function(...) { x <- 1.0; v <- 0; k <- 1.0; dt <- 0.01; tolerance <- 1e-3 sho <- SHO(x, v, k) # Use ODESolverFactory solver_factory <- ODESolverFactory() solver <- createODESolver(solver_factory, sho, "DormandPrince45") # solver <- DormandPrince45(sho) # this can also be used # Two ways of setting the tolerance # solver <- setTolerance(solver, tolerance) # or this below setTolerance(solver) <- tolerance # Two ways of initializing the solver # solver <- init(solver, dt) init(solver) <- dt i <- 1; rowVector <- vector("list") while (getState(sho)[3] <= 500) { rowVector[[i]] <- list(x = getState(sho)[1], v = getState(sho)[2], t = getState(sho)[3]) solver <- step(solver) sho <- getODE(solver) i <- i + 1 } return(data.table::rbindlist(rowVector)) } solution <- SHOApp() plot(solution)
# This example uses ODESolverFactory importFromExamples("SHO.R") # SHOApp.R SHOApp <- function(...) { x <- 1.0; v <- 0; k <- 1.0; dt <- 0.01; tolerance <- 1e-3 sho <- SHO(x, v, k) # Use ODESolverFactory solver_factory <- ODESolverFactory() solver <- createODESolver(solver_factory, sho, "DormandPrince45") # solver <- DormandPrince45(sho) # this can also be used # Two ways of setting the tolerance # solver <- setTolerance(solver, tolerance) # or this below setTolerance(solver) <- tolerance # Two ways of initializing the solver # solver <- init(solver, dt) init(solver) <- dt i <- 1; rowVector <- vector("list") while (getState(sho)[3] <= 500) { rowVector[[i]] <- list(x = getState(sho)[1], v = getState(sho)[2], t = getState(sho)[3]) solver <- step(solver) sho <- getODE(solver) i <- i + 1 } return(data.table::rbindlist(rowVector)) } solution <- SHOApp() plot(solution)