({{, (RefLink[DependentVariables, paclet:ref/DependentVariables]) 
is an option for (RefLink[NDSolve, paclet:ref/NDSolve]) and other functions that specifies the list of all objects that should be considered as dependent variables in equations that have been supplied.}})

OpenersNotesSection(Spacer1)Details

With (RefLink[DependentVariables, paclet:ref/DependentVariables])->(RefLink[Automatic, paclet:ref/Automatic]), the dependent variables are determined from the equations.

(RefLink[DependentVariables, paclet:ref/DependentVariables])->{(Subscript[u, 1]),(Subscript[u, 2]),…} specifies a complete list of dependent variables (Subscript[u, i]) representing functions that should be solved for, even if the solutions are not eventually returned.

(RefLink[DependentVariables, paclet:ref/DependentVariables])->{(Subscript[uspec, 1]),(Subscript[uspec, 2]),…} can be used to specify ranges for dependent variables.

Possible forms for (Subscript[uspec, i]) are:

OpenersPrimaryExamplesSection(Spacer1)Examples  (12)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Save only the solution for x[t]:

xsol=NDSolve[{x'[t]==y[t],y'[t]==-Sin[x[t]],x[0]==3.1,y[0]==0},x,{t,0,20},DependentVariables->{x,y}]

Plot the solution x[t] as a function of t:

Plot[x[t]/.xsol,{t,0,20}]

Stop the integration when the solution has left a specified range:

sol=NDSolve[{y'[t]==y[t],y[0]==1},y,{t,0,10},DependentVariables->{{y[t],0,3}}]

Plot[y[t]/.sol,{t,0,1.1}]

OpenersExampleSection1(Spacer1)Scope  (4)

Multiple range specifications can be enforced for a single dependent variable:

a=1;

NDSolve[{y'[t] == a y[t], y[0]==2}, y, {t, 0, 1}, DependentVariables->{{y, 0, 3}, {y, 1, 4}}]

a=-1;

NDSolve[{y'[t] == a y[t], y[0]==2}, y, {t, 0, 1}, DependentVariables->{{y, 0, 3}, {y, 1, 4}}]

Perform a custom action when a dependent variable goes out of range:

{sol,{point}}=NDSolve[{y'[t]==y[t],y[0]==1},y,{t,0,2},DependentVariables->{{y[t],0,5}:>{Print[{t,y[t]}],Sow[{t,y[t]}]}}]//Reap;

Plot[y[t]/.sol,{t,0,2},Epilog->{PointSize[Medium],Point[point]}]

The event action each time the variable leaves the specified range:

{sol,{points}}=NDSolve[{y''[t]==-y[t],y[0]==0,y'[0]==1},y,{t,0,20},DependentVariables->{{y[t],-.5,.5}:>Sow[{t,y[t]}]}]//Reap;

Plot[y[t]/.sol,{t,0,20},Epilog->{PointSize[Medium],Point[points]}]

Print a message and stop the integration the first time a variable goes out of range:

NDSolve[{y''[t]==-y[t],y[0]==0,y'[0]==1},y,{t,0,20},DependentVariables->{{y[t],-.5,.5}:>{Print[{ t,y[t]}],"StopIntegration"}}]

OpenersExampleSection3(Spacer1)Applications  (2)

Set up a very large system of equations:

n = 1000;
vars = Table[(Subscript[x, i])[t], {i, n}];
eqns = Table[j = Mod[i, n] + 1;{(Subscript[x, i])'[t] == 1/((((Subscript[x, i])[t] + (Subscript[x, j])[t]))^2), (Subscript[x, i])[0] == 1/i}, {i, n}];

Short[eqns, 3]

Solve for all of the dependent variables, but save only the solution for (Subscript[x, 1]):

sol = NDSolve[eqns, (Subscript[x, 1]), {t,0,100}, DependentVariables->vars]

Plot[(Subscript[x, 1])[t] /. sol, {t,0,100}, PlotRange->All]

This saves a lot of memory versus saving all the solutions:

allsol = NDSolve[eqns,vars, {t,0,100}];

{ByteCount[sol], ByteCount[allsol]}

Model an unstable inverted pendulum with oscillating base:

de[a_]:=With[{ω=50},θ''[t]-(-9.8/10)Sin[θ[t]]== -(a/10)ω^2 Sin[ω t]Sin[θ[t]]];
ic={θ[0]==π,θ'[0]==0.01};

Stop the simulation if θ[t] goes outside the range [2,4]:

sol=NDSolve[{de[5],ic},θ,{t,0,2},DependentVariables->{{θ[t],2,4}}]

Plot[θ[t]/.sol,{t,0,1.0732},PlotRange->{2,4}]

At a stable amplitude, the inverted pendulum with oscillating base will not fall out of range:

sol=NDSolve[{de[2],ic},θ,{t,0,2},DependentVariables->{{θ[t],2,4}}];

Plot[θ[t]/.sol,{t,0,2},PlotRange->{3.139,3.145}]

OpenersExampleSection4(Spacer1)Properties & Relations  (1)

Variable range checking can also be achieved with (RefLink[WhenEvent, paclet:ref/WhenEvent]):

NDSolve[{y'[t]==y[t],y[0]==1,WhenEvent[(y[t]+10)(y[t]-10),"StopIntegration"]},y,{t,0,10}]

An equivalent range check with (RefLink[DependentVariables, paclet:ref/DependentVariables]) is more direct and comprehensible:

NDSolve[{y'[t]==y[t],y[0]==1},y,{t,0,10},DependentVariables->{{y[t],-10,10}}]

(RefLink[WhenEvent, paclet:ref/WhenEvent]) is useful for more complicated range checking:

NDSolve[{y'[t]==y[t],y[0]==1,WhenEvent[y[t]^8-y[t]-2,"StopIntegration"]},y,{t,0,10}]

OpenersExampleSection5(Spacer1)Possible Issues  (3)

A variable cannot be specified as both dependent and discrete:

NDSolve[{y'[t]==a[t]y[t],y[0]==1,a[0]==1},y,{t,0,1},DiscreteVariables->{a},DependentVariables->{a, y}]

A dependent variable cannot have a discrete range:

NDSolve[{y'[t]==y[t],y[0]==1},y,{t,0,1},DependentVariables->{Element[y[t],{0,1,2,3}]}]

The variables in a range specification must be valid dependent variables:

NDSolve[{y'[t]==y[t],y[0]==0.5},y[t],{t,0,1},DependentVariables->{{y[t]^2,0,1}}]

Use conditions directly for the dependent variable:

NDSolve[{y'[t]==y[t],y[0]==0.5},y[t],{t,0,1},DependentVariables->{{y[t],-1,1}}]

Or use a (RefLink[WhenEvent, paclet:ref/WhenEvent]) expression in the equation:

NDSolve[{y'[t]== y[t],WhenEvent[((y[t])^2)==1,"StopIntegration"],y[0]==0.5},y[t],{t,0,1}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[NDSolve, paclet:ref/NDSolve])  ▪  (RefLink[RecurrenceTable, paclet:ref/RecurrenceTable])  ▪  (RefLink[NDSolveValue, paclet:ref/NDSolveValue])  ▪  (RefLink[ParametricNDSolve, paclet:ref/ParametricNDSolve])  ▪  (RefLink[ParametricNDSolveValue, paclet:ref/ParametricNDSolveValue])  ▪  (RefLink[DiscreteVariables, paclet:ref/DiscreteVariables])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Differential Equations with Events, paclet:guide/DifferentialEquationsWithEvents])}})}})