title: Fast Karatsuba Squaring, how to?

text: I want to improve timing of squaring for big numbers. So I asked What is the fastest way to split a number into parts and What is the most efficient way to add zeros to end of a number with several answers posted. Karatsuba multiplication must benefit from smaller size multiplication but mine suffer from this.                 FastSquare[a_] := (TotalLen = IntegerLength[a];        If[TotalLen == 1, Return[a*a]];        e = Quotient[TotalLen, 2];        {A, B} = QuotientRemainder[a, 10^e];        Result = A*A*10^(2*e) + 2*A*B*10^(e) + B*B;        Return[Result])      And timings are:               In[21]:= First[Timing[(2^200000000 + 1)^2]]          Out[21]= 2.281          In[20]:= First[Timing[FastSquare[2^200000000 + 1]]]          Out[20]= 15.86                  (Debug) In[25]:= FastSquare[2^200000000 + 1]; // RuntimeTools`Profile               Calls   Time    Evaluation     1   15.766  FastSquare[2^200000000+1];     1   15.766  FastSquare[2^200000000+1]     1   15.75   FastSquare[a_]     1   15.75   TotalLen=IntegerLength[a];If[TotalLen==1,Return[a a]];e=Quotient[TotalLen,2];{A,B}=QuotientRemainder[a,10^e];Result=A A Power[<<2>>]+2 A B Power[<<2>>]+B B;Return[Result]     1   10.422  Result=A A 10^Times[<<2>>]+2 A B 10^e+B B     1   10.422  A A 10^(2 e)+2 A B 10^e+B B     1   5.328   {A,B}=QuotientRemainder[a,10^e]     1   5.328   QuotientRemainder[a,10^e]     1   5.203   A A 10^(2 e)     1   4.141   2 A B 10^e     1   1.344   10^(2 e)     1   1.031   B B     1   0.656   10^e     1   0.625   10^e     1   0.016   2^200000000+1      As you can see 5 seconds are spent on splitting the numbers (pre-processing). And each half size multiplication took double of original squaring time because of adding zeros. Already I've shown here that it is quite possible to improve the speed of some of Mathematica functions by rewriting them. Anyway to reduce the timing of `FastSquare` function to less than timing of `^2` ?


title: Importing multiple images for machine learning classification

