[Date Index]
[Thread Index]
[Author Index]
Re: Generalization of Variables ?
*To*: mathgroup at smc.vnet.net
*Subject*: [mg109239] Re: Generalization of Variables ?
*From*: Bob Hanlon <hanlonr at cox.net>
*Date*: Sun, 18 Apr 2010 05:59:36 -0400 (EDT)
variables[expr_] :=
Union[
Cases[
expr, _Symbol?(! NumericQ[#] &), Infinity]]
expr = x + E^y + Sin[x*Pi];
variables[expr]
{x,y}
Bob Hanlon
---- Jack L Goldberg 1 <jackgold at umich.edu> wrote:
=============
Hi Folks,
The built-in command "Variables" does not give the (naively expected)
answer when it is called with functions such as x + Sin[x]. This
behavior is mentioned in the description of "Variables".
I have constructed a generalization of "Variables" which works as
expected - I think? I would appreciated a critique of this code which
addresses these issues:
a) Is there a situation in which it fails?
b) If the code works, can it be improved.
Question b) is asked because I am not fully acquainted with all of
Mathematica's commands.
Here is the code.
variables[f_]:= Flatten[
Union[
Cases[
Map[N,Level[f,{-1},z_Symbol]]/.True->{}
]
I have tried "variables" on functions coded in the obvious manner, say,
Sin[x]+Exp[x^2], Sin[x+y]-z^2, etc. and a few esoteric examples.
Jack
Prev by Date:
**Tracking dynamic trigger**
Next by Date:
**Re: Where is the code for DistanceMatrix?**
Previous by thread:
**Generalization of Variables ?**
Next by thread:
**Re: Generalization of Variables ?**
| |