Split absolute value in chambers

I usually expand expression containing absolute values, with the PiecewiseExpand[] function.               Delta[m1_, m2_, m3_] := -Abs[m2 - m3] + 1/2*(Abs[m1 - m2] + Abs[m1 - m3]) + 3/2 (Abs[m2] + Abs[m3])          PiecewiseExpand[Delta[m1, m2, m3], {m1 ∈ Integers, m2 ∈ Integers, m3 ∈ Integers, m2 >= m3}] // FullSimplify      This usually splits the absolute value in the various chambers in which it assumes a certain functional form which does not contain absolute values anymore, and also the conditions which define the cells are given by the PiecewiseExpand[] function. However, the last chamber is never given, but it corresponds to the bool vale "True". How can I recover it?


How can AbsoluteTimes be split by date faster?

I have data where the date is stored as an `AbsoluteTime`. Here's a dummy dataset:               sampleData=Transpose[{#,Range[Length[#]]}]&[Range[AbsoluteTime[{2012,10,01}],         AbsoluteTime[{2013,09,30}],60]];      I want to split it by date, so I use:               splitData=SplitBy[sampleData,DateList[First[#]][[;;3]]&];      This takes ~22 s on my machine. Often I have bigger data sets than this. Is there a faster way to get `splitData`?


How to speed up multi-curve plotting?

