Vertices, their labels, and how to refer to them?

In the examples I have seen, graph vertices in Mathematica are usually explicit small integers. However, Wolfram documentation says that vertices can be any arbitrary expression (eg., george, x^2, London, 5). Nevertheless, it seems that vertices are always _referred to_ by number, that is, by the position of the vertex expression in `VertexList[gr]`. This can be confusing. For example, if I build a graph like this, using nonconsecutive vertex numbers,               Graph[1<->2, 2<->10, 10<->3, 3<->4]      then I still have to refer to the vertices as if I had made each vertex number equal to its creation order, as if I had built the graph with strictly consecutive vertex numbers:               Graph[1<->2, 2<-3 ,3<->4, 4<->1]       Am I understanding this correctly?


Splitting a string into substrings of length 1 and 2

There is already a thread on how to split a string into equal sized chunks. I'm wanting to split a string into sets of substrings of length 1 and 2. For example, if I have the string "123456", my list would include elements such as {12,3,4,56}, {1,2,3,45,6}, and {1,2,34,56}. I found this little bit of Python code, but 1) I don't know how to translate it into Mathematica code and 2) it gives you strings with a bunch of extra commas (because it's basically just distributing n commas through the string in different ways). I suspect there is a very simple way of doing this in Mathematica.


How to plot small values

I wonder, why small values (eg. 10^-1600) would not show on a plot? Here is a small example, where Evaluate gives a list of very small values and Plot does not show them, starting from x=20.               testfunc[x_] := 10^(-16 x)      testvalues = {x -> {10, 20, 30, 40, 50, 60, 70, 80, 100}};     Evaluate[testfunc[x]] /. testvalues     LogPlot[Evaluate[testfunc[x]], {x, 1, 100}, AxesOrigin -> {0, 10^-1600}]      ![enter image description here](http://i.stack.imgur.com/D9jkY.jpg) I guess it has something to do with precision, but I could not find any solution for Plot function yet and would appreciate any help. Had no luck with SetPrecision/WorkingPrecision.


ShearingTransform and Dynamic

Background: I have a geometric transformation composed of a `RotationTransform`, `ScalingTransform` and `ShearingTransform`, I can use dynamic constructs with rotations and scalings but this does not (seem to) work with the `ShearingTransform`. Consider the following snippet:                 DynamicModule[{shr, deg = 30},        shr0 = ShearingTransform[deg Degree, {1, 0}, {0, 1}];        shr1 = Dynamic[ShearingTransform[deg Degree, {1, 0}, {0, 1}]];        shr2 = ShearingTransform[Dynamic[deg Degree], {1, 0}, {0, 1}];       Column[{          Slider[Dynamic[deg], {0, 90, 1}],          GeometricTransformation[{Blue,            Rectangle[{0, 0}, {3, 1}]},           shr0] // Graphics}        ]]      Note that the snippet does not work (as expected) : moving the slider does not change the angle of the shear. See `shr1` and `shr2` for alternatives I have already tried. **Question: How can I make the angle in a`ShearingTransform` dynamic, such that it works in the context of the snippet above?**


Calculate deviation of sum of several equal normal distribution

I have a normal distribution with mean m and standard deviation d. How can I calculate what will be the deviation if I add N such distributions? As I understand, mean will be m*N. Will standard deviation be d*N? P.S. It looks like I should be using standard variances vs standard deviation. Sum of Gauss(Mean1, Standard Variance1) + Gauss(Mean2, Standard Variance2) = Gauss (Mean1 + Mean2, Standard Variance1 + Standard Variance 2). This way standard variance for N will be v*N, which mean that d=sqrt(N)*d


ParallelTable: explicitly assign iterator values to kernels

I've a construct that reads               ParallelTable[      MyFunction[i],      {i, 16}     ]      Now, MyFunction[i] takes an amount of time to be evaluated which is a decreasing function of i. When I evaluate with multiple kernels however, mathematica assigns close values of i to the same kernels. In this example it has assigned i=1,2 to kernel 8 and i=3,4 to kernel 7, and this is of course not optimized at all. Out of 8 cores I get a speedup of only 2.49 which is quite unsatisfactory, due to the fact that a huge part of the work was made by 2 kernels leaving the other 6 with a relatively low load. ![Parallel Kernel Status screenshot at the end of the evaluation](http://i.stack.imgur.com/W99Vv.png) Is there a way to explicitly assign values of i to the kernels?


How can I replace bi-directional DirectedEdge pairs in a Graph with a single UndirectedEdge?

The Cayley graphs produced by Mathematica 8.0's `CayleyGraph` function represent actions that are their own inverses in an unconventional way: rather than using a single edge without arrows, it uses two edges, each represented by an arrow. Is there a way to replace all (and only) pairs of such reflexive arrows in a Cayley diagram with a single undirected edge, while leaving any unpaired directed edges untouched? For example is there a way to make edges in this               CayleyGraph[DihedralGroup[4]]      ![enter image description here](http://i.stack.imgur.com/Flv2n.png) look like this ![enter image description here](http://i.stack.imgur.com/WCzz6.png) * * * Note that I'm aware that one could generate the desired output "manually", using `Graph` (as was done to generate the example above), but the solution I'm seeking must work for _far_ more complex graphs than the one illustrated here from the simple group specifications that can be provided to `CayleyGraph`.


Why can't Mathematica "Solve" my equation?

I am trying to get Mathematica to solve the following equality in terms of $w_i$ $\displaystyle \frac{\sum_{i = 1}^{n} x_i }{\sum_{i = 1}^{n} y_i} = \frac{\sum_{i = 1}^{n} ( (\frac{x_i}{y_i}) w_i ) }{n} $ (Background: http://math.stackexchange.com/questions/137332/relationship- between-ratios-and-averages-of-ratios) But it's telling me "This system cannot be solved with the methods available to Solve." Now, I'm guessing this is because I haven't given Mathematica enough information about my assumptions (specifically, that $w_i$ is expressible as a function of $x_i$ and $y_i$, or something similar) What am I doing wrong here, and how would I go about using Mathematica to solve equalities like these?               Solve[Sum[Subscript[x, i],           {i, 1, n}]/         Sum[Subscript[y, i],           {i, 1, n}] ==         Sum[(Subscript[x, i]/            Subscript[y, i])*           Subscript[w, i],           {i, 1, n}]/n,        Subscript[w, i]]      PS.) I realize my title stinks... I blame myself for not even knowing enough about what my problem is to give this question a cogent title. If someone could Edit the question and give it a real title and/or suggest one, I'd be appreciative.


How to find the position of elements in a list satisfying criteria

Say I have a list `x={2,4,6,8,10}` and I want to find out the positions of the elements that are greater than 7. `Select[x, #>7&]` gives the elements themselves, and `Position[x,8]` gives the position of the elements satisfying one of the possible criteria, but what I am looking for would be a mix of the two returning `{4,5}`. Any suggestions?


How to avoid spaces between numbers when displaying TagBox(es)

The instruction : `DisplayForm[RowBox[List[0,1,Superscript[2,3],Superscript[1,2],a]]]` displays a gap between the first two items of the list ![enter image description here](http://i.stack.imgur.com/YKZkx.png) but if one is careful not to have two consecutive integers, there is no gap `DisplayForm[RowBox[List[0,a,1,Superscript[2,3],Superscript[1,2],a]]]` ![enter image description here](http://i.stack.imgur.com/DQA6S.png) I would like to know if there is a way to disable (locally) the space inserted by Mathematica between two integers in this case to have something like that: ![enter image description here](http://i.stack.imgur.com/VLFny.png) I would like the result to stay a TagBox or InterpretationBox, easy to copy/paste, if possible.


Transparent textures don't show

> **EDIT** For now, I'm going to accept Brett's answer. It's a way to get > transparency back by having 3D calculations done in software instead of > hardware. It addresses the symptoms but not the causes. As I wrote above, my > PC and graphics card are provably able to do it, but there's something in > the interaction with MMA that disables it after restarts. Anyone who solves > this gets the Accept check. * * * > **Edit** I got conformations from several users with the following hardware: > >   * Simon Woods: Windows 7 64 bit, with an NVidia GTX 550 Ti graphics card. >   * texasAUtiger: Windows 7, 64 bit on Intel on Intel iCore i7-2760QM 2.4 > ghz, NVidia NVS 4200M graphics card > * * * I have this problem where several of the examples in the doc page of `Texture` don't work.               data = Table[{1, 0, 0, a}, {u, 0, 1, 1/100}, {a, 0, 1, 1/100}];          vtc = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};     coords = {{{0, 0, 0}, {0, 1, 0}, {1, 1, 0}, {1, 0, 0}}, {{0, 0,           0}, {1, 0, 0}, {1, 0, 1}, {0, 0, 1}}, {{1, 0, 0}, {1, 1, 0}, {1,           1, 1}, {1, 0, 1}}, {{1, 1, 0}, {0, 1, 0}, {0, 1, 1}, {1, 1,           1}}, {{0, 1, 0}, {0, 0, 0}, {0, 0, 1}, {0, 1, 1}}, {{0, 0,           1}, {1, 0, 1}, {1, 1, 1}, {0, 1, 1}}};          Graphics3D[{Texture[data],        Polygon[coords, VertexTextureCoordinates -> Table[vtc, {6}]]},       Lighting -> "Neutral", Boxed -> False]      is supposed to give: ![Mathematica graphics](http://i.stack.imgur.com/yz9oS.png) but I get this: ![Mathematica graphics](http://i.stack.imgur.com/0Auig.png)               data1 = Table[{1, 2/3, 0, If[u^2 + v^2 < 1/2, 0, 1]}, {u, -1, 1,          1/100}, {v, -1, 1, 1/100}];     data2 = Table[{0, 0, 1, If[u^2 + v^2 < 1/2, 0, 1]}, {u, -1, 1,          1/100}, {v, -1, 1, 1/100}];      Additionally,               Graphics3D[{FaceForm[Texture[data1], Texture[data2]],        Polygon[coords, VertexTextureCoordinates -> Table[vtc, {6}]]},       Lighting -> "Neutral", Boxed -> False]      should yield: ![Mathematica graphics](http://i.stack.imgur.com/55K26.png) but I get the empty cube again. Then there's the example in the `Scope>Texture styling` section of the doc page which is supposed to result in: ![enter image description here](http://i.stack.imgur.com/V73Wc.gif) In my case I get: ![Mathematica graphics](http://i.stack.imgur.com/2F8j2.png). This is not a general transparency issue as               Plot3D[x^4 + y^4 - 5 x^2*y^2, {x, -3, 3}, {y, -3, 3},       PlotStyle -> Opacity[0.8], Mesh -> None]      gives me this: ![Mathematica graphics](http://i.stack.imgur.com/lK9So.png) I'm using a 1 year old Dell XPS-15 (model L501 X)Running Windows 7-64 with an nVidia GeForce GT 435M graphics card, driver version 8.17.12.6639. I reported this earlier on Mathgroup and got the advice to update my drivers which I did and it sure helped. However this is not the end of the story as the behavior returned soon afterwards. I have updated the driver various times using both nVidia's and Dell's newest version and it always was a short-lived solution. Last time I tested it, I installed the _same_ version of the driver over the existing one and the transparent textures showed up as intended in my notebook even without re- executing the code, only to disappear after MMA's next restart. So, apparently my system is able to handle transparent textures but there is some interaction between MMA and the driver that causes this ability to be switched off. **Update** This issue seems to have been resolved in Mathematica 9. All of the above mentioned problems did not reappear when I tested them in the trial version of V9.


Copy last/second last (etc.) input from history into current cell

I like to use terminals (e.g. `gnome-terminal`) where you can use the up key to copy the last command into the current input 'field'. For example, to repeat the last command you just have to press `up`, `enter`. Or, to modify the last input and re-run, it is just `up`, modify, `enter`. As beginner I often make mistakes, or experiment by slightly changing previous inputs. Is there any way in which I can obtain this convenient input behavior in the _Mathematica_ front end?


Difference In Eigenvectors

When running my program in both Mathematica and MathCad, I end up with the same eigenvalues, but different eigenvectors. The ones in MathCad are normalized, which the documentation for Mathematica says they too are normalized. I also tried `Normalize[]` and they still differed. Any advice for how to change it so that they match up? EDIT:: Code               {{0. + 0. I, -0.00105652 + 0.00306633 I, -0.000992072 - 0.000550179 I,        0. + 0. I, 0. + 0. I, 0. + 0. I, 0. + 0. I, 0. + 0. I, 0. + 0. I,        0. + 0. I, 0. + 0. I, -0.00080248 - 0.000276499 I,        3.94975*10^-6 - 7.12212*10^-6 I,        0.0000192495 + 6.63251*10^-6 I, -7.8995*10^-6 +         0.0000142442 I, -2.53122*10^-6 - 2.0506*10^-6 I, 0. + 0. I,        0. + 0. I, 0. + 0. I, 0. + 0. I, 0. + 0. I,        0. + 0. I}, {0.00119848 - 0.00323969 I,        0. + 0. I, -0.00089753 + 0.00242618 I, -0.000743608 - 0.000434551 I,        0. + 0. I, 0. + 0. I, 0. + 0. I, 0. + 0. I, 0. + 0. I, 0. + 0. I,        0. + 0. I, -1.5511*10^-6 + 8.53409*10^-6 I, -0.000868186 -         0.000321173 I, 8.75277*10^-6 - 0.0000149778 I,        0.0000203377 + 7.52365*10^-6 I, -8.75277*10^-6 +         0.0000149778 I, -2.64607*10^-6 - 2.24413*10^-6 I, 0. + 0. I,        0. + 0. I, 0. + 0. I, 0. + 0. I,        0. + 0. I}, {-0.00124465 - 0.00025056 I, 0.000991057 - 0.00253121 I,        0. + 0. I, -0.000658751 + 0.00168248 I, -0.000461387 -         0.000281434 I, 0. + 0. I, 0. + 0. I, 0. + 0. I, 0. + 0. I,        0. + 0. I, 0. + 0. I,        0.0000212182 + 8.30765*10^-6 I, -3.59755*10^-6 +         0.0000178707 I, -0.000909167 - 0.00035597 I,        9.49275*10^-6 - 0.0000155626 I,        0.0000212182 + 8.30765*10^-6 I, -9.49275*10^-6 +         0.0000155626 I, -2.73555*10^-6 - 2.41019*10^-6 I, 0. + 0. I,        0. + 0. I, 0. + 0. I,        0. + 0. I}, {0. + 0. I, -0.000915438 - 0.000197309 I,        0.000705296 - 0.00173145 I,        0. + 0. I, -0.00034951 + 0.000858025 I, -0.000154043 -         0.0000968679 I, 0. + 0. I, 0. + 0. I, 0. + 0. I, 0. + 0. I,        0. + 0. I, 3.97422*10^-6 - 0.0000184388 I,        0.0000218358 + 8.89464*10^-6 I, -3.97422*10^-6 +         0.0000184388 I, -0.000935629 - 0.000381122 I,        0.000010041 - 0.0000159676 I,        0.0000218358 + 8.89464*10^-6 I, -0.000010041 +         0.0000159676 I, -2.79628*10^-6 - 2.53224*10^-6 I, 0. + 0. I,        0. + 0. I, 0. + 0. I}, {0. + 0. I,        0. + 0. I, -0.000555325 - 0.000123831 I,        0.000361803 - 0.000870433 I, 0. + 0. I,        6.4961*10^-6 - 0.0000156284 I, 0.000167434 + 0.000106958 I,        0. + 0. I, 0. + 0. I, 0. + 0. I,        0. + 0. I, -3.83436*10^-6 - 1.7215*10^-7 I,        4.17683*10^-6 - 0.0000187311 I,        0.0000221515 + 9.20749*10^-6 I, -4.17683*10^-6 +         0.0000187311 I, -0.000949159 - 0.000394527 I,        0.0000103313 - 0.0000161729 I,        0.0000221515 + 9.20749*10^-6 I, -0.0000103313 +         0.0000161729 I, -2.82664*10^-6 - 2.59656*10^-6 I, 0. + 0. I,        0. + 0. I}, {0. + 0. I, 0. + 0. I,        0. + 0. I, -0.000180652 - 0.0000402588 I, -6.49204*10^-6 +         0.0000156244 I, 0. + 0. I, 0.000374561 - 0.000901456 I,        0.00049078 + 0.000313423 I, 0. + 0. I, 0. + 0. I, 0. + 0. I,        0. + 0. I, -3.83319*10^-6 - 1.71599*10^-7 I,        4.17309*10^-6 - 0.0000187258 I,        0.0000221458 + 9.20173*10^-6 I, -4.17309*10^-6 +         0.0000187258 I, -0.000948914 - 0.00039428 I,        0.000010326 - 0.0000161692 I,        0.0000221458 + 9.20173*10^-6 I, -0.000010326 +         0.0000161692 I, -2.82609*10^-6 - 2.59538*10^-6 I,        0. + 0. I}, {0. + 0. I, 0. + 0. I, 0. + 0. I, 0. + 0. I,        0.000190732 + 0.0000410344 I, -0.000361392 + 0.000888151 I,        0. + 0. I, 0.000716521 - 0.00176091 I, 0.00080346 + 0.000504823 I,        0. + 0. I, 0. + 0. I, 0. + 0. I,        0. + 0. I, -3.76634*10^-6 - 1.40845*10^-7 I,        3.96361*10^-6 - 0.0000184233 I,        0.0000218189 + 8.87822*10^-6 I, -3.96361*10^-6 +         0.0000184233 I, -0.000934908 - 0.000380418 I,        0.0000100257 - 0.0000159566 I,        0.0000218189 + 8.87822*10^-6 I, -0.0000100257 +         0.0000159566 I, -2.79465*10^-6 - 2.52885*10^-6 I}, {0. + 0. I,        0. + 0. I, 0. + 0. I, 0. + 0. I, 0. + 0. I,        0.000541679 + 0.000108715 I, -0.00066847 + 0.00171026 I, 0. + 0. I,        0.000999783 - 0.00255791 I, 0.00109362 + 0.000666203 I, 0. + 0. I,        0. + 0. I, 0. + 0. I, 0. + 0. I, -3.63939*10^-6 - 8.56735*10^-8 I,        3.58173*10^-6 - 0.0000178461 I,        0.0000211913 + 8.28283*10^-6 I, -3.58173*10^-6 +         0.0000178461 I, -0.000908015 - 0.000354907 I,        9.46946*10^-6 - 0.0000155449 I,        0.0000211913 + 8.28283*10^-6 I, -9.46946*10^-6 +         0.0000155449 I}, {0. + 0. I, 0. + 0. I, 0. + 0. I, 0. + 0. I,        0. + 0. I, 0. + 0. I,        0.000857822 + 0.000155255 I, -0.000904508 + 0.00245062 I, 0. + 0. I,        0.00120425 - 0.00326273 I, 0.00135116 + 0.000788249 I, 0. + 0. I,        0. + 0. I, 0. + 0. I, 0. + 0. I, -3.46257*10^-6 - 1.56372*10^-8 I,        3.08334*10^-6 - 0.0000170362 I,        0.0000203025 + 7.49351*10^-6 I, -3.08334*10^-6 +         0.0000170362 I, -0.000869931 - 0.000321086 I,        8.72413*10^-6 - 0.0000149543 I,        0.0000203025 + 7.49351*10^-6 I}, {0. + 0. I, 0. + 0. I, 0. + 0. I,        0. + 0. I, 0. + 0. I, 0. + 0. I, 0. + 0. I,        0.00112915 + 0.000178104 I, -0.00106069 + 0.00308684 I, 0. + 0. I,        0.0013247 - 0.00385516 I, 0. + 0. I, 0. + 0. I, 0. + 0. I,        0. + 0. I, 0. + 0. I, -3.24913*10^-6 + 5.87823*10^-8 I,        2.53158*10^-6 - 0.0000160499 I,        0.0000192081 + 6.60019*10^-6 I, -2.53158*10^-6 +         0.0000160499 I, -0.000819963 - 0.000281752 I,        3.93415*10^-6 - 7.10805*10^-6 I}, {0. + 0. I, 0. + 0. I, 0. + 0. I,        0. + 0. I, 0. + 0. I, 0. + 0. I, 0. + 0. I, 0. + 0. I,        0.00135075 + 0.000179137 I, -0.00114114 + 0.00360727 I, 0. + 0. I,        0. + 0. I, 0. + 0. I, 0. + 0. I, 0. + 0. I, 0. + 0. I,        0. + 0. I, -3.01338*10^-6 + 1.28696*10^-7 I,        1.98264*10^-6 - 0.0000149497 I,        0.0000179729 + 5.68564*10^-6 I, -9.91319*10^-7 +         7.47487*10^-6 I, -0.000749264 - 0.000237026 I}, {1, 0, 0, 0, 0, 0,        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 0, 0, 0, 0,        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 1, 0, 0, 0,        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 0,        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 1, 0,        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 1,        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0,        1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0,        0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0,        0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0,        0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0,        0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}      I will work on getting the MathCad, but the first few values of the 19th eigenvector should be -.001048-.001033i, -.002461-.00404i...


What BarChart Option controls Joined line thickness?

Is there a named option that controls the thickness of the line segments that appear in `BarChart` with options `ChartLayout -> "Stacked"`, `Joined->True`? It is not `EdgeForm`, since `ChartBaseStyle -> EdgeForm[None]` is the value set in the following example: ![enter image description here](http://i.stack.imgur.com/IgZwH.png) It's unclear what `Directive` can be passed. Changing `Thickness` value in `ChartBaseStyle -> {Thickness[0.0001], EdgeForm[None]}` has no effect for example.


Skipping over iterator values in a Table

I have been using the built-in function `Table` for some computations. (The following is not an actual representation of the equations I am using). $$\text{Table}[f[k]=g[k],\{k,1,10\}]$$ However, the assignment $f[k]=g[k]$ is not true for one $k$ value, say $k=6$. That is, say, $g[k]=k^2+1$ for $k\neq 6$ and $g[6]=1$ (when $k=6$). I can then break the table into two parts: $\{k,1,5\}$ and $\{k,7,10\}$. Is there any other (more efficient) way of doing this?


Testing the convergence when solving an integral equation

I am trying to find the solution of an integral equation such that a certain convergence criterion is fulfilled. Now the problem is that the function doesn't look like what I am actually expecting, in the sense that I have solved the equation also with a normal iteration, and there I get the "expected" (physical) result, but there I don't know how to implement the convergence criterion, at least not in an elegant way. The other problem I have is that the integration actually goes from 0 to 1, but since _Mathematica_ spits errors when I use 1 as the upper limit of integration, I have to replace 1 with 0.999.... Is there a better way to do this? Here the code               α = 2.85;     g = (Pi/2) α;     Nf := 2;          cs[x_] := 2 ArcCos[x]/Sqrt[1 - x^2];     csh[x_] := 2 ArcCosh[x]/Sqrt[x^2 - 1];     prefB[p_, k_, d_] :=      (p^2 + k^2 (1 - 1/d^2))/Sqrt[p^2 d^4 - 1/4 ((p^2 + k^2) d^2/k - k )^2];     pieceB[k_, d_] :=        If[d B[k]/k^2 < 1, cs[d B[k]/k^2], If[d B[k]/k^2 > 1, csh[d B[k]/k^2], 2]];          B[p_] = p^2 ;     iterstep :=      (values =      Parallelize[     Table[{p, p^2 +  g/(Pi^3  Nf) (NIntegrate[             prefB[p, k, d] ((d^2 B[k]^2/k^4 - 1) (Pi - g pieceB[k, d]) +                 B[k ]/k^2 d  g^2 csh[g])/(d^2 B[k]^2/k^4 + g^2 - 1),             {d, 0, 1/(1 + p)}, {k, p d/(d + 1), p d/(1 - d)},             WorkingPrecision -> 16,             PrecisionGoal -> 2,             MaxRecursion -> 100,            AccuracyGoal -> 16,             Method -> {"SymbolicPreprocessing", "OscillatorySelection" -> False}] +            NIntegrate[            prefB[p, k, d] ((d^2 B[k]^2/k^4 - 1) (Pi - g pieceB[k, d]) +                 B[k ]/k^2 d  g^2 csh[g])/(d^2 B[k]^2/k^4 + g^2 -1),             {d, 1/(1 - p), Infinity},             {k, p d/(d + 1), p d/(d - 1)},              WorkingPrecision -> 16, PrecisionGoal -> 2,             MaxRecursion -> 100, AccuracyGoal -> 16,            Method -> {"SymbolicPreprocessing","OscillatorySelection" -> False}])},             {p, 0, 0.99999, 1/20}]];          B[p_] = Interpolation[values , p, InterpolationOrder -> 4,   Method -> "Hermite"])               Do[iterstep, {3}] // AbsoluteTiming      The last code works relatively ok (although it gets extremely slow), but the problem is that I have no good control over convergence. Is there a way to tell the Do loop to stop when a certain convergence criterion is reached? Also, the problem with the upper integration limit still remains...


Combining graphics

# Original question I would like to put a coloured grid behind the following plot: ![enter image description here](http://i.stack.imgur.com/VdZAQ.gif) which was generated by:               a = Table[x, {x, 1, 10}];     b = Table[10 x, {x, 1, 10}];     ListLinePlot[{Table[x^2, {x, 1, 10}]}, InterpolationOrder -> 0,     PlotRange -> {{0, 10}, {0, 100}}, GridLines -> {a, b}, GridLinesStyle ->        Directive[GrayLevel[0.8], Dashed], AspectRatio -> 1]      so that I could shade certain squares of the grid so it looks something like: ![enter image description here](http://i.stack.imgur.com/QDrgu.png) for example. # Update1 Using Kuba's code below, it is fairly straightforward to overlay an x^2 shaded plot with an x^3 ListLinePlot using the following code:               data = Table[{x, x^2}, {x, 0, 10}];     ceiling = {#, Ceiling[#2 + 1, 10]} & @@@ data;     floor = {#, Floor[#2, 10]} & @@@ data;     a = Table[x, {x, 1, 10}];     b = Table[10 x, {x, 1, 10}];     c = ListLinePlot[{Table[x^3, {x, 1, 10}]}, InterpolationOrder -> 0,      PlotRange -> {{0, 10}, {0, 100}}, GridLines -> {a, b},      GridLinesStyle -> Directive[GrayLevel[0.8], Dashed],      AspectRatio -> 1, PlotStyle -> {Thick}];     Show[ListPlot[{data, ceiling, floor}, InterpolationOrder -> 0,      Joined -> True, AspectRatio -> 1, Filling -> (2 -> {3}),      GridLines -> {Range[10], Range[0, 100, 10]},      GridLinesStyle -> Directive[GrayLevel[0.8], Dashed],      PlotStyle -> {None, None, None}], c]      which generates: ![enter image description here](http://i.stack.imgur.com/Eyq4T.gif) without too much fiddling. Is there a similarly straightforward way of showing a shaded x^3 plot & ListLinePlot x^2 without running into problems with the dimensions of the grid (without fiddling around with the dimensions each time)? # Update2 Thanks to Kuba's code: ![enter image description here](http://i.stack.imgur.com/4UP8e.gif) with:               lineData[f_, max_, min_: 0] := Table[{x, f[x]}, {x, min, max}];     shadeData[f_, max_, min_: 0] :=      Transpose[{{#, Ceiling[#2 + 1, 10]}, {#, Floor[#2, 10]}} & @@@      Table[{x, f[x]}, {x, min, max}]]          With[{stdOpt = {InterpolationOrder -> 0,      GridLines -> {Range[10], Range[0, 300, 10]},      GridLinesStyle -> Directive[GrayLevel[0.8], Dashed],      Joined -> True, AspectRatio -> 1}},      ListPlot[{lineData[#^2 &, 10], ##} & @@ shadeData[#^3 &, 10],      Filling -> (2 -> {3}), PlotStyle -> {Thick, None, None}, stdOpt,      PlotRange -> {{0, 10}, {0, 100}},          Epilog -> {Red, Opacity[0.5], Rectangle[{1, 10}, {2, 20}], Blue,      Opacity[0.5], Rectangle[{2, 40}, {3, 50}]}          ]]      # Update3 Having some fun with it: ![enter image description here](http://i.stack.imgur.com/CmM4i.gif) with:               shadeData[f_, max_, min_: 0] :=      Transpose@Table[{{x, Ceiling[f[x] + If[FractionalPart[f[x]] == 0.5, 0.5, 0], 1]},     {x, Floor[f[x], 1]}}, {x, min, max}]          Animate[Quiet[With[{stdOpt = {InterpolationOrder -> 0, GridLines -> {Range[-10, 28,     1], Range[-10, 14]}, GridLinesStyle -> Directive[GrayLevel[0.8], Dashed],      Joined -> True, AspectRatio -> 0.25}}, ListPlot[shadeData[(Sin[# + n])*10 &, 28],      Filling -> (2 -> {1}), FillingStyle -> Directive[Opacity[0.5], Orange],      PlotStyle -> {None, None, None}, stdOpt, Axes -> False, Frame -> False,      ImageSize -> 600, PlotRange -> {{0, 24}, {-10, 10}}]]], {n, 0, 2 \[Pi]},      AnimationDirection -> Forward, AnimationRate -> 0.5]      and ![enter image description here](http://i.stack.imgur.com/Gyd6Y.gif) ...etc :)


Transfer of symbols between contexts

As many others (I guess) I'm struggling with the handling of contexts within Mathematica. I'm working on a new package definition with the usual syntaxt specified by the Mathematica documentation:               BeginPackage["example`"];          <Entry Points>          Begin["`Private`"]          <Definitions>          End[];          EndPackage[];      Now I want to use symbols generated in another Notebook and saved with DumpSave for efficiency. The code in this other Notebook is thus               DumpSave[<some mx file>,{symbol1,symbol2,...,symboln}]      when I import these symbols into my package it looks like this:               BeginPackage["example`"];          <Entry Points>          Begin["`Private`"]          DumpGet[<some mx file>];     <Definitions>          End[];          EndPackage[];      there is already the catch: The Symbols are not automatically loaded into the private context of the package (which is example`Private` in the above code snippet) but into the original context of the Notebook where the mx file has been generated (which is Global` in my case)! Thus I need to convert the symbols either into the private context in the package definition (which would the following statements               example`Private`symbol1=Global`symbol1;     example`Private`symbol2=Global`symbol2;     .     .     .     example`Private`symboln=Global`symboln;     Remove[Global`symbol1,Global`symbol2,...,Global`symboln])      or save the symbols already into the right context by using               example`Private`symbol1=symbol1;     example`Private`symbol2=symbol2;     .     .     .     example`Private`symboln=symboln;     DumpSave[<some mx file>,{example`Private`symbol1, example`Private`symbol2,        ..., example`Private`symboln}]      in the generating Notebook (which would be my preferred solution). I need to do all of this clumsy setup because I do not want to have the symbols in the Global` context because then the symbols are visible outside of the package, which is not necessary and may cause shadowing problems too. Now my question: Is there a quick way to copy symbols over from one context into another? Something like               Set[Evaluate[example`Private`#],Global`#]&/@{symbol1,symbol2,...,symboln}      would be preferrable. However above statement does not work... Any ideas?


Running out of memory when filtering a large data set

My goal is to read `list0.dat`, filter the data with a function `f`, and then write the transformed data to `list1.dat`, as in the following:               input = <<list0.dat;     output = Map[f[#]&, input];     output >> list1.dat;      However, `input` and `output` are both very large lists. (The format is just the usual anlytical expression.) So "No more memory available" always appears. How can I deal with this problem? I need some suggestions for memory control and how to export the transformed data to an external file in real time.


How can I get Mathematica to recognize the documentation for a newly installed package?

To install a new package on one's machine, one first downloads and unpacks the package into the `$BaseDirectory/Applications` directory. The tutorial Installing NewAddons of Version 5.2 then recommends one go to Menu > Help and click on the Rebuild Help Index menu item. However, the tutorial was written for the version 5.2. S0 now I cannot find the Rebuild Help Index item under the Menu > Help. What should I do instead in version 9.0.1.0?


Error with minimization of NProbability

I'm trying to solve the following problem:               Minimize[{NProbability[(1 - 2 g)*y + g^.5 + s <      x, {x, y} \[Distributed] UniformDistribution[{{0, 1}, {0, 1}}]], 0 < g < 1 && 0 < s < 1}, {g, s}]      This code gives an error message from NIntegrate (`NIntegrate::izero`) Any ideas why the error message? How can I solve the problem? If I run a contour plot of the objective over the constrained area I get something that looks well behaved:               ContourPlot[NProbability[(1 - 2 g)*y + g^.5 + s < x, {x, y} \[Distributed] UniformDistribution[{{0, 1}, {0, 1}}]], {g, 0, 1}, {s, 0, 1}]      ![enter image description here](http://i.stack.imgur.com/wnvNX.jpg)


workbench: how to see values of global variables during debugging

Consdier the following package               BeginPackage["packageName`"];        exportedFunction::usage = "...";        Begin["`Private`"];           globalVariable = Null;           initializePackage[args___] := (globalVariable = workOn1[args]);           exportedFunction[args___] :=               Block[{localVariable},                 If[globalVariable===Null, Abort[]];                 localVariable = workOn2[globalVariable, args];                 workOn3[localVariable]              ];           workOn1[args___] := ...;           workOn2[gv_, args___] := ...;           workOn3[lv_] := ...;        End[];     EndPackage[];      and assume that is being debugged in a workbench session, and that a break point has been set somewhere in exportedFunction. The debugger reports on the values of localVariable, but I can never see the value of globalVariable. Is there a way to inspect the value of globalVariable as well?


Problem with exporting a plot with a legend to PDF

I've found a simple example that illustrates my problem:               ContourPlot[x^2 - 1 == y, {x, -1, 1}, {y, -1, 1}, PlotLegends -> "Expressions"]      When I try to export this to PDF, I get the following: ![Contour plot with legend and bug](http://i.stack.imgur.com/AmdpK.png) and in the legend, the expression is misspaced and unreadable. Is this a known bug? Is there a known work around?


How do I create a function pointer typedef using SymbolicC

I am just getting started with the SymbolicC package, and am trying to figure out how to handle function pointer typedefs, like, say:               typedef double (*rhs)(double, double);      The problem is that the `CTypedef` function expects its arguments to be `CTypedef[type, var]`, which isn't really how function pointer declarationss in C work. An ordinary pointer typedef is done using `CDereference`, as:               CTypedef["double", CDereference["xp"]]      I'm not sure how to make that work in the context of `CFunction`.


Conditional options in Plot

I was hoping to incorporate an `If` function into a `Plot` option, as in               Plot[Sin[t], {t, 0, 2 Pi}, Filling -> Axis,       FillingStyle -> If[Sin[t] > 0, LightGreen, LightRed]]      or               Plot[Sin[t], {t, 0, 2 Pi}, PlotStyle -> If[Sin[t] > 0, Dashed, Thick]]      to no avail. Is it possible to pass an `If` to the plot options? I know that I can manually accomplish the effect via `Piecewise`, but I have more complicated applications in mind where I would not want to manually precompute the interval(s) on which my piecewise defined function would need to be defined.


How to evaluate all the essentially distinct polynomials in 4 variables over $F_2$ on points of $F_2 ^ 4$

I am a beginner with _Mathematica_. For my research purpose I would like to get a list of all the polynomials in $F_2[x,y,z,w]$ and for each polynomial I would like to know the result that it gives then it is applied on each point on $F_2 ^ 4$. More concretely, F_2={0,1}.Take 2 variables x and y. Consider all possible polynomials, where degree of both x and y are less than or equal to 1.you have usual multiplication and addition modulo 2.(that means whatever you get by adding or multiplying elements of F_2 take the remainder when divided by 2). The desired answer would be like, Polynomials (0,0) (0, 1) (1,0) (1,1)                x         0     0     1     1       likewise consider all other polynomials with the property given above and I would like to get a table of what values the polynomial takes at the given point, like I have mentioned for the polynomial x. Any help will be appreciated.


Why does Thread FileDate give an error message?

I tried for example               Thread[FileDate[FileNames["new*", "h:\\temp\\", 1]]]      It gives > FileDate::fstr: File specification > {h:\temp\NEWEA7D.tmp,h:\temp\NEWEA7E.tmp,h:\temp\NEWEAAE.tmp} is not a > string of one or more characters. >> but still gives the right answer               Out[13]= {{2013, 11, 18, 23, 14, 32.}, {2013, 11, 18, 23, 14,        32.}, {2013, 11, 18, 23, 14, 32.}}      Why is there a error message? How to avoid it?


Why do I see the error "only assignments to symbols are allowed" when using a Module and not otherwise?

When I type               Remove["Global`*"]     foo[] := Module[{Subscript[a, 1] = "x"}, 0];      foo[]      I get the expected error "only assignments to symbols are allowed". I understand the error. ![enter image description here](http://i.stack.imgur.com/CWYl1.png) But why I do not get the same error when I type the same assignment in the notebook?               Remove["Global`*"]     Subscript[a, 1] = "x"      No error and no beep. ![enter image description here](http://i.stack.imgur.com/R2jXs.png) What is the difference? I'm using version 8.04 on Windows. * * * ## Update The non-localized trick shown by Szabolcs answer worked for me on a demo. Here is a screen shot of the result. What I was trying to do is to typeset some information about a solver, some matrix equation, and I thought why not take advantage of `MatrixForm` and `Grid`'s nice way of typesetting things, and display the information right there in the demo screen as an option? This is easier than putting it in the text section below where it can hard to get to as I have so many such things. Here is an example of the code and the result. You can see I did not localized these symbols in the module which builds this expression. I just started trying this idea, but so far I am happy that it worked. This below is only an example, not cleaned up, just wanted to see if the demo will work. ![enter image description here](http://i.stack.imgur.com/dqwg6.png)


Resume/continue interrupted evaluation

I interrupted an evaluation to quickly do something else. How do I resume the interrupted evaluation? I cannot open the "Interrupt evaluation" window, as it is disabled. There is no "Resume" button to press...


Different results for integration using Mathematica and MATLAB

I have the following integration: $$\text{y}=2 \sqrt{\frac{1}{\pi }} \int_0^{\infty } \frac{e^{-z} \left(1-e^{-\frac{z}{b}} \left(\frac{a}{a+c z}\right)^L\right)}{\sqrt{z}} \, dz$$ I get different results when I use _Mathematica_ and MATLAB. The _Mathematica_ code is:               L=2;     sn=1;     a=10^(0.1*sn);     b=10^(0.1*sn);     c=0.01*a;     result = 2*Sqrt[1/Pi]*       Integrate[        (1/(E^z*Sqrt[z]))*(1 - (a/(a + c*z))^L/E^(z/b)),         {z, 0, Infinity}       ]      which gives me `2.37664*10^66`, whereas MATLAB's result is `0.51515243`. What is the reason for this discrepancy?


The value of an option inside a native function

I'm looking for something similar to `AbsoluteOptions` but that can be evaluated inside the function. That is, I want to read the absolute settings of options specified in the current context. For example, instead of:               AbsoluteOptions[      Plot[       Sin[x]       , {x, 0, 2 Pi}       , PlotRange -> Automatic       ]      , PlotRange]      > {PlotRange -> {{0., 6.28319}, {-1., 1.}}} I would like to have something like               Plot[      Sin[x]      , {x, 0, 2 Pi}      , PlotRange -> Automatic      , Epilog -> Inset[        "PlotRange is " <> ToString@AbsoluteOptions[PlotRange]        , {4, 1}]      ]      > ![Mathematica graphics](http://i.stack.imgur.com/mt4I6.png) is it possible to read the absolute settings for options associated with the current function environment?


Are there suitable versioning systems for Mathematica notebooks?

I am considering a project using _Mathematica_ and openCL. I know that the openCL C source code can be tracked. Has anyone used a versioning site or software so multiple developers can modify a common notebook? Is it possible to:   * check out a notebook non-exclusively?   * check out a notebook exclusively?   * change the notebook?   * merge a notebook locally?   * check in a notebook?


How can you compute Itō Integrals with Mathematica? I tried searching through the documentations but I didn't find anything. P.S. I was not at all sure how to tag this question. I had to put in at least one tag, and I do not have enough reputation to create a new one. Somebody with more rep can feel free to tag it appropriately.


Creating ordered triplets from an Excel sheet

I have an Excel sheet of the form:                   " "  a  b  c          1   R  S  T          2   U  V  W          3   X  Y  Z      Where every entry is a number (except the blank quotes, which is just a blank cell). These are supposed to be `{x,y,z}` coords but Mathematica imports them as `{" ",a,b,c},{1,R,S,T},...`. I get that I need to transpose them but I'm not sure how. Essentially for this example the end result should be `{a,1,R},{b,1,S},{c,1,T},{a,2,U}...`. This is similar but without the extra lines which is kind of the issue I'm having: Import Excel sheet into 3D array?


How to "ignore" an element of Map or MapIndexed

Say I have some function that I'm applying every element in a list to... if that element matches some criteria:               If[#==<condition>,{#}, <Do nothing> ] & /@ LongList      Is there a way to do something like this? I want the result to just not have that element.


Is there any way to stop calculation of unimodular matrix in HermiteDecomposition

I want to calculate Hermite normal form of a matrix. But I do not want the unimodular transformation matrix. Is there any way to stop the calculation of unimodular matrix? HermiteDecomposition function return both matrices. The reason I want to stop calculation of unimodular matrix is I think It will save some memory and computation also may little faster. My matrix size is around (45000 * 3000) Any comment appreciated.


Export to mat file does not work

I use this command from the _Mathematica_ documentation center               Export["1.mat", {"t" -> {{1,2,3}},"u" -> {{4,5,6}}}, "LabeledData"]      to save data as mat file with two variables `t` and `u`, and it does not work. The file is empty! The command `Export["1.mat",{{1,2,3}}]` works fine. How to solve this problem? I'd like to save in single file plenty variables. I am using Mathematica 7.


Adding a circle to an already existing drawing

With reference to my earlier post: Adding a point to an already existing graphic I would like to add an outer circle to the whole drawing. This outer circle is a fixed one of `radius 40`. Something like this is helpful:               Graphics[Circle[{0, 0}, 40]]      But I do not know exactly where to put it in my code so that it remain a fixed circle in the background. Thanks a lot...


Splitting words into specific fragments

I am looking into splitting words into a succession of chemical elements symbols, where possible. For example: > Titanic = Ti Ta Ni C _(titanium, tantalum, nickel, carbon)_ A word may or may not be decomposable under those rules, and if it is the decomposition might not be unique. I did two things: the first is a function checking if a decomposition is possible. I relied on the trivial regular expression to do so:               elements = ToLowerCase /@        Select[Table[ElementData[i, "Symbol"], {i, Length@ElementData[]}], StringLength[#] < 3 &]     regexp = RegularExpression["(" <> StringJoin@Riffle[elements, "|"] <> ")+"];     decomposable[s_] := StringMatchQ[ToLowerCase@s, regexp];     decomposable /@ {"Mathematica", "archbishop"}      which gives: `{False, True}`. Slightly harder was to implement a function returning possible decompositions. I recently learnt of the existence of `Sow` and `Reap` via this very website, so I implemented the most naïve, greedy algorithm with a recursive function:               beginsWith[s_, sub_] := (StringTake[s, Min[StringLength[s], StringLength[sub]]] == sub);     decompose0[s_, pre_] := Module[{list, remains},        If[StringLength[s] == 0, Sow[pre]];        list = Select[elements, beginsWith[s, #] &];        remains = StringDrop[s, StringLength[#]] & /@ list;        If[Length[list] >= 1, decompose0[remains[[1]], pre <> " " <> list[[1]]]];        If[Length[list] >= 2, decompose0[remains[[2]], pre <> " " <> list[[2]]]];      ];     decompose[s_] := Reap[decompose0[ToLowerCase@s, ""]][[2, 1]];      This works nicely:               In:= decompose["archbishop"]     Out= {" ar c h b i s h o p", " ar c h b i s ho p", " ar c h bi s h o p", " ar c h bi s ho p"}     In:= decompose["titanic"]     Out= {" ti ta n i c", " ti ta ni c"}      So, the question is: **in which way could I use Mathematica’s higher-level functions, e.g. the pattern-matching ones, to improve the algorithm or the code simplicity?** I'm not into code-golfing, so it's not about making the code shorter, but about using a better-optimized algorithm or writing higher- level code. (The above I could pretty much have written in C, C++ or Fortran, my usual languages.)


Computing intersections between a large number of sets: doing it sequentially vs. sending everything to Intersection[...]

Say we want to compute the largest common subset among a very large number of sets $Q_i$. One option would be to simply run the command:               Intersection[Q1, Q2, Q3, Q4, Q5, Q6, Q7, ...];      However, this seems to choke for very large numbers of input sets ($10^4$ or so with on-order $10^2$ elements each). Another option would be compute `Q12 = Intersection[Q1,Q2]`, then `Q123 = Intersection[Q12,Q3]`, then `Q1234 = Intersection[Q123,Q4]`, and so forth. Are these two procedures equivalent? Is there a better way?


How do you get Weisstein’s Hyphenate package to run?

I've put Eric Weisstein's `Hyphenate.m` package in `$UserBaseDirectory/Utilities`; installed the requisite `texhyphj` files in my local `texmf` tree; run its `Makefile` to create the Java classes corresponding to the distributed `.java` source files; and in `Hyphenate.m` set `$HyphenPath` to the path for `texhyphj`. Yet when I load the package, I get a Java `ClassNotFoundException` error for the Java class `net.davidashen.text.Hyphenator`. What am I doing wrong or also need to do to get this add-on package to work? (The package provides a functions that hyphenate a given string and list the syllables of a string.) P.S. Yes, `WordData[word, "Hyphenation"]`will give a list of syllables for `word`, but I would expect using Java for this may be quicker, since no delay is involved in going out to the WRI server to import the needed word data paclets.


Efficiently evaluating a held expression directly from a list

I am able to evaluate a held expression that I have put on a list by:               ReleaseHold[expressionList[[1]]]      and               expression1 := ReleaseHold[expressionList[[1]]];     expression1      Using `expression1` is more efficient than `ReleaseHold[expressionList[[1]]]`, but I loose the ability to use it in `Map` (or so I think). I would like to be able to use the held expression directly from a list, i.e. `expressionList[[1]]` . Any suggestions? A test harness follows. You can change the expressions being tested see `AddExpression[1];`, which is currently `1` to `Pause[$TimeUnit]`, `Range[1, 1000]`, ... . * * *               SetAttributes[AddExpression, HoldAll];     AddExpression[expression_] := AppendTo[expressionList, Hold[expression]];          EvaluateExpressions[] :=      (       expression1 := ReleaseHold[expressionList[[1]]];       expression2 := ReleaseHold[expressionList[[2]]];            totalRunTimeDo = AbsoluteTiming[          Do[(expression1; expression2;), {iterations}];          ][[1]];            Print["Do      total: ", totalRunTimeDo, "   per iteration: ",         totalRunTimeDo/ iterations];            (* -------------------------------------------------*)            totalRunTimeDoMap = AbsoluteTiming[          Do[Map[ReleaseHold[#] &, expressionList], {iterations}];          ][[1]];            Print["DoMap   total: ", totalRunTimeDoMap, "   per iteration: ",         totalRunTimeDoMap/ iterations];       )          iterations = 10000000;     expressionList = {};     AddExpression[1];     AddExpression[1];     EvaluateExpressions[];      Results:               Do      total: 12.526729   per iteration: 1.2526729*10^-6     DoMap   total: 19.018290   per iteration: 1.9018290*10^-6      Obviously, you can see why I want to pull it directly from the list. ## Background The above test harness was boiled down from something I was using to benchmark code.               iterations = 10000000;     expressionList = {Hold[1], Hold[1]};      I started here:               expressionTimingsByIteration =       Map[Map[AbsoluteTiming[ReleaseHold[#]][[1]] &, expressionList] &,        Range[1, iterations]];     iterationsTimingsByExpression = Transpose[expressionTimingsByIteration];      Refactored to this:               iterationsTimingsByExpression =       Map[        (          expression := ReleaseHold[#];          Map[AbsoluteTiming[expression][[1]] &, Range[1, iterations]]           ) &        , expressionList];      However evaluating code whose `AbsoluteTiming < $TimeUnit` is prone to error. Which I refactored for those cases to:               totalTimingByExpression =       Map[        (          expression := ReleaseHold[#];          AbsoluteTiming[Do[expression, {iterations}]][[1]]          ) &, expressionList];     totalTimingByExpression


Find exact limit of recurrence relation $x_{n+1}=\cos(x_n)+1, x_0=1$

I did this:               b[x_] := Cos[b[x - 1]] + 1; b[0] = 1;     num = SequenceLimit[N[Table[b[n], {n, 1, 100}], 50]]      I also did the listplot which shows a convergent value. ![the recurrence relation](http://i.stack.imgur.com/4IOtd.jpg) Both results suggests that SequenceLimit did the right thing. The limit is 1.2834287895560837995226068447. Is there a way to find the exact value of convergent recurrence relation? Or find the limit without repeated calculation ?


Find set of subgraphs of g1 isomorphic to g2

I would like to find all the subgraphs of a given graph g that are isomorphic to the graph h. My current code doesn't work how it should. Many solutions are missed and I think something is fundamentally wrong with my approach.   * I generate g and h.    * Extract the subsets from g with the same length as h.    * Select the subsets that are isomorphic to h    * Generate subgraphs and highlight them in g .               {g, h} = {Graph[RandomInteger[#] \[UndirectedEdge] # + 1 & /@ Range[1, 4]],      Graph[{{1, 2}, {2, 3}, {3, 4}}]}     s = Subsets[Range[VertexCount[g]], {VertexCount[h]}];     Select[Subgraph[g, #] & /@ s, IsomorphicGraphQ[#, h] &];     HighlightGraph[g, #] & /@ %


Simplifying already defined symbols

Consider the following code:               ClearAll[x, y]     x = y;     y = 2;     ?x     ?y      This will store $x$ being equal to _the variable $y$_ , and $y$ having _the value of $2$_. Now switch the assignment lines:               ClearAll[x, y]     y = 2;     x = y;     ?x     ?y      the internal representation will be $x=2$, $y=2$, since at the time of the assignment $x=y$, _the value of $y$_ is known and used for the assignment, not the variable $y$ itself, as it has been in the first case. Now consider the case where I've built up a long code with complicated expressions being substituted into each other, and at some final point I would like to boil this down as much as possible. Stated differently: _How would I make sure $x$ is updated to the value of $y$ in the first example instead of still referring to $y$?_


Efficient method for Inserting arrays into arrays

This is strongly related to the following Questions:   * Looking for a way to insert multiple elements into multiple positions simultaneously in a list   * Building matrices by attaching vectors (columns) and matrices   * What is the most efficient way to add rows and columns to a matrix? I am looking for an efficient method to insert an array into an array. Let’s assume that both arrays have similar number of rows. Let’s further assume insertion is by column.               a = {{a1, b1, c1, d1, e1}, {a2, b2, c2, d2, e2}, {a3, b3, c3, d3, e3}}; (*example may be larger*)     b = {{x1, y1, z1}, {x2, y2, z2}, {x3, y3, z3}}; (*example may be larger*)      **Q1:** What is the fastest method to insert **b** into **a** at a position _p_. Let’s assume that both arrays have similar number of rows. Let’s further assume insertion is by column. My current method is as follows:               insertarray[a_, b_, pos_] :=     FlattenAt[     Transpose@Insert[Transpose@a, b[[##]], pos ] & [Range[Length@a]],      Table[{i, pos}, {i, 1, Length@a}]];      which allows me to do ![insert array](http://i.stack.imgur.com/P2gWj.png) **Q2** : Some times I have to intersperse columns of **b** into **a** at multiple positions. How do I best extend **insertarray** so that:               insertarray[a,b,{1,2,5}]//MatrixForm      ![enter image description here](http://i.stack.imgur.com/7YjEQ.png)


Pasting $\LaTeX$ into a Mathematica notebook

I have read that $\LaTeX$ source can be directly pasted into a Mathematica notebook. However, I have been unsuccessful in this regard. An example of the errors received are:               $\frac{1}{2}$     Syntax::sntxb: Expression cannot begin with "$ frac{1}{2}$".     Syntax::tsntxi: "$ frac" is incomplete; more input is needed.     Syntax::sntxi: Incomplete expression; more input is needed .      This is not remediated by removal of the `$` signs, placement of two `$` signs (`$$`), or use of other $\LaTeX$ math mode delimiters (e.g., `\\[ \\]`, `\begin{displaymath}\end{displaymath}`, `\begin{equation}\end{equation}`, etc). I do not wish to import an entire `.tex` file as I merely want to pass a few select equations. Please advise as to my error. Thank you. **Edit:** I am using Mathematica 8.0.1.0.


MapThread with List Manupulation

I have the following three lists:               kr = {{8, 8, 19, 3, 3}, {8, 8, 21, 3, 3}, {8, 8, 23, 3, 3}};     Rk = {{8., 3, 4, 5, 6}, {8., 4, 5, 6, 7}, {8., 5, 6, 7, 8}};     qsum = {{320, 270, 120, 140, 170}, {320, 280, 120, 150, 190}, {320, 290, 120, 160, 210}};       When I use               MapThread[#1 + #2 + #3 &, {Take[#, {3, -2}] & /@ kr, Take[#, {4, -1}] & /@ Rk, Take[#, {3, -2}] & /@ qsum}]      It shows the output {{144., 149.}, {147., 160.}, {150., 171.}} which is perfectly fine, but using the function `floExct` in the `MapThread` as               floExct[n_, ku_, qr_] := Min[100*ku, (2500*n) - qr];     MapThread[ floExct[#1, #2, #3] &, {Take[#, {3, -2}] & /@ kr, Take[#, {4, -1}] & /@ Rk, Take[#, {3, -2}] & /@ qsum}]      gives me               {500., 600., 700.}      instead of the format               {{a,b},{c,d},{e,f}};      What am I missing?


How do I use wildcard characters with StringTake?

Say I'd like to pick substrings from some string such that these substrings have the pattern `@@@q@@@`, where `@` is used here as a stand-in for a 'wildcard' character (i.e. any character) and `q` is just an example of a specific character that can be specified as desired. The kind of lame solution might be as follows:               substringList = StringTake[testString, # + {-3, 3} & /@ StringPosition[testString, "q"]];      This, of course, runs into trouble when `q` appears near one of the two ends of `testString`. What's the correct way to do this?


Find eigenvalues without filling the matrix

Is it possible to find eigenvalues of a matrix without filling it? The matrix elements are given by a known function `f[p1,p2]`. This is relevant for a matrix too large to fit in a memory. Of course, a custom implementation of the Arnoldi algorithm would allow one to do so. I wonder whether it is possible with built-in functions like `Eigenvalues[]` and some clever rules.


Dual complex integral over implicit path using contour plot

**Context** I am interested in doing double contour integral over paths which are defined implicitely. For the sake of debugging, let's assume its $$\oint_{\cal C}\oint_{\cal C} \frac{1}{u\, x} d u d x$$ where $\cal C$ is defined implicitly as the zero of a function (here for instance $x^4+y^4- x y/2=0$). I would like to make use of the `Contour` function of mathematica to extract the contour path for me.   (The motivation is to implement the so called "saddle point method" in the complex plane while integrating over contours of null imaginary part of some given function) **Question** > How to extract smooth enough contours to not mess up the double complex > integral? **Attempt** I first extract the path               pl = ContourPlot[x^4 + y^4 - 1/2 x y == 1, {x, -2, 2}, {y, -2, 2}, PlotPoints -> 25];     dat = Cases[pl // Normal, Line[a_] :> a, Infinity][[1]] // Chop // Rest // Transpose;     dat = GaussianFilter[#, 0] & /@ dat;nn = Length[dat[[1]]];rg = (Range[nn] - 1.)/(nn - 1);     dat = Transpose /@ Partition[Riffle[{rg, rg}, dat], 2];     path = Interpolation[#, InterpolationOrder -> 1] & /@ dat;     path = Function[t, path[[1]][t] + I path[[2]][t] // Release];      (ignore the `GaussianFilter` for now) which looks like this               {ParametricPlot[path[t] // {Re[#], Im[#]} & // Release, {t, 0, 1},ImageSize -> 200],     Plot[path[t] // {Re[#], Im[#]} & // Release, {t, 0, 1}, ImageSize -> 200]} // Row      ![Mathematica graphics](http://i.stack.imgur.com/JBrT1.png) For reference let us also define an explicit (circular) path               path0[t_] = Exp[2 Pi I t];      Let's now start with a simple contour integration in the complex plane, using `NContourIntegrate` defined by                  NContourIntegrate[f_, par : (z_ -> g_), {t_, a_, b_}, opts : OptionsPattern[]] :=         NIntegrate[Evaluate[D[g, t] (f /. par) /. t -> t1], {t1, a, b},opts]      :               NContourIntegrate[1/x, x -> path0[t], {t, 0, 1}, PrecisionGoal -> 3] // Chop     NContourIntegrate[1/x, x -> path[t], {t, 0, 1}, PrecisionGoal -> 3] // Chop          (* 0. +6.28319 I -0.00291648-6.27423 I *)      (the negative $2\pi\imath$ reflects a wrong orientation of the implicit path which is not relevant to my problem). Now moving on to double integration, first with the explicit path (where I divide the answer by the expected answer $(2 \imath \pi)^2$)                Clear[h]; h[u_?NumberQ] := NContourIntegrate[1/x/u, x -> path0[t], {t, 0, 1}, PrecisionGoal -> 3];      NContourIntegrate[h[u], u -> path0[t], {t, 0, 1},PrecisionGoal -> 3]/(2 I Pi)^2 // Chop           (* 1.*)      and finally for the implicit path               Clear[h]; h[u_?NumberQ] := NContourIntegrate[1/x/u, x -> path[t], {t, 0, 1}, PrecisionGoal -> 3];     NContourIntegrate[h[u], u -> path[t], {t, 0, 1}, PrecisionGoal -> 3]/(2 I Pi)^2 // Chop           (* 1.53254 +0.00796458 I *)      which is a terrible answer! Now in the code above I replace the useless command `dat = GaussianFilter[#, 0] & /@ dat;` by               dat = GaussianFilter[#, 4] & /@ dat;      I get                (* 1.00097 +0.00168785 I *)      which is better. I strongly suspect that the problem lies with the contour extraction which produces dat containing duplicates such as {{-1., 0} {-1., 0} {-1., 0} {-1., 0} {-0.990251, 0.0735841} {-0.988311, 0.0833333} {-0.987415, 0.0959183}} which in turn as suppressed by the Gaussian filtering. Indeed, while the contour itself seems unaffected, its components in red and pink are less jaggy: ![Mathematica graphics](http://i.stack.imgur.com/0orp5.png) and this apparently small amount of noise (and/or duplicates) mess up completely the integral. > Is it possible to tweak the `ContourPlot` routine or its output to avoid > duplicates and get good accuracy on this type of integrals? **EDIT** The improvement involved with the `GaussianFilter` is actually critical because if I extend this problem to a triple integral, $$\oint_{\cal C}\oint_{\cal C}\oint_{\cal C} \frac{1}{u \,v\, x } d u d v d x$$ via               Clear[h1]; h1[u_?NumberQ, v_?NumberQ] := NContourIntegrate[1/(x u v), x -> path[t], {t, 0, 1}];     Clear[h2]; h2[v_?NumberQ] := NContourIntegrate[h1[u, v], u -> path[t], {t, 0, 1}]     NContourIntegrate[h2[v], v -> path[t], {t, 0, 1}]/( 2I Pi)^3      I get               (* -0.975052-0.00767858 I *)       compared to               (* -2.91536 -0.040382 I *)      without! **EDIT 2** To be more specific about the core of the problem, this curve is too jaggy:               pl = ContourPlot[x^4 + y^4 - 1/2 x y == 1, {x, -2, 2}, {y, -2, 2}, PlotPoints -> 25];     dat = Cases[pl // Normal, Line[a_] :> a, Infinity][[1]] // Chop // Rest // Transpose;     dat = GaussianFilter[#, 0.] & /@ dat;nn = Length[dat[[1]]];rg = (Range[nn] - 1.)/(nn - 1);     dat = Transpose /@ Partition[Riffle[{rg, rg}, dat], 2];dat[[1]] // ListLinePlot      ![Mathematica graphics](http://i.stack.imgur.com/ikJhA.png) I can make it less jaggy by changing the option to `PlotPoints -> 125` but it actually makes the contour integration worse!


Mathematica style (drawing cubes)

I wanted to draw (lattice-aligned) unit cubes inside a sphere with a given radius centered on the origin, so I wrote this program:               Cube[x_, y_, z_] := Cuboid[{x - 1, y - 1, z - 1}, {x, y, z}];     Coords[r_] := {#1, #2, Floor[Sqrt[r^2 - #1^2 - #2^2]]} & @@ # & /@         With[{t = Sqrt[r^2 - 1]},          Select[Flatten[Table[{x, y}, {x, 1, t}, {y, 1, x}], 1],           Norm[#] <= t &]];     Cubes[r_] :=        Cube @@ # & /@         Union[Flatten[Permute[#, SymmetricGroup[3]] & /@ Coords[r], 1]];     Draw[r_] :=        Graphics3D[        Union[Cubes[r], {{Green, Opacity[0.1], Sphere[{0, 0, 0}, r]}}],         PlotRange -> {{0, r}, {0, r}, {0, r}},         ViewPoint -> {r, 3 r/4, 3 r/5}];     Draw /@ Sqrt /@ {50, 100, 250, 500, 1000, 2500, 6054}      (Note that it shows only the cubes on the outside -- drawing the inner ones takes too long and usually Mathematica runs out of memory.) It gets the job done, but it's pretty ugly. I'm not a regular Mathematica user, and tips for improving my code? That is, how can I write idiomatically-better Mathematica code? * * * Improved code:               Coords[r_] := {#1, #2, Floor[Sqrt[r^2 - #1^2 - #2^2]]} & @@@         With[{t = Sqrt[r^2 - 1]},          Select[Join @@ Table[{x, y}, {x, t}, {y, 1, x}], Norm[#] <= t &]];     Cubes[r_] := (Cuboid /@ (Union @@ (Permute[#, SymmetricGroup[3]] & /@               Coords[r]) - 1));     Draw[r_] :=        Graphics3D[        Union[Cubes[r], {{Green, Opacity[0.1], Sphere[{0, 0, 0}, r]}}],         PlotRange -> {{0, r}, {0, r}, {0, r}},         ViewPoint -> {r, 3 r/4, 3 r/5}];     Draw /@ Sqrt /@ {50, 100, 250}


Fourier transformation of HeavisideTheta functions

I want to find 2D-Fourier transformation of the function given below               f = HeavisideTheta[y1]*HeavisideTheta[y2 - y1]      For the purpose, I use built-in function in two ways as below,               FourierTransform[f, {y2, y1}, {q2, q1}]      FourierTransform[f, {y1, y2}, {q1, q2}]       The outputs are different depending on the order of variables. Please, See below. > >     -(1/(2 π q1 q2 + 2 π q2^2)) + (I DiracDelta[q2])/(2 q1) + >     (I DiracDelta[q1 + q2])/(2 q2) + 1/2 π DiracDelta[q2] DiracDelta[q1 + > q2] >   >     -(1/(2 π q1 q2 + 2 π q2^2)) + (I DiracDelta[q2])/(2 q1) - (I > DiracDelta[q1 + q2])/(2 q1) >   I thought they should be same. I don't know why they are different. Please help me to figure out which one is correct.


My plot is cut off if a frametick is "0" but resized if a frametick is "0." Why?

I have been trying to customize the frame ticks and frame label around a certain contour plot and am running into very strange behavior where the graphics will get cut off by `ImageSize` rather than being resized. In the following example code (more or less minimal), note that all I have changed is a `0` to `0.` in the frametick specification. What's going on here? Minimal example:               ContourPlot[θ1 + θ2 == 0, {θ1, -3 π/2, π/2}, {θ2, -π/2, 3 π/2},      FrameTicks -> {{{0, π}, None}, {{-π, 0.}, None}},       FrameLabel -> {"\!\(\*SubscriptBox[\(θ\), \(1\)]\)", "\!\(\*SubscriptBox[\(θ\), \(2\)]\)"},       BaseStyle -> {FontSize -> 20}, ImageSize -> 200]          ContourPlot[θ1 + θ2 == 0, {θ1, -3 π/2, π/2}, {θ2, -π/2, 3 π/2},      FrameTicks -> {{{0, π}, None}, {{-π, 0}, None}},       FrameLabel -> {"\!\(\*SubscriptBox[\(θ\), \(1\)]\)", "\!\(\*SubscriptBox[\(θ\), \(2\)]\)"},       BaseStyle -> {FontSize -> 20}, ImageSize -> 200]      ![input and output](http://i.stack.imgur.com/gue4h.png)


List of dangerous functions

_I no longer believe it is a good idea to work with a list of dangerous functions. I have tried to edit the question is such a way that it respects my earlier perspective, but also so that it does not give users the impression that certain things are safe whereas they are not._ **Introduction** Running _Mathematica_ code from an untrusted source is very dangerous. Luckily, _Mathematica_ warns you about dynamic content, so that it is probably safe to open any notebook, as long as you don't run it. I feel it would be very nice to have a list of functions that can harm a system. Using this, we may be able to make a function that checks if a notebook is safe. **A function to find dangerous functions** A naive function to see if dangerous expressions are present in a `NotebookObject`, could be the following.               Through[{Unprotect, ClearAll}[dangerousFunctionsQ]]          dangerousFunctionsQ[nb_] := !         FreeQ[ToExpression[Unevaluated[#], StandardForm,             HoldComplete] & /@ (NotebookRead@Cells[nb])[[All, 1]],          Alternatives @@ listOfDangerousFunctions];          Protect[dangerousFunctionsQ];      Where `listOfDangerousFunctions` is given. Unfortunately, this code does not guarantee safety, even we know the full list of dangerous functions. Furthermore, getting the `NotebookObject` is a bit tricky. We could simply open the notebook and use `Notebooks`, but opening the notebook doesn't sound too safe. Also making an automated approach based on this is inelegant. Note however, that using the obvious alternative, which is to use `Import` (with one argument) on the notebook file turns out not to be safe. **The question is** : Which built-in functions are dangerous (especially just by themselves)? **Related** In a CDF can I suppress or avoid “This file contains potentially unsafe dynamic content…”


Multiplayer game in Mathematica: how to communicate between kernels?

This may have been asked already, but I am considering making a game in Mathematica that two people can play. However, the issue with my idea is that the other player can't view the cards of the first player. Does anyone have any suggestions as to how I would tackle this problem? I would use two different computers, both with Mathematica installed.


Plotting power spectral density from transfer function

I am new to signal processing. The equations below are given in $LaTeX$. I have the following transfer function (from the Dryden Model) for the two- sided Power Spectral Density: $$S(w) = \frac{\sigma_u ^2 \tau_u}{\pi} \frac{1}{1+(\tau_u w)^2}$$ I would like to plot the above as: Power Spectral Density, dB vs. w Any help on this would be appreciated. (please use any numerical values for $\sigma_u, \tau_u$) I also need to calculate the auto-correlation function by taking the inverse Fourier transform (call it `R(s)` ) of `S(w)`. Finally, I want to compute $$S1(w) = \int_{0}^{\infty} R(s) \cos (ws) ds$$ I would really appreciate someone's kindest help and advice in this regard. Thank you! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%               L := 50     Umc := 4.31     Su[\[Omega]_, \[Sigma]_, \[Tau]_] := (\[Sigma]^2 *\[Tau]/\[Pi] )*1/(1 \     + (\[Tau] *\[Omega])^2)     Sw[\[Omega]_, \[Sigma]_, \[Tau]_] := (\[Sigma]^2 *\[Tau]/(2*\[Pi] \     ))*(1 + 3*(\[Tau]* \[Omega])^2)/(1 + (\[Tau]*\[Omega])^2)^2          Ru[s_] := InverseFourierTransform[Su[\[Omega], 1, L/Umc], \[Omega], s]          S2 [\[Omega]_] := Integrate[Ru[s]*Cos[2*\[Omega]*s], {s, 0, Infinity}]          Plot[S2[\[Omega]] , {\[Omega], 0, 1}]


Color of first and last point in a graphic

I'm trying to make a graphic of a random walk in 1D, but i want that the first and the last point have a color (in this case the first one red and the last blue), but i dont know what i'm doing wrong.. This is my code:               RandomWalk[n_, d_] :=      NestList[(# + Table[Random[Real, {-1, 1}], {d}]) &, Table[0, {d}],      n];          OneDim = RandomWalk[5000, 1];          firstpoint = OneDim[[1]]          lastpoint = OneDim[[5001]]          ListPlot[{{Hue[0], PointSize[.02],      Point[firstpoint]}, {Hue[.7], PointSize[.02], Point[lastpoint]},      Line[OneDim]}]


How to replace While construct to NestWhile(functional-style) correctly?

Recently,I find the program of _@J.M._ about Get a "step by step" evaluation in Mathematica is a very useful example for learning _Mathematica_ programming. In the function **`WalkD`** ,I see the construct of **`While`** (it is common in procedural programming paradigm).I know _Mathematica_ 's functional programming paradigm is very elegent,so I'd like to use the function **`NestWhile`** to rewrite the the construct of **`While`**. ### Origin program:               WalkD[f_, x_] := Module[{derivative, oldderivative, k},          derivative = d[f, x]; displayStart[derivative];             (*First While construct*)         While[! FreeQ[derivative, d],             oldderivative = derivative; k = 0;                  (*Second while construct*)             While[oldderivative == derivative,                       k++;                       derivative = derivative /.                                ToExpression[StringReplace[$RuleNames[[k]], " " -> ""]]];             displayDerivative[derivative, k]];         D[f, x]]      ### My trial to rewrite the inner `While` construct               WalkDRewrite[f_, x_] :=      Module[       {derivative, oldderivative, k},        derivative = d[f, x];        displayStart[derivative];           While[! FreeQ[derivative, d],       oldderivative = derivative;       k = 0;           (*begin to rewrite*)      NestWhile[        CompoundExpression[#2++,          #1 = #1 /. ToExpression[StringReplace[$RuleNames[[k]], " " -> ""]]] &,        Sequence[derivative, k],        oldderivative != derivative      ]      (*end *)            displayDerivative[derivative, k]      ];      D[f, x]     ]      However,I failed after debugging all morning. ## Question: Is it possible to use `NestWhile` to replace `While`?Thanks sincerely!


Mapping multiple parameters of a function to specific values

I am a little bit confused by the documentation for `Apply` (`@@`). I want to define a list of parameters, for instance:               parameters = {{1/2, 1/2}, {1, 1/3}, {2, 1/4}, {0.5, 1/5}};      Then I have a function:               (b/a)*((a/x)^(b+1))      Now I want to map the pair (a,b) to the values defined in `parameters` and generate a plot for each pair of parameters in the same graph. Now the plot syntax would look something like this:               p = Plot[Evaluate[myfunction /@ parameters], {x, 0, 3},              AxesOrigin -> {0, 0}, AxesLabel -> {x, f}, PlotStyle -> styles]      What I struggle with, is getting the syntax right in the following part:               myfunction /@ parameters      How do I need to define this so I get a proper map of (a,b) to my list of parameters? To be honest, I am not very satisfied with the documentation for `Map`. Are there better tutorials?


How can I change InputField value dynamically

I am storing the values from xlData to the result in a `Grid` form. I want when I change any of the value in any of the `InputFields`, it should show the change dynamically when I evaluate result again. I have to use this result variable again in my code. How can I do this?                  result = {};           xlData = {{1, "a", "b", "c"}, {2, "d", "e", "f"}};        For[i = 1, i <= Length[xlData], i++,         (iniRow = {};          For[j = 1, j <= Length[xlData[[i]]], j++,           If[xlData[[i, j]] != "",                (iniRow =Append[iniRow,InputField[xlData[[i, j]], FieldSize -> {4, 1}]];           )]];                                 result = Append[result, iniRow];)]            Grid[result]


Automating Esc [[ Esc formatting?

Is it possible to program the Front End to automatically format double square brackets without having to type `Esc``[[``Esc` each time? It's awful to have to type `Esc` four times for each `Part` expression, and even more annoying to visually parse the unformatted double brackets. See also this entry in MathGroup archive: adding a keyboard shortcut for double brackets


Is it possible to make a variable wrapped in Dynamic non-dynamic?

If I have a function call wrapped in `Dynamic` can I make one or more of the parameters in the call non-dynamic? i.e. I would like to make `diskcx` and `diskcy` in the following snippet be unaffected by changes in their values after the call while making the output of `colorer` and the value of `rectangleCoordinates` dynamic: `...Graphics[ {Dynamic[colorer[ rectangleCoordinates, {radius + diskcx, diskcy}, .4 radius]], Disk[{radius + diskcx, diskcy}, .4 radius]....` Edit: As requested, here is the relatively large block of code the problem is concerned with. Of note is that: `rectangleCoordinates` refers to a set of rectangles that can pass over a disk to change its color;`colorer[rectangles_,center_,radius_]` is a function whose output is a color that depends on whether a rectangle passes over the disk defined by the center and radius that are given as parameters; the `radius` variable is defined outside the module; and of course as a precondition `amount_` is never greater than 5.                   diskGenerator[amount_, space_] :=          Module[{z = 1, listx, listy, positionx, positiony, diskcx, diskcy,          intervals = space/11, disks = {}},         listx = {1, 3, 5, 7, 9};         listy = {1, 2, 3, 7, 8, 9, 10};         For[z = 1, z <= amount, z++,           positionx = RandomChoice[listx];           positiony = RandomChoice[listy];           listx = DeleteCases[listx, positionx];           (*listy=DeleteCases[listy,positiony];*)           diskcx = positionx*intervals;           diskcy = positiony*intervals;           disks =            AppendTo[disks,                Graphics[{             Dynamic[colorer[rectangleCoordinates, {radius + diskcx, diskcy}, .4 radius]],              Disk[{radius + diskcx, diskcy}, .4 radius],                  Dynamic[colorer[rectangleCoordinates, {.5 radius + diskcx, Sqrt[3]/2 radius + diskcy}, .4 radius]],              Disk[{.5 radius + diskcx, Sqrt[3]/2 radius + diskcy}, .4 radius],                  Dynamic[colorer[rectangleCoordinates, {-.5 radius + diskcx, Sqrt[3]/2 radius + diskcy}, .4 radius]],              Disk[{-.5 radius + diskcx, Sqrt[3]/2 radius + diskcy}, .4 radius],                  Dynamic[colorer[rectangleCoordinates, {-radius + diskcx, diskcy}, .4 radius]],              Disk[{-radius + diskcx, diskcy}, .4 radius],                  Dynamic[colorer[rectangleCoordinates, {-.5 radius + diskcx, -(Sqrt[3]/2) radius + diskcy}, .4 radius]],              Disk[{-.5 radius + diskcx, -(Sqrt[3]/2) radius + diskcy}, .4 radius],                  Dynamic[colorer[rectangleCoordinates, {.5 radius + diskcx, -(Sqrt[3]/2) radius + diskcy}, .4 radius]],             Disk[{.5 radius + diskcx, -(Sqrt[3]/2) radius + diskcy}, .4 radius],                  Dynamic[colorer[rectangleCoordinates, {diskcx, diskcy}, .5 radius]],              Disk[{diskcx, diskcy}, .5 radius]           }]           ]         ];         Return[disks]         ];      I'm thinking I should just create a List of `diskcx` and `diskcy` values that the function would refer to just to avert the problem, but if this solution seems unsound I would be happy to read others. Thanks for your time, in any case.


Using Mathematica or WebMathematica to develop interactive, crowdsourced timeline visualizations

I aim to develop a series of timeline ZUI visualizations which will display a set of events similar to Wolfram's own Timeline of Computable Knowledge, but that can also handle crowdsourced uploading of events (and hyperlink to, say Wikipedia articles). In addition, I would like the layout to look more like the printed poster version of the Wolfram timeline (shown at the bottom of the page), which means developing a layout engine so that labels don't overlap. Could this project be developed as a CDF? With WebMathematica? Any pointers to documentation, tutorials or identification of other technologies (such as databases) to this end are appreciated.


Interpolating a function of two variables

I am trying to create the interpolating function for a function of two variables, over a finite area. Just for consistency we can think of a function:               MyFunc[a_,b_]:=Sin[a*b]/Sqrt[1+a^2+b^2]      I've read the documentation and, in order to get the interpolating function I use:               MyTable=Table[MyFunc[a,b],{a, -5, 5, 0.1}, {b, -5, 5, 0.1}]     MyApproximateFunc = ListInterpolation[MyTable]      this seem to work, but when I try to plot MyFunc and MyApproximateFunc they look very different: I must have missed some detail...               Plot3D[MyFunc[a, b], {a, -5, 5}, {b, -5, 5}]     Plot3D[MyApproximateFunc[a, b], {a, -5, 5}, {b, -5, 5}]      Thanks in advance for your kind help!


Is there a bug in the Part function of Mathematica 10?

I am using Mathematica 10 now. I typed code below               {{1, 2}, {2, 4}, {3, 6}, {4, 8}}[[;; , 1]][[1]]      and this gives result               1      But code               {{1, 2}, {2, 4}, {3, 6}, {4, 8}}[[;; , 1, 1]]      gives error > Part::partd: Part specification {{1,2},{2,4},{3,6},{4,8}}[[1;;All,1,1]] is > longer than depth of object. >> But according to help doc > expr[[i,j,...]]] or Part[expr,i,j,...]] is equivalent to expr[[i]][[j]]... What is wrong?!! I remember I always coded it like this in Mathematica 9, no error occurs. Is it a bug??


Difference between AbsoluteTiming and Timing

I need to evaluate the efficiency of my code. Therefore I would like to evaluate the time the code need for some calculations. Mathematica gives me two possibilities for this kind of evaluation: `AbsoluteTiming[expr]` > evaluates expr, returning a list of the absolute number of seconds in real > time that have elapsed, together with the result obtained. `Timing[expr]` > evaluates expr, and returns a list of the time in seconds used, together > with the result obtained. For both functions the Mathematica Documentation does not provide the section "Properties & Relations" which normally helps to find out the differences between two or more functions. Does anyone have an idea?


Flying to Australia

I want to compare different flight routes to Australia and their lengths. So far I have written:               departure =      Entity["City", {"BuenosAires", "BuenosAires", "Argentina"}];          destination =      Entity["City", {"Perth", "WesternAustralia", "Australia"}];          km =      ToString@QuantityMagnitude@Round@(GeoDistance[departure, destination]) <> " km";          GeoGraphics[      {       {Thick, Red, GeoPath[{departure, destination}]},       Style[Text[km, GeoPosition[destination]], Blue, 14, Bold]       },      GeoCenter -> destination,      GeoProjection -> "Mercator",      GeoRange -> "World",      ImageSize -> 400,      Frame -> True]      ![enter image description here](http://i.stack.imgur.com/g1ONM.jpg) My problem: To specify a city with Mathematica I have to include its federal state / administrative division, which, in many cases, I don' t know. So I have to google and manually input it. Since I want to automate the program for other cities the question is: How can I persuade Mathematica to tell me that Perth, Australia, is part of Western Australia and use this answer as automated input?


Why does Mathematice dislike my boundary condition in NDSolve?

im trying to solve a PDE-System, with the "periodic boundary condition"               c[t,0]==4*c[t,2pi]      But mathenmatica says: NDSolve::bcedge: "Boundary condition c[t,0]==4\ c[t,2\ [Pi]] is not specified on a single edge of the boundary of the computational domain." If i replace the 4 by 1 everything is fine. Anyone can explain this to me? And/or can tell me how/if mathematica can solve this? Thanks for reading!


How to enter a LaTeX integral?

How can I enter a LaTeX integral into _Mathematica_? For example, I evaluated the expression               ToExpression["\int 2*x\[DifferentialD]x ", TeXForm]      but _Mathematica_ told me that this is wrong.


Projecting Reference Lines in a SmoothHistogram3d Surface

What is the best way to draw a path (red color, dashed) along the surface of the smoothHistogram3D. Assume the paths desired to be the X=0 and Y=0 Axes.               data = {{0.798333, 1.21167}, {-0.415, 0.915}, {-0.675, 0.715}, {0.785,      0.675}, {-0.55, 0.645}, {-0.125, 0.57}, {0.15, 0.27}, {-0.3,      0.115}, {0.925, -0.685}, {0.748333, 1.27167}, {-0.465,     0.975}, {-0.725, 0.775}, {0.735, 0.735}, {-0.6, 0.705}, {-0.175,      0.63}, {0.1, 0.33}, {-0.35, 0.175}, {0.875, -0.625}, {0.628333,      1.18167}, {-0.585, 0.885}, {-0.845, 0.685}, {0.615, 0.645}, {-0.72,       0.615}, {-0.295, 0.54}, {-0.02, 0.24}, {-0.47,      0.085}, {0.755, -0.715}, {0.718333, 1.23167}, {-0.495,      0.935}, {-0.755, 0.735}, {0.705, 0.695}, {-0.63, 0.665}, {-0.205,     0.59}, {0.07, 0.29}, {-0.38, 0.135}, {0.845, -0.665}, {0.738333,      1.23167}, {-0.475, 0.935}, {-0.735, 0.735}, {0.725, 0.695}, {-0.61,      0.665}, {-0.185, 0.59}, {0.09, 0.29}, {-0.36,      0.135}, {0.865, -0.665}, {1.07833, 1.43167}, {-0.135,      1.135}, {-0.395, 0.935}, {1.065, 0.895}, {-0.27, 0.865}, {0.155,      0.79}, {0.43, 0.49}, {-0.02, 0.335}, {1.205, -0.465}};     SmoothHistogram3D[data]      ![enter image description here](http://i.stack.imgur.com/A4pdw.png)


How do I make data retrieved from Wolfram|Alpha persist in a notebook?

I want to store hourly temperature readings retrieved from Wolfram|Alpha in an array in my notebook. If this is not possible, then tell me how to preserve the retrieved data in my notebook, so when it is reopened, the previously retrieved data need not be reentered. Additional data entry should be limited to just the data required from the user. Thanks in advance.


Trying to plot ugly expression, not working

I have this ugly function :               A[x_]:=((2 x^3 + 9 x^2 + 27 x + 3 Sqrt[3] (3 x^4 + 14 x^3 + 27 x^2)^(1/2))/2)^(1/3)      (notice the fractional exponents at the end, it is indeed ugly) and it so happens that I want to plot the complex solutions               Abs[A[x] + (3x + x^2)/A[x] + x] == Abs[rho A[x] + rho^2 (3 z + z^2)/A[x] + x]      where rho is a cube root of unity (so we can just set it to `(-1 - I Sqrt[3])/2)`. This displays beautifully with ContourPlot and gives a picture of a curve (I actually have to replace x above by x+Iy and both x and y are in a [-3,3] range to see the picture). In theory, I am supposed to be able to simplify this equation to something a little simpler, i.e. giving something like this :               A[x] Conjugate[x] + Conjugate[(3x+x^2)/A[x]] x + Conjugate[A[x]] (3x + x^2)/A[x] ==      rho^2 Conjugate[A[x] Conjugate[x] + Conjugate[(3x+x^2)/A[x]] x + Conjugate[A[x]] (3x + x^2)/A[x]]      I have checked the details a thousand times ; getting from the above equation to the latter is just squaring the absolute values, using `|z|^2 = z Conjugate[z]` and expanding, it's really trivial math. But when I use ContourPlot to find the solutions to the latter equation, the curve doesn't show up. Any explanations on this?... Anything would be appreciated! From a wild guess to a very detailed attempt or even a suggestion/question.


Solving equations with QuantityVariable

I'm trying to understand how to easily solve equations that use `QuantityVariable`. Why does this fail?               Quantity["Speed of Light"] ==         QuantityVariable[ν, "Frequency"] (2 π)/QuantityVariable[k, "wavenumber"] /.           QuantityVariable[ν, "Frequency"] -> Quantity[2, "THz"]     // Solve      > Solve::units: Solve was unable to determine the units of quantities that > appear in the input. >> while this doesn't?               Solve[      QuantityVariable[k, "wavenumber"] == (2 π)/QuantityVariable[λ, "Wavelength"],       QuantityVariable[λ, "Wavelength"]]      > >     {{QuantityVariable[λ,"Wavelength"] -> (2 > π)/QuantityVariable[k,"wavenumber"]}} >   Nor does this,               Solve[ 3 10^8 == 2 10^12 (2 π)/k]      > >     {{k -> (40000 π)/3}} >   Notice that its not necessary to explicitly say which variable to solve in the last example as there is only one possibility, yet that fails if using `QuantityVariable`. The question is: Why does my first code fails?


Highlighting a single Period of a Trig Plot

How do I highlight a single period of a trig function say by using color and/or thickness when the graph itself extends further than just a single period? Thanks...Gregory Lane


How to rotate the z label in 3D plots

Let's take the following simple and funny case               S0 = ParametricPlot3D[{t*Sin[t], t*Cos[t], t}, {t, -100, 100},           BoxRatios -> {1, 1, 1}, AxesLabel -> {"x", "y", "a very long label"}, ImageSize -> 550]      which gives this ![plot](http://i.stack.imgur.com/O2rYB.jpg) We see, that the label of the z axes is printed horizontally by default, thus wasting a lot of space. In two-dimensional plots however, this can be easily fixed with the option `RotateLabel -> False`. Is there something similar for three-dimensional plots for rotating and printing vertically the z label? Many thanks in advance.


Finding Values of All Nine Constants in q-hypergeometric Equation

I suspect that an identity of the form $$\sum_{j=-n}^{j=n}(-1)^jq^{j(5j+1)/2}=\sum_{r=0}^{n}f_{ar+bn+c}(-1)^{n-r}q^{(n-r)(dr+en+f)/2}\frac{(q;q)_{gr+hn+j}}{(q;q)_{n-r}}$$ for $a, \dots , j$ integer constants, where $$f_N=\sum_{j=0}^{N}{N \brack j}q^{j^2}.$$ Here $(a;q)_n$ and $a \brack b$ denote the standard q-pochammer symbol and q binomial coefficient, resp. I turned to Mathematica for help in determining exactly what these integer constants must be. The bulk of my code is as follows:               f[n_] := Expand[Sum[FunctionExpand[QBinomial[n, j, q]]*q^(j^2), {j, 0, n}]]          lhs[n_] := Sum[(-1)^j*q^(j (5 j + 1)/2), {j, -n, n}]      The following implementation worked for 3 variables, but not for 6 variables:               rhs[n_, a_, b_, c_, d_, e_, f_] :=        Expand[Sum[f[r]*(-1)^{n - r}*q^{(n - r) (a*n + b*r + c)/2}*         FunctionExpand[QPochhammer[q, q, d*n + e*r + f]/QPochhammer[q, q, n - r]], {r,          0, n}]]          L[n_] :=        Do[         If[CoefficientList[lhs[n], q] == CoefficientList[rhs[n, a_, b_, c_, d_, e_, f_], q],          Print[{a, b, c}]], {a, t, -t + 1}, {b, t, -t + 1}, {c, t, -t + 1}, {d, 1, 3},          {e, 0, 3}, {f, 0, 3}]       It's also fairly sluggish in 3 variables. ### A New Approach Following George2079's suggestion, I now seek polynomials $g(r,n), h(r,n)$ in $q$ of fixed degree for which $$\sum_{j=-n}^{j=n}(-1)^jq^{j(5j+1)/2}=\sum_{r=0}^{n}f_{g(r,n)}\cdot h(r,n).$$ I am almost certain that such an $h(r,n)$ exists for all $n$ when $g(r,n)=ar+bn$. Then the following is a preliminary function on the assumption that $g(r,n)=r$, and finds something for $n\le8$:               Guess[n_] :=       Module[{maxr = Floor[Sqrt[n (5 n + 1)/2]], maxk = 20, mat, ns},        mat = Transpose[          PadRight[CoefficientList[#, q] & /@             Append[Flatten[Table[q^k*f[r], {r, 0, maxr}, {k, 0, maxk}]], lhs[n]]]];       ns = Select[NullSpace[mat], Last[#] =!= 0 &];       If[Length[ns] =!= 1, Throw["Error"]];       Return[((#.q^(Range[Length[#]] - 1)) & /@ Partition[Most[First[ns]], maxk + 1]).         Table[F[r], {r, 0, maxr}]];     ];          Guess[5]     (-1 + q^2 + q^3 + q^8 + q^9 - 3 q^10 - 8 q^11 + q^12 + 12 q^13 +      7 q^14 - 5 q^15 - 12 q^16 + 10 q^17 + 16 q^18 + 3 q^19 -      5 q^20) F[0] -      13 q^20 F[1] + (19 q^19 + 11 q^20) F[     2] + (-8 q^16 - 17 q^17 - 17 q^18 - 9 q^19 + 5 q^20) F[     3] + (9 q^14 + 18 q^15 + 18 q^16 + 8 q^17 + 5 q^18 - 2 q^19 -      10 q^20) F[     4] + (-9 q^12 - 11 q^13 - 9 q^14 - 8 q^15 + q^17 + 3 q^18 +      4 q^19 + 6 q^20) F[     5] + (5 q^10 + 3 q^11 + 2 q^12 + q^13 + q^14 - q^15 - 2 q^16 -      2 q^17 - q^18 - q^19 - q^20) F[6] + (-q^8 - q^9 + q^11 + q^16) F[     7]              Expand[% /. F -> f]     -1 + q^2 + q^3 - q^9 - q^11 + q^21 + q^24 - q^38 - q^42 + q^60 + q^65          tab = {}; ii = 1;     While[True, AppendTo[tab, Guess[ii]]; ii++; Print[ii]]     2     3     4     5     6     7     8      And one gets `Hold[Throw[Error]]`. Can someone produce an implementation that caters well to guessing what the general $h(r,n)$ might look like/be?


Unsatisfactory view of Panel, when transformed to pdf

I like very much to wrap Mathematica images by `Panel`, which gives many of them a much better view. To be precise, if image is some illustration, plot etc. I would like to put it in Mathematica document as `Panel@image` Then I typically mark the output as Figure in the JournalArticle StyleSheet. However, most of my documents should be later transformed into PDF for further use. This is unavoidable, since in my company nobody else uses Mathematica. In the PDF document version the panel loses most of its attractiveness. The gray color becomes almost white, and the fine rim details (which made the panel looking in Mathematica like a 3D-relief) disappear. In this form Panel makes the view worse, rather than improve it. To be more precise, here is an image wrapped by a panel: please execute the following in Mathematica notebook:               Panel[Import["ExampleData/rose.gif"]]      ![Mathematica graphics](http://i.stack.imgur.com/01qNy.png) As you see the panel looks a 3D relief. It does not exist any more in the PDF version of the file that you can see below. Besides, the panel color is much worse now. Have you any idea of what could be done to improve the `Panel` view after the document is transformed into PDF?


Alternatives to While Loops?

I am using Mathematica to run a probabilistic simulation. Essentially, I have a list of members of a population (they only have one, numerical, attribute, so it's just implemented as a list of numbers), and a function to move from one generation to the next, in a random manner. I need to iterate this function on my list until the list exceeds a given length, and then I want the number of iterations/generations is took to reach that length. My first instinct would be to use a While loop, but I know that using explicit loops in Mathematica is usually bad practice. Unfortunately, I haven't been able to find a better or more functional construction, and that's where I'm asking for help.


Axes/Frame Label as Log base 10

I am trying to label one of the frames on a ListPlot as log_10(x). When I try `ListPlot[twodimndata,Frame -> True, FrameLabel -> {Style[Log10[r], 20], Style[d, 20]}}` the output on the x-axis is `Log[r]/Log[10]`, rather than Log_10[r] as I expected How can I get Mathematica to plot Log_10[r] on the x-axis?


Switching the axis of a plot

I have a plot but the x and y axis need to be switched. The problem is that I can't explicitly solve for the other so I can change the axis.               e = .65;          Ec[M_] = M +        Sum[(1/2^(n - 1)*           Sum[((-1)^k*(n - 2*k)^(n - 1))/((n - k)!*k!)*             Sin[(n - 2*k)*M], {k, 0, Floor[n/2]}])*e^n, {n, 1, 3}]     Plot[Ec[M], {M, 0, 2 \[Pi]},       PlotRange -> {{0, 2 \[Pi]}, {0, 2 \[Pi]}}]      Basically, I want Ec to be on the x axis and M the y axis. As of right now, they are swapped.


Extracting Imported Information

What I want to do is to compare the relationship between the consumption of say beer and wine using scatter plots where each point designates the particular country (preferably named). I have tried to part the information - so that each particular column becomes a vector - using the function Part without any success. I find this bewildering given that `Dimension[data]` yields the result `{19,4}`. For those of you that are familiar with R: What I would like to do to is to part the information, like this                   > Country <-data$Country         > Beer <-data$Beer         > Wine <-data$Wine         > HardLiquid <-data$HardLiquid      and then produce scatter plots which names every country.               > plot(Beer,Wine,type="n")     > text(Beer,Wine,Country)      **Extra** This is the data that I am working on in _Mathematica_ :               data = {{"Country", "Beer", "Wine", "Hard Liquid"},       {"Sweden", 56., 16., 2.9},       {"Danmark", 98., 32., 2.7},       {"Finland", 79., 10., 5.7},       {"Norway", 56., 11., 2.4},       {"Belgium", 98., 30., 2.6},      {"France", 47., 41., 7.2},       {"Irland", 155., 13., 5.3},       {"Italy", 29., 54., 2.7},       {"Netherlands", 80., 20., 4.7},       {"Switzerland", 57., 42., 2.4},       {"Kingdom United", 20., 97., 3.9},       {"Germany", 26., 119., 5.3},       {"Austria", 36., 106., 3.2},       {"USA", 85., 7., 4.8},       {"Canada", 70., 10., 4.3},       {"Australia", 21., 89., 2.6},       {"Nya Zeeland", 19., 78., 2.3},       {"Japan", 55., 10., 8.2}}


DeleteDuplicates not deleting duplicates

It is not surprising that `DeleteDuplicates[{5,5.}]` returns `{5,5.}` because `DeleteDuplicates` uses `SameQ` by default, and `SameQ[5,5.]` is `False`. However, `Equal[5,5.]` is `True`, but `DeleteDuplicates[{5,5.},Equal]` still returns `{5,5.}`. It is interesting to note that `Union` works properly, in that `Union[{5,5.},SameTest->Equal]` returns `{5}`, as expected. Is this a bug, or am I missing something? I'm using version 9. **Update:** I realize that using the function `#1==#2&` will get it working, thanks for pointing this out. However, my question really is "Is this a bug, or am I missing something?". To illustrate this further, consider the following:               f[x__]:=Equal[x]     DeleteDuplicates[{5,5.},f]     (* {5} *)      In what capacity are `f` and `Equal` different? Or what is leading `DeleteDuplicates` to treat them differently? They both take an arbitrary number of inputs, which is what I originally thought was the problem.


Clojuratica setup in Windows

I have been trying to setup Clojuratica on Windows using instructions from Clojure Data Analysis Cookbook and http://drcabana.org/2012/10/23/installation-and-configuration-of-clojuratica/ Each time I run this code               java -cp ".\clojure-1.6.0\clojure-1.6.0.jar;.\Clojuratica-master\clojuratica.jar;     C:\Program Files\Wolfram Research\Mathematica\9.0\SystemFiles\Links\JLink\JLink.jar;."          clojure.main Clojure 1.6.0      I get the error > Exception in thread "main" java.io.FileNotFoundException: Clojure (The > system cannot find the file specified) What am I doing wrong?


writing a function using multiple variables

I am fairly new to _Mathematica_ and am trying to write a function for the equation:               xx = [x/(Sqrt[h^2 + d^2 + y^2]))*(Sqrt[h^2 + (d + yy)^2])      where h, d are known and x, y and yy are functions that give lists of numbers of equal list length. Is there a way to write a function that encompasses all the variables x, y, yy? I'm assuming it would start with               xx[x_, y_, yy_] := .........      or is the best method to create a loop?


How to find a fit for a function?

I have the following function:               F[t_] := V1 (Cos[w1 t - ph1] Exp[-alpha1 t] -           Cos[ph1] Exp[-beta t]) +        V2 (Sin[w2 t + ph2] Exp[-alpha2 t] - Sin[ph2] Exp[-beta t])      where all the variables are constants. I want to express it in terms of Spherical Bessel Functions of any type or any linear superposition of them. My first idea was to extract the data from the function making a list and then use               FindFit[data, p SphericalBesselJ[q, t], {p, q} t];      But I am struggling to export the data so that it matches the form of a function. I tried:               data = Table[F[t], {t, 0, 0.1, 0.0001}]      But the label of the x axis is 1,2,3.... where I need 0.0001, 0.0002 and so on. Any ideas of how to get around it or maybe another way of finding the correct expression of `F[t]` in terms of Bessel Functions?


NDSolve Differential Equation Error

I am trying to solve the following differential equation-               k = NDSolve[{y'''[x] == -76*Sin[y[x]], y[0] == Pi/4, y'[0] == 0,         y[1.85] == 0}, y, {x, 0, 2}, AccuracyGoal -> 10,        PrecisionGoal -> 30]      I am getting a solution but when I plot a graph, it does not satisfy the boundary conditions. I am getting the following two errors- FindRoot::sszero: The step size in the search has become less than the tolerance prescribed by the PrecisionGoal option, but the function value is still greater than the tolerance prescribed by the AccuracyGoal option. >> **NDSolve::berr: There are significant errors {-0.239832,-0.0591905,-0.0015434} in the boundary value residuals. Returning the best solution found. >>** The funny thing is when I reduce the coefficient of `Sin[y[x]]` it works fine. Can anyone help me with this? Thanks,


How can I make the output from Solve look nice?

I have a problem with presenting solutions. Roots of 4th order polynomials are big expressions. Is there a way to present the roots, s2 and s3, in normal form with some substitutions? Maybe a way to force _Mathematica_ to find some similar terms under the radicals and replace them with substitutions (to factorize or simplify that way), so s2 and s3 are presented in a way that looks nice?               a1 = Roots[x^4 + r1 x^3 + r2 x^2 + r3 x + r4 == 0, x][[1]][[2]];     a2 = Roots[x^4 + r1 x^3 + r2 x^2 + r3 x + r4 == 0, x][[2]][[2]];     a3 = (-s2 - Sqrt[s2^2 - 4  s3])/2 ;     a4 = (-s2 + Sqrt[s2^2 - 4  s3])/2 ;          Solve[{a1 - a3 == 0, a2 - a4 == 0}, {s2, s3}]


Is it possible to assign different colors to parts of an .obj file?

There are four different cubes in an .obj file. After loaded into Mathematica, is it possible to assign four random colors to the cubes?                (* assuming the .obj file was loaded in the c: root *)      cubes = Import["c:\\4cubes.obj"] ;      Graphics3D[  First[cubes]  ]      ![enter image description here](http://i.stack.imgur.com/GaVST.gif)


Selecting expressions from a sequence that are not subexpressions of earlier elements

I have a `While` loop that generates and prints an expression on each iteration (there can be thousands of iterations). _UPDATE:_ Some expressions are generated in unevaluated form (e.g. `1 + 1`) and printed in this form. This behavior should be kept in the modification explained below. I want to modify it to print only _new_ expressions -- that do not appear as sub-expressions of any expression that has been generated at an earlier step. We assume that any expression is a sub-expression of itself, so no expression should be printed twice. Generated expressions may contain patterns, and they should be handled verbatim (each symbol represents only itself). For example:               (* Iteration 1 *)     f[_] (* PRINTED *)          (* Iteration 2 *)     f (* Skipped *)          (* Iteration 3 *)     _ (* Skipped *)          (* Iteration 4 *)     Blank (* Skipped *)          (* Iteration 5 *)     f[0] (* PRINTED *)          (* Iteration 6 *)     f[_] (* Skipped *)          (* Iteration 7 *)     g[f[0]] (* PRINTED *)      What is the most efficient way to maintain a set of expressions that have been already printed and validate newly generated expressions against this set?