4

If I have an expression, let us say something like this:

Cos[3 x] + π/cofe Exp[y^(c  z)]

how can I get all non-number symbols in the expression which are:

{x, cofe, y, c, z}

I tried this:

Cases[Cos[3 x] + π/cofe Exp[y^(c  z)], _Symbol]

but it didn't work.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Basheer Algohi
  • 19,917
  • 1
  • 31
  • 78

1 Answers1

11
expr = Cos[3 x] + \[Pi]/cofe Exp[y^(c z)];

Cases[expr, _Symbol?(! NumericQ[#] &), Infinity] // Union

(* {c, cofe, x, y, z} *)

In this case the Union is not necessary; however, in general it is needed to eliminate duplicates.

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198