title: Earth to Mars Interplanetary Travel Escape Velocity

text: I'm trying to create a script that simulates interplanetary travel from Earth to Mars using a Hohmann transfer, but I'm having a few difficulties getting the correct escape velocity. I'm using an x-y Heliocentric coordinate system, so I have to break down the escape velocity into its x- and y-components and then add it to the initial conditions of the spacecraft that is orbiting Earth. I've tried using some standard interplanetary escape velocity equations, but so far have come up with the spacecraft going in the right direction, but doing it with too much speed. Here's the code that solves a system of ODEs (I apologize for the horribe looking code, I'm not too sure how to add special Mathematica symbols like epsilons and sigmas to a forum post):               (*Gravitational Constant*)         G = 6.672*10^-11;         Subscript[t, max] = 100000000;         (*Masses of Sun, Earth, Mars and satellite*)         m[0] = AstronomicalData["Sun", "Mass"];         m[1] = AstronomicalData["Earth", "Mass"];          m[2] = AstronomicalData["Mars", "Mass"];         m[3] = 100;         (*Heliocentric positions of Earth, Mars and satellite*)         p[1] = AstronomicalData["Earth", {"Position", {2013, 1, 1, 0, 0, 1}}]         p[2] = AstronomicalData["Mars", {"Position", {2013, 18, 1, 0, 0, 1}}]          p[3] = AstronomicalData[         "Earth", {"Position", {2013, 1, 1, 0, 0, 1}}] + {0, -r[1] -           200000, 0};         (*Planetary radii of Sun, Earth and Mars*)         r[0] = AstronomicalData["Sun", "Radius"];         r[1] = AstronomicalData["Earth", "Radius"];         r[2] = AstronomicalData["Mars", "Radius"];         (*Heliocentric radii components of Earth and Mars*)         rex = Norm[p[1][[1]]];         rey = Norm[p[1][[2]]];         rmx = Norm[p[2][[1]]];         rmy = Norm[p[2][[2]]];         (*Heliocentric velocities of Earth, Mars and spacecraft calculated \         via central difference approximation f'(x)=(f(x+h)-f(x-h))/2h*)         v[1] = ((AstronomicalData[            "Earth", {"Position", {2013, 1, 1, 0, 0, 1.001}}] -            AstronomicalData[            "Earth", {"Position", {2013, 1, 1, 0, 0, 0.999}}]))/(2 (0.001));         v[2] = ((AstronomicalData[            "Mars", {"Position", {2013, 18, 1, 0, 0, 1.001}}] -            AstronomicalData[            "Mars", {"Position", {2013, 18, 1, 0, 0, 0.999}}]))/(2 (0.001));         (*Hyperbolic escape velocities for spacecraft travelling to Mars*)         v1x = Sqrt[(G m[0])/rex] (Sqrt[(2 rmx)/(rex + rmx)] - 1)         v1y = Sqrt[(G m[0])/rey] (Sqrt[(2 rmy)/(rey + rmy)] - 1)         (*Spacecraft initial velocity*)         v[3] = v[1] + {-v1x, -v1y, 0}         (*Softening factor*)         \[Epsilon] = 0.001;         (*Numerical solution to 4-body problem, modelling the gravitation \         interation between the Sun, Earth, Mars and an artificial satelite*)         soln = NDSolve[{         x[0]''[t] == -\!\(         \*UnderoverscriptBox[\(\[Sum]\), \(i =              0\), \(3\)]\(\((G\ m[i] \((\(x[0]\)[t] - \(x[i]\)[t])\))\)/         \*SuperscriptBox[\((         \*SuperscriptBox[\((\(x[0]\)[t] - \(x[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\((\(y[0]\)[t] - \(y[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\((\(z[0]\)[t] - \(z[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\(\[Epsilon]\), \(2\)])\), \(3/2\)]\)\),         y[0]''[t] == -\!\(         \*UnderoverscriptBox[\(\[Sum]\), \(i =              0\), \(3\)]\(\((G\ m[i] \((\(y[0]\)[t] - \(y[i]\)[t])\))\)/         \*SuperscriptBox[\((         \*SuperscriptBox[\((\(x[0]\)[t] - \(x[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\((\(y[0]\)[t] - \(y[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\((\(z[0]\)[t] - \(z[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\(\[Epsilon]\), \(2\)])\), \(3/2\)]\)\),         z[0]''[t] == -\!\(         \*UnderoverscriptBox[\(\[Sum]\), \(i =              0\), \(3\)]\(\((G\ m[i] \((\(z[0]\)[t] - \(z[i]\)[t])\))\)/         \*SuperscriptBox[\((         \*SuperscriptBox[\((\(x[0]\)[t] - \(x[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\((\(y[0]\)[t] - \(y[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\((\(z[0]\)[t] - \(z[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\(\[Epsilon]\), \(2\)])\), \(3/2\)]\)\),         x[1]''[t] == -\!\(         \*UnderoverscriptBox[\(\[Sum]\), \(i =              0\), \(3\)]\(\((G\ m[i] \((\(x[1]\)[t] - \(x[i]\)[t])\))\)/         \*SuperscriptBox[\((         \*SuperscriptBox[\((\(x[1]\)[t] - \(x[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\((\(y[1]\)[t] - \(y[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\((\(z[1]\)[t] - \(z[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\(\[Epsilon]\), \(2\)])\), \(3/2\)]\)\),         y[1]''[t] == -\!\(         \*UnderoverscriptBox[\(\[Sum]\), \(i =              0\), \(3\)]\(\((G\ m[i] \((\(y[1]\)[t] - \(y[i]\)[t])\))\)/         \*SuperscriptBox[\((         \*SuperscriptBox[\((\(x[1]\)[t] - \(x[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\((\(y[1]\)[t] - \(y[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\((\(z[1]\)[t] - \(z[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\(\[Epsilon]\), \(2\)])\), \(3/2\)]\)\),         z[1]''[t] == -\!\(         \*UnderoverscriptBox[\(\[Sum]\), \(i =              0\), \(3\)]\(\((G\ m[i] \((\(z[1]\)[t] - \(z[i]\)[t])\))\)/         \*SuperscriptBox[\((         \*SuperscriptBox[\((\(x[1]\)[t] - \(x[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\((\(y[1]\)[t] - \(y[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\((\(z[1]\)[t] - \(z[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\(\[Epsilon]\), \(2\)])\), \(3/2\)]\)\),         x[2]''[t] == -\!\(         \*UnderoverscriptBox[\(\[Sum]\), \(i =              0\), \(3\)]\(\((G\ m[i] \((\(x[2]\)[t] - \(x[i]\)[t])\))\)/         \*SuperscriptBox[\((         \*SuperscriptBox[\((\(x[2]\)[t] - \(x[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\((\(y[2]\)[t] - \(y[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\((\(z[2]\)[t] - \(z[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\(\[Epsilon]\), \(2\)])\), \(3/2\)]\)\),         y[2]''[t] == -\!\(         \*UnderoverscriptBox[\(\[Sum]\), \(i =              0\), \(3\)]\(\((G\ m[i] \((\(y[2]\)[t] - \(y[i]\)[t])\))\)/         \*SuperscriptBox[\((         \*SuperscriptBox[\((\(x[2]\)[t] - \(x[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\((\(y[2]\)[t] - \(y[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\((\(z[2]\)[t] - \(z[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\(\[Epsilon]\), \(2\)])\), \(3/2\)]\)\),         z[2]''[t] == -\!\(         \*UnderoverscriptBox[\(\[Sum]\), \(i =              0\), \(3\)]\(\((G\ m[i] \((\(z[2]\)[t] - \(z[i]\)[t])\))\)/         \*SuperscriptBox[\((         \*SuperscriptBox[\((\(x[2]\)[t] - \(x[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\((\(y[2]\)[t] - \(y[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\((\(z[2]\)[t] - \(z[i]\)[t])\), \(2\)] +           \*SuperscriptBox[\(\[Epsilon]\), \(2\)])\), \(3/2\)]\)\),         x[3]''[t] == -\!\(         \*UnderoverscriptBox[\(\[Sum]\), \(i =              0\), \(3\)]\(\((G\ m[i] \((\(x[3]\)[t] - \(x[i]\)[t])\))\)/         \*SuperscriptBox[\((         \*SuperscriptBox[\((\(x[3]\)[t] - \(x[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\((\(y[3]\)[t] - \(y[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\((\(z[3]\)[t] - \(z[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\(\[Epsilon]\), \(2\)])\), \(3/2\)]\)\),         y[3]''[t] == -\!\(         \*UnderoverscriptBox[\(\[Sum]\), \(i =              0\), \(3\)]\(\((G\ m[i] \((\(y[3]\)[t] - \(y[i]\)[t])\))\)/         \*SuperscriptBox[\((         \*SuperscriptBox[\((\(x[3]\)[t] - \(x[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\((\(y[3]\)[t] - \(y[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\((\(z[3]\)[t] - \(z[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\(\[Epsilon]\), \(2\)])\), \(3/2\)]\)\),         z[3]''[t] == -\!\(         \*UnderoverscriptBox[\(\[Sum]\), \(i =              0\), \(3\)]\(\((G\ m[i] \((\(z[3]\)[t] - \(z[i]\)[t])\))\)/          \*SuperscriptBox[\((         \*SuperscriptBox[\((\(x[3]\)[t] - \(x[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\((\(y[3]\)[t] - \(y[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\((\(z[3]\)[t] - \(z[i]\)[t])\), \(2\)] +          \*SuperscriptBox[\(\[Epsilon]\), \(2\)])\), \(3/2\)]\)\),              x[0][0] == 0, y[0][0] == 0, z[0][0] == 0, x[1][0] == p[1][[1]],          y[1][0] == p[1][[2]], z[1][0] == p[1][[3]], x[2][0] == p[2][[1]],          y[2][0] == p[2][[2]], z[2][0] == p[2][[3]], x[3][0] == p[3][[1]],          y[3][0] == p[3][[2]], z[3][0] == p[3][[3]], x[0]'[0] == 0,          y[0]'[0] == 0, z[0]'[0] == 0, x[1]'[0] == v[1][[1]],          y[1]'[0] == v[1][[2]], z[1]'[0] == v[1][[3]],          x[2]'[0] == v[2][[1]], y[2]'[0] == v[2][[2]],          z[2]'[0] == v[2][[3]], x[3]'[0] == v[3][[1]],          y[3]'[0] == v[3][[2]], z[3]'[0] == v[3][[3]]}, {x[0][t], y[0][t],          z[0][t], x[1][t], y[1][t], z[1][t], x[2][t], y[2][t], z[2][t],          x[3][t], y[3][t], z[3][t]}, {t, 0, Subscript[t, max]},          Method -> "StiffnessSwitching", MaxSteps -> 10000000]      And here's the plot code:               orbits = ParametricPlot3D[{{x[0][t], y[0][t], z[0][t]}, {x[1][t],      y[1][t], z[1][t]}, {x[2][t], y[2][t], z[2][t]}, {x[3][t],      y[3][t], z[3][t]}} /. soln, {t, 0, Subscript[t, max]},      AxesLabel -> {x, y, z}, ImageSize -> Large,      PlotRange -> {{-0.3*10^12, 0.3*10^12}, {-0.3*10^12, 0.3*10^12}, {-0.3*10^12, 0.3*10^12}}]      As you can see, the output shows the spacecraft shooting off into outer space and never returning, whereas what I would like to see is the spacecraft just getting to the orbital path of Mars (I'll worry about timing and phase angles a little later). ![enter image description here](http://i.stack.imgur.com/ppaZw.png) Does anyone know what I'm doing wrong? Any help would be appreciated, thanks guys.


title: Pretty InputField

text: I'm trying to create a "template" notebook for myself.   I want to get input from a single `InputField`, and then run a few operations on it. **How can I make the`InputFiled` (that is, the box itself) be prettier?** How can I manipulate it's style? **EDIT:**   I was asked to define prettier (which stands to reason).   So let's have _WolframAlpha's_ (website) input box as a refrence point.


How to pick increasing numbers from the list.                  lst = {5, 3, 6, 2, 7, 4, 8};      out:                    {5,6,7,8}      So many interesting answers, is it possible know the index of result elements or position of elements with respect to the old "lst"?


title: How to create a real-time dashboard in Mathematica?

text: I am trying to figure out how to use Mathematica as a real-time interface. I've used Excel/ODBC connection to a SQL database to use the graphing functions within to get my real-time dashboard. I also know there are many Python implementations (http://dashing.io/), Javascript (d3), Ruby() on watching data. I currently I not looking to do this at a big data implementation. The first piece I am looking for to do is have an updated top 10 SKU Sales that are over 30 locations that are synced back to a Sql Server Database. My thought was to use a simple `SQLExecute` statement to the database every 5 minutes or so. Currently I am trying to figure out how to reissue that command to the db to get my new numbers and automatically update the table. The second piece is to watch transaction flow at each of these locations. Here I just simply want to graph by the hour which I'd update an array with the data. I just don't know how to trigger the data execution. After some searching online, I haven't found anyone who has done this with Mathematica. Does anyone have links/examples where a dashboard is implemented into Mathematica?


title: Is it possible to simulate a RS latch?

text: Combining the solutions provided from the nice guys here to my previous two questions(first, second), Interesting enough, simulations for simple logic gates can be implemented easily. An example is given below. Is it possible to simulate logic gates involved loop-backs, such as RS Latchs or JK Flip-flops? I wonder.               (********* gates ************)     not[str : _String] :=        StringJoin[        Characters[str] /. {"1" -> False, "0" -> True} /. {False -> "0",           True -> "1"}];          nand[str : {__String}] :=        not[StringJoin[         MapThread[And,            Characters[str] /. {"0" -> False, "1" -> True}] /. {False ->             "0", True -> "1"}]];               (********* display ************)     funB[str : {__String}, opts : OptionsPattern[]] :=       Module[{fs, n, timd},        fs = Riffle[#, #]~Append~Last[#] & /@ ToExpression@Characters@str;       n = Length@First@fs;       timd = Reverse@fs~Append~PadLeft[{1}, n, {1, 0}];       ListLinePlot[MapIndexed[#1 + 2 First@#2 - 2 &, timd],         InterpolationOrder -> 0,         Frame -> True,     Epilog -> {Table[          Text[Style[ln, {12, Italic}], {ln*2 + .5, 2 *Length[str] }], {ln, 1, 8}],             Dashed, Lighter@Lighter@Blue,          Table[Line[{{ln, 0}, {ln, 2 *Length[str]}}], {ln, 1, 9*2, 2}]},       FrameTicks -> {Thread[{Range[1.5, n - 1.5, 2], Range[n/2]}],          Thread[{Range[0.5, 2 Length@timd, 2],            Join[Reverse@str, {"clock"}]}], None, None},        PlotRange -> {{0, n + 1}, Automatic}, opts]]          Dynamic[Refresh[str2 = StringRotateRight /@ str2;        funB[str2, ImageSize -> 400]  , UpdateInterval -> 0.5],       TrackedSymbols -> {}]          (********* testing ************)     inp1 = "11000000";     inp2 = "10000001";     str2 = {inp1, not[inp1], inp2,  nand[{not[inp1], inp2}]};      ![enter image description here](http://i.stack.imgur.com/xmFwa.gif) @Mr. Wizard Oh yes, it seems possible to build functions for the RS latch and JK flip-flop from their fundamental characteristics instead of just wiring the "logic gates" from strictly following their symbolic diagrams. ![enter image description here](http://i.stack.imgur.com/cwrQ5.gif)


title: 1D Random Walk with Excluded Sites and Variable Time-Step

text: Here is the physical problem I would like to simulate: Consider the following variations to the 1d random walk:   1. allow for certain, random sites to be excluded with probability 1/2.    2. allow for the walker to be able to hops either 1 or 2 units to left or right   3. whether hopping 1 or 2 units is weighted by hopping rate   4. time in between hops is taken from exponential distribution with width being total hopping rate (to all 4 possible sites) In the end, I would like to find out how much slower a walker takes to reach, say x = 100, when the exclusions are present as to when they are not. The following will be my attempt at the problem. I think I have the basics down but I am hoping there are areas to decrease the computation time. These problems were alluded to earlier in the question and answers of 1D Random Walk variant. First the 4 different hop rates are defined:               kBack1[k0_] := k0 Exp[- 2 ];     kFor1[k0_] := k0 Exp[- 2 ];     kBack2[k0_] := k0 Exp[- 2  * 2];     kFor2[k0_] := k0 Exp[- 2 *2];      I know these are redundant since there are actually only two unique rates. However, I would like to eventually add a bias to the random walk which will make the 4 rates all different. Now we need to choose which site the walker will hop to and how long it takes to make the hop. So the excluded sites are accounted for by If statements. If an excluded site is nearby, there is a probability that that site is unreachable. The new site (newCoords) is chosen by weighting the different hopping rates. The time-step is sampled from the exponential distribution and the simulation time is updated.               FindRate[k0_] := Module[{},       kB1 = If[({Xi} \[Intersection] blockedSites + 1) != {},      RandomChoice[{1/2, 1/2} -> {0, kBack1[k0]}], kBack1[k0]];       kB2 = If[({Xi} \[Intersection] blockedSites + 2) != {},      RandomChoice[{1/2, 1/2} -> {0, kBack2[k0]}], kBack2[k0]];       kF1 = If[({Xi} \[Intersection] blockedSites - 1) != {},      RandomChoice[{1/2, 1/2} -> {0, kFor1[k0]}], kFor1[k0]];       kF2 = If[({Xi} \[Intersection] blockedSites - 2) != {},      RandomChoice[{1/2, 1/2} -> {0, kFor2[k0]}], kFor2[k0]];          newCoords =      RandomChoice[{kB1, kB2, kF1, kF2} -> {Xi - 1, Xi - 2, Xi + 1,        Xi + 2}];          dt = RandomReal[ExponentialDistribution[kB1 + kB2 + kF1 + kF2]];     t = simT;     {Xi, simT} = {newCoords, t + dt}     ]      EDIT: More explanation on how the hop is chosen: Consider the walker to be at point 4. The next hop is chosen in the following way. Is the walker 1 or 2 spaces away from an excluded point? Let's say point 6 is excluded. The rate (kF2) to point 6 is then 0. The other points (2,3, and 5) can be hopped to with respective rate kB2,kB1, and kF1. Which one does it hop to? Well, compare the different rates. In the example we'll have kB2, kB1 = kF1, and kF2 = 0. Which rate is chosen is decided by `RandomChoice` where the choices are weighted by the rates. END EDIT Now it's time to string the hops together               hopMod[k0_, Xf_] := Module[{},     Xi = 0; simT = 0;     blockedSites = RandomInteger[{-100, Xf-2}, 11];(*keep exclusion away from endpoint*)     NestWhileList[FindRate[k0] &, {0, 0}, Xi < Xf &]     ]      where I define a random set of excluding sites. I would prefer to not have adjacent or next-adjacent points not both be exclusions (so separated by at least 2 normal sites). Is there a way to force `RandomInteger` to not sample consecutive integers? Now calculate the time to reach a specified endpoint, Xf. And average this for n configurations.               With[{k0 = 1, Xf = 10, n = 20},(* n is # of runs to average over*)      Print[AbsoluteTiming[       Table[p[i] = hopMod[k0, Xf], {i, 1, n}];]];      iTable = Flatten[Table[p[j][[-1]][[1]]/p[j][[-1]][[2]], {j, 1, n}]]]      This took me 1.33 seconds. The time is highly varying. The time increases dramatically as Xf or increase. For some reason, when I used `ParallelTable`, I got identical results every time I calculated another iTable. Must be something with the seed going wrong. To get convergence, n needs to be increased. So how can this be sped up? Some different schemes for the hopMod module were discussed at 1D Random Walk variant. However I was not sure how to generalized all those approaches to my situation where I also need to keep track of the simulation time.


title: Why do EstimatedDistribution and DistributionFitTest work this way

text: I am fitting some time-series data to both a stable distribution and a normal distribution in order to assess the goodness of fit of each. Along the way I encountered the following confusing result. Could someone explain why this happens?               data1 ={0.0779615, 0.10661, -0.10661, -0.0253178, -0.0392207, 0.0892311, \     0.115069, 0.231802, 0.19517, 0.0279739, -0.0901511, -0.0784716, \     -0.0631789, -0.0572607, -0.0825012, 0.195567, 0.0505117, 0.183754, \     0.365871, 0.45219, 0.210721, -0.0396115, 0.0260313, 0.021456, \     -0.0318827, 0.0274891, -0.0239223, -0.00786374, 0.0194273, -0.030735, \     -0.0706707, 0.0745345, -0.0557558, 0.11472, 0.00521248, -0.0694686, \     0.0305097, 0.195748, 0.0830934, 0.205548, 0.0840846, -0.208923, \     -0.112126, 0.0727309, 0.0298448, 0.274583, 0.181881, -0.0555489, \     -0.350074, 0.0276329, 0.0780266, 0.0703987, 0.0228365}          (* First use the distribution fit test and then extract the fitted distribution *)     h1 = DistributionFitTest[data1, Automatic, "HypothesisTestData"];     h1["FittedDistribution"]      > >     NormalDistribution[0.0443194, 0.1352] >                 (* EstimatedDistribution produces the same result when called with symbolic params*)     d1 = EstimatedDistribution[data1, NormalDistribution[μ1, σ1]]      > >     Out=NormalDistribution[0.0443194, 0.1352] >                 (* Use DistributionFitTest on the estimated distribution *)     h2 = DistributionFitTest[data1, d1, "HypothesisTestData"];     h2["FittedDistribution"]      > >     Out= NormalDistribution[0.0443194, 0.1352] >                 (* Output the TestDataTable and observe very different results *)     Grid[{{h1["TestDataTable", All]}, {h2["TestDataTable", All]}}\[Transpose], Frame -> All]      ![grid output](http://i.stack.imgur.com/YDgYh.jpg) Looking inside these objects shows only one difference, which is the symbolic parameters in h1 and numeric parameters in h2, but I'm not sure why this should be, since the evaluation of the symbolic parameters should produce the same numeric results.


title: Set number of columns in text-based interface

text: Is it possible to set the number of columns in _Mathematica_ 's text-based interface? Or disable word wrapping in the text-based interface ? Specifically, my concern is output from `MatrixForm` and `TableForm`, which wraps output at about 85 columns. It seems as if the values were hardcoded in 1992. I use the text based interface within an emacs shell buffer. EDIT: The answer below that I checked green solves this problem in a few tests of commands that give long output, such as MatrixForm.


title: How to get the list of notebooks that are automatically opened when Mathematica starts?

text: How to get the list of notebooks that are automatically opened when Mathematica starts programmatically? I know a tedious approach is opening option inspector and finding and copying the list out.


title: the winding number for the circle map (Arnold tongue)

text: I want to do an iterative calculation:               f[n_, a_, b_] := Nest[# + a - b Sin[2 π #] &, 0, n]/n;      If I use i use the machine precision, it maybe produce a great error,for example:               N@f[500, 1/2, 3/5]     f[500, 0.5, 0.6]      > 0.5 > > 0.0282658 In the most of the time it can not ust infinity precision and then use N. How can I calculate this in high precision? **Edit:** this question is from this: http://en.wikipedia.org/wiki/Circle_map I want to reappear this image： ![enter image description here](http://i.stack.imgur.com/BNYAP.jpg) My code is：               f = Compile[{n, a, k}, Nest[# + a - k Sin[2 \[Pi] #] &, 0, n]/n];     dat =Outer[f[500, #2, #] &, Range[0, 1, 1/500], Range[0, 1, 1/500]]; // AbsoluteTiming     ArrayPlot[dat,         ColorFunction -> (Blend[{Black, Blue, Green, Yellow, Red}, #] &),         ColorFunctionScaling -> False, DataReversed -> True]      My rusult is: ![enter image description here](http://i.stack.imgur.com/0OxVM.jpg)


title: Insphere for Irregular Tetrahedron

text: I am looking for existing _Mathematica_ code to compute the unique sphere inscribed inside an irregular tetrahedron. I can write it myself, but I would love to find that someone already performed this calculation and can share their code. I want to take as input four points (a,b,c,d) in 3D and return the center, radius, and four tangency points of the insphere. If no one has already done this, then I will go ahead and write it myself. Responding to the request for an example:               a = {0, 0, 0};     b = {1, 0, 0};     c = {2, 1, 0};     d = {1, 3/2, 1};         ![Tetrahedron](http://i.stack.imgur.com/QOf5N.jpg) * * * **Updated**. ( _11Oct13_ ) The Wikipedia pages to which `ybeltukov` pointed _are_ correct. Here the inradius is all of $0.127$:   ![Tetra InSphere](http://i.stack.imgur.com/D0qNi.jpg)   I have the insphere center and radius, but not yet the four tangency points.... * * * And here are the four points of tangency:   ![InSphere Tangencies](http://i.stack.imgur.com/nurg2.jpg)


title: Why is either Listable or HoldFirst not working?

text: Starting with a fresh kernel, I evaluate the following:               Questions = {         (* Statement, Answer, Incorrect Answer *)         {"What is the capital of Switzerland?", "Bern", {"Vaduz", "Berlin", "Vienna"}},         {"Who is the king of the jungle?", "Lion", {"Giraffe", "Mouse", "Monkey"}},         {"2+2?" , "4", {"15", "13", "1e15"}}     } ;     Dynamic@Column@Questions          SetAttributes[DynamicInputField, {HoldFirst, Listable}];     DynamicInputField[var_, OptionsPattern[ContentType -> Expression]] :=        InputField[Dynamic[var], OptionValue[ContentType],         ContinuousAction -> True, ImageSize -> Full];          Dynamic@Grid[{        {"Statement", DynamicInputField[Questions[[1, 1]], ContentType -> String]},        {"Answer", DynamicInputField[Questions[[1, 2]], ContentType -> String]},        {Column[{"Incorrect Answers"}, BaselinePosition -> Top],          Column[DynamicInputField[#, ContentType -> String] & /@ Questions[[1, 3]],             BaselinePosition -> Top]        }     }, Alignment -> Left]      ![Statement](http://i.stack.imgur.com/dtvc6.jpg) I must say that I took me a while to find out that I needed to set HoldFirst as an attribute for my function to work at least with the first two input fields. Nevertheless, the function does not work by mapping it into a list, i.e., the three last input fields send a error, the same one I had before I set HoldFirst as an attribute:               Set::setraw : Cannot assign to raw object Vaduz.>>      What am I doing wrong? I also tried the following:               Column[DynamicInputField[Questions[[1, 3]], ContentType -> String],          BaselinePosition -> Top]      ![Attempt1](http://i.stack.imgur.com/NGfH8.jpg)               Column[Table[         DynamicInputField[Questions[[1, 3, n]], ContentType -> String],          {n, 3}], BaselinePosition -> Top]      ![Attempt2](http://i.stack.imgur.com/6xiFU.jpg) Giving the errors:               Part::pkspec1 : The expression n cannot be used as a part specification.>>      even when I put the Table inside a `With[[n=n],...]`. Moreover, why is not the same result in my two attempts of "solving" even though the function was set to be listable?


title: How to correctly project heat map onto map

text: I'm importing the NGA ASAM piracy database into Mathematica for analysis.               asamjson=Import["http://msi.nga.mil/MSI_JWS/ASAM_JSON/getJSON?typename=\     DateRange_AllRefNumbers&fromDate=19900101&toDate=20140801",       "JSON"];     Needs["GeneralUtilities`"]     asamdataset = Dataset[ToAssociations@asamjson];     piracyLocations =       Map[GeoPosition[ ToExpression@{#["lat"], #["lng"] }]   &,        asamdataset];      I can import the data fine, and get lat/longs (for some reason they're included twice in the ASAM data). I can then draw them with GeoListPlot and get map of all the piracy events.               GeoListPlot[Take[piracyLocations, 300]]      However, when I then go to make a heat map histogram things fall apart. What displayed nicely now shows up with a wildly out of skew map. It looks like I need to choose some different form of projection, but which?               dat = Map[ ToExpression@{#["lat"], #["lng"]}&,Take[asamdataset, 4000]];          histo = SmoothDensityHistogram[dat, .3,       ColorFunction -> "SunsetColors", PlotPoints -> 150, Mesh -> 20,       MeshStyle -> Opacity[.1], PlotRange -> All];          Show[histo,       Graphics[{FaceForm[], EdgeForm[Directive[White, Opacity[.7]]],       CountryData["World", "Polygon"]}]]      How do I project my heatmap of piracy events correctly onto the world? EDIT: My first problem is that Geoposition and related functions take Lat/Long pairs. Which is Y/X, whereas other Mathematica functions take X/Y pairs.


title: Need an efficient way to do this list manipulation

text: Lets say i have two lists with me as given below:               l1 = {4, 6, 8, 9, 10, 12};          l2 = {2, 3, 4, 5, 6, 7};      Now i have a function S2P(details irrelevant) which takes one argument and spits out a list.               S2P[a_] := DeleteDuplicates[Apply[Times,Partition[Flatten[IntegerPartitions[a, {2}]], 2], {1}]]      Now i want to feed S2P the elements of l2 and find which elements of l2 gives an output that is a subset of l1. For e.g               S2P[5]     (*{4, 6}*)           S2P[7]     (*{6, 10, 12}*)      These are the only two elements of l2 for which the output from S2P is a subset of l1 and im finding them like this:               t1[n_] := Module[{l3, res, len},     l3 = S2P[l2[[n]]];     len = Length[l3];     res = Count[     Flatten[Table[{l3[[i]]} == {l1[[#]]} & /@ Range[Length[l1]], {i,1,len}]],True];     If[res == len, Sow[l2[[n]]]]];          DeleteCases[t1[#] & /@ Range[Length[l2]], Null]     (*{5, 7}*)      Can someone show me how to do this more efficiently for large data. Below i have shown the actual function l1 and l2 where n can go upto 1000.               f4 = #~Extract~SparseArray[Unitize[#2 - 1]]["NonzeroPositions"] & @@      Transpose@Tally@# &; (* to keep only duplicates*)          l1[n_] :=      DeleteCases[f4[Flatten[Table[i*j, {i, 1, n}, {j, 1, n}]]], _?PrimeQ]          l2[n_] :=      DeleteDuplicates[Flatten[Table[i + j, {i, 1, n}, {j, 1, n}]]]


title: ParametricPlot3D with three variables

text: `ParametricPlot3D` can be used with one or two variables to plot paths and surfaces in 3-D such as               ParametricPlot3D[{x + y, x y, Sin[x] + Cos[y]}, {x, 0, 1}, {y, 0, 1}]      However, say I wanted to plot a 3-D solid where the x, y and z coordinates are defined in terms of 3 variables. Is there some way to use `ParametricPlot3D` or other Mathematica functions to perform this task? A simple test case could be               ParametricPlot3D[{x, y, z}, {x, 0, 1}, {y, 0, 1}, {z, 0, 1}]      which should output a cube.


title: BoxWhiskerChart with logarithmic axes 2

text: I actually already found my answer on the question, however it is not working. see BoxWhiskerChart with logarithmic axes I want to create a boxwiskerchart with a logaritmic axes. But when I try `ScalingFunctions` with "Log" I do not get the results I am suppose to get. Sometimes it does not work at all. And sometimes I get the wiskers upside down. What am I doing wrong?               data = RandomVariate[RayleighDistribution[RandomInteger[500]], {8, 50}];     BoxWhiskerChart[data, "Outliers", ChartStyle -> 56]      ![enter image description here](http://i.stack.imgur.com/aHd1r.jpg)               BoxWhiskerChart[data, "Outliers", ChartStyle -> 56, ScalingFunctions -> "Log"]      ![enter image description here](http://i.stack.imgur.com/Lfpc5.jpg) Also using Log10 does not work               BoxWhiskerChart[data, "Outliers", ChartStyle -> 56, ScalingFunctions -> "Log10"]      ![enter image description here](http://i.stack.imgur.com/zIAjn.jpg)


title: Weird behavior when changing parts of matrix

text: I have this matrix:               mat = {{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16,          17, 18, 19, 20}, {21, 22, 23, 24, 25}};      and here are its second row and second column:               {mat[[2]], mat[[All, 2]]}     (* {{6, 7, 8, 9, 10}, {2, 7, 12, 17, 22}} *)      When I tried to change its second column to all zeros, this method works:               mat = {{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16,          17, 18, 19, 20}, {21, 22, 23, 24, 25}};     mat[[All, 2]] = 0;     mat // MatrixForm      ![Mathematica graphics](http://i.stack.imgur.com/yY2WN.png) But using the method to change the second row, the entire row become a big zero:               mat = {{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16,          17, 18, 19, 20}, {21, 22, 23, 24, 25}};     mat[[2]] = 0;     mat // MatrixForm      ![Mathematica graphics](http://i.stack.imgur.com/efWeD.png) * * * **My question is:** **1)** Why would the replacement of a row versus a column in a matrix different? **2)** Why would setting the list of all column elements to zero automatically set each of them to zero? Setting a list to a single number doesn't seem to work in isolation:               {a, b, c} = 0      ![Mathematica graphics](http://i.stack.imgur.com/usAWS.png)


title: graphics and manipulate stiffness method

text: I'm trying to create a structures analysis program based on the stiffness method. The program should analyse frames. All the program should be included in the manipulate function. What I want at first to be able to draw the structure using graphics. The problem is the user has to specify some variables in order to draw the figure(spans and floors number) which will be the variables in the manipulate. How can I do this? Since the number of objects to draw is varying how can creat one single function to do this job. I'll will explain it again. If the user chooses one span and one floor the function should draw two vertical lines with one horizontal between them. If he chooses 2 spans 2 floors he should see 3 vertical lines with 2 lines horizontally spaning between them midway and 2 horizontal lines at the top. Thank you.


title: Vectorizing an image like "Trace Bitmap" in Inkscape

text: Lately, we had a nice question about artistic image vectorization which got very nice answers. As Szabolcs pointed out himself > Since "true" vectorization performed by various specialized software is a > tough problem, I suggest to consider "artistic" approaches, which produce > inexact, but beautiful version of the original. And this is true: Sophisticated bitmap tracers like the implementation in Inkscape let you adjust how many color-levels, how detailed or how smooth the vectorized image should be. Following example was created from a Mathematica image with Inkscape: ![Mathematica graphics](http://i.stack.imgur.com/a9GPY.png) **Still, I wonder whether it is possible to implement a vectorizer which comes very close to the behavior of the above without re-implementing the algorithm but with the help of the many tools we have in Mathematica?**


title: How to give ClusteringComponents initial values?

text: I came across a variant of k-means that adds a algorithm to select good starting values called k-means++.               kMeansInitializer[data_, k_Integer] :=      Module[       {startingPoint = RandomChoice[data], getDistance, getDistances,         nextPoint},       getDistance[datum_, points_] := Min[Norm[datum - #]^2 & /@ points];       getDistances[points_] := getDistance[#, points] & /@ data;       nextPoint[points_] := RandomChoice[getDistances[points] -> data];       NestList[nextPoint, startingPoint, k - 1]       ]      After implementing the algorithm (a bit of a challenge for someone at my level) I now find I have no idea how to feed the values I generate to `ClusteringComponents` to use as initial values for use in its k-means implementation.


title: Using J/Link to decode Google Maps Polyline strings

text: I would like to use this java code inside _Mathematica_ using J/Link. It converts Google Maps API Encoded Polylines to a list of points. I tried the _Mathematica_ tutorial but got lost. There is the Java code:               private List<GeoPoint> decodePoly(String encoded) {          List<GeoPoint> poly = new ArrayList<GeoPoint>();     int index = 0, len = encoded.length();     int lat = 0, lng = 0;          while (index < len) {         int b, shift = 0, result = 0;         do {             b = encoded.charAt(index++) - 63;             result |= (b & 0x1f) << shift;             shift += 5;         } while (b >= 0x20);         int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));         lat += dlat;              shift = 0;         result = 0;         do {             b = encoded.charAt(index++) - 63;             result |= (b & 0x1f) << shift;             shift += 5;         } while (b >= 0x20);         int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));         lng += dlng;              GeoPoint p = new GeoPoint((int) (((double) lat / 1E5) * 1E6),              (int) (((double) lng / 1E5) * 1E6));                     poly.add(p);         }              return poly;     }      As example:               wjiGtdpcNrAlBJZ      should return               43.64175, -79.38651     43.64133, -79.38706     43.64127, -79.3872      I have no experience in Java. The code came from here.


title: Getting the 557th element of a table

text: > Make a table with elements $\sin(\sqrt{8 n}/4) + r\, $for $n$ from $1$ to > $1000$, where $r$ is a random real number between $-0.1$ and $0.1$ that is > different for each value of $n$. Also make a plot of all the points of this > table. What is the $557^{th}$ element of this table? Everything is working well, but I can't get the 557th element of the table. I've tried to use the `Select` command.               Select[TableSin[Sqrt[(a*n)/4]] + Random[Real, {-0.1, 0.1}], {n, 1, 1000}] ,557]      but it's not working. I can't figure out how to fix it. Can anyone give me some hints?


title: Simulating Stochastic Processes the MMA way

text: This question is really a specific problem and a methodological one concerning MMA best practices. I want to simulate a system of stochastic processes. If this were a geometric Brownian motion or random walk then the recursive (univariate) nature of the problem means `FoldList` or `Nestlist` is easy and neat to implement. However, what if I wanted to simulate an mean-reverting process which itself had a mean-reverting long run mean? Now, I cannot work out the MMA efficient way of doing it other than within a `For` loop. For example, the following code simulates an OU process for inflation with a stochastic central tendency :               Clear["Global`*"];           norθ[mu_, sigma_] := Random[NormalDistribution[mu, sigma]];      norπ[mu_, sigma_] := Random[NormalDistribution[mu, sigma]];           deltaθt[θnow_] :=-λθ*(θnow-θbar)*deltaT + σθ*norθ[0, 1]*Sqrt[deltaT]         deltaπt[πnow_] := -λπ*(πnow - θnow)*deltaT + σπ*norπ[0, 1]*Sqrt[deltaT]          λθ     = 0.07;     σθ     = 1.2;     θbar   = 2;     θnow   = 2;     λπ     = 1.;     σπ     = 1.25;     πnow   = 2;     deltaT = 1/12;     noYear = 100*12;          Process = Reap[For[i = 1, i < noYear, i++,          Sow[{i, πnow, θnow}];          πnow = deltaπt[πnow] + πnow;          θnow = deltaθt[θnow] + θnow;       ]][[2, 1]];           inflation = Process[[All, {1, 2}]];      target    = Process[[All, {1, 3}]];          ListLinePlot[{inflation, target}]


title: Equation Simplification in Mathematica

text: I wonder if the following equation could be further simplified by Mathematica. There are $22$ Integrals involved and many of them are in the range $y_l$ and $y_u$. I would guess that at least those terms could be collected in the same integral. I used the command FullSimplify but the result is the same with the input. Are there some more clever ways to simplify such type of equations?               (2*(1 - \[Epsilon]0)^2*Integrate[((Sqrt[f1[y]*l[yu]] - Sqrt[f0[y]*l[yl]     *l[yu]])*(-Sqrt[f1[y]*l[yl]] + Sqrt[f0[y]*l[yl]*l[yu]]))/(-Sqrt[l[yl]] +      Sqrt[l[yu]])^2, {y, yl, yu}] - 2*(Integrate[(Sqrt[f0[y]]*(-Sqrt[f1[y]*l[yl]] +      Sqrt[f0[y]*l[yl]*l[yu]]))/(-Sqrt[l[yl]] + Sqrt[l[yu]]), {y, yl, yu}] +      Integrate[f0[y], {y, -Infinity, yl}]*Sqrt[l[yl]])*(Integrate[(Sqrt[f0[y]]*      (Sqrt[f1[y]*l[yu]] - Sqrt[f0[y]*l[yl]*l[yu]]))/(-Sqrt[l[yl]] + Sqrt[l[yu]]),      {y, yl, yu}] + Integrate[f0[y], {y, yu, Infinity}]*Sqrt[l[yu]]) -      Sqrt[(-2*(1 - \[Epsilon]0)^2*Integrate[((Sqrt[f1[y]*l[yu]] -      Sqrt[f0[y]*l[yl]*l[yu]])*(-Sqrt[f1[y]*l[yl]] +      Sqrt[f0[y]*l[yl]*l[yu]]))/(-Sqrt[l[yl]] + Sqrt[l[yu]])^2, {y, yl, yu}] +      2*(Integrate[(Sqrt[f0[y]]*(-Sqrt[f1[y]*l[yl]] +      Sqrt[f0[y]*l[yl]*l[yu]]))/(-Sqrt[l[yl]] + Sqrt[l[yu]]), {y, yl, yu}] +      Integrate[f0[y], {y, -Infinity, yl}]*Sqrt[l[yl]])*(Integrate[(Sqrt[f0[y]]*     (Sqrt[f1[y]*l[yu]] - Sqrt[f0[y]*l[yl]*l[yu]]))/(-Sqrt[l[yl]] +      Sqrt[l[yu]]), {y, yl, yu}] + Integrate[f0[y], {y, yu, Infinity}]*     Sqrt[l[yu]]))^2 - 4*((Integrate[(Sqrt[f0[y]]*(-Sqrt[f1[y]*l[yl]] +      Sqrt[f0[y]*l[yl]*l[yu]]))/(-Sqrt[l[yl]] + Sqrt[l[yu]]), {y, yl, yu}] +      Integrate[f0[y], {y, -Infinity, yl}]*Sqrt[l[yl]])^2 -      (1 -\[Epsilon]0)^2*(Integrate[(Sqrt[f0[y]]*(-Sqrt[f1[y]*l[yl]] +      Sqrt[f0[y]*l[yl]*l[yu]])^2)/(-Sqrt[l[yl]] + Sqrt[l[yu]])^2, {y, yl, yu}] +      Integrate[f0[y], {y, -Infinity, yl}]*l[yl]))*((Integrate[(Sqrt[f0[y]]*     (Sqrt[f1[y]*l[yu]] - Sqrt[f0[y]*l[yl]*l[yu]]))/(-Sqrt[l[yl]] +      Sqrt[l[yu]]), {y, yl, yu}] + Integrate[f0[y], {y, yu, Infinity}]*     Sqrt[l[yu]])^2 - (1 - \[Epsilon]0)^2*(Integrate[(Sqrt[f1[y]*l[yu]] -      Sqrt[f0[y]*l[yl]*l[yu]])^2/(-Sqrt[l[yl]] + Sqrt[l[yu]])^2, {y, yl, yu}] +      Integrate[f0[y], {y, yu, Infinity}]*l[yu]))])/(2*((Integrate[(Sqrt[f0[y]]*     (Sqrt[f1[y]*l[yu]] - Sqrt[f0[y]*l[yl]*l[yu]]))/(-Sqrt[l[yl]] + Sqrt[l[yu]]),      {y, yl, yu}] + Integrate[f0[y], {y, yu, Infinity}]*Sqrt[l[yu]])^2 -      (1 - \[Epsilon]0)^2*(Integrate[(Sqrt[f1[y]*l[yu]] -      Sqrt[f0[y]*l[yl]*l[yu]])^2/(-Sqrt[l[yl]] + Sqrt[l[yu]])^2, {y, yl, yu}]      +Integrate[f0[y], {y, yu, Infinity}]*l[yu])))


title: Equivalent Nested Loop Structure

text: Consider the following examples:               Flatten @ Table[ f[a, b, c], {a, 1, 3}, {b, 1, 3}, {c, 1, 3}] ==     f @@@ Tuples[ Range[3], 3]          Flatten @ Table[ If[ a != b != c, f[a, b, c], Unevaluated[]],                       {a, 1, 3}, {b,  1, 3}, {c, 1, 3}] ==      f @@@ Permutations[ Range[3], {3}]          Flatten @ Table[ f[a, b, c], {a, 1, 5}, {b, a + 1, 5}, {c, b + 1, 5}] ==      f @@@ Subsets[ Range[5], {3}]      > >     True >     True >     True >   Is there a similar built-in function performing this:               Flatten @ Table[ f[a, b, c], {a, 1, 5}, {b, a, 5}, {c, b, 5}]      in a simpler way?


title: Solving asymptotic equations

text: Let's say I have several equations that have solutions given as a negative series $$y(t,x)=\sum_{n=-1}^\infty a_n(t) x^{-n}=a_{-1}x+a_0+a_1x^{-1}+\mathcal{O}(x^{-2})$$ My equations look like $$eqns=\mathcal{O}(x^{n})$$ where RHS is given for each equation. Now what that means is that after putting my ansatz of solution in the equation, all the powers smaller than ones given by RHS will cancel each other out, and I'll end up with equations for my coefficients $a_n$. For instance $$2\frac{\partial}{\partial t}y+3y=\mathcal{O}(1)$$ $$2(a_{-1}'x+a_0'+\mathcal{O}(x^{-1}))+3(a_{-1}x+a_0+\mathcal{O}(x^{-1})=\mathcal{O}(1)$$ which gives me $$2a_{-1}'x+3a_{-1}x=0$$ which can now be solved and used elsewhere, for other coefficients etc. This is simple example since I have only one solution, but in reality I'm dealing with a solution that is vector with 4 components that have similar expansion for each component, that's why I'd like to speed up the process by finding out what each component will look like. Now I can get the equations in Mathematica, and I have even made a simple ansatz (different than this ofc)               y = Sum[a[#1][n] #2^-n, {n, -1, 4}] &;      And I can input that in to my equations, and with `Collect` I can gather all the 'stuff' with all the powers of x. Now I'd like to see if there is any way that I can make Mathematica give me the coefficient equation, and all I need to do is specify which parts of the equation with series needs to be kept (in my examples all the $\mathcal{O}(1)$ parts cancel each other so I'm neglecting all the $x^0, x^{-1},...$ parts in my ansatz). Because the way I'm doing it now is just inputing it all, collecting and seeing what is $\mathcal{O}(x^n)$ for each component and manually have to solve it.


title: Reducing a long complex expression to a simplier one by using assumptions

text: so I have an ugly looking equation that I wish to solve under some specific circumstances. Using DSolve I write;                t = DSolve[{p'[r] ==  A*((r - (rc^2)/r) - ((l)*Log[((rc - r)^2 + l)/l])/r +                  (2*Sqrt[l]*rc*ArcTan[(rc - r)/Sqrt[l]])/r), p[rc] == 0},  p[r], r]      And this yields a long, ugly expression involving imaginary numbers and PolyLog functions - this is fair enough, but I'm trying to simplify it further by telling it only to look at realistic cases; $A, r, r_{c}$ are always real and positive, as is $p$. Also, $r_{c} >= r$ so that $r_{c} - r$ is always a positive number. $L$ is also always positive and orders of magnitude smaller than $r$ or $r_{c}$. So I attempted to use full simplify with these assumptions on the expression by               u = FullSimplify[t, rc > 0 && r > 0 && rc >= r && l > 0 && A > 0 && p >= 0 ]      This simplifies the expression somewhat, but still has clunky imaginary parts and I suspect it can be further simplified. I have tried Refine but this doesn't yield a better expression. Is it possible to clean this up, or do I accept this as just a complex looking expression that gives me real answers and cannot be further simplified ? Thanks!


title: CDF embedding in HTML

text: I created a working CDF file on my Mac, and I am trying to embed it into an html page, and although I followed all the steps suggested on the mathematica web embedding page, it is not working (I always get a white page when I try to open my page). This is what I have done so far:   * I exported my _Mathematica_ code as a CDF standalone "AGN-standaloneClear.cdf", checked and it is working with CDF Player   * I opened TextEdit, converted to plain text and wrote:                        <embed src="AGN-standaloneClear.cdf” width=“1380” height=“6792”>                and saved it as test.html into the same folder where the cdf is. When I try to open it with Chrome the page is completely white however, and if I try to reopen the test.html file it is completely white. I never tried to deal with html, so I think I could be doing some very noob errors that are not even explained in the guides I read so far, but however I don't know what to do. -EDIT- Here is the code that generates the white page:                                                        and here is the one that generates the cropped cdf (http://postimg.org/image/tgqa3bicl/):


title: Copy string with markup so it looks good on input

text: How can I copy a string with a bunch of `*Box` expressions without it blowing up into the raw expression?               text = Integrate::usage     (* Nice looking String *)          text//Head     (* String *)      After copying the output and pasting it into an input cell it looks like                "\!\(\*RowBox[{\"Integrate\", \"[\", RowBox[{StyleBox[\"f\", ....      Same thing happens when evaluating in place, so how can I do this without retyping the entire expression?


title: Setting a Counter in Mathematica Notebook

text: I would like to write a book using _Mathematica_ , but I will write one chapter on several files. How to tell _Mathematica_ that the `BookChapterNumber` pointer has the value pointing to the next file in the same chapter ?


title: NIntegrate (multi-dimensional integral)

text: I am interested in the numerical evaluation of the following integral: $\int \prod_{i=1}^n dx_i \delta(\sum_{i=1}^n x_i) \prod_{i=1}^n f_i(x_i)$ where $f(x)$ is a complicated function. Unfortunately NIntegrate seems to give an answer with too large errors; this seems to be problem of the multi- dimensional integral. The function contains the phase fluctuations ($\sim e^{ikx}$), which could be one of the reasons. In practice $n\sim 5$, although it is certainly better if I could take $n$ large. For comparison, I can also consider an integral $\int \prod_{i=1}^n dx_i \prod_{i=1}^n f_i(x_i)$ but instead of evaluation this whole expression in NIntegrate, I could factorize the integral to be $\prod_{i=1}^n \left(\int dx_i\, f_i(x_i)\right)$, evaluate the 1-dimensional integral first and then take a product. This seems to give an answer which is numerically much better than NIntegrating the n-dimensional integral. [I am numerically checking the known mathematical identity so I have something to compare with. The one with the delta function corresponds to $SU(N)$, the one without to $U(N)$.] The trouble with the one above, with 1 delta function, is that the integral does not factorize. However I hope there is a way to achieve numerical accuracy, rather than brute-force NIntegrate of the whole expression. In any case I would appreciate any suggestions for better numerical accuracy.


title: Obtain a stable solution using NDSolve

text: I am trying to solve a partial differential equation using `NDSolve`. When I am not specifying any method options with `NDSolve`, it gives me a solution which is quite oke but shows oscilations that are not suppose to be there. I expected to be able to solve this using options like `MaxStepSize` to get rid off or at least reduce this oscilations. However, unfortunately, when I use for example `MaxStepSize -> 0.01` I get results that do not make sense and errors like `NDSolve::mconly: For the method IDA, only machine real code is available. Unable to continue with complex values or beyond floating-point exceptions. >>` I do not really understand why I get this error. Hopefully someone could illuminate this to me. Also I guess `MaxStepSize` is not the way to give me a better solution, are there any other options to improve my solution or should I just be satisfied with the one I have so far? Thanks in advance Simplification of the code:               tmin = 0; tmax = 70;     xmin = 0; xmax = 183;     rate = 0.00084;     a = 96;     b = 5/3;          f[t_] :=  If[t > 1 && t < 30, rate, 0];          eq1 = i[x, t] == a *h[x, t]^b;     eq2 = D[i[x, t], x] + D[h[x, t], t] ==  f[t];     ic1 := h[x, 0] == 0;     ic2 := i[x, 0] == 0;     bc1 := h[0, t] == 0;          solution = NDSolve[{eq1, eq2, ic1, ic2, bc1},         {i, h}, {x, xmin, xmax}, {t, tmin, tmax}, (*MaxStepSize -> 0.01*)];     Manipulate[      Plot[Evaluate[i[x, t] /. solution], {t, 0, tmax}, PlotStyle -> Red,        ImageSize -> {350}], {x, xmin, xmax}]      ![result for x=16.4, where the top of the graph is supposed to be flat](http://i.stack.imgur.com/K946n.jpg)


title: Computing integrals with differential operator

text: I've to compute this expression $$ \hat{H} = \frac{1}{4}g_2\int d^3R\int d^3r\ \bar{\Psi}(\vec{R}+\frac{\vec{r}}{2})\bar{\Psi}(\vec{R}-\frac{\vec{r}}{2})\left[ \delta(\vec{r})\nabla_{\vec{r}}^2 +\nabla_{\vec{r}}^2\delta(\vec{r}) \right]\Psi(\vec{R}+\frac{\vec{r}}{2})\Psi(\vec{R}-\frac{\vec{r}}{2}) $$ where $\bar{\Psi}$ is the conjugate of $\Psi$. How can i calculate it with Mathematica? I don't know how to represent the differential operator and doing this kind of integral with Mathematica. ///// **Edit** ///// Instead to give me negative vote, you can explain me what i've to add to my question.


title: Sum all numbers from 1 to 1000 divided by either 2,3,5 or 7

text: How do I find the sum all numbers from 1 to 1000 divided by atleast one of 2,3,5 or 7? EDIT: I am sorry for complicating this, but I need it to work for 10^11. So anything that requires too much heap space or too long loops will fail.


title: Reduce cannot evaluate the inequality

text: Reduce[{(4 I1^2 (-2 + b (-2 + I1)^2 + 2 I1 - I1^2) +        c^2 (-3 - I1^4 + b (-3 + I1^2)^2) -        4 c I1 (-2 + I1^2 - I1^3 + b (6 - 3 I1 - 2 I1^2 + I1^3))) ((      c (-1 + I1) (c - 2 I1 + c I1))/(b I1^2 (a - r)))^b < 0, c > 0,       c < 1, b > 1, r > a, r > 0, a > 0}, I1, Reals]      The code above cannot be "reduced" in Mathematica. Could someone tell me what I am doing wrong?


title: Longest path in 0/1 matrix

text: I have a matrix of 0's and 1's forming a number of disjoint paths: * * *   ![RandomPaths](http://i.stack.imgur.com/pUlT7.jpg) * * * I would like to find the lengths of the paths, and from that "spectrum," the longest length (in the above example: 27, starting at {1,14}). (The shortest length possible is 3, just from how I generate these paths. There are never trees or cycles--just paths.) I can do it by identifying start 1-cells as either on the boundary, or having three 0-neighbors and one 1-neighbor, and then tracing from the start cell along the path. This is quite clunky. Can anyone see a slicker method? Efficiency is not my main concern at the moment. Thanks for your ideas! Here's the matrix displayed above: * * *               {{0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1,        0, 0, 0, 0, 0, 0, 0}, {1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0,        1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1}, {0, 1, 0, 0, 0, 0, 0,        1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,        0}, {0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,        0, 1, 0, 0, 1, 0, 0, 1, 0}, {0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0,        1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1}, {0, 0, 0, 0, 1,        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0,        0, 0}, {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0,        0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0,        0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1}, {0, 1, 0, 0,        1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1,        0, 0, 1, 0}, {0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,        0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0}, {1, 1, 1, 0, 1, 1, 0, 1, 1, 1,        1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1}, {0, 0,        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,        1, 0, 0, 0, 0}, {0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0,        0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0}, {1, 1, 0, 0, 1, 1, 0, 1, 0,        0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1}, {0,        0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1,        0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,        0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 1, 1, 1, 1, 0, 0,        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1,        0}, {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,        0, 1, 0, 0, 1, 0, 0, 0, 0}, {0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,        1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0}, {0, 1, 1, 0, 1,        1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1,        1, 0}, {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0,        0, 0, 1, 0, 0, 1, 0, 0, 0, 0}, {0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0,        0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 0, 1,        1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1,        1, 1, 1, 1}, {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,        0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0}, {0, 0, 0, 0, 1, 0, 0, 1, 0, 0,        1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1,        1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0,        1, 1, 1, 1, 1}, {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1,        0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0}, {0, 1, 0, 0, 0, 0, 0, 0, 0,        0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0}, {1,        1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1,        0, 1, 1, 0, 1, 1, 0}, {0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0,        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}


title: Tracking iterations of a function

text: I'm learning MMA with Wagner's book. On page 41, he uses this to display the iterative steps of a FindRoot. However, I can't seem to replicate this (code at end), perhaps due to the difference in MMA versions (his was MMA 3.0!). Using Trace doesn't seem to help; it just displays the final value of x. ![FindRoot iteration Trace](http://i.stack.imgur.com/qn7nu.png) Codes:               FindRoot[Print[x]; Sin[x] - Cos[x], {x, 0.5}]     Trace[FindRoot[Sin[x] - Cos[x], {x, 0.5}]]      **Edit** I have also tried to use his method--Print[x] within a function--for an exercise in the section and that seems to work (though with some quirk in the result). EvaluationMonitor also works, and frankly I find the latter much more intuitive. Below is my solution for the problem (code at end); I'm not sure if this is the way Sin[x] is actually sampled, so any feedback is very welcome. ![Sin\[x\] sampling animation](http://i.stack.imgur.com/XNc0A.gif) ![EvaluationMonitor](http://i.stack.imgur.com/NF3v3.png)               Plot[Sin[x], {x, \[Pi]/4, \[Pi]/2}] // InputForm     Plot[Print[x]; Sin[x], {x, \[Pi]/4, \[Pi]/2}]     Reap[Plot[Sow[x]; Sin[x], {x, \[Pi]/4, \[Pi]/2}]][[2]]     {plot, List@stepValue} =        Reap[Plot[Sin[x], {x, \[Pi]/4, \[Pi]/2},          EvaluationMonitor :> Sow[x]]];     stepValuePoints = {stepValue, Sin[stepValue]} // Transpose;     ListPlot[stepValue, AxesLabel -> {Step, x}]     Manipulate[      Show[       (* Actual y = Sin[x] curve *)       Plot[Sin[x], {x, \[Pi]/4, \[Pi]/2}, PlotStyle -> Yellow],       (* Generated mesh points *)       ListPlot[stepValuePoints, PlotStyle -> Red],       (* Arrow tail *)       ListLinePlot[{Table[stepValuePoints[[i]], {i, step - 5, step - 1}]}],       (*Arrow head *)       Graphics@{Blue,          Arrow[{stepValuePoints[[step - 1]], stepValuePoints[[step]]}]},       PlotRange -> {{\[Pi]/4, \[Pi]/2}, {Sqrt[2.]/2, 1}}], {step, 6,        Length[stepValuePoints], 1}]     anim = Table[        Show[         (* Actual y = Sin[x] curve *)         Plot[Sin[x], {x, \[Pi]/4, \[Pi]/2}, PlotStyle -> Yellow],         (* Generated mesh points *)         ListPlot[stepValuePoints, PlotStyle -> Red],         (* Arrow tail *)         ListLinePlot[{Table[            stepValuePoints[[i]], {i, step - 5, step - 1}]}],         (*Arrow head *)         Graphics@{Blue,            Arrow[{stepValuePoints[[step - 1]], stepValuePoints[[step]]}]},         PlotRange -> {{\[Pi]/4, \[Pi]/2}, {Sqrt[2.]/2, 1}}], {step, 6,          Length[stepValuePoints], 1}];     Export["anim.gif", anim, "DisplayDurations" -> 0.25]


title: Putting values into a grid after iteration process

text: I'm developing a model of thermodynamic cycle in _Mathematica_. I wrote several functions, applied them to a list containing starting values and iterated, for the model to converge.               fixed = FixedPoint[       f1[f2[Nest[f3,f4[f5[f6[Nest[f7, f8[#], 100]]]],100]]] &, startinglist, 20];      I would like to see not only final, converged values, but also values at each other point of the cycle, so I threw them into a grid:               data = {       Prepend[fixed, "starting point"],       Prepend[f8[fixed], "before condenser"],       Prepend[Nest[f7, f8[fixed], 100], "after condenser"],       Prepend[f6[Nest[f7, f8[fixed], 100]], "before pump"],       Prepend[f5[f6[Nest[f7, f8[fixed], 100]]], "after pump"],       Prepend[f4[f5[f6[Nest[f7, f8[fixed], 100]]]], "before heat exch"],        Prepend[Nest[f3, f4[f5[f6[Nest[f7, f8[fixed], 100]]]], 100], "after heat exch"],       Prepend[f2[Nest[f3,f4[f5[f6[Nest[f7, f8[fixed], 100]]]], 100]],"before turbine"],       Prepend[f1[f2[Nest[f3,f4[f5[f6[Nest[f7, f8[fixed], 100]]]], 100]]], "after turbine"]     };          Text@Grid[       Prepend[data, {"Point", "Temp [\[Degree]C]", "pressure [bar]", "enthalpy [kJ/kg]",        "enthropy [kJ\kg\K]", "density [kg/m3]", "viscosity [kg/m/s]", "quality [-]"}],       Frame -> All]      It works, but doesn't look very clean. The second thing is that while creating `data` _Mathematica_ is once again performing `Nest`, which might consume a lot of time, if I'm going to extend my model. Any other ways to do all of that quicker?


title: Which Mathematica syntaxes are unavailable in Wolfram Alpha?

text: Do you get the sense that Wolfram Alpha plays dumb sometimes? Like sometimes I can get it to obey a Flatten command by itself, or maybe Flatten _and_ Sort, but if I try to put that into a Table, it instead responds with the Mathematica documentation of the Table command. Wolfram Alpha also seems to me to be completely incapable of Plus@@ or Times@@ anything, though sometimes I can get Sum to work.


title: Maximum and mean of a multi-variate function over a restricted lattice

text: I have a function `Q`, and I want to find the maximum value, the corresponding arguments for the maximum value, and the mean over a certain range of arguments. I have the following working for finding the maximum value, which works:               Best[a_, b_, c_] :=        Max[Table[Q[a, b, c, w, v, x, y, z], {w, 0, 4}, {v, 0, 4}, {x, 0, 4}, {y, 0, 4}, {z, 0, 4}]]      Unfortunately, you can't use `ArgMax` and `Mean` in the same way as `Max`. I tried the following for finding the maximum arguments:               Args[a_, b_, c_] :=         ArgMax[{           Q[a, b, c, w, v, x, y, z],            0 <= w <= 4 && 0 <= v <= 4 && 0 <= x <= 4 && 0 <= y <= 4 && 0 <= z <= 4 &&              Element[w | v | x | y | z, Integers]         },          {w, v, x, y, z}]      This is the type of error message I get: > Part::pspec: "Part specification 1 + v is neither a machine-sized integer > nor a list of machine-sized integers. I tried similarly for the mean of the function:               M[a_, b_, c_] :=        Mean[{           Q[a, b, c, w, v, x, y, z],            0 <= w <= 4 && 0 <= v <= 4 && 0 <= x <= 4 && 0 <= y <= 4 && 0 <= z <= 4 &&              Element[w | v | x | y | z, Integers]          }]      Any help would be appreciated.


title: How to use TransformationFunctions on a compound expression?

text: I was trying to answer this question but having hard time with the correct way to write the transformation rule. Trying to write a rule to transform `Gamma[1/2 + n]` to `Sqrt[Pi] (Factorial2[2 *(n - 1/2) - 1])/2^(n - 1/2)`. Will worry about the conditions when this transformation is valid later on. I now can't even make `Simplify` use this rule. The rule is being invoked (I add a `Print` and see it there), but the final result returned by the transformation function is not being used or returned) I looked at this answer and tried what is there, but still no success. These are my attempts. The result of the `Simplify` command should return `Sqrt[Pi] (Factorial2[2 *(n - 1/2) - 1])/2^(n - 1/2)` in this example. I am not sure if it is scoping issue. Can one use an `If` or `Cases` in the transformationFunction or must it be based only on the syntax of `/. :>`? I wish help has more examples. Only 3 basic examples are shown and that is it. When an expression being used inside the tranformation function (like in this case, `Gamma[1/2 + n]` then `n` here is taken as global symbol, right? I mean it will not have a $$n or it? That what seems to be the case. So I do not see why any of these are not working.               ClearAll[n, f, e];     f = # /. Gamma[1/2 + n] :> Sqrt[Pi] (Factorial2[2*(n - 1/2) - 1])/2^(n - 1/2) &     Simplify[Gamma[1/2 + n], TransformationFunctions -> {Automatic, f}]      ![Mathematica graphics](http://i.stack.imgur.com/uHxEP.png)               ClearAll[n, f, e];     f[e_] := If[MatchQ[e, Gamma[1/2 + n]], Sqrt[Pi] (Factorial2[2 *(n - 1/2) - 1])/2^(n - 1/2), e]     Simplify[Gamma[1/2 + n], TransformationFunctions -> {Automatic, f}]      ![Mathematica graphics](http://i.stack.imgur.com/EcC8w.png) http://reference.wolfram.com/mathematica/ref/TransformationFunctions.html


title: Locator to show coordinates of plot

text: # Old I would like to make the locator follow a plot, giving the coordinates as it moves. I don't really know where to start with this one, but I would like the dynamic plot to look something like this: ![enter image description here](http://i.stack.imgur.com/nzDJ9.gif) the code for which is as follows:               Plot[{Sqrt[x]}, {x, 0, 10}, PlotRange -> {{0, 12}, {0, 3.5}},     Epilog -> {PointSize[Large], Red, Point[{4, 2}]}]      with the locator showing its coordinates as it is moved along the plot. Obviously, the movement of the locator needs to be constrained to the plot, just as it is constrained to the coordinates of the circle in this Wolfram Documentation example: ![enter image description here](http://i.stack.imgur.com/X43vW.gif) by the following code:               Deploy[DynamicModule[{p = {1, 0}}, Graphics[{Red, Disk[],      Locator[Dynamic[p, (p = Normalize[#]) &]]}, PlotRange -> 1.5]]]      basically, so it behaves in a similar way to Google graphs: ![enter image description here](http://i.stack.imgur.com/D4jnt.gif) where the coordinates appear to the top right of the plot. # New @Timothy Wofford The solution you gave works great for functions like Sqrt[x], but runs into difficulties when complex values are encountered. For example: ![enter image description here](http://i.stack.imgur.com/3fWht.gif) generated by the code:               f[x_] := ((\[Pi]^x/Zeta[x])^(1/x)/\[Pi]) - 1/Zeta[x]     Manipulate[Plot[f[x], {x, 0, 10}, Epilog -> {PointSize[Large], Red,      Tooltip[Point[#], #] &@{p[[1]], f[p[[1]]]}}, PlotLabel ->      {p[[1]], f[p[[1]]]}], {{p, {1, 0}}, Locator, Appearance -> None},      AppearanceElements -> None]      shows as a red screen when the locator moves off screen into the imaginary values, generating an error screen as follows: ![enter image description here](http://i.stack.imgur.com/cHb7J.gif) Is there any way of preventing this from happening? - ie, from stopping the locator moving past {1,0}?


title: Why is Mathematica's expansion of expressions with square roots so slow?

text: _Mathematica_ expansion of expressions with symbols isn't slow, but with square roots it is very slow. In Maple or Mupad both are fast: with square roots they both take less than a second. Here is an example.               Expand[(a + b + c + d + e)^100]; // Timing          Expand[(Sqrt[2] + Sqrt[3] + Sqrt[5] + Sqrt[6] + Sqrt[7])^100]; // Timing      ![enter image description here](http://i.stack.imgur.com/CGLAE.png) ![enter image description here](http://i.stack.imgur.com/8fRmw.png) Can you reproduce this? I used Mathematica9.0.0.0 and Maple16 on windows7 64 bit. **Updated** Maple and Mupad also give the exact result, please see following picture. It's equal to Mathematica' result. ![enter image description here](http://i.stack.imgur.com/TxHrL.png)


title: Working around behaviour of EdgeRenderingFunction

text: One can make graphs               GraphPlot[{1 -> 2, 2 -> 3, 3 -> 4, 4 -> 5, 5 -> 1, 1 -> 1, 5 -> 5}]      and one can generalize the input such that one labels edges                GraphPlot[{1 -> 2, {2 -> 3, "my favorite edge"}, 3 -> 4, 4 -> 5,  5 -> 1, 1 -> 1, 5 -> 5}]       Now in the Mathematica help for GraphPlot, under Options and then EdgeRenderingFunction one finds the example               GraphPlot[{1 -> 2, 2 -> 3, 3 -> 4, 4 -> 5, 5 -> 1, 1 -> 1, 5 -> 5},      EdgeRenderingFunction -> (If [      First[#2] == Last[#2], {Red, Arrow[#1]}, {GrayLevel[0.5],        Arrow[#1]}] &)]      I want to use this to change the color of edges according to their naming, i.e. if the edge says "my favorite edge", then that edge should be green. Problem is that once I use EdgeRenderingFunction,               GraphPlot[{1 -> 2, {2 -> 3, "my favorite edge"}, 3 -> 4, 4 -> 5, 5 -> 1, 1 -> 1, 5 -> 5},      EdgeRenderingFunction -> (If [      First[#2] == Last[#2], {Red, Arrow[#1]}, {GrayLevel[0.5],        Arrow[#1]}] &)]      the data beyond "2 -> 3" gets ignored. How to solve this problem? (I don't really have to use EdgeRenderingFunction to change the color, I just want more than just the names to point out some special edges.)


title: Problem in reading data from a text file with two variables

text: I want to read in a data file, test.txt, in Mathematica. The file has the following content:               7                                                          9.339746404911912e-01 2.390665790330537e-16     -9.660816659011047e-01 -3.665687545173490e-16          1.315811450789676e+00 -3.728808440402881e-16     5.351989286996225e-02 -4.983348938581225e-17          4.472964563970432e-01 2.924635360279648e-17     6.075434861678513e-01 -5.468444707473763e-17          -4.491183862398205e-01 1.316628013212084e-16     1.433072380629653e-01 1.825593170558248e-16          1.468347618480511e-01 3.826623805151808e-16     -5.510211996466368e-01 9.127627039612340e-18          -5.773829817302568e-16 1.018116881684214e-17     -5.090584408421044e-18 -2.886914908651284e-16          2.973875045664112e-02 2.112972391320319e-16     -2.020849668577390e-01 4.590918574118308e-18      I want to first read the top most integer number which says how many groups of two complex numbers I have. In this case it is 7 groups each of 2 complex numbers. Then I want to take each of these groups, which contains two lines, and assign the first line to `x[1]` and the second line to `x[2]`. e.g., from the first group, I should have `x[1]={9.339746404911912 * 10^(-01) + I 2.390665790330537* 10^(-16)}` and `x[2] = {-9.660816659011047 * 10^(-01) + -3.665687545173490 * 10^(-16)}`. So, I wrote the following code:               SetDirectory["C:\\your_dir_containing_the_data_file"];     Dim = 2;     streamread = OpenRead["test.txt"];     num = Read[streamread, Number];     Skip[streamread, String];     Print[num];     Do[       tmp[j] = {};       Do[        tmp[j] = Append[tmp[j], Read[streamread, {Number, Number}]],        {i, Dim}         ];       tmp[j] = tmp[j] /. {x_, y_} -> x + I  y,       (*Print[Chop[Equations/.Thread[Var-> soltmp[MainCounter]]]],*)       {j, num}       ];          maintmp = Table[tmp[j], {j, num}];     Close[streamread];      But when I execute it, it gives `maintmp`               {{0.933975 - 0.966082 I,        2.39067*10^-16 - 3.66569*10^-16 I}, {1.31581 +         0.0535199 I, -3.72881*10^-16 - 4.98335*10^-17 I}, {0.447296 +         0.607543 I,        2.92464*10^-17 - 5.46844*10^-17 I}, {-0.449118 + 0.143307 I,        1.31663*10^-16 + 1.82559*10^-16 I}, {0.146835 - 0.551021 I,        3.82662*10^-16 + 9.12763*10^-18 I}, {-5.77383*10^-16 -         5.09058*10^-18 I,        1.01812*10^-17 - 2.88691*10^-16 I}, {0.0297388 - 0.202085 I,        2.11297*10^-16 + 4.59092*10^-18 I}}      In short, it screws up the real and imaginary parts of each number to one another. Now, surprisingly, the problem occurs only if `Dim=2`, i.e., if the groups are made of exactly `2` complex numbers. If they were made of `1` or `2+`, then everything is fine. I think Mathematica gets confused here at some point for `Dim=2`. Do you guys know what's going wrong here? Thanks!


title: Arbitrary number of variables in Module, Block, etc

text: How do I specify an arbitrary number of variable names and initialize them inside of a Module or Block? For example, I want to do something like:               Module[Join[{mu = 100}, Array[(Symbol["lambda"<> ToString@#] = 0) &, 10]],           lambda3 = 7; Print[mu <> lambda2]; Print[mu <> lambda3];          ]      Instead, I get all sorts of errors about improper local variable definitions. I tried wrapping things in Evaluate, or making my own Hold and then Release sequence, but nothing I did seemed to work. Any help would be much appreciated! Best wishes, Andy


title: How can I define a Listable function only apply to a vector?

text: Consider the function `f` which should behave as               f[{{1, 2}, {3, 4}, {5, 6, 7}}]      > >     {f[{1, 2}], f[{3, 4}], f[{5, 6, 7}]} >   The following code doesn't worked as expectation               fromDig[ls_?VectorQ] := 10^Range[Length@ls - 1, 0, -1].ls;     SetAttributes[fromDig, Listable];     fromDig@{{1, 2}, {3, 4}, {5, 6}}      I figured out a way, using `Compile`,               Clear["Global`*"];     cfromDig = Compile[{{A, _Integer, 1}},      10^Range[Length@A - 1, 0, -1].A, RuntimeAttributes -> {Listable}];     cfromDig[{{1, 2}, {3, 4}, {5, 6}}]      Is there a better way?


title: Find the position of a string element, knowing only part of the string

text: I have a list, e.g.:               list = {1, 2, 3, "Element 1", 4, 5, "Element 2", "Something else 1", "etcetera"}      Now, I want all elements starting with `"El"`. Using `Position`, I could find the position of e.g. `"Element 1"`:               Position[list, "Element 1"]      But, I would like to know the positions of `"Element 1"` and `"Element 2"`, as both start with `"El"`. So, I would like to have something like               Position[list, "El"_]      I just can't get something like this to work. Thanks for any help.


title: FullSimplify used with Assuming giving unexpected results

text: Can someone shed some light on why               Assuming[{x ∈ Reals}, x (Sign[x]^2 - 1)] // FullSimplify      returns               x (-1 + Sign[x]^2)      instead of zero please?   I know one can not expect `FullSimplify` to perform miracles but this example does seem pretty obvious.


title: Replacing gamma at half integers by double factorial

text: It is well-known that for any positive integer $n$ the equality $\Gamma(n+\frac12)=\sqrt\pi\,(2n-1)!!/2^n$ holds, where $!!$ stands for the double factorial. I am using `FullSimplify[expr,Assumptions -> n \[Element] Integers]` on certain expression `expr`, and the output contains $\Gamma(-\frac12+n)/\sqrt\pi$. My question is: how can I instruct Mathematica to perform the simplification "$\Gamma(n+\frac12)=\sqrt\pi\,(2n-1)!!/2^n$ whenever $n$ is a positive integer" ? Of course, I want an answer no limited to this specific situation. **Edit:** What I want is to "add" the simplification rule above to the list of simplifications included in `FullSimplify`, not merely "replace" the "string" $\Gamma(\cdots)$ by $\cdots !!/\cdots$.


title: How do I create matrices with arbitrary list restrictions?

text: I want to randomly generate a square matrix of dimension n with entries in the list StartingEntries, and also satisfying that for any such matrix M, the matrix Inverse[IdentityMatrix[n] - M] has entries coming from the list EndingEntries. Below is my (not-working) code for the case dimension 3. It's the last line that keeps generating error messages. I'd like to know why. (Also if anyone can think of a better way of solving this problem, I'm all ears!)               (*generate 10,000 possible matrices.*)     mat = {{#1, #2, #3}, {#4, #5, #6}, {#7, #8, #9}} &     candidates = Apply[mat, RandomChoice[StartingEntries, {10000, 9}], 1]          (*get all matrices M so that I-M is invertible*)     invertibleCandidates = Select[candidates, Det[IdentityMatrix[3] - #] != 0 &]      So far so good. Now we want to make sure that the inverted matrix has the correct entries. I couldn't find a boolean Subset function in Mathematica, so I made my own:               SubsetQ[x_, y_] := (Length[Intersection[x, y]] == Length[x])      Now test to see if the inverse has entries lying inside EndingEntries. This is the line that keeps failing on me and I don't know why.               newerCan = Select[invertibleCandidates, SubsetQ[Flatten[Inverse[IdentityMatrix[3] - #]], EndingEntries] &]      Edit 1: SubSetQ modified to be               SubsetQ[x_, y_] := (Length[Intersection[DeleteDuplicates[x], DeleteDuplicates[y]]] == Length[DeleteDuplicates[x]])      Edit 2: The error messages I'm getting are               DeleteDuplicates::normal: Nonatomic expression expected at position 1 in DeleteDuplicates[nums].     Intersection::heads: Heads DeleteDuplicates and List at positions 2 and 1 are expected to be the same.     Inverse::luc: "Result for Inverse of badly conditioned matrix {{0.6,-0.7,-0.2},{-0.4,0.6,-0.1},{-0.2,-0.3,1.}} may contain significant numerical errors."     Inverse::sing: "Matrix {{0.7,-0.8,0.},{0.,0.9,-0.9},{-0.7,0.,0.8}} is singular."      I'm assuming that the first three error messages are because I'm not formatting the input to SubSetQ in the appropriate list format, but I don't know how to fix it, and I don't know why I'd be getting the "singular" error message.


title: Find asymptotics of Sum[2^i*Binomial[n-i-1,2*n/3-1],{i,0,n/3}]

text: I have an expression               2^n / Sum[ 2^i Binomial[ n - i - 1, 2n/3 - 1], { i, 0, n/3}]      > >     2^n / ( Binomial[ -1 + n, -1 + (2 n)/3] Hypergeometric2F1[ 1, -(n/3), 1 > - n, 2]) >   I would like to find if there is an exact asymptotic expression for this for large $n$.   I suspect it is something like $\;\sqrt{n}\;\;1.06^{\;n}\quad$ from numerical experiments.   Is it possible to work out it out exactly using _Mathematica_?


title: Replacing variables in an RSolve expression

text: I have a recursive expression, which is something like: $$ a(n,x)=f(x,y,m)\,a(n-1,x)+g(x,y)\,a(n-1,y) $$ where $f(x,y,m)$ and $g(x,y)$ are known. So the second $a$ depends on $y$ rather than $x$. I tried to get it into `RSolve` with:               RSolve[{a[n] == f[x, y, n]*a[n-1] + g[x, y]*(a[n] /. {x -> y}), a[0]==1}, a[n], n]      but the `/.{x ->y}` part doesn't seem to change anything. How can I do the replacement?


title: What are all the named Mathematica styles?

text: This question came to mind because of this answer to a recent question. Under Style, the _Mathematica_ Documentation Center says the following about named styles. > A few common named styles include: "Button", "Graphics", ..., "Title" Altogether it lists 13 named styles, but the phrase "a few of" implies there are more. Other cell styles such as "SubTitle" and "SubSubSection" come to mind. But strings other than those naming cell styles evidently qualify as named styles. In the referenced answer, Mr.Wizard uses "TI" as a named style for the "Times Italic" font.               Style["The quick brown fox ...", "TI"]      ![TI.png](http://i.stack.imgur.com/pYZxH.png) By trial and error, I have found these addition named styles:               "TR"   (Times Roman -- plain Times)     "TB"   (Times Bold)     "TBI"  (Times Bold Italic)     "SR"   (Sans serif Roman -- plain sans serif)     "SB"   (Sans serif Bold)     "SO"   (Sans serif Oblique)     "SBO"  (Sans serif Bold Oblique)      I wonder what other named styles exist, other than cell styles, that _Mathematica_ will accept in a `Style` expression. I further wonder what sort of spelunking in _Mathematica_ would turn them up.


title: Simplifying with noncommutative multiplication

text: I am trying to do some quantum algebra computations in _Mathematica_. Up to now I was able to make the noncommutative multiplication linear and to factorize powers. However, I still have some issues with associativity. In particular, I would like to be able to remove brackets expressions like `a ** ( b ** c )` and get `a ** b ** c`. The reason for that is that I already have a procedure that substitutes `a^2 ** b` to `a ** a ** b`, but this doesn't work when I have brackets `(a ** ( a ** b ))`.   Does anyone know how to overcome this problem?


title: Variable Boundaries on ParametricPlot3D

text: Is there any way to plot correctly using the `ParametricPlot3D` command with one of variable's boundaries defined in function of the other ? In the example given here the variables are `u` and `r`.   * `r` boundaries are set from `0.01` to `d/2`   * `u` boundaries are set from the lower limit function `x0(r)` and upper limit function `corda(r)-x0(r)` I noticed a problem on the leading edge of this wing profile present only when using a variable boundary, while if I use a constant boundary limit the wing is plotted correctly. Any ideas on how to solve this problem? The code is presented below for reference.               c = 1;  e = 2;  d = 0.35;     (*Distribuição de Corda*)     corda[r_, c_] := c ( -30.04*r^3 + 4.65*r^2 + 0.116*r + 0.01)     (*Distribuição de Espessura*)     naca[r_, e_] := e ( -47.511*r^3 + 13.346*r^2 - 1.3953*r + 0.1511)     x0[r_, c_] := 0.4 corda[r, c]     (*Imagem do Perfil*)     FNaca[u_, r_, c_, e_] :=         (naca[r, e]/0.2) corda[r,c] (  0.2969 Sqrt[(u + x0[r, c])/corda[r, c]]                                       - 0.126 (u + x0[r, c])/corda[r, c]                                      - 0.3516 ((u + x0[r, c])/corda[r, c])^2                                      + 0.2843 ((u + x0[r, c])/corda[r, c])^3                                       - 0.1015 ((u + x0[r, c])/corda[r, c])^4 )     m = 0.04;  p = 0.4;     (*Camber Bordo de Ataque*)     ba[u_, r_, c_] := m (u + x0[r, c]) ( 2 p - (u + x0[r, c])/corda[r, c])/p^2      (*Camber Bordo de Fuga*)     bf[u_, r_, c_] :=         m ((corda[r, c] - (u + x0[r, c]))/(1 - p)^2) ( 1 + (u + x0[r, c])/corda[r, c] - 2 p)     PerfilSup[u_, r_, c_, e_] := If[ u + x0[r, c] <= p corda[r, c],                                      FNaca[u, r, c, e] + ba[u, r, c],                                      FNaca[u, r, c, e] + bf[u, r, c] ]     PerfilInf[u_, r_, c_, e_] := If[ u + x0[r, c] <= p corda[r, c],                                     -FNaca[u, r, c, e] + ba[u, r, c],                                     -FNaca[u, r, c, e] + bf[u, r, c]]     d1[u_, r_, c_, e_] := PerfilInf[u, r, c, e]     f1[u_, r_, c_, e_] := PerfilSup[u, r, c, e]          ParametricPlot3D[{ {d1[u, r, c, e], u, r}, {f1[u, r, c, e], u, r}},                        {r, 0.01, d/2}, {u, -x0[r, c], corda[r, c] - x0[r, c] } ]


title: Export high resolution figure causes missing ticks

text: I understand that _Mathematica_ has a bug when exporting images. The ticks are scaled not correctly when exporting at high resolution. For example: when you do:               Export["xx.png", plot, ImageResolution -> 360];      The image looks good, but all the frame ticks are all gone. When you do               Export["xx.png", plot, ImageResolution -> 100];      The ticks are there, but the resolution of the image is not good enough. I tried the trick of using `ImportString` and `ExportString`:               ImportString[ExportString[plot, "PDF"]      It works, but creates another problem: the `PlotRangeClipping` option is missing, and the figure has plot lines sticking out all the way to the boundary of the image, not the boundary of the axes. Can someone provide an easy and relatively universal workaround?


title: Explicit StreamPoint

text: I have trouble with getting the explicit initial StreamPoint to work. The number of streamlines are not the same as the number of initial points. What am I doing wrong?               Clear["Global`*"]     KDIM = 178.2;     KDNA = 9900;     n = 7;     b1 = 1.6;     b4 = 0.003;     b3 = b4/10;     b2 = (b1 + b3)/2;     b1 = b1 - b4; b2 = b2 - b4 ; b3 = b3 - b4;          gamma1 = 0.0012;     gamma2 = 0.0012;     r2 = 2.3;     M[x1_] := (KDIM/KDNA)*((1 + (1 + (4/KDIM)*(2*x1))^(1/2))/(2*(2*x1)))^2;     Y1[x1_, x2_] := r2*x2 - gamma2*x1;     Y2[x1_, x2_] := n*((M[x1]/(1 + M[x1]*3*x1))*(b1 + b2 + b3)*x1) + n*b4 - gamma1*x2;     eqs = { Y1[x, y], Y2[x, y]};          xmin = 20000;     xmax = 50000;     ymin = 0;     ymax = 30;     points = Tuples[{Range[xmin, xmax, xmax/20],Range[ymin, ymax, ymax/5]}];     gv = VectorPlot[eqs, {x, xmin, xmax}, {y, ymin, ymax},VectorPoints -> Fine, VectorScale{Automatic, Automatic},StreamPoints -> points, StreamStyle -> {Red, "Line"},PlotRange -> {{xmin, xmax}, {ymin, ymax}}]      ![Too Few Streamlines\]!\[I expected to get 100 streamlines, but I am only getting 2 and they are short](http://i.stack.imgur.com/6gKj2.jpg) I expected to get 100 streamlines, but I am only getting 2 and they are short


title: Why are my recursive functions running so slowly? And how do I fix them?

text: I am working with making numerical solvers for a modeling class I am in, and I want to use the internal recursion handling that is built into mathematcia, but there seems to be a problem. NDSolve gives me very rapid results that match up with these, but they are so slow. Euler's method for 20 steps is taking nearly a minute to complete, and Runge-Kutta simply sits there for forever if I go above 6 steps. I know they should be faster, and I could do them as for loops easily enough, but I want to know how to make these work as quickly as they should be. I am sure that I am just missing something.               (*Euler's Method*)     a = 20;     h1 = 2./(a);     f1[t_, x_] := 2 x - 2 t^2 - 3;     t1[k_] := t1[k - 1] + h1;     y1[k_] := y1[k - 1] + h1*f1[t1[k - 1], y1[k - 1]];     t1[0] = 0;     y1[0] = 2;     y1[a]          (*Runge-Kutta*)     b = 6;     h2 = 2/b;     K1[k_] := h2*f2[t2[k], y2[k]];     K2[k_] := h2*f2[t2[k] + 1/2*h2, y2[k] + 1./2*K1[k]];     K3[k_] := h2*f2[t2[k] + 1/2*h2, y2[k] + 1/2*K2[k]];     K4[k_] := h2*f2[t2[k] + h2, y2[k] + K3[k]];     f2[t_, y_] := 2 y - 2 t^2 - 3;     t2[k_] := t2[k - 1] + h2;     y2[k_] := y2[k - 1] + 1/6 (K1[k - 1] + 2*K2[k - 1] + 2*K3[k - 1] + K4[k - 1]);     t2[0] = 0;     y2[0] = 2;     y2[b]


title: How can I calculate the limit without using the L'Hopital's rule

text: I need to prove this limit without using the L'Hopital's rule: $$\lim_{x\to 0} \frac{(1+a\,x)^{1/4} - (1+b\,x)^{1/4}}{x} = \frac{a-b}{4}$$ How can I do it in _Mathematica_?


title: Find the longest constant sublist

text: Given a list               list = {1,2,2,2,2,5,1,3,2,6,6,6,6,6,6,6,6,6,6,6,10,-3};      how to find the longest constant sublist (or equivalently the element and the number of times it is repeated)? (in this example, {6,6,6,6,6,6,6,6,6,6,6} or {6,11})


title: Read in bezier curve from svg file

text: I am trying to do some calculation of some svg file,After read in with `Import["filename","XML"]`and some easy operation, I can get the string of the bezier curve, which is               "m", "10.297065,122.86673", "c", "-1.1327165,-2.9517", \     "-1.9996959,-5.44247", "-1.926621,-5.53505", "0.073075,-0.0926", \     "3.957119,-0.67937", "8.63121,-1.30398", "C", "51.148046,111.46463", \     "75.614452,102.94", "87.948536,91.308267", "L", "93.5,86.072926", \     "68.309017,86.036463", "c", "-13.855041,-0.02005", \     "-25.421756,0.336936", "-25.703812,0.793312", "-0.282056,0.456376", \     "1.914958,3.227403", "4.882253,6.157839", "l", "5.395081,5.328064", \     "-4.191269,3.372522", "-4.19127,3.37251", "-5.633788,-6.202247", \     "-5.633788,-6.202251", "-8.192543,4.262229", "c", \     "-4.505899,2.344227", "-8.454026,4.000749", "-8.773616,3.681159", \     "-0.31959,-0.31959", "-1.579212,-2.234924", "-2.79916,-4.256295", \     "l", "-2.218088,-3.675221", "7.125491,-3.411753", "c", \     "9.721447,-4.65472", "21.775439,-12.818376", "29.827634,-20.200987", \     "l", "6.702143,-6.144822", "4.047857,2.065063", "C", \     "61.178464,66.111369", "63,67.351969", "63,67.732472", "c", \     "0,0.380504", "-1.893694,2.621358", "-4.208208,4.979676", "L", \     "54.583584,77", "80.791792,77", "107,77", "l", "0,4.300463", "c", \     "0,3.602014", "-0.69025,5.119122", "-4.25,9.341089", "C", \     "92.980914,102.22798", "77.402299,111.67795", "57,118.39344", "c", \     "-11.332786,3.73023", "-30.101934,8.14519", "-39.071725,9.19063", \     "l", "-5.571726,0.64939", "-2.059484,-5.36673", "z"      how the data is managed is described in this link, so, It there any good way to get a bezier function out of this data?


title: Conditionally formatting elements in a list

text: I have a list `{{a1, a2, a3},{b1, b2, b3}, ...}` and I want to replace the numbers less than 10 by `0x` (just insert a 0 before the element, so that `2 -> 02`, `3 -> 03`, etc). How can I do that? To clarify, I will later export this table and run it through a program that will upload it to a database. These number are identifications for different objects, and for some reason the list needs to be all aligned. If I just export it as it is, I would get something like > >     1  2  3 >     20  40  55 >   which the program can't read.


title: How to scale Histogram counts with the value of bin center?

text: I am analyzing some variates from a steeply falling power-law distribution (approximately with a power index -4) using               Histogram[data, Automatic, "PDF"]      While the option `ScalingFunctions->{"Log", "Log"}` helps a lot in keeping the results in perspective, I cannot really see small deviations from the power law since the dominant trend in the log-log view will be a linear function with approximate slope -4. The usual trick in such studies is to scale the resulting pdf by dividing it with the approximate trend, i.e. for the bin entries I want something like               ScalingFunctions->{"Log", Function[{count, center}, Log[center^4 count]]}      instead of only `Function[x, Log[x]]` which I get with the `"Log"` option. Unfortunately `Histogram` seems to call this function with only one argument which is the corresponding bin count (or pdf value in my case), unlike e.g. `Plot` which calls `RegionFunction` with all the coordinates and similarly other plotting functions in Mathematica. Is there a way to convince Mathematica to call the scaling functions not only with the bin value but also with the bin center or location of bin edges?


title: Sorting an Array with words in different languages

text: Array consists of words of different languages. I need to sort elements in reverse alphabetical order and make a list of elements, which consist of english letters. Example of array which consist of english and russian words:               m = {"computer", "экзамен", "elephant", "стол", "bread", "телефон",         "exception", "desktop", "best", "колонка", "zoom", "saphire",         "ярость"};      Sorting with `Reverse@Sort[m]` and `Sort[m]` work with english words only. `Select[m, LetterQ]` can make a list of english words. Problem is a different language (Russian in this e.g.)


title: Can I run calculations on an external ssh server that doesn't have Mathematica installed?

text: I am currently running some rather compilex _Mathematica_ calculations on my laptop and sometimes run into an out-of-memory errors. However, I have access to some larger simulation servers via ssh, but they don't have _Mathematica_ installed on them. Is there a possibility I can use this additional calculation-power for my calculations? (I already found ConnectToARemoteKernel but if I understand correctly this only works, if _Mathematica_ is installed on both systems.)


title: Volumetric Rendering of cylinder symmetric radial image

text: I would like to render a cylinder symmetric radial cross-section with Image3D. As an example one could use the propagation of a Bessel Beam through a Lens: ![Bessel Beam Focusing](http://i.stack.imgur.com/C6VOD.png) Here the cylinder axis is the bottom of the image and the radial coordinate is along the vertical direction of the image. A 3D volumetric rendering would show the resulting focus ring at a radius of 1mm very nicely. My solution is very slow and uses a tomographical approach by generating array plots of rotated image rows and stacking them together in Image3D.               inpdata =        ImageData[        Import[NotebookDirectory[] <> "<Filename of image to rotate>.png"]][[;; , ;; , 1]];     outdata =        Monitor[Table[tint = Interpolation[Reverse[1 - inpdata[[;; , i]]]];          Image[ArrayPlot[           Table[Piecewise[{{tint[Sqrt[x^2 + y^2]],                Sqrt[x^2 + y^2] < Length[inpdata]}},              0], {x, -Length[inpdata],              Length[inpdata]}, {y, -Length[inpdata], Length[inpdata]}],            Frame -> False, ImageMargins -> None,            ColorFunctionScaling -> False]], {i, 1, Dimensions[inpdata][[2]], 1}], i];     Image3D[outdata]      I hope that there is a more efficient way to do this in _Mathematica_...


title: NIntegrate issue to do with unknown types

text: I have a numerical function zz:               zz[s_ ? NumericQ] := so3toE3[Inverse[yn[s]].ND[yn[k], k, s]];      The other functions involved have 2 pages of code defining them so I will leave it at that for now unless asked to give more detail               Print[A0];     Print[ND[zz[kk], kk, 1]];     Print["J1 A=0 ", NIntegrate[Norm[ND[zz[kk], kk, tt] ], {tt, 0, 1}, Method -> {"TrapezoidalRule", "Points" -> 100}, MaxRecursion -> 0, PrecisionGoal -> 3]]     Print["J1 A only ", NIntegrate[Norm[A0], {tt, 0, 1}, Method -> {"TrapezoidalRule", "Points" -> 100}, MaxRecursion -> 0, PrecisionGoal -> 3]];     Print["J1 ", NIntegrate[Norm[ND[zz[kk], kk, tt] - A0], {tt, 0, 1}, Method ->{"TrapezoidalRule", "Points" -> 100}, MaxRecursion -> 0,  PrecisionGoal -> 3]];      The output of the preceding statements are:               {0.5,-0.1,0.}     {-1.57106,4.25392,-0.435128}     J1 A=0 4.21996     J1 A only 0.509902      These are as expected. The problem happens when I then try and subtract A0 from the other expression:               NIntegrate::inum: Integrand Sqrt[Abs[-0.5+1/63 (Times[<<2>>]+Times[<<2>>])]^2+Abs[0. +1/63 (Times[<<2>>]+Times[<<2>>])]^2+Abs[0.1 +1/63 (Times[<<2>>]+Times[<<2>>])]^2] is not numerical at {tt} = {0.}. >>     NIntegrate::inum: Integrand Sqrt[Abs[-0.5+1/63 (Times[<<2>>]+Times[<<2>>])]^2+Abs[0. +1/63 (Times[<<2>>]+Times[<<2>>])]^2+Abs[0.1 +1/63 (Times[<<2>>]+Times[<<2>>])]^2] is not numerical at {tt} = {0.}. >>     J1 NIntegrate[Norm[ND[zz$1746189[kk],kk,tt]-A0$1746189],{tt,0,1},Method->{TrapezoidalRule,Points->100},MaxRecursion->0,PrecisionGoal->3]      Why is subtracting `A0` from `ND[zz[kk], kk, tt]` causing a problem even though I know they are both vectors of the same dimension? Is there a way of 'declaring' that `zz` is a vector of `Length[]` equal to 3? Thanks.


title: Dynamic ListLinePlot

text: I have a list of lists looking like this: `{{{x1, y1}, {x2, y2}}, {x1, y1},...}}`. Furthermore I have defined a legend, which is taken from the filenames. Now I want to plot this data dynamically, add/remove sub-lists in a `ListLinePlot`, e.g. with a `Checkbox`. This is the part of the code I have so far: Importing the data:               files = FileNames["*.dat"];     data = Import[#, "Data"] & /@ files;     legend = StringReplace[files, ".dat" -> ""];      So far I have made the plot like this:               plot1 = ListLinePlot[data[[1]], PlotLegends -> legend[[1]]];     plot2 = ListLinePlot[data[[2]], PlotLegends -> legend[[2]]];          Manipulate[     Show[       If[x1 == True, plot1, Sequence @@ {}],       If[x2 == True, plot2, Sequence @@ {}],       {{x1, True, "plot1"}, {True, False}}, {{x2, True, "plot2"}]      Is there maybe a more elegent way of realizing this, maybe automatically, for list of sub-lists?


title: How to enumerate multisets?

text: Given the eight-element set `{1,2,3,4,5,6,7,8}`, I would like to enumerate all multisets (subsets with repetition) of size `n`, where `n >= 3`. For example, with `n = 3`, the sets `{1,1,1}, {1,1,2}, ..., {8,8,7}, {8,8,8}` would all be found. Ideally, I would like to be able iterate through each set, rather than create one gigantic program-crashing list, so that I can use each set at the time it is found. Since `Binomial[n, k]` only works for values of `k <= n`, I'm not sure how to best go about this.


title: Mathematica output in ASCII or larger text size for the output?

text: I am trying to read the output of this code that has crosses, circles and spaces. For some reason, the output is in very-very small alphabets so I would like to get it in ASCII and/or in larger alphabets to be more easily readable. ![enter image description here](http://i.stack.imgur.com/1JSgH.png) So >   1. how can I get Mathematica output in ASCII let say with the earlier > style table having only crosses, circles and spaces? > >   2. is there some setting to control the output formatting to specify the > size of writing such as the crosses, circles and errs? Are there environment > variables to adjust the size of the writing? > >


title: Unexpected behavior of Unevaluated

text: _Maybe it is about time I read some proper text about the main loop. Maybe I should not care (so much) about Unevaluated (as Leonid suggests). But I think this is an interesting question anyway._ This question of mine got a bit ruined by the fact that I got a bit confused. I hope this separate question will take away this confusion. My confusion was that I found it strange that we have, for               x = 3;     g[_Symbol] := "yay"      that as expected               g[Unevaluated[x]]      -> "yay" but               g[_Symbol] := "yay"     g[Sequence[Unevaluated[x]]]      -> g[Unevaluated[x]] and even               With[{yyyy = g[Sequence[Unevaluated[x]]]}, Identity[yyyy]]      -> g[Unevaluated[x]] The strange thing here is that even though `g[Unevaluated[x]]` is not in its "final form" (at a fixed point), in the sense that a rule can be applied to this as we can see above, Mathematica stops evaluating. I show the third example in which With occurs, because one might have thought that the behavior occurs because Mathematica assumes that rules for g have already been applied or something. But even when we use With (or in fact, Identity, With is really not necessary) to start a "clean evaluation", Mathematica refuses to do the last step. For a little while, I had the following question/hypothesis about this: "Does Mathematica remember if an expression has been fully evaluated?". Using that I found another similar example. We have               Clear[h, somethingElse, something]     h[something, something = somethingElse]      -> h[something, somethingElse] even though, if we evaluate the resulting expression again, we have               h[something, somethingElse]      -> h[somethingElse,somethingElse] But this time, we have               Clear[h, somethingElse, something]     Identity[h[something, something = somethingElse]]      -> h[somethingElse, somethingElse] So that Mathematica does continue evaluation in this case. The same happens for a user-defined Identity. Note that the following does not result in a "fixed point" (expression that is left unchanged by the rules).               Clear[h, somethingElse, something]     List[h[something, something = somethingElse]]      -> {h[something, somethingElse]} Which probably makes sense. I guess Identity is defined in terms of a rule, and after a rule we have to evaluate again. However, if we put something in a list, we can assume that the thing inside the list was evaluated correctly so we don't have to evaluate again. Little tentative conclusion: It is not true that Mathematica repeatedly evaluates an expression until it does not change anymore. It seems to be a little more subtle than that. The question is: Is it a bug that               g[_Symbol] := "yay"     Identity[g[Sequence[Unevaluated[x]]]]      Evaluates to               g[Unevaluated[x]]      ?


title: Expanding Matrix Expressions

text: I want Mathematica to recognize that               A.(-B.C)+A.B.C = 0      Yet FullSimplify and the like leaves the expression as it is. How do I get around this?


title: User-defined DistanceFunction for RegionNearest

text: In the function `Nearest` , I can define my custom function using the `DistanceFunction` option. e.g:               dist[{u_, v_}, {x_, y_}] := 3 Abs[u - x] + 2 Abs[v - y]      Which I can use like this               Nearest[{ {1.5, .6}, {2, 0}, {1.25, 1.25}}, {0, 0}, DistanceFunction -> dist]      Is it possible to give a user-defined `DistanceFunction` for `RegionNearest` in **V10**? I don't see how to do this.


title: How to model shocks to parameter in a dynamic system?

text: My simple model is:               m[t_] := m[t] = m[t - 1]*p + 2     m[0] = 0     p = 0.5      I can plot the system as:               DiscretePlot[m[t], {t, 0, 50}]      Now, I would like to shock `p` for a short period, say, from 10 to 13 during which it would be 0.8 and then recovering its original value, 0.5, afterwards. Would `Insert` do this?