Solve initial value problems (IVPs) using numerical methods
stm_ivps_rkf4.Rdstm_ivps*() set of functions solve IVPs for ordinary differential
equations (ODEs) using various numerical methods. Supports solving
single equations or systems of ODEs.
Usage
stm_ivps_rkf4(
odeqtn,
exactsol = NULL,
vars = c("t", "y"),
time_span = NULL,
y0 = NULL,
step_size = NULL,
nsteps = 10,
maxit = 100,
hmin = 0.01,
hmax = 0.25,
tolerance = 1e-16,
show_iters = NULL,
view_table = FALSE,
show_plot = TRUE,
digits = 8
)Arguments
- odeqtn
A function defining the ODE system. It should take two arguments: the current time and state vector as
y = f(t, y).- exactsol
Optional. A function representing the exact solution for comparison. Default is
NULL.- vars
Independent and dependent variables.
- time_span
A numeric vector specifying the time range for the solution. Should be of length
2.- y0
Initial state values for the ODE system.
- step_size
The step size for the numerical method. If
NULL, it is computed based on the time span and number of steps.- nsteps
The number of time steps to take. Default is
10.- maxit
Maximum number of iterations for iterative methods. Default is
10.- hmin
Minimum step size for the adaptive step-size control. Default is
0.01- hmax
Maximum step size for the adaptive step-size control. Default is
0.25- tolerance
Error tolerance for controlling the local truncation error. Default is
1e-16- show_iters
Logical. If
TRUE, iteration details are displayed. Default isNULL.- view_table
Logical. If
TRUE, the results are viewed in the R spreadsheet. Default isFALSE.- show_plot
Logical. If
TRUE, the results are plotted. Default isTRUE.- digits
The number of significant digits to display in the results. Default is
8.
Value
A data frame containing the time points and corresponding solution values. If an exact solution is provided, the error at each time point is also included.
Time (t): Time points.
Approx. (yi): State values at each time point.
Exact (y): Exact solution if
exactsolis provided.Error: |y - yi|: The error at each time point if
exactsolis provided.