Solve initial value problems (IVPs) using numerical methods
stm_ivps_rk3.Rd
stm_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_rk3(
odeqtn,
exactsol = NULL,
vars = c("t", "y"),
time_span = NULL,
y0 = NULL,
step_size = NULL,
nsteps = 10,
maxit = 100,
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
.- 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
exactsol
is provided.Error: |y - yi|: The error at each time point if
exactsol
is provided.
Details
These functions solve initial value problems for ODEs using a specified numerical method. They can handle both single ODEs and systems of ODEs by providing state variables as a vector. If an exact solution is provided, the error at each time point will be calculated for comparison.
Examples
f <- "y - t^2 + 1"
ft <- "(t + 1)^2 - 0.5 * exp(t)"
result <- stm_ivps_rk3(
odeqtn = f,
exactsol = ft,
time_span = c(0, 2),
y0 = 0.5,
nsteps = 10,
show_plot = FALSE
)
stm_gtable(result)