Adapt ticks in plot and font in legend

Some of my 2-dimensional data are displayed with a code similar to this:               Needs["PlotLegends`"]     sampleData =      Transpose[{RandomVariate[NormalDistribution[0, 3*10^-6], 20000],      RandomVariate [NormalDistribution[0, 3*10^-6], 20000]}];      binning = {{-1*10^-5, 1*10^-5, 1*10^-7}, {-1*10^-5, 1*10^-5,1*10^-7}};     (*binning of my sampleData*)     maxBinnedData=Max[HistogramList[sampleData,binning][[2]]];     (*seachring for the maximum of the binned data*)     ShowLegend[DensityHistogram[sampleData,binning,LabelingFunction->None,     PerformanceGoal->"Speed",      ColorFunction->(If[1-#1===0,White,ColorData["Rainbow"][#1]]&),     ColorFunctionScaling->True,PlotRange->{{-1*10^-5, 1*10^-5},{-1*10^-5, 1*10^-5}},      FrameLabel->{"x", "y"},     LabelStyle->Directive[Black,FontSize->12,FontFamily->"Arial"],ImageSize->{500,500}],{(If[1-#1===0,White,ColorData["Rainbow"][1-#1]]&),11,     ToString[maxBinnedData],ToString[0],LegendTextOffset->{-2, 0},     LegendPosition->{1.1,-0.4},LegendShadow->None,     LegendLabel->Style["Counts",Black,FontSize->12,FontFamily->"Arial"]}]      The output is quite nice for my taste (see figure).![Output of my code](http://i.stack.imgur.com/uk3zH.png) Yet, I want to improve two things, but all my attempts have been unsuccessfully so far. First: How can I manage that the ticks are all in scientific form (e.g. $1.0\times10^{-5}$ instead of 0.00001)? Somehow I was not able to adapt the tricks of e.g. this post to my problem. I could do it perhaps by hand, but the scale is often different (e.g. from $-2.4 \times 10^{-5}$ to $4.0 \times 10^{-6}$) so that this will be unhandy. Second: As perhaps can be seen, I try to use for all names and numbers the `FontSize->12` and the `FontFamily->“Arial”`. That works fine except for the numbers in my legend (0 and 20). How do I have to change the font setting there? I tried things like `Style[ToString[maxBinnedData], Black, FontSize -> 12, FontFamily -> "Arial"]` instead of `ToString[maxBinnedData]` but nothing worked. I would be happy if some people here could give me some hints!


backward compatibility

When producing or enhancing code, it is tempting to use recent new primitives of Mathematica introduced in version 7 and 8, but for library code or in preparation or future version change in production code, it is better to be compatible with slightly older versions while maintaining only one version of the code. To do this, I have sometimes written washed-down versions of list manipulation or other primitives of Mathematica 6, 7 and 8 that can run on Mathematica 3, 4 or 5 in a separate .m file that I include in the dependencies of my personal packages. Of course they are most of the times less efficient and less general than the original ones but often sufficient to have the code running. Have others have done the same thing and if so, are there already published resources on this? (Note: we could probably merge these efforts (and test cases, etc.) to have a more or less standard "backward compatibility" code. This could also help people maintaining code on hardware which cannot be updated and would be fun as problem solving !)


How to resize the text content of a grid with it?

I am in a resizing mood these days. This code works quite well, up to a point.               Grid[Partition[       Table[Pane[Style[FromCharacterCode[96 + i], FontSize -> 150],          ImageSizeAction -> "ResizeToFit",          ImageSize -> {Scaled[1], Scaled[1]},          Alignment -> {Center, Center}], {i, 1, 25}], 5], Dividers -> All,       ItemSize -> {Scaled[.2], Scaled[.2]}]      It makes a 5x5 grid of 25 letters with boxes extending and shrinking according to the Notebook's width, and the strings centered in each box. The letters also shrink and expand accordingly. That's the minimal example of what I wanted. But when I shrink the window a little too much, the result is clipped instead of shrinked: ![enter image description here](http://i.stack.imgur.com/2FYoQ.png) And when I enlarge the window a little too much, depending on the fontsize used, the letters stop to enlarge as well, as you could probably guess, this is not what I want. Moreover, I would like the code not to be dependent on an heuristic font size. I have tried various options but without success. Any idea, any better code ?


Scoping in assigning a derivative

While answering another question, I stumbled upon a problem I cannot easily resolve. To assign the derivative of a function to another function, typically one can do this with a `Set` or a `SetDelayed`:               f[x_]=D[Sin[x],x]     f2[x_]:=Evaluate@D[Sin[x],x]      Both give the same result, since forcing evaluating on a `SetDelayed`is essentially the same as using `Set`. However, **both** can give rise to naming conflicts, i.e.               x=7;     f[x_]=D[Sin[x],x]     f2[x_]:=Evaluate@D[Sin[x],x]      won't work. This bothers me a lot, because the reason I always use `SetDelayed`is to avoid this (sometimes difficult to find) type of bugs. So I tried to force some kind of local scoping, but until now didn't find a working solution. Using               f3[x_]:=Evaluate[Block[{x},D[Sin[x],x]]]     f4[x_]:=Evaluate[Module[{x},D[Sin[x],x]]]     f5[x_]:=Evaluate[With[{y=x},D[Sin[y],y]]]      doesn't work, because `Block` and `With` release the variable too fast and `Module` renames it locally (as can be seen by doing `?f3`, `?f4` or `?f5). What does work, is using               f6[x_] := With[{y = x}, Evaluate@D[Sin[y], y] /. y -> x]      And it works even when both `x` and `y` already have an assigned value. However, if we look at its definition, we get:               ?f6     Global`f6     f6[x_]:=With[{y=x},Evaluate[D[Sin[y],y]]/. y->x]      This is not what I want, because now the evaluation is delayed. Whenever my original function (here `Sin[x]`) is much more complicated, the derivation can take some time. If I need to calculate a lot of values of `f6`, this will stack up to a huge amount of time. Any ideas to get a 'name-conflict-safe' derivative assignment which evaluates at its definition? Thanks!


Calculus 1: Create the  plot of a function satisfying certain conditions

Today in class we were shown how to create an infinite limit graph (plot) given the preceding conditions. While I have a fairly terrible sketch of this graph in my notebook, I'd like to create a clean version with Mathematica to import into my notes. Here were the conditions: $$ \begin{align*} g(2)&=1\\\ g(5)&=-1\\\ \lim_{x\to4}g(x)&=-\infty\\\ \lim_{x\to-7^-}g(x)&=\infty\\\ \lim_{x\to-7^+}g(x)&=-\infty\\\ \end{align*} $$ Any help would be appreciated!


Finding maximum/minimum value of system of inequalites

How would I get the maximum values for `x1` and `x2` given that I have plotted the region governed by the following system of inequalities? Basically want to find the smallest bounding box around the plot's coordinates               (x1 == -120 && x2 == 240) || (-120 < x1 <= -12 && -2 x1 <= x2 <= 120 - x1) ||      (-12 < x1 <= 0 && (60 - x1)/3 <= x2 <= 120 - x1) ||      (0 < x1 <= 30 && 1/3 (60 - 2 x1) <= x2 <= (240 - x1)/2) ||      (30 < x1 <= 60 && 30 - x1 <= x2 <= (240 - x1)/2) ||      (60 < x1 < 90 && 30 - x1 <= x2 <= 120 - 2 x1) || (x1 == 90 && x2 == -60)      I tried using the maximize function and maxvalue but both did not seem to work? E.g. > MaxValue::objv: The objective function (System of inequalities here) > contains a nonconstant expression Less independent of variables {x1,x2}. >> Could someone please tell me what to do here? Thanks


How to select the text on the button?

For example, I have a `Button`               Button["http://www.wolfram.com",        NotebookLocate[{URL["http://www.wolfram.com"], None}],        Appearance -> None]      How to select text with the mouse?


Parameter Estimation of a mixture of sums of Lognormals

Let $X$ be a random variable that is of a mixture distribution of two lognormals (with the same sigma), so $X \approx p\cdot \mathcal L (\mu_1, \sigma) + (1-p)\cdot \mathcal L (\mu_2,\sigma)$. Now set $Y=X_1 + X_2$, so $Y$ is a sum of two samples from this mixture. First I generate some data according to this distribution:               dMix[p_, m1_, m2_, s_] :=      MixtureDistribution[{p, 1 - p}, {LogNormalDistribution[m1, s],      LogNormalDistribution[m2, s]}];          dat = Plus @@ RandomVariate[dMix[0.75, 0.5, -1.5, 0.2], {2,100}];      this is the pdf of my distribution, using `TransformedDistribution`               dMixSum =       TransformedDistribution[x1 + x2,        Thread[Distributed[{x1, x2},         MixtureDistribution[{p, 1 - p}, {LogNormalDistribution[m1, s],          LogNormalDistribution[m2, s]}]]]];          pdf[z_] = PDF[dMixSum, z];          pDist = ProbabilityDistribution[pdf[z], {z, -Infinity, Infinity},        Assumptions -> DistributionParameterAssumptions[dMixSum]]      Now `FindDistributionParameters` should do the job (but it doesn't)               FindDistributionParameters[dat, pDist, {{m1, 1}, {m2, -1}, {s,       1}, {p, .5}}]      I think this is because the sum of two lognormals is not lognormally distributed (in a closed form), it is only approximately lognormal. Can I tell mathematica somehow to take this into account or is there another way to solve this?


Solving a trigonometric equation with one parameter

I have the following equation:               2 a^2 k^2 Sin[b k] - 6 a (k Cos[b k] - Sin[b k]/b) == 0      I set the value of `b` to 1, and I want to plot the value of `k` as it ranges over 0.01 to 6.0 in increments of 0.01. When the above equation becomes zero for some value of `a`, I want to print the value of `k`. Later I will plot `k` as a function of ratio `a/b`. This is a general question, but I am struggling with the logic can to solve this. Do I put it in a loop?               xxx = 2 a^2 k^2 Sin[b k] - 6 a (k Cos[b k] - Sin[b k]/b)     b = 1;     Do[If[xxx == 0, {Print[k], Print[a]}, Continue[]], {a, 0.01, 6, 0.01}]      Thanks


How do I fix Needs["OpenCLLink`"] failure?

In Mathematica 8.0.4 under Mac OS X 10.8.2, when I evaluate               Needs["OpenCLLink`"]      I get error `General::cdir: Cannot set current directory to authserver.` Where should that directory be?


Using Plot3D with one variable dependent on the other

Plot3D[f,{x,xmin,xmax},{y,ymin,ymax}]      In the above , is there any way to give range of y in terms of x. I want to give like `{x, 0, 9000}` and `{y, x, 9020-x}` and `f = 9020/(9020 + y)`.


FindMaxValue specifics

I'm using `FindMaxValue` to study the distribution of maxima of `Abs[RiemannSiegelZ[t]]` between consecutive values of `ZetaZero`, Some background: `RiemannSiegelZ[t]` is `Zeta[1/2+I* t]` 'with the phase taken out'; i.e. real for real $t$ and with the same absolute value as `Zeta`. Outside of _Mathematica_ this is known as Hardy's function $Z(t)$. On the Riemann Hypothesis, $Z(t)$ has no positive local minima or negative local maxima 'for $t$ sufficiently large' (see Edwards' book "Riemann's Zeta Function".) In fact $t>5$ is sufficient. Thus on the Riemann Hypothesis $Z(t)$ is positive (resp. negative) and concave down (resp. up) with a unique local maximum (resp. minimum) for $t$ between `ZetaZero[2k-1]` and `ZetaZero[2k]` (resp `ZetaZero[2k]` and `ZetaZero[2k+1]`). To determine the maxima, I'm less concerned with speed or precision than I am with robustness. The documentation says that > `FindMaxValue[f,{x, x0, x1}]` searches for a local maximum in `f` using `x0` > and `x1` as the first two values of x, avoiding the use of derivatives. Is this routine _guaranteed_ to return a value between `x0` and `x1` if there is in fact a unique local maximum there (i.e., guaranteed to not jump outside the interval)? Should I be using a `Method` other than `Automatic`, and if so, which one? The documentation also says: > `FindMaxValue[f,{x, x0, xmin, xmax}]` searches for a local maximum, stopping > the search if `x` ever gets outside the range `xmin` to `xmax`. It does not say what the parameter `x0` determines but from earlier documentation one would suppose that it is the starting point for the search. What does it mean if the search 'stops'? Does _Mathematica_ return an error message? What is the difference between               FindMaxValue[f,{x, x0, xmin, xmax}]      and               FindMaxValue[{f, xmin < x < xmax}, {x, x0}]      Finally, I'm having difficulties with (I think) the fact that `FindMaxValue` has the attribute `HoldAll`, for example               In[3]:= t1 = N[Im[ZetaZero[1]]]; t2 =       N[Im[ZetaZero[2]]]; tmid = (t1 + t2)/2; FindMaxValue[      RiemannSiegelZ[t], {t, tmid, t1, t2}]          FindMaxValue::nrgnum: The gradient is not a vector of real numbers at {t} = {17.8742}. >>          Out[3]= 2.31595


Simplifying a trigonometric sum

I want to caculate `Cos[θ] + Cos[2 θ]+ ... + Cos[n θ]`               Sum[Cos[k θ], {k, 1, n}]      > >     Cos[1/2 (1 + n) θ] Csc[θ/2] Sin[(n θ)/2] >   But when I use Euler's formula               Re[Expand[ExpToTrig[Sum[E^(I k θ), {k, 1, n}]]]]      I get > >      Im[Sin[θ]/(-1 + Cos[θ] + I Sin[θ])] - >      Im[(Cos[n θ] Sin[θ])/(-1 + Cos[θ] + I Sin[θ])] - >      Im[(Cos[θ] Sin[n θ])/(-1 + Cos[θ] + I Sin[θ])] + >      Re[-(Cos[θ]/(-1 + Cos[θ] + I Sin[θ])) + >        (Cos[θ] Cos[n θ])/(-1 + Cos[θ] + I Sin[θ]) - >        (Sin[θ] Sin[n θ])/(-1 + Cos[θ] + I Sin[θ])] >   Why doesn't _Mathmatica_ simplify it?


Can I customize a TradingChart?

What I would like to do is generate a chart similar to the TradingChart but to have two lines on it instead of the candlestick. The lines I want to plot will look something like this; ![enter image description here](http://i.stack.imgur.com/3YAAl.png) And what I want to do is replace the top plot on this chart; ![enter image description here](http://i.stack.imgur.com/zpd8z.png) The idea is to have the two lines on the DateListPlot with the trading volume bar chart below. By question is am I better off setting up a GraphicsColumn with a DateListPlot and a BarChart or can I modify the TradingChart to get it to do what I want? I'd prefer to modify the TradignChart because it's got some nice interactive content which I don't know how to do myself.


Load a Mathematica Package via .Net code

I'm using C# to pass data to _Mathematica_ and return graphs:               MathKernel k = new MathKernel();     k.CaptureGraphics = true;     k.GraphicsFormat = "JPEG";     k.Compute("Show[Graphics[{Thick, Blue, Circle[{#, 0}] & /@ Range[4], Black, Dashed, Line[{{0, 0}, {5, 0}}]}]]");     pictureBox1.Image = k.Graphics[0];      ![enter image description here](http://i.stack.imgur.com/TVxHw.png) This works until I need to use a package. I'm seeing the raw data is returned instead of an image:               StringBuilder command = new StringBuilder();     command.Append("fakedata01 = With[{n = DayCount[{2008, 01, 01}, {2011, 3, 27}]}, Transpose[{Array[DatePlus[{2008, 01, 01}, #] &, n, 0], #}] & /@ (100. + (Accumulate /@ RandomVariate[NormalDistribution[0, 1], {8, n}]))];");     command.Append("Dimensions[%];");     command.Append("XYZLineGraph[fakedata01, Title -> \"Banks\\[CloseCurlyQuote] Share Prices\", Subtitle -> \"1 January 2008 = 100\", ScaleUnits -> \"Index\", DateLabelFormat -> \"Quarter1\", PartialLastYear -> 2.95/12, Footnotes -> {{\"*\", \"MSCI financials index\"}}, Sourcenotes -> {\"Bloomberg\"}, SpecialGridValues -> 100, PlotStyle -> {Red, XYZDarkBlue, XYZPink, XYZMauve, XYZPaleOrange, XYZTurquoise, Green, Gray}, Epilog -> {Red, Arrow[{{{2009, 3}, 30}, {{2009, 8}, 48}}], Text[\"Label\", {{2009, 3}, 25}]}]");          MathKernel k = new MathKernel();     k.CaptureGraphics = true;     k.GraphicsFormat = "JPEG";     k.Compute("Get[\"XYZ`XYZGraphs`\"];");     k.Compute("Get[\"XYZ`XYZUtilities`\"]");     k.Compute("Show[" + command.ToString() + "]");     pictureBox1.Image = k.Graphics[0];      The error is: **Get::noopen: Cannot open XYZ`XYZGraphs`.** I have installed the Packages in _Mathematica_ so on startup they are available. When I run the command in _Mathematica_ it gives me the expected output. **Does anyone know how to load the packages so they are available via a .NET call?** These two lines dont work:               k.Compute("Get[\"XYZ`XYZGraphs`\"];");     k.Compute("Get[\"XYZ`XYZUtilities`\"]");      I've also tried the following and it has the same problem:               k.Compute("Get[\"XYZ`XYZGraphs`\"];Get[\"XYZ`XYZUtilities`\"];Show[" + command.ToString() + "]");      _I've already seen these threads but they are in Mathematica not in C#:_ http://stackoverflow.com/questions/8385317/load-a-mathematica-package-from- within-a-package http://stackoverflow.com/questions/5567980/building- application-packages-with-multple-packages-and-references-in-mathematic **Edit:** I have managed to overcome the error: `Get::noopen: Cannot open XYZ`XYZGraphs` by not issuing the `Get`, but maybe I do need to get the packages and that's why I'm getting this next error. I'm getting the result back as data, not **-Graphics-** , how do I force it to show? ![enter image description here](http://i.stack.imgur.com/WeG67.png) **Edit 2:** Providing the keyword `Graphics` I got a result but its got an error, any ideas how I fix it? ![enter image description here](http://i.stack.imgur.com/gqgg7.png) **Edit 3:** Sorry to make you dizzy by going in full circles, but now I'm pretty sure I **DO** have to specify the Packages like so:               k.Compute("Get[\"XYZ`XYZGraphs`\"];Get[\"XYZ`XYZUtilities`\"];Show[Graphics[" + command.ToString() + "]]");      And when I do this I get the error again:               Get::noopen: Cannot open XYZ`XYZGraphs`.       Get::noopen: Cannot open XYZ`XYZUtilities`.      **Edit 4:** I'm stumped why they cannot be opened. I took a ProcMon trace and it shows the packages are found and read successfully: ![enter image description here](http://i.stack.imgur.com/DBrgP.png) **Edit 5:** I've discovered loading the packages via .Net has errors: ![enter image description here](http://i.stack.imgur.com/wzny3.png) Does this mean before even trying to `Get` the package that I will need to load them in? Or does this error mean the package is already available to the MathKernel?


Making an animated simulation without procedural loops

I'm still new to Mathematica and this is the first time I've wanted to do something more complicated than plotting and changing parameters of mathematical functions. I want to make a simple simulation of a bus station. Two `SkewNormalDistribution`s with different parameters give the rates for arrivals and services. Basically, the program should draw a number from the arrival distribution, then draw a number from the service distribution, subtract it from the arrivals and go on to the next simulation step. If possible, each number should be represented graphically. For instance, drawing `20` from the arrival distribution could be represented as a list of 20 circles, or 20 `*`s. As far as I know, this is something that could be made with `Animate[]` (and maybe `Table[]`), but I don't even know where to start. I thought of using a `While[]` loop and using `Pause[]` at the end of each step, but I don't think this is a good way of doing it. Edit: Here's the procedural code of what I want to do:               arrivals = SkewNormalDistribution[30, 5, -4];     departures = SkewNormalDistribution[2, 1, 0];          Do[      entries = Round[RandomReal[arrivals]];      services = Round[RandomReal[departures]];      remaining += entries - services;      If[remaining < 0, remaining = 0];      Print[entries]; Print[services]; Print[remaining]; Print["    "],      {n, 10}     ]


How do I solve this equation?

I want to solve the equation $$ f(f(-1)) = \sqrt{2} + g(f(2)), $$ where $$f(x) = \dfrac{a}{x^2} - 3x + 2, \quad g(x) = a\cdot \sin 2x$$ $a$ is unknown. The solution is $a \approx{-5.81}$. I tried               Clear[f];     Clear[g];     f[x_] := a/x^2 - 3 x + 2;     g[x_] := a*Sin[2 x];     Solve[f[f[-1]] == Sqrt[2] + g[f[2]], a]      and               Clear[f];     Clear[g];     f[x_] := a/x^2 - 3 x + 2;     g[x_] := a*Sin[2 x];     Reduce[f[f[-1]] == Sqrt[2] + g[f[2]], a]      but, I got the following error: > "Reduce::nsmet: This system cannot be solved which the methods available to > Reduce." This is a picture of the desired solution that I drew in GeoGebra ![enter image description here](http://i.stack.imgur.com/1Y2sS.png) How can I solve this?


Contour coloring and (List)ContourPlot projection

I have two questions concerning (List)ContourPlots. Since they are related to a single visualization desire, I have combined the questions into a single post. I'm hoping that they will be easy to answer. The first question concerns coloring in (List)ContourPlots. Traditionally, in (List)ContourPlots, a specific color is assigned to a region inside of a contour based upon the magnitude of that region. In light of this, I would like to know: is there a way to apply a contour coloration scheme solely to the contours themselves and not to the regions that they enclose? More specifically, I am wanting to ensure that the regions inside the contours will be transparent, like in `ContourPlot[Sin[x] Sin[y], {x, -3, 3}, {y, -3, 3}, ContourShading -> None]`, when I go to save out the ListContourPlots as a PDF/EPS figure. However, since the interior regions of the contours are no longer colored, I'd like to transfer the color that would have been used for that region to the associated contour that encloses it. If possible, I'd also like to have a white border surrounding the individual contours. My ultimate desire is to overlay the contour plot on top of another image and it can sometimes be difficult to distinguish the colors from the plot from those of the image; consequently, I'm hoping that a white border around each colored contour will help with that. In a related post, I asked about how to apply a perspective transformation to two-dimensional (List)StreamPlots such that it would give the illusion of depth. Since I am still very much a beginner when it comes to Mathematica, I was wondering: is there was a simple way to apply the same idea to (List)ContourPlots? More specifically, I have a ListStreamPlot that is oriented in the exact manner that I need:               data = {{{1, 1}, {1.0, 0.0}}, {{11, 1}, {0.971194, 0.0}}, {{21, 1}, {0.963011, 0.0}}, {{31, 1}, {0.993688, 0.0}}, {{41, 1}, {1.023889, 0.0}}, {{51, 1}, {1.024193, 0.0}}, {{61, 1}, {1.010802, 0.0}}, {{71, 1}, {1.032089, 0.0}}, {{81, 1}, {1.026697, 0.0}}, {{91, 1}, {0.987981, 0.0}}, {{101, 1}, {1.025693, 0.0}}, {{111, 1}, {1.105825, 0.0}}, {{121, 1}, {1.098795, 0.0}}, {{131, 1}, {1.065537, 0.0}}, {{141, 1}, {1.012451, 0.0}}, {{151, 1}, {1.0, 0.0}}, {{1, 11}, {1.0, -0.083697}}, {{11, 11}, {0.932164, -0.106793}}, {{21, 11}, {0.925340, -0.192984}}, {{31, 11}, {1.122307, -0.187170}}, {{41, 11}, {1.161864, 0.085156}}, {{51, 11}, {0.976324, 0.115229}}, {{61, 11}, {0.978851, 0.035055}}, {{71, 11}, {1.049432, -0.030869}}, {{81, 11}, {0.936428, 0.062604}}, {{91, 11}, {0.912342, -0.146168}}, {{101, 11}, {1.147333, -0.143745}}, {{111, 11}, {1.166712, 0.127165}}, {{121, 11}, {1.041843, 0.129961}}, {{131, 11}, {1.045287, 0.083479}}, {{141, 11}, {0.994206, 0.122328}}, {{151, 11}, {1.0, 0.132739}}, {{1, 21}, {1.0, -0.023829}}, {{11, 21}, {0.890156, -0.030084}}, {{21, 21}, {0.674394, -0.050241}}, {{31, 21}, {0.0, 0.0}}, {{41, 21}, {0.658960, -0.210046}}, {{51, 21}, {0.716182, 0.091213}}, {{61, 21}, {0.472093, -0.225292}}, {{71, 21}, {0.732020, 0.265153}}, {{81, 21}, {0.843532, 0.369957}}, {{91, 21}, {0.279971, -0.348445}}, {{101, 21}, {0.963035, -0.753370}}, {{111, 21}, {1.002857, 0.538380}}, {{121, 21}, {0.756004, 0.204065}}, {{131, 21}, {0.806599, -0.138649}}, {{141, 21}, {0.913204,  0.279003}}, {{151, 21}, {1.0, 0.159432}}, {{1, 31}, {1.0, 0.044899}}, {{11, 31}, {0.908289, 0.060171}}, {{21, 31}, {0.856098, 0.122421}}, {{31, 31}, {0.762294, 0.042601}}, {{41, 31}, {0.0, 0.0}}, {{51, 31}, {-0.438033, 0.780580}}, {{61, 31}, {0.382021, -0.726038}}, {{71, 31}, {0.550500, -0.113628}}, {{81, 31}, {0.860478, 0.363810}}, {{91, 31}, {1.373814, -0.269792}}, {{101, 31}, {0.153576, -0.482892}}, {{111, 31}, {0.113453, 0.274464}}, {{121, 31}, {0.286391, 0.307524}}, {{131, 31}, {0.275092, -0.174137}}, {{141, 31}, {0.651551, -0.053446}}, {{151, 31}, {1.0, 0.028982}}, {{1, 41}, {1.0, 0.091944}}, {{11, 41}, {0.942248, 0.107845}}, {{21, 41}, {0.914909, 0.147823}}, {{31, 41}, {0.914062, 0.226842}}, {{41, 41}, {1.090780, 0.280458}}, {{51, 41}, {1.423264, 0.011814}}, {{61, 41}, {1.084930, -0.364051}}, {{71, 41}, {0.899861, -0.177124}}, {{81, 41}, {0.992899, -0.106340}}, {{91, 41}, {1.136605, -0.039446}}, {{101, 41}, {0.830366, 0.086879}}, {{111, 41}, {0.653521, 0.119604}}, {{121, 41}, {0.862727, 0.513709}}, {{131, 41}, {1.041204, -0.599559}}, {{141, 41}, {0.911816, -0.171321}}, {{151, 41}, {1.0, -0.089802}}, {{1, 51}, {1.0, 0.0}}, {{11, 51}, {0.972851, 0.0}}, {{21, 51}, {0.958161, 0.0}}, {{31, 51}, {0.956957, 0.0}}, {{41, 51}, {1.008198, 0.0}}, {{51, 51}, {1.082196, 0.0}}, {{61, 51}, {1.119506, 0.0}}, {{71, 51}, {1.011644, 0.0}}, {{81, 51}, {0.905500, 0.0}}, {{91, 51}, {0.811638, 0.0}}, {{101, 51}, {0.953396, 0.0}}, {{111, 51}, {0.978083, 0.0}}, {{121, 51}, {1.166181, 0.0}}, {{131, 51}, {1.289609, 0.0}}, {{141, 51}, {1.066669, 0.0}}, {{151, 51}, {1.0, 0.0}}};          ypos = 25;     data3d1 = ListStreamPlot[data, StreamPoints -> Fine, StreamScale -> Tiny, StreamStyle -> Thick, StreamColorFunction -> ColorData[{"CandyColors", "Reverse"}]][[1]] /. Arrow[pts_] :> Arrow[{#[[1]], ypos, #[[2]]} & /@ pts];     Graphics3D[Rotate[Rotate[Rotate[{data3d1}, 0 Degree, {1, 0, 0}], 0 Degree, {0, 1, 0}], 15 Degree, {0, 0, 1}], ViewPoint -> .009 {90, -7, 3}, Axes -> False, Boxed -> False]      I would like to ensure that the corresponding ListContourPlot is also oriented in the same way and has the same color scheme applied only to the contours (and not the regions inside the contours) so that I can manually layer it on my background image in LaTeX (tikz/pgf). As an aside, if someone knows how to apply a white border around each of the ListStreamPlot arrows, I'd greatly appreciate a solution for that too!


How can I get WhenEvent to recognize criterion I specify?

Using NDSolve I want to solve a differential equation till a quantity which is a function of the dependent variables reaches a certain value. My functions and criteria are complicated, but I am able to reproduce the error with a simple DE:               a[t_] := x[t]^2     NDSolve[{x'[t] == Sin[t]^2, x[0] == 0,         WhenEvent[a[t] == 1, "StopIntegration"]}, {x}, {t, 0, 10}]      Here is the error message I get: > NDSolve::nbnum1: "The function value x[0.00205297]^2==1 is not True or False > when the arguments are {0.00205297,5.40788*10^-9,4.21468*10^-6}." Any Ideas would be great


Can I evaluate a notebook using Mathematica in text mode on remote machine?

I have a _Mathematica_ notebook file called "my.nb". It was prepared using _Mathematica_ 7.0 on my local machine running the Linux OS. Now, I want to evaluate it on the remote machine, which also has _Mathematica_ 7.0 running on Linux, but this is a separate licence. I log into the remote machine using ssh. I also want to be able to log out immediately after starting evaluation. I know I can use _Mathematica_ in the text mode, typing `nohup math < my_commands.m &`, but then I have to prepare a text file "my_commands.m". This is very irritating, because .nb file is much more clear and easy to modify than the text file. Is there any way to perform a long-running evaluation of "my.nb" on the remote machine (in text mode or in GUI)? By long evaluation I mean that it runs without me being logged in while the evaluation runs to completion.


How can I solve my recursion equation?

How can I solve the recursion equation given below? I doubt there have no solution for the recursion equation because this is circulating recucrsion equation.               RSolve[      If[n >= 3,        S[n] == ((c/m + 1)*S[n - 1] - q*S[n - 2])/q,        {S[2] == (S[1]*(c + m))/(m*q) - 2*S[0],         S[1] == ((S[0] - 1)*(c/m + 1) + 2*q)/q - S[n]}],      S[n], n]


How can I detect a rectangular region of interest in a picture?

Here is a downsampled input image I converted to greyscale. ![enter image description here](http://i.stack.imgur.com/n1063.png) To select the rectangular region of interest we first preform preprocessing:               binarizedImage =       Dilation[Erosion[        Dilation[Binarize[FillingTransform@ColorNegate@resizedGreyImage],          3], 4], 3]      And then find the relevant components and corners               regions =       SelectComponents[       DeleteSmallComponents[binarizedImage,         Method -> "Mean"], {"Rectangularity"}, 1]          corners =       ImageCorners[regions, 4, 0, 10, MaxFeatures -> 4,        "MaxRefinement" -> 0]      Here is the result:               Show[input,       Graphics[{Opacity[0.5], PointSize[.05], Yellow,         Polygon[corners[[ConvexHull[corners]]]], Thickness[0.4], Blue,         Point /@ corners, White, Text[ToString@#, #] & /@ corners, Green,         Point /@ centers, EdgeForm[{Red, Thick}], FaceForm[Opacity[0]],         Rectangle @@ # & /@ boundingBoxes}], ImageSize -> 600]      ![enter image description here](http://i.stack.imgur.com/boaEa.png) I'd like this to be more robust. I'm not sure that "Rectangularity" is the best measure, for instance, in this picture, selecting the component with highest "Rectangularity" doesn't always work:               ![enter code here][3]          DeleteSmallComponents[          ImageForestingComponents[ImageResize[input, 300]]]          % // Colorize     regions = SelectComponents[%%, {"Rectangularity"}, 1] // Colorize      ![enter image description here](http://i.stack.imgur.com/KziGk.png) Also, I'm coding this in opencv, I'm only using mathematica to prototype so if you know the underlying methods used that would be very helpful. Here are some test images: ![enter image description here](http://i.stack.imgur.com/t95sV.jpg) ![enter image description here](http://i.stack.imgur.com/MVP47.jpg) ![enter image description here](http://i.stack.imgur.com/QpiLb.jpg) ![enter image description here](http://i.stack.imgur.com/pHHZ4.jpg) ![enter image description here](http://i.stack.imgur.com/wlFpH.jpg) ![enter image description here](http://i.stack.imgur.com/x7YO9.jpg) ![enter image description here](http://i.stack.imgur.com/zCHSm.jpg)


How can I draw temperature 3D plot?

I want to draw temperature 3D plot based on given data points {{x1,y1,z1},{x2,y2,z2},...}. Here z coordinate is temperature.Am going to Show the temperature z in corresponding {x,y} coordinate. In my example i used only 11 points. I tried like this.               list = {};     width = 50;     length = 30;     place = { {20, 4, 20}, {20, 10, 10}, {20, 15, 10}, {20, 19, 15}, {20,      23, 5}, {20, 27, 60}, {40, 5, 50}, {40, 10, 30}, {40, 19,      20}, {40, 27, 40}, {45, 10, 35}};     Table[AppendTo[list, Table[0, {x, width}]], {y, length}];         Table[                     list = ReplacePart[list, {{y, x} -> place[[n, 3]]}],                     {n, Length[place]}, {y, place[[n, 2]] - 1,place[[n, 2]] + 1}, {x, place[[n, 1]] - 1, place[[n, 1]] + 1}             ];     ListPlot3D[list, Mesh -> 10, AxesLabel -> {x, y, z},RotationAction -> "Clip"]      Here i have given the data is x coordinate, y coordinate and z coordinate(temperature). Sub list {x,y,z} represent each point. In this manner, I want to create 1000 to 1500 points that are laid out in the plot with gap between each point shown clearly. I have specified length and width of plot as 50 and 30 respectively. The problem am facing is i can't layout all(1000 to 1500) points in 50*30 dimension of `Plot`, even if i place all the points in 50*30 dimension plot the gap between each point is not shown clearly. If i increase the dimension of list from 50 to 500 and 30 to 300 means 500*300, i will get the output but its really slow. Because 500*300 leads 150,000 data which makes the plot slow. In this plot i have used `ReplacePart[]` function to replace 0 with given temperature and i have used table to span from previous point of current point to next point of current point means -1 to 1(three points).


Check Google PageRank for a given URL

Does anyone know how to write a _Mathematica_ function that returns the Google PageRank of a given URL? I found a tutorial for achieving this in a bash script here, but I have no idea how to port this over to _Mathematica_.


plot cropped in large amount when setting Text Style to some specific sizes and in some locations

I make a `Graphics` and then add `Text[Style["b",size]` to it. When changing the size, I noticed that the overall graphics gets cropped by large amount when the size is set to some specific value. For example, changing the size from 15 to 16 in this example below. Here is the MWE               Clear[x, y]     a = 4;     b = 2;     Graphics[      {       First@ContourPlot[x^2/a^2 - y^2/b^2 == 1, {x, -6, 6}, {y, -3, 3}],       Text[Style["b", 15], {-a, b/2}, {1, -1}]       },      PlotRange -> All, Axes -> True, AspectRatio -> Automatic      ]      ![Mathematica graphics](http://i.stack.imgur.com/c0dAo.png) Now I changed the size of "b" in the above to 16 and this is the result ![Mathematica graphics](http://i.stack.imgur.com/tDCEi.png) The same problem when the size is 17 and 18. But when the size is 19, it become normal again. This is below is the same code as above, but size set to 19 ![Mathematica graphics](http://i.stack.imgur.com/Uyak4.png) The strange thing, is that if I put the "b" in different locations, I do not see this effect. Here is "b" with size 16, but on the right side               Clear[x, y]     a = 4;     b = 2;     Graphics[      {       First@ContourPlot[x^2/a^2 - y^2/b^2 == 1, {x, -6, 6}, {y, -3, 3}],       Text[Style["b", 16], {a, b/2}, {1, -1}]  (*different location*)       },      PlotRange -> All, Axes -> True, AspectRatio -> Automatic      ]      and this shows ok ![Mathematica graphics](http://i.stack.imgur.com/d5nPx.png) The plot gets cropped only when I move "b" to the other location (and may be some other locations, did not check) and when using some specific size (in this example it was 16,17 and 18) Here is a display showing range of sizes. Notice the size=16,17,18 in this               plot[s_Integer] := Module[{a = 4, b = 2, x, y},       Labeled[Graphics[         {          First@ContourPlot[x^2/a^2 - y^2/b^2 == 1, {x, -6, 6}, {y, -3, 3}],          Text[Style["b", s], {-a, b/2}, {1, -1}]          },         PlotRange -> All, Axes -> True         ]        , Row[{"size ", s}]        ]       ]      Grid[Partition[plot[#] & /@ {13, 14, 15, 16, 17, 18, 19, 20, 21}, 3],         Spacings -> {1, 1}, Frame -> All]      ![Mathematica graphics](http://i.stack.imgur.com/LdwZl.png) This below is the same run as above, just put the "b" on different location. Changed the line `Text[Style["b", s], {-a, b/2}, {1, -1}]` to `Text[Style["b", s], {a, b/2}, {1, -1}]` in the above function. Now the problem do not show up: ![Mathematica graphics](http://i.stack.imgur.com/CsEBh.png) Any explanation for this result? What is special about those sizes? and the location? I am using V 9.01 on windows 7, 64 bit


I evaluated               Integrate[(1 + x/n)^n*Exp[-x], {x, 0, Infinity}] .       thinking the answer should be approximately $\sqrt{\pi n/2}$. _Mathematica_ gave me > ConditionalExpression[E^n n ExpIntegralE[-n, n], Re[n] > 0 || n ∉ Reals] which I am not sure how to interpret. How can I get _Mathematica_ to give me something closer to what I was expecting?


Why is FindRoot initial value far from the specified one?

I am trying to numerically find the root of a function that looks a bit like: `1/x - (SchurDecomposition[A[x]][[2]])[[1]]`, where `A` is some matrix using the syntax               FindRoot[f[x], {x,3}],       where               f[x_?NumericQ] = 1/x - (SchurDecomposition[A[x]][[2]])[[1]]      However when I monitor the values of x evaluated using the option `StepMonitor :> Print[x]`, the first value that appears is far away (e.g. 6) from my specified start point (i.e. 3). Does anybody understand why it is doing this? This is an issue since the value being used (in my example 6) lies far away from the attractor basin of the function and hence `FindRoot` is giving me a wrong result. The initial starting value (in my example 3) lies very close to the root as I can see by plotting the function. In practice my numbers are a bit different and the function to calculate the matrix `A` quite complicated, however these have been extensively verified and I am sure they are working correctly. Thanks for your help.


Liouville theorem demonstration

My goal is to create a demonstration of the Liouville theorem in 2D phase space. I made up an interesting potential energy function $U(x) = (x-4)x^3 + 27$, so that the minimal energy of system is exactly zero. The Hamiltonian equations are (in dimensionless units): $$dp/dt = -4(x-3)x^2,\ dx/dt = p$$ The equation for Contour plot is $(1/2)p^2 + U(x) = E$. Now I want to demonstrate that for given initial set of $(x, p)$ in phase plane, forming an area $D(0)$, which is time-evolving, and this area is conserved, i.e, $D(0) = D(t)$. The problem is that this non-linear system of ODEs is not solvable, so I cannot tell for a given initial $(x,p)$, how it will move in phase space after one second, it has to be solved numerically. The goal is to draw several images -- first with chosen volume $D(0)$ formed by a large number of initial values of (x,p). Next image would be a system evolved in time, say in one second. It'd be nice to see the volume $D(0)$ being distorted due to the Hamiltonian equations and the non-linear force. One approach is 1) to parametrically describe the volume $D(0)$, 2) numerically solve the Hamilton equations for all those points in $D(0)$ to get their position for latter time 3) draw a new image with volume $D(t)$. It should be sufficient to solve the Hamiltonian equations only on the boundary of $D(0)$, which should preserve continuity in time. Another approach is to choose the initial volume $D(0)$, randomly choose, say, a hundred points in this volume, then solve Hamilton equations for all these points until time $t$, and draw these hundred points at their new position. The problem is, I don't have the slightest idea how to do this practically in _Mathematica_ 8\. I'd appreciate any help.


Modify BinList to give elements indices in list instead of giving the list elements belonging to each bin

How could I use BinList to give elements indices in list instead of giving the list elements belonging to each bin ? Thanks.


How to use Mathematica to obtain the correct simplified results?

I have a question on simplification: Given that                   Kxx1=-((π^2 (x - x0) Cosh[π (x - x0)])/(           2 (-Cos[π (y - y0)] + Cosh[π (x - x0)]))) + (π^2 (x -              x0) Cosh[π (x - x0)])/(          2 (-Cos[π (-1 + y + y0)] + Cosh[π (x - x0)])) + (π^2 (x -              x0) Sinh[π (x - x0)]^2)/(          2 (-Cos[π (y - y0)] + Cosh[π (x - x0)])^2) - (π^2 (x -              x0) Sinh[π (x - x0)]^2)/(          2 (-Cos[π (-1 + y + y0)] + Cosh[π (x - x0)])^2)              Kxy1=-((π^2 (x - x0) Cos[π (y - y0)])/(           2 (-Cos[π (y - y0)] + Cosh[π (x - x0)]))) - (π^2 (x -              x0) Cos[π (-1 + y + y0)])/(          2 (-Cos[π (-1 + y + y0)] + Cosh[π (x - x0)])) + (π^2 (x -              x0) Sin[π (y - y0)]^2)/(          2 (-Cos[π (y - y0)] + Cosh[π (x - x0)])^2) + (π^2 (x -              x0) Sin[π (-1 + y + y0)]^2)/(          2 (-Cos[π (-1 + y + y0)] + Cosh[π (x - x0)])^2)      But                   M1 = Collect[Kxx1 (Dxx - Dyy)/2 + Kxx1 (Dxx + Dyy)/2 + Kxy1 (Dyy - Dxx)/2 +             Kxy1 (Dyy + Dxx)/2, FullSimplify]      gives me the result               1/2 (-Dxx +          Dyy) (-((π^2 (x - x0) Cos[π (y - y0)])/(          2 (-Cos[π (y - y0)] + Cosh[π (x - x0)]))) - (π^2 (x -             x0) Cos[π (-1 + y + y0)])/(         2 (-Cos[π (-1 + y + y0)] +             Cosh[π (x - x0)])) + (π^2 (x -             x0) Sin[π (y - y0)]^2)/(         2 (-Cos[π (y - y0)] + Cosh[π (x - x0)])^2) + (π^2 (x -             x0) Sin[π (-1 + y + y0)]^2)/(         2 (-Cos[π (-1 + y + y0)] + Cosh[π (x - x0)])^2)) +       1/2 (Dxx +          Dyy) (-((π^2 (x - x0) Cos[π (y - y0)])/(          2 (-Cos[π (y - y0)] + Cosh[π (x - x0)]))) - (π^2 (x -             x0) Cos[π (-1 + y + y0)])/(         2 (-Cos[π (-1 + y + y0)] +             Cosh[π (x - x0)])) + (π^2 (x -             x0) Sin[π (y - y0)]^2)/(         2 (-Cos[π (y - y0)] + Cosh[π (x - x0)])^2) + (π^2 (x -             x0) Sin[π (-1 + y + y0)]^2)/(         2 (-Cos[π (-1 + y + y0)] + Cosh[π (x - x0)])^2)) +       1/2 (Dxx -          Dyy) (-((π^2 (x - x0) Cosh[π (x - x0)])/(          2 (-Cos[π (y - y0)] + Cosh[π (x - x0)]))) + (π^2 (x -             x0) Cosh[π (x - x0)])/(         2 (-Cos[π (-1 + y + y0)] +             Cosh[π (x - x0)])) + (π^2 (x -             x0) Sinh[π (x - x0)]^2)/(         2 (-Cos[π (y - y0)] + Cosh[π (x - x0)])^2) - (π^2 (x -             x0) Sinh[π (x - x0)]^2)/(         2 (-Cos[π (-1 + y + y0)] + Cosh[π (x - x0)])^2)) +       1/2 (Dxx +          Dyy) (-((π^2 (x - x0) Cosh[π (x - x0)])/(          2 (-Cos[π (y - y0)] + Cosh[π (x - x0)]))) + (π^2 (x -             x0) Cosh[π (x - x0)])/(         2 (-Cos[π (-1 + y + y0)] +             Cosh[π (x - x0)])) + (π^2 (x -             x0) Sinh[π (x - x0)]^2)/(         2 (-Cos[π (y - y0)] + Cosh[π (x - x0)])^2) - (π^2 (x -             x0) Sinh[π (x - x0)]^2)/(         2 (-Cos[π (-1 + y + y0)] + Cosh[π (x - x0)])^2))      But actually `Dxx - Dyy == -(Dyy - Dxx)` and `Dxx + Dyy` (in the second term of the result) `== Dxx + Dyy` (in the fourth term). How to further simplify the result? Is there any method to directly obtain the correct simplified result? I tried `Assumptions -> {Dxx - Dyy > 0 && Dxx + Dyy > 0}`, but it didn't work.


Memory consumed by NMaximize with NDSolve

I'm using `NMaximize` on a function that calls `NDSolve`, and running out of memory. I created the following minimal example that (I think) recreates the problem I'm having, but on a smaller scale.               f[t_?NumericQ] := Block[{sol, s, x},       sol = First[NDSolve[{x''[s] + Sin[x[s]] == 0, x[0] == 0, x'[0] == 1}, x, {s, 0, t}]];       x[t] /. sol]          memInit = MaxMemoryUsed[];     ListPlot[Reap[NMaximize[       {f[t], t < Pi, t > 0}, t,       Method -> "NelderMead",       EvaluationMonitor :> Sow[MaxMemoryUsed[] - memInit]]][[2]]]      On my machine, with a freshly launched MathKernel, the memory usage increases badly after a run of not increasing at all. Here's the plot: ![Memory usage after each evaluation of f](http://i.stack.imgur.com/fIkpy.png) If I run `NMaximize` on `Sin[t]` instead of `f[t]`, the memory usage does not increase. Can anyone explain the difference in behavior or suggest how to reduce memory usage?


Projection of ContourPlot3D

Suppose I have the following `ContourPlot3D`:               ContourPlot3D[     p1 p2^6 (C p1 - (-1 + C) p2)^3 ((-1 + C) p1 - C p2)^2      ==      (-1 + p1) (-1 + p2)^6 (-1 + C p1 - (-1 + C) p2)^3 (1 + (-1 + C) p1 - C p2)^2,     {p1, 0, 0.3}, {p2, 0.5, 1}, {C, 0, 1},       Lighting -> ({"Directional", White, #} & /@ Tuples[{-1, 1}, 3]),       Mesh -> None, ContourStyle -> {Directive[Red, Opacity[0.5]]},       AxesLabel -> {"\!\(\*SubscriptBox[\(p\), \(1\)]\)",       "\!\(\*SubscriptBox[\(p\), \(2\)]\)", "C"}]      which looks like: ![enter image description here](http://i.stack.imgur.com/zOokL.png) My question is: how to project this transparent red surface onto the $p_1,p_2$ plane and then convert the projection to a standard 2d plot (like what we will get by using `Plot[]`) **Additional requirement** : It would be nice if the resulting 2D plot is clean, because I may need to plot other curves on top of the 2D plot.


How to apply an rule to factors matching a certain form

Suppose we have many expressions involving irrational ArcTan expressions (such as `ArcTan[Sqrt[3],5]`) along with other irrational factors (such as `1/Sqrt[2]`). I want to simplify all of these ArcTans. For example, I might want to apply `N@` to them to get their decimal approximation, or, I might want to apply `Rationalize` as in               N@ArcTan[Sqrt[3], 5]     (* out: 1.23732 *)             Rationalize[ArcTan[Sqrt[3], 5]/Pi, .0001] Pi       (* out: 13 Pi/33 *)        However, I would like to be able to implement either of these options throughout large expressions involving many ArcTan functions and not act on any other forms. Simple example would be:               m = 1/Sqrt[3]+ Sqrt[2] ArcTan[Sqrt[3], 5]        How can I apply a rule or something to m that will allow me to implement one of these types of solutions to the ArcTan but not act on the other irrational factors?


Is there a faster way to do Normal[SparseArray[{{1,1,1}→1.2, {1,1,2}→20.2, ..., {m,n,p}→0.3}]]?

I have a list of the form `{{1,1,1}→1.2, {1,1,2}→20.2, ..., {m,n,p}→0.3}` and I want to create an $m \times n \times p$ array, $A$, where the value of $A[[i,j,k]]$ is as specified by the list (e.g., $A[[1,1,2]] == 20.2$ in the example above). This array represents a series of $p$ matrices, each $m \times n$, and each of which represents two-dimensional imaging data. The array $A$ can be formed by `Normal[SparseArray[{{1,1,1}→1.2, {1,1,2}→20.2, ..., {m,n,p}→0.3}]]`. However, I'm looking for the fastest way to create the array $A$. Specifically, I'm looking for a method that minimizes runtime (see below). Is the above approach the best, or is there a faster one? Typical values for $m, n, p$ are 320, 320, 20, respectively. The values to be stored are machine-precision numbers. The array is not particularly sparse (perhaps as much as 20% of the elements will be zero). I need to create many such $A$ arrays within an optimization (each instance of $A$ will differ from the previous one as the optimization proceeds). Once the array has been created, further processing will be applied (the first thing that will be done is to apply a two-dimensional discrete Fourier transform to each of the $p$ matrices. I assume for this reason that it makes sense for the array $A$ to be dense rather than sparse (or, at least) for each of the $p$ matrices to be dense.


Connect to SQLite database

I am trying to connect to a SQLite database and since there is no officially supported driver; I decided to use the sqlite-jdbc driver and port the respective code into Mathematica. However, the DriverManager refuses to connect to the database, the error message is:               Java::excptn: A Java exception occurred: java.sql.SQLException:      No suitable driver found for jdbc:sqlite:C:/sqlite/test.db     at java.sql.DriverManager.getConnection(DriverManager.java:602)     at java.sql.DriverManager.getConnection(DriverManager.java:207).      The driver & the code that I am trying to port is at: https://bitbucket.org/xerial/sqlite-jdbc and the respective lines that I am having issue is:               ....     Class.forName("org.sqlite.JDBC");          Connection connection = null;     try     {       // create a database connection       connection = DriverManager.getConnection("jdbc:sqlite:sample.db");     ....      I noticed the code uses a Class.forName() and I used the JLinkClassLoader to load the same class. Here are my efforts so far:               <<JLink`     (*location of the driver jar*)     AddToClassPath["C:\\drivers\\sqlite"];          LoadJavaClass /@       {"java.sql.Connection", "java.sql.DriverManager",  "java.sql.ResultSet",        "java.sql.Statement", "java.sql.SQLException","org.sqlite.JDBC"}          LoadJavaClass["com.wolfram.jlink.JLinkClassLoader"];     cls=Class`forName["org.sqlite.JDBC",True,JLinkClassLoader`getInstance[]];          (*Errors out with the message above*)     DriverManager`getConnection["jdbc:sqlite:C:/sqlite/test.db"]      I used `DriverManager.getDrivers()` and it shows me that only the sun.jdbc.odbc driver has been loaded; so the error message is justified. I am at this point not sure how to proceed /debug the issue and will greatly appreciate any assistance. If you have any suggestions, I will be very grateful.


Space around indices in Mathematica 10

When i write something like f(x_0) in traditional form mm puts white space around the index, so that especially the distance to the end parenthesis looks weird. In mm 9 I could reduce the issue by putting a 'negative space' (esc - space space) after the index. But in mm 10 this suddenly looks even weirder with the end parenthesis going through the index. It can be fixed by using af smaller negative space and add a space afterwards as seen on the image below. My students use both versions, so I wonder if there is a way to make it look the same regardless of which version of mm is used to view a notebook? This picture shows the problem: ![enter image description here](http://i.stack.imgur.com/FX6yc.png)


Mathematica2tikz an equivalent function

Matlab2tikz is script which generates native Latex/Tikz figures from MATLAB. I am looking for an equivalent method/function in Mathematica to generate similar results. Obviously the final script may need some manual tinkering as Mathematica has a numerous different plotting styles. I am looking for the equivalent of `ListLinePlot[]` A similar question is there. **Further information:** Tikz is a native Latex graphics package. For many users of Latex it provides very high quality diagrams. Users therefore need to export data from Mathematica to plot within Tikz. An example is shown in the Figure. A minimal working example of Tikz usage is provided for a simple case, although the ultimate graphics capabilities of Tikz is vast. Other examples are here ![Figure A](http://i.stack.imgur.com/V4LWK.png)               \documentclass[12pt]{article}     \usepackage{tikz}     \usepackage{pgfplots}          \begin{document}          \begin{figure}     \centering     % This file was created by matlab2tikz v0.1.4.     % Copyright (c) 2008--2011, Nico Schlömer <nico.schloemer@gmail.com>     % All rights reserved.     %      % The latest updates can be retrieved from     %   http://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz     % where you can also make suggestions and rate matlab2tikz.     %      \begin{tikzpicture}          \begin{axis}[%     scale only axis,     width=3.2877in,     height=2.37695in,     xmin=0, xmax=100,     ymin=0, ymax=100,     xlabel={x label},     ylabel={y label},     xmajorgrids,     ymajorgrids,     legend entries={$y=x$},     legend style={at={(0.97,0.03)},anchor=south east,fill=white,draw=black,nodes=right}]     \addplot [     color=blue,     solid     ]     coordinates{      (1,1)(2,2)(3,3)(4,4)(5,5)(6,6)(7,7)(8,8)(9,9)(10,10)(11,11)(12,12)(13,13)(14,14)(15,15)(16,16)(17,17)(18,18)(19,19)(20,20)(21,21)(22,22)(23,23)(24,24)(25,25)(26,26)(27,27)(28,28)(29,29)(30,30)(31,31)(32,32)(33,33)(34,34)(35,35)(36,36)(37,37)(38,38)(39,39)(40,40)(41,41)(42,42)(43,43)(44,44)(45,45)(46,46)(47,47)(48,48)(49,49)(50,50)(51,51)(52,52)(53,53)(54,54)(55,55)(56,56)(57,57)(58,58)(59,59)(60,60)(61,61)(62,62)(63,63)(64,64)(65,65)(66,66)(67,67)(68,68)(69,69)(70,70)(71,71)(72,72)(73,73)(74,74)(75,75)(76,76)(77,77)(78,78)(79,79)(80,80)(81,81)(82,82)(83,83)(84,84)(85,85)(86,86)(87,87)(88,88)(89,89)(90,90)(91,91)(92,92)(93,93)(94,94)(95,95)(96,96)(97,97)(98,98)(99,99)(100,100)      };          \end{axis}     \end{tikzpicture}          \end{figure}          \end{document}


system of ODE through NDSolve

I am quite puzzled to solve the coupled ode's numerically. Please tell me why it runs for a long time and not giving any output in mathematica. I am using NDsolve. please have a look               NDSolve[{ x'[t] == x[t]/y[t] + x[t]/z[t] - x[t]/z[t]^2,                y'[t] == 1 + y[t]/z[t] - (2 y[t])/z[t]^2,                z'[t] == -z[t] - z[t]/y[t] - (2 z[t])/y[t]^2,               x[0] == 2,               y[0] == 5,                z[0] == 7},             {x, y, z},             {t, -10, 10},             MaxSteps -> Infinity]


Project Euler (memory and speed issues)

Let n be a positive integer. An integer triple (a, b, c) is called a factorisation triple of n if: 1 ≤ a ≤ b ≤ c   a·b·c = n. Define f(n) to be a + b + c for the factorisation triple (a, b, c) of n which minimises c / a. One can show that this triple is unique. For example, f(165) = 19, f(100100) = 142 and f(20!) = 4034872. Find f(43!). Above is the question. You can see my solution below:                f[n_] := Module[{lis1, lis2, lis3, pos, cand, filt},            lis1 = Subsets[Divisors[n], {3}]; lis2 = Times @@@ lis1;            pos = Position[lis2, n]; cand = Extract[lis1, pos];            filt = ( #[[3]] / #[[1]] ) & /@ cand;            Plus @@ (Extract[cand, Position[filt, Min[filt]]] // Flatten)]      Let's test it:               f[165]      > 19               f[100100]      > 142 The code is relatively fast even for n as large as 10!               f[10!]//Timing      > {2.698817, 462} The problem arises if I try to compute `f[20!]`, I run out of memory. Any tips to circumvent this memory issue will be greatly appreciated. I know my code is straight-up brute force and certainly not the best way to go about this, but it gives the right answer when it works (doesn't run out of memory). Also, the idea is to get the answer in about a minute or less. Thanks. Edit: Ok, so I've made progress with the memory issue using Mr. Wizard's advise in the comment. Of course it's still going to be slow unless one can find a way to generate only `Subsets` for which the product of the elements equals `n`. It would be great if `Subsets` had a 4th `Option` that accepts predicates. For now here's the updated code:               f[n_, incr_, end_] :=       Module[{lis1, pos, cand = {}, filt, div = Divisors[n]},         Do[lis1 =           Select[Subsets[div, {3}, {i, i + incr}] // Quiet, Times @@ # == n &];          cand = {cand, lis1}, {i, 1, end, incr}];         cand = Flatten[cand] ~ Partition ~ 3;         filt = ( #[[3]] / #[[1]] ) & /@ cand;         Plus @@ (Extract[cand, Position[filt, Min[filt]]] // Flatten)] ~       Monitor ~ i      Usage:               f[11!,500000,10^15]          (* 1026 *)      Now the problem is speeding this code up.


NDSolve does not respond

For some sets of constants, NDSolve gives me true solutions, but when I try for example, `T = 1/(2*2200)`, _Mathematica_ does not respond. What can I do? The code below has no problem, but I need to change the constants defined at the beginning of the code and see the results. Any suggestions?               Io = 3.38*10^-12     NS = 8     Cp = 90*10^-15     Cs = 30*10^-15     T = 1/(2*2100)     ss = 51.23*10^-3     dV = 0.45     Cl = 1*10^-12     V = 0.3          \[Beta] = (2*Io)/((Cs + Cp)*ss)          a = \[Beta]*T     b = \[Beta]*T/2     c = Cl/((Cs + Cp)/(2 T))     d = Io/((Cs + Cp) /(2 T))          s = NDSolve[       {Vo[t] == V +            Log[b/(E^((c*Vo'[t] + d)/ss) - 1)] ss +            Log[(b* E^((dV + c*Vo'[t] + d)/ss))/(E^((c*Vo'[t] + d)/ss) - 1)] ss +            Log[(a* E^((dV + c*Vo'[t] + d)/ss))/(E^((2*(c*Vo'[t] + d))/ss) - 1)] ss (NS-1),        Vo[0] == 0.3        },        Vo,       {t, -0.0001, 1}]            Plot[Evaluate[Vo[t] /. s], {t, -0.0001, 1}, PlotRange -> All]


How can I include a popup menu in my wizard's content?

I'm trying to create a wizard that enables the user to choose between different shaft components. At the same time, I need a flag to be 1 if he chooses a bearing and 0 otherwise. I extended the example code from one of the `GUIKit`` help pages which you can find here:               ref = GUIRun[       Widget["WizardFrame", {         "wizard" -> Widget["Wizard", {            "title" -> "Shaft sections",            "pages" -> {              Widget["WizardPage", {                "navigationNames" -> {"Next"},                "title" -> "Select the main feature of this section: ",                "content" -> Widget["Panel", {Widget["WizardHTMLPanel"]                         PopupMenu[                     Dynamic[flag[1]], {0 -> coupling, 0 -> shoulder,                       1 -> bearing, 0 -> gear, 0 -> pulley}]                   }]                }]              }            }]         }]]     GUIScreenShot[ref]      The program says that the GUI definition contains invalid content. Help??


Remote Mathkernel: SSH encountered a networking error while launching kernel Error code = 1

I have a problem concerning the connection to a remote kernel via ssh on a vpn. I found a working configuration in this question: Connection to remote kernel can not be established - No specific error shown However, I use Windows 7 as my client and therefore cannot run the same command as the kind sir there provided in his answer: `ssh -R 31415:10.8.0.6:31415 -R 31416:10.8.0.6:31416 user@10.8.0.1 "dbus- launch --exit-with-session /usr/local/bin/math -mathlink -LinkMode Connect ..."` because Windows does not have openssh built in but instead adapted that command to use the installed openSSH version of cygwin: `C:\Users\<username>\bin\bash --login -i -c "ssh -v -i /cygdrive/c/Users/<username>/Path/to/private/key user@10.8.0.1 /usr/local/bin/math -mathlink -LinkMode Connect ..."` This command DOES work if I run it directly in the windows console, the connection with the private key gets established, but when I try this same command in the remote kernel configuration the error in the title occurs without more specific troubleshooting help. Also the other question dealing with that error I could find had passphrase/private key problems and couldn't even connect via the console. Upon inspecting the differences of the openssh version I noticed my client in cygwin uses 6.1p1 while the server uses 5.5p1. I tried installing a current openssh version on the Debian 6.0 server but the last officially supported and maintained one for that OS version is 5.5p1 and it doesn't seem such a good idea to me to upgrade to a not officially supported version. When trying to install an older version in cygwin, I cannot even select an older openssh version when running the cygwin setup again and selecting a cygwin packages mirror. So I searched for ~10 alternative mirrors that provide older openssh packages, but they all seem to lack a "setup.ini" file so no connection could be established. I ask for help here because this seems to be a Mathematica specific problem, not a ssh related one..other clients with Mac OS X 10.8 can connect to the server using the same private key fine.. Does anyone have a similar setup and could give me a hint what might cause the error? Is there something I did not see in the remote kernel configuration? I use Mathematica 8.0.4, Windows 7 64bit client with openssh-6.1p1, Debian 6.0 server with openssh-5.5p1, cygwin 1.7.17. Thank you! Update: In the meantime I found someone with nearly the same problem, however 3 years ago and with no answer (i hope you don't mind links to other platforms: https://groups.google.com/forum/#!topic/comp.soft- sys.math.mathematica/K-Z3xbQNzbY


project from a n-dimensional space to 2-dim

let's say that I have a sphere in $N$-dimensions $$x_1^2+x_2^2+...+x_N^2=R$$ If I want to know the projection on the $x_1-x_2$ plane in this case I can figure out myself that is a circle, but how can I get Mathematica to do the projection and plot it for me? Of course I need to apply this to a more complicated case where the N-dimensional surface is not as simple and can only be defined implicitly by $f(x_1,...,x_N)=0$. I hope I have not forgot too much math from school that I am asking mathematica to do this for me.


load static library (.lib) using NETLink

is it possible to load static library (.lib) compiled in c++ using NETLink or similar in Mathematica?


Gauss Markov Process

I am trying to model a 1st order Gauss Markov Process (gyroscope drift). I know the Allan Variance characteristics of the process (bias instability, random walk characteristics). I know the model should look like:               RandomFunction[SomeProcess[some_process_args], {some_time_characteristics}]       but not quite sure where to start. I looked up `ARProcess` but it only seems to work with a unit time increment


How to anchor a Pane's scroll position to the bottom?

Suppose I have a `Pane` containing some dynamic text, for example that is being updated by a logging function.               Pane[Dynamic[logText],       Scrollbars -> {False, True},       ImageSize -> {Full, 200},       ScrollPosition -> {0, 10000000}]      I want this pane to remain scrolled to the bottom so that I can always see the last line of text. I tried setting `ScrollPosition -> {0, Infinity}` (or to `{0, Full}`, or to `{0, All}`), which would be a possible interface to achieve this, but neither of these work.


Efficiency of ParallelDo when a global variable./matrix is being updated

(Disclaimer: I realize that the addition of matrices a and b below can be done very fast just by typing a+b. The code below is just meant to illustrate behavior similar to what I observe in much more complicated code, too lengthy to reproduce here). Suppose I want to add matrices a and b               n = 50;      I can do it via a double loop in a single kernel, this takes 0.02 seconds:               a = RandomReal[{}, {n, n}];     b = RandomReal[{}, {n, n}];     c1 = RandomReal[{}, {n, n}];     Do[       Do[        c1[[i, j]] = b[[i, j]] + a[[i, j]],        {j, 1, n}],      {i, 1, n}] // AbsoluteTiming          Out[363]= {0.0240014, Null}      I can try to parallelize the outer loop -- I use 4 kernels -- this takes 25 seconds -- ouch -- presumably due to the fact that the master kernel is in constant communication with the various kernels, updating c2.               SetSharedVariable[c2];     c2 = RandomReal[{}, {n, n}];     ParallelDo[       Do[        c2[[i, j]] = b[[i, j]] + a[[i, j]],        {j, 1, n}],       {i, 1, n}] // AbsoluteTiming          Out[366]= {25.8984813, Null}      I can try to reduce communication to an absolute minimum, by introducing a temporary array on each kernel. Surprisingly, this still requires 0.3 seconds.               SetSharedVariable[c3];     UnsetShared[vtemp];     c3 = RandomReal[{}, {n, n}];     ParallelDo[       vtemp = Table[0., {n}];       Do[        vtemp[[j]] = b[[i, j]] + a[[i, j]],        {j, 1, n}];       c3[[i]] = vtemp,       {i, 1, n}, Method -> "CoarsestGrained"] // AbsoluteTiming          Out[370]= {0.2940168, Null}      Again, my own code is far more complicated. But it shares with this example the need to distribute the task of updating a piece of a matrix. Updating the global variable/matrix invariably takes more time than executing the code on a single processor, even when the calculations on each processor are far more complex that in the above. Are there techniques to mitigate this problem?


Where can I permanently modify $Path?

I've quite forgotten: what file does one modify in order to add directories to `$Path` globally? Specifically, I want to include `$UserBaseDirectory/ExtraPackges`. Or does one do it by means of modifying some setting in the OptionInspector (for Global Preferences) and, if so, which setting? I didn't see a relevant one under `Global Options>File Locations`.


RootSearch for complex or multiple equations

First the background. I'm trying to solve for the roots of a rather messy complex equation. This is not the exact equation, but it's a decent (simpler) stand in:               Tan[x - I a] + I == I (x - I a)^(-1/2)      I can use `FindRoot` to solve for a particular root, i.e.               FindRoot[Tan[z] + I == (I) (z)^(-1/2), {z, Pi - .3 I}]      which gives `{z -> 3.08945 - 0.465902 I}`. The thing is, the real part of these equations (as well as the imaginary parts) alone have periodic solutions. For example, look graphically at this solution: ![Mathematica graphics](http://i.stack.imgur.com/oJAna.png) However, realizing that the real roots tend to be spaced roughly at integer factors of $\pi$ (i.e. consider `Tan[x]==x^(-1/2)`), using `FindRoot[Tan[z] + I == (I) (z)^(-1/2), {z, 2 Pi - .3 I}]` indeed gives the next root. However, in the actual equation some roots get spaced un-evenly, and it's possible to miss particular roots when using this guess method. I recognize that another approach to doing this explicitly solves the real and imaginary parts of the equation as simultaneous roots to two real equations:                FindRoot[{Re[Tan[x + I y] + I] == Re[(I) (x + I y)^(-1/2)],         Im[Tan[x + I y] + I] == Im[(I) (x + I y)^(-1/2)]},       {{x, Pi}, {y, -.3}}]      and gives the same result, `{x -> 3.08945, y -> -0.465902}`. Given this info, is there a way to use a `RootSearch`-type function to find _all_ complex (simultaneous) roots to this (these) equation(s) over a particular range of real values **without guessing** each real part of root to be an integer value of $\pi$? **Edit** As an added complication, I actually have two complex equations that I need to solve simultaneously, so if the solution could be generalizeable to allow for this sort of thing, that would be an added bonus. * * * **Also Edit** I've tried a few of the suggestions in the comments and answers below. Some work for the sample case I gave above, but for my actual problem they don't really work. So, I figured may as well give the whole crazy thing I'm trying to solve:                   s1 = {(-2 ky Pi wavelength Cot[           1/2 (b ky + n Pi)] + (km - I nm) (4 Pi^2 +             ky^2 wavelength^2 -             2 ky (km - I nm) Pi wavelength Tan[              1/2 (b ky + n Pi)]))/((km - I nm) wavelength) == 0,                (-2 kx Pi wavelength Cot[           1/2 (a kx + m Pi)] + (km - I nm) (4 Pi^2 +             kx^2 wavelength^2 -             2 kx (km - I nm) Pi wavelength Tan[1/2 (a kx + m Pi)]))/((km - I nm) wavelength) == 0}      This equation needs to be solved for different values for the parameters in this equation `a`, `b`, `wavelength`, etc. Here's a sample:               wavelength = 26 10^-3;     nm = -100;     km = 5;     a = 13 10^-4;     b = 64 10^-5;     m = 1;     n = 0;      Now, if I try               Solve[{Sequence@@s1, Abs[kx] <= 10, Re[kx] >= 0, Abs[ky] <= 10, Re[ky] >= 0}]      I get an error "This system cannot be solved with the methods available to Solve.". However, trying `Sequence@@N@s1` it suggests trying exact input. Similarly, `Reduce` does not work with `N` values, and with exact values takes impossibly long to solve. So, I'm still looking for a _fast_ numerical approach. Perhaps something like J.M. suggested in a comment could be generalized for more than two equations?


Is there any automatic differentiation package?

I'm wondering if an automatic differentiation package exists for _Mathematica_. This is what I mean by automatic differentiation.


Problem with importing a JCAMP-DX IR spectrum file

I wrote a little function to import JCAMP-DX electron ionization or mass spectral files from the NIST webbook web site (e.g. mass spectrum of hydrogen chloride at http://webbook.nist.gov/cgi/cbook.cgi?ID=C7647010&Units=SI&Mask=200#Mass-Spec, IR spectrum at http://webbook.nist.gov/cgi/cbook.cgi?ID=C7647010&Units=SI&Type=IR- SPEC&Index=0#IR-SPEC). I already managed to fix a small issue to allow importing mass spectra, but the IR spectrum import does not work yet. My function is               importspectrum[casnr_, type_] := Module[{},        Quiet[Check[          ImportString[            StringReplace[             Import["http://webbook.nist.gov/cgi/cbook.cgi?JCAMP=C" <>                StringReplace[casnr, "-" -> ""] <> "&Index=0&Type=" <> type,               "String"], {x : NumberString ~~ " " ~~ y : NumberString :>                x <> "\n" <> y}], "JCAMPDX"][[1]], "NA"]]];      importmassspectrum[casnr_] := importspectrum[casnr, "Mass"];     importIRspectrum[casnr_] := importspectrum[casnr, "IR"];      This works OK for mass spectra:               spec=importspectrum["7647-01-0", "Mass"]     {{35, 1702}, {36, 9999}, {37, 540}, {38, 3243}}          ListPlot[spec, Filling -> Axis, FillingStyle -> Blue,       PlotRange -> All, PlotStyle -> PointSize[0]]      But it doesn't work for the IR spectra:               spec=importspectrum["7647-01-0", "IR"]      There, the problem is that Mathematica expects X, Y values whereas in the NIST IR spectrum files each line is an X value plus several measured Y values (which should be averages):               ##DATA PROCESSING=DIGITIZED BY NIST FROM HARD COPY (FROM TWO SEGMENTS)     ##XUNITS=1/CM     ##YUNITS=TRANSMITTANCE     ##XFACTOR=1.000000     ##YFACTOR=1     ##DELTAX=0.935163     ##FIRSTX=456.047     ##LASTX=3765.59     ##FIRSTY=0.959     ##MAXX=3765.59     ##MINX=456.047     ##MAXY=1.001     ##MINY=0.213     ##NPOINTS=3540     ##XYDATA=(X++(Y..Y))     456.047000 0.9590 0.9590 0.9590 0.9580 0.9580     460.722814 0.9560 0.9560 0.9560 0.9560 0.9560     465.398628 0.9550 0.9550 0.9550 0.9530 0.9530     470.074442 0.9530 0.9530 0.9520 0.9520 0.9520     474.750255 0.9520 0.9500 0.9500 0.9500 0.9490     ...      So this should first be transformed to               456.047000 average of (0.9590 0.9590 0.9590 0.9580 0.9580)      Does anyone know what would be the most elegant way to do this in Mathematica, without using For to loops etc?


Plotting a section of an hemisphere

I'm writing a little package in Mathematica for geology where a particular stone may be approximated as an hemisphere. Anyway this is a rough estimation because a real hemisphere has its height as loong as its radius. Instead, a reservoir stone (for an hydrocarbon) has often a form of a section of an hemisphere, its height is lower than the radius. For example, I can have an hemisphere with radius long 5 km and height of only 3 km and I can plot it like that:               semisfera[x_, y_, raggio_] := Sqrt[raggio^2 - (x - raggio)^2 - (y - raggio)^2];      plotsemisfera = Plot3D[semisfera[x, y, raggioSfera], {x, 0, 2  raggioSfera}, {y, 0, 2  raggioSfera}, PlotRange -> {0, 3}, AxesLabel -> {"lunghezza km" , "larghezza km","profondità km"}, PlotLabel ->  Style[Framed["Referenced Theorical Hemisphere"], 22, Black]]      and I get the following graphic: ![enter image description here](http://i.stack.imgur.com/O5pSO.jpg) you'll agree with me that is a section of ah hemisphere without the top part, won't you? Sometimes it may happen that the height is << radius. In my case, my geology student worked on a stone with radius of 5km and an height of only 0.2 km. If I try to plot this as I've done before, I get a very awful graphic, here: ![enter image description here](http://i.stack.imgur.com/Zo3eb.jpg) So, I'd just like to know if there is a way to plot a more precise graphic, without all that irregular part at the base of the hemisphere. The centre of the "hemisphere" should be in = <0,0> Maybe it could be something like that: ![enter image description here](http://uploadpie.com/eAVvq) but I really don't understand why for low values of the height the base of the hemisphere is so jagged! How can I plot that? Thank you


Is there a bug in Pick?

I wanted to use the `Pick` function with a condition. But there seems to be an issue here. Take a look at this:               selection = {0,1.2,3,0.,5};     Pick[{1,2,3,4,5},selection,elem_ /; elem =!= 0]      In _Mathematica_ 8 it will give `{1,2,3,4,5}` instead of `{2,3,4,5}`. Please note, that the `Pick` function works nicely with               Pick[{1,2,3,4,5},selection,elem_ /; elem === 0]      Giving `{1}` as a result. Is this a bug or am I missing something?


How to Enable Syntax Coloring of Pattern Match Variable Only (i.e. Without Coloring any Associated Pattern)?

Syntax coloring for the following function definition               foo[x_List] := ...      will color green (and italicize by default) the argument name `x` as well as the pattern name `_List`: > ![enter image description here](http://i.stack.imgur.com/AYbC9.png) On the other hand, syntax coloring for               foo[x:_List]      colors only the identifier `x` green and not the `_List` qualifier: > ![enter image description here](http://i.stack.imgur.com/n48IJ.png) Is there a way to configure the front end to color just the identifier name as in the second example? Looking through the Option Inspector, I cannot find any relevant switches, so I suspect not. I do wonder however if this behavior is a bug or a feature whose purpose I don't fully understand. **EDIT:** The remaining issue in this question is the following: The syntax coloring rule which specifies that function argument names should be colored green in the body of the function in which these names are bound also colors green any head to the right of the underscore that is present for pattern matching purposes. _In what sense is the underscore itself and any head that is attached to it part of the function argument name proper?_ The two examples provided above exhibit a pair of semantically equivalent function definitions where the coloring (which is syntax) is applied differently to semantically equivalent parts of the respective function definitions. **EDIT:** Here is another example where the syntax coloring rule for pattern names is being applied in a seemingly inconsistent fashion:               f[a + b] + f[a + c] /. f[a + x_] + f[a + y_] -> p[x, y]      Shouldn't the `x` and the `y` arguments in `p[x,y]` be colored green much like in a function definition (whose syntax also defines a transformation rule)? Another puzzling example:               MatchQ[{1, 1}, {x_?IntegerQ, x_ /; x > 0}]      In my front-end (v8) the first `x` is black. On the other hand, the second and third instances are colored green. These examples raise the issue of whether or not color syntax rules for pattern names as they are currently implemented cause more confusion than they are worth for helping the user visualize lexical scopes that are in force at a particular position in the code. Anyone else agree?


Convex hull of a 3D object?

I am trying to find a convex hull command for a `Graphics3D` object. Does it exist in _Mathematica_?               egg = Graphics3D[Cuboid /@ Position[DiskMatrix[{12, 10, 8}], 1]]      ![Mathematica graphics](http://i.stack.imgur.com/7AVBz.png) The `ConvexHull` command of the `"ComputationalGeometry`"` package does not work on 3D objects:               Needs["ComputationalGeometry`"]     ConvexHull[egg]      ![Mathematica graphics](http://i.stack.imgur.com/xSWSV.png)


Efficient drawing of convex polyhedron given a set of points

I have a set of points in the 3D space and I want to draw the bounding convex polyhedron of those points. A very naïve solution would be to draw a triangle between every three points:               Graphics3D[         {EdgeForm[None], Polygon[Part[pts, #] & /@ Subsets[Range[Length@pts], {3}]]},          Axes -> True]      However, this method is very inefficient. It takes a few seconds to be drawn on my laptop and whenever I want to rotate it using the mouse, it doesn't move smoothly. I know what the issue is: I am drawing too many triangles, many of them are not even visible (since they are placed inside the polyhedron). But how can I fix it? Here is an example and the set of the points: ![Polyhedron](http://i.stack.imgur.com/w7TBN.png)               pts={{0., 0., 0.}, {0., 0., 1.79176}, {0., 1.79176, 0.}, {1.79176, 0.,        0.}, {0., 1.79176, 0.}, {0., 0., 1.79176}, {1.79176, 0., 0.}, {0.,        1.79176, 0.606136}, {0., 0.606136, 1.79176}, {0., 1.79176,        0.606136}, {0., 0.606136, 1.79176}, {1.79176, 0.,        0.606136}, {0.606136, 0., 1.79176}, {1.79176, 0.606136,        0.}, {0.606136, 1.79176, 0.}, {1.79176, 0., 0.606136}, {0.606136,        0., 1.79176}, {1.79176, 0.606136, 0.}, {0.606136, 1.79176,        0.}, {1.79176, 0., 0.}, {0., 1.79176, 0.}, {0., 0.,        1.79176}, {1.79176, 0., 0.606136}, {0.606136, 0.,        1.79176}, {1.79176, 0.606136, 0.}, {0.606136, 1.79176, 0.}, {0.,        1.79176, 0.606136}, {0., 0.606136, 1.79176}, {0., 1.79176,        0.606136}, {0., 0.606136, 1.79176}, {1.79176, 0.606136,        0.}, {0.606136, 1.79176, 0.}, {1.79176, 0., 0.606136}, {0.606136,        0., 1.79176}, {1.79176, 0.606136, 0.}, {0.606136, 1.79176,        0.}, {1.79176, 0., 0.606136}, {0.606136, 0., 1.79176}, {1.79176,        0.606136, 0.}, {0.606136, 1.79176, 0.}, {1.79176, 0.,        0.606136}, {0.606136, 0., 1.79176}, {0., 1.79176, 0.606136}, {0.,        0.606136, 1.79176}, {0., 1.79176, 0.606136}, {0., 0.606136,        1.79176}, {1.79176, 0.606136, 0.374693}, {1.79176, 0.374693,        0.606136}, {0.606136, 1.79176, 0.374693}, {0.374693, 1.79176,        0.606136}, {0.606136, 0.374693, 1.79176}, {0.374693, 0.606136,        1.79176}, {1.79176, 0.606136, 0.374693}, {1.79176, 0.374693,        0.606136}, {0.606136, 1.79176, 0.374693}, {0.374693, 1.79176,        0.606136}, {0.606136, 0.374693, 1.79176}, {0.374693, 0.606136,        1.79176}, {1.79176, 0.606136, 0.374693}, {1.79176, 0.374693,        0.606136}, {0.606136, 1.79176, 0.374693}, {0.374693, 1.79176,        0.606136}, {0.606136, 0.374693, 1.79176}, {0.374693, 0.606136,        1.79176}, {1.79176, 0.606136, 0.374693}, {1.79176, 0.374693,        0.606136}, {0.606136, 1.79176, 0.374693}, {0.374693, 1.79176,        0.606136}, {0.606136, 0.374693, 1.79176}, {0.374693, 0.606136,        1.79176}, {1.79176, 0.606136, 0.374693}, {1.79176, 0.374693,        0.606136}, {0.606136, 1.79176, 0.374693}, {0.374693, 1.79176,        0.606136}, {0.606136, 0.374693, 1.79176}, {0.374693, 0.606136,        1.79176}, {1.79176, 0.606136, 0.374693}, {1.79176, 0.374693,        0.606136}, {0.606136, 1.79176, 0.374693}, {0.374693, 1.79176,        0.606136}, {0.606136, 0.374693, 1.79176}, {0.374693, 0.606136,        1.79176}}


Draw an arbitrary convex polyhedron

I want to draw a set of convex polyhedrons whose vertices are defined by spherical coordinates on the surface of a unit sphere. How can I accomplish this in Mathematica? It seems I cannot do it with PolyhedronData (even though the polyhedrons I want to draw are symmetric and quite simple). It even cannot draw a hexagonal dipyramid, {"Dipyramid", 5} works, {"Dipyramid", 6} does not. I also tryed to use Polygon, but it leaves a number of faces not filled.


Custom formatting for DateListPlot

I'd like to control more aspects of a `DateListPlot`, for example: shading for weekend days, and/or indicators for daytime/nighttime areas. By way of illustration, here's a simple example of a set of time data points (recent questions on mathematica.stackexchange):               questions =        First[Rest[         Import["http://api.stackexchange.com/2.0/questions?page=1&\     pagesize=100&order=desc&sort=creation&site=mathematica", "JSON"]]];          questionTimes =        Cases[questions, HoldPattern["creation_date" -> value_] :>  value,         Infinity];          hours = (Mod[#, 86400] /86400) 24  & /@ questionTimes ;          DateListPlot[Transpose[{questionTimes, hours}], Filling -> Bottom,       GridLines -> False, Frame -> {True, True, False, False}]      and the plot is like this: ![stack exchange](http://i.stack.imgur.com/xwQlR.png) I can't see how to show the necessary information along the x-axis, nor how to shade different areas of the graph to show day/night. _Edit_ : I now realise that the date/times returned by the SE API are in Unix Epoch (1970), and I hadn't noticed because I wasn't able to see the day numbers or years on my first attempt at a plot...


How does the speed of WriteString compare to other languages?

I'm doing something where the most sensible approach seems to be to open a file and write to it as I process data from some large tables. Old school. While testing the program, I remembered the low level write statements I use to use to do this kind of thing in FORTRAN and how fast they seemed to be, and I wondered how `WriteString` compared, so I did a little test. It took 10.875 seconds to write 1,000,000 records with record number, "Hello World." That seems pretty fast, but how does that compare to other languages? I use only Mathematica these days so I can't easily do any comparisons.               funit = OpenWrite[NotebookDirectory[] <> "writetest.csv"];     Timing[Do[WriteString[funit, i, ",Hello World\n"];, {i, 1, 1000000}]]          (*  {10.875000, Null}  *)


Problems using hand-made transformation functions

I experience difficulties when using custom transformation rules. Below I give two concrete problems. I am interested in fixing each of them and in understanding what is wrong with my attitude to the issue in general. 1) Suppose I try to make symbolic computations involving gamma function $\Gamma(z)$ more effective. Particularly, I want $\it{Mathematica}$ to make use of the property $\frac{\Gamma(z+1)}{\Gamma(z)}=z$ in simplification, which it doesn't do on its own. Evaluation of               Simplify[Gamma[z + 1]/Gamma[z]]      returns               Gamma[1 + z]/Gamma[z]      In order to handle this task let me define the first transformation function               tf1[e_] := e /. Gamma[x_]/Gamma[y_] /; Simplify[x - y] == 1 :> y;      Now evaluation of                Simplify[Gamma[z + 1]/Gamma[z],       TransformationFunctions -> {Automatic, tf1}]      indeed gives               z      However, execution of               Simplify[Gamma[z + 1]^2/Gamma[z]^2,      TransformationFunctions -> {Automatic, tf1}]      results in no real simplification and gives               Gamma[1 + z]^2/Gamma[z]^2      Well, one unwitty way to deal with this problem is to define a separate transformation function for the ratio of squares. But the ratio of the third powers will then require a third transformation function and so on. I would like to handle all these possibilities universally. I've tried something like               tfUniversal[e_] :=      e /. (Gamma[x_]/Gamma[y_])^n_ /; Simplify[x - y] == 1 :> y^n;      but this didn't work. Is there a way to solve this problem? 2) The second chapter of my adventures includes teaching "Mathematica" identity $\Gamma(z)\Gamma(1-z)=\frac{\pi}{\sin{\pi z}}$. Here problem comes right at the start. I define transformation function               tf2[e_] :=      e /. Gamma[x_] Gamma[y_] /; Simplify[x + y] == 1 :> Pi/Sin[Pi x];      and then evaluate               Simplify[{Gamma[-z] Gamma[1 + z], Gamma[z] Gamma[1 - z]},      TransformationFunctions -> {Automatic, tf2}]      which gives               {-\[Pi] Csc[\[Pi] z], Gamma[1 - z] Gamma[z]}      so that simplification occurs in the first case but not in the second. I wonder what is the problem here. Overall, I am very often troubled with such issues. Is it possible to find some references in the literature on using custom transformation rules? Any help is highly appreciated, thanks :)


Plotting TransformedDistributions of a Poly-Aeppli distribution

I do not know how to plot a `TransformedDistribution` of the named Polya- Aeppli distribution and do not know if the transformation can be handled after reading: Just what kind of transformations can TransformedDistribution handle?. I'm having trouble understanding the format of the plotting transformed distributions but hope that I can keep `TransformedDistribution` as part of the command.


How to use Interpolation to fill in missing data

I have a bit of data that looks like this:               data = {79., 79.1, 78.3, 78.6, 79., 77.2, 79.3, 79.3, "", "", 79.3, 76.6, \     79.3, 79.8, 78.4, 79., 78.4, 78.4, 79.4, 79.5, 79.4, 79.3, 79.2, \     79.2, 79.3, 79.6, "", 79.2, 79.3, 79., 79.1, 79.2}      I'm looking to do Linear Interpolation to fill in the missing data. The `Interpolation` functions with `InterpolationOrder->1` seems to be just what I am looking for. But I can't figure out how to feed the data to the `Interpolation` function in order to get a a sensible result.


How to define the Poisson bracket in Mathematica

If $f,g$ are functions of the independent variables $\\{q_1, q_2, ..., q_N, p_1, p_2, ..., p_N\\}$, then the Poisson bracket is defined as: \begin{equation*} [f, g] = \sum_{i=1}^N \left(\frac{\partial f}{\partial q_i}\frac{\partial g}{\partial p_i} - \frac{\partial f}{\partial p_i}\frac{\partial g}{\partial q_i}\right) \end{equation*} I'd like to define Poisson bracket in _Mathematica_. Just so to prove I'm not lazy, I wrote the following snippet (I doubt it is correct, let alone slick).               ClearAll["Global`*"];     pbra[f_, g_, q_, p_] :=         With[{c = Join[q, p]},          Sum[           D[f@@c, q[[k]]] D[g@@c, p[[k]]] - D[f@@c, p[[k]]] D[g@@c, q[[k]]],          {k, 1, Length@q}]]      And call it like (dummy example):               f[x_, y_, px_, py_] := x+y+px*py;     h[x_, y_, px_, py_] := x-y+px/py;     p[f, g, {x, y}, {px, py}]      How would _you_ define Poisson bracket ? For example, I am wondering whether it would be more sound to define it in a way that the user calls it like:               f[x_, y_, px_, py_] := x+y+px*py;     h[x_, y_, px_, py_] := x-y+px/py;     p[f[x, y, px, py], g[x, y, px, py]]


Solving a constrained vector system with NDSolve

I'm trying to replicate the pendulum DAE example in the Documentation Center (example/ModelConstrainedSystemsAsDAEs) using Mathematica 9's vector support with NDSolve. So far I have:               deqns = {m X''[t] == \[Lambda][t]-{0, m 9.81}};     constraints = {Norm[X[t]] == 1};     initialConditions = {X[0] == {1, 0}, X'[0] == {0, 1}};     params = {g -> 9.81, m -> 1, l -> 1};          pendulumSol =       First[NDSolve[{deqns, constraints, initialConditions} /.         params, {X, \[Lambda]}, {t, 0, 15},           Method -> {"IndexReduction" -> Automatic}]];      but am getting:               NDSolve::ndincd: "Initial conditions for derivatives of the                        function X[t] do not have consistent dimensions."      Is this an issue with NDSolve properly identifying the vector nature of the equations, or have I overlooked something? Any help would be appreciated.


Need help in building a pattern

Suppose I have the following list:               list = {w, r, {f, first, t, y}, {a, y}, last, {k, r, first, e}, m, e, last, r, t}      I am expecting this               Cases[list, {__, {__, first, x__}, y__, last, __} :> {{first, x}, y,         last}]      to result in this               (*{{{first, t, y}, {a, y}, last}, {{first, e}, m, e, last}}*)      and this               Cases[Flatten@list, {__, first, x__, last, __} :> {first, x, last}]      to result in this               (*{{first, t, y, a, y, last}, {first, e, m, e, last}}*)      but the results for both are `{}`. How can I build a suitable pattern to get the desired results?


Sporadic bugs in multidimensional SparseArray objects

**Udate** This `SparseArray[]` bug is (apparently) fixed on version 10.0               $System//Print;     $Version//Print;          Mac OS X x86 (64-bit)     10.0 for Mac OS X x86 (64-bit) (June 29, 2014)      Thanks, Wolfram! * * * **Resolution**   * WRI affirms that `SparseArray[__]` is broken (in 9.0 and 9.01)   * WRI's suggested workaround is `SparseArray//Normal` My experience with this particular `SparseArray` bug has been that reliable coding requires that the `Normal` workaround be applied to _every_ instance of `SparseArray`, because the failures of `SparseArray` are sporadic, occult, and associated to unknown preconditions. Ouch! My thanks are extended to all who commented. * * *               Wolfram Technical Support      email: support@wolfram.com     Re: [CASE:646986]          Sporadic bugs (?) in multidimensional `SparseArray` objects          Hi John,          Thank you for getting back to us.          I understand that for now your temporary workaround      of `aTest = aTest // Normal` is holding the fort.          Our developers are working on this issue and      we anticipate that the resolution will appear      in the future release of Mathematica.          Sincerely,          <name redacted>          Wolfram Technology Group     Wolfram Research, Inc.       * * * What appear to be sporadic bugs (?) in multidimensional `SparseArray` objects (?) are plaguing our code development efforts.               $Version//Print;     9.0 for Mac OS X x86 (64-bit) (January 24, 2013)       The following code elicits wrong answers and/or kernel crashes:               Do[         (* aTest is a SparseArray[...] that crashes the kernel and/or            yields incorrect results unless wrapped in Normal[...] *)              aTest = RandomReal[NormalDistribution[0,1], {2,2,2,2}] +             I*RandomReal[NormalDistribution[0,1], {2,2,2,2}]//           SparseArray[               {                   {i_,j_,k_,1 ,i_} :> #[[k,1,i,j]]*#[[k,2,1,j]],                   {i_,j_,k_,2 ,j_} :> #[[k,1,i,j]]*#[[k,2,2,i]],                   {i_,j_,k_,n_,j_} :> #[[k,1,i,j]]/;Equal[n-2,i]               },               {2,2,2,4,2},               Complex[0.0,0.0]           ]&//Flatten[#,1]&//             Transpose[#,{4,1,2,3}]&//               Flatten[#,2]&//                 Transpose;              (* enable the following line to "fix" aTest *)         (* aTest = aTest//Normal; *)              (* the following all should be 0.0 (to machine precision) *)              (aTest//Normal)-aTest//           Flatten//Abs//Max//Print["      (aTest//Normal)-aTest =?= 0 = ",#]&;              id = SparseArray[{i_,i_}\[Rule]1,{16,16},0];         (aTest//Normal).id-aTest.id//           Flatten//Abs//Max//Print["(aTest//Normal).id-aTest.id =?= 0 =",#]&;     ,{10}];      **Results** (when the kernel doesn't crash immediately)                     (aTest//Normal)-aTest =?= 0 = 0.     (aTest//Normal).id-aTest.id =?= 0 =7.43925           (aTest//Normal)-aTest =?= 0 = 0.     (aTest//Normal).id-aTest.id =?= 0 =3.14861           (aTest//Normal)-aTest =?= 0 = 0.     (aTest//Normal).id-aTest.id =?= 0 =1.27373           (aTest//Normal)-aTest =?= 0 = 0.     (aTest//Normal).id-aTest.id =?= 0 =1.8666           (aTest//Normal)-aTest =?= 0 = 0.     (aTest//Normal).id-aTest.id =?= 0 =2.03269           (aTest//Normal)-aTest =?= 0 = 0.     (aTest//Normal).id-aTest.id =?= 0 =3.26388           (aTest//Normal)-aTest =?= 0 = 0.     (aTest//Normal).id-aTest.id =?= 0 =1.30013           (aTest//Normal)-aTest =?= 0 = 0.     (aTest//Normal).id-aTest.id =?= 0 =3.14138           (aTest//Normal)-aTest =?= 0 = 0.     (aTest//Normal).id-aTest.id =?= 0 =0.953447           (aTest//Normal)-aTest =?= 0 = 0.     (aTest//Normal).id-aTest.id =?= 0 =0.841252      **Remarks** Variants of the above code crash/fail for Complex-valued and Integer-valued SparseArrays; apparently the multidimensionality is the essential trait. Help, advice, and workarounds all are appreciated!


String pattern matching in function definition

I have a function f and its downvalues. I want to code an extra downvalue for arguments of the form "part1:part2" I don't understand why               f[a__~~":"~~b__] := {a,b}      does not work. I can only think of               f[string_String] /; StringMatchQ[string,__~~":"~~__] := StringCases[string, a__~~":"~~b__ :> {a,b}][[1]]      but this doesn't seem very smart as the string structure is examined two times.


Most influential and/or disrupting features introduced with new versions of Mathematica

This is something that has been bugging me for ages. With every upgrade, _Mathematica_ has added new functionalities and amendend some of its bugs. In the process, though, some older functionality has inevitably been disrupted or made obsolete. This is to be expected of course, and more often than not these modifications and additions are only limited to a change in names, or very limited changes in behaviour (with some completely transparent to users). Some changes, though, have a deeper influence on the way we code and use the front-end with _Mathematica_. Two major game changers (IMBO) have been the introduction of the two-dimensional notation in all versions of Mathematica 3 (Traditional Form notation), and the graphics revolution in Mathematica 6 (graphics are no longer side effects, but real objects). Other important changes that come to mind are the introduction of the packed-array facility in Mathematica 4, the continuing evolution of numerical evaluation through all versions, and the availability of curated data from the Web. The incorporation of most external packages in the core is another game changer, since it contributed to hiding the code and made it harder for users to understand what is going on under the hood. Also, the introduction of Manipulate and of the CDF format have changed the way people use _Mathematica_ to convey ideas. I am well aware that there are sections of the documentation dedicated to _all_ these changes, namely the " **What's new in Mathematica X.x** " parts, that can be found here http://www.wolfram.com/mathematica/quick-revision- history.html and more specifically (for integer values of version numbers) here: > http://www.wolfram.com/mathematica/new-in-9/ > > http://www.wolfram.com/mathematica/new-in-8/ > > https://www.wolfram.com/products/mathematica/newin7/ > > http://www.wolfram.com/products/mathematica/newin5/summary.html > > _?? version 4 what's new ??_ > > http://reference.wolfram.com/legacy/v3/index105.html > > _older versions seems to lack a dedicated part of the documentation_ The purpose of this 'question' is to create a **_selected_** listing of the most disrupting and/or influential changes introduced with every new version. The utility of such a listing is multifold:   1. Understanding older code (need to adapt some old program? reading an old book on Mathematica?)    2. Getting rid of older coding habits (What, you're still using $DisplayFunction?)    3. Getting to know new, more efficient ways, to do stuff (Maybe Total is better than Plus@@ with Packed Arrays?)    4. Having a list _ordered_ by perceived importance of the most relevant changes (Yeah, let's see the really important changes of paradigm that I have overlooked...) The template for the answers, in my opinion, should carry a title like this > **From X.x to Y.y : name of the feature of behaviour** for example (these are just examples of the titles of three separate answers)                   From 2.2 to 3.0 : Frontend with two dimensional notation         From 3 to 4 : Packed Arrays         From 5.1 to 5.2 : 64-bit-enhanced arbitrary-precision numerics      And then elaborate what is that has changed, why is that important and how it has changed the way you coded or used Mathematica. **ONE** answer, **ONE** feature. My idea is to have answers to this post pop up naturally by voting, and then from time to time update this very post with a list by importance for each version change. As many other threads of this kind, this is a Collaborative Wiki post.


Saving a graph of a great number of nodes

I'm developing a code where I get graphs with over 10K nodes. These graphs have a particular relationship between clustering and degree that I need to save for future analysis. The problem is when I use `EdgeList` and then save the list in a _Mathematica_ file (.nb), when I recall it, the size of some communities are different to the ones showed by the graph. The following sizes are obtained after change the graph by the `EdgeList`               Community = FindGraphCommunities[g];     aux = Length[#] & /@ FindGraphCommunities[g]      > >     {1845, 1656, 1536, 1419, 1206, 441, 349, 342, 210, 205, 168, 126, >               113, 103, 73, 58, 57, 45, 40, 8} >   Then I use `EdgeList[g]`, click on Show full Output and copy the entire cell and save it into the file.nb. When I call again the graph `g3` from the file.nb it gives me the following sizes               g = g3;     Community = FindGraphCommunities[g];     aux = Length[#] & /@ FindGraphCommunities[g]      > >      {1884, 1766, 1720, 1364, 643, 420, 420, 394, 266, 218, 211, 159, 117, >             101, 93, 76, 29, 28, 24, 21, 20, 16, 10} >   I don't know what happen there, could be the command `EdgeList` or something behind...Then I try to save the graph by Exporting it as a `gml` file and after 10 minutes it was still running... So, do you have any suggestion for this, how can I export efficiently this information or do I have to wait for the exportation in `gml` format?


Cropping a Plot without rasterization

Suppose that I make a plot of $x^2$ vs. $x$:               myPlot = Plot[x^2, {x, -1, 1}, Frame -> True]      ![myPlot1](http://i.stack.imgur.com/PkklF.png) If I click on the plot, I see the orange handles with which I can resize the plot: ![myPlot2](http://i.stack.imgur.com/xfyTX.png) Now, suppose that I want to actually crop the plot -- I would like to effectively shrink the orange box so that some of the plot is actually cropped. ( _Why in the world would I want to do this?_ It's a long story...) I have found, from answers to a question that I previously asked, that this is possible using `ImagePad` with negative arguments. For example, suppose that I want to crop 40 pixels off the right side of the plot. I can do the following:               ImagePad[myPlot, {{0, -45}, {0, 0}}]      ![myPlot3](http://i.stack.imgur.com/Fh4Vy.png) It looks good so far. **_However,_** when I resize the resulting cropped plot by dragging the orange handles, it looks like the image has been rasterized: ![myPlot4](http://i.stack.imgur.com/BhwSu.png) **But, in contrast, I need the image to remain a vector image (non-rasterized) after cropping.** Is that possible? I am running both version 8 and 9.


Manipulate strings within a list

Let's say I have               Solve[x^4 + 3 == 0, x]      with output               {{x -> -(-3)^(1/4)}, {x -> -i (-3)^(1/4)}, {x ->i (-3)^(1/4)}, {x -> (-3)^(1/4)}}      how do i lose the "x->" part of each string within this list and get something like               {-(-3)^(1/4), -i (-3)^(1/4), i (-3)^(1/4), (-3)^(1/4)}      Thanks for the answers/links. Judging by the answers I realise now that I have formulated my question poorly. I wanted to know how I lose symbols that are in front of a specific symbol. Let's have a look at two more examples:               list={a: horse, b: chicken, c: fish}      how do I lose "a: ","b: ","c: " or               list2={section 1, section 2, section 3}      how do I lose "section"


SSH known hosts in Windows (Error code = 124)

I had to re-install Raspbian OS and now it has new SSH key. SSH clients usually let ignore this fact and save the new key, but not now. Mathematica gives no way to go if the Host Key was changed. I get an error               SSH received a different Host Key while launching kernel 'Raspberry Pi'. Error code = 124.      when trying to start remote kernel and I have found no any information about where is the Mathematica's SSH client on Windows... I just need to clear known hosts... The easy way is to change Raspberry's IP, but it's far less interesting, moreover not always possible


VertexLabelStyle not found in Mathematica 8.0.0.0

I tried to use `VertexLabelStyle`, but seemed not recognized in my system with version number 8.0.0.0. Is this expected or I have missed something? From the online documentation page, I don't see this option was added after version 8.0.0.0; it just says "New in version 8".


Manipulate[] inside DialogInput[]

I would like to get input from an interactive dialog that uses `Manipulate[]`. But I find that my `Manipulate[]` breaks when I put it inside a `DialogInput[]`. So, when I try `DialogInput[Manipulate[Plot[Sin[e x], {x, 0, 2 \[Pi]}], {e, 1, 10}]]` the plot inside the dialog is not connected to the `Manipulate[]` slider. What am I missing here?