title: listplot very large numbers

text: Suppose we have the following function:               NN = 150;     W[n1_] := NN!/(n1 ! (NN - n1!)) (1/2)^n1 (1/2)^(NN - n1)      Then we can Plot or Listplot it:               ListPlot[Table[{n1, W[n1]}, {n1, 1, 10, 0.1}], Joined -> True,       Frame -> True, Axes -> None, BaseStyle -> {FontSize -> 16},       PlotMarkers -> {"\[Bullet]", 10}, PlotStyle -> Red]      ![enter image description here](http://i.stack.imgur.com/FiRF2.png) If we change NN to 200 or more, then we get the following error: > ListPlot::prng: Value of option PlotRange -> > {{0,10.},{-1.341145999799935*10^312,2.466246209857526*10^312}} is not All, > Full, Automatic, a positive machine number, or an appropriate list of range > specifications. >> How can we deal with these large numbers in plot?


title: How to get CUDALink working on linux (Crunchbang Waldorf) with NVS 3100m

text: I am trying to get CUDALink working on my laptop. I am running Crunchbang "waldorf" which is based on Debian 7 "wheezy". I am a linux novice. The issue is that Mathematica can "see" the nVidia drivers, but yet I am not able to get CUDALink to work. I have searched, and read over the article CUDALink not working on Linux-64 and Asus GTX460 which is close to my issue but doesn't seem to cover it, and where it does shed some light I don't appear to have any of the directories mentioned. I have engaged the Crunchbang linux forums to no avail.. I would really like to get CUDALink working.. I have tried information such as on this website http://www2.warwick.ac.uk/fac/sci/statistics/staff/academic- research/graham/cuda5-debian-wheezy/ but it ruined my video driver setup and I was forced to go through the smxi script again and re-install to get the GUI back. At the moment I am re-downloading the cuda_5.5.22_linux_64.run file from nVidia. I have tried installing the nVidia CUDA binaries from the debian package manager but it ruins my system every time, forcing me to use the smxi script to repair. Otherwise, Mathematica 9 is running wonderfully. If someone can please illustrate the process of setting up CUDA/CUDALink I would greatly appreciate it. Cheers! Will EDIT: I have installed CUDA 5.5 from the above package and have run deviceQuery, with positive results. It detects the card and all fields are nominal, referencing the nVidia website for the 3100m. EDIT 2: It was discovered from https://wiki.archlinux.org/index.php/Mathematica that the x64 version of Mathematica is "hard wired" to look for drivers in the /usr/lib64 and not in /usr/lib where things are installed in an x64 native system. Since making a symbolic link using "ln -s /usr/lib /usr/lib64" Mathematica's CUDALink appears to be working now. This question is now closed, but hopefully this can act as community support for others. EDIT 3: As is mentioned in my answer, there is now an issue with CUDALink not running certain functions. It is the same symptoms as this question: CUDALink is not initialized


title: How can I set multiple values to local variables in a Module?

text: Multiple assignment is supported by `Set`. How can do something similar in `Module` expressions? If I could do it, whould there be drawbacks? Here is what I tried so far:               g[x11_, y11_] := {xx111, yy111} = {x11, y11}          g[x11_, y11_] := Module[{{x111, y111} = {x11, y11}}, 1]          g[1, 2]      > Module::lvset: Local variable specification {{x111, y111} = {1, 2}} contains > {x111, y111} = {1, 2}, which is an assignment to {x111,y111}; only > assignments to symbols are allowed. >> Possible alternatives are:               ggg[x11_, y11_] :=        Module[{xx = {x11, y11}, x1, x2}, {x1 = xx[[2]], x2 = xx[[1]]}]      or               ggg[x11_, y11_] := Module[{x1111=x11, y1111=y11}, what... ]


title: Google API and URLFetch

text: I am trying to systematically obtain the distance between two given locations using the Google Maps API Distance Matrix facility: developers.google.com/maps/documentation/distancematrix/ From the example they give in the web: I'd use: > > URLFetch["http://maps.googleapis.com/maps/api/distancematrix/xml?origins=Vancouver+BC|Seattle&destinations=San+Francisco|Vancouver+BC&mode=bicycling&language=fr- > FR&sensor=false"] and then parse the xml data. Now if I want to do this for many cities, I would build a string with URL changing the appropriate `origins` and `destinations` and other parameters. However, it looks pretty cumbersome to me and I feel that there should be a more efficient way to do it. Perhaps using the `parameters` option in `URLFetch`. So, there is the question, using the Google Maps API, given two locations is an more efficient (faster) way to obtain its distance? Thanks in advance!


title: Code Performance Tuning

text: The following code takes over 4 seconds to run. Any one has suggestions to make the expressions for `qf`, `phi`, `qr`, and `k` more efficient? Can someone suggest ways I can use`NestWhile` in the place of `While` and `Compile[]` on the four expressions (`qf`, `phi`, `qr`, and `k`) to enable `Parallelization`?               demand[n_, k_] := Min[k Vf, n capacity];     supply[n_, k_] := Min[(n Kj - k) w, n capacity];     flo[n_, ku_, kd_] := Min[demand[n, ku], supply[n, kd]];     gamma[ku_, kd_] := Min[1, supply[L, kd]/demand[L, ku]];     inflow [phi_, FQin_] := (phi - \[Beta] FQin) dx;     density[qin_, qout_, qr_] := (qin - qout + qr)/Vf;          L = 1; \[Beta] = 0.1; dx = 1/6; capacity = 7500; Kj = 150.; w = 100.; Vf = 100.;TT=0; RML = 2     k0 = Table[1, {i1, 1, 10}];     kr = Table[Table[1, {i1, 1, 4}], {i2, 1, 10}];     While[TT < 200000,        qf = Map[flo[L, #[[1]], #[[2]]] &, Partition[k0, 2, 1]];        phi = Flatten[Map[demand[1, #] &, Take[kr, All, -1]]][[2 ;; -2]]*Map[gamma[#[[1]], #[[2]]] &, Partition[k0[[2 ;; -1]], 2, 1]];        qr = (inflow @@ #) & /@ Transpose[{phi, qf[[1 ;; -2]]}];        k = (Plus @@ #) & /@ Transpose[{Insert[Map[density[#[[1]], #[[2]], #[[3]]] &, Flatten /@ Transpose[{Partition[qf, 2, 1], qr}]], 0, {{1}, {-1}}], k0}];        k0 = k;        TT += Plus @@ k0;     ]; // Timing      **Edit:** I also have the following piece of code that will go right below the k0=k in the above code               RMori = Table[100 (i1 dx)^2 + 50 (i1 dx) + 1000, {i1, 1, n - 2}];     RM = MapThread[Min[#1, #2] &, {RMori, flo[1, #[[RML]], #[[RML + 1]]] & /@ kr}];     qr = MapThread[Join[#1, {#2}, #3, {#4}] &, {flo[L, ##] & @@@ Partition[#[[;; RML]], 2, 1] & /@ kr, RM, flo[L, ##] & @@@ Partition[#[[RML + 1 ;;]], 2, 1] & /@ kr, \[Phi]}];     kr = MapThread[(#1 + #2) &, {Join[{0}, #] & /@ (density[Most@#,Rest@#, 0] & /@ qr), kr}];      in line of the suggestions made by SimonWoods, Can some one suggest ways to improve this piece of code? Also, I need some guidance on using `NestWhile` in place of `While`.


title: List of lengths of runs of elements

text: I have a list where a few distinct numbers occur, e.g.               {41, 41, 41, 1009, 41, 41, 41, 41, 41, 41, 41, 1009, 41, 41, 41}      I want to extract the information of how many times in a row each number occurs. For the above list,               {{3,7},{1}}      I actually already have something that works, but it seems excessively complicated and amateurish. Any ideas to improve this?               (Take[#, All, {2}] // Flatten) & /@      Sort[       GatherBy[{#[[1]], Length[#]} & /@ Union@Split@INPUTLIST,        First],       First@First[#1] < First@First[#2] &]


title: Question about NDSolve

text: Here is my code:               k = 0.42; e = 5; d = 7; n = 1/0.7158; R2 = 40000;           s =       NDSolve[{k^2  (u'[y] )^(3/2) (u'[y] + 2 u[y] Exp[y]/(R2 - Exp[y]))^(           1/2) - (-u'[y] (R2 Exp[-y] - 1) - 2 u[y]) (n - 1)/R2 - 1 == 0,         u[Log[4.17 (n - 1)]] == 4.17},        u, {y, Log[4.17 (n - 1)], Log[(n - 1) R2/(2 n)]}];          C1[y_] = Evaluate[u[y] /. s[[2]]];          Plot[C1[y], {y, Log[4.17 (n - 1)], Log[(n - 1) R2/(2 n)]}]          x = (((-C1'[y] (R2 Exp[-y] - 1) - 2 C1[y])/(-Exp[y] + R2)^3 +            R2/((n - 1) (-Exp[y] + R2)^3)) Abs[          C1'[y] Exp[-y] + 2 C1[y]/(R2 - Exp[y])])^(-1/4) Exp[-y] (n - 1)^(       1/2) R2^(-1/2)          f[y_] = NIntegrate[       2/3 a^(-5/3)         Exp[-a d Abs[x]] (1 + (e n Exp[y]/(R2 (n - 1)))^2/a^2)^(-17/         6), {a, 1, Infinity}]          f1 = FunctionInterpolation[(f[y])^(       3/4), {y, Log[4.17 (n - 1)], Log[(n - 1) R2/(2 n)]}]          Plot[Re[f1[y]], {y, Log[4.17 (n - 1)], Log[(n - 1) R2/(2 n)]}]          s = NDSolve[{k^2  (f1[y]) (u'[y])^(           3/2) (u'[y] + 2 u[y] Exp[y]/(R2 - Exp[y]))^(           1/2) - (-u'[y] (R2 Exp[-y] - 1) - 2 u[y]) (n - 1)/R2 - 1 == 0,         u[Log[4.17 (n - 1)]] == 4.17},        u, {y, Log[4.17 (n - 1)], Log[(n - 1) R2/(2 n)]}]          C1[y_] = Evaluate[u[y] /. s[[2]]]          Plot[Re[C1[y]], {y, Log[4.17 (n - 1)], Log[(n - 1) R2/(2 n)]}]          x = (((-C1'[y] (R2 Exp[-y] - 1) - 2 C1[y])/(-Exp[y] + R2)^3 +            R2/((n - 1) (-Exp[y] + R2)^3)) Abs[          C1'[y] Exp[-y] + 2 C1[y]/(R2 - Exp[y])])^(-1/4) Exp[-y] (n - 1)^(       1/2) R2^(-1/2)          f[y_] = NIntegrate[       2/3 a^(-5/3)         Exp[-a d Abs[x]] (1 + (e n Exp[y]/(R2 (n - 1)))^2/a^2)^(-17/         6), {a, 1, Infinity}]          f1 = FunctionInterpolation[(f[y])^(       3/4), {y, Log[4.17 (n - 1)], Log[(n - 1) R2/(2 n)]}]               Plot[Re[f1[y]], {y, Log[4.17 (n - 1)], Log[(n - 1) R2/(2 n)]}]          (*up to here, I think there is no problem. then the kernel crashes below*)          s = NDSolve[{k^2  (f1[y]) (u'[y])^(           3/2) (u'[y] + 2 u[y] Exp[y]/(R2 - Exp[y]))^(           1/2) - (-u'[y] (R2 Exp[-y] - 1) - 2 u[y]) (n - 1)/R2 - 1 == 0,         u[Log[4.17 (n - 1)]] == 4.17},        u, {y, Log[4.17 (n - 1)], Log[(n - 1) R2/(2 n)]}]          C1[y_] = Evaluate[u[y] /. s[[2]]]          Plot[Re[C1[y]], {y, Log[4.17 (n - 1)], Log[(n - 1) R2/(2 n)]}]      `R2` is a constant. When I set `R2` smaller than `33000`, I can always got a numerical solution of `u[y]`. However when `R2` gets very large,i.e. `40000`, mathematica just doesn't work at all. I mean there is no solution given for the third differential equation. Can anybody tell me how to solve this problem? I will be more than appreciated. Thanks.


title: Finding all simple paths between two vertices in a graph

text: There are built-in methods to find a shortest path between two vertices in a graph, and the question on finding all shortest paths between two vertices has gathered quite a bit of attention. A path is _simple_ if it repeats no vertices. As is with all shortest paths between a pair of vertices, the number of simple paths between two vertices can be huge. What would be a nice and clean method of finding all simple paths between two vertices? Assume the input graph is undirected, simple, and it may have cycles in it. I am not interested in the _number_ of simple paths between $s$ and $t$, but I want to explicitly enumerate all of them. Furthermore, note that this problem cannot be solved in polynomial time. Even writing the output might take time that is not polynomial in the number of vertices. One way of listing the simple paths is to use depth-first search. Maybe `DepthFirstScan` is useful here. The DFS can avoid repeating vertices by marking them as they are visited in the recursion, and then removing the mark just before returning from the recursive call. I learned a backtracking solution might not be that fast.


title: How is + as an infix operator associated with Plus?

text: How is `+` associated with `Plus`? Suppose I want to define a head `FooBar` and have it associated with a unicode character of my choice, ideally used as an infix form, i.e.               FooBar[x, y]      is equivalent               x ↗ y      as seen by the kernel. How this kind of thing can be done?


title: Using Reduce on an inequality

text: I have been evaluating this formula, $\frac {3^r - 1} {2^r - 1}$ for $r>1$. The numerator is always even and the denominator is always odd. I am trying to show that the denominator will not wholly-divide the numerator and leave a denominator of $1.$ The first table shows the `GCD` and the second shows the result is less than the original denominator.               Table[PolynomialGCD[(3^r - 1), (2^r - 1)], {r, 2, 10}]     (* {1, 1, 5, 1, 7, 1, 5, 1, 11} *)          Table[PolynomialGCD[(3^r - 1), (2^r - 1)] < (2^r - 1), {r, 2, 10}]     (* {True, True, True, True, True, True, True, True, True} *)          Reduce[PolynomialGCD[(3^r - 1), (2^r - 1)] < (2^r - 1)]     (* 2^r > 2 *)        The result of `Reduce` is true for $r>1$. Does the `Reduce` remove the `PolynomialGCD` info because it is always true? ### Edit per _rasher's_ comment               Reduce[r ∈ Integers && n ∈ Integers && r >= 1 &&        PolynomialGCD[(3^r (2n - 1) - 1), (2^r (2n - 1) - 1)] < (2^r (2n - 1) - 1)]     (* ((n | r) ∈ Integers && n >= 2 && r >= 1) || (r ∈ Integers && n == 1 && r >= 2) *)            Exists[r, PolynomialGCD[(3^r (2n - 1) - 1), (2^r (2n - 1) - 1)] < (2^r (2n - 1) - 1)]     Exists[n, PolynomialGCD[(3^r (2n - 1) - 1), (2^r (2n - 1) - 1)] < (2^r (2n - 1) - 1)]


title: How can I prevent a Plot expression from evaluating points forbidden by its RegionFunction?

text: I just ran into this and it had me scratching my head for a good while. Say I have a function which may produce error messages for certain inputs, like e.g.               f[x_, y_] := (Sin[x] - Sin[y])/(x - y)      which will return `Power::infy` and `Infinity::indet` when called on the diagonal `x==y`. If I want to avoid that singular input in a plot, the standard way of telling Mathematica to not evaluate it there is to use a `RegionFunction` command, like               Plot3D[f[x, y]      , {x, -10, 10}, {y, -10, 10}      , RegionFunction -> Function[{x, y, f}, Abs[x - y] > 5]      ]      This will successfully generate a plot with the diagonal taken off, but it will still produce the same error messages as `f[1,1]`. This behaviour remains even if I add the qualifiers `f[x_: NumericQ, y_: NumericQ]` to the definition, so some singular inputs are definitely passed to the function even though they are away from where I'm telling it to plot. So: why is this? Is this actually the correct way to specify regions to stay away from? If not, what's the best practice for that?


title: Simplifying a trigonometric equation to obtain specific terms

text: When I try to solve the non-homogeneous differential equation               DSolve[ y''[x] + y[x] == a Cos[2x] + b Cos[x] + c Cos[2x-3]+ d Cos[2x]^2-         6d Cos[2x]+9d + e Cos[x]^2+ fCos[x] Cos[3x]+h Cos[x]^2 Cos[2x-3] +i cos[x]^4, y[x], x]       I get a solution with squares of $\sin x$ and $\cos x$. I want to remove all the $\sin x$ terms from the solution and want to express the solution in terms of $\cos 2 x$ and $\cos 4x$. So what should be the input that will give the result that I want?


title: How to generate a matrix group?

text: I have three $7\times 7$ matrices (with real entries, lots of zeros) and I'd like to check if they generate a finite group (or, more precisely, if the group they generate is of precise order). Would it be possible to do with Mathematica? * * * These are the matrices. All of order 3. I expect this group to be of order 6048 or 12096.               gMatrix =        SparseArray[{{1, 3} -> 1, {2, 1} -> 1, {3, 2} ->           1, {4, 4} -> -(1/2), {4, 5} -> -(1/2), {4, 6} -> -(1/2), {4,            7} -> -(1/2), {5, 4} -> 1/2, {5, 5} -> -(1/2), {5, 6} ->           1/2, {5, 7} -> -(1/2), {6, 4} ->           1/2, {6, 5} -> -(1/2), {6, 6} -> -(1/2), {6, 7} -> 1/2, {7, 4} ->           1/2, {7, 5} ->           1/2, {7, 6} -> -(1/2), {7, 7} -> -(1/2), {_, _} -> 0}, 7];          hMatrix =        SparseArray[{{1, 5} ->           1, {2, 2} -> -(1/2), {2, 3} -> -(1/2), {2, 6} -> 1/2, {2, 7} ->           1/2, {3, 2} -> 1/2, {3, 3} -> -(1/2), {3, 6} -> -(1/2), {3, 7} ->           1/2, {4, 1} -> 1, {5, 4} -> 1, {6, 2} -> -(1/2), {6, 3} ->           1/2, {6, 6} -> -(1/2), {6, 7} ->           1/2, {7, 2} -> -(1/2), {7, 3} -> -(1/2), {7, 6} -> -(1/2), {7,            7} -> -(1/2), {_, _} -> 0}, 7];          kMatrix =        SparseArray[{{1, 4} -> -1, {2, 2} -> -(1/2), {2, 3} -> -(1/2), {2,            6} -> -(1/2), {2, 7} -> 1/2, {3, 2} ->           1/2, {3, 3} -> -(1/2), {3, 6} -> -(1/2), {3, 7} -> -(1/2), {4,            5} -> -1, {5, 1} -> 1, {6, 2} -> 1/2, {6, 3} ->           1/2, {6, 6} -> -(1/2), {6, 7} -> 1/2, {7, 2} -> -(1/2), {7, 3} ->           1/2, {7, 6} -> -(1/2), {7, 7} -> -(1/2), {_, _} -> 0}, 7];


title: Why will my plot not generate my entire plot?

text: I am trying to plot a sum of multiple `HeavisidePi` functions. A typical example would be something like this:               Plot[HeavisidePi[1/10 (-595 + x)] + HeavisidePi[1/10 (-535 + x)] +        HeavisidePi[1/10 (-425 + x)] + HeavisidePi[1/10 (-365 + x)], {x,        300, 800}, Exclusions -> None]      In this interval in the code above, I can see all four of them. However, if I were to back out to an interval of {100,800}, for instance, only two of them show up for me (the one at 595 and 425). Any idea why this would be the case? Any help would be greatly appreciated.


title: Solve f'[x]==0 for x

text: I tried the following:               f[x_] := x^n/(k + x^(2 n));     Solve[f'[x] == 0, x]      But I got the following response: > Solve::nsmet: This system cannot be solved with the methods available to > Solve. >> Any suggestions?


title: Solving a differential equation for a variable in a function

text: This may sound like a very trivial question, but I need to solve a differential equation as follows:               a := 3.24077*10^-20 (* km \[Rule] Mpc *)     b := 3.16888*10^-14 (* s \[Rule] MYear *)     c := a/b*(2.99792*10^5) (*Mpc/ MYear*)     \[HBar] := a^2/b (1.05457*10^-37)(*kgMpc^2/MYear*)     H0 := a/b*71 (*1/MYear*)     G := a^3/b^2*6.67398*10^-20 (*Mpc^3/(Kg*MYear^2)*)     \[CapitalOmega]M := 0.27     \[CapitalOmega]\[Gamma] := 8.24*10^-4     \[CapitalOmega]\[CapitalLambda] := 0.73     \[Lambda] := 1/a^2 1*10^-58(*1/Mpc^2*)     f := 1*10^-4     y := 10     \[Rho]pert[r_] := \[Rho]*(1 + f*Exp[-(r/y)^2]) // N     M2[r_] := 4 \[Pi]*Integrate[\[Rho]pert[r1]*(r1)^2, r1] /. r1 -> r     E2[r_] :=       1/2*((H[999]*r)/(c*(1000)))^2 - ((G *M2[r] (1000))/(        c^2 (r))) - (\[Lambda]*r^2)/(3 (1000)^2)     ScaleFactor2 =       NDSolve[SetPrecision[{(D[R2[r, t], t]) ==           Sqrt[(2*G*M2[r])/R2[r, t] + 2*c^2*E2[r] + (           2 c^2 \[Lambda]*R2[r, t]^2)/3], R2[r, 0] == r/1000}, 200],        R2, {r, 1, 20000}, {t, 1, 15000}, AccuracyGoal -> 2]     Rad2[r_, t_] := Evaluate[R2[r, t] /. ScaleFactor2]     RadPrime2[r_, t_] := D[Rad2[r1, t], r1] /. r1 ->  r     Raddot2[r_, t_] := D[Rad2[r, t], t]     ***chi = DSolve[(c Sqrt[1 + 2 E2[r]])/RadPrime2[r, t], r, t]***      I am looking for a solution for the differential equation chi, but would like an answer whose subject is the variable _r_ that appears in `RadPrime2[r,t]`. In other words, I am looking for the functional form of r(t)... I apologise in advance if this seems really badly phrased and/or trivial, but I couldn't find anything in the literature that helped...


title: Graphical representation of a moving sound source

text: Some explanation since I have got a specific and another more open-ended question: I used two microphones in a 90° arrangement (see picture below) to capture sound from a source moving around the room in a circular /elliptical fashion. The intention is to get an idea about directional hearing. (A second measurement with a KEMAR dummy-head was done as well). ![arrangement](http://i.stack.imgur.com/kHEKa.jpg) ![microphone arrangement](http://i.stack.imgur.com/pUUt9.jpg) I saved the measured data as .wav (48kHz) and imported the .wav file into _Mathematica_. (The .wav- file can be found here). That made a pretty long list - approximately 900000 entries per channel. Hence I used                dropfunction[data_, n_] :=       Table[Nest[Drop[#, {1, -1, 2}] &, data[[i]], n], {i, 1, 2}]       to reduce the resolution. I found by hearing/looking at `ListLinePlot` that `n = 7` is a good catch. That leaves around 7000 entries per channel. Here comes my first and very specific question: I plotted the absolute values of my list in a fashion like:               ListLinePlot[Abs@data[[1]], -Abs[data[2]]]      and got: ![left vs. right channel](http://i.stack.imgur.com/MLZtq.png) with left and right channel clearly divided along the x-axis. **Question 1:** Is there a possibility to flip the plot in such a way that x-axis becomes the y-axis? (So that for instance the "loudness" of the right channel is on the right hand side). I tried `PairedBarChart` actually gives the kind of representation I wish, but It is just not suitable for my data. **Question 2:** Does anybody else have a great idea how to graphically represent my data? I tried plotting the difference of the absolute values of both channels to get a graph showing which channel is currently louder at the positions in time/on my elliptical path. With some lowpass-filtering I got: ![enter image description here](http://i.stack.imgur.com/KSAux.png)


title: How to show a general graphic (not a Plot) inside a Manipulate

text: I'm building a little interface, which consists only of a button, as you can see here:               Button["File Input",        file = Import[SystemDialogInput["FileOpen"]];                  Print[principalFunction[file]]]      Now I'd like to insert the produced graphic and the button inside a `Manipulate`. Note that I'm not using Plot, Plot3D, etc. -- the graphics are produced by `principalFunction` as the final result of evaluating many other functions.


title: How do I access the binary matrix underlying an EdgeDetect output?

text: Applying `EdgeDetect` to an image generates a black and white edge-detected image, which I suspect corresponds to an underlying binary matrix. How can I access this underlying data structure, and map between a given matrix position and the corresponding coordinates in the processed image? Ideally, I'd just like a list of, say, the $1$'s or $0$'s in the matrix (whatever corresponds to the white lines in the edge-detected image) and their coordinates.


title: DateString and localization, $Language ignored

text: I have a `DateString` calculated in English. Now I would like to change the output according to localization. I have read that localization is possible for Menu, Messages and Cells. A simple `$Language = "French"` before calling `DateString` is ignored. Since this should be a basic feature for localization, I am wondering if my keywords for Google and SX are just plain wrong? Or is this feature not present?


title: How to format a large Number

text: There is a large number               a = 123456789012345678901234567.123456789012345678901234567        By format with AccountingForm               b = AccountingForm[a, 54]        it becomes               123456789012345678901234567.123456789012345678901234567        How to to parameterise the integer part and the fractional and the   n-digit precision part to produce a number. Like               int=123456789012345678901234567.       fra=.123456789012345678901234567       pre=54        resulting to the same outcome like b above? **UPDATE** A general solution was found.               int = 1234567890123456789012345678900;     fra = 123456789012345678901234567890;          SetPrecision[ToExpression[ToString[int] <> "." <> ToString[fra]],      StringLength[ToString[int]] + StringLength[ToString[fra]]]        is still a number,               1.234567890123456789012345678900123456789012345678901234567890*10^30        now look at it as a string with all digits minutely preserved               ScientificForm[%, ExponentStep -> StringLength[ToString[int]]]            1234567890123456789012345678900.123456789012345678901234567890


title: How to plot two sets of points in diferent colors with Epilog?

text: I want to plot two sets of poins (say, one in black and other in gray). How can do I this? I only obtain one set, and I don´t know how to use two colors in an Epilog option.               peaks[x_, y_] :=        3*(1 - x)^2*Exp[-(x^2) - (y + 1)^2] -          10*(x/5 - x^3 - y^5) Exp[-x^2 - y^2] - 1/3 Exp[-(x + 1)^2 - y^2];     ContourPlot[peaks[x, y], {x, -2, 2}, {y, -2, 3},        ColorFunction -> "DarkRainbow",        ContourLines -> False,        Contours -> 25,        LabelStyle -> {Bold, 20},        Epilog -> {Black, PointSize -> .036, Point[ {{0, 1}, {1, 1}, {1, 1.5}}]},        Epilog -> {Gray, PointSize -> .036, Point[ {{-1, 1}, {-1, 1}, {-1, 1.5}}]}]      * * * Before posting I tried any options, like               ContourPlot[peaks[x, y], {x, -2, 2}, {y, -2, 3},        ColorFunction -> "DarkRainbow",        ContourLines -> False,        Contours -> 25,        LabelStyle -> {Bold, 20},         Epilog ->         {{Black, Gray}, PointSize -> {.036, 0.36},          Point[{ {{0, 1}, {1, 1}, {1, 1.5}}, {{-1, 1}, {-1, 1}, {-1,1.5}}}]}]


title: Patterns of function-arguments in expressions

text: I want a function that compares an expression with a specific pattern. The expression has always the following form:               expr = F1[x1]F2[y1] + F1[x2]F2[y2] + F1[x3]F2[y3]      which is a sum of three terms, each term being the product of`F1[..]*F2[..]` with arbitrary arguments. Now what I need is a function that searches the arguments of the expression for a specific pattern. As an example, I want the following pattern: `x1! = x2`, `x1 == x3`, `y1 != y 2`, `y2 != y3`.               v = F1[a]*F2[b] + F1[c]*F2[d] + F1[a]*F2[e]; IsMyPattern[v] (*True*)     w = F1[a]*F2[a] + F1[c]*F2[c] + F1[a]*F2[e]; IsMyPattern[w] (*True*)     x = F1[a]*F2[b] + F1[a]*F2[d] + F1[a]*F2[e]; IsMyPattern[x] (*False, because x1 == x2*)     y = F1[a]*F2[b] + F1[c]*F2[d] + F1[f]*F2[e]; IsMyPattern[y] (*False, because x1 != x3*)     z = F1[a]*F2[b] + F1[c]*F2[b] + F1[a]*F2[e]; IsMyPattern[z] (*False, because y1 != y2*)      The only idea I have is to use `ToString` and apply string manipulations, but thats ugly and most likely slow. **Update** A followup question on the same issue: How can I make the IsMyPattern function more general, such that it matches inputs which have (complex) coefficients and different signs?               k = 2*F1[a]*F2[b] + F1[c]*F2[d] + F1[a]*F2[e]; IsMyPattern[k] (*True*)     l = F1[a]*F2[b] - F1[c]*F2[d] - F1[a]*F2[e]; IsMyPattern[l] (*True*)     m = I*F1[a]*F2[b] + 3*F1[c]*F2[d] - F1[a]*F2[e]; IsMyPattern[m] (*True*)      **Update2** The solution to this problem is remarkable simple, one just needs to add a BlankNullSequence. The function (for arbitrary number of arguments) looks like this:                IsMyPattern[expr_] := MatchQ[expr, ___ F1[x1__]*F2[y1__] + ___ F1[x2__]*F2[y2__] + ___ F1[x3__]*F2[y3__] /; {x1} =!= {x2} && {x1} === {x3} && {y1} =!= {y2} && {y2} =!= {y3}]


title: Solving a system of three differential equations

text: I'm trying to create this coloured graph which I'm going to animate, but I'm stuck with solving a system of three differential equations:               lista = (Sort@{{"Aleppo", 2}, {"Atarib", 2}, {"North Mount Simeon", 2},        {"South Mount Simeon", 2}, {"Al-Safirah", 2}, {"Afrin", 2}, {"Azaz", 2},        {"Al-Bab", 2}, {"Dayr Hafir", 2}, {"Manbij", 2}, {"Ayn Al-Arab", 2},        {"Jarabulus", 2}, {"Daraa", 2}, {"Izra", 2}, {"Al-Sanamayn", 2},        {"Abu Kamal", 2}, {"Mayadin", 2}, {"Deir ez-Zor", 2}, {"Al-Suqaylabiyah", 2},        {"Muhardeh", 2}, {"Masyaf", 2}, {"Hama", 2}, {"Salamiyah",2}, {"Al-Hasakah", 2},        {"Ra's al-'Ayn", 2}, {"Al Qamishli",2}, {"Al-Malikiyah", 2}, {"Homs", 2},        {"Al-Qusayr",2}, {"Talkalakh", 2}, {"Ar-Rastan", 2}, {"Al-Mukharram",2},        {"Palmyra", 2}, {"Harem", 2}, {"Idlib",2}, {"Jisr al-Shugur", 2},        {"Arihah", 2}, {"Ma'arrat al-Numan",2}, {"Latakia", -2}, {"Al-Haffah", -2},        {"Qardaha", -2}, {"Jableh", -2}, {"Quneitra", 2}, {"Fiq", 2}, {"Al-Raqqah", 2},        {"Tell Abyad", 2}, {"Al-Thawrah", 2}, {"Duma",2}, {"Markaz Rif Dimashq", 2},        {"Al-Tall", 2}, {"Al-Qutayfah",2}, {"Al-Nabk", 2}, {"Yabrud", 2},        {"Zabadani", 2}, {"Darayya",2}, {"Qatana", 2}, {"As-Suwayda", 2},        {"Shahba", 2}, {"Salkhad", 2}, {"Tartus", -2}, {"Duraykish", -2},        {"Al-Shaykh Badr", -2},{"Baniyas", -2}, {"Safita", -2}})[[All, 2]];          listb = (Sort@{{"Aleppo", 869}, {"Atarib", 2}, {"North Mount Simeon", 0},        {"South Mount Simeon", 0}, {"Al-Safirah", 0}, {"Afrin",3}, {"Azaz", 26},        {"Al-Bab", 14}, {"Dayr Hafir", 0}, {"Manbij",1}, {"Ayn Al-Arab", 0},        {"Jarabulus", 0}, {"Daraa",31}, {"Izra", 0}, {"Al-Sanamayn", 1},        {"Abu Kamal", 56}, {"Mayadin", 4}, {"Deir ez-Zor", 6}, {"Al-Suqaylabiyah",0},        {"Muhardeh", 0}, {"Masyaf", 0}, {"Hama",565}, {"Salamiyah", 1},        {"Al-Hasakah", 1}, {"Ra's al-'Ayn", 0}, {"Al Qamishli", 36}, {"Al-Malikiyah", 0},        {"Homs",1551}, {"Al-Qusayr", 1}, {"Talkalakh", 1}, {"Ar-Rastan",0},        {"Al-Mukharram", 0}, {"Palmyra", 26}, {"Harem", 0}, {"Idlib", 359},        {"Jisr al-Shugur", 0}, {"Arihah", 0}, {"Ma'arrat al-Numan", 0}, {"Latakia", 224},        {"Al-Haffah", 0}, {"Qardaha", 16}, {"Jableh", 3}, {"Quneitra", 22},        {"Fiq",1}, {"Al-Raqqah", 0}, {"Tell Abyad", 6}, {"Al-Thawrah",0},        {"Duma", 0}, {"Markaz Rif Dimashq", 0}, {"Al-Tall" ,0}, {"Al-Qutayfah", 0},        {"Al-Nabk", 0}, {"Yabrud",4}, {"Zabadani", 49}, {"Darayya", 27}, {"Qatana",8},        {"As-Suwayda", 0}, {"Shahba", 0}, {"Salkhad",0}, {"Tartus", 48},        {"Duraykish", 1}, {"Al-Shaykh Badr", 0}, {"Baniyas", 74}, {"Safita", 1}})[[All, 2]];          listc = (1 - lista);          eq = DSolve[{       x'[t] == #1*y[t]*z[t] - #2*x[t]*y[t],       y'[t] == #3*y[t] - #2*x[t]*y[t],       z'[t] == #1*(x[t] - y[t]),       x[0] == 219100,       y[0] == 287500,       z[0] == 1505920},       {x, y, z}, t] & @@@ Thread[{lista, listb, listc}]      I'm still receiving errors: ![enter image description here](http://i.stack.imgur.com/F32Oh.png) And ![enter image description here](http://i.stack.imgur.com/33B5K.png) EDIT: Okay, so I edited listb so that all the 0s became 1s. But now I get this error: ![enter image description here](http://i.stack.imgur.com/W4KyJ.png)


title: How to apply Robin boundary condition in Mathematica

text: Robin condition is the boundary condition which combines the Dirichlet and Neumann condition at the same boundary. For example: At the boundary x = 0 to 2: I want to apply `u[x] = 0` for `x = 0 to 1` and `du/dx = 0` for `x = 1 to 2`. I think one of the possible approach is reformulate the PDE discretization using the finite difference method, and manual apply the Robin boundary condition on the systems of ODE. Could we trick that for `DSolve`, `NDSolve`?


title: Why this numerical integration takes so long?

text: Let me explain the problem. I am trying to integrate a one dimensional integral: $$\int {g\left( {{k_x}},parameter1,parameter2,...\right)d{\mkern 1mu} {k_x}} $$ for the sake of clarity, I will give function `g` in the last. I choose a specific set of parameter, and do the following integration:               In:=NIntegrate[g[kx, 9, -2, 7, 1, 1, 0.05], {kx, -\[Pi]/3,\[Pi]/3}]//AbsoluteTiming          Out:={422.396160, 0.163126 + 0.103155 I}      This takes me 422s on my computer!!! I use the following code to show the sampling points used during the integration.               sampp = Reap[      NIntegrate[#, {kx, -\[Pi]/(3), \[Pi]/(3)},        EvaluationMonitor :> Sow[{kx, #}]]] &[     g[kx, 9, -2, 7, 1, 1, 0.05]] ;     {Length[#], ListPlot[#, AxesOrigin -> {0, 0}, Filling -> Axis]} &[      relist@sampp[[2, 2, 1]]]      ![sampling points](http://i.stack.imgur.com/Px5Qz.png) it shows that it used 733 sample points. But should that take 400 seconds? Actually, **the evaluation of the integrand at each sample point is acually fast.** I use the most simple interpolation method to do the same integration as below, I use 1000 sample points that is evenly distributed and it only takes 1.3 second. Besides the integration result is quite accurate.               In:=(sampp = Table[{kx,       g[kx, 9, -2, 7, 1, 1, 0.05]}, {kx, -\[Pi]/3, \[Pi]/3,       2 \[Pi]/3/1000}];     Integrate[     Interpolation[sampp, InterpolationOrder -> 2][     x], {x, -\[Pi]/3, \[Pi]/3}]) // AbsoluteTiming     Out:={1.308075, 0.163126 + 0.103155 I}      So what did _Mathematica_ do in the extremely long 400 second? Of course, it needs to do many error estimation, but that should not take too much time. I scan the documents and related questions in stackexchange. Somebody suggest to set "SymbolicProcessing"->0. OK, I tried               In:=NIntegrate[g[kx, 9, -2, 7, 1, 1, 0.05], {kx, -\[Pi]/3,     \[Pi]/3},      Method -> {"GlobalAdaptive", Method -> "GaussKronrodRule",      "SymbolicProcessing" -> 0}]//AbsoluteTiming     Out:={401.791981, 0.163126 + 0.103155 I}      unfortunately, the result is the same. Even more peculiar, when I use "Trapezoidal" strategy and limit the MaxRecursion                In:=NIntegrate[g[kx, 9, -2, 7, 1, 1, 0.05], {kx, -\[Pi]/3, \[Pi]/3},       Method -> "Trapezoidal", MinRecursion -> 1, MaxRecursion -> 4]     Out:={413.894674, 0.163126 + 0.103155 I}      the sample points shows as follows ![sample points2](http://i.stack.imgur.com/hXK0V.png) it only used 257 sample point, but the time cost is the same??!!It is unbelievable! Anyway, I think the "Trapezoidal" should be the same as evenly sample interpolation method. **I really can't understand what did _Mathematica_ do in the `NIntegrate` of function g. Can somebody explain it?** **Of course, it seems that I can use the simple interpolation integration method manually, because it is fast, and the result seems good in this case. But it is not robust, I insisted using the built in "Adaptive" strategy, because I have to Integrate some other functions which are sharp at specific points.** * * * In the last the form of function `g`               g[kx_, xx_, e_, width_, ii_, label_, \[Eta]_] :=      Inverse[(e - I \[Eta]) IdentityMatrix[2*width] -       armchairibbonmat[kx, width]][[2*(ii - 1) + label,      2*(ii - 1) + label]] E^(I kx xx)          (*armchairibbonmat is a function used in function g*)          armchairibbonmat[kx_, n_] :=     (     h = Table[0, {i, 1, 2 (n + 2)}, {j, 1, 2 (n + 2)}];     a[m_] := 2 m - 1;     b[m_] := 2 m;     t1 = 1;     aa = 1;     Do[     h[[b[i], a[i]]] = t1 E^(I kx aa);     h[[a[i], b[i]]] = t1 E^(-I kx aa);     h[[b[i + 1], a[i]]] = t1 E^(-I kx aa/2);     h[[b[i - 1], a[i]]] = t1 E^(-I kx aa/2);     h[[a[i - 1], b[i]]] = t1 E^(I kx aa/2);     h[[a[i + 1], b[i]]] = t1 E^(I kx aa/2);     , {i, 2, n + 1}];     h = ArrayPad[h, -2]     )


title: Orthonormalization of non-hermitian matrix eigenvectors

text: When using `Orthogonalize[]` one can specify which definition of "inner product" is to be used. For example, `Orthogonalize[vectors,Dot]` presupposes that all values are real. When dealing with non-hermitian matrices, the "inner product" definition (apparently) needs to be $|z|^2 = zz$, just like with real numbers. Consider this matrix:               mat = {{0. + 1.002 I, -1}, {-1, -I}}      The following code does not orthonormalize the eigenvectors of my matrix, as can be seen:               Orthogonalize[N[Eigenvectors[mat]]];     N[%[[1]].%[[2]]]          -2.90378*10^-15 + 0.999 I      The `Dot` option does not work, it presents me with an error > Orthogonalize::ornfa: The second argument Dot is not an inner product > function, which always should return a number or symbol. If its two numeric > arguments are the same, it should return a non-negative real number. which is not surprising, since I have complex entries. How can I force `Orthogonalize[]` to use the real number inner product definition, without `Dot`? _I'm using the words "inner product", but feel free to correct me as it seems they're not appropriate. Maybe I should say "involution"?_ **EDIT** As there's a bounty on this question, I'm leaving it open until the last day it's effective. Thanks for the answers. After talking with my supervisor, turns out we'll have to "manually" orthonormalize eigenvectors _that share the same eigenvalue_ , since the eigenvectors are otherwise already orthonormal, as in this case: ![Mathematica graphics](http://i.stack.imgur.com/zcPGN.png)


title: Pattern matching and HoldForm

text: Create rules based on data. I have a system that picks out on date,based on some rules. I then want to generate a new rule based on this date and apply the rule to a new dataset.               datePicked={{2008, 3, 21, 0, 0, 0.}}     rule=datePicked/. {t_, n_, o_, b___} :> HoldForm[{t, n, v_, b} /; v <= o];               d=DateRange[{2008, 2, 21, 0, 0, 0.`}, {2008, 3, 21, 0, 0, 0.`}]     Cases[d,#]&@@rule      Problem is that the rule I have made is not general, it has assigned the $ to v. How can I make it general?


title: How can I put an image on a surface

text: I want to paste an image on the surface of a 3D plot. For example consider this image ![](http://i.stack.imgur.com/5JpK4.jpg)which I want to paste on the surface of this sphere               ContourPlot3D[x^2 + y^2 + z^2 == 1, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, Mesh -> 1]      What will be the best way to do that? ## EDIT and Clarification My main objective is not to make a globe but to find a general way to use any arbitrary image on a surface. I choose the map and sphere just as an example (a popular one). `Texture` is a good option, but I find some difficulty to use it with `ContourPlot3D` or `Plot3D`. To make my point clear, I would request to show me an example with this image ![](http://i.stack.imgur.com/XVgk0.jpg) and the following surface,               Plot3D[Abs[x y], {x, -1, 1}, {y, -1, 1}]


title: How to import Mathematica folders into Workbench

text: I have been working with _Mathematica_ for a while and have accumulated a number of folders (not in _Workbench_ project form), each with a few files such as a .nb file, maybe a .m file, and their products (images etc.). I then acquired _Wolfram Workbench_ , and am up and running, and wish to transfer my existing folders to _Workbench_. If I try               File -> Import -> General -> Existing Projects into Workspace -> Next      and select the directory that contains my folders, the information up the top of the dialogue box says, "No projects are found to import". If I simply transfer my folders to the base _Workbench_ directory, they are not visible in the Package Explorer or Navigator even after pressing F5 (Refresh). Any ideas? * * * PS $\hspace{5mm}$ After experimenting a little more, I've discovered that I can go               File -> New -> Project -> Mathematica -> Basic Project      and create a project with the same name as the folder I wish to import; then paste the contents of my folder into the project folder. This is a work- around, but what I'd really like to do is import all of my existing folders into the base workspace and have _Workbench_ recognise them as projects (and create the necessary infrastructure around them if need be), without my having to faff around creating projects manually.


title: Transpose uneven lists

text: Is there a quick method to transpose uneven lists without conditionals? With:               Drop[Table[q, {10}], #] & /@ Range[10]      Thus the first list would have the first element of all the lists, the 2nd list would have all the 2nd elements of all the lists, etc. If there are no elements, skips. I have a feeling that this should incorporate Mathematica's Reap / Sow function, but unfamiliar.


title: Using Texture to color countries according to their timezones

text: So I'm trying to make a world map, where each country is colored according to its timezone. Except, for countries with multiple timezones, the country is filled with vertical stripes of colors corresponding to the various timezones.               colorstripes[zones_] :=        Graphics[MapIndexed[{#1, Rectangle[{#2[[1]], 0}]} &,          ColorData["Rainbow"][(# + 12)/24] & /@ zones]];     Graphics[{EdgeForm[Black],          Texture@colorstripes[CountryData[#, "TimeZones"]],          CountryData[#, "Polygon"]} & /@ CountryData["Countries"]]      ![does not work, everything is black](http://i.stack.imgur.com/o7mdD.png) Yet, my colorstripes function works: ![enter image description here](http://i.stack.imgur.com/4Z4DO.png) So, I am probably misusing `Texture` in a way, but as it does not give any warning or error, I'm kind of stuck. Do you see what's missing?


title: Notation for specifying transformation rules

text: I would like to have a compact notation for specifying conditions and results in transformation rules. Consider `ReplaceAll`:               r=ReplaceAll;          r[1, x_/;x>0:>-x]      (* -1 *)      I'd like to avoid writing `x_/;` and `:>`. Here is what I came up with:               Clear[f];     Attributes[f] = {HoldRest};     f[val_,cond_,res_] := val /. x_ /; cond :> res      I could only get it to work thus,               f[1, x$>0, -x$]      (* -1 *)      That expression may not even be robust, because I'm not sure that the pattern always gets renamed `x$`. But what I'm really after is a notation like this:               f[1, x>0, -x]      without the `$` on the `x`. It should work even if `x` is defined (hence the `HoldRest` `Attribute`): for this purpose `x` should be interpreted simply as a notational convenience. How can we do this? My motivation is now one of curiosity, to get a better understanding of how scoping works inside patterns. Initially I was setting up conditions on a problem, for which many different replacement rules were to be used on the same expression, and I was looking for ways to simplify the notation so as not to keep writing `/.`, `x_/;`, and `:>`.


title: How to plot Venn diagrams with Mathematica?

text: How does one plot Venn diagrams with Mathematica? I've searched quite a bit and I've found one source at MathWorld which provides the source code for doing them. But I don't understand this code, can someone help me?


title: Tab between elements in a GUI layout

text: If I have a bunch of input fields, I can tab between them quite conveniently, but if I want to navigate between the input fields and another element (in my case, a button), I have to click on the button manually. Is there any option or other code construct that would allow the user to tab out of an input field and takes the focus to the button? Ideally I could just press enter and the button would activate. A simple example:               Column[{       TableForm[{          Row[{           InputField[Dynamic@var, Number, ImageSize -> 150],            InputField[Dynamic@unit, String, ImageSize -> 150]         }]// Deploy       }],       Button["print", Print[#1] & [Quantity[var, unit]]]     }]


title: How do I sort complex numbers?

text: Okay, so I posted something about sorting, and it was linked as a duplicate to This post However, I am having problems trying to sort a list that contains both real and complex numbers. I put them into one big list and used `SortBy[]` but that does not sort the complex numbers as I want them to. Any ideas? I can post what code I am using if that helps. EDIT:: Data               A=      {{0.651301, 0.671298, -0.000107956 + 0.735512 I,        9.93642*10^-6 + 0.764605 I, 0.965926, 0.97048, 0.0344992 + 1.4214 I,        0.0028631 + 1.4505 I, -0.0626803 + 1.78014 I, -0.12443 + 1.98252 I,        0.167724 +         2.24691 I}, {{-6.79317*10^-6 - 2.8086*10^-6 I, -0.0000157028 +          0.0000511297 I, 0.000393492 + 0.0000998273 I,         0.000323404 - 0.00221263 I, -0.0140581 - 0.00161283 I,         0.00034936 + 0.0455525 I, 0.227164 - 6.59195*10^-17 I,         0.000350353 + 0.0494098 I, 0.0042655 - 0.0016156 I,         0.000351651 + 0.00161694 I, -2.50028*10^-6 -          0.0000297226 I, -0.0000277994 - 0.0000114935 I, -0.0000642597 +          0.000209235 I, 0.00161027 + 0.000408518 I,         0.00132345 - 0.00905464 I, -0.0575294 - 0.00660009 I,         0.00142967 + 0.186412 I, 0.929613 + 0. I, 0.00143373 + 0.202197 I,         0.0174555 - 0.00661145 I,         0.00143904 + 0.00661691 I, -0.0000102317 -          0.000121632 I}, {0.000325231 - 0.00225856 I, -0.0141806 -          0.00160866 I, 0.000361568 + 0.0454971 I,         0.220155 - 6.245*10^-17 I, 0.000362024 + 0.0494813 I,         0.00410192 - 0.00161389 I,         0.000363184 + 0.00165808 I, -6.77596*10^-6 - 0.000030037 I,         0.0000121624 + 0.0000262499 I, -1.0809*10^-6 + 2.11658*10^-8 I,         1.98638*10^-7 + 2.53517*10^-7 I,         0.00137179 - 0.00952634 I, -0.0598123 - 0.00678514 I,         0.00152505 + 0.191902 I, 0.92859 + 0. I, 0.00152698 + 0.208706 I,         0.0173014 - 0.0068072 I,         0.00153187 + 0.00699361 I, -0.0000285803 - 0.000126693 I,         0.0000512998 + 0.000110719 I, -4.55912*10^-6 + 8.92749*10^-8 I,         8.37833*10^-7 + 1.06931*10^-6 I}, {-0.00936005 - 0.00689504 I,         0.00194175 + 0.0457214 I, -0.0000294616 -          0.200724 I, -0.00204752 + 0.0455102 I,         0.00912273 - 0.00677289 I, -0.00206909 + 0.000712454 I,         0.000308104 + 0.000136869 I, -0.0000338275 - 0.0000413905 I,         6.69395*10^-8 + 6.60345*10^-6 I,         4.55605*10^-7 - 7.51471*10^-7 I, -8.81591*10^-8 + 3.57016*10^-8 I,         0.0318708 - 0.0432515 I, -0.211296 + 0.00894252 I,         0.927617 + 0. I, -0.210317 - 0.0094932 I,         0.0312938 + 0.042164 I, -0.0032911 - 0.0095625 I, -0.000632731 +          0.00142376 I,         0.000191303 - 0.000156301 I, -0.0000305169 + 3.04872*10^-7 I,         3.47251*10^-6 + 2.10602*10^-6 I, -1.6493*10^-7 -          4.07439*10^-7 I}, {-5.0264*10^-7 -          8.58797*10^-7 I, -2.37939*10^-7 + 7.30947*10^-6 I,         0.0000371583 - 0.0000443393 I, -0.000328693 + 0.00013847 I,         0.0021433 + 0.000752547 I, -0.00910293 - 0.00695052 I,         0.0021046 + 0.0453582 I,         2.50419*10^-6 - 0.192697 I, -0.00210251 + 0.0453522 I,         0.00910842 - 0.00696524 I, -0.00217144 + 0.000743651 I,         4.12576*10^-6 - 2.41481*10^-6 I, -0.0000351158 - 1.14264*10^-6 I,         0.000213015 + 0.000178511 I, -0.00066525 -          0.00157909 I, -0.00361522 + 0.0102968 I,         0.0333908 - 0.0437323 I, -0.217908 + 0.0101137 I,         0.925747 + 0. I, -0.217879 - 0.010098 I,         0.0334627 + 0.0437578 I, -0.00357275 -          0.0104319 I}, {-0.0000358944 + 0.000126095 I,         0.000744548 + 0.000168628 I,         0.000462218 - 0.00346567 I, -0.0160687 - 0.00154484 I,         0.000533786 + 0.0440688 I, 0.147403 + 6.93889*10^-17 I,         0.000538762 + 0.0497767 I, 0.00157728 - 0.00155399 I,         0.000527326 + 0.00215325 I, -0.000121227 - 0.0000164675 I,         0.0000226836 + 0.0000418986 I, -0.000217846 + 0.000765279 I,         0.00451873 + 0.00102342 I,         0.00280524 - 0.0210335 I, -0.0975223 - 0.00937576 I,         0.0032396 + 0.267458 I, 0.894604 + 0. I, 0.0032698 + 0.302099 I,         0.00957266 - 0.00943131 I,         0.00320039 + 0.0130683 I, -0.000735739 - 0.0000999426 I,         0.000137669 + 0.000254286 I}, {0.000740075 + 0.000166838 I,         0.000463177 - 0.00347749 I, -0.0160926 - 0.0015432 I,         0.000536526 + 0.0440383 I, 0.146592 - 1.38778*10^-17 I,         0.000541552 + 0.049773 I, 0.00153733 - 0.00155267 I,         0.000529806 + 0.00215943 I, -0.000123573 - 0.0000161104 I,         0.0000229325 + 0.0000423765 I, -4.68374*10^-6 + 1.27897*10^-6 I,         0.00451276 + 0.00101733 I,         0.00282432 - 0.0212047 I, -0.0981278 - 0.00940995 I,         0.00327157 + 0.268533 I, 0.893872 + 0. I, 0.00330223 + 0.303501 I,         0.0093742 - 0.00946775 I,         0.0032306 + 0.0131676 I, -0.000753512 - 0.0000982366 I,         0.000139836 + 0.0002584 I, -0.00002856 +          7.79878*10^-6 I}, {0.00919186 + 0.0428642 I,         0.00225897 - 0.0930717 I, -0.00582016 + 0.0395705 I,         0.00877203 - 0.00965772 I, -0.00354763 + 0.00153788 I,         0.000872782 + 0.000117415 I, -0.000154478 - 0.000120785 I,         0.0000131793 + 0.0000345226 I,         1.35683*10^-6 - 6.59455*10^-6 I, -7.61336*10^-7 + 8.03641*10^-7 I,         1.70839*10^-7 - 3.9198*10^-8 I, -0.380824 + 0.0913832 I,         0.831706 + 0. I, -0.354663 - 0.0434019 I,         0.0881538 + 0.0762489 I, -0.0145037 - 0.0313503 I, -0.00085944 +          0.0078202 I,         0.00104523 - 0.00140582 I, -0.000305462 + 0.000125187 I,         0.0000591896 + 0.0000106883 I, -7.34228*10^-6 - 6.62524*10^-6 I,         3.87106*10^-7 + 1.51725*10^-6 I}, {7.99461*10^-7 +          8.43966*10^-7 I, -1.30319*10^-6 - 6.8308*10^-6 I, -0.0000142133 +          0.0000348017 I,         0.000159864 - 0.000116815 I, -0.000870595 + 0.0000850061 I,         0.00342612 + 0.00169007 I, -0.00817676 - 0.00973414 I,         0.0032317 + 0.0383895 I,         0.000181951 - 0.0921798 I, -0.00259292 + 0.0392848 I,         0.00884829 - 0.0104629 I, -7.67732*10^-6 + 7.30127*10^-6 I,         0.0000622308 - 0.0000119998 I, -0.00031743 - 0.00012891 I,         0.0010675 + 0.00145486 I, -0.000790386 -          0.00793286 I, -0.0153412 + 0.0312552 I,         0.0885675 - 0.0746961 I, -0.349814 + 0.0301436 I,         0.840108 + 0. I, -0.358079 - 0.0229246 I,         0.0955152 + 0.0804529 I}, {-0.00253399 - 0.0719661 I,         0.0113022 + 0.0475596 I,         0.00389645 - 0.0167886 I, -0.00429156 + 0.00510902 I,         0.00166148 - 0.000734737 I, -0.000470727 - 0.0000705509 I,         0.0000855359 + 0.000066461 I, -7.33604*10^-6 -          0.0000215169 I, -9.97209*10^-7 + 4.33961*10^-6 I,         5.86732*10^-7 - 5.52976*10^-7 I, -1.38467*10^-7 + 2.36119*10^-8 I,         0.805934 + 0. I, -0.536402 + 0.107684 I,         0.186245 + 0.0501935 I, -0.0554538 - 0.0500129 I,         0.00756365 + 0.0188729 I,         0.000974495 - 0.00523727 I, -0.000777049 + 0.000930539 I,         0.000243554 - 0.0000735791 I, -0.0000481455 - 0.0000128628 I,         5.95393*10^-6 + 6.78033*10^-6 I, -2.09565*10^-7 -          1.55805*10^-6 I}, {-7.14387*10^-7 - 3.11508*10^-7 I,         2.34287*10^-6 + 3.33967*10^-6 I, -1.70002*10^-6 -          0.0000200966 I, -0.0000399888 + 0.0000837606 I,         0.000320663 - 0.000228999 I, -0.00148637 + 0.000164631 I,         0.00482644 + 0.00184217 I, -0.00988419 - 0.0106442 I,         0.0104973 + 0.0343516 I, -0.00368235 - 0.0586699 I, -0.0147028 +          0.0342975 I,         4.43882*10^-6 - 8.65524*10^-6 I, -0.0000434324 + 0.000026573 I,         0.000251662 - 5.46439*10^-6 I, -0.0010121 - 0.000563607 I,         0.00260183 + 0.00417338 I, -0.000888655 -          0.0186437 I, -0.0267204 + 0.0586804 I,         0.140318 - 0.114801 I, -0.436109 + 0.103903 I,         0.733702 + 0. I, -0.415733 - 0.20996 I}, {3.70775*10^-7 +          3.44736*10^-7 I, -5.72806*10^-7 -          2.43401*10^-6 I, -3.97703*10^-6 + 0.0000112541 I,         0.0000405196 - 0.0000326462 I, -0.000214321 + 0.0000263692 I,         0.000738563 + 0.000288755 I, -0.00162487 - 0.00211852 I,         0.00215028 + 0.00773783 I,         0.00384473 - 0.0174451 I, -0.0209518 + 0.0395755 I,         0.00377232 - 0.0505358 I, -4.47615*10^-6 + 5.59781*10^-6 I,         0.0000337592 - 0.0000106518 I, -0.000163074 - 0.0000442868 I,         0.000503592 + 0.000537642 I, -0.000598135 -          0.00299795 I, -0.00329824 + 0.0107312 I,         0.0281964 - 0.0251721 I, -0.106975 + 0.0385116 I,         0.250337 + 0.0358946 I, -0.580797 - 0.254086 I, 0.717427 + 0. I}}}      I want `A[[1]]` to be `{.9704,.9659,.67129,.6513,-.000107+.73i,.000000994+.76i,.0344+1.42i,....}` Sorry For the mess of data. I am trying to sort eigenvalues and keep the corresponding eigenvector with them


title: Another 3D plot question- good and ugly but no bad-

text: I have the following code with the intention to have a 3D plot:               f0[y_] :=1/(E^((1 + y)^2/2)*Sqrt[2*Pi])     f1[y_] :=1/(E^((-1 + y)^2/2)*Sqrt[2*Pi])          l[y_] :=f1[y]/f0[y]          t[x_] :=NIntegrate[f1[y]^x*f0[y]^(1 - x), {y, -Infinity, Infinity}]          epsilon0[x_] :=-Log[t[x]] + (x*NIntegrate[l[y]^x*f0[y]*Log[l[y]], {y, -Infinity, Infinity}])/t[x]          epsilon1[x_] :=-Log[t[x]] + ((-1 + x)*NIntegrate[l[y]^x*f0[y]*Log[l[y]], {y, -Infinity, Infinity}])/t[x]          Plot[epsilon0[x], {x, 0, 1}]     Plot[epsilon1[x], {x, 0, 1}]      I have the following figures ![enter image description here](http://i.stack.imgur.com/GWL05.jpg)! ![enter image description here](http://i.stack.imgur.com/q3CnX.jpg)! **Good:** > However I want to have a single graph probably a 3D plot for epsilon0, > epsilon1 and $x$ For example when $x=0.2$ we have $\epsilon_0=0.08$ and $\epsilon_1=1.28$ if I change $x\in[0,1]$ I will get a pair $(\epsilon_0,\epsilon_1)$ for each $x$ and this should be representable in 3D at least as points. But I couldt do it. **Ugly:** > What is the 3D figure if we allow **any** pair of continuous densities $f_0$ > and $f_1$ on $\mathbb{R}$ which have $D(f_0,f_1)=2$ and $D(f_1,f_0)=2$ where > $D$ is the relative entropy or KL divergence?


title: Why does the order of arguments in Show influence the result?

text: I am wondering why there is a difference in the results from evaluating the two expressions, which differ only in the order of the arguments given to `Show`. When I run               Animate[Show[spring[t], bob[t], traj], {t, 0, 20}]      the animation is different from               Animate[Show[traj, spring[t], bob[t]], {t, 0, 20}]      Parts of the plot get cut off, depending on the order of the arguments.


title: How to convert a spaceless data into tab delimited

text: I have a data set in form of:(this is just an example)               1324501020     3241030205     4332020134      the data are stored in a text file (e.g. data.txt) but I need to convert them into a matrix format such that each number be place in a cell like this:               1 3 2 4 5 0 1 0 2 0     3 2 4 1 0 3 0 2 0 5     4 3 3 2 0 2 0 1 3 4      or in terms of `List` in Mathematica, I need to have `{{1,3,2,4,5,0,1,0,2,0},{3,2,4,1,0,3,0,2,0,5},{4,3,3,2,0,2,0,1,3,4}}` in other words, the final data set supposed to be a matrix of numbers. Any idea??


title: Getting EPS imports to respect the original fill rule

text: One major problem in my attempt to answer to the CountryData flags question is that the way Mathematica handles filled curves differs from the way SVG and EPS style editors do. The latter two have the option to apply either of two rules, the non-zero rule or the even-odd rule, with the non-zero rule being default. The Windows .NET Framework 4.5 knows both rules too. Mathematica's`FilledCurve` doc page says: > Filled curves can be non-convex and intersect themselves. Self-intersecting > curves are filled according to an even-odd rule that alternates between > filling and not at each crossing. Unfortunately, since `Import` translates filled curve as a `FilledCurve` with this even-odd rule one gets a star that was efficiently coded in SVG with five points as follows:               Graphics[{Thickness[0.001388888888888889],            {FaceForm[{Blue, Opacity[1.]}],             FilledCurve[{{{0, 2, 0}, {0, 1, 0}, {0, 1, 0}, {0, 1, 0}}},                {{{366.902, 230.137}, {258.902,265.33599999999996},                  {326.105, 173.336}, {326.105,286.93799999999993},                  {258.902, 194.93800000000002}}}            ]}},             AspectRatio -> Automatic]      ![Mathematica graphics](http://i.stack.imgur.com/of7eu.png) (BTW: I would consider this behavior of `Import` a bug, as it doesn't respect the original's default setting.) Getting a star, filled as desired, takes twice as much points:               Graphics[{FaceForm[Blue],        Polygon@{{427.3, 183.3}, {401.5, 218.4}, {360.2, 204.8}, {385.7,           240}, {360, 275.2}, {401.5, 261.8}, {427.3, 296.6}, {427.2,           253.5}, {468.1, 240}, {427.2, 226.6}}}]      ![Mathematica graphics](http://i.stack.imgur.com/gyZZi.png) (and, of course, `Import` doesn't do this automatically.) > My question is: Is there a way to let `FilledCurve` behave according to a > non-zero rule, for instance using some undocumented properties like > discussed here and here? If not, would it be doable to automatically break > up a `FilledCurve` (that not necessarily contains only straight lines) into > separate entities that fill up the original shape as intended?


title: Metaquestion: how to find out why (e.g.) MatchQ[42, _?Function[x, True]] is False?

text: Suppose you run into a bewildering Mathematica result (which happens to me several times per Mathematica session, even after a 20-year acquaintance), such as, for example:               MatchQ[42, _?Function[x, True]]     False      So you go pore over the docs, but you still can't figure out an explanation. Then what? > What tool can one use to figure out why Mathematica's evaluation is > different from what one expects? PS. By sheer luck, I had read something a few days earlier that helped me figure out the answer to the one above, but I would have never guessed it without that prior hint. Yes, after knowing the answer I can zero in the place in the docs where the mystery is solved, but _only then_. This is why the documentation does not go as far in such situations as one would think: if one knew where in the documentation to look, one wouldn't have been puzzled by the original result in the first place. Here's a different hint: when completely nonplussed, what could be more fitting than to interrogate the documentation for ?


title: Web scraping and multi-threading in Mathematica

text: I'm working in some web scraping using Mathematica, and today, to speed-up the process, I used bash commands (xargs with parallel options with curl and wget) using `ReadList` or `Run`. I would like to do all this inside Mathematica, but I miss multi-thread capability with asynchronous evaluation. I could use more cores, but it's not the answer because the lag is due to time lag, not lack of processor capacity. In bash I can do things like:               cat url.txt | xargs - n1 - P20 wget      Even with 4 cores it distribute the download process in 20 processes. In Mathematica I can do this:               data = ParallelMap[Import,urlList]      But you get limited to cores number. I thought that it would be natural to be multi-threaded if Mathematica is able to use multiple cores. Any clues?


title: RevolutionPlot3D of 4 piecewise functions around X-axis crashing mathematica

text: I'm trying to rotate 4 piecewise functions around the X-axis using `RevolutionPlot3D`. The 4 functions I have are:               bottom[x_] := Piecewise[{{{2 + x - x^2/6}, 0 <= x < 3}}, Indeterminate]     side[x_] := Piecewise[{{7/2, 3 <= x < 15}}, Indeterminate]     top[x_] := Piecewise[{{{37/2 - x}, 15 <= x < 17}}, Indeterminate]     neck[x_] := Piecewise[{{3/2, 17 <= x <= 20}}, Indeterminate]      If I try to rotate all of these around the X-axis using `RevolutionPlot3D`, I get errors:               RevolutionPlot3D[{{bottom[x]}, {side[x]}, {top[x]}, {neck[x]}}, {x, 0, 20},                      AxesLabel -> {"x", "y", "z"}, RevolutionAxis -> {1, 0, 0}]      This gives me > Dot::rect: Nonrectangular tensor encountered. errors. This has worked previously with other functions. I tried only the straight lines one for debugging, that is `side` and `neck`:               RevolutionPlot3D[{{side[x]}, {neck[x]}}, {x, 0, 20},       AxesLabel -> {"x", "y", "z"}, RevolutionAxis -> {1, 0, 0}]      But this actually crashes the _Mathematica_ kernel. Any ideas how I get _Mathematica_ to show a revolution plot around the X-axis of these 4 functions?


title: Optimization in Mathematica

text: There is a R package called TIMP. By this package someone can fit data to a model. There is a GUI for TIMP called Glotaran. When I fit my data by this package it does not take so much time to get the answer which is consisted of lifetimes and amplitudes of the fluorescence spectra of a sample. However, when I try to do the same thing by Mathematica, doing a global analysis-> fitting different data sets to different models which have some parameters in common such as lifetime here, it takes so longer and Mathematica eats a huge chunk of RAM, at the bottom line Mathematica is not as fast as TIMP. I want to know that why this happens? Is it due to being written in Mathematica language? or Is it that TIMP package use a different algorithm? My objection is that I would expect Mathematica to do a much better job because 1- It is supposed to do heavy mathematical operations 2- It is expensive so I expect much higher quality Personally, I considered Mathematica a tool to do various heavy computations. What is the point of putting so much energy and time to mastering Mathematica if I have to learn other more specialized software to achieve my goal?


title: Second Order Non Linear Differential Equation

text: I'm trying to solve the following differential equation numerically:               s = NDSolve[{           (z + 2 r[z] r'[z]) (1 + r'[z]^2) -z r[z] r''[z] == 0,            r[0.01] == 0.0001,            r'[0.01] == 10          },           r, {z, 0.01, 10}         ]      But, when I set the initial condition to $z=0$, there are singularities, so I tried to set it as 0.01. Also, for $r(z=0.01)=0$ there is a singularity, so I set $r(z=0.01)=0.0001$. However, when I try to solve the equation for any value that I put in the boundary conditions, I'm getting "step size is effectively zero; singularity or stiff system suspected." Is there any method to sort this out?


title: Why does Equal["string", False] not evaluate to False?

text: Why does `Equal["string", False]` not evaluate to `False`? I would have thought _Mathematica_ could prove that these two things are not equal.


title: Getting error FullSimplify::infd: ... simplified to ComplexInfinity

text: I tried to run the following code:               FullSimplify[(4*          Pi*(-(r*(1 + r)^2*               Sqrt[-(((1 + r)^4 + (-1 + r^2)^2 -                      2*(1 + r)^2*(1 + r^2))/(r^2*(1 + r)^2))]) +             3*(1 + r)^3*ArcCos[(-1 + r^2 + (1 + r)^2)/(2*r*(1 + r))]))/        9 - (4*Pi*(-((1 - r)^2*r*               Sqrt[-(((1 - r)^4 + (-1 + r^2)^2 -                      2*(1 - r)^2*(1 + r^2))/((1 - r)^2*r^2))]) +             3*(1 - r)^3*             ArcCos[(-1 + (1 - r)^2 + r^2)/(2*(1 - r)*r)] + (r*                Sqrt[(1 - r)^2/(1 + r)^2]*                Sqrt[-(((-(1 - r)^2 + (-1 + r)^2)*(-(1 - r)^2 + (1 +                          r)^2))/r^2)]*                EllipticF[                 ArcSin[Sqrt[2 + (1 - (1 - r)^2)/r + r]/                   2], (4*r)/(1 + r)^2] -                2*r^3*Sqrt[(1 - r)^2/(1 + r)^2]*                Sqrt[-(((-(1 - r)^2 + (-1 + r)^2)*(-(1 - r)^2 + (1 +                          r)^2))/r^2)]*                EllipticF[                 ArcSin[Sqrt[2 + (1 - (1 - r)^2)/r + r]/                   2], (4*r)/(1 + r)^2] +                r^5*Sqrt[(1 - r)^2/(1 + r)^2]*                Sqrt[-(((-(1 - r)^2 + (-1 + r)^2)*(-(1 - r)^2 + (1 +                          r)^2))/r^2)]*                EllipticF[                 ArcSin[Sqrt[2 + (1 - (1 - r)^2)/r + r]/                   2], (4*r)/(1 + r)^2] + ((7*I)*                  Sqrt[1 - (1 - r)^2/(-1 + r)^2]*(1 - r)*(1 + r)^2*                  Sqrt[1 - (1 - r)^2/(1 + r)^2]*(EllipticE[                          I*ArcSinh[(1 - r)*                        Sqrt[-(-1 + r)^(-2)]], (-1 + r)^2/(1 + r)^2] -                     EllipticF[                     I*ArcSinh[(1 - r)*                        Sqrt[-(-1 + r)^(-2)]], (-1 + r)^2/(1 + r)^2]))/                Sqrt[-(-1 + r)^(-2)] + (I*                  Sqrt[1 - (1 - r)^2/(-1 + r)^2]*(1 - r)*r^2*(1 + r)^2*                  Sqrt[1 - (1 - r)^2/(1 + r)^2]*(EllipticE[                     I*ArcSinh[(1 - r)*                        Sqrt[-(-1 + r)^(-2)]], (-1 + r)^2/(1 + r)^2] -                     EllipticF[                     I*ArcSinh[(1 - r)*                        Sqrt[-(-1 + r)^(-2)]], (-1 + r)^2/(1 + r)^2]))/                Sqrt[-(-1 + r)^(-2)])/((1 - r)^2*r*               Sqrt[-(((1 - r)^4 + (-1 + r^2)^2 -                      2*(1 - r)^2*(1 + r^2))/((1 - r)^2*r^2))])))/9,       0 < r < 1 && r \[Element] Reals]      I cannot figure out what is wrong here. All the denominator pose no problems. Square root and Elliptic functions and Arc trig functions should not be able to produce complex infinity. Yet every time I run it will produce a warning and result in ComplexInfinity. The warning look like this:               FullSimplify::infd:Expression 4/9 π (-r (1+r)^2      Sqrt[-((Power[<<2>>]+Power[<<2>>]+Times[<<3>>])/(r^2 Plus[<<2>>]^2))]+3 (1+r)^3      ArcCos[(-1+Power[<<2>>]+Power[<<2>>])/(2 r Plus[<<2>>])])-4/9 π (-(1-r)^2 r      Sqrt[-((Power[<<2>>]+Power[<<2>>]+Times[<<3>>])/(Plus[<<2>>]^2 r^2))]+3 (1-r)^3      ArcCos[(-1+Power[<<2>>]+Power[<<2>>])/(2 Plus[<<2>>] r)]+<<1>>/((1-r)^2 r      Sqrt[-((Power[<<2>>]+<<1>>+<<1>>)/(<<1>>^2 r^2))])) simplified to ComplexInfinity. >>      (I got an error if I try to convert to input form, so I have to paste that as plain text; but in any case, all the <<1>> and <<2>> seriously obscure where the error are occurring) I am unable to simplify this on my own. I hope you can help. Thank you very much.


title: Possible bug: SparseArray Part assignment loses default value?

text: This sure looks like a bug to me (Mathematica 10.0.0, MacOS):               (Local) In[345]:= s = SparseArray[{}, {20}, 1]          (Local) Out[345]= SparseArray[< 0 >, {20}, 1]          (Local) In[346]:= s // Normal          (Local) Out[346]= {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}          (Local) In[347]:= s[[All]] = 1; s          (Local) Out[347]= SparseArray[< 0 >, {20}]          (Local) In[348]:= s // Normal          (Local) Out[348]= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}      Apparently when I assigned 1 to all elements of s, it correctly realized that everything was still equal to the default, so left everything unspecified. But it incorrectly lost the 1 default value and changed the array to have the default default value of 0. This is a toy example, but it comes out of a more complicated example in which it is causing me a serious problem. I don't know the full scope of the problem, but it is not necessary to assign to the entire array for the default value to be lost. I guess the lesson is that non-zero defaults are fragile. Is this really a bug, or am I missing something obvious?


title: Truncate High order terms

text: Suppose I want to compute this : `Series[Sin[1/f], {f, Infinity, 10}]` but finally I prefer `Sin[1/f]` up to the fourth order in `1/f`. How can I do this ? My first idea was to use the `O[]` function but it didn't work because `1/f is not a valid variable`. My second idea was to use firstly `/. f -> 1/eps` and then `O[eps]^4` but it didn't work as well... Note also that, for many reasons, `Series[Sin[1/f], {f, Infinity, 4}]` is not a solution to me !


title: Why do images in a PopupMenu sometimes make a program load sluggishly?

text: In a demonstration, I would like to display a `PopupMenu` with a list of small PDF images, each weighing in at approximately 50k. The code of interest is below: ![PopupMenu](http://i.stack.imgur.com/uBuWR.png) After hitting `Shift`+`Enter`, the demo requires 25 seconds before being ready to operate. However, once it is ready, it works responsively, without hesitation. A simple list of numbers in the `PopupMenu` works much better:               {{s, 2, ""}, Range[12], PopupMenu, ControlPlacement -> Bottom}      One second or so after hitting `Shift`+`Enter`, the demo is ready to go. I realize that I could save some memory by using images with smaller footprints (e.g. moving to 8-bit or even 1-bit images), but there may be other things I should be considering to increase the efficiency of `PopupMenu`. Any suggestions would be appreciated. * * * **Update** Image file size was not the culprit in this case. It turns out that some of my PDF images were not in a format fully acceptable to Mathematica. When halirutan was able to quickly import and display large PDF files using my code (but adding the additional burden of importing), I decided to use his code to import my large files. Mathematica refused to import several of my files as `Images`, using the routine Halirutan included in his response. However, Mathematica does allow those same files to be imported via the menu via "Insert/Picture/From file". Because MMA had accepted all my images when I manually inserted them into the `Popupmenu` control (as shown above), and because it displayed them correctly (albeit after an initial delay), I did not suspect that some of the files (but not others) were in a format uncongenial to MMA. It accepted the corrupt files and "reluctantly" figured out how to display them properly in the PopupMenu control. So halirutan provided the essential resources that turned out to be instrumental for solving the issue. * * * **Update 2** Neither .pdf nor .png graphics files produced from OmniGraffle Pro (v. 5.3.6) can be successfully imported by Mathematica via the `Import[..., "Images"]` command. However GraphicConverter (v. 7.2) can import either of these. While in GraphicConverter, simply "saving as" a .png file from OmniGraffle to .pdf will produce a file that can then be imported by Import into Mathematica. That file will have a white background even if the original .png file had a transparent background. But the important thing is that MMA will accept it readily. By the way, by making my PDF's this way, they turn out to be 7k in size.


title: Manipulate BarChart with Mathematica

text: In the following minimal working example:               Manipulate[BarChart[{a,b}],{a,1,2},{b,1,2}]      I'd like to be able to control the size of the bars by using some sort of `Locator` property for manipulate i.e. change the vertical size of each bar by placing my mouse on the edge of the bar (ideally anywhere along its width). Obviously, `Locator` won't work. Any ideas how to easily do this? I want the value of the bar chart to dynamically update. In the above example, I would have `a, b` obey some constraint (like `a + b = 2` so whenever one changes the other does so accordingly). \-------- Answered -------- This was so that there's some playing with the Greek general election. I wanted to play with the latest poll results and vary them before the election on Sunday. @Mike Honeychurch: You are right, barspacing doesn't change the locator positioning but the locators are off center like so (this is my output when I run your code): ![Mikes](http://i.stack.imgur.com/p3XcT.png) I assume you run a different version of Mathematica than me - I run 7, sorry, should have said so. So, I had to fiddle with the x-coordinates of your locators in some way like this when defining `pt`: `numberofpoints = 5; barspacing = 0.1; xcoords = Table[i + barspacing i - 1/2, {i, 1, numberofpoints}]; pt = xcoords~Riffle~RandomInteger[{0, 3}, 3]~Partition~2` I got the chart to look OK at the end (locators here for only the first three bars): ![Mikes to mine](http://i.stack.imgur.com/q7Miz.png) but wasn't entirely happy with the way it was done because of the fiddling I mentioned above. So I am going with @Heike 's approach that works a treat out of the box exactly the way I wanted:               lastpoll = {{LightBlue, 24.3, "ΝΔ"}, {Green, 15.4, "ΠΑΣΟΚ"}, {Red, 10.9, "ΚΚΕ"},      {Yellow, 8, "ΔΗΜΑΡ"}, { Pink, 9.5, "ΣΥΡΙΖΑ"}, {Blue, 9.6, "Αν. Ελληνες"},     {Gray, 6.3, "Χρυση Αυγη"}, {LightBlue, 4.2, "ΛΑΟΣ"}, {Green, 4.4, "Οικολογοι"},      {LightCyan, 2.1, "Δημ. Συμμαχια"}, {Yellow, .8, "ΕΠΑΜ"}, { LightRed, .8, "ΔΡΑΣΗ"},     {Blue, .8, "ΑΝΤΑΡΣΥΑ"}, {LightGray, .8, "Κοιν. Συμφωνια"}, {White, 2, "Λοιπα"}};     values = #[[2]] & /@ lastpoll;     dragBar[values,      ChartLabels -> Placed[(Last /@ lastpoll), Axis, Rotate[#, 55 Degree] &],     ChartStyle -> (First /@ lastpoll), BarSpacing -> .6, ImageSize -> Large]      with the following result (all fiddlable): ![enter image description here](http://i.stack.imgur.com/Pnoct.png) In any case, thank you all for taking the time. This was harder than I expected it would be..


title: Plot a real part of complex equation depending on a parameter

text: I would ask you to kindly provide me a way to solve this problem in mathematica way. Let the equation $z^2 + 9 -1.5 e^{- t z}=0$ where $z\in \mathbb C$ and $t\in \mathbb R^+$. In order to plot graph of $t \mapsto \mathrm{Re}(z)$, I have triyed this:               f[z_] = z + 9  - 1.5 E^(- t z)          z = x + I y           ExpToTrig[       E^(-t (x + I y)) (-1.5 + 9. E^(t (x + I y)) + E^(t (x + I y)) x +          (0. + 1. I) E^(t (x + I y)) y)]      > >     (0. + 0. I) - 1.5 Cosh[t x + I t y] + 9. Cosh[t x + I t y]^2 + >       x Cosh[t x + I t y]^2 + (0. + 1. I) y Cosh[t x + I t y]^2 + >       1.5 Sinh[t x + I t y] - 9. Sinh[t x + I t y]^2 - >       x Sinh[t x + I t y]^2 - (0. + 1. I) y Sinh[t x + I t y]^2 >                 TrigExpand[(0. + 0. I) - 1.5 Cosh[t x + I t y] +         9. Cosh[t x + I t y]^2 +         x Cosh[t x + I t y]^2 + (0. + 1. I) y Cosh[t x + I t y]^2 +         1.5 Sinh[t x + I t y] - 9. Sinh[t x + I t y]^2 -         x Sinh[t x + I t y]^2 - (0. + 1. I) y Sinh[t x + I t y]^2]      > >     (9.` + 0.` I) + x + (0.` + 1.` I) y - >       1.5` Cos[t y] Cosh[t x] + (0.` + 1.5` I) Cosh[t x] Sin[t y] + >       1.5` Cos[t y] Sinh[t x] - (0.` + 1.5` I) Sin[t y] Sinh[t x] >   In the last I can't do Real part. Any help is welcome.


title: Does the VerticalCallout algorithm in PieChart3D work correctly?

text: In real world usage you often want to use real world labels with long strings (say 15-20 characters) in 3D pie charts. Here is a toy example :               Clear[labeler];     labeler[datax_][v_, {1, c_}, ___] :=        Placed[Column[{datax[[c]], v}, Alignment -> Center,          BaseStyle -> Directive[FontFamily -> "Arial", 11]],         "VerticalCallout"];     data = Transpose[{"This is label " <> ToString[#] & /@ Range[14],          Range[14]}];          PieChart3D[{data[[All, 2]]},      ChartElementFunction ->        ChartElementDataFunction["ProfileSector3D", "Profile" -> 4],      ChartStyle -> 54,      ImageSize -> 400,      LabelingFunction -> labeler[data[[All, 1]]],      PerformanceGoal -> "Speed",      PlotRange -> All,      SectorOrigin -> {Pi, 0},      SectorSpacing -> 0.2]      ![enter image description here](http://i.stack.imgur.com/WLUDT.png) We see that the plot area seems to have been determined without reference to the labels that will be placed around the chart. Consequently the labels are cut off. Q. Is this an `Image Padding` issue? A. no (note that `All` gives the same output as `Full`) ![enter image description here](http://i.stack.imgur.com/nixbd.png) Q. So why not expand the margins around the image to give the labels enough space to be rendered? ![enter image description here](http://i.stack.imgur.com/5ooGc.jpg) So increasing the image margins merely creates another graphics area around the original image. This looks like a bug or design flaw to me. Does anyone have any ideas about how to get `VerticalCallout` labels working in `PieChart3D`?


title: Area between Contours in ContourPlot

text: I feel slightly foolish for asking this because I am so close, but I'm having trouble, so I will anyway. I asked this question two days ago regarding finding the lengths of contours. Now, I'd like to find the areas between them. I have read and played around with the information here, here and here, but am having difficulties. ![The contour plot looks something like this...what are the areas?!](http://i.stack.imgur.com/TdjKk.jpg) Having extracted the individual contours of `f[x,y]` via the method given by chris, I would like to find the areas bounded by the contours and the plot region. Is there a simple way to do this? For reference, I am using the contour plot of the following function:               q[r_] := Piecewise[{{25/(0.1*1), r < 0.1}, {25/r, r >= 0.1}}]     phi[r_, t_] := (Pi/2) + q[r]*t     v[r_, t_] := q[r]*r*Cos[phi[r, t]]     s[x_] := Piecewise[{{x = -1, x < 0}, {x = 1, x >= 0}}]          f[x_,y_] := s[x]*v[Sqrt[x^2 + y^2],ArcTan[y/x]/q[Sqrt[x^2 + y^2]]]          ContourPlot[f[x, y], {x, -1, 1}, {y, -1, 1}, RegionFunction -> Function[{x, y}, x^2 + y^2 <= 1],      PlotPoints -> 100, Contours -> Range[-25, 25, 1]]


title: Mathematica 10 crashes when kernel is quit from MenuItem

text: I'm actively developing a large codebase that I load every time I use _Mathematica_. I frequently quit my kernel and reload the codebase to incorporate new changes. I've created a custom menu by editing `MenuSetup.tr` to include menu items and keyboard shortcuts that allow me to quit the kernel and reload my codebase quickly and easily. Unfortunately, the 'Quit' functionality no longer works in _Mathematica_ 10\. Both the `"EvaluatorQuit"` `FrontEndToken` and manually running `KernelExecute[ToExpression["Quit[]"]]` from a `MenuItem` cause the FrontEnd to crash (the code used in my `MenuItem` is derived from this thread). The same bits of code work fine when run directly from the FrontEnd. There clearly still exists a viable method of quitting a kernel from a menu, because the 'Quit Kernel' submenu in the 'Evaluation' menu still functions fine without crashing the FrontEnd. Unfortunately, the way this is done seems to be hidden behind the `"MenuListQuitEvaluators"` token used to generate that submenu. Any advice on how to get around this bothersome crashing behavior would be most welcome.


title: Exhaustive examples of variable replacement due to nested scoping constructs

text: Consider the following examples, where I have replaced dollar signs in the output by a D.               3/.x_:> Rule[var_,x]     3/.x_:> RuleDelayed[var_,x]     3/.x_:> Function[var, x]     3/.x_:> Hold[Compile[{var, _Integer}, x]]     3/.x_:> Hold[SetDelayed[var_, x]]     3/.x_:> Hold[Set[var_,x]]     3/.x_:> Hold[TagSet[2,var_,x]]     3/.x_:> Hold[UpSet[var_,x]]     3/.x_:> Hold[UpSetDelayed[var_, x]]     3/.x_:> Hold[TagSetDelayed[2, var_, x]]     3/.x_:> Hold[With[{var=b},x]]     3/.x_:> Hold[Module[{var=b},x]]          (*not Block*)     (*3/.x_:> Hold[Block[{var=b},x]]*)     (*not DynamicModule*)     (*3/.x_:> ToString@Hold[DynamicModule[{var=b},x]]*)     (*not the Table family*)     (*3 /. x_ :> Hold[Table[x, {var, 5}]] *)          Function[x,Condition[var_,x]][3] (*ReplaceAll interacts with Condition, so I use Function*)          (*not RuleCondition*)     (*Function[x, Hold[RuleCondition[var_, x]]][3]*)      > >     varD_->3 >     varD_:>3 >     Function[varD,3] >     Hold[Compile[{varD,_Integer},3]] >     Hold[varD_:=3] >     Hold[varD_=3] >     Hold[2/:varD_=3] >     Hold[varD_^=3] >     Hold[varD_^:=3] >     Hold[2/:varD_:=3] >     Hold[With[{varD=b},3]] >     Hold[Module[{varD=b},3]]   >     varD_/;3 >   and these ones               {"Replace",Replace[3,x_:> Rule[var_, x]]}     {"ReplaceAll",ReplaceAll[3, x_ :> Rule[var_, x]]}     {"ReplaceRepeated",ReplaceRepeated[{3},{x_Integer}:> Rule[var_, x]]}     {"With",With[{x=3},Rule[var_,x]]}     {"Module",Module[{x=3},Rule[var_,x]]}     (*not Block*)     (*{"Block",Block[{x=3},Rule[var_,x]]}*)     {"DynamicModule",ToString[DynamicModule[{x=3}, Rule[var_,x]],InputForm]}     (*The example below works for any "assignment function" (Set)*)     Clear[f]     {"Replacement by evaluation",Set[f[x_],RuleDelayed[var_,x]],f[3]}     (*not Function with Slots*)     (*Function[Rule[var_,#]][3]*)     {"FunctionNamedArg",Function[x,Rule[var_,x]][3]}      > >     {Replace,varD_->3} >     {ReplaceAll,varD_->3} >     {ReplaceRepeated,varD_->3} >     {With,varD_->3} >     {Module,varD_->3} >     {DynamicModule,DynamicModule[{x = 3}, varD_ -> 3, DynamicModuleValues :> > {}]} >     {Replacement by Evaluation, var_:>x, varD_:>3} >     {FunctionNamedArg,varD_->3} >   A general explanation of such examples can be found in the Q&A called "Enforcing correct variable bindings and avoiding renamings for conflicting variables in nested scoping constructs", in this answer. However I felt a bit more could be said about this. The first list of examples basically lists all functions that could be considered "inner scoping constructs". The "inner scoping constructs" are searched for by "outer scoping constructs" in their bodies. The outer scoping constructs are listed in the second set of examples. Note that in the second list of examples there is an example with `Set`, labeled "Replacement by Evaluation". This example is different from the others, in that it is not `Set` here that is the function that looks for scoping constructs in its body. Rather, it appears that whenever the kernel evaluates an expression `x`, it emulates searching for scoping constructs in `x`. The kernel already does a lot of this kind of bookkeeping, so maybe this is why it is not a big performance hit. In the example we use `Set`, but it appears that any definition made using "assignment functions" (`SetDelayed`, `Set`, `TagSet`, `UpSet`, `TagSetDelayed`, `UpSetDelayed`) will cause replacement of such variables. This replacement will happen for definitions corresponding to `DownValues`, `UpValues` as well as `SubValues`. It cannot happen for definitions that correspond to `OwnValues` as it is not possible to create an `OwnValues` with a pattern on the LHS of the (generated) rule. I think interaction between inner and outer scoping constructs depends on the combination of the scoping constructs in a kind of independent manner. I.e. all the outer scoping constructs have the same strategy for to resolve a conflict between a local variable and the second argument of `Rule`. If this is true, all the interaction between inner and outer scoping constructs can be illustrated with only a few examples. I would consider the list to be exhaustive if all the cases where variable replacement happens can be predicted from the list, because all inner and outer scoping constructs are present. **Question** Are my examples exhaustive? **Related** StringReplace, ReplaceAll and Rule interact in a bizarre way (answer by Leonid)


title: What is the correct way to use specific rule for specific pattern match when parsing an expression?

text: **update:** Thanks for the answers below. But I noticed they do not handle the following special cases: `lis=1` and `lis=z` , `lis=1/z` and `lis=-z` as these are also considered legal input as given in the question below. It is easy to add special case processing for these, by making them `lis={1}` and `lis={z}` etc... before calling the parser (this is what I actually had to do myself). but it will be nice if this was incorporated as special pattern/rule as well. I could not do it myself inside `Alternative` and had to check for this before as special case. To make sure what is the input, I'll clarify it again: Each term is of the form `c*z^n` where there can be _one or more terms_. i.e. `lis= term1+term2+term3...` In each term, `c` can be any numerical value, and `n` can be any numerical value (positive or negative). The result will be list of `{{c,n},.....}`, one entry for each term. Even if there is one term only, it should work. Examples to verify against:               lis=1   --->  {{1,0}}     lis=z ----> {{1,1}}     lis=-z --->{{-1,1}}     lis=1/z  ---->{{1,-1}}     lis=1+z^-1 --->{{1,0},{1,-1}}     lis=1/z^3 + 3/z + 3 z + z^3 -->{{1,-3},{3,-1},{3,1},{1,3}}     lis=6 + 1/z^4 + 4/z^2 + 4 z^2 + z^4 -->{{6, 0}, {1, -4}, {4, -2}, {4, 2}, {1, 4}}      **Original question** The hammer I use now for everything I see that needs parsing with patterns is `Cases`. So, I was trying to write a simple pattern based parser that accepts any output from `Expand(f[z])` where `f[z]` is rational function of `z` only. For example, it take such input as               Expand[(z + 1/z)^4]     (*6 + 1/z^4 + 4/z^2 + 4 z^2 + z^4*)      or               Expand[(z + 1/z)^3]     (*1/z^3 + 3/z + 3 z + z^3*)      or `1` or `z` or `z^-1` or `1+z` and so on. So the input can be thought of as power series in `z`. All terms are in this form. So it is well defined what it is. The output of the parser will be a list that shows the coefficient of each term, and the exponent of `z`. So given the input `6+(1/z^4) + 4/z^2 + 4 z^2 + z^4` the output will be                {{6,0},{1,-4},{4,-2},{4,2},{1,4}}      The best I can come up with is this:               lis = 6 + 1/z^4 + 4/z^2 + 4 z^2 + z^4     Cases[lis, Alternatives[x_. Power[z, e_.],                             Times[x_, Power[z, e_.]],                             x_.] :> {x, e}]      The problem is that the above generates                 {{6},{1,-4},{4,-2},{4,2},{1,4}}      and not                 {{6,0},{1,-4},{4,-2},{4,2},{1,4}}      This is because the pattern that matched x_. (the last one in the `Alternatives` does not have an `e` in it, and Mathematica replaced the `e` with the Null sequence as documented in help. Another problem with the above, is that `x_.` has to the last one in the alternatives. If I had wrote this instead:               Cases[lis, Alternatives[x_., x_. Power[z, e_.], Times[x_, Power[z, e_.]]] :>             {x, e}]      Then it would not have worked (another thing to worry about). Ok, this is all fine, except now the output is not symmetric and needs special case processing. What I was hoping to do is something like this                Cases[lis, Alternatives[x_. Power[z, e_.] :> {x,e} ,                               Times[x_, Power[z, e_.]] :> {x,e},                               x_. :> {x,0}]             ]      ie. have a specific rule for each specific pattern. The above is much easier to work with, since now I can specific the output for each pattern instead of having all pattern target one output. But the above of course is not valid Mathematica code and `Cases` does not like it. Are there such general ways of doing the pattern matching that allows one to write specific rules for specific pattern? It does not have to use `Cases` as long as it follows this general approach. I know that one can probably use the Polynomial specific functions (such as `CoefficientRules`, `CoefficientList`, and related functions to do this for this case, but I am more interested in this general approach so I can learn how to use it for things other that this example)


title: Prevent Grid from resizing images

text: Aligning my images in `Grid` causes one of them to become smaller, despite specifying each of their sizes with `ImageSize`:               dat = Table[{x, y, RandomReal[]*x*y}, {x, 1, 50}, {y, 1, 50}];     img = ListContourPlot[Flatten[dat, 1], ImageSize -> {300, 300}];     oldspotlight =        Graphics[{}, Background -> Black, PlotRange -> {{1, 50}, {1, 50}},         ImageSize -> 300];     a=Show[img,       Graphics[{Circle[{90, 60}, 10]}, PlotRange -> {{1, 50}, {1, 50}},        ImageSize -> {300, 300}]]     b=ImageMultiply[img,       ImageAdd[oldspotlight,        Graphics[{ColorData["GrayTones"][10/20], Disk[{90, 60}, 10]},         Background -> Black, PlotRange -> {{1, 50}, {1, 50}},         ImageSize -> {300, 300}]]]     Grid[{{a,b}}]      Output: ![enter image description here](http://i.stack.imgur.com/fxDPB.jpg) ![enter image description here](http://i.stack.imgur.com/z8vAq.jpg) ![enter image description here](http://i.stack.imgur.com/BgS8X.jpg) Please note that I don't want to use `GraphicsGrid`. (The reason is because it doesn't cooperate with `Dynamic`, which is an unrelated question.)


title: How to fix this error : SetDelayed::write: Tag Plus in (<<1>>)[x_] is Protected.?

text: I don't get the meaning of the sign <<>> and also from which line the error is coming as I have a program of more than 30 lines with many defined functions without using "Module" . Is not there any way to display line numbers in Mathematica so that we can know from which line error is coming?


title: Plotting with ColorFunction -> GrayLevel - no black

text: This is probably a fairly trivial question, yet I have been unable to find an answer - help would be much appreciated! :) I am trying to plot a 28 x 28 matrix (tabulated data given here), containing continuous pixels values on the interval [0;1]. I am using MatrixPlot and ColorFunction -> GrayLevel, so that 0 comes out as black and 1 as white, and all values inbetween will cover the gray spectrum. MatrixPlot produces a lovely 28 x 28 matrix plot - however, for some reason it uses a medium gray for 0, and scales the remaining values accordingly on the gray spectrum, with 1 still being white. This is the code used:               input1 = Get["http://pastebin.com/raw.php?i=PP2t8tp6"];     MatrixPlot[input1, ColorFunction -> GrayLevel, Mesh -> None, AspectRatio -> 1/1, ImageSize -> 300]      The resulting image: ![enter image description here](http://i.stack.imgur.com/3GGxr.png) Adding a file extension (.dat, .csv, .txt) and adding separators made no difference - I also tried forcing the color spectrum with ColorRule, but no luck.


title: Problem with SphericalPlot3D plotting

text: I want to plot the real part of the `SphericalHarmonicY[1,1,θ,φ]`. That is, I want to plot $$ - \frac{1}{2}\sqrt {\frac{3}{{2\pi }}} \cos[\phi ]\sin[\theta ]$$ To do so, I evaluated the following expression:               SphericalPlot3D[-(1/2) Sqrt[3/(2 π)] Cos[φ] Sin[θ], {θ, 0, π}, {φ, 0, 2 π}]      But the result I got doesn't show the negtive part. What is wrong? ![spherical](http://i.stack.imgur.com/XF1eS.gif)


title: Is there an easy way to specify an arbitrary two-dimensional Polyomino tiling in Mathematica 8.0?

text: Is there an easy way to generate an arbitrary two-dimensional Polyomino tiling: http://en.wikipedia.org/wiki/Polyomino? Specifically, I would like to generate an array of integer coordinates, for example: {{0,1},{10,11},{15,6},...}, and then output a graphic showing a tiling pattern where a tile is centered at each integer coordinate in my array, and where each tile is labeled with its integer coordinate. Is there a way for me to do this in three-dimensions? I have access to Wolfram Mathematica 8.0.


title: Symbolic multiplicative partitions

text: Let $p_n\\#\equiv\prod_{k=1}^{n}p_k$ (primorial):               p[n_] := Times @@ Prime[Range[n]]      then the multiplicative partitions of $p_{1,2,3,4}\\#$ are $$ \\{\\{2\\}\\},$$$$ \\{\\{6\\},\\{2,3\\}\\},$$$$ \\{\\{30\\},\\{2,15\\},\\{3,10\\},\\{5,6\\},\\{2,3,5\\}\\},$$$$ \\{\\{210\\},\\{2,105\\},\\{3,70\\},\\{5,42\\},\\{6,35\\},\\{7,30\\},\\{10,21\\},\\{14,15\\},\\{2,3,35\\},\\{2,5,21\\},\\{2,7,15\\},\\{3,5,14\\},\\{3,7,10\\},\\{5,6,7\\},\\{2,3,5,7\\}\\}$$ computed with               g[lst_, p_] :=      Module[{t, i, j}, Union[Flatten[Table[t = lst[[i]]; t[[j]] = p*t[[j]];     Sort[t], {i, Length[lst]}, {j, Length[lst[[i]]]}], 1],      Table[Sort[Append[lst[[i]], p]], {i, Length[lst]}]]];          z[n_] := Module[{i, j, p, e, lst = {{}}}, {p, e} =      Transpose[FactorInteger[n]];     Do[lst = g[lst, p[[i]]], {i, Length[p]}, {j, e[[i]]}]; lst];          Table[z[p[n]], {n, 1, 4}]      What is the best way to turn this into a symbolic function, so the output of the above becomes $$\\{\\{a\\}\\}$$$$ \\{\\{ab\\}\\},\\{\\{a,b\\}\\}$$$$ \\{\\{abc\\}\\},\\{\\{a,bc\\},\\{b,ac\\},\\{c,ab\\}\\},\\{\\{a,b,c\\}\\}$$$$ \\{\\{abcd\\},\\{a,bcd\\},\\{b,acd\\},\\{c,abd\\},\\{d,abc\\},\\{ab,cd\\},\\{ac,bd\\},\\{ad,bc\\}, \\{a,b,cd\\},\\{a,c,bd\\},\\{a,d,bc\\},\\{b,c,ad\\},\\{b,d,ac\\},\\{c,d,ab\\},\\{a,b,c,d\\}\\}$$ ? The primorial example above is given for combinatorial simplicity. I would ideally like the function to be applicable to any number, e.g.: $72$ ($2^3\cdot 3^2$) would be tackled as $a^3\cdot b^2$. Of course, it is possible to take this approach:               n = 4; ColumnForm[Map[FactorInteger[z[p[n]]][[#]] &, Range[Length[z[p[n]]]]]     /. 2 -> a /. 3 -> b /. 5 -> c /. 7 -> d]      ... etc., but I wondered whether there was a more direct route? _NB - This question is an extension ofthis one._ # Update Have got this far:               n = p[4];     m = ColumnForm[Map[FactorInteger[z[n]][[#]] &, Range[w[n]]]      /. 2 -> a /. 3 -> b /. 5 -> c /. 7 -> d];     ColumnForm[Table[Table[Map[m[[1, k]][[v]][[#]][[1]]^m[[1, k]][[v]][[#]][[2]] &,      Range[Length[m[[1, k]][[v]]]]], {v, 1, Length[m[[1, k]]]}], {k, 1, w[n]}]]      BTW, is there an easier way of doing               /. 2 -> a /. 3 -> b /. 5 -> c /. 7 -> d /. 11 -> e /. 13 -> f /.                          17 -> g /. 19 -> h /.      ...etc.?


title: What is available for editing Mathematica source code with Emacs?

text: I can find several Emacs libraries for _Mathematica_ , but I'm not aware of a clear favourite, a definitive list, or of a library which is actively maintained and developed. None of these appear to be in the Emacs Lisp Package Archive or Milkypostman’s Emacs Lisp Package Archive.   * http://www.watson.org/~mccann/mathematica.el   * https://github.com/Leockard/elisp   * http://library.wolfram.com/infocenter/MathSource/4567/   * http://www.itwm.fhg.de/as/asemployees/wichmann/mma.html   * http://chasen.org/~daiti-m/dist/math++.el I have been using the first one on the list for a while, but the indentation engine is not ideal. What do people use for editing _Mathematica_ source code in Emacs? I'm just talking about editing source code; I don't need to evaluate _Mathematica_ expressions in a subsidiary kernel process, etc. The important features for me are   * indentation,   * syntax-highlighting,   * forward/backward/up/down in _Mathematica_ bracketed expressions. Additional "IDE" features would be very welcome, especially imenu support.


title: How to make plots scaling consistent when running a series of simulations?

text: In my function it returns a plot of my data, say example, using ListLinePlot, and this is the size I obtain: ![enter image description here](http://i.stack.imgur.com/nAgS4.png) ![enter image description here](http://i.stack.imgur.com/ImAlW.png) but when running a series of simulations inside a Table: Table[tCorrStudentsT[i]=sensStudentsT[sensMat[[i]], mcRun,chrT,hrT,ppT,r] ,{i,10}] the resultant graphs look like these, without manually adjusting each graph after simulation is complete? ![enter image description here](http://i.stack.imgur.com/Tz129.png) so how can I set it such that the series of graphs will be consistent with my single simulation result plot size?


title: How to correctly use DSolve when the force is an impulse (dirac delta) and initial conditions are not zero

text: `DSolve` (and `NDSolve`) return different and unexpected solution to differential equation when the input is an impulse. This is because `DiracDelta[t]` at $t=0$ remains `DiracDelta[0]`. **This question is two parts question** : If it is a user error to use `DiracDelta[t]` in this example, should then software still return a solution? And the second part asks how to use `DSolve` or `NDSolve` in order to obtain the correct solution to a differential equation when the input is an impulse $\delta\left(t\right) $ as is commonly understood and used in engineering and mathematics problems (the dirac delta function). Initial conditions used are not all zero in this example. ## Problem description An example which is standard ODE is used that models a single degree of freedom second order differential equation for an underdamped system. When using $f(t)=\delta\left( t\right) $ as the RHS of the differential equation, the answer returned is the same as the answer when $f\left( t\right) =0$. The user might go on and use the solution without knowing that $\delta\left( t\right) $ effect was not used since no warning is issued. Here is an example solving $my^{\prime\prime}\left( t\right) +cy^{\prime }\left( t\right) +k=f\left( t\right) $. The solution was obtained for $f\left( t\right) =\delta\left( t\right) $ and $f\left( t\right) =0$ and for the same initial conditions $y\left( 0\right) =1,y^{\prime}\left( 0\right) =0$ The answers returned _are the same_ as can be seen by the plots, and also the analytical answers are the same as well.               plot[title_, sol_] :=        Plot[sol, {t, 0, 10}, PlotRange -> All, Frame -> True,         FrameLabel -> {{y[t], None}, {Row[{t, " (sec)"}], title}},         GridLines -> Automatic, ImageSize -> 300];     eq1 = m y''[t] + c y'[t] + k y[t] == DiracDelta[t];     eq2 = m y''[t] + c y'[t] + k y[t] == 0;     parms = {m -> 1, c -> .7, k -> 5};     sol1 = First@DSolve[{eq1 /. parms, y[0] == 1, y'[0] == 0}, y[t], t];     sol2 = First@DSolve[{eq2 /. parms, y[0] == 1, y'[0] == 0}, y[t], t];     Grid[{       {plot["DiracDelta[t]", y[t] /. sol1],         plot["zero RHS", y[t] /. sol2]},       {Simplify[y[t] /. sol1], Simplify[y[t] /. sol2]}       }, Frame -> All]      ![Mathematica graphics](http://i.stack.imgur.com/Ytx5i.png) The analytical answer are the same. When impulse is input, the solution given is               E^(-0.35 t) (1. Cos[2.20851 t] - 0.294317 Sin[2.20851 t] +         0.452795 HeavisideTheta[t] Sin[2.20851 t])      and when the input is zero, the solution given is               E^(-0.35 t) (1. Cos[2.20851 t] + 0.158478 Sin[2.20851 t])      And they are the same since `HeavisideTheta[t]=1` for $t>0$ The correct analytical solution for this differential equation derived by hand is different. And a plot of this solution is compared with the above solutions by Mathematica. Taking the case of underdamped system, the analytical solution is $$ u\left( t\right) =e^{-\xi\omega t}\left( u(0)\cos\omega_{d}t+\frac {u^{\prime}(0)+u(0)\xi\omega}{\omega_{d}}\sin\omega_{d}t\right) +e^{-\xi\omega t}\left( \frac{1}{m\omega_{d}}\sin\omega_{d}t\right) $$ where $\zeta=\frac{c}{2\omega m},\omega_{d}=\omega\sqrt{1-\zeta^{2}}% ,\omega=\sqrt{\frac{k}{m}}$, $u(0)$ and $u^{\prime}(0)$ are the initial conditions. For the parameters in this example, the solution is               parms = {m -> 1, c -> .7, k -> 5};     w = Sqrt[k/m];     z = c/(2 m w);     wd = w Sqrt[1 - z^2];     analytical =        Exp[-z w t] (u0 Cos[wd t] + (v0 + (u0  z w))/wd Sin[wd t] +1/(m wd ) Sin[wd t]);     analytical /. parms /. {u0 -> 1, v0 -> 0}           (* E^(-0.35 t) (Cos[2.20851 t] + 0.611273 Sin[2.20851 t]) *)      Compare the above to the solution by `DSolve` which is given above, here it is again:                (* E^(-0.35 t) (1. Cos[2.20851 t] + 0.158478 Sin[2.20851 t]) *)      Now plotting the above hand derived solution to compare:               Grid[{       {plot["DiracDelta[t]", y[t] /. sol1],         plot["drived", analytical /. parms /. {u0 -> 1, v0 -> 0}]}       }, Frame -> All]      ![Mathematica graphics](http://i.stack.imgur.com/5zR2H.png) The difference can be seen clearly around $t=0$. ![Mathematica graphics](http://i.stack.imgur.com/y9Rpi.png) A unit impulse has the effect of giving the system an initial velocity of $1/m$. In otherwords, a system with an impulse as input, can be replaced by an equivalent free input system by adding to its initial velocity an amount of $1/m$. This is why the initial velocity can not be zero in the solution. The slope of the displacement curve generated by the derived solution shows this, while the solution by DSolve used the zero initial velocity. This is all because `DiracDelta[t]` was basically not used. ps. If I have to post the derivation of the solution done by hand, I can do this as well.