title: Shading using VertexNormal changed when combining graphics3D andy ListContourPlot3D with Show

text: I want to combine some `ListContourPlot3D` and `Graphics3D` to present, on one 3D plot, the projection of the contour plots on each face of the cube and a region of defined amplitude. Here is a working example. ![Contour plots on each face together with a region of defined amplitude](http://i.stack.imgur.com/K4bKJ.jpg) I also want to add shading on the projected contours so that it appears more realistic. I succeeded in obtaining a realistic result using `VertexNormals`. ![Projection of the contour plots with realistic lighting](http://i.stack.imgur.com/2ENRu.jpg) When I add the `ListContourPlot3D`, the shading changed and looked bad. ![Complete picture with mixed up shading](http://i.stack.imgur.com/pKqW7.jpg) ` Do you have any suggestions for keeping the shading as in Fig. 2 (`GraphContour in the code below) even when the `ListContourPlot3D` plot is added. (`GraphComplete`)?               (*Define the vector for use in VertexNormals*)     {p1, p2,p3} = {{1, 0, 0}, {1, 1, 1}, {0, 0, 1}};     n = Cross[p2 - p1, p3 - p1];     (*Define constants for the boundary of the table*)     Rmin = -0.5; Rmax = 0.5; Rstep = 0.1; Rlength = (Rmax - Rmin)/Rstep; R0 = Rlength/2;          sphere =        Table[(Rx^2 + 0.6 Ry^2 + 0.5 Rz^2),          {Rx, Rmin, Rmax,Rstep}, {Ry, Rmin, Rmax, Rstep}, {Rz, Rmin, Rmax, Rstep}];          (*Plot of the region representing value of 5%*)     SphereP =        ListContourPlot3D[sphere/Max[sphere],          Contours -> {0.05}, AxesLabel -> {"x", "y", "z"},         DataRange -> {{Rmin, Rmax}, {Rmin, Rmax}, {Rmin, Rmax}},         MeshStyle -> Directive[Red, Opacity[0]],          Lighting -> "Neutral", Boxed -> False,          ContourStyle -> Directive[Orange, Opacity[0.9]],         AxesEdge -> {{-1, -1}, {1, -1}, {-1, -1}}];          (*Define contour plot for projection on the cube faces*)     ContourXZ =        ListContourPlot[         Table[(sphere[[Rx]][[R0]][[Rz]])/Max[sphere], {Rx, 1, Rlength}, {Rz, 1, Rlength}],         DataRange -> {{Rmin, Rmax}, {Rmin, Rmax}}, Contours -> 10,          Axes -> False, PlotRangePadding -> 0, Frame -> False,          PlotLegends -> None, ClippingStyle -> Automatic, PlotRange -> {0, 1},         ColorFunction -> ColorData[{"SunsetColors", "Reverse"}]];     level = Rmin; (*Level at which the contour appears*)     grIntXZ =        Graphics3D[         {Texture[ImageData @ Rasterize[ContourXZ, "Image"]], EdgeForm[],           Polygon[{{Rmin, Rmin, level}, {Rmax, Rmin, level},                    {Rmax, Rmax,level}, {Rmin, Rmax, level}},          VertexNormals -> {n, n, n, -n},          VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]},          Lighting -> "Neutral"];     ContourXY =        ListContourPlot[         Table[(sphere[[Rx]][[Ry]][[R0]])/Max[sphere], {Rx, 1,Rlength}, {Ry, 1, Rlength}],         DataRange -> {{Rmin, Rmax}, {Rmin, Rmax}}, Contours -> 10,         Axes -> False, PlotRangePadding -> 0, Frame -> False,         PlotLegends -> None, ClippingStyle -> Automatic, PlotRange -> {0, 1},         ColorFunction -> ColorData[{"SunsetColors", "Reverse"}]];     level = -0.5; (*Level at which the contour appears*)      grIntXY =         Graphics3D[          {Texture[ContourXY], EdgeForm[],            Polygon[{{level, Rmin, Rmin }, {level, Rmax, Rmin},                     {level, Rmax,Rmax}, {level, Rmin, Rmax}},           VertexNormals -> {n, -n, n, n},           VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]},          Lighting -> "Neutral"];     level = +0.5; (*Level at which the contour appears*)     ContourYZ =       ListContourPlot[         Table[(sphere[[R0]][[Ry]][[Rz]])/Max[sphere], {Ry, 1,Rlength}, {Rz, 1, Rlength}],          DataRange -> {{Rmin 10^6, Rmax 10^6}, {Rmin 10^6, Rmax 10^6}},          Contours -> 10, Axes -> False, PlotRangePadding -> 0, Frame -> False,         PlotLegends -> None, ClippingStyle -> Automatic,         PlotRange -> {0, 1}, ColorFunction -> ColorData[{"SunsetColors", "Reverse"}]];     grIntYZ =        Graphics3D[         {Texture[ContourYZ], EdgeForm[],           Polygon[{{Rmin , level, Rmin }, {Rmax, level, Rmin},                    {Rmax,level, Rmax}, { Rmin, level, Rmax }},          VertexNormals -> {-n, n, n, n},          VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]},         Lighting -> "Neutral"];     (*Without the ListContourPlot3D, the shading are nice and realists*)          GraphContour =        Show[grIntXZ, grIntXY, grIntYZ,          PlotRange -> All,BoxRatios -> {1, 0.9,0.9}];     (*Everything get disturbed when adding the ListContourPlot3D*)          GraphComplete =        Show[SphereP, grIntXZ, grIntXY, grIntYZ,          PlotRange -> All, BoxRatios -> {1, 0.9, 0.9}];


title: Mapping a function over n levels

text: I want to map a function over a matrix of rank n, for example:               PercentChange[v_?VectorQ] := Differences@v/Most@v*100     PercentChange[v_] := Map[PercentChange, v, {Length@Dimensions@v-1}]          m = N@Range@10;          PercentChange /@ {m, {m, m}, {{m, m}, {m, m}}}      This works as expected. Now, as a lazy beginner, I thought that I could get rid of the duplicate definition of "PercentChange" and simply state:               PercentChange[v_] := Map[PercentChange, v, {Length@Dimensions@v - 1}]      However, to my disappointment this didn' t function because "Map" doesn't accept a level {0} parameter:               Map[Differences@m/Most@m, m, {0}]*100      On the other hand, this functions in all cases:               Percent2[v_] := Map[Differences@#/Most@# &, v, {Length@Dimensions@v-1}]*100      How would you write this without duplication and slot-notation?


title: Exporting a compiled function for later use

text: I compiled a function then used it in `NMinimize`. The computation took 19 seconds. Then, I exported this compiled function and restarted MMA and imported this compiled function into my notebook. This time the computation took 30 seconds. Every time I compile the function and use it immediately the computation finishes faster. I use:                Cdiff = Compile[{a, t, mu, b, del}, Evaluate[diff]];(*diff is an expresion not shown here*)            With[{variable = Cdiff},        fun = Compile[{{a, _Real}, {t, _Real}, {mu, _Real}, {b, _Real},     {del, _Real}}, variable[a, t, mu, b, del],          "RuntimeOptions" -> {"EvaluateSymbolically" -> False},          CompilationOptions -> {"InlineCompiledFunctions" -> True},          CompilationTarget -> "C", Parallelization -> True]];          Export["Compiled.wdx",fun]      Does anybody know why this happens? Here is a mini example:                   SetDirectory[NotebookDirectory[]]              function =        Compile[{{x, _Real}}, Sum[Sin[Cos[-x^2*i]], {i, 1, 10^6}],        CompilationTarget -> "C", RuntimeAttributes -> {Listable},        Parallelization -> True]            function[Range[10]]; // AbsoluteTiming       {0.191019, Null}       Export["compiled.wdx", function]      Now restart MMA:                SetDirectory[NotebookDirectory[]]      function = Import["compiled.wdx"]      function[Range[10]]; // AbsoluteTiming          {0.310031, Null}      **Edit** **\-------------------------------------------------------------------------**               function =       Compile[{{x, _Real}}, Sum[Sin[Cos[-x^2*i]], {i, 1, 10^6}],        CompilationTarget -> "C", RuntimeAttributes -> {Listable},        Parallelization -> True]      This function now accepts lists:                function[{1, 0}]      Return:                {-0.2982909888387981, 841470.9848238959}      I have found one way to export this function:                Needs["CCodeGenerator`"]      LibraryGenerate[function, "Myfun"]      Now I load it:                myfunction1 = LibraryFunctionLoad["Myfun", "Myfun", {Real}, Real]      Although now I can export the function there are two problems: 1-It seems that even if you do not compile to c code when you export as mentioned above it compiles to c code because if the function is not compiled to c code after loading it, it gets as fast as a function compiled to c code. 2- The more important issue is that now the function won't accept list as its argument:                myfunction1[{1, 0}]      Returns:               LibraryFunction::cfsa: Argument {1,1} at position 1 should be a machine-size real number. >>


title: Replacing multiple instances of a symbol with different variables and assignments

text: I have an expression of the form:               expr=x+y+n+Sin[n]+n^2      I would like to replace each of the variables `n` with a different variable, like:               x+y+n1+Sin[n2]+n3^2      The order doesn't matter, but it matters that each `n` have a different name. I can find the positions of the `n`'s simply with:               pos=Position[expr,n]      and this returns a list of positions `{{1}, {2, 1}, {5, 1}}` as expected. I would then like to run through this list and make replacements in those positions. However, I don't want to have to do this by hand. Clearly I could do:               expr[[5,1]]=n3      but the real expression I have is many thousands of times larger. I have tried using:               Apply[Part, Join[{expr}, pos[[3]]]]=n2      which would allow be to do this in a loop, or functionally, but this doesn't alter the element of the expression as I would like. I have tried playing with `Hold` in various places but it doesn't seem to work. Anything simple that I am missing?


title: Why GridLines->function does not work with LogPlot?

text: Version 10: This works:                 grids[min_, max_] := Table[If[EvenQ[i], {i, Red}, {i, Blue}],             {i, Ceiling[min], Floor[max], 1}];       Plot[Sin[x], {x, -Pi, Pi}, GridLines -> grids]      ![Mathematica graphics](http://i.stack.imgur.com/XMPLa.png) But when used with `LogPlot` it gives an error:               LogPlot[x^x, {x, 1, 5}, GridLines -> grids]      ![Mathematica graphics](http://i.stack.imgur.com/tFiPF.png)


title: Can I frame text in a plot to look like legend?

text: I have a `DateListPlot`, much the same as below, that I want to overlay text onto. I'd like the text to be wrapped in a frame much the same way as the legend box is, but I can't figure out how to do it. I've tried the cheaters way of putting a rectangle beneath the text, but then I can't get the rounded corners to match the legend box. I am also unable to changed the thickness of the legend frame. Any help would be greatly appreciated.               DateListPlot[{FinancialData["IBM", "Jan. 1, 2008"],        FinancialData["GOOG", "Jan. 1, 2008"]}, Joined -> False,       ImageSize -> Large, AspectRatio -> .3, FrameLabel -> {None, "Price"},       Epilog -> {Text[Style["Several\nLines\nof Text", 12],          Scaled[{0.02, .5}], {-1, 0},          Background -> RGBColor[1, 1, 1, .8]]},       PlotLegends ->        Placed[PointLegend[{"IBM", "GOOGLE"}, LabelStyle -> 12,          LegendFunction -> (Framed[#,              FrameStyle -> Directive[Thickness[.05]], RoundingRadius -> 4,              Background -> RGBColor[1, 1, 1, .8]] &)], {{.98, .95}, {1,           1}}]]      ![CurrentPlot](http://i.stack.imgur.com/TSd0F.png)


title: Defining a function in terms of matrix elements

text: Currently trying to use elements from a matrix in defining a function however having some trouble. This is a somewhat simplified version of the problem. Say I have the matrix               m={{Sin[x],Cos[x]},{Tan[x],ArcTan[x]}}      And I want to define a function in terms of the first element. How would I go about doing this ? Have tried               f[x_]:=m[[1,1,1]]      This seems to work until I try and evaluate it for a value of x.Then it just returns Sin[x]. Any help would be much appreciated.


title: Equivalent of ReplaceAll for Associations?

text: Is there a nice (built-in) way to apply Replace-style rules to key-value pairs in an association? Something like               SomeFunction[<| "id" -> 3, "freq" -> 4 |>, "freq" -> #freq+1 &]     (* should produce <| "id" -> 3, "freq" -> 5 |> *)      This could also be used to add computed keys, like               SomeFunction[..., "density" -> #mass / #volume &]      This would be really useful when combining with `Query` and `Dataset`.


title: Find the eigenvector associated with the smallest eigenvalue, not smallest in magnitude

text: I am trying to find the eigenvector of a $20000 \times 20000$ sparse matrix associated with the smallest eigenvalue. I realized that the smallest eigenvalue might be negative; for example, if the eigenvalues of the matrix are $ \\{-3,1,2,5 \\}$, I want to find the eigenvector associated with $-3$, not $1$ or $5$. Therefore the commands `Eigensystem[matrix,-1]` or `Eigensystem[matrix,1]` cannot be guaranteed to return the desired result. Furthermore, I don't have a lower bound estimate for the possible smallest eigenvalue. Is there a way to find the eigenvectors efficiently?


title: Reading Options from DateListPlots with legends

text: Normally I can recover the options used on a DateListPlot easily with Options[]. However if one of the options said a Legend should be attached, it appears all the options are then unreadable. For example, here are two plots identical apart from p2 has a legend. I can read the options for p1 fine, but Options on p2 returns nothing.               data1 = {{{2006, 10, 1}, 10}, {{2006, 10, 15}, 12}, {{2006, 10, 30}, 15}, {{2006, 11, 20}, 20}};     data2 = {{{2006, 10, 5}, 15}, {{2006, 10, 20}, 8}, {{2006, 11, 10}, 5}, {{2006, 11, 15}, 1}};     p1 = DateListPlot[{data1, data2}, Joined -> True]     p2 = DateListPlot[{data1, data2}, Joined -> True, PlotLegends -> Automatic]          Options[p1, FrameTicks]     Options[p2]      ![enter image description here](http://i.stack.imgur.com/GtZgF.png) I am keen to be able to read the FrameTicks option to complete a function to create DateListPlots with 2 y-axis. Alexey Popkov kindly solved what I thought was my final problem, only for this one to appear from behind it: Combine two DateListPlots and retain a time axis


title: Clicking to add/remove a Locator

text: I would like to add a `Locator` to a figure displayed by `Manipulate` when I click inside the figure, at the location where I click, and to have this trigger an update of the figure. I would also like to have clicking on an existing `Locator` remove it, and dragging a locator reposition it (again, redrawing the figure in response in each case). For (a silly) example, I would like clicking anywhere in the region displayed by               With[{locs = {}},       Manipulate[Graphics[Text[locs, {0, 0}], PlotRange -> 2],       {{q, {1, 1}}, Locator,         Appearance -> Graphics[{Green, Disk[{0, 0}, .1]}, ImageSize -> 10]},       {{p, locs}, Locator,         Appearance -> Graphics[{Red, Disk[{0, 0}, .1]}, ImageSize -> 10]}]]      to add the corresponding `Point` to `locs`, and for clicking on any `p` `Locator` to remove it from `locs`, with the text, updating accordingly in response to additions, deletions or repositionings of a `Locator`. To make things hard, I have another locator `q` that needs to coexist with the one to which I would like to add/remove; and `p` and `q` have different appearances.


title: Extracting information from the result of ContinuousWaveletTransform

text: I'm trying to analysis a signal and identify some time-frequency information of it. For example, around which time the specific frequency arrives. It appears that Mathematica has very powerful wavelet analysis functions builtin suitable for my job. I've being reading the documentation of them, but still can't get it. In particular I don't really understand what the functions `ContinuousWaveletTransform` and `WaveletScalogram` do. For example, for this example in the document,               data = Table[        Piecewise[{{Sin[2 π 10 t], 0 <= t < 1/4}, {Sin[2 π 25 t],            1/4 <= t < 1/2}, {Sin[2 π 50 t],            1/2 <= t < 3/4}, {Sin[2 π 100 t], 3/4 <= t <= 1}}], {t, 0,          1, 1/1023}];     ListLinePlot[data, AspectRatio -> 0.2]      ![enter image description here](http://i.stack.imgur.com/pRGUJ.png)               cwd = ContinuousWaveletTransform[data,         DGaussianWavelet[5], {Automatic, 12}];     WaveletScalogram[cwd, ColorFunction -> "RustTones"]      ![enter image description here](http://i.stack.imgur.com/pZqgU.png) The above example shows the maps of a 1D time signal into a 2D time-frequency representation. So my questions are:   1. In the documentation, it says `WaveletScalogram` "plots wavelet vector coefficients", what that really mean? What is the x and y axis represent? In my understanding the time-frequency 2d plot is kind of like a musical score where the time axis is horizontal and the frequencies (notes) are plotted on a vertical axis. It this understanding correct?   2. Is there a way to see the identify frequencies in the signal from the 2D plot? For example, we can see four difference frequencies from the 2d plot, can we read off their frequencies from the corresponding y value?


title: Make equation size larger when using TraditionalForm

text: If I am using TraditionalForm, how do I make the output larger in size? I don't want to change the general font size of the GUI, just make the output of one expression larger. I tried:               TraditionalForm[x^3 + y^3 == 22 z^3, FontSize -> Large]      but this does not work. FontSize is apparently not allowed as an attribute here.


title: Counting the permuted forms of a list with repeated members under a permutation group

text: DeleteDuplicates[Permute[{g, g, g, g, g, e, r}, AlternatingGroup[7]]]      How to count number of lists automatically?


title: Matrix exponential MatrixExp[] vs Sum[MatrixPower[]] doesn't match?

text: I might be an idiot, but I cannot get the manual expansion of e^At to match the `MatrixExp[A t]` result. For example, I have the following:               k = 1.0; c = 3.0;     A = {{0., 1.}, {-k, -c}};     MatrixExp[A t] /. {t -> 20}      which produces $\left( \begin{array}{cc} 0.000563347 & 0.000215179 \\\ -0.000215179 & -0.0000821912 \\\ \end{array} \right)$ But if I do the expansion manually:               eAt = Sum[(MatrixPower[A, k] t^k)/(k!), {k, 0, 100}];     eAt /. {t -> 30}      I get the result $\left( \begin{array}{cc} -2.59526\times 10^{30} & -6.79448\times 10^{30} \\\ 6.79448\times 10^{30} & 1.77882\times 10^{31} \\\ \end{array} \right)$ This is clearly incorrect, as the `A` matrix has eigenvalues of -1, -3 so it must be stable. Please help? (http://en.wikipedia.org/wiki/Matrix_exponential)


title: How do I select only those lists whose elements are all above a certain number?

text: I'm essentially doing coin flips, using RandomReal to populate a bunch of lists, each with 8 elements. I then want to select only those lists for which all elements are greater than a certain number, e.g. .5. So far I have this:               class = RandomReal[1, {100, 8}];     pass = Select[class, #[[1]] > (.5) &]      but this doesn't work. I suspect a simple Select function would do the trick, but I can't seem to get the syntax right to test every element of the nested listed against a certain number and then only return those lists for which every element passes. Or indeed simply to return the number of sublists for which every element passes. Thanks.


title: Defining a function from a list

text: I have a list of 49 numbers, and I would like to define a function f such that f(n) is simply the nth number in the list. How can I do this?


title: Having trouble saving a plot with legends

text: I am trying to plot a graph.               Subscript[R, 0] = 1.2;      Subscript[A, Pb] = 208 ;      Subscript[A, Ca] = 40;      Subscript[A, O] = 16;      Subscript[ρ, 0] = 0.138;     R[A_] := Subscript[R, 0]*(A^(1/3))     ρ[r_, R_, a_] := Subscript[ρ, 0]/(1 + Exp[(r - R)/a])      I cannot save the following plot with its legend.               a = 0.5;     Plot[{       ρ[r, R[Subscript[A, Pb]], a],        ρ[r, R[Subscript[A, Ca]], a],        ρ[r, R[Subscript[A, O]], a]},        {r, 0, 10},        Frame -> True,        FrameLabel -> {"r (fm)", "ρ(r) nucleons/fm\.b3"},        PlotLegends -> Placed[{"Pb", "Ca", "O"}, Right]]      I cannot select both the plot and legends to save them. How can I deal with this?


title: How to "reversely" replace definitions?

text: I have the following problem at hand. 1.) I have a list of definitions like               L[{0},z]=H[{0},z]+H[{0},zp]     L[{1},z]=H[{1},z]+H[{1},zp]     L[{0,0},z]=H[{0,0},z]+H[{0,0},zp]+H[{0},z]H[{0},zp]     ...      and many more of this and similar kind. Note that there is NO common pattern. 2.) Now I have a sum of terms like               g=1/2*H[{0},z]+1/2*H[{0},zp]+...      3.) Here comes the question: How can I tell Mathematica to replace the terms in g by the (actually long list) definitions of 1.), e.g.               g=1/2L[{0},z]+...      I want to do this in an automated fashion just by somehow throwing all definitions of 1.) to 2.), i.e. I don't want to write a replace command by hand for all definitons of 1.) Some more info: I am given the function g defined through the H's (which are polylogs). These polylogs can used to define a basis of another type of polylogs called L (denoted in 1.)). Now, my goal is to reexpress the function g given in the H-basis in the L-basis through the definitions in 1.). Edit: z, and zp are the complex variable z and its conjugate. To give an example: I have an expression like this:               -(1/16) (H[{0}, z] + H[{0}, zp])^2 + 1/4 (1/2 H[{0}, z] + 1/2 H[{0}, zp] + H[{1}, z] + H[{1}, zp])^2      which is equivalent to (just using the definitions from above)               -(1/16) (L[{0},z])^2 +  1/4 (1/2 L[{0}, z] + L[{1}, z])^2      Using FullSimplify on this would shadow the nice structure since the definitions of point 1 are already obvious here. Probably very unelegant, my attempt (I have to put in the number of definitons of L by hand. Here = 14).               rules = Table[Expand[a_.*DownValues[L][[i]][[2]]] -> a*DownValues[L][[i]][[1]], {i, 1, 14}]      It does what I want though :)


title: Converting ConditionalExpression to Piecewise

text: I have `Solve[]` return a list like `{{F->ConditionalExpression[EXPR1, 0<z<a1]},{F->ConditionalExpression[EXPR2, a1<z<a2]},...}` and so on -- `EXPR*` and `a1,a2,...` are somewhat complicated expressions, containing things like `Root[]`:               EQ = F^4 (138880 z + 318688 F z + 98415 F^10 z + 6561 F^9 (5 + 4 z) +          405 F^5 (625 + 1136 z) + 243 F^6 (-2500 + 5077 z)) ==          1024 z + 11008 F z + 40192 F^2 z + 33536 F^3 z + 46944 F^6 z +          709776 F^7 z + 368388 F^8 z + 4374 F^12 (50 + 43 z) +          4374 F^11 (-125 + 202 z);          ftz = Solve[EQ && 0 < F < 1 && 0 < z < 1, F];      e.g. the first conditional:               In[100]:= N[(F /. ftz[[1]])]          Out[100]= ConditionalExpression[      Root[-1024 z - 11008 z #1 - 40192 z #1^2 - 33536 z #1^3 +          138880 z #1^4 + 318688 z #1^5 - 46944 z #1^6 - 709776 z #1^7 -          368388 z #1^8 + (253125 + 460080 z) #1^9 + (-607500 +             1233711 z) #1^10 + (546750 - 883548 z) #1^11 + (-218700 -             188082 z) #1^12 + (32805 + 26244 z) #1^13 + 98415 z #1^14 &,        2], 0. < z < 0.674139]      I need to (numerically) integrate this function for given parameter values, which Mathematica refuses to do. However, if I convert the expression into a Piecewise function: for example as               ff = Piecewise[{{ftz[[1]][[1]][[2]][[1]], ftz[[1]][[1]][[2]][[2]]},         {ftz[[2]][[1]][[2]][[1]], ftz[[2]][[1]][[2]][[2]]},         {0, z == 0},         {1, z == 1}}];      it easily computes the integral. Unfortunately, the number of intervals and the breakpoints are parameter dependent, and this must be done automatically as the function is called inside another function. Does anyone have any suggestions on how to convert such a list of conditionals into a Piecewise function, or how to otherwise compute the integral? Thanks!


title: Error Interpretation in NIntegrate

text: I am using a recursion algorithm developed by Migdal for Lattice Field Theory, and I have the following code:               (** The dimension of the representation **)     dim[r_] := 2 r + 1      (**The trace of a product around the loop, also the sum of the eigenvalues **)     χ[r_] := Sin[dim[r] θ/2]/Sin[θ/2]      (** The main equation in the paper I went out to 12 terms in the above sum **)     migdal[a_] := Sum[        ((1/dim[r]) NIntegrate[(Sin[θ/2]^2)/(2 π) a χ[r], {θ, 0, 4 π}])^(λ^2)       * dim[r] χ[r], {r, 0, 3, 1/2}     ]^(λ^(d - 2))           (** The λ used as expansion parameter **)     λ = 2^(1/10)           d = 4                l6 = Table[Table[Simplify[      Re[NIntegrate[       Log[Nest[        migdal,         Exp[(9/1000) (χ[1/2] - dim[1/2]) - (3/100000) (χ[1] - dim[1])             + 0 (χ[3/2] - dim[3/2])],        i]] χ[j] Sin[θ/2]^2/(2 π), {θ, 0, 4 π}]]     ], {i,0, 20}] , {j, 1/2, 1, 1/2}]      and it says that               NIntegrate::ncvb: "NIntegrate failed to converge to prescribed accuracy      after 9 recursive bisections in θ near {θ} = {9.71911}. NIntegrate obtained     6.127043317150083`*^-15 and 1.1472584029987046`*^-16 for the integral and     error estimates."      I have tried to change the MinRecursion, on the first NIntegrate, but then the integral converges too slowly, and there are further errors. Mathematica makes a number of recommendations having to do with changing error estimates, however I don't understand what it is referring to. In my code $a$ is where my Boltzmann factor goes, more or less, as an initial input, followed by subsequent recursion of that factor. The factor itself depends the trace, $\chi$, and so depends on $\theta$. FYI the initial conditions that are variable in this are the 9/1000, 3/100 000, and 0. The first two numbers are initial points that are plotted against each other with the first number corresponding to the x-axis, and the second corresponding to the y-axis. I have been varying their range andwhere from the current numbers to (1.2, 0.1) respectively. If someone would be so kind as to help me with these error messages I would be grateful. Thanks,


title: CUDALink with Nvidia GTX770

text: We are running a _Windows 7_ machine with _Nvidia GTX 770_. According to this reference GPU Hardware: _CUDA_ for _Mathematica 9_ is not supported on that hardware. Is there any way to get it running?               CUDAQ[]      > >     False >                 CUDAInformation[]      > >     During evaluation of In[8]:= CUDAInformation::syslibfld: CUDA failed to > load system >     libraries.  Refer to CUDALink System Requirements for system > requirements. >> >                 CUDADriverVersion[]      > >     "320.57" >


title: Polar Plotting in Complex Plane

text: How would I plot the following functions in the polar complex plane? $$ \phi={-k\over 2\pi r}cos(\theta_0-\theta) $$ and $$ \psi={-k\over 2\pi r}sin(\theta_0-\theta) $$ Please provide the function calls if possible. I realize that I need to pick values for k and $\theta_0$. It would be even better if someone knew how to sketch the flow.


title: How to extract a specific element from EXIF photographic metadata?

text: It's now possible to import photographs into _Mathematica_ and import the EXIF data at the same time:               i = Import["ExampleData/coneflower.jpg", "ImageWithExif"]      ![coneflower](http://i.stack.imgur.com/wvzxz.png) You can now look at all the metadata:               Options[i, MetaInformation]      > {MetaInformation -> {"Exif" -> {"ImageDescription" -> " ", "Make" -> > "NIKON", "Model" -> "E950", "Orientation" -> 1, "XResolution" -> 300, > "YResolution" -> 300, "ResolutionUnit" -> 2, "Software" -> "Adobe Photoshop > CS3 Macintosh", "DateTime" -> "2008:08:19 11:29:05", etc... So how would I extract - say - the exposure time ("ExposureTime")? I was trying something like this:               "ExposureTime" /. Options[i, MetaInformation] ...      but I don't know enough about the structure of the stored metainformation. Can you do this without knowing that structure?


title: Export Grayscale Bitmap

text: I have a grayscale (one channel) image in Mathematica. How can I export it as a grayscale Bitmap? Every single option I tried so far does not have an influence on the Bitmap exported using `Export`. If I export the image as PNG, Mathematica exports the grayscale image as expected. **Simple Example** Let's create a simple grayscale image:               image = Image[RandomReal[{0, 1}, {100, 150}]];      Simple export via:               Export["test.bmp",image];      shows exactly the problem mentioned above. Additional options like setting `ColorSpace->"Grayscale"` does not seem to have any effect. Any kind of color- conversion before doing the export did not work either, which is not surprising to me because the image already clearly carries the information that it is a grayscale image and export via               Export["test.png",image];      does export a grayscale PNG. Verification can for example be done by simple reimporting the ColorSpace Element of the exported image:               Import["test.bmp","ColorSpace"];


title: Difficulty with computing a limit

text: I meet some difficulties when trying to compute this limit,               Limit[1/n*Integrate[1/(Cos[x]^2 + 4 Sin[2 x] + 4), {x, 0, Pi*n}],   n -> Infinity,Assumptions -> n \[Element] Integers]      The output is,               Limit::cas: Warning: Contradictory assumption(s) (n\[Element]Integers&&(Re[n]<=1/2||n\[NotElement]Reals))&&n>4096 encountered. >>      The limit is finite though.


title: ArrayPlot copied to PDF shows blurred mesh

text: Certain (but not all) images displayed in `ArrayPlot`, and then copied to PDF, show what appear to be fuzzy mesh lines in white areas. An example is shown below. I am aware of previous answers regarding viewing in Preview, but this happens when the copied image is viewed in Pages, TextEdit, or even Mathematica! It persists in these when the preview smoothing option is turned off, though the problem goes away in preview. Also, the PDF file is very large, takes long time to copy. Is it representing all the elements of the array as graphic rectangles? Here is a simple example:               ArrayPlot[1. - IdentityMatrix[4], ColorFunction -> GrayLevel,       ColorFunctionScaling -> False, Mesh -> None]      Copy the output as PDF, then paste back into the Mma notebook, and `Mesh` lines will be evident.


title: Is it possible to frame a group of cells?

text: Is it possible to put a frame around a group of cells (e.g. a numbered list)? My problem is, that if I select the cell group and then click frame on the writing assistant, then it puts a frame around each cell in stead of one frame around all the cells in the marked group. Merging the cells into one does not work either, as that removes the item numbers in lists.


title: Animated Wave Propagation using Fourier & InverseFourier

text: This is a continuation off of previous help on the first part of my project: fourier issue arising from input miscommunication Now I want to go one step further in the current code. Here's the code from earlier with some comments to explain the thought-process:               xdomain = Table[i, {i, -10, 10, .1}];     initialState= E^-2#^2 & /@ xdomain;          f1 = E^-I #^2*Δt & /@ xdomain;      (* For the first step, I want to multiply my initial function by a second function and then fourier transform it. So I'm breaking down both function into a table of points and then fourier-transforming the product of the multiplied-points, because (I think) this is the most efficient way of doing this numerically.*)               f2 = E^-I #^2*Δt & /@ xdomain;      (* The second step is the same principle. We then take this fourier'd result, multiply it by another function, and then Inverse-fourier transform back *)               finalstate=InverseFourier[Fourier[f1*initialState]*f2];       (* ^This line is doing the two steps mentioned in the above two comments. *) My result represents a wave that is propagated 1-unit-delta-t forward in time. To find out what this wave looks like 2-units in time, we need to take our "finalstate" function and use that instead of our intial state. (so to find something 10-units in time forward, I would have to run this 10 times, each time replacing the output with the input.) Eventually I'd want to have a series of plots that I would assemble to form a movie of the wave's behavior. This is what I have so far:               xdomain = Table[i, {i, -50, 50, .05}];     initialState = E^-#^2 & /@ xdomain;          cache = {initialState};     (*For 1\[Rule]10 *)     Δt = .001;          f1 = E^-I #^2*Δt & /@ xdomain;     f2 = E^-I #^2*Δt & /@ xdomain;          For[i = 0, i < 15, i++,      ftot = Abs@InverseFourier[Fourier[f1*initialState]*f2];      initialState = ftot;      cache = Join[cache, {ftot}];      ListLinePlot[        Partition[Riffle[xdomain, cache[[i + 1]]]/Norm[cache[[i + 1]]],          2]] // Print]      So there are two things that I'm looking for answers for:   1. If my method numerically fourier-transforming these functions by turning them into points and multiplying the points individually, makes sense and is the best way of handling it numerically in Mathematica.   2. How can I export these printed for-loop pictures into an animation. (I eventually will decrease the value of delta_t, and increase the amount of pictures taken, so I won't be able to export the animation by hand.)  Thanks again everyone for your help so far! Let me know what you think. P.S. In case anyone's interested, what I'm constructing is a program that numerically performs the Split-Operator method for solving the wave equation in an arbitrary potential (that commutes with p).


title: How to define Similarity Rules?

text: I have a question about _Mathematica_ 's `SimilarityRules` defining (for e.g. `SequenceAlignment` function). So help centre clearly stands for > `SimilarityRules -> {{a_, a_} -> 1, {a_, b_} -> -1}`, giving a score of `+1` > for any pair of identical elements, and a score of `-1` for any mismatch, > deletion or insertion. Ok, I get it, but what if I want to give different score for mismatch, and different for indeles? I tried:               SimilarityRules -> {{a_, a_} -> 3, {{a_, b_} && {{a_!=""} && {b_ != ""}}} -> -8}       and many other combination of `{}`, `&&` positions, but it doesn't seem to help. Any suggestions, is it just a typo I'm doing, or it's rather a silly idea to define it like this?


title: How to Dynamically Locate (get coordinates) of a point, inside a Manipulate?

text: I've been searching all around the "Documentation Center" and other forums and just can't get to solve this issue. I'd like to dynamically locate a point (get it's coordinates) inside a Manipulate. This point is in fact a function of another parameter (hence the Manipulate). Here's the setup. First I create the functions that will provide with the points coordinates :               T01[q1_] = {{Cos[q1 Degree], 0, Sin[q1 Degree], 0}, {0, 1, 0,      0}, {-Sin[q1 Degree], 0, Cos[q1 Degree], 0}, {0, 0, 0,      1}}; (*Matrice de passage de R0 à R1*)           T12[q2_, l1_] = {{Cos[q2 Degree], 0, Sin[q2 Degree], 0}, {0, 1, 0,          0}, {-Sin[q2 Degree], 0, Cos[q2 Degree], -l1}, {0, 0, 0,          1}}; (*Matrice de passage de R1 à R2*)          T02[q1_, q2_, l1_] =        T01[q1].T12[q2, l1]; (*Matrice de passage de R0 à R2*)          E2[l2_] = {0, 0, -l2, 1}; (*position de l'effecteur dans le repère R2*)          E0[q1_, q2_, l1_, l2_] =        T02[q1, q2, l1].E2[l2]; (*position de l'effecteur dans R0*)          O22 = {0, 0, 0, 1};(*position du centre articulaire O2 dans R2*)          O20[q1_, q2_, l1_] = T02[q1, q2, l1].O22;(*position de 02 dans R0*)          O11 = {0, 0, 0, 1};(*position de O1 dans R1*)          O10[q1_, q2_] = T01[q1].O11;(*position de O1 dans R0*)      I'm in fact interested in showing the $E_0$ coordinates dynamically if possible inside the manipulate window... So then I create the Manipulate environment which shows a double pendulum parameterized by the $q_1$ and $q_2$ variables :               Manipulate[      ListLinePlot[       {        {O10[q1, q2][[1]], O10[q1, q2][[3]]}, {O20[q1, q2, 400][[1]],          O20[q1, q2, 400][[3]]}, {E0[q1, q2, 400, 300][[1]],          E0[q1, q2, 400, 300][[3]]}        }, PlotRange -> {{-710, 710}, {-710, 710}},        AspectRatio -> Automatic, PlotMarkers -> Automatic, Ticks -> None       ], {{q1, 5, "\!\(\*SubscriptBox[\(q\), \(1\)]\)"}, -170,        170}, {{q2, 5, "\!\(\*SubscriptBox[\(q\), \(2\)]\)"}, -170, 170}      ]      I tried the Locator function without success, also I tried the Dynamic function but I just couldn't get to make it work for the $E_0$ variable... Does anybody has any idea that might help? Thanks in advance.


title: Gradient Filter Function

text: I am trying to understand EXACTLY what the GradientFilter function in Mathematica is doing. As far as I can tell, it appears to be doing a convolution of a first derivative of a Gaussian with the user supplied data using some kind of padding on the edges because, I can replicate the results of the GradientFilter almost exactly by doing this except for the behavior at the edges due to the padding. However, one of my colleagues (a MATLAB user by the way) disagrees and thinks it is doing more than just that. Also, is there any way to see the convolution kernel that the GradientFilter is using given a certain radius and standard deviation? The documentation is somewhat ambiguous. So, if anyone out there has any insight to this, I would really appreciate it.


title: The correct pattern for Cases

text: I have a problem that, admittedly, I have already solved using `Select` instead, but it is irking me that I cannot seem to construct the right pattern to solve it using `Cases`. I would like the output of               Cases[         {{{1, 2}, {3}, {4, 5}}, {{6}, {}}, {{}, {}}},         (* THE CORRECT PATTERN HERE *)     ]      to be               {{{1, 2}, {3}, {4, 5}}, {{6}, {}}}      In other words, I would like a pattern that picks up all the elements of the outer list that have at least one non-empty list as an element. Thanks in advance for your help.


title: How can I recreate Trott's Riemann Surface plot in Mathematica?

text: In reading Michael Trott's Visualization of Riemann Surfaces of Algebraic Functions, he has:               ParametricPlot3D[{r Cos[φ], r Sin[φ], Sqrt[r] Sin[φ/2],        SurfaceColor[Hue[φ/(4 π)]]}, {r, 0, 1}, {φ, 0, 4 π},       PlotPoints -> {20, 60}, Boxed -> False, Axes -> False]      How would you do this coloring now in _Mathematica 9_ ?


title: Defining a formal Primitive Recursion

text: I'm searching for a way to define the function this wikipedia article call **Primitive Recursion**. It should have two functions as argument and it should return a function. I need this as helping in studying mathematical recursion theory. I need another help with a similar problem; this time i want a "primitive minimization", that is a function called primMin a try i made inspired by @Rojo is.               primMin[f_] := Module[{h},         h[x___Integer] := Module[{}, For[i = 0, f[x, i] != 0, i++,]; i];         h]      this take f a two argument function and return a one argument function that given x as an argument and search for the first second argument so that f[x,#] == 0. this code work but i couldn't find a way to substitute the For with a Map or something similar. I need that given x there is no y so that f[x,y] == 0 then program will crash or continue to run forever. thank


title: how to get a linearized curve in some intervals

text: in below picture I draw a graph base on weight of a controller system against cost function. I want to linearise and divide this curve to for example 5 five intervals. is there any function in mathematica to give me such a thing. I thinking first maybe I can get gradient of function and choose the nearest amount together. ![enter image description here](http://i.stack.imgur.com/uW5VP.jpg)


title: Counting instances where the two identical characters are at the same positions in two strings

text: Let $s_a$ and $s_b$ be two strings over a $q$-ary alphabet. For each character $(c_1,...c_q)$ in the alphabet, I'd like to return a pair of values $(r,k)$ where $r$ represents the count for the character in $s_a$ and $k$ represents the number of instances where this character is in the same position in $s_a$ and $s_b$. For example, if we have two binary strings:               sa="00011001";     sb="11001001";      For the character $0$, we'd return the value $(r_0,k_0) = (5,3)$. For the character $1$, we'd return $(r_1,k_1) = (3,2)$. What is the fastest way to carry out these string operations? Should we be using arrays instead of strings?


title: Mathematica Plotting of complex and convolution integrals

text: I was trying to plot the following:               j = 10;      a = 0; b = 0; s = 0;           B[n_] = Integrate[2*Sin[n*Pi*x]*x, {x, 0, 1}];     u[x_, t_] = Sum[B[n]*Sin[n*Pi*x]*Exp[-(n*Pi)^2*t], {n, 1, j}];          K[x_, t_] = (1/(2*Pi))*        Integrate[         Exp[I*x*psi]*(Exp[-I*b*psi]*Exp[-I*a*psi^2]*             Exp[-I*t*psi^2])/((1 + psi^2)^s), {psi, -10, 10}];          S = (Total[u[x, t]]/Length[u[x, t]]);          T[x_, t_] = Integrate[K[x - y, t]*y*S, {y, -10, 10}]          Plot3D[T[x, t], {x, 0, 1}, {t, 0.01, 1}, AxesLabel -> {"x", "t", "y"}, Boxed -> False, Mesh -> False]      The problem is that this is a really complicated solution and I would like to get the results numerically, but it ran for a long time and nothing plotted -- just empty axis. In my definition of all the variables -- I have also used the := statement, but it didn't help! If anyone can please help me with this then I'll greatly appreciate it. Thanks!


title: Formatting data tables with Grid + Dividers vs. SplitBy --> GridBy?

text: A quick method to format human-readable data tables with headers, is to use `Grid`, eg:               Grid@ColSel[        PACE["PRE"], {"VISIT_ID", "PHYSICIAN_ID", "PT_DROPOUT_Q",          "DUAL_MONITOR_Q", "VOICE_RECOG_Q", "COMPANION_Q",          "CAM_TRUNCATED_Q"}] /. {0 -> ""}       Which yields this table of which only the top portion is shown (note the horizontal spacing induced by the header) ![enter image description here](http://i.stack.imgur.com/kxudE.jpg) It is desirable to segment the data by PHYSICIAN_ID, which can have _variable_ number of visits. Is there a convenient expression to map such a rule to positional information required by `Grid` and `Dividers`? A more verbose alternative is to space by first applying SplitBy #[2] (2nd column = PHYSICIAN_ID), then Grid, and finally Column:               Column[#, Automatic, 2] & @(Grid /@         SplitBy[ColSel[           PACE["PRE"], {"VISIT_ID", "PHYSICIAN_ID", "PT_DROPOUT_Q",             "DUAL_MONITOR_Q", "VOICE_RECOG_Q", "COMPANION_Q",             "CAM_TRUNCATED_Q"}] /. {0 -> ""},         #[[2]] &])      Which yields (again only showing data for the first 3 physicians): ![enter image description here](http://i.stack.imgur.com/zoE39.jpg) Vertical spacing is visually less satisfactory than horizontal grid lines (which visually guide the eye). Also note the header has been split from the data so the vertical alignment is lost. So overall Grid and Dividers is preferable; What are the issues in developing a "GridBy" functionality analogous to SplitBy?


title: How to install packages?

text: This is always a problem when I distribute my packages to colleagues working on different platforms. I have my packages installed into a private directory and I autoload some of them when _Mathematica_ starts, but since everyone has a different folder hierarchy and different customs on where to put files/what to autoload, this is always a bottleneck. Should non-power-users simply use the menu option: `Install...`? Can a foolproof script be defined, that - no matter what platform is in use - installs these packages in a way that both the user and both _Mathematica_ (and the code I wrote and distributed) can find it? That is, packages are not added to the system-default package directory. Or would it be better to put packages into the default directory of _Mathematica_ (e.g. `C:\Applications\Mathematica 8.0.1\AddOns`)? If yes, then which directory should hold them: `LegacyPackages`, `ExtraPackages` or `Packages`? **Further questions:** What if the package that I send consists of multiple packages, in a delicate directory structure? Can the menuitem `Install...` deal with that?


title: How to use initial fixed timestep, then decrease it according to dependent variable, while spatial stepsize is fixed

text: I am trying to solve an advection equation. I want to force constant spatial step size (x dimension) with the “MethodOfLines” option, whereas I want to use initially fixed time step size 0.01 then decrease the time step size to be (0.001, 0.0001) when the minimum value of u(t,x) is less than (-6, -7). I tried the following code, and adopt ImplicitRungeKutta method to integrate with respect to time. I even can not set time step size in the ImplicitRungeKutta method. I try this               WhenEvent[{u[t, x]<=-6}, stepsize -> 0.001];     WhenEvent[{u[t, x]<=-7}, stepsize -> 0.0001];      But how can I combine this event trigger in my time integration method? Anyone can help me?               mdfun = First[u /. NDSolve[{D[u[t, x], t] ==        0.5 D[u[t, x], x, x] + u[t, x] D[u[t, x], x],       u[t, -Pi] == u[t, Pi] == 0, u[0, x] == Sin[x]},      u, {t, 0, 10}, {x, -Pi, Pi},      Method -> {"MethodOfLines",        Method -> {"ImplicitRungeKutta", DifferenceOrder -> 2,          "ImplicitSolver" -> {"Newton", "IterationSafetyFactor" -> 1}},        "SpatialDiscretization" -> {"TensorProductGrid",          "MinPoints" -> 100, "MaxPoints" -> 100,          "DifferenceOrder" -> 2}}]]      Then Plot it               Plot3D[Evaluate[mdfun[t, x]], {t, 0, 10}, {x, -Pi, Pi}, PlotPoints -> 100, PlotRange -> All]


title: Why is JLink loaded every time I start Mathematica?

text: When I start a Mathematica 8 session (either command line or with the notebook front end), I notice that there are several packages that have already been loaded for me (using `SystemInformation[]`):               PackagesLoaded -> {JLink`, PacletManager`, WebServices`, System`, Global`}      I understand System` and Global` and even WebServices`, but why JLink`? Does Mathematica have a primary dependency on Java? What does it use it for?


title: Controlling plots with sliders without using Manipulate

text: Why are the sliders in the following code not affecting the plot? (Without using `Manipulate`)               Module[{t, o, z}, f[t]];     {Slider[ Dynamic[o], {1, 5, 0.1}], Dynamic[o]}     {Slider[ Dynamic[z], {0.1, 1.4, 0.1}], Dynamic[z]}     {Slider[ Dynamic[Ts], {5, 20, 1}], Dynamic[Ts]}     tf[o_, z_] := TransferFunctionModel[ω^2/(s^2 + 2 z o s + o^2), s];     f[t] = OutputResponse[tf[o, z], UnitStep[t], t];     Plot[f[t], {t, 0, T}, PlotRange -> {{0, T}, {0, 2}}]


title: downloading home version for mac

text: This is I think a trivial question but I did check against those already asked. I am downloading Mathematica (home use). Very slow connection. So my Mac displayed the progress bar but this morning the bar is replaced in the downloads window with "mounting failed." When I double-click this icon it informs me the program can't be accessed because it is still downloading. When I right-clicked "get info" on the dmg file it went from 2.07G to 4 KB over the course of a few minutes. a. Has the download stopped? Been reversed? b. Is it possible to get the progress bar back to see what's happening? Thanks for any advice.


title: Why does SocialMediaData return such a small FollowerNetwork?

text: I have hooked up my Twitter account to Mathematica and I have 1468 followers               myfollowers = Length[SocialMediaData["Twitter", "Followers"]]          1468      I wondered what my follower network would look like but the returned graph was far too simple looking:               a = SocialMediaData["Twitter", "FollowerNetwork"]      ![enter image description here](http://i.stack.imgur.com/R5cpx.png) The graph only has 32 vertices:               VertexCount[a]      Looking at the names of the Twitter users it has included, it seems that it has only considered the most recent people who have followed me. So, how do I get Mathematica to consider all of my followers?


title: Interpolation Problem

text: I have the following list:               AA1 = {{55.3346, 694.253}, {55.3373, 691.275}, {55.34,         688.323}, {55.3426, 685.396}, {55.3453, 682.494}, {55.348,         679.617}, {55.3506, 676.765}, {55.3533, 673.936}, {55.356,         671.131}, {55.3565, 668.277}, {55.3565, 665.428}, {55.3565,         662.604}, {55.3565, 659.803}}      By interpolating the data, I get an error:               AA2 = Interpolation[AA1, InterpolationOrder -> 1]      "Interpolation::inddp: The point 55.3565` in dimension 1 is duplicated. >>" Therefore, I want to delete the duplicated terms:               DeleteDuplicates[AA1[[All, 1]]]      But how do I merge these values with the **correct** values of the second part in list AA1 (694.253 until 659.803?


title: Dynamic with RegionNearest keeps one CPU core at 100% - Is this a bug?

text: Normally, when you use `Dynamic` with a CPU-intensive expression, the expression only gets evaluated when a symbol in the expression changes. This doesn't seem to work with `RegionNearest`:               d = RegionIntersection[Ellipsoid[{2., 2.}, {5, 3}],         Ellipsoid[{5., 3.}, {4, 3}]];         nf = RegionNearest[d];     pt = {0, 0};      `Timing[nf[pt]]` tells me that this takes .6s on my PC (side question: why does this take so long? I thought this would be equivalent to finding the nearest point to each of the two ellipsoids, then checking if that point is contained in the other.) Now when I write:               Dynamic[nf[pt]]      The Mathematica kernel goes to 25% CPU utilization (one core) and stays there, even when nothing changes. Is this a bug? **ADD:** as @Nasser remarked in a comment, `Dynamic[nf[pt]]` doesn't make much sense on it's own. My actual code was:               LocatorPane[Dynamic[pt],      Show[       Graphics[Dynamic[Line[{pt, nf[pt]}]]],       RegionPlot[d]]]      But `Dynamic[nf[pt]]` is the simplest way to reproduce the problem.


title: Modifying imported 3D file

text: Since I am visualizing my work using Mathematica, I import some 3D models of molecules to my notebook. So, the question is, is there any way to modify somehow that imported models inside Mathematica to, for example, label bonds' length? Currently I use .mol2 format, but maybe some others formats provide that ability? Or can Mathematica process that models to `Graphics3D`? Thanks.


title: How to integrate a function which is only known at discrete points

text: I have an integration to do. I want to integrate. $\int_0^\infty sin^2(2\pi t)f(t)dt$ where $f(t)$ takes values from an array in the form $\\{t,f(t)\\}$ The time steps in the array is 1.1s. Can you please suggest a method to do this? I tried using the Trapezoidal method for numerical integration but gave a bad approximation. Is there an easy method with inbuilt function or another method?


title: How can I turn off generation of Dynamic elements by Histogram?

text: By default `Histogram` generates `Graphics` expression with embedded `Dynamic` constructs as can be seen by looking on its `InputForm`. Is it possible to switch off generation of any `Dynamic` constructs and get non-interactive `Graphics` from `Histogram`? P.S. There are two reasons to turn off interactivity: 1) Interactivity is not needed when preparing graphics for `Export`. 2) Unnecessary `Dynamic` elements complicate generated `Graphics` expression and make difficult to modify it.


title: Multidimensional array reduction through summation over one of its dimensions

text: ## 1\. Introduction I am using an array of dimension 3 (might become more) to store some values. I would like to implement a function that takes as argument the array and a couple of numbers smaller than the array dimension and returns a standard matrix (dim=2) which is obtained by reduction or "projection" (I don't really know how to call it) of the array along all the "other" dimensions. First a quick example with an array of dimension/depth 3               data=Table[10 (i - 1) + 3 (j - 1) + k, {i, 2}, {j, 3}, {k, 4}]     --> data = {{{1, 2, 3, 4}, {4, 5, 6, 7}, {7, 8, 9, 10}},                {{11, 12, 13, 14}, {14, 15, 16, 17}, {17, 18, 19, 20}}}      My desired function would do, for example, the following               Myfunction[data,{1,2}] = {{10,22,34},{50,62,74}}      After this brief introduction, let me explain where I've arrived. First let's generalize a little bit, as it is my goal, eventually. ## 2\. Definitions Let $M \in \mathbb{R}^{\Pi d_i}$ be an array of dimension $N \in \mathbb{N}$. Let $d_i \in \mathbb{N}, \quad i=1,\dots,N\quad$ be the sublengths of each of the dimensions. What I will call in the following the **projection** of the array along the dimension $q$ is the following surjective function : $$ \textrm{For } q\leq N \in \mathbb{N}_0,\quad P(M,q) : \mathbb{R}^{\Pi d_i} \rightarrow\mathbb{R}^{\frac{\Pi d_i}{d_q}} : M(n_1,\dots,n_N) \mapsto \sum_{j=1}^{n_q}M(n_1,\dots,n_{q-1},j,n_{q+1},\dots,n_N) $$ ## 3\. Goal The goal is to write a function that takes any multidimensional array as well as a list of all the dimensions that will be "kept" in the final array. For the sake of any representation, the obtained array should be of dimension $\leq$ 2 but I would like to stay as general as I (we) could. The dimensions ordering should simply be the one used to implement the array, and the code should be consistent in order to keep the dimensions in the same order at any time. ## 4\. Implementation               ProjectedColumns[len_,cols_]:= Complement[Range[len],cols]      ProjectedColumns is a function that returns a list of the dimensions to project, where `cols` is the list of dimensions to be kept and len is the dimension of the array.               CompoundProjection[data_, cols_] :=     Module[{len, vect},         len = Depth[data] - 1;         vect = ProjectedColumns[len, cols];         Do[             SingleProjection[data, vect[[i]]],             {i, Length[vect]}         ]     ]      CompoundProjection is a function that will project all the dimensions sequentially in order to arrive to the final result (The projection is commutative).               SingleProjection[data_, dimnumber_] := ???      Now what I need and I don't manage to get is the function that will actually perfom a one-dimensional projection. In my mind, I would need to have a number of `Do` loops which equals the dimension of the array. In that case, I simply parse through the array and do the summation over the one I'm interested in. Is it possible to set up such a structure with all the commands that Mathematica offers and that I probably don't know ? ## 5\. In summary   1. Has anyone followed this nonsense ?   2. Is there a Mathematica command that makes what I want directly ? (If Yes then No to the previous questions, then I'm happy)   1. Is there a way to improve the correctness or elegance of what I did ?   2. Is there a way to intricate a dynamic number of Do loops ?   3. Or, in general, is there another way to achieve the goal described in 3.


title: Obtain input expression from history without evaluating

text: I typed and evaluated an expression, but deleted it from the notebook. For instance, suppose it was               In[1]:= Round@SessionTime[]     Out[1]= 2      I now want to retrieve the input so that I can edit it again. I know Mathematica keeps the history of evaluated expressions in `In`. But if I try to access it directly `In[123]`, rather than giving the unevaluated input expression, it evaluates it again:               In[2]:= In[1]     Out[2]= 10      If I use `Hold` to suppress evaluation, then `In[...]` doesn't get evaluated, so I don't see the input:               In[3]:= Hold[In[1]]     Out[3]= Hold[In[1]]      How can I retrieve the input expression in an editable form, without evaluating it?


title: E-mail and password

text: I've just learned Mathematica can send e-mails using external servers: this is great... ! Now, using this link, I've set this up using my Gmail account. But is it possible to incorporate somewhere my Gmail password, so as not to have to add it every time in the               SendMail[..., "Password"-> ... ]      command? Thanks all for your help!


title: A one-liner to place some number of Graphics3D polytopes on a plane and to randomly assign colorations

text: I'm looking for a nice one- or two-liner to randomly place some number, $N$, of `Graphics3D` polytopes on a plane with dimensions $X \times Y$, and to specify that $k \leq N$ of them should be one color (e.g. `Red`) and the remaining $N-k$ another color (e.g. `Blue`). If possible, I would also like the option to randomly reassign colors an arbitrary number of times (perhaps by clicking a mouse) without changing the coordinates of the polytopes. Is this possible? We can get started by placing a single red colored Dodecahedron at the coordinate $(0,0,0)$ with the following line of code:               Graphics3D[{Red, Scale[Translate[PolyhedronData["Dodecahedron", "Faces"], {0, 0, 0}], 3]},               Boxed -> False, Background -> Gray]      Perhaps we would want to use `Map` here?


title: How does the built-in debugger decide what to highlight?

text: How does the built-in debugger decide which definition to highlight in the notebook when Break on messages" is enabled? Here's an example to illustrate what I mean. First, enable the debugger (Evaluation -> Debugger), then define a function that issues a message:               f::boo:="Boo!!!";     f[]:=Module[{a,b,c,d},       a=1;       b=a;       Message[f::boo];       c=b;       d=c;       a+b+c+d     ]      When running `f[]`, evaluation will pause on the message and the point where the break occurred will be highlighted: ![](http://i.stack.imgur.com/Wq2L0.png) Now let's re-assign its own DownValues to `f`, and re-run it. Now this second definition will be highlighted, but not the original one. ![](http://i.stack.imgur.com/55y9R.png) **The question:** How does the debugger know what to highlight and can we influence this somehow? I would like the definition printed by this spelunking tool to be highlighted, if possible.


title: How to find first list element that differs from average of N previous elements by more than a given amount?

text: Given a list of real numbers, I need to write a function that returns the value of the first element in the list that differs from the mean of the previous $N$ elements by greater than $P$ standard deviations of those same elements. (I use mean and standard deviation as sample functions, I may decide to use something else.) Clearly, I can write a loop to do this, but I'd like to use functional programming techniques to do this, and continue to learn better Mathematica programming style. `Select[ ]` looked promising, but I see no way to involve the previous list elements in the selection criterion. Thanks in advance for your help! Tom


title: Summation matrix

text: I have problem with summation when it is in matrices. I want to make mathematica compute this: ![enter image description here](http://i.stack.imgur.com/MAYyb.png) Large X I have added dataset for as well as e. Would anyone be able to show me how to compute this in mathematica. Due to comments Ill explain a bit more, X' is Transpose[X] so yes it would be a 2 by 2 matrix.               X= {{20.08, 1}, {19.78, 1}, {19.86, 1}, {19.4, 1}, {19.66, 1}, {19.32,        1}, {18.99, 1}, {19.29, 1}, {19.43, 1}, {19.52, 1}, {20.07,        1}, {20.13, 1}, {20.02, 1}, {19.9, 1}, {20.11, 1}, {20.44,        1}, {20.37, 1}, {20.31, 1}, {19.7, 1}, {20.12, 1}, {19.63,        1}, {19.76, 1}, {19.34, 1}, {19.66, 1}, {19.85, 1}, {20.32,        1}, {20.5, 1}, {20.9, 1}, {21.21, 1}, {21.15, 1}, {21.18,        1}, {21.02, 1}, {21.29, 1}, {20.92, 1}, {20.83, 1}, {21.22,        1}, {20.73, 1}, {20.76, 1}, {21.16, 1}, {21.31, 1}, {21.94,        1}, {22.7, 1}, {22.95, 1}, {22.8, 1}, {22.7, 1}, {22.9, 1}, {22.6,        1}, {22.4, 1}, {22.34, 1}, {22.43, 1}, {22.07, 1}, {22.01,        1}, {22.17, 1}, {22.1, 1}, {22.86, 1}, {23.26, 1}, {23.38,        1}, {23.59, 1}, {23.59, 1}, {23.53, 1}, {23.5, 1}, {23.78,        1}, {23.38, 1}, {23.52, 1}, {23.3, 1}, {23.48, 1}, {23.83,        1}, {24.2, 1}, {24.49, 1}, {24.69, 1}, {23.98, 1}, {23.79,        1}, {23.7, 1}, {23.26, 1}, {23.47, 1}, {23.95, 1}, {24.38,        1}, {24.75, 1}, {25.2, 1}, {24.68, 1}, {24.43, 1}, {24.73,        1}, {24.3, 1}, {24.97, 1}, {25.07, 1}, {25.17, 1}, {26.07,        1}, {26.41, 1}, {26.24, 1}, {26.83, 1}, {26.39, 1}, {26.64,        1}, {27.34, 1}, {26.58, 1}, {26.52, 1}, {26.58, 1}, {27.,        1}, {26.54, 1}, {26.02, 1}, {26.33, 1}, {26.07, 1}, {25.81,        1}, {26.33, 1}, {26.3, 1}, {26.39, 1}, {26.26, 1}, {25.75,        1}, {26.21, 1}, {27.04, 1}, {26.74, 1}, {26.4, 1}, {25.89,        1}, {26.37, 1}, {26.28, 1}, {26.54, 1}, {26.66, 1}, {26.24,        1}, {25.35, 1}, {25.19, 1}, {24.07, 1}, {24.96, 1}, {25.29,        1}, {25.47, 1}, {25.13, 1}, {25.24, 1}, {24.99, 1}, {25.59,        1}, {25.68, 1}, {25.53, 1}, {26.68, 1}, {26.56, 1}, {27.04,        1}, {27.23, 1}, {27.34, 1}, {26.88, 1}, {29.66, 1}, {29.66,        1}, {29.11, 1}, {27.86, 1}, {27.36, 1}, {27.84, 1}, {28.27,        1}, {28.11, 1}, {27.93, 1}, {28.05, 1}, {28.09, 1}, {27.96,        1}, {27.65, 1}, {27.67, 1}, {27.32, 1}, {27.39, 1}, {27.48,        1}, {27.68, 1}, {28.35, 1}, {28.34, 1}, {28.05, 1}, {27.14,        1}, {27.32, 1}, {26.91, 1}, {27.12, 1}, {27.06, 1}, {27.9,        1}, {27.99, 1}, {27.7, 1}, {27., 1}, {27.11, 1}, {27.3, 1}, {27.12,        1}, {27.78, 1}, {28.07, 1}, {28.23, 1}, {28.17, 1}, {29.24,        1}, {29.48, 1}, {29.19, 1}, {29.65, 1}, {29.26, 1}, {29.62,        1}, {30., 1}, {30.44, 1}, {31.03, 1}, {30.93, 1}, {30.26,        1}, {31.27, 1}, {31.34, 1}, {32.75, 1}, {33.55, 1}, {33.17,        1}, {34.31, 1}, {34.14, 1}, {33.88, 1}, {34.89, 1}, {34.14,        1}, {32.93, 1}, {33.01, 1}, {33.87, 1}, {34.15, 1}, {34.,        1}, {33.38, 1}, {33.09, 1}, {32.74, 1}, {33.43, 1}, {34.06,        1}, {33.94, 1}, {33.1, 1}, {33.08, 1}, {32.25, 1}, {32.35,        1}, {33.17, 1}, {32.57, 1}, {32.94, 1}, {33.18, 1}, {33.19,        1}, {32.97, 1}, {32.88, 1}, {32.11, 1}, {33.12, 1}, {33.82,        1}, {34.07, 1}, {35.1, 1}, {35.69, 1}, {35.47, 1}, {34.98,        1}, {34.63, 1}, {35.62, 1}, {36.3, 1}, {36.49, 1}, {36.29,        1}, {36.64, 1}, {36.96, 1}, {36.98, 1}, {37.01, 1}, {36.56,        1}, {38.13, 1}, {38.87, 1}, {38.86, 1}, {38.87, 1}, {40.22,        1}, {39.16, 1}, {39.35, 1}, {39.73, 1}, {39.73, 1}, {39.51,        1}, {40.04, 1}, {40.2, 1}, {40.12, 1}, {40.77, 1}, {40.85,        1}, {40.65, 1}}                        e={-39.5086, -34.3476, -21.3119, -17.2624, -22.8212, -12.6281, \     -4.05305, -10.284, -29.2365, -28.9788, -47.4106, -52.2288, -57.3004, \     -57.044, -21.7327, -14.2378, -13.6716, -15.6634, -3.07337, -9.56075, \     0.0428573, 17.8984, 7.95581, 9.61876, 11.0461, 7.3986, 15.974, \     6.7027, 0.0836829, 3.19188, 7.67778, 15.2763, 24.9694, 16.4266, \     20.9189, 18.9357, 17.7393, 16.6252, 19.9538, 19.0034, 14.0373, \     17.3368, 30.486, 25.6365, 28.4368, 24.1961, 32.2371, 28.1878, 26.836, \     21.6437, 20.0929, 14.5311, 15.5325, 20.0288, 4.56828, -2.70303, \     -5.26942, -5.80811, -15.5681, -23.0899, -15.6158, -8.19073, -8.70942, \     -22.0519, -30.5952, -41.6398, -44.3709, -37.6881, -42.0611, -45.5617, \     -42.4614, -28.0188, -37.4065, -47.103, -16.4617, -23.8073, -22.8127, \     -23.1099, -34.5714, -34.0337, -12.4429, -11.6738, -9.01844, -10.4266, \     4.10304, 18.3527, -0.190233, 10.8367, 11.3732, 10.7993, 15.0527, \     20.6719, 38.3996, 38.3901, 44.6483, 43.0501, 34.8527, 24.5722, \     26.1599, 11.7909, 23.8498, 14.9986, 9.23092, 10.165, 5.15272, \     -1.32286, 7.33681, 5.00731, 6.98059, 22.2116, 17.1747, 17.4044, \     14.8388, 14.3011, 21.4022, 33.8758, 40.5732, 38.6981, 37.4166, \     43.9763, 26.3214, 28.5563, 29.1317, 37.8048, 43.5765, 41.9573, \     36.5953, 42.233, 56.2035, 38.1798, 40.8262, 47.4906, 47.248, 47.1996, \     49.3891, 4.39601, -3.47399, -8.86219, 24.9919, 25.9935, 17.508, \     -4.48744, -4.30891, -4.54432, 2.20928, -1.59285, 16.9316, 24.1806, \     22.2945, 19.3957, 12.3694, 12.9571, 7.54649, -7.9417, -12.0437, \     -18.9007, -14.6697, -20.2643, -5.04498, -8.59367, -3.73548, -12.6302, \     -17.5525, -16.7896, -21.9673, -25.3056, -21.4283, -27.1137, -24.0638, \     -17.3968, -11.9953, -11.0271, -19.4666, -22.6394, -10.5365, -20.936, \     -18.7627, -25.7619, -33.4171, -23.1605, -37.4145, -31.1141, -37.136, \     -52.7573, -63.4735, -84.8161, -99.2387, -93.7135, -100.639, -96.9627, \     -104.754, -124.455, -119.213, -112.161, -111.235, -112.446, -113.121, \     -106.63, -90.9322, -70.3292, -74.0381, 37.6777, 19.6116, 25.208, \     62.8927, 57.3488, 60.1155, 58.3352, 66.6165, 70.2785, 64.5913, \     57.2585, 56.1704, 55.0572, 57.7095, 55.078, 47.1967, 30.6944, \     27.9336, 32.3462, 25.7823, 27.589, 33.3226, 32.5037, 13.9685, \     14.9823, 9.79964, 27.0003, 33.9492, 33.5921, 29.756, 24.1719, \     30.0634, 10.1723, -2.36215, 10.3259, 18.4378, 3.62343, 13.0049, \     2.67227, -12.503, -0.312969, 0.043751, 6.55802, 5.49949, 21.1638, \     25.3716, 20.8474, 29.628}      I have added the explanation from the book: ![enter image description here](http://i.stack.imgur.com/fqWmv.jpg)


title: Proper way to add vertices to an adjacency matrix

text: I'm looking for a robust way to add vertices to a graph by modifying its `AdjacencyMatrix`. Here's what I have so far:               addNode[matrix_,in_,out_]:=Module[{mod},         mod=ArrayPad[matrix,1];         mod[[1,2]]=1;         mod[[2,1]]=1;         mod[[Length@mod,-out]]=1;         mod[[-out,Length@mod]]=1;         mod     ]      This will add a vertex connected to `vertex 1` and another vertex connected to `vertex out`. Notice that I only add 1x1 0's to my matrix. This is because at the moment I only need to add 2 vertices to my graphs. * * * **Examples:** ![Mathematica graphics](http://i.stack.imgur.com/BdGfp.png) ![Mathematica graphics](http://i.stack.imgur.com/BtQcJ.png) * * * I've tried implementing a similar function that accepts the `in` argument, but I couldn't get it to work properly. It seems as if I have to program special cases for it to work. Is there a better way to do this?


title: How do I get java to recognize import com.wolfram.jlink

text: I'm trying to write a java program that uses mathematica code for processing and graphs while using java for the front end. From what I've been able to glean from the j/link tutorials on the wolfram site I will need to import com.wolfram.jlink in my java program like so:               import com.wolfram.jlink.*;      I can't seem to get it to work. When I try to compile my compiler says that the com.wolfram package does not exist. I'm guessing that I need to download and install the com.wolfram package somewhere but I don't know where to acquire it and google has been less than helpful. In case it's helpful I'm running JRE 1.6 on a machine running windows 7.


title: Evaluation inside Compile

text: here's a simple question: I have a function:               Compile[{T, μ, dq, ω, m},       Module[{s = 0.0 + 0.0 I, mu = -10*T},        Do[s = s + 0.1*T*(expr), {mu, -10.0 T, 10.0 T, 0.1 T}]; s], CompilationTarget -> "C"]      where `expr` is some long expression assigned before. I cannot make this work other that manually copy-pasting an explicit long expression for expr. I tried `Evaluate` and some combinations of `ReleaseHold`, but it did not work for me. Any ideas?


title: How to speed up calculations with large number of replacement rules?

text: In my program I have an expression which looks like:               AnalyticalExpression = 2^(-1-n-np)R^(-2+n+np)(8np1f[-2+n+np,-1+p1+p1p,1+p2+p2p,1+q1+q1p,3+q2+q2p]-8np1f[-2+n+np,-1+p1+p1p,3+p2p2p,1+q1+q1p,1+q2+q2p]-4np1f[-2+n+np,p1+p1p,p2+p2p,q1+q1p,4+q2+q2p]+...)      I gave here a short example; full expression is few pages long. From my point of view, this expression serves as a function of the integer variables n,np,p1,p1p,q1,q1p,... and two real variables R,x. My program evaluates the above expression by using a replacement rule, for instance:               tmp = AnalyticalExpression /. {n->2,np->3,p1->0,p2->4,...}      The problem is that the program has to evaluate this expression hundreds of thousands times with different values of these integer variables. This makes the whole program painfully slow. Is there a tricky way to perform this substitution efficiently? Tabulation of AnalyticalExpression for every combination of the integer variables seems quite weird to me... Thanks in advance for the answers and suggestions. Michal


title: Plotting the results of iterating a function

text: This is what I am stuck on               f[a_][x_] := x^2 + a;     w[a_] := Take[NestList[f[-1.8], 0, 1000], 100]      Now I want to evaluate this for different values of the constant $a$ from -1.8, to 0.3, store the results in a table, suppress the results because they will be very long, and then make a plot of $a$ versus $x$ using `ListPlot`. How can I evaluate for different values of $a$ and then plot? I have tried the `Do` function but can't get it to work.


title: Inlining calculations in a notebook

text: ## Context In $\LaTeX$, I can write something like:                 Thus, we have $x = \sqrt{2}$, ...          the $ ... $, as opposed to $$ ... $$, inline the LaTeX symbols.      Now, with _Mathematica_ , I type a line of Input, I press `Shift``Enter`, and it produces the answer on a different line of output. However, I would like to type something like this:                 Thus, we get $c^2 - c = 1$, and solving it, we get $N[solve[c^2 - c = 1, c]]$, ...      The idea is that mathematica evaluates the command, takes the output, and _inlines_ it into the sentence, rather than have it as a separate line. I have no idea how to do this. From what I've read, this sounds like "cells", but from goofing around, it's not clear how to make this work. ## Question: How do I inline a mathematica expression, such that its output is displayed inline?


title: Does Mathematica have a "MATLAB Builder" equivalent?

text: I was wondering if _Mathematica_ has an equivalent of MATLAB's "MATLAB Builder" as seen here? I found this but it reads as if all programs using .NET/Link must have _Mathematica_ installed on them as well. I have several systems to replicate and it would be impossible to have _Mathematica_ installed on all 25-1000 computers. Thanks! **EDIT** Additional Information: I use C# applications to control various systems and I would like to use a bunch of _Mathematica_ 's functions (interactive plots, optimization, statistical analysis, etc.) within them. From the link, MATLAB's "MATLAB Builder" can create assemblies of user designed functions/scrips for standalone use in C#/.NET applications (i.e. MATLAB isn't required on the deployment PCs for the MATLAB assembly functions to run). I'm looking for a _Mathematica_ equivalent.


title: Creating a Mathematica executable that uses JLink

text: I am making a program in Mathematica that uses the Robot class of Java and some other Mathematica functions. I want the end product to be a standalone executable that can run even if a computer does not have Mathematica. Is this possible, and how so? Would CDFPlayer work, or is there some other way?


title: List of Mathematica textual symbols

text: ## Context I am using _Mathematica_ to create live documents - documents that are both interactive and show mathematical derivations. Now, I'm aware that there are certain symbols that are available via:               \[CapitalSigma]      or `esc`S`esc` However, some of the symbols I want (`\in`: $\in$, `\subsetneq`: $\subsetneq$) do not belong in the greek letters. Is there a list of something similar to this but lists _Mathematica_ symbols instead of $\LaTeX$ symbols? Thanks!


title: Rebinding keys to define new keyboard shortcuts

text: I've checked **_Mathematica_** → **Preferences** , and poked around the options on the toolbar. However, I don't see a way to define new keyboard shortcuts in _Mathematica_. I've used VIM for 10+ years, and I've rebound `Ctrl`+`F` to be `Esc` for the last decade or so. I would like to also use this shortcut in _Mathematica_ , to have `Ctrl`+`F` be `Esc`, so hitting something like: `Ctrl`+`F` `S` `Ctrl`+`F` should give me capital Sigma. Question: how do I define new keybindings in _Mathematica_? (I have a CS background, so I'd prefer things that involve editing config files / writing scripts -- that would give me more power -- over clicking things in a GUI).


title: How to display each step of an A star algorithm?

text: I wrote a pathfinding program: A*, which is an extension of Dijkstra. I want to see the result of each step at a time. Which function should I use? The main program is the notebook Astar, which is implemented based on a data structure called priority queue. The package `PriorityQueue.m` is put in location F:\ by default. For example, here are some results of a whole run. ![enter image description here](http://i.stack.imgur.com/HeScT.gif) ![enter image description here](http://i.stack.imgur.com/r5R3T.gif) ![enter image description here](http://i.stack.imgur.com/fBd9c.gif)


title: Contour plot of complex function: problem in choosing argument

text: I have a complex function F[x,y], and now I want to plot the contour F[x,y] = 0. What can I do in order to have the contour plot vs Re[x] and y (That is, I want to treat y a real variable and x a complex one)? Thanks you very much!


title: Plotting double inequality only for integer values

text: `RegionPlot` is plotting for all values. And using `ListPlot` I can only evaluate one inequality. How can I plot this type of inequality: $$\frac{1}{\alpha+1} \leq \frac{\sum_{i=0}^k i^a}{\sum_{i=0}^k i^b} \leq 1+\alpha$$. $a$,$b$ are const (I know values $a$ and $b$). I want to plot dependency between $\alpha$ and $k$ only for integer values of $k$ and $\alpha$ is only from $(0,1]$. So I tried to use `ListPlot` (as you suggested me in previous post).               ListPlot[Table[{k, (-1) + (Sum[i^a, {i, 0, k}]/            Sum[i^b, {i, 0, k}])}, {k, 1, n}], PlotRange -> {0, 1},       Filling -> Top]      But I don't know how to add here the second inequality. I tried also to use `RegionPlot`. This commend is easier for me, because I know how to add the second inequality, but I don't know how to restrict that `k` should be only integer               RegionPlot[(Sum[i^a, {i, 0, k}]/           Sum[i^b, {i, 0, k}]) <=         1 + f && (Sum[i^a, {i, 0, k}]/           Sum[i^b, {i, 0, k}]) >= 1/f, {k, 1, n}, {f, 0, 1}]


title: Paste data into Mathematica with formatting

text: Select the following Mathematica code and paste it into a notebook. In Windows 7(Mathematica 8) the line breaks are not interpreted in the expression. In fact any data copipasted from stackexchange loses it's formatting. How do I paste content from stackexchange into Mathematica while keeping the formatting?               Print[       "text"     ]      **EDIT:** Now ideally Mathematica would support this natively. Solutions to integrate this into Mathematica would be great. I have 3 possible ideas.   1. modify Ctrl+V so this automatically occurs   2. assign a different modifier    3. create a button or palette I'm going to do the 3rd for now, but any other solutions are appreciated.


title: How to make a 3D-Plot from 2D-interpolated data

text: I have data of the form `{x,y}` for different concentrations. Therefore I added the concentration as `z`, resulting now in `{x,y,z}`. Example data (for concentrations A:1%, B:2%, C:4%):               dataA = {{1, 20, 1}, {2, 19, 1}, {3, 18, 1}, {4, 17, 1}, {5, 16, 1}};          dataB = {{1, 20, 2}, {2, 19.5, 2}, {3, 19, 2}, {4, 19.5, 2}, {5, 16, 2}};          dataC = {{1, 20, 4}, {2, 21, 4}, {3, 20.5, 4}, {4, 19.5, 4}, {5, 16, 4}};      Now I want to make a 3D surface plot from these traces (by 2D-interpolation). How to do that? **Edit:** the real data here: dropboxlink


title: Unsetting messages

text: The following code suggests that Mathematica stores the messages in cache:               (*1*)Remove[VariationalD]     (*2*)Messages[VariationalD]     (*3*)Message[VariationalD::args, OPS]     (*4*)Messages[VariationalD]      The output of the second line is `{}` as expected for a symbol that has just been removed. The output of the third line however is not the expected "-- Message text not found --". Instead, Mathematica seems to have pulled that message from some cache. In any case, **how can I reset the message cache (without resetting the whole installation)?** * * * **Update** I apologize because my previous example did not really work. In any case, the following is a better example. This code was executed on a freshly launched kernel.               before = Messages[General]; Message[General::dummies, OPS];     after = Messages[General]; Complement[after, before]      ![enter image description here](http://i.stack.imgur.com/gOhd5.png) The message `General::dummies` was not part of the original list of messages attached to `General`. Following the documentation, the next place to check would be `$NewMessage`, but `Messages[$NewMessage]` is empty. So, where did `General::dummies` come from?


title: Bug in handling backslashed Cyrillic symbols in v.10.0.0?

text: Consider:               "\бвгд" // FullForm     "\\бвгд" // FullForm      In v.8.0.4 I get this: > >     "\\:0431\:0432\:0433\:0434" >     "\\\:0431\:0432\:0433\:0434" >   But v.10.0.0 adds redundant backslash before the first backslashed Cyrillic symbol: > >     "\\\:0431\:0432\:0433\:0434" >     "\\\\:0431\:0432\:0433\:0434" >   ![screenshot](http://i.stack.imgur.com/HFbKC.png) As the result it is not possible to open any file which name (or name of a directory in the path) starts from a Cyrillic symbol. Also after evaluating the above (in the case the Cyrillic symbols were typed, not pasted in the Notebook) the following bugs appear:   * When I try to cut by pressing `Ctrl+X` any `Cell` or group of cells in this Notebook I get http://demonstrations.wolfram.com/ opened in my browser and nothing changed in the FrontEnd   * After some additional editing (entering backslashed Cyrillic symbols after the quote `"` but without entering the closing quote and without evaluation of the cell) an attempt to cut an input cell by pressing `Ctrl+X` results in commenting all the code in the selected input cell. Pressing `Ctrl+X` again uncomments the code. All the above manipulations with `Ctrl+X` give this result when English keyboard locale is selected. Does anyone also observe this? Is there a workaround? P.S. OS Win7 x64.


title: Animation - Autorun?

text: Reworking on a pre-made simulation, when I click the 'Play' button, it won't actually play and when I autorun the program, it just cycles through all the balloons in 10 seconds... is there a way in which I could slow down the time it takes to go through all the balloons as well as? I have not linked the actual graphic of the girl in the code (as it takes up a lot of space).. I've tried using AutorunSequencing yet I don't know where to place it within the code.. ![enter image description here](http://i.stack.imgur.com/OrLko.png)                Manipulate[SeedRandom[236175234];        With[{rp = Prepend[RandomReal[UniformDisk[2], n + 1], {0, -35}]},       Graphics[GraphicsComplex[rp,        {Translate[{Inset[, {2.5, -39.5}, Automatic, {6, 9.5}],       {Opacity[.5], Thickness[.001],          Line[{1, #}],          Hue[RandomReal[]],          Disk[#, 2.8]} & /@ Range[2, n + 1]},       If[n > 83, {0, Up}, {0, 0}]], Darker@Red, Thickness[.04],      Line[{{-25, -44.8}, {25, -44.8}}]}],       PlotRange -> {{-23, 23}, {-46, 25}}, Background -> LightOrange]],          {{n, 1, "Balloons"}, 1, 150, 1, Appearance -> "Labeled"},     {Up, 0, 50, ControlType -> Trigger},      Initialization :> ({UniformDisk /:      Random`DistributionVector[UniformDisk[r_?Positive], n_Integer,        prec_?Positive] :=      r*Sqrt[RandomReal[1, n, WorkingPrecision -> prec]]*       Transpose[        10 {Cos[#], Sin[#]} &[         RandomReal[2 Pi, n, WorkingPrecision -> prec]]]})]


title: How to search a file in a particular system using Mathematica

text: I want to know if there is any function which can search a file from the whole system and gives the whole path for that particular file. I have tried `$Path` but it gives some default paths also. * * * Addendum: If the file is stored in multiple locations and I want only one location out of all, how can I get that? I want to stop the search as soon as the file is found.


title: How to add label to a plot in PopupMenu which does not change the plot size

text: I am facing a problem in adding a label to a `PopupMenu`. I have two plots a and b of same size. But when I am adding label to them in `PopupMenu`, it is changing the size of the plot. When the `Label` size is bigger, it compresses the plot so that it adjust to the `FieldSize` of `PopupMenu`. But I dont want this.                a = Manipulate[            l = DiscretePlot[Cos[a t], {t, 0, 2 Pi, Pi/6}, ExtentSize -> Full,             ImageSize -> Scaled[1], AspectRatio -> .25, ImageMargins -> 0,             ImagePadding -> 0],             Mouseover["vertical", Control[{{a, 1, "a Manipulator"}, 1, 20}]],             ControlPlacement -> Bottom];     b = Manipulate[q = Graphics[          DiscretePlot[Sin[g t], {t, 0, 2 Pi, Pi/6}, ExtentSize -> Full,           PlotStyle -> Orange, AspectRatio -> .25, ImageSize -> Scaled[1],           ImageMargins -> 0, ImagePadding -> 0]], {g, 1, 10}];          Grid[{{PopupMenu[             Dynamic[p], {a ->Labeled[l, (Framed["pop_up_window Plot"]), {Right},                         LabelStyle -> Directive[Bold, FontFamily -> "Helvetica"]],                       b -> Labeled[q, (Framed["mouseover Plot"]), {Right},                     LabelStyle -> Directive[Bold, FontFamily -> "Helvetica"]]},             FieldSize -> {24, 8}, ImageMargins -> 0,             FrameMargins -> 0, ContentPadding -> False,             Alignment -> {Center, Center}]}, {Dynamic[p]}}, Spacings -> 20,             Alignment -> {Left, Top}]      ![enter image description here](http://i.stack.imgur.com/ZBhTc.png) When I am adding label, then the first plot becomes smaller than the second. I want that `Label` size should not affect the `Plot`size.


title: Can RowReduce work in this matrix?

text: The matrix $Q$ with dimensions $n\times2*n*m$ is structured by $$Q=[B|AB|\cdots|A^{2*n-1}B]$$ where $Q$ is an augmented matrix built from a $3\times3$ matrix, $A$, and a $3\times2$ matrix, $B$. I need $\DeclareMathOperator{\rank}{rank}\rank(Q)<n$ but I get $\rank(Q)=n$. If I `RowReduce` matrices $A$ and $B$ before that calculation the $Q$ matrix has $\rank<n$ as I want, but its elements aren't the ones I need to continue, but 0's and 1's. Any Idea on how to get the desired $Q$ matrix? If I multiply $Q$ by $Q_\text{reduced}$ (with dimensions $2*n*m\times n$) I get an $n\times n$ matrix, $W$ with $\rank(W)=n$, so that's not what I want. I've no Idea how to implement the _Mathematica_ code here. Any suggestions would be helpful.               CellGroupData[{       A0 = RandomInteger[{1, 10}, {4, 4}],       B0 = RandomInteger[{1, 10}, {4, 3}],       A1 = RowReduce[A0],       B1 = RowReduce[B0],       m = 3,       n = 4,            (*Original Matrices Proc *)       Do[Lnn[j] = MatrixPower[A0, j - 1].B0, {j, 2*n}],       Do[Flatten[Lnn[j][[i]], m], {i, n}, {j, 2*n}],           M222 = Table[Lnn[j][[i]], {i, n}, {j, 2*n}],       R222 = Flatten[M222],       Qnn = Partition[R222, 2*n*m],       η1 = MatrixRank[Qnn],       {p1, r1} = Dimensions[Qnn],       QN11 = RowReduce[Qnn],            (*RowReduced Matrices used now *)       Do[Lnn1[j] = MatrixPower[A1, j - 1].B1, {j, 2*n}],       Do[Flatten[Lnn1[j][[i]], m], {i, n}, {j, 2*n}],           M22 = Table[Lnn1[j][[i]], {i, n}, {j, 2*n}],       R22 = Flatten[M22],       Qn = Partition[R22, 2*n*m],       η = MatrixRank[Qn],       {p, r} = Dimensions[Qn],       QN = RowReduce[Qn],            Print[MatrixForm[Qnn], MatrixForm[QN11]],       Print[MatrixForm[Qn], MatrixForm[QN]]}];


title: Simulated Annealing InitialPoints option

text: I have a cost function that depends on 4 parameters: `CostFunction[{tx,ty,tz,ox}]`. I used `NMinimize[]` function with `SimulatedAnnealing` method to determine its minimum. I looked for an example that uses the `InitialPoints` option but I did not find any. For this reason I am posting my question. My code is like this (I cannot post the `CostFunction[]`):                 NMinimize[{             CostFunction[{tx, ty, tz, ox}],             tx >= 0 && tx <= a, ty >= 0 && ty <= b, tz >= 0 && tz <=c, ox >=0 && ox <= d},       {tx,ty,tz,ox},       Method -> {"SimulatedAnnealing", "PerturbationScale" -> 3, "SearchPoints" -> 10}]       The above code works correctly but when I add the `"InitialPoints"->{0,0,0,0}`, I receive the following error: > `NMinimize::parchange: "Inappropriate parameter: \!\(\"InitialPoints\"\) -> > {0,0,0,0}, changed to Automatic"` Another option is not very clear `"RandomSeed"` ? What is wrong, please?


title: Executing C programs within mathematica

text: I have a requirement for executing a C program within Mathematica. The user will provide the inputs and the expected results on a front end. Mathematica runs the C file, obtains the result for the provided inputs and compares with the user provided expected results. Further, a green pass button will be displayed if the results matched else a red failed button will be displayed. Later, I want to be able to do the same for C++, Python, Java, and Perl programs. Anyone has worked on this before ? Warm regards, Anuk


title: Changing the default font size

text: Hey I have problems reading my mathematica notebooks due to the small fonts. I'd like to change their default values for the input and output. I already figured out that everything seems to be defined in core.nb but I couldn't find any definitions inside. It just states things like: ![enter image description here](http://i.stack.imgur.com/URduf.png) But I don't see any definition, also I couldn't find them in the FormatType Styles section that looks like: ![enter image description here](http://i.stack.imgur.com/KUOjY.png) An easy solution to my problem is to change the magnification but this is only possible in too huge steps. I also played around with the Option Inspector, but I could't find any place that effetcs the font size of my input/output. Changing the FontSize in Global options also didn't change anything: ![enter image description here](http://i.stack.imgur.com/j8T6T.png) Any ideas? I know there are many similar threats already but I couldn't find a working answer. And I doubt that the solution has to be super complicated. Edit: Just realized that the last way changes the fonts as expected but only inside the documentation center.


title: Cell copy results in jaggy, aliased output

text: When I copy a cells by selecting them from the collapse bars on the right, then using the context menu option "Copy", the pasted image of plots is not anti-aliased and in general the text seems to have bad styling compared to a screen. For example, here is a plot which is copied using the built-in copy command:               Manipulate[Plot[Cos[a x], {x, 0, 3 \[Pi]}], {a, 1, 10, 0.3}]      ![copied plot](http://i.stack.imgur.com/13VxF.png) and here is a screen shot of the same command and plot: ![enter image description here](http://i.stack.imgur.com/ArIPX.png) As you can see the screen shot looks a lot better. For example, compare the graphical quality of the buttons in the animation panel.


title: Using levels in MapIndexed

text: I am trying to use `MapIndexed` to manipulate a matrix of data but I am having trouble getting the levels parameter to work the way I would like. Suppose that my data looks like this, with every odd column being a count and the even columns being some piece of data:               a = {{11, d11, 21, d21, 31, d31},          {12, d12, 22, d22, 32, d32},          {13, d13, 23, d23, 33, d33},          {14, d14, 24, d24, 34, d34}};          b = {{11, d11, 0, Null, 31, d31},          {12, d12, 0, Null, 32, d32},          {13, d13, 0, Null, 33, d33},          {14, d14, 0, Null, 34, d34}};          c = {{0, Null, 0, Null, 31, d31},          {0, Null, 0, Null, 32, d32},          {0, Null, 0, Null, 0, Null},          {0, Null, 0, Null, 34, d34}};      As you can see, some odd columns will have a zero count and the corresponding data column will be `NULL`. Edit: _I have changed`c` to reflect some new bits of information about the data. There may be some rows that contain the `0, NULL` pattern, but I only want to eliminate columns in which the first row is like this. The first row is a sum of the following rows, and I only want to eliminate a column if it has no data at all. This is why I structured the `For` loop in the way I did. Based on the responses, I felt I needed to clarify._ I'd like to eliminate both the count and data columns any time this is the case. For example, after some operation I'd like to have:               a0 = {{11, d11, 21, d21, 31, d31},           {12, d12, 22, d22, 32, d32},           {13, d13, 23, d23, 33, d33},           {14, d14, 24, d24, 34, d34}};          b0 = {{11, d11, 31, d31},           {12, d12, 32, d32},           {13, d13, 33, d33},           {14, d14, 34, d34}};          c0 = {{31, d31},           {32, d32},           {0, NULL},           {34, d34}};      I accomplished this using a hack with a `For` loop but this is obviously not the proper way to use Mathematica and I was directed to `MapIndexed`:               a0 = For[i = 1, i < Length @ a[[1]], i = i + 2,               If[a[[1, i]] == 0,                  a = Drop[a, None, {i, i + 1}];                  i = i - 2              ]          ];      How can I get `a0` with something of this form?:               a0 = MapIndexed[f, a, list];


title: Building conditional lists with Manipulate

text: I'm trying to select elements of a list that satisfy some criteria using `Manipulate[]`. Given 2 lists:               list1 = {{a, b, c}, {d, e, f}, {g, h, i}};     list2 = {{9, 0}, {2, 1}, {9.5, 3}};      I want to build a function that, when some criteria are `True`, will look for them at a specific position in `list2`. Let me show with an example: Consider the case in which I only want to find if elements in position 1 of `list2` are `>=9` and then take the corresponding position from `list1`. I would write               Pick[list1, Map[#[[1]] >= 9 &, list2]]     (*{{a, b, c}, {g, h, i}}*)      However, if I was to look into elements in position 1 being `>=9` and elements of position 2 being `<2` I would write               Pick[list1, Map[#[[1]] >= 9 && #[[2]] < 2 &, list2]]     (*{{a, b, c}}*)      **But what I want is** to have a manipulable function that uses the `And` function in the second case, but without excluding the possibility that only one of the criterion may be desired. I.e., when only `c1 = True` I want the first case to be analyzed; when only `c2 = True` I only want the second case; when both are true, I want the both conditions to be analyzed. I was thinking about using the following function, but this doesn't work mainly because the new list is not even created.               Manipulate[      Block[{conditional, condlist, c1, c2},       condlist = {};       If[c1, Insert[condlist, #[[1]] > 9, -1]];       If[c2, Insert[condlist, #[[2]] > 3, -1]];       condlist             (*Pick[list1, Map[condlist &, list2]]*)       ], {c1, {True, False}}, {c2, {True, False}}]      Anyone has any tips on how I can solve this? Thanks in advance! **Edit:** though the example I present here only considers 2 conditionals `c1` and `c2`, this is to be applied to a much larger set of conditions. It includes 8 conditionals, and may have any combination among it (e.g. `c1 AND c2 AND c4`, or `c7`, or `c5 AND c6 AND c7`, etc).


title: Arranging and combining multiple plots and graphics

text: I have 4 plots/schematics. They are either created with ArrayPlot[], ParametricPlot3D[] or Graphics[]. As I play with calculation resolutions their absolute sizes will change. I would like a neat way to arrange them inside a YouTube sized box (1920 x 1080) using relative positioning so that when/if they change size the final combination still looks more or less how I want. To simplify the question let's say I have:               videoBox = Graphics[{EdgeForm[Thick], White, Rectangle[{0, 0}, {1920,1080}]}];     plot1 = Graphics[{Blue, Rectangle[{0, 0}, {2, 3}]}];     plot2 = Graphics[{Red, Disk[{0, 0}, 2]}];     plot3 = Graphics[{Orange, Disk[{0, 0}, 2]}];     plot4 = Graphics[{Gray, Rectangle[{0, 0}, {2, 1}]}];     GraphicsRow[{videoBox, plot1, plot2, plot3, plot4}]      ![](http://i.stack.imgur.com/JDFnN.png) Using relative positioning I would like to combine them to look something like: ![](http://i.stack.imgur.com/WbatV.png) Any suggestions? **Update 1** The answers and suggestions have certainly helped, but I still need more control over the positioning. For example here is the actual image I have created using the suggestions so far: ![](http://i.stack.imgur.com/9fz0B.jpg) Close but no cigar. I would like to move the blue and red dots schematic up so that the bottom lines up with the bottom of the rectangular box plot.


title: Computing polynomial eigenvalues in Mathematica

text: MATLAB offers a function polyeig for computing polynomial eigenvalues, which appear, for instance in quadratic eigenvalue problems (see here for some applications) such as: \begin{equation} (M\lambda^2 + R\lambda + K)x =0 \end{equation} where $M$, $R$ and $K$ are matrices. Any realistic way of accomplishing this in _Mathematica_? By realistic I mean one that actually employs specialized algorithms. * * * P.S. If anyone from Wolfram is reading this: any perspectives on whether this may appear in future releases of _Mathematica_?


title: Changing background colour of a Manipulate element

text: Please consider the following:                Manipulate[Plot[Sin[x (1 + a x)], {x, 0, 6}], {a, 0, 2}];      Now, I would like to change the background colour to yellow. I tried the following, but in this case the nice looking rounded corners of the manipulate element get lost:               Panel[#, Background -> Yellow] &@      Manipulate[Plot[Sin[x (1 + a x)], {x, 0, 6}], {a, 0, 2},        Paneled -> False]      Maybe somebody has a better idea. **EDIT** The background colour of `Manipulate`is by default grey. ![Manipulate](http://i.stack.imgur.com/mz8fw.png) In addition the graphical element in which the `Manipulate` is embedded has rounded corners ![rounded corner](http://i.stack.imgur.com/ICUH7.png) which I would like to keep. Applying my approach will change the colour but I loose the rounded corners.


title: What is the best way for an application to provide customisation options for the user?

text: Suppose that an application needs to be configured specifically for a user's system. e.g. the application needs to be told the location of certain data directories. What is the best way to provide this possibility to the user, so that the user doesn't have to enter this information every time they load the package?


title: pH calculations, speeding up code involving Solve

text: I'm trying to calculate pH values of solutions containing water and acetic acid. The relevant equations have been defined and I now want to find a solution using Mathematica. For a specific acid concentration (0.0001) I can do the following.               Solve[(concentrations && equilibrium && requirements) /. {c2 -> 0.0001}]      But I would prefer to solve the system of equations once and then insert the acid concentration. But the following code does not work               Solve[(concentrations && equilibrium && requirements)] /. {c2 -> 0.0001}      Which throws the following error               Solve::ratnz: Solve was unable to solve the system with inexact      coefficients. The answer was obtained by solving a corresponding      exact system and numericizing the result. >>"      My working code so far is shown here               concentrations = cHp == c1 + c3 && cOHm == c1 && cCH3COOm == c3 && cCH3COOH == c2 - c3;     equilibrium = 10^-14 == cHp cOHm && 1.1614 10^-5 == cCH3COOm cHp/cCH3COOH;     requirements = cHp > 0 && cOHm > 0 && cCH3COOH > 0 && cCH3COOm > 0;     Plot[-Log[10, cHp] /.        Solve[(concentrations && equilibrium && requirements) /. {c2 ->            x}], {x, 0, 0.00010}, PlotRange -> {2, 9}]


Why I can not get the plot when I use NDSolve`ProcessSolutions? Anyone can give me a cue. Thanks a lot!               state = First[NDSolve`ProcessEquations[{D[u[t, x], t] == D[u[t, x], x, x],u[0, x] == Cos[\[Pi] /2 x], u[t, 0] == 1, u[t, 1] == 0}, u, t, {x, 0, 1}]];     NDSolve`Iterate[state, {0, 4}];     NDSolve`ProcessSolutions[state, "Forward"];     Plot[Evaluate[u[4, x] /. %], {x, 0, 1}]


title: Clean-up Code / Reduce variables

text: I'm writing a playing card simulator of sorts, and everything works fine, but some `Module`s use a disgusting amount of variables. For Example:               randomHand[x_] :=      Module[{hand, kings, cards, suits, value, suitsK, valueK, cardList},     hand = PadLeft[IntegerDigits[RandomInteger[{1, 52}, x], 13]];     kings = Cases[hand, {___, 0}, 2];     cards = DeleteCases[hand, {___, 0}, 2];     suits = First /@ cards;     value = Last /@ cards;     suitsK = First /@ kings;     valueK = ReplaceAll[Last /@ kings, 0 -> "King"];     suits = suits /. {0 -> "Hearts", 1 -> "Diamonds", 2 -> "Clubs",       3 -> "Spades"};     suitsK = suitsK /. {1 -> "Hearts", 2 -> "Diamonds", 3 -> "Clubs",       4 -> "Spades"};     value = value /. {11 -> "Jack", 12 -> "Queen"};     cardList = Partition[Riffle[value, suits], 2];     Map[ToString[cardList[[#]][[1]]] <> " of " <> cardList[[#]][[2]] &, Range[Length[cardList]]]]      My Mathematica knowledge is not as fluent as I'd like it to be, so I'm wondering if it is bad to use so many variables, and if it is, how would I go about cleaning up the above excerpt?