Tag Info

New answers tagged

2

Whilst valid Leonid's code has been superseded by new functionality in Mathematica 10. As well as Association take a look at the Dataset, Select and Query functions in the help. But basically try some of the following : data = {{"1", "Cat", "Tiddles"}, {"2", "Dog", "Spot"}}; cols = {"id", "animal", "name"}; (* turns a list of animals into an ...


1

step and injector pattern First method, load my step function and use the injector pattern: z2 := {{a, {1, 2, 3}}, {b, Complement[{1, 2, 3}, {a}]}, {c, Complement[{1, 2, 3}, {a, b}]}} step[z2] /. _[{x__}] :> Table[{a, b}, x] {{{{1, 2}}, {{1, 3}}}, {{{2, 1}}, {{2, 3}}}, {{{3, 1}}, {{3, 2}}}} UpValues definition Second method, use ...


0

Your expression for chi should be rewritten as chi = Table[ With[{ val = Sech[Tc03/(mu T) ((T/Tc03) x /. FindRoot[Tanh[x] == (T/Tc03) x, {x, 1}])]}, (mu^2 val^2)/(k T (1 - (Tc03/T) val^2))], {T, 1.*10^-6, 4., 1.}] {-5.73535*10^-20, 2.64408*10^-22, 1.319*10^-22, 8.78661*10^-23} However, FindRoot will always find ...


0

If you want to export machine real values, you will need ask for them in you computation. Try something like fun[x_] := c11*(b1*c)^x*(f1*Gamma[-x, b1*d]/Factorial[x]) T4 = Table[{q, fun[q]}, {q, 20, 60}] // N; ListLinePlot[T4, PlotMarkers -> Automatic] Export["CAP4.mat", {T4}, "Table"] This will also increase the speed of ListLinePlot.


1

