Find intersection of pairs of straight lines

I have a list of 24 points, in which 2 consecutive points (1st and 2nd, 3rd and 4th, ...) are supposed to form a line.               p1={{243.8, 77.}, {467.4, 12.}, {291.8, 130.}, {476., 210.5}, {103.2,        327.}, {245.2, 110.5}, {47.4, 343.}, {87.4, 108.5}, {371.,        506.5}, {384.6, 277.}, {264.6, 525.5}, {353.8, 294.5}, {113.2,        484.5}, {296., 304.5}, {459.6, 604.5}, {320.2, 466.5}, {288.2,        630.5}, {199.6, 446.5}, {138.8, 615.5}, {81.8, 410.}, {232.4,        795.}, {461.8, 727.}, {27.4, 671.5}, {206.8, 763.5}};      I also have another list of different 24 points with the same behavior.               p2={{356.8, 32.}, {363.2, 120.}, {346., 245.}, {393.8, 158.}, {163.8,        211.5}, {230.2, 250.}, {54.6, 225.}, {139.6, 220.}, {366.,        394.5}, {451.8, 372.}, {241., 398.}, {321., 411.5}, {163.2,        347.}, {213.2, 406.5}, {332.4, 596.5}, {402.4, 528.5}, {176.,        585.5}, {256., 530.5}, {38.2, 553.}, {122.4, 507.}, {345.2,        774.5}, {345.2, 688.}, {104.6, 728.}, {161.8, 647.}};      My goal is to find the intersections between a line in p1 and a line in p2 as shown in the graph below. I really don't know how to start with this ~~, and worse, a line on p1 does not match up with the intersecting line in p2 in terms of order in each list. This could be observed by different colors of 2 intersecting lines, and makes it harder for element-by-element manipulation~~ *. How can I solve this?               Join[Partition[p1, 2], Partition[p2, 2]] // ListLinePlot      ![Join Partition line intersection](http://i.stack.imgur.com/MLpbe.png) *I found out that this is thankfully not true, as seen below when line i in p1 and line i in p2 are plotted together, and also by @Öskå in a comment to eldo's answer.               Row@Table[       ListLinePlot[{Partition[p1, 2][[i]], Partition[p2, 2][[i]]}], {i, 1,         Length@Partition[p1, 2]}]      ![line pairs](http://i.stack.imgur.com/NNQbO.png) ![lines](http://i.stack.imgur.com/FvZ0Q.gif)


How to power-series expand determinants?

Say $g$ is a matrix which is given as, $g = g_0 + xg_2 + x^2 g_4 .. +x^{d/2 -1}g_{d-2}+ x^{d/2}(g_d + h_d(log (x)))$ where $d$ is an even number and each $g_i$ is a matrix (same dimension as $g$) and $h_d$ is another matrix.   * For such a set of arbitrary matrices, how can one power-series expand $\sqrt {det(g)}$ in $x$?


Webdings are different on V10 vs V9. Why?

I use FontFamily->"Webdings" in interfaces in several places, but among other things for custom opener icons, for example I use the following "icons" for open and closed openers: ![enter image description here](http://i.stack.imgur.com/UBTWn.png) In version 10 this is what happens: ![enter image description here](http://i.stack.imgur.com/xLF7g.png) Both screen grabs are taken on the same computer. Webdings is installed. I open V9 and evaluate and take a grab. I close V9 and open V10 and do the same. I knew the Mathematica fonts were different in V10 compared to V9 but I don't understand why Webdings would be being rendered differently. I've tested a hand full of other fonts, including Wingdings, and have not observed any difference between V9 and V10. Can anyone enlighten me why Webdings is now different? I'm on OS X 10.9.4 but my interfaces have worked on both Windows and Mac with V9. **Edit** I always use OS X. On my current machine I am running OS X 10.9.4. I have V8, V9, and V10 installed. None of these have a `/SystemFiles/CharacterEncodings/Webdings.m` Regarding the error message that @m_goldberg gets when using `FromCharacterCode`. The same message occurs in V8 and V9 so I think that is irrelevant to the present issue. V8 ![enter image description here](http://i.stack.imgur.com/PBFsz.png) V9 ![enter image description here](http://i.stack.imgur.com/Okwvj.png) So the same error message occurs for `FromCharacterCode` in previous versions but it clearly has no bearing on the using of `Style[6,FontFamily->"Webdings"]`. The present issue is that you could use Webdings as a font in V8 and V9 on OS X and now you can't.


Simplifying an Integral over Two DiracDeltas

Integrate[DiracDelta[a + k] DiracDelta[-b + k], {k, -\[Infinity], \[Infinity]}]      (*DiracDelta[a + b]*)      This works fine. But                Integrate[k DiracDelta[a + k] DiracDelta[-b + k], {k, -\[Infinity], \[Infinity]}]      does not give the expected `b DiracDelta[a + b]`. Why not? How can it be fixed?


How to sum over duplicates?

I have a list of the form:               {{1, 0, 1}, {2, 1, 2}, {1, 0, 3}, {2, 4, 2}, {2, 1, -1}, {1, 0 ,0}}      that I would like to sort such that I calculate the sum over the third column whenever the first two columns are equal. I.e. in this case the output would be               {{1, 0, 1 + 3 + 0}, {2, 1, 2 + (-1)}, {2, 4, 2}}       or                {{1, 0, 4},{2, 1, 1},{2, 4, 2}}      Is there an elegant way to do this?


Efficiently compute double sum

Is there a "Mathematica Way", like Map or Apply to compute the following double sum? $\sum_{i=1}^{N_1}\sum_{j=1}^{N_2} m_i n_j \, f(\tau_{i} \gamma_{j})$ I have already stored the lists $m,n,\tau,\gamma$. $m$ and $\tau$ are of length $N_1$ and $n$ and $\gamma$ of length $N_2$. So my approach was to use something like               Outer[f, τ, γ]      for the function map, and then               Total[Total[Outer[f, τ, γ]]]      but how do Ι multiply `m`and `n` into the sum? EDIT: Undo Edit, figured out the bug in my code


How to transform and swap columns of this matrix in a simple way? Version 2

So, earlier today I asked the question How to transform this matrix & swap its columns in a simple way? and was given useful and elaborated answers. Now, I'm still not used to the "Array", "Reverse", "Map", etc. functions (which were new to me this morning) and this question is in fact a particular case of the other one : I would like to transform matrix $\mathbf A = \begin{pmatrix} a_{11}&b_{11}&a_{12}&b_{12}&a_{13}&b_{13}\\\ a_{21}&b_{21}&a_{22}&b_{22}&a_{23}&b_{23} \\\ a_{31}&b_{31}&a_{32}&b_{32}&a_{33}&b_{33} \\\ a_{41}&b_{41}&a_{42}&b_{42}&a_{43}&b_{43} \\\ a_{51}&b_{51}&a_{52}&b_{52}&a_{53}&b_{54} \\\ a_{61}&b_{61}&a_{62}&b_{62}&a_{63}&b_{63} \\\ a_{71}&b_{71}&a_{72}&b_{72}&a_{73}&b_{73} \\\ a_{81}&b_{81}&a_{82}&b_{82}&a_{83}&b_{83} \end{pmatrix}$ into matrix $\mathbf B = \begin{pmatrix} a_{83}&-b_{83}&a_{82}&-b_{82}&a_{81}&-b_{81} \\\ a_{73}&-b_{73}&a_{72}&-b_{72}&a_{71}&-b_{71}\\\ a_{63}&-b_{63}&a_{62}&-b_{62}&a_{61}&-b_{61} \\\ a_{53}&-b_{53}&a_{52}&-b_{52}&a_{51}&-b_{51} \\\ a_{43}&-b_{43}&a_{42}&-b_{42}&a_{41}&-b_{41}\\\ a_{33}&-b_{33}&a_{32}&-b_{32}&a_{31}&-b_{31} \\\ a_{23}&-b_{23}&a_{22}&-b_{22}&a_{21}&-b_{21} \\\ a_{13}&-b_{13}&a_{12}&-b_{12}&a_{11}&-b_{11} \end{pmatrix}$. In fact, to do this, I can multiply matrix $\mathbf A$ by the anti-diagonal identity matrix on the left : $\begin{pmatrix} 0&0&0&0&0&0&0&1\\\ 0&0&0&0&0&0&1&0 \\\ 0&0&0&0&0&1&0&0 \\\ 0&0&0&0&1&0&0&0 \\\ 0&0&0&1&0&0&0&0 \\\ 0&0&1&0&0&0&0&0 \\\ 0&1&0&0&0&0&0&0 \\\ 1&0&0&0&0&0&0&0 \end{pmatrix}$, and multiply on the right by $\begin{pmatrix} 0&0&0&0&0&0&1&0\\\ 0&0&0&0&0&0&0&-1 \\\ 0&0&0&0&1&0&0&0 \\\ 0&0&0&0&0&-1&0&0 \\\ 0&0&1&0&0&0&0&0 \\\ 0&0&0&-1&0&0&0&0 \\\ 1&0&0&0&0&0&0&0 \\\ 0&-1&0&0&0&0&0&0\end{pmatrix}$ to obtain matrix $\mathbf B$. But I can't figure out how to generalize this to $\\{n\times m,\ n>8,\ m>6\\}$ size matrices, and most importantly how to make it efficient in terms of time consumption... Does anyone have any ideas? Thanks in advance. Mathematica expression of A :                   A = Table[Sequence @@ {a[i, j], b[i, j]}, {i, 8}, {j, 3}]      Additional note : What I intend to do is to :   * Turn the matrix upside down   * Treat block matrices by sets of two columns and in each set     * Change the sign of the second column of each set   * Finally flipping the matrix as in a mirror image (but keeping the sets of two columns in order : for the example above $\rightarrow$ columns 1 & 2 become 4 & 6; columns 2 & 3 stay in their place (only in this example); columns 4 & 6 become 1 & 2\.


Importing Quicken Tab Delimited .*TXT File and plotting

I am using Mathematica 7 to try and plot my quicken data file. I have exported my quicken file as a .*TXT and have made zero changes to it. I want to do a `DateListPlot` on the file. The date is in column 1 and the amount is in column 9. So I want `ALL` data in those columns lined up by date. Now my paycheck I keep track of the taxes I pay so an entry in the file will have those amounts listed but no date in the associate column, so I'm guessing I may need to do some clean up there (many thousands of rows...) I have the following code:               quickentest =       DateListPlot[       Take[Import[         "C:\\location of file\\quickentest.txt", {"Data",           All, {2, 10}}], "DateList" -> "Month", "", "Day", "", "Year"]]      And I get the following output error:               Take::seqs: Sequence specification (+n, -n, {+n}, {-n}, {m, n}, or {m, n, s}) expected at position 2 in Take[{{Date,Amount},{,},{BALANCE 2/18/2006,0.},{2/19/2006,168.77},{2/20/2006,-32.54},{2/21/2006,-20.},{2/23/2006,-103.03},{2/23/2006,-10.},{2/24/2006,-21.75},{2/24/2006,1044.},<<4248>>},DateList->Month,,Day,,Year]. >>     DateListPlot::ntdt: The first argument to DateListPlot should be a list of pairs of dates and real values, a list of real values, or a list of several such lists. >>      I also get some output which for the most part looks pretty good except for the header row which looks like this:               DateListPlot[      Take[{{"Date", "Amount"}, {"", ""}, {"BALANCE 2/18/2006",          0.}, {"2/19/2006",          168.77}, {"2/20/2006", -32.54}, {"2/21/2006", -20.}, \     {"2/23/2006", -103.03}, {"2/23/2006", -10.}, {"2/24/2006", -21.75}, \     {"2/24/2006",          1044.}, {"", -127.18}, {"", -15.13}, {"", -64.73}, {"", -37.87}, \     {"", -1.2}, {"2/24/2006", 68.28}, {"2/25/2006", -32.51}, {"2/25/2006",          0.}, {"2/27/2006", -40.}, <<4220>>, {"12/10/2012", -29.43}, \     {"12/10/2012", -35.55}, {"12/10/2012", -30.}, {"12/12/2012", -18.4}, \     {"12/13/2012", -50.}, {"12/14/2012",          381.27}, {"12/14/2012", -6.29}, {"12/14/2012", -120.}, \     {"12/15/2012", -7.73}, {"12/15/2012", -18.85}, {"12/17/2012", \     -35.02}, {"12/17/2012", -58.73}, {"12/17/2012", -21.72}, \     {"12/17/2012", -15.}, {"12/18/2012", -152.06}, {"12/18/2012", -37.}, \     {"12/28/2012", -959.}, {"1/1/2013", -355.}, {"2/19/2006 - 1/1/2013", \     -1007.55}}, "DateList" -> "" \[Ellipsis] "h", <<2>>, "", "Year"]      I tried to exclude the header by using the suggested code below `2;;` to span out what I want but get errors I listed in the comment section. When exporting from Quicken 2013 Deluxe my only option is a .*TXT file from inside the checkbook registry. Thank you


How to get complement from two matrices?

This is a special case of my question How to do nor on matrices?                    a = IdentityMatrix[3];           b = {{1, 0}, {0, 1}, {0, 0}}           MapThread[Complement[#1, #2] &, {a, b}]       _Mathematica_ returns `{{}, {}, {1}}` , whereas I expect `{{0}, {0}, {1}}`, which is what I need.


Differential operator involving permutations

I would like to construct an operator in _Mathematica_ of the following form, $$D_i=\partial_i +\sum_{i \neq j}^n\frac{1}{x_i-x_j}p_{ij}, \quad i=1,...,n$$ where $p_{ij}$ is a (symmetric) permutation operator and does not commute with the $x_i$ and $\partial_i$, $$p_{ij}x_i=x_jp_{ij}, \quad p_{ij}\partial_i=\partial_j p_{ij}, \quad p_{ij}^2=1$$ I was trying using the `NCAlgebra` package, making all the operators non- commutative and defining the proper rules, but the result is far to be efficient when many operators (for instance $D_i^6$ ) are applied. The most efficient way I have found is to try to push always the permutation operator to the right and behind the derivatives. The problem appears when some properties of the powers and derivatives of the functions $\frac{1}{x_i-x_j}$ are not simplified when are defined as non-commutative objects and also that for large powers of the operator the number of terms heavily increases. But maybe the `NCAlgebra` package is not longer needed, and such operator can be defined in the normal _Mathematica_ environment Thanks in advance!


Importing base-64 encoded Canvas element into Mathematica

The aim of this code is to transfer a web image into webMathematica for image manipulation. Since the question here failed to resolve direct URL loading, I tried a different method of extraction involving converting the image to a Base-64 string and passing the data directly to the webMathematica jsp. Attempting to import a canvas image element Base-64 string into _Mathematica_ fails, with it giving the error > `Import::fmterr:` Cannot import data as PNG format The base-64 text string was exported using the Javascript function:               function convertImageToCanvas(image) {         var canvas = document.createElement("canvas");         canvas.width = image.width;         canvas.height = image.height;         canvas.getContext("2d").drawImage(image, 0, 0);         return canvas;     }     var canv  = convertImageToCanvas(document.getElementById("image"));     var dataUrl = canv.toDataURL();      The beginning segment of the data imported is shown:               data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAAA6CAYAAAD1AhaMAAAgAElEQVR4nKydd3hUZf63n/SemWTSe0iFACGUAIGQMqEjrl3sq64uurqru/7cn1ssYKdKUVBAUVB670iVjrQgINLSe51Mn3Pu948zmZkkoLvv+851fa5hgmZmzjn3+Xzb8yBubv0D1K4DuZ5ff0jd5PqwgmyCul3odxfD7mhFeyJhb4RTh


List of numbers without common factors with a certain number

Is there any function in Mathematica which directly gives an array of integer numbers with no common factor with a certain integer number? For example, all the integer numbers between 0 and 1728, which do not have any common factor with 12 (apart from the common factor one ofcourse.) I know how to make a program to do that, I just wonder wether there is a comand to do it.


Reinstalling Mathematica home edition with new linux distro

I bought _Mathematica_ home edition and installed it under Ubuntu. During an Ubuntu upgrade the power went out and wrecked the process. I installed Linux Mate Debian Edition and tried to reinstall _Mathematica_. It refused to license itself claiming that it had been installed on a 'different' computer. The MAC addresses are still the same. Wolfram does't provide support with Home Edition (though I think this is a bug) and suggested that I ask on this forum. Has anyone else bumped into this?


Building documentation with interactive examples in Wolfram Mathematica

There are interactive examples in the documentation in Wolfram Mathematica. Thus to compile them we just need `Shift`+`Enter`. I want to develop such examples for functions from my own package, how can I do this? * * * Thanks a lot for comments..I use W. Workbench 2.0 to build documentation. But here is the problem, while building, even the examples like NumericalAnalysis it failed with errors: > BUILD FAILED > > C:\Documents and Settings\NumericalAnalysis\docbuild.xml:132: The following > error occurred while executing this line: > > C:\Documents and Settings\NumericalAnalysis\docbuild.xml:97: The following > error occurred while executing this line: > > C:\Program Files\Wolfram > Research\WolframWorkbench\2.0\configuration\org.eclipse.osgi\bundles\10\1.cp\MathematicaSource\DocumentationBuild\SystemFiles\ant\Build\notebook.xml:71: > Failed to launch or connect to Mathematica kernel: Connected MathLink > program has closed the link, but there might still be data underway. > > Total time: 3 seconds If anyone has any suggestions, please , write!!


How can I make sure all InputFields have values before processing a nb form?

This is a two part problem:   1. I have a form that accepts both numeric and text inputs, then runs a function using a "process" Button. The issue I'm having is users that forget to fill out all of the fields and the function will not run. What I would like to do is to add some form of message dialog to the user that explains the problem, and preventing the function from running.    2. Two of these InputFields feed a function that displays results in the notebook dynamically. Prior to having values in the InputFields for this dynamic function the code is visible in the section of the Grid the results will be displayed. How can I hide the code and just display the results after the InputFields have been populated? Here is an example of the InputField code I'm working on:               Column[      {Grid[{{Style["code test", FontFamily -> "Arial", "Helvetica"]},       {Grid[{{Style["input 2 #", FontFamily -> "Arial", "Helvetica"],          InputField[          Dynamic[f1, If[# === Null, f1 = 0, f1 = Round[#, 00.001]] &],           Number, FieldSize -> {4, 1}],         Style["input 3 #", FontFamily -> "Arial", "Helvetica"],          InputField[          Dynamic[f2, If[# === Null, f2 = 0, f2 = Round[#, 00.001]] &],           Number, FieldSize -> {4, 1}],         Dynamic[data1 = Round[f2, .01] , CachedValue :> 0,           ContinuousAction -> False]}}, Frame -> None, ItemSize -> 10]},     {Grid[{{Style["input 4 #", FontFamily -> "Arial", "Helvetica"],          InputField[          Dynamic[f3,            If[# === Null, f3 = Round[#, 0.01], f3 = 00.001] &], Number,           FieldSize -> {4, 1}],         Style["input 4 #", FontFamily -> "Arial", "Helvetica"],          InputField[          Dynamic[f4,            If[# === Null, f4 = Round[#, 0.01], f4 = 00.001] &], Number,           FieldSize -> {4, 1}],          Dynamic[data2 = Round[f4, .01] , CachedValue :> 0,           ContinuousAction -> False]}}, Frame -> None,        ItemSize -> 10]}}, Frame -> None],      Button[Style["Process"], SelectionMove[yes =      Mean[f2, f3], Method -> "Queued", All, ButtonCell]]}]     Print["yes", yes];      Code updated to provide a better example of the problem. Thanks for your help!


What alternative notation of subscripts/superscripts that are also treated as SYMBOLS in Mathematica?

I tried to avoid using the subscript $A_0$ in the Module, and get an error with $A[0]$.                   In[119]:= Module[{A[0] = 1},A[0]]                   During evaluation of In[119]:= Module::lvset: Local variable specification {A[0]=1} contains A[0]=1, which is an assignment to A[0]; only assignments to symbols are allowed. >>                Out[119]= Module[{A[0] = 1}, A[0]]      EDIT: Alternatively, I tried to define "A0, A1, A2", but failed with command                        Sum[Ai, {i, 3}]      I just want a Symbol of combining a letter with a postfix of number, e.g. Ai, A_i, A[i], A(i),... any notation that is treated as a Symbol in MMa would be okay. EDIT2: For example,                   In[130]:= Module[{A0 = 1},Sum[Symbol["A" <> ToString[i]], {i, 0, 3}]]               Out[130]= A0 + A1 + A2 + A3      But I wish to replace $A0$ with $1$, and get `1+ A1 + A2 + A3` This would work when A0 defined globally.                    In[132]:= Sum[Symbol["A" <> ToString[i]], {i, A0 = 1; 0, 3}]               Out[132]= 1 + A1 + A2 + A3


TeXToBoxes and BoxesToTeX BoxRules options

A recent question has gotten me to look more into the tex conversion rules. Consider the following latex string:               \int_{a \hphantom{b} c}^{\hphantom{a} b \hphantom{c} d}      In latex it generates: $$ \int_{a \hphantom{b} c}^{\hphantom{a} b \hphantom{c} d} $$ _Mathematica_ has an undocumented function that it uses when it imports latex files. This is the function `Convert`TeX`TeXToBoxes`. Let us see what _Mathematica_ does when it encounters that $\TeX$ string string.               RawBoxes@Convert`TeX`TeXToBoxes["\\int_{a\\hphantom{b} c}^{\\hphantom{a} b\\hphantom{c} d}"]      The output is: ![enter image description here](http://i.stack.imgur.com/OZuld.png) So it seems that _Mathematica_ has no boxes to put the `\hphantom` latex command. There are others such as the `aligned` environment in latex that doesn't know how to import.               RawBoxes@Convert`TeX`TeXToBoxes["\\begin{aligned}       a+b+c&=d \\\\       c&=d-a-b     \\end{aligned}"]      ![enter image description here](http://i.stack.imgur.com/nBSor.png) When it should have been displayed as: \begin{aligned} a+b+c&=d \\\ c&=d-a-b \end{aligned} Mathematica is capable of displaying correctly by using the `\[AlignmentMarker]`, see this answer to see how it is done. In this question I'm curious to see how a perfectly aligned equation can be exported to LaTeX, I already provided one solution which Mr.Wizard helped me complete. But I have a feeling that using `"BoxRules"` options might be a better way of doing things. So the question here is: Can you come up with the right set of rules to transform from Mathematica Boxes to Tex and from Tex To Mathematica Boxes? This should be done at least in these two examples. # Edit: It seems that this question is only valid for exporting mathematica boxes to latex. I tried to look for the options allowed in in the two functions and this is what I got: ![enter image description here](http://i.stack.imgur.com/yMF5z.png) This means that it is only fair to make this question about changing the mathematica boxes to latex using the `"BoxRules"` option. A simple example can be found here               Convert`TeX`BoxesToTeX[SqrtBox["3"], "BoxRules" -> {SqrtBox[x_] :> x <> "^(1/2)"}]      which returns:               "3^(1/2)"


Scatterplots for subsets of multivariate data [Updated]

**Update/Re-write** There has been a lot of ambiguity over what i'm am trying to do with this question so I have decided to give it a full rewrite. I'm _really_ sorry for the confusion. If you want to see the background please see the edit history. I hope things are clearer now.. I have some data made up into the following fashion:               datac =       {        data1 = RandomReal[1, {7, 3}],        data2 = RandomReal[1, {13, 3}],        data3 = RandomReal[1, {19, 3}],        data4 = RandomReal[1, {16, 3}],        data5 = RandomReal[1, {5, 3}]        };      `data1` through `data5` are subsets of a multivariate dataset with 3 _independent_ variables. `data1`, for example, is composed of 7 individual data points (each with 3 variables). If I use the following function:               Needs["StatisticalPlots`"]     pairwisecol[data_, col_] :=      PairwiseScatterPlot[data,                            PlotStyle -> col,                            DataTicks -> True,                             DataLabels -> {"x", "y", "z"}]      I can create a _combined_ plot comparing the various subsets. E.g.               Show[{pairwisecol[data1, Red],            pairwisecol[data2, Blue],            pairwisecol[data3, Green],             pairwisecol[data4, Purple],            pairwisecol[data5, Orange]}]      ![enter image description here](http://i.stack.imgur.com/KAXLy.png) This curently has the major drawbacks that each subset has to be defined and have a colour explicitly assigned to it. Also, `Show` in this instance overlays all of the `DataTicks` etc, rather than just the elements from the first plot (as is normally the case with `Show[{Plot1,Plot2}]`). What I'm looking for is a way to use the whole (partitioned) dataset `datac` to generate such a plot/diagram. i.e. something like,               Show[pairwisecol[#, Red] & /@ datac]      but, with `Red` being replaced by a series of colours to represent each subset (like in the plot shown). ...Alternatively, starting with a 2-level list e.g.               datap = RandomReal[1, {60, 3}];      and a definition of sublist partitions,               parts = {7, 13, 19, 16, 5};      or               partspos = {[[1;;7]], [[8;;20]], [[21;;39]], [[40;;55]], [[56;;60]]};      then defining a function something like:               pairwiseP[data_, partlist_] := ...      that would partition `datap` into appropriate sublists, create a series of `PairwiseScatterPlot`'s (each with a different plot colour) and then combine them using `Show`. Note that this example has n = 3 independent variables. I am looking for a method that works for 1 < n < ~20. Can anyone suggest how to do this?


Transforming Sin into Abs[Sin] dynamically

Is it possible to interpolate a polynomial that approximates `Sin`, and then be able to manipulate the polynomial or a sample of its points to make sections of the plotted curve progressively steeper? Basically, I'd like to be able to make a plot showing, over a suitable domain, `Sin` and `Abs[Sin[]]` and everything in between.


How to draw a normalized tangent arrow

I want to draw a _normalized_ tangent arrow, so I use the `Normalize` command as follows:               tangent =        Table[{{t, Sin[t]}, {t, Sin[t]} + Normalize @ {1, Cos[t]}}, {t, -π, π, π/2}];     Plot[Sin[x], {x, -2 π, 2 π},        PlotRange -> 2, Epilog -> {Red, Arrowheads[0.02], Arrow /@ tangent}]      and I get this plot: ![enter image description here](http://i.stack.imgur.com/W3A50.png) Seems good, but if take a close look at the length of the arrows, you'll see that the length is not normalized at all. I've tried the `Show` and `Graphics` command instead of `Epilog`, but got the same plot. Can someone tell me what I missed here?


Find where an error occurred in a bunch of command line scripts

I have been using my intuition to solve errors in my _Mathematica_ scripts. But when calculations got more complex and I started getting errors involving code in more participating scripts (a script needs another one which needs another one, etc.), I searched for a way to find a _file_ and _line number_ or something and I found: How to find line where error occurred in Mathematica notebook? and The clearest way to represent Mathematica's evaluation sequence both of them more appropriate to the notebook (UI) environment. I can probably use a notebook and try to run my script there; but I wonder if there is a better way to work purely command line. Any ideas? (I am using _Mathematica_ version 9)


Use JavaScript to evaluate webMathematica tags?

In my HTML form I have 3 buttons. Each button calls different `.mx` files, based upon an `.mx file data`. `listplot` will be created in another `jsp` page. I placed all `.mx` files under `WEB-INF/Applications`. I wrote 3 functions in Javascript. Inside these functions I wrote the _webMathematica_ code between `<msp:evaluate>`tags. However the code doesn't seem to be working inside a Javascript function. I wrote the functions in the following way:               function button1()         {             <msp:evaluate>                 Get["Data/first.mx"];                 mxData=first;             </msp:evaluate>             var id=document.getElementById("name");             id.action="second.jsp";             id.submit();         }      I called this function in the following way:                <input type="button" value="Button1" onclick="button1()"/>


Parallelizing is much slower than single kernel evaluation?

Starting with a vector of matrices, `tVec`, I would like to parallelize the multiplication of each element with the same matrix `tMat`. However, employing `Parallelize` yields by far slower results than the plain calculation with a single kernel. There is a minimal working example below. Does anybody have hints on how to improve the situation, and on how to resolve this and thus efficiently use all kernels for evaluation?               dim = 24;     tVec = Table[RandomReal[{}, {dim, dim}], {i, 1, 100000}];     tMat = RandomReal[{}, {dim, dim}];          DistributeDefinitions[tMat, tVec];          Timing[(tMat . #) & /@ tVec;]     (*     >>> {1.08807,Null}     *)          Timing[Parallelize[(tMat . #) & /@ tVec;]]     (*     >>> {11.6207,Null}     *)


How to unprotect a variable in a package

In _Mathematica_ 9, I had the function(s). I apologize for the weak formatting.               RemoveBackground[data_,n_,rng_?NumericQ]:=RemoveBackground[data,n,{{-∞,-rng},{rng,∞}}];          RemoveBackground[data_,n_:2,regions_:{{-∞,∞}}]:= (          RemoveBackground[] = Function[{x}, Evaluate[         Fit[             (* select points only in specified regions *)             Select[                 Flatten[data,Depth[data]-3],                 Function[{pt},Or@@(#[[1]]<=pt[[1]]<=#[[2]]&/@regions)]             ][[;;,;;2]],             (* build list of polynomial terms *)             x^#&/@Range[0,n],             x         ]     ]];          Map[ReplacePart[#,2->#[[2]]-RemoveBackground[][#[[1]]]]&, data, {-2}] );      Now in _Mathematica_ 10.0, `RemoveBackground` is a protected function. I know that you can unprotect variables. This worked perfectly fine when I had to do it `Devices`, which they also protected in _Mathematica_ 10.0. For some reason since one of the calls to `RemoveBackground` has four arguments it goes red inside the package and continues to give the message > SetDelayed::write: Tag RemoveBackground in RemoveBackground[data_, n_:2, > regions_:{{-inf,inf}}] is protected. It doesn't seem to to matter where I put `Unprotect[RemoveBackground]`; I keep getting this error. Any ideas as to why? I have also tried various combinations of `Unprotect` then `Clear` as well.


Import matrices side-by-side separated by TAB

The problem is `0(TAB)0` interpreted falsely as a dark red square although it should be a dark red square surrounded by zeroes/ones. Import has different data-formats such as Data and Matrix but I don't know which one this is: ASCII? So how can I import the below type data as a text-file to Mathematica and get the goal-style matrixplot? Is there some format command to specify the structure of the data for importing? **Goal** ![](http://i.stack.imgur.com/sUi6E.jpg) **Failure** ![enter image description here](http://i.stack.imgur.com/Mj5P7.png) **Data**               0,0,1,1,1,1,0   0,1,1,1,1,1,0     0,0,1,1,1,1,0   0,0,1,1,1,1,0     0,0,0,0,1,1,0   0,0,0,1,1,1,0     0,0,0,0,1,1,0   0,0,0,0,1,1,0     0,0,0,0,0,1,0   0,0,0,0,0,0,0     0,0,0,0,0,0,0   0,0,0,0,0,0,0     1,1,1,1,1,1,0   1,1,1,1,1,1,0      > ![enter image description here](http://i.stack.imgur.com/Zc8x1.png)


Exporting a plot without drawing it

I'm trying to create a rather big 3D image and export it. Currently, I create the image then display using `Show`, then use `Export`. The problem is that drawing the 3D image as an interactive object is absolutely caning my little laptop, and I don't really need it - I just want a _jpeg_ output. Any way to do this? What I am doing is basically along the lines of               Show[{object list}, options]     Export["name.jpeg",%,options]      So as an example, if I wanted an image of a `Sin[x]` graph without _Mathematica_ first "drawing" it, how would I do it? Thanks


How can I assign specific colors and sizes to 2D coordinate arrays being plotted with ListLogPlot?

I'd like to plot two sets of coordinates in two different arrays using ListLogPlot, and be able to individually specify the sizes and colors of the datapoints for each array. Things seem to work fine if I allow Mathematica to specify point sizes and colors automatically:               ListLogPlot[{ListA, ListB}, ImageSize -> {800, 800}]      I can also specify that datapoints for ListA should be Red and that datapoints for ListB should be Blue:               ListLogPlot[{ListA, ListB}, PlotStyle -> {Red, Blue}, ImageSize -> {800, 800}]      However, attempting to specify a PointSize for one or either array seems to break things:               ListLogPlot[{ListA, ListB}, PlotStyle -> {PointSize[0.02], Red, Blue}, ImageSize -> {800, 800}]      Here, the colors are correct, but only ListB datapoints are rescaled to the correct size. I've also tried using Show[], and specifying the plots individually therein, but this seems to generate a plot with an axis scaled only for one of the datasets. Why is this happening, and how might I work around it?


Symbolize Subscript doesn't work

I want _Mathematica_ to interpret subscripted variables as symbols. I found documentation suggesting the `Notation` package could do this, but if I do:               Needs["Notation`"]     Symbolize[ParsedBoxWrapper[SubscriptBox["_", "_"]]]     x = 1     Subscript[x, 1]      I still get: > >     1 >     Subscript[1, 1] >   Am I doing anything wrong?


Using a LocatorPane

I have a network of a power grid where the edge are the power lines and the vertices are loads or generators. I was wondering how I can import an image into _Mathematica_ to derive some sort of coordinate system to calculate some topological properties that are related to distance and position using Monte Carlo Cooling methods and other methods of this sort. The code below is giving me back errors that are shown below.               im = Import["C:\Research\Pictures\FloridaPowerGrid.jpg"];     Module[{picturesize, i, bigger, imagesizes},        picturesize = {1038, 1386};       values = {};       i = 1;       imagesizes = ImageDimensions[im]; bigger = 1;       DynamicModule[{pt = {0, 0}},        If[imagesizes[[1]] < imagesizes[[2]], bigger = 2];        TableForm@{         Button["Record!", AppendTo[values, {i, pt}]; i++;],          LocatorPane[Dynamic@pt,            Dynamic @ Graphics[             Join[               {Inset[im, {0, 0}, {0, 0}, {1, 1}]},                Flatten[{Blue, Disk[#[[2]], .01], White, Text[#[[1]], #[[2]]]} & /@ values]],              PlotRange ->                {{0, imagesizes[[1]]/imagesizes[[bigger]]},                {0, imagesizes[[2]]/imagesizes[[bigger]]}},              ImageSize -> picturesize]],          Dynamic[N @ pt],          Dynamic[MatrixForm@values]}]]      ![enter image description here](http://i.stack.imgur.com/7Rytu.png) ![enter image description here](http://i.stack.imgur.com/pjxBe.jpg)


How to monitor the communication between parallel kernels

Recently I increased the problem size in my code, and it scales up very badly using `ParallelTable`. With a lot of help from the this community, it seems that the problem maybe caused by the communication of large data between the kernels. So is there a way to monitor the communication between these kernels? For example, to see how much data is copied from one kernel to another. * * * **Edit** As requested, here is a example demonstrate the problem:               Clear["`*"]     LaunchKernels[];      I have 16 kernels on my system               $KernelCount     (* ==> 16 *)      define some matrix               m = 30000; n = 640;     a = RandomComplex[{0., 1. + I}, {n, m}];     b = RandomComplex[{0., 1. + I}, {n, m}];      define some function which does some simple algebraic calculation, the detailed can be ignored.               SelectbyWRange[A_, {WMin_, WMax_}, {TakeWMin_, TakeWMax_}] :=       Module[{lthA, nMax, nMin}, lthA = Length[A];       nMin = Round[-((-WMax + lthA WMin)/(WMax - WMin)) - ((1 -                lthA) TakeWMin)/(WMax - WMin)];       nMax = Round[-((-WMax + lthA WMin)/(WMax - WMin)) - ((1 -                lthA) TakeWMax)/(WMax - WMin)];       Transpose[{Table[          TakeWMin + n*(TakeWMax - TakeWMin)/(nMax - nMin), {n, 0,            nMax - nMin}], Take[A, {nMin, nMax}]}]]     g[{x_, y_}] :=       SelectbyWRange[-Im[x*Conjugate[y]], {-834., 834.}, {19.5, 20.5}]      Timing `Table`, `ParallelTable`, `Map`, `ParallelMap`:               Table[g[{a[[n]], b[[n]]}], {n, 1, Length[a]}]; // AbsoluteTiming     (* ==> {0.390135, Null} *)          ParallelTable[g[{a[[n]], b[[n]]}], {n, 1, Length[a]}]; // AbsoluteTiming       (* ==> {14.352067, Null} *)          Map[g, Transpose[{a, b}]]; // AbsoluteTiming     (* ==> {1.010789, Null} *)          ParallelMap[g, Transpose[{a, b}]]; // AbsoluteTiming      (* ==> {8.101203, Null} *)          ParallelTable[        g[{RandomComplex[{0., 1. + I}, {m}],           RandomComplex[{0., 1. + I}, {m}]}], {n}]; // AbsoluteTiming       (* ==> {0.128660, Null} *)      We can see that `ParallelTable[g[{a[[n]], b[[n]]}], {n, 1, Length[a]}]` is worst in timing, this maybe because whole `a` and `b` have to be copied to each subKernel and thus took long time. Also in the last `ParallelTable`, there is no data copying from master kernel to subKernels and it has the best performance. As why `Table` is so fast and `ParallelMap` is so slow I have no clue. I thought monitor the communication between the kernels maybe helpful in understanding their behaviors.


Expectation taking unusually long to evaluate

I am trying to evaluate an expectation, but it is taking an extremely long time although the expression itself should not be too complicated. My code is               myFun[a_, b_, c_, d_, e_, f_, g_, h_, i_] :=       Module[{\[Alpha], \[Beta], \[Gamma]},       \[Alpha] = Min[i - d + c, h];       \[Beta] = Min[i + d - c, g];       \[Gamma] = d + \[Alpha] - \[Beta] - c;        (a + e) \[Beta] - (b + f) \[Alpha] +         c*Piecewise[{{f, c > 0}, {e, True}}] + \[Gamma]*         Piecewise[{{f, \[Gamma] > 0}, {e, True}}] -         d*Piecewise[{{f, d > 0}, {e, True}}]]          Expectation[      myFun[a, b, c, d, e, f, g, h,        i], {g \[Distributed] GeometricDistribution[\[Lambda]a],        h \[Distributed] GeometricDistribution[\[Lambda]b]},       Assumptions ->        c \[Element] Integers && d \[Element] Integers &&         i \[Element] Integers && i > 0 && Sign[d] == Sign[c] &&         a \[Element] Reals && b \[Element] Reals && b <= 0 <= a &&         e \[Element] Reals && f \[Element] Reals &&         0 < f < e && \[Lambda]a \[Element] Reals && \[Lambda]b \[Element]          Reals && 0 < \[Lambda]a < 1 &&         0 < \[Lambda]b < 1 && ((-i <= d <= c <= 0) || (0 <= c <= d <= i))]      I have introduced all the assumptions to make the job as easy as possible, and if I plug in values for most of the function's arguments the evaluation does complete in a reasonable time. I need, however, the general analytical form (if one exists), and that computation has not terminated in over four hours on a fast machine. Suggestions? **Edit:** using linearity of expectation for and evaluating separately the expectation of               \[Gamma]*             Piecewise[{{f, \[Gamma] > 0}, {e, True}}]      and that of the rest of the function I managed to get the result. The full computation, meanwhile, was still running after almost 8 hours. Why did Mathematica not use the same trick automatically?


Using variable with delay in WhenEvents in NDSolve

I have a system of differential equations which is solved correctly. However, I want to trigger two events, one of which depends on the "time elapsed" after of the first event trigger. Is it possible to ever satisfy the second WhenEvent function:               Manipulate[Plot[Evaluate[y[t] /. NDSolve[{       y'[t] == n[t]*b - a y[t],       y[0] == 0,       n[0] == 1,       WhenEvent[y[t] > y0, {n[t] -> 0, timeEvent1 = t}],       WhenEvent[Mod[t, timeEvent1 + delay] == 0 && y[t] < y0, n[t] -> 1]},      y, {t, 0, 100}, DiscreteVariables -> {n[t] \[Element] {0, 1}},      MaxSteps -> \[Infinity]]],     {t, 0, 100}],     {b, .2, 2}, {a, .1, 2}, {delay, 1, 10}, {y0, 1.5, 20}]      where n[t] is a DiscreteVariable. In my system, when n[t]->0, y[t] begins to decrease. What I would like to happen can be summarized in the below pseudo- code:               when y[t] reaches a certain level, y[t] begin to decay,     once y[t] decays after a given time elapse of "delay", if y[t] falls below the     above mentioned level, it beings to be produced again.     Rinse and repeat.      I hope this was clear enough. I'm hoping to get oscillations like this: ![real](http://i.stack.imgur.com/3zYaI.png) ![desired](http://i.stack.imgur.com/9QH9T.png) I think my issue is that the Mod[t,time+delay]==0 is never satisfied due to the nature of the variable t during the integration and n[t] never gets switched back to 1. Event 1 is triggered, but Event 2 is never triggered even though y[t] falls below yo and a time of time+delay has elapsed. Please let me know if I need to provide more information.


Evaluating an indefinite integral at the boundaries

I have the following expression i need to integrate over $\alpha$ from 0 to 1 and $x$ from $x1$ to $\infty$ $$\frac{1}{2p1x(-p2(1-x1)x1(1-\alpha)+kp2(1-\alpha)\alpha+x^{2}\alpha\zeta2+\alpha\lambda2)}$$ where $\alpha$ is a Feynman parameter and $\lambda2,-p2\ll1$ and $kp2,\zeta2>0$. I first need to perform the $\alpha$ integration. In order to simplify this integration i apply a partial fraction decomposition and expand the resulting square roots to leading order in $p2$ and $\lambda2$. This yields $$\frac{kp2}{2p1x(-p2\left(1-x1\right)x1+kp2\alpha)\left(kp2-p2\left(1-x1\right)x1+x^{2}\zeta2+\lambda2\right)}-\frac{kp2}{2p1x\left(kp2\left(\alpha-1\right)-x^{2}\zeta2-\lambda2\right)\left(kp2-p2\left(1-x1\right)x1+x^{2}\zeta2+\lambda2\right)}$$ Performing an indefinite integration over $\alpha$ and evaluating the resulting expression at the boundaries gives $$\frac{-\log\left(\left(-p2\left(1-x1\right)x1\right)\left(x^{2}\zeta2+\lambda2\right)\right)}{2p1x\left(kp2-p2\left(1-x1\right)x1+x^{2}\zeta2+\lambda2\right)}+\frac{\log\left(\left(kp2-p2\left(1-x1\right)x1\right)\left(kp2+x^{2}\zeta2+\lambda2\right)\right)}{2p1x\left(kp2-p2\left(1-x1\right)x1+x^{2}\zeta2+\lambda2\right)}$$ I'm pretty sure that the integral over this expression over $x$ from $x1$ to $\infty$ does converge, since it goes like $\frac{\log\left(x^{2}\right)}{x^{3}}$. In order to perform the $x$ integration i apply `Apart[expr,x]` to the above expression and write the resulting terms as a list using `Level[expr,1]`. The indefinite $x$ integral of this expression is then, after summing the elements of the list using `Total[expr]`, given by > >     (1/(4 p1 (kp2-p2 x1+p2 x1^2+λ2)))(2 Log[x] Log[1+(x^2 ζ2)/λ2]-2 Log[x] > Log[p2 (-1+x1) x1 (x^2 ζ2+λ2)]+2 Log[x] Log[(kp2+p2 (-1+x1) x1) (kp2+x^2 > ζ2+λ2)]-2 Log[x] Log[(kp2+x^2 ζ2+λ2)/(kp2+λ2)]-Log[(kp2+p2 (-1+x1) x1) > (kp2+x^2 ζ2+λ2)] Log[(kp2+p2 (-1+x1) x1+x^2 ζ2+λ2)/(p2 (-1+x1) x1)]+Log[p2 > (-1+x1) x1 (x^2 ζ2+λ2)] Log[(kp2+p2 (-1+x1) x1+x^2 ζ2+λ2)/(kp2+p2 (-1+x1) > x1)]+PolyLog[2,-((x^2 ζ2)/λ2)]-PolyLog[2,-((x^2 > ζ2)/(kp2+λ2))]+PolyLog[2,-((x^2 ζ2+λ2)/(kp2+p2 (-1+x1) > x1))]-PolyLog[2,(kp2+x^2 ζ2+λ2)/(p2 x1-p2 x1^2)]) >   When I now try to evaluate this expression at the boundaries I have no problems with the lower boundary $x1$. However, I don't have any idea how to take the limit of $x$ to $\infty$ since the above expression diverges in this limit. What did I do wrong? Does anyone know how I could integrate my initial expression over $\alpha$ first and then over $x$ and then get a finite result? Thanks in advance, any help is welcome! Here's my code of the above calculation, I didn't have it at hand when I asked the question               (* Integration of the Feynman parameter α *)               $Assumptions =       kp2 >= 0 && -1 < p2 < 0 && 1 > λ2 > 0 && x1 >= x >= 0 &&        1 >= α >= 0 && p1 >= 0 && ζ2 >= 0      > >      kp2 >= 0 && -1 < p2 < 0 && 1 > λ2 > 0 && x1 >= x >= 0 && >      1 >= α >= 0 && p1 >= 0 && ζ2 >= 0 >                 Denominator5 :=       2 p1*x (-kp2*α (α - 1) +      p2*x1 (α - 1) (1 - x1) + λ2*α + ζ2*      x^2*α)          Denominator5PartialFraction :=       2 p1*x*kp2*(-α + (kp2 + x^2 ζ2 + λ2)/      kp2) (α - (p2 (1 - x1) x1)/kp2)          StartingExpressionThirdTerm1 = 1/Denominator5      > >     1/(2 p1 x (p2 (1 - x1) x1 (-1 + α) - kp2 (-1 + α) α + >        x^2 α ζ2 + α λ2)) >                 (*The same partial fraction decomposition as before yields*)           StartingExpressionThirdTerm2 =      Apart[1/Denominator5PartialFraction, α]      > >      kp2/(2 p1 x (-p2 x1 + p2 x1^2 + kp2 α) (kp2 - p2 x1 + p2 x1^2 + >        x^2 ζ2 + λ2)) - kp2/( 2 p1 x (-kp2 + kp2 α - x^2 ζ2 - λ2) (kp2 - p2 > x1 + >         p2 x1^2 + x^2 ζ2 + λ2)) >                 ResultThirdTermα =       Integrate[Level[StartingExpressionThirdTerm2, 1], α]      > >      {Log[p2 (-1 + x1) x1 + kp2 α]/( >      2 p1 x (kp2 + p2 (-1 + x1) x1 + x^2 ζ2 + λ2)), -( >       Log[kp2 - kp2 α + x^2 ζ2 + λ2]/( >       2 p1 x (kp2 + p2 (-1 + x1) x1 + x^2 ζ2 + λ2)))} >                 (*Now evaluate this expression at the limits*)           ResultThirdTermαUpper =       Limit[ResultThirdTermα, α -> 1, Direction -> 1]           {Log[kp2 + p2 (-1 + x1) x1]/(      2 p1 x (kp2 + p2 (-1 + x1) x1 + x^2 ζ2 + λ2)), -(       Log[x^2 ζ2 + λ2]/(       2 p1 x (kp2 + p2 (-1 + x1) x1 + x^2 ζ2 + λ2)))}           ResultThirdTermαLower =       Limit[ResultThirdTermα, α -> 0, Direction -> -1]      > >      {Log[p2 (-1 + x1) x1]/( >      2 p1 x (kp2 + p2 (-1 + x1) x1 + x^2 ζ2 + λ2)), -( >       Log[kp2 + x^2 ζ2 + λ2]/( >       2 p1 x (kp2 + p2 (-1 + x1) x1 + x^2 ζ2 + λ2)))} >                  FinalResultThirdTermα =       FullSimplify[       Total[ResultThirdTermαUpper - ResultThirdTermαLower]]      > >      (-Log[p2 (-1 + x1) x1] + >      Log[((kp2 + p2 (-1 + x1) x1) (kp2 + x^2 ζ2 + λ2))/( >       x^2 ζ2 + λ2)])/(2 p1 x (kp2 + p2 (-1 + x1) x1 + >        x^2 ζ2 + λ2)) >                  FinalResultThirdTermαList =       FullSimplify[ResultThirdTermαUpper - ResultThirdTermαLower]      > >      {(-Log[p2 (-1 + x1) x1] + Log[kp2 + p2 (-1 + x1) x1])/( >      2 p1 x (kp2 + p2 (-1 + x1) x1 + x^2 ζ2 + λ2)), >      Log[1 + kp2/(x^2 ζ2 + λ2)]/( >      2 p1 x (kp2 + p2 (-1 + x1) x1 + x^2 ζ2 + λ2))} >                 (*Before performing the x integration bring this to a different form*)           FinalResultThirdTermαSimplified1 =       FinalResultThirdTermα /. {Log[((kp2 + p2 (-1 + x1) x1) (kp2 +            x^2 ζ2 + λ2))/(x^2 ζ2 + λ2)] ->          Log[(kp2 + p2 (-1 + x1) x1) (kp2 + x^2 ζ2 + λ2)],        Log[p2 (-1 + x1) x1] -> Log[p2 (-1 + x1) x1 (x^2 ζ2 + λ2)]}      > >     (-Log[p2 (-1 + x1) x1 (x^2 ζ2 + λ2)] + >      Log[(kp2 + p2 (-1 + x1) x1) (kp2 + >      x^2 ζ2 + λ2)])/(2 p1 x (kp2 + p2 (-1 + x1) x1 + >        x^2 ζ2 + λ2)) >                 Integration of the momentum fraction x           FinalResultThirdTermαPartialFraction =       Level[Apart[FinalResultThirdTermαSimplified1, x], 1]      > >      {(x ζ2 (Log[p2 (-1 + x1) x1 (x^2 ζ2 + λ2)] - >     Log[(kp2 + p2 (-1 + x1) x1) (kp2 + x^2 ζ2 + λ2)]))/( >      2 p1 (kp2 - p2 x1 + p2 x1^2 + λ2) (kp2 - p2 x1 + p2 x1^2 + >     x^2 ζ2 + λ2)), (-Log[ >     p2 (-1 + x1) x1 (x^2 ζ2 + λ2)] + >       Log[(kp2 + p2 (-1 + x1) x1) (kp2 + x^2 ζ2 + λ2)])/( >      2 p1 x (kp2 - p2 x1 + p2 x1^2 + λ2))} >                  ResultThirdTermX =       Together[Total[Integrate[FinalResultThirdTermαPartialFraction, x]]]      > >     (1/(4 p1 (kp2 - p2 x1 + >        p2 x1^2 + λ2)))(2 Log[x] Log[1 + (x^2 ζ2)/λ2] - >       2 Log[x] Log[p2 (-1 + x1) x1 (x^2 ζ2 + λ2)] + >       2 Log[x] Log[(kp2 + p2 (-1 + x1) x1) (kp2 + x^2 ζ2 + λ2)] - >       2 Log[x] Log[(kp2 + x^2 ζ2 + λ2)/(kp2 + λ2)] - >      Log[(kp2 + p2 (-1 + x1) x1) (kp2 + x^2 ζ2 + λ2)] Log[( >         kp2 + p2 (-1 + x1) x1 + x^2 ζ2 + λ2)/(p2 (-1 + x1) x1)] + >       Log[p2 (-1 + x1) x1 (x^2 ζ2 + λ2)] Log[( >         kp2 + p2 (-1 + x1) x1 + x^2 ζ2 + λ2)/( >         kp2 + p2 (-1 + x1) x1)] + PolyLog[2, -((x^2 ζ2)/λ2)] - >       PolyLog[2, -((x^2 ζ2)/(kp2 + λ2))] + >       PolyLog[2, -((x^2 ζ2 + λ2)/(kp2 + p2 (-1 + x1) x1))] - >       PolyLog[2, (kp2 + x^2 ζ2 + λ2)/(p2 x1 - p2 x1^2)]) >                 (*Now evaluate this expression at the boundaries*)           ResultThirdTermXLower = Limit[ResultThirdTermX, x -> x1, Direction -> -1]      > >      (1/(4 p1 (kp2 + >        p2 (-1 + x1) x1 + λ2)))(2 Log[x1] Log[ >         1 + (x1^2 ζ2)/λ2] - >       2 Log[x1] Log[p2 (-1 + x1) x1 (x1^2 ζ2 + λ2)] + >       2 Log[x1] Log[(kp2 + p2 (-1 + x1) x1) (kp2 + x1^2 ζ2 + λ2)] - >       2 Log[x1] Log[(kp2 + x1^2 ζ2 + λ2)/(kp2 + λ2)] - >       Log[(kp2 + p2 (-1 + x1) x1) (kp2 + x1^2 ζ2 + λ2)] Log[( >         kp2 + p2 (-1 + x1) x1 + x1^2 ζ2 + λ2)/(p2 (-1 + x1) x1)] + >       Log[p2 (-1 + x1) x1 (x1^2 ζ2 + λ2)] Log[( >         kp2 + p2 (-1 + x1) x1 + x1^2 ζ2 + λ2)/( >         kp2 + p2 (-1 + x1) x1)] + PolyLog[2, -((x1^2 ζ2)/λ2)] - >       PolyLog[2, -((x1^2 ζ2)/(kp2 + λ2))] + >       PolyLog[2, -((x1^2 ζ2 + λ2)/(kp2 + p2 (-1 + x1) x1))] - >       PolyLog[2, (kp2 + x1^2 ζ2 + λ2)/(p2 x1 - p2 x1^2)]) >                  ResultThirdTermXUpper = Limit[ResultThirdTermX, x -> Infinity, Direction -> 1]      > >      ComplexInfinity >


What SampleRate and SampleDepth does Mathematica use on output?

The `Play` function will happily accept arbitrary values for its `SampleDepth` and `SampleRate` options. For example, if I do:               Play[Sin[2 π 440 t], {t, 0, 1}, SampleDepth -> 240, SampleRate -> 480000]      … this will evaluate without a problem, and when I hit the play button, I will hear the sound. But I know that my computer hardware is not capable of outputting sound at 240 bits and 480 kHz. So what sample depth and rate am I actually hearing? Does Mathematica use some standard rate for output (maybe 16 bits at 44.1 kHz)? Does it use the maximum capability of my hardware (in my case, 24 bits at 48 kHz)? Or something else? Is there any way to query Mathematica for my system's audio capabilities?


Nested NIntegrate - NIntegrate::inum: - error

I have the problem quite similar as in: Nested NIntegrate I define two functions:               r[x_] := Evaluate[q[x] /. NDSolve[{q'[t] == 0.0001 + (-1 + I*1 + q[t])*q[t],q[0] == 0}, q,                                        {t, 0, 50}]]          fn[k_?NumericQ] := Exp[8*NIntegrate[r[s]*Exp[2*beta*1] + 8*r[s], {s, 0, k}]]          beta=1      When I want to know the value of:               NIntegrate[fn[k], {k, 0, 5}]      I obtain following error: > NIntegrate::inum: "Integrand fn[k] is not numerical at {k} = > {0.03978659976289378`}." Adding `?NumericQ` to r[k_] I obtain error: > NIntegrate::inumr: "The integrand fn[k] has evaluated to non-numerical > values for all sampling points in the region with boundaries {{0,5}}" What do I wrong?


Keep Ordering of Bra Ket When Printing

I would like to keep the ordering of the bra ket-print but right now this doesn't happen. Any Idea? I tried playing with HoldForm but then i could evaluate the expression inside properly               Ns = 1;     Table[      (Ket[(Replace[ Quotient[i - 1, Ns], {0 -> "\[UpArrow] ",           1 -> "\[DownArrow] "}] <> ToString@Mod[i, Ns])]       Bra[(Replace[        Quotient[j - 1, Ns], {0 -> "\[UpArrow] ",           1 -> "\[DownArrow] "}] <> ToString@Mod[j, Ns])])          , {i, 1, Ns*2}, {j, 1, Ns*2}   ] // MatrixForm      Right now this gives: ![bad braket](http://i.stack.imgur.com/qzzxa.png) I would like it to give something more like: ![good braket](http://i.stack.imgur.com/nnhIj.png) Thank you


Forming Cone with Tube fails to work in version 9.0.1

I use two different radii in a `Tube` expression to draw a cone. I know for a fact that this worked in Mathematica 8, but when I reevaluated my code in versio 9.0.1               Graphics3D[{CapForm["Butt"], Tube[{{0, 0, 2}, {0, 0, 4}}, {2, 4}]}]      which looks like this I get a tube !["Butt" gives no cone.](http://i.stack.imgur.com/dEgCj.jpg) while               Graphics3D[{CapForm[None], Tube[{{0, 0, 2}, {0, 0, 4}}, {2, 4}]}]      returns open cones, which is not what I want ![None gives a cone but is open](http://i.stack.imgur.com/PrioW.jpg) The `Help` does not indicate that any changes have been applied in version 9. **EDIT** Thanks for the comments. The error has been reported. Below a summary of Mathematica's behavior.               Graphics3D[{Opacity[0.6], CapForm["Square"], #, CapForm[None], #,     CapForm["Butt"], #}] & @ Tube[{{0, 0, 2}, {0, 0, 4}}, {2, 4}]      ![Summary of CapForm error.](http://i.stack.imgur.com/kU10D.jpg)


EmpiricalDistribution for Gini Coefficient Runs Slow

I am repurposing code that I found in this blog post (http://datavoreconsulting.com/sports/gini-coefficients-and-the-olympic-medal- race/) to generate the Gini coefficient for other data sets I am working on. When I run the code it generates the coefficient, but seems to take an inordinate amount of time. Does anyone have suggestions for how I can speed this up? Here is my code and the sample Olympic medal data from the site.               medals={{45, 19, 14, 11, 7, 7, 6, 5, 3, 3, 2},     {110, 48, 35, 16, 9, 8, 7, 6, 6, 5, 5, 5, 5, 4, 3, 2, 2, 2, 2, 1, 1},      {234, 13, 9, 6, 4, 2, 2, 2, 2, 1},      {142, 46, 25, 19, 16, 14, 9, 8, 8, 5, 5, 5, 4, 3, 3, 2, 2, 2,1},      {65, 63, 41, 26, 25, 16, 12, 9, 8, 8, 8, 7, 6, 6, 4, 4, 3, 2, 1, 1},      {94, 63, 43, 42, 42, 34, 32, 25, 14, 11, 11, 10, 10, 3, 3, 3, 2, 2, 2, 1, 1, 1},      {99, 40, 37, 36, 29, 25, 16, 13, 11, 11, 10, 10, 10, 6, 6, 6, 4, 4, 3, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1},      {56, 39, 25, 25, 25, 23, 22, 20, 16, 15, 10, 9, 9, 7, 7, 5, 5, 5, 4, 4, 4, 4, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},      {110, 36, 25, 24, 24, 20, 18, 17, 16, 16, 9, 8, 8, 6, 5, 5, 5, 4, 3, 2, 2, 1, 1, 1, 1, 1, 1, 1},      {101, 57, 27, 21, 20, 20, 19, 18, 18, 17, 16, 14, 9, 9, 9, 7, 7, 6, 5, 5, 3, 3, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1},      {84, 46, 32, 31, 27, 26, 22, 22, 22, 16, 14, 12, 11, 8, 7, 7, 7, 6, 5, 5, 4, 3, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1},      {76, 70, 42, 35, 24, 22, 21, 18, 14, 12, 11, 11, 10, 8, 7, 6, 5, 5, 5, 5, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1},      {98, 74, 35, 26, 26, 25, 24, 19, 17, 15, 14, 13, 9, 7, 6, 6, 5, 5, 5, 4, 4, 4, 3, 3, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1},      {103, 71, 42, 36, 22, 21, 21, 20, 18, 10, 9, 8, 7, 6, 6, 6, 5, 5, 4, 4, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},      {93, 90, 50, 29, 27, 23, 22, 18, 18, 15, 14, 12, 10, 10, 8, 6, 6, 5, 5, 5, 4, 4, 3, 3, 3, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},      {107, 91, 32, 26, 25, 25, 19, 17, 15, 15, 15, 13, 13, 9, 9, 9, 8, 8, 7, 5, 5, 5, 4, 4, 4, 4, 4, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1},      {99, 95, 66, 40, 35, 29, 21, 21, 18, 17, 17, 16, 16, 13, 9, 8, 8, 8, 5, 5, 5, 5, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},          {126, 94, 90, 39, 27, 25, 25, 22, 22, 14, 13, 13, 11, 9, 8, 8, 6, 6, 6, 5, 5, 5, 4, 4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1},      {194, 126, 41, 32, 31, 25, 21, 20, 15, 14, 14, 12, 9, 9, 8, 6, 5, 5, 4, 4, 4, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1},      {173, 59, 52, 46, 37, 32, 32, 31, 28, 23, 19, 19, 18, 13, 12, 11, 8, 8, 6, 6, 5, 4, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},      {132, 102, 94, 40, 35, 33, 28, 24, 24, 23, 16, 16, 14, 14, 14, 13, 12, 11, 10, 9, 9, 8, 6, 5, 4, 4, 4, 4, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},      {112, 108, 82, 53, 31, 31, 29, 28, 27, 22, 22, 20, 19, 19, 18, 18, 16, 15, 12, 10, 9, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},      {102, 65, 63, 50, 41, 37, 35, 27, 25, 23, 22, 21, 19, 19, 17, 17, 15, 15, 15, 15, 14, 11, 11, 8, 8, 8, 7, 7, 6, 6, 6, 6, 6, 6, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},     {93, 89, 58, 58, 56, 38, 34, 29, 28, 28, 26, 25, 23, 18, 17, 17, 14, 14, 13, 13, 12, 12, 11, 10, 9, 9, 8, 8, 7, 7, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},      {102, 92, 63, 49, 49, 37, 33, 32, 30, 30, 27, 23, 22, 19, 19, 17, 16, 15, 12, 12, 10, 10, 10, 8, 8, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},      {110, 100, 73, 47, 46, 41, 41, 31, 27, 27, 25, 24, 19, 18, 18, 16, 15, 14, 13, 10, 10, 10, 9, 9, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},      {104, 87, 82, 65, 44, 38, 35, 34, 28, 28, 20, 20, 18, 17, 17, 17, 14, 13, 13, 13, 12, 12, 11, 10, 10, 10, 9, 9, 8, 8, 7, 7, 7, 6, 6, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}}          gini[list_] := Module[{d}, d = EmpiricalDistribution[list];           1 - Sum[( PDF[d, y]*(Sum[PDF[d, x]*x, {x, 0, y - 1}] + Sum[PDF[d, x]*x, {x, 0, y}]))/ Sum[PDF[d, x]*x, {x, 1, Max[list]}], {y, 1, Max[list]}] // N]           ginicoefficient = ParallelMap[gini[#] &, medals];      I was able to get a 1.67 speedup by using ParallelMap. The speedup gets takes about about 30 seconds to run on my machine. Other data sets I have tried have taken much longer. Here is the actual data I am using for my analysis:               dataA={27202226, 9706145, 8754168, 7768391, 7728354, 6619827, 6278530,5723010, 4572486, 3468553, 2578256, 2375609, 2103342, 1781526, 1748144, 1300719, 985237, 976930, 951310, 572229, 572035, 554326, 508000, 466145, 341955, 289557, 267754, 258240, 251059, 208431, 190313, 182377, 160547, 159761, 159619, 143532, 113995, 106034, 101413, 101138, 92257, 92226, 83332, 73705, 73529, 70442, 60404, 57552, 51019, 40933, 39887, 38273, 37720, 33268, 28769, 27047, 25113, 24071, 20321, 17362, 14005, 13301, 11358, 10762, 10262, 10000, 9972, 8714, 8218, 6918, 6592, 6097, 5200, 5004, 4600, 4147, 4000, 3629, 3074, 2532, 2511, 1955, 1926, 1742, 1682, 1547, 1410, 1266, 867, 747, 713, 672, 452, 438, 360, 248, 107, 80}          dataB={14017085, 13167607, 10682037, 10454713, 10165633, 8189166, 5750866, 4825388, 3608333, 3357039, 2230084, 1827165, 1684532, 1605366, 1481081, 1173900, 1125886, 971655, 716186, 645870, 634825, 550483, 522765, 470109, 370176, 296950, 289277, 263830, 213575, 212790, 202016, 143543, 140156, 137528, 133740, 122878, 70418, 69752, 63407, 56687, 55669, 55665, 54069, 49534, 47970, 39071, 36732, 36722, 35488, 33966, 32583, 27212, 22004, 20992, 20962, 20325, 20263, 20202, 19006, 16597, 15924, 15392, 13828, 12700, 12163, 11024, 9552, 9350, 9034, 7785, 5714, 5432, 3975, 3747, 3516, 3273, 2301, 2075, 2075, 1913, 1845, 1829, 1545, 1364, 1092, 977, 667, 327, 311, 228}          gini[list_] := Module[{d}, d = EmpiricalDistribution[list];           1 - Sum[( PDF[d, y]*(Sum[PDF[d, x]*x, {x, 0, y - 1}] + Sum[PDF[d, x]*x, {x, 0, y}]))/ Sum[PDF[d, x]*x, {x, 1, Max[list]}], {y, 1, Max[list]}] // N]           ginicoefficient = ParallelMap[gini[#] &, {dataA, dataB}];      I am using two data sets dataA and dataB because if I run them one at a time I get an error that EmpiricalDistribution requires a rectangular array of data to work. Any thoughts?


How to label the Vertex and, or Edge labels with their weight

I noticed that the Mathematica 9.0 documentation only mentions the usage of "Name" to label the vertexlabel or edgelabel in the Graph. Is there an option to use the Weights automatically just as "Name" does?


inverse of abstract matrix

If you assume the matrix $A$ is invertible, then $A^{-1} \cdot A = I$. Is there an assumption for invertibility in Mathematica 9? How can one make the following evaluate to the identity matrix $I_3$?               $Assumptions = {Element[A, Matrices[{3, 3}]]}     Inverse[A].A


Why use Column with Rows instead of Grid?

In general, what are the advantages of using Grid versus a combination of Column and Row? Is Grid better in some situations but not others? For example, is there any reason why one would do this:               Grid[{{"Some text I want above a formula:"},           {Integrate[f[x], x]}}]      versus this:               Column[{Row[{"Some text I want above a formula:"}],              Row[{Integrate[f[x], x]}]}]


PlotRange adjustments with BarChart

I'm working on making some `BarCharts`, however, some of my data is contained within a small range so I want the plot to start above 0 and cut-off the bars below that, however, when I try to use `PlotRange` the bars are not cropped properly (they extend below the axis) and if you try to introduce `ChartLabels` they are cut in half!               BarChart[RandomReal[1, 10], BarSpacing -> Large, ChartLabels -> Range[10]]      ![Mathematica graphics](http://i.stack.imgur.com/hUd3M.png)               BarChart[RandomReal[1, 10], BarSpacing -> Large, PlotRange -> {Automatic, {0.2, 1}}]      ![Mathematica graphics](http://i.stack.imgur.com/rJ8Di.png)               BarChart[RandomReal[1, 10], BarSpacing -> Large, PlotRange -> {Automatic, {0.2, 1}}, ChartLabels -> Range[10]]      ![Mathematica graphics](http://i.stack.imgur.com/m0fp9.png) I've tried playing around with `ImagePadding` and `BarOrigin` but nothing seems to work. Is there a better solution? With a `ListPlot` adjusting the `PlotRange`               ListPlot[RandomReal[1, 10], PlotRange -> {Automatic, {0.2, 1}}]      ![Mathematica graphics](http://i.stack.imgur.com/4XBrD.png)


How to apply multiple format to a list

I have a nested list like               matrix = {{1.2345664, 2.38673956, 3.567846}, {0.00034554, 124.4554654,     6.34543}, {0.0000233, 244.34454, 2}}      and I want to apply `MatrixForm`, but also `NumberForm[,{5,4}]`, because I want that in every element of the matrix the numbers are properly padded. Is this possible in some way? Interestingly perhaps, I want eventually write the resulting output list in a file. P.S.: Now I write with `Export["my_file.dat",Flatten[matrix]]`, and after I obtain the proper padding using a C program. But there must be a clever way...


Quickly sum over vector outer products

I am trying to do a simple summation over outer products. I wrote the code as straightforwardly as I could, but perhaps there is a more efficient way to do it.               {mat1,mat2} =         Import["https://dl.dropboxusercontent.com/s/d9m7mgd4gio78t4/12SeptemberData.nc",         {"Datasets",{"matrix1","matrix2"}}];     {sdim,ldim}=Dimensions[mat1];     dim = sdim + ldim;          DM = ConstantArray[0, {dim,dim}];     kcounter=0;     Do[        If[kcounter != k, Print[k]; kcounter += 1;];        (*The evaluation seems to take forever,           so this just spits out the current value of the k iterator          so I can keep track of what is going on.*)        If[b != a && Chop[mat1[[k, a]] mat1[[k, b]]] != 0 ,           DM += mat1[[k, a]] mat1[[k, b]] Outer[Times, mat2[[a+sdim]], mat2[[b + sdim]]]];            ,{k, sdim}, {a, ldim}, {b, ldim}];      Before I added the term where it checks to make sure the necessary term is not zero, it was taking a lot longer. But still, I know there are a lot of _Mathematica_ functions I don't know about, and if there were a way to speed up this computation that would be fantastic.


How can I nicely overlay fits for multiple arrays with ListPlot or ListLogPlot?

I'm plotting multiple lists with ListPlot[] or ListLogPlot[]:               ListLogPlot[{ListA, ListB, ListC, ListD, ListE}, PlotRange -> {{0, 100}, Automatic}]      I also have fits, $(f_a,f_b,f_c,f_d,f_e)$ for the data in each of the lists. How can I overlay the fits in the same color and for the same $(x,y)$ range?


Sum and NSum gives different solutions

I'm working on a _Mathematica_ lab for Calc. 2, and I ran into a problem last night. I was trying to calculate the midpoint approximation of the definite integral of `Cos[x]` from 0 to 2. Here's what I came up with:               Clear[a, b, n, f]           f[x_] = Cos[x]          a := 0; b := 2; n := 578          N[((b - a)/n)*Sum[f[a + (i - (1/2))*((b - a)/n)], {i, 1, n}]]          0.909298      This is fine, but if I try to use `NSum` instead of `N[...Sum[...]]` then this happens:               Clear[a, b, n]          a := 0; b := 2; n := 578          ((b - a)/n)*NSum[f[a + (i - (1/2))*((b - a)/n)], {i, 1, n}]      > During evaluation of In[35]:= SequenceLimit::seqlim: The general form of the > sequence could not be determined, and the result may be incorrect. >> > > During evaluation of In[35]:= SequenceLimit::seqlim: The general form of the > sequence could not be determined, and the result may be incorrect. >> > > 35.538 According to the documentation, `Sum` evaluates the given sum (http://reference.wolfram.com/mathematica/ref/Sum.html), and the `N` function gives the numerical value of the parameter (http://reference.wolfram.com/mathematica/ref/N.html). Also, `NSum` should give the numerical approximation of the sum. To my understanding, `N[Sum[...]]` Should be the same as `NSum[...]`, or am I missing something? It's not a huge deal as far as typing more, but I'd just like to know why it doesn't work as expected. I've read online that `NSum` apparently tries to work out part of the sum symbolically, but even if it does I don't see how it could be _THAT_ much different from the real answer.


Can we give Mathematica hints for symbolic sums and products?

I have this question at MO and I would like to know if we can give hints to get the symbolic sums and products to come out as $\frac{6}{\pi^{2}}\pm\epsilon$ instead of $0.60792710...$ accurate to $\epsilon$.               ε = 0.000000001; s = 0;     Sum[(MoebiusMu[n] + ε)/n^s, {n, 1, ∞}] /        Product[n^(MoebiusMu[n] ε), {n, 1, ∞}] == 1/Zeta[s] + ε        When $s=0$ we get $-2\pm\epsilon$, but we have to use NSum. When $s=2$ or greater, we get the decimal expansion and I would like to see the zeta values $\pm\epsilon$. Can we do this?


Writing results directly to file

I am trying to find all simple paths in a large directed graph (542 vertex, density ~ 5%) between two nodes. For this purpose, I use the algorithm from this thread. Unfortunately, my computer is running out of memory during this operation. I was thinking it would help to write the paths found directly to a text file, but I don't know how to do it in this case. Maybe, you'll have other suggestions as well. Here's the file with the adjacency matrix.               SetDirectory["C:\\Users\\crazyfrog\\Documents\\ДИПЛОМ"];     findPaths[a_?MatrixQ, s_Integer, t_Integer] :=        Module[{child, find},         child[v_] := Flatten@Position[a[[v]], Except@0, 1, Heads -> False];        find[v_, list_] :=          Scan[If[# === t, Sow[Append[list, #]],             If[FreeQ[list, #], find[#, Append[list, #]]]] &, child@v];        If[# =!= {}, First@#, {}] &@Last@Reap@find[s, {s}]];     findPaths[g_Graph, s_, t_] :=        Module[{nodes = VertexList@g, convert},         convert = Thread[nodes -> Range@Length@nodes];        findPaths[Normal@AdjacencyMatrix@g, s /. convert, t /. convert] /.          Reverse /@ convert];     << JLink`;     InstallJava[];     ReinstallJava[JVMArguments -> "-Xmx1024m"]; data =       Import["test.xlsx"][[1]]; data2 = Round[data];     g = AdjacencyGraph[data2];     $HistoryLength = 0; findPaths[g, 1, 542] >> "result.txt"


How does Mathematica estimate error on fit parameters?

When performing a fit using `NonlinearModelFit` (or any of _Mathematica_ fitting functions, but I am particularly interested in nonlinear models), _Mathematica_ makes a covariance matrix available for all the fit parameters. I was wondering if anyone has an idea of how _Mathematica_ does this error estimation on parameters?


Multiple panel figure from combination of plots - bad alignment

I am trying to combine 3 `ListContourPlot`s to obtain a 3 in-row panel figure in Mathematica 7, to export in one single eps file. One of the plots has also its own legend. I am using `GraphicsGrid`, as suggested in Mathematica help. The problem is that the panels in the final figure are not aligned and the actual plot area is different from panel to panel. This fact has probably something to do with Mathematica considering as dimensions of each plot the entire occupied are, including also axis labels, and aligning the plots according to them as opposed to with respect to the axis themselves. How can I get the panels to align on the axes?


How to create a histogram of annual events, such as cherry blossom time

I have calculated blooming and ripening times for a specific variety of plant, based on actual temperature data from over 40 years. I would like to create two histograms on a single axis; one for blossoming and one for ripening. Surely there is a more straightforward way than converting to integer dates and adjusting for leap years… Here is some actual data (years have been removed) in the form of `{month, day}`:               {       {4, 3}, {4, 22}, {4, 15}, {4, 2}, {4, 18},        {4, 20}, {4, 12}, {3, 30}, {4, 4}, {4, 24},        {4, 26}, {3, 4}, {4, 26}, {4, 13}, {5, 1},        {4, 4}, {4, 8}, {4, 18}, {4, 9}, {4, 19},        {4, 10}, {4, 20}, {4, 3}, {4,4}, {3, 21},        {4, 19}, {4, 15}, {4, 17}, {4, 9}, {4, 17},        {4, 9}, {4, 8}, {4, 23}, {4, 17}, {4, 1},        {4, 10}, {4, 15}, {4, 15}, {4, 11}, {4, 15},        {4, 19}, {4, 22}, {4, 11}, {4, 4}, {4, 12},        {3, 27}, {3, 24}, {4, 26}, {3, 28}, {4, 16}     }


Generate a Combination of letters by a number

I'm trying to write a function `f`. example:                f /@ Range[0, 52]           (* ==> {A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,        AA,AB,AC,AD,AE,AF,AG,AH,AI,AJ,AK,AL,AM,AN,AO,AP,AQ,AR,AS,AT,AU,AV,AW,AX,AY,AZ,BA} *)          f /@ (10^Range[8])          (* ==> {K,CW,ALM,NTQ,EQXE,BDWGO,UVXWK,HJUNYW} *)      How I do it?


Metaprogramming in Mathematica

Being functional, and having no "quotation", i.e. essentially treating data and programs semantically same, Mathematica seems naturally capable of doing metaprogramming. But could anyone construct a more thorough analysis about this? If you think there is any missing elements that prohibit Mathematica from doing (practical) metaprogramming, could you give an example?


How to change the default ColorData used in Mathematica's Plot?

This question leads on from the recent question What are the standard colors for plots in Mathematica? There it was determined that the default color palette used by `Plot` is _equivalent_ to `ColorData[1]` (see the note at the end). This can be changed through the use of the option `PlotStyle`. My question is how can we make, e.g., the default color palette be `ColorData[3]` **and** have this default survive manual changes to other aspects of the plot styling? * * * So, for example, let's make a list of monomials and some dashing settings               fns = Table[x^n, {n, 0, 5}];     dash = Table[AbsoluteDashing[i], {i, 1, 6}];      Note that the default plot colors survive other choices to styling:               GraphicsRow[{Plot[fns, {x, -1, 1}], Plot[fns, {x, -1, 1}, PlotStyle -> dash]}]      ![default](http://i.stack.imgur.com/XY43s.png) The colors in the plot may be changed by locally setting `PlotStyle`, such as               Plot[fns, {x, -1, 1}, PlotStyle -> ColorData[3, "ColorList"]]      or by setting the default options. Let's do that and run the `GraphicsRow` command again:               SetOptions[Plot, PlotStyle -> ColorData[3, "ColorList"]];     GraphicsRow[{Plot[fns, {x, -1, 1}], Plot[fns, {x, -1, 1}, PlotStyle -> dash]}]      ![ColorList 3](http://i.stack.imgur.com/eYMqM.png) Note that the new colors in the default plot style is overwritten by the use of `PlotStyle -> dash`. This can be manually fixed, in this case, with `Transpose[{dash, ColorData[3, "ColorList"][[1 ;; 6]]}]`, but you don't want to do that every time. Changing the default `PlotStyle` will always have this problem. You'd expect there to be a default `ColorData` or color scheme setting somewhere, but I have been unable to find it. * * * Note that running the hack               Unprotect[ColorData];     ColorData[1] := ColorData[3]     ColorData[1, a__] := ColorData[3, a]     Protect[ColorData];      does not fix the default plot colors. Which probably means that the default internals of `Plot` does not make an explicit call to `ColorData`... * * * It's also interesting to note that when running a `Trace[Plot[...],TraceInternal -> True]` the colors seem to appear out of nowhere! I looked at such a trace in trying to answer this recent SO question related to how Mathematica determines the number of lines and thus colors it needs in a plot.


Implementing a dictionary data structure

As one learns from a course on data structures, hash maps or dictionaries can be efficient when applied to appropriate tasks. I need a hash map in _Mathematica_ and I've never found it. I'm scratching in one of my notebooks files, and I find myself still using the following code (Leonid Shifrin) to simulate this data structure.               ClearAll[linkedList, toLinkedList, fromLinkedList, addToList, pop, emptyList];     SetAttributes[linkedList, HoldAllComplete];     toLinkedList[data_List] :=        Fold[linkedList, linkedList[], data];     fromLinkedList[ll_linkedList] :=         List @@ Flatten[ll, Infinity, linkedList];          addToList[ll_, value_] := linkedList[ll, value];     pop[ll_] := Last@ll;     emptyList[] := linkedList[];          ClearAll[makeHash];     makeHash[] := Module[{hash},         hash[_] := emptyList[];        hash /: add[hash, key_, value_] := ash[key] = addToList[hash[key], value];        hash /: get[hash, key_] := fromLinkedList@hash[key];        Return[hash]];      I was wondering if any of you had needed a dictionary. If you have, I would like know how you implemented it. I'm interested to use a `map<string, int>`.


Very long Refine/Solve batch run - is my code broken, or just complicated?

So I'm trying to run some Mathematica code in batch mode from my university cluster. Specifically, I'm trying to find the equilibria of a system of ordinary differential equations. Inspired by the answer to my original question on the Math site, I'm using a combination of Refine and Solve for this. Code for a simpler but related system, which runs swimmingly on either the cluster or my own machine is this: ![enter image description here](http://i.stack.imgur.com/huWKw.png) Since then, I've tried to run this adapted code for a considerably more complicated system: ![enter image description here](http://i.stack.imgur.com/vUVnV.png) This is taking _forever_. In the "longer than a day, devoured all the RAM on a 48 Gb cluster node and was well on its way to eating the RAM on a 96 Gb node before I killed it" sense of the word. Which is fine if the code is actually working - it's something of a hard problem for a computer to do, and if it just _takes_ a long time, so be it. My problem is there's also the distinct possibility I've done something wrong, created a runaway process, etc. and I'm not a good enough Mathematica programmer to spot it (I'm a rather poor Mathematica programmer in fact). Anyone able to spot anything clearly pathological about what I've done? Edit: Adding in editable/cut-and-pasteable code. Converting between the standard form and the input form has changed the code slightly, including swapping Simplify and Solve, but I have no idea if that matters.               Refine[(Simplify[#1, ϑ > 0 && ρp > 0 && σp >             0 && ρd > 0 && σd > 0 &&                  ρa > 0 && σa > 0 &&            1/ω > 0 && α > 0 && ψp > 0 && μp > 0 &&                  μa > 0 && θp > 0 && νup > 0 && θ >             0 && ζ > 0 && ψa > 0 &&                  θa > 0 && νua > 0 && γ > 0 && ϕ >             0 && κ > 0 && νcp > 0 &&                  τ > 0 && νca > 0] & )[          Solve[{ϑ*H - ρp*σp*            Cp*(Us/N) - ρd*σd*D*(Us/N)*ρa*σa*            Ca*(Us/N) == 0,               ρp*σp*Cp*(Us/N) + ρd*σd*            D*(Us/N)*ρa*σa*Ca*(Us/N) + ϑ*H == 0,               (1/ω)*Ua - α*Up - ρp*ψp*            Up*(H/N) - μp*σp*Up*(Cp/N) -                   μa*σa*Up*(Ca/N) - θp*            Up + νup*(θ*M + ζ*D) == 0,               α*Up - (1/ω)*Ua - ρa*ψa*            Ua*(H/N) - μp*σp*Ua*(Cp/N) -                   μa*σa*Ua*(Ca/N) - θa*            Ua + νua*(θ*M + ζ*D) == 0,               (1/ω)*Ca + γ*ϕ*D + ρp*ψp*            Up*(H/N) + μp*σp*Up*(Cp/N) +                   μa*σa*Up*(Ca/N) - α*Cp - κ*            Cp - θp*Cp + νcp*(θ*M + ζ*D) == 0,               α*Cp + γ*(1 - ϕ)*D + ρa*ψa*            Ua*(H/N) + μp*σp*Ua*(Cp/N) +                   μa*σa*Ua*(Ca/N) - (1/ω)*            Ca - κ*τ*Ca - θa*Ca +                   νca*(θ*M + ζ*D) ==           0, κ*Cp + κ*τ*Ca - γ*ϕ*            D - γ*(1 - ϕ)*D -                   ζ*D + νd*(θ*M + ζ*D) == 0,          Us + H + Up + Ua + Cp + Ca + D == 0,               Up + Ua + Cp + Ca + D == 0}, {Us, H, Up, Ua, Cp, Ca, D, N,          M}, Reals]], Null]      **Update** Per some suggestions below, am now trying the following:               Solve[{ϑ*H - ρp*σp*          Cp*(Us/N) - ρd*σd*D*(Us/N)*ρa*σa*          Ca*(Us/N) ==         0, ρp*σp*Cp*(Us/N) + ρd*σd*          D*(Us/N)*ρa*σa*Ca*(Us/N) + ϑ*H ==         0, (1/ω)*Ua - α*Up - ρp*ψp*          Up*(H/N) - μp*σp*Up*(Cp/N) - μa*σa*          Up*(Ca/N) - θp*Up + νup*(θ*M + ζ*D) ==         0, α*Up - (1/ω)*Ua - ρa*ψa*          Ua*(H/N) - μp*σp*Ua*(Cp/N) - μa*σa*          Ua*(Ca/N) - θa*Ua + νua*(θ*M + ζ*D) ==         0, (1/ω)*Ca + γ*ϕ*D + ρp*ψp*          Up*(H/N) + μp*σp*Up*(Cp/N) + μa*σa*          Up*(Ca/N) - α*Cp - κ*Cp - θp*          Cp + νcp*(θ*M + ζ*D) ==         0, α*Cp + γ*(1 - ϕ)*D + ρa*ψa*          Ua*(H/N) + μp*σp*Ua*(Cp/N) + μa*σa*          Ua*(Ca/N) - (1/ω)*Ca - κ*τ*Ca - θa*          Ca + νca*(θ*M + ζ*D) ==         0, κ*Cp + κ*τ*Ca - γ*ϕ*          D - γ*(1 - ϕ)*D - ζ*          D + νd*(θ*M + ζ*D) == 0,        N == Us + H + Up + Ua + Cp + Ca + D,        M == Up + Ua + Cp + Ca + D , ϑ > 0, ρp >         0, σp > 0, ρd > 0, σd > 0, ρa >         0, σa > 0, ω > 0, α > 0, ψp > 0, μp >         0, μa > 0, θp > 0, νup > 0, θ > 0, ζ >         0, ψa > 0, θa > 0, νua > 0, γ > 0, ϕ >         0, κ > 0, τ > 0, νca > 0, νd > 0}, {Us, H, Up,        Ua, Cp, Ca, D, N, M}, Reals]      It hasn't immediately solved the problem (let it run for ~hour on a local machine), but sending it to the cluster to see if it gets fixed.


Comparing Unequal Lists of Surnames to Establish Over or Under-Representation

I've been using _Mathematica_ to explore historical records. I have two long lists (one is 69k, the second 17k) of unequal length. They are like so (FWIW, the first list is the first 40 entries from the surnames of First World War attestation papers; the second list is the first 30 entries from the surnames of First World War war grave surnames - I have created percentage lists, to get a sense of how frequent their names were amongst all names):               atts={{"SMITH", 0.10031}, {"BROWN", 0.0555427}, {"WILSON",        0.0451438}, {"MCDONALD", 0.0411175}, {"JONES",        0.0375836}, {"TAYLOR", 0.0356139}, {"CAMPBELL",        0.033398}, {"JOHNSON", 0.0320656}, {"ANDERSON",        0.0303276}, {"WILLIAMS", 0.0298352}, {"THOMPSON",        0.0289952}, {"MARTIN", 0.0279669}, {"SCOTT", 0.0257944}, {"WHITE",        0.0250413}, {"STEWART", 0.0243606}, {"MILLER", 0.0240854}, {"CLARK",        0.0237088}, {"MACDONALD", 0.0224054}, {"WALKER",        0.0216233}, {"JOHNSTON", 0.0212322}, {"MOORE", 0.0212177}, {"YOUNG",        0.0211888}, {"ROBINSON", 0.0209426}, {"ROSS",        0.0196391}, {"WRIGHT", 0.018437}, {"MURRAY",        0.0182053}, {"ROBERTSON", 0.0181763}, {"MITCHELL",        0.0177273}, {"MCLEOD", 0.0176839}, {"JACKSON", 0.0175825}};              kia={{"SMITH", 0.0452787}, {"BROWN", 0.0260468}, {"WILSON",            0.0195784}, {"JONES", 0.0174415}, {"TAYLOR",            0.0169217}, {"CAMPBELL", 0.0166907}, {"McDONALD",            0.0146694}, {"ANDERSON", 0.0127057}, {"JOHNSON",            0.012417}, {"STEWART", 0.0123592}, {"SCOTT", 0.0120705}, {"WHITE",            0.0118394}, {"WILLIAMS", 0.0116662}, {"THOMPSON",            0.0115507}, {"MARTIN", 0.0107421}, {"WALKER", 0.0106844}, {"MOORE",            0.0103956}, {"CLARK", 0.0102224}, {"YOUNG", 0.0101646}, {"MILLER",            0.0101646}, {"ROSS", 0.00987583}, {"ROBERTSON",            0.00981808}, {"REID", 0.00958706}, {"WRIGHT", 0.00918279}, {"KING",            0.00912504}, {"MURRAY", 0.00895178}, {"MITCHELL",            0.008432}, {"JOHNSTON", 0.00825874}, {"HALL",            0.00820098}, {"MORRISON", 0.00814323}};      Does _Mathematica_ have a function that could help compare these two lists? I'm trying to think of a systematic way to establish that McDonald, for example, is under-represented in the war graves (4% of enlistees had the last name McDonald, whereas only 1.4% of dead did so). But since our lists are so long, would there be any way to do this systematically?


Problem with NDSolve

I'm solving a PDE that is partially elliptic. So I need to solve the equation iteratively. My problem is at the end of the code. I'm doing interactions manually in order to evaluate the code. At the second interaction, I don't know why NDSolve doesn't accept the new boundary condition. Please, find comments in the body of the code. Could some one help me?               vm = 5;     r0 = 127.25;     di = r0*2;     de = 273;     v = 0.000000464;     ρf = 958;     pr = 2.88;     kf = 0.656;     cf = 4186;     hi=35308.2;         αf = kf/(ρf*cf)     f=0.0174719     c1 = (-f*ρf*vm^2/(4*r0/1000))     tinf=298;     tme=373;     re = (vm*(2*r0/1000)/v)               ym[r_] := (((r0/1000) - r)*vm*(f/8)^(0.5))/v;     εm[r_] := v*(0.4*ym[r]/6)*(1 + (r/(r0/1000)))*(1 + 2*(r/(r0/1000))^2);            momento = NDSolve[{(1/r)*D[(v + εm[r])*r*D[u[r], r], r] == (1/ρf)*c1,u'[0.0000001] == 0, u[(r0/1000)] == 0},u[r], {r, 0.0000001, (r0/1000)}, MaxSteps -> 10000]; (*considerando difusividade de momento*);     mom[r_] = u[r] /. First[momento];          hi = (kf/(2*r0/1000))*((re - 1000)*pr*(f/8))/(1 + 12.7*(f/8)^0.5*(pr^(2/3) - 1))     umed=5.47              tmed[x_, t_] = 310;     ttf[x_, r_, t_] = tinf;     l = 160;     tempo = 80;          (*While[erro≥eps,*)          enf1 = NDSolve[{(ρf*cf*(D[tf[x, r, t], t] + mom[r]*D[tf[x, r, t], x])) == ((1/r)*        D[(r*(αf + εm[r])*D[tf[x, r, t], r]), r]),tf[x, r, 0] == (tme - tinf)*Exp[-1000*x] + tinf, tf[0, r, t] == tme, (D[tf[x, r, t], r] /. r -> 0.0000001) ==       0, -kf*(D[tf[x, r, t], r] /. r -> (r0/1000)) == (1 - Exp[-1000*x])*(1 - Exp[-1000*t])*hi*(tmed[x, t] - ttf[x, r0/1000, t])}, tf[x, r, t], {x, 0, l}, {r, 0.0000001, (r0/1000)}, {t, 0, tempo}, Method -> {"MethodOfLines", "SpatialDiscretization" -> {"TensorProductGrid", "MinPoints" -> 13}}];      tff[x_, r_, t_] = tf[x, r, t] /. First[enf1];          Clear[med]          (*this calculates the average temperature*)     med[x_?NumericQ, t_?NumericQ] := (NIntegrate[(mom[r]*tff[x, r, t]*r), {r, 0.0000001,        r0/1000}])*(2/((r0/1000)^2*umed));          (*an evaluation of med[x,t] at x=0 shows that med is numeric at this position. this is valid for any time*)     med[0, tempo/2]     373.          (*so, it is created a new function that shall be numerically equal to med[x,t]*)     tmed1[x_?NumericQ, t_?NumericQ] := Evaluate[med[x, t]]      Up to here, everything is ok.               (*so, the code returns to NDSolve. The only thing that has changed here is tmed to tmed1. Why the mistake??*)          enf1 = NDSolve[{(ρf*cf*(D[tf[x, r, t], t] + mom[r]*D[tf[x, r, t], x])) == ((1/r)*        D[(r*(αf + εm[r])*D[tf[x, r, t], r]), r]), tf[x, r, 0] == (tme - tinf)*Exp[-1000*x] + tinf, tf[0, r, t] == tme, (D[tf[x, r, t], r] /. r -> 0.0000001) ==       0, -kf*(D[tf[x, r, t], r] /. r -> (r0/1000)) == (1 - Exp[-1000*x])*hi*(tmed1[x, t] - ttf[x, r0/1000, t])}, tf[x, r, t], {x, 0, l}, {r, 0.0000001, (r0/1000)}, {t, 0, tempo}, Method -> {"MethodOfLines", "SpatialDiscretization" -> {"TensorProductGrid", "MinPoints" -> 13}}];     tff[x_, r_, t_] = tf[x, r, t] /. First[enf1];      > >     NDSolve::ndnum: Encountered non-numerical value for a derivative at x == > 0.`. >> >   PS: The original message on WOLFRAM community is here: http://community.wolfram.com/groups/-/m/t/317994?p_p_auth=NrBn8wS0


Optimise CPU-intensive list combining function

I have a list of numbers `list1` from which I want to create another list (`list2`) consisting of only those numbers that are equal to the sum of _any_ two members of `list1`, as long as the total is under 15. So for example if `list1 = {1,4,6,8}`, then I want `list2 = {2,5,7,8,9,10,12,14}`. I could do this by: `list2 = Union[Flatten[Table[Table[i + j, {i, list1}], {j, list1}]]]` which does give the right result, but then I run into two problems:   1. I have no idea how to filter the list so that it only displays numbers less than 15. I tried appending `/; x_ < 15` to the end, but this didn't do anything   2. This works fine for a list this small, but what I really want to do is scale this up to a list consisting of several thousand elements - for which it takes a very long time, and crashes my computer in the process. How could I make this function more efficient? Thank you


How to asynchronously download 100000 urls in an efficient way

`URLSaveAsynchronous` can download one url page, how to download 100000 urls in an efficient way? And better to with an whole progress bar. I've downloaded 90000 htmls a web-dictionary in mathematica this way, I think it's interesting.               progress= 0.;     progFunction[_, "progress", {dlnow_, dltotal_, _, _}]:= Quiet[progress = dlnow/dltotal]     Dynamic[ProgressIndicator[progress]]          cells = Table[Defer[URLSaveAsynchronous][urls[[i]], names[[i]], progFunction,      "Progress" -> True], {i, 10000}];      Here is the working Document.               CreateDocument[ExpressionCell[#, "Input"] & /@ cells]      Maybe can speed up it? Another aspect is how to do the whole job in Mathematica more comfortably. To build the download tasks took so much time in the working document which looks like I'm not downloading in an asynchronous way.


Gather lists according to another list

I have a first list of pairs like this one:               list1= {{1, 2}, {3, 4}, {5, 6}, {7, 8}, {9, 10}, {11, 12}, {13, 14}, {15, 16}, {17, 18}, {19, 20}, {21, 22}, {23, 24}, {25, 26}, {27, 28}, {29, 30}, {31, 32}, {33, 34}, {35, 36}, {37, 38}, {39, 40}, {41, 42}, {43, 44}, {45, 46}, {47, 48}, {49, 50}}      And a second one containing information about how the elements of the first list are related:               list2 = {{1, 46}, {5, 27}, {8, 42}, {21, 26, 29}, {31, 45}, {33, 36}, {35, 37}, {47, 49}}      How can I gather elements of the first list using list2 as a reference to get groups like these:               {{{1, 2}, {45, 46}, {31, 32}}, {{5, 6}, {27, 28}}, {{7, 8}, {41, 42}}, {{21, 22}, {25, 26}, {29, 30}}, {{31, 32}, {45, 46}}, {{33, 34}, {35, 36}, {37, 38}}, {{47, 48}, {49, 50}}}      So what it's happening here is that, element `{1, 46}` of list2 is telling that the pair containing element "1" (`{1, 2}`) of list1 is linked to element containing element "46" (`{45, 46}`) and so on. Note that when you use list 2 element `{35, 37}` to gather `{{35, 36}, {37, 38}}` you should consider that list 2 element `{33, 36}` already linked `{{33, 34}, {35, 36}}` so you will have a three element group `{{33, 34}, {35, 36}, {37, 38}}`. I tried to use graph related functions but couldn't make it work. Any ideas?


How to plot a decahedron with Mathematica?

I wrote               Graphics3D[{Opacity[.9], FaceForm[Yellow], PolyhedronData["Dipyramid", "Faces"]}]      and I get this picture: ![decahedron](http://i.stack.imgur.com/FQGu6.jpg) I would like to plot a decahedron without any defects on its surface. How can I do this? Thanks!


Draw an arbitrary convex polyhedron without excess diagonals drawn

I want to draw a set of convex polyhedrons whose vertices are defined by spherical coordinates on the surface of a unit sphere. Currently I followed the advice from here: http://mathematica.stackexchange.com/a/21842/651 But it draws diagonals on any tetragonal face. Each face is composed of triangles. Is it possible to accomplish the same but without tetragonal faces diagonaled? The current code:               Needs["TetGenLink`"]     mapping[{1,0,0}]={0,0,1}     mapping[{1,Pi,0}]={0,0,-1}     mapping:=CoordinateTransformData[{"Spherical"->"Cartesian"},"Mapping"]     verteces[n_]:=Flatten[Table [{1,Pi k/n, i 2Pi/Binomial[n,k]},{k,0,n},{i,0,Binomial[n,k]-1}],1]     Convex[n_]:=TetGenConvexHull[mapping/@ verteces[n]]     pts[n_]:=First[Convex[n]]     surface[n_] :=Last[Convex[n]]     b:=5     Graphics3D[{Yellow,Opacity[.9],GraphicsComplex[pts[b],Polygon[surface[b]]], Black, Line[{{0,0,-1.1},{0,0,1.1}}]}]


What is wrong with this Cobweb plot

Something is wrong with my cobweb plot code but I couldn't figure out where do the mistakes come from. So basically we have the iterative map $x_n == x_{n-1}^{2} - 3 \mu$. I would like to draw a cobweb diagram that shows in the range $-\frac{1}{12}<\mu<\frac{1}{4}$ there exists a fixed point $\frac{1}{2}(1-\sqrt{1+12\mu})$. Below are the code and the diagram: ![enter image description here](http://i.stack.imgur.com/vrHFf.png) ![enter image description here](http://i.stack.imgur.com/6mNGh.png) ![enter image description here](http://i.stack.imgur.com/MJM7P.png) My questions are:   1\. Why the diagonal line in the cobweb is not appearing and why is it replaced by a horizontal blue line?   2\. The label on top is wrong and I couldn't fix it.   3\. How can I fix the cobweb code so that I can show, say let $-\frac{1}{12}<\mu=0.2<\frac{1}{4}$ and initial value 2, there is a convergence towards a fixed point $\frac{1}{2}(1-\sqrt{1+12\mu})$. Many thanks. I really appreciate any helps.


"The function DiscretizeGraphics is not implemented for GraphicsComplex" confusion

Why does `DiscretizeGraphics` seems to work on one `GraphicsComplex` and not the other? Here is an example that works:               v = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};     p1 = Graphics[GraphicsComplex[v, Polygon[{1, 2, 3, 4}]]];     DiscretizeGraphics[p1]      But this does not               p2 = Graphics3D[First@ParametricPlot3D[{Cos[t],  Sin[u], c Sin[t]},         {u, 0, 2 Pi}, {t, 0, 2 Pi}]];     DiscretizeGraphics[p2]          (*The function DiscretizeGraphics is not implemented for \      GraphicsComplex[{{0.9999999999998993`,4.487989505128125`*^-7,*)      But `p2` is a GraphicsComplex? Looking at `FullForm[p2]` ![Mathematica graphics](http://i.stack.imgur.com/UmA56.png) Here is the `FullForm` for `p1` ![Mathematica graphics](http://i.stack.imgur.com/C8qcA.png) Are not `p1` and `p2` both `GraphicsComplex` ? `p1` is `2D` and `p2` is `3D`, but are they not both considered `GraphicsComplex`? ![Mathematica graphics](http://i.stack.imgur.com/mOlfR.png) It will good to know exactly what can and what can not be discretized. I tried to find this, but could not. All what I see are examples of usages so far. reference: http://www.wolfram.com/mathematica/new-in-10/data-and-mesh- regions/discretizing-graphics.html http://reference.wolfram.com/language/ref/DiscretizeGraphics.html?q=DiscretizeGraphics ![Mathematica graphics](http://i.stack.imgur.com/x61d6.png) I also looked at possible issues, and did not notice anything about this. Only one that came close is this `multiple volume primitives is not supported`. Is this the case here?


Expansion of $E(i c \mid m)$ at $c\to\infty$?

Currently, I am using a Windows machine with _Mathematica 8_. I noticed a difference in a series expansion of the function `EllipticE[]` in comparison with a result given by _Mathematica 9_ on Linux (which I was using previously). In _Mathematica 8_ on Windows the following input:               Series[EllipticE[I c, m], {c, Infinity, 0}] // PowerExpand // FullSimplify       produces a warning: > General::ivar: I c is not a valid variable. >> and the following output (slightly rearranged by me to better fit the browser): $$-\frac{i\left(6m+\frac{(1+m)}{\sinh^2(c)}\right)}{6\sinh(c)m^{3/2}}-\text{EllipticE}[m]+\frac{m \text{EllipticE}[\frac{1}{m}] + (1-m)\text{EllipticK}[\frac{1}{m}] }{\sqrt{m}}-$$ $$\frac{(1+m \cosh(2 c))\sqrt{\text{Limit}\big[-m\sinh^2(c)~,~i c \to 0\big]}}{\sinh^2(c)2m}$$ Same output as a code:               -((I (6 m Csch[c] + (1 + m) Csch[c]^3))/(6 m^(3/2))) -       EllipticE[m] +       (m EllipticE[1/m] - (-1 + m) EllipticK[1/m])/Sqrt[m] -       (((1 + m Cosh[2 c]) Csch[c]^2 Sqrt[Limit[-m Sinh[c]^2, I c -> 0]])/(2 m))      Now, in _Mathematica 9_ on Linux there was no such warning, and no `Limit` term appeared. I am confused about how to treat this `Limit` term, since it might just be a sign of something going terribly wrong in the guts of _Mathematica 8_. Does anyone have an advice on how to proceed? Maybe some of you can evaluate the same series expansion in a different version of _Mathematica_ so that we could compare results? ### EDIT Evaluating instead:               Series[EllipticE[c, m], {c, I Infinity, 0}] // PowerExpand // FullSimplify       worked as a charm without errors.


Randomly redrawing part of a random sample that matches a criterion

I would need some (a lot of) help to improve/rewrite some code. Since my real problem is a bit too complicated to explain, I try to show with a simplified scheme what I want to achieve. I create some random numbers on an interval between 0 and 1 with:               maximumRandomNumberFirstStep=10000;     randomNumberFirstStep=RandomReal[{0,1},maximumRandomNumberFirstStep];      Out of some reasons, I am only interested in values which are higher than a special limit value. So, I am searching for these values with:               limitValue=0.5;     helpListFirstStep=ParallelTable[If[randomNumberFirstStep[[i]]<limitValue,i,0],        {i,1,maximumRandomNumberFirstStep}];      For all values which are lower than this limit value I want to generate some new random numbers. At the moment I am doing this with:               maximumRandomNumberSecondStep=maximumRandomNumberFirstStep-Count[helpListFirstStep,0];     randomNumberSecondStep=RandomReal[{0,1},maximumRandomNumberSecondStep];      Now I want to add the new random numbers (randomNumberSecondStep) to all the old random numbers (randomNumberFirstStep) which are below my limit value. I am doing this with this very ugly code:               j=1;     randomNumberSecondStep2=Table[If[         helpListFirstStep[[i]]==0,         {randomNumberFirstStep[[i]],0},         {randomNumberFirstStep[[i]]+randomNumberSecondStep[[j]],j++}     ],{i,1,maximumRandomNumberFirstStep}];     randomNumberSecondStep2=randomNumberSecondStep2[[All,1]];      (By the way, this code does only work with `Table` but not with `ParallelTable` if I execute it more than once. Perhaps somebody has also a solution for that). If one creates a histogram `Histogram[randomNumberSecondStep2]`, it can be seen, that there are still values which are below my limit value. So, I have to copy my code from above, rename Second to Third and execute it again. I am doing this so often until none of my `randomNumberNthStep2`-values are below my limit value. This works, but I think it cannot be programed worse than I am doing it (copying, renaming etc. is really not nice, especially if your real problem is more complicated because of more variables). So, how can I write a better program in which all the copying and renaming steps can be avoided? I think there should be a solution in which all these steps are executed automatically. Unfortunately, my programing skills are too low to develop a nice solution. But I hope that some people here can give some help and hints. I would appreciate every support!


Alternatives to DateQ of Calendar Package

This answer notes that `Calendar` package has a function `DateQ` but the documentation suggests that the input is limited to a fixed format `YY,MM,DD` etc. Is there a more robust way to check any String for date-form ? (Self answer, below)


How to make binary image from black holes on white background

How to convert black holes on white background, so that I can see a binary image of holes on white image or bright dots on black image. ![enter image description here](http://i.stack.imgur.com/Eskg5.png) I can create a mask then also I am stuck with bright dot on black area, and then remaining white area.                ms = ColorNegate[image]      ![enter image description here](http://i.stack.imgur.com/TlMUh.png)


How can I run MUnit TestSuites outside WorkBench?

I would like to run MUnit tests inside TestSuite constructs from the command line or a notebook interface without loading the Workbench GUI. I tried               TestRun["suite.mt"]      where suite.mt contains:               TestSuite[{"file1.mt","file2.mt"}]      and each of the fileX.mt contain standard `Test[...]` constructs. However, this does not run the tests; I get the output that 0 tests were run. `TestRun["file1.mt"]` works. I cannot find documentation for `TestRun`, so maybe it does not support this, but in that case, how do I run testsuite files without loading the Workbench GUI?


Having Trouble Fitting Complicated Exponential Function with FindFit

I am working on high pressure shock experiments and am trying to figure out a the temperature of a sample under strong shocks. I have a measure value from 4 wavelengths of a pyrometer and am using a model to fit these points to a blackbody-like spectrum in order to back out a bulk true temperature, and a temperature of the hot spots/cracks that might also get viewed. The 4 temperature data points, namely:               {{1.8*10^-6, 1266.38}, {2.3*10^-6, 1137.87}, {3.5*10^-6, 901.019}, {4.8*10^-6, 751.279}}      with the second value of each pair corresponding to a real temperature. I am fitting them using the following hot spot model:               hotspotmodel = c2/(lam Log[(1/((1 - alpha)/(Exp[c2/(lam TT)] - 1) + alpha/(Exp[c2/(lam THS)] - 1))) + 1])      I am trying to use FindFit in te following way, but cannot get an answer that makes realistic sense:               pointsfit = FindFit[points, {hotspotmodel, TT > 0}, {{alpha, 0.05}, {TT, 500}, {THS, 2000}}, lam]          ""          function = Function[{lam}, Evaluate[hotspotmodel /. pointsfit]];     p1 = Plot[function[lam], {lam, 10^-7, 6 10^-6}, PlotStyle -> Thickness[.005]];     p2 = ListPlot[points2, AxesOrigin -> {0, 0},  PlotMarkers -> {Automatic, 12}];     Show[{p1, p2}, AxesOrigin -> {10^-7, 400}, PlotRange -> All,  AxesLabel -> {"\[Lambda (m)", "T (K)"}]      The problem is the function is not fitting properly, or returning sensible results. If I take away the constants, it returns a negative true temperature (TT), or a negative hot spot temperature (THS) and then has issues with trying to fit complex variables. My sense of the physical system says that true values should be within ~25% of those guesses. Any idea where I am going wrong? Thanks.


Notation for implicit derivative

Consider the following line of code:               D[x == y^3 + x y, x, NonConstants -> y]      The output would be:               1 == y + x D[y, x, NonConstants -> {y}] + 3 y^2 D[y, x, NonConstants -> {y}]      This is a confusing and cumbersome notation for the more natural:               1 == y + x y' + 3y^2 y'      I am trying to use the Notation package to help me replace the messy, default, output with the more natural one.   I have not succeeded. Of-course I have read this Q. The answer, if relevant, seems inaccessible to me, unfortunately.   Any help would be appreciated.


How to generate a real-time stream of data?

I'm experimenting with Inversion-of-Control (callback) programming patterns, and I would like a way to generate streams of data at specified real-time intervals. I came up with the illustrated way to use Animate (or Manipulate) to do it, and that's fine for experiments with the notebook front end, but I would like to have pure-code solutions I could put in a .m package. As always, I will be grateful for any hints, advice, and solutions! ![enter image description here](http://i.stack.imgur.com/dvVuZ.jpg)


Quick question about the FinancialBond function

If I want the fair price of a bond with coupon interval twice per year with interest rate $i$ p.a., I use "CouponInterval"->1/2. However, **the InterestRate should be the effective, or nominal interest rate?** Thank you for help.