title: Mathematica Version 9.0.1 EPS Format Improvements

text: Is it just me or has the ability to make high quality EPS graphics increased greatly in version 9.0.1 compared to 9.0.0? I've always found it difficult to get plots that I make in Mathematica to print nicely in Microsoft Word. Mathematica does a terrific job of converting whole notebooks to a pdf but in my experience, it does a much poorer job of saving individual cells or graphics to a pdf. So I've started saving a given notebook as a pdf. From there I open it up in Adobe Acrobat 11 and crop the figure I want. Then I save the resulting pdf as a .eps which I then import in word. Here's the kicker though, do this with version 9.0.0 and your likely to have issues with the misplacement of text in your figures (or the text may even be missing completely) upon importing the .eps in word. Do this in version 9.0.1 and you'll get beautiful, crystal clear graphics upon the printing of the word document. Did Wolfram Research acknowledge that changes in this area were made with this update? I know we don't like to post too many questions all at once but I was annoyed with the fact that I ended up having to uninstall 9.0.0 from my system in favor of 9.0.1. Why doesn't Mathematica update automatically from version x.a to version x.b? Thanks


title: Unpacked eigenvectors of complex matrices

text: **Edit:** This bug is fixed in _Mathematica_ 10.0.0 I want to calculate eigenvectors of a Hermitian matrix. For example               $HistoryLength = 0;     n = 3000;     mat = # + ConjugateTranspose[#] &@RandomComplex[{0, 1 + I}, {n, n}];     evec = Eigenvectors[mat];      However, `evec` is unpacked!               evec // Developer`PackedArrayQ      > False System monitor shows ![enter image description here](http://i.stack.imgur.com/1GrDX.png) It seems that the result was unpacked in the end of evaluation. I think the problem is that the last element of each eigenvector is real instead of complex               evec[[All, -1]]      > >     -0.100012, -0.059244, -0.0723702, ... >                 evec[[All, -2]]      > >     -0.0994738 - 0.00136552 I, -0.0527357 - 0.0532419 I, 0.158174 + > 0.0341157 I, ... >   With real matrices everything is fine               n = 5000;     mat = # + Transpose[#] &@RandomReal[1, {n, n}];     evec = Eigenvectors[mat];     evec // Developer`PackedArrayQ      > True ![enter image description here](http://i.stack.imgur.com/R9cEy.png) My current workaround consist in packing the result immediately after `Eigenvectors`               evec = Developer`ToPackedArray[0.0 I + Eigenvectors[mat]];      Now `evec` is packed but there is a very big peak in the memory usage ![enter image description here](http://i.stack.imgur.com/lNBEQ.png) It is not a problem for a small matrices, but if matrix `mat` is ~30GB then I need ~300GB memory. It is quite a lot even for the swap space! It seems that this is a very simple question, but I could not find anything. P.S. I use _Mathematica_ 9.0.1 and Linux. _Mathematica_ 8 has the same problem. **Update** halirutan's answer solves this problem completely! Now memory profile is much better ![enter image description here](http://i.stack.imgur.com/NJ9DS.png) Some notes: You need 11 version of MKL. In Gentoo it is available in science overlay. I compile the library with the command               gcc -shared -fPIC -o PackedEigenvectors.so -I /usr/local/Wolfram/Mathematica/9.0/SystemFiles/IncludeFiles/C/ -I /opt/intel/composerxe-2013.0.080/mkl/include/ PackedEigenvectors.c      Helpful links: 1, 2


title: A question about definite integrals and timing

text: I need to integrate the expression `G` given below:               R = {Rx, Ry, Rz};     b = {bx, by, bz};     r = Sqrt[(s*b - R).(s*b - R)];     K = Exp[-r/L]/r;     G = Simplify[-K*(1/r + 1/L)*1/r*b.(s*b - R)];      If I use:               Integrate[G,{s,0,1}]      it takes quite a long time; instead if I use:               int = Integrate[G, s]     Simplify[(int /. s -> 1) - (int /. s -> 0)]      it takes less than a second. Why is it so?


title: How to convert TableForm to proper LaTex and why is "\" not replaced by StringReplace?

text: I'm trying to optimize the teXForm output of a table because the standard output ist not satisfying:               badLatex = TeXForm[TableForm[{     {"nm", "E1", "E2"},     {500.`, -0.001`, -0.001`},     {499.`, -0.001`, 0.`},     {498.`, 0.`, -0.001`}}]]      I get this output               \begin{array}{ccc}          \text{nm} & \text{E} & \text{E} \\          500. & -0.001 & -0.001 \\          499. & -0.001 & 0. \\          498. & 0. & -0.001 \\         \end{array}      No I want to replace the decimal points with commas, change the environment and eliminate the "\text" command. The last doesn't work for me.               goodLatex = StringReplace[ToString[badLatex],         {"array" -> "tabular","." -> "," ,  "\text" -> ""}]      I get the following result:                   \begin{tabular}{ccc}              \text{nm} & \text{E1} & \text{E2} \\              500, & -0,001 & -0,001 \\              499, & -0,001 & 0, \\              498, & 0, & -0,001 \\         \end{tabular}      As you can see, the expression "\text" is still there. Why is "\" not replaced by StringReplace? Do you have a better idea how to convert tables to proper LaTex code? Thanks in advance for your help! Michael


title: Is LinearSolve the most robust way to solve the equation $Ax=b$?

text: I want to solve the equation $Ax=b$, where $A$ is an $n\times n$ matrix, and $x$ and $b$ are $n\times 1$ column vectors. Here $n=124$. `LinearSolve[A,b]` I got the following warning message: `LinearSolve::luc: Result for LinearSolve of badly conditioned matrix {{2075.28,-2527.91,633.713,-282.942,160.179,-103.364,72.5099,-53.9143,41.8539,-33.5945,27.6963,-23.3423,20.0412,-17.4831,15.4647,-13.8482,12.5376,<<17>>,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,<<74>>},<<49>>,<<74>>} may contain significant numerical errors. >>` The determinant of the matrix $A$ in this case is about $10^{282}$. I also used Matlab to solve the same problem; there is no warning massage and the result is consistent with the Mathematica result. This is only a small part of a program, and it can be checked that the final result is correct despite the warning message. But it is disturbing that the precision may not be good enough. What is the best way to solve the equation $Ax=b$ when the matrix $A$ is large? How can we increase the precision or control the precision?


title: Multiple swapping of rows and columns

text: m={{a, b, c, p}, {d, e, f, x}, {g, h, k, z}, {u, v, w, y}};      I want to swap 1st and 2nd rows by 4th and 3rd rows respectively. And then, swap 1st and 2nd columns by 4th and 3rd columns.


title: Constrain Fit to make a fit that remains positive over the range of my independent variable

text: For example, say I have the following data.               {{100, 1.5157*10^-3}, {200, 1.4556*10^-4}, {300, 2.8538*10^-5},       {400, 7.5323*10^-6}, {500, 2.3853*10^-6}, {600, 8.3798*10^-7}}      When I attempt to use the `Fit` command (to any order of x) the result always allows for the y value to be negative at some x. Is there anyway I can add a constraint that will prevent this from happening?


title: nested use of Apply/Map/MapThread in pure functions