Update: n = 5; sa = SparseArray[CellularAutomaton[{Total, {}, 1/2}, {{1}, 0}, n]]; satr = Block[{i = 1}, Transpose[RotateRight[#, n + 1 - i++] & /@ (Riffle[#, {0}] & /@ sa) /. 0 -> ""]] ; satr // Grid Original post: saF = SparseArray[CellularAutomaton[#, {{1}, 0}, #2]][#3] &; ptF = Function[{n}, saF @@@ {{{Total, {}, ...


1

Here's a Graphics approach to layout: pascal = With[{n0 = 5}, Table[Binomial[n, k], {n, 0, n0}, {k, 0, n}] ]; With[{scale = {Sqrt[3]/2, 1}, fontsize = 0.12}, Graphics[ MapIndexed[Text[#1, scale (#2 - {0, #2[[1]]/2})] &, pascal, {2}], BaseStyle -> {"TR", FontSize -> Scaled[fontsize]}, PlotRangePadding -> Scaled[fontsize/2]] ] ...


0

pascal[depth_] := Module[ {}, Row[#, Spacer[2]] &@ (Column[#, Center] & /@ Table[ Take[#1[[#2]], #2] & @@ {Array[Binomial, {depth, depth}, 0], i}, {i, 1, depth} ] ) ] pascal[7]


0

tab:={{1},{1,1},{1,2,1}} tab1=Map[Rotate[#,-90\[Degree]]&,#,{2}]&@tab tab2=TableForm[#,TableAlignments->Center]&@tab1 (*on this stage you can apply your alignment function to tab1*) Rotate[#,90\[Degree]]&@tab2


1

rows = 5; Rotate[Column[ StringJoin /@ Map[" " <> ToString[#] <> " " &, NestList[ListConvolve[{1, 1}, #, {1, -1}, 0] &, {1}, rows], {2}], Center], Pi/2] Cleaner: Row[Map[TableForm[#, TableSpacing -> 2] &, NestList[ListConvolve[{1, 1}, #, {1, -1}, 0] &, {1}, rows]], " "]


3

hIters = Hold[{{a, {1, 2, 3}}, {b, Complement[{1, 2, 3}, {a}]}, {c, Complement[{1, 2, 3}, {a, b}]}}] hIters2 = Hold[{a, {1, 2, 3}}, {b, Complement[{1, 2, 3}, {a}]}, {c, Complement[{1, 2, 3}, {a, b}]}] Delete[Hold[Table][{a, b}, hIters], {{0, 0}, {2, 0}, {2, 1, 0}}] ReleaseHold[Hold[Table][{a, b}, hIters2]] Function[Null, Table[{a, b}, ##], ...


9

General I think that one can achieve the goal much easier if we reformulate the request. A variable is IMO not a proper object to store an iterator in the form of expression. What you really need is an environment, which would use certain iterator in code. Simple lexical / dynamic environment Here is how it may look: ClearAll[withIterator]; ...


5

For version 10, another way to use the Inactive/Activate combination with @Kuba's set-delayed trick for defining z2: z20:={{a, {1, 2, 3}}, {b, Complement[{1, 2, 3}, {a}]}, {c, Complement[{1, 2, 3}, {a, b}]}}; Activate@Block[{Complement=Inactive[Complement], Table=Inactive[Table]},Table[{a,b,c}, ##&@@z20]] (* {{{{1, 2, 3}}, {{1, 3, 2}}}, {{{2, 1, 3}}, ...


5

How aboutInactivate? m = Sequence @@ MapThread[{#1, Inactive[Complement][#2, #3]} &, {vars, cr, varsx}]; res = Inactive[Table][vars, m] // Activate (* {{{{{2, 1, 0, 3}}, {{2, 1, 3, 0}}}, {{{2, 3, 0, 1}}, {{2, 3, 1, 0}}}}, {{{{3, 1, 0, 2}}, {{3, 1, 2, 0}}}, {{{3, 2, 0, 1}}, {{3, 2, 1, 0}}}}} *) Another approach, two variations: ClearAll[tab]; ...


7

Would this work for you? m = Sequence @@ MapThread[{#1, comp[#2, #3]} &, {vars, cr, varsx}]; tab[vars, m] /. {tab -> Table, comp -> Complement} (* {{{{{2, 1, 0, 3}}, {{2, 1, 3, 0}}}, {{{2, 3, 0, 1}}, {{2, 3, 1, 0}}}}, {{{{3, 1, 0, 2}}, {{3, 1, 2, 0}}}, {{{3, 2, 0, 1}}, {{3, 2, 1, 0}}}}} *)


8

Not sure if this fits your needs: z2 := Sequence[{a, {1, 2, 3}}, {b, Complement[{1, 2, 3}, {a}]}, {c, Complement[{1, 2, 3}, {a, b}]}] Unevaluated @ Table[{a, b}, z2] /. OwnValues @ z2 {{{{1, 2}}, {{1, 3}}}, {{{2, 1}}, {{2, 3}}}, {{{3, 1}}, {{3, 2}}}} You can use z2 with Set here too: z2 = Unevaluated @ Sequence[{a, {1, 2, 3}}, {b, ...


1

With integers and real numbers as imin, imax, and di it should work. di = 2^(-100) imin = 1 imax = imin + 10 di Table[Numerator[i] - Denominator[i], {i, imin, imax, di}] {0, 1, 1, 3, 1, 5, 3, 7, 1, 9, 5}


0

Just rewriting rasher's terse comment above. You should use the == (Equal) operator and not = (Set) ,because the last one is used only for assigning values to symbols. Like this: RecurrenceTable[ {s[n + 1] == s[n] - (3*s[n]*i[n])/(E^(0.05*n)*100), i[n + 1] == (3*s[n]*i[n])/(E^(0.05*n)*100), s[0] == 99, i[0] == 1}, {s, i}, {n, 1, 30}] (* ...


1

This is due to the HoldAll Attribute of Function. This can be demonstrated by temporarily clearing this attribute as follows: Internal`InheritedBlock[ {Function}, ClearAttributes[Function, HoldAll]; Table[#[[i]] &, {i, 1, 5}] ] // Quiet {1 &, #1[[2]] &, #1[[3]] &, #1[[4]] &, #1[[5]] &} You can find statements regarding ...


2

You can do, for example, the following: list = Table[{i, {2^i, 3^i, 5^i}}, {i, 1, 10}] then Export["test.m", list] and Clear @ list and finally list = Import["test.m"]



Top 50 recent answers are included