0
$\begingroup$

This question already has an answer here:

Assume I have an expression caontaining n paramters x1...xn and I wish to what happens to my expression when all of my n parameters are 0. Is there a way to use Wildcard character * (I mean something like x*->0)?

$\endgroup$

marked as duplicate by mattiav27, Community Feb 8 '17 at 9:27

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.

  • 2
    $\begingroup$ at least closely related: 75294 $\endgroup$ – Kuba Feb 8 '17 at 9:20
  • $\begingroup$ @Kuba yep. I will flag it as duplicate. $\endgroup$ – mattiav27 Feb 8 '17 at 9:25
  • $\begingroup$ @Kuba I forgot my own duplicate. :-( $\endgroup$ – Mr.Wizard Feb 8 '17 at 9:29
3
$\begingroup$
{x1, x2, x3, y1, y2} /. s_Symbol /; StringMatchQ[SymbolName[s], "x*"] -> 0
{0, 0, 0, y1, y2}

Consider using Context if you need more control, e.g. Pattern match any member of a Context

$\endgroup$
  • 1
    $\begingroup$ +1 ! or use your approach with a pattern test {x1,x2,x3,y1,y2}/._Symbol?(StringMatchQ[SymbolName[#], "x*"] &) -> 0 $\endgroup$ – Ali Hashmi Feb 8 '17 at 9:27

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