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)?
$\begingroup$ $\endgroup$
3 - 2$\begingroup$ at least closely related: 75294 $\endgroup$Kuba– Kuba2017-02-08 09:20:42 +00:00Commented Feb 8, 2017 at 9:20
- $\begingroup$ @Kuba yep. I will flag it as duplicate. $\endgroup$mattiav27– mattiav272017-02-08 09:25:48 +00:00Commented Feb 8, 2017 at 9:25
- $\begingroup$ @Kuba I forgot my own duplicate. :-( $\endgroup$Mr.Wizard– Mr.Wizard2017-02-08 09:29:37 +00:00Commented Feb 8, 2017 at 9:29
Add a comment |
1 Answer
$\begingroup$ $\endgroup$
1 {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
- 1$\begingroup$ +1 ! or use your approach with a pattern test
{x1,x2,x3,y1,y2}/._Symbol?(StringMatchQ[SymbolName[#], "x*"] &) -> 0$\endgroup$Ali Hashmi– Ali Hashmi2017-02-08 09:27:18 +00:00Commented Feb 8, 2017 at 9:27