0
$\begingroup$

This question already has an answer here:

From an expression describing a mathematical function, I would like to extract its parameters. For example, from the expression 4 Sin[2 a x^2 + b x + c], assuming that x is the function variable, I would like to have {a,b,c}.

I tried using patterns with FixedPoint and the TreeForm to select the leaves with heads corresponding to Symbol (but x), but unfortunately unsuccessfully.

$\endgroup$

marked as duplicate by MarcoB, Yves Klett, user9660, m_goldberg, Jason B. Mar 3 '16 at 14:44

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

5
$\begingroup$
expr = 4 Sin[2 a π x^2 + b x + c] + d E^f;

Cases[Level[expr, {-1}], Except[x, _Symbol?(! NumericQ[#] &)]] // Union

(*  {a, b, c, d, f}  *)

Or

Cases[Level[expr, {-1}], Except[x | _?NumericQ, _Symbol]] // Union

(*  {a, b, c, d, f}  *)
$\endgroup$
  • $\begingroup$ Works great, thank you ! Be careful to delete duplicates if there is twice a symbol occurring. $\endgroup$ – Mammouth Mar 8 '16 at 18:39
  • $\begingroup$ @Mammouth - use Union instead of Sort. Modified above. $\endgroup$ – Bob Hanlon Mar 8 '16 at 18:41

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