text: **1\. My main question** I have a function with two argument slots. I wan't to apply this function to 2 lists with different length's. I thought in this solution:               Map[Map[f[# &, #], b] &, c]      But it doesn't work. Why is that? **Example**               f[x_, y_] := Sin[x y]                 b = {1, 2}       c = {1, 2, 3}      The output seems pretty close of what i wanted but not close enough:               {{Sin[#1 &][1], Sin[#1 &][2]}, {Sin[2 (#1 &)][1],        Sin[2 (#1 &)][2]}, {Sin[3 (#1 &)][1], Sin[3 (#1 &)][2]}}      **2.** It seems that i only need to take the &'s out of the square brackets. **a)** Is it so? Why? **b)** how can i do that? Thanks


title: Exporting Dynamic@Graphic with Mathematica and Player Pro

text: Why does               DynamicModule[{grf, x},       Panel[{Button["Export", Export["test.png", grf]],         Slider[Dynamic[x], {1, 4}],         grf = Dynamic[Graphics[{Line[{{1, x}, {x, 1}, {3, 2}}]}]]}]]      export properly in Mathematica but not Player Pro and               DynamicModule[{grf, x},       Panel[{Button["Export", Export["test.png", grf]],         Slider[Dynamic[x], {1, 4}],         Dynamic[grf = Graphics[{Line[{{1, x}, {x, 1}, {3, 2}}]}]]}]]      export properly in both? Thanks in advance.


title: How to specify VertexCoordinates as geographic coordinates of cities?

text: I have been very busy these days with giving the `VertexCoordinates` of the cities the geographic coordinates from `CityData["CityName","Coordinates"]` of the cities. Could somebody please help me on writing algorithm?               Graph[{"Uppsala" -> "Marsta", "Marsta" -> "Uppsala",        "UpplandsVasby" -> "Sollentuna", "Sollentuna" -> "UpplandsVasby",        "UpplandsVasby" -> "Marsta", "Marsta" -> "UpplandsVasby",        "Stockholm" -> "Boo", "Boo" -> "Stockholm",        "Stockholm" -> "Lidingo", "Lidingo" -> "Stockholm",        "Stockholm" -> "Sollentuna", "Sollentuna" -> "Stockholm",        "Stockholm" -> "Taby", "Taby" -> "Stockholm"},       VertexLabels -> "Name"]


title: on simplifying an expression

text: After some integration process, I ended up with the following expression:               (1/(b (-1 + E^b) Re[b]))E^-Re[b](  b E^b - b + E^Re[b] Re[b] - E^(b + Re[b]) Re[b]                                      + E^Re[b] Sqrt[E^(-2 b) (-1 + E^b)^2] Re[b]                                      + b E^(b + Re[b]) Sqrt[E^(-2b)(-1 + E^b)^2] Re[b] )      all is good, but this expression is supposed to be equal to               1 + (2/b) e^(-b) - 1/b      via simple numerical trials, i can confirm that they are equal. But, it would be great if I can actually make _Mathematica_ simplify that nasty expression into this innocent form. I tried, `Fullsimplify`, it does not work. Does anyone have any suggestion?


title: Table/Tree of values

text: **My question:** Is there a way to create a tree of values? Something like the output of the command TreeForm, but with values in the nodes? **Why do I want this?** I'm trying to do a complete program to analyse the output of my labs classes. Each column of data has a symbol assigned. In general, each column is meaningful: it's not just a pile of diferent variables. What i want to say is that in general,calculations are done "column wise".My problem is when i need a to do a calculation that needs a more envolved "horziontal" structure : Assigning the variables to columns lacks "horizontal flexibility" . (In a way,this is the kind of problems that are solved in Excel with the `$$` and array formulas) let me ilustrate with an example:               y={1,2,3,4,5,6,7,8,9};     x={-1,-2,-3};      I want to associate the 1;;3, 4;;8, 9;;9 parts of y to each element of x. What i mean by associating is that for some calculation the input of the function will have as argument each of this sets. I'm aware of functions like Map, Apply, Thread and MapThread. I've been using them to solve this kind of problems, but sometimes it gets a little confusing. I'm also aware of Partition, wich would solve my problem if i wanted to separate y in subarrays of the same length. As i say in my question, what i want is to construct something like a net/tree that "archives" the structure of the arguments in each step of my calculations. Something like in networking theorys, when each node as an associated list of it's connections to the rest of the network. Notice that this list should not contains the values but some kind of coordinates of the connected nodes **Example:** Calculate the mean and the mean square deviation of the irregular partition of lenghts `n={3,2,5}` of the list                y={3,5,8,7,9,4,6,2,1,5};      **My very conceptual aproach:** The first column of my Table/Tree will be the data y. To refer to some value on some column, I will use a pair of coordinates i,j: i stands for the column and j stands for the internal position. I will assign to y the coordinate i=1. For the means calculation, what kind of "calculating conections" i have?               Yav=F1[y]=Mean[y]      The column of the means, Xav i=2, will have 3 elements. To each one I assign a list of conections to y: (Conection of "" is rerpesent with a C"")                   CYav[[1]]: {1,{1,2,3}}         CYav[[2]]: {1,{4,5}};         CYav[[3]]: {1,{6,7,8,9,10}}      The connection are written in the form {i,{j's of the elements of i}} Now, let's calculate the mean squared deviation. That is ,                  Ymsd=F2[y,Yav]=Mean[(y-Yav)^2]      This column as `i=3` and also 3 elements. For this calculation, i want to use the columns i=1,2. The calculating connections to y are the same that the ones used to calculate Yav. But now, i need to connect Ymsd to Yav.                   CYmsd[[1]]: {{1,{1,2,3}},{2,1}}         CYmsd[[2]]: {{1,{4,5}},{2,2}}         CYmsd[[3]]: {{1,{6,7,8,9,10}},{2,3}}      Now the conections are a pair of conections of the former type, one to each column connected. After assigning the conections, i would use a function that would fetch the correct values, guided by the map created, and apply the F1,F2. Thanks


title: Eliminate doesn't work in Mathematica

text: Hello Mathematica users, I have problems trying to eliminate variable $Q(x,y)$ froma PDE, but Mathematica output is just `True`. The problem is that I already found how to eliminate it. We can apply $d/dx$ on the second equation and then from the first equation we can determine and substitute $dQ[x,y]/dx$ in the second. Why can't Mathematica do that? My output is in that case a PDE of fourth order, but I don't have `Q[x,y]`, which is the aim, and I solved it by hand.                Eliminate[{A0*D[w[x,y],{y,2}]-B0*D[w[x,y],{x,2}]-        C0*D[Q[x,y],{x,1}]+C0*D[w[x,y],{x,2}]==0,        E0*D[Q[x,y],{y,2}]-FF0*D[Q[x,y],{x,2}]-CC0*D[w[x,y],{x,1}]-Q[x,y]==0},         {(Q^(0,2))[x,y],(Q^(1,0))[x,y],Q[x,y]}]


title: MathKernel and MathLM interaction

text: If one restarts MathLM on a Linux server, will that restart mathkernel as well? In other words, will restarting MathLM affect the current jobs running that use MathKernels? Thanks.


title: Why does $Path change when I examine it in new cell after I just changed it?

text: This is really driving me crazy. In one cell, I change `$Path` by removing from it un-needed paths that I do not want for the duration of a computation I will be doing. Immediatly after, in new cell, I type $Path and see it was changed ok. Now, I open a new cell, and do the same. I type $Path again, and now I see some of the Paths I removed are back again! Here is a screen shot from my notebook now ![enter image description here](http://i.stack.imgur.com/Isyws.png) You can see the variable $Path now has changed, on its own. This is what I type               $Path =DeleteCases[$Path, "C:\\Users\\me"];     $Path =DeleteCases[$Path, "."];     $Path =DeleteCases[$Path,"C:\\Program Files\\Wolfram Research\\Mathematica\\8.0.4\\AddOns\\LegacyPackages"];     $Path =DeleteCases[$Path,"C:\\Users\\me\\AppData\\Roaming\\Mathematica\\Autoload"];     $Path =DeleteCases[$Path,"C:\\Users\\me\\AppData\\Roaming\\Mathematica\\Kernel"];     $Path =DeleteCases[$Path,"C:\\Users\\me\\AppData\\Roaming\\Mathematica\\Applications"];     $Path =DeleteCases[$Path,"C:\\ProgramData\\Mathematica\\Applications"];     $Path =DeleteCases[$Path,"C:\\ProgramData\\Mathematica\\Autoload"];     $Path =DeleteCases[$Path,"C:\\ProgramData\\Mathematica\\Kernel"];     $Path=DeleteCases[$Path,"C:\\Program Files\\Wolfram     Research\\Mathematica\\8.0.4\\Documentation\\English\\System"];      Then in new cell               $Path      Then in new cell the same. And now the $Path has been reset. I noticed this when I was calling Leonid function he posted, and in it, it uses `$Path`, but I noticed I was getting packages that should not show up since I changed the $Path before calling it. This is really strange. I am using V 8.0.4 on windows 7 **edit** Just installed version 9. Not able to reproduce this. Using the same PC, same notebook, same steps. So it looks like, whatever it was, is fixed in Version 9.


title: How do I keep the right ordering of eigenvalues using Eigensystem?

text: I'm having an issue with the `Eigensystem` command. I need to diagonalize a bunch of 3 by 3 complex valued matrices, but more importantly, I need to keep the exact ordering of their eigenvalues once brought to their diagonal form. For example, if               A = { {1.999, 0.000428712*I, 0} , {-0.000428712*I, 2.00072, 0} , {0, 0, -4.00057} }      then `Eigensystem[A]` returns the three eigenvalues (with their corresponding eigenvectors) listed in order of decreasing magnitude (absolute value). What is even more annoying is if my loop runs into an already diagonal 3 by 3 matrix such as `B = {{2,0,0},{0,-3,0},{0,0,2}}`, it will reorder the eigenvalues as `{-3,2,2}`. Is there a command that gives me the eigenvalue without re-sorting them?


title: Global precision setting

text: Coming from Maple I do not understand how the precision for numerical computations in Mathematica is specified. I understand that there are various options to commands such as `WorkingPrecision` and `PrecisionGoal`. But I would like to use the same precision (above machine precision) for a number of computations including matrix operations and the `FindRoot` command outside and inside of routines. Also I would like to specify the precision of the output.


title: Formatting ANOVA table and/or ParameterTable without using Grid?

text: Does anyone know if there is an option or function that can automatically format the output of `ANOVATable` and `ParameterTable`, but without using the `Grid` function ?


title: Distances between points in periodic cube

text: How can one implement more efficiently/elegantly/memory savvily the following function which returns a matrix of all Euclidian distances between points in 3D within a cube of width `size`, while accounting for the periodicity of the cube?               Clear[PeriodicDistance];     PeriodicDistance[x_, size_: 1] := Module[{xm, ym, zm},     xm = {Outer[EuclideanDistance, x[[;; , 1]], x[[;; , 1]]],      size - Outer[EuclideanDistance, x[[;; , 1]], x[[;; , 1]]]};     xm = Map[Min[Abs[#]] &, Transpose[xm, {3, 1, 2}], {2}];     ym = {Outer[EuclideanDistance, x[[;; , 2]], x[[;; , 2]]],      size - Outer[EuclideanDistance, x[[;; , 2]], x[[;; , 2]]]};     ym = Map[Min[Abs[#]] &, Transpose[ym, {3, 1, 2}], {2}];     zm = {Outer[EuclideanDistance, x[[;; , 3]], x[[;; , 3]]],      size - Outer[EuclideanDistance, x[[;; , 3]], x[[;; , 3]]]};     zm = Map[Min[Abs[#]] &, Transpose[zm, {3, 1, 2}], {2}];     Sqrt[xm^2 + ym^2 + zm^2]     ]      As a side question, is it possible to carry out such computation within mathematica using e.g. octree so that it could be scaled up to millions on points? Thanks for your help


title: Invisible characters being inserted into the output from FindMaximum

text: I have been using _Mathematica_ for quite some time but I have never seen anything like this. It started without warning and I am not sure how to fix this. Please have a look at the following example https://dl.dropboxusercontent.com/u/23383252/bugs_editor.nb The notebook exemplifies my problem. Before you run it to check it, please read through it as I have explained every step of the problem. I am using a dropbox link to my notebook, since I have no idea how to attach a file (or if it is possible at all!) to this message. In short, the problem is as follows: there is an issue with `FindMaximum` (could be other built in functions as well, but so far this is where it started) where, the editor changes the output from `{maximum, {xx -> maximum position}}` to `{maximum(extra invisible characters), {(xx -> maximum position)(some more invisible characters)}}`. This has a huge impact on the rest of the variable types that are calculated with either element of the `FindMaximum` output (see the notebook for an example with `ListPlot`). Has anyone seen this and how did they fix it. P.S.: I tried to google this problem but I had no success since I don't really know what generates it. Update: As discussed below, I have modified the shared notebook to make it simpler. Got rid of all the unnecessary parameters and replicated the problem on my computer. Now, as rasher said, the issue could arise due to the excessive use of comments. This seems to be the case, because I copy and pasted the first cell where function nx is defined, into a new notebook and same thing happened. Again the problem was fixed if I wrote the function in a new cell. I will try to add the code to this message together with the output for `Va=2`:               nx[Va_] := Block[     {WmaxL},     WmaxL = FindMaximum[{rr^2 - 10 rr + Va - 1/rr, rr > 0}, {rr, 1}];     WmaxL     ] ;      This is the original function. Please note the extra spaces between the last `]` and `;` (this was a surprise for me too as is not evident in my notebook!). The output for this function is as not what you would expect from `FindMaximum`:               Out[15]= {-5.221174649 TextCell[""], {(rr -> 0.3271088) TextCell[""]}}      More surprises! This is what I get when I copy from the _Mathematica_ notebook and paste it here! What is this `TextCell` in the output? It is obvious for me why the rest of the notebook is not working as it should, but I have no idea why are these invisible characters inserted in my expressions. I hope this clarifies the issue a bit more, and allows you to check it on your machines too. P.P.S.: the modified notebook can be found at the same link.


title: Derive a smooth circle with cusp from an image

text: ![enter image description here](http://i.stack.imgur.com/3VEuj.jpg) ## question 1 get the center * * * ( _sample data_ ) `sample` is the black circle with cusp.                (*Input 1 ==< *)      sample = Binarize[Import["http://i.stack.imgur.com/z7isS.png"]]      > >     (*Output CellExpression, You can copy to Notebook or just Skip*) > > \!\(\*GraphicsBox[TagBox[RasterBox[CompressedData["1:eJztnc1u1DAUhR3Egh079jwKPEJ5glaCLVJBQn17mpnpNImPnTj+ude+51OpVI1jn/v5ZzLTqfj69Pvh1wfn3J9Pr98eHv99e35+fPnx8fWH7y9/fz7ND32enPvy+m9qhpuJPz65W7MFq8fHw+1ouT0cszKmmGm9YtbVX782Le+tt44Gw6/0bsUZtLLdGP7PsfaDSilhRSZ4VfatrMse3AraCrsFwotG8kMrK4pXM4QbWtlSN32vbirnXvbdh5ZG89jZZmqUtWMrFdP2Y6V5zi7UtM+o3YrgtCk2I7mYlVoRny2VB4x4JFrZC6DCiqI0iszoSbJ8eSSYRdHcvLF871MqgkIr0om0CXlHMhmtaBs7jlAyhQfKGpGAtKJiyFO0TUkrsmPl0i4qrYSH6UDJG7SCqJ3XdWuldv9dCblSOXWnVnY/65vdd4dOZuolp5VAv30qmerN6BhWSlcwhpXCvTa4Q6zK+41W0Sp6t1L8NVHPTz4LaAVSUkuHr3wClKyEVmr3JUuxSuo8n4lBK4gytQyl5Ep+RWMtlCvFrBRLpIH8mR7RSm5VI+6fmby6aKX81XrJqGuwG5U1p2ujlciFNTKp4JwYI1aSPq088vZ5I73C8Z3kWBnZS7IVA/sn/ZSwcKqctlI1kwbSvNBKpHXlTPLQCiLFihEl0+J3zwfuQOxYSXkNbNHKzmKxcaty5+BacWaO2gtHrVhycoFWEEdOFmtOjp2ktBJs0yyRBvatGBNygVYQe1bMbZ4btIKgFUR8D9FK6NHGgVSwb8WmmNiLRFrxirerZKIVDK0gaAVBKwGwF1qhFR9oJXp7ZwFkJXJvZ4SIFbFM8tAKglYQtIKgFUTQytCfrt3Dt8KVQisYWoGErJj24n+ciU5iVix74VrB0AqCVhDb5xxamUFWRAOpgFYQKyvcPjdoBUErCFpB0Apidc9PK3doBUErPjxXELSCoBUErSCcW3ihlRu0gqAVBM8VBK0gaAVDKwha8eEOQqysTHyP/wqtIGgFQSsIWkEgKxRDKwhaQdAKglYQWwu0MkMrCFpB0AoCWRGMowRaQXAHIWgFQSsIWvHxHdAKrWBoBQEc0Aq8Z6OVoBXTXmgFQSsIWvHB5Zu3El0rRr0EiqcVvFVM7yBaQcStWNWyY8WkFheunVZia8Wgl8iCiAgbnZiV2PYamWjVzupiiVdt7H86vLNXtc3VslewRSeHrVjycqhcWgk2ohXUyJKWg9Wa0nK4WFrJajgCqVZseKEVREqpVqykLQBayW/dK87Rio/jWgGkrhUbXtJrpJXoNdUyCXNy2mml4GW9cLI4WolcRivosjF/73x+ytNvcvoho7JhrWTVRSuVrtdIfk0Dni1FKhrTSpFOaAV1Qiuok3HEFKuEViIdjWClYB20Eu+tby/FZ5dWoh0W6k+ECidB916qFEArTbttQ7XsI1ip8mZrr2Iq5na0ItF7JarP5vszfkdeqkemlZ0hevHSJCytRIfpQEzbpLSyN2CT0U6wMtIqZVdWmqXsy4rIsO0GPUrqx4vLDaxZi5gVoa17ANlctHIkgMD4HioCqQixREUgFSGWiO8ebUGc05LET6Mlh7QVkEh4eAVCZqRTSY8fpkCyU9dux9XkhFYwtBIkJ2H6db4QfUZyU45q5crZrCnXgDH0CrlAK2FQ7kjylNZ9CrlAKyGwGa+GQLODSBSWxVkrSZ4kCsvirJU0JCrL5WSNAxuZqWml+7+zPjXzKW27hFZihJ5fpHPJkmFlXHXBexHpYIqgDIRuK/8B+/IYOQ=="], > {{0, 271}, {278, 0}}, {0, > 1},ColorFunction->GrayLevel],BoxForm`ImageTag["Bit", ColorSpace -> > Automatic, Interleaving -> > None],Selectable->False],BaseStyle->"ImageGraphics",ImageSizeRaw->{278, > 271},PlotRange->{{0, 278}, {0, 271}}]\) >                  (*Input 2 ==< *)     pts0 = PrincipalComponents@N@Position[ImageData[sample], 0];     {length = pts0 // Length,      radius = EuclideanDistance[#, {0, 0}] & /@ pts0 // Mean,     center = Mean@pts0 // N // Chop,      g1 = Graphics[{Point[pts0], {Red, Thick, circleNew = Circle[center, radius]}}]     }      > >     Output result see picture ==> :)@@ >   I do not like this, I' d like the red circle overlap the black circle. ## question 2 get the cusp. * * * Thought 1: Put one locator in the cusp and drag it to along the diameter (from cusp point to center), and the `circleNew` will go to the center. Maybe need interpolation, ie something `BezierCurve` or `BSplineCurve.`. Thought 2: Go on ImageProcessing, directly make `circleNew` (smooth except the place of cusp) overlap the balck circle. Maybe here we can directly `Fit` one curve with one function?                (*Input 3 ==< *)      Pruning[Thinning[ColorNegate[Erosion[sample, 1]]]]      > >     (*Output CellExpression, You can copy to Notebook or just Skip*) > > \!\(\*GraphicsBox[TagBox[RasterBox[CompressedData["1:eJztnMtu00AYhWcQC3bs2PMo8AjlCVoJtkgFCfXtSVtTcjm2ZzyX/3Y+qRfXdnLOZ8/ISZp8fvh59+NdSunXh9O3u/s/Xx4f75++vT8tfH36/f3hedXHnNKn0xcxQH5DOokezl3Qy0LeXIxCvuJmvUQoAd76l00dZ7IczzT55peivRY1PrU0H22HWnqMAFejqOP1h5uLmREdjHsZdlztehl7qhsdSONDm9My50gam3unJrWhZfrhs3C6SERUr0UmoGYtgnOf3mlXOpb0/QM0HCsFES5RkkdJjAU1aRTNL2qCvKIijTInSYUWBRFuEM8kHgAifP7qlJJEveibUs4QyqbaSRLSotxJEkmoX8r8jNpHz8LUS10jTl6ZlNWUk1lWbDlJcwKbk8KXplYYHdqklNGpbUoZnNuqlKHJ7UoZmN2ylGHpbUuhFcyQ/NalDGlgX8qADh6kdG/hQ0rnHl6k9G1CK2NvSpp+VRxJ6VfGlZRedZxJ6VPInZQelRxKae/kUUp7K59WWms5tdLWy6uUpmZ+pTR08yzlcDvfUg728y7lWENa6bWPMeorBpBS3zGClPqWtNK+uVnqekaxUvmxQaNSaKOmaBgpNU3jSKnoGklKeVtaOb6ZF2gFUtQ3mpSyxvGsFFQOKGW/c0Qpu6VDStlrHVPKTu2gUrZ7R5VCK5it5nGtbFWnlep1vqEVCIcQZLV7ZCmr5UNLoRUIrUBW6ge3stI/uhUoILwUWoHQCgIYoBRagdAKglYQtIK4VUAptIK5cUApiVYwHEEIWkHQCoLzCoJWINcWaOWFvLEUF1pB5NWFyOSV32NDKwhaQdAKglYQtIKgFQStIGgFQSsIWkHQCoJWELSCoBUErSBoBUErCFpB0AqCVhB8jh9BKwhaQdAKgq+oImgFkTcXo0IrCFpB0AqA/wGGoBUErSBoBUErCFpB0AqCVhC0AuC7GwB8exCCVhC0AuA73xH89BUAFhBdC60gaAVBK4CV+rRS9fcY0AqCVhCr7UNroRXAendaqVvjn43ucbVsNQ9rZbN4VCvbvWnlyGqn7LYOqWW/dEAtBZXjWSlpHM5KWeFoWgr7xtJS2pZW2jb0AK0gystG0kIrgJqqcbRUNY2ipa4nrfTY3Cq0AqhuGUJLfckAWg5U9G/lUEPvWg72863laDta6bmfCY6X86yloZtfLS3NvFrJbcV8amlu5VFLh07+tHRp5E1Lpz7OtNAKoFsbV1r6lXGkpWMVP1a6NvGipXMPJ1p613ChpXsJD1YGdLCvZUgD61oG5betZVh6y1oGZrerZWhyo1oan5Dcv/2xNz+G8aENapkRefTZ2J1JeW1pmZbWkpaJWQ1pmRnVipbJk6ANLdNTWtAikFG9FplLCOVapOKp1iIXTq8W0QtwrVqEc2WNj4o0ZFIQ4RIdgXSdL4rCMAlESxgtORZUxFE0ehYUBFIQ4YYsOuvK3vs2YsHUGnlB4pBpPk3+w+e/MDOfQTYjZWJWQ06eOeQl58o5wpiUdOThUb74UXIPlXegg7pP8Xjbumw3o07SMiQKN73YreB2j2ZSQlH+q402S5s38kLem0XRyrXN7Z8ll6y2wSvyOanArVFWGpUU9ajjH+hYO65bwfWYkM6jCwohhATjL3IdCrM="], > {{0, 271}, {278, 0}}, {0, > 1},ColorFunction->GrayLevel],BoxForm`ImageTag["Bit", ColorSpace -> > Automatic, Interleaving -> > None],Selectable->False],BaseStyle->"ImageGraphics",ImageSizeRaw->{278, > 271},PlotRange->{{0, 278}, {0, 271}}]\) >   ![enter image description here](http://i.stack.imgur.com/thEyK.png)


title: Pick with nested list

text: I have a list of pairs of values. Some of those pairs are invalid based on another list. I would like to select only the valid pairs.               list1 = {"abc", "def", "ghi", "jkl", "mno"};     list2 = {{"abc", 1}, {"def", 2}, {"ghi", 3}, {"jkl", 4}, {"mno", 5}};     sel = {{2}, {}, {4}, {1}, {7}};     Pick[list1, sel, {_}]     Pick[list2, sel, {_}]      list1 is a sample of what I would like. list2 is similar to my actual case. sel is the result of `Position` where I'm checking a corresponding list against valid cases. When the result of `Position` is an empty list, I do not want the values in list1 or list2. The output from the above code is: ![enter image description here](http://i.stack.imgur.com/2hmRU.jpg) I see from the documentation that what I'm doing with list2 is not valid. My question is what is a good way to do this? I want my original list2, but without {"def",2}. Everything I can think of is pretty messy.


title: How to export to .html .nb file together with links «in» and «out»

text: If use «File > Save As > HTML» lines «in» and «out» are lost To save a document without loss of these lines/links? ![enter image description here](http://i.stack.imgur.com/RGetT.png) ![enter image description here](http://i.stack.imgur.com/1gMzf.png)


title: How to modify font for all text fields?

text: I know that one can modify the StandardForm style so that all input and output codes (and maybe other things too) follow that style. This makes it tricky to make input code different from output code (though this problem has been solved here) because the StandardForm is the overriding style for both inputs and outputs. Here I have an opposite problem with formatting texts. I want all text fields in my notebook to have the same font, and that includes the style of Title, Subtitle, Sections, Text, Item, Subitem, and so on. Of course I could set all of them to be the same font in my stylesheet, but I'm wondering if there's a style that I could change and that would apply that change to all texts. That way if I want to change the font of my texts in the future, I could just change that one style instead of changing all text styles one by one. In other words, is there any equivalence to StandardForm for text fields?


title: Replace matrix with conditions

text: I want to replace the values of 1. in `slot` under the condition that the year and month in `basevalue` and `slot` have to be matched Here are my matrices: `basevalue = {{{2012, 9}, 0.2819}, {{2012, 10}, 1.01406}, {{2012, 11}, 1.06447}, {{2012, 12}, 0.929704}, {{2013, 1}, 1.11471}, {{2013, 2}, 1.08585}}` `slot = {{{2012, 3}, 1.}, {{2012, 4}, 1.}, {{2012, 5}, 1.}, {{2012, 6}, 1.}, {{2012, 7}, 1.}, {{2012, 8}, 1.}, {{2012, 9}, 1.}, {{2012, 10}, 1.}, {{2012, 11}, 1.}, {{2012, 12}, 1.}, {{2013, 1}, 1.}, {{2013, 2}, 1.}}` I have tried the following code by my own `Map[Function[arg, ReplacePart[arg, 2 -> Select[basevalue, #[[1]] == arg[[1]] &][[All, -1]] ]], slot]` , but it returned me different from what I want. I think I still do not fully understand how to use `function` :( Any helps or suggestions would be appreciated Thank you


title: Partitioning a numerical integral: need to integrate spectra

text: I am trying to integrate a spectrum I obtained from a fourier transform infrared spectroscopy experiment, in order to determine the global warming potential of green house gases. In order to do this, I would like to integrate the spectrum that I have in chunks of 10 wave numbers (x axis is wave numbers). IE, I would like to generate a list that has the integral from 525 - 535 in the first slot, 535-545 in the next slot Here is a link to my data: https://drive.google.com/file/d/0B5gGZ4-SD7-ZZDRoNE5XMzFnYnM/edit?usp=sharing               data = Import["/home/marco/Documents/Mathematica/GlobalWarming/nitrogenforMathematicaTest.csv"]     spectraInterp = Interpolation[data, InterpolationOrder->3] (* Here we  create an interpolation function to represent our data *)               ListPlot[data]     Plot[spectraInterp[x], {x,525,1400}, PlotRange->{{525, 1400}, {0, 0.3}}]     NIntegrate[spectraInterp[x], {x,600,1400}]


title: Calculate the algebraic multiplicity of known eigenvalues of a large, sparse matrix

text: I have a large (and sparse) matrix with size 1000x1000 -- 10000x10000. I believe i know all eigenvalues for the matrices. All entries are integers and so are the eigenvalues. I want to check this by calculating the algebraic multiplicity of the eigenvalues and see if they sum up to the dimension my matrix implying I have all the eigenvalues. I know the matrices to be non-diagonalizable, which makes it non-sufficient to calculate the dimension of each corresponding nullspace. I also need to do the calculations symbolically (numerically I seem to have found them all at least within error margin). I have tried calculation the characteristic polynomial but this seems to be very slow. Once I have the characteristic polynomial checking multiplicity would have been a simple task. Anyone have any ideas? I guess the question simplifies to: How do i find the algebraic multiplicity of a known eigenvalue when the matrix is large and sparse?


title: ListPlot of lists with specified x coordinate

text: I want to do:               ListPlot[{{x1, y1}, {x2, y2}, ...}]      each y being not a number but a list of numbers. I tried:               ListPlot[{{x1, {y1}}, {x2, {y2}}, ...}]       but it does not work. Does anybody now how to do this? Thanks a lot!


title: How can I compile this function

text: I want to simplify my function `f1` to `f2`, but `f2` can't be compiled. How can I make it compilable?               f1 = Compile[{{arr, _Real, 2}},        Module[{a, b, c, d}, {a, b, c, d} = arr;         {{a, (a + b)/2, (a + c)/2, (a + d)/2}, {(a + b)/2, b, (b + c)/2, (           b + d)/2}, {(a + c)/2, (b + c)/2, c, (c + d)/2}, {(a + d)/2, (           b + d)/2, (c + d)/2, d}}         ], RuntimeAttributes -> {Listable}];          v = {{{0, 0, .6}, {-.3, -.5, -.2}, {-.3, .5, -.2}, {.6, 0, -.2}}};     n = 3;     p = Nest[f1, v, n]~Flatten~n;     Graphics3D[Tetrahedron /@ p]               f2 = Compile[{{arr, _Real, 2}},        Module[{a, b, c, d}, {a, b, c, d} = arr;         With[{t = Evaluate@Map[Mean, Partition[Tuples[{a, b, c, d}, 2], 4], {2}]},          t          ]         ], RuntimeAttributes -> {Listable}];      ![enter image description here](http://i.stack.imgur.com/w2mH7.png)


title: Simplify system functions

text: Consider the code defining two constants:               a=Cos[t]     b=Sin[t]      Suppose that we have another value in terms of `Cos[t]` and `Sin[t]`, for example,               c=2*Cos[t]+Sin[t]^2      How to show the result of `c` in terms of `a` and `b`, that is, instead of the line above I'd like my computations being showed as               c=2*a+b^2      In other words, how to ask Mathematica to recognize `Cos[t]` as `a`?


title: Options which require RuleDelayed

text: For some functions in _Mathematica_ it is important to use `RuleDelayed`. One prominent example is the `EvaluationMonitor` for functions like `NMinimize`               NMinimize[x^4 - 3 x^2 - x, x, EvaluationMonitor :> Print[x]]      Here it is inevitable to use `RuleDelayed` because otherwise `Print[x]` would be evaluated too soon. **Question:** Is there a comprehensive list of options which require `RuleDelayed`? Btw, the reason why I need this list is to support this correctly in the IntelliJ Plugin for Mathematica: ![enter image description here](http://i.stack.imgur.com/zJ1rv.gif)


title: Having used Mathematica as a "gateway" language, where to from here?

text: I have been using _Mathematica_ for about a year. It is the first language that I have attempted to learn. I'm still very much a newbie, but there are moments I feel more like I am waving than drowning. As with many addictions, at first it left an unpleasant taste, but with time, using _Mathematica_ started to open up new possibilities and I have come to depend on it. It has occurred to me that there are a number of reasons why at some stage I would like to learn some new language(s) to complement _Mathematica_ and further nurture my 'coding brain'. At times I feel slightly handicapped by not really understanding the capabilities/pitfalls of, for example, `Do` loops and other constructs that seem common in many languages. Indeed, it would be nice to be able to understand/relate to programmers that don't use _Mathematica_. Although a lot of coding paradigms can be used in _Mathematica_ , I feel it would be instructive to spend some time learning strictly procedural, object- oriented, etc. programming styles in the context of another language. Which other programming languages should a _Mathematica_ -only user be interested in, so as to appreciate the underlying programming principles and constructs that one takes for granted with _Mathematica_? Alternatively, I understand that there are a number of languages that can be implemented or interfaced from within _Mathematica_. Would it be a worthwhile trying to learn other languages/coding styles without leaving the notebook environment?


title: Is it possible to Import urls not type ""

text: These days I often copy urls from Internet Explorer's address bar. When I paste the url into a Mathematica cell it is neither a string nor a expression. Import@http://mathematica.stackexchange.com/search?q=load+file I always manually add " " to get                Import@"http://mathematica.stackexchange.com/search?q=load+file"      Another method is to use `InputString[]` sometimes, I don't like the pop-up dialog. Is there any more lazy way to make               Import@http://mathematica.stackexchange.com/search?q=load+file      successful, maybe by using a button, or InputField, or other setting, or some styled-cell?


title: How can I shade specific regions between two curves in a Plot?

text: From               Plot[{       ((0.707106 Sqrt[1 - 1.5 s13^2] + 0.5 s13)^2)/(1 - s13^2),        ((0.707106 Sqrt[1 - 1.5 s13^2] - 0.5 s13)^2)/(1 - s13^2)},        {s13, 0.0, 0.23},       PlotRange -> {{0.0, 0.23}, {0.35, 0.67}}, Frame -> True,       FrameLabel -> {FrameLabel -> {sin13, sin223}},       PlotStyle -> {{Gray, Thick}, {Brown,Thick}},       LabelStyle -> Directive[Black, Bold], Filling -> True,       FillingStyle -> Directive[Opacity[.19], Green]     ]      I obtained this ![enter image description here](http://i.stack.imgur.com/Bna4b.gif) * * * But I want to shade definite regions of the axes with different colors. Like ![\(\)](http://i.stack.imgur.com/Tf3cc.png) sorry for poor quality of the 2nd picture


title: notebooks not opening in mathematica 10

text: I`m a guest here, and thought I could just ask you guys. `I've tried filling in mathematica's support form on their website, but all I got was an e-mail telling me to use their support form!` \- and I'm not phoning them! - I live in Scotland! My problem is that I have downloaded mathematica 10 upgrade, and have opened new notebooks, closed them, and when I try to open them again, a message comes up with something about the book having potentially damaging "dynamic content" - which it doesn`t! - tried it with just saving a notebook with a simple quadratic equation in it! If I press the "enable dynamic content - nothing happens, and I have to create blank documents in mathematica 8 that will successfully open in version 10. What can I do about this myself, if anything? * * * I've given up using it and I'm just using my laptop with mathematica 9 the exact message is: " this notebook contains potentially harmfull dynamic content. Do you still wish to open?"


title: Constraint in a 2D plot with Legend

text: I have the following plot:               Plot[Table[C*r^2 + 2 C, {C, {25, 100, 150, 300}}] // Evaluate,          {r, 0, 1000},           PlotLegends ->LineLegend[{25, 100, 150, 300}, LegendLabel -> C,                  LabelStyle -> {GrayLevel[0.2], Bold, 10}, LegendFunction -> "Frame"],           AxesLabel -> {r, Plot},           PlotLabel -> "Plot"]      But I need to include a constraint: `r >= C.` So when `C` is `300`, the plot should show only for `r = 300` to `r = 1000`. How should I modify this code?


title: Numerically Integrating to find a Maximum using NDSolve

text: I am trying to numerically find an equilibrium (maximum) of a function using its differential. The following is a simplified version.               myEquilibrium[p_]:=Last[{myPreviousStep=1;NDSolve[{s'[t]==p-s[t],s[0]==myPreviousStep,WhenEvent[s[t]-myPreviousStep<10^-4||s[t]<10^-4,"StopIntegration"]},{s},{t,0,Infinity},StepMonitor:>(myPreviousStep=s[t])];myPreviousStep}]      myEquilibrium[.5] // 0.5 which is correct The function should be constrained to positive s, which is why I included the `s[t]<10^-4` requirement. However this does not seem to work. myEquilibrium[-.5] // -0.5 but should be 10^-4 The NDSolve should also not go to `0` exactly, as the real, non-simplified version contains a `1/s[t]` in the differential. That's another reason I want the procedure to stop at `s[t]=10^-4`, before `s[t]=0`. myEquilibrium[0] // 0. but should be 10^-4 Finally, I often get `NDSolve::mxst: Maximum number of 10000 steps reached at the point t == 6.57563031118913721074693815431*^4952. >>` and `NDSolve::ndsz: At t == 1.79769313486*^308, step size is effectively zero; singularity or stiff system suspected. >>`. What would typically solve this issue? Thanks.


title: AssociationMap to query Dataset across levels?

text: Is there a way to operate on Dataset across levels to apply a function `f` to a `key -> value` pair in an Association as follows:               pivotApply[f_, key_ -> value_] :=  key -> f[key, value]      For example, take the Titanic dataset and pivot up "class":               titanicClass = titanic[GroupBy[Key@"class"], KeyDrop[Key@"class"]];      For this problem, assume only titanicClass. `"class"` key has been deleted and so can't referenced. The motivation is tree-structured data where it would be inefficient to insert the keys `{"1st"...}` at the deeper level. Here `foo` represents a "client" function to be applied to deeper level data but depenent on class values. **EDIT // #age >= 18 &**               foo["1st", data_] := Dataset[data][All, #age >= 18 &];     foo["2nd", data_] := Dataset[data][All, "sex"];     foo["3rd", data_] := Dataset[data][All, "survived"];      Is there a way to avoid inefficient downcasting to Normal and back to Dataset to use AssociationMap? Also note there are Datasets nested in a larger one, which should also be cast to Lists (since there is an outer Dataset).               AssociationMap[pivotApply[foo, #] &, titanicClass // Normal] // Dataset      ![enter image description here](http://i.stack.imgur.com/L4Rik.jpg) Is there a way to query Datasets across levels like this? This seems extremely roundabout, but haven't figured an implementation using, say Keys and Values and related Dataset operators.


title: Finding Symmetries of Points on a Sphere

text: Currently, I am working on a project where I would like to find symmetries of points plotted on a sphere. One example would be to rotate the sphere 180 degrees about the x-axis and the picture would look the same. I am looking through many different formations of points and am wondering whether or not there is a way to speed it up and to increase the accuracy. Is there a function to find rotational symmetries about different axes (as they are not limited to x,y, and z)? If relevant, my points are currently in cartesian form, but I also have them available as spherical coordinates. Thanks! -Chase


title: A few specific questions on a number of plots in a do loop

text: I have created the picture displayed below, with the following line of code:               Colors = List[Brown, Red, Orange, Yellow, Green, Blue, Pink, Purple, Black];         Show[Table[            Plot[Part[list, i, 2]*Prob[Part[list, i, 2]*n] /. {y -> a,               z -> Part[list, i, 3]}, {n, 0, 3},             PlotStyle -> {Thick, Part[Colors, i]}], {i, Length[list]}],           PlotRange -> {All, {0, 1.2}}]      The array list just contains sum numbers of the form { {a,b,c}, {c,d,e}, ...} and Prob is just some function, with constants y and z which I specify in the above. There are a few questions I have concerning this code: -Note that the axis of the graph appears to lie above zero. I would like to make a graph with its x axis really at y=0. How to do this? -I would like to give every graph in the picture a different label, which is stored in Part[list, i,2]. However, I have two problems: PlotLegends gives an error and I only know how to include text between " ", not a number which is determined by the running of the do loop.  Any help is very much appreciated! ![enter image description here](http://i.stack.imgur.com/iInR3.png)


title: Recursive function with if-statement

text: I am trying to represent the following function definition in Mathematica: $$\begin{align*} f(1)&=1 \\\ f(2n)&= \begin{cases}f(n) & \text{if}\space n\equiv0\pmod{2} \\\ 2f(n) & \text{if}\space n\equiv1\pmod{2}\end{cases} \\\ f(2n+1)&=\begin{cases}2f(n)+1 & \text{if}\space n\equiv0\pmod{2} \\\ f(n) & \text{if}\space n\equiv1\pmod{2}\end{cases} \end{align*}$$ I have tried both the following definitions, but both of them return `f[2011]` as their output when I input `f[2011]` into the kernel. Using _if-statements_ :               f[1] := 1     f[2 n_] := If[Mod[n, 2] == 0, f[n], 2 f[n]]     f[2 n_ + 1] := If[Mod[n, 2] == 0, 2 f[n] + 1, f[n]]      And using _switch-statements_ :               f[1] := 1     f[2 n_] := Switch[Mod[n, 2], 0, Evaluate[f[n]], 1, 2 Evaluate[f[n]]]     f[2 n_ + 1] := Switch[Mod[n, 2], 0, 2 Evaluate[f[n]] + 1, 1, Evaluate[f[n]]]      Neither of these definitions seem to give me what I'm after, so I'd appreciate any help.


title: ParallelTable running on outermost index only

text: I need to run a simple `ParallelTable`:               ParallelTable[       {tab1[[i1]], tab2[[i2]], tab3[[i3]], tab4[[i4]],        fun[tab1[[i1]],tab2[[i2]],tab3[[i3]],tab4[[i4]]]       },        {i1, 1, n1}, {i2, 1, n2}, {i3, 1,n3}, {i4, 1, n4}     ]      The computation, however, is parallelized only on the outermost index `i1` and not on all of them. The problem is that I have more cores than `n1` and so I'm not computing this table as fast as I had hoped. Is there a simple way to run on as many cores as possible without having to rewrite the table in a flattened version?


title: Can not Import PDF

text: I try to import PDF and extract text from it               Import["D:\\Vegetarian MS.pdf", {"PDF", "Plaintext"}]      but with some files I have a problem like this               Import::general: Unimplemented operator ' encountered >>          Import::general: Could not draw page 1 stream 0 >>          Import::general: Could not draw page 1 >>      How can I solve this? Thank you link to file http://dl.dropbox.com/u/15137276/Vegetarian%20MS.pdf


title: How to output an expression to an external file in "plain text" format without breaking lines?

text: Given a pretty long expression, such as               a={-11 ψ^2 λ[1]+6 ψ λ[2],35 ψ^2 λ[2],11 ψ^2 λ[1]^2-11 ψ^2 λ[2]-6 ψ λ[1] λ[2],ψ^2 λ[1]^2-ψ^2 λ[2]-ψ λ[1] λ[2]+λ[2]^2,-λ[1]^3+2 λ[1] λ[2],-3 ψ λ[1]^3+6 ψ λ[1] λ[2]+λ[1]^2 λ[2]-λ[2]^2,-ψ λ[1]^3+λ[1]^4+2 ψ λ[1] λ[2]-3 λ[1]^2 λ[2]+λ[2]^2}      `a >> tmp` would output the expression of `a` to an external file `tmp`. But I don't like the format in this output. It breaks lines, and contains extra spaces between operators of "+-*/". In fact, in _Mathematica_ , selecting an expression, we could do **(right click)** > **Copy as** > **Plain Text** , and then we could paste it to any external text editor without any problem. Is it possible to specify the output stream using this "Plain Text" format above?


title: What is the simplest way to determine which call to a superfunction has generated a Message?

text: I have a complicated function which contains many calls to `NIntegrate`, `NSolve`, `FindRoot` and other superfunctions in many places. My function is organized in such a way that every call to a superfunction is assigned to unique `Block`ed variable. Sometimes these functions produce `Messages` but it is not obvious which call has generated the message. I wish to find a straighforward way to know which call has generated the message. It would be great to include this information in the `Message` itself but just printing this information before/after the `Message` would be sufficient. I know that there is undocumented function `Internal`HandlerBlock` which seemingly can do such tasks but I do not know how to restrict it to handle only _printed_ messages. For example,               Internal`HandlerBlock[{"Message",        If[MatchQ[#, Hold[_, True]], Print[#]] &},       NIntegrate[Cos[20000 x]/Sqrt[x], {x, 0, 1}]]      Produces many prints but only one of them corresponds to the actually printed one `Message`.


title: Constructing variable names from a string

text: I have groups of descriptive variable names and dont want to write explicit code for each group, e.g. (and this is a contrived simplification)               EnergySensorALow[1]=somefuncALow[#]& /@ lstSensorA;     EnergySensorAHigh[1]=somefuncAHigh[#]& /@ lstSensorA;     EnergySensorBLow[1]=somefuncALow[#]& /@ lstSensorB;     EnergySensorBHigh[1]=somefuncAHigh[#]& /@ lstSensorB;      etc. I want create a function that should work as follows:               fnew[sensorType_String]:=                                 "EnergySensor"+sensorType+"Low[1]"="somefunc"+sensorType+"Low"[#]& /@                                "lstSensor"+sensorType;      So the function will take an input String, e.g. "A" and then refer to an existing variable name **EnergySensorALow[1]** , which it will set equal to an existing function **somefuncALow[#] &** and map this over an existing list **lstSensorA** The code will also be run periodically when the sensor values update, and each time the function needs to be applied to the list and stored in the appropriate "EnergySensor" variable name. The variable index[n] makes it easy to use the data in a Manipulate and select which dataset needs to be plotted, I prefer not to add additional indexes to accomplish the functionality I need. Any suggestions?


title: How to align grid dividers of inner grids in a grid?

text: How to have the vertical dividers of inner grids aligned to each other in the following?               Grid[{     {"12",Grid[{{"1","2"},{"foo","bar"}},Dividers-> All]},     {"xxxx",Grid[{{"1","2"},{"foooo","barbar"}},Dividers-> All]}     },     Dividers-> All     ]      ![enter image description here](http://i.stack.imgur.com/hBr2Y.png)


title: The difference between "SymbolicProcessing" -> 0 and restricting the function definition to numeric values only

text: The Documentation tells us that there are two ways to disable symbolic processing of the integrand by the `NIntegrate` function when it is known that it just slows down the computation. One way is documented and heavily used on the Documentation page "NIntegrate Integration Strategies" and some other Documentation pages:               Method -> {Automatic, "SymbolicProcessing" -> 0}      Another approach is to define the integrand as a "black-box" function and this way is recommended in the "Possible Issues" section of the `NIntegrate` documentation page. Let us compare:               f[x_] := Nest[Sin[# + Sin[2 #]] &, x, 20]     NIntegrate[f[x], {x, 0, 1},        Method -> {Automatic, "SymbolicProcessing" -> 0}] // Timing          (* => {2.797, 0.947747} *)          g[x_?NumericQ] := Nest[Sin[# + Sin[2 #]] &, x, 20]     NIntegrate[g[x], {x, 0, 1}] // Timing          (* => {0.032, 0.947747} *)      One can see the two-order speedup of the "black-box" over the `Method` option. What is the reason? Are there cases when the `Method` option have advantages over the "black-box" approach? In which cases it is recommended to use one or another?


title: What is the natural way of using Dataset to get a FittedModel?

text: The new Dataset in Mathematica 10 is a great addition to the language, potentially reducing the convenience gap with R. Given this, I would like to understand what the equivalent simple or natural workflow in Mathematica is for a model fit. In R, one can set up a data frame by columns (`c` creates a vector):               dataset=data.frame(days=c(1,2,6,8),area=c(3,6,8,2),frequency=c(1,4,4,2),height=c(2,3,11,6))      which is displayed like this:                 days area frequency height     1    1    3         1      2     2    2    6         4      3     3    6    8         4     11     4    8    2         2      6      You can then fit a model using a model formula:               fit=lm(height~days+area,data=dataset)      You could view the coefficients, for example, with `coef(fit)`               (Intercept)        days        area       -2.8167116   0.9198113   0.9278976      In Mathematica one option that occurs to me is:               dataset = Dataset[MapThread[Association, Thread /@ {"days" -> {1, 2, 6, 8},      "area" -> {3, 6, 8, 2}, "frequency" -> {1, 4, 4, 2}, "height" -> {2, 3, 11, 6}}]]     LinearModelFit[dataset[[All, {"days", "area", "height"}]] // Normal // Values,      {days, area}, {days, area}]      The specific questions are:   1. What is a more natural way to create the Dataset in Mathematica? I find it helpful to have the data specified by columns and for the column name to be near the data, but if that idiom is not natural in Mathematica, that would be good to know.   2. Is there a simpler way to do the fit, perhaps one as straightforward as the R approach? Specifying the column names is important for experimentation and model selection when the number of potential variables is large. Given some comments below, here are some clarifications:   * In R the data frame is a core structure and it is manipulated in many ways e.g. by combining data frames, adding new columns, modifying existing columns etc. My underlying interest is to understand to what extent Dataset can play this role. I think the column view is pretty important for this.   * Functional wrappers can be written to suit an individual's way of doing things. However, I am interested to know if there is any fundamental or natural way of approaching this in Mathematica. There is clearly a natural way to do it in R.


title: Better code for two variable fractal interpolation functions

text: I am trying to write code for 2-variable fractal interpolation functions using two iterated function systems and two starting functions (both $y(x)=x$) which creates a sequence of piecewise defined functions using iterated functions systems(IFS) that converges to an element of the single superfractal. There is randomness involved so each run generates a different attractor. I am not familiar with most of _Mathematica_ 's built in features, so the best I could do involved too many if-statements. The code is very long due to the fact that at each stage of the iteration process (and for each function in the chosen IFS) one of the two previous stage's functions is used. The code plots the first four stages of the two sequences of functions. There must be an easier way and any help would be much appreciated.               {a1, b1} = {.25, .4}; {a2, b2} = {.28, .22}; {a3,        b3} = {.3, .26}; {a4, b4} = {.32, .1}; {a5, b5} = {.7, .8}; {a6,        b6} = {.73, .6}; {a7, b7} = {.78, .8}; {a8, b8} = {.8, .6};     {c1, d1} = {.20, .45}; {c2, d2} = {.25, .3}; {c3,        d3} = {.28, .45}; {c4, d4} = {.32, .2}; {c5, d5} = {.6, .75}; {c6,        d6} = {.7, .65}; {c7, d7} = {.8, .7}; {c8, d8} = {.83, .6};     y0[x_] := x; z0[x_] := x;          If[RandomInteger[] == 0,     If[RandomInteger[] == 0,       f1[x_] := b1*y0[x/a1],       f1[x_] := b1*z0[x/a1]];      If[RandomInteger[] == 0,       g1[x_] := (b2 - b1)*y0[(x - a1)/(a2 - a1)] + b1,       g1[x_] := (b2 - b1)*z0[(x - a1)/(a2 - a1)] + b1];      If[RandomInteger[] == 0,       h1[x_] := (b3 - b2)*y0[(x - a2)/(a3 - a2)] + b2,       h1[x_] := (b3 - b2)*z0[(x - a2)/(a3 - a2)] + b2];      If[RandomInteger[] == 0,       i1[x_] := (b4 - b3)*y0[(x - a3)/(a4 - a3)] + b3,       i1[x_] := (b4 - b3)*z0[(x - a3)/(a4 - a3)] + b3];      If[RandomInteger[] == 0,       j1[x_] := (b5 - b4)*y0[(x - a4)/(a5 - a4)] + b4,       j1[x_] := (b5 - b4)*z0[(x - a4)/(a5 - a4)] + b4];      If[RandomInteger[] == 0,       k1[x_] := (b6 - b5)*y0[(x - a5)/(a6 - a5)] + b5,       k1[x_] := (b6 - b5)*z0[(x - a5)/(a6 - a5)] + b5];      If[RandomInteger[] == 0,       l1[x_] := (b7 - b6)*y0[(x - a6)/(a7 - a6)] + b6,       l1[x_] := (b7 - b6)*z0[(x - a6)/(a7 - a6)] + b6];      If[RandomInteger[] == 0,       m1[x_] := (b8 - b7)*y0[(x - a7)/(a8 - a7)] + b7,       m1[x_] := (b8 - b7)*z0[(x - a7)/(a8 - a7)] + b7];      If[RandomInteger[] == 0,       n1[x_] := (1 - b8)*y0[(x - a8)/(1 - a8)] + b8,       n1[x_] := (1 - b8)*z0[(x - a8)/(1 - a8)] + b8];       y1[x_] :=        If[0 <= x < a1, f1[x],         If[a1 <= x < a2, g1[x],          If[a2 <= x < a3, h1[x],           If[a3 <= x < a4, i1[x],            If[a4 <= x < a5, j1[x],             If[a5 <= x < a6, k1[x],              If[a6 <= x < a7, l1[x], If[a7 <= x < a8, m1[x], n1[x]]]]]]]]],           If[RandomInteger[] == 0,        o1[x_] := d1*y0[1/c1*x],        o1[x_] := d1*z0[1/c1*x]];      If[RandomInteger[] == 0,        p1[x_] := (d2 - d1)*y0[(x - c1)/(c2 - c1)] + d1,        p1[x_] := (d2 - d1)*z0[(x - c1)/(c2 - c1)] + d1];      If[RandomInteger[] == 0,        q1[x_] := (d3 - d2)*y0[(x - c2)/(c3 - c2)] + d2,        q1[x_] := (d3 - d2)*z0[(x - c2)/(c3 - c2)] + d2];      If[RandomInteger[] == 0,        r1[x_] := (d4 - d3)*y0[(x - c3)/(c4 - c3)] + d3,        r1[x_] := (d4 - d3)*z0[(x - c3)/(c4 - c3)] + d3];      If[RandomInteger[] == 0,        s1[x_] := (d5 - d4)*y0[(x - c4)/(c5 - c4)] + d4,        s1[x_] := (d5 - d4)*z0[(x - c4)/(c5 - c4)] + d4];      If[RandomInteger[] == 0,        t1[x_] := (d6 - d5)*y0[(x - c5)/(c6 - c5)] + d5,        t1[x_] := (d6 - d5)*z0[(x - c5)/(c6 - c5)] + d5];      If[RandomInteger[] == 0,        u1[x_] := (d7 - d6)*y0[(x - c6)/(c7 - c6)] + d6,        u1[x_] := (d7 - d6)*z0[(x - c6)/(c7 - c6)] + d6];      If[RandomInteger[] == 0,        v1[x_] := (d8 - d7)*y0[(x - c7)/(c8 - c7)] + d7,        v1[x_] := (d8 - d7)*z0[(x - c7)/(c8 - c7)] + d7];      If[RandomInteger[] == 0,        w1[x_] := (1 - d8)*y0[(x - c8)/(1 - c8)] + d8,        w1[x_] := (1 - d8)*z0[(x - c8)/(1 - c8)] + d8];       y1[x_] :=        If[0 <= x < c1, o1[x],         If[c1 <= x < c2, p1[x],          If[c2 <= x < c3, q1[x],           If[c3 <= x < c4, r1[x],            If[c4 <= x < c5, s1[x],             If[c5 <= x < c6, t1[x],              If[c6 <= x < c7, u1[x], If[c7 <= x < c8, v1[x], w1[x]]]]]]]]]]          If[RandomInteger[] == 0,      If[RandomInteger[] == 0,       f1[x_] := b1*y0[x/a1],       f1[x_] := b1*z0[x/a1]];      If[RandomInteger[] == 0,       g1[x_] := (b2 - b1)*y0[(x - a1)/(a2 - a1)] + b1,       g1[x_] := (b2 - b1)*z0[(x - a1)/(a2 - a1)] + b1];      If[RandomInteger[] == 0,       h1[x_] := (b3 - b2)*y0[(x - a2)/(a3 - a2)] + b2,       h1[x_] := (b3 - b2)*z0[(x - a2)/(a3 - a2)] + b2];      If[RandomInteger[] == 0,       i1[x_] := (b4 - b3)*y0[(x - a3)/(a4 - a3)] + b3,       i1[x_] := (b4 - b3)*z0[(x - a3)/(a4 - a3)] + b3];      If[RandomInteger[] == 0,       j1[x_] := (b5 - b4)*y0[(x - a4)/(a5 - a4)] + b4,       j1[x_] := (b5 - b4)*z0[(x - a4)/(a5 - a4)] + b4];      If[RandomInteger[] == 0,       k1[x_] := (b6 - b5)*y0[(x - a5)/(a6 - a5)] + b5,       k1[x_] := (b6 - b5)*z0[(x - a5)/(a6 - a5)] + b5];      If[RandomInteger[] == 0,       l1[x_] := (b7 - b6)*y0[(x - a6)/(a7 - a6)] + b6,       l1[x_] := (b7 - b6)*z0[(x - a6)/(a7 - a6)] + b6];      If[RandomInteger[] == 0,       m1[x_] := (b8 - b7)*y0[(x - a7)/(a8 - a7)] + b7,       m1[x_] := (b8 - b7)*z0[(x - a7)/(a8 - a7)] + b7];      If[RandomInteger[] == 0,       n1[x_] := (1 - b8)*y0[(x - a8)/(1 - a8)] + b8,       n1[x_] := (1 - b8)*z0[(x - a8)/(1 - a8)] + b8];       z1[x_] :=        If[0 <= x < a1, f1[x],         If[a1 <= x < a2, g1[x],          If[a2 <= x < a3, h1[x],           If[a3 <= x < a4, i1[x],            If[a4 <= x < a5, j1[x],             If[a5 <= x < a6, k1[x],              If[a6 <= x < a7, l1[x], If[a7 <= x < a8, m1[x], n1[x]]]]]]]]],           If[RandomInteger[] == 0,        o1[x_] := d1*y0[1/c1*x],        o1[x_] := d1*z0[1/c1*x]];      If[RandomInteger[] == 0,        p1[x_] := (d2 - d1)*y0[(x - c1)/(c2 - c1)] + d1,        p1[x_] := (d2 - d1)*z0[(x - c1)/(c2 - c1)] + d1];      If[RandomInteger[] == 0,        q1[x_] := (d3 - d2)*y0[(x - c2)/(c3 - c2)] + d2,        q1[x_] := (d3 - d2)*z0[(x - c2)/(c3 - c2)] + d2];      If[RandomInteger[] == 0,        r1[x_] := (d4 - d3)*y0[(x - c3)/(c4 - c3)] + d3,        r1[x_] := (d4 - d3)*z0[(x - c3)/(c4 - c3)] + d3];      If[RandomInteger[] == 0,        s1[x_] := (d5 - d4)*y0[(x - c4)/(c5 - c4)] + d4,        s1[x_] := (d5 - d4)*z0[(x - c4)/(c5 - c4)] + d4];      If[RandomInteger[] == 0,        t1[x_] := (d6 - d5)*y0[(x - c5)/(c6 - c5)] + d5,        t1[x_] := (d6 - d5)*z0[(x - c5)/(c6 - c5)] + d5];      If[RandomInteger[] == 0,        u1[x_] := (d7 - d6)*y0[(x - c6)/(c7 - c6)] + d6,        u1[x_] := (d7 - d6)*z0[(x - c6)/(c7 - c6)] + d6];      If[RandomInteger[] == 0,        v1[x_] := (d8 - d7)*y0[(x - c7)/(c8 - c7)] + d7,        v1[x_] := (d8 - d7)*z0[(x - c7)/(c8 - c7)] + d7];      If[RandomInteger[] == 0,        w1[x_] := (1 - d8)*y0[(x - c8)/(1 - c8)] + d8,        w1[x_] := (1 - d8)*z0[(x - c8)/(1 - c8)] + d8];       z1[x_] :=        If[0 <= x < c1, o1[x],         If[c1 <= x < c2, p1[x],          If[c2 <= x < c3, q1[x],           If[c3 <= x < c4, r1[x],            If[c4 <= x < c5, s1[x],             If[c5 <= x < c6, t1[x],              If[c6 <= x < c7, u1[x], If[c7 <= x < c8, v1[x], w1[x]]]]]]]]]]          If[RandomInteger[] == 0,      If[RandomInteger[] == 0,       f2[x_] := b1*y1[x/a1],       f2[x_] := b1*z1[x/a1]];      If[RandomInteger[] == 0,       g2[x_] := (b2 - b1)*y1[(x - a1)/(a2 - a1)] + b1,       g2[x_] := (b2 - b1)*z1[(x - a1)/(a2 - a1)] + b1];      If[RandomInteger[] == 0,       h2[x_] := (b3 - b2)*y1[(x - a2)/(a3 - a2)] + b2,       h2[x_] := (b3 - b2)*z1[(x - a2)/(a3 - a2)] + b2];      If[RandomInteger[] == 0,       i2[x_] := (b4 - b3)*y1[(x - a3)/(a4 - a3)] + b3,       i2[x_] := (b4 - b3)*z1[(x - a3)/(a4 - a3)] + b3];      If[RandomInteger[] == 0,       j2[x_] := (b5 - b4)*y1[(x - a4)/(a5 - a4)] + b4,       j2[x_] := (b5 - b4)*z1[(x - a4)/(a5 - a4)] + b4];      If[RandomInteger[] == 0,       k2[x_] := (b6 - b5)*y1[(x - a5)/(a6 - a5)] + b5,       k2[x_] := (b6 - b5)*z1[(x - a5)/(a6 - a5)] + b5];      If[RandomInteger[] == 0,       l2[x_] := (b7 - b6)*y1[(x - a6)/(a7 - a6)] + b6,       l2[x_] := (b7 - b6)*z1[(x - a6)/(a7 - a6)] + b6];      If[RandomInteger[] == 0,       m2[x_] := (b8 - b7)*y1[(x - a7)/(a8 - a7)] + b7,       m2[x_] := (b8 - b7)*z1[(x - a7)/(a8 - a7)] + b7];      If[RandomInteger[] == 0,       n2[x_] := (1 - b8)*y1[(x - a8)/(1 - a8)] + b8,       n2[x_] := (1 - b8)*z1[(x - a8)/(1 - a8)] + b8];       y2[x_] :=        If[0 <= x < a1, f2[x],         If[a1 <= x < a2, g2[x],          If[a2 <= x < a3, h2[x],           If[a3 <= x < a4, i2[x],            If[a4 <= x < a5, j2[x],             If[a5 <= x < a6, k2[x],              If[a6 <= x < a7, l2[x], If[a7 <= x < a8, m2[x], n2[x]]]]]]]]],           If[RandomInteger[] == 0,        o2[x_] := d1*y1[1/c1*x],        o2[x_] := d1*z1[1/c1*x]];      If[RandomInteger[] == 0,        p2[x_] := (d2 - d1)*y1[(x - c1)/(c2 - c1)] + d1,        p2[x_] := (d2 - d1)*z1[(x - c1)/(c2 - c1)] + d1];      If[RandomInteger[] == 0,        q2[x_] := (d3 - d2)*y1[(x - c2)/(c3 - c2)] + d2,        q2[x_] := (d3 - d2)*z1[(x - c2)/(c3 - c2)] + d2];      If[RandomInteger[] == 0,        r2[x_] := (d4 - d3)*y1[(x - c3)/(c4 - c3)] + d3,        r2[x_] := (d4 - d3)*z1[(x - c3)/(c4 - c3)] + d3];      If[RandomInteger[] == 0,        s2[x_] := (d5 - d4)*y1[(x - c4)/(c5 - c4)] + d4,        s2[x_] := (d5 - d4)*z1[(x - c4)/(c5 - c4)] + d4];      If[RandomInteger[] == 0,        t2[x_] := (d6 - d5)*y1[(x - c5)/(c6 - c5)] + d5,        t2[x_] := (d6 - d5)*z1[(x - c5)/(c6 - c5)] + d5];      If[RandomInteger[] == 0,        u2[x_] := (d7 - d6)*y1[(x - c6)/(c7 - c6)] + d6,        u2[x_] := (d7 - d6)*z1[(x - c6)/(c7 - c6)] + d6];      If[RandomInteger[] == 0,        v2[x_] := (d8 - d7)*y1[(x - c7)/(c8 - c7)] + d7,        v2[x_] := (d8 - d7)*z1[(x - c7)/(c8 - c7)] + d7];      If[RandomInteger[] == 0,        w2[x_] := (1 - d8)*y1[(x - c8)/(1 - c8)] + d8,        w2[x_] := (1 - d8)*z1[(x - c8)/(1 - c8)] + d8];       y2[x_] :=        If[0 <= x < c1, o2[x],         If[c1 <= x < c2, p2[x],          If[c2 <= x < c3, q2[x],           If[c3 <= x < c4, r2[x],            If[c4 <= x < c5, s2[x],             If[c5 <= x < c6, t2[x],              If[c6 <= x < c7, u2[x], If[c7 <= x < c8, v2[x], w2[x]]]]]]]]]]          If[RandomInteger[] == 0,      If[RandomInteger[] == 0,       f2[x_] := b1*y1[x/a1],       f2[x_] := b1*z1[x/a1]];      If[RandomInteger[] == 0,       g2[x_] := (b2 - b1)*y1[(x - a1)/(a2 - a1)] + b1,       g2[x_] := (b2 - b1)*z1[(x - a1)/(a2 - a1)] + b1];      If[RandomInteger[] == 0,       h2[x_] := (b3 - b2)*y1[(x - a2)/(a3 - a2)] + b2,       h2[x_] := (b3 - b2)*z1[(x - a2)/(a3 - a2)] + b2];      If[RandomInteger[] == 0,       i2[x_] := (b4 - b3)*y1[(x - a3)/(a4 - a3)] + b3,       i2[x_] := (b4 - b3)*z1[(x - a3)/(a4 - a3)] + b3];      If[RandomInteger[] == 0,       j2[x_] := (b5 - b4)*y1[(x - a4)/(a5 - a4)] + b4,       j2[x_] := (b5 - b4)*z1[(x - a4)/(a5 - a4)] + b4];      If[RandomInteger[] == 0,       k2[x_] := (b6 - b5)*y1[(x - a5)/(a6 - a5)] + b5,       k2[x_] := (b6 - b5)*z1[(x - a5)/(a6 - a5)] + b5];      If[RandomInteger[] == 0,       l2[x_] := (b7 - b6)*y1[(x - a6)/(a7 - a6)] + b6,       l2[x_] := (b7 - b6)*z1[(x - a6)/(a7 - a6)] + b6];      If[RandomInteger[] == 0,       m2[x_] := (b8 - b7)*y1[(x - a7)/(a8 - a7)] + b7,       m2[x_] := (b8 - b7)*z1[(x - a7)/(a8 - a7)] + b7];      If[RandomInteger[] == 0,       n2[x_] := (1 - b8)*y1[(x - a8)/(1 - a8)] + b8,       n2[x_] := (1 - b8)*z1[(x - a8)/(1 - a8)] + b8];       z2[x_] :=        If[0 <= x < a1, f2[x],         If[a1 <= x < a2, g2[x],          If[a2 <= x < a3, h2[x],           If[a3 <= x < a4, i2[x],            If[a4 <= x < a5, j2[x],             If[a5 <= x < a6, k2[x],              If[a6 <= x < a7, l2[x], If[a7 <= x < a8, m2[x], n2[x]]]]]]]]],           If[RandomInteger[] == 0,        o2[x_] := d1*y1[1/c1*x],        o2[x_] := d1*z1[1/c1*x]];      If[RandomInteger[] == 0,        p2[x_] := (d2 - d1)*y1[(x - c1)/(c2 - c1)] + d1,        p2[x_] := (d2 - d1)*z1[(x - c1)/(c2 - c1)] + d1];      If[RandomInteger[] == 0,        q2[x_] := (d3 - d2)*y1[(x - c2)/(c3 - c2)] + d2,        q2[x_] := (d3 - d2)*z1[(x - c2)/(c3 - c2)] + d2];      If[RandomInteger[] == 0,        r2[x_] := (d4 - d3)*y1[(x - c3)/(c4 - c3)] + d3,        r2[x_] := (d4 - d3)*z1[(x - c3)/(c4 - c3)] + d3];      If[RandomInteger[] == 0,        s2[x_] := (d5 - d4)*y1[(x - c4)/(c5 - c4)] + d4,        s2[x_] := (d5 - d4)*z1[(x - c4)/(c5 - c4)] + d4];      If[RandomInteger[] == 0,        t2[x_] := (d6 - d5)*y1[(x - c5)/(c6 - c5)] + d5,        t2[x_] := (d6 - d5)*z1[(x - c5)/(c6 - c5)] + d5];      If[RandomInteger[] == 0,        u2[x_] := (d7 - d6)*y1[(x - c6)/(c7 - c6)] + d6,        u2[x_] := (d7 - d6)*z1[(x - c6)/(c7 - c6)] + d6];      If[RandomInteger[] == 0,        v2[x_] := (d8 - d7)*y1[(x - c7)/(c8 - c7)] + d7,        v2[x_] := (d8 - d7)*z1[(x - c7)/(c8 - c7)] + d7];      If[RandomInteger[] == 0,        w2[x_] := (1 - d8)*y1[(x - c8)/(1 - c8)] + d8,        w2[x_] := (1 - d8)*z1[(x - c8)/(1 - c8)] + d8];       z2[x_] :=        If[0 <= x < c1, o2[x],         If[c1 <= x < c2, p2[x],          If[c2 <= x < c3, q2[x],           If[c3 <= x < c4, r2[x],            If[c4 <= x < c5, s2[x],             If[c5 <= x < c6, t2[x],              If[c6 <= x < c7, u2[x], If[c7 <= x < c8, v2[x], w2[x]]]]]]]]]]          If[RandomInteger[] == 0,      If[RandomInteger[] == 0,       f3[x_] := b1*y2[x/a1],       f3[x_] := b1*z2[x/a1]];      If[RandomInteger[] == 0,       g3[x_] := (b2 - b1)*y2[(x - a1)/(a2 - a1)] + b1,       g3[x_] := (b2 - b1)*z2[(x - a1)/(a2 - a1)] + b1];      If[RandomInteger[] == 0,       h3[x_] := (b3 - b2)*y2[(x - a2)/(a3 - a2)] + b2,       h3[x_] := (b3 - b2)*z2[(x - a2)/(a3 - a2)] + b2];      If[RandomInteger[] == 0,       i3[x_] := (b4 - b3)*y2[(x - a3)/(a4 - a3)] + b3,       i3[x_] := (b4 - b3)*z2[(x - a3)/(a4 - a3)] + b3];      If[RandomInteger[] == 0,       j3[x_] := (b5 - b4)*y2[(x - a4)/(a5 - a4)] + b4,       j3[x_] := (b5 - b4)*z2[(x - a4)/(a5 - a4)] + b4];      If[RandomInteger[] == 0,       k3[x_] := (b6 - b5)*y2[(x - a5)/(a6 - a5)] + b5,       k3[x_] := (b6 - b5)*z2[(x - a5)/(a6 - a5)] + b5];      If[RandomInteger[] == 0,       l3[x_] := (b7 - b6)*y2[(x - a6)/(a7 - a6)] + b6,       l3[x_] := (b7 - b6)*z2[(x - a6)/(a7 - a6)] + b6];      If[RandomInteger[] == 0,       m3[x_] := (b8 - b7)*y2[(x - a7)/(a8 - a7)] + b7,       m3[x_] := (b8 - b7)*z2[(x - a7)/(a8 - a7)] + b7];      If[RandomInteger[] == 0,       n3[x_] := (1 - b8)*y2[(x - a8)/(1 - a8)] + b8,       n3[x_] := (1 - b8)*z2[(x - a8)/(1 - a8)] + b8];       y3[x_] :=        If[0 <= x < a1, f3[x],         If[a1 <= x < a2, g3[x],          If[a2 <= x < a3, h3[x],           If[a3 <= x < a4, i3[x],            If[a4 <= x < a5, j3[x],             If[a5 <= x < a6, k3[x],              If[a6 <= x < a7, l3[x], If[a7 <= x < a8, m3[x], n3[x]]]]]]]]],           If[RandomInteger[] == 0,        o3[x_] := d1*y2[1/c1*x],        o3[x_] := d1*z2[1/c1*x]];      If[RandomInteger[] == 0,        p3[x_] := (d2 - d1)*y2[(x - c1)/(c2 - c1)] + d1,        p3[x_] := (d2 - d1)*z2[(x - c1)/(c2 - c1)] + d1];      If[RandomInteger[] == 0,        q3[x_] := (d3 - d2)*y2[(x - c2)/(c3 - c2)] + d2,        q3[x_] := (d3 - d2)*z2[(x - c2)/(c3 - c2)] + d2];      If[RandomInteger[] == 0,        r3[x_] := (d4 - d3)*y2[(x - c3)/(c4 - c3)] + d3,        r3[x_] := (d4 - d3)*z2[(x - c3)/(c4 - c3)] + d3];      If[RandomInteger[] == 0,        s3[x_] := (d5 - d4)*y2[(x - c4)/(c5 - c4)] + d4,        s3[x_] := (d5 - d4)*z2[(x - c4)/(c5 - c4)] + d4];      If[RandomInteger[] == 0,        t3[x_] := (d6 - d5)*y2[(x - c5)/(c6 - c5)] + d5,        t3[x_] := (d6 - d5)*z2[(x - c5)/(c6 - c5)] + d5];      If[RandomInteger[] == 0,        u3[x_] := (d7 - d6)*y2[(x - c6)/(c7 - c6)] + d6,        u3[x_] := (d7 - d6)*z2[(x - c6)/(c7 - c6)] + d6];      If[RandomInteger[] == 0,        v3[x_] := (d8 - d7)*y2[(x - c7)/(c8 - c7)] + d7,        v3[x_] := (d8 - d7)*z2[(x - c7)/(c8 - c7)] + d7];      If[RandomInteger[] == 0,        w3[x_] := (1 - d8)*y2[(x - c8)/(1 - c8)] + d8,        w3[x_] := (1 - d8)*z2[(x - c8)/(1 - c8)] + d8];       y3[x_] :=        If[0 <= x < c1, o3[x],         If[c1 <= x < c2, p3[x],          If[c2 <= x < c3, q3[x],           If[c3 <= x < c4, r3[x],            If[c4 <= x < c5, s3[x],             If[c5 <= x < c6, t3[x],              If[c6 <= x < c7, u3[x], If[c7 <= x < c8, v3[x], w3[x]]]]]]]]]]          If[RandomInteger[] == 0,      If[RandomInteger[] == 0,       f3[x_] := b1*y2[x/a1],       f3[x_] := b1*z2[x/a1]];      If[RandomInteger[] == 0,       g3[x_] := (b2 - b1)*y2[(x - a1)/(a2 - a1)] + b1,       g3[x_] := (b2 - b1)*z2[(x - a1)/(a2 - a1)] + b1];      If[RandomInteger[] == 0,       h3[x_] := (b3 - b2)*y2[(x - a2)/(a3 - a2)] + b2,       h3[x_] := (b3 - b2)*z2[(x - a2)/(a3 - a2)] + b2];      If[RandomInteger[] == 0,       i3[x_] := (b4 - b3)*y2[(x - a3)/(a4 - a3)] + b3,       i3[x_] := (b4 - b3)*z2[(x - a3)/(a4 - a3)] + b3];      If[RandomInteger[] == 0,       j3[x_] := (b5 - b4)*y2[(x - a4)/(a5 - a4)] + b4,       j3[x_] := (b5 - b4)*z2[(x - a4)/(a5 - a4)] + b4];      If[RandomInteger[] == 0,       k3[x_] := (b6 - b5)*y2[(x - a5)/(a6 - a5)] + b5,       k3[x_] := (b6 - b5)*z2[(x - a5)/(a6 - a5)] + b5];      If[RandomInteger[] == 0,       l3[x_] := (b7 - b6)*y2[(x - a6)/(a7 - a6)] + b6,       l3[x_] := (b7 - b6)*z2[(x - a6)/(a7 - a6)] + b6];      If[RandomInteger[] == 0,       m3[x_] := (b8 - b7)*y2[(x - a7)/(a8 - a7)] + b7,       m3[x_] := (b8 - b7)*z2[(x - a7)/(a8 - a7)] + b7];      If[RandomInteger[] == 0,       n3[x_] := (1 - b8)*y2[(x - a8)/(1 - a8)] + b8,       n3[x_] := (1 - b8)*z2[(x - a8)/(1 - a8)] + b8];       z3[x_] :=        If[0 <= x < a1, f3[x],         If[a1 <= x < a2, g3[x],          If[a2 <= x < a3, h3[x],           If[a3 <= x < a4, i3[x],            If[a4 <= x < a5, j3[x],             If[a5 <= x < a6, k3[x],              If[a6 <= x < a7, l3[x], If[a7 <= x < a8, m3[x], n3[x]]]]]]]]],           If[RandomInteger[] == 0,        o3[x_] := d1*y2[1/c1*x],        o3[x_] := d1*z2[1/c1*x]];      If[RandomInteger[] == 0,        p3[x_] := (d2 - d1)*y2[(x - c1)/(c2 - c1)] + d1,        p3[x_] := (d2 - d1)*z2[(x - c1)/(c2 - c1)] + d1];      If[RandomInteger[] == 0,        q3[x_] := (d3 - d2)*y2[(x - c2)/(c3 - c2)] + d2,        q3[x_] := (d3 - d2)*z2[(x - c2)/(c3 - c2)] + d2];      If[RandomInteger[] == 0,        r3[x_] := (d4 - d3)*y2[(x - c3)/(c4 - c3)] + d3,        r3[x_] := (d4 - d3)*z2[(x - c3)/(c4 - c3)] + d3];      If[RandomInteger[] == 0,        s3[x_] := (d5 - d4)*y2[(x - c4)/(c5 - c4)] + d4,        s3[x_] := (d5 - d4)*z2[(x - c4)/(c5 - c4)] + d4];      If[RandomInteger[] == 0,        t3[x_] := (d6 - d5)*y2[(x - c5)/(c6 - c5)] + d5,        t3[x_] := (d6 - d5)*z2[(x - c5)/(c6 - c5)] + d5];      If[RandomInteger[] == 0,        u3[x_] := (d7 - d6)*y2[(x - c6)/(c7 - c6)] + d6,        u3[x_] := (d7 - d6)*z2[(x - c6)/(c7 - c6)] + d6];      If[RandomInteger[] == 0,        v3[x_] := (d8 - d7)*y2[(x - c7)/(c8 - c7)] + d7,        v3[x_] := (d8 - d7)*z2[(x - c7)/(c8 - c7)] + d7];      If[RandomInteger[] == 0,        w3[x_] := (1 - d8)*y2[(x - c8)/(1 - c8)] + d8,        w3[x_] := (1 - d8)*z2[(x - c8)/(1 - c8)] + d8];       z3[x_] :=        If[0 <= x < c1, o3[x],         If[c1 <= x < c2, p3[x],          If[c2 <= x < c3, q3[x],           If[c3 <= x < c4, r3[x],            If[c4 <= x < c5, s3[x],             If[c5 <= x < c6, t3[x],              If[c6 <= x < c7, u3[x], If[c7 <= x < c8, v3[x], w3[x]]]]]]]]]]                              If[RandomInteger[] == 0,      If[RandomInteger[] == 0,       f4[x_] := b1*y3[x/a1],       f4[x_] := b1*z3[x/a1]];      If[RandomInteger[] == 0,       g4[x_] := (b2 - b1)*y3[(x - a1)/(a2 - a1)] + b1,       g4[x_] := (b2 - b1)*z3[(x - a1)/(a2 - a1)] + b1];      If[RandomInteger[] == 0,       h4[x_] := (b3 - b2)*y3[(x - a2)/(a3 - a2)] + b2,       h4[x_] := (b3 - b2)*z3[(x - a2)/(a3 - a2)] + b2];      If[RandomInteger[] == 0,       i4[x_] := (b4 - b3)*y3[(x - a3)/(a4 - a3)] + b3,       i4[x_] := (b4 - b3)*z3[(x - a3)/(a4 - a3)] + b3];      If[RandomInteger[] == 0,       j4[x_] := (b5 - b4)*y3[(x - a4)/(a5 - a4)] + b4,       j4[x_] := (b5 - b4)*z3[(x - a4)/(a5 - a4)] + b4];      If[RandomInteger[] == 0,       k4[x_] := (b6 - b5)*y3[(x - a5)/(a6 - a5)] + b5,       k4[x_] := (b6 - b5)*z3[(x - a5)/(a6 - a5)] + b5];      If[RandomInteger[] == 0,       l4[x_] := (b7 - b6)*y3[(x - a6)/(a7 - a6)] + b6,       l4[x_] := (b7 - b6)*z3[(x - a6)/(a7 - a6)] + b6];      If[RandomInteger[] == 0,       m4[x_] := (b8 - b7)*y3[(x - a7)/(a8 - a7)] + b7,       m4[x_] := (b8 - b7)*z3[(x - a7)/(a8 - a7)] + b7];      If[RandomInteger[] == 0,       n4[x_] := (1 - b8)*y3[(x - a8)/(1 - a8)] + b8,       n4[x_] := (1 - b8)*z3[(x - a8)/(1 - a8)] + b8];       y4[x_] :=        If[0 <= x < a1, f4[x],         If[a1 <= x < a2, g4[x],          If[a2 <= x < a3, h4[x],           If[a3 <= x < a4, i4[x],            If[a4 <= x < a5, j4[x],             If[a5 <= x < a6, k4[x],              If[a6 <= x < a7, l4[x], If[a7 <= x < a8, m4[x], n4[x]]]]]]]]],           If[RandomInteger[] == 0,        o4[x_] := d1*y3[1/c1*x],        o4[x_] := d1*z3[1/c1*x]];      If[RandomInteger[] == 0,        p4[x_] := (d2 - d1)*y3[(x - c1)/(c2 - c1)] + d1,        p4[x_] := (d2 - d1)*z3[(x - c1)/(c2 - c1)] + d1];      If[RandomInteger[] == 0,        q4[x_] := (d3 - d2)*y3[(x - c2)/(c3 - c2)] + d2,        q4[x_] := (d3 - d2)*z3[(x - c2)/(c3 - c2)] + d2];      If[RandomInteger[] == 0,        r4[x_] := (d4 - d3)*y3[(x - c3)/(c4 - c3)] + d3,        r4[x_] := (d4 - d3)*z3[(x - c3)/(c4 - c3)] + d3];      If[RandomInteger[] == 0,        s4[x_] := (d5 - d4)*y3[(x - c4)/(c5 - c4)] + d4,        s4[x_] := (d5 - d4)*z3[(x - c4)/(c5 - c4)] + d4];      If[RandomInteger[] == 0,        t4[x_] := (d6 - d5)*y3[(x - c5)/(c6 - c5)] + d5,        t4[x_] := (d6 - d5)*z3[(x - c5)/(c6 - c5)] + d5];      If[RandomInteger[] == 0,        u4[x_] := (d7 - d6)*y3[(x - c6)/(c7 - c6)] + d6,        u4[x_] := (d7 - d6)*z3[(x - c6)/(c7 - c6)] + d6];      If[RandomInteger[] == 0,        v4[x_] := (d8 - d7)*y3[(x - c7)/(c8 - c7)] + d7,        v4[x_] := (d8 - d7)*z3[(x - c7)/(c8 - c7)] + d7];      If[RandomInteger[] == 0,        w4[x_] := (1 - d8)*y3[(x - c8)/(1 - c8)] + d8,        w4[x_] := (1 - d8)*z3[(x - c8)/(1 - c8)] + d8];       y4[x_] :=        If[0 <= x < c1, o4[x],         If[c1 <= x < c2, p4[x],          If[c2 <= x < c3, q4[x],           If[c3 <= x < c4, r4[x],            If[c4 <= x < c5, s4[x],             If[c5 <= x < c6, t4[x],              If[c6 <= x < c7, u4[x], If[c7 <= x < c8, v4[x], w4[x]]]]]]]]]]          If[RandomInteger[] == 0,       If[RandomInteger[] == 0,        f4[x_] := b1*y3[x/a1],        f4[x_] := b1*z3[x/a1]];       If[RandomInteger[] == 0,        g4[x_] := (b2 - b1)*y3[(x - a1)/(a2 - a1)] + b1,        g4[x_] := (b2 - b1)*z3[(x - a1)/(a2 - a1)] + b1];       If[RandomInteger[] == 0,        h4[x_] := (b3 - b2)*y3[(x - a2)/(a3 - a2)] + b2,        h4[x_] := (b3 - b2)*z3[(x - a2)/(a3 - a2)] + b2];       If[RandomInteger[] == 0,        i4[x_] := (b4 - b3)*y3[(x - a3)/(a4 - a3)] + b3,        i4[x_] := (b4 - b3)*z3[(x - a3)/(a4 - a3)] + b3];       If[RandomInteger[] == 0,        j4[x_] := (b5 - b4)*y3[(x - a4)/(a5 - a4)] + b4,        j4[x_] := (b5 - b4)*z3[(x - a4)/(a5 - a4)] + b4];       If[RandomInteger[] == 0,        k4[x_] := (b6 - b5)*y3[(x - a5)/(a6 - a5)] + b5,        k4[x_] := (b6 - b5)*z3[(x - a5)/(a6 - a5)] + b5];       If[RandomInteger[] == 0,        l4[x_] := (b7 - b6)*y3[(x - a6)/(a7 - a6)] + b6,        l4[x_] := (b7 - b6)*z3[(x - a6)/(a7 - a6)] + b6];       If[RandomInteger[] == 0,        m4[x_] := (b8 - b7)*y3[(x - a7)/(a8 - a7)] + b7,        m4[x_] := (b8 - b7)*z3[(x - a7)/(a8 - a7)] + b7];       If[RandomInteger[] == 0,        n4[x_] := (1 - b8)*y3[(x - a8)/(1 - a8)] + b8,        n4[x_] := (1 - b8)*z3[(x - a8)/(1 - a8)] + b8];        z4[x_] :=         If[0 <= x < a1, f4[x],          If[a1 <= x < a2, g4[x],           If[a2 <= x < a3, h4[x],            If[a3 <= x < a4, i4[x],             If[a4 <= x < a5, j4[x],              If[a5 <= x < a6, k4[x],               If[a6 <= x < a7, l4[x], If[a7 <= x < a8, m4[x], n4[x]]]]]]]]],            If[RandomInteger[] == 0,         o4[x_] := d1*y3[1/c1*x],         o4[x_] := d1*z3[1/c1*x]];       If[RandomInteger[] == 0,         p4[x_] := (d2 - d1)*y3[(x - c1)/(c2 - c1)] + d1,         p4[x_] := (d2 - d1)*z3[(x - c1)/(c2 - c1)] + d1];       If[RandomInteger[] == 0,         q4[x_] := (d3 - d2)*y3[(x - c2)/(c3 - c2)] + d2,         q4[x_] := (d3 - d2)*z3[(x - c2)/(c3 - c2)] + d2];       If[RandomInteger[] == 0,         r4[x_] := (d4 - d3)*y3[(x - c3)/(c4 - c3)] + d3,         r4[x_] := (d4 - d3)*z3[(x - c3)/(c4 - c3)] + d3];       If[RandomInteger[] == 0,         s4[x_] := (d5 - d4)*y3[(x - c4)/(c5 - c4)] + d4,         s4[x_] := (d5 - d4)*z3[(x - c4)/(c5 - c4)] + d4];       If[RandomInteger[] == 0,         t4[x_] := (d6 - d5)*y3[(x - c5)/(c6 - c5)] + d5,         t4[x_] := (d6 - d5)*z3[(x - c5)/(c6 - c5)] + d5];       If[RandomInteger[] == 0,         u4[x_] := (d7 - d6)*y3[(x - c6)/(c7 - c6)] + d6,         u4[x_] := (d7 - d6)*z3[(x - c6)/(c7 - c6)] + d6];       If[RandomInteger[] == 0,         v4[x_] := (d8 - d7)*y3[(x - c7)/(c8 - c7)] + d7,         v4[x_] := (d8 - d7)*z3[(x - c7)/(c8 - c7)] + d7];       If[RandomInteger[] == 0,         w4[x_] := (1 - d8)*y3[(x - c8)/(1 - c8)] + d8,         w4[x_] := (1 - d8)*z3[(x - c8)/(1 - c8)] + d8];        z4[x_] :=         If[0 <= x < c1, o4[x],          If[c1 <= x < c2, p4[x],           If[c2 <= x < c3, q4[x],            If[c3 <= x < c4, r4[x],             If[c4 <= x < c5, s4[x],              If[c5 <= x < c6, t4[x],               If[c6 <= x < c7, u4[x],                If[c7 <= x < c8, v4[x], w4[x]]]]]]]]]];          GraphicsRow[{Show[Plot[y1[x], {x, 0, 1}],         PlotRange -> {{0, 1}, {0, 1}}],        Show[Plot[z1[x], {x, 0, 1}], PlotRange -> {{0, 1}, {0, 1}}]},       ImageSize -> {Large}]     GraphicsRow[{Show[Plot[y2[x], {x, 0, 1}],         PlotRange -> {{0, 1}, {0, 1}}],        Show[Plot[z2[x], {x, 0, 1}], PlotRange -> {{0, 1}, {0, 1}}]},       ImageSize -> {Large}]     GraphicsRow[{Show[Plot[y3[x], {x, 0, 1}],         PlotRange -> {{0, 1}, {0, 1}}],        Show[Plot[z3[x], {x, 0, 1}], PlotRange -> {{0, 1}, {0, 1}}]},       ImageSize -> {Large}]     GraphicsRow[{Show[Plot[y4[x], {x, 0, 1}],         PlotRange -> {{0, 1}, {0, 1}}],        Show[Plot[z4[x], {x, 0, 1}], PlotRange -> {{0           , 1}, {0, 1}}]}, ImageSize -> {Large}]


title: Ways to access lists inside lists

text: I have gone through some reference material but I am not getting really good links that will help me grow understanding of `pure functions,patterns and list manipulations combined together`. Most of the examples referred in documentation are for single list(without sublists). For example, say from a list I wanted to pick first element of every sublist, say,`fi = FactorInteger[12]`so I used               Table[fi[[i, 1]], {i, 1, Length[fi]}]      I try to do everything with `Table`. Though it should be achievable via other simple ways too. Can someone please put some examples where one can get to learn how to access data from lists of sublists and how to decompose it. This might sound pretty trivial to lot of people but I couldn't find books and links either that can give insight into combining these Mathematica features together.


title: Using ImplicitRegion to define an ellipse around Multinormal distribution for integration

text: I have both a 2D 'MultinormalDistribution', and also a single xy point, and I would like to be able to calculate the probability of this point (given the multinormal distribution) and also plot an ellipse with the same probability as this point around the mean of the distribution. So far I have defined the Multinormal (xy) distribution like:               bvn = MultinormalDistribution[{-3.89764, 1.29137}, {{0.08369444426^2, 0}, {0, 0.0175124^2}}]      I also have the fixed point in this xy plane, at -3.98529, 1.30482. Previously (thanks to help from users ubpdqn and Karsten 7 in a previous question) I approached this by essentially doing two-tailed Gaussian integrals in both of the normal distributions that make up the multinormal distribution, which gave me the probability inside a square, represented visually with:               Plot3D[PDF[bvn, {x, y}], {x, -4.5, -3.5}, {y, 1.2, 1.4}, PlotRange -> All,    MeshFunctions -> {#1 &, #2 &}, Mesh -> {{xl = -3.98529, xu = -3.80999}, {yl = 1.27792, yu = 1.30482}}]      ![enter image description here](http://i.stack.imgur.com/aR3CB.png) I realize now that this square isn't exactly what I want, and instead I want to define an ellipse of constant probability around the mean, consistent with this xy point. ubpdqn suggested several approaches to performing the integration in the square, including:               NIntegrate[PDF[bvn, {x, y}], {x, xl, xu}, {y, yl, yu}]      and:               reg = ImplicitRegion[xl < x < xu && yl < y < yu, {x, y}]      NIntegrate[PDF[bvn, {x, y}], {x, y} \[Element] reg]      I have attempted to modifiy this implicit region such that it becomes an ellipse centered on the mean of the multinormal distribution (-3.89764, 1.29137), and bounded by the xy point like this:               xl = -3.98529;     yl = 1.27792;     xc = -3.89764;     yc = 1.29137;     reg2 = ImplicitRegion[((x - xc)^2/xl^2) + ((y - yc)^2/yl^2) == 1, {x,y}];     NIntegrate[PDF[bvn2, {x, y}], {x, y} \[Element] reg2]      Although this isn't yielding a sensible answer so it is clear to me that I'm doing something wrong. If anyone could suggest a modification to my approach I would be very grateful.


title: How do I constrain variables to a user-defined domain in ArgMax?

text: I am trying to `ArgMax` a function over `x`, but `x` is only defined between `[0,1]` How do I do that? I have tried:               ArgMax[f1[x], x ∈ [0,1]]      But it gave me an error. "{x}[Element]" cannot be followed by "[0,1]".


title: How can I generate a legend for a BubbleChart?

text: Is there a way to make a nice disk radius legend (with linear or log scale) for a BubbleChart[]? Something like the following example should be built in! ![enter image description here](http://i.stack.imgur.com/4hNYK.png)


title: An recurrence equation that can be solved in version 7 but not in version 8

text: A friend of mine showed me this code sample:               RSolve[{a[n] == a[n - 5] + 1, Sequence @@ Table[a[i] == 1, {i, 5}]}, a[n], n] // Timing      It's solved by version 7 in about 40s, while in version 8 it keeps running for more than 10 minutes… is it a bug?


title: How to change FieldSize to be the same as dropdown menu width in PopupMenu?

text: I've tried the following code to change the `FieldSize` but I can't make it equal the actual value of `MenuSize` and I tried to remove first `Delimiter` but I can't.               ActionMenu["PopupMenu",       Flatten@Table[{Delimiter, lable1}, {ittration3, 1, 3}],       Appearance -> "PopupMenu", Enabled -> True,       Background -> RGBColor[0.235, 0.486, 0.768], FieldSize -> 6]      And please tell me how to change the background color of the field.


title: How to use this Lorentzian function fit my data, I tried NonlinearModelFit, it always resulted with an error

text: The data is uploaded to Ideone http://ideone.com/ktIbVk , my code is :               data = ReadList["-10dBm.txt", {Number, Number}];     model = a/((b - f)/c)^2 + d;     result = NonlinearModelFit[data, model, {a, b, c, {d, 0}}, f];     result1 = result["ParameterTable"];     fitplot1 = plot[result[f], {f, 4.124, 4.133}];      the error is :               NonlinearModelFit::cvmit:     Failed to converge to the requested accuracy or precision within 100 iterations      Any ideas?


title: How can I remove edges from my DiscretePlot?

text: By default, `DiscretePlot` displays "edges" along the sides and, prominently, align the top when `ExtentSize -> Full` is set. For example               DiscretePlot[{0.0273981, 0.0161957, 0.0164603, 0.0200524, 0.0235201,         0.0291751, 0.0203139, 0.00744914, 0.0206204, 0.0215697, 0.0841179,         0.0243641, 0.0200671, 0.0262562, 0.0268045, 0.0398572, 0.030682,         0.0279297, 0.0266079, 0.0303529, 0.0301269, 0.030297, 0.0111498,         0.0292085, 0.0334679, 0.0300855, 0.0264582, 0.0237181, 0.0287921,         0.0267715, 0., 0.0278168, 0.0267868, 0.0206096, 0.0223239,         0.0178952, 0.00802177, 0.020115, 0.0227009, 0.0238601}[[x]], {x, 1,        40}, PlotRange -> Full, ExtentSize -> Full, PlotStyle -> Gray]      produces ![](http://i.stack.imgur.com/XQOdC.png) How can I eliminate these features so that the bars are colored and shaded evenly throughout.


title: How can I control the behavior of a Manipulate with check boxes and radio buttons?

text: I've been stuck for a long time on this problem, and I really would appreciate if somebody helps me move in the right direction. I have two functions and each can take one of two forms. I am interested in seeing the sum of these functions. I would like to see a single plot all the time instead of the configuration I show in the code posted below. I want two checkboxes (one for AU and one for TU. If one of these boxes is checked, then I want to be able to choose with radio buttons which form (AU1 or AU2) is plotted. So my `Manipulate` should have two check boxes and beneath of each two radio buttons. The plot should always show the functions if both check boxes are checked. For example, if AU1 and TU2 are checked, I want to see AU1 + TU2, but if TU is not checked, I only want to see AU1. The radio buttons select which form of of AU or TU is used to form the sum when both functions are checked. Is my problem with `Control@...`? I tried things like:               Style[Control@{{x, 1, ""}, {3 -> "AU1", 1 -> "AU2"}, ControlType -> RadioButtonBar}, Blue]       but that didn't get me anywhere. I think there are two things:   1. I need to rethink the structure I built with `If` expressions.   2. I need to know how to build a structure with checked check boxes being able to enable and disable radio buttons. Here is my code and an image:                Manipulate[         Show[          If[f11, {Plot[ ( Exp[-p]), {p, 0, 1},             PlotStyle -> {Thickness[0.006], Red}, PlotPoints -> 200,             AxesLabel -> {p, U}]}, {}],          If[f12, {Plot[ (3 *p), {p, 0, 1},             PlotStyle -> {Thickness[0.006], Red}, PlotPoints -> 200,             AxesLabel -> {p, U}]}, {}],           If[f21, {Plot[ (-4) (p - 3), {p, 0, 1},             PlotStyle -> {Thickness[0.006], Green}, PlotPoints -> 200,             AxesLabel -> {p, U}]}, {}],           If[f22, {Plot[3, {p, 0, 1}, PlotStyle -> {Thickness[0.006], Green},             PlotPoints -> 200,            AxesLabel -> {p, U}]}, {}],          If[f41, {Plot[  Exp[-p] + (-4) (p - 3), {p, 0, 1},             PlotStyle -> {Thickness[0.006], Orange}, PlotPoints -> 200,             AxesLabel -> {p, U}]}, {}],          If[f42, {Plot[ (3 *p) + (-4) (p - 3), {p, 0, 1},             PlotStyle -> {Thickness[0.006], Orange}, PlotPoints -> 200,             AxesLabel -> {p, U}]}, {}],          If[f51, {Plot[( Exp[-p]) + 3 , {p, 0, 1},             PlotStyle -> {Thickness[0.006], Blue}, PlotPoints -> 200,             AxesLabel -> {p, U}]}, {}],          If[f52, {Plot[ (3 *p) + 3, {p, 0, 1},             PlotStyle -> {Thickness[0.006], Blue}, PlotPoints -> 200,             AxesLabel -> {p, U}]}, {}],        PlotRange -> All, ImageSize -> 450],             {{f11, False, Style["(AU_1)", 12, Bold, Red]}, {True, False}},        {{f12, False, Style["(AU_2)", 12, Bold, Red]}, {True, False}},        {{f21, False, Style["(TU_1)", 12, Bold, Green]}, {True, False}},        {{f22, True, Style["(TU_2)", 12, Bold, Green]}, {True, False}},        {{f41, True, Style["(AU_1 + TU_1)", 12, Bold, Orange]}, {True,False}},        {{f42, False, Style["(AU_2 + TU_1)", 12, Bold, Orange]}, {True,False}},        {{f51, False, Style["(AU_1 + TU_2)", 12, Bold, Blue]}, {True, False}},        {{f52, False, Style["(AU_2 + TU_2)", 12, Bold, Blue]}, {True, False}},             AppearanceElements -> "ResetButton",        ControlPlacement -> Left]      ![](http://i.stack.imgur.com/l1hj6.png)


title: How can I change a list to a sequence without destroying nested list

text: I defined a function `f` like               f[x___, y_] := something;      and if `x`s and `y` are all number, when I use this function, I would input like this:               f[1, 5, 3, 6, 3]      For this, `x = Sequence[1, 5, 3, 6]` and `y = 3`. Suppose that I have a list `l = {1, 5, 3, 6}`. Then I might use `f` like               f[l /. List -> Sequence, 3]      using `ReplaceAll` to convert `List` to `Sequence`. It is very good way to convert I think. But, the problem is, when I want to input               f[1, {5, 3}, 6, 3]      which is given by `l = {1, {5, 3}, 6}`, if I use `/.`, `ReplaceAll`, `{5, 3}` is also converted into the sequence so the whole input becomes `f[1, 5, 3, 6, 3]`, not `f[1, {5, 3}, 6, 3]`. I have searched several alternative functions like `Replace` which includes a `levelspec` option. But `Replace` can not convert `List`. How can I convert without loss of inside lists?


title: Time-efficient creation of matrix

text: I have expressions like               xx1=FF[1, 1] GG[1, 1] + FF[1, 1] GG[2, 2] + FF[2, 2] GG[2, 2]     xx2=2*FF[1, 2] GG[1, 1] + FF[1, 1] GG[1, 2] + FF[2, 2] GG[2, 2]      and I want to transform it to special matrices               CreateMatrix[xx1] (* {{1, 1}, {0, 1}} *)     CreateMatrix[xx2] (* {{0, 1, 0}, {2, 0, 0}, {0, 0, 1}} *)      The logic of `CreateMatrix` is that we construct a grid like this (here using elements from `xx1`):               {{FF[1, 1] GG[1, 1], FF[1, 1] GG[2, 2]},       {FF[2, 2] GG[1, 1], FF[2, 2] GG[2, 2]}}      and if say `FF[1,1] GG[1,1]` exists in the expression then its coefficient takes the place of `F[1,1], GG[1,1]` in the grid. Elements that exist in the grid but not in the expression are taken to be zero. My code works, but is slow (it runs a double-for-loop to fill the matrix):               CreateMatrix[state_] := (       ElementsFF = Union[Cases[state, _FF, {0, Infinity}]];       ElementsGG = Union[Cases[state, _GG, {0, Infinity}]];       MatrixSize = Length[ElementsFF];       startTime = AbsoluteTime[];       If[MatrixSize > 0,        dM = IdentityMatrix[MatrixSize];        For[k = 1, k <= MatrixSize, k++,         For[l = 1, l <= MatrixSize, l++,           dM[[k, l]] = state /. {ElementsFF[[k]]*ElementsGG[[l]] -> 1};           ];         ];        Block[{FF}, FF[__] = 0; dM = dM];        Print["After MatrixConstr: " <> ToString[AbsoluteTime[] - startTime]];         startTime = AbsoluteTime[];,        dM = 0;        ];       Return[dM];       )          xx1= FF[1, 1] GG[1, 1] + FF[1, 1] GG[2, 2] + FF[2, 2] GG[2, 2]     CreateMatrix[xx1]      A small part of the code is already optimized from an earlier partial question. > Can you create a faster algorithm for the given problem? **Comparison** I test with three huge matrices (those which I need later). _My original approach_   * {136.7564571, 51.4342097, 20.0780016} seconds _kguler's solution_   * {123.7996434, 46.8804843, 19.1074500} seconds _Mr.Wizard's solution1_   * {123.3144573, 47.5587309, 18.2832670} seconds _Mr.Wizard's solution2_   * {0.0510345, 0.0315209, 0.0255171} seconds (!!!)


title: Manipulate crashes after running 4 minutes

text: The following code generates the familiar 3D-plot:                   Manipulate[      Plot3D[Sin[x a] - Cos[y ], {x, -10, 10}, {y, -10, 10},        ColorFunction -> "TemperatureMap"], {a, -2, 2, 0.1}]      However approximately 4 minutes after pressing the play-button, Mathematica 10.0.0 crashes. I noticed the memory usage increased to about 3GB and then crashed. (I run on a MacBook Pro 2.6 GHz, 16 GB) Can anyone replicate this problem ?


title: Can TemporalData be used as a container for TimeSeries and TimeSeries Metadata

text: When I create two `TimeSeries` with some `MetaInformation` I can combine them into one `TemporalData` object. But I lose the `MetaInformation` for the `TimeSeries` objects.               ts1 = TimeSeries[{{1, 2}, {2, 5}, {3, 7}, {4, 3}}, MetaInformation -> {"signaalnaam" -> "CR1HAH90", "Eenheid" -> "m^3"}]     ts2 = TimeSeries[{{1, 4}, {2.5, 2}, {4, 4}}, ResamplingMethod -> {"Interpolation", InterpolationOrder -> 0}, MetaInformation -> {"signaalnaam" -> "CR1HAH98", "Eenheid" -> "m^2"}]          td = TemporalData[{ts1, ts2}]      In `td` the `MetaInformation` of `ts2` is gone. Is this by design?


title: Obsolete AstronomicalData - how to convert to PlanetData

text: As of _Mathematica_ version 10, `AstronomicalData` is obsolete, deprecated in favor of `PlanetData`, `CometData`, `MinorPlanetData`, `PlanetaryMoonData`, `ExoplanetData`, `StarData`, `GalaxyData`, `NebulaData`, `PulsarData`, and friends. (It still works, but who knows how long for?) There are also many other changes, such as units/quantities, and DateObjects, which I'm struggling with for the first time. How would I update code like this:               Table[AstronomicalData["Jupiter", {"Declination", x}],         {x, DayRange[{2014, 1, 1}, {2014, 1, 31}]}]      to produce a series of simple numbers, because in version 9, this code produced this:               {22.5875, 22.6058, 22.6241, 22.6423, 22.6603, 22.6782, 22.6960,       22.7136, 22.7310, 22.7483, 22.7653, 22.7822, 22.7988, 22.8152,       22.8314, 22.8474, 22.8631, 22.8785, 22.8937, 22.9086, 22.9233,       22.9377, 22.9518, 22.9656, 22.9791, 22.9924, 23.0053, 23.0179,       23.0302, 23.0422, 23.0539}      So far, using version 10 I've managed to get as far as this:               Table[PlanetData["Jupiter",         EntityProperty["Planet",             "Declination", {"Date" -> DateObject[x]}]],         {x, DayRange[{2014, 1, 1}, {2014, 1, 31}]}]      but it still produces a list of things which don't look or act like numbers: ![odd output](http://i.stack.imgur.com/8pbS0.png)


title: Result of Integrate depends on order of integration although the domain is rectangular

text: The following:               Mass/(2 J)       Integrate[(-2 Rotation (r^2 (r - Mass) (1 - 3 Cos[θ]^2) - Rotation^2 (r Cos[θ]^2 (3 - Cos[θ]^2) -        Mass (1 + Cos[θ]^2) (2 - Cos[θ]^2))))/(r^2 + Rotation^2 Cos[θ]^2)^2 Sin[θ], {r, r1, ∞}, {θ, 0, π},        Assumptions -> r1 > 0 && Rotation >= 0 && Mass > 0]      yields > >     (1/(6 J r1^2 Rotation^2))Mass (r1 Rotation (12 r1^3 + >     8 r1 Rotation^2 - 3 Mass (6 r1^2 + π r1 Rotation + 2 Rotation^2)) + >     6 Mass r1^2 Rotation^2 ArcTan[r1/Rotation] + 6 (-2 r1^3 (r1^2 + > Rotation^2)+ >     Mass (3 r1^4 + 3 r1^2 Rotation^2 - Rotation^4)) ArcTan[Rotation/r1]) >   in v.9.0.1 and > >     (1/(6 J r1^2 Rotation^2))Mass (2 r1^2 (6 r1^2 Rotation + 4 Rotation^3 - > 3 π r1 (r1^2 + Rotation^2)) + >     3 Mass (-2 r1 Rotation (3 r1^2 + Rotation^2) + π (3 r1^4 + 2 r1^2 > Rotation^2 - Rotation^4)) + >     6 (r1^2 + Rotation^2) (2 r1^3 + Mass (-3 r1^2 + > Rotation^2))ArcTan[r1/Rotation]) >   in v.10.0.0. If I switch the order of integration, v.9.0.1 says that the integral diverges and v.10.0.0 does not return after tens of minutes. Numerical integration indicates that this integral converges. According to Fubini's theorem, the order of integration should not matter for rectangular domain. Why does the result depend on the order of integration? This is related to Mathematica 10 fails to calculate integral that Mathematica 9 can handle. In that case, Mathematica 10 fails to calculate the integral unless I change the order of integration. In this case, the result is wrong if I change the order of integration.


title: How can I prevent kets to from growing too large?

text: In `TraditionalForm`, _Mathematica_ formats kets incorrectly in certain expressions. For example, if used in a summation with indices indicated, a ket becomes too "tall" (red) compared to the rest of the expression: ![see the big ket](http://i.stack.imgur.com/qUDhK.png) Is there a way to prevent this gigantism? * * *               Cell[BoxData[      FormBox[       RowBox[{        RowBox[{         RowBox[{          RowBox[{           RowBox[{            RowBox[{             RowBox[{              RowBox[{"\[LeftBracketingBar]", "\[Psi]"}], "\[RightAngleBracket]"}], "=",              RowBox[{              SubscriptBox["\[Delta]", "0"],               RowBox[{"\[LeftBracketingBar]",                SubscriptBox["d", "0"]}]}]}], "\[RightAngleBracket]"}], "+", "\[Ellipsis]", "+",            RowBox[{            SubscriptBox["\[Delta]",              RowBox[{"N", "-", "1"}]],             RowBox[{"\[LeftBracketingBar]",              SubscriptBox["d",               RowBox[{"N", "-", "1"}]]}]}]}], "\[RightAngleBracket]"}], "=",          RowBox[{          UnderoverscriptBox["\[Sum]",            RowBox[{"i", "=", "0"}],            RowBox[{"N", "-", "1"}]],           RowBox[{           SubscriptBox["\[Delta]", "i"],            RowBox[{"\[LeftBracketingBar]",             SubscriptBox["d", "i"]}]}]}]}],         StyleBox["\[RightAngleBracket]",         FontColor->RGBColor[1, 0, 0]]}], TraditionalForm]], "DisplayFormula"]