title: Use Simplify option Trig->False when 3rd argument to Collect is Simplify

text: I would like to simplify the following expression               AAA (4 Sin[x]^2 Cos[x]^2) + AAA 4 Sin[x] Cos[x] + AAA      with the `Trig->False` option inside a `Collect`:               Collect[AAA (4 Sin[x]^2 Cos[x]^2) + AAA 4 Sin[x] Cos[x] + AAA, AAA, Simplify]      how can I insert the `Trig->False` condition in such an expression? Thank you in advance


title: Riemann surface for cubic root

text: I'm trying to generate Riemann surfaces of higher order. I read How to visualize Riemann surfaces?, and the subsequent documents. I'm able to reproduce the surface using polar representation, but I'm having a difficult time generating them using rectangular coordinates, for roots greater then 2. So far what I have is:               p1 =       Plot3D[{Im[(x + I*y)^(1/2)], -Im[(x + I*y)^(1/2)]}, {x, -2, 2}, {y, -2, 2},         PlotPoints -> {40, 120}, Mesh -> 25, BoxRatios -> {2, 2, 2},         ColorFunction -> Function[{x, y, z}, Hue[z]]]          p2 =       ParametricPlot3D[         Evaluate[({r Cos[#1], 0, (r)^(1/3) Sin[#1/3]} &) /@ {0, π,2 π, 3 π}],         {r, 0, 2},         PlotStyle -> {{Black, AbsoluteThickness[5]}}]          Show[p1, p2]      ![enter image description here](http://i.stack.imgur.com/d2fCx.jpg) Rectangular coordinates and branches in black               p3 =       ParametricPlot3D[{r Cos[φ], r Sin[φ], r^(1/2) Sin[φ/2]}, {r, 0, 1}, {φ, 0, 4 π},         ColorFunction ->           Function[{x, y, z, r, φ, θ}, {Specularity[#], Glow[#]}& @ Hue[Rescale[φ, {0, 1}]]],         PlotPoints -> {20, 60}, Mesh -> 25]          Show[p3, p2]      ![enter image description here](http://i.stack.imgur.com/Bh4r0.jpg) Polar coordinates with branches in black The square roots are both identical. If I go on the cubic roots, the polar representation is the same with a change from 2 to 3, but I don't know how to modify the rectangular code to generate the same surface. So for example:               p4 =       ParametricPlot3D[{r Cos[φ], r Sin[φ], (r)^(1/3)Sin[φ/3]}, {r, 0, 1}, {φ, 0, 6 π},         ColorFunction ->           Function[{x, y, z, r, φ, θ}, {Specularity[#], Glow[#]}& @ Hue[Rescale[φ, {0, 1}]]],         PlotPoints -> {40, 120},         Mesh -> 25]          p5 =       ParametricPlot3D[         Evaluate[({r Cos[#1], 0, (r)^(1/3) Sin[#1/3]} &) /@ {0, π,2 π, 3 π, 4π, 5π}],         {r, 0, 2},         PlotStyle -> {{Black, AbsoluteThickness[5]}}]          Show[p4, p5]      ![enter image description here](http://i.stack.imgur.com/NVq86.jpg) Cubic root in polar with branches in black I have no idea how to get the same cubic root surface using polar coordinates.


title: Symbolic solution of system

text: everyone! I am sorry, but I am an abcolute novice of Mathematica (to be more precise this is my first day of using it) and even after surfing the web and all documents I am not able to solve the following system:               Solve[{y*(((y*x)/(beta*b))^(1/(beta - 1)) - v) - c*alpha ==         0, ((x/alpha))*(((y*x)/(alpha*beta*b))^(1/(beta - 1)) -             v) + (((y*x)/alpha) -             2*alpha*((yx)/(2*beta*b))^(1/(beta - 1)))*(1/(beta -               1))*(x/(alpha*beta*              b))*((y*x)/(alpha*beta*b))^((2 - beta)/(1 - beta)) == 0}, {x,        y}]      What I need is to solve following systems, getting x and y expressed through all these symbols. Is it even possible? Thank you in advance.


title: Comparing 2 Data Sets in a Single Plot

text: I have 2 data sets, `data1` and `data2` with large (in the thousands) amounts of data and I want to compare them in a plane. They aren't modeled by the normal distribution, but I'm using that here for simplicity.               data1 = RandomReal[NormalDistribution[], {10000, 2}];     data2 = data1+1;      I can put these on a list plot and plot them. However, this is visually unpleasing and even hides some of the data.               combPlot = ListPlot[{data1, data2},         PlotRange->All,         PlotStyle->PointSize[0.01],         PlotStyle->Directive[Opacity[0.5]]     ];     Export[Directory[] <> "/figures/test-comb.pdf", combPlot];      ![](http://imgur.com/ylFd9.png) The `SmoothDensityHistogram` command with the following color function shows the data exactly how I want it for each data set.               histOpts = {ColorFunction -> Function[c, GrayLevel[1 - c]],         PlotRange -> {{-4, 4}, {-4, 4}}, ImageSize -> Medium};     hist1 = SmoothDensityHistogram[data1, histOpts];     Export[Directory[] <> "/figures/test-hist1.pdf", hist1];     hist2 = SmoothDensityHistogram[data2, histOpts];     Export[Directory[] <> "/figures/test-hist2.pdf", hist2];      ![](http://i.imgur.com/z20jC.png) ![](http://i.imgur.com/vtZSJ.png) How can I combine these into a single plot, preferably with different colors? I had no success using the `Show` command. Again, the idea is to visually compare the 2 data sets. If there are any other alternatives, I'd like to see them too. * * * Update: After seeing Diego Zviovich's post, I was able to get it working for my example. However, my actual data sets may significantly differ so the bounds aren't the same:               data1 = RandomReal[NormalDistribution[], {10000, 2}];     data2 = data1+10;          hist1 = SmoothDensityHistogram[data1,         ColorFunction->Function[c, Hue[215/360, .973, 1, c]],          PlotRange->All, ImageSize -> Medium];     hist2 = SmoothDensityHistogram[data2,          ColorFunction->Function[c, Hue[311/360, .973, 1, c]],          PlotRange->All, ImageSize -> Medium];     combHist = Show[         Rasterize[hist1],         Rasterize[hist2],         PlotRange->All     ];          Export[Directory[] <> "/figures/test-hist1.pdf", hist1];     Export[Directory[] <> "/figures/test-hist2.pdf", hist2];     Export[Directory[] <> "/figures/test-combHist.pdf", combHist];      data1: ![](http://i.imgur.com/Wrtky.png) data2: ![](http://i.stack.imgur.com/qp6Wn.png) Combined: ![](http://i.stack.imgur.com/jgGph.png) ~~How do I correct the bounds for this?~~ * * * Update: Using m_goldberg's suggestion, I'm able to get what I want: ![](http://i.stack.imgur.com/gD1HV.png) I'll leave this opened for a little for any further discussion, but I'm satisfied with this now. Thanks to everyone who helped! * * * Further update (sorry): I'm a little unsatisfied with the results for my actual data. The first one appears fine, but the second is overly distorted: ![](http://i.stack.imgur.com/pD2mv.png) ![](http://i.stack.imgur.com/TF6e9.png) Does anybody have any further suggestions for these?


title: Automatically wrap abritrary-length text in graphics

text: **Question:** How to insert `Style`d text of unknown style and length into a graphics and have it wrap at a `Scaled` width? **Attempt:** I found the following two ways to wrap text when I was googling:               (* Based on: http://forums.wolfram.com/mathgroup/archive/2008/Mar/msg00977.html *)     syd[txt_, w_: 100, h_: 50] :=       Graphics[{Inset[Framed@txt, {0, 0}, {0, 0}, {w, h}]}]          (* Based on: http://forums.wolfram.com/mathgroup/archive/2008/Mar/msg00916.html *)     fred[txt_, w_: 150] := Graphics[{        Inset[Framed@Pane[Style[txt, LineIndent -> 0, TextAlignment -> Left], w], {0, 0}]        }]      But I want to handle text of unknown length so I did this to Syds solution:               (* Since {w,h}={100,50} worked for a string of length 460     it's reasonable to assume each character needs (100*50)/460 area units,     so any string should have area of StringLength[txt]*(100*50)/460 \     since w is given let      h=StringLength[txt]*(100*50)/(460*w)     *)     sydGuessHeight[txt_, w_: 100] :=       Graphics[{Inset[         Framed@txt, {0, 0}, {0, 0}, {w,           StringLength[txt]*(100*50)/(460*w)}]},        PlotLabel -> Style["syd guess: w=" <> ToString[w], Red, Bold]]      A test:               txt1 = (StringJoin @@          Table["The quick brown fox jumped over the lazy dog. ", {10}]);     txt2 = (StringJoin @@          Table["The quick brown fox jumped over the lazy dog. ", {20}]);     Grid[Partition[Image /@ {         syd[txt1],         syd[txt2],         syd[txt2, 100, Automatic] ,         fred[txt1],         fred[txt2],         sydGuessHeight[txt2]}, 2]]      ![enter image description here](http://i.stack.imgur.com/YlGmH.png) This is all very inelegant and I still can't use it to wrap text of a `Scaled` width nor can I supply `Style`d text since any modification in font will break the guess.


title: Extracting Pareto elements from a list

text: How can I extract the Pareto elements from a list? For example, for that list:               list = {      {"A&W", 15}, {"Bubbly", 19}, {"Aquabona", 42},       {"Lanitis Extra", 91}, {"Ayataka", 80}, {"DASANI Nutriwater", 12},       {"diet Lift/Lift light", 2}, {"Minute Maid Antiox", 74},       {"Bimbo", 40}, {"Minute Maid Deli", 5}, {"Fire", 69}, {"Club",14},       {"Nada", 46}, {"Bu", 46}, {"Aybal", 29}, {"Kin",73},       {"Minute Maid Just 10", 31}, {"Hero", 90}, {"diet Oasis",65}, {"Canada Dry", 30}     }      I want to get this result:               {{"Lanitis Extra",91},{"Hero",90},{"Ayataka",80},{"Minute Maid Antiox",74},      {"Kin",73},{"Fire",69},{"diet Oasis",65},{"Nada",46},{"Bu",46},{"Aquabona",42}}      ![enter image description here](http://i.stack.imgur.com/h2cX8.png) So that these products represent approximately 80% of the total value. The final list can be sorted or not and the real case has 15,000 elements. Make no difference for my purpose that is to tag these products as special ones.


title: Why might ListStreamPlot fail to cover StreamPoints?

text: I have a pretty sparse array of vectors (in the colloquial sense that it covers the domain sparsely; it's not a `SparseArray`). `ListStreamPlot` without options was only showing one stream. I'm trying to pass in an array of `StreamPoints` to hit (namely, the points for which vectors are defined), but most still end up not hit: ![sparse StreamPoints failing to hit](http://i.imgur.com/3SOWua6.png) You can see the notebook here: https://dl.dropboxusercontent.com/u/13934821/incomemobility.nb My guess is my vector array (21 vectors from this data on income mobility (pdf link)) is too sparse, and the vector field ends up kind of, um, underspecified? Does that make any sense?


title: Import a data stored in EXCEL and change it to a Table

text: I have an EXCEL file in which large amount of numbers is stored in a column in the first sheet, like data in the column A of the sheet1 of excel file. When I apply the Import function; the data is imported into Mathematica like this: {{{1},{2},{3}}}. But I want them to be in form of a one dimensional table or array like: {1, 2, 3}. How is this possible?


title: Summa package problem

text: I need to use the features of the Summa package but it doesn't work in _Mathematica_ 9\. It gives the error               Cannot open Utilities`FilterOptions`      My question is: Is there an alternative (more modern) package with similar features, or a way to make `Summa.m` work in _Mathematica_ 9? * * * Following @Nasser I solved it. The problem was that the input of `FilterRules` is in opposite order, e.g.               FilterOptions[Expand,{opts}]      is changed to               Sequence@@FilterRules[{opts},Options@Expand]


title: Understanding Function and Variable in Mathematica for beginner

text: I'm reading the book of Leonid Shifrin, and I love the way the book explains the core in `Mathematica`. As everything is an expression, now I understand that, there are no real function or variable in `Mathematica`. Function is such an indexed variable containing several rules.               Head /@ {Sin, Sin[x], x, 3}     AtomQ /@ {Sin, Sin[x], x, 3}     Attributes /@ {Symbol, String, Integer}      > {Symbol, Sin, Symbol, Integer} > > {True, False, True, True} > > {{Locked, Protected}, {Protected}, {Protected}} So both function `Sin` and variable `x` are `Symbol`. Everything in `Mathematica` is Symbol, String, or Number. This principle helps me a lot.               f = Sin;     g = Sin[x];     {f[x], g[x]}      > {Sin[x], Sin[x][x]} Without this principle, a beginner can think that the function `g` equals to the function `Sin[x]`. So `g[x]` should return as `Sin[x]`. And he can think that the definition `f = Sin` is impossible because Sin should be expressed as a function Sin[something]. But here, we can see that `Mathematica` is very flexible. If we consider `Sin` as a variable, so assigning `f = Sin` is totally correct. And `g[x]` is not equal to `Sin[x]`, but `Sin[x][x]`. I think this is a very basic thing, that a beginner should remember. So many books on `Mathematica` don't explain these principles, they just teach how to use the command. But understanding the core in Mathematica for me is much more important, because it is the basic to master `Mathematica` programming style. Thank you Leonid Shifrin. As now, I see that functions and variable are `Symbol`. Beside `Symbol`, could we use another type as a variable? For example, I would like to have a list of 40 variables a1=1, a2=2, a3=3,... a40=40. But I don't want to use indexed variable `a[1]`, `a[2]`, `a[3]`, `a[40]` because for me, it is just one variable `a` with several index. Of course, the natural way is typing `a1 = 1`, `a2 = 2`, ... `a40 = 40` manually. But how to do it in automatically in a loop or table way? My first try is to generate `"a1"`, `"a2"`, ... `"a40"` as `String`.               "a" <> # & /@ ToString /@ Table[i, {i, 3}]      > >     {"a1", "a2", "a3"} >   But `String` can not be used as variable....               {"a1", "a2", "a3"} = {1, 2, 3}      > Set::setraw: Cannot assign to raw object a1. >> So how to generate a list of variable? a1, a2, a3...? I try to use `ToExpression` to convert the String to Expression, I got a list of variable a1,a2,a3.               ToExpression["a" <> # & /@ ToString /@ Table[i, {i, 3}]]      > {a1, a2, a3} I'm trying to assign the value: (*)               ToExpression["a" <> # & /@ ToString /@ Table[i, {i, 3}]]] = {1, 2, 3}      > Set::write: Tag ToExpression in ToExpression[{a1,a2,a3}] is Protected. > >> > What is wrong here. I try to add Evaluate on the l.h.s:               Evaluate@ToExpression[        "a" <> # & /@ ToString /@ Table[i, {i, 3}]] = {1, 2, 3}     {a1, a2, a3}      > {1, 2, 3} Finally, it works. But are there any another way than this way (too long) to generate a list of variable `a1`, `a2`, `a40`? and why I need to `Evaluate` the l.h.s at (*) before `Set` to {1,2,3} ? Edit: Thanks to @RunnyKine, now I understand why I must `Evaluate` at (*) before using `Set`. > "because when using Set, Mathematica evaluates the R.H.S. and leaves the > L.H.S. unevaluated."


title: Hungarian Algorithm using BipartiteMatchingAndCover Function

text: I have a bipartite graph with two sets of vertices.               Needs["Combinatorica`"]     g = CompleteGraph[3, 3];     edgeWeights = {{53, 96, 37}, {47, 87, 41}, {60, 92, 36}};     g1 = SetEdgeWeights[g, Flatten[edgeWeights]];      I want to find the optimal assignment that minimizes the total cost (sum of assigned edges). For this I use:               BipartiteMatchingAndCover[g1]      The answer I get is {{1, 5}, {2, 6}, {3, 4}}, which tells me that vertex 1 is assigned to vertex 5, 2 is assigned to 6 and 3 is assigned to 4. These assignments correspond to a total cost of 96+41+60 = 197. I would have expected the answer to be {{1,6},{2,4},{3,5}} which corresponds to a total cost of 37+47+92=176. It seems like the function is finding the assignments associated with the maximum cost instead of the minimum cost. I tried using `1/edgeWeights` as edge weights, but got the same result. Any ideas?


title: Using sublists returned from a function as elements of a list argument to an other function

text: This is a contrived example, but it gets the point across. I am looking to use the following as inputs:               a = {10, 11};     b = {5, 7};     MakeCD[x_] := {{x, 2 x}, {3 x, 4 x}};      to function that takes a list of sublists. `ListPlot` is a suitable example of the function. Using `1` as the argument to `MakeCD`, `MakeCD` returns: `{{1, 2}, {3, 4}}` I am looking to supply `{{10, 11}, {5, 7}, {1, 2}, {3, 4}}` to `ListPlot` I can achieve this with the following:               {c, d} = MakeCD[1];     {a, b, c, d}      Also with:               Join[{a}, {b}, MakeCD[1]]      I am sure there is a better way to do this, but I have not yet stumbled upon it yet.


title: ListPlot, PlotMarker -> y value

text: at first sorry if this question is already answered. I would like to display y value as plot marker in listplot               ll = {{33, 11, 2}, {3, 5, 4}, {6, 4, 8}}     Table[ListLinePlot[ll[[i, 1 ;; 3]], PlotLabel -> i,        PlotMarkers -> valueY], {i, 3}]      Gives me output like this: ![output from code](http://i.stack.imgur.com/qlZM9.png) and I'd like to have 33, 11, 2 instead of valueY. Thanks in advance.


title: Marking specific points on a 3D curve

text: Here is the curve below. (written as a position vector)               r = {Cos[7 Pi*t], Cos[6.2*Pi*t], 2.5*t}     ParametricPlot3D[r, {t, 0, 2}]      I want to know how I can mark specific points on this curve, for example when `t = 0` and `t=1`. I would also like to label those points.


title: Sorting a list and finding an array of indices that sorts the list

text: How can I sort a list and also get a list of indices that sort this list? For example: primary list is a               a={1,4,6,7,0,2};      sorted list is b               b={7,6,4,2,1,0}      and also return list c               c={4,3,2,6,1,5}


title: Code performance problem

text: Could anyone help me with the attached code? How would you speed up my attached code in some degree? Your comments are highly welcome.               ClearAll["Global`*"];     α = 0.95; k = 1000; M = 25000;          t0 = 0; tf = 25; h = (tf - t0)/M;          g1[t_] := 0.55;          x1[i_ /; -k <= i <= 0] := g1[t];          t[j_] := j*h          alfa = 0.75;          f1[t_, u_, v_] := u - u*u*u - alfa*v          x1[j1_] := x1[j1] =         g1[0] + (h^α/Gamma[α + 2])*          f1[t[j1],            g1[0] + (1/Gamma[α])*             Sum[(h^α/α)*((j1 - 1 + 1 - j)^α - (j1 -                     1 - j)^α)*                          f1[t[j], x1[j], x1[j - k]], {j, 0, j1 - 1}],            x1[j1 - k]] + (h^α/Gamma[α + 2])*               Sum[Which[             j == 0, (j1 - 1)^(α + 1) - (j1 -                  1 - α)*(j1 - 1 + 1)^α,              1 <= j <= j1 -            1, (j1 - 1 - j + 2)^(α + 1) + (j1 - 1 -              j)^(α + 1) -                     2*(j1 - 1 - j + 1)^(α + 1), True, 1]*        f1[t[j], x1[j], x1[j - k]], {j, 0, j1 - 1}];           ListLinePlot[Table[{t[n], x1[n]}, {n, 0, 25000}]]


title: How do I slice an image of size "width × height" in n² pieces of size "width / n × height / n"?

text: Background: What I want is to make a jigsaw from an image. (A simple one where the pieces are polygons.) I have the following strategy in mind. Create a set of polygons and assign images (or just the original image) to them as a texture and set the texture coordinates. I know from the documentation (Lena example) how to use an image as a texture. Is chopping up the image in parts and assign these parts as textures a feasible strategy? If so, then I have the following question: **Question: Given an image of size width × height, how do I slice it in n² pieces of size width / n × height / n ?**


title: Removing commented lines of text in a string

text: Suppose that I have a string `str`. `str` contains headings -- which are written in commented lines -- and data. For example:               str = "# Heading 1     # Heading 2     @ Heading 3     @ Heading 4     Data 1     Data 2     Data 3";      where `#` and `@` denote commented lines. Now, I would like to write a function `removeComments` to remove all lines in `str` that are commented. That is, I would like to remove all lines in `str` that start with the character `#` or the character `@`. I have come up with one way to do this, I think. My procedure is to first split `str` into lines using `StringSplit` with the `"\n"` delimiter; then use `DeleteCases` to delete all lines in that list which begin with either `#` or `@`; and, finally, convert the list back to a string using `Riffle` and `StringJoin`. So, I have the following:               removeComments[str_String] := Module[{result},       result = StringSplit[str, "\n"];       result =         DeleteCases[         result, _?(StringMatchQ[#, ("#" ~~ ___) | ("@" ~~ ___)] &)];       result = StringJoin[Riffle[result, "\n"]];       result       ]     removeComments[str]      which gives the following _correct_ output (a string):               Data 1     Data 2     Data 3      _However_ , now suppose that one of my data items (for example, a single space in front of `Data 2`) has one or more leading spaces:               str = "# Heading 1     # Heading 2     @ Heading 3     @ Heading 4     Data 1      Data 2     Data 3";          removeComments[str]      In this case, I get the **_incorrect_** output:               Data 1     Data 3      That is, `Data 2` is omitted altogether. Something is clearly wrong with my approach, but I haven't been able to find my mistake (although it is probably obvious). Could you please help me find what is wrong? Thanks for your time.


title: Proper localization of variable names

text: In functions like `NonlinearModelFit` I need to specify parameters with a symbol name. If I localize these parameters they get cluttered in the output (e.g.`"ParameterTable"`):               {a, b, c, d} = {2, 30, 4, 0};     data = a PDF[NormalDistribution[b, c], Range@100] +         RandomReal[{-.01, .01}, 100];          fitFunc[a_, b_, c_, d_, x_] := a PDF[NormalDistribution[b, c], x] + d          fit[data_] := Module[{a, b, c, d, aStart, nlmf},       aStart = Max@data;       nlmf = NonlinearModelFit[data,          fitFunc[a, b, c, d, x], {{a, aStart}, {b, 30}, {c, 4}, {d, 0}}, x];       nlmf["ParameterTable"]       ]          fit@data      How can I avoid outputs like `a$18554` in the the ParameterTable without using global symbol names for the parameters a, b, c, d inside `NonlinearModelFit`?


title: Efficient way of setting up a rule

text: I tried to define a simple rule defining how λ acts on `ψ[n]`:               myrule1 = λ ψ[n_] -> α[n + 1]  ψ[n + 1];      The result I get is correct provided there's just one λ on the RHS of `ψ[n]`. For instance:               λ^2  ψ[n] //. myrule1      isn't computed at all. On the other hand, if I do it step by step:               λ α[1 + n] ψ[1 + n] /. myrule1      I get the correct result. I tried to define a new rule:               myrule2 = λ^m_ ψ[n_] -> α[n + 1] λ^(m - 1) ψ[n + 1];      but it doesn't work. Since the recursive method seemed to work, I created a function which multiplies `ψ[m]` by λ `n` times:               timesλ[n_] := Nest[Times[λ, #] /. myrule1 &, ψ[m], n] &      But this is a very crude way of solving this problem. Do you have any other ideas?


title: Find intersection of pairs of straight lines

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


title: How to power-series expand determinants?

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


title: Webdings are different on V10 vs V9. Why?

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


title: Simplifying an Integral over Two DiracDeltas

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


title: How to sum over duplicates?

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


title: Efficiently compute double sum

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


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

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


title: Importing Quicken Tab Delimited .*TXT File and plotting

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


title: How to get complement from two matrices?

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


title: Differential operator involving permutations

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


title: Importing base-64 encoded Canvas element into Mathematica

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


title: List of numbers without common factors with a certain number

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


title: Reinstalling Mathematica home edition with new linux distro

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


title: Building documentation with interactive examples in Wolfram Mathematica

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


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

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


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

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


title: TeXToBoxes and BoxesToTeX BoxRules options

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


title: Scatterplots for subsets of multivariate data [Updated]

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


title: Transforming Sin into Abs[Sin] dynamically

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


title: How to draw a normalized tangent arrow

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


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

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


title: Use JavaScript to evaluate webMathematica tags?

text: 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()"/>


title: Parallelizing is much slower than single kernel evaluation?

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


title: How to unprotect a variable in a package

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


title: Import matrices side-by-side separated by TAB

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


title: Exporting a plot without drawing it

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


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

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


title: Symbolize Subscript doesn't work

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


title: Using a LocatorPane

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


title: How to monitor the communication between parallel kernels

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


title: Expectation taking unusually long to evaluate

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


title: Using variable with delay in WhenEvents in NDSolve

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


title: Evaluating an indefinite integral at the boundaries

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


title: What SampleRate and SampleDepth does Mathematica use on output?

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


title: Nested NIntegrate - NIntegrate::inum: - error

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


title: Keep Ordering of Bra Ket When Printing

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


title: Forming Cone with Tube fails to work in version 9.0.1

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


title: EmpiricalDistribution for Gini Coefficient Runs Slow

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


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

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


title: inverse of abstract matrix

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


title: Why use Column with Rows instead of Grid?

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


title: PlotRange adjustments with BarChart

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


title: How to apply multiple format to a list

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


title: Quickly sum over vector outer products

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


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

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


title: Sum and NSum gives different solutions

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


title: Can we give Mathematica hints for symbolic sums and products?

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


title: Writing results directly to file

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


title: How does Mathematica estimate error on fit parameters?

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


title: Multiple panel figure from combination of plots - bad alignment

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


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

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


title: Generate a Combination of letters by a number

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


title: Metaprogramming in Mathematica

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


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

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


title: Implementing a dictionary data structure

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