Function Repository Resource:

DependentVariableQ (1.0.0) current version: 1.1.1 »

Source Notebook

Determine whether an expression is a dependent variable

Contributed by: E. Chan-López & Jorge Luis Ramos Castellano

ResourceFunction["DependentVariableQ"][var]

gives True if var depends on one or more variables, and gives False otherwise.

Details

ResourceFunction["DependentVariableQ"] threads over lists.

Examples

Basic Examples (1) 

Use DependentVariableQ to identify a variable that depends on a single variable:

In[1]:=
ResourceFunction["DependentVariableQ"][x[t], t]
Out[1]=

Scope (3) 

Use DependentVariableQ with a list of variables that depend on a single variable:

In[2]:=
ResourceFunction["DependentVariableQ"][{x[t], y[t]}, t]
Out[2]=

Use DependentVariableQ with a variable that depends on two variables:

In[3]:=
ResourceFunction["DependentVariableQ"][x[t, s], {t, s}]
Out[3]=

These are not dependent variables:

In[4]:=
ResourceFunction["DependentVariableQ", ResourceVersion->"1.0.0"][{Tan[\[Theta]], Cos[\[Theta]]}, \[Theta]]
Out[4]=

Applications (4) 

Define a simple function to identify all dependent variables of a single variable for a given Lagrangian:

In[5]:=
f[g_, indepvar_] := Sort[DeleteDuplicates@
   ReplaceAll[Derivative[_][x_][_] :> x[indepvar]][
    Map[If[ResourceFunction["DependentVariableQ"][#, indepvar] === True, #, Nothing] &, DeleteDuplicates[
      Flatten[Which[Depth[#] == 1 \[Or] Depth[#] == 2, #, Depth[#] >= 3, Level[#, {Length[Depth[#]] - 2}]] & /@ Level[g, {1}]]]]]]

Lagrangian for the double pendulum:

In[6]:=
L1 = 1/6 m l^2 (\[Theta]2'[t]^2 + 4 \[Theta]1'[t]^2 + 3 \[Theta]1'[t]*\[Theta]2'[t]*
       Cos[\[Theta]1[t] - \[Theta]2[t]]) + 1/2 m g l (3 Cos[\[Theta]1[t]] + Cos[\[Theta]2[t]]);
In[7]:=
f[L1, t]
Out[7]=

Lagrangian for the spherical pendulum:

In[8]:=
L2 = 1/2 m l^2 (\[Theta]'[t]^2 + Sin[\[Theta][t]]^2*\[Phi]'[t]^2 + m g l Cos[\[Theta][t]]);
In[9]:=
f[L2, t]
Out[9]=

Lagrangian for the PUMA-Like Robot:

In[10]:=
L3 = 1/2 m2 (x2'[t]^2 + y2'[t]^2 + z2'[t]^2) + 1/2 m3 (x3'[t]^2 + y3'[t]^2 + z3'[t]^2) + 1/2 (C1 + C2 Cos[\[Theta]2[t]]^2 + C3 Cos[\[Theta]3[t]]^2 + B2 Sin[\[Theta]2[t]]^2 + B3 Sin[\[Theta]3[t]]^2) \[Psi]1'[
     t]^2 + 1/2 A2 \[Theta]2'[t]^2 + 1/2 A3 \[Theta]3'[t]^2 - g (m2 z2 + m3 z3);
In[11]:=
f[L3, t]
Out[11]=

Properties and Relations (4) 

Use DependentVariableQ with the resource function SolutionRulesToFunctions to convert solution rules to function rules in a given list containing rules whose left-hand side don't match with a variable that depends on other variables:

In[12]:=
Map[If[Head[#] === Rule && ResourceFunction["DependentVariableQ"][#[[1]], t] === True, ResourceFunction["SolutionRulesToFunctions"][#], Nothing] &, {m, s,
   q, y[t] -> a x[t], z[t] -> c b w[t]}]
Out[12]=

Use DependentVariableQ with the resource function SolutionRulesToFunctions on a more complicated list:

In[13]:=
Map[If[Head[#] === Rule && (ResourceFunction["DependentVariableQ"][#[[1]], t] === True \[Or] ResourceFunction["DependentVariableQ"][#[[1]], {x, t}] === True), ResourceFunction["SolutionRulesToFunctions"][#], Nothing] &, {1, Cos[t], m, s, q, y[t] -> a x[t], sol[x, 0, t] -> Sinc[x - t]}]
Out[13]=

Use DependentVariableQ with the resource function SymbolToSubscript:

In[14]:=
Map[If[Head[#] === Rule && ResourceFunction["DependentVariableQ"][#[[1]], t] === True, ResourceFunction["SymbolToSubscript"]@
    ResourceFunction["SolutionRulesToFunctions"][#], Nothing] &, {m, s, q, y1[t] -> a x1[t], z2[t] -> c b w2[t]}]
Out[14]=

Use DependentVariableQ with the resource function FormalizeSymbols:

In[15]:=
Through[ReleaseHold@
  HoldForm[ResourceFunction]["FormalizeSymbols"][
    ToExpression@CharacterRange["\[Alpha]", "\[Kappa]"]][t]]
Out[15]=
In[16]:=
ResourceFunction["DependentVariableQ"][%, t]
Out[16]=

Possible Issues (1) 

DependentVariableQ only identifies dependent variables that have the formats x[var] or x[vars]:

In[17]:=
ResourceFunction["DependentVariableQ"][y[1][t], t]
Out[17]=

Publisher

Ramón Eduardo Chan López

Version History

  • 1.1.1 – 21 July 2023
  • 1.1.0 – 26 June 2023
  • 1.0.1 – 01 May 2023
  • 1.0.0 – 17 April 2023

Source Metadata

Related Resources

Author Notes

The current implementation has been enriched with valuable recommendations from a kind reviewer from the Wolfram Team.

License Information