The below code for getAllVariables
was lifted without attribution from some StackOverflow post.
headlist = {Or, And, Equal, Unequal, Less, LessEqual, Greater,
GreaterEqual, Inequality};
getAllVariables[f_?NumericQ] := Sequence[]
getAllVariables[{}] := Sequence[]
getAllVariables[t_] /; MemberQ[headlist, t] := Sequence[]
getAllVariables[ll_List] :=
Flatten[Union[Map[getAllVariables[#] &, ll]]]
getAllVariables[Derivative[n_Integer][f_][arg__]] :=
getAllVariables[{arg}]
getAllVariables[f_Symbol[arg__]] :=
Module[{fvars},
If[MemberQ[Attributes[f], NumericFunction] || MemberQ[headlist, f],
fvars = getAllVariables[{arg}],(*else*)fvars = f[arg]];
fvars]
getAllVariables[other_] := other
Example:
Leff = (mc dm^2 + mc/12*(h^2 + 3 R^2) + ma da^2 + ma/12 La^2)/(mc dm +
ma da)
getAllVariables[Leff]
(* Out[254]= {da, ma, dm, mc, ma, da, ma, La, mc, dm, mc, h, R} *)
{ c, d, a, b, L, h, R}
instead of unreasonable and awful{mc, dm, ma, da, La, h, R}
? $\endgroup$