title: Categorical Distribution

text: Suppose I want to do calculations with a random variable $X$ that has a simple categorical distribution (a.k.a generalised Bernoulli distribution or discrete distribution). I was expecting to be able to work with a distribution "symbolically". That is, I was expecting that there would be a function like `CategoricalDistribution`, that we could use like this.               distX = CategoricalDistribution[{1/3, 1/2, 1/6}];      But no distributions in tutorial/DiscreteDistributions looked like they were suitable. An example of how the distribution would be used would be               {Probability[x == 0, x \[Distributed] dist],      Probability[x == 1, x \[Distributed] dist],      Probability[x == 2, x \[Distributed] dist]}      would output > >     {1/3, 1/2, 1/6} >   In this particular case, we can do a workaround, by doing               dist = TransformedDistribution[       x1 + x2, {x1 \[Distributed] BernoulliDistribution[1/2],         x2 \[Distributed] BernoulliDistribution[1/3]}]      Unfortunately, this is not always possible, even with only 3 possible outcomes. For example, we cannot simulate `CategoricalDistribution[{1/2, 0, 1/2}]` like this, as we cannot have independent Bernoulli random variables that behave like this. I was hoping the categorical distribution might be a special case of another distribution. Especially the `MultinomialDistribution` with 1 as its first argument looks useful, but I cannot transform that distribution into a distribution that gives an integer. Again it seems like I am missing a function like `CategoricalDistribution` to do so. To give an example               Position[RandomVariate@MultinomialDistribution[1, {1/2, 0, 1/2}],        1][[1, 1]]      "has the right distribution", but unfortunately I cannot use `Position` inside `TransformedDistribution`. I am aware of functions like `RandomChoice`, but really I only want to do manipulations on distributions. Does anybody know how to do this?


title: How do I expand StirlingS2[n, 10] in terms of elementary functions?

text: I know that it is possible to expand `StirlingS2[n, 10]` in terms of elementary functions of `n`. I tried `FunctionExpand` but it returned unevaluated:               In[1]:= FunctionExpand[StirlingS2[n, 10]]     Out[1]= StirlingS2[n, 10]      Is there a way to do this in _Mathematica_?


title: Is the TCPIP link type compressed?

text: Since I'm already piping a _MathLink_ connection in a ssh tunnel (connect back is a pain!), I wonder if it makes sense to compress the data in the stream (`ssh -C`). As with any optimization matter, one should measure, but unfortunately it seems there's no way to get statistics out of `ssh` on the connection so I cannot just test and measure the gain or loss. My question is then, is it known whether this _MathLink_ type is already compressed?


title: Plotting a list in real time

text: I would like to use Mathematica for a presentation and have a list plotted in front of my audience, one coordinate at a time. How would I go about plotting a list progressively in real-time, ie the coordinates {1,y1} first, then one second after the coordinates {2,y2}, etc... ? Something with Manipulate so that I could switch on and off this option would be nice, but I don't see any function in the documentation that would let me plot lists in real time.


title: Standard message definition construct

text: Why are the messages almost always defined like this (at least in packages):               If[Not@ValueQ[function::usage], function::usage = "Usage message"]      and not just like this?               function::usage = "Usage message";      Is this some sort of safety measure in case of double loading of the package?   I also notice that error messages, coming after usage messages, are usually defined the second way.   I cannot imagine a reason why I would do that.   Are there situations when someone would like to import a package, redefine some usage messages and be sure they are not reset in case of reloading of the package?


title: Font size in PlotLegends, using Table to generate the list in the legend

text: I am currently trying to get to graph with several functions as below. My problem is that I cannot change the font size in the legend (authomatically generated numbers by "Table" function). This code below is the best what I can get. Does anyone know how to insure that also automatically generated numbers have font size of 16 (or any). ## Thanks!               <<PlotLegends`     Plot[       Evaluate[(g (-1+q)^2 (a+b+g (1-q ) s)^2)/((a+b+g-g p q)^3)                   /.{q->4/5,p->1/4,a->0.1,g->500,s->Range[0.1,3,0.4]}       ],       {b,0,100},       AxesLabel->{b,F},       PlotLabel->Style["q = 4/5, p = 1/4",FontSize->14],       PlotStyle->Directive[Thick],       PlotLegend->Table[Row[{Style["s = ",Bold,Italic,FontSize-> 16],i}],{i,0.1,3,0.4}],       LabelStyle->Directive[Italic,FontFamily->"Helvetica",FontSize->12],       LegendPosition->{0.5,-0.8}     ]


title: How to pass a list of arguments into HoldAll

text: I have a list of arguments (which in reality is lengthy):               arguments = {a, b, c}     arguments2 = {a_, b_, c_}     f[Sequence@@arguments2] := a + b + c      _Note_ : It seems awkward to define two lists here, there should be a better way to do this. And I want to numerically integrate a function of those arguments:               int[Sequence@@arguments2] := NIntegrate[f[Sequence@@arguments], {x, 0, 1}]      This does not work because of the `HoldAll` property of `NIntegrate`. Is there a way to do this correctly?


title: Reading RData files without RLink

text: I am using Mathematica 8. I would like to read some RData files which I have received. I do not currently have an installation of R on the machine with Mathematica.


title: Correct use of ListInterpolation

text: I have a small problem with `ListInterpolation`. I want to use `ListInterpolation` to postprocess result of a numerical simulation. Therefore, I give the function (2D) and its first and second derivatives to `ListInterpolation`. When I do so, it works with the method "Hermite". But if I switch to "Spline", I receive the warning, that the method "Spline" could not be used because "the data could not be coerced to machine real numbers".               A = ListInterpolation[data, {sigAxis, muAxis}, Method -> "Spline", InterpolationOrder -> 5];      > ListInterpolation::mspl: The Spline method could not be used because the > data could not be coerced to machine real numbers. I want to use "Spline" because I want to have accurate derivatives. I checked the _Mathematica_ manual and googled to learn what I have to do to ensure that the data can be coerced to machine real numbers. Unfortunately without any sucess at all. Could anyone give me some pointers?


title: Labeling individual curves in Mathematica

text: I need to create a plot for export and inclusion in a report. Is there a better way to label curves than `PlotLegends`? From what I've read and my personal experience, `PlotLegends` is pretty bad. Is there a better package for legends, or, ideally, a simply way to place small text next to each curve?


title: Legends in combined Plot and ListPlot

