New answers tagged table
0
Is this what you're looking for?
Clear[t]
SetSharedVariable[vals]
t[d_, n_] :=
t[d, n - 1]*d*NIntegrate[Exp[-d*x^2], {x, -Infinity, Infinity}]; (*missing d*)
t[_, 0] := 1;
vals = ParallelTable[{i, t[i, 3]}, {i, 1, 500}]
To check:
Table[t[i, 0], {i, 10}]
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
4
I recommend you create a List of lists (which is how you represent an array or matrix in Mathematica):
mytable = Prepend[data, label]
(* {{"x", "y", "z"}, {0.15339, 0.622021, 0.932763}, {0.804435, 0.894563, 0.0611165}, {0.786724, 0.980867, 0.766825}} *)
Then Export it to an Excel file:
Export["mytable.xls", mytable]
And then import it into Word, which ...
1
I cannot give an explanation why it does not work for you unless you give the definition of your makePolynomial. But what about this?
makePolynomial[deg_] := Sum[RandomInteger[{0, 9}]*x^i, {i, 0, deg}]
Table[makePolynomial[3], {5}]
4
Cases[{{1, 2}, {2, 4}, {2, 8}}, {x_, y_} -> {x, 2 y}]
Table[{First@i, Last@i*2}, {i, {{1, 2}, {2, 4}, {2, 8}}}]
{#1, 2 #2} & @@ Transpose@{{1, 2}, {2, 4}, {2, 8}} // Transpose
data = RandomReal[10, {10^6, 2}];
r1 = {#1, 2 #2} & @@ Transpose@data // Transpose; // Timing
r2 = {#1, 2 #2} & @@@ data; // Timing
r1 == r2
(*
{0.109201, Null}
...
7
I like to use Apply for this kind of task.
{#1, 2 #2} & @@@ {{1, 2}, {2, 4}, {2, 8}}
10
9
You can also do it this way:
{{1, 2}, {2, 4}, {2, 8}} /. {x_, y_} -> {x, 2 y}
Which gives:
{{1, 4}, {2, 8}, {2, 16}}
You can change 2 in 2 y to whatever constant you want. This method is flexible because, say you want to multiply the first dimension by a different constant you just put that number in front of x. E.g. Suppose you want to multiply the ...
8
Works nicely:
{{1, 2}, {2, 4}, {2, 8}}.DiagonalMatrix[{1, 2}]
DiagonalMatrix[] is particularly convenient for scaling rows or columns.
From whuber:
Multiplying by a diagonal matrix is fast for up to somewhere between 100 and 1000 columns; beyond that, a solution modeled after Transpose[{1, 2} * Transpose[a]] becomes superior. Even better for such ...
0
You could use Style[StringForm["s = ``", i], Bold, Italic, 16] to combine number and string (and quite a bit of PlotLegends parameter fumbling):
<< PlotLegends`
Plot[Evaluate[(g (-1 + q)^2 (a + b + g (1 - q) s)^2)/((a + b + g - g p q)^3)
/. {q -> 4/5, p -> 1/4, a -> 0.1, g -> 500, s -> Range[0.1, 3, 0.4]}
],
{b, ...
0
In your legend, you can replace the line
Row[{Style["s = ",Bold,Italic,FontSize-> 16],i}]
by this:
Row[{"s = ", i}, BaseStyle -> {Bold, Italic, FontSize -> 16}]
Here, I just used an option for Row to specify the style, because both elements of Row are intended to have the same style. Your statement had Style wrapping only the first element of ...
3
The answer isn't so much related to Map or Table, but to Unevalauted and the evaluation sequence.
The first one
Map[Unevaluated, {1, 2}]
(* {Unevaluated[1], Unevaluated[2]} *)
All the heads and arguments are inert, and none has heads Evaluate or Unevaluated to worry about. Note that the symbol Unevaluated doesn't have head Unevaluated.
Just apply the ...
3
To my mind, it would be better to control the values i is allowed take in the second argument to Table rather than in the first. For your particular example that means writing the very simple and efficient
Table[{i, j} -> 1, {i, 2, 3}, {j, 1, 3}]
{{{2, 1} -> 1, {2, 2} -> 1, {2, 3} -> 1},
{{3, 1} -> 1, {3, 2} -> 1, {3, 3} -> 1}}
This approach can ...
3
I prefer a slightly different approach to Jonathan's, and I believe it is simpler and more in line with the spirit of using rule replacements for getting things done. First, note that since you're dealing with elements in the periodic table, which are finite and small in number (and pairs of those), you can easily generate your matrix of pairs of elements ...
5
The following will take all of the data that you want from the json file and give you a Table that you can use as you wish. Is this what was wanted?
elementList = {"Sc" -> 1, "Ti" -> 2, "V" -> 3, "Cr" -> 4, "Mn" -> 5,
"Fe" -> 6, "Co" -> 7, "Ni" -> 8, "Cu" -> 9, "Zn" -> 10, "Y" -> 11,
"Zr" -> 12, "Nb" -> 13, "Mo" ...
3
This seems rather convoluted, and there is almost certainly an easier way to approach whatever it is you are wishing to do, but I like answering questions like this as it allows working with more unusual aspects of the language.
We can do this:
Block[{tmp, Part}, Hold @@ {test[2]}] /. _[x_] :> (x = {111, 222});
As with my previous answer we may wish ...
2
If speed is an issue, I think testing for the halting condition is likely to be counterproductive, unless a small proportion of elements of the list fit the condition. The suggestion by @b.gatessucks seems more on target. Whether it works depends on how easy and fast it is to solve for the first point at which the "huge functions" become zero.
Here I make ...
6
Generic short-circuiting Table
Preamble
I interpret your question as a general request for an implementation of Table that would, while supporting the general syntax of Table, support the short-circuiting as well. While the core of the implementation described below uses Reap and Sow, similarly to other answers, the advantage of the present approach is its ...
3
It sounds like you want to short circuit your evaluation, in that case Table is a bad choice, as it per definition will carry out each iteration no matter what. A better choice is to use a different iterator constructor for instance While:
y = 0.1;
Module[{x = 0.1},
While[10 - x - y^2 >= 0 && x <= 15,
(Sow[{10 - x - y^2, 1/x - ...
1
If you somehow don't like Do, Table, Reap and Sow (I don't know where you'd get that idea ;) ), you can also use Fold in the following way
Clear[collector]
y = 0.1;
kkkk = 20;
xRange = Table[x, {x, 0.1, 15, 0.5}];
Module[{group},
With[{kkkk = kkkk},
collector[{list_, n_}, elem_] :=
If[n == kkkk, Throw[list],
If[And @@ Positive[elem], ...
8
I'd probably use Sow[]/Reap[] for this case, along with Do[]:
With[{y = 0.1},
Reap[Do[
If[And @@ Positive[temp = {10 - x - y^2, 1/x - y}],
Sow[temp],
Break[]],
{x, 0.1, 15, 0.5}]][[-1, 1]]]
which yields
{{9.89, 9.9}, {9.39, 1.56667}, {8.89, 0.809091}, {8.39, 0.525}, {7.89, 0.37619},
...
7
You can pull out the points by searching for Polygon objects in addHatToL /@ Take[Flatten[Take[LsOnDodecahedron, All]], All]:
p1 = addHatToL/@Take[Flatten[Take[LsOnDodecahedron, All]], All];
surfacepoints = Flatten[Flatten[Cases[Flatten[p1[[#]]],Polygon[m_] ->m], 1]&/@Range[Length[p1]], 1];
surfacepoints will then give you the points on the surface ...
0
If what you want is just formatting your output in the described way, you can use Column/Grid.
MapIndexed[Column[{#1, #2[[1]]},
Alignment -> Center,
Dividers -> {False, {False, True, False}}] &,
{6., 6.63583, 7.64905, 8.97767, 10.5495, 12.2936, 14.1498, 16.0735,
18.0349, 20.0161, 22.0073, 24.0032, 26.0014, 28.0006, 30.0003,
32.0001, ...
1
I may be missing a subtlety in your question but if you just want the numeric values:
lst = {6., 6.63583, 7.64905, 8.97767, 10.5495, 12.2936, 14.1498, 16.0735, 18.0349,
20.0161, 22.0073, 24.0032, 26.0014, 28.0006, 30.0003, 32.0001, 34., 36., 38., 40., 42.,
44., 46., 48., 50., 52., 54., 56., 58., 60.};
MapIndexed[#/#2[[1]] &, lst]
{6., ...
1
Try this one:
Rational@@@Thread[{#, Range[Length[#]]}]&@rootslist[0, 1, 30]
Top 50 recent answers are included




