Tag Info

New answers tagged

1

Not sure if this would this would achieve what you described (I haven't been using MMA as much as I would like so my answer might be clumsy): Clear[countSameLetters] countSameLetters[list_List, distance_Integer] := Position[ Flatten@Differences@Position[list, #] & /@ CharacterRange["a", "z"], distance] // Length To display each distance with ...


1

comp[a_, b___, c_] := a == c k[list_, dist_] := Count[ListConvolve[SparseArray[{1 -> 1, # -> 1}, #]&[dist+1], list, {-1, 1}, 0, Times, comp], True] list = {d, a, e, a, e, b, e, b, c, d, d}; k[list, #] & /@ Range[Length[list] - 1] (* {1, 4, 0, 1, 0, 0, 0, 0, 1, 1} *)


3

Leaving your first part unchanged Remove["Global`*"] firstline = {1, 2, 3, 2, 7}; secondline = {4, 3, 2, 5, 7}; typeOfEndCondition = 0; cc = {3, 2}; In the second part of your code there is only a ; missing after the Print function: avald1 = Table[{}, {i, 5}]; For[i = 1, i <= Length[cc], i++, If[typeOfEndCondition == 0, conline = ...


6

Since version 9 you do not need to do anything extra. tab1 = {{a1, a1 + a2}, {b1, b2*b2}} tab2 = {{2, 5}, {5, 2}} Solve[tab1 == tab2] {{a2 -> 3, b1 -> 5, a1 -> 2, b2 -> -Sqrt[2]}, {a2 -> 3, b1 -> 5, a1 -> 2, b2 -> Sqrt[2]}}


3

You can use MapThread for this purpose: eqs = MapThread[Equal, {tab1, tab2}, 2] (*{{a1 == 2, a1 + a2 == 5}, {b1 == 5, b2^2 == 2}}*) Solve[Flatten[eqs]] (*{{a2 -> 3, b1 -> 5, a1 -> 2, b2 -> -Sqrt[2]}, {a2 -> 3, b1 -> 5, a1 -> 2, b2 -> Sqrt[2]}}*)


3

Histograms can be generated within the dataset using AssociationMap: icds[ GroupBy[Floor[#"parameter"] &] /* AssociationMap[#[[1]] -> SmoothHistogram[#[[2]], PlotLabel -> #[[1]]] &] , All , "response" ] If desired, the histograms can be extracted from the dataset by adding an additional ascending operator to convert the association's ...


2

Outer and Tuples may be helpful, e.g. l1 = {1, 2, 3} l2 = {4, 5, 6, 7} Total /@ Tuples[{l1, l2}] Join @@ Outer[Plus, l1, l2] yields:{5, 6, 7, 8, 6, 7, 8, 9, 7, 8, 9, 10} or symbolically, Join @@ Outer[Plus, {a, b, c}, {d, e, f, g, h}] gives: {a + d, a + e, a + f, a + g, a + h, b + d, b + e, b + f, b + g, b + h, c + d, c + e, c + f, c + g, c + h}


7

"Reflected" padding works as desired but "Periodic" padding is missed. There is corresponding definition for "Reflected" RandomProcesses`TemporalDataUtilitiesDump`toCannonicalPadding[ RandomProcesses`TemporalDataUtilitiesDump`td_, "Reflected", RandomProcesses`TemporalDataUtilitiesDump`w_, RandomProcesses`TemporalDataUtilitiesDump`Caller_] := ...


7

Here is one way: movingMapCircular[f_, l_List] := MapThread[f@* List, {l, RotateLeft[l]}]; For example: movingMapCircular[f, {1, 2, 3, 4}] (* {f[{1, 2}], f[{2, 3}], f[{3, 4}], f[{4, 1}]} *) A generalization of this approach for arbitrary window size may look like: ClearAll[movingMapCircular]; movingMapCircular[f_, l_List, {n_Integer}] := MapThread[ ...


7

I would use the following, Quiet[ Check[ PowerMod[#, -1, 126] + #, ##&[], PowerMod::ninv ]& /@ Range[125], PowerMod::ninv ] (* {2, 106, 34, 110, 106, 92, 34, 146, 142, 92, 146, 124, 128, 106, 160, 110, 106, 92, 160, 146, 142, 92, 146, 124, 128, 106, 160, 110, 106, 218, 160, 146, 142, 218, 146, 250} *) where ##&[] inserts a ...


0

data = {{a, b}, {c, d}, {e, f}}; transform[{x_, y_}] := {x, (f[x] + f[y])/f[x]} then transform/@data


0

I like the solutions that @kguler present. Here is another solution (please tell me if there is a drawback with this): data = {{a, b}, {c, d}, {e, f}}; dataEdited = data /. {a_, b_} -> {a, (f[a] + f[b])/f[a]} {{a, (f[a] + f[b])/f[a]}, {c, (f[c] + f[d])/f[c]}, {e, (f[e] + f[f])/ f[e]}} Edit: I see that @alancalvitti already showed this (but ...


1

data = {{a, b}, {c, d}, {e, f}}; ClearAll[foo, f1, f2, f3]; f1 = MapAt[Divide[Plus @@ foo /@ {##}, foo@#] & @@ # &,Transpose[{#[[All, 1]], #}], {{All, 2}}] &; f2 = MapAt[Divide[Plus@##, #] &@@ # &, Transpose[{#[[All, 1]], Map[foo, #, {-1}]}], {{All, 2}}] &; f3 = {#1, (foo[#] + foo[#2])/foo[#]} & @@@ # &; f1 @ data == f2 @ ...


2

The point is that List has the special property that the head doesn't disappear even with one element. So the solution (as belisarius noted in the comment) is to make the code generate expr with Head=List instead of Plus i.e, expr = List[a[i],b[i],c[i],d[i]] Then I can safely pass this to Map as in Map[f, expr], and it doesn't matter how many elements f ...



Top 50 recent answers are included