The following example is a very simplified version of the problem I'm working with, though I hope it still captures the essentials. First, the definitions:               sigmoid[s_, a_][x_] := (a (-s + x))/Sqrt[1 + a^2 (s - x)^2];          plots[params_] := Module[{fns},        fns = sigmoid @@ # & /@ params;        Plot[#[x] & /@ fns, {x, -20, 20}, ImageSize -> Small]];      The `plots` function produces a plot containing as many sigmoid curves as there are parameter sets in the list `params`. E.g., with 5 parameter sets (differing only in the first parameter):               plots[{{-10, 1}, {-5, 1}, {0, 1}, {5, 1}, {10, 1}}]      `plots` produces ![5-curve plot](http://i.stack.imgur.com/kTwgA.png) More typically, however, I need to run `plots` with an argument consisting of ~100 sets of parameters, and I'm finding it to take considerably longer than I had expected. (Maybe I've gotten spoiled!) For example, running               plots[{#, 1} & /@ Array[# &, 100, {-15, 15}]]      takes ~40s on my desktop. Does this sound right? Currently I am in the process of producing several figures each consisting of a grid containing ~100 plots of comparable complexity (i.e. ~100 curves/plot), so I need to find ways to significantly speed this up. Any suggestions would be appreciated. NB: The details of the `sigmoid` function should not be an important aspect of the proposed optimization, since I chose this function for this example only because it is significantly simpler than the function that I am actually working with. (For one thing, the latter is parametrized by three rather than two numbers. Nevertheless, it produces s-shaped curves looking very similar those produced by `sigmoid`.)


Why can NSolve only solve this system of equations after trivial substitution?

The first system immediately yields {}, but the second, equivalent, system yields the solution `{{k -> 4.96048, tl1 -> 1.64842, tl2 -> 2.07466}}` :               NSolve[{       (5 - k)(2940/100) == tl1^0.3,        (5 - k)(3150/100) == tl2^0.3,        4200 tl1^0.7 + 4500 tl2^0.7 == 1000000},        {k, tl1, tl2}]          NSolve[{       (5-k)(2940/100) == tl1^0.3,       (5-k)(3150/100) == tl2^0.3,        (5-k) 4200(2940/100)^(7/3) + (5-k) 4500 (3150/100)^(7/3) == 1000000},        {k, tl1, tl2}]      The second system is created by noting that `tl1^0.7 = (tl1^0.3)^(7/3)` and `tl2^0.7 = (tl2^0.3)^(7/3)` and substituting the results into the third equation. Is there a way to get _Mathematica_ to do such substitutions on its own?


Understanding a slowdown associated with wrapping a set of nested Do loops with a ParallelDo expression

I have a set of set of nested Do loops that require data from three different arrays (though the position from each array is fixed per cycle of the outer Do loop). Let's call these arrays: ListA, ListB, ListC. My attempts at parallelizing the outer Do loop (i.e. using ParallelDo) seem to work, but there is a ~100x slowdown on a 12 core processor. I was hoping someone here could help me understand why. Here's some nonsense pseudocode that should capture the structure of the bit of code I evaluated:               Do[        Do[           Do[              ListA[[i]] = Append[ListA[[i]], ListB[[i, a]] + ListB[[i, b]]];             , {b, (a+1), M}             ];          , {a, 1, M}          ];               ListA[[i]] = Sort[ListA[[i]]];                  Do[             If[Abs[ListA[[i, j]] - ListA[[i, j + 1]]] < ListC[[i]],                  ListC[[i]] = Abs[ListB[[i, j]] - ListB[[i, j + 1]]];               ];           , {j, 1, Length[PairwiseSums[[i]]] - 1}          ];               , {i, 1, Length[AllSubsets]}     ];      Previously defining ListA, ListB, and ListC, and writing:               SetSharedVariable[ListA]     SetSharedVariable[ListB]     SetSharedVariable[ListC]          ParallelDo[        Do[           Do[              ListA[[i]] = Append[ListA[[i]], ListB[[i, a]] + ListB[[i, b]]];             , {b, (a+1), M}             ];          , {a, 1, M}          ];               ListA[[i]] = Sort[ListA[[i]]];                  Do[             If[Abs[ListA[[i, j]] - ListA[[i, j + 1]]] < ListC[[i]],                  ListC[[i]] = Abs[ListB[[i, j]] - ListB[[i, j + 1]]];               ];           , {j, 1, Length[PairwiseSums[[i]]] - 1}          ];               , {i, 1, Length[AllSubsets]}     ];      Yields the ~100x slowdown on a 12 core processor. Why?


how to efficiently jump between sections in a notebook?

I have functions defined in some section of the notebook and some cells where I use these functions maaaaany pages below in the same notebook. If I want to go and change the definition of the function I need to climb up in the notebook, find the definition and change it, then climb down to the place where I was working and using these functions. This is very inconvenient and looks like "navigation by sight". I was wondering how this can be made more efficient. For instance if it was a C++ or TeX source I would use the table of content of the file that my editor builds for me so that I can jump to the section where I define function clicking the TOC and then jump back to the original location either using "back" or again clicking the TOC. Can anything like this be done in mathematica?


Better method for creating a tuple out of two lists

I just combined two lists using this method               molefrac = {1., 0.787402, 0.478927, 0.282592, 0.}     calibrationIndexOfRefraction = {1.440, 1.421, 1.395, 1.380, 1.351}     Partition[Riffle[molefrac, calibrationIndexOfRefraction], 2]      > >     {{1., 1.44}, {0.787402, 1.421}, {0.478927, 1.395}, {0.282592, 1.38}, > {0., 1.351}} >   The purpose of this was to prepare the lists to be plotted using `ListPlot`. Is there some way to use `ListPlot` directly (or something more functional) to do this without going through all the extra steps?


Efficiently finding the maximum value of a column in a matrix

Imagine I have a matrix of the following form: TestArray = $((a_1,b_1,...),(a_2,b_2,...),(a_3,b_3,...),...)$, where a specific example might be: TestArray = $((10^6,1,...),(10^7,7,...),(10^3,4,...))$ In the above example, we have $Max[a_i] = 10^7$, and $Max[b_i] = 7$. In a single line of Mathematica, how can I find the maximum $a_i$, $b_i$, etc.? Moreover, what is the most computationally efficient manner in which to do this?


Undirected Network and its Monte Carlo Simulation

So I have this array of points, in the form {x, {y,z}}, where x is the node number assigned when I used the locator pane to make a network, and y and z are its unitary coordinates. The graph is made up of two distinct node types, let's call them A and B. I want to be able to distinguish these two by assigned different shapes to their nodes and also want to connect the network how it originally was and using Primm's Algorithm (Minimum Spanning Tree). I was wondering how I go about it. I should also probably mention that from this network I am going to run some Monte Carlo Simulations on it. The code I have so far is:               graphicslist =        Table[Rectangle[mpg[[i, 2]] , mpg[[i, 2]] + {.005, .005}], {i, 1, Length@mpg}];       Graphics[graphicslist]       where mpg is the array of my nodes and their coordinates. This returns: ![enter image description here](http://i.stack.imgur.com/juI6d.png) Small sample of the mpg:               mpg == ({{1, {0.0996, 0.4195}}, {2, {0.1046, 0.392}}, {3, {0.1144,       0.468}}, {4, {0.1164, 0.4415}}, {5, {0.1432,       0.4455}}, {6, {0.1442, 0.376}}, {7, {0.147, 0.5085}}, {8, {0.16,       0.4965}}, {9, {0.1628, 0.5305}}, {10, {0.1708, 0.484}}.......      Here the integer is the node number and the following decimals are the unitary coordinates of its corresponding vertex. In the real Maryland Power Grid, there are two distinct vertices; loads and generators. I plotted, using the locator pane, all of its vertices and wish to differentiate which one are loads and which are generators rather than just have squares for both of them.


How can I extract when a select condition is met in a do loop the value of the iterator?

I use the following code to find out the number of consecutive prime numbers using a formula $n^2+n+i$ found out by Euler (starting from n=0):               Nbs = {};     Do[Nbs = Union[Nbs,      Select[Range[5000], (PrimeQ[#^2 + # + i] == False &), 1]], {i, 1,      5000}];     Nbs       How can I also get in the output list the value of the `Do` iterator where $i$ is corresponding to each number of consecutive primes? I would like to get something like that:               ({1,2},...,{40,41}}


symbolic integration of a definite integral, how to speed up

I am wondering what are the general tips & hints for speeding up symbolic integration. As far as I understand, it solely depends on the form a function is represented before it is processed by `Integrate`. So, `Simplify`, `ExpandAll`, `PowerExpand` _etc._ should be used. Are there any other strategies? My monster function (it looks relatively simple, though) is:               f[r_]:=(A^(2) E^((2 r α)/(3)) α^(3) (A^(8/3) \     (-0.002396-0.001198 r α)+E^((8 r α)/(3)) α^(4) \     (0.00001755-(8.776*10^(-6)) r α)+A^(4/3) E^((4 r \     α)/(3)) α^(2) (-0.0002734+0.0004785 r α)))/(r \     (1.000 A^(4/3)+0.02853 E^((4 r α)/(3)) α^(2))^(4))      or (TeX) $$ \frac{A^2 \alpha ^3 e^{\frac{2 \alpha r}{3}} \left(\alpha ^4 \ e^{\frac{8 \alpha r}{3}} \left(0.00001755-\alpha r \left(8.776 \times 10^{-6}\right)\right)+\alpha ^2 A^{4/3} (0.0004785 \alpha \ r-0.0002734) e^{\frac{4 \alpha r}{3}}+A^{8/3} (-0.001198 \alpha \ r-0.002396)\right)}{r \left(0.02853 \alpha ^2 e^{\frac{4 \alpha \ r}{3}}+1.000 A^{4/3}\right)^4} $$ where $\alpha > 0$ and $A > 0$ are some parameters. What I am trying to do: `Integrate[f[r]*r^2*4*Pi,{r,O,Infinity}]` Sure, I could have used `NIntegrate` for some specific $\alpha$ and $A$ (and belive me, I did it:), but now I am interested in the general result. Seems like the situation is hopeless, because my laptop can not handle it.


Plotting discrete data but not using discreteplot function

For a given function:               Plot[Sqrt[Abs[x]], {x, -Pi, Pi}]      I have the code to draw the function (with its Abs remove), partial sums and cesaro means as:               f[x_] := Sqrt[x]     s[k_, x_] := \frac{2\sqrt{\pi}}{3}+(-Sqrt[2] FresnelS[Sqrt[2] Sqrt[n]] + 2 Sqrt[n] Sin[n \[Pi]])/(n^(3/2) Sqrt[\[Pi]]) Cos[n x], {n, 1, k}]      partialsums[x_] = Table[s[n, x], {n, {4}}];      c[n_, x_] := (1/n) Sum[s[m, x], {m, 0, n - 1}]     Plot[Evaluate[{f[x], partialsums[x], c[4, x]}], {x, -Pi, Pi},     PlotLegends -> {"f(x)=x", "Fourier, 4 terms", "Cesaro, 4 terms"},      PlotStyle -> {{Blue}, {Dashed, Thickness[0.006]}, {Red, Thickness[0.006]}}]      This code fails on my computer and hence I resolve to manual computation. Updates: It turn out that I can easily solve this issue by removing the k with any number rather than letting it to be indefinite. Although I am not certain the graph is right for k=4 as both graphs(Partial and Cesaro) coincides with each other.


Rookie mistake in defining a function with Modules?

I can't figure out what's wrong with this piece of code. I'm trying to define a function that counts the occurrences of `x`, `y` and `l` or `lc` in expressions like `x[x[y[l]]`, where `x` will add 1 to an "eigenvalue", `y` will subtract 1 and likewise for `l` and `lc`. Then for example I would get `H[x[x[y[l]]] = 2`. Now I'm stuck at the first phase with the function defined below:               H[z_] := Module[{list1 = Join[Level[z, Infinity], {z}], lam = 0},       Which[list1[[1]] == l, lam = lam + 1,              list1[[1]] == lc, lam = lam - 1       ];       lam     ]      This should give `H[l] = 1` and `H[lc] = -1`, but instead I get just the initial value `lam = 0` for the "lc" case... When I discard the last line and use instead               H[z_] := Module[{list1 = Join[Level[z, Infinity], {z}], lam = 0},       Which[list1[[1]] == l, lam = lam + 1,              list1[[1]] == lc, lam = lam - 1       ]     ]      I get               Which[lc == l, lam$538474 = lam$538474 + 1,            list1$538474[[1]] == lc, lam$538474 = lam$538474 - 1     ]      Clearly something's wrong with the `list1$538474[[1]]` above. What am I missing?


Plot, extract data to a file

I need to save data that _Mathematica_ uses inside the `Plot` command. The format that I would like to have is:               x1 y1     x2 y2     .....      i.e. basically, two columns, _x_ and _y_ (sorted, if possible) so that I can use the data for other programs. I already played with `Export` and got the data enclosed in `{}` and tons of other information I don't need: color, axis, _etc._ What is the nicest way to do what I am trying to do?


How to extract data from a plot?

Here is the equation I want to plot,               t = -((E^-η h1^2 γ)/(16 (1 + γ)^7)) -      (E^-η h1^3 γ)/(32 (1 + γ)^7) - (     E^-η h1^2 Nr γ)/(6 (1 + γ)^7) - (     E^-η h1^3 Nr γ)/(8 (1 + γ)^7) - (     E^-η h1^2 Nr^2 γ)/(9 (1 + γ)^7) - (     E^-η h1^3 Nr^2 γ)/(6 (1 + γ)^7) - (     2 E^-η h1^3 Nr^3 γ)/(27 (1 + γ)^7) - (     4 E^-η h1^2 Pr γ)/(9 (1 + γ)^7) - (     85 E^-η h1^3 Pr γ)/(216 (1 + γ)^7) - (     35 E^-η h h1 M^2 Pr γ)/(72 (1 + γ)^7);               Clear[η, M, γ, h, h1, Nr, Pr];     θ[η_, M_, γ_, h_, h1_, Nr_, Pr_] = t;     Plot[{  θ[η, 1.5, 0.6, -0.5, -0.5, -0.5, 0.1],      θ[η, 1.5, 0.6, -0.5, -0.5, -0.5, 0.1],      θ[η, 1.5, 0.6, -0.5, -0.5, -0.5, 0.3],      θ[η, 1.5, 0.6, -0.5, -0.5, -0.5, 0.5],      θ[η, 1.5, 0.6, -0.5, -0.5, -0.5, 0.7],      θ[η, 1.5, 0.6, -0.5, -0.5, -0.5, 0.9],      θ[η, 1.5, 0.6, -0.5, -0.5, -0.5, 1.1]},      {η, 0, 8}, PlotRange -> All, AxesLabel -> {"\!\(\*StyleBox[\"η\",\nFontSize-   >22]\)", " \!\(\*StyleBox[\"θ\",\nFontSize->20]\)\!\(\*StyleBox[\"(\",\nFontSize->22]\)\!\(\*StyleBox[\"η\",\nFontSize->22]\)\!\(\*StyleBox[\")\",\nFontSize->22]\)"}, PlotStyle -> Directive[Black],AxesStyle -> {Directive[Black, 12, Bold], Directive[Black, 12, Bold]}]      How to save data from this plot as a .txt file? Thanks


Manipulation of Automatic settings in a given case

Often I use the `Automatic` option to specify plot styles, plot ranges, image sizes, etc. I'd like to be able to apply some modifications to these automatically defined values. For example, if a plot with the `PlotRange -> Automatic` would draw the function on the interval $[0,1]$, I'd like to be able to use something like `PlotRange -> #*2 & /@ Automatic` to extend the plot range to $[0,2]$. Is this possible in general, or maybe every case would need a specific solution? _I'm not sure what tags are most appropriate for this topic, please add them if you think they're more suitable than the one I've chosen._


Coloring a honeycomb structure

I am trying to generate a honeycomb structure. With the help of this MMA.SE question & this website, I got               hexgon = Polygon[       N@Transpose[Through[{Re, Im}[Exp[2 Pi I Range[6]/6]]]]];               points[x_, y_] :=        Flatten[Table[{{3 m, Sqrt[3] n}, {3 m + 3/2,            Sqrt[3] n + Sqrt[3]/2}}, {m, 0, x}, {n, 0, y}], 2];          Graphics[Translate[       Rotate[{RGBColor[RandomReal[], RandomReal[], RandomReal[]],          hexgon}, \[Pi]/6], ({#[[2]], #[[1]]} &) /@ points[1, 4]]]      ![Honeycomb](http://i.stack.imgur.com/Z9WkI.png) How do I fill every hexagon with different color?


how to mean of day,month value

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.


How does Mathematica know my location?

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.


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

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.


How to place legend labels for Histogram and ListLinePlots correctly?

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)


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

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?


Auto simplifications of power products

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`.


How can I fix CDF Windowsize as constant

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?


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

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.


Datastream to Mathematica

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?


Programmatic generation of enhanced (Enterprise) CDF

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.


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

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.


Getting serious about Mathematica programming

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.


Multivariate resultant in Mathematica?

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


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

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?


Preserve information in flattening a nested list

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?


LinearProgramming errors

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?


Factor a Vector

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}}


Simulating CoordinatesToolOptions (for CDF) & the Inflexibility of MousePosition

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?


DynamicModule updating unexpectedly

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]}]         ]        }]      ]


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

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?


Map of Specific US States? (Isolated)

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?


SetOptions and Cell

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!


preventing TraditionalForm from getting "squished"

`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.


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

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)


Suppressing reduction in fraction box size in multi-level fractions

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)


Fractions formatting in Column / Grid

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.


Conditions in SparseArray

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}];


NDSolve boundary query / Extracting values from solution

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!


Plot failing when given a list of functions

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?


Creating a nested menu with OpenerView

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)


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

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?


Stretch Grid to fit width of containing object?

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)


Custom default ImageSize while allowing inheriting

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.


Getting unevaluated function expression

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.


Putting set elements into venn diagram

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.


Optimising code for nested integrals

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]


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

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.


Calculate max value

# 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.


ListDensityPlot

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.


error message DSolve::"bvnul"

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?


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

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 *)


Why does the iterator index in Table not work here?

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?


Optimizing my code to generate symmetric tensors

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).


RowReduce : Record of all the row operations for RREF

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?


Construct an infinte matrix with finite sub-matrices

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?


Color Blend in BezierCurve

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)


Using quantifiers with free indices as declarative conditions in equation solving

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)


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

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.


Dataset: cannot reproduce a basic example. A bug?

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.


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

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.


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

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?


Aborting a computation correctly in .NETLink to allow future computations

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.


find derivative with defined function

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


How can I produce multiple column data for export?

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?


Ugly plots when printing notebook to pdf

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.


How can I set the speed of manipulate play button?

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


Use TraditionalForm (or something similar) in AxesLabel/PlotLegends

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. ;)


statistical database calculation

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?


Memory running out generating ContourPlot3D

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.


Plotting bipartite graph from adjacency matrix

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


How to export notebook in colored PDF form

> **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) * * *


Selecting a sublist based on Length

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.


Parametric regions

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?


Strange filling

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.