text: I have a set of data               plotgamma6 = {{0.1, 14/15}, {0.2, 17/20}, {0.3, 11/15}, {0.4,      43/60}, {0.5, 2/3}, {0.6, 13/20}, {0.7, 7/12}, {0.8, 17/30}, {0.9,      17/30}, {1., 31/60}, {1.1, 31/60}, {1.2, 7/15}, {1.3,      7/15}, {1.4, 9/20}, {1.5, 9/20}, {1.6, 9/20}, {1.7, 13/30}, {1.8,      5/12}, {1.9, 2/5}, {2., 2/5}, {2.1, 2/5}, {2.2, 23/60}, {2.3,      23/60}, {2.4, 11/30}, {2.5, 11/30}, {2.6, 11/30}, {2.7,      7/20}, {2.8, 1/3}, {2.9, 1/3}, {3., 1/3}, {3.1, 1/3}, {3.2,      1/3}, {3.3, 19/60}, {3.4, 19/60}, {3.5, 19/60}, {3.6, 3/10}, {3.7,      3/10}, {3.8, 4/15}, {3.9, 1/4}, {4., 7/30}, {4.1, 13/60}, {4.2,      13/60}, {4.3, 13/60}, {4.4, 13/60}, {4.5, 13/60}, {4.6,      13/60}, {4.7, 13/60}, {4.8, 13/60}, {4.9, 13/60}, {5., 13/60}};     plotgamma10 = {{0.1, 93/100}, {0.2, 89/100}, {0.3, 83/100}, {0.4,          81/100}, {0.5, 37/50}, {0.6, 18/25}, {0.7, 17/25}, {0.8,          16/25}, {0.9, 61/100}, {1., 59/100}, {1.1, 14/25}, {1.2,          14/25}, {1.3, 13/25}, {1.4, 13/25}, {1.5, 49/100}, {1.6,          23/50}, {1.7, 23/50}, {1.8, 9/20}, {1.9, 9/20}, {2.,          43/100}, {2.1, 43/100}, {2.2, 21/50}, {2.3, 41/100}, {2.4,          2/5}, {2.5, 19/50}, {2.6, 37/100}, {2.7, 9/25}, {2.8, 7/20}, {2.9,          17/50}, {3., 33/100}, {3.1, 29/100}, {3.2, 29/100}, {3.3,          29/100}, {3.4, 27/100}, {3.5, 13/50}, {3.6, 6/25}, {3.7,          6/25}, {3.8, 6/25}, {3.9, 6/25}, {4., 6/25}, {4.1, 21/100}, {4.2,          1/5}, {4.3, 1/5}, {4.4, 19/100}, {4.5, 9/50}, {4.6, 9/50}, {4.7,          4/25}, {4.8, 4/25}, {4.9, 4/25}, {5., 4/25}};      which I plot using ListPlot               Needs["PlotLegends`"]     a = ListPlot[{plotgamma6, plotgamma10}, AxesOrigin -> {0, 0},       PlotRange -> {{0, 5}, {0, 1}}, AxesLabel -> {"gamma", "quantity"},       PlotStyle -> PointSize[0.02], PlotLegend -> {"N=6", "N=10",},       LegendPosition -> {1.1, -0.4}, Joined -> {True, True},       PlotMarkers -> Automatic]      Now, I also want to plot a function which needs to be compared with the above data, i.e.,                   f[z_] := Exp[-z/2] BesselI[0, z/2];         b = Plot[-2 f'[z], {z, 0, 5}, PlotLegend -> "Theory",        LegendPosition -> {1.1, -0.4}]      Now, I want to combine these two plots into one, so I use               Show[a,b]      However, this gives a messed up plot! If I remove the plot legends from both the plots, then the combined plot looks reasonable though. But I really want to retain the plot legends. How would you combine these two plots? It doesn't matter to me how you plot these data, i.e., if you use `Show` or some other function. Please note that my question is closely related to How to show legend in a combined plot of many lists, However, that question wasn't answered fully either. Thanks! dbm368


title: Labels for each curve on a multi-curve plot using an efficient method(without writing a large code)

text: I have a question on plot labeling in _Mathematica_. I have               y = 4 x / L + 2      where               L = {10, 20, 30, 40}      I want to draw a graph of y vs. x. When I evaluate               Plot[y, {x, 0, 100},         ImageSize -> Scaled[1.0],        PlotLabel ->  Style["y vs X ", FontSize -> 18]]      I get four different lines in the same plot. I want to know how to label each line with its relevant L value; e.g., "l = 10" for the corresponding line. Could anyone please tell me how to do this?


title: How to add labels to a graph

text: This should be an easy question but since few examples are given for `ShowLegend` and I am a new user, I got stuck after many attempts. I plot three graphs which are seperately defined as `t1`, `t2`, `t3`. In each graphs there are one or two curves (Original codes to yield the graphs are complicated and not important). Then I present them in one graph, coding               graph1 = Show[t1, t2, t3, PlotRange->All]      Now I would like to add texts for identification for each curve in the graph1, in a form like                 --- x=2       ___ x=3       ''' x=4      Since the graph1 has already been plotted, `PlotLegend` may not work. I used `ShowLegend` but don't know how to establish the codes. Many thanks in advance.


title: Handling ± in a set of equations

text: First let me post the question that I am doing: ![enter image description here](http://i.stack.imgur.com/aaayQ.png) You see for wave equation y2, there is a `±` sign. I know how to do `+` or `-` at one time. Of course, I can use copy, paste and do each case separately; yet, I don't think that would be smart. I am wondering is there a way to include the both `Animation` in two graphs? (Simple and efficient code) The way I approach this problem is that first I define A1 as a constant, whose value is 1. Then I can vary the ratio of A2 versus A1. I would like apply `Animate` to variable `A2` and `δk`, because in the problem we are asked to `Animate` different amplitude ratio and phase difference. Here is my code for the `+` case:               Remove["Global`*"]          k2 = k1 + δk;          y1[x_, t_] = A1 Sin[k1 (x - v t)];     y2[x_, t_, A2_, δk_] = A2 Sin[k2 (x + v t)];          yr[x_, t_, A2_, δk_] = y1[x, t] + y2[x, t, A2, δk];          k1 = 2 π;     A1 = 1;     v = 1;          xmax = 10;     tmax = 30;     range = {{0, xmax}, {-4, 9}};          pix1[t_] := Plot[y1[x, t] + 4, {x, 0, xmax}, PlotStyle -> Red]          pix2[t_, A2_, δk_] := Plot[y2[x, t, A2, δk] + 4, {x, 0, xmax}, PlotStyle -> Blue]          pixr[t_, A2_, δk_] := Plot[yr[x, t, A2, δk], {x, 0, xmax}, PlotStyle ->Black]          plot[t_, A2_, δk_] :=        Show[{pix1[t], pix2[t, A2, δk], pixr[t, A2,δk]}, PlotRange -> range, AxesLabel -> {x, y}]          Animate[plot[t, A2, δk], {t, 0, tmax}, {A2, 1, 4, 1}, {δk, π/8, π, π/8}]


title: Series expansion using an exponential basis

text: I am currently trying to Laplace invert an expression with the following pattern $$ \frac{s \alpha \text{Cosh}[s(L-x)]+\beta \text{Sinh}[s(L-x)]}{s(\gamma \text{Cosh}[sL]+s \delta \text{Sinh}[sL])} $$ where $s$ is the complex variable and $x\in[0,L]$ a real variable; all other parameters are real constants. One path I foresee in achieving the inversion is by expressing the denominator in the form of a power series of exponential terms, as these correspond to shifts in the time domain. For instance, this approach can successfully be applied to $$ \frac{1}{s(1+\mathrm{e}^{-s})}=\frac{1}{s}\sum_{n=0}^{\infty}(-1)^n\mathrm{e}^{-ns} $$ which upon inversion yields a train of Heaviside functions $$ \mathcal{L}^{-1}\left(\frac{1}{s(1+\mathrm{e}^{-s})}\right)=\sum_{n=0}^{\infty}(-1)^n H(t-n) $$ Therefore, my question is, using Mathematica, how can I transform $(\gamma \text{Cosh}[sL]+s\delta\text{Sinh}[sL])^{-1}$ into a series of exponential functions; that is, $$ \frac{1}{\gamma \text{Cosh}[sL]+s\delta\text{Sinh}[sL]} = \sum_{n=0}^\infty a_n(s) \mathrm{e}^{-n sL} $$ Any help will be appreciated.


title: How can I add a column into a existing Dataset?

text: I'm very excited about the brand new `Dataset` function. I have played with it in Wolfram Cloud, and haven't figured out how can I add a new column into an existing `Dataset`. Here is an example:               data={<|"col1"->1,"col2"->2|>,<|"col1"->3,"col2"->4|>,<|"col1"->5,"col2"->6|>};     ds=Dataset[data]      Now I can play with `ds` columns. For example, I can easily make calculations between columns using their names like:               ds[All, (#col1+#col2&)]      > {3, 7, 11} Another way is:               ds[All, <|"col3"-> (#col1+#col2&)|>]      > <|col3->3,col3->7,col3->11|> Now, how can I update `ds`, to append the brand new calculated column as "col3"? I tried:               Join[ds,ds[All, <|"col3"-> (#col1+#col2&)|>],2]      without success. It would be magic if I could just do something like:               ds[All, "col3"]=ds[All, (#col1+#col2&)]      But it does not work either.


title: Find intersection points with V10

text: My question departs from this one: Find intersection of pairs of straight lines but now I want to find the points with the new V10 `Region`-functions.               lines =      {{Line[{{243.8`, 77.`}, {467.4`, 12.`}}], Line[{{356.8`, 32.`}, {363.2`, 120.`}}]},       {Line[{{291.8`, 130.`}, {476.`, 210.5`}}], Line[{{346.`, 245.`}, {393.8`, 158.`}}]},       {Line[{{103.2`, 327.`}, {245.2`, 110.5`}}], Line[{{163.8`, 211.5`}, {230.2`, 250.`}}]},       {Line[{{47.4`, 343.`}, {87.4`, 108.5`}}], Line[{{54.6`, 225.`}, {139.6`, 220.`}}]},       {Line[{{371.`, 506.5`}, {384.6`, 277.`}}], Line[{{366.`, 394.5`}, {451.8`, 372.`}}]},       {Line[{{264.6`, 525.5`}, {353.8`, 294.5`}}], Line[{{241.`, 398.`}, {321.`, 411.5`}}]},       {Line[{{113.2`, 484.5`}, {296.`, 304.5`}}], Line[{{163.2`, 347.`}, {213.2`, 406.5`}}]},       {Line[{{459.6`, 604.5`}, {320.2`, 466.5`}}], Line[{{332.4`, 596.5`}, {402.4`, 528.5`}}]},       {Line[{{288.2`, 630.5`}, {199.6`, 446.5`}}], Line[{{176.`, 585.5`}, {256.`, 530.5`}}]},       {Line[{{138.8`, 615.5`}, {81.8`, 410.`}}], Line[{{38.2`, 553.`}, {122.4`, 507.`}}]},       {Line[{{232.4`, 795.`}, {461.8`, 727.`}}], Line[{{345.2`, 774.5`}, {345.2`, 688.`}}]},       {Line[{{27.4`, 671.5`}, {206.8`, 763.5`}}], Line[{{104.6`, 728.`}, {161.8`, 647.`}}]}};      This function finds the points but is horribly slow:               (points = Point /@ RegionCentroid /@ DiscretizeRegion /@ RegionUnion @@@ lines); //        Timing // First      > 1.591210               Graphics[{lines, {Red, PointSize@0.02, points}}, Frame -> True]      ![enter image description here](http://i.stack.imgur.com/b7Vei.jpg) The next function finds the same points in less time (0.28 seconds), but is ugly and probably not general enough.               points = Cases[Show[DiscretizeRegion /@ RegionIntersection @@@ lines],        {a_Real, b_Real} :> Point[{a, b}], Infinity];      I hope somebody can suggest a fast and terse V10-method to find intersection points in 2 dimensions


title: Solving the magic backyard puzzle with MMA

text: I was trying to solve this puzzle using mma ![Mathematica graphics](http://i.stack.imgur.com/4Lidi.png) It looks like the generalization of the magic square. Anyway here my attempt:- There are four columns $(x,y,z,w)$ and nine rowa which are denoted by the array index. First i define the variables which have zero values               x[1] = 0; x[2] = 0; x[3] = 0; x[9] = 0; w[1] = 0;      Then the equation equating all the columns               c[1] = Sum[x[i], {i, 4, 8}];     c[2] = Sum[y[i], {i, 1, 9}];     c[3] = Sum[z[i], {i, 1, 9}];     c[4] = Sum[w[i], {i, 2, 9}];          col = Equal @@ Thread[Array[c, 4]]      Next for the rows               r[n_] := x[n] + y[n] + z[n] + w[n];     row = Equal @@ Thread[Array[r, 9]]      Here we can give some upper bound for the solutions.               all = Join[Array[x, 5, {4, 8}], Array[y, 9], Array[z, 9], Array[w, 9]];     And @@ Thread[0 <= all <= 100]      For distinct solutions:               allne = Unequal @@      Thread[Join[Array[x, 5, {4, 8}], Array[y, 9], Array[z, 9],      Array[w, 8, {2, 9}]]]      List of all variables               allvar = Join[     Join[Array[x, 5, {4, 8}], Array[y, 9], Array[z, 9],      Array[w, 8, {2, 9}]]]      Finally when I use FindInstance it just keeps running(its been 2hr now).               FindInstance[{col && row && And @@ Thread[0 <= all <= 100] &&       allne}, allvar, Integers]      So my question is why is FindInstance so slow even after putting bounds on integer solutions.Also can this be done by any other method. I also tried the simplest $3 \times 3$ magic square               FindInstance[     a + b + c == d + e + f == g + h + i == a + d + g == b + e + h ==      c + f + i && a != b != c != d != e != f != g != h != i, {a, b, c,      d, e, f, g, h, i}, Integers]      This also kept on running. Do you think that i just need to wait for the output because for these kind of sums mma will take that long?


title: How to syntax check that all instance of symbol must be contained in Subscript[]

text: I have a function `f[expr]` that is only allowed to take an expression `expr` that is a polynomial in `Subscript[x,_]`. By this, I mean that `expr` can be a sum/difference of terms (up to other multiplicative symbols) in $x_{\text{symb}}$, and symb can be any symbol (in Atomic form). The symbol $x$ cannot stand by itself, and it cannot appear inside other functions. Allowed form is: `expr = Subscript[x,i] Subscript[x,j] + b Subscript[x, k] Subscript[y, a] - 3 a Subscript[x,m]` (= $x_ix_j + b\, x_k y_a - 3\, a\, x_m$), But not   1. `expr = a Sqrt[Subscript[x,i]] + Subscript[x,j]` (Cannot be inside another function)   2. `expr = a Sqrt[Subscript[x,i]]` (same problem as 1.)   3. `expr = x + b Subscript[x,i]` (cannot be outside `Subscript`)   4. `expr = x` (same problem as 3.)   5. `expr = Subscript[x,i,j]` ($x$ cannot not have two indices)   6. `expr = $Subscript[y,x]$`. ($x$ cannot occur as an index) So, inside the body of `f`, I tried to do something like               Cases[expr, f_[x, y___] :> If[f =!= Subscript, Return[$Failed], "Pass"], Infinity]      But this misses the possibility that `x` is standing alone, outside of `Subscript`. Is there an economic way for checking if `expr` satisfies this property?


title: coding simple structures, potential problems (multithreading) and how to solve them

text: This post contains two parts. In the first part I will explain what I am trying to do. In the second part I will explain what I fear. My questions are about these fears. Are they justified and if yes how to deal with the problem? Part 1: I am developing a simple phraser package "structures`" to define structures (objects) that one can operate on. The package is to be used like this               Needs["structures`"];     beginStructure[];     defineField[f1,f2,f3];     defineMethod[        constructor[arg1_,arg2_]:=(THIS=newObject;THIS@f1=arg1;THIS@f2=THIS@f1+arg2)     ];     defineMethod[        instanceMethod[arg1_,arg2_]:=(THIS@f1=arg1;THIS@f2=arg2)     ];     ...     endStructure[];      I want to avoid this               Needs["structures`"];     beginStructure[];     ref = defineField[f1,f2,f3];     defineMethod[ref,        constructor[arg1_,arg2_]:=(THIS=newObject;THIS@f1=arg1;THIS@f2=THIS@f1+arg2)     ];     defineMethod[ref,        instanceMethod[arg1_,arg2_]:=(THIS@f1=arg1;THIS@f2=arg2)     ];     ...     endStructure[ref];      The coding of the data structure should be as automatic as possible, thus the information flow between the define... methods is done in the background. They leave traces of what they do. I want to avoid passing things explicitly around (like with the ref version). Essentially, what the functions defineMethod and defineFields do is that they operate on the body (the code) that is provided to them and they arrange things in the background. While doing that they leave traces of what they do so that all the methods (defineMethod, defineFields) can work in synergy (have to be called in the right order etc). Part 2: What worries me is multithreading (I know nothing about it, I have never used it). I would like to code all this in a safe way. I see a potential problem if the package is used in a parallel fashion, i.e. two instances of the package are run at the same time. Then it might happen that the following is effectively being executed               ...     beginStructure[];     ...     beginStructyure[];     ...     defineMethod[...];     endStructure[];      which is a disaster, since the defineMethod does not know which environment it should operate within, or depends on. (beginStructure should prepare the stage for other calls). The question: I would like to know: are my fears justified? Is it possible that such a situation occurs that the package is beingn run at the same time, in the same kernel? If not, why is it not possible? If yes, how to prevent it? I could have asked: How to make sure that a piece of code is never excecuted in parallel?, but that would be missleading. The environment is everything here.


title: How to assign Subscript[C, i] to a Sum?

text: What I want to show is:               Plot3D[       Sum[1000*Subscript[C, i]^2/(1000*Subscript[C, i] - 600)^r, {i, 1, k}],       {k, 1, 30}, {r, 0.1, 1.5}]      And, I want the list of `Subscript[C, i]` to be the elements of the subsets:               Select[Subsets[Range[30], {k}], Total[#] == 30 &]      For example, if `k = 2`, the results of               Select[Subsets[Range[30], {2}], Total[#] == 30 &]      is               {{1, 29}, {2, 28}, {3, 27}, {4, 26}, {5, 25}, {6, 24}, {7, 23}, {8,        22}, {9, 21}, {10, 20}, {11, 19}, {12, 18}, {13, 17}, {14, 16}}      Further, I want to assign `{1, 29}` to C1 and C2 of Sum firstly, and then assign `{2, 28}` to C1 and C2 of Sum secondly, etc. As a result, I will be able to get the graphic I want by `Plot3D`!


title: Find missing values in time series and fill them with Na

text: I have this list               list = {{1, 3}, {3, 7}};      representing a time series from t = 1 to t = 4. How would I go about filling the missing values so that my list looks like this in the end:               list = {{1, 3}, {2,Na}, {3, 7}, {4,Na}};      Of course, the length of my list and position of missing values might vary so I need a general function to do this, not just               Insert[list,{2,Na},2]


title: Why is Solve returning an empty list?

text: I evaluate               Solve[{-((2 (4 θ0 + θ1))/σ^2) - (2 (4 θ0 + θ2))/σ^2,             -((4 θ0 + θ1)/(2 σ^2)), -((4 θ0 + θ2)/(2 σ^2)),            -(2/σ) + (4 θ0 + θ1)^2/(2 σ^3)             + (4 θ0 + θ2)^2/(2 σ^3)} == {0, 0, 0, 0} && σ > 0,            { θ0, θ1, θ2, σ}]      and `Solve` returns `{}`. Why? Should it be able to solve the equation?


title: PDE Boundary Conditions

text: I am solving a PDE using Mathematica and I would like to know how to implement the condition that the two-variable function `y[t,s]` is zero whenever `t=s`. I tried the obvious:               u[t,t]==0      or               u[s,s]==0      but Mathematica gives me the following output:               The arguments should be ordered consistently      To be more specific, I am solving the following PDE:               NDSolve[{p3D[t, s]*D[y[t, s], t, t] - v3D[t, s]*(q^2)*y[t, s] -      r3D[t, s]*D[y[t, s], t] == 0, y[t, 0] == ysol[t], y[1, 1] == 0,      y[0, s] == 0}, y, {t, 0, 1.}, {s, 0, 1}]      Where p3D,v3D,r3D and ysol[t] are known functions. I need to include the condition I mentioned inside the NDSolve. Can I do that?


title: How to extract and assign output of Free-Form input to a variable?

text: Selecting a Free-Form input cell with the mouse I can query something like:               convert 1 atm to pascals      and get as a result               101\[ThinSpace]325\[ThickSpace]Pa (pascals)      I can take that number and manually enter it into a variable (I can't cut and paste it since the space turns the cut and pasted value into (101)(325)). Is there a way to just extract the numeric portion of the result and assign it to a variable?


title: Are there rules of thumb for knowing when RandomVariate is more efficient than RandomReal?

text: Please consider the following: From a fresh Mathematica kernel, `RandomVariate` is more efficient for `NormalDistribution` but `RandomReal` is for uniformly distributed noise.               RandomReal[NormalDistribution[0, 1], 100]; // Timing      > `{0.00535, Null}`               RandomVariate[NormalDistribution[0, 1], 100]; // Timing      > `{0.000069, Null}`               RandomReal[{0, 1}, 100]; // Timing      > `{0.00004, Null}`               RandomVariate[UniformDistribution[], 100]; // Timing      > `{0.005236, Null}` But if I re-evaluate, I get `Timing` results that are much more similar:               RandomReal[NormalDistribution[0, 1], 100]; // Timing      > `{0.000051, Null}`               RandomVariate[NormalDistribution[0, 1], 100]; // Timing      > `{0.000052, Null}`               RandomReal[{0, 1}, 100]; // Timing      > `{0.00003, Null}`               RandomVariate[UniformDistribution[], 100]; // Timing      > `{0.000058, Null}` Does caching the distribution definition really matter that much? Obviously `RandomVariate` has the advantage that it can generate data from mixed (not only fully continuous or fully discrete) distributions. So it is more general. But if one is generating random numbers from standard distributions like the normal or the Poisson, **is there any advantage – performance or otherwise – to using`RandomVariate` instead of `RandomReal` or `RandomInteger`?**


title: How to include Mathematica animation in a PowerPoint presentation?

text: **Note: Cross-posted atWolfram Community** I want to include a Mathematica animation in PowerPoint presentation. My code is:               poskus = Manipulate[       Graphics3D[        Dynamic@{{GrayLevel[.3], Line[space[[1 ;; t]]]}, {Blue,            PointSize[.015], Point[space[[t]]]},}, Axes -> True,         AxesStyle -> Directive[FontSize -> 20, FontFamily -> "Helvetica"],         AxesLabel -> {"x [nm]", "y [nm]", "z [nm]"},         BoxRatios -> {1, 1, 1}, ImageSize -> 700,         BoxStyle -> Directive[Dashed, Thick],         PlotRange -> {{-2620, 1600}, {-1700, 1450}, {-3500, 350}},         SphericalRegion -> True],        Row[{Control[{t, 1, Length[data], 1, Animator, ImageSize -> Small,            AnimationRunning -> False, AnimationRate -> 50,            AnimationRepetitions -> 1}], Spacer[10],          Dynamic["time = " <> ToString[data[[t, 1]]]]}], FrameMargins -> 0]      I want to place the animation into the PowerPoint slide so that the first frame is shown. Then I want to start it by mouse click. It should stop in the end position and wait for my next mouse click (for next slide). How can I achieve it? The best I could get was when exporting to swf. But the problem is that it runs immediately after I reach the slide. And it doesn't stop at the end, but it goes in reverse direction and then forward ... It is also very fast. And my computer becomes slow. The file size (test.swf) is 146 KB. Some things I would like to know:   * How to export without the sliders showing   * which format best to use   * how to influence the frame rate, length and direction of the animation   * how to most conveniently integrate the animation into PowerPoint **Edit** Sample of my data: first column is time multiplied by a factor, the others are coordinates.               data={{0.146, -160.582, 125.712, 20.1735}, {0.288, -192.582, 182.712,        58.1735}, {0.431, -207.582, 237.712, 201.174}, {0.576, -250.582,        134.712, 162.174}, {0.723, -234.582, 226.712,        292.174}, {0.877, -259.582, 236.712, 175.174}, {1.02, -303.582,        241.712, 61.1735}, {1.16, -362.582, 282.712,        17.1735}, {1.3, -448.582, 268.712, 114.174}, {1.45, -309.582,        188.712, 87.1735}, {1.58, -275.582, 193.712,        31.1735}, {1.73, -142.582, 182.712, -67.8265}, {1.88, -296.582,        257.712, -41.8265}, {2.02, -412.582,        307.712, -80.8265}, {2.16, -389.582,        366.712, -119.826}, {2.31, -337.582,        402.712, -273.826}, {2.46, -470.582,        499.712, -179.826}, {2.6, -432.582,        546.712, -208.826}, {2.76, -386.582,        539.712, -339.826}, {2.9, -467.582,        429.712, -377.826}, {3.05, -479.582,        462.712, -338.826}, {3.18, -514.582,        383.712, -239.826}, {3.32, -592.582,        279.712, -169.826}, {3.46, -574.582,        313.712, -134.826}, {3.61, -575.582,        262.712, -198.826}, {3.74, -542.582,        269.712, -241.826}, {3.89, -570.582,        201.712, -179.826}, {4.04, -637.582,        156.712, -128.826}, {4.19, -784.582, 155.712,        30.1735}, {4.33, -837.582, 212.712, 31.1735}, {4.48, -750.582,        144.712, -121.826}, {4.62, -858.582, 110.712,        58.1735}, {4.76, -880.582, 41.7125, -70.8265}, {4.89, -884.582,        117.712, -171.826}, {5.04, -874.582,        56.7125, -209.826}, {5.2, -924.582, -11.2875, -228.826}, {5.35, \     -896.582, -38.2875, -270.826}, {5.5, -869.582, -44.2875, -317.826}, \     {5.64, -915.582, -132.288, -221.826}, {5.8, -971.582, -51.2875, \     -349.826}, {5.94, -992.582, -95.2875, -377.826}, {6.08, -1060.58, \     -5.2875, -266.826}, {6.23, -1054.58,        3.7125, -431.826}, {6.38, -1099.58,        31.7125, -505.826}, {6.53, -1211.58,        85.7125, -477.826}, {6.68, -1203.58,        108.712, -508.826}, {6.83, -1001.58,        67.7125, -649.826}, {6.98, -1051.58, -1.2875, -675.826}}


What is the complete list of valid Front End Tokens? Preferably, by version number.


title: Solve in terms of specific variables

text: As part of my physics homework (which I do not need the answer for, as I did it by hand, and got the correct $$\frac{m_1 g-m_2 g \sin(\theta)}{-m_1-m_2}$$ as the answer) I would have liked to have solved the following system of equations as shown (i.e. put $a_1$ as `Subscript[a,1]` and not `a1` or something similar. The equations that I wanted to solve were:   1. `Subscript[m, 2] Subscript[a, 2 x] == T - Subscript[m, 2] g Sin[\[Theta]]`   2. `Subscript[m, 1] Subscript[a, 1 y] == T - Subscript[m, 1] g`   3. `Subscript[a, 2 x] == -Subscript[a, 1 y]` I tried the following, and was given `{}` as the answer (which is clearly false): `Solve[Subscript[m, 2] Subscript[a, 2 x] == T - Subscript[m, 2] g Sin[\[Theta]] && Subscript[m, 1] Subscript[a, 1 y] == T - Subscript[m, 1] g && Subscript[a, 2 x] == -Subscript[a, 1 y], Subscript[a, 1 y]]` It seems that there at least two problems with the equations that I am asking it to solve.   1. I do not think that it is treating $a_{1y}$ as a variable. When I typed a in the part of solve that asks for the variables that I am solving for, all terms that have `a` in them light up as blue, but when I enter the subscript, it loses that highlighting.   2. It would seem (at least to me) that a perfectly valid answer to `Solve` would be $-a_{2x}$ but that would be a useless answer, as I want the answer in terms of $m_1 , m_2 , g, \theta$ and not in terms of other "compound variables" **Note:** When I tried a "subscript-less" version (`Solve[m2 a2x == T - m2 g Sin[\[Theta]] && m1 a1y == T - m1 g && a2x == -a1y, a1y]` I still got `{}` as the answer. Using Mathematica 8. What is going on, and how can I enter the equations normally, and solve for them in terms of specific variables?


title: Third argument of Compile

text: In his last comment on this answer, halirutan shows an example in which the third argument of `Compile` does not have any effect. The example is as follows.               cfu = Compile[{}, Module[{y = {}}, AppendTo[y, 1]], {{y, _Integer, 1}}];     cfu[]      Outputs > >     {1.} >   rather than `{1}` Does anybody know an example where using the third optional argument of `Compile` does have an effect?


title: Plot graphs with direction and numbered in Mathematica

text: I would like to write a code in _Mathematica_ such that it shows the direction with numbers on points. I wrote this code which does not do this. I want just to complete this code with two options I told. Any Idea. thanks.               ListPolarPlot[{Table[{2^n, 1}, {n, 1, 6}]}, Joined -> True,PlotStyle -> {Blue, Red, Green, Yellow, Gray}, Mesh -> All, MeshStyle -> Red]      ![enter image description here](http://i.stack.imgur.com/OEtml.jpg)


title: Transform an expression into a graph that can be plotted with TreeGraph (not TreeForm)

text: I would like to plot an expression (like `TreeForm` does), but using the new `TreeGraph` functionality. `TreeGraph` takes as input a set of edges (of the form `a -> b`), so it seems that to solve the problem it is necessary to turn an expression into a set of edges. For example `Sin[Plus[a, b]]` would need to be transformed into: `{Sin -> Plus, Plus -> a, Plus -> b}`. How can this transformation be done for any _Mathematica_ expression? Thanks!


title: Detect a graphic primitive inside a Graphic

text: Please excuse me if that question is too basic but I couldn't find anything in the documentation or on here. If you consider the following `Graphic` I would like to know how to detect which primitive is being clicked,               Graphics[{Disk[#, 0.5]} & /@ {{0, 0}, {1, 0}}]      ![enter image description here](http://i.stack.imgur.com/06rIn.png) and for example change the color of the clicked `Disk`, change its radius or get the coordinates of its center or anything related to its geometry. I am aware that `EventHandler` is my friend but as the questions states, I have no clue how to detect which primitive is being clicked (except by using `Mouseposition` and compare it to the centers). I am also aware that my question is somehow poorly researched but I feel like I'm blocking on a basic notion.


title: Elegant way to do series expansion around x+$\epsilon$

text: Suppose I have a function $p(x+\epsilon,y-\epsilon,t)$, and I want to expand it around $(x,y)$ like $$ p(x+\epsilon,y-\epsilon,t)=p(x,y,t)+\dfrac{\partial p}{\partial x}\epsilon+\dfrac{\partial p}{\partial y}(-\epsilon)+\cdots $$ A naive way to do it is               Series[p[x+e,y-e,t],{x+e,x,1},{y-e,y,1}]      which will result in the following error message:               General::ivar: "e+x is not a valid variable."     ....      Right now I do the expansion in the following clumsy way:               Replace[     Normal@Series[p[x, y, t], {x, a, 1}, {y, b, 1}],      {x - a -> \[Epsilon], y - b -> -\[Epsilon]},      Infinity]      /. {a -> x, b -> y}      **Question** : Is there an elegant way to do it? In the end, I want to expand $p(x,y,t)$ in $$ -(x+z)p(x,y,t)+(x+\epsilon)p(x+\epsilon,y-\epsilon,t)+(1-x-y+\epsilon)p(x,y-\epsilon,t) $$ and keep only the $\epsilon$ terms.


title: How can I forecast time series data with cellular automata?

text: I have a time series data, for example               data = FinancialData["JK:ADRO", "July 16 2012"]      Can I use `CellularAutomaton` to forecast some period of data? How would I go about doing that?


title: Wavelet expansion of given function (as opposed to DWT of given data)

text: To illustrate, say I take the following function (the reason for the square root will be apparent soon)               dist = NormalDistribution[0.5,0.1];     f[x_] := Sqrt[PDF[dist,x]];      Then I can grab the Haar wavelet to calculate coefficients like               data = Table[Evaluate@f[x], {x,0,1,1/31}]; (* 32 equally spaced points *)     dwt = DiscreteWaveletTransform[data, HaarWavelet[], 5];      If I then take squares of coefficients, because of $$ \sum _{j=J_o}^{J_1} \sum _{k\in \mathbb{Z}} \psi _{j,k}^2+\sum _{z\in \mathbb{Z}} \varphi _{J_0,k}^2\simeq \int f^2 (x) \, dx = \left\| f\right\| ^2 $$ I should get $\simeq 1.0$ as $f$ is, in this case, the square root of a probability density function. And it kind-of works; to wit:               Total[Flatten[Last[#] & /@ dwt[Automatic]]^2]/31      returns 1.0 (`dwt[Automatic]` gives you the coefficients for the inverse transform only; see here). This should be very close to `NIntegrate[Evaluate@f[x]^2, {x, 0, 1}]`, which is _0.999999_. However, note that "/31"! Where did that come from? This is: that `1/31` does not appear in the Parseval's identity but it is needed for the calculation to work (!) And if I change `HaarWavelet[]` by `DaubechiesWavelet[]`, say, then this _data sampling_ no longer works. I am even taking care of the fact that the Daubechies family has bigger support and for that I am using the following function to determine the number of points required as:               dataSize[wave_, 1] :=       Length[WaveletFilterCoefficients[wave, "PrimalLowpass"]];     dataSize[wave_, n_Integer /; n > 1] :=       2 dataSize[wave, n - 1] -        Length[WaveletFilterCoefficients[wave, "PrimalLowpass"]] + 2;      What I am doing wrong? ( _Why this?_ You may ask. For example, one could use wavelet expansions to calculate the norm (in Hilbert space) between two functions, or a function and some other approximation; instead of attempting `NIntegrate`. By the way, I am actually interested in dimensions greater than 1) **Note:** I am only interested in _orthogonal_ wavelets; Parseval's formula should be just ok as far as I know. **UPDATE** I modified `dist` to `NormalDistribution[0.5,0.5]`. In this case, one needs a longer interval `{x,-2,3}` to effectively cover $f$. In this case, the squared coefficients are added like **5**`Total[Flatten[Last[#] & /@ dwt[Automatic]]^2]/31` (note the factor 5.) This points me to the fact that the $x_i$ sample points are usually considered as in the `[0,1]` interval (if I remember correctly), therefore the final answer needs to be _rescaled_ by 5. Still... work in progress.


title: FindRoot on a 2D list of Equations

text: I have a $n \times k$ Matrix of data that I want to feed into an equation and solve for an unknown variable. I suppose I can always just convert the Matrix into a long Array but I'd like to learn how to do this while keeping the data structure as is. I want to be able to solve $n \times k$ `FindRoots` in one shot and mimicking some code from MMA.SE this is what I have managed.               f = x^(Mod[a, 3]) + b     a = {{2, 5, 8}, {1, 4, 7}};     b = {{-3, -5, -7}, {3, 5, 7}};     eqn = Table[(#[[j]] == 0), {j, 1, Dimensions[f][[2]]}] & /@ (f)     {{-3 + x^2 == 0, -5 + x^2 == 0, -7 + x^2 == 0}, {3 + x == 0, 5 + x == 0, 7 + x == 0}}     Table[FindRoot[#[[i]], {x, 1}] & /@ eqn, {i, 1, Dimensions[f][[2]]}]     {{{x -> 1.73205}, {x -> -3.}}, {{x -> 2.23607}, {x -> -5.}}, {{x -> 2.64575}, {x ->7.}}}      As you can see, this works but is a kind of a mess. I am hoping I can be helped in the direction of a cleaner, better code and learn how to use pure functions on n-dimensional lists. Thanks.


title: FindFit::nrlnum What am I doing wrong?

text: I have a model called qobs:               qobs=0.039 ns (T (8.314 + (8.314 - 8.314 m) Hypergeometric2F1[1., 1/m,          1. + 1/m, (ns/ns∞)^m] +        8.314 Log[-1. (A E^((0.120279 ΔE)/T))^(-1./           m) (-1. + 1/(1. - 1. (ns/ns∞)^m))^(-1./           m) (1/(-1. + 1. (ns/ns∞)^m))^1. (ns/           ns∞)^(1. m) Psat[T]]) + 1. λp[T])      I have a set of data with two independent variables (ns and T):               Data = {{0, 85, 0}, {0.131592244, 85, 69.07308925}, {0.230286428, 85,      115.4518887}, {0.255592629, 85, 126.8281889}, {0.382123633, 85,      181.8483799}, {0.426409484, 85, 200.2798617}, {0.516246497, 85,      237.7531003}, {0.60102227, 85, 271.3000332}, {0.642777502, 85,      288.766803}, {0.749063545, 85, 329.4612163}, {0.760451336, 85,      332.9712438}, {0.762981956, 85, 334.6336615}, {0, 100,      0}, {0.074653293, 100, 39.4734225}, {0.111347284, 100,      57.64231052}, {0.127796314, 100, 65.7007577}, {0.212572087, 100,      104.7308741}, {0.269511039, 100, 130.1461666}, {0.29481724, 100,      141.0225864}, {0.408695144, 100, 189.1969421}, {0.523838358, 100,      236.109073}, {0.536491458, 100, 241.0802459}, {0.551675179, 100,      247.1796371}, {0.58710386, 100, 261.1558457}, {0.632655021, 100,      278.7613986}}      Other known values within the model are:               λp[85] = 6540     λp[100] = 6540     Psat[85] = 78896.6     Psat[100] = 323767     R = 8.314      I have tried using FindFit:                FindFit[Data, qobs, {ns∞, m, A, ΔE}, { ns, T}]      And I get the error code:               FindFit::nrlnum: "The function value {0.,-69.0731+0.0051321\ (85.\ (8.314 +8.314\ Log        [<<1>>])+1.\ λp[85.]),<<21>>,-261.156+0.0228971\ (100.\ (8.314 +8.314\ Log     [<<1>>])+1.\ λp[100.]),-278.761+0.0246735\ (100.\ (8.314 +8.314\ Log[<<1>>])+1.     \ λp[100.])} is not a list of real numbers with dimensions {25} at {ns     ∞,m,A,ΔE} = {1.,1.,1.,1.}. "      I found, what I thought was a similar problem here how to avoid inducing complex numbers in FindFit In particular the answer suggested by Oleksandr R. which involves splitting the model into explicitly real and imaginary parts and changing the data to force the imaginary part of the model to go to zero. Hence I changed my model to:               ComplexModel = Inner[#1[qobs] KroneckerDelta[i, #2] &, transformation,      Range@Length[transformation]]      where               transformation = {Re, Im}      and I reformatted my data to:               ComplexData = {{1, 0, 85, 0}, {1, 0.131592244, 85, 69.07308925}, {1,      0.230286428, 85, 115.4518887}, {1, 0.255592629, 85,      126.8281889}, {1, 0.382123633, 85, 181.8483799}, {1, 0.426409484,      85, 200.2798617}, {1, 0.516246497, 85, 237.7531003}, {1,      0.60102227, 85, 271.3000332}, {1, 0.642777502, 85, 288.766803}, {1,     0.749063545, 85, 329.4612163}, {1, 0.760451336, 85,      332.9712438}, {1, 0.762981956, 85, 334.6336615}, {1, 0, 100,      0}, {1, 0.074653293, 100, 39.4734225}, {1, 0.111347284, 100,      57.64231052}, {1, 0.127796314, 100, 65.7007577}, {1, 0.212572087,      100, 104.7308741}, {1, 0.269511039, 100, 130.1461666}, {1,      0.29481724, 100, 141.0225864}, {1, 0.408695144, 100,      189.1969421}, {1, 0.523838358, 100, 236.109073}, {1, 0.536491458,      100, 241.0802459}, {1, 0.551675179, 100, 247.1796371}, {1,      0.58710386, 100,      261.1558457}, {1, 0.632655021, 100, 278.7613986} {2, 0, 85, 0}, {2,     0.131592244, 85, 0}, {2, 0.230286428, 85, 0}, {2, 0.255592629, 85,     0}, {2, 0.382123633, 85, 0}, {2, 0.426409484, 85, 0}, {2,      0.516246497, 85, 0}, {2, 0.60102227, 85, 0}, {2, 0.642777502, 85,      0}, {2, 0.749063545, 85, 0}, {2, 0.760451336, 85, 0}, {2,      0.762981956, 85, 0}, {2, 0, 100, 0}, {2, 0.074653293, 100, 0}, {2,      0.111347284, 100, 0}, {2, 0.127796314, 100, 0}, {2, 0.212572087,      100, 0}, {2, 0.269511039, 100, 0}, {2, 0.29481724, 100, 0}, {2,      0.408695144, 100, 0}, {2, 0.523838358, 100, 0}, {2, 0.536491458,      100, 0}, {2, 0.551675179, 100, 0}, {2, 0.58710386, 100, 0}, {2,      0.632655021, 100, 0}}      I tried to use FindFit again:               FindFit[ComplexData, ComplexModel, {ns∞, m,      A, ΔE}, {i, ns, T}]      however I am still getting an error code:               FindFit::nrlnum: The function value {0.,-69.0731+0.0051321 Re[85. (8.314 +Times     [<<2>>])+1. λp[85.]],<<45>>,0. +0.0228971 (831.4 Im[Log[Times[<<2>>]]]+1. Im     [λp[100.]]),0. +0.0246735 (831.4 Im[Log[Times[<<2>>]]]+1. Im[λp     [100.]])} is not a list of real numbers with dimensions {49} at {ns∞,m,A,     ΔE} = {1.,1.,1.,1.}. >>      Any help would be greatly appreciated.


title: why mathematica outputs "TRUE" sometimes in outputs that are conditional to mean "in all other cases"?

text: consider this simple Input:               Probability[g <= m && m <= -g + 1,       {m, g} \[Distributed] UniformDistribution[{{0, 1}, {0, gg}}]]      which generates a piecewise continuous function: $$\begin{cases} 1-gg & gg\le\frac{1}{2}\\\ \frac{1}{4\,gg} & \text{True} \end{cases}$$ My question is: why does mathematica outputs `True` rather that `gg>1/2`?


title: Using FindFit for step functions

text: Having used `FindFit` like so:               x = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11};     y = {17, 14, 11, 11, 10, 10, 9, 9, 9, 9};     data = Transpose[{x, y}];          model = a Zeta[b n + c]     fit = FindFit[data, model, {a, b, c}, n]     modelf = Function[{n}, Evaluate[model /. fit]]          Plot[modelf[x], {x, 0, 11}, Epilog -> Map[Point, data], PlotRange ->      {{0, 11}, {0, 50}}, AspectRatio -> Automatic]      with a relatively small data set, I took the average a, b & c (which were all very close) (n clearly followed a linear trend) & came up with a step function that plotted the following against the original data points: ![enter image description here](http://i.stack.imgur.com/1yBBj.gif) Plotted with:               x = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11};     y = {17, 14, 11, 11, 10, 10, 9, 9, 9, 9};     data = Transpose[{x, y}];     n = 10;     ListLinePlot[Round[Table[     (n - 1) Zeta[(Cos[1/2] + Sin[1/2]) + (Cos[1/2] - Sin[1/2]) (x)], {x, 0, 20}], 1],       InterpolationOrder -> 0, PlotRange -> {{1, 12}, {0, 70}}, Frame -> True,      AspectRatio -> Automatic, Filling -> Bottom, ImageSize -> 100,      Epilog -> {PointSize[Medium], Red, Point[data]}]      Is there any way I can improve the accuracy of these plots? Do I have any hope of finding the _exact_ step function, or am I being a little optimistic? Original data set:               x = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11};      where x is the same for all               y = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};     y = {2, 1, 1, 1, 1, 1, 1, 1, 1, 1};     y = {4, 3, 2, 2, 2, 2, 2, 2, 2, 2};     y = {6, 5, 4, 3, 3, 3, 3, 3, 3, 3};     y = {7, 6, 5, 5, 4, 4, 4, 4, 4, 4};     y = {8, 7, 7, 6, 5, 5, 5, 5, 5, 5};     y = {12, 8, 8, 7, 7, 6, 6, 6, 6, 6};     y = {13, 10, 9, 8, 8, 7, 7, 7, 7, 7};     y = {15, 13, 10, 10, 9, 8, 8, 8, 8, 8};     y = {17, 14, 11, 11, 10, 10, 9, 9, 9, 9};     y = {18, 15, 13, 12, 11, 11, 10, 10, 10, 10};     y = {20, 16, 14, 13, 13, 12, 11, 11, 11, 11};     y = {23, 18, 15, 14, 14, 13, 12, 12, 12, 12};


title: Modify a sub-part of a sub-list only

text: I have this list:               a = {{{0, 0}, {1, 7}, {2, 0}, {3, 2}, {4, 7}}, {{0, 0}, {1, 0}, {2, 1}, {3, 2}, {4, 7}}}      and I'd like to transform it to this:               a = {{{0, 0}, {1, 7}, {2, Na}, {3, 2}, {4, 7}}, {{0, 0}, {1, Na}, {2, 1}, {3, 2}, {4, 7}}}      ie I'd like to replace every 0 by Na except in the first sub-sub-list of each sub-list. All I can come up with is:               Part[#, 2 ;; All, All] & /@ a  /. 0 -> Na      and it works I get               {{{1, 7}, {2, Na}, {3, 2}, {4, 7}}, {{1, Na}, {2, 1}, {3, 2}, {4, 7}}}      but the modification is not attributed to `a`. How can I do that?


title: Adjusting placement of control objects in a row within a panel

text: My minimal example               Panel[Column[{        Row[{"Board size: ", InputField[Dynamic[max], Number, FieldSize -> 3],           Button["Clear Board"]}], "A graphic object which is large enough"}]]      evaluates to ![enter image description here](http://i.stack.imgur.com/Bzkoi.jpg) Since I have a large graphic object underneath the first row, there is some space to the right of the "Clear Board" button. I would like to move the button to the right so that it is flush with the boundary of the panel -- basically the effect of the LaTeX command `\hfill` if I were typesetting. I have been messing with `Alignment` and `ControlPlacement`, but no luck so far.


title: Changing the Actions in EventHandler

text: I would like to be able to change which action specified events take depending on some condition. For example, I have established a `SetterBar`               SetterBar[Dynamic[setter], {Zoom, Pan}]      and created a graphic that I would like the left mouse button to cause to either zoom or pan, depending on what the value of `setter` is when the event occurs.               DynamicModule[{frac = 0, zoomval = 7*Pi/36, drag = {0, 0},      pt = CurrentValue[ImageSize], CurrentPosition = {1/2, 1/2},      panvalue = {0, 0}},      EventHandler[     Dynamic[Show[graphics,      ViewCenter -> {{1/2, 1/2,         1/2}, {x = CurrentPosition[[1]] + panvalue[[1]],         y = CurrentPosition[[2]] - panvalue[[2]]}},      ViewAngle -> (Which[drag[[2]] > 0,         zoomval = Min[Pi*0.7, zoomval + frac*(Pi - zoomval)],         drag[[2]] < 0,         zoomval = Max[zoomval - frac*(Pi - zoomval), 0.2],         drag[[2]] == 0, zoomval = zoomval]),      RotationAction -> "Clip"]], {{"MouseDown",       1} :> (a = CurrentValue[MousePosition]), {"MouseDragged",       1} :> {Which[       setter == Zoom, {b = CurrentValue[MousePosition], drag = b - a,         frac = 0.5 Norm[drag]/Norm[pt]},        setter == Pan, {b = CurrentValue[MousePosition], drag = b - a,         panvalue = {drag[[1]]/(pt[[1]]),           drag[[2]]/(pt[[2]])}}]}, {"MouseUp", 1} :> {frac = 0,       drag = {0, 0}, panvalue = {0, 0}, CurrentPosition[[1]] = x,       CurrentPosition[[2]] = y}}]]      This may be a little difficult to follow, but esentially I want the `Which` function to alter the action taken by the event `"MouseDragged"` depending on if setter is set to Zoom or Pan. Currently, everything works when the value is set to Zoom, but no action occurs upon setting the value to Pan. Also, `graphics` is simply a red cylinder created for example.               graphics = Graphics3D[{Red, Cylinder[]}];


title: Import a file only if it contains a certain pattern

text: Let's say I have three files containing:               File 1:     x y z     1 4 6           File 2:     x y z     2 5 9           File 3:     x y z     5 4 8      My goal is to import the data from a file only if in this file `y == 4` (so here I would want to import files 1 and 3). Is there a way to do that with functional programming? The only solution I can think of currently is to loop through all the files, check if `data[[2, 2]] == 4`, and append this data to a list if true. Is there a better way to do that? And if I have to loop, is it better to import all the files as lists and then discard the lists that do not match `y == 4`? Or is it better to import only the files matching `y == 4` in the first place?


title: Mathematica Precision

text: How can I set the output precision of the following statement to 10 decimal places? I was looking through the documentation, and for some reason, all I could find was `Accuracy[]` or `Precision[]`.               f[x_] := E^Cos[x]     NIntegrate[f[x], {x, 0, 2*Pi}]      Which, by default, evaluates to:               7.95493      Thank you for your time.


title: Finding all length-n words on an alphabet that have a specified number of each letter

text: For example, I might want to generate all length `n=6` words on the alphabet `{A, B, C}` that have one `A`, three `B`'s and two `C`'s. An example of such a word is: `'ABBBCC'`. I'd like to generate all such words. I've already tried generating all permutations of a particular string (like `'ABBBCC'`) and deleting all duplicates. This is too slow for my purposes.


title: Inheriting Stylesheets when using CreateDocument

text: I build a lot of presentations and custom notebooks with very different stylesheets, and use `Button` and `CreateDocument` quite often to accommodate optional/procedurally generated content. For instance,               Map[Button[Style[ToString[#] <> " random images", "Text"],             CreateDocument[               {Cell["Here are " <> ToString[#] <> " random image(s)", "Title"],                             ExpressionCell[Column@Table[RandomImage[2, {200, 200}], {#}],                "Output"]}]] &,        Range[5]]      What I'd like to do is specify that the notebook generated by `CreateDocument` inherits the StyleSheet from the parent notebook, without having to save the StyleSheet and provide the `StyleSheetPath` Option in the `CreateDocument` function each time I change a style. I imagine there's an undocumented feature, but haven't found it in my brief searches of StackExchange.


title: Having the derivative be an operator

text: How do I create an operator which acts like a derivative to everything to the right of it: for example: $ \left( \partial_x + \partial_y + z \right ) x \psi $ How do I make that evaluate to: $x \partial_x \psi + \psi + x \partial_y \psi + z x \psi $ (I want the derivatives to distribute...)


title: RandomReal closed on left & open on right?

text: I have a number of algorithms that depend on uniform random reals in half-open intervals such as $[0,1)$. In particular, I need a (pseudo) random-number generator that produces machine-precision numbers in the range $0.0$ to $1-\epsilon$. It can return $0.999...$, but will never return exactly $1.0$. I haven't found in the Mathematica documentation whether Mathematica's `RandomReal` satisfies this requirement. The documentation does state that `RandomInteger[{xMin,xMax}]` produces values in the double-closed interval $[x_{min}, x_{max}]$ inclusive of both ends, but I haven't found an equally clear statement about the real-number generators. The documentation that I've read just says "between 0 and 1." I could read this as double-open, but it really isn't precise enough for me. I would be grateful for an authoritative answer.


title: How to prove an expression by method of mathematical induction?

text: I want to prove the expression $$1^2 + 2^2 + 3^2 + \cdots + n^2 = \dfrac{n(n+1)(2n+1)}{6}$$ by method of mathematical induction with Mathematica, but I do not know how to start. How do I tell Mathematica to do that?


title: MatchQ and patterns for similar lists

text: I can't seem to find the right set of patterns to independently match two different lists. Simplified versions of the lists are as follows:               list1 = {{2}, {2}, {20}, {2}, {10}}     list2 = {{2}, {2}, {2}, {2}, {2}, {2}}      In general, the second list will always have the same number inside the parentheses. They can have different lengths. Both will have just a single number inside the parentheses. I am trying to find two patterns (`p1`,`p2`):               p1 = {{s_?NumericQ} ..};     p2 = {{_?NumericQ} ..};      Such that               {MatchQ[list1,p1],MatchQ[list1,p2],MatchQ[list2,p1],MatchQ[list2,p2]}      Gives               {True, False, False, True}      My test patterns give `{True, True, False, True}` instead. I'm sure the answer is easy, but I just can't get it right...


title: Shading in squares crossed by a diagonal

text: You have a rectangle and it is diagonal. How many squares will be crossed by the diagonal (I guess assuming the side length of the rectangle are nice whole numbers) I've seen an implementation in Geogebra to shade in the squares that are crossed by the diagonal of a rectangle. I'd really be happy to see how to do this using Mathematica, it would help me learn a lot. But it's beyond me right now. Here is my "start"....               Manipulate[ Module[{length, width},              length = Round[p[[1]]];         width = Round[p[[2]]];              Graphics[{              {GrayLevel[0.8],           Line /@ Table[{{i, 0}, {i, 20}}, {i, 0, 20}],          Line /@ Table[{{0, i}, {20, i}}, {i, 0, 20}]},              (*rectangle to mark off area*)         {Line[{{0, 0}, {Round[p[[1]]],              0} , Round[p], {0, Round[p[[2]]]}, {0, 0}}]},              (*point to control rectangle*)         {Blue, AbsolutePointSize[8],           Point[Round[p]]},              (*diagonal*)         Line[{{0, 0}, Round[p]}]              },             PlotRange -> {{-0.1, 20.1}, {-0.1, 20.1}},        ImageSize -> {800, 640}]],      {{p, {1, 1}}, {0, 0}, {20, 20}, Locator, Appearance -> None}     ]      ![Mathematica graphics](http://i.stack.imgur.com/0f1nT.png) Any help would be appreciated.


title: How to pull scalars out of a function that should act on lists?

text: Suppose I have               A = a vecA     B = b vecB      where `a` and `b` are supposed to be arbitrary scalars and `vecA={vA1,vA2}` and `vecB={vB1,vB2}` are vectors, i.e. lists (I guess from a mathematica point of view the difference is that a and b have Head `Symbol`, whereas vec1 and vec2 have head `List`?). Now imagine an arbitrary function of two arguments `f[A,B]`. What I would like to do is to pull out the scalars and multiply them:               f[A,B] -> a * b * g[vecA,vecB]      where g[vecA,vecB] is again an arbitrary function that only works on vectors (lists). How can I achieve that? The background is that I would like to process (simplify, rearrange, expand in series, etc.) expressions that mix scalars and vectors and contain inner products of such mixtures without explicitly expanding the inner products into the components of the vectors. Such that I can later on easily replace occurrences of some inner products. See also my (not yet really solved) question: Symbolically associate vectors and their norms My current take on this is to use               Inner[f,A,B]      instead of `Dot[A,B]` such that the inner product is not explicitly expanded into components. However I do need to pull out the scalars somehow..


title: How do I define the "Coupon" within the function FinancialBond with a time-varying coupon

text: Is it possible using `FinancialBond` function to calculate the yield of a bond paying a gradual coupon ? An example : > A bond with maturity of 7 years pays 4.125% the first 3 years, then 6% the > next two and finally 7.75% the last two. The actual price of the bond is > 102.35% and it is redeemed at par. I know the answer using `TimeValue` and `Cashflow` functions. It is 5.14601% But I want to know if it is possible to calculate it straight from the `FinancialBond` function.


title: making a TreeGraph VertexLabel that contains a text label and also a Tooltip?

text: I am trying to make a TreeGraph[] that has as labels for vertices both text and Tooltip. The text displays all the time, when the `TreeGraph` is plotted, and in addition, when the mouse moves over the vertex, another text shows up using `Tooltip` (may be below the static text, but I'll worry about this later). This Tooltip text will contain more information about the node. Right now, I can do each one of the above separately but can't figure how to combine them. I'll show my attempts below. This is all using V9 ### Tooltip shows up when mouse on vertex               TreeGraph[{1, 2, 3}, {1 -> 2, 1 -> 3},      VertexLabels -> {"Name", 3 -> Placed["equation 1", Tooltip]},       ImagePadding -> 20]      ![enter image description here](http://i.stack.imgur.com/W3WTT.png) ### standard vertex label               TreeGraph[{1, 2, 3}, {1 -> 2, 1 -> 3},      VertexLabels -> {"Name"}, ImagePadding -> 20]      ![Mathematica graphics](http://i.stack.imgur.com/2FHgK.png) # Attempts to combine them I noticed that it says in the help that any expression can be used as label: ![Mathematica graphics](http://i.stack.imgur.com/QiH3i.png) ### attempt 1 Since any expression can be used as label, then I tried `Column`               TreeGraph[{1, 2, 3}, {1 -> 2, 1 -> 3},      VertexLabels -> {"Name",         3 -> Column[{"3", Placed["equation 1", Tooltip]}]},       ImagePadding -> 20]      Which does not work. ![Mathematica graphics](http://i.stack.imgur.com/WOtqH.png) ### attempt 2               TreeGraph[{1, 2, 3}, {1 -> 2, 1 -> 3},      VertexLabels -> {"Name",         3 -> Labeled[Placed["equation 1", Tooltip], "3"]},       ImagePadding -> 20]      ![Mathematica graphics](http://i.stack.imgur.com/RiMbR.png) ### attempt3 The strange thing is that one can add a button that changes the color of the node and speaks when clicked and also add a Tooltip at the same time, but so hard to add a text in addition to Tooltip               TreeGraph[{1, 2, Button[Style[3, Red], Speak["Vertex 3"]]}, {1 -> 2,        1 -> 3}, VertexLabels -> {"Name",         3 -> Placed["equation 1", Tooltip]}, ImagePadding -> 20]      ![Mathematica graphics](http://i.stack.imgur.com/E4hdT.png) Tried maybe another 10 different ways, too boring to show. So I gave up. I am a newbie in using Graphs in Mathematica, only today I started looking at them. **Question** How make a label for Vertex and also show Toolip when mouse is on Vertex?


title: how can I avoid CPU waste (by master kernel) using WaitNext?

text: I'm using `WaitNext` in _Mathematica_ for parallel processing on Mac OS X. I have 4 processors on my MacBook and `LaunchKernels[]` has launched 4 kernels in _Mathematica_ , in addition to the master kernel. However, each of these 4 kernels gets approximately 75-80% of a processor, while the master kernel gets 70-75%. It seems to me that the master kernel should be just waiting, instead of using CPU. The relevant code is               While[Length[parallelJobs] > 0,      {result, pJ, parallelJobs} = WaitNext[parallelJobs];      Write[outputstream, result];      setofresults = Join[setofresults, result]     ]      where `parallelJobs` is a list of process IDs of the form `ParallelSubmit[{...},...]`, and each of the jobs should take about an hour. Thus, there is no reason for the master kernel to be running. A similar code with `WaitAll` instead of `WaitNext` leaves the master kernel with 0% CPU and gives 100% to each of the launched parallel kernels. But the reason I want to use `WaitNext` instead is because I want to write the results as they're generated. I'd be grateful for any explanation of what's going on or ideas for getting around this waste of CPU. Thanks. Later: Here's a fix. I bundle more stuff into the `ParallelSubmit[...]` parts, in order to Write there, and then I use `WaitAll` on the list of `ParallelSubmit` items. This seems to result in considerably less overhead CPU used by the master kernel. It now seems to be an academic question: why does `WaitNext` (seem to?) use so much more overhead than `WaitAll`?


title: Disconnected Frame/Axes in Plots

text: Is it possible to have "Tufte" style figure axes? That is so that the axes do not need to connect or span the entire data range? For an example of what I mean from the R's default histogram style: ![enter image description here](http://i.stack.imgur.com/4TXsD.png) I know how to get the ticks out etc ... but not how to break the axes at the origin or only draw the axes/frame for a subset of the graphic range.


title: Adding a label to an expression result

text: To make my notebook easier to read for non-Mathematica literate colleagues (myself included), I'd like to have the output from an assignment expression look somewhat more obvious. Normally an expression assignment would look something like this:               In[1]= myVariable = 1 + 1          Out[1]= 2      But I'd like to get an output that looks more like:               Out[1]= myVariable = 2      I'm sure there are very convoluted ways to get this as an output but is there some really simple thing I can do so that the input is also still fairly easily readable without a heap of other commands wrapped around it?


title: How to combine two vectors into a matrix by columns?

text: I know it may sounds idiot, but I've been looking through the document, and couldn't find a way to combine two vectors say `{a, b}` and `{c, d}` into `{{a, c}, {b, d}}`. Thanks all.


title: Subscripts to a variable; why a letter shoud come before a digit?

text: I noticed that I cannot create a variable $f_{2s}$ since Mathematica seems to leave a space between the subscripts `2` and `s` implying that $f_{2s}$ is not recognised in later calculations. But I see that I can create the variable $f_{s2}$ instead without any problem. Is there a way to create the variable $f_{2s}$ in Mathematica? Thank you.


title: Cleaning mildew from old documents using Mathematica (Image processing)

text: While visiting family over the holiday period, I managed to have some good mother-daughter bonding over how far back I’ve managed to trace the family tree (Mom is in her 80s and doesn’t do computers). I’ve been using the usual databases like Ancestry.com, familysearch.org and asking the odd question over on genealogy.SE when I get stuck. But I’ve also been lucky that certain old church records for parts of Kent in England have been scanned and the images available online. Unfortunately some of them are in poor condition, and I thought I could use Mathematica’s image processing capabilities to clean them up a bit. Take this example:               raw = ImageRotate[Import["http://goo.gl/er4c5"], 180 Degree];      Cleaning this up with `Sharpen` and some of the filters like `MeanShiftFilter` definitely helps.               sharpened = Sharpen[raw, 3]         s2 = MeanShiftFilter[sharpened, 2, 0.03, MaxIterations -> 20]      ![enter image description here](http://i.stack.imgur.com/drdLx.png) But there are still a lot of mildew blotches on the image. I’d like to fade out the things that look like disks, and darken the things that look like handwriting, but I have not yet found the iteration of things like `MorphologicalComponents` that would do the trick. I keep getting the background of the page as the connected component, so I can’t, for example used the `"Holes"` property to select handwriting and not mildew blotches. Does anyone have any suggestions? I’m quite unfamiliar with the image processing side of Mathematica.


title: Calculating the density of nearest neighbours

text: I am trying to plot this ![](http://i.stack.imgur.com/8I0EM.png) which is a numerical simulation of the Montgomery-Odlyzko law for the nontrivial 1st $10^5$ zeros of the Riemann zeta function $ζ(s)$. The solid line is given by `1-(Sin[π x]/(πx))^2`. The following is what I can't seem to interpret: > The blue symbols indicate the pair correlation function of normalized > spacings $δn=(γ_{n+1}-γ_n)\log(γ_n/2π)/2π$ between two consecutive > nontrivial zeros $1/2+iγ_n$ and $1/2+iγ_{n+1},\ n=1\dots10^5)$ of the > Riemann zeta function $ζ(s)$. from this page. I have looked at various ways of calculating the density, using `Histogram`, `NearestFunction`, `FindClusters`, etc. but am getting nothing like the image above. I realise that this is largely due to a conceptual misunderstanding, but I was hoping someone could point me in the right direction. # Update ![](http://i.stack.imgur.com/BNIbu.gif) plotted with               DeleteCases[Flatten[Table[Abs[z1 - z2] Log[z2/(2 π)]/(2 π),      {z1, Take[zz,1000]}, {z2, Take[zz,1000]}]], 0];     Show[ListPlot[HistogramList[%, {0, 3, 0.1}][[2]]/200,      DataRange -> 3], Plot[1 - (Sin[π u]/(π u))^2, {u, 0, 3}]]      using First $10^5$ zeros as `zz`, thanks to Rahul Narain's comments below. Unfortunately, my computer won't calculate for $10^5$ zeros, but link left for those that will. ... I am now beginning to appreciate the computational power that would have to be used to generate an image like this or this!


title: On generalizing Partition[] (with offsets) to sublists of unequal length

text: The usual `Partition[]` function is a very handy little thing:               Partition[Range[12], 4]     {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}}          Partition[Range[13], 4, 3]     {{1, 2, 3, 4}, {4, 5, 6, 7}, {7, 8, 9, 10}, {10, 11, 12, 13}}      One application I'm working on required me to write a particular generalization of `Partition[]`'s functionality, which allowed the generation of sublists of unequal lengths, for as long as the lengths were appropriately commensurate. (Let's assume for the purposes of this question that the list lengths being commensurate is guaranteed, but you're welcome to generalize further to the incommensurate case.) Here's my generalization in action:               multisegment[lst_List, scts_List] := Block[{acc},       acc = Prepend[Accumulate[PadRight[scts, Length[lst]/Mean[scts], scts]], 0];       Inner[Take[lst, {#1, #2}] &, Most[acc] + 1, Rest[acc], List]]          multisegment[CharacterRange["a", "x"], {3, 1, 2}]     {{"a", "b", "c"}, {"d"}, {"e", "f"}, {"g", "h", "i"}, {"j"}, {"k", "l"},      {"m", "n", "o"}, {"p"}, {"q", "r"}, {"s", "t", "u"}, {"v"}, {"w", "x"}}      (Thanks to halirutan for optimization help with `multisegment[]`.) The problem I've hit into is that I wanted `multisegment[]` to also support offsets, just like in `Partition[]`. I want to be able to do something like the following:               multisegment[Range[14], {4, 3}, {3, 1}]     {{1, 2, 3, 4}, {4, 5, 6}, {5, 6, 7, 8},       {8, 9, 10}, {9, 10, 11, 12}, {12, 13, 14}}      How might a version of `multisegment[]` with offsets be accomplished?


title: How can I create a ColorFunction using Blend?

text: As shown below, I am trying to find a cool way to show some variance weighted deviation from the mean. There are 10 attributes that I compute the distance for. How can I add a color function such that it is progressively a darker shade of red when its value is negative (towards the left) and green when the value is positive (towards the right of the graphics)?               distance = {0.245, -0.235, 0.053, -0.048, -0.128,                 -0.007, -0.075, -0.067,-0.005, 0.082}          Show[       Function[         attributes,         Graphics[           Rectangle[             {If[distance[[attributes]] < 0, distance[[attributes]]*10, 0],               attributes - 1},             {If[distance[[attributes]] < 0, 0, distance[[attributes]]*10],               attributes}           ],           PlotRange -> {{-5, 5}, {0, 10}},           Epilog -> {White, Line[{{0, 0}, {0, 11}}]}       ]] /@ Range[10],       Frame -> True]      ![enter image description here](http://i.stack.imgur.com/e2Pft.png)


title: sprintf() or close equivalent, or re-implementation?

text: Is there a `sprintf()` command (some command that takes a `printf`-style format string and a list of values to insert into the string) or something very much like it (preferably with a similar style of format specifiers)? Or, alternately, how would I implement `sprintf()` in Mathematica?


title: Labeling triangle edges in Mathematica 10

text: Mathematica 10 introduced lots of new geometry related functions, and one of these is SSSTriangle which creates a triangle graphic given the three side lengths. Is it possible however to label the side lengths to achieve something like this ![enter image description here](http://i.stack.imgur.com/PzQYP.png)


title: Export vector images

text: I am having difficulties exporting vector graphics. Using Kardashev3's code provided here:               images = Image[ListPlot[pdata = Table[Sin[2 \[Pi] x/12.34], {x, #}] +      RandomReal[.1, {#}]]] & /@ Table[i, {i, 100, 200, 10}];      and then exporting them as follows:               Export[NotebookDirectory[] <> "image" <> ToString[#] <> ".eps",      "AllowRasterization" -> False, Image[images[[#]]]] & /@ Range[Length[images]]     Manipulate[images[[n]], {n, 1, Length[images], 1}]      I get the error message:               <<Export::noelem: {...} is not a valid set of export elements for the EPS format.>>      The code works well for rasterized graphics, but appears to run into problems with vector graphics.


title: How can I create a Distribution from its probability density function?

text: I have a probability density function. Is there a mechanism to create a `Distribution` object from it, such that normal Mathematica commands that usually work on distributions, such as `Variance`, `RandomVariate`, etc., work on it?


title: Can ParallelDo speed up a counting problem?

text: How to make parallelize the following code keeping the same "idea". The example I have in mind is more complicated, but I would like to know if a program of this structure can be parallelized?               c = 0     ParallelDo[If[RandomReal[] > 0.5, c += 1], {i, 100}]


title: Possible Bug in DiscretizeRegion with Option MaxCellMeasure

text: Consider the following `ImplicitRegion`:               reg = ImplicitRegion[x^2 + y^2 + z^2 == 16, {x, y, z}];      We can discretize it using `DiscretizeRegion`               dr = DiscretizeRegion[reg]      ![Mathematica graphics](http://i.stack.imgur.com/g0hE2.png) To get finer triangles the option `MaxCellMeasure` is available, only it does nothing when used.               DiscretizeRegion[reg, MaxCellMeasure -> {"Area" -> #}] & /@ {0.1, 0.05}      ![Mathematica graphics](http://i.stack.imgur.com/iEGOh.png) Of course using one of the `Graphics` primitives               DiscretizeRegion[Ball[], MaxCellMeasure -> {"Area" -> #}] & /@ {0.1, 0.05}      ![Mathematica graphics](http://i.stack.imgur.com/DO7W2.png) You can see that it works fine. I'm on **Windows 8.1** , can anyone confirm this on other platforms? Confirmed on **Linux** via the Wolfram Programming Cloud.


title: Generate a list of values with equal number of each value

text: I want to create a list of 32 values such that from `{a,b}` I can generate               {{a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b},     {a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,b,a,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b},...,     {b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a}}      (that's exactly 16 a's and 16 b's in each array, with repeats allowed). I have tried `Select[Tuples[{a,b},32],Count[##,a]==16]`, but get an error that `"The length of the output of Tuples[{a,b},32] should be a machine integer."` The problem as I see it is that `Tuples` is generating a lot of unneeded cases for my problem and the computer can't handle such a large number (and it would take a really long time even if it could). I did a study of the timing of running some lower length arrays and assuming that the scaling stays linear (like it did for some of the larger numbers) it would take nearly 7 hours. EDIT: I have the answer, but it won't let me post it, because I am new. So here it goes: Building off of Kuba's suggestion, I came up with an answer that works for my problem. Sorry if I was unclear. I built a list and then made every permutation of the list until all elements were switched. It is easy enough to make sure it goes through the switch and then back to the original (thus generating every possible combination without eliminating repeats).               list = Join @@ (ConstantArray[#, 16] & /@ {a, b});     For[c = 1, c < 17, c++,      For[d = 17, d <= 33 - c, d++,       new = Permute[list, Cycles[{{c, d}}]];      ];      list = new     ];      Hopefully this will help someone else!


title: ArrayPlot of square matrix: how does ColorFunction -> Automatic work?

text: Suppose you have the following:               tt = Table[{i, j}, {i, 0, 10}, {j, 0, 10}]      The table `tt` is a matrix of pairs, `{i, j}`. Now you issue               ArrayPlot[tt]      you get a nice image with the top row and the rightmost column white. How does `ArrayPlot` work in this case? I tried to look into the `ColorFunction` documentation but I was not able to actually understand how the system is working. I am curious to find an explanation.


title: Swapping rows and columns in matrix

text: If I have an array like the following $\left( \begin{array}{ccc} 1 & 2 & 3 \\\ 4 & 5 & 6 \\\ 7 & 8 & 9 \end{array} \right)$ How can I swap the rows and columns, so it is transformed into this? $\left( \begin{array}{ccc} 1 & 4 & 7 \\\ 2 & 5 & 8 \\\ 3 & 6 & 9 \end{array} \right)$ This question touches upon the subject, but rather than swapping it simply rotates the matrix.


title: Mathematica averaging a big list of large images

text: I have a list of several hundred images, and I want to average the list to get a single image. Each image is 12bit TIFF with 2048*2048 pixels, and I am using the following to do the job:               result=Mean[Map[ImageData[Import[#]]&,imagelist]];      The problem is that the data becomes huge. I tried to do the task with about 400 images with 2048*2048 resolution. The computer ran out of ram, created a 25GB of virtual memory, and could not finish the task. Is there any other alternative that I can use to do the task? I would greatly appreciate your help.


title: Problem with large values in ParametricPlot

text: I've got a question quite similar to No 18163:Problem with high parameter values in ParametricPlot, but the solution of that problem did not work for me. So I hope you may have another tip. I want to plot an equation similar (just a bit more difficult) then the following, the parameter and data range of concern is also similar: $\omega = 2 c \pi / \lambda$, where $c$ is the speed of light. Now, the other function is a bit more tricky, therefore I want to use `ParametricPlot` and not `Plot`. My problem however is that it does not display the x-axis (or it might be so small I don't see it) when I use the correct value for `c`. It seems to be a problem with the large values, as everything is OK if I set `c = 2` or `c = 10` instead. The code I used is: 1)               ParametricPlot[{(2 π)/λ, (2 π)/λ*1000}, {λ, 300, 1000}]      2)               ParametricPlot[{(2 π)/λ, (2 π])/λ*1000}, {λ, 300, 1000},        PlotRange -> {{0.010, 0.02}, {10^15, 10^16}},        MaxRecursion -> 15,       Evaluated -> True]      I tried to apply a workaround, creating a list to `Map` over the range $\lambda$ = 300 .. 1000 and then using `ListPlot`. This would work; however, it's not so good for my full problem.


title: Loop through a list and select elements

text: I am new to _Mathematica_ and I have no idea how to make a basic for loop work. I want to loop through the elements of a list: `Range[45, 200]`. I want to select the elements (i) for which the following conditions holds: if i mod 3 and i mod 8 and i mod 12 == 1 and i mod 5 == 0 I want to print the element. How would I achieve this? I want something like this:               for i in range(45, 201):        if i%3==1 and i%8==1 and i%12==1 and i%5==0:           print i      Of course in _Mathematica_ language. Sorry if this is a dumb question but the _Mathematica_ documentation is pretty hard to understand. Thanks.


title: Plotting the solutions of a system of differential equations on a simplex

text: I want to solve and plot the solutions of the following system on the triangle simplex:               x'[t] == x[t]*(2*x[t] - 2)     y'[t] == y[t]*(2*x[t])      z'[t] == z[t]*(2*x[t])      It is assumed that `x[t] + y[t] + z[t] == 1` for all times `t`. I am looking for output similar to this: ![Imgur](http://i.imgur.com/Koz3AP0.png) I;m also interested in plotting the frequency changes of `x[t]`,`y[t]` and `z[t]` over time. That is, given an initial value, I want to find how the frequencies vary over time?


title: Color plot markers using If statement

text: I am calculating eigenvlaues. Some are negative, some are positive. I define the index nn and mm (as well as np and mp) of each matrix element by some functions that assign positive, zero and negative integer values for nn (np) and strictly positive integers for mm (mp). My code is much more complex, but a simplified version of it looks like this:               nn = 2; mm = 3; som = 2 (nn + 1) mm; RX = 1; PO = 5;     n[a_] := Floor[(a - 1)/mm] - Floor[(a - 1)/((nn + 1) mm)] - nn;      m[a_] := Mod[a - 1, mm] + 1;     np[b_] := Floor[(b - 1)/mm] - Floor[(b - 1)/((nn + 1) mm)] - nn;      mp[b_] := Mod[b - 1, mm] + 1;     Vnozer[nn1_, np1_, mm1_,         mp1_] := (2 nn1 + 3 np1 + 4 mm1 + 5 mp1) Exp[kx];     Vzer[nn1_, np1_, mm1_,         mp1_] := (-4 nn1 - 3 np1 - 2 mm1 - 1 mp1) Exp[kx];     V[nn1_, np1_, mm1_, mp1_] :=        If[Abs[nn1] > 0 && Abs[np1] > 0, Vnozer[nn1, np1, mm1, mp1],         Vzer[nn1, np1, mm1, mp1]];     EN[nn1_] := Sign[nn1] Sqrt[Abs[nn1]];     c[a_, b_] :=        EN[n[a]] KroneckerDelta[Abs[n[a]], Abs[np[b]]] KroneckerDelta[m[a],           mp[b]] KroneckerDelta[Sign[n[a]], Sign[n[b]]] +         V[n[a], np[b], m[a], mp[b]];     Q = Array[c, {som, som}];     MF = Table[{kx, Eigenvalues[Q]}, {kx, -RX, RX, (2 RX)/(PO - 1)}];     Array[ou, som]; Array[pl, som];     Table[ou[y] = Table[{MF[[x, 1]], MF[[x, 2]][[y]]}, {x, 1, PO}], {y, 1,         som}];     Table[pl[y] = ListPlot[ou[y], PlotRange -> All], {y, 1, som}];     FPL = Table[pl[z], {z, 1, som}];     Show[FPL]      ![Eigenvalue plot looks like this.](http://i.stack.imgur.com/5aFGb.jpg) I would like to get Red PlotMarkers when my eigenvalues are positive and, say, Blue when my eigenvalues are negative. I played around with an If statement, but I was not able to figure out the right syntax. Something along the lines               PlotMarkers->{If[x]>0, {Red, dotsize}, {Blue, dotsize}}


title: Extract information from function definition returned by DefineDLLFunction

text: I have an application using `DefineDLLFunction` whose output is: > Function[Null, If[NETLinkDLLPrivatecheckArgCount["DRV_AOVoltageOut", > {##1},2], WolframNETLinkDynamicDLLNamespaceDLLWrapper2DRVUAOVoltageOut[##1], > $Failed], {HoldAll}] How to extract the information “DynamicDLLNamespaceDLLWrapper2” from the output above?


title: ToExpression and Fortran notation

text: ToExpression["9.0E-03"]      interprets String as               9*e - 3      instead of what I am expecting               0.009      How can I convert to expression Fortran notation?


title: Determining the dimension of a probability distribution

text: Functions like `Mean` and `RandomVariate` clearly infer the dimension of the distribution passed to them. One can also usually determine the dimension of a distribution by calling one of these functions, but this is suboptimal. `RandomVariate` does not work if some of the parameters of the distribution are symbolic and long tailed distributions may not have a well defined mean. Even when this method works it is overkill. Presumably there is some lower level function that just determines the dimension that `Mean` and `RandomVariate` themselves use to determine the dimesion but I have not been able to find it.


title: Plot a function based on Derivative - Gradient field

text: I'm trying to plot the gradient field of a function in such a way that is possible to change it easily, only editing the function. Consider the code:               xmin := -2; xmax := -xmin; ymin := -2; ymax := -ymin;     f[x_, y_] := x^2 + y^2     Plot3D[f[x, y], {x, xmin, xmax}, {y, ymin, ymax}]      ![enter image description here](http://i.stack.imgur.com/PoDlW.png) So, the following code produces a very fancy result:               VectorPlot[{2 x, 2 y}, {x, xmin, xmax}, {y, ymin, ymax},       StreamPoints -> Coarse, StreamColorFunction -> Hue]      ![enter image description here](http://i.stack.imgur.com/WGaR7.png) Since `{D[f[x, y], x], D[f[x, y], y]}` produces `{2 x, 2 y}` I tried to define               Gradf := {D[f[x, y], x], D[f[x, y], y]}      and use               VectorPlot[Gradf, {x, xmin, xmax}, {y, ymin, ymax},       StreamPoints -> Coarse, StreamColorFunction -> Hue]      but I got a lot of errors as > General::ivar: -1.99971 is not a valid variable. >> > > General::stop: Further output of General::ivar will be suppressed during > this calculation. >> I really don't understand why it is not working. Any idea how to solve this so I could only change the definition of `f` and plot again?


title: How do I get a different (random) independent edge set each time I run FindIndependentEdgeSet?

text: I'd like to use FindIndependentEdgeSet[g] repeatedly to get random maximal matchings of a fixed graph, but each time I call this function it gives me the same answer (i.e. the same list of edges). How do I "randomise" it?


title: FullSimplify assumptions for function body

text: I'd like to pass an assumption to `FullSimplify` so whenever it gets a function that is squared and square rooted would return me only the function body, without `Abs[f]` (I've tried assumption `_Symbol ∈ Reals && _Symbol > 0` but it gives `Abs[f]` instead of `f`.               f[x_] := a x^2;     FullSimplify[Sqrt[f[x]^2], _Symbol ∈ Reals && _Symbol > 0]      > >     x^2 Abs[a] >


title: How do I avoid the gaps introduced by a frame on a plot?

text: You can see that there are gaps on all sides of the plot between the frame and the extent of the line that I've plotted. How do I get rid of these? I'd like the frame to cover $[0,1]\times[0,1]$ and no more.               Plot[x, {x, 0, 1}, Frame -> True]      > ![enter image description here](http://i.stack.imgur.com/Y5Ck5.png)


title: Kronecker delta notation

text: Is there an easier way to enter `KroneckerDelta[n,m]` in Mathematica? When I use the notation $ \delta_{n,m} $, it won't work.


title: Interpolation of multidimensional data organized logarithmically

text: The following threads call our attention to the fact that "accuracy of Interpolation will be worse with an unstructured grid", in the context of interpolation of 3d data: interpolation of 3D data Improved interpolation of mostly-structured 3d data I want to know if there is a systematic way to do the interpolation correctly for a 3D data with the points distributed logarithmically along x and y. **Simple example** The xy grid would be built using               grid = Table[ {10^t, 10^u}, {t, 1, 3, 0.05}, {u, 1, 3, 0.1}]     ListPlot[ grid ]      ![Logarithmic grid](http://i.stack.imgur.com/8GxNs.jpg) Of course, in logarithmic scale it looks fine (linear):               ListLogLogPlot[ grid ]      ![enter image description here](http://i.stack.imgur.com/KPGvv.jpg) The 3D data would be built using some 2 variable function `func`:               tabx = Table[10^w, {w, 1, 3, 0.05}]     taby = Table[10^w, {w, 1, 3, 0.1}]     tab = Table[ {{x,y},func[x, y]}, {x, tabx}, {y, taby}]      Then, how to interpolate `tab` properly?


title: Solving polynomial equations takes infinit time

text: I need to solve an polynimial equation, but when i try to use Solve or NSolve in mathematica, its cant find the solution in appropriate time (i interrupted calculation after 5 hour left). The equations is:               Remove["Global`*"];     g = 9.8;     C1 = 3.6;     C2 = 0.25;     C3 = 666;     C4 = 2;     c = -36;     e = 0.86;     P0 = 24.44;     h0 = 0.1;          h = h0*(1 + C3*P^C4);     NSolve[{P/P0 == ((1 - e*(1 - h/e))/(1 - e))^((2 + c)/3)/(1 - h/e)^4.65}, {P}]      Maybe my computer is too weak or I'm using the wrong method?


title: NonLinearFit with "complicated" integral model

text: I have a set of data $y_i (z_i)$ with errors $\Delta y_i$                data = {{0.015, 34.1114},{0.0277, 35.705},{0.048948, 36.7316},{0.0651, 37.3067},{0.100915, 38.4567},{0.159, 39.4164},{0.248508, 40.2722},{0.455, 42.3239},{0.655, 42.3151},{0.75, 43.243},{0.84, 43.5143},{0.961, 44.2642},{1.188, 44.6076},{1.34, 45.0675},{1.414, 44.8038}}                sigmadata={0.215239,0.118114,0.175773,0.242628,0.121087,0.21481,0.152213,0.306006,0.188809,0.198402,0.471047,}      that I want o fit with a complicated formula $$ Y(z) = 5\log \Bigl((1+z)\int_0^z \frac{dz'}{a+bz'+cz'^2}\Bigr)+25; $$ I used a `NonLinearFit` in the following way               model[a_?NumericQ, b_?NumericQ, c_?NumericQ, z_] := 5*Log[10, (1 + z)*      NIntegrate[1/(a + b*x + c*x^2), {x, 0, z}, PrecisionGoal -> 7,        AccuracyGoal -> 7]] + 25                  fit1 =  NonlinearModelFit[data, model[a,b,c,z], {a, b, c}, z,         Weights -> 1/(sigmadata)^2];       Mathematica was not able to make the fit, and the problem seems to be that the coefficients becomes complex. I decide then to use the analytical form of the Integral and then make the fit (to avoid the integration),               model2=5Log[10,(1+z)*(2ArcTan[(b+2*c*z)/(Sqrt[4*a*c-b^2])])/(Sqrt[\4*a*c-b^2])]+25;       but the same problem appears. There is any way to fix somehow the conditions over $\\{a,b,c\\}$ ??. The full set of data is about 580 points, its a Cosmological fot for Supernovae. I appreciate your help.


title: Fredholm integral equation of the second kind with kernel containing Bessel and Struve functions

text: I need to solve this Fredholm integral equation of the second kind:               f[s]+integrate[f[t] K[s,t],{t,0,1}]=s       where `0<=s<=1`. The kernel is:               K[s,t]=(a/2)*(BesselJ[1,a*(s+t)]-BesselJ[1,a*Abs[s-t]]-i*StruveH[1,a*(s+t)]+i*StruveH[1,a*Abs(s-t)])       where a: real, i: imaginary unit. I tried to solve this with the method described here: Integral equation numerical solution with NDSolve, this is the best algorithm for this case I have come across so far but it takes for ages and in the end it doesn't produce any result (due to memory insufficiency). Could anyone please help me solve it?


title: How can I define a ⊕ operator?

text: What is wrong with the following code?               CirclePlus := SparseArray[Band[{1, 1}] -> {##}] &     a_ ⊕ b_ := CirclePlus[a, b]      > SetDelayed::write: Tag Function in (SparseArray[Band[{1,1}]->{##1}]&)[a_,b_] > is Protected. >> I want to define the operator ⊕ to work like `+,-,*,/`, so it can be used as `a ⊕ b`.


title: How do you programatically load data into symbols?

text: I am trying to convert a list of string names into symbols, which will then be used to store data. I have 24 files (where the name of each file is a member of the list mentioned above) that I need to process, which is why I am trying to accomplish my goal progammatically. The code below results in a Tag warning. I have read the normal documentation sources, and appreciate that you can not inappropriately assign something to a protected symbol, but this doesn't help me solve the problem. Would you have any advice how to accomplish my goal?               Table[(ToExpression[mmsignalnames[[i]]] =         Extract[ToExpression[celfilenames[[i]]], mmammindices[[j]]]), {i,        1, Length[mmsignalnames]}, {j, 1, Length[mmammindices]}]          Set::write: Tag ToExpression in ToExpression[mmsignalGSM356796] is Protected. >>


title: How to get Symbol["x"]=3 to work

text: This is probably a really simple one, but I'm stumped. I want `Symbol["x"]=3` to work just like `x=3`. However I can't figure out how to get Mathematica to evaluate the `Symbol`, converting the string to the symbol `x`, but then _not_ evaluate `x`. > x = 2 > > 2 > > Symbol["x"] = 3 > > Set::write: Tag Symbol in Symbol[x] is Protected. >> > > 3 > > Evaluate[Symbol["x"]] = 2 > > Set::setraw: Cannot assign to raw object 3. >> > > 2 I know that I can remove the definition, but I have a ton of these and would like to be able to replace their values that have been already set. `x=3` doesn't require that I remove the definition of `x` to set it. In case it matters, I'm using 10.0.0.


title: Solving algebraic equations

text: How may I make `n` and `k` in terms of `x` and `y` in this equation?: $$\frac{1-n-i k}{1+n+i k}=\sqrt{x} e^{i y}$$ I have tried separating the real and imaginary terms on the left hand side using complex expand so that I can have 2 sets of equations now but I have no idea how to continue?               ComplexExpand[((1 - n - I k)/(1 + n + I k))]


title: Is it possible to do vector calculus in Mathematica?

text: I am trying to rearrange and manipulate some vector differential equations in _Mathematica_. As far as I understand you have to tell _Mathematica_ that a variable is a vector by specifying the components of the vector. For example               r = {x, y, z};      If I want to define vector fields I have to do it in the following way               v = {vx[r, t], vy[r, t], vz[r, t]};     n = {nx[r, t], ny[r, t], nz[r, t]};      Now I can use the Div operator to express a differential equation, in this case the continuity equation in hydrodynamics.               D[n, t] + Div[n*v, r] == 0      My problem is the output I get from this. It looks absolutely horrible and I can't do anything with it.                  ({0, 0, 0},1)                                    ({0, 0, 1},0)     {nx             [{x, y, z}, t] + vz[{x, y, z}, t] nz             [{x, y, z}, t] +                          ({0, 0, 1},0)                                    ({0, 1, 0},0)      nz[{x, y, z}, t] vz             [{x, y, z}, t] + vy[{x, y, z}, t] ny             [{x, y, z}, t] +                          ({0, 1, 0},0)                                    ({1, 0, 0},0)      ny[{x, y, z}, t] vy             [{x, y, z}, t] + vx[{x, y, z}, t] nx             [{x, y, z}, t] +                          ({1, 0, 0},0)      nx[{x, y, z}, t] vx             [{x, y, z}, t],        ({0, 0, 0},1)                                    ({0, 0, 1},0)     ny             [{x, y, z}, t] + vz[{x, y, z}, t] nz             [{x, y, z}, t] +                          ({0, 0, 1},0)                                    ({0, 1, 0},0)      nz[{x, y, z}, t] vz             [{x, y, z}, t] + vy[{x, y, z}, t] ny             [{x, y, z}, t] +                          ({0, 1, 0},0)                                    ({1, 0, 0},0)      ny[{x, y, z}, t] vy             [{x, y, z}, t] + vx[{x, y, z}, t] nx             [{x, y, z}, t] +                          ({1, 0, 0},0)      nx[{x, y, z}, t] vx             [{x, y, z}, t],        ({0, 0, 0},1)                                    ({0, 0, 1},0)     nz             [{x, y, z}, t] + vz[{x, y, z}, t] nz             [{x, y, z}, t] +                          ({0, 0, 1},0)                                    ({0, 1, 0},0)      nz[{x, y, z}, t] vz             [{x, y, z}, t] + vy[{x, y, z}, t] ny             [{x, y, z}, t] +                          ({0, 1, 0},0)                                    ({1, 0, 0},0)      ny[{x, y, z}, t] vy             [{x, y, z}, t] + vx[{x, y, z}, t] nx             [{x, y, z}, t] +                          ({1, 0, 0},0)      nx[{x, y, z}, t] vx             [{x, y, z}, t]} == 0      I would like _Mathematica_ to write the equation in vectorial form so that I can rearrange it and use vector identities to manipulate it. Is there a way to do this?


title: How can I do symbolic vector differentiation in mathematica?

text: I want to do this calculation using Mathematica and I do not know how. I want to finf gradient of a vector function I Have this $$ f:R^n\to R $$ $$ \nabla_xf(x)=\nabla_x(x^tBx) $$ I want to get this using mathematica (I want to differentiate vector function) $$ \frac{1}{2}(B+B^t) $$ $B$ is for example a $n\times n$ matrices and $x$ is a $n\times 1$ vector. does anybody know how am I supposed to do this using mathematica?


title: Control which frontend session/kernel the Workbench gets attached to

text: (I am new to Workbench) I have 2 or 3 Mathematica frontend sessions open with a few of them running some long-running codes. When I try to open/edit a code in Workbench, I see that it sometimes it attaches itself to the "busy" frontends. (This is not useful since any new evaluations are queued up)   * How does Workbench interact with Mathematica to decide which frontend to attach to?   * Is there a way in the settings, to force the Workbench to open its "own" new kernel for each session and keep reusing it?   * Is there a way to force the Workbench to open the code (and hence attach to) in a particular frontend session, which is free, so that I can continue coding/debugging?


title: Calculate the centroid of a group of pixels with the same PixelValuePositions

text: My question is about how to recognise objects in a image. I would like to recognise objects of the same color. Then I want to calculate the centroid of these objects. I want to apply this calculation on the image below. ![enter image description here](http://i.stack.imgur.com/xNI6h.gif) Based on the centroid it is possibe to calculate the xy-coordinate of the soccer players on this field. The difficulty is that the soccer players can wear a shirt and socks of the same color, but I will be happy if I can get an approximation.


title: How to combine more locations (GPS coordinates inside one city) with Google map?

text: I have a list of GPS coordinates.E.g.               GPSList = {{47.680800, 17.626446}, {47.681078, 17.627283}, {47.682759,          17.631810}};      I would like to crate a Google Map of the part of the city (Győr) with some signs. If I could do that, I could change simple red dots to discs or bars showing data.               Show[CountryData["Hungary", {"Shape", "Equirectangular"}],       Axes -> True,       Epilog -> {PointSize[0.01], Red, Point[Reverse /@ GPSList]}]      The resolution of that is not enough.


title: How do I make Reduce yield all solutions explicitly?

text: Say I want to do the following:               Reduce[ x+y+z==1, {x,y,z}, Modulus -> 7 ]      then I get a solution with parameters, `C[1]` : > >     x == 1 + 6 C[1] + 6 C[2] && y == C[2] && z == C[1] >   Now, for non-linear equations, such as               Reduce[x + y^2 + z == 1, {x, y, z}, Modulus -> 7]      I get a complete list of solutions, here are the first `5` of them :               %[[ ;; 5]]      > >     (x == 0 && y == 0 && z == 1) || (x == 0 && y == 1 && z == 0) || >     (x == 0 && y == 2 && z == 4) || (x == 0 && y == 3 && z == 6) || >     (x == 0 && y == 4 && z == 6) >   Is there a way to make the system yield this type of output also in the first case ? (Of course, I can just loop over all possibilities of the parameter and get a complete list, but I'd prefer to make _Mathematica_ do it for me if it is possible.)


title: Am I missing anything? Solving Equations

text: I want to know what $ a^4+b^4+c^4 $ would be when $ a+b+c=1, a^2+b^2+c^2=2, a^3+b^3+c^3=3. $ I tried               Solve[{a + b + c == 1, a^2 + b^2 + c^2 == 2,      a^3 + b^3 + c^3 == 3}, {a, b, c}]          a^4 + b^4 + c^4 /. {a -> ... }      I copied and pasted one instance from the result of `Solve[]` into `{a -> ...}` The solution and the result of `Simplify[]` of it was not quite what I expected. So as a test, I tried `a+b+c /. {a -> ...}` Still it was strange, it didn't come up with 1 which is obvious correct answer. So am I missing anything here? Is there any better way?