trajectory function

Phase plane trajectory plotting

Phase plane trajectory plotting

Performs numerical integration of the chosen ODE system, for a user specified set of initial conditions. Plots the resulting solution(s) in the phase plane.

trajectory( deriv, y0 = NULL, n = NULL, tlim, tstep = 0.01, parameters = NULL, system = "two.dim", col = "black", add = TRUE, state.names = if (system == "two.dim") c("x", "y") else "y", method = "ode45", ... )

Arguments

  • deriv: 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 vignette, or in the help file for the function ode.

  • y0: The initial condition(s). In the case of a one-dimensional system, this can either be a numeric vector

    of length one, indicating the location of the dependent variable initially, or a numeric

    vector indicating multiple initial locations of the independent variable. In the case of a two-dimensional system, this can either be a numeric vector of length two, reflecting the location of the two dependent variables initially, or it can be numeric

    matrix where each row reflects a different initial condition. Alternatively this can be specified as NULL, and then locator can be used to specify initial condition(s) on a plot. In this case, for one-dimensional systems, all initial conditions are taken at tlim[1], even if not selected so on the graph. Defaults to NULL.

  • n: If y0 is left NULL, such initial conditions can be specified using locator, n sets the number of initial conditions to be chosen. Defaults to NULL.

  • tlim: Sets the limits of the independent variable for which the solution should be plotted. Should be a numeric

    vector of length two. If tlim[2] > tlim[1], then tstep should be negative to indicate a backwards trajectory.

  • tstep: 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: Parameters of the ODE system, to be passed to deriv. Supplied as a numeric vector; the order of the parameters can be found from the deriv file. Defaults to NULL.

  • system: Set to either "one.dim" or "two.dim" to indicate the type of system being analysed. Defaults to "two.dim".

  • col: The colour(s) to plot the trajectories in. Should be a character vector. Will be reset accordingly if it is not of the length of the number of initial conditions. Defaults to "black".

  • add: Logical. If TRUE, the trajectories added to an existing plot. If FALSE, a new plot is created. Defaults to TRUE.

  • state.names: The state names for ode functions that do not use positional states.

  • method: Passed to ode. See there for further details. Defaults to "ode45".

  • ...: Additional arguments to be passed to plot.

Returns

Returns a list with the following components (the exact make up is dependent on the value of system): - add: As per input.

  • col: As per input, but with possible editing if a character vector of the wrong length was supplied.

  • deriv: As per input.

  • n: As per input.

  • method: As per input.

  • parameters: As per input.

  • system: As per input.

  • tlim: As per input.

  • tstep: As per input.

  • t: A numeric vector containing the values of the independent variable at each integration step.

  • x: In the two-dimensional system case, a numeric

    matrix whose columns are the numerically computed values of the first dependent variable for each initial condition.

  • y: In the two-dimensional system case, a numeric

    matrix whose columns are the numerically computed values of the second dependent variable for each initial condition. In the one-dimensional system case, a numeric

    matrix whose columns are the numerically computed values of the dependent variable for each initial condition.

  • y0: As per input, but converted to a numeric

    matrix if supplied as a vector initially.

Examples

# Plot the flow field, nullclines and several trajectories for the # one-dimensional autonomous ODE system logistic logistic_flowField <- flowField(logistic, xlim = c(0, 5), ylim = c(-1, 3), parameters = c(1, 2), points = 21, system = "one.dim", add = FALSE) logistic_nullclines <- nullclines(logistic, xlim = c(0, 5), ylim = c(-1, 3), parameters = c(1, 2), system = "one.dim") logistic_trajectory <- trajectory(logistic, y0 = c(-0.5, 0.5, 1.5, 2.5), tlim = c(0, 5), parameters = c(1, 2), system = "one.dim") # Plot the velocity field, nullclines and several trajectories for the # two-dimensional autonomous ODE system simplePendulum simplePendulum_flowField <- flowField(simplePendulum, xlim = c(-7, 7), ylim = c(-7, 7), parameters = 5, points = 19, add = FALSE) y0 <- matrix(c(0, 1, 0, 4, -6, 1, 5, 0.5, 0, -3), 5, 2, byrow = TRUE) simplePendulum_nullclines <- nullclines(simplePendulum, xlim = c(-7, 7), ylim = c(-7, 7), parameters = 5, points = 500) simplePendulum_trajectory <- trajectory(simplePendulum, y0 = y0, tlim = c(0, 10), parameters = 5)

See Also

ode, plot

Author(s)

Michael J Grayling

  • Maintainer: Michael J Grayling
  • License: MIT + file LICENSE
  • Last published: 2022-09-02