Learn R Programming

QPot (version 1.0)

TSTraj: Simulate two-dimensional stochastic differential equations

Description

This function allows you to simulate two-dimensional stochastic differential equations.

Usage

TSTraj(y0, time, deltat, x.rhs, y.rhs, parms = NA, sigma, lower.bound = NA,
  upper.bound = NA)

Arguments

y0
the a two-element vector of the initial conditions for the state variables. Elements must be assigned as objects (see Example below).
time
numeric value indicating the total time over which the simulation is to be run.
deltat
numeric value indicating the frequency of stochastic perturbation, as $\Delta t$.
x.rhs
A string containing the right hand side of the equation for x.
y.rhs
A string containing the right hand side of the equation for y.
parms
n-element vector of objects representing unvalued paramters in the equation. If parameter values are values in the equation, then default is parms = NA.
sigma
numeric value specifying the noise intensity.
lower.bound
numeric value specifying a lower bound in the simulation.
upper.bound
numeric value specifying an upper bound in the simulation.

Value

  • returns a matrix with three columns (timestep, x values, and y values) with a legth of time/deltat (2*e4 in the examples below).

Examples

Run this code
# First, the parameter values
	model.state <- c(x = 3, y = 3)
	model.sigma <- 0.2
	model.deltat <- 0.005
	model.time <- 100

# Second, write out the deterministic skeleton of the equations to be simulated
	equationx <- "1.54*x*(1.0-(x/10.14)) - (y*x*x)/(1.0 + x*x)"

# Third, Run it

#Can also input x.rhs and y.rhs as strings that contain parameter names
#and include parms with names and values of parameters
model.parms <- c(alpha = 1.54, beta = 10.14, delta = 1, kappa = 1, gamma = 0.476, mu = 0.112509)

Run the code above in your browser using DataLab