Tag Info

Hot answers tagged

9

The Notation package is not necessary to use an infix form of \[Star] as that is handled automatically. Also I recommend PadRight for constructing your expression (reference Generating a matrix using sublists A and B n times). SetAttributes[Star, HoldFirst] Star[a_List, n_Integer] := PadRight[a, n*Length@a, a] {1, 2}⋆5 (* ⋆ is \[Star] *) {1, 2, ...


7

Unevaluated@Sequence[1, 2]~ConstantArray~10 $\ $ {1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2} Or using Notation << Notation` Notation[ParsedBoxWrapper[ RowBox[{ RowBox[{"[", "const_", "]"}], "\[Star]", "reps_"}]] \[DoubleLongRightArrow] ParsedBoxWrapper[ RowBox[{ RowBox[{"Unevaluated", "@", RowBox[{"Sequence", "[", "const_", ...


6

Brief? How about this. Define: c = ConstantArray; Now you can get what you want using the infix notation: "a"~c~7 and 10~c~7 With lists {1, 2}~c~7 you'll need to Flatten.


3

I think the comment solution will serve you well: p1 = Join @@ Permutations /@ IntegerPartitions[3, {18}, Range[0, 3]]; result = Cases[p1, Alternatives @@@ Range[0, {1, 3, 3, 1, 3, 3, 1, 3, 3, 1, 3, 3, 1, 3, 3, 1, 3, 3}]]; Testing this (on my loungebook, so I limited both yours and this to indices to u), yours took ~30 seconds and the initial table took ...


3

Probably. A = Array[a, {3, 4}]; functionTable = A + A f@# &; functionTable[x]


2

The second argument to ListInterpolation can either be a range of x-values (assumed to be equally spaced) or a list of x-values corresponding to the list values. So in your case you may simply do ListInterpolation[ pressure[[All,2]] , pressure[[All,1]] ] Or simply use Interpolation[ptopp] for the same result, or InterpolatingPolynomial[ptopp,x] if ...


2

I figured out a way to do what I was trying to do. Turns out the graph is not that interesting b/c the scale explodes so quickly. In anycase, I believe what I have made use of here (the xx[n] construct) is an "indexed object". Manipulate[ formals = Table[xx[n], {n, 1, a}]; data = {#, 1, 6} & /@ formals; t = Table @@ Prepend[data, formals]; pdf ...


2

If it is enough to apply a uniform style to the whole table, then that can be achieved after applying TableForm: data = Transpose[{Range[9, 14], RandomReal[{-5, 20}, 6]}]; Style[ TableForm[data, TableAlignments -> "."], Red, FontFamily -> "Times New Roman", FontSize -> 23 ]


2

One possibility is to use MapIndexed: n = 3; dyn = Table[False, {i, n}]; A = Dynamic@Transpose[{Range[n], dyn}] MapIndexed[Checkbox[Dynamic[dyn[[#2[[1]]]]]] &, Range[n]]


2

Compare the output of this: Table[ Dynamic[i], {i,3}] (* gives {i,i,i} *) with this: Table[ With[{i=i},Dynamic[i]], {i,3}] (* gives {1,2,3} *) Now you can use that: a = Range[3]; Table[ With[{i=i}, Dynamic[ a[[i]] ] ], {i,3}] (* gives {1,2,3} *) Then: a+=1; (* changes output above to {2,3,4} *) Addendum to address question in the comments ...


2

The following function will find the number of loops for a particular variable: countLoopsWithVar[all_, var_] := Count[all, _?(MemberQ[Flatten[List @@@ #, 1], var] &)] For example, countLoopsWithVar[cycles, 1] returns 0; replacing 1 with 2 returns 3. The way it works is to convert from rules to lists and then checks whether the list is ...


1

I don't know if this will save you sufficient memory, but it will certainly cut down your memory use. $HistoryLength = 0; list1 = Flatten[ Table[{i, j, k, l, m, n, o, p, q, r, s, u, v, x, y, z, a, b}, {i, 0, 1}, {j, 0, 3}, {k, 0, 3}, {l, 0, 1}, {m, 0, 3}, {n, 0, 3}, {o, 0, 1}, {p, 0, 3}, {q, 0, 3}, {r, 0, 1}, {s, 0, 3}, {u, 0, 3}, ...


1

This may not be the fastest way, but it's a way: SetSharedFunction[ParallelSow] ParallelSow[expr_] := Sow[expr] Reap[ParallelDo[If[countedQ[i], ParallelSow[f[i]]], {i, 1, 10^7}]] where countedQ[i] is some Boolean function that determines whether f[i] gets added to the accumulated list. Feel free to make improvements. Note that AppendTo scales as $O(n^2)$ ...


1

Perhaps this is what you are looking for. arry = Array[a, {4, 3}] {{a[1, 1], a[1, 2], a[1, 3]}, {a[2, 1], a[2, 2], a[2, 3]}, {a[3, 1], a[3, 2], a[3, 3]}, {a[4, 1], a[4, 2], a[4, 3]}} funcTable = Map[With[{a = #}, Function[x, a (1 + f[x])]] &, arry, {2}]; This shows how the functions in funcTable can be evaluated at an arbitrary value t. ...


1

Try something like this. Also study this to learn how to create a minimal working example: mwe = Table[{j, Table[RandomInteger[10, 3], {i, 1, 36, 1}]}, {j, 1, 25}]; Row[Column[{#[[1]], MatrixForm@#[[2]]} , Center ] & /@ mwe] showing here a smaller version:


1

Here's an alternative take. pdf[n_Integer] := Tally@Flatten@Array[Plus, ConstantArray[6, n]] Manipulate[ListPlot[pdf[n]], {n, 1, 5, 1}] Performance is significantly improved (10 dice is bearable). To get the cdf add memoization (because bruteforce computation is costly, but end result is simple) and have this: pdf[n_Integer] := (pdf[n] = ...


1

Summarizing J.M.'s comments you could use: Do[ f[m] = Table[i/11 + j/m, {i, 5}, {j, 5}], {m, 9, 12} ]; f[11] // MatrixForm $\left( \begin{array}{ccccc} \frac{2}{11} & \frac{3}{11} & \frac{4}{11} & \frac{5}{11} & \frac{6}{11} \\ \frac{3}{11} & \frac{4}{11} & \frac{5}{11} & \frac{6}{11} & \frac{7}{11} \\ \frac{4}{11} ...


1

This is an alternate method, but I rather prefer kale's: FindCol[t_, n_, col_] := t[[Position [t, n][[1, 1]], col]] FindCol[data, 0.049, 3] (* -0.439999 *)



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