text: I want to create a ML classifier using images just like this example. I have two classes of images in two different folders. Is there an easier way to import all images from both folders rather than inserting picture by picture? ![enter image description here](http://i.stack.imgur.com/stYyQ.png)


title: EventHandler and ActionMenu

text: Here is the bit of code causing me issues:               {DynamicModule[{nothing},       EventHandler[        ActionMenu["Set x", {"x = 1" :> (x = 1;)}, Enabled -> True],        {"MouseClicked" :> (nothing++)}]], Dynamic[x]}      No matter how hard I try to click the `ActionMenu` does not open at all. Removing the `{"MouseClicked" :> (nothing++)}` allows to open the `ActionMenu`:               {DynamicModule[{nothing},       EventHandler[        ActionMenu["Set x", {"x = 1" :> (x = 1;)}, Enabled -> True],        {}]], Dynamic[x]}      The aim of the code would be to `Enable`/`Disable` the `ActionMenu` after `x = 1` is clicked in this example. What am I doing wrong in the first bit of code?


title: Need help looping a notebook evaluation

text: I'm a new user and would like to find the minimum value of soln1[30] obtained after repeating the following evaluation (below) for 1000 cycles (for instance). I can obtain sequential values of soln[30] if I reevaluate the entire notebook manually each time, but I want to be able to automate this process until a minimum value of soln1[30] is reached. The difficulty that I am encountering is that the entire notebook requires evaluation in order to generate a different random integer each time- I am having trouble figuring out how to force the evaluation to include the randominteger step using commands like Table, etc. I'm probably missing something simple- any help would be appreciated. Thanks in advance...               Clear[w, t, q, soln1]          f1[t_] := 5*t;          w = RandomInteger[{1111, 9999}];     a = IntegerDigits[w][[1]];     b = IntegerDigits[w][[2]];     c = IntegerDigits[w][[3]];     d = IntegerDigits[w][[4]];     p = 0.1;     k = 0.6;          end1 = a;     p1 = end1 + p;     end2 = p1 + b;     p2 = end2 + p;     end3 = p2 + c;     p3 = end3 + p;     end4 = p3 + d;          soln1[t_] := Piecewise[{{f1[t], t < end1}, {k*f1[end1],       end1 <= t < p1}, {f1'[t]*(t - p1) + k*f1[end1],       p1 <= t < epnd2}, {k*f1[end2],       end2 <= t < p2}, {f1'[t]*(t - p2) + k*f1[end2],       p2 <= t < end3}, {k*f1[end3],       end3 <= t < p3}, {f1'[t]*(t - p3) + k*f1[end3], p3 <= t <= 30}}];           soln1[30]


title: EventHandler and Refresh rate

text: Based on the example of the Documentation of MousePosition, Properties and Relations, here is my test code using "MouseDragged" instead of "MouseClicked":               DynamicModule[{list = {}},      EventHandler[       Dynamic[        Framed@Graphics[{Red, Point[list]}, PlotRange -> 2]        ]       , {"MouseDragged" :> AppendTo[list, MousePosition["Graphics"]]}       ]      ]      Using this, one can drag lines of dots as follows: ![enter image description here](http://i.stack.imgur.com/nTlQc.jpg) The top line was drawn while moving the mouse very slowly, the bottom line was drawn with a faster mouse movement. I would now like to add even more points in the bottom line, to be able to have an almost full line, even with fast mouse movements. I have checked out `Refresh`, and `UpdateInterval`, but that didn't change everything. So: is it possible to track **all** pixel movements of the mouse inside a certain region, to be able to plot **all** points? As always, thanks for all help!


title: Format-Size-Larger/Smaller shortcut disabled in M10?

text: It seems that the keyboard shortcuts for enlarging/reducing the font size (ALT+= / ALT+-) don't work anymore in M10 as it did in M9. If I select the text (or code) **inside** a cell they work. But if I select **a cell or more cells** they don't do nothing anymore. The only way to change the font size of some cells is now to go through the _Format-Size_ menu. With M9 I used these shortcuts very often to gradually adjust the font size of one or more cells. Maybe there is some setting in the Option Inspector that I must change? (I'm on windows 8.1 64bit)


title: How can I solve my non-linear ODE?

text: DSolve[{-x^2 + y[x]^2 - 2 x*y[x]*y'[x] + 2*x^2 *y'[x]^2 == a^2}, y[x], x]      `DSolve` is returning the input statement unevaluated. Any kind of help will be most appreciated.


title: Combining images with CUDA

text: **2nd Edition** : To make it a bit more clear, and to summarize the discussion in comments. **I have a small image** , like this one:               InsertImage =       DensityPlot[Sqrt[1 - x^2 - y^2], {x, -1, 1}, {y, -1, 1},        Frame -> False,        ColorFunction -> (Opacity[Max[Re[#], 0],            GrayLevel[Max[Re[#], 0]]] &), ImageSize -> 40,        Background -> Opacity[0, Black]]      It is just a semi-transparent gray ball: ![enter image description here](http://i.stack.imgur.com/JsouH.jpg) Outside the ball you see white - because of transparency. **I have a big background** , like this one:               InsertIntoImage = Image[GrayLevel[0], ImageSize -> 400];      It is just big black background. **I want to insert the small image into the big one many-many times** , e.g. at these scaled positions:               PosList = {Cos[Pi #], Sin[4 Pi #]}^2 & /@ Range[0, 1, 0.005];      Vaguely, the result should be like:               Rasterize[       Graphics[{Inset[InsertIntoImage],          Inset[InsertImage, Scaled[#]] & /@ PosList},         ImageSize -> 400]] // AbsoluteTiming      ![enter image description here](http://i.stack.imgur.com/Vr41C.jpg) **Ideally** :   1. I want to add up only grayscale channels of big and small images.   2. Small images are to be added really many times - it is for video production, and the above example is a very light version of it.   3. I want to make it work fast for many more images at a time: Inset is way too slow. **Question: How to do it with CUDA?** **Notes on CUDA (why CUDA)** :   1. It should work much faster. Note, the overhead of caching one small image is negligible.   2. I can't seem to find an appropriate inbuilt function: CUDAImageAss[] uses only images of similar size.   3. Putting small images pixel by pixel in matrix form is not very much to my liking. I want to be able to specify small image positions at subpixel accuracy. Normally, this would smear each pixel of each small image with a pointspread function. It is doable, but I believe there must be existing algorithms.   4. Such a problem must have been solved a thousand times, e.g. in videogames, movie production, etc. Note, that GPUs in videogames allow rendering in realtime, hence this approach should work fast here too.


title: Why does FindFit seem to have trouble fitting exponential data?

text: I have 4 data points. t is in minutes, and y is radioactive counts per minute. When I input the following lines:               data = {{90., 140075.}, {120., 96018.}, {150., 73003.}, {180., 36980.}};     model = a*Exp[-k*t];     fit = FindFit[data, model, {a, k}, t]      the output given is:               {a -> 64.6435, k -> 0.29285}      This is clearly not correct. The parameter 'a' should be somewhere around 530000 (as per Excel's fitted equation). What's happening here, and how can I fix this? I'm surprised a bit. This is a simple exponential fit. What am I doing wrong?


title: Why is `NMinimize` trying to evaluate my function analytically instead of numerically?

text: I have been having some trouble with `NMinimize`. I am trying               NMinimize[f[x], x]      where `f` is a complicated function. The whole reason I am using `NMinimize` is because `f` is too complicated to be able to compute for an arbitrary `x`, but for a fixed value of `x` it is fine. Well `NMinimize` seemed to be taking up an outrageous amount of time and memory, so I added a print statement inside `f`               f[x_]:= Module[{},     Print[x];     ...     ]      and ran the `NMinimize` code again. To my surprise, Mathematica prints `x$4770`, the name of a local variable. Why is `NMinimize` calling my function with non-numeric values? How can I stop it from doing so?


title: Impact Crater Simulation

text: I have been trying to model crater formation on a given planetary surface - $500\,\textrm{km}^2$. The locations of impacts are random, however, if an impact is within $30\,\textrm{km}$ of another, the previous crater is considered eliminated. So far I have used `RandomReal[0,500]` for both the $x$ any $y$ coordinate values on the $500\,\textrm{km}^2$ plot. My problem is that the arrangement of craters changes for every evaluation I do. What I'm looking to achieve is a cumulation of craters, one by one."Drawn on" so to speak. This way, appropriate crater destruction can also ensue. I am also still trying to figure out a way to model crater destruction. As I mentioned, if an impact location is within $30\,\textrm{km}$ of another, the previous crater is eliminated. I tried using `If[EuclideanDistance[],...]` but no luck. The code I used for crater location (points) is:                   craterlocations = Table[{RandomReal[{0, 500}], RandomReal[{0, 500}]}, {n}]         p1 = ListPlot[craterlocations]      I need to produce a similar plot, but the craters should continually form. As of now I will always wind up with a different random arrangement for each number of impacts (`n`).


title: Force integration to be linear over sum?

text: Is there an obvious way to force Mathematica to separately integrate the terms in a sum? According to the docs, > When part of a sum cannot be integrated explicitly, the whole sum will stay > unintegrated. But I want to do this because some of the terms have a nice closed form, and some don't, but I want to compute the former. Here's what I've done; it works, but it seems inelegant:               integrand = m^2 + mp^2 + mp f[mp] (* the actual integrand is much more complicated! *)          (myint[integrand // Expand]          //.  myint[a_ + b_] :> myint[a] + myint[b]         //.  myint[i_] :> Integrate[i, {mp, -1, 1}]) // FullSimplify      Which gives the correct               2/3 +  2*m^2 + Integrate[mp*f[mp], {mp, -1, 1}]


title: Plotting the results of a system of equations

text: I believe this is a question of more list manipulation than plotting, but I hope you could help me. I solve numerically a system of equations of 3 variables, take only real solutions where one of the parameters is within the unit circle and evaluate its stability for different cost parameter C as               costValues = {};     solutionValues = {};     stabilityValues = {};     Do[     (*real steady state solutions where m is within the unit circle*)     ssOut = Select[NSolve[{x == xEq, p == pEq, m == mEq} /.{C -> costVal}, {x, p, m}],      Element[{x, p, m} /. #, Reals] && 0 < ({x, p, m} /. #)[[3]] < 1 &];     (*calculate eigenvalues for the Jacobian for each solution*)     eigenValues = Table[N[Eigenvalues[jacobian /. {C -> costVal} /.solution]], {solution, ssOut}];     (*check how many eigenvalues are within the unit circle*)     stability = Table[Length[Cases[eigenValue, x_ /; -1 < Re[x] < 1]], {eigenValue,  eigenValues}];     (* append the results to the lists *)     AppendTo[costValues, costVal];     AppendTo[solutionValues, ssOut];     AppendTo[stabValues, stability];     , {costVal, 0, 1}]      My result lists look the following               costVals= {0., 1};     solutionValues= {{}, {{x -> 28.8952, p -> 0.059159, m -> 0.010203}, {x -> -28.8946,      p -> -0.0577157, m -> 0.010203}, {x -> 28.8886, p -> 0.0432996,      m -> 0.010203}, {x -> -28.888, p -> -0.0418563, m -> 0.010203}}};     stabValues= {{}, {3, 2, 1, 1}};      Of course, there could be many more costVar values. The point is, that for each costVar value I could have a number of solutions with different stability values. I would like to plot on separate diagrams different solution values x, p and m against the costValues and with a condition that if a stabValue is equal 2 the color should be green (stable) and if not then it should be red (unstable). So for example above, on horizontal axis I would like to have values 0 and 1 and on vertical axix for instance for variable x I would like to 0 points for costVal=0 and 4 points for costVal=1 where the second solution should be marked green and the other red. I spent a couple of days on that without a success, do you have any idea how to do that efficiently?


title: Why am I getting so many error messages from my pendulum simulation?

text: I'm doing my end of semester project for a physics class. We were supposed to graphically model a physical occurrence; I chose doing a Pendulum Wave. I have my code written, however Mathematica keeps kicking out these errors:               Manipulate::vsform: Manipulate argument Null does not have the correct form for a variable specification.      The help files isn't much use, but going to the error box gives these errors:               Lighter is not a Graphics primitive or directive.     Darker is not a Graphics primitive or directive.     Blue is not a Graphics primitive or directive.      There are a couple of more errors dealing with the Coordinate command. Below is all of my code. My best guess as to what's going on is that Graphics cannot be combined with the Table command. If that's the case, how do I use the list of solutions for the lengths with Graphics?                   Manipulate[          Module[           {sol, \[Theta], t, L, periods, perFcn, nPend, \[Theta]0, lens,             g = 9.8},           periods = 60/Range[51 + nPend - 1, 51, -1] ;           perFcn =             Sqrt[(32 L)/(g (1 - Cos[\[Theta]0]))]              EllipticF[\[Theta]0/2, Csc[\[Theta]0/2]^2];           lens = Chop[             Table[L /. First@Solve[periods[[i]] == perFcn, L], {i, nPend}] // N];           sol = Table[             NDSolve[{\[Theta]''[t] + g/lens[[i]] Sin[\[Theta][t]] ==                 0, \[Theta][0] == \[Theta]0, \[Theta]'[0] == 0}, \[Theta][               t], {t, 0, time}, Method -> "StiffnessSwitching"]             , {i, 1, nPend}             ];           Table[            Graphics[{              {Line[{{0,                   0}, {(lens[[i]])*Sin[sol[[i]]], -(lens[[i]])*                   Cos[sol[[i]]]}}]},              {Lighter[Brown], Rectangle[{-4, 0}, {4, .5}]},              {Darker[Red], Disk[{0, 0}, .1]},              {Blue,                Disk[{(lens[[i]])*Sin[sol[[i]]], -(lens[[i]])*                  Cos[sol[[i]]]}, .2]}              },             PlotRange -> {{-5, 5}, {.5, -14}}, ImageSize -> {500, 300}             ],            {i, 1, nPend}            ]           ]          ,          {{nPend, 10, "Number of Pendulums"}, 1, 25, 1(*,Appearance->"Labelled"*)},          {{\[Theta]0, \[Pi]/6, "Initial Angle"}, {0, \[Pi]/12, \[Pi]/6, \[Pi]/4, \[Pi]/3}},          ]      The graphics code came from this, with minor variations.


title: Does Mathematica have a built-in date picker?

text: Does _Mathematica_ have an interactive date input control that lets the user choose a date by browsing to a calendar view and returning the selected date as a date list? For example, something like the Datepicker in jQuery.


title: Mathematica 9 Autocomplete Pop-up issue

text: I've just installed Mathematica 9.0.1 Student Edition on my Laptop and my Home PC. On my Laptop, it works just fine. But on my Home PC I get this weird issue of the pop-up command autocomplete window having some weird graphical issues as seen in the attached picture. I've already tried resetting and reinstalling it. It didn't help. When I click on the arrow and scroll through the list, the whole thing goes black. PC is running Windows 7 Ultimate (x64) CPU: i7 870 GPU: Nvidia GTX-470 (Drivers are up-to-date) Thanks, for your help! ![The described problem](http://i.stack.imgur.com/SKdxG.png)


title: Save notebook without including Front End version information

text: How can a notebook be saved without including the front end version? If you open a `.nb` file, you'll see something like               FrontEndVersion -> "9.0 for Mac OS X x86 (32-bit, 64-bit Kernel) (November 20, 2012)"      close to the end of the `Notebook` expression. I would like to simply not have this option. **Use case:** Mathematica will issue a warning when opening a notebook that was created in a newer version (for example when using version 8 to open a notebook created in version 9). This applies to palettes as well. When distributing a palette (such as the SE image uploader) to people with both version 8 and version 9, I need to make sure that the palette doesn't have `FrontEndVersion` that indicates version 9, otherwise people with v8 get a warning. I would like to keep the flexibility to generate the palette in v9 though, and just test with v8 occasionally. My current options are either editing out the version info manually from the `.nb` or generating the palette only with v8.


title: Highlight integer points in RegionPlot

text: Is there any way to mark integer points after plotting region in _Mathematica_? For example, if I:               RegionPlot[x >= 4 y && x <= 4 y + 3 , {x, 0, 63}, {y, 0, 15}]      ![Mathematica graphics](http://i.stack.imgur.com/ozJjh.png) then it highlights the region but I want to see Y value corresponding to integer X value. Can I do it with _Mathematica_?


title: Changing order of TeXForm output

text: I am creating Taylor polynomials and exporting them using `TeXForm`. When a polynomial `p[x]` is displayed in _Mathematica_ , it shows, for instance, `1+x+x^2+x^3`. However, `TeXForm` always reverses the polynomial, giving it with largest power first: `TeXForm[p[x]] = x^3+x^2+x+1`. How can I keep the polynomial in the same order? Taylor polynomials are generally thought of as being constructed from low-to-high powers, so reading them in the generated format is a bit confusing to some.


title: Adapt ticks in plot and font in legend

text: 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!


title: backward compatibility

text: 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 !)


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

text: 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 ?


title: Scoping in assigning a derivative

text: 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!


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

text: 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!


title: Finding maximum/minimum value of system of inequalites

text: 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


title: How to select the text on the button?

text: 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?


title: Parameter Estimation of a mixture of sums of Lognormals

text: 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?


title: Solving a trigonometric equation with one parameter

text: 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


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

text: 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?


title: Using Plot3D with one variable dependent on the other

text: 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)`.


title: FindMaxValue specifics

text: 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


title: Simplifying a trigonometric sum

text: 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?


title: Can I customize a TradingChart?

text: 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.


title: Load a Mathematica Package via .Net code

text: 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?


title: Making an animated simulation without procedural loops

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


title: How do I solve this equation?

text: 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?


title: Contour coloring and (List)ContourPlot projection

text: 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!


title: How can I get WhenEvent to recognize criterion I specify?

text: 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


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

text: 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.


title: How can I solve my recursion equation?

text: 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]


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

text: 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)


title: How can I draw temperature 3D plot?

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


title: Check Google PageRank for a given URL

text: 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_.


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

text: 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?


title: Why is FindRoot initial value far from the specified one?

text: 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.


title: Liouville theorem demonstration

text: 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.


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

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


title: How to use Mathematica to obtain the correct simplified results?

text: 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.


title: Memory consumed by NMaximize with NDSolve

text: 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?


title: Projection of ContourPlot3D

text: 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.


title: How to apply an rule to factors matching a certain form

text: 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?


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

text: 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.


title: Connect to SQLite database

text: 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.


title: Space around indices in Mathematica 10

text: 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)


title: Mathematica2tikz an equivalent function

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


title: system of ODE through NDSolve

text: 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]


title: Project Euler (memory and speed issues)

text: 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.


title: NDSolve does not respond

text: 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]


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

text: 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??


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

text: 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


title: project from a n-dimensional space to 2-dim

text: 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.


title: load static library (.lib) using NETLink

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


title: Gauss Markov Process

text: 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


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

text: 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.


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

text: (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?


title: Where can I permanently modify $Path?

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


title: RootSearch for complex or multiple equations

text: 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?


title: Is there any automatic differentiation package?

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


title: Problem with importing a JCAMP-DX IR spectrum file

text: 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?


title: Plotting a section of an hemisphere

text: 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


title: Is there a bug in Pick?

text: 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?


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

text: 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?


title: Convex hull of a 3D object?

text: 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)


title: Efficient drawing of convex polyhedron given a set of points

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


title: Draw an arbitrary convex polyhedron

text: 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.