VFGEN
  • Home
  • Download
  • Support
  • User's Guide
  • §   Vector Field File
  • §   ADOL-C
  • §   AUTO
  • §   Check
  • §   CVODE
  • §   DDE23
  • §   DDE-BIFTOOL
  • §   DDE_SOLVER
  • §   Delay2ODE
  • §   DSTool
  • §   EVF
  • §   GSL
  • §   Help
  • §   Javascript
  • §   LaTeX
  • §   LSODA
  • §   MATCONT
  • §   MATLAB
  • §   Octave
  • §   PDDE-CONT
  • §   PyDSTool
  • §   PyGSL
  • §   R
  • §   RADAU5
  • §   Scilab
  • §   SciPy
  • §   Taylor
  • §   XPP

R deSolve Package

The deSolve package provides a suite of ODE, DAE and DDE solvers for the R language. VFGEN provides a command to generate R functions suitable for use with this package.

The VFGEN R Command

R files that can be used with the deSolve package are created by the command

$ vfgen r vector_field_file.vf

The main file created is [name].R, where [name] is the name of the vector field given in the vector field file. This R file will contain the functions [name] and [name]_jac.

Options

func If the option func=yes is given, VFGEN also converts any user-defined functions in the vector field file into functions in the R file. For each user-defined function, two R functions are created. One can be used as a rootfunc with the ode function. The other accepts two arguments: a solution returned by ode and the parameter variable that was given to ode.
Default: func=no
demo If the option demo=yes is given, the file [name]_demo.R is created. The R file contains a script that uses ode to generate a plot of the solution to the differential equations.
Default: demo=no

Example 1

Here is a sample vector field file for the differential equations of a pendulum: pendulumv.vf. The file includes two user-defined function. One computes the energy of the function, and other, defined as

<Function Name="v" Description="the v coordinate (velocity)" Formula="v" />

simply returns the v coordinate of the pendulum.
The files created by

$ vfgen r:func=yes,demo=yes pendulumv.vf

are
  • pendulumv.R
  • pendulumv_demo.R

The script pendulumv_demo.R generates the following plot:

Graphs of theta and v versus time.

The demonstration script shows only the most basic use of ode. Another example is the script plot_pendulumv_solution.R, which demonstrates the use of user-defined functions to find the points where the velocity is zero, and to compute the energy of the solution as a function of time. It generates the following plot.

Graphs of theta and energy versus time.

Example 2

The Mackey-Glass delay-differential equation is $$x'(t) = -bx + \frac{ax(t-\tau)}{1 + x(t-\tau)^{10}}$$

Here is the Mackey-Glass vector field file: MackeyGlass.vf.
The files created by

$ vfgen r:demo=yes MackeyGlass.vf

are
  • MackeyGlass.R
  • MackeyGlass_demo.R

The default time interval use in MackeyGlass_demo.R is 10 time units. This can be changed by editing the line that defines the times sequence to be, for example,

times = seq(0, 500, by = 0.25)
After making this change, the demo script generates the following plot:
Plot of x(t)
(Compare this to the solution generated by the Fortran DDE_SOLVER library here.)

Copyright © 2005-2014 Warren Weckesser