1
$\begingroup$

Given an expression, is there any means to list variables?

Example:

a^3 + b^2 + c -> a,b,c

I need this functionality because I am manipulating large expressions of many variables (20) and would like to know which variables remain once the manipulations have been done.

$\endgroup$
  • $\begingroup$ Do you have parameters in those expressions ? $\endgroup$ – Sektor Mar 30 '15 at 18:16
  • $\begingroup$ @Sektor, I am new to Mathematica. Could you give an example? $\endgroup$ – mod0 Mar 30 '15 at 18:16
6
$\begingroup$

Use the Variables command:

 Variables[a x^2 + b x + c]

(* {a,b,c,x} *)

You can easily remove the x.

Alternatively:

CoefficientList[a x^2 + b x + c, x]

(* {a, b, c} *)

| improve this answer | |
$\endgroup$
4
$\begingroup$

A quite general approach is to use Cases.

Cases[a^3 + b^2 + c, z_Symbol :> z, {0, Infinity}]
(* {a, b, c} *)

or

Cases[Cos[a] b^c Gamma[d]/e, z_Symbol :> z, {0, Infinity}]
(* {b, c, e, a, d} *)
| improve this answer | |
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.