DiscreteVariables

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

DetailsDetails

  • DiscreteVariables->{v1, v2,} specifies that , , 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 are:
  • vv 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
    {v,vmin,vmax}v has range
    vspeciactioniperform when 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.

ExamplesExamplesopen allclose all

Basic Examples  (2)Basic Examples  (2)

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

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=

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

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=
In[3]:=
Click for copyable input
Out[3]=
Introduced in 2012
(9.0)