# Tag Info

8

list = {a, b, c}; Mean[{#, RotateLeft@#}]& @ list Mean /@ Partition[#, 2, 1 , 1]& @ list DeveloperPartitionMap[Mean, #, 2, 1, 1]& @ list MovingAverage[ArrayPad[#, {0, 1}, "Periodic"], 2]& @ list MovingAverage[PadRight[#, 1 + Length@#, #], 2]& @list ({##} + { ##2, #})/2 & @@ list {(a + b)/2, (b + c)/2, (a + c)/2} Perfomance ...

7

This is fugly but fulfils the need of staying in the Dataset domain and is much quicker for large datasets. Basically if we use the analogy of a dataset being a SQL table - I do what I would do in the same situation. Create a dummy key on each, join, then drop the dummy key. Personally for small Datasets I prefer the @Mr.Wizard approach from a readability ...

7

No, there isn't. There are several reasons for that: Tr operates on tensors of arbitrary rank, not just matrices Listable functions will automatically thread to the deepest level of lists, so if you set Tr to be Listable, it'll individually wrap each deepest element of a nested list, e.g. Tr[{{1,2},{3,4}}] would transform to {{Tr[1], Tr[2]}, {Tr[3], ...

7

You need to either join all desired plots, e.g. ContourPlot[#, {x, -10, 10}, {y, -10, 10}, ContourStyle -> Red] &@(Join @@ Table[{y == (1/Sqrt[3])*x + i, y == -(1/Sqrt[3])*x + i, x == i*Sqrt[3]/2}, {i, -7, 7}]) or Show, e.g.: Show[ContourPlot[#, {x, -10, 10}, {y, -10, 10}, ContourStyle -> Red] & /@ Table[{y == ...

6

list = {a, b, c}; Append[MovingAverage[list, 2], Mean[{First[list], Last[list]}]] {(a+b)/2, (b+c)/2, (a+c)/2} You can define a function if you want: newMovingAverage[list_] := Append[MovingAverage[list, 2], Mean[{First[list], Last[list]}]] newMovingAverage[list] {(a+b)/2, (b+c)/2, (a+c)/2}

5

The part specification used by Position is shared by Extract: g = Plot[Sin[x], {x, 1, 5}]; pos = Position[g, _Directive] Extract[g, pos] {{1, 1, 3, 1}, {2, 11, 2}} {Directive[ (* omitted *) ], Directive[GrayLevel[0.5, 0.4]]} Note that Extract supports extracting multiple disjoint subexpressions at once. Part can only extract one of these at a ...

5

data = {{193.303, 601.595, 0.001079}, {193.383, 612.928, 0.000071}, {199.129, 476.9, 0.000828}, {199.21, 488.223, 0.000761}} Method 1 {{#1, #2}, #3} & @@@ data {{{193.303, 601.595}, 0.001079}, {{193.383, 612.928}, 0.000071}, {{199.129, 476.9}, 0.000828}, {{199.21, 488.223}, 0.000761}} Method 2 {Take[#, 2], Last[#]} & /@ data Method ...

5

data = RandomInteger[100, {15, 15}]; styleElement[x_] := MouseAppearance[ Mouseover[x, Style[x, Red]], "LinkHand" ] showIndex[x_, index_] := EventHandler[x, {"MouseUp" :> MessageDialog[index]}] Outer[ showIndex[styleElement@data[[##]], {##}] &, Range[15], Range[15] ] // Grid // Deploy Or you can use Tooltip: styleElement[x_, ...

5

eqs = Table[{y == (1/Sqrt[3])*x + i, y == -(1/Sqrt[3])*x + i, x == i*Sqrt[3]/2}, {i, -7, 7}]; ParametricPlot[ Evaluate[{x, y} /. ToRules /@ Flatten[eqs] /. {x -> t, y -> t}], {t, -3, 3}, PlotRange -> 3]

5

eqns = Table[{y==(1/Sqrt[3])*x+i,y == -(1/Sqrt[3])*x+i}, {i, -3, 3}]; ContourPlot[Evaluate[## & @@@ eqns], {x, -3, 3}, {y, -3, 3}] eqns2 = Table[{ x == i Sqrt[3]/2, y == (1/Sqrt[3])*x + i, y == -(1/Sqrt[3])*x + i}, {i, -7, 7}]; ContourPlot[Evaluate[## & @@@ eqns2], {x, -3, 3}, {y, -3, 3}]

4

args = {{m1, n1}, {m2, n2}, {m3, n3}, {m4, n4}}; f @@@ args {f[m1, n1], f[m2, n2], f[m3, n3], f[m4, n4]} Apply[f, args, {1}] {f[m1, n1], f[m2, n2], f[m3, n3], f[m4, n4]} f @@ # & /@ args {f[m1, n1], f[m2, n2], f[m3, n3], f[m4, n4]} f[Sequence @@ #] & /@ args {f[m1, n1], f[m2, n2], f[m3, n3], f[m4, n4]} % == %% == %%% == ...

4

This is comparable to Option 1 from Nasser, but a bit simpler to implement. Try redefining the Subscript symbol to a function, i.e. Subscript[a_,b_]:=a[[b+1]]; c=Range[10]; Enter c then "ctrl -" for the subscript shortcut then your index number. Execute to return the zero indexed list value. This get's the same simple input syntax as Nasser's answer ...

4

Two possible options: option 1 ClearAll[v] Needs["Notation"] len = 5; v = RandomReal[{0, 1}, len]; And now add notation to shift the indes Notation[NotationTemplateTag[ Subscript[v, i_]] \[DoubleLongLeftRightArrow] NotationTemplateTag[v[[(i_) + 1]]]] The above looks like this in the notebook And now use the subscripted version for ...

4

As David commented, there is no unique answer. But here's one possibility: take the Hilbert transform (filter) of the signal and then threshold. q1 = data[[All, 2]]; ListPlot[Abs[HilbertFilter[q + RandomReal[{-.1, .1}, Length[q]], 2.2]]] To show the resiliency to noise, I've added randomness to the data. Even for reasonably large noise, you can still ...

3

Expanding on my comment: this is a perfect example of a common mistake that beginners make when using Mathematica (please don't take offense Marco, none is intended!) The thought process may be something like this: "I know how Total works, and I want to get the total of each sublist, so I'll use a loop structure (such as For, Do, or Table) to make Total work ...

3

MapThread can solve this. a = {{x1, y1}, {x2, y2}, {x3, y3}}; b = {{u1, v1}, {u2, v2}, {u3, v3}}; c = MapThread[List, #] & /@ MapThread[List, {a, b}] The output is {{{x1, u1}, {y1, v1}}, {{x2, u2}, {y2, v2}}, {{x3, u3}, {y3, v3}}}

3

How about getting Mathematica to do the work for us? FullForm[Sequence @@ (XMLNote[#1, m] &) /@ attributes ] // HoldForm Which yields: Apply[Sequence,Map[Function[XMLNote[Slot[1],m]],attributes]] These two expressions are formally equivalent in every single way (they are a different syntax for the same thing). If they yield different results, there ...

3

If you have version 10 or later you can use operators forms, i.e. Map[Tr] acts as a function: mylistofmatrices = {{{a, b}, {c, d}}, {{q, r, s}, {t, u, v}}}; Map[Tr][mylistofmatrices] {a + d, q + u} This is a subtle difference but it may be useful nevertheless. If you always want the trace of a tensor with a specific array depth you can check for ...

3

ListPointPlot3D[Join[#[[2,All,2]],{#[[1]]}]&/@yourList] ... or use ListPlot3D rather than the point plot. The command inside the ListPointPlot3D will extend to more dimensions and also works when your list contains say... {{43, {u->6,v->2,w->5}} <<more items>> }

2

s = {value, {x -> value_x, y -> value_y}} {x /. s[[2]], y /. s[[2]], s[[1]]}

2

You have trailing commas on each line that are imported as empty strings. imported = Import["csv.txt", "CSV", HeaderLines -> 2] {{700.0443115, 0.08416349441, ""}, {699.0369263, 0.08557280153, ""}, {698.0291138, 0.08568932861, ""}, {697.0210571, 0.08601997793, ""}, {696.0126343, 0.08787558973, ""}, {695.0039063, 0.08656696975, ""}, {693.994812, ...

2

♭♭ = ## & @@@ {#2 & @@@ #2, #} & @@ # &; Example: lst ={{35.3919, {x -> 3.17532, y -> 0.826616}}, {22.7658, {x -> 2.74215, y -> 1.86474}}, {47.6532, {x -> 2.59448, y -> 5.939}}, {51.3295, {x -> 2.25842, y -> 5.10077}}, {26.2436, {x -> 1.23835, y -> 2.10218}}, {36.0848, {x ...

2

Update You could just make the equal indices vanish: Sum[Sign[Abs[i - j]] c[i] \[Phi][i, j] \[Beta][j], {i, 1, 4}, {j, 1, 4}] or better as @Guesswhoitis. using Iverson notation concept: Sum[Boole[i!=j] c[i] \[Phi][i, j] \[Beta][j], {i, 1, 4}, {j, 1, 4}] or somewhat ridiculous: mat[sym_, m_, n_] := Normal@SparseArray[{i_, j_} :> sym[i, j] ...

2

Simplify[(Cos[2*a + b + c]*Tan[a + 2*b + 2*c])/ Sin[(b + c - a)/2]] /. (b -> Pi - a - c) // TrigExpand Tan[a] Simplify[(Sin[(6*Pi)/5 + x])^2 + (Sin[(4*Pi)/5 - x])^2 // Simplify, Pi/5 + x == ArcCos[m^-1]] // Together (2*(-1 + m^2))/m^2

2

What you are doing wrong is not paying attention to the form NSolve uses for returning results. Do it in three steps. First evaluate the your NSolve assigning the results to a variable. Do not end this assignment with a semicolon (;) -- you need to see the results. Next transform the results expression into a list of values. Finally apply Max to the list of ...

2

Let's try to simplify this even further and use a handful of extra keystrokes, they are cheap, to try to make this more understandable for a new user. Suppose you wanted to write a function that would be given a list of three elements {a, b, c} and you wanted it to return {{a, b}, c}. You might see the similarity between this and what you want to do with ...

2

Inexact zeros preThreeJSymbols[l1,m1,l2,m2,k] seems to return both 0 and 0. You introduced inexact arithmatic in the expression: ThreeJSymbol[{l1, 0.}, {k, 0.}, {l2, 0.}] You can either add Chop to your result or make these zeros exact: ThreeJSymbol[{l1, 0}, {k, 0}, {l2, 0}] However if you use expr != 0 as Pickett recommended you do not need ...

2

While I think of a way to accomplish your first request, let me contribute this helper function that can highlight positions in a table-formatted array for you, i.e. the very last part of your question): Clear[highlight] highlight[list_, position_] := Grid[array, Background -> {None, None, # -> Yellow & /@ position}] Let's create an array of ...

2

expr2ind[i_, j_] := β[j](ψ[i, j] Boole[i != j] R[i] + ϕ[i, j] Boole[i != j] C[i]) - γ[j] Inf2[i, j] Boole[i != j] pairs = Join @@ {#, Reverse /@ #} &@Subsets[Range[4], {2}]; expr2ind @@@ pairs Sum[expr2ind @@ k, {k, pairs}]

2

One can also use ListCorrelate or ListConvolve which I expect to be quick: 1/2 ListCorrelate[{1, 1}, list, 1] Gives: {(a + b)/2, (b + c)/2, (a + c)/2}

Only top voted, non community-wiki answers of a minimum length are eligible