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)?
Asked
Active
Viewed 390 times
0
mattiav27
- 6,677
- 3
- 28
- 64
-
2at least closely related: 75294 – Kuba Feb 08 '17 at 09:20
-
@Kuba yep. I will flag it as duplicate. – mattiav27 Feb 08 '17 at 09:25
-
@Kuba I forgot my own duplicate. :-( – Mr.Wizard Feb 08 '17 at 09:29
1 Answers
3
{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+1 ! or use your approach with a pattern test
{x1,x2,x3,y1,y2}/._Symbol?(StringMatchQ[SymbolName[#], "x*"] &) -> 0– Ali Hashmi Feb 08 '17 at 09:27