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$

closed as off-topic by Artes, m_goldberg, Bob Hanlon, bbgodfrey, ciao Mar 31 '15 at 0:04

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Artes, m_goldberg, Bob Hanlon, bbgodfrey, ciao
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\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} *)

$\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} *)
$\endgroup$

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