title: Generating an array using list values at indices corresponding to entries in a separate list satisfying some criterion

text: Imagine one has an array of integer value sets that looks like this:               testValues = {{9, 8, 8, 10, 1}, {10, 0, 0, 1, 0}, {8, 0, 0, 5, 7}, {1, 5, 7, 2, 7}, {6, 9, 3, 9, 10}, {7, 10, 7, 5, 3}, {3, 10, 6, 1, 9}, {5, 8, 7, 9, 2}, {2, 3, 2, 7, 0}, {3, 7, 10, 2, 7}};      And a set of lists that looks like this:               listA = {1,2,3,4,5,6,7,8,9,10};     listB = {1,2,3,4,5};     listR = {{67,56,55,33,24,32,54,667,99,103498},{5}};     listQ = {{653,29,49,69,19},{20987}}      Here, `Length[listA] == Length[listR[[1]]]`, `Length[listB] == Length[listQ[[1]]]`, and the number of entries in `testValues` is `Length[listA]*Length[listB]`. I want to very quickly output an array with entries:               {{listR[[a, 1]], listQ[[b, 1]]},...}      For all `{a,b}` pairs where `testValues[[a,b]] >= threshold` for some integer `threshold` value. The entries in the array do not need to be in any particular order. The naive way of proceeding could look like:               outputList ={};          For[a = 1, a <= Length[listA], a++,       For[b = 1, b <= Length[listB], b++,              If[testValues[[a, b]] >= threshold,           outputList = Append[outputList, {listR[[a, 1]], listQ[[b, 1]]}];           ];              ];       ];      However, this is quite slow. Is there a much faster method using `Select` perhaps? The relevant list sizes are in reality something like `Length[listA]` $\approx 10^2$, `Length[listB]` $\approx 10^4$, and `testValues` has `Length[listA]*Length[listB]` entries. * * * Update: I was able to use Position to do the following:               goodIndices = Position[int, x_ /; x >= 3];     outputList[[i]] = {listR[[#[[1]], 1]], listQ[[#[[2]], 1]]} & /@ goodIndices;      This is about 4x faster than the naive approach I posted earlier. Are further speedups possible?


title: Custom WindowToolbar for my stylesheet

text: So I've noticed that some stylesheets (for instance Slideshow stylesheets) load a toolbar using the assignment `WindowToolbars -> {"ToolbarName"}` and I've been wondering whether it's possible to prepare and load a custom one using this mechanism. I've searched Mathematica directories but I couldn't find the toolbars source directory.


title: Is there documentation on the comparative performance of Mathematica functions?

text: Recently I have been solving some Project Euler problems. I find there are always several ways to do the same thing. For example, one could join two lists like this:               a = {2, 1};     b = {2, 3};     Union[a, b]     Join[a, b]      Which gives > {1, 2, 3}   >  {2, 1, 2, 3} So the `Union` function sorts the element and deletes duplicates. I guess the `Join` function will be faster, but how much faster? In a loop, would it be more efficient to use `Join` and `DeleteDuplicates` at each 100th step? Is there documentation of the comparative performance of _Mathematica_ functions? Because heuristics as above could be totally wrong, and I don't know how much experimenting it would take to form a good understanding of the complexity of functions.


title: Identify / change working directory for the InstallableNET runtime

text: I am currently attempting to use .NET/link to call a third party DLL from _Mathematica_ using `DLLDefinedFunction`. I have been able to link against and call many of the functions in the DLL, but have encountered issues with one function in particular, which attempts to read in data from a file whose path is hard-coded relative to the current working directory. Forgive my ignorance, but as I am not "au fait" with .NET, I don't know how to determine what InstallableNET32.exe is using as its working directory, or how to change it to something else. (I do know how to change the working directory for the MathKernel, but based on my experimentation, any changes to the kernel's working directory do not appear to "flow through" to the InstallableNET runtime.) Could someone please provide guidance on how I can identify, and then change, the working directory being used by the InstallableNET runtime (Is this an example of another undocumented feature in .NET/link, like the `"Force32Bit"->True` option?)


title: How can you show data in a CDF Animate Graphic?

text: I want to show (dynamically) the curvature and torsion in a CDF to understand the quantitative measure of any points. Do you know what I have to do to show data in a `Animate` graph? https://www.dropbox.com/s/85sy5bg9c96f818/Helice%20Pagina%2090%20OK%20TOTAL.cdf I want to view curvature and torsion in different curves to understanding the graphical sense. Thank you. * * * I add the code where i want to see dynamically the curvature and torsion Hello, what i want if to visualize the curvatura and torsion in every point where you can see the Frenet-3 vectors               Clear[a]     r[t_] := {Sin[t], Cos[t], a*t}     uT[t_] := Simplify[r'[t]/Norm[r'[t]], t \[Element] Reals]     vN[t_] := Simplify[uT'[t]/Norm[uT'[t]], t \[Element] Reals]     vB[t_] :=       Simplify[Cross[r'[t], r''[t]]/Norm[Cross[r'[t], r''[t]]],        t \[Element] Reals]     {uT[t], vN[t], vB[t]} // Column // TraditionalForm          rp1[t_] = Simplify[D[r[t], t]]     rp2[t_] = Simplify[D[rp1[t], t]]     rp3[t_] = Simplify[D[rp2[t], t]]          {rp1[t], rp2[t], rp3[t]} // Column // TraditionalForm          (*rr[t_]:=Simplify[r[t],t\[Element]Reals]     {rr[t]}//Column//TraditionalForm*)          curvatura[t_] :=       Sqrt[Cross[rp1[t], rp2[t]].Cross[rp1[t], rp2[t]]]/(Sqrt[          rp1[t].rp1[t]]^3)     Print["curv ", curvatura[t]]     Print["curv ", N[ curvatura[2]]]     Print["curv ", curvatura[Pi/2]]     Print["curv ", curvatura[Pi]]          torsion[t_] :=       Det[{rp1[t], rp2[t], rp3[t]}]/       Sqrt[Cross[rp1[t], rp2[t]].Cross[rp1[t], rp2[t]]]     Print["tors ", torsion[t]]     Print["tors ", N[torsion[2]]]     Print["tors ", torsion[Pi/2]]     Print["tors ", torsion[Pi]]          Simplify[Norm /@ {uT[t], vN[t], vB[t]}, t \[Element] Reals]     Manipulate[      Show[ParametricPlot3D[{r[t]}, {t, -Pi/a, Pi/a},         PlotStyle -> {Blue, Thick}],        Graphics3D[{{Thick, Darker@Red,           Arrow[{r[s], r[s] + uT[s]}]}, {Thick, Darker@Green,           Arrow[{r[s], r[s] + vB[s]}]}, {Thick, Darker@Cyan,           Arrow[{r[s], r[s] + vN[s]}]}}],(*Print[curvatura[r,s]],Print[       torsion[r,s]],*)PlotRange -> {{-2, 2}, {-2, 2}, {-Pi, Pi}},        ViewPoint -> {3, -2, 2}],       Style["Representación espacial de la noria del hamster", 12,        Bold], Delimiter, {{a, 0.5, "a (elegir valor entre -1 y 1)"}, -1, 1,        Appearance -> "Open"}, Delimiter, {{s, -Pi,         "Valor del parametro en el que se visualizar el Triedro de \     Frenet"}, -Pi/a, Pi/a,        Appearance ->         "Open"},(*Delimiter,Style["Curva Azul.- Representación de la \     curva" r[u],Darker@Blue],*)Style["Curvatura ", curvatura[s]],       Style["Torsión ", torsion[s]],      Style["Vertor Rojo.- Representa el vector Tangente", Darker@Red],       Style["Vector Cyan.- Representa el vector Normal", Darker@Cyan],       Style["Vector Verde.- Representa el vector Binormal", Darker@Green],       ControlPlacement -> Left, SaveDefinitions -> True]      * * *


title: plotting an equation with double summations

text: Thank you so much for the helpful comments. Now able to manage to plot all the functions.               Remove[q, qC, IIC]          ass = {d > 1, num > 0, \[CapitalDelta] > 0, t > 0, n >= 0};          q[\[Nu]_, num_, \[CapitalDelta]_, t_] :=       1/num (1 +          2 Exp[-\[Nu]] NSum[           Sin[(\[Pi] d)/num]/((\[Pi] d)/num) Exp[-d \[CapitalDelta]^2]             Cos[(\[Pi] d)/num (2 t + 1)] \[Nu]^(n + d/2)/Sqrt[            n! (n + d)!], {d, 1, 10}, {n, 0, 10}])          AbsoluteTiming[Table[q[2, 4, 0.2, t], {t, 0, 200, 20}]]          Plot[q[2.0, 4.0, 0.2, t], {t, 0, 200}]          qC[\[Nu]_, num_, \[CapitalDelta]_, t_] :=        1/num (1 +           2 Exp[-\[Nu]] Sum[            Sin[(\[Pi] d)/num]/((\[Pi] d)/num) Exp[-d \[CapitalDelta]^2]              Cos[(\[Pi] d)/num (2 t + 1)] \[Nu]^(n + d/2)/Sqrt[             n! (n + d)!], {d, 1, 20}, {n, 0, 20}]);          AbsoluteTiming[Table[qC[2., 4., 0.2, t], {t, 0, 200, 10}]]          ListPlot[Table[{t, qC[2, 4, 0.2, t]}, {t, 0, 200}]]          IIC[\[Nu]_, num_, \[CapitalDelta]_] :=       Log[2, num] - Sum[(q[[Nu], num, [CapitalDelta], t]) Log[2, q[[Nu], num, [CapitalDelta], t]], {t, 0, num - 1}]; AbsoluteTiming[Table[IIC[[Nu], 4, 0.2], {[Nu], 1, 200, 20}]] ListPlot[Table[{[Nu], IIC[[Nu], 4, 0.2]}, {[Nu], 1, 50}], PlotRange -> All, AxesOrigin -> {0, 0}]


title: Problem with | operator in pattern matching

text: My first question here as I only got into _Mathematica_ programming recently. Basically I have a large symbolic algebraic expression where I know certain variables with head pε appear with degree 2 in each term. So the terms look like this:               (...) pε[i, j] pε[k, l] + (...) pε[m ,n] pε[p, q] + ...      I want to pick out which of these appear in my expression, and I figured out this would do the trick               (Reap[expr /. patt : (x_pe y_pe | _pe _pe) :> Sow[patt] ;][[2,1]]) // DeleteDuplicates      which gives: > {pe[4, 6]^2, pe[3, 6]^2, pe[2, 6]^2, pe[5, 6]^2, pe[3, 6] pe[4, 6], pe[3, 6] > pe[5, 6], pe[4, 6] pe[5, 6]} This however is missing terms because, when I ran two sets of pattern matches without `|`, I get more terms               (Reap[expr /. patt : x_pe y_pe :> Sow[patt] ;      expr /. patt : _pe _pe :> Sow[patt] ;][[2,1]]) // DeleteDuplicates      > {pe[3, 6] pe[4, 6], pe[2, 6] pe[4, 6], pe[2, 6] pe[3, 6], pe[3, 6] pe[5, 6], > pe[4, 6] pe[5, 6], pe[2, 6] pe[5, 6], pe[4, 6]^2, pe[3, 6]^2, pe[2, 6]^2, > pe[5, 6]^2} So I would like to know what's going on. In particular I imagine the first would be a lot more efficient if it worked properly. Also feel free to give alternative ways of doing this. My choice of using `Reap, Sow` was one of efficiency but my of knowledge of the language is still small. ### Edit Based on the example given by @Federico I have constructed a small analogue where the difficulties are manifest, I use `Cases` because it's conceptually clearer               sum = Sum[pe[i, j] l[i, j] pe[j, k], {i, 3}, {j, 3}, {k, 3}]      whose output is: > l[1, 1] pe[1, 1]^2 + l[1, 1] pe[1, 1] pe[1, 2] + l[1, 1] pe[1, 1] pe[1, 3] + > l[2, 1] pe[1, 1] pe[2, 1] + l[1, 2] pe[1, 2] pe[2, 1] + l[2, 1] pe[1, 2] > pe[2, 1] + l[2, 1] pe[1, 3] pe[2, 1] + l[1, 2] pe[1, 2] pe[2, 2] + l[2, 2] > pe[2, 1] pe[2, 2] + l[2, 2] pe[2, 2]^2 + l[1, 2] pe[1, 2] pe[2, 3] + l[2, 2] > pe[2, 2] pe[2, 3] + l[3, 1] pe[1, 1] pe[3, 1] + l[3, 1] pe[1, 2] pe[3, 1] + > l[1, 3] pe[1, 3] pe[3, 1] + l[3, 1] pe[1, 3] pe[3, 1] + l[2, 3] pe[2, 3] > pe[3, 1] + l[1, 3] pe[1, 3] pe[3, 2] + l[3, 2] pe[2, 1] pe[3, 2] + l[3, 2] > pe[2, 2] pe[3, 2] + l[2, 3] pe[2, 3] pe[3, 2] + l[3, 2] pe[2, 3] pe[3, 2] + > l[1, 3] pe[1, 3] pe[3, 3] + l[2, 3] pe[2, 3] pe[3, 3] + l[3, 3] pe[3, 1] > pe[3, 3] + l[3, 3] pe[3, 2] pe[3, 3] + l[3, 3] pe[3, 3]^2 So there are two types of terms those that contain `pe` squared and those that don't. Those that do are captured by               Cases[sum, _pe^2, Infinity]      those that don't require               Cases[sum, _ x_pe y_pe -> x y, Infinity]      So the question now is why does the following also work for the case with no `pe` squared?               (Reap[sum /. patt : (x_pe y_pe) :> Sow[patt]; ][[2,1]])      And a followup question, how would one capture the squared terms if _Mathematica_ didn't collect them in a square? For example, if I had `pe[1, 1]l[1, 1] pe[1, 1]` can I construct a pattern to capture this? Or will it never happen due to `Times` having the `Orderless` attribute? I am thinking of a situation where `l[1,1]` is very large and _Mathematica_ doeesn't order it. Another question is can I combine both pattern matching cases in one with the use of `|`, and, if so, would that be more efficient?


title: Rasterized image together with vector-graphics axes

text: Following some of the questions here on _Mathematica_ Stack Exchange, I am trying to export an image that contains a rasterized object and vector- graphics axes. Here is an example:               myArray = Table[{x, y, RandomReal[]}, {x, 0, 100}, {y, 0, 100}];          size = 500;          myImage =       ListDensityPlot[Flatten[myArray, 1], Mesh -> 20,        ColorFunction -> "AvocadoColors", PerformanceGoal -> "Quality",        FrameLabel -> {"\[Mu]", "C"}, FrameStyle -> Directive[14],        ImageSize -> size];          img = Rasterize[Show[myImage, Frame -> None], ImageResolution -> 100,         ImageSize -> size];          g = Graphics[       Inset[img, Scaled[{0.5, 0.5}], {Center, Center}, size],        AbsoluteOptions[myImage]]      Here is the result:: ![enter image description here](http://i.stack.imgur.com/rV92A.png) You can notice, if you compare with the original image, that the scaling of the inserted object is not correct. Now two my questions:   1. How to figure out the size of the object that I insert automatically. Here, if I replace `size` with `0.21 size` I will get a correct image. Why is 0.21?   2. Why the size of ticks and numbering does not coincide with the original image and how to fix it?


title: Using triangulation

text: I have been presented with 3 known points and the power densities at those points. I need to use those points to find the location of the actual antenna which is generating the signals. Power Density is calculated through $PD=(power by antenna)/4*Pi*R^2$ and the inverse law also applies, $PD=\frac{1}{R^2}$, where R is the distance between a known point and the antenna. What is the best method of apporaching this problem using the Mathematica enviroment? Till now I havent been able to tackle this problem mathematically aswell, as I don't know how it would be done. I did however come across something, which said plotting circles will be the best, and their intersections will give the coordinates? how will this work? This is the module where I have to write the code:               Triangulate[measure_] := Module[(* Enter your code here*)]       `measure_` contains 3 lists, e.g you would input               Triangulate[{{2000,0,1/2},{0,1000,1},{0,0,1/2}}]      where first two elements are the x and y coordinates, and the last element is the power density at those points. Any help to get me started will be appreciated, cause at the moment i dont know how to start or tackle this.


title: Force multiplication by a single factor

text: I have an expression that Mathematica decides to return in the general form:               y =  f ( a/f + b/Sqrt[f + 2] + c*f^2/Sqrt[f + 2])      (actually my expression is much longer and the coefficients `a`, `b`, `c` are more complicated). Ultimately I want to set `f` to zero, however if I do it using `y /. f -> 0` Mathematica returns `Indeterminate`. Obviously from the form of the equation this is incorrect, since `y` is well defined in this case. Use of functions such as `Limit`, `Expand` etc are basically out the questions since I'd like to keep the coefficients `a`, `b`, `c` as they are (and they are too complicated to think of inputing them into a `Hold` function. Is there a way that I can force Mathematica to simply multiply through by `f`, so that I can use `Replace`? Thanks a lot in advance for your help.


title: Integration with vector coefficients

text: I asked this same question in Mathematics, and it was suggested I might try here. I'm more comfortable with Maple, but if I can get Mathematica to do what I'm after, so much the better. Basically I'm trying to symbolically integrate something like this: $\displaystyle\int \frac{a\mu-b}{||a\mu-b||^3} \mathrm{d}\mu$ where $a,b$ are vectors and $\mu$ is a scalar. The denominator is the cube of the 2-norm of the vector, and can be found by taking the dot product of a vector with itself, and raising it to the power of $\frac{3}{2}$. Right now in Maple I'm explicitly multiplying out the denominator and making substitutions so that the denominator, at least, is only in terms of scalars ($a \cdot a = C$, etc. ), but I hate doing it this way, because it adds a lot of bookkeeping. Basically I'd like the computer to understand that $a * (b \cdot a)$ is not the same thing as $b * a^2$, but that $a \cdot b * c \cdot d = c \cdot d * a \cdot b$. What's the most kosher way to do this integration in Mathematica? **UPDATE** This is the full integral I'm trying to do. I'm not sure it even has an answer, but the first integral is similar to what I have above. So I was hoping I could take any techniques that work on the simpler one above and apply them to the full problem below. Let: $\vec{f} = (a - c) \mu_1 + (b - c) \upsilon_1 - (x - z) \mu_2 - (y-z) \upsilon_2 - (z - c) $ where $a, b, c, x, y, z$ are vectors representing positions, and $\mu_1, \nu_1, \mu_2, \nu_2$ are scalars. I want to find: $\vec{F_G} = \displaystyle\int_0^1 \int_0^{1-v_2} \int_0^{1} \int_0^{1-v_1} \! \frac{f}{||{f}||^3} \, \mathrm{d} \mu_1 \mathrm{d} \upsilon_1 \mathrm{d} \mu_2 \mathrm{d} \upsilon_2 $


title: Symbolically associate vectors and their norms

text: I am wondering how to handle the following situation: I do have vectors of known dimension that I would like to handle symbolically. I suppose I can do something like               avec = Array[a,2];     bvec = Array[b,2];      Now in my equations there are also scalars that represent the norms of these vectors, i.e. `A == Norm[avec]` So suppose I write an expression like               expr = A avec.(avec + bvec)      What I would like Mathematica to do is:   1. Whenever `avec.avec` is encountered, replace this by A^2   2. Whenever `avec.bvec` is encountered, leave this symbolic, don't expand into the elements of the vectors. How can I achieve this?


title: Baffling increase in runtime

text: **Background of my question** I discovered Project Euler today, and decided I would work through the problems in Mathematica. I became obsessed with the first problem, which is essentially _"sum all the numbers from 0 to n that are multiples of 3 or 5"_. I came up with several interesting solutions, and decided I would compare their runtimes to see if there is a way to optimize this calculation. While amusing myself with `ListPlot`'s of runtimes, I noticed some very interesting behavior in my solution that uses `Fold`:               FoldSum[m_, n_] :=       Fold[If[Mod[#2, 3] == 0 || Mod[#2, 5] == 0, #1 + #2, #1] &, 0, Range[m, n]]     FoldSum[n_] := FoldSum[0, n]      I came up with this plotting function in order to visualize the runtimes of the summing functions as _n_ increased. (In order to maintain fairness amongst trials, I called `ClearSystemCache[]` just to ensure caching benefits are not messing with the independence of trials).               PlotSum[f_, a_, b_, step_] :=       ListPlot[{#, (ClearSystemCache[]; First[AbsoluteTiming[f[#]]])} & /@         Range[a, b, step], AxesOrigin -> {a, 0}]     PlotSum[f_, b_, step_] := PlotSum[f, 0, b, step]      It was quite interesting to generate graphs comparing the different summing functions I came up with (I listed them below in a separate section). For example, I would plot FoldSum's runtime from n = 0 to n = 999 in steps of 10 by executing `PlotSum[FoldSum, 999, 10]` **The question** My question pertains to the plot of FoldSum - I noticed that around n = 96000, the runtime of FoldSum suddenly jumps by a factor of around 15. I used the plotting function to generate smaller and smaller ranges until I finally found this:               In[1] = FoldSum[95934] // AbsoluteTiming     Out[1] = {0.020469, 2147472998}          In[2] = FoldSum[95935] // AbsoluteTiming     Out[2] = {0.303367, 2147568933}      ![the specific plot](http://i.stack.imgur.com/muid9.png) My question is, what is so special about numbers greater than 95934 (i.e. why does the runtime suddenly jump by a factor of around 15)? Is it just my computer that does this, or is this reproducible? **Some other fun stuff** In case you actually threw this into Mathematica to reproduce these results, you might enjoy these other solutions:               ListSum[m_, n_] :=       Total[Select[Range[m, n], Mod[#, 3] == 0 || Mod[#, 5] == 0 &]]          TransposeSum[m_, n_] :=       Total[First /@         Select[Transpose[{Range[m, n], Mod[Range[m, n], 3],            Mod[Range[m, n], 5]}], #[[2]] == 0 || #[[3]] == 0 &]]          ConcurrentSum[m_, n_] :=       ParallelSum[If[Mod[i, 3] == 0 || Mod[i, 5] == 0, i, 0], {i, m, n}]          ParallelListSum[m_, n_] :=       Total[Level[        ParallelCombine[ListSum[First[#], Last[#]] &, Range[m, n]], 1]]          ParallelizeSum[f_, m_, n_] :=       Total[Level[ParallelCombine[f[First[#], Last[#]] &, Range[m, n]],         1]]     ParallelizeSum[f_, n_] := ParallelizeSum[f, 0, n]     (* ParallelizeSum[FoldSum, 999] *)      also, to graph a comparison plot between different solutions,               PlotCompare[fList_, m_, n_, step_] :=       ListPlot[PlotSumData[#, m, n, step] & /@ fList]     PlotSumData[f_, m_, n_,        step_] := {#, First[AbsoluteTiming[(ClearSystemCache[]; f[#])]]} & /@        Range[m, n, step]


title: Plotting Zeros of a Complex Variable

text: I'm trying to plot the zeros within a certain distance from the origin using Mathematica of a given function (in my case, partial sums of the Zeta Function). I've tried plugging in simple functions, such as 1+2^(-s), but the program keeps throwing an error (it won't even show a plot). I am a beginner with Mathematica; will someone explain how to perform the task at hand or point me to some examples? I've found a few references, but they all seemed centered around learning the programming language as a whole. If possible, I want to avoid this for now and put it off until the summer when I'll have more time to sit down and play with it.


title: Aligning plot axes in a graphics object

text: I need to align the y-axes in the plots below. I think I'm going to have to do some rasterizing and searching for vertical lines, then vary `x` and `w`. Is there a better way?               a = ListPlot[{{0, 0}, {16, 20}},        PlotRange -> {{0, 16}, {0, 20}}, Frame -> True];     b = ListPlot[{{0, 0}, {160000, 200000}},         PlotRange -> {{0, 160000}, {0, 200000}}, Frame -> True];     x = 3.1; w = 5;     Graphics[{LightYellow, Rectangle[{0, 0}, {7, 8}],        Inset[a, {x, 5.5}, Center, {w, Automatic}],        Inset[b, {3.1, 2.2}, Center, {5, Automatic}]},       PlotRange -> {{0, 7}, {0, 8}}, ImageSize -> 300]      ![enter image description here](http://i.stack.imgur.com/KdCcn.png)


title: Weather Maps with Mathematica

text: I've been trying to set up a weather map with Mathematica similar to what NOAA publishes in their website. ![enter image description here](http://i.stack.imgur.com/rNAVN.png) So far I've been successful to bring the data over and extend it across the whole picture frame.                          weatherMap[region_, property_] :=               Module[{polygon, coord, minX, maxX, minY, maxY, data, deltaX, deltaY},                    polygon = CountryData[region, "Polygon"];               coord = Cases[CountryData[region, "Coordinates"], {_, _}, Infinity];               minX = Floor@Min[coord[[All, 2]]];               maxX = Ceiling@Max[coord[[All, 2]]];               minY = Floor@Min[coord[[All, 1]]];               maxY = Ceiling@Max[coord[[All, 1]]];               deltaX = (maxX - minX)/25;               deltaY = (maxY - minY)/25;               data = DeleteCases[                 Flatten[Table[{x, y, WeatherData[{y, x}, property]}, {x, minX,                     maxX, deltaX}, {y, minY, maxY, deltaY}], 1], {x_,                   y_, _Missing}];               Show[Graphics[{Opacity[0], polygon}],                 ListContourPlot[data, Contours -> 10,                  ColorFunction -> "Temperature", InterpolationOrder -> 3,                  PlotLegends -> Placed[Automatic, Above],                  PerformanceGoal -> "Quality"],                 Graphics[{EdgeForm[Black], FaceForm[Opacity[0.01], GrayLevel[.1]],                   polygon}]]]        weatherMap["USA", "Temperature"]      ![enter image description here](http://i.stack.imgur.com/fXpwA.png) What would be the best way to limit the contour temperature graphic to within the frame of the given polygon?


title: equidistant solutions in Sequence Sums That Are Squares

text: In my demonstration "Sequence Sums That Are Squares" I demonstrate two "lines" of solutions (of infinite length) and ask whether someone can find one more line. I am looking forward to your solution. I did not find a third line of solutions.


title: Applying non-Affine transforms to 2D polygons with textures

text: I am trying to create a vanishing point perspective transformation of 2D polygons, for example transforming the red polygon into the blue polygon:               p1 = Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}];     p2 = Polygon[{{0, 0}, {1, 0}, {0.55, 0.5}, {0.45, 0.5}}];     Graphics[{FaceForm[None], EdgeForm[Red], p1, EdgeForm[Blue], p2}]      ![Mathematica graphics](http://i.stack.imgur.com/qIZA5.png) I can find the transformation easily enough with `{err, tr} = FindGeometricTransform[First@p2, First@p1]`; however, since the transformation is not an affine mapping, it cannot be handled by `GeometricTransformation`. Instead, I need to transform the points that make up the polygon:               Graphics[{FaceForm[None], EdgeForm[Red], p1, EdgeForm[Blue], Polygon@tr@First@p1}]      All seems well. If I try to apply a texture to the transformed polygon, things get ugly:               vop = VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}};     Graphics[{Texture[ExampleData[{"Texture", "Bricks3"}]], EdgeForm[Red],       Polygon[tr@First@p1, vop]}]      ![Mathematica graphics](http://i.stack.imgur.com/rX3YQ.png) It appears that the internals of `Texture` can't handle the non-affine mapping very well, despite being able to handle affine transforms:               str = ShearingTransform[30 Degree, {1, 0}, {0, 1}]     Graphics[{Texture[ExampleData[{"Texture", "Bricks3"}]], EdgeForm[Red],        Polygon[str@First@p1, vop]}]      ![Mathematica graphics](http://i.stack.imgur.com/ScqlZ.png) A rather clunky way around this problem is to use `ImagePerspectiveTransformation`, which was mentioned previously as having the ability to map any type of transform (affine or not).               ipt = ImagePerspectiveTransformation[       ExampleData[{"Texture", "Bricks3"}], tr, Padding -> None]     Show[ipt,       Graphics[{FaceForm[None], EdgeForm[{Thick, Red}],         Polygon[First@ImageDimensions[ipt]*p2[[1]]]}], ImageSize -> 400]      ![Mathematica graphics](http://i.stack.imgur.com/iiXd4.png) This problem (I think) boils down to performing a non-affine transform to a texture, so I am wondering **how (or if) this might be done efficiently than to perform the ImagePerspectiveTransformation on the texture image first**?


title: NDSolve gives wrong results for "stiff system"

text: I have a physical problem in which I want to solve for `c[e]` as a function of `e`, where `c` is expected to be in the range from 0 to 1. I have a ODE to solve, which is `c'[e] == f[c[e], e]`, and `f[c[e], e]` is given by               (2.*10^-6 (-0.706288 - 3.24379*10^-9 e +           c[e] (0.767155 +              6.48758*10^-9 e + (-0.27 - 2.2833*10^-9 e) c[               e])))/((1.42066 - 1. c[e])^2 ((          e (-6.4542*10^-7 +              e (2.72905*10^-15 - 1.65436*10^-30 c[e])))/(-1.42066 +             1. c[e])^3 + (          1.11743*10^-30 e^2 (6.18655*10^8 + 1.42066 e +              c[e] (-6.71971*10^8 -                 2.84132 e + (2.365*10^8 + 1. e) c[e]))^2)/(1.42066 -             1. c[e])^4 + (1. + (1/((1.42066 - 1. c[e])^2))            e (0.000010341 + 2.37466*10^-14 e +                c[e] (-0.0000112321 -                   4.74932*10^-14 e + (3.95315*10^-6 + 1.67152*10^-14 e) c[                    e])))^2))      I use `NDSolve`,               g = NDSolve[{c'[e] == f[c[e], e], c[0] == 0}, c, {e, -150000, 0}]      but get a message > *NDSolve::ndsz: "At e == -120259., step size is effectively zero; > singularity or stiff system suspected." The result is an interpolating function. For `e` > -120258, the result is good. For example               Plot[Evaluate[c[e] /. g], {e, -120258, 0}]      gives ![enter image description here](http://i.stack.imgur.com/PsSYO.png) But if `e` = -120259, `c` instantly becomes order 10^15, which I know must be wrong. I also plot `f[c, e]` (as a surface, for all possible `c` and `e`) and `f[c[e], e]` (as a single curve) in 3D plot.               Show[       ParametricPlot3D[{c, e, f[c, e]}, {c, 0, 1}, {e, -150000, 0},          PlotRange -> {{0, 1}, {-150000, 0}, {-0.001, 0.001}}],        ParametricPlot3D[{c[e] /. g[[1]], e, f[c[e] /. g[[1]], e]}, {e, -120259, 0},          PlotStyle -> Red,          PlotRange -> {{0, 1}, {-150000, 0}, {-0.002, 0.002}}],        BoxRatios -> {1, 1, 1}]      gives ![enter image description here](http://i.stack.imgur.com/qJbKC.png) I see the surface is mostly smooth, but at a strip region the derivative values are quite unstable as in a "stiff system". When the solution curve enters that region it goes wrong. In this case, how can I get the correct result? Update: as suggested by @Nasser, source codes are provided below               s11t = 7.4*10^(-12);     s33t = 13.1*10^(-12);     s12t = -1.4*10^(-12);     s13t = -4.4*10^(-12);     s44t = 16.4*10^(-12);     s66t = 7.6*10^(-12);     k11t = 4400*8.85*10^(-12);     k33t = 129*8.85*10^(-12);     d15t = 564*10^(-12);     d31t = -33.4*10^(-12);     d33t = 90*10^(-12);     M0 = {        {s11t, s12t, s13t, 0, 0, 0, 0, 0, d31t},        {s12t, s11t, s13t, 0, 0, 0, 0, 0, d31t},        {s13t, s13t, s33t, 0, 0, 0, 0, 0, d33t},        {0, 0, 0, s44t, 0, 0, 0, d15t, 0},        {0, 0, 0, 0, s44t, 0, d15t, 0, 0},        {0, 0, 0, 0, 0, s66t, 0, 0, 0},        {0, 0, 0, 0, d15t, 0, k11t, 0, 0},        {0, 0, 0, d15t, 0, 0, 0, k11t, 0},        {d31t, d31t, d33t, 0, 0, 0, 0, 0, k33t}        };     M1 = {        {s11t, s12t, s13t, 0, 0, 0, 0, 0, -d31t},        {s12t, s11t, s13t, 0, 0, 0, 0, 0, -d31t},        {s13t, s13t, s33t, 0, 0, 0, 0, 0, -d33t},        {0, 0, 0, s44t, 0, 0, 0, -d15t, 0},        {0, 0, 0, 0, s44t, 0, -d15t, 0, 0},        {0, 0, 0, 0, 0, s66t, 0, 0, 0},        {0, 0, 0, 0, -d15t, 0, k11t, 0, 0},        {0, 0, 0, -d15t, 0, 0, 0, k11t, 0},        {-d31t, -d31t, -d33t, 0, 0, 0, 0, 0, k33t}        };     I0 = IdentityMatrix[9];     L0 = Inverse[M0];     L1 = Inverse[M1];     s1111 = 1;     s1122 = L0[[1, 2]]/L0[[1, 1]];     s1133 = L0[[1, 3]]/L0[[1, 1]];     s1212 = 1/2;     s1313 = 1/2;     s1341 = -1/2*L0[[7, 5]]/(L0[[4, 4]]*M0[[7, 7]] + (L0[[7, 5]])^2);     s4242 = 1;     s4343 = 1;     S = {        {s1111, s1122, s1133, 0, 0, 0, 0, 0, 0},        {0, 0, 0, 0, 0, 0, 0, 0, 0},        {0, 0, 0, 0, 0, 0, 0, 0, 0},        {0, 0, 0, 0, 0, 0, 0, 0, 0},        {0, 0, 0, 0, 2 s1313, 0, 2 s1341, 0, 0},        {0, 0, 0, 0, 0, 2 s1212, 0, 0, 0},        {0, 0, 0, 0, 0, 0, 0, 0, 0},        {0, 0, 0, 0, 0, 0, 0, s4242, 0},        {0, 0, 0, 0, 0, 0, 0, 0, s4343}        };     B1 = Inverse[I0 + L0.(I0 - S).(M1 - M0)];     Q[c_] := Inverse[c*B1 + (1 - c)*I0];     A[c_] := (M1 - M0).B1.Q[c];     Bp1[c_] := I0 - (1 - c)*(M1 - M0).B1.Q[c].L0.(I0 - S)     Bp2[c_] := B1.Q[c];     Bp3[c_] := Transpose[Bp2[c]];     B[c_] := Bp1[c] + Bp3[c];     C2[c_] := -(1 - c)*B1.Q[c].L0.(I0 - S);     X[e_] := {0, 0, 0, 0, 0, 0, 0, 0, e};     Yds = {0, 0, 0, 0, 0, 0, 0, 0, -0.54};     Bf2[c_] := B1.Q[c].(B1 - I0).Q[c];     Bf3[c_] := Transpose[Bf2[c]];     Af[c_] := A[c] - c*(M1 - M0).B1.Q[c].(B1 - I0).Q[c];     Bf[c_] := B[c] + c*(-Bf3[c] + (M1 - M0).B1.Q[c].(I0 + (1 - c)*(B1 - I0).Q[c]).L0.(I0 - S));     Cf[c_] := C2[c] + c*(B1.Q[c].(I0 + (1 - c)*(B1 - I0).Q[c])).L0.(I0 - S);     fdriv[c_, e_] := 1/2 (X[e].Af[c].X[e] + X[e].Bf[c].Yds + Yds.Cf[c].Yds);     n = 2.0*10^(-6);     r1 = 6.83*10^4;     r2 = 1.08*10^6;     delpc[c_, e_] := D[fdriv[x, y], x] /. {x -> c, y -> e};     delpE[c_, e_] := D[fdriv[x, y], y] /. {x -> c, y -> e};     f[c_, e_] := FullSimplify[n*delpE[c, e]/((1 - fdriv[c, e]/r1)^2 + (fdriv[c, e]/r2)^2-n*delpc[c, e])];     g = NDSolve[{c'[e] == f[c[e], e], c[0] == 0}, c, {e, -150000, 0}]


title: Why Mathematica can't solve this? NSolve or Solve

text: _**I want solution of x and y which should be positive real numbers_**               Solve[2*(1 - a)*((x)^-n) + 2*a*((y)^-n) - 1 ==         0 && (1 - a)*((x)^(1 - n)) + a*((y)^(1 - n)) - 1 == 0 , {x, y}]      > During evaluation of In[2]:= Solve::ifun: Inverse functions are being used > by Solve, so some solutions may not be found; use Reduce for complete > solution information. >> > > During evaluation of In[2]:= Solve::svars: Equations may not give solutions > for all "solve" variables. >> > > Out[2]= {{y -> 2^(1/n) ((a x^n)/(-2 + 2 a + x^n))^(1/n)}} * ** _Supppose now I plug in certain numeric values n=0.3 a=0.6, it still can't solve it ._**               NSolve[2*(1 - 0.6)*((x)^-0.3) + 2*0.6*((y)^-0.3) - 1 ==         0 && (1 - 0.6)*((x)^(1 - 0.3)) + 0.6*((y)^(1 - 0.3)) - 1 == 0, {x,        y}, Reals]      > NSolve::ratnz: NSolve was unable to solve the system with inexact > coefficients. The answer was obtained by solving a corresponding exact > system and numericizing the result. >>


title: Data is imported as string instead of numbers

text: newdata = Import["data.txt", "TSV"];     ListPlot[newdata]      My `data.txt` file consists of two columns of numbers, separated by commas, like this:               1,4     2,5     3,5      and so on. When I look at how my `newdata` output seems to be fine (list of datapoints).               (* in  *) newdata     (* out *) {{1, 4}, {2, 5}, {3, 5}}      But, when I try the `ListPlot` command, I get just a blank graph at the origin with x and y's that range from 1. Can somebody help me with this type of graphing? Thanks in advance.


title: Strategies for simplifying complicated expressions

text: I have a very complicated expression involving trigonometric functions, complex numbers etc. You may find it here as it is too long to be pasted here. You may also find a screenshot of it here. **Assumptions:** All variables are real and strictly positive. This expression should be real! I'm dealing with this expression for days. Could someone tell me a strategy for simplifying it within Mathematica 8 ? More generaly, are there good tutorials or textbooks or lessons on strategies for simplifications? Perhaps is simplification a subjective concept? In my case it means more readable, and why not something that could fit in a research paper.


title: How to edit the text coming together with the numeration of pages in pdf produced out of a notebook?

text: I am writing a text that I am going to publish on-line. When I transform it from the notebook into the pdf format I get the numeration style typical for Mathematica: ![Mathematica graphics](http://i.stack.imgur.com/2WHPE.png) I would like to edit the text following the page numeration. For example, instead of "2|Supporting Materials 3.nb" I would like to leave either simple "2" or "2|Supporting materials". My question is: is it possible to edit this?


title: Evaluate Notebook from .Net

text: How is it possible to send the whole content of an existing notebook to _Mathematica_ for evaluation by using NetLink/C#?


title: Laplacian in D Dimensions

text: Is it possible to compute $\Delta F=\nabla^2 F$ for $F=F(x^1,x^2,…,x^D)$ with $D$ finite? I seem to be only able to specify spherical coorindates, for example, if I want to leave standard Cartesian coordinates. The function I'm actually using looks like this $F(x^1,x^2,…,x^D)=f^1(x^1)\times f^2(x^2) \times … \times f^D(x^D)$ (separation of variables). Is there a way mathematica can do this?


title: How to remove the 1. when differentiating 0.5x^2

text: My question is very basic, When using the Differentiate functionality of Mathematica in this way:               D[0.5 x^2, x]      This results in:               1.x      I don't need the 1. but how can I tell mathematica to remove this? It works further along in my code and gives me results like:               {{1. m, 0, 0}, {0, 1. m, 0}, {0, 0, 1. Jcm}}      Any ideas?


title: How do I get rid of the overlap of gridlines and tick mark labels?

text: I wish to include the plot generated by the following Mathematica code               Plot[1/Root[-3 - 8 #1 Tan[a/2] - 3 Tan[a/2]^2                    + #1^4 (1 + Tan[a/2]^2) + #1^2 (-9 + 3 Tan[a/2]^2) &, 2],       {a, 0, 2 Pi},       AxesOrigin -> {0, 0},        Ticks -> {{0, Pi/6, Pi/3, Pi/2, 2 Pi/3, 5 Pi/6, Pi, 7 Pi/6, 4 Pi/3,          3 Pi/2, 5 Pi/3, 11 Pi/6, 2 Pi}, {0, 0.125, 0.25, 0.375, 0.5,          0.625, 0.75, 0.875, 1, 1.125, 1.25, 1.375, 1.5}},        GridLines -> {{Pi/6, Pi/3, Pi/2, 2 Pi/3, 5 Pi/6, Pi, 7 Pi/6, 4 Pi/3,          3 Pi/2, 5 Pi/3, 11 Pi/6, 2 Pi}, {0, 1/8, 2/8, 3/8, 4/8, 5/8, 6/8,          7/8, 1, 9/8, 10/8, 11/8, 12/8}},        GridLinesStyle -> Directive[Dashed]]      > ![Mathematica graphics](http://i.stack.imgur.com/heVOV.png) in an article I'm writing. I don't like how the GridLines overlap the axis labels however. I searched around a bit for a solution but I'm no Mathematica expert and I can't work it out. Does anyone have a solution?


title: Methods for NonlinearModelFit

text: I am using `NonlinearModelFit` for a thesis project. I get quite different results if I change the Method to LevenbergMarquardt or QuasiNewton or ConjugateGradient and so on. My nonlinear model includes polynomials up to second order and a sigmoid function such as `ArcTan` or `Tanh`. I would like to know, which conditions Mathematica uses to choose the best algorithm if I set the `Method` as `Automatic`. It works sometimes, but most of the time it doesn't and I do not have the knowledge to say which method should be the best in my case. Just by trying out, I found `Gradient` and sometimes `ConjugateGradient` to work the best for my purpose. I also cannot find anywhere on the Internet which exact implementation of these methods is used inside Mathematica and how does it change the results. Here maybe an interesting link: Optimization Algorithms Thanks!


title: Efficiently finding the positions of a large list of targets in another, even larger list

text: I have a big list. It contains nearly 60,000 sub-lists. It's structured like               bigList = {{x1,y1,z1},{x2,y2,z2},{x3,y3,z3},.....,{x60000,y60000,z60000}};      I have picked 1200 elements from the `bigList` at random.               smallList = {{x1,y1,z1},{x2,y2,z2},......,{x1200,y1200,z1200}};      I want to find the positions of the `smallList` elements in the `bigList`. To that end I wrote the following code.               Flatten[Map[Position[bigList, #]&, smallList]]      It's working fine, but it takes **30 seconds** to evaluate.               Timing[Flatten[Map[Position[bigList, #]&, smallList]]]      How can I reduce that evaluation time?


title: What happened with the file?

text: What happened with this file?               infile = "\\test data.txt";            outstr = OpenWrite[infile];     instr = OpenRead[infile];     Read[instr, Record];     Close[instr];        All content of "test data.txt" was lost.


title: Can anyone explain this strange behavior of InputForm?

text: In Mathematica 9.0.0, when to display the input form of two numbers, I come across maybe a puny problem. In order to focus on the problem, I will put up a simplified version.               In[1]:=InputForm[E]            InputForm[Pi]      and the output is               Out[2]//InputForm=         Pi      The input form of `E` is eaten by the `Pi` one. Why would this happen? And if I add a semicolon to the later one, the input form of `E` will show up. And what's more, if I enter `InputForm` and `StandardForm` consecutively like this               In[7]:=InputForm[E]            StandardForm[Pi]      I get               Out[8]//StandardForm=         \[Pi]                E      the `E` being placed in a separate cell without the `InputForm` label. IMO, the output is made in the wrong sequence. So my question is, what does `InputForm` really do? Why does it "eat" the previous output?


title: Copy big or small values to LaTeX

text: When I create a DistributionFitTest of a distribution i receive very low P values. Eg. $2.456750213008007 \times 10^{-367}$. When I copy this (by right clicking and copy to LaTeX), and insert it in my LaTeX document, I receive the number as               \text{2.4567502130080068515188263453399491266$\grave{ }$15.778498511135323*${}^{\wedge}$-367}      Where I would prefer to receive a rounded value such as:               \text{2.457} \times 10^{-367}      Or at least receive an output equivalent, so that I don't have round up manually or edit "*" to "\times", or add up "10".


title: How can I impose a condition on Solve or FullSimplify?

text: I would like to define a real 3-D vector as, say, `v = {x, y, z}`, but I want it to have a fixed norm and not necessarily a unit norm. I would like to impose this condition on the vector `v` before I start using `v` in a calculation. In particular, I want _Mathematica_ to insert `x^2 + y^2 + z^2 = constant` during a calculation using `Solve` or `FullSimplify`. I have used `/. x^2 + y^2 + z^2 -> constant`, but this simply evaluates the result for the given constant. Is there way to impose my condition before/during the calculation.


title: Determining if a point is inside or outside a 3DS (.3ds) or 3DS MAX (.max) object?

text: Imagine I import some 3DS (i.e. 3D studio) file (http://reference.wolfram.com/mathematica/ref/format/3DS.html) or a 3DS MAX file. How could I place this model (say, the 747.3ds file in the Mathematica manual) in a scaled cloud of 3D points, then generate a list of points that are internal or external to this object? I would also settle for points being within a threshold distance of some feature in the mesh defining the object? As per Yves Klett's request (and hat tip to him for how to pull out a polygon list with triangle subcomponents) - what is the most efficient way to determine the set of points inside a list of polygons? I could perform a ray/triangle intersection test, for example, but is there some faster way using built-in routines in Mathematica 9? Is there something like InsidePolygonQ, perhaps using Delaunay triangulation? It looks like 3DS file polygons are convex (is this always true?), so that should simplify things. Running the import command:               Import["...\\test.3ds", "PolygonObjects"]      Yields a list of convex polygons of the form:               {Polygon[{{1.67293, 8.08139, 100.633}, {1.67267, 8.15993, 100.652}, {-0.0264846, 8.07622, 100.631}}], <<13099>>}      I would be very happy to have a function that would like me input one of these polyhedra and a test point, and determine if that test point is inside out outside the polyhedra.


title: User defined output forms

text: I have a mathematica program which performs some manipulation which I then want to continue in another language, as I already have some code written in it. Syntactically this language is very similar to `InputForm` and so I wanted to try and build my own output form based upon `InputForm` which would transform an expression into something understandable in this other language. The type of transformations would be things like swapping square brackets with parentheses, and renaming of functions. That is, a mapping like:               Den[x]*Den[y]+Den[x]*Den[z]  --> D(x)*D(y) + D(x)*D(z)      My naive attempts at doing something like this were to try and copy `InputForm` into `MyForm` and then try and apply various calls to Format, that is something like (just using the renaming in this example):               MyForm = InputForm;     Format[Den[x_], MyForm] := D[x];      But as MyForm is simply pointing towards InputForm, I have not managed to copy InputForm and so the Format calls to MyForm affect InputForm as well. At time of writing I do not have a complete list of the kind of output style transformations I wish to apply, but I am not looking for a complete solution, just an idea of how to get started with my own version of `InputForm` (without breaking the original). Any ideas on how to proceed would be appreciated. Thanks! Edit: eldo's answer has made me realise that there is a loophole in what I have written - All of my symbols/expressions already have StandardForm set up, and I don't want to break that either. That is, for example, I have:               Format[Den[x_], StandardForm] := 1/x^2;      In principle, this is why I'm looking to define a NEW output form, I don't want to get it tangled with any other that is already defined.


title: RSolve? How do I Solve these equations using Mathematica

text: How do I solve these using _Mathematica_? I'd like to have formula for `p[2]` to `p[n-1]`. `P[j]` is the general equation, `P[n]` is the last element, but finite `x[j]` is just some exogenous variables               p[j] == 0.5((p[j + 1] (x[j] - x[j - 1]))/(x[j + 1] -        x[j - 1]) + (p[j - 1] (x[j + 1] - x[j]))/(x[j + 1] -        x[j - 1]) + (x[j + 1] - x[j]) (x[j] - x[j - 1]))          p[1] == 0.5(p[2] + (x[1] + x[2]) (x[2] - x[1]))          p[n] == 0.5(p[n - 1] + (2 - x[n - 1] - x[n]) (x[n] - x[n - 1]))


title: Find white regions in image

text: At the white regions of this image I want to add a few random arrows. I would like to realize two different of adding the random arrows:   * The arrows may not leave the white region   * The arrows have to leave the white region -                img = Import["ExampleData/spikey2.png"]      ![enter image description here](http://i.stack.imgur.com/Sggh2.png) How can you do this with Mathematica? In particular I would like to know how to detect the white regions, and how to store this information. If I give you an arrow can you tell me whether it crosses non-white parts of the image? There is not much space for the arrows in this picture. It would be good to add a bit of white canvas to create some space for the arrows.


title: specifying a list (vector) of arbitrary length

text: When trying to do symbolic calculations in mathematica involving a space of dimension `n`, which is arbitrary but fixed, I'd often like to work with vectors that have arbitrary but fixed length `n`. So I'd like to have a vector defined like `vec = Array[v,n]`, which of course does only work if `n` has been initialized with an integer value before. I'd then like to apply some differential operators like let's say `D[vec,v[2]]`. Does anybody know an elegant way to do that (maybe using the new Inactive construct in Mathematica 10)? p.s.: Interestingly enough mathematica supports sums of arbitrary length, which for example enables the following kind of symbolic computation:               x /: D[x[i_], x[j_], NonConstants -> {x}] := KroneckerDelta[i, j];     D[Sum[x[i], {i, 1, n}], x[2], NonConstants -> x];      which yields the correct result: > Piecewise[{{1, n > 1}}, 0]


title: How can Mathematica solve 7 equations and want to find 7 variables

text: * I have 7 equations as below * e1 := (1 - a) p Subscript[A, 0] Subscript[s, K ] ! *SubsuperscriptBox[(s), (L), (-a)] = (1 - b) Subscript[B, 0] (1 - Subscript[s, K]) (1 - Subscript[s, L])^-b; e2 := a p Subscript[A, 0] ! *SubsuperscriptBox[(s), (L), (1 - a)] = b Subscript[B, 0] (1 - Subscript[s, L])^(1 - b); e3 := x = Subscript[A, 0] Subscript[s, K] ! *SubsuperscriptBox[(s), (L), (1 - a)]; e4 := [Pi] = R + [Delta] - (1 - Subscript[[Tau], y])/(1 + R Subscript[[Theta], i]) b Subscript[B, 0] (1 - Subscript[s, L])^(1 - b); e5 := [[Sigma] + [Phi] (1 - [Sigma])][ Subscript[B, 0] (1 - Subscript[s, K]) (1 - Subscript[s, L])^( 1 - b) - [Delta]] + [Rho] + [Pi] - R = 0; e6 := [Mu] - [Pi] - 1/Subscript[[Theta], i] (z - Subscript[[Theta], c] p x) + [Delta] = 0; e7 := [Gamma] = Subscript[B, 0] (1 - Subscript[s, K]) (1 - Subscript[s, L])^( 1 - b) - [Delta];   * some variable value* a = 0.35; b = 0.4; [Delta] = 0.1; Subscript[[Theta], c] = 0.65; \ Subscript[[Theta], i] = 0.15; [Phi] = 0.5; Subscript[[Tau], y] = \ 0.28; [Rho] = 0.01; [Mu] = 3.7; R = 0.047; Subscript[A, 0] = 0.4; Subscript[B, 0] = 1.99; [Sigma] = 1.1;   * how should I find the 7 vars: Subscript[s, L], Subscript[s, K], [Pi], x, p, z, [Gamma] ?*   * it's no response with below* Solve[{e1 == 0, e2 == 0, e3 == 0, e4 == 0, e5 == 0, e6 == 0, e7 == 0}, {Subscript[s, L], Subscript[s, K], [Pi], x, p, z, [Gamma]}]


title: ListPlot with conditions

text: I have a data file containing the position of about $10^5$ stars of a spiral galaxy. Here is the plot ![enter image description here](http://i.stack.imgur.com/L6Flj.jpg) and this is the corresponding code               Clear["Global`*"]     SetDirectory[" ... "];          data = Import["data_SGC.out", "Table"];     L0 = ListPlot[data, PlotStyle -> {Blue, PointSize[0.001]}, Axes -> False,                    Frame -> True, FrameLabel -> {"x", "y"},                    RotateLabel -> False, LabelStyle -> Directive[FontFamily -> "Helvetica", 20],                    AspectRatio -> 1, PlotRange -> 100, ImageSize -> 550];      As we can see, there are two arms starting at about $(x,y) = (-14.6,0)$ and $(x,y) = (14.6,0)$. Now I would like to customize `ListPLot`, so as the arm starting at the left part $(x,y) = (-14.6,0)$, be in green color, while the other one in red. All the other points between the two yellow banana-type areas should be in gray. Any suggestions? The complete data file can be found here: data. Obviously, I could not generate simple random data in order to replicate this complicated spiral structure.


title: How to get solution from DSolve

text: How to get the solution from DSolve in such way that there is no need to copy the result. When for example solving:               f[x_, y_] := a y + x^2      DSolve[{D[y[x], x] == f[x, y[x]], y[0] == c}, y[x], x]      I get the solution:               {{y[x] -> (-2 + 2 E^(a x) + a^3 c E^(a x) - 2 a x - a^2 x^2)/a^3}}      How can I make a function of this let's say sol[x] so I can use it in such context:               Manipulate[      Plot[sol[x], {x, 0, 5}], {a, -5, 5}, {c, -5, 5}]      EDIT: not interested in:               sol[x_, a_, c_] =       y[x] /. DSolve[{D[y[x], x] == f[x, y[x]], y[0] == c}, y[x], x]


title: DatabaseLink Example for DB2 and Mathematica

text: could someone please point me to good example on how to make a JDBC connection to an IBM DB2 database?


title: A question regarding 1 divided 243

text: Here is a problem due to Feynman. If you take 1 divided by 243 you get 0.004115226337 .... It goes a little cockeyed after 559 when you're carrying out the decimal expansion, but it soon straightens itself out and repreats itself nicely. Now I want to see how many times it repeats itself. Does it do this indefinitely, or does it stop after certain number of repititions? Can you write a simple _Mathematica_ program to verify one conjecture or the other?


title: Why do InputFields not respond in Manipulate utilizing FindGeometricTransform?

text: In the following code changing the `InputField` does not result in observing changes in a result from `FindGeometricTransform`, but moving the `Locator` does. This is related to a previous answer would seem to have a solution, but the fix from that solution doesn't fix the observed behavior, or rather, it causes other problems. Manipulate not working inside DialogInput In this Question/Answer, `LocalizeVariables` is set to `False` for the `Manipulate`, and the control in question is explicitly set as `Dynamic`. This then allows the `Manipulate` to respond appropriately. However, my FindGeometricTransform breaks when I try this. In playing around with the system, I think that I have found that the situation is actually a bit more subtle than I thought. Using Nasser's suggestion, moving the Manipulate to the outside of the Module does partially solve the problem. I can get the GeometricTransform to update whenever I change the fields. That would seem to solve the problem, however, it has a similar problem when I try to add data points to a table based upon the transform (my eventual goal). Here is a new function named maniTransform2 that illustrates the observed behavior.                   imageIUsed = ExampleData[{"TestImage", "Clock"}]         maniTransform2[image_] := Manipulate[Module[{func, points},             func =               Dynamic[FindGeometricTransform[{{coord1x, coord1y}, {coord2x,                    coord2y}}, {loc[[1]], loc[[2]]}][[2]]];             points =              If[Length[loc] > 2,                 Setting@func[loc[[3 ;; Length[loc]]]], {}];                  Row[{Show[{                 Image[image],                 Graphics[{Red, PointSize -> Large,                    Point[{{coord1x, coord1y}, {coord2x, coord2y}}]}]}],               func, Spacer[40],                Grid[Join[{{"X-coord", "Y-Coord"}}, points                 ]                ]               }]], {{loc, {{10, 10}, {20, 20}}}, Locator,              LocatorAutoCreate -> True}, {{coord1x, 50, "x-Position"},              InputField[#, Number] &}, {{coord1y, 50, "y-position"},              InputField[#, Number] &}, {{coord2x, 100, "x-Position"},              InputField[#, Number] &}, {{coord2y, 100, "y-position"},              InputField[#, Number] &}];              holderFunc := DynamicModule[{img = imageIUsed},           switcher =             Panel[TabView[{Dynamic[maniTransform2[img]], "Other Functions"}]];           DialogInput[Row[{Dynamic[switcher], InputField[Dynamic[img]]}]]]      So, calling `maniTransform2[imageIUsed]` directly, the `GeometricTransform` updates whenever I move one of the `Locator` points or if I change a value in one of the various `InputField`s. If I call `holderFunc`, then if I move any of the `Locator` points the `GeometricTranform2` updates. It also updates when I change one of the fields. When I add a Locator (command-Click on a Mac), the procedure adds it to the Table of points below the transform function. Whatever the values are in the input fields are frozen for the transform at that point. Changing the values in the input fields will change the transform function, but they won't change the values of the points in the Table. For that matter, the If statement in general is frozen. I.e. it needs to be wrapped in a Dynamic somehow. However, doing so then places the func into a Dynamic and since func is declared in the Module, this is a no-no and it turns red.


title: How to define an n-variate empirical distribution function probability for any n?

text: I'm using Mathematica 9.0 to calculate the probability according to the empirical distribution function (EDF) of some sample data. Afterwords this is included in a maximization stage so I define this probability as a function. I have to do apply this to groups of data in which each group has different dimensionality. Therefore I'd like to define a generic version of "probability given by an EDF" that I can apply to any of these groups. Here there is a toy example for some 2-dimensional samples:               data = Transpose[{{1, 3, 4, 9, 8, 7, 8}, {2, 1, 1, 6, 7, 8, 9}}];     MatrixForm[data]      Its EDF is simply:               edf := EmpiricalDistribution[data];      Then by hand one can easily define its probability function:                edfProbFunction[t1_, t2_] := NProbability[x1 <= t1 \[And] x2 <= t2, {x1, x2} \[Distributed] edf];      and compute the probability by just defining:               edfProb[w1_, w2_] := Evaluate[edfProbFunction[w1, w2]];      In this way, given a new point (2,4) from this distribution, it has probability 0.142857 given by:               edfProb[2,4]      My question is **how to define a function like _edfProbFunction_ for any dimension, not a fixed dimension** (2 in the example)? I tried to do it in different ways but didn't succeed. I lack background in Mathematica so these attempts may be nonesense. I summarize them anyway in case this can be of any help: **First naive attempt** -- use a vector of input variables, straightforward               edfProbFunction[t__] := NProbability[x <= t, x \[Distributed] edf];     edfProb[w__] := Evaluate[edfProbFunction[w]];      Using this definition of _edfProb_ together with the _edfProbFunction_ defined in the toy example works, but not with this _edfProbFunction_ here. This made me think that I had to somehow made explicit each of the individual predicates (the inequalities) in _edfProbFunction_ **Second attempt** -- use MakeBoxes But a simple example shows that the expressions produced by this are not seen as variables in _edfProbFunction_ :               xP /: MakeBoxes[xP[x___], form_] := RowBox[Riffle[Map[MakeBoxes[#, form] &, {x}], ","]]     x[1] = "" <> {"x", IntegerString[1]};     x[2] = "" <> {"x", IntegerString[2]};     varx = xP[x[1],x[2]] (*this produces a list x1,x2 *)     edfProbFunction[t1_,t2_] := NProbability[x1 <= t1 \[And] x2 <= t2, {varx} \[Distributed] edf];      **Third attempt** -- I tried to define a function that recursively creates the predicate, but it doesn't work neither:               table = Table[x[i] <= t[i], {i, 2}];     g[n_] := If[Length[n] > 1, n[[1]] \[And] g[Drop[n, 1]], If[Length[n] == 1, n[[1]], 0]]     predicate = g[table]     edfProbFunction[t_] := NProbability[predicate, {t[1], t[2]} \[Distributed] edf];     edfProb[w__] := Evaluate[edfProbFunction[w]];     edfProb[{2, 4}]      Any suggestions will be welcome, specially complete answers to my question.


title: Copy and paste behaviour with Subscript

text: I tend to use a lot of subscripts in my code, and I am aware that copy and paste of subscripts from Mathematica to MathematicaSE (or any text editor, for that matter) is screwy in the sense that $a_b$ copies to MathematicaSE as               Subscript[a, b]      which when pasted back into Mathematica yields `Subscript[a, b]`. This is quite different behavior than Greek or other special symbols; for example, $\Lambda$ copies into MathematicaSE as               \[CapitalLambda]      which when pasted back into Mathematica correctly yields $\Lambda$. The same applies even for more obscure symbols, like `\\[WhiteBishop]`. Is there any way at all to have subscripts correctly copy and paste from notebook to text to notebook like all the other special symbols in Mathematica? Or is there no choice but to use infix symbols, like `a[b]`?


title: How to stop a ParametricPlot3D from autorotating

text: The 3d graphic functions like `ParametricPlot3D` and `ContourPlot3D` always give me a rotating plot. Sometimes, I even can't stop it rotating when I select the plot. For example, I am getting autorotation, like an animation, from               ParametricPlot3D[{Sin[a] Cos[b], 2 Sin[a] Sin[b], 3 Cos[a]},        {a, 0, π}, {b, 0, 2 π}, BoxRatios -> Automatic]


title: Create a "perspective animation"

text: Inspired by How can this confetti code be improved to include shadows and gravity? I would like to create my new experiment/stimuli using Mathematica. The idea is to study how people move their eyes in a dynamic scene. To do so I need to build some animations (1 minute long to start) where we feel like going forward in a perspective grid like the one below. ![enter image description here](http://i.stack.imgur.com/ZGtaT.png) I will need to make some object appear/disappear/change within that scene. The grid itself could just be made out of point, and i will add some geometric colored shapes. While I know how to draw perspective I don`t know how i could "program" it and then animate it.


title: Drawing Rotated views while ignoring the Bounding box

text: I am trying to make an animation of a rotating cube using the following code:               cube = GraphicsComplex[     {{0, 0, 0}, {0, 0, 1}, {0, 1, 0}, {0, 1, 1}, {1, 0, 0}, {1, 0, 1}, {1, 1, 0}, {1, 1, 1}},     Polygon[{{1, 2, 4, 3}, {5, 6, 8, 7}, {1, 2, 6, 5}, {3, 4, 8, 7}, {1, 3, 7, 5}, {2, 4, 8, 6}}]     ]          cubes = Table[     Graphics3D[{Rotate[cube, x, {1, 1, 1}, {0, 0, 0}]},      ViewPoint -> {3, 1/2, -2}, ViewVertical -> {1, 1, 1},      Boxed -> False], {x, 0, 2 Pi/3 - Pi/48, Pi/24}]      However, as the cube rotates, the bounding box (which is not drawn because `Boxed->False`) causes the image of the cube to be shrunk to fit the larger bounding box in the field of view. Is there a way to keep the scale constant and not vary with the varying size of the bounding box? I've gone through the list of options for `Graphics3D`, yet none seem to help. * * * **Edit:** Heike's answer works like a charm! For those interested, here is the finished code, used to create the illustration for this answer on math.SE.               cube =     GraphicsComplex[     {{0, 0, 0}, {0, 0, 1}, {0, 1, 0}, {0, 1, 1}, {1, 0, 0}, {1, 0, 1}, {1, 1, 0}, {1, 1, 1}},     Polygon[{{1, 2, 4, 3}, {5, 6, 8, 7}, {1, 2, 6, 5}, {3, 4, 8, 7}, {1, 3, 7, 5}, {2, 4, 8, 6}}]     ];          envelope[t_] := If[t < 1, t, If[t < 2, Sqrt[(2 t - 3)^2 + 3]/2, 3 - t]]          lozenge =      Rotate[     RevolutionPlot3D[{Sqrt[2/3] envelope[t], t/Sqrt[3]}, {t, 0, 3}, MaxRecursion -> 5][[1]],     {{0, 0, 1}, {1, 1, 1}}];          enveloped =      Table[     Graphics3D[{Rotate[cube, x, {1, 1, 1}, {0, 0, 0}],  Opacity[1/2], lozenge},     ViewVector -> {3, 1/2, -2}, ViewAngle -> 30 Degree, ViewCenter -> {1/2, 1/2, 1/2},      ViewVertical -> {1, 1, 1}, Boxed -> False, ImageSize -> 300],     {x, 0, 2 Pi/3 - Pi/48, Pi/24}];          Export["enveloped.gif", enveloped, "GraphicsList", "DisplayDurations" -> {.05}]


title: Opening a context menu (with the Menu key)

text: Is it by any chance possible to make the Menu key work as one would expect in _Mathematica_ : opening a context menu? The Menu key does nothing in version 7 or 8 on Windows.


title: how to extract a subinterval from a previous element in a list (in condition)

text: **question:** i need to use mathematica to write an intermediate value theorem's algorithm, but i don't know how to write in a module form... i have a function and then, we need to set up a range and also its stepsize... **example:** f(x)=8x-12x^2+4x^3 range=[-0.5,3.5] stepsize=1 thus, x={-0.5,0.5,1.5,2.5,3.5 } compute f(-0.5),f(0.5),f(1.5),f(2.5),f(3.5) a series of element will showed y={-7.5,1.5,-1.5.7.5,52.5} **condition:** an interval of x will be choose when it consists a -ve value and follow by a +ve value in its function value. **result:** since {-7.5,1.5} and {-1.5,7.5} hence subinterval[-0.5,0.5]and [-1.5,7.5] selected. **question (cont)** random choose a value from interval(s) selected and run a newton method step x[n+1]=x(n)-(f[x(n)]/f'x(n)]


title: How to copy groups of cells with NotebookWrite?

text: I'm trying to use:               NotebookWrite[nb, NotebookRead[EvaluationNotebook[]];      to copy cells from the `EvaluationNotebook[]` to a new notebook `nb`. For this, I move around in the `EvaluationNotebook[]` using different applications of `SelectionMove[nb, ...]`. Now, I would like to copy the exact same cell groupings of the current document as well, and this doesn't seem to happen. In the newly created notebook `nb`, I just see consecutive cells, without any grouping. Why is that? how can copying of groups be achieved? All help very much appreciated!


title: Can I place a link to a package file (.m) in my Applications folder

text: I am developing a package and would like to be able to test it without having to copy the package file to my `$UserBaseDirectory/Applications` folder for each change, so it would be convenient for me to just create a Finder link or symlink pointing back to my working file. So far I have not been able to convince Mathematica to treat the link as a package file. Am I missing a subtle technique that may make this possible?


title: Sum[expr,{i,0,Infinity}] for power series of cumulative normal distribution gives exponential function?

text: The Taylor series (about 0) for the cumulative normal distribution has coefficients:               g[i_] := Piecewise[{{Sqrt[Pi/2], i == 0}, {(-1/2)^((i - 1)/2)/(((i - 1)/2)!*i), Mod[i, 2] == 1}}]/Sqrt[2*Pi]      However,               Sum[g[i]*x^i,{i,0,Infinity}]      gives $e^x$ and not the $\frac{1}{2} + \frac{1}{2} Erf(\frac{x}{\sqrt{2}})$ expected. When I               Plot[Sum[g[i]*x^i, {i, 0, 20}], {x, -5, 5}]      I get something looking like an exponential (not expected). But when I               Plot[Evaluate[Sum[g[i]*x^i, {i, 0, 20}]], {x, -5, 5}]      I get something looking like the cumulative normal distribution (expected). Trying to understand the different plots, I looked at               {Limit[Sum[g[i]*x^i, {i, 0, n}], n -> 3], Sum[g[i]*x^i, {i, 0, 3}]}      Which gave $\left\{\frac{e^x \Gamma (4,x)}{6},-\frac{x^3}{6 \sqrt{2 \pi }}+\frac{x}{\sqrt{2 \pi }}+\frac{1}{2}\right\}$ - the choice of n=3 is just for tidiness, similar results hold for all n (that I tried). These are clearly not equal as substituting $x\to 0$ gives $\{1,\frac{1}{2}\}$. This, presumably, explains why I am getting the incorrect answer for the infinite sum and different plot results depending on the placement of the evaluate. Is there an explanation as to why I get different results with/without the limit and how to work around it (in the infinite sum case)? The motivation is that I am trying to combine these coefficients in other infinite sums (corresponding to cumulative distribution of a sum of Gaussians centered at different positions) and it is giving results that differ from the series expansion I otherwise would obtain (using Series). The above was tested on Mathematica 9.01 on Linux. **EDIT** Turns out that the sum doesn't evaluate on Mathematica 9.01, there was traces of previous definitions lying around that caused it to evaluate when it shouldn't have. Solution is to avoid the piecewise definition and explicitly only sum the odd terms.


title: How to export a 16 or 32 bit TIFF file

text: I have a function that creates a monochrome grayscale image that must be export as a 16-bit and 32-bit TIFF file. The _Mathematica_ documentation mentions that these bit depths are supported during `Export`, but makes no reference as to how to specify them under TIFF or `Export`. How is the bit depth specified for this type of export?


title: Converting polar coordinate expression to cartesian coordinates

text: An intermediate step in my analysis requires me to work in polar coordinates, but I would like to convert the results back into cartesian coordinates. The conversion is very simple but tedious for complex expressions. I expected to use substitutions, but it isn't panning out for me               polarf[{r_, phi_}] := r^6 Sin[phi]^2 Cos[phi]^2     cartesianf[{k1_, k2_}] :=       polarf[{r, phi}] /. r^2 Sin[phi]^2 -> k2^2 /.         r^2 Cos[phi]^2 -> k1^2 /. r^2 -> k1^2 + k2^2     cartesianf[{k1, k2}]      gives me back my original expression:               r^6 Cos[phi]^2 Sin[phi]^2      I'm pretty sure there is a way to get Mathematica to spit out               (k1^2 + k2^2) k1^2 k2^2      or something similar. But how? My searches of Google, Mathematica documentation, and this site have not turned up an answer.


title: Add elements in a sublist

text: I have created a subset of arrays:               b = Subsets[Range[10], {5}]     (* Out= {{1, 2, 3, 4, 5}, {1, 2, 3, 4, 6}, {1, 2, 3, 4, 7}, {1, 2, 3, 4, 8},              {1, 2, 3, 4, 9}, ..., {6, 7, 8, 9, 10}} *)      This command shows the combinations I wish to evaluate with. How can I add the elements of each subset in the list above to get an output like:               {{15}, {16}, {17}, {18}, {19},..., {40}}


title: Second-Order Feedback Pathways

text: I'm relatively new to Mathematica and I've tried searching and reading through the Mathematica documentation but I'm not able to find a good place to start. I want to model a simple, second-order negative feedback loop between two parties. I would like a) to have a visual animation of the system (this can be crude) and b) for there to be a plot of the amount of each party there is over time (this should obviously be some sort of periodic function depending on the parameters of the system). Finally, I want to be able to see the change in behavior as a function of the delay in response of party A from party B. If the delay is long it should take a long while for equilibrium to occur after a shock. A lot of the specific functionality I've mentioned is something I'm willing to try and figure out later, I just want a good place to start learning how to model such a system. Thanks!


title: Efficient Dyson series implementation

text: I'm trying to implement a Dyson series \begin{array}{lcl} U(x,x_0) & = & 1 + \int_{x_0}^{x}{dy_1V(y_1)}+\int_{x_0}^x{dy_1\int_{x_0}^{y_1}{dy_2V(y_1)V(y_2)}}+\cdots \\ & &{} + \int_{x_0}^x{dy_1\int_{x_0}^{y_1}{dy_2 \cdots \int_{x_0}^{y_{n-1}}{dy_nV(y_1)V(y_2) \cdots V(y_n)}}} +\cdots \end{array} where $V(x)$ is a large matrix. (I'm aware of the solution for symmetric functions, it doesn't work in my case.) Probably the main bottleneck is the integration but, since it involves multiple integrals, I don't see any easy way of dealing with it. Compile seems to be out of reach as well. I'll greatly appreciate any kind of advice. Here's the code I've written so far:               myInt[exp_, x1_, rat_] :=       Module[{mulInt, len, int, sum, s1, s2, rar, x, x2 = rat x1, r2,         r1},       SetAttributes[x, NHoldFirst];       (*to prevent switching into numerical values*)            mulInt[y1_, y2_, n_Integer /; n > 0] := Module[{tab},         tab = Table[{x[i], y1, x[i - 1]}, {i, 1, n - 1, 1}];         Return@Prepend[tab, {x[0], y1, y2}]         ];       (*mulInt creates lists of variables to be integrated*)            int[n_] :=         Integrate[Dot @@ (#1 /@ #2[[;; , 1]]), Sequence @@ #2] &[exp[#] &,          mulInt[x1, x2, n]];       (*maps first elements of mulInt's lists as variables of exp,        creates a matrix product out of all exps*)            sum[n_] := Module[{set},         set = Sum[int[m], {m, 1, n}];         len = Length[set[[1]]];         Return[IdentityMatrix[len] + set]         ];       (*Dyson series*)            s1 = sum[3];       rar = Total[Abs@Flatten[#]] &;       r1 = rar[s1];       (*a function for convergence check*)       Do[s2 = s1 + int[n];        r2 = rar[s2];         Print[{n, r2 - r1}];         If[Abs[r2 - r1] <= 10^-3. len^2, Break[]]; s1 = s2;         r1 = r2;, {n, 4, 15}];       (*convergence test*)            Return[s2]       ]      Here's a simple example with the 3rd Pauli matrix:               MatrixExp[Integrate[PauliMatrix[3], {x, 1., 2.}]]     myInt[PauliMatrix[3] &, 1., 2.]     (*results:     {{2.718282, 0.}, {0., 0.3678794}}     {{2.716667, 0}, {0, 0.3666667}}     *)      Of course, `MatrixExp[Integrate[function, {x, 1., 2.}]]` does not work in more general cases. The operators I work with are sparse arrays (code below) and it take ages to get the result. Typical values of `M`: 10 to 20 (`M=2` can be a good working example). To run the code, type for instance `myInt[toMT[ #, 2]& , 10^-7, 2.]`.               toMT[x_, M_] :=       Module[{nMax = 8 M + 4, sw, ret, v = 0.1, t = 5 10^8., ntol, mrul},       ntol[nn_, Mn_] := Mn - (Ceiling[nn/4] - 1.);     mrul[n_, m_, y_] := {n, m} -> y;            sw[n_] :=         Switch[{Mod[n, 4], n + 12 <= nMax, n + 15 <= nMax, n - 12 >= 1},         {1, True, True, _},         {mrul[n, n, -ntol[n, M] /x],          mrul[n, n + 12, I v  t],          mrul[n, n + 15, 2 v   (ntol[n, M] - 2) /x]},              {1, True, False, _},         {mrul[n, n, -ntol[n, M] /x],          mrul[n, n + 12, I v  t]},              {1, False, _, _},         {mrul[n, n, -ntol[n, M] /x]},              {2, _, _, _},         {mrul[n, n, (ntol[n, M] - 1) /x],          mrul[n, n + 1, -I t ]},              {3, _, _, True},         {mrul[n, n, ntol[n, M] /x],          mrul[n, n - 12, I t v  ],          mrul[n, n - 13, -2 v  (ntol[n, M] + 2) /x]},              {3, _, _, False},         {mrul[n, n, ntol[n, M] /x]},              {0, _, _, _},         {mrul[n, n, -(ntol[n, M] + 1) /x],          mrul[n, n - 3, -I t ]}         ];       ret = Map[sw[#] &, Range[1, 8 M + 4]];       Return[SparseArray@Flatten[ret]]]


title: Are there some other ways to solve a second PDE except DSolve?

text: I have a partial differential equation as follows: $$\frac{\partial p(x,t)}{\partial t}=\text{Dp} \frac{\partial ^2p(x,t)}{\partial x^2}-\frac{p(x,t)-\text{p0}}{\tau }$$ What I try to do was to get its general solution by               DSolve[D[p[x, t], t] == -((p[x, t] - p0)/τ) + Dp D[p[x, t], {x, 2}], p, {x, t}]      However, the output returns what I have inputted, which means **_Mathematica_** cannot solve this PDE. By looking up the help document, I find that `DSolve` can only find the general solution for a restricted type of homogeneous linear second-order PDEs, that is, for such a linear second-order PDE as $b \frac{\partial ^2u}{\partial x\, \partial y}+a \frac{\partial ^2u}{\partial x^2}+c \frac{\partial ^2u}{\partial y^2}+d \frac{\partial u}{\partial x}+e \frac{\partial u}{\partial y}+f u=g$, only when `d=0`,`e=0`,`f=0` and `a`,`b` and `c` are all constants can we get the general solution. I have tried this PED in **Maple** , and get a solution with conditions, but I don't know whether it is correct. The help document tells that the algorithm used by `DSolve` is not applicable in this case. So, I wonder whether there exist some other ways or some packages to solve this PDE. If finding the general solution is impossible, is it possible to get a special solution?


title: How to change working directory for calculation and save

text: Hello Mathematica users, I have problem to set working directory, I want to calculate and save my data on D, but down you can see that mathematica shift automatically on old C. How to use D partition for calculating if mathematica is installed on C? If I do calculation as this, file is saved on D but first it is saved on C and on C I don't have enough space.                 In[7]:= ResetDirectory[]                  "C:\\Users\\user\\Documents"            In[8]:= DirectoryStack[]            Out[8]= {}            In[10]:= SetDirectory["D:\\"]            Out[10]= "D:\\"            A:=5;            Export["A.wdx", A];            In[13]:= DirectoryStack[]             {"C:\\Users\\user\\Documents"}


title: Get rid of external library dependency

text: I am trying to generate C code for some functions, which I do not post in full because they are a few hundred lines long. The functions do nothing too fancy: a bunch of dot products, powers and roots. Still, when compiling to C code Mathematica sticks in some unwanted dependency on its own libraries, which is not acceptable for the use case in question. The functions I am trying to compile have 5 arguments, 4 of which are 3-dimensional vectors. The compile printout of one of them can be found **here**. As you can see, there are 3 Mathematica functions being pulled in: DotVV, Power and Internal`ReciprocalSqrt. Is there any way I can get rid of these without modifying the code manually? **Edit:** here is the code I am using to compile the function               Compile[{{pos, _Real, 1} , {a, _Real, 1}, {v, _Real, 1}, {ba, _Real,          1} , {V, _Real}} ,        xSol, CompilationTarget -> "C"];


title: Quick way to use conditioned patterns when defining multi-argument function?

text: I have a simple function that is supposed to only accept numeric values (i.e. complex/real numbers and constant symbols e.g. Pi, E). $$f(a,b,c)=a+b+c$$ **Edit** : I should have chosen a less simple function for this question as there might be approaches that will work for this simple function but not for functions in general (1-see end of question). Please think of a more complicated function, such as $$f(a,b,c)=a^2 sin(b) log(c)$$ when you're thinking of an answer. I know that one can use _?NumericQ for each parameter such that only numeric values of that parameters are entered into the function (click here for more information on putting constrains on patterns).               Clear[f1]     f1[a_?NumericQ, b_?NumericQ, c_?NumericQ] := a + b + c          f1 @@@ {{1, 2, 3}, {x, y, z}, {1, y, z}, {x, 2, z}, {x, y, 3}}     (* {6, f[x, y, z], f[1, y, z], f[x, 2, z], f[x, y, 3]} *)      However, for functions with more than 1 variables, I'm way too lazy to add NumericQ after each parameter. Using /; at the end of the function definition works, but I feel it's still too long and I have to retype the name of the parameters (a,b,c) at the end.               Clear[f2, f3]     f2[a_, b_, c_] := a + b + c /; And @@ (NumericQ[#] & /@ {a, b, c})     f3[a_, b_, c_] := a + b + c /; VectorQ[{a, b, c}, NumericQ]      Is there any way to express the condition only once, and without having to type the list of parameters one more time? I know that this is a frivolous question borne out of sheer laziness but I'd love to hear your ideas. (1) such as using the double underscore (BlankSequence) to apply NumericQ to any number of arguments passed to Plus (per Kuba's helpful suggestion). This is because these arguments have identical hierarchy in the function--thus having no need for parameters with different names to represent them--and because Plus can take any number of arguments.               Clear[f4]     f[a__?NumericQ] := Plus[a]          f @@@ {{1, 2, 3}, {x, y, z}, {1, y, z}, {x, 2, z}, {x, y, 3}}         (* {6,f[x,y,z],f[1,y,z],f[x,2,z],f[x,y,3]} *)


title: What does None mean in a control specification for Manipulate?

text: I am now struggling to understand code that contains the following (simplified) `Manipulate` structure.               Manipulate[         complexparts[E^(I Pi t)],      {{t, 1/4.}, 0., 2},      {{complexparts, {Re[#], Im[#]} &}, None}]      I am having difficulty with the last line: `{{complexparts, {Re[#], Im[#]}&}, None}`. Somehow, this creates a "pure function" with a name "complexparts," which is then used above in the line               complexparts[E^(I Pi t)]      I tried to execute these independently outside the body of code so I could watch them do what they do, but without success. I evaluated:               {{complexparts, {Re[#], Im[#]} &}, None}      and then:               complexparts[x+Iy]      But my output was just:               complexparts(x+I y)      Can I get some help in understanding how `{{complexparts, {Re[#], Im[#]} &}, None}` works? And what does the word `None` do?


title: Finding Expectation of function of a Log-normal distribution

text: Say $Y=g(X)$ and $p_X = \frac{e^{-\frac{(\mu -\log (x))^2}{2 \sigma ^2}}}{\sqrt{2 \pi } x \sigma }$ is Log-normal density function: [Wiki] Find E[Y]? Since $E[Y] = \int_0^\infty y f_Y \ dy = \int_0^\infty g(x)f_X(x)dx$. So, I do not need to find $f_Y(y)$.               .         px = Simplify[PDF[LogNormalDistribution[Mu, Sigma], x], x > 0]     Integrate[Log2[1 + x] px, {x, 0, \Infinity}, Assumptions -> {Sigma > 0}]     .      Unfortunately, Mathematica cannot evaluate this integral for a closed form expression and I'm not quite sure how else to solve it. Will appreaciate any help I can get on the evaluation steps. Edit: I've also tried the code below with no results:                Expectation[Log2[1 + x], x \[Distributed] LogNormalDistribution[Mu, Sigma]]


title: Maximum size of TIF files in Mathematica

text: I have a question concerning the maximum size of TIFF files Mathematica can handle. According to the TIFF 6.0 specification -revision 6.0 (see: http://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf) the maximum size of TIFF files is determined by the 32 Bit offsets used by this format. Thus, the theoretical maximum file size of a TIFF file should be about 4 GB. I am dealing with huge TIFF files that I need to import, process and export with Mathematica. Using Mathematica's Import and Export functions, I cannot import a TIFF file larger than 2 GB nor can I export a TIFF file that exceeds the 2 GB limit. Consider the following example i created:               data = ConstantArray[Image[ConstantArray[0, {1000, 1000}], "Bit16"],         1500];          Export["test.tif", data];      I create 1500 black images with a bit depth of 16. When i export the data, the export stops at about 2 GB. When I open the file with other software, the file only contains 1073 images. My first guess was that somehow one Bit is used to determine the sign, but I cannot figure out how to show that. Does anybody have a solution how to import and export TIFF files larger than 2 GB? Thanks in advance! **System specification**   * OS: Windows 7 Professional, Service Pack 1 (64-bit)    * Processor: Intel Xeon CPU E5630 @ 2.53 GHz (2 Processors)    * Installed memory: 96 GB   * Mathematica 9.0    * Java version 1.7.0_07 **Edit** Since I did not find any other solution, I tried reinstalling Mathematica 8 on my computer. Surprisingly, with Mma 8 it was no problem to export and import the testset. I am wondering why this is not possible with the new version. If you have any ideas, please let me know.


title: How to convert from and to UTM coordinates in Mathematica?

text: How to use the UTM coordinate system (northing, easting) in Mathematica using the built-in functions (`GeoPositionENU`, `GeoGridPosition`, etc.). There are UTM Zones implemented in Mathematica, e.g.:               GeoProjectionData["UTMZone33"]      gives               {"TransverseMercator", {"Centering" -> {0, 15},   "CentralScaleFactor" -> 1, "GridOrigin" -> {0, 0},   "ReferenceModel" -> "WGS84"}}      From N45, E15 one should get Easting 500000 and Northing 4982950.4 (zone 33), but I can't reproduce it.               GeoGridPosition[GeoPosition[{45, 15, 0}, "WGS84"], "UTMZone33"]      gives               GeoGridPosition[{0., 4.98494*10^6, 0}, "UTMZone33"]      (Easting offset 500000 is understandable - default, but Northing is way off.) Any help would be appreciated.


title: Creating a stacked RectangleChart

text: I would like to make a "Stacked" `BarChart` where the bars have variable widths, like a `RectangleChart`. However, `RectangleChart` does not accept `ChartLayout -> "Stacked"`. Is there a way to do this, or does anyone have a workaround? For example, here is a `RectangleChart` with the bars at different widths: ![enter image description here](http://i.stack.imgur.com/9001Q.png) Here is a "Stacked" `BarChart` with the bars decomposed into two components: ![enter image description here](http://i.stack.imgur.com/VW9C6.png) I would like to make a stacked `RectangleChart` with variable-width bars that can be decomposed into components.


title: Wait / sleep miliseconds

text: Is there any way to make _Mathematica_ stop for some miliseconds? I know about the `Pause[]` but it seems it only works with seconds.


title: Generating figures over remote connection (using terminal)

text: Recently I've been making movies by having _Mathematica_ create figures and then I combine all of them together using `ffmpeg`. The problem now is that my macbook is not fast enough to generate the figures I want in a short amount of time. I have access to a linux machine and I would like to be able to send a script to that machine so that I can generate my figures. The problem I'm facing is that _Mathematica_ can't open display ":0.0". ![enter image description here](http://i.stack.imgur.com/5FbcP.png) I also found this, but it did not solve my problem. Does anyone know how to generate figures in the terminal? All I want it to do is to write them to a file.


title: Computing the distance between two curves obtained from image data?

text: I've got some image data that I've binarized. The image contains two curves, from which I'd like to compute the distance between (eventually computing an average radius for each point in the picture). I've done the computation, but it's done in C programmer style, and fairly ugly               data = ImageData[ b ] ;     {h, w} = Dimensions[data] ;          min = Table[0, {w}] ;     max = Table[0, {w}] ;     averageRadiusList = {} ;     scale = 0.1 / w  ;          For [ column = 1, column < w + 1, column++,      For [ row = 1, row < h/2, row++,        If [         data[[row, column]] != 1,            min[[column]] =  row ; Break         ]        ]       For [ row = h, row > h/2, row--,        If [         data[[row, column]] != 1,           max[[column]] =  row ; Break         ]        ]       If [ min[[column]] !=  0  && max[[column]] != 0,             AppendTo[         averageRadiusList, {column * scale,          scale * (max[[column]] - min[[column]])/2} ]        ]      ]      I was wondering if there's a more natural "Mathematica way" of doing things ... something that is presumably more elegant, efficient, compact, and more general?


title: How to implement something like NMaximize[ NMinimize [ f(x,y) , {x} ], {y} ]?

text: Title says it all, really. I want to find some set of values for which a function of those values can't be made larger than a certain number, when some other values (on which that function is also dependent) are unknown.


title: Subspaces in Mathematica

text: I'm working on a research project and I need to learn how to use _Mathematica_ to calculate subspaces. Specifically I plan to solve the following operations and I would greatly appreciate if you could give me an example of how to solve it. For example:   1. In the vector space $Ρ^n$, consider the sub space  $$S = \left\langle(1, -2,1,0, ..., 0), (0,1, -2,1,0, ..., 0) ... (0,0, ..., 1, -2,1)\right\rangle$$ Calculate equations defining $S$ for $n = 4, 8, 16, 20$.   2. Find generator subspaces of "magic" matrices of $2\times2$, $3\times3$ and $4\times4$ (a square matrix is called magic if the sums of the elements in each row, each column and in the diagonal are always the same)


title: How to un-eat memory?

text: Consider this code:               MemoryInUse[]     T = Table[RandomComplex[], {i, 1, 6000}, {j, 1, 6000}];     MemoryInUse[]     T += T\[ConjugateTranspose];     MemoryInUse[]     {Es, Ys} = Eigensystem[T];     MemoryInUse[]     T = Table[RandomComplex[], {i, 1, 6000}, {j, 1, 6000}];     MemoryInUse[]     T += T\[ConjugateTranspose];     MemoryInUse[]     {Es, Ys} = Eigensystem[T];     MemoryInUse[]     $HistoryLength = 0;     MemoryInUse[]     Clear[T]     MemoryInUse[]     Clear[Es, Ys]     MemoryInUse[]     ClearSystemCache[]     MemoryInUse[]      It gives me the following results: > 15808208 > > 880820520 > > 1456822832 > > 4919500424 > > 5783503032 > > 6359505096 > > 9822181440 > > 9822182648 > > 9822182112 > > 9822181384 > > 9822162952 Clearly, the memory clears negligibly on any of `ClearSystemCache`, `Clear` and zeroing `$HistoryLength`. Repeating its execution leads to swapping, after start of which I hurry up to kill MathKernel before my X or WM or anything else are OOM-killed. So what are the working ways to release the memory?


title: "Covering up" text in Graphics

text: Consider the following code:               Show[{Graphics3D[{Opacity[0.2], Sphere[], Opacity[1.0], Blue,      Polygon[{{-.2, -.3, -.3}, {-.2, .3, -.3}, {-.2, .3, .3}, {-.2, \     -.3, .3}}]}],      ParametricPlot3D[{Sin[th] Cos[ph], Sin[th] Sin[ph], Cos[th]}, {th,      0, Pi}, {ph, 0, 2 Pi},      RegionFunction -> Function[{x, y, z}, Abs[x] < .9],      PlotRange -> {-1, 1}, PlotStyle -> Red, Mesh -> None]}]      ![Mathematica graphics](http://i.stack.imgur.com/UDuQQ.png) (Doctored somewhat from another question on this site.) It produces a sphere, with an opaque red surface, except for two "portholes", which allow one to see the blue rectangle inside. Now consider the following minor tweak, replacing the square by some text:               Show[{Graphics3D[{Opacity[0.2], Sphere[], Opacity[1.0], Blue,      Text["Surprise!", {0, 0, 0}]}],      ParametricPlot3D[{Sin[th] Cos[ph], Sin[th] Sin[ph], Cos[th]}, {th,      0, Pi}, {ph, 0, 2 Pi},      RegionFunction -> Function[{x, y, z}, Abs[x] < .9],      PlotRange -> {-1, 1}, PlotStyle -> Red, Mesh -> None]}]      ![Mathematica graphics](http://i.stack.imgur.com/v3Z10.png) The output (which I don't know how to save as a rotating GIF [side question?]) shows the blue text _over_ the red sphere, whether or not I am "looking" through the porthole or not. The reason for this is in the help: > Text is drawn in front of all other objects. Is there way to treat Text like other Graphics primitives, so that indeed it will be a "Surprise!" when you look through the porthole? That is, to get behavior similar to that of the blue rectangle? Perhaps I should clarify I am most interested in being able to change the "z order" of the Text. But the fact that it doesn't rotate with the rest of the Graphics objects (using the mouse) is also kind of annoying. Thanks!


title: Second-order DSolve overdetermined with only 2 boundary conditions

text: I was going through some circuit analysis problem and came up with a second- order differential equation, which I decided to solve with _Mathematica_ : $$ L\frac{\mathrm{d}^{2} I}{\mathrm{d}t^{2}} + R\frac{\mathrm{d}I}{\mathrm{d}t} - \frac{I}{C} = 0. $$ I used the following syntax:               DSolve[{L i''[t] + R i'[t] - i[t]/C == 0, i[0] == 0, L i'[t] == 1}, i[t], t]      Yet _Mathematica_ returns the following error:               DSolve::overdet: There are fewer dependent variables than equations, so the system is overdetermined. >>      However, it is a second-order ODE, and so it should not be overdetermined with only two boundary conditions.


title: How can I create an interactive application that accepts data and and plots it?

text: I have some code in _Mathematica_ which shows a colored plot, where the coloring depends on data values. I would like to make this into an interactive application that accepts two inputs:   1. data, a list of data points.   2. PocetDat, an integer parameter. I know little about CDF, but i don't see how I can get inputs or table inputs from the users. Further, I want the users of the application to only see the inputs and the final plot -- no code.               data =        {-0.003, 0.002, 0.008, 0.014, -0.026, -0.036, -0.042, -0.010, -0.000,         -0.014, -0.013,  0.048, 0.014, -0.035, -0.023, 0.025, 0.001, -0.002,          0.050, 0.053,  0.031, -0.045, 0.003, 0.052, 0.066, -0.040,  0.016,         -0.054, -0.040, -0.042, -0.018, -0.034, -0.032, -0.021,  0.008, -0.007};     PocetDat = 912;      KorelCiara = 2*Sqrt[1/PocetDat];      PRange = 1.2*Max[{data, KorelCiara}];     Show[       DiscretePlot[data[[i]], {i, 1, Length[data]},          ExtentSize -> Full,          ColorFunction -> Function[x, If[Abs[data[[x]]] > KorelCiara, Red, Blue]],           ColorFunctionScaling -> False],       Plot[{KorelCiara, -KorelCiara}, {x, 0, Length[data]}],        PlotRange -> {-PRange, PRange}]


title: Multiple plots using dynamics

text: I am studying Dynamic and DynamicModule, and I have tried to make a simple plot of a family of real functions. The number of functions should be a dynamic variable controlled by a slider. So I have tried something like this               {Slider[Dynamic[z], {1, 4, 1}], Plot[Evaluate[Dynamic[Table[Sin[i*t], {i, 1, z}]]], {t, 0, 2 Pi}]}      In this case variable `t` is highlighted in red and the output is empty. But if you do it outside of `Plot[]`, then you get a correct list of functions               {Slider[Dynamic[z], {1, 4, 1}], Evaluate[Dynamic[Table[Sin[i*t], {i, 1, z}]]]}      So, how one plots this kind of things?


title: Creating a data1 versus data2 plot?

text: I have a table of data with multiple rows and columns, and I have to make a versus data table using two of these columns. Essentially, I have to set one column of data (column 3) as the y-axis and another column of data (column 5) as the x-axis. How do I accomplish this?


title: Efficient Table Generation & NDSolve Error

text: I'm currently working on solving an SEIR model with data from the CDC. I've created a function to calculate the Square difference for the model and want to create a table of values for the 4 variable combinations, along with their Goodness of fit characteristic from the square difference. I'm getting this alert when running the function:   " _NDSolve has computed initial values that give a zero residual for the differential-algebraic system, but some components are different from those specified. If you need them to be satisfied, giving initial conditions for all dependent variables and their derivatives is recommended._ " It sounds like something I could ignore, but I don't want to mess anything up by doing so. Also... the big question. Is there any recommendations to make creating this table of values more efficient rather than waiting a half hour for this to work itself out?               ClearAll["Global`*"]          CDCdata = {{0, 161}, {1, 197}, {2, 298}, {3, 339}, {4, 409}, {5,      614}, {6, 848}, {7, 1359}, {8, 1985}, {9, 3346}, {10, 4590}, {11,      5938}, {12, 6511}, {13, 6514}, {14, 6952}, {15, 5982}, {16,      5167}, {17, 4077}, {18, 3126}, {19, 2457}, {20, 2136}, {21,      1848}, {22, 1680}, {23, 1497}, {24, 1269}, {25, 1007}, {26,      898}, {27, 644}, {28, 459}, {29, 380}};          ListPlot[CDCdata]          p = Interpolation[CDCdata];     Plot[p[t], {t, 0, 29}]          Population = 20328;     Squarediff[Mu_, Beta_, Alpha_,        Nu_] := (sol =         First@NDSolve[{s'[t] ==             Mu*Population - Mu*s[t] - Beta*(i[t]/Population)*s[t],            e'[t] == Beta*(i[t]/Population)*s[t] - (Mu + Alpha) e[t],            i'[t] == Alpha*(e[t]) - (Nu + Mu)*(i[t]),            r'[t] == Nu*i[t] - Mu*r[t],           i[0] == 161,           s[0] == 20328,           r[0] == 0, e[0] == 0},          {s, e, i, r}, {t, 0, 29}];        Sum[(((CDCdata[[j, 2]] - i[CDCdata[[j, 1]]]) /. sol)^2), {j, 1,          Length[CDCdata]}])          values = Flatten[        Table[{{a, b, c, d}, Squarediff[a, b, c, d]}, {a, 0, 0.0005,           0.00001}, {b, 0, 0.2, 0.01}, {c, 0, 0.1, 0.01}, {d, 0, 0.1,           0.01}], 1];


title: Why does Mathematica simplify $x/x\to1$?

text: If I enter `x/x`, I get `1`. Such behavior leads to this:               Simplify[D[Sqrt[x^2], x, x]]      > 0 The same would be even if I use `Together` instead of `Simplify`. One could then think that $\sqrt{x^2}$ is doubly differentiable at least $\forall x\in\mathbb R$, but if we remove `Simplify` call, we would reveal that it's not:               D[Sqrt[x^2], x, x]      > -(x^2/(x^2)^(3/2)) + 1/Sqrt[x^2] Even more ridiculous is this (which I guess is because `x/x` is simplified before feeding to `Assuming`):               Assuming[x == 0, x/x]      > 1 Why does Mathematica assume $x\ne0$? Is there a way to make it not cancel out such terms?


title: Resources/ best practices for exploratory economic theory work

text: This is a little general, so I will try to make it as specific as possible. I used Mathematica a fair amount to derive and check analytical solutions to problems in theoretical economics. Lots of derivatives, integrals over probability distributions, root-finding, etc. I also find myself using the Manipulate[Plot] functions a lot to investigate the basic behavior and shape of equations to help conjecture solutions and outcomes. However, I feel like a large amount of what I do is an absurd kluge. My notebooks rapidly become an unreadable mess, and I often find myself accidentally clashing variable definitions or mis-specifying function definitions under Plots. I probably end up restarting the kernel 3-4 times a session just because. Some of this has improved over time simply by learning more about the language and developing my own workflow, but I feel like it's a little inefficient and that I'm probably re-inventing the wheel (octagonal wheels at that) a lot. Are there any online or printed resources for people who use Mathematica for the things I do? Alternatively, does anyone else use Mathematica for this type of exploratory work and have a short list of best practices?


title: Lists - pairing up

text: I have two (fairly large) lists of equal length & would like to pair them up. eg - from:               a = {{0, 1}, {0, 2}, {0, 3}};     b = {{1, 2}, {1, 3}, {1, 4}};      I would like to get:               {{{0, 1}, {1, 2}}, {{0, 2}, {1, 3}}, {{0, 3}, {1, 4}}}      I have looked at various thing like Tuple, but can't see a way of doing it efficiently.


title: Decimal representations of analytic values in an expansion

text: I have a solution to an ODE (which I call `sol`), which I would like to expand in terms of Log[1+x] around x=-1. I thought that:               Series[y[x] /. sol, {Log[1+x], -1, 6}]      would do the trick, but it doesn't seem to work. That isn't too much of a problem, because if I just do:                Series[y[x] /. sol, {x, -1, 6}]      and I can spot the Log terms myself. It would be very useful though if rather than having an analytic expansion (I get constants in terms of Bessel functions and so on) if I could just get numerical values (i.e. approximate decimal representations) of the terms in the expansion. For concreteness rather than: $\frac{2 (\log (x+1)+\gamma -\log (2))}{\pi }-\frac{(x+1)^2 (\log (x+1)+\gamma -1-\log (2))}{2 \pi }+O\left((x+1)^4\right)$ i'd like something like: 1.234 Log[1+x] + 23.321 (1+x)^2 Log[1+x] etc. Thankyou


title: Numerical Integration with Variable Parameters

text: So I want to numerically compute the integral of a long complicated expression over a specified domain (in this case an ellipse). I know how to use a Boole function to sample within the ellipse, but I want to pass a list of points within this ellipse into the function and have the integral be evaluated at each of these specific points. An example would be: $\frac{1}{(x \cos(\theta)+y \sin(\theta))^\frac{5}{2}} $ So I want to integrate over θ from 0 to 2 π and I want to use different points (x, y) within the specified domain when integrating. Can anyone help me with this?


title: Multiplying two dimensional data by a constant

text: I have a list of lists of the form:               {{1, 2}, {2, 4}, {2, 8}}      But I want to multiply only the second dimension of that data by a constant. I know I could do this with a loop but that is "dirty". There has to be a better way. For example if I multiply the second dimension by 2 I would get:               {{1, 4}, {2, 8}, {2, 16}}


title: How to make a notebook not savable?

text: How to make a particular notebook not savable? Optionally, how to do this by evaluating a command in the notebook?