title: how to mean of day,month value

text: data={{{2006, 1, 1, 0, 0, 0.}, 326.492, {2006, 1, 1, 3, 0, 0.}, 323.08, {2006, 1, 1, 6, 0, 0.}, 314.223, {2006, 1, 1, 9, 0, 0.}, 314.361, {2006, 1, 1, 12, 0, 0.}, 322.048, {2006, 1, 1, 15, 0, 0.}, 323.954, {2006, 1, 1, 18, 0, 0.}, 329.694, {2006, 1, 1, 21, 0, 0.}, 328.151, {2006, 1, 2, 0, 0, 0.}, 330.2, {2006, 1, 2, 3, 0, 0.}, 326.028, {2006, 1, 2, 6, 0, 0.}, 321.627, {2006, 1, 2, 9, 0, 0.}, 322.35, {2006, 1, 2, 12, 0, 0.}, 324.12, {2006, 1, 2, 15, 0, 0.}, 326.305, {2006, 1, 2, 18, 0, 0.}, 326.472, {2006, 1, 2, 21, 0, 0.}, 328.135, {2006, 1, 3, 0, 0, 0.}, 329.194, {2006, 1, 3, 3, 0, 0.}, 327.481, {2006, 1, 3, 6, 0, 0.}, 326.669, {2006, 1, 3, 9, 0, 0.}, 328.192, {2006, 1, 3, 12, 0, 0.}, 333.164, {2006, 1, 3, 15, 0, 0.}, 335.645, {2006, 1, 3, 18, 0, 0.}, 336.476, {2006, 1, 3, 21, 0, 0.}, 338.306, {2006, 1, 4, 0, 0, 0.}, 339.458, {2006, 1, 4, 3, 0, 0.}, 334.536, {2006, 1, 4, 6, 0, 0.}, 328.724, {2006, 1, 4, 9, 0, 0.}, 328.655, {2006, 1, 4, 12, 0, 0.}, 332.485, {2006, 1, 4, 15, 0, 0.}, 335.088, {2006, 1, 4, 18, 0, 0.}, 337.114, {2006, 1, 4, 21, 0, 0.}, 337.366, {2006, 1, 5, 0, 0, 0.}, 338.779, {2006, 1, 5, 3, 0, 0.}, 335.708, {2006, 1, 5, 6, 0, 0.}, 326.423, {2006, 1, 5, 9, 0, 0.}, 325.267, {2006, 1, 5, 12, 0, 0.}, 329.921, {2006, 1, 5, 15, 0, 0.}, 332.107, {2006, 1, 5, 18, 0, 0.}, 333.599, {2006, 1, 5, 21, 0, 0.}, 333.82, {2006, 1, 6, 0, 0, 0.}, 334.48, {2006, 1, 6, 3, 0, 0.}, 330.553, {2006, 1, 6, 6, 0, 0.}, 321.303, {2006, 1, 6, 9, 0, 0.}, 320.164, {2006, 1, 6, 12, 0, 0.}, 325.976, {2006, 1, 6, 15, 0, 0.}, 326.513, {2006, 1, 6, 18, 0, 0.}, 329.622, {2006, 1, 6, 21, 0, 0.}, 330.697, {2006, 1, 7, 0, 0, 0.}, 331.182, {2006, 1, 7, 3, 0, 0.}, 326.039, {2006, 1, 7, 6, 0, 0.}, 318.691, {2006, 1, 7, 9, 0, 0.}, 318.71, {2006, 1, 7, 12, 0, 0.}, 324.686, {2006, 1, 7, 15, 0, 0.}, 326.495, {2006, 1, 7, 18, 0, 0.}, 328.6, {2006, 1, 7, 21, 0, 0.}, 329.187, {2006, 1, 8, 0, 0, 0.}, 331.104, {2006, 1, 8, 3, 0, 0.}, 326.403, {2006, 1, 8, 6, 0, 0.}, 319.914, {2006, 1, 8, 9, 0, 0.}, 319.141, {2006, 1, 8, 12, 0, 0.}, 320.443, {2006, 1, 8, 15, 0, 0.}, 323.578, {2006, 1, 8, 18, 0, 0.}, 326.673, {2006, 1, 8, 21, 0, 0.}, 328.346, {2006, 1, 9, 0, 0, 0.}, 330.256, {2006, 1, 9, 3, 0, 0.}, 328.464, {2006, 1, 9, 6, 0, 0.}, 319.662, {2006, 1, 9, 9, 0, 0.}, 320.738, {2006, 1, 9, 12, 0, 0.}, 325.786, {2006, 1, 9, 15, 0, 0.}, 334.061, {2006, 1, 9, 18, 0, 0.}, 329.304, {2006, 1, 9, 21, 0, 0.}, 328.593, {2006, 1, 10, 0, 0, 0.}, 326.963, {2006, 1, 10, 3, 0, 0.}, 322.941, {2006, 1, 10, 6, 0, 0.}, 313.76, {2006, 1, 10, 9, 0, 0.}, 312.741, {2006, 1, 10, 12, 0, 0.}, 314.636, {2006, 1, 10, 15, 0, 0.}, 316.681, {2006, 1, 10, 18, 0, 0.}, 318.124, {2006, 1, 10, 21, 0, 0.}, 319.609, {2006, 1, 11, 0, 0, 0.}, 321.136, {2006, 1, 11, 3, 0, 0.}, 319.109, {2006, 1, 11, 6, 0, 0.}, 314.94, {2006, 1, 11, 9, 0, 0.}, 314.124, {2006, 1, 11, 12, 0, 0.}, 314.691, {2006, 1, 11, 15, 0, 0.}, 315.855, {2006, 1, 11, 18, 0, 0.}, 316.476, {2006, 1, 11, 21, 0, 0.}, 317.422, {2006, 1, 12, 0, 0, 0.}, 320.974, {2006, 1, 12, 3, 0, 0.}, 320.894, {2006, 1, 12, 6, 0, 0.}, 317.82, {2006, 1, 12, 9, 0, 0.}, 320.186, {2006, 1, 12, 12, 0, 0.}, 323.888, {2006, 1, 12, 15, 0, 0.}, 323.839, {2006, 1, 12, 18, 0, 0.}, 323.132, {2006, 1, 12, 21, 0, 0.}, 326.405, {2006, 1, 13, 0, 0, 0.}, 329.781, {2006, 1, 13, 3, 0, 0.}, 326.373, {2006, 1, 13, 6, 0, 0.}, 319.098, {2006, 1, 13, 9, 0, 0.}, 319.103, {2006, 1, 13, 12, 0, 0.}, 323.52, {2006, 1, 13, 15, 0, 0.}, 327.681, {2006, 1, 13, 18, 0, 0.}, 318.762, {2006, 1, 13, 21, 0, 0.}, 319.757, {2006, 1, 14, 0, 0, 0.}, 317.946, {2006, 1, 14, 3, 0, 0.}, 318.51, {2006, 1, 14, 6, 0, 0.}, 318.662, {2006, 1, 14, 9, 0, 0.}, 318.798, {2006, 1, 14, 12, 0, 0.}, 323.251, {2006, 1, 14, 15, 0, 0.}, 327.992, {2006, 1, 14, 18, 0, 0.}, 336.417, {2006, 1, 14, 21, 0, 0.}, 329.91, {2006, 1, 15, 0, 0, 0.}, 330.959, {2006, 1, 15, 3, 0, 0.}, 325.356, {2006, 1, 15, 6, 0, 0.}, 320.116, {2006, 1, 15, 9, 0, 0.}, 318.204, {2006, 1, 15, 12, 0, 0.}, 324.788, {2006, 1, 15, 15, 0, 0.}, 326.794, {2006, 1, 15, 18, 0, 0.}, 326.043, {2006, 1, 15, 21, 0, 0.}, 328.213, {2006, 1, 16, 0, 0, 0.}, 329.418, {2006, 1, 16, 3, 0, 0.}, 325.934, {2006, 1, 16, 6, 0, 0.}, 320.338, {2006, 1, 16, 9, 0, 0.}, 319.361, {2006, 1, 16, 12, 0, 0.}, 325.494, {2006, 1, 16, 15, 0, 0.}, 327.167, {2006, 1, 16, 18, 0, 0.}, 328.414, {2006, 1, 16, 21, 0, 0.}, 329.696, {2006, 1, 17, 0, 0, 0.}, 330.53, {2006, 1, 17, 3, 0, 0.}, 326.143, {2006, 1, 17, 6, 0, 0.}, 320.913, {2006, 1, 17, 9, 0, 0.}, 320.573, {2006, 1, 17, 12, 0, 0.}, 325.655, {2006, 1, 17, 15, 0, 0.}, 328.056, {2006, 1, 17, 18, 0, 0.}, 330.983, {2006, 1, 17, 21, 0, 0.}, 329.368, {2006, 1, 18, 0, 0, 0.}, 327.041, {2006, 1, 18, 3, 0, 0.}, 324.301, {2006, 1, 18, 6, 0, 0.}, 319.651, {2006, 1, 18, 9, 0, 0.}, 320.206, {2006, 1, 18, 12, 0, 0.}, 326.33, {2006, 1, 18, 15, 0, 0.}, 328.402, {2006, 1, 18, 18, 0, 0.}, 333.758, {2006, 1, 18, 21, 0, 0.}, 330.415, {2006, 1, 19, 0, 0, 0.}, 331.269, {2006, 1, 19, 3, 0, 0.}, 325.665, {2006, 1, 19, 6, 0, 0.}, 320.229, {2006, 1, 19, 9, 0, 0.}, 319.886, {2006, 1, 19, 12, 0, 0.}, 325.75, {2006, 1, 19, 15, 0, 0.}, 326.794, {2006, 1, 19, 18, 0, 0.}, 327.799, {2006, 1, 19, 21, 0, 0.}, 327.676, {2006, 1, 20, 0, 0, 0.}, 326.539, {2006, 1, 20, 3, 0, 0.}, 323.767, {2006, 1, 20, 6, 0, 0.}, 321.039, {2006, 1, 20, 9, 0, 0.}, 318.396, {2006, 1, 20, 12, 0, 0.}, 322.366, {2006, 1, 20, 15, 0, 0.}, 325.274, {2006, 1, 20, 18, 0, 0.}, 325.658, {2006, 1, 20, 21, 0, 0.}, 326.558, {2006, 1, 21, 0, 0, 0.}, 327.196, {2006, 1, 21, 3, 0, 0.}, 323.771, {2006, 1, 21, 6, 0, 0.}, 316.523, {2006, 1, 21, 9, 0, 0.}, 316.252, {2006, 1, 21, 12, 0, 0.}, 321.72, {2006, 1, 21, 15, 0, 0.}, 324.336, {2006, 1, 21, 18, 0, 0.}, 327.127, {2006, 1, 21, 21, 0, 0.}, 328.491, {2006, 1, 22, 0, 0, 0.}, 328.535, {2006, 1, 22, 3, 0, 0.}, 322.131, {2006, 1, 22, 6, 0, 0.}, 318.04, {2006, 1, 22, 9, 0, 0.}, 316.22, {2006, 1, 22, 12, 0, 0.}, 321.768, {2006, 1, 22, 15, 0, 0.}, 322.051, {2006, 1, 22, 18, 0, 0.}, 323.318, {2006, 1, 22, 21, 0, 0.}, 324.169, {2006, 1, 23, 0, 0, 0.}, 324.497, {2006, 1, 23, 3, 0, 0.}, 322.241, {2006, 1, 23, 6, 0, 0.}, 317.922, {2006, 1, 23, 9, 0, 0.}, 317.827, {2006, 1, 23, 12, 0, 0.}, 318.877, {2006, 1, 23, 15, 0, 0.}, 321.213, {2006, 1, 23, 18, 0, 0.}, 322.607, {2006, 1, 23, 21, 0, 0.}, 325.508, {2006, 1, 24, 0, 0, 0.}, 326.516, {2006, 1, 24, 3, 0, 0.}, 325.44, {2006, 1, 24, 6, 0, 0.}, 322.301, {2006, 1, 24, 9, 0, 0.}, 320.571, {2006, 1, 24, 12, 0, 0.}, 323.99, {2006, 1, 24, 15, 0, 0.}, 325.769, {2006, 1, 24, 18, 0, 0.}, 325.893, {2006, 1, 24, 21, 0, 0.}, 323.95, {2006, 1, 25, 0, 0, 0.}, 322.063, {2006, 1, 25, 3, 0, 0.}, 317.175, {2006, 1, 25, 6, 0, 0.}, 311.124, {2006, 1, 25, 9, 0, 0.}, 310.832, {2006, 1, 25, 12, 0, 0.}, 317.104, {2006, 1, 25, 15, 0, 0.}, 319.588, {2006, 1, 25, 18, 0, 0.}, 321.886, {2006, 1, 25, 21, 0, 0.}, 324.605, {2006, 1, 26, 0, 0, 0.}, 325.571, {2006, 1, 26, 3, 0, 0.}, 319.892, {2006, 1, 26, 6, 0, 0.}, 312.419, {2006, 1, 26, 9, 0, 0.}, 311.632, {2006, 1, 26, 12, 0, 0.}, 317.151, {2006, 1, 26, 15, 0, 0.}, 315.756, {2006, 1, 26, 18, 0, 0.}, 309.114, {2006, 1, 26, 21, 0, 0.}, 308.152, {2006, 1, 27, 0, 0, 0.}, 307.869, {2006, 1, 27, 3, 0, 0.}, 306.179, {2006, 1, 27, 6, 0, 0.}, 304.344, {2006, 1, 27, 9, 0, 0.}, 310.731, {2006, 1, 27, 12, 0, 0.}, 312.042, {2006, 1, 27, 15, 0, 0.}, 315.486, {2006, 1, 27, 18, 0, 0.}, 319.399, {2006, 1, 27, 21, 0, 0.}, 326.018, {2006, 1, 28, 0, 0, 0.}, 323.422, {2006, 1, 28, 3, 0, 0.}, 321.549, {2006, 1, 28, 6, 0, 0.}, 315.104, {2006, 1, 28, 9, 0, 0.}, 318.588, {2006, 1, 28, 12, 0, 0.}, 324.495, {2006, 1, 28, 15, 0, 0.}, 329.223, {2006, 1, 28, 18, 0, 0.}, 331.212, {2006, 1, 28, 21, 0, 0.}, 331.474, {2006, 1, 29, 0, 0, 0.}, 333.785, {2006, 1, 29, 3, 0, 0.}, 327.536, {2006, 1, 29, 6, 0, 0.}, 321.733, {2006, 1, 29, 9, 0, 0.}, 318.309, {2006, 1, 29, 12, 0, 0.}, 325.799, {2006, 1, 29, 15, 0, 0.}, 327.442, {2006, 1, 29, 18, 0, 0.}, 327.955, {2006, 1, 29, 21, 0, 0.}, 328.15, {2006, 1, 30, 0, 0, 0.}, 330.915, {2006, 1, 30, 3, 0, 0.}, 326.628, {2006, 1, 30, 6, 0, 0.}, 317.78, {2006, 1, 30, 9, 0, 0.}, 316.483, {2006, 1, 30, 12, 0, 0.}, 322.661, {2006, 1, 30, 15, 0, 0.}, 327.509, {2006, 1, 30, 18, 0, 0.}, 330.479, {2006, 1, 30, 21, 0, 0.}, 333.422, {2006, 1, 31, 0, 0, 0.}, 335.805, {2006, 1, 31, 3, 0, 0.}, 329.932, {2006, 1, 31, 6, 0, 0.}, 322.188, {2006, 1, 31, 9, 0, 0.}, 322.895, {2006, 1, 31, 12, 0, 0.}, 330.111, {2006, 1, 31, 15, 0, 0.}, 333.34, {2006, 1, 31, 18, 0, 0.}, 334.173, {2006, 1, 31, 21, 0, 0.}} how to find mean of day and month, years value? ... this is only month data.


title: How does Mathematica know my location?

text: On the `AstronomicalData` page in the online reference, it says for               AstronomicalData["Sun", "NextRiseTime"]      that it finds the next rise time for the Sun **from your current location** and time. Where does _Mathematica_ keep that? I don't remember giving that during installation and I can't find it in the Preferences either. **edit**   Particularly the returned value               {2012, 9, 5, 7, 3, 52.704}      to 1 ms resolution suggests that the location is known to some precision. At the latitude where I live, 1 ms is 25 cm.


title: Mathematica crashes after evaluating a call to a user-defined function

text: I have recently installed Mathematica 9 on my macbook pro, os version 10.6.8. As you can see in the minimal example notebook you can download here: https://dl.dropbox.com/u/1163801/crashing_notebook.nb when I simply run a sequence of inputs everything is fine, bit as soon as I put exactly the same inputs into a function of two variables and call this function with the same parameters used before the UI crashes. This doesn't happen for all functions, but for this one it does. Any ideas? Any help would be very much appreciated. PS: Don't ask why I define a constant to be a function of S, this will be used as a function of S later.


title: How to place legend labels for Histogram and ListLinePlots correctly?

text: I would like to place AxesLabels:   1. For x axis at center of the Histogram and LineListPLots.    2. For y axis rotated 90 degree anti clockwise. I don't see any options for it?               Histogram[Table[zcb[i],{i,mcRunHJM}],AxesLabel->{Price,Relative Frequency}]          ListLinePlot[Table[zcb[i],{i,mcRunHJM}],PlotRange->{{0,mcRunHJM},{0.9,1.1}}, PlotLabel->Style["Convergence",FontSize->12],AxesLabel->{Simulation Step,Price}]        ![enter image description here](http://i.stack.imgur.com/hpCEr.png)


title: The front end encountered an error while processing a "NotebookPredictions" packet

text: I occasionally get the error > The front end encountered an error while processing a "NotebookPredictions" > packet. I cannot find any documentation for this error message online. It does not seem to affect anything however, so is there a way to prevent this message from ever showing up?


title: Auto simplifications of power products

text: Mathematica automatically simplifies `Exp[a]Exp[b]` to `Exp[a+b]`. The problem is now that I can't do this `Exp[a]Exp[b]/.Exp[a]->c` for example. How to solve this kind of problem? In particular I want something like this to work `Exp[x_+y_]//.Exp[x]Exp[y]/.Exp[some_pattern]->c`.


title: How can I fix CDF Windowsize as constant

text: I want to make `CDF` `WindowSize` as constant so that the end user can not resize it either by dragging Window or by maximizing it. Is there any in built `Mathematica` function to do this?


title: How to find the Shortest Path, visiting ALL vertices, without coming back to the start (Hamiltonian Path, minimum distance)

text: A car has to pick up each person and take them to their destination. I am trying to find the shortest tour that will do this. How can I find the shortest path between any s and t.... visiting all vertices, and without coming back to the start? ![competition](http://i.stack.imgur.com/LEJqM.png) In this case I have 10 points. After each `For[]`, I obtain an array with the distances from i to j.               t = {       {{2, 1}, {5, 2}},       {{7, 1}, {9, 4}},       {{9, 2}, {6, 6}},       {{5, 4}, {2, 3}},       {{4, 5}, {7, 9}},       {{8, 5}, {2, 4}},       {{3, 7}, {7, 7}},       {{4, 8}, {1, 10}},       {{3, 10}, {10, 7}},       {{9, 10}, {9, 8}}       }     (* t[[i,j,k]    i\[Rule]Trip Nºi    j\[Rule] \     1=Inicio=Pick-Up  2=Fin=Drop-Off     k\[Rule] 1ª o 2ª componente (es \     decir x ó y) *)          Array[t2t, {10, 10}]     For[i = 1, i <= 10, i++,      For[j = 1, j <= 10, j++,       If[i != j,        t2t[i, j] =              Sqrt[(t[[j, 1, 1]] - t[[i, 2, 1]])^2 +              (t[[j, 1, 2]] - t[[i, 2, 2]])^2], t2t[i, j] = Infinity        (* In t2t there is the distance from i to j            different from distance from j to i, in general *)        ]       ]      ]      I want to find the shortest tour through the 10 vertices, with the weight/distsances `t2t[i,j]` visiting all vertices, and not coming back to the start.


title: Datastream to Mathematica

text: I currently use data from Thomson Reuters Datastream. With an add-in in Excel, the data can be requested. Because I need to use the data in Mathematica, and I need to update the data frequently: Is it possible to extract data from Datastream directly into Mathematica (with an API) ? Does anyone has experience/knowledge doing such a thing?


title: Programmatic generation of enhanced (Enterprise) CDF

text: How does one PROGRAMATICALLY generate enhanced CDFs under an Enterprise license? Undocumented options to CDFDeploy[] perhaps?. Wizard works fine for me, but attempts to do this programatically (from script) have defeated me - I just get standard CDFs labeled under the FreeCDF terms (this result with no code changes.) Can't find this in documentation.


title: How can I scale a plot in vector graphic or PDF form?

text: I am not at all a computer graphics expert, but it seems that portable document format (PDF) files have a "native size," even though they may (and usually do!) contain vector graphics that can be scaled essentially infinitely without loss of quality. In Mathematica, the `ImageSize` option in graphics and plotting commands like `Graphics`, `Plot`, and `ListPlot` allows one to specify the size of images such as graphics and plots. One way to use the `ImageSize` option is to simply specify a width $w$. The image will be given that width and the image's height will be automatically chosen so as to maintain the image's `AspectRatio` (which, for plots, has the default `1/GoldenRatio`). Now, in the documentation for `ImageSize` (see the Details section), it is stated that one possible specification for width $w$ (and for height $h$) is $72 di$, which specifies $di$ inches (before magnification), according to the Documentation. This means that if I want an image (for example, a `ListPlot`) to be $di$ inches in width, I just need to use the option `ImageSize -> (72*di)` within the `ListPlot`. (I'm not certain, but it may be necessary to round the result to an integer, since I'm not sure if `ImageSize` accepts fractional/decimal arguments. If so, then I can just use `ImageSize -> Round[72*di]`). So here's an example. Suppose that I'm told by a publisher that my image should be 8 inches wide. So I use `ImageSize -> (72*8)` in `ListPlot`. Then I customize my `ListPlot` in a variety of ways: I use the `BaseStyle` option to set the font size and family and I use `Disk[]` shapes as the `PlotMarkers`. I play with the parameters until my plot looks nice. For example:               xdata = Range[0, 0.05, 0.00115];     ydata = Sin[160*xdata];          pmSize = 10;(* size of PlotMarkers *)     pm = Graphics[{Red, Disk[]}, ImageSize -> pmSize];(* PlotMarkers *)          imgSizeInInches = 8;     imgSizeInPixels = Round[72*imgSizeInInches];(* ImageSize *)          pl = ListPlot[Transpose[{xdata, ydata}],       PlotRange -> {-1.1, 1.1},       Frame -> True,       FrameLabel -> {"x (unit)", "y (unit)"},       FrameStyle -> Thickness[Medium],       AxesStyle -> Thickness[Medium],       BaseStyle -> {26, FontFamily -> "Arial"},       PlotMarkers -> pm,       ImageSize -> imgSizeInPixels]      which gives this output: ![FirstOutput](http://i.stack.imgur.com/Idxmo.png) Now I export to a PDF file called "example.pdf":               Export["example.pdf", pl, "AllowRasterization" -> False]      I open this PDF in Adobe Acrobat. Adobe Acrobat tells me (see the status bar at the bottom left) that, as promised, the image is 8 inches wide: ![PDFImage](http://i.stack.imgur.com/U0xSF.png) Yea! I am pleased, and so is my publisher: the PDF file's native size is 8 inches wide! _**Now, however,_** suppose that the publisher changes its mind and now wants the PDF image to be natively 5 inches wide instead. My first thought is to simply set `ImageSize` to `72*5`. That will make the width of the image 5 inches. I do this by simply setting `imgSizeInInches = 5;` in my code:               xdata = Range[0, 0.05, 0.00115];     ydata = Sin[160*xdata];          pmSize = 10;(* size of PlotMarkers *)     pm = Graphics[{Red, Disk[]}, ImageSize -> pmSize];(* PlotMarkers *)          imgSizeInInches = 5;     imgSizeInPixels = Round[72*imgSizeInInches];(* ImageSize *)          pl = ListPlot[Transpose[{xdata, ydata}],       PlotRange -> {-1.1, 1.1},       Frame -> True,       FrameLabel -> {"x (unit)", "y (unit)"},       FrameStyle -> Thickness[Medium],       AxesStyle -> Thickness[Medium],       BaseStyle -> {26, FontFamily -> "Arial"},       PlotMarkers -> pm,       ImageSize -> imgSizeInPixels]      ...which gives this output: ![SecondOutput](http://i.stack.imgur.com/beFfW.png) When I export to a PDF file using `Export["example.pdf", pl, "AllowRasterization" -> False]` and open the resulting file in Adobe Acrobat, Adobe Acrobat confirms that the native width of the image is 5 inches: ![NewOut](http://i.stack.imgur.com/RbTSi.png) **But** now the image is crammed -- the size of the image decreased, but the sizes of the font and the plot markers did not. _**So, my question is:_** is there any way to simply **scale** the image so that the PDF file's "native" size decreases while _also_ proportionally decreasing the size of the text, plot markers, etc? In that way, the _entire_ image would "shrink" proportionally -- although without loss of quality since the image is a vector graphic! Please not that I do not want to rasterize the image; I would like to keep the image as a vector graphic. Thank you for any help you can give with this confusing issue.


title: Getting serious about Mathematica programming

text: I'm at a point in my _Mathematica_ journey where I need to be a little bit more strategic about my coding. Presently, I have a bunch of notebook files organized using the filesystem of the OS and tossed on to a cloud drive (Ubuntu One, Google Drive, whatever) so that I have access to the code from the 3-4 machines upon which I use Mathematica. Since I'm not a programmer by trade, I suspect a number of the following questions will be fairly generic, but since we've discussed using Mathematica as a first language (multiple times) my issues may arise with other relatively new users of the software. I am trying to address the following concerns:   * What are some best practices for maintaining notebooks and packages across multiple computers?   * How does one effectively implement version control for notebooks?   * What strategies are useful for managing tasks in large projects?   * How can packages be distributed efficiently, especially to a user-base that may have limited _Mathematica_ knowledge. **Multicomputer use:** As alluded to above, I'm using a cloud service to maintain my notebooks; however I've run in to syncing problems enough times that I wonder if there aren't better solutions. I understand that CVS is an option for team-based programming, but I've never used this system before, have no prior knowledge of how hard it is to set up a server, and wonder if this would be overkill for projects that are effectively written by me on multiple computers. My experience with git is limited to downloading the SEUploader and getting scared away by rm-rf's answer to using git. **Version control:** I have no idea how to do this properly. Presently whenever I start a project, I name it project-v01.nb and move on from there. I arbitrarily change the version number, typically when my cloud drive service throws a syncing error. There's not a chance in the world that my current system can provide differences between versions. **Task management:** In an ideal world, I would finish every project at one, uninterrupted sitting. Presently I've tried two approaches: I use the heading styles of a notebook to create a type of outline. These notebooks get convoluted quickly because they are a mix of project design and project application. I then thought to move the project design components to a new notebook, which I named currentproblems-v01.nb. Then, like bunnies, currentproblems-v02, v03, ... popped up. I have no idea which current problem is, uh, current. **Distribution:** I suspect other programmers have delusions of grandeur as well, thinking that their code will be used by millions. At the very least, I'd like to port my projects to the computers used by my research students, who have to use my code or I can fire them... I suspect this will involve using the Wolfram Workbench, but then I've heard some folks prefer Eclipse. I don't have a preference since I've used neither; I think the only real requirements of the software are (a) make my life easier and (b) maintain development so I don't become dependent on abandoned software. I envision creating notebooks and packages that undergraduate students (in Chemistry) will use in research and the classroom. Given that my students (the first- years, anyway) will have limited experience with Mathematica, I wonder if asking them to install packages is the best option to distribute code.


title: Multivariate resultant in Mathematica?

text: Is there any command in Mathematica 7 which can compute the (McCaulay) resultant of a parametric system of multivariate polynomial equations? In fact, it would be great if there is also a way to compute the discriminant of such a system in Mathematica as well. Thanks, - dbm


title: Find $Y \in (0, 5)$ such that the roots of $4x^2 + 4xY + Y + 2 = 0$ are real?

text: The problem is to find all $Y \in (0, 5)$ such that the roots of $4x^2 + 4xY + Y + 2 = 0$ are real. I took a straightforward approach with Mathematica with the intent of listing the only solutions which are real. It's not quite giving me the output I expected, which is a listing of only real number solutions. What am I missing? The code               ϵ = 0.01;     a = 4;     f[y_] := -(4) (y) ± √(((4 y)^2 -              4 (a) (2 + y)))/(2 a);     Table[Element[f[x], Reals] , {x, 0, 5, ϵ}]      The output               Boole[0. ± (0. + 0.707107 I) ∈         Reals] (0. ± (0. + 0.707107 I)),      Boole[-0.04 ± (0. + 0.708855 I) ∈         Reals] (-0.04 ± (0. + 0.708855 I)),      Boole[-0.08 ± (0. + 0.710563 I) ∈         Reals] (-0.08 ± (0. + 0.710563 I)),      Boole[-0.12 ± (0. + 0.712232 I) ∈         Reals] (-0.12 ± (0. + 0.712232 I)),      Boole[-0.16 ± (0. + 0.713863 I) ∈         Reals] (-0.16 ± (0. + 0.713863 I)), <<492>>,      Boole[-19.88 ± 2.1054 ∈         Reals] (-19.88 ± 2.1054),      Boole[-19.92 ± 2.11071 ∈         Reals] (-19.92 ± 2.11071), ...      Also, is there a simpler way to solve this?


title: Preserve information in flattening a nested list

text: I have a series of lists in the form below:               list={ {1,1} , {2,2}, {3,{3,1},{3,2},{31,{31,1},{32,2}}} }      Its a nested list which the dimension is changing case to case. I want to manipulate the list to have an output like this:               LIST={{1,1},{2,2},{3,3,1},{3,3,2},{3,31,31,1},{3,31,32,2}}      I am trying to use this ReplaceList rule               list //. {a_, {b___}} :> {a, b}      But it is not working at all!! How should I make a list out of this nested list?


title: LinearProgramming errors

text: I have a family of equations I want to solve over the non-negative integers. One particular instance of it is this.               A = {{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},      {0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},      {0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},      {0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},      {0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},      {0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},      {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},      {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0},      {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0},      {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0},      {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0},      {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0},      {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0},      {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0},      {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1}}          b = {1, 2, 3, 1, 2, 2, 0, 1, 1, 0, 0, 0, 0, 0, 0}      I'd like to solve the problem $$ A.x = b,\quad x \in \mathbb{N}^{22} $$ So I call up `LinearProgramming` and ask               LinearProgramming[ Table[0, {22}], A, {#,0}& /@ b,                         Table[{0,Infinity}, {22}],Table[ Integers, {22}]]      The purported solution is               c = {1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}      which is not, actually, a solution of the problem. _Why does this happen?_ Why doesn't _Mathematica_ tell me that there is no solution?


title: Factor a Vector

text: Does there exist a function in Mathematica that simply takes out a common factor from a vector/list of expressions? This seems like such a simple operation that I am surprised that I could not find it in Google or the Mathematica help. It could return the common factor and the list without it:               Function[{a b c , b c, c d}] = {c,{a b, b, d}}      Or it could even simply return the common factor:               Function[{a b c , b c, c d}] = c      edit: sorry I was not completely clear. It would factor out algebraic expression too. So:               Function[{x^2 y, x}]      would yield:               {x,{x y, 1}}


title: Simulating CoordinatesToolOptions (for CDF) & the Inflexibility of MousePosition

text: I got two lists of equal lengths, which I show in two `ListPlot`s, arranged in a `Column` or `GraphicsColumn` (whatever works). When I mouse over any of the two `ListPlot`s, I want to show the y-values of both `ListPlot`s tooltip style right where the mouse is. I know how to do this using `CoordinatesToolOptions`; however, that's not an option, because it has to work in CDF, and it appears that the coordinate tool (pressing "." after having selected a graphic) does not work in CDF. So I'm trying to simulate this behavior with `Epilog`, `Text`, `MousePosition`, `Mouseover`; in what I tried, I find that the behavior of MousePosition is weird, which might be due to my lack of understanding. So first of all, here is the functionality I'd like to simulate.               With[{         top = 0.5 RandomReal[{0, 1}, 100] + Table[Sin[0.0628 i], {i, 100}],         bot = 0.5 RandomReal[{0, 1}, 100] + Table[Cos[0.0628 i], {i, 100}]     },     With[{ttDisplayFun = Function[pt,          Column[{             Row[{"top ", top[[Min[100, Max[1, Round[pt[[1]]]]]]]}],             Row[{"bot ", bot[[Min[100, Max[1, Round[pt[[1]]]]]]]}]         }]     ]},     With[{opts = {Joined -> True, ImageSize -> 400,          CoordinatesToolOptions -> {"DisplayFunction" -> ttDisplayFun}}},             Dynamic@Column[{ListPlot[top, opts], ListPlot[bot, opts]}]     ]]]      ![want](http://i.stack.imgur.com/JCW4U.jpg) Now, trying it without `CoordinatesToolOptions`, I got no problem displaying the desired tooltip underneath the two plots.               With[{         top = 0.5 RandomReal[{0, 1}, 100] + Table[Sin[0.0628 i], {i, 100}],         bot = 0.5 RandomReal[{0, 1}, 100] + Table[Cos[0.0628 i], {i, 100}]     },     Dynamic@Column[{         ListPlot[top, Joined -> True, ImageSize -> 400],         ListPlot[bot, Joined -> True, ImageSize -> 400],         With[{mouse = MousePosition[{"Graphics", Graphics}, {0, 0}]},             With[{mouseX = mouse[[1]], mouseY = mouse[[2]]}, Column[{                 "good: mouse coords are in units used in the plot",                 "y values of top and bot easy to retrieve",                 "bad: I want this displayed tooltip style wherever the mouse is",                 Row[{"mouseX: ", mouseX}],                 Row[{"mouseY: ", mouseY}],                 Row[{"top: ", top[[Min[100, Max[1, Round[mouseX]]]]]}],                 Row[{"bot: ", bot[[Min[100, Max[1, Round[mouseX]]]]]}]             }]]         ]     }]]      ![underneath](http://i.stack.imgur.com/99bJK.jpg) First thing I tried was to move the code into Epilog.               With[{         top = 0.5 RandomReal[{0, 1}, 100] + Table[Sin[0.0628 i], {i, 100}],         bot = 0.5 RandomReal[{0, 1}, 100] + Table[Cos[0.0628 i], {i, 100}]     },     Dynamic@Column[{         ListPlot[top, Joined -> True, ImageSize -> 400, Epilog -> With[             {mouse = MousePosition[{"Graphics", Graphics}, {99999, 99999}]},                 Text[Style[Framed[Column[{                     "I am Lazarus", "+++++++++",                     Row[{"top: ", top[[Min[100, Max[1, Round[mouse[[1]]]]]]]}],                     Row[{"bot: ", bot[[Min[100, Max[1, Round[mouse[[1]]]]]]]}]                 }]]                 , Background -> LightYellow, FontSize -> 16]                 , mouse, {-0.5, 1.4}]             ]],         ListPlot[bot, Joined -> True, ImageSize -> 400, Epilog -> With[             {mouse = MousePosition[{"Graphics", Graphics}, {99999, 99999}]},                 Text[Style[Framed[Column[{                     "I am Lazarus", "---------",                     Row[{"top: ", top[[Min[100, Max[1, Round[mouse[[1]]]]]]]}],                     Row[{"bot: ", bot[[Min[100, Max[1, Round[mouse[[1]]]]]]]}]                 }]]                 , Background -> LightYellow, FontSize -> 16]                 , mouse, {-0.5, 1.4}]             ]]         }]     ]      ![lazarus](http://i.stack.imgur.com/o7AiX.jpg) `MousePosition` will always return coordinates, when the mouse is over _one_ of the two `ListPlot`s; I'd rather have `MousePosition` only return something (other than the default), if the mouse is over that `ListPlot` in the `Epilog` of which I'm calling `MousePosition`. There obviously _should_ be a way to tell `MousePosition`, that one is interested _only_ in the coordinates, when the mouse is over _some specific_ graphic. Is there a way to do that? Anyway, my next attempt was to use `GraphicsColumn` instead of column, because that has an Epilog option, which `Column` doesn't. (I actually would prefer `Column`, since `GraphicsColumn` adds lightyears of superfluous white space.) But now it turns out that in the Epilog of `GraphicsColumn`, we're dealing with a whole new coordinate system. I'd like to refer to _any_ of the two coordinate systems of the two plots (don't matter which, since I need only the horizontal component, and that's the same for both.) So it's kind of the same problem as above; `MousePosition` appears to be inflexible. Am I missing something?               With[{         top = 0.5 RandomReal[{0, 1}, 100] + Table[Sin[0.0628 i], {i, 100}],         bot = 0.5 RandomReal[{0, 1}, 100] + Table[Cos[0.0628 i], {i, 100}]     },     Dynamic@Column[{         GraphicsColumn[{             ListPlot[top, Joined -> True, ImageSize -> 400],             ListPlot[bot, Joined -> True, ImageSize -> 400]         }         , Epilog -> With[             {mouse = MousePosition[{"Graphics", Graphics}, {99999, 99999}]},                 Text[Style[Framed[Column[{"wrong coordinate system", mouse}]]                 , Background -> LightYellow, FontSize -> 16], mouse, {-1, 2}]             ]]         }]     ]      ![wrong coordinate system](http://i.stack.imgur.com/k1amI.jpg) This post is getting too long, what I tried with Mouseover didn't work either. So ideally, what I'd want would be something like               MousePosition[<specific graphics object>,...]      or               If[CurrentGraphic[] == someGraphic, ...]      **update** Well, I answered my own question below, but I still have no clue whether or not the above things that I would wish one could do with `MouseCoordinates` are possible. Are they?


title: DynamicModule updating unexpectedly

text: I have cut down a DynamicModule that was updating unexpectedly and found the following behaviour I don' t understand. If I do this I get one random value as expected               Dynamic[      th = RandomReal[{-1, 1}];      th     ]      In this case I also get one value as expected               DynamicModule[{th},      Dynamic[ RandomReal[{-1, 1}]]     ]      However, in this case the value is updating continuously. I did not expect this.               DynamicModule[{th},      Dynamic[       th = RandomReal[{-1, 1}];       th      ]     ]      Why does it do this and how do I make it give me just one value? Edit Here is a fuller example to show what I am aiming for. The DynamicModule has two parts that are wrapped in Dynamic and information from the first (set up and calculation) must be shared with the second (graphics).               DynamicModule[{th, ft, rr = 1, f = 0.2345, m, c, x, res},      Column[{        Row[{Slider[Dynamic[rr], {0, 10}], " ran amp = ", Dynamic[rr]}],        Dynamic[         th = Table[            Cos[2 \[Pi] f (n - 1)] + RandomReal[{-rr, rr}], {n, 400}];         ft = Fourier[th, FourierParameters -> {-1, -1}];         res = FindFit[Abs[ft[[1 ;; 200]]], m x + c, {c, m}, x];         {m, c} /. res         ],        Dynamic[         ListPlot[Abs[ft[[1 ;; 200]]], PlotRange -> All,          ImageSize -> 5 72,           Epilog -> {Line[{{1, c}, {200, m 200 + c}} /. res]}]         ]        }]      ]


title: Implementing local variables of a recursive function with either Module or Block

text: First, some quick background: I have been eagerly learning Wolfram and Mathematica for two months now, and along the way have written about 250 pages of teaching material that has ballooned into a computer science book of sorts, available at http://www.scs.ryerson.ca/~ikokkari/Math/ The question I wanted to ask concerns the difference of Module and Block, specifically when used in recursion. I have googled the Wolfram documentation, StackExchange and other places where I have previously learned a bunch of stuff, but this is still not entirely clear. Suppose we try out the functional programming and list manipulation standard textbook exercise of implementing Flatten.               flatten[x_List] := Module[{result = {}},        Scan[(result = Join[result, flatten[#]]) &, x];        result        ];     flatten[x_] := List[x];      I get the correct results from this function when I try it out, so I assume that Module always creates new versions of its local symbols by tacking a dollar sign and a running number to the end of each symbol name. Despite the fact that the documentation says that Module uses lexical scoping, this seems to be done dynamically each time that the module is entered recursively, so the different levels of recursion end up having differently named local variables that cannot clash, the running tally of ModuleNumber increasing by one at each recursive call. Alternatively, we can use Block:               flattenblock[x_List] := Block[{result = {}},        Scan[(result = Join[result, flattenblock[#]]) &, x];        result        ];     flattenblock[x_] := List[x];      As I understood it, there now exists only one instance of the variable result that is shared by all levels of recursion, but each time the recursive Block is entered, its old value is pushed into an internal stack, from where it is popped the moment that the Block is exited, so the different levels of recursion again end up using separate values of the same variable. This is similar to the way that recursion is usually implemented in imperative stack- based languages. Question: outside advanced metaprogramming and staying within the realm of the recursion exercises traditionally seen in computer science textbooks, does there exist a simple situation where Module and Block, when used inside a recursively defined function that uses them to define a local variable that represents an intermediate result, would produce a different end result? Or are these two always pretty much equivalent, even with recursion?


title: Map of Specific US States? (Isolated)

text: My question here is fairly basic, and I'm sure I'm overlooking something basic. I know about `CountryData` for creating shapes of entire countries, and it works, to an extent; I can plot geographical data on it with the coordinates, but I'd like to have a magnified view of a state alone. The goal is to be able to measure borderlines. Is there built-in functionality for this, or do I have to import a shape file of a state?


title: SetOptions and Cell

text: I'm trying to change the CellLabel of Cells using                SetOptions[Cell, CellLabel -> "test"]      or                SetOptions[NotebookRead[nb], CellLabel -> "test"]      if nb is the notebook, without success. How should this be done? Thanks, once again, for all help!


title: preventing TraditionalForm from getting "squished"

text: `TraditionalForm[]` does a great job generally speaking, with complex equations like the following,               TraditionalForm[        Defer[          1/Pi =           2*Sum[((-1)^k*(6*k)!*(13591409 + 545140134*k))/((3*k)!*k!^3*640320^(3*k + 3/2)), {k, 0, 44}]        ]     ]      (which is to say…) ![pretty equation](http://i.stack.imgur.com/ExGzu.png) However, if I put this same equation in a `Grid[]` or `Table[]` or `Column[]`, it gets "squished," as in the following ![squished](http://i.stack.imgur.com/N3jTW.png) How can I prevent this from happening? I particularly want to prevent it from swinging the upper bound of the summation to the right of the sigma.


title: Any way to make my equations look better, more Latex like?

text: I find that the equations I write in Mathematica are not always publication quality. Here is a typical example: ![in-cell equation from a notebook](http://i.stack.imgur.com/1Lg93.png) If I copy as Latex, then I get the following code:               \frac{\sum _{i=1}^N \frac{(k|k) \tilde{x}_j^i}{\sqrt{P_{\text{jj}} (k|k)}}}{N}      This code is actually kind of messed up and does not reproduce the equation correctly, but it is easy to manually edit it to create the right Latex code:               \frac{1}{N}{\sum _{i=1}^N \frac{ \tilde{x}_j^i(k|k)}{\sqrt{P_{\text{jj}} (k|k)}}}      Now, if we render this Latex code we get a much nicer looking version of the same equation: ![Latex version of the same equation](http://i.stack.imgur.com/PAPBI.gif) The sigma looks better, variables are italicized, the vertical line (not sure what it is called) looks much better. The runt vertical line in Mathematica just looks really bad. Also, the coloring is removed, which for my purposes is better because I am including the equation in black and white text and do not want randomly colored symbols. My question is: how can I make the equation look better in the notebook? For example, if I am using Mathematica to make a slide show or presentation, I want the equation to look as professional as possible, but still be an editable cell. What are my options? Note that using TraditionalForm has the following consequences: ![TraditionForm of Summation](http://i.stack.imgur.com/JSHgM.jpg) _**Update_** If we really torture it with both Defer and HoldForm, looks like we can get the typeset equation: ![Typeset equation using TraditionalForm and HoldForm and Defer](http://i.stack.imgur.com/jGv2o.jpg)


title: Suppressing reduction in fraction box size in multi-level fractions

text: Mathematica display complex fractions like this, ![enter image description here](http://i.stack.imgur.com/usbtK.png) the second `x` look smaller, I want it look like this, how can I get it in Mathematica? ![enter image description here](http://i.stack.imgur.com/ffD9P.png)


title: Fractions formatting in Column / Grid

text: Fractions are squished in `GridBox`:               expr = Style["\!\(\*FractionBox[\(\[Alpha]\),\(360 \[Degree]\)]\)", Bold, 30];          {#, Column[{#}]} & @ expr      > ![enter image description here](http://i.stack.imgur.com/VQj5g.png) But we can fix this with `AllowScriptLevelChange -> False` as shown in linked topic.               {#, Column[{#}, AllowScriptLevelChange -> False]} &@expr      > ![enter image description here](http://i.stack.imgur.com/WQLnv.png) * * * **The problem is`GridBox` inherits this option** from outer `GridBoxes` **only when it is`True`**! Moreover even if I fix the inner option `AllowScriptLevelChange -> False` it will be overwritten by default `True` from outer one.               Grid[{{#, Column[{#}, AllowScriptLevelChange -> False]}}         ] &@expr      > ![enter image description here](http://i.stack.imgur.com/8zioi.png)               Grid[{{#, Column[{#}]}},           AllowScriptLevelChange -> False] &@expr      > ![enter image description here](http://i.stack.imgur.com/P37Dt.png) This behaviour is forcing me to manually put this option in each `GridBox`.               Grid[{{#, Column[{#}, AllowScriptLevelChange -> False]}},           AllowScriptLevelChange -> False] &@expr      > ![enter image description here](http://i.stack.imgur.com/ELPS4.png) ### IMO it is a bug.


title: Conditions in SparseArray

text: I got confused by `{i_, j_} /;` in the following code. I didn't see an explanation in the `SparseArray` documentation. Can anyone tell me how this part work in the code?               m1 = SparseArray[{{i_, i_} -> -2, {i_, j_} /; Abs[i - j] == 1 -> 1}, {5, 5}];


title: NDSolve boundary query / Extracting values from solution

text: I have a function $O_{2}$ with boundary conditions $O_{2}(r_{o}) = p_{o} $ and $O_{2}(g) = O_{2}'(g) = 0$. I plot it using the solver code below;               a = 5*10^-7;     po = 100;     omega = 3.0318*10^7;     ro = 5*10^-6;     Do2 = 2*10^-9;     ko = 1;     con = (a*omega)/(Do2);     g = 110*10^-6;          s = NDSolve[{D[r*O2'[r], r] - con*r*((O2[r])/(O2[r] + ko)) == 0,      O2'[g] == 0, O2[ro] == po}, O2, {r, ro, g},       Method -> {"Shooting", "StartingInitialConditions" -> {O2[g] == 0, O2'[g] == 0}}];          Af = Plot[Evaluate[{(O2[r]) /. s}], {r, ro, g}, PlotStyle -> {Red},        PlotLegends -> LineLegend[{"Solution"}]]      This produces the following solution; ![110 solution](http://i.stack.imgur.com/mnC5W.png) Now, we can see that at $g$, the solution doesn't reach zero. Let's choose a different $g$ - let's say $g = 130 \cdot 10^-6$ - then we get the solution; ![130 image](http://i.stack.imgur.com/DRUKe.png) Which does indeed seem to hit zero. I'm trying to find the approximate value of $g$ such that the initial conditions are satisfied and $O_{2}(g) = 0$ - So I have two questions; (1) Is there a automated method of doing this such that the "ideal" value of $g$ is found to satisfy the equation? (2) Is there a way I can get or extort the solution value at a point of my choosing? For example, is I want to find $O_{2}(g/2)$ or $O_{2}(g)$ , what would I have to enter it? I have, for example, tried               s[g/2]       and this merely tells me the solution is an interpolating function, not the specific value of it. All advice welcome, thanks in advance!


title: Plot failing when given a list of functions

text: I wrote a code which plots a Maclaurin expansion of cos(x) in various degrees.               f[x_] := Cos[x]     Animate[       Plot[Evaluate @ Normal[Series[f[x], {x, 0, s}]],{x, -10 Pi, 10 Pi},         PlotRange -> {-1, 1}],        {s, 0, 80, 2}]      This code works well. Next, I just added the original function to Plot, but it does not work.               f[x_] := Cos[x]     Animate[       Plot[{Evaluate @ Normal[Series[f[x], {x, 0, s}]], f[x]}, {x, -10 Pi, 10 Pi},         PlotRange -> {-1, 1}],        {s, 0, 80, 2}]      I found that just one function in the List style is also not work correctly.               Plot[{Evaluate @ Normal[Series[f[x], {x, 0, 20}]]}, {x, -10 Pi, 10 Pi},       PlotRange -> {-1, 1}]      What's wrong with what I am doing?


title: Creating a nested menu with OpenerView

text: I have a file with the following structure:               GAME     {         version = 0.23.5         linkURL =          Mode = 1         PARAMETERS         {             FLIGHT             {                 CanQuickSave = True                 CanQuickLoad = True             }         }         SCENARIO         {             name = ScenarioDiscoverableObjects             scene = 7, 8, 5              = 703987854             sizeCurve             {                 key = 0 0 1.5 1.5                 key = 0.3 0.45 0.875 0.875             }         }     }      I'd like to create a nested menu for easy visualization of the file's contents. I've managed to parse the file to the following structure:               data = {"GAME", {"version", "0.23.5"}, {"linkURL", ""}, {"Mode",        "1"}, {"PARAMETERS", {"FLIGHT", {"CanQuickSave",          "True"}, {"CanQuickLoad", "True"}}}, {"SCENARIO", {"name",         "ScenarioDiscoverableObjects"}, {"scene", "7, 8, 5"}, {"",         "703987854"}, {"sizeCurve", {"key", "0 0 1.5 1.5"}, {"key",          "0.3 0.45 0.875 0.875"}}}}      I then started to make the menu using `OpenerView`:               OpenerView[{First[#], Column[Rest[#]]}] &@data      However, I can't manage to apply this function over all levels of `data`. edit: Here's a screenshot of what I'm trying to achieve: ![menu screenshot](http://i.stack.imgur.com/sKVj4.png)


title: Can I change the font of all elements in my barchart with one property?

text: I have this BarChart: ![enter image description here](http://i.stack.imgur.com/reLXZ.png) created with this code:               sizes = {10718, 881, 395, 387, 375, 309, 297};     BarChart[sizes, ChartStyle -> 33, ImageSize -> 480, BarOrigin -> Left, ChartLabels ->        Placed[sizes, {{1, 0.25}, {0, 0}}, "  " <> ToString[#] <> " kB" &],      ChartLegends -> {"DelphiXE3", "Delphi2010", "Delphi2005", "Delphi7",        "Delphi6", "Delphi5", "Delphi4"}]      Now I want all of the text: ChartLabels, ChartLegends and tick labels in Helvetica. Can I do this with a single property, or do I have to add the property for each of the three elements separately? And how do I either?


title: Stretch Grid to fit width of containing object?

text: How can I stretch this Grid to the width of the encapsulating Panel (so that "right" floats on the right side? I want to achieve something along the lines of the menu at the top of the Documentation notebooks.               Panel[      Grid[       {{"left", "nextToLeft", "right"}},       Alignment -> {{Left, Left, Right}, Baseline}],      ImageSize -> Full]      Looks like this now: ![enter image description here](http://i.stack.imgur.com/xSyC5.png)


title: Custom default ImageSize while allowing inheriting

text: When displaying graphics in the Mathematica front end, and leaving `ImageSize` at the default, the result will always keep its previous size. For example,   * `Plot[Sin[x], {x, 0, 5}]` produces an output 360 pixels wide (the default size).   * Resize the plot with the mouse to make it bigger.   * Change the input to `Plot[Sin[x], {x, 0, 10}]` and re-evaluate it.   * The output figure remains at its manually set size and won't revert to 360 pixels wide. If we were to use `Plot[Sin[x], {x, 0, 5}, ImageSize -> 500]` instead, then the size of the output would be re-set to 500 pixels every time this command is re-evaluated. `ImageSize -> Inherited` will generally allow this behaviour. **Question:** How can I create a function that will output graphics at sizes larger than 360 pixels by default, yet when re-sizing the output manually and re-evaluating the function, the manually set size will be kept? I do not wish to change the default output size for other functions.


title: Getting unevaluated function expression

text: Say I've got a function `f[x_] := a x^2 + b*x + c;` and later set for some other reason `a=1;` how can I get the expression of f in an untouched form (with "a" and not "1")? I don't want to use `HoldForm` or `Unevaluated` in definition of `f` nor parse `Definition[f]`. **An example code that I'm trying to modify, so that it ignores evaluation of symbols in the first 2 StylePrints.**               SetAttributes[DD, HoldFirst];     DD[f_, var_] := HoldForm[\!\(\*SubscriptBox[\(\[PartialD]\), \(var\)]f\)];          SetAttributes[CSE, HoldFirst];     CSE[e_] :=        ToExpression[        If[StringFreeQ[ToString[HoldForm@e], "Subscript["],          "\[CapitalDelta]" <> ToString[HoldForm@e] <> "",          StringReplace[ToString[HoldForm@e],           "Subscript[" -> "Subscript[\[CapitalDelta]"]], TraditionalForm,         HoldForm];          SetAttributes[TDE, HoldFirst];     TDE[fun2_, vars2__] :=        Sqrt[Sum[i, {i, ((CSE[#] DD[fun2, #])^2) & /@ vars2}]];          SetAttributes[TotalDiffrentialError, HoldFirst];     TotalDiffrentialError[fun_, vars__] := Module[{Expanded},        StylePrint[CSE[fun] == TDE[fun, vars], "EquationNumbered"];        StylePrint[CSE[fun] == FullSimplify[ReleaseHold[TDE[fun, vars]]],          "EquationNumbered"];        FullSimplify[ReleaseHold[TDE[fun, vars]]]];      So what I'm trying to do with that is to print elegant equations without numerical values, up to a certain point when (in current implementation) I release all the Holds. This design would in theory let me to define values somewhere before and not bother about passing them to the function.


title: Putting set elements into venn diagram

text: My problem has two parts. Before that I have two Lists/Sets. It suppose to be created them by two initial strings. In the first part, I need to show sets' elements in venn diagram. I can create venn diagram with following code but it is not enough for my purpose. Also, I don't want to use internet.               WolframAlpha["(A \[Intersection] B)", {{"VennDiagram", 1}, "Content"}]      I don't need coloring though. On the other hand, A and B are two different sets. I need to show their elements in appropriate places. Here is an example image: ![enter image description here](http://i.stack.imgur.com/jMjHt.png) Second part, I should show this two sets ordered in column representation. If there are matching elements, arrows should point from appropriate element of A to appropriate element of B. Here is an example image: ![enter image description here](http://i.stack.imgur.com/nutB6.jpg) It is pretty challenging. Thanks everybody for their attention.


title: Optimising code for nested integrals

text: See below for some code I wrote to model a non-homogenous poisson process. The code generates the correct results but takes a long time due to the number of nested integrations. I have tried reducing plot points, have used `PerformanceGoal`, set `MaxRecursion` to `0` and set `WorkingPrecision` to `10`. Any tips? For those interested it is a model of information propagation on the _Bitcoin Network_.               ClearAll[ μ, q, k, prop]          μ := Log[1.76 + 0.066 q/2];     k = 1/600;     prop[q_] := 1.76 + 0.25 q/2;          ClearAll[inf, uninf]          inf[w_] := Evaluate[CDF[LogNormalDistribution[ μ, 0.944], w]];     uninf[x_] := 1 - Evaluate[CDF[LogNormalDistribution[ μ, 0.944], x]];          ClearAll[i1, i2, u1, u2, PDFi, PDFu, CDFi, CDFu, CDFui, CDFuu]          i1[z_?NumericQ] := i1[z] = inf[z]     i2[j_?NumericQ] := i2[j] = NIntegrate[i1[z], {z, 0, j}]     PDFi[z_?NumericQ] := PDFi[z] = k*i1[z] Exp[-k*i2[z]]     CDFi[j_?NumericQ] := CDFi[j] = NIntegrate[PDFi[z], {z, 0, j}]     u1[j_?NumericQ] := u1[j] = uninf[j]     u2[u_?NumericQ] := u2[u] = NIntegrate[u1[j], {j, 0, u}]     PDFu[j_?NumericQ] := PDFu[j] = k*u1[j] Exp[-k*u2[j]]     CDFu[u_?NumericQ] := CDFu[u] = NIntegrate[PDFu[j], {j, 0, u}]     CDFuu[u_?NumericQ] := CDFuu[u] = NIntegrate[u1[j]*PDFu[j], {j, 0, u}]     CDFui[j_?NumericQ] := CDFui[j] = NIntegrate[i1[z]*PDFu[z], {z, 0, j}]          ClearAll[Case1, Case2, Case3, Case2a, Case3a, Case2b, Case3b, Case3c, \     Case3d, Case3i, q]          Case1[q_] := Exp[-1/600*(prop[q])];     Case2a[q_?NumericQ] :=        Case2a[q] = NIntegrate[PDFu[j]*CDFi[j], {j, 0, prop[q]}];     Case2b[q_] := (1 - CDFu[prop[q]])*CDFi[prop[q]];     Case3a[q_?NumericQ] :=        Case3a[q] = NIntegrate[PDFi[j]*CDFuu[j], {j, 0, prop[q]}];     Case3b[q_?NumericQ] :=        Case3b[q] = NIntegrate[PDFi[j]*CDFui[j], {j, 0, prop[q]}];     Case3c[q_] := (1 - CDFi[prop[q]])*CDFuu[prop[q]];     Case3d[q_] := (1 - CDFi[prop[q]])*CDFui[prop[q]];          Case2[q_] := Case2a[q] + Case2b[q]     Case3[q_] := Case3a[q] + Case3b[q] + Case3c[q] + Case3d[q]     Case3i[q_] := Case3b[q] + Case3d[q]     Case3u[q_] := Case3a[q] + Case3b[q]


title: when using FileDate----The Creation date of a file is not available on Macintosh and Unix?

text: when I use               FileDate[filename,"Creation"]      it gives messages like > FileDate::nocreationunix: The Creation date of a file is not available on > Macintosh and Unix. >> > > FileDate::nocreationunix: The Creation date of a file is not available on > Macintosh and Unix. >> > > FileDate::nocreationunix: The Creation date of a file is not available on > Macintosh and Unix. >> Why? **Edit** I forgot to say my OS. My OS is Linux. As george2079 said, Linux don't have creation date. But I found `FileDate[filename,"Change"]` works like "Creation" in windows system.


title: Calculate max value

text: # Update Using               Manipulate[Plot[{(LogIntegral[x])^(1/2),      (((x*E^s)/Log[x*E^s]) ((((Log[Log[x*E^s]])^(w - 1))/((w - 1)!))))/     RiemannR[x]}, {x, 2, 5000}, PlotStyle -> {Blue,Red}, ImageSize -> 700],      {w, 33.34, 40, 0.01}, {s, 43.2, 50, 0.01}]      to play with the plot ![enter image description here](http://i.stack.imgur.com/rleKB.gif) I am trying to find the max values of `w` and `s` **_where the $y$-value of the red curve is at no point greater in value that of the blue curve (for any $x$)_**. Is there a better way of doing this? (I have started `w` and `s` at a reasonable estimate, but when values become much higher than $1000$, manipulation is not really feasible.) N.B. My best guess so far at the relationship between `s` and `w` is `s=[N[Log[((w/5) + 1)!]]`, but this is clearly way off. # Original question Which approach would be the best to take in order to calculate the max value of $a$, where $a\log(x+1)$ at no point exceeds $\sqrt{x}$?               Plot[{a Log[x + 1], Sqrt[x]}, {x, 0, 100}, PlotStyle -> {Blue, Red}]      ![enter image description here](http://i.stack.imgur.com/IxC0x.gif) I have tried using `Manipulate` to get a rough guess, but I am really searching for a more accurate approach.


title: ListDensityPlot

text: In _Mathematica_ help it's written that: > `ListDensityPlot[array]` -> generates a smooth density plot from an `array` > of values. There is also an example:                ListDensityPlot[{{1, 1, 1, 1}, {1, 2, 1, 2}, {1, 1, 3, 1}, {1, 2, 1, 4}}, Mesh -> All]      ![enter image description here](http://i.stack.imgur.com/Mhmmk.jpg) I understand when the input is in the form of $ \{ x, y, f(x,y)\}$, what this function does. But, I really cannot understand what this function does when it has an array as an input.


title: error message DSolve::"bvnul"

text: DSolve[{2 y[x] y''[x] == y'[x]^2 + y[x]^2, y[0] == 1, y'[0] == -1}, y[x], x]          DSolve::"bvnul" For some branches of the general solution, the given      boundary conditions lead to an empty solution "      It is no solution.But we can check that E^-x is a solution.               2 E^-x D[E^-x, {x, 2}] == D[E^-x, x]^2 + (E^-x)^2     ("True")      But if we write code like this,it has a solution.               sol = DSolve[{2 y[x] y''[x] == y'[x]^2 + y[x]^2, y[0] == a, y'[0] == b}, y[x], x]     sol /. {a -> 1, b -> -1}      1.Whats the mean of "For some branches of the general solution"? 2.How to explain this phenomenon?


title: Why is this parallel evaluation with Dispatch[] so slow?

text: Can you efficiently parallelize this? The parallel versions are much slower than the sequential version, and I'm not sure why. Does `SetSharedVariable` allow simultaneous reads for different kernels? It appears that it doesn't even though the documentation says you should use `CriticalSection` to make separate reads and writes atomic and thread-safe.               dispatch = Dispatch@Table[i -> RandomReal[1, 500], {i, 20000}];          Map[Select[# /. dispatch, # < .1 &] &,       RandomInteger[{1, 20000}, 10000]] (* < 3 secs *)          ParallelMap[Select[# /. dispatch, # < .1 &] &,       RandomInteger[{1, 20000}, 10000]] (* 50 secs *)          SetSharedVariable[dispatch]; ParallelMap[      Select[# /. dispatch, # < .1 &] &, RandomInteger[{1, 20000}, 10000],       DistributedContexts -> None] (* longer than 2 minutes *)


title: Why does the iterator index in Table not work here?

text: I type the following command line               Table[D[#1,varx[[i]]] &,{i,3}]      where `varx` is a vector of dummy variables               varx = {x1, x2, x3}      According to this link NonCommutativeMultiply, I want to obtain a vector like this > $\left\{\frac{\partial }{\partial \text{x1}},\frac{\partial}{\partial > \text{x2}},\frac{\partial}{\partial \text{x3}}\right\}$ But I got this > ![enter image description here](http://i.stack.imgur.com/U2QMV.png) It seems like the index `i` in the command `Table` does not work. I don't know why this happens. I try not to use the placeholder '#1' like this               Table[D[2 x1^2 + 4 x2^3 + x3^4, varb[[i]]], {i, n}]      And this works all fine               {4 x1, 12 x2^2, 4 x3^3}      If I want to keep the placeholder, what should I do?


title: Optimizing my code to generate symmetric tensors

text: I have written code that does carries out the following **task** : Construct a fully symmetric rank-$P$ "tensor" out of a collection of user- input rank-1 vectors, and a rank-2 symmetric tensor $h$. The number of times each vector is to be repeated, and the indices of the final rank-$P$ tensor are user-input. **Example #1:** _Three vectors, three indices_ -- Given input vectors $u$ repeated once, $v$ repeated twice, and indices {$a,b,c$}, the output should be the symmetric tensor: $$u_a v_b v_c + u_b v_a v_c + u_c v_a v_b$$ **Example #2:** _Two vectors, four indices_ -- This time, take input vector $u$ repeated twice, but with four indices {$a,b,c,d$}. Since there are two excess indices, they must be assigned to $h$. The output: $$u_a u_b h_{c d}+u_a u_c h_{b d}+u_a u_d h_{b c}+u_b u_c h_{a d}+u_b u_d h_{a c}+u_c u_d h_{a b}$$ **Note** : User must input such that number of excess indices must be _even_ , and can never be less than the number of rank-1 tensors. My code here as follows, starting with definitions and input:               (*Tells engine that \[DoubleStruckH] is symmetric *)     Clear[\[DoubleStruckH]];     Subscript[\[DoubleStruckH], i_, j_] ^:= Subscript[\[DoubleStruckH], j, i] /; ! OrderedQ[{i, j}];      Here are the input variables:               (*Example 1*)     sym = {u, v};  (*symbols of rank-1 vectors*)     n = {1, 2};    (*repetition: u once, v twice*)     indices = {a, b, c};   (*Indices of rank-3 tensor.*)          (*Example 2*)     sym = {u};     (*symbols of rank-1 vectors*)     n = {2};       (*repetition: u twice*)     indices = {a, b, c, d};   (*Indices of rank-4 tensor.*)      Useful definitions:               P = Length[indices];  (*rank of final tensor*)     r = (P - Total[n])/2; (*number of \[DoubleStruckH] in tensor*)      So now my clumsy code: strategy is to begin with one-representative term of the symmetric tensor (which needs some help).               representative = Apply[Function[#,      Product[1/        n[[j]]! Product[Subscript[         sym[[j]], #[[i]]], {i, 1 + Sum[n[[k]], {k, 1, j - 1}],           Sum[n[[k]], {k, 1, j}]}], {j, 1, Length[sym]}]*1/(r! 2^r)       Product[       Subscript[\[DoubleStruckH], #[[i]], #[[i + 1]]], {i,         Total[n] + 1, P, 2}]] &, {Table[Unique[], {P}]}]      In the case of `(*Example 1*)`, the output of `representative` is: ![Output of representative](http://i.stack.imgur.com/4zbQv.png) I know I need help here, since `representative` is supposed to be a pure function, with the arguments being the slots where the indices go. But the output of this reveals that it doesn't fully evaluate the products. Anyway, carrying on. Now all I need is to add up all possible permutations:               answer = Plus @@ With[{func = representative}, Map[Apply[func, #] &, Permutations[indices]]]      ![enter image description here](http://i.stack.imgur.com/j0TNZ.png) It works, but it slow for large ($P\gtrsim 6$) tensors. The two places where I need help is:   1. I need to make this work somewhat quickly for large tensors (with 6 or 8 indices). Clearly the code does more work than it needs to because of the factorials that I use in `representative` to divide out extra terms.   2. My `representative` function needs help, too (see above).


title: RowReduce : Record of all the row operations for RREF

text: I read "for what right-hand sides $b=(a,b,c)$ does $Ax=b$ have a solution", but that question pertains to solving for the unknown vector. I'd like a record of all of the row operations required to put a matrix in reduced row echelon form without LU Decomposition. When I input `RowReduce[{{3, 1, a}, {2, 1, b}}]`, Mathematica returns:   `{{1, 0, a - b}, {0, 1, -2 a + 3 b}}` Howbeit, when I input RowReduce[{{1, 2, r_1}, {2, 3, r_2}, {2, 4, r_3}, {2, 5, r_4}}], Mathematica doesn't manifest explicitly the resource vector $(r_1, r_2, r_3, r_4)$ in :   `{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}, {0, 0, 0}}` ?   How can I oblige it to, whenever matrices are input and not only for this one?


title: Construct an infinte matrix with finite sub-matrices

text: How can I construct an infinite matrix with finite sub-matrices of the form               A = (B0,  0, B1           0, B2,  0           0,  0, B3)      where each Bi is a rectangular or a square matrix?


title: Color Blend in BezierCurve

text: How can I color a `BezierCurve` from `Red` into `Green` just as `Line` does?               pts={{0,0},{1,1},{2,0}};     Graphics[{Thick,BezierCurve[pts],Line[{{0,0},{2,0}},VertexColors->{Red,Green}]}]      ![spLine](http://i.stack.imgur.com/ChnKo.png)


title: Using quantifiers with free indices as declarative conditions in equation solving

text: This is a toy example: Is there a way to rewrite               Reduce[{Norm@{c[1], c[2], c[3]} == 1,               0 <= c[1] &&                c[1] < c[2] < c[3]},             {c[1], c[2], c[3]}]      As something like               Reduce[{Norm@{c[1], c[2], c[3]} == 1,               0 <= c[1] &&                ForAll[{i,j}, Implies[i<j, c[i] < c[j]]]},            {c[1], c[2], c[3]}]      ?   (Which of course doesn't work)


title: How to keep the ctrl+shift+k help menu remain in display while typing?

text: In Mathematica 9, one can type `ctrl+shift+k` to display menu which has all the possible signatures/definitions for the function or command in question. One can select one of those, which is pasted in place, Then the menu disappears right after that. ![enter image description here](http://i.stack.imgur.com/U9Oyj.png) That is all fine. But what I really prefer, is to have the menu remain in display, while writing the rest, either myself or even if the fill-in was selected. I like to keep looking at the small menu for reference, since it has information in it that helps while writing the rest of the function call, also, it is possible one might decide to change which one of those signatures to actually use while typing, and it would be easy to do that if the menu is still up there for reference on the other signatures. What happens now is that once one starts typing, the menu goes away, and one loses the reference that was there to look it. Is there a way to keep this menu in place while typing, then use some other special key to close it? That would be really useful. i.e. I like something like this: ![enter image description here](http://i.stack.imgur.com/FPqTH.png) **Is there a way to keep this menu up and close it when I choose using another short-cut key?** Version 9.01 on windows 7.


title: Dataset: cannot reproduce a basic example. A bug?

text: Just to report: I try to reproduce the very first example for the `Dataset` from the Documentation Center:                   dataset = Dataset[{        <|"a" -> 1, "b" -> "x", "c" -> {1}|>,        <|"a" -> 2, "b" -> "y", "c" -> {2, 3}|>,        <|"a" -> 3, "b" -> "z", "c" -> {3}|>,        <|"a" -> 4, "b" -> "x", "c" -> {4, 5}|>,        <|"a" -> 5, "b" -> "y", "c" -> {5, 6, 7}|>,        <|"a" -> 6, "b" -> "z", "c" -> {}|>}]      The message error reads: An unknown box name (TypeSystem`TypeMap) was sent as the BoxForm for the expression. Check the format rules for the expression.


title: How to restore default seed generation in SeedRandom[] when specifying method?

text: I want to generate low-discrepancy sequences and for that purpose I use `SeedRandom[]`, like:               BlockRandom[        SeedRandom[(* ..., *) Method -> {"MKL", Method -> {"Sobol", "Dimenstion"->2}}];     RandomReal[1,10]]      The problem is that `RandomReal[]` returns the same sequence always as if I set the seed to some fixed number. My **question** is: what should I put as argument to `SeedRandom[]` in order to restore the default behaviour or how could I change the method without affecting the way the generator is seeded ? **EDIT** : One work-around would be to calculate a bunch of seeds with, say, `seeds = RandomInteger[2^32]` before calling `SeedRandom[]` for the 1st time and subsequently feed them to the latter.


title: Possibility of evaluating the expression within a NestList at each iteration?

text: I want to rotate iteratively a triangle about the same point, increasing for each iteration the length of its side in the same proportion and change the color of its sides.   I came up with the solution below:               triangle[x_] :=      Line[ {{0, 0}, {1 + x, 0}, {(1 + x)/2, (Sqrt[3] (1 + x)/2)}, {0, 0}}]     randomcolor[] := Apply[RGBColor, RandomReal[1, {3}]]     Show[Array[Graphics[Rotate[{Thick, randomcolor[], triangle[#]}, # (Pi/5), {0,        0}]] &, 3]]       (* a simple output *)     Show[Array[Graphics[Rotate[{Thick, randomcolor[], triangle[#]}, # (Pi/9), {0,        0}]] &, 180]]   (* more elaborated *)      There are certainly other and better ways to achieve this result. However my first attempt for my solution was to use NestList which I felt to be more suitable but could not proceed further than this line:               rot[gr_] := Rotate[gr, Pi/16, {0, 0}]     Graphics[{NestList[rot, triangle[#], #]}] & [2]      The same figure is repeated which is as expected there but is there any way at the start of each iteration to re-evaluate the value of the function triangle[#] with the current value of the Nestlist iterator?


title: Aborting a computation correctly in .NETLink to allow future computations

text: Has anyone had any success using the `AbortEvaluation()` function in `IKernelLink` to stop a computation and then do more computation and retrieve results?   I've managed to find the jlink sample and some description on how to set it up; Put`Evaluate` and `WaitForAnswer()` on one thread, and call `AbortEvaluation()` from another. The following is a sample code that I'm written according to the description:                       var mlink = MathLinkFactory.CreateKernelLink();             var t = Task.Factory.StartNew(                 () =>                 {                     mlink.Evaluate("Do[2+2, {200000000}]");                     Debug.WriteLine("Waiting for Result...");                     mlink.WaitForAnswer();                 }             );                  Thread.Sleep(200);             Task.Factory.StartNew(                 () =>                 {                     Stopwatch st = new Stopwatch();                     st.Start();                     while (!t.IsCompleted)                     {                         if (st.ElapsedMilliseconds > 100)                         {                             mlink.AbortEvaluation();                             Debug.WriteLine("Action Aborted");                             break;                         }                     }                     st.Stop();                 }             );                  Task.WaitAll(new Task[] {t});                  Debug.WriteLine("Result = " + mlink.GetString());             mlink.Evaluate("1 + 1");             mlink.WaitForAnswer();             Debug.WriteLine("1 + 1 = " + mlink.GetString());             mlink.Evaluate("2 + 2");             mlink.WaitForAnswer();             Debug.WriteLine("2 + 2 = " + mlink.GetString());             mlink.Evaluate("4 + 4");             mlink.WaitForAnswer();             Debug.WriteLine("4 + 4 = " + mlink.GetString());             mlink.Close();      Output is: Waiting for Result..., Action Aborted, Result = In[1]:= , 1 + 1 = Null, 2 + 2 = 2, 4 + 4 = 4 I've tried the class `MathKernel` as well which results in the same problem where the results are shifted off (considering the implementation of `MathKernel` uses `IKernelLink` this is to be expected). Several other attempts has resulted in MLGet out of sequence errors or attempt to read protected memory. * * * EDIT: Nevermind, I forgot to discard the initial packet. Simply add the line `mlink.WaitAndDiscard()` at after `CreateKernelLink();` for it to work. MathKernel abort works as well. Trick appears to be launching them in two separate threads.


title: find derivative with defined function

text: s[a_, b_] := NDSolve[{y''[x] == y[x] Cos[x + y[x]], y[0] == a, y'[0] == 1}, y, {x,0, b}]      I need to find the minimal of $\int _1^by[x]^2$ in the region $-1<a<1$ and $b>1$, and express $a$ in terms of $b$, what I am doing is like:               w[a_,b_]:=First[NIntegrate[Evaluate[y[x]^2 /. s[a, b]], {x, 0, b}]]     j[a_,b_]:=D[w[a,b],a]     h[b_]:=a/.FindRoot[j[a,b]==0,{a,0}]      I am too naive, does anyone have any idea? thanks AS Michael E2 suggests using ND, so instead of               j[a_,b_]:=D[w[a,b],a]      I change it as:               j[d_,b_]:=ND[w[a,b],{a,1},d]      but when I enter j[1,1] as a check, I receive a warning instead of the a number. So I tried b.gatessucks's suggestion, using NMinimize,                   w[b_]:=NMinimize[NIntegrate[Evaluate[y[x]^2 /. s[a, b]], {x, 0, b}],{a}]      Unfortunately, w[1] does not give a number. Anyway, thanks for your help. and thanks ruebenko


title: How can I produce multiple column data for export?

text: I have data produced by the following code:               u2 := y^2 + ϕ + 1          ϕ = 0.1;                      aa1 = Table[{y,u2}, {y, -1.2, 1.2, 0.05}]          ϕ = 0.15;                                             aa2 = Table[u2, {y, -1.2, 1.2, 0.05}]          ϕ = 0.20;                                               aa3 = Table[u2, {y, -1.2, 1.2, 0.05}]      I want to save this data in a single file like this               y      u2 (output form aa1)        u2 (output form aa2)        u2 (output form aa3)     -1.2      2                           3                           4     -1        3                           4                           3      0        2                           2                           2      The full code can be found here How to export data from listplot?


title: Ugly plots when printing notebook to pdf

text: One image is worth one thousand words, so: ![enter image description here](http://i.stack.imgur.com/btK7J.png) **Question** : At what options should I be looking, so that what I see in my notebook is what I get in my printed pdf ? Here is the code I'm using:               deq = x''[t] == x[t] - x[t]^3 + x[t]^2 + a Cos[t];          genPoincareMapPoints[deq_] :=       Module[{},         Reap[          NDSolve[{deq,            WhenEvent[             Mod[t, 2 \[Pi]] == 0,             Sow[{x[t], x'[t]}]]            }, {}, {t, 0, 5 10^4},           AccuracyGoal -> 10, PrecisionGoal -> 10,            MaxSteps -> ∞]]][[-1, 1]];          Style[      Grid@{        Parallelize[         ListPlot[            genPoincareMapPoints[             {deq /. a -> #, x[0] == 0, x'[0] == 0.0}],            AxesLabel -> {"x[t]", "x'[t]"},            PlotRange -> All,             PlotLabel -> "Poincare Map for a=" <> ToString@#,            PlotStyle -> AbsolutePointSize[0.5]] &          /@ {0.03, 0.3, 3}]        }, ImageSizeMultipliers -> 1]      **EDIT** : Mac OSX 10.9, Mathematica 9.0.1. I am printing with 'File -> Print... -> PDF -> Save as PDF...'. I'm viewing the PDF with 'Preview' app of Mac OSX.


title: How can I set the speed of manipulate play button?

text: Can you set the speed at which a `Manipulate` plays when the play button is clicked?


title: Use TraditionalForm (or something similar) in AxesLabel/PlotLegends

text: I use the following command to export plots to PDF which I then use in latex:               plot = Plot[x^2, {x, -2, 2}, AxesLabel -> {x, x^2},             PlotLegends -> {"Function f(x) = x^2"}]     Export[NotebookDirectory[] <> "SimplePlot.pdf", plot]      ![enter image description here](http://i.stack.imgur.com/XJk4R.png) Now the "problem" is that the font of $x$, $x^2$ and $f(x)=x^2$ is not at all similar to the standard font of latex. I found that the command `TraditionalForm` produces output with a font that seems to fit latex much better: ![enter image description here](http://i.stack.imgur.com/PCsuS.png) But simply putting `AxesLabel -> {TraditionalForm[x], TraditionalForm[x^2]}` for example does not change the plot's font. So how can I change the font in my plot to the one that `TraditionalForm` offers? And no, I do not want to change the font in latex. ;)


title: statistical database calculation

text: Assume a database with 10,000 elements of data is queried, through a statistical interface, for the average data value. The response is determined using the random-sample query method, with a subset of 500 elements being used. Assuming you had access to all data elements, how could you determine what the least accurate response could be?


title: Memory running out generating ContourPlot3D

text: The code below               BanchoffChmutov[n_] := ContourPlot3D[ ChebyshevT[n,x]+ChebyshevT[n,y]+ChebyshevT[n,z], {x,-1.3,1.3},{y,-1.3,1.3},{z,-1.3,1.3}, Contours->0.02, AspectRatio->Automatic, Boxed->False, Axes->{False,False,False}, BoxRatios->Automatic, PlotRangePadding->None, PlotPoints->100, ViewPoint->{-2,3,3}];     pic = BanchoffChmutov[10]     Export["C:\\Z10.png", pic, ImageResolution->100, ImageSize->1000, Background->None];      runs fine when 10 is replaced by any of 1,...,9, but it produces an error for 10 and up: > No more memory available. Mathematica kernel has shut down. Try quitting > other applications and then retry. I've stopped almost all other applications, but still it doesn't produce an image. How can I tell my Mathematica to increase the amount of memory associated to this computation, and also, to calculate longer if necessary, and not just quit. I have 3.24GM of RAM and 3GHz of CPU.


title: Plotting bipartite graph from adjacency matrix

text: I have an $m\times n$ matrix $A$ representing the adjacencies between the nodes of a bipartite graph. Specifically, the nodes are arranged in two partitions, of $m$ and $n$ nodes respectively, such that $A_{ij}\ne 0$ if and only if there is an edge between nodes $i$ and $j$. Moreover, if $A_{ij}\ne 0$, I would like to display the number $A_{ij}$ next to the edge connecting $i,j$. The nodes from the two partitions should have distinct colors, so I can differentiate the partitions. What I have managed to do thus far is to display the graph, by constructing an $(m+n)\times (m+n)$ block matrix: $$\left(\begin{array}{cc} 0 & A\\ A^{T} & 0 \end{array}\right)$$ and passing it as argument to `AdjacencyGraph`. Explicitly, this is my code so far:               MatToGraph[mat_?MatrixQ] :=       ArrayFlatten[{{0, mat}, {Transpose[mat], 0}}] /. _?(# != 0 &) -> 1 //        AdjacencyGraph


title: How to export notebook in colored PDF form

text: > **Possible Duplicate:**   >  Saving a notebook as PDF, preserving syntax highlighting I would like to export my notebook code in a colored PDF form. What I do is select the brace in the right side of the lines I'd like to export and then from "File->Save Selection As" I export it as pdf. The thing is that there aren't any colors. ![](http://i.imgur.com/QA8vq.png) Is there a way to export in PDF while adopting all colors? * * * **EDIT:** I also tried "Print Selection" instead of "Save selection As" but I faced to problems: The is a lot of empty space, which means that I will not be able to include it in my tex code and secondly there aren't any colors in my input code, while the output graphic really adopts color. My output is ![Mathematica graphics](http://i.stack.imgur.com/7tCzX.png) * * *


title: Selecting a sublist based on Length

text: If you have a simple list of lists as follows:               test = {{1, 2}, {4, 5, 6, 7}, {5, 4, 3}}      How do you ask _Mathematica_ to return the sublist of greatest length? I've been trying to write a `Select` command using pure functions without success.


title: Parametric regions

text: I'm trying to plot $a x^2 + b x + c$ where $a, b, c$ (and $x$) take on a range of values. I tried               ParametricPlot[{x, a x^2 + b x + c}, {x, -1, 1},                    {a, -.25, .25}, {b, -.25, .25}, {c, -.25, .25}]      but `ParametricPlot` can only handle up to two parameters. My work around uses `FindInstance` which can be really slow:               RangePlot[eq_Equal, {x_, xmin_, xmax_}, {y_, ymin_, ymax_}, vars_List, constraints_] :=          RegionPlot[             FindInstance[And[constraints, eq], vars] =!= {}, {x, xmin, xmax}, {y, ymin, ymax}         ]          RangePlot[y == a x^2 + b x + c, {x, -1, 1}, {y, -1, 1}, {a, b, c},          -.25 < a < .25 && -.25 < b < .25 && -.25 < c < .25]      ![result of RangePlot\[\]](http://i.stack.imgur.com/62yng.png) Is there a better way to do this?


title: Strange filling

text: I observed some strange behaviour when plotting a function with filling. **The code** is as follows:               fx[x_] := 1/(Exp[-x - 7] + 1) + 1/(Exp[x - 7] + 1) - 3/2          blue = RGBColor[17.6/100, 41.6/100, 63.1/100];     yellow = RGBColor[96.9/100, 68.6/100, 20.8/100];          u10 = Plot[fx[x], {x, -15, 15}, PlotRange -> All, AxesLabel -> {"x", "fx(x)"}, PlotStyle -> Directive[Dashed, AbsoluteThickness[0.5], blue], Filling -> {1 -> {Axis, {Directive[Opacity[0.75], yellow], Directive[Opacity[0.5], yellow]}}}]          u11 = Show[u10, Frame -> False, Axes -> True,  AxesStyle -> Directive[AbsoluteThickness[0.3], 6, FontFamily -> "Helvetica"], ImageSize -> 120, TicksStyle -> Directive[AbsoluteThickness[0.3], 5, FontFamily -> "Helvetica"]]          Export[FileNameJoin[{HomeDirectory[],"u11.pdf"}], u11]      The problem with generated image is that only leftmost filling area is properly rendered. The central and the rightmost areas **go slightly beyond the borders**. The mismatch is not large, around one line-width, but visible. I attach below the generated image converted from pdf to png with 1200pt resolution. ![1200ptx800pt](http://i.stack.imgur.com/mNZ67.png) **Notice** This is not an artefact of pdf viewers: Adobe Acrobat 8 Professional, Adobe Reader X (Windows); Preview, Adobe Illustrator CS6, Adobe Acrobat 10.1.9 (Mac) consistently produce the same picture. Preview generates some more artefacts, however, it is not important in this context. The problem seems to be specific for Mathematica 9.0.1 for Mac and Win 7 (64 bit). I can confirm that the problem does not arise for Mathematica 6.0.1 for Win XP. Other users indicate proper rendering with versions 7 and 8. **Details** The effect does not depend on the line-style (full, dotted, etc.), on the opacity, plot-type (frame vs axes, list plot vs. plot). Reducing the line- width reduces the undesired effect, however, it is not an option for me (as explained in this post). I would appreciate any suggestions on how to fix the problem.


title: How to customize derivative behavior via upvalues?

text: I'm having trouble getting customized derivatives (defined using upvalues) to behave in sane ways. By this I mean that I'd like to define a derivative using an upvalue and then have Mathematica apply all derivative rules it normally would, delegating to the upvalues when appropriate. For example.               X /: D[X[x_], y_] := A KroneckerDelta[x,y]     Y /: D[Y[x_], y_] := B KroneckerDelta[x,y]     D[X[x], x]        (* Gives the Expected Answer:  A *)     D[X[x] + Y[x], x] (* Desired Output:   A + B  *)     D[X[x] Y[x], x]   (* Desired Output:   A Y[x] + X[x] B   *)      For the latter two, I get `X'[x] + Y'[x]` and `Y[x] X'[x] + X[x] Y'[x]`. I'm not understanding why the upvalues aren't kicking in. A similar question was asked here, but I couldn't adjust it for my problem. **Update:** It looks like I didn't specify my problem in enough detail. To give a better sense of the direction I'm looking, see this question. My (present) understanding of `Derivative` suggests it cannot achieve what I want since the arguments to my functions are abstract indices (e.g. multiple arguments are implicit). Consider a (discrete) joint probability $p_{XY}(i,j)$ where $i$ and $j$ are indexes (with unspecified ranges) that represent the possible values. Now, consider a marginal distribution $p_X(i) = \sum_j p_{XY}(i,j)$. Each $p_X(i)$ depends on all of the $p_{XY}(j,k)$ with $j = i$. I was hoping to declare the derivatives of $p_{XY}(i,j)$ and $p_X(i)$ with respect to $p_{XY}(k,l)$ (treating each $p_{XY}(i,j)$ as independent variables). Then, I wanted to be able to differentiate any generic expression involving those functions. Mathematically, this is the behavior: $$ \frac{\partial p_{XY}(i,j)}{\partial p_{XY}(k,l)} = \delta_{ij} \delta_{jk} \qquad\qquad \frac{\partial p_X(i)}{\partial p_{XY}(k,l)} = \delta_{ik} $$ Here is a toy expression I'd like to differentiate: $$\frac{\partial}{\partial p_{XY}(k,l)} \left[ p_{XY}(i,j) p_X(i)^2 \right] = \delta_{ik} \delta_{jl}\, p_X(i)^2 + 2 p_{XY}(i,j)\, p_X(i) \, \delta_{ik} $$ The above is just an application of the product rule, so it's pretty straight- forward to do these calculations by hand, once the derivatives of the primitives are specified. However, I don't want to re-specify all the rules of differentiation. Somehow I'd like to tell Mathematica to use its own system, while incorporating my primitives. Things I've tried...               pXY /: D[pXY[i_, j_], pXY[k_, l_]] := Simplify[KroneckerDelta[i, k] KroneckerDelta[j, l]]     pX /: D[pX[i_], pXY[j_, k_]] := KroneckerDelta[i, j]     D[pXY[i, j] pX[i]^2, pXY[k, l]]   (* Undesirably returns 0 *)      I think I understand why (via pattern matching) this gives 0. Another attempt:               pXY /: D[pXY[i_, j_], pXY[k_, l_]] := Simplify[KroneckerDelta[i, k] KroneckerDelta[j, l]]     pX[i_] := MySumX[pXY[i, j], {i, j}]     MySum /: D[MySum[s_, {i_, j_}], pXY[k_, l_]] := D[s /. {i -> k, j -> l}, pXY[k, l]]     MySumX /: D[MySumX[s_, {i_, j_}], pXY[k_, l_]] := D[s /. {i -> k}, pXY[k, l]]          D[pX[i], pXY[i, k]]  (* Result is correct *)     D[pXY[i, j] + pX[i], pXY[k, l]] (* Result is not correct *)      Hopefully its clearer now how the original question relates to what I'm truly after. Just to keep it fun, here is another expression I'd like to differentiate: $$ \frac{\partial}{\partial p_{XY}(k,l)} \sum_{i,j} p_{XY}(i,j)\log \frac{ p_{XY}(i,j)}{p_X(i) p_Y(j)}$$


title: Color ramp banding in PDFKit when exporting Raster image Inset to PDF

text: Here I produce a `Raster` image with large uniformly colored rectangles and put it in an `Inset`:               With[{n = 5},      Graphics[Inset[        Graphics[Raster[          {Map[            List @@ ColorConvert[ColorData["LakeColors"][#],                RGBColor] &, (Range[n - 1] - 1)/(n - 2)]}          ]],        Automatic, Automatic, {.45, .5}        ]       ]      ]      ![Raster](http://i.stack.imgur.com/8Xe5C.png) Now export this to `PDF`:               Export["p.pdf", %]      ![ramp artefacts](http://i.stack.imgur.com/chkrn.png) The uniform regions have been replaced by a series of discrete bands that seem to try an interpolate between the rectangles. This happens if I choose fewer rectangles too (e.g., `n = 3`). If I generate the same thing _without_ using `Raster`, the exported `PDF` looks fine - e.g., try this:               With[{n = 5},      Graphics[Inset[        Graphics[         MapIndexed[{ColorData["LakeColors"][#],             Translate[Rectangle[], {#2[[1]], 0}]} &, (Range[n - 1] -              1)/(n - 2)]         ]        ,        Automatic, Automatic, {.45, .5}        ]       ]      ]      So it's the conversion of the rasterized image in `Export` that's responsible for this effect. Interestingly, one can work around this (on Mac) by selecting the graphic, going to `Edit > Copy As > PDF` and pasting the result into `Preview`. Although I have some workarounds now, it still seems mysterious to me why this banding effect happens with `Raster`. And it would of course be nice if someone knew **how to use`Raster` in an `Inset` inside a `Graphics` without triggering the effect** that causes the blocks of the raster to lose their uniform color. Also - the arguments to `Inset` can be left out (in particular the scaling `{.45, .5}`). But it seemed to me that this problem didn't always happen with `Raster`, and that it probably has something to do with the size of the bitmap being scaled up relative to some assumed coordinate system used in `Export`.


title: How to handle infeasible points in FindRoot?

text: I am calling               FindRoot[f[x,y],{{x,xInit,xMin,xMax},{y,yInit,yMin,yMax}}]      where for some points `{x,y}`, `f[x,y]` is undefined. I now wonder which value `f[x,y]` should return at `{x,y}` in order for `FindRoot` to neglect these points, and to continue searching. Should `f` maybe return `Null` or `Indeterminate` at the critical `{x,y}`? Note, that so far I have not added any domain restrictions on `f`. I also do not know whether adding domain restrictions would be a possibility? To give some more background: `f[x,y]` is a composite function of other functions of `x` and `y`. For some points `{x,y}`, bounds for integrals inside these functions become complex, which is nonsensical. Currently, I throw an error as far as possible down the tree of interdependent functions - call the function where I do this `l`. Points `{x,y}` are infeasible if `g[x,y]<h[x,y]`.               l[x_,y_]:=Module[{...},If[g[x,y]<h[x,y],Throw["Error"],Null],...]      However, I am not catching this error properly and `FindRoot` terminates.


title: Symbolic integration of elliptic functions

text: Is there some clever way to **integrate products of elliptic functions** $\wp(z;g_2,g_3)$ or $\zeta(z;g_2,g_3)$ in _Mathematica_? * * * _Mathematica_ seems to be able to integrate functions like               Integrate[WeierstrassP[z, {g2, g3}]^3, z]      However, not something like               Integrate[WeierstrassP[z, {g2, g3}] WeierstrassP[z + a, {g2, g3}]], z]      I have tried using the addition formulae for the $\wp(z)$, but _Mathematica_ is still unable to give the answer.


title: How to set tick label precision

text: When I make a plot like               Plot[Exp[x], {x, 1 - 10^-9, 1}]      The resulting plot looks like ![exp plot near 1](http://i.stack.imgur.com/7sKyb.png). Notice all the ticks on the x-axis are all labeled 1. Is there any way to increase the precision of the tick labels? So that the ticks are labeled something like 0.999999999, or 1-10^{-10} etc.


title: How do I prevent this precision exception?

text: I have the following as the first step to a sequence.               x = 2 - GoldenRatio;     Ceiling[x + x^(1/2)]      It gets a precision exception. The value is correct, but I would like to prevent the exception. (If we subtract 0.000001 from x, everything is fine.) Is there a way to limit the precision? For one step only? Edit: the sequence where 2-GoldenRatio is the seed.               x = 2 - GoldenRatio; t = Table[(x = Ceiling[x + x^(1/2)]), {2000}];      If ceiling is removed the first step works fine. However, I need the ceiling for alternate steps. Edit2: $0 < x \leq 2-\phi$ where $\phi$ is the golden ratio. $\textit{When x = 2 - $\phi$, the first step equals $1$}$.


title: Computation of parametric integral

text: I am trying to compute the integral               Integrate[(g^(u^(g - 1)))/(1 + u^g), {u, 0, t}]      but as an answer I get my input expression. There must be something wrong with parameters but even if I give values to `t` or `g` mathematica'a answer is the same: it just gives me back my input expression... My output is ![](http://i.imgur.com/5lACY.jpg) How can I compute this integral?


title: Mathematica 9 Linking with R

text: I would like to run a batch job from within the current Mathematica .m file using "R CMD BATCH &" (the job runs in the background when Mathematica proceeds with the current calculations. How can I do that in Mathematica 9?


title: How to define a large number of assumptions?

text: Please consider the following _simple_ and _larger_ example:               varSimple = ToExpression@CharacterRange["a", "b"];     fSimple = Total@Map[Sqrt[#^2] &, varSimple];     assumpSimple = And[Element[varSimple, Integers] , a >= 0 , b >= 0];     simpfSimple = Simplify[fSimple, assumpSimple]     (*a+b*)      When one defines a larger function such as `fLarge`, it is very inconvenient to type `character1>=0 && ... && character#>=0` for the whole `CharacterRange` to define the assumptions.               varLarge = ToExpression@CharacterRange["a", "z"];     fLarge = Total@Map[Sqrt[#^2] &, varLarge];     assumpLarge = And[Element[varLarge, Integers] , a >= 0 , ... , z=>0];     simpfSimple = Simplify[fSimple, assumpLarge]     (*a+...+z*)      **Question 1** Since `And` (as well as `Alternatives`) cannot cope with `List` as an argument, how can I combine a larger number of expressions with `And` (or `Alternatives`)? **Question 2** With `ToExpression@CharacterRange["a", "z"]` the number of variables is limited to 24. Is there another (easy) way to define a larger number of variables?


title: Can TextRecognize read digits?

text: While answering this question, I tried `TextRecognize` to read single digits. But it doesn't recognize a single digit, even though the digits are clearly readable. For example, this ![enter image description here](http://i.stack.imgur.com/EYX3I.png) is not recognized. This is my code:               digits = ImagePartition[Import["http://i.stack.imgur.com/cLncR.png"], 50];     Map[TextRecognize, digits, {2}]


title: Publishing quality graphs to Adobe Illustrator?

text: I am trying to produce publishing quality graphs. I would like to export graphs from a Notebook to Ai (Adobe Illustrator). How do I do this? Just started using Mathematica, very new! Thanks, Anousheh PS This is NOT a duplicate question!!! It has nothing to do with the FONTS!!! A simple question of how to export graphs into Ai. Can we attache files (Notebooks) for easiness? Thank you, Anousheh


title: Is there a keyboard shortcut for hiding the suggestion bar?

text: I see that there's a control I can click to hide or "minimize" version 9.0's "suggestion bar". Is there a keyboard shortcut to do this?


title: Mixing patterns with string patterns

text: I have imported an XML document into _Mathematica_. It is now represented as Symbolic XML expression in the variable `xml`:               XMLObject["Document"][{XMLObject["Declaration"]["Version" -> "1.0"]},       XMLElement[       "slideshow", {}, {XMLElement["title", {}, {"XML Tutorial"}],         XMLElement[         "slide", {}, {XMLElement["title", {}, {"Agenda"}],           XMLElement["item", {}, {"Introduction"}],           XMLElement["item", {}, {"XML technologies"}],           XMLElement["item", {}, {"Editors for XML documents"}]}]}], {}]      Using the `Cases` function I want to extract the `XMLElement` expressions whose plain text contents contain the word "XML":               Cases[xml, XMLElement["item", _, {___ ~~ "XML" ~~ ___}], Infinity]      This however returns the empty list, probably because it is mixing a _Mathematica_ expression pattern with a string expression pattern. How does one go about embedding a string pattern into a regular pattern?


title: Dynamic and LibraryLink: dynamic visualization of a simulation

text: I am asking this question to save some time and I am expecting answers only from people who have tried something like this before. (I realize that I could just try it and see if it works, but that takes a non-trivial amount of time.) Suppose you wrote a simulation in pure Mathematica. As the simulation progresses, a vector is being periodically updated changed. One could then have a `Dynamic@ListPlot[vector]` and watch the progress "live". Now the question is: is this possible when using LibraryLink? With LibraryLink it's possible to access a kernel variable (`vector`) directly. Is it possible to get the system to register the changes to that variable and to run the `Dynamic` when necessary? Or is there an alternative _simple_ (low effort) way to achieve the same, i.e. use Mathematica to visualize a simulation "live"? One way I see that certainly work is periodically calling back to the kernel through a MathLink connection and setting a variable through Mma code, which contains the information to be visualized. Is there a simpler/better way?


title: Generating unique random number lists

text: I am new in programming. I have an array containing, let's say 20 elements and first I want to randomly select two elements from it and record them. Then I will select two elements from the array of twenty elements again and record them. The process continues, let's say 10 times and in these 10 draws, I do not want to repeat any of the two elements that I have already drawn. I used `RandomSample` to generate random numbers.               j = 0;     For[i = 0, i < 2, i++,       Yarray[j] = RandomSample[Range[8], 2];       Print[Yarray[j]];       j++;]


title: How to connect Mathematica 9 to MS SQL 2012 using Windows 7 enterprise (64-bit)

text: I have used Microsoft Open Database Connectivity (ODBC) with _Mathematica_ 8.0 and MSSQL 2008 on Windows XP, but I can't get it to work on Windows 7 Enterprise (64-bit) with _Mathematica_ 9.0.1.0 and MS SQL server 2012 (64-bit). Has anyone had success in doing this?


title: FindShortestTour for charity (or: How can I optimize meal delivery with FindShortestTour?)

text: I've been wondering about this for a while - but never got around to asking - until I saw faleichik's incredible answer to _Mathematica_ Minecraft. I did some work at a not-for-profit a little while ago, which participated in a program called Meals On Wheels - wherein I helped to deliver food to those who are homebound. Myself and a partner would deliver meals to a daily list of addresses, sorted by name; not the most efficient route. The time to complete a route varied by as much as two hours because of it. `FindShortestTour`, however, is only one (possible) part of the solution. I'd need to parse addresses, read map data, and handle the slight irregularities of NYC streets. How can I use `FindShortestTour` to find the optimal meal delivery route, given a list of addresses?


title: Center of quadrangular

text: Having 4 points **A** `(ax, ay)`, **B** `(bx, by)`, **C** `(cx, cy)` and **D** `(dx, dy)` that describe any quadrangular in 2D, with `x` and `y` in range `[-100, 100]` I would like to calculate point **E** `(ex, ey)`, which would be a center of this quadrangular. What algorithm can be used for such calculation and why?


title: Why isn't autosave enabled by default?

text: While I've come across several ways to implement/enable autosave (see: Is there a notebook autosave frequency configuration?, Saving my code before cell evaluations: Insurance against front end hanging, How can I set up a versioning system within a notebook?), I've never found a reason why it isn't enabled by default. It seems incredibly useful to me - surely there must be some good reason why Wolfram chose to leave it unconfigured! Why isn't autosave enabled by default?


title: Faster Solve for Fermat 4n+1 conjecture

text: Assuming that Fermat `4n+1` conjecture (each prime of the form `4n+1` is the sum of two squares) is true then I like to solve the equation in the fastest possible form.               fermatQ[z_] :=       Length[Solve[x^2 + y^2 == z && x > 0 && y > 0 && x > y, {x, y},          Integers]] == 1      * * *               n = RandomPrime[10^1000]     7204820541697853265697482198302184350747317334028070603629009839116252110492095578256567601106541188796967599300930463571131759731713652353047579003939845222202423352007102653912639893572595606320600084613647266601717191253462990524380427645290376322143085916721648030108591154681102352260206273871572063237796538519461643983233381100630087701623080830334878529319816938438525254877567479353234371918939199585631244203057530334523235226572902803801085582846927846832856652925979381175382144232563160719058478946717172490138082439192330136929995648881640700486082783629709282614697667884919440294962926788805345569631546029257495702381802397055578335502287473342083514426712460325643772655909154310734572274430109077955105556789724468724642608390802045303940792665411216800131523990931511413428660061711347430190867360920645531069644270820680156683794692381221310012472305068130266122993566902672115038607482079495349772492239436104516688041844051770082711796572639884658459765037703578841572775761721          Divisible[(n - 1), 4]         True      * * *               Timing[fermatQ[n]]          {0.296875, True}          Timing[PrimeQ[n]]          {0.203125, True}          Timing[Length[PowersRepresentations[n, 2, 2]] == 1]          {0.687500, True}        1. Can we optimize `fermatQ` to solve it faster?   2. Can we say to `Solve` to halt and return upon finding the first `k` solutions ? (Not to compute them all and extract the first `k` solutions) **Updated** Added timing for MMA built-in `PowersRepresentations` which is slower than `Solve`. **Update 2** Based on @KennyColnago answer, we can write a one line formula but yet the timing is the same (everything behind the scene seems to be equal):               ModularRootPrimeQ[n_] := Length[PowerModList[-1, 1/2, n]] == 2          Select[Prime[Range[4, 1000000]],       Mod[#, 4] == 1 && ! ModularRootPrimeQ[#] &]          {} // Checked the first million primes and found no counterpart      If you run the same over all 4m+1 numbers, you'll get all 4m+1 primes with only prime powers:               Select[Range[1000000],       Mod[#, 4] == 1 && ! PrimePowerQ[#] &&         ModularRootPrimeQ[#] && ! PrimeQ[#] &]          {} // If you remove the condition !PrimePowerQ[#] , only prime powers will appear here.