New answers tagged

3

Maybe something like: ClearAll[cyclicPattern, cyclicPatternRule] cyclicPattern[n_, h_: X] := Times @@ (h /@ (Pattern[#, Blank[]] & /@ # & /@ Partition[Symbol["x" <> ToString[#]] & /@ Range[n], 2, 1, 1])) cyclicPatternRule[n_, h_: X] := cyclicPattern[n, h] -> Symbol[SymbolName[h] <> ToString[n]] cyclicPatternRule /@ Range[...


1

MapThread[ReplaceAll] @ {listA, listB} {1, 4, 27}


1

Here is one way. Try this listA = {x, x^2, x^3}; listB = {x->1, x->2, x->3}; listC = Map[#[[1]]/.#[[2]]&,Transpose[{listA,listB}]] which instantly gives you {1,4,27} The Transpose matches up corresponding items. Just look at the result of Transpose[{listA,listB}] by itself to see what that did for you. Then the Map uses the -> on each ...


1

ToString and ToExpression is a alternative method. A = {12.5 Hz, 16 Hz, 20 Hz, 25 Hz, 31.5 Hz, 40 Hz, 50 Hz, 63 Hz, 80 Hz, 100 Hz, 125 Hz, 160 Hz, 200 Hz, 250 Hz, 315 Hz, 400 Hz, 500 Hz, 630 Hz, 800 Hz, 1 kHz, 1.25 kHz, 1.6 kHz, 2 kHz, 2.5 kHz, 3.15 kHz, 4 kHz, 5 kHz, 6.3 kHz, 8 kHz, 10 kHz, 12.5 kHz, 16 kHz, 20 kHz} // ToString /@ # & // ...


0

An answer of poor quality: f /: f[-x_] := -f[x] f[x_ /; x < 0] := -x f[-x] f[-2]


1

Maybe try converting kHz to 1000 Hz (so that now everything is the same unit-wise) and then using part (to get the Integer or Real part of each entry),as follows: {your,data,list}/. {kHz :> 1*^3 Hz})[[All,1]]; For Example: A=({12.5 Hz,16 Hz,20 Hz,25 Hz,31.5 Hz,40 Hz,50 Hz,63 Hz,80 Hz,100 Hz,125 Hz,160 Hz,200 Hz,250 Hz,315 Hz,400 Hz,500 Hz,630 Hz,800 ...


5

Update: If elements of A are strings as in a2 = {"12.5 Hz", "16 Hz", "20 Hz", "25 Hz", "31.5 Hz", "40 Hz", "50 Hz", "63 Hz", "80 Hz", "100 Hz", "125 Hz", "160 Hz", "200 Hz", "250 Hz", "315 Hz", "400 Hz", "500 Hz", "630 Hz", "800 Hz", "kHz", "1.25 kHz", "1.6 kHz", "2 kHz", "2.5 kHz", "3.15 kHz", "4 kHz", "5 kHz", "6.3 kHz", "8 kHz", "10 kHz", ...


2

I don't see any quotes in that, perhaps they were lost in the process. Try A={12.5 Hz,1.25 kHz}/.{kHz->1*^3,Hz->1} and that should replace Hz and kHz. If there are supposed to be quotes then try A={12.5 "Hz",1.25 "kHz"}/.{"kHz"->1*^3,"Hz"->1}


5

Consider using the Increment operator: (*In[1]:= *)i = 1; (*In[2]:= *)inp = {x, y, z, x, y, x, x, z}; (*In[3]:= *)inp /. x :> i++ (*Out[3]= {1, y, z, 2, y, 3, 4, z}*) Hopefully it's obvious how this can be extended to your example using Symbol.


2

Suppose your F contains indexed variables x[0], x[1], .... You just need to make replacement rules: xList = RandomReal[10, 10]; rules = Thread[Array[x, 10, 0] -> xList] {x[0] -> 7.30088, x[1] -> 6.64534, x[2] -> 0.195005, x[3] -> 0.750164, x[4] -> 1.75732, x[5] -> 8.85201, x[6] -> 2.86472, x[7] -> 6.51873, x[8] -> 2....


0

Is there something you need listed below? g = # - # Log[# + Sqrt@#] &; f[x_List,] := c + Total[g /@ x] f@{1, 2, 3, 4, 5} g = # - # Log[# + Sqrt@#] &; f = c + Total[g /@ Table[x[i], {i, 5}]]; With[{x = {1, 2, 3, 4, 5}[[#]] &}, f]


1

rule = MapAt[_String?(StringStartsQ[#]) &, testru, {All, 1}] Replace[ {str1, str2}, rule, All] {xx, yy} {str1, str2} /. rule {xx, yy} Also srule = # ~~ ___ -> #2 & @@@ testru; # & @@@ StringReplace[srule] @ {str1, str2} {xx, yy}


1

I do not exactly know what you mean. Maybe one or more of the symbols that you use in the replacement have already definitions attached to them? If you prefer to do it by vectorization (which indeed should generally be prefered over ReplaceAll for performance reasons), you can do it like this: Define a function f; Block takes care of shielding the symbols ...


Top 50 recent answers are included