# DiscreteVariables

is an option for NDSolve and other functions that specifies variables that only change at discrete times in a temporal integration.

# Details • DiscreteVariables->{v1, v2,} specifies that v1, v2, should be treated as variables that only change at discrete times.
• The value of a discrete variable v can be changed through WhenEvent[event,v->val] or WhenEvent[event,v->"DiscontinuitySignature"].
• The discrete variable solution v can be returned by using NDSolve[eqn,{v,},].
• DiscreteVariables->{vspec1,vspec2,} can be used to specify the ranges for discrete variables.
• Possible forms for vspeci are:
•  v v has range Reals or Complexes Element[v,Reals] v has range Reals Element[v,Complexes] v has range Complexes Element[v,Integers] v has range Integers Element[v,{n1,…}] v has discrete range {n1,…} {v,vmin,vmax} v has range vspeciactioni perform actioni when vspeci is no longer satisfied
• Derivatives with respect to time of discrete variables are zero almost everywhere and should not appear in the equations.
• For partial differential equations, discrete variables can depend only on the temporal independent variable in a method of lines semi-discretization.

# Examples

open all close all

## Basic Examples(2)

Solve for with , a discrete variable that changes at regular intervals in time:

 In:= Out= In:= Out= Solve for with , a discrete variable that changes whenever crosses 0:

 In:= Out= In:= Out= In:= Out= ## Possible Issues(3)

Introduced in 2012
(9.0)