Numerically solves a two dimensional autonomous ODE system for a given initial condition, using ode from the package deSolve. It then plots the dependent variables against the independent variable.
numericalSolution(deriv, y0 = NULL, tlim, tstep = 0.01,
parameters = NULL, type = "one", col = c("red", "blue"),
add.grid = TRUE, add.legend = TRUE, state.names = c("x", "y"), ...)A function computing the derivative at a point for the ODE system to be analysed. Discussion of the required structure of these functions can be found in the package guide.
The initial condition. Should be a vector of length two reflecting the location of the two dependent variables initially.
Sets the limits of the independent variable for which the solution should be plotted. Should be a vector of length two. If tlim[2] > tlim[1], then tstep should be negative to indicate a backwards trajectory.
The step length of the independent variable, used in numerical integration. Decreasing the absolute magnitude of tstep theoretically makes the numerical integration more accurate, but increases computation time. Defaults to 0.01.
Parameters of the ODE system, to be passed to deriv. Supplied as a vector; the order of the parameters can be found from the deriv file. Defaults to NULL.
If set to "one" the trajectories are plotted on the same graph. If set to "two" they are plotted on separate graphs. Defaults to "one".
Sets the colours of the trajectories of the two dependent variables. Will be reset accordingly if it is not a vector of length two. Defaults to c("red", "blue").
Logical. If TRUE, grids are added to the plots. Defaults to TRUE.
Logical. If TRUE, a legend is added to the plots. Defaults to TRUE.
State names for ode functions that do not use positional states
Additional arguments to be passed to plot.
Returns a list with the following components:
As per input.
As per input.
As per input, but with possible editing if a colour vector of the wrong length was supplied.
As per input.
As per input.
A vector containing the values of the independent variable at each integration step.
As per input.
As per input.
A vector containing the numerically computed values of the first dependent variable at each integration step.
A vector containing the numerically computed values of the second dependent variable at each integration step.
As per input.
# NOT RUN {
# A two dimensional autonomous ODE system, vanDerPol.
vanDerPol.numericalSolution <- numericalSolution(vanDerPol, y0 = c(4, 2), tlim = c(0, 100),
parameters = 3)
# }
Run the code above in your browser using DataLab