title: Building matrices by attaching vectors (columns) and matrices

text: Having the need to attach a column to a matrix or to join matrices to make longer rows is an operation that I use very frequently and I find the `Join` function ideal for these cases.               m1 = {{10, 11, 12}, {21, 22, 23}};     m2 = {100, 101};          (* Join matrices to make longer rows: *)     Join[m1, m1, 2]     (* --> {{10, 11, 12, 10, 11, 12}, {21, 22, 23, 21, 22, 23}} *)          (* Attach a column to a matrix *)     Join[m1, List /@ m2, 2]     (* --> {{10, 11, 12, 100}, {21, 22, 23, 101}} *)          (* Join two columns to make a matrix *)     Join[List /@ m2, List /@ m2, 2]     (* --> {{100, 100}, {101, 101}} *)      However, I wanted to define my own function that would simplify the notation needed to reach my goal:               columnAttach[a1_List, a2_List] :=        Join[If[VectorQ[a1], List /@ a1, a1],        If[VectorQ[a2], List /@ a2, a2], 2]          columnAttach[m1, m1]     (* --> {{10, 11, 12, 10, 11, 12}, {21, 22, 23, 21, 22, 23}} *)     columnAttach[m1, m2]     (* --> {{10, 11, 12, 100}, {21, 22, 23, 101}} *)     columnAttach[m2, m2]     (* --> {{100, 100}, {101, 101}} *)      This works as expected, but I would like to generalize it a bit. For instance, `Join` can take a list of vectors/matrices of any length:               Join[m1, m1, List /@ m2, List /@ m2, 2]     (* --> {{10, 11, 12, 10, 11, 12, 100, 100},       {21, 22, 23, 21, 22, 23, 101, 101}} *)      How can I adapt my `columnAttach` function to achieve the same flexibility?


title: What can I do to improve the performance of my calculations?

text: I'm trying to express a simple probability problem in _Mathematica_ , but am having trouble getting my calculations to execute at a reasonable speed. I have an object whose unknown location is modeled as a random variable with coordinates $\Theta=(\Theta_1,\Theta_2)$ distributed as $$f_\Theta(\theta)=f_\Theta(\theta_1,\theta_2)=\frac{1}{2\pi}e^{-(\theta_1^2+\theta_2^2)/2}$$ and a collection of sensors at given locations $(a_i, b_i)$ each of which has a probability of detecting a signal from the object that decays exponentially with the distance, modeled as a boolean-valued random variable $X_i$ with $$\mathbf{P}(X_i=T|\Theta=(\theta_1,\theta_2))=p_{X_i|\Theta}(T|\theta)=e^{-\sqrt{(a_i-\theta_1)^2+(b_i-\theta_2)^2}}$$ so that the joint PDF of a set of sensor states $x=\\{x_1,x_2,\ldots\\}$ and object location $\theta$ is $$f_{X,\Theta}(x,\theta)=f_\Theta(\theta)p_{X|\Theta}(x|\theta)=f_\Theta(\theta)\prod_{i|x_i=T}p_{X_i|\Theta}(T|\theta)\prod_{i|x_i=F}(1-p_{X_i|\Theta}(T|\theta))$$ so that $$p_X(x)=\int_{-\infty}^\infty\int_{-\infty}^\infty f_{X,\Theta}(x,\theta)d\theta_1 d\theta_2$$ and thus the probability that the object is at location $(\theta_1,\theta_2)$ given a set of sensor observations $x$ is given by the PDF $$f_{\Theta|X}(\theta|x)=\frac{f_{X,\Theta}(x,\theta)}{p_X(x)}$$ I've tried to express this in _Mathematica_ as               PDetect[sensloc_, srcloc_] := Exp[-EuclideanDistance[sensloc, srcloc]];     PDFSrcloc[srcloc_] := 1/(2 Pi)Exp[-(srcloc[[1]]^2 + srcloc[[2]]^2)/2];                           (*PDF[BinormalDistribution[{1,1},0],srcloc]*)     PDFJointSrcSens[srcloc_, senslocs_, sensstates_] :=        PDFSrcloc[srcloc]*        If[Length[sensstates] > 0,          Times @@ MapThread[           If[#1, PDetect[#2, srcloc],  1 - PDetect[#2, srcloc]] &, {sensstates, senslocs}], 1];     PDFSensLocs[senslocs_, sensstates_] :=        PDFSensLocs[senslocs, sensstates] =         If[Length[sensstates] > 0,          NIntegrate[          PDFJointSrcSens[{x, y}, senslocs, sensstates], {x, -Infinity,            Infinity}, {y, -Infinity, Infinity}], 1];     PDFSrcLocGivenSens[srcloc_, senslocs_, sensstates_] := (PDFJointSrcSens[srcloc, senslocs, sensstates])/        PDFSensLocs[senslocs, sensstates];      This seems to give me the results I expect, but performance is quite slow and plagued with beeps and warnings for many values. This is adequate for simple evaluations and marginal plots, but I need to put this in a `Manipulate` in which I dynamically plot the `DensityPlot` for `PDFSrcLocGivenSens` — that is, $f_{\Theta|X}(\theta|x)$ — as I add and remove sensors (adding/removing and changing the values of $x_i$; adding and removing elements to `senslocs` and adjusting the corresponding `sensstates`). What can I do to speed up my calculations and avoid the beeps I'm getting? * * * I'm (clearly) not great at this, so any assistance in a more elegant formulation would be appreciated. I'm particularly unhappy with my argument and function names. The original formulation of the scenario, which I may have garbled, can be found on p. 418 of _Introduction to Probability, 2nd Edition_, by Dimitri P. Bertsekas and John N. Tsitsiklis.


title: Creating a nonperiodic function in mathematica

text: I want to create a non-periodic square wave with values of 1 and -1(not necessarily alternating). For e.g. I want to convert an arbitrary array like {1,-1,-1,1,-1,1,-1} into a function. I tried using Piecewise but I don't know how to do this without typing a huge number of conditions. I also want to add the length of each stack(i.e. the duration for which it is in 1 or -1) e.g. two inputs value={1,-1,-1,1,-1,1,-1} and duration={5,6,1,2,3,8,2} Please Help P.S: The version I am using is 8.0.4.0


title: Operator operation

text: There are two basic operators `r={x,y,z}` and `p=-I*h*{D[#,x] , D[#,y], D[#,z]} &`. The angular momentum operator is defined as $\hat{\textbf L}=\hat{\textbf r}\times\hat{\textbf p}$. So how can I get `L` from `p` and `r` in mathematica? The first thing that comes to mind, `l=Cross[r,p]`, won't work. P.S. how could I define `p` in a better, more MMA-styled way?


title: Avoiding unnecessary computations within loops

text: Consider the following data:               test = RandomReal[{1, 2}, {10, 5, 3, 3}];      How can I do the following without the `For` loops, e.g. using `Table` or similar _Mathematica_ functions?               Module[{res = {}},        For[i = 1, i < 11, i++,         For[j = 1, j < 6, j++,            p = test[[i, j, 1]];           q = test[[i, j, 2]];           r = Cross[p,q];           mat = Orthogonalize[{p, q, r}];           For[k = 1, k < 6, k++,             AppendTo[res, mat.SeparationVector[p, test[[i, k, 1]], 2]]]]];       res]      where               SeparationVector[x_, y_, z_] := If[# < z/2, x - y, Sequence @@ {}]& @       Sqrt[Total[((x - y) - z*Round[(x - y)/z])^2]]      My Problem with using `Table` is that between the `j` and `k` indices, I define variables that depend on `j` so that I don't have to calculate these values for every iteration of `k`. I don't know how to achieve the same functionality without the `For` loops. But this is _Mathematica_ , and I know there are better and faster ways to do this. Any ideas?


title: How can I Flatten this List with Inner List of Lists?

text: Given the following `List`               lis =     {       {1, 2, 3}, {3, 2, 3}, {{3, 7, 5}, {7, 5, 3}, {6, 2, 1}}, {3, 2, 7},        {{3, 3, 5}, {7, 7, 8}, {9, 4, 2}, {9, 0, 0}}, {8, 5, 4}, {7, 4, 3}     }      I would like to get this `List`:               {       {1, 2, 3}, {3, 2, 3}, {3, 7, 5}, {7, 5, 3}, {6, 2, 1}, {3, 2, 7},        {3, 3, 5}, {7, 7, 8}, {9, 4, 2}, {9, 0, 0}, {8, 5, 4}, {7, 4, 3}     }.      `Flatten` is not doing it for me. Note that the actual List is huge and the List of Lists contained in this list can have variable lengths as in the example above one contains 3 inner list the other contains 4.


title: Polynomial Approximation from Chebyshev coefficients

text: I would like to expand a function $f(r)$ in the domain $[0,R]$, around the points $r =0$, and $r = R$ in the following manner $f(r = 0) = \Sigma_{i=0,i = even}^{imax} f_i (r/R)^i$ and $f(r = R) = \Sigma_{k=0}^{kmax} f_k (1 - r/R)^k$ I would like to get the coefficients $f_i$ and $f_k$ by first decomposing $f(r)$ into Chebyshev's and then turn that into the power series. Here is what I have so far for a random function : g[x_] = 0.17768*x^5 + 0.115594*x^4 - 0.049490*x^3 - 0.659085*x^2 - 0.2254209; The function looks like ![enter image description here](http://i.stack.imgur.com/XLZC5.jpg) Now to expand $g[x]$ in terms of Chebyshev I do this               In[8]:= GS = 6; (*gridsize*)          In[9]:= Clear[A, a]          In[10]:= A = Array[a, GS + 1, 0]          Out[10]= {a[0], a[1], a[2], a[3], a[4], a[5], a[6]}          In[11]:= For[i = 1, i <= GS + 1, i++, a[i] = 2/\[Pi]*         (Integrate[g[y]*ChebyshevT[i, y] 1/Sqrt[1 - y^2], {y, -1, 1}])]          In[12]:= a[0] = 1/\[Pi]* (Integrate[g[y]*ChebyshevT[0, y] 1/Sqrt[1 - y^2],          {y, -1, 1}])          Out[12]= -0.511616          In[13]:= A          Out[13]= {-0.511616, 0.0739325, -0.271746, 0.0431525, 0.0144492, 0.011105, -1.00221*10^-15}          In[14]:= t1 = Table[a[i]*ChebyshevT[i, y]  , {i, 0, GS}]          Out[14]= {-0.511616, 0.0739325 y, -0.271746 (-1 + 2 y^2), 0.0431525      (-3 y + 4 y^3), 0.0144492 (1 - 8 y^2 + 8 y^4), 0.011105 (5 y - 20 y^3 + 16         y^5), -1.00221*10^-15 (-1 + 18 y^2 - 48 y^4 + 32 y^6)}          In[15]:= g1[y_] = Sum[t1[[i]], {i, 1, GS + 1}]            Out[15]= -0.511616 + 0.0739325 y - 0.271746 (-1 + 2 y^2)      + 0.0431525 (-3 y + 4 y^3) + 0.0144492 (1 - 8 y^2 + 8 y^4)      + 0.011105 (5 y - 20 y^3 + 16 y^5) -1.00221*10^-15 (-1 + 18 y^2 - 48 y^4 +           32 y^6)      Now I plot the function and the Chebyshev approximation $g1[x]$. ![enter image description here](http://i.stack.imgur.com/VkVYQ.jpg) and you can not really see the difference between the two plots, so this makes me think I am doing the Chebyshev part correctly. After this I attempt to get the power series approximation using (Numerical Recipes sectinon 5.10, Clenshaw recurrence)               In[17]:= Clear[D1, d]          In[18]:= D1  = Array[d, GS]          Out[18]= {d[1], d[2], d[3], d[4], d[5], d[6]}          In[19]:= d[GS + 1] = 0          Out[19]= 0          In[20]:= d[GS] = 0          Out[20]= 0          In[23]:= For[i = GS - 1, i >= 1, i--, d[i] = 2*x*d[i + 1] - d[i + 2] + a[i]]          In[24]:= D1          Out[24]= {0.041885 - 2 (0.0144492 + 0.02221 x) x       \+ 2 x (-0.286195 - 0.02221 x + 2 x (0.0320475 + 2 (0.0144492 + 0.02221 x) x)), -0.286195 - 0.02221 x + 2 x (0.0320475 + 2 (0.0144492 + 0.02221 x) x), 0.0320475 + 2 (0.0144492 + 0.02221 x) x, 0.0144492 + 0.02221 x, 0.011105, 0}               In[27]:= d[0] = x*d[1] - d[2] + a[0]          Out[27]= -0.225421 + 0.02221 x - 2 x (0.0320475 + 2 (0.0144492 + 0.02221 x) x) + x (0.041885 - 2 (0.0144492 + 0.02221 x) x + 2 x (-0.286195 - 0.02221 x +       2 x (0.0320475 + 2 (0.0144492 + 0.02221 x) x)))               In[28]:= f[x_] = Simplify[d[0]]          Out[28]= -0.225421 + 5.48173*10^-16 x - 0.659085 x^2 - 0.04949 x^3 + 0.115594 x^4 + 0.17768 x^5      Now I plot all there versions ![enter image description here](http://i.stack.imgur.com/b4mbJ.jpg) and again I can see no difference between different versions. I take this to mean that I have used the Clenshaw recurrence correctly. **Question 1: Did I really use it correctly or did I just get lucky?** **Question 2: How would I change my code to deal with the function $f(r)$ around the origin which has to be normalized in its domain?** **Question 3: Where do I even begin with $f(r)$ around $r =R$ since that does not have the normal power series form?**


title: Having input aliases appear in the autocomplete box?

text: On mathematica 9 when you begin to type a special character you get a popup window that allows you to autocomplete it like such: ![](http://i.stack.imgur.com/VBR06.png) However, when you try the same with an input alias like ![enter image description here](http://i.stack.imgur.com/MZAED.png) no autocomplete appears. Is it possible to add the input alias to the autocomplete box and have them appear there like the special characters?


title: How to make a cleaner copy out of a blurry text image before OCR?

text: A cleaner copy can be obtained from a blurry original by using the `level adjustment` in _Photoshop_ before going for a better OCR. The picture below shows an example. My code below failed to do so. What is the appropriate way to get the same job done in Mathematica? ![enter image description here](http://i.stack.imgur.com/dAwXm.jpg)                im = Import ["http://i.stack.imgur.com/BO30x.jpg"];      Manipulate[      adjIm = Dilation[Erosion[Sharpen[im, a], b], c],      Grid[{        {         Control[{{a, 0, "Sharpen"}, 0, 10, Appearance -> "Labeled"} ],         Control[{{b, -1, "Erosion"}, -2, 2, Appearance -> "Labeled"}  ],         },        {         Control[{{c, -1, "Dilation"}, -2, 2, Appearance -> "Labeled"} ],         Button["OCR", Print[TextRecognize@adjIm]]         }        }]      ]      ![enter image description here](http://i.stack.imgur.com/JE6o9.jpg)


title: Plotting a piecewise function with strange subdomains

text: I have a function, which analityc expression is $C=2*max[b-c,0]$(you can see the expressions of b and c down). Then I have to considerer $q_\pm=\frac{(1\pm \sqrt{ (1-C^2)})}{2}$ and then to plot $E_n=-q_+log_2(q_+)-q_-log_2(q_-)$. I tried in this way:               b = (p*(2 - n)/4);     c = n*(1 + p)*(2 - n)/16 + (1 - p)*(2 - n)/8;     Conc = If[(b - c) < 0, 0, 2*(b - c)];     qplus = (1 + Sqrt[1 - Conc^2])/2;     qminus = (1 - Sqrt[1 - Conc^2])/2;     En = -qplus*Log[2, qplus] - qminus*Log[2, qminus]     Plot3D[En, {n, 0, 2}, {p, 0, 1}]      This is the output: > -(1/(2 Log[ 2]))(1 - √(1 - If[2 (-(1/8) (2 - n) (1 - p) + 1/4 (2 - n) p - > 1/16 (2 - n) n (1 + p)) < 0, 0, 2 (b - c)]^2)) Log[ 1/2 (1 - √(1 - If[2 > (-(1/8) (2 - n) (1 - p) + 1/4 (2 - n) p - 1/16 (2 - n) n (1 + p)) < 0, 0, 2 > (b - c)]^2))] + (1/( 2 Log[2]))(-1 - √(1 - If[2 (-(1/8) (2 - n) (1 - p) + > 1/4 (2 - n) p - 1/16 (2 - n) n (1 + p)) < 0, 0, 2 (b - c)]^2)) Log[ 1/2 (1 + > √(1 - If[2 (-(1/8) (2 - n) (1 - p) + 1/4 (2 - n) p - 1/16 (2 - n) n (1 + p)) > < 0, 0, 2 (b - c)]^2))] > > Indeterminate expression (0 (-∞))/Log[2] encountered. I don't know where is the error. Thank you.


title: Looking for an elegant way to solve a (system of) ODEs/functional equations with undetermined coefficients

text: I want to solve an ODE using undetermined coefficients/guess-and-verify and am looking for an elegant way to use this technique. I am running into a few ugly warts. Here is a basic implementation for a simple example:               ode = r v[z] == Exp[z] + g v'[z] + s^2/2 v''[z]     guess = {v[z_] -> a Exp[z] + b Exp[c z]} (* for some a,b,c*)          (* Inelegance 1: how can I substitute the guess into the ode directly?     For example, ode //. guess doesn't work  *)     guessderivs =        Union[guess, {v'[z_] -> (D[v[z] /. guess, z]), v''[z_] -> (D[v[z] /. guess, z, z])}]     (* ugly, but complete now.  Substitute*)          odesub = ode //. guessderivs // FullSimplify     (* => e^z (1 + a (g - r)) + b e^(c z) (c g - r) == 0 *)          (*Inelegance #2: This is an easy example, but is there a standard way to     get equations to solve for all z?  SolveAlways[odesub,z] didn't work *)          (* Doing it manually works, of course*)         a$sub = First@Solve[(2 + a (2 g - 2 r + s^2)) == 0, a]         c$sub = Solve[(2 c g - 2 r + c^2 s^2) == 0,c]          (* The last constant, b, would come from an initial value. mine is v'[0]==0 for example *)      To summarize where this is ugly:   1. How to make a guess substitution of a functional form, and have the derivatives work (i.e. `v'[z] //. {v[z_]-> a Exp[b z]}` but actually substitute the derivatives) I recognize the problem here that `FullForm[v'[z]] == Derivative[1][v][z]` so the rule doesn't match, but is there a nice way to replace these generally?   2. How to get the system of equations (in general) with undetermined coefficients? I thought that `SolveAlways` was supposed to do this? **EDIT:** It looks like the cleanest method is from @RiemannZeta which is to give a list of linearly independent basis vectors (anonymous as described by @belisarius), substitute, and find the coefficients. For this setup, let me give the following goal for some generic UndeterminedCoefficientsSystem function:               ode = {r v[z] == Exp[z] + g v'[z] + s^2/2 v''[z]};     ic = {v'[0] == 0};     equations = Union[ode, ic]; (* In reality, I will be trying a system of equations *)     v$basis = {Exp[#]&, Exp[d #]&, # &}; (* with an addition to test, which should be 0 here *)         coefficientsystem = UndeterminedCoefficientSystem[{{v, v$basis}}, equations};          (* Assume that this function generates a list of coefficients of the form C[1][1], C[1][2],... for the entire basis then it substitutes into the set of equations  *)     coefficientsystem == {C[1][1] == -1 - g C[1][1] + r C[1][1] - 1/2 s^2 C[1][1],     C[1][2] == -d g C[1][2] + r C[1][2] - 1/2 d^2 s^2 C[1][2],     C[1][3] == r C[1][3],     C[1][1] + d C[1][2] + C[1][3] == 0     } (* The last equation comes from the v'[0]==0 *)      So basically, the function does the following:   1. For arguments, takes a list of function name with a list of basis as anonymous functions. Here it is only 1, but I need to use this to solve a more complicated system of ODEs. Index the functions by j.   2. Take each function with index j and basis of length i of anonymous functions. Generate a list of coefficients for `C[i][j]` of these.   3. For each function and basis, create a guess anonymous function as the linear combination of these, with the `C[i][j]` coefficients. Create a substitution rule given the function name to the linear combination of basis.   4. For each given equation, substitute in the concatenated list of guesses (for each j)   5. For each basis, for each equation, find the coefficient with @RiemannZeta technique and append the whole list (if there are different basis for the different functions, it is reasonable to just look for the coefficients of the union of all anoymous basis)   6. Return the whole list of equations. Does that make sense as a generic function? It should work for any sort of functional equations, and not just ODEs. (I am getting stuck very early here. For example, we need to have anonymous guesses (to ensure that we can both take derivatives and evaluate at initial values such as `v'[0] == 0`) but how do I take two anonymous functions and concatenate a linear combination to form a new one?)


title: Function output of two lists are only diagonal elements

text: I'm having a little crysis over here. What I basically want to do is some sort of 3D-Plot, but I'm only interested in the resulting values. I have two vectors x and p:               x={x1,x2}; p={p1,p2};      and I want to calculate the value of the function f depending on 2 variables, for example               f[x_,p_]=x*p;      The input               f[x,p]      however does only calculate the diagonal elements and not all terms f[x1,p1], f[x1,p2], f[x2,p1] and f[x2,p2] what I would intuiveley expect from it. I tried some "Map" commands but didn't get the desired result. Could someone please help me out? And if possible even share some insight of why Mathematica is doing only the diagonal elements by default? I would be very interested in it because I have the feeling that my way of thinking is often quite perpendicular to the way Mathematica does -.-


title: double-backslash-file path problem@version 10.0

text: I found this happen @ _Mathematica 10_ pre test version and formal English version.   * Copy a file from windows, then paste into FrontEnd cell, you'll get a path, such like `"C:\\Users\\Hyper\\Documents\\b"` This is Ok. However, in the Chinese character case               "C:\\Users\\Hyper\\Documents\\新建文件夹"      This is bad. [It's fine before version 10.0]   * choose a file then Shift+Right-Mouse-Click, and `Copy as path`, then paste into FrontEnd cell, you'll get a path, such like `file1="C:\Users\Hyper\Documents\b"` `file2="C:\Users\Hyper\Documents\新建文件夹"` `file3="C:\Users\Hyper\Documents\b\新建文件夹"` So, two methods to get path from windows system both work badly, ie `FileExistsQ[file1]==>False` `FileExistsQ[file2]==>True` `FileExistsQ[file3]==>False` I have many old files in Chinese path, they cannot be dealt conveniently by _Mathematica 10.0_ @Windows now. I should manually delete a backslash in the path string, and if I use another method to get file path, \b, \hello these names are annoying. ![enter image description here](http://i.stack.imgur.com/7kTqs.jpg) Is this a simple bug? Why not just keep it the same as that in Version 9?


title: Defining tensor components generally

text: I would like to define a tensor according to its components, something like the following:               [F(x)]_i,j = Integrate[f(x,y)A_i(y)B_j(y),y]      where i and j are components between 1 and 3, i.e. A_i(y)B_j(y) is a 2nd rank tensor. F is also a 2nd rank tensor, with components i and j. Now, I don't want to explicitly enter the separate values for this definition, i.e.               [F(x)]_1,1 = Integrate[f(x,y)A_1(y)B_1(y),y]     [F(x)]_1,2 = Integrate[f(x,y)A_1(y)B_2(y),y]      etc. How can I do it generally? Also, I would not like to enter specific values for A and B components, but keep it general for arbitrary A and B. * * * ### EDIT Suppose I have the following:               f = 5 x + 3 y;     A = {8 y^2, 5 y, 17 y^3 + 3};     B = {7 y + 3, 4 y, 5 y + 3 y^2};      Now, I don't know my exact input (that's what I am asking) but it would be something like that:               F[i,j]=Integrate[f A[[i]] B[[j]],{y,0,8}]      I want it to be defined as a tensor, so that later I will be able to contract its indices with other tensors. My output should look like:               F = {{Integrate [f*A[[1]] B[[1]], {y, 0, 8}],            Integrate [f*A[[1]] B[[2]], {y, 0, 8}],            Integrate [f*A[[1]] B[[3]], {y, 0, 8}]},          {Integrate [f*A[[2]] B[[1]], {y, 0, 8}],            Integrate [f*A[[2]] B[[2]], {y, 0, 8}],            Integrate [f*A[[2]] B[[3]], {y, 0, 8}]},          {Integrate [f*A[[3]] B[[1]], {y, 0, 8}],            Integrate [f*A[[3]] B[[2]], {y, 0, 8}],            Integrate [f*A[[3]] B[[3]], {y, 0, 8}]}}      I want this to work when I don't define explicitly `A`, `B`, `f`. without definitions, I want _Mathematica_ to write the answer in terms of `A[[1]]` etc, and understand it as a tensor, so I can use it later. I hope now it's clear.


title: Use EvaluationCompletionAction to notify me only after long evaluation

text: Is it possible to use the option `EvaluationCompletionAction` to notify me (e.g. with a `Beep[]`) when an evaluation that took longer than, for example, 30s is finished? One of the default settings for EvaluationCompletionAction is `"ShowTiming"` which indicates that the frontend is in some way aware of the duration of evaluations. Ideally, I would want something like this:               SetOptions[       $FrontEnd,       EvaluationCompletionAction -> Which[duration > 30, Beep[]]     ]      Is it possible to do this? And could anyone point me in a direction how to accomplish this?


title: Using Combinatorica`ListNecklaces in v9

text: I am using _Mathematica_ for visualization of DeBruijn graphs. However, I am having a bit of trouble using `ListNecklaces`. I want to know how many cyclic shifts of length `n` with variables `x` and `y`. This is equivalent to looking at the number of necklaces (cyclic) with `n` beads and 2 colors. However, I'm not sure how to use the command `ListNecklaces`. I don't get anything back when I input `ListNecklaces[n ,2, Cyclic]`. I also am having trouble with some of the graph theory commands. In versions older than V9, I would need to load the Combinatorica package. Is it true that now I don't have to? Sometimes, _Mathematica_ doesn't recognize `ListNecklaces`, `DeBruijnGraph`, etc. What is the proper way to set up _Mathematica_ to use these? I am using Version 9, Student's Edition.


title: Mathematica 10 Notebook Fonts Look Bad

text: I've upgraded my home installation of _Mathematica_ from version 9 to 10 today on a Windows 8.1 machine, and I'm getting a weird font issue - the fonts are not anti-aliased, and look unbalanced and weird. Just look: > ![HALP](http://i.stack.imgur.com/cnuXE.png) For comparison, here what it looks on Linux with _Mathematica_ V10 > ![Mathematica graphics](http://i.stack.imgur.com/Qf6kO.png) At this point you may object, as these issues are too minor to get worked up about. But neither I nor my otherwise benign OCD can work like this. Any ideas? **EDIT** I've just had an idea, that maybe I need to manually remove old fonts leftover from the old _Mathematica_ 9 installation. I've read somewhere that they were not going to pollute the main font catalog with symbol fonts in the next release, and maybe the new _Mathematica_ is using old fonts for some reason. I can't test it right now myself, unfortunately.


title: Numerical integration of two variable function

text: The aim is to calculate the definite integral of the function $f$ of the form $$f(x,t) \;\;\;\; x \in [0, \infty ) \;\;, \;\;t \in [t_0,T]$$ numerically. For example consider the function below $$f = e^{-xt}$$ For each **$t_i$** belongs to interval $[t_0, T]$, there is an integral like this: $$\int_{0}^{\infty} f(x, t) dx \;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;(*)$$ If the interval of $[t_0,T]$ divided to $n$ equal part, then we have $n$ integral of the form $(*)$ where $t_i$ is the lower bound of each interval. Also I'm willing to plot the result of $n$ integration. In MATLAB it's easy to code the above integral; by defining a **for** loop, one can deal with sweeping **t** over interval $[t_0,T]$.                         for t = t0 : 0.01 : T                    fun = @(x) f(x, t);                   q = integral(fun,0,Inf);               end      I familiar with the command "Integrate" (in Mathematica) but I can't sweep **t** over interval. How can I do this?


title: UNIX time to DateList

text: I have data that is timestamped with UNIX time, which is the number of seconds since January 1, 1970 UTC. Unfortunately, it seems that most of the date and time functions in Mathematica are based on the system's local time zone. How can I convert a UNIX timestamp to a `DateList` in UTC?


title: How to put some number of queens on chess board dynamically?

text: I asked how to make resizable chessboard in here. nickjamesuk help me . Here is the code. I thought I can put queens on the board chess board easily after created resizable board, but it didn't work out. Now, I want to write whole problem here. For now, I don't need to solve the N-queens problem. I have some solution, and I want to represent that solutions of N-queens problem attractively. Here is an example: ![Board example](http://i.stack.imgur.com/tj735.png) Also, number of solution is different for each board size. Here is the source. I want to include all the solution for individual board sizes. End product should have two parameters. First one will resize the board from 1 to n. Second parameter will be used changing between different solutions for predefined board sizes. It seems very hard task for me. I will really appreciated everybody try to do it.


title: What's the difference between variables with and without a subscript?

text: If I input $x = a + b$, the $x$, $a$ and $b$ are blue. When I hit `Shif`+`Enter`, the $x$ turns black, indicating the kernel now knows this variable. But when I input $x_r = a + b$, and hit `Shift`+`Enter`, $x_r$ is still blue. What's the difference between variables with and without subscript?


title: Converting an expression to modular arithmetic automatically

text: I have the expression $\frac{1}{15} \left(-(-1)^n-5\times 2^{n+2}+3\times 2^{2 n+1}+15\right)$ which I want to calculate mod _m_ for a very large _n_. My current method is to ask for this exression in **FullForm** :               Times[Rational[1,15],Plus[15,Times[-1,Power[-1,n]],Times[-5,Power[2,Plus[2,n]]],Times[3,Power[2,Plus[1,Times[2,n]]]]]]      And to conver all `Rational`s and `Power`s to `PowerMod`s manually:               Mod[Times[PowerMod[15,-1,m],Plus[15,Times[-1,PowerMod[-1,n,m]],Times[-5,PowerMod[2,Plus[2,n],m]],Times[3,PowerMod[2,Plus[1,Times[2,n]],m]]]],m]      However, this is kind of time-consuming and I'm sure there's a better way. Is there any sort of 'smart' find-and-replace function I can apply to do something like this?


title: How should I reproduce this colorful swirling gif?

text: Surfing on the web, I came upon this cool gif: ![enter image description here](http://s6.pikabu.ru/post_img/2014/05/10/7/1399712484_969112766.gif) Does any one know how to reproduce this in Mathematica? I have some ideas myself, so I will try to answer this question as well.


title: Reading binary strings from file as strings

text: I have a file that contains binary strings like               01011     00101     01011      I want to import the file to Mathematica as a list of strings, but               Import["test.dat", "Table"]      gave me               {{1011}, {101}, {1011}},      which is a list of numbers rather than strings. What should I do to make sure that the binary strings are read as strings rather than numbers?


title: How would I get the best quality plot into a TeX editor which includes the legends?

text: I have currently used "Save Selection As" after highlighting the graph and legend and then saved it as a PNG file, but the quality isn't brilliant. I am using TeXworks on Windows 7. The "Copy As LaTeX" gives an error message as well, guess it doesn't like the legends. Saving it as a PDF or EPS file messes up the title in the plot, which are some recommendations I saw on different questions.


title: Multiplying a list and randomly re-assigning that list to a series of numbers

text: I'm trying to write a script that matches a particular element to a coordinate. Let's say there are 24 coordinates; and that fractionally a:b:c:d:e is 18%:18%:18%:18%:27%. Instead of matching 4 of a, b, c, and d to individual coordinates and e to the final 8 (to a sum of 24), I want to generate a list of 24 points from my initial list of a,b,c,d,e and those percentages and then randomly pair them to available coordinates. The current code I'm using is below, is there an easier way to do this? Inputs:               elements = Transpose[{{aa, bb, cc, dd, ee}}]     xelement = {0.09, 0.09, 0.09, 0.09, 0.18};     spin = Transpose[{{"Spin=4", "Spin=3", "Spin=3", "Spin=2",       "Spin=2"}}];          PosFCC = {     {0.000000, 0.250000, 0.500000 },      {0.166667, 0.750000, 0.000000 },      {0.333333, 0.750000, 0.500000 },      {0.666667, 0.750000, 0.500000 },      {0.833333, 0.500000, 0.500000 },      {0.833333, 0.250000, 0.000000 },      {0.333333, 0.500000, 0.000000 },      {0.500000, 0.750000, 0.000000 },      {0.833333, 0.750000, 0.000000 },      {0.000000, 0.000000, 0.000000 },      {0.000000, 0.500000, 0.000000 },      {0.333333, 0.000000, 0.000000 },      {0.000000, 0.750000, 0.500000 },      {0.500000, 0.000000, 0.500000 },      {0.166667, 0.000000, 0.500000 },      {0.166667, 0.250000, 0.000000 },      {0.666667, 0.500000, 0.000000 },      {0.500000, 0.500000, 0.500000 },      {0.666667, 0.250000, 0.500000 },      {0.166667, 0.500000, 0.500000 },      {0.333333, 0.250000, 0.500000 },      {0.666667, 0.000000, 0.000000 },      {0.500000, 0.250000, 0.000000 },      {0.833333, 0.000000, 0.500000}      };      Current Code:               pos1 = ArrayFlatten[{{elements, spin}}];     For[       (i = 1) && (balance = 0) && (store = pos1),       i < Dimensions[pos1][[1]] + 1,       i++,       (For[          j = 1,          j < (If[             balance > 1.01,             ((Round[xelement[[i]]*Dimensions[PosFCC][[1]]]) + 1),             (Round[xelement[[i]]*Dimensions[PosFCC][[1]]])             ]),          j++,          store = Insert[store, pos1[[i]], 1]          ])        &&        (If[          balance > 1.01,          balance = 0,           balance =            balance + (xelement[[i]]*Dimensions[PosFCC][[1]] -               Round[xelement[[i]]*Dimensions[PosFCC][[1]]])          ]         )       ];          pos2 = RandomSample[store];     pos3 = Transpose[Insert[Transpose[PosFCC], pos2[[All, 1]], 1]];     pos4 = Transpose[Insert[Transpose[pos3], pos2[[All, 2]], 5]];     posd = TableForm[pos4, TableSpacing -> {0, 5}];      Output:               bb     0.           0.25     0.5     Spin=3     dd     0.166667     0.75     0.      Spin=2     dd     0.333333     0.75     0.5     Spin=2     bb     0.666667     0.75     0.5     Spin=3     cc     0.833333     0.5      0.5     Spin=3     ee     0.833333     0.25     0.      Spin=2     aa     0.333333     0.5      0.      Spin=4     dd     0.5          0.75     0.      Spin=2     ee     0.833333     0.75     0.      Spin=2     bb     0.           0.       0.      Spin=3     aa     0.           0.5      0.      Spin=4     ee     0.333333     0.       0.      Spin=2     ee     0.           0.75     0.5     Spin=2     aa     0.5          0.       0.5     Spin=4     bb     0.166667     0.       0.5     Spin=3     bb     0.166667     0.25     0.      Spin=3     aa     0.666667     0.5      0.      Spin=4     cc     0.5          0.5      0.5     Spin=3     aa     0.666667     0.25     0.5     Spin=4     dd     0.166667     0.5      0.5     Spin=2     dd     0.333333     0.25     0.5     Spin=2     cc     0.666667     0.       0.      Spin=3     cc     0.5          0.25     0.      Spin=3     cc     0.833333     0.       0.5     Spin=3


title: Help using NIntegrate

text: I need some help with NIntegrate. I pasted the code that I wrote below; I know that up to "de" is correct. What I would like to do is NIntegrate de w.r.t phi{0,0.1} and curlE{-10,10}. The final answer should be just a number, but I am not sure if I am going about this wrong.                e = 1.60217657*10^-19;      n = 10^-10/e;      r = 1.5;      sigma = 50*10^-6;      p[phi_] := (r*phi^3)/(24 sigma);      g[curlEprime_] := Exp[-((curlEprime)^2/2)];           gSomething[phi_, curlE_] :=  With[{p = p[phi]}, p^(-(1/3)) (g[curlE - p] - g[curlE - 4             p]) + NIntegrate[     1/(curlE - curlEprime)^(1/3) g'[curlEprime], {curlEprime, curlE - p, curlE}]]           de[phi_, curlE_] := (2*e^2*n)/(3^(1/3)*Sqrt[2 Pi]*r^(2/3)*      sigma^(4/3))*gSomething[phi, curlE]           de1[phi_, curlE_] := NIntegrate[de[phi, curlE], {phi, 0, 0.103}]           de2[curlE_] := NIntegrate[de1[curlE], {curlE, -1, 1}]      So, at the end de2 should give a numerical value.


title: How to get output from standard error in command line?

text: I'm trying to run some external command line program in Mathematica, and I have problem getting the output. For example,               Import["!echo hello world\nexit\n", "Text"]     (*"hello world"*)      run echo and get the output. However this doesn't work for me               Import["!g++ -v", "Text"]      I only get an empty line. In version 10, there is the `RunProcess` function which seems to work               RunProcess[$SystemShell, "StandardError", "g++ -v      exit      "]          (*     Configured with: --prefix=/Library/Developer/CommandLineTools/usr \     --with-gxx-include-dir=/usr/include/c++/4.2.1     Apple LLVM version 6.0 (clang-600.0.51) (based on LLVM 3.5svn)     Target: x86_64-apple-darwin14.0.0     Thread model: posix     *)      My question is, can we do the same thing in version 9, using other functions ?


title: DensityPlot Increase Information

text: I am trying to make a density plot in Mathematica, however the distribution of the plot is not as visible as I would like. I plotted the same function in python and it contains a greater visible range of information. This can be seen in the first picture below. ![enter image description here](http://i.stack.imgur.com/0t5ES.png) When I try the same plot in Mathematica some information is lost. I cant see the decrease in intensity on either side of the central bright spot. I am using PlotRange "All" and I can adjust the plot range but I get large white spots where I am outside of the plot range. I am not sure how to tackle the problem if anyone has any ideas I would appreciate your thoughts! My code is as follows               DensityPlot[di, {x, -5, 5}, {y, -5, 5}, PlotLegends -> Automatic,      ColorFunction -> "Rainbow", PlotRange -> All]      Thanks, Ben ![enter image description here](http://i.stack.imgur.com/HVQ5M.png)


title: Graphics`Mesh`FindIntersections[ ] fails to detect intersections

text: `Graphics`Mesh`FindIntersections[ ]` is an undocumented function for, well, detecting intersections very efficiently. Take a look:               i = Import@"http://i.stack.imgur.com/PcWcz.png";     perim = ImageValuePositions[Thinning@EdgeDetect@i, 1];     fcp = FindCurvePath[perim];     perimPts = perim[[First@fcp]];     Graphics`Mesh`MeshInit[]; (*not sure if needed*)     myLine = Line@{1.1 {750.5`, 955.5`}, {182.5`, 671.5`}};     pts = Graphics`Mesh`FindIntersections[{myLine, Polygon@perimPts}];     Graphics[{Line@perimPts, Red, myLine, Green, PointSize[Large],                Point@pts}, AspectRatio -> Automatic]      ![Mathematica graphics](http://i.stack.imgur.com/dg9uX.png) But it doesn't work consistently (here I change `myLine`):               myLine = {Line@{{750.5`, 955.5`}, {182.5`, 671.5`}},                Line@{{622.5`, 1031.5`}, {222.5`, 831.5`}}};     pts = Graphics`Mesh`FindIntersections[{#, Polygon@perimPts}] & /@ myLine;     Graphics[{Line@perimPts, Red, Sequence @@ myLine, Green,                PointSize[Large], Point /@ pts}, AspectRatio -> Automatic]      ![Mathematica graphics](http://i.stack.imgur.com/e4Y6q.png) Is there something that can be done about this behavior?


title: Trying to graph trajectory function in Mathematica? Won't Graph?

text: The exercise is: define the trajectory function `y(x)` in _Mathematica_. Pick the initial speed (in meters per second) equal to `2` and the angle equal to `30 degrees`. Plot this function from `x=0` to `x=0.5`. I approached this problem by typing               y[x_] := x*Tan[θ] - ((9.8*x^2)/(2*v^2*(.5 + (.5*Cos[2 θ]))))      I then assigned θ and initial speed:                θ==30          v==2      and then wrote the plot function:               Plot[y, {x,0,0/5}]      AND THEN GOT AN EMPTY GRAPH! HELP!


title: NotebookWrite Multiple Selected Objects

text: Lets say I select shapes in a `Graphics` diagram in the following picture. ![enter image description here](http://i.stack.imgur.com/pMWRi.png) Generated from the following set of code:               Print[      Button["NotebookWrite",        (* Write Triangle *)       NotebookWrite[EvaluationNotebook[],         PolygonBox[{{-1, 0}, {1, 1}, {1, -1}}]         ];       ],      Dynamic[Refresh[        NotebookRead[SelectedNotebook[]]        , UpdateInterval -> 1]]      ]     Graphics[{       CircleBox[{0, 0}], CircleBox[{0, 0}],       CircleBox[{1, 1 }], CircleBox[{1, 1 }],       Rectangle[{0, -1}, {2, 1}], Rectangle[{0, -1}, {2, 1}]       }, ImageSize -> {55, 55}]      Now if I press ![NotebookWrite](http://i.stack.imgur.com/kYsDz.png) it replaces `{CircleBox[{0,0}],RectangleBox[{0,-1}]}` with a Triangle. ![enter image description here](http://i.stack.imgur.com/jOwMG.png) My question: Is there a way to replace each shape (`CircleBox[{0,0}]` and `RectangleBox[{0,-1}]`) with separate objects instead of replacing both with one object?


title: Plotting multiple vector fields with different domains in a single graph

text: I have attached a scheme of the problem. Essentially what I need is to plot 2 different vector fields in a single graph with different domains. The underlying physical problem is to model electric current around and inside a sphere of a different material than the surroundings. ![enter image description here](http://i.stack.imgur.com/Z9ZKb.png) Thanks


title: Simplifying using assumptions

text: Is there a way to simplify the following equation                (-p(a-x)((a-b)P(b-x)+Q(b+x)(a-b+2x))+q(a+x)(-(a-b)Q(b+x)+P(b-x)(-a +b+2x)))/((b-x)(-a + x)(a+x)(b+x))      assuming                {p+q == 1, P + Q == 1}      in order to get               q/(-a + x) - p/(a + x) - Q/(-b + x) + P/(b + x)      ? Although FullSimplify works in this case when I am using instead of p,q,P,Q variables with subscripts according to the following substitution:               {p -> Subscript[A,1], q -> Subscript[B,1], P -> Subscript[A,2], Q -> Subscript[B,2],a-> Subscript[a,1],b-> Subscript[a,2]}      FullSimplify ceases to produce the desired result! This is pretty unexpected behaviour!


title: Finding the position of strings in a list that contain a particular word/string sequence

text: If I have a list of strings Like:               text = Select[       StringSplit[        StringReplace[         StringTake[ExampleData[{"Text", "AliceInWonderland"}], {25, 997}],          Alternatives @@ Characters["<>?;'|:\"()-_!&"] -> " "], "." | ","],        StringLength[#] > 2 &]      > {"Alice was beginning to get very tired of sitting by her sister on the > bank"," and of having nothing to do"," Once or twice she had peeped into the > book her sister was reading"," but it had no pictures or conversations in > it"," and what is the use of a book"," thought Alice"," without pictures or > conversations So she was considering in her own mind as well as she could"," > for the day made her feel very sleepy and stupid "," whether the pleasure of > making a daisy chain would be worth the trouble of getting up and picking > the daisies"," when suddenly a White Rabbit with pink eyes ran close by > her"," There was nothing so very remarkable in that"," nor did Alice think > it so very much out of the way to hear the Rabbit say to itself"," Oh dear > Oh dear I shall be too late But when the Rabbit actually took a watch out of > its waistcoat pocket and looked at it and then hurried on"," Alice started > to her feet"," for it flashed across her mind that she had never before seen > a rabbit with "} how do I find the positions of the list elements that contain the following words/character strings:               words = {"her", "she", "alice", "bbit"};      Following on from this question, I tried using `Position` like so:               Position[text,       s_ /; StringMatchQ[s, __ ~~ Alternatives @@ words ~~ __,          IgnoreCase -> True] &]      > {} but this doesn't produce the list of positions. The follwing seems to suggest that I have the right string-matching criteria:               StringMatchQ[text, __ ~~ Alternatives @@ words ~~ __,       IgnoreCase -> True]      > > {True,False,True,False,False,False,True,True,True,True,True,True,True,True,True} What am I missing?


title: Renaming a list with name obtained interactively

text: I have a list say:               m = {1, 2, 3}      The list is inside a package, and is the result of a calculation. I want to give the user the option to rename it, for example with an input:               new = Input["enter a new name"]      I have not enough experience, but I tried in several ways and failed. The most obvious failure is to make:               new -> m      I cannot define `new` as a list prior to this assignment. On the other hand, I cannot define the name of a list as a vector with super-index or sub-index, for example:               v^i_; j = {1, 2, 3}      Can somebody help me?


title: Dynamic visualization of Graph[] on a webpage

text: How can we embed a dynamic version of a `Graph` object on a web page, similar to the one showcased on the networkx home page? This sort of dynamic visualization can be very useful for presentations, especially if more information could be shown than just the node names by tooltips.


title: Calling Table with custom iterator

text: I often find myself in situations where I, for example, need to build a table for some expression, but want to set the number of points rather then the step size, so the code ends up looking like this               lower = 0.2;     upper = Pi^2;     points = 100;     Table[Sin[x], {x, lower, upper, (upper - lower)/(points - 1)}] // ListPlot      I think that the typical Table syntax is much nicer in cases where we want to set the stepsize, but would much rather prefer to just think of the iteration specifications to be of the form {var,min,max,num} in these cases. Initially I though I would to this by just defining a function that takes this other iteration specification and returns the traditional equivalent, but since Table has holdall, you'd need to wrap everything in Evaluate which isn't pretty either example:               myIter[L_]:={L[[1]],L[[2]],L[[3]],(L[[3]]-L[[2]])/L[[4]]}     Table[Sin[x], Evaluate@myIter[{x, 0.2, Pi^2, 100}]] // ListPlot      So to get around this I added a pattern to modify the way Table is called if the second argument was wrapped in linIter:               linIter /: Table[exp_, iterator_linIter] := Table[exp, Evaluate@myIter[List @@ iterator]]     Table[Sin[x], linIter[x, 0.2, Pi^2, 100]] // ListPlot      This then allows me to have somewhat nice syntax to specify a new iterator. So my questions are   * Whether others have a more elegant way of implementing this, that allows one to call the expression with multiple iterators mixing step size and number based?   * What capabilities of `Table` I might possibly be losing by calling it this way?   * Is it possible to retain the syntax highlighting of `Table` while doing this?   * Also I'd appreciate general feedback. Am I committing blasphemy by messing with the call syntax for a built-in, or is would you easily get the intention if you where reading though some code that relied on this type of tricks to sort of have custom iterators?


title: NIntegrate with an arbitrary number of variables

text: I need to evaluate `NIntegrate` with a variable number of variables. Here's a concrete example. I'll accept an answer that finds a way to make the example work. I want to calculate the following integral: $$\int_0^1 \left( \sum_{i=1}^n x_i \right) \prod_{i=1}^n\mathrm{d}x_i = \frac{n}{2} $$ where $n$ is the number of variables. This particular integral can be separated into independent integrals, but in general this is not possible. I chose it because it is a simple example. In Mathematica, we start by defining `n`, say:               n = 4;      Then I try to evaluate the following command:               NIntegrate[Sum[x[i], {i, 1, n}],          Sequence@@Table[{x[i], 0, 1}, {i, 1, n}]]      and it gives an error. What I'm trying to do here is use `x[1], x[2], ...,x[n]` as variables of integration. Note that `Integrate` does work. So the problem is restricted to `NIntegrate`.


title: representing triplet data set with color on 2d plot

text: I have a huge list of data in the form of triplets numbers (e.g. {x,y,z}) and I want 2d plot. In which I want to plot y vs x on which values of z should be shown with color depending on the value of z for each x,y point. Means variation of z with color on x,y plot. Is it possible to show plot legend outside the plot boundaries? Please give me suggestions


title: ListPlot and ColorFunction

text: I've been searching for the use of ColorFunction as an Option for ListPlot, but haven't found anything about it in the documentation. When trying the code               ListPlot[      RandomReal[5, {10}]      , ColorFunction -> Hue[#1, #2, 1] &      ]      I get the error message               ListPlot::nonopt: "Options expected (instead of ColorFunction->Hue[#1,#2,1]&) beyond position 3 in ListPlot[{2.14801,2.18933,<<6>>,3.48,0.566812},ColorFunction-><<1>>&]. An option must be a rule or a list of rules."      Is it possible, and if so, how, to use ColorFunction with ListPlot? What are the arguments of the function, then? Thanks for all help, as always!


title: Coloring Points in a List Plot

text: > **Possible Duplicate:**   >  ListPlot with each point a different color and a legend bar I want to color the points in a list plot using a function of the (x,y) values. I tried this (example with random data):               ListPlot[RandomReal[1, {100, 2}],      PlotStyle -> Thick,      Joined -> False,      ColorFunction -> Function[{x, y}, Hue[(x + y)/2]]      ]      ![Mathematica graphics](http://i.stack.imgur.com/CUxbH.png) But, apparently, `ColorFunction` requires the data to be joined.               ListPlot[RandomReal[1, {100, 2}],      PlotStyle -> Thick,      Joined -> True,      ColorFunction -> Function[{x, y}, Hue[(x + y)/2]]      ]      ![Mathematica graphics](http://i.stack.imgur.com/1SVnh.png) That's a big ugly mess that I don't want. How can I get the points colored without joining them, am I missing something simple here?


title: Linking points in separate lists in ListPlot (updated)

text: **Updated:** I have two lists (of different lengths) of co-ordinates, in the form `{x,y,"tag"}`, that I wish to plot so that one list is graphically linked to the other list via their tags. In other words, I want to show the parent- daughter relationships between two datasets on a plot. Here is some example code:               parents = {Flatten@{RandomReal[10, 2], "p1" (*parent 1*)},         Flatten@{RandomReal[10, 2], "p2" (*parent 2*)}}          daughters =        Partition[        Flatten@Thread@          List[Partition[RandomReal[10, 12], 2], {"d1", "d1", "d1", "d2", "d2", "d2"}], 3]          (* d1 corresponds to p1, etc. *)          ListPlot[{parents[[All, 1 ;; 2]], daughters[[All, 1 ;; 2]]},       PlotMarkers -> {{"\[FilledSquare]", 18}, {"\[FilledDiamond]", 18}},       AxesOrigin -> {0, 0}]      which produces the following: > >     {{3.89794, 6.38947, "p1"}, {2.97147, 2.27053, "p2"}} >   >     {{5.05879, 8.04477, "d1"}, {3.94848, 0.52971, "d1"}, {0.310406, 5.55621, > "d1"}, >      {8.058, 4.5872, "d2"}, {9.64885, 3.806, "d2"}, {9.63257, 7.76892, > "d2"}} >   > > ![enter image description here](http://i.stack.imgur.com/D5Ykz.jpg) What I want to end up with is something like this: ![enter image description here](http://i.stack.imgur.com/JCCgz.jpg) I think this may be achieved with `Epilog` but I am unsure about how to utilise the 'tags' effectively. Does anyone know how to do this? Also, the number `daughters` relative to `parents` (although consistent in the above example) needs to be variable (e.g. 1 parent - 10 daughters,1 parent - 2 daughters, etc.) * * * **EDIT:** Just to clarify/extend the usefulness of what i'm trying to achieve (taking on board what was said by Halirutan and Mr Wizard in their answers), here is an amended example:               parents = {Flatten@{RandomReal[10, 2], "cats" },        Flatten@{RandomReal[10, 2], "dogs"},        Flatten@{RandomReal[10, 2], "frogs" }}          children =       Partition[       Flatten@Thread@         List[Partition[RandomReal[10, 18], 2], {"kittens", "kittens",            "kittens", "puppies", "puppies", "puppies", "tadpoles",            "tadpoles", "tadpoles"}], 3]     (* kittens corresponds to cats, etc. *)          ListPlot[{parents[[All, 1 ;; 2]], children[[All, 1 ;; 2]]},       PlotMarkers -> {{"\[FilledSquare]", 18}, {"\[FilledDiamond]", 18}},       AxesOrigin -> {0, 0}]      The output is essentially the same as above, however, the tags are unique and need to be related to each other explicitly. How do I tell Mathematica that kittens come from cats? **Update2:** For those who are interested here is an example of one of the plots created as a result of the answers: ![enter image description here](http://i.stack.imgur.com/Tddyf.jpg) The filled circles are starting compositions (made from various natural and synthetic rocktypes) for melting experiments between 700 - 1100 degC and 1 - 15 kbar. The diamonds are partial melts resulting from the incongruent melting of the starting material. The darker diamonds are low-pressure experiments. The lighter diamonds are high-pressure experiments. The small dots in the background are natural granite compositions for comparison. A first order observation is that the melts are always less mafic (MgO+FeO) than the starting material (and generally more potassic). One would expect that this phenomena would lead to the formation of more mafic residue if melt is lost from the system. Thanks again!


title: How can I speed up this plot manipulation? Why does Evaluate not help?

text: If I were able to "Save" the computed inverse function somewhere and then plot it, the manipulation would become faster. As I understand, Evaluate should do the job, but for some reason it does not. Why?               f[x_] := Sqrt[x]; c[x_] := x^2; g[x_] := c'[x]/f'[x];     x[gamma_, δ_, φ_, ρ_, mode_] :=        InverseFunction[g][gamma/(1 - δ*φ*ρ)*mode];          Manipulate[       Plot[         {Evaluate@x[gamma, δ, φ, ρ, 1],           Evaluate@x[gamma, δ, φ, ρ, 2]},         {gamma, 0, 10},          PlotRange -> {{0, 10}, {0, 10}}],           {δ, 0, 1}, {φ, 0, 1}, {ρ, 0, 1}     ]


title: RSolve: Errors while solving Partial Difference Equation

text: I tried solving following partial difference equation in _Mathematica_ by typing               RSolve[{C[n, k] == C[n-1, k] + C[n-1, k-1], C[n, 0] == 1, C[n, n] == 1}, C[n, k], {n, k}]      but returns the following error message > RSolve::conarg: The arguments should be ordered consistently. >> but it does not work, please someone help me in this regard. Thanks and regards in advance.


title: NDSolve doesn't solve my system of ODEs

text: What is causing the error in this code?               N0 = 4; μ = 2; ρ = 1; d = 1; n = 1;     eqone = Flatten[                Join[                  Table[x[i]''[t] == ϵ*(1 - x[i][t]^2)*x[i]'[t] - x[i][t] + d (z[t] - x[i][t]),                         {i, 0, N0}],                   {z'[t] == ρ*d/n (Sum[x[i][t] - z[t], {i, 0, N0}])}, z[0]==0,                     x[0][0] == 1, x[0]'[0] == .5, x[N0/2][0] == 0, x[N0/2]'[0] == 0},                  Table[x[i]'[0] == 0, {i, 1, N0/2 - 1}],                   Table[x[i][0] == 0, {i, 1, N0/2 - 1}],                  Table[x[i]'[0] == 0, {i, N0/2 + 1, N0}],                   Table[x[i][0] == 0, {i, N0/2 + 1, N0}]                    ]                    ]      and once I get my equations, I should be able to solve the differential equation, but it isn't working. I get a message that starts out: > The function value is not a list of numbers with dimensions ... I think I have to flatten something again in the NDSolve, but I'm not entirely sure how to do that and why.               eqtwo = NDSolve[eqone, {Table[x[i], {i, 0, N0}],z}, {t, 100}]


title: Assigning numerical values to constants results in complex coefficients in Equations of Motion

text: I am using Mathematica to get the Equations of Motion (EOM) for a mechanical system (using Lagrangian Mechanics). While I get the EOM in symbolic form, on introducing the following code for assigning numerical values to constants, the resulting EOMs of the system end up having complex coefficients.               ClearAll["Global`*"];     Needs["Notation`"];     Symbolize[ParsedBoxWrapper[SubscriptBox["_", "_"]]];          (*Segment C*)     Subscript[ρ, Al] = 2.7;   (*Density of Aluminium 6061 in g/cc*)     Subscript[ρ, MS] = 7.85; (*Density of Mild Steel in g/cc*)     Subscript[ρ, Fl] = 0.9;  (*Density of hyraulic fluid in g/cc*)          Subscript[r, C1] = 0.5;     Subscript[l, C1] = 4.2;     Subscript[r, C2] = 2;     Subscript[t, C2] = 0.25;     Subscript[l, C2] = 16.4;     Subscript[l, C3B] = 17.8;     Subscript[r, C3Bouter] = 1;     Subscript[r, C3Binner] = 0.45;     Subscript[r, C3s] = 2;     Subscript[l, C3s] = 0.6;     Subscript[l, C2f] = Subscript[l, C2] - Subscript[l, C3s];          Subscript[m, C1] = Subscript[l, C1] Subscript[ρ, Al]      \!\(\*SubsuperscriptBox[\(r\), \(C1\), \(2\)]\) N[π];     Subscript[m, C3s] = Subscript[l, C3s] Subscript[ρ, MS]      \!\(\*SubsuperscriptBox[\(r\), \(C3s\), \(2\)]\) N[π];     Subscript[m, C3B] = Subscript[l, C3B] Subscript[ρ, MS] (\!\(     \*SubsuperscriptBox[\(r\), \(C3Bouter\), \(2\)] -      \*SubsuperscriptBox[\(r\), \(C3Binner\), \(2\)]\)) N[π];     Subscript[m, C2s] = Subscript[l, C2] Subscript[ρ, Al] ((Subscript[r, C2] + Subscript[t, C2])^2 -\!\(\*SubsuperscriptBox[\(r\), \(C2\), \(2\)]\)) N[π];     Subscript[m, C2f] = Subscript[l, C2f] Subscript[ρ, Fl] \!\(\*SubsuperscriptBox[\(r\), \(C2\), \(2\)]\) N[π];     Subscript[m, C3] = Subscript[m, C3B] + Subscript[m, C3s];     Subscript[m, C] =  Subscript[m, C1] + Subscript[m, C2f] + Subscript[m, C2s] + Subscript[m, C3];          (*Segment B*)     Subscript[λ, P5] = 4.8; (*Linear mass density of Profile 5 \bars in g/cm*)     Subscript[b, B1] = 2;     Subscript[b, B2] = 4.367;     Subscript[l, B2] = 1.5;     Subscript[l, B1] = 32;     Subscript[l, B4] = 23.8;     Subscript[b, B4] = Subscript[b, B1];     Subscript[b, B3] = 8;     Subscript[l, B3] = 4;     Subscript[l, B] = 9.2;     Subscript[t, B2] = Subscript[b, B1];     Subscript[t, B3] = Subscript[b, B1];          Subscript[m, B1] = Subscript[λ, P5] Subscript[l, B1];     Subscript[m, B2] = Subscript[b, B2] Subscript[l, B2] Subscript[ρ, MS] Subscript[t, B2];     Subscript[m, B3] = Subscript[b, B3] Subscript[l, B3] Subscript[ρ, MS] Subscript[t,     B3];     Subscript[m, B4] = Subscript[λ, P5] Subscript[l, B4];     Subscript[m, B] = Subscript[m, B1] + Subscript[m, B2] + Subscript[m, B3] + Subscript[m, B4];          (*Segment D*)     Subscript[l, D1] = 36.8;     Subscript[b, D1] = 3;     Subscript[b, D2] = 6.8;     Subscript[l, D2] = 4;     Subscript[t, D2] = Subscript[b, B1];     Subscript[m, D1] = Subscript[λ, P5] Subscript[l, D1];     Subscript[m, D2] = Subscript[b, D2] Subscript[l, D2] Subscript[ρ, MS] Subscript[t,     D2];     Subscript[m, D] = Subscript[m, D1] + Subscript[m, D2];          (*Segment E*)     Subscript[l, E] = 75;     Subscript[b, E] = 22;     Subscript[m, E] = 50000; (*50 kg = 50,000 g*)          (*Terms used in the displacement constraints*)     Subscript[l, GB] = Subscript[l, B]/2;     Subscript[h, B] = Subscript[b, B1] + Subscript[b, B3] + Subscript[b, B4];     Subscript[h, GB] = Subscript[h, B]/2;     Subscript[l, GD] = Subscript[l, D1]/2;       Subscript[h, GD] = Subscript[b, D2]/2;     Subscript[l, GE] = Subscript[l, E]/2;     Subscript[l, D] = Subscript[l, D1];     α = 0.5;     Subscript[l, BL] = 2;     Subscript[h, BL] = Subscript[b, B2];     Subscript[l, DU] = 6;     Subscript[h, DU] = Subscript[b, D2];     g = 981; (*cm/sec^2*)     c = 3 10^7; (*3*10^4 is the average damping coefficient whilst using \kg and m*)     Subscript[W, g] = 15000 g;     Subscript[T, H] = 5*10^7; (*5 N-m = 5*10^7 when g and cm is employed instead of kg \and m*)     Subscript[T, K] = 5*10^7;      I guess I have made some mistake in this assignment due to which 'iota' somehow creeps into my resultant equations, but I am not able to figure out where the mistake is.


title: Summation with constraints

text: I am trying to do the summation shown below, $\sum_{i_1=0}^{imax_1} \sum_{i_2=0}^{imax_2} \dots \sum_{i_k=0}^{imax_k} f(i_1,\dots,i_k)$ $k$ is a variable. Therefore $i$ and $imax$ are defined as arrays of length $k$.               Array[i,k]     Array[imax,k]      Is there a way to accomplish this?


title: Selecting StyleBox with Cases

text: Continuing my question in this link, I would like to be able to select just a portion of the following expression:               Cell[TextData[{       "test ",       StyleBox["2+3", "Input"]      }], "Text"]      I wish now to select the part `"2+3"`. I've been thinking to do that with Cases, and have tried the following pattern for selecting the `StyleBox["2+3", "Input"]`:               _StyleBox      but that didn't seem to work. Any help with this? Thanks again for all the help!


title: Log of products to sum of logs

text: I have a log of products: $$\log \left(\prod _{i=1}^n \left( g(a(i,i)) \prod _{k=1}^i f(a(i,k))\right)\right)$$ That I turn into a sum of logs (I know everything involved is nice enough): $$\sum _{i=1}^n \left(\sum _{k=1}^i \log (f(a(i,k)))+\log (g(a(i,i)))\right)$$ I had to use a custom rule for this:               Log[Product[g[a[i, i]] Product[f[a[i, k]], {k, 1, i}], {i, 1, n}]] //.       {Log[Product[expr_, range_]] :> Sum[Log[expr], range],       Log[Times[a_, b_]] :> Log[a] + Log[b],       Log[Power[a_, n_]] :> n Log[a]}      Some observations: * * * `FullSimplify` does nothing, even with assumptions:               FullSimplify[      Log[Product[g[a[i, i]] Product[f[a[i, k]], {k, 1, i}], {i, 1, n}]],      {a[_, _] > 0 && g[_] > 0 && a[_, _] > 0 && f[_] > 0}]      * * * Not even with penalty for `Product` does it do anything:               FullSimplify[      Log[Product[a[i], {i, 1, n}]],      a[_] > 0,      ComplexityFunction ->       (20 Count[#, _Product, Infinity] + LeafCount[#] &)]      * * * But for `Times` it works:               FullSimplify[      Log[a b c],      a > 0 && b > 0 && c > 0,      ComplexityFunction ->       (20 Count[#, _Times, Infinity] + LeafCount[#] &)]     (* Log[a] + Log[b] + Log[c] *)      Unless I use `a[i]`               FullSimplify[      Log[a[1] a[2] a[3] ],      a[_] > 0 , (* a[1]>0 && a[2]>0 && a[3]>0 works *)      ComplexityFunction -> (20 Count[#, _Times, Infinity] + LeafCount[#] &)]      * * * Is there a more general way to do this that does not rely on making up a bunch of manual transformations?


title: Set all output to be of specific form

text: I want every output expression in a notebook to use `//PowerExpand` and also to format numbers as scientific. Is there a way to do this without explicitly calling `ScientificForm[]` and `//PowerExpand` on every input? i.e. I want to be able to enter               In: 4.3*^-5*Sqrt[M]*(L*n^2)^{3/4}     Out: {0.000043 \Sqrt[M] (L n^2)^(3/4)}      and instead get,               Out: 4.3e-5 M^(1/2} L^(3/4} n^(3/2)      ~~Aside: is there a way to make mathematica ** _never_** use radical symbols, and to use exponents instead?~~


title: Strategies to avoid LessEqual::nord in NMinimize?

text: When using `NMinimize` on functions with complex intermediate expressions (but a real end result), quite often one gets the error `LessEqual::nord`. Example:               NMinimize[Abs[(a+I b)^(3/2)],{a,b}]     (*     LessEqual::nord: Invalid comparison with 0.306069 + 0. I attempted.          LessEqual::nord: Invalid comparison with 0.306069 + 0. I attempted.          LessEqual::nord: Invalid comparison with 0.306069 + 0. I attempted.          General::stop: Further output of LessEqual::nord          will be suppressed during this calculation.          Less::nord: Invalid comparison with -0.0745302 + 0. I attempted.          NMinimize::cvmit:         Failed to converge to the requested accuracy or precision within 100          iterations.          {1.0635969220476164*^-12 + 0.*I, {a -> -8.71759358950322*^-9, b -> 5.707170335837908*^-9}}     *)      In some cases (not the one above; I didn't find a simple one where it happens) this also results in a clearly wrong result. Therefore it's desirable to remove the error messages. Now the only way to get rid of this error is to change the expression in a way that it doesn't trigger the error. However the expressions are generally complicated enough that it's not feasible by hand. I've found that a combination of the following strategies works _sometimes:_   * Use `ComplexExpand` with the option `TargetFunctions->{Re,Im}`.   * Put the entire expression into an `Abs` or `Re` (despite it being known to be real from construction) and use `Simplify` or `FullSimplify` with appropriate constraints (and hope it finishes in reasonable time). (`Abs` of course only works if the result is also nonnegative) However those strategies are not always sufficient. Therefore my question: What are other good strategies to get the expression into a form suitable to `NMinimize`?


title: How to convert comment in RowBox to DisplayForm string

text: ToExpression[RowBox[{"a","(*","what", "*)"}],StandardForm]      This conversion above ignores the commment content `(*what*)` The result I expected is something like the `DisplayForm` below.               RowBox[{"a","(*","what","*)"}]//DisplayForm      ![enter image description here](http://i.stack.imgur.com/Le4UJ.png) Update: one of my test code, how to improve it, and not use (`StringReplace`) if possible.               RowBoxtoString[x_]:=StringReplace[     ToString[ToExpression[x/.RowBox[{"(*",t_,"*)"}]:>"CommentLeft"<>(StringJoin@@t)<>"ComentRight"],     StandardForm],     Shortest["CommentLeft"~~t__~~"ComentRight"]:>"(*"<>t<>"*)"]          RowBoxtoString[RowBox[{"(*","Comment Content","*)"}]]     (*Comment Content*)


title: Negative probability?

text: I am trying to get the sum of the squares of seven random variables, all uniformly distributed. This is what I tried.               Probability[       a^2 + b^2 + c^2 + d^2 + e^2 + f^2 + g^2 < 1,       {a, b, c, d, e, f, g} \[Distributed]        UniformDistribution[{{0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}}]]      The output was > >     -π^3/840 >   How can I get _Mathematica_ to get the right answer? **Warning:** the code takes about seven minutes to run on my machine.


title: Improve TextRecognize on numbers

text: I have an image contain only numbers, and TextRecognize fail to recognize some numbers: img=![enter image description here](http://i.stack.imgur.com/cPRrY.png);               TextRecognize[img]     (*826718*)      The documentation says that "The quality of recognized text may improve by enlarging the image", but no luck on this example               TextRecognize[ImageResize[img, Scaled[2]]]     (*826718*)      also tried different language, also no help               TextRecognize[ImageResize[img, Scaled[2]], Language -> "French"]     (*826718*)      I also tried Walfram|Alpha, it also gave the same results as Mathematica: ![enter image description here](http://i.stack.imgur.com/GknU9.png) Are there some ways to solve the problem?


title: Animation of moving rectangles in 2D from data file

text: I am not very familiar with mathematica but I know the basics so I thought I give it a try. For a project I have to animate rectangles moving around in 2D (later also 3D). The data come from a C simulation I wrote so I can change the output as I want, but for now I have **N** files each looking like this:               t       x-coordinate      y-coordinate     length     1           1                 3              10     2           5                 3              10     3           10                3              10     ...         ...               ...            ...      the thickness of the rectangles should be const over time. How would you approach this? I found the help on importing data and making animations rather confusing so far. Please help me.


title: How can I make an InputField with a proper newline/carriage return?

text: The return key does not work as expected in an InputField, how can I overcome this?


title: Make Enter create new line break inside InputField

text: I would like to write multiple lines of text inside an `InputField`, using `ContinuousAction->True` to update some variable `x` (so I don't need `Enter`).               InputField[Dynamic[x], String, ContinuousAction -> True]      ![enter image description here](http://i.stack.imgur.com/kYKwI.png) To do the above image, I have to copy and past the text. The point is, if I press `Enter`, the standard behavior is to try to update `x` value. How can I change it in order to make `Enter` to create a new line break in the text inside the `InputField` instead of try to evaluate it?


title: Input text field GUI

text: Is there a way to input multiple rows of text and save it as a variable? Like an InputField, but with multiple rows? I would like to make a simple text redactor, so that I could enter a text and then use it as a variable.


title: why Level does not sort output according to their levels

text: Consider this example:               Level[a + f[x, y^n], {0, Infinity}]          (*{a, x, y, n, y^n, f[x, y^n], a + f[x, y^n]}*)      Why the output is sorted in this way. why not following their levels? I was expecting to get:               (*{a + f[x, y^n], a, f[x, y^n], x, y^n, y, n}*)


title: Copying each object in a plot as an image

text: I would like to copy a plot from _Mathematica_ as an image, into a powerpoint slide. This plot has two curves. When I try to do the (naïve) usual "copy graphics" and paste, I find the full plot (along with the two curves) as a single image. I wish to copy the image such that powerpoint can view the plot as three different objects:   1. The X-Y axes alone.   2. Curve 1   3. Curve 2 Here is an example of two functions and the plot:               f[x_] := (1 - x)^20 + 12*(1 - x)^19*x + 225*(1 - x)^18*x^2 + 1820*(1 - x)^17*x^3 + 13182*(1 - x)^16*x^4 + 16112*(1 - x)^15*x^5 + 15681*(1 - x)^14*x^6 + 15395*(1 - x)^13*x^7 + 15226*(1 - x)^12*x^8 + 15141*(1 - x)^11*x^9 + 15127*(1 - x)^10*x^10 + 15152*(1 - x)^9*x^11 + 15210*(1 - x)^8*x^12 + 15266*(1 - x)^7*x^13 + 15339*(1 - x)^6*x^14 + 15403*(1 - x)^5*x^15 + 15465*(1 - x)^4*x^16 + 15517*(1 - x)^3*x^17 + 15564*(1 - x)^2*x^18 + 15622*(1 - x)*x^19 + 15684*x^20;          g[x_] := (641135*(1 - x)^15*x^5)/171 + (802276*(1 - x)^14*x^6)/95 + (15581573*(1 - x)^13*x^7)/855 + (15099914*(1 - x)^12*x^8)/855 + (172649*(1 - x)^11*x^9)/10 + (14529139*(1 - x)^10*x^10)/855 + (5748121*(1 - x)^9*x^11)/342 + (950524*(1 - x)^8*x^12)/57 + (14169122*(1 - x)^7*x^13)/855 + (939301*(1 - x)^6*x^14)/57 + (1556712*(1 - x)^5*x^15)/95 + (27851407*(1 - x)^4*x^16)/1710 + (27665347*(1 - x)^3*x^17)/1710 + (305276*(1 - x)^2*x^18)/19 + (606145*(1 - x)*x^19)/38 + (2306804*x^20)/285;          Plot[{0.1 f[p], g[p]}, {p, 0, 1/2}, PlotStyle -> {{Thick, Blue}, {Thick, Red}}, LabelStyle -> Large, AxesStyle -> Thick]      Can I make _Mathematica_ output three objects separately ? In that case I can copy each one and paste them in powerpoint.


title: Creating an Adjacency Matrix to connect an undirected network

text: I used the locator pane to map a network, specifically the Maryland Power Grid. **What I would like is to have some sort of numbering of the vertices on the unconnected network, how to make an adjacency matrix for the network to then use that to connect the network, and show either in color or shape that some vertices are different (i.e. loads and generators).** It might be worthy to note that I first recorded the loads then the generators from left to right, consequently the last 13 vertices are generators. Here is the code I used for the locator pane, The Maryland Power Grid picture I imported to record vertices, and the resulting network. The locator pane code makes the x and y coordinates unitary. Locator Pane Code                im= Import["http://esm.versar.com/pprp/ceir16/Images/Figure2_20.jpg"];     Module[{picturesize,i,bigger,imagesizes},     picturesize=675;     values={};     i=1;     imagesizes=ImageDimensions[im];bigger=1;     DynamicModule[{pt={0,0}},     If[imagesizes[[1]]<imagesizes[[2]], bigger=2];     TableForm@{         Button["Record!",AppendTo[values,{i,pt}];i++;],         LocatorPane[             Dynamic@pt,             Dynamic@Graphics[                 Join[                     {Inset[im,{0,0},{0,0},{1,1}]}                      ],             PlotRange->{{0,imagesizes[[1]]/imagesizes[[bigger]]},{0,imagesizes[[2]]/imagesizes[[bigger]]}},             ImageSize->picturesize]     ],     Dynamic[N@pt],     Dynamic[MatrixForm@values]     }]     ]      The Maryland Power Grid I used with the locator pane ![enter image description here](http://i.stack.imgur.com/IUz0n.jpg) The resulting unconnected network ![enter image description here](http://i.stack.imgur.com/v4LcJ.jpg) The locator pane also returned an array of points in the form {n, {x,y}} where n is the vertex number recorded chronologically (I tried to do them from left to right) and the x and y are the x and y unitary coordinates.               ({       {1, {0.0996, 0.4195}},       {2, {0.1046, 0.392}},       {3, {0.1144, 0.468}},       {4, {0.1164, 0.4415}},       {5, {0.1432, 0.4455}},       {6, {0.1442, 0.376}},       {7, {0.147, 0.5085}},       {8, {0.16, 0.4965}},       {9, {0.1628, 0.5305}},       {10, {0.1708, 0.484}},       {11, {0.1776, 0.379}},       {12, {0.1836, 0.4335}},       {13, {0.1856, 0.408}},       {14, {0.1936, 0.4495}},       {15, {0.2034, 0.5295}},       {16, {0.1974, 0.3595}},       {17, {0.2122, 0.4395}},       {18, {0.2152, 0.4465}},       {19, {0.2252, 0.3555}},       {20, {0.229, 0.4415}},       {21, {0.2716, 0.3535}},       {22, {0.2952, 0.313}},       {23, {0.3258, 0.4265}},       {24, {0.3446, 0.475}},       {25, {0.3476, 0.4315}},       {26, {0.3536, 0.408}},       {27, {0.3584, 0.3545}},       {28, {0.3694, 0.3665}},       {29, {0.3732, 0.384}},       {30, {0.393, 0.3535}},       {31, {0.395, 0.4205}},       {32, {0.4028, 0.3625}},       {33, {0.4028, 0.378}},       {34, {0.4088, 0.3525}},       {35, {0.4108, 0.4345}},       {36, {0.4286, 0.4505}},       {37, {0.4336, 0.405}},       {38, {0.4434, 0.247}},       {39, {0.4542, 0.303}},       {40, {0.4532, 0.4415}},       {41, {0.4612, 0.3515}},       {42, {0.469, 0.3455}},       {43, {0.47, 0.3685}},       {44, {0.477, 0.391}},       {45, {0.4888, 0.31}},       {46, {0.4948, 0.3315}},       {47, {0.4958, 0.371}},       {48, {0.4986, 0.217}},       {49, {0.4918, 0.4375}},       {50, {0.5214, 0.376}},       {51, {0.5244, 0.3455}},       {52, {0.5284, 0.4315}},       {53, {0.5294, 0.457}},       {54, {0.5302, 0.471}},       {55, {0.5302, 0.2875}},       {56, {0.554, 0.243}},       {57, {0.554, 0.323}},       {58, {0.554, 0.299}},       {59, {0.559, 0.231}},       {60, {0.559, 0.2575}},       {61, {0.559, 0.2725}},       {62, {0.5628, 0.244}},       {63, {0.5668, 0.221}},       {64, {0.5668, 0.316}},       {65, {0.5708, 0.1755}},       {66, {0.5816, 0.2665}},       {67, {0.5836, 0.224}},       {68, {0.5916, 0.152}},       {69, {0.5806, 0.307}},       {70, {0.5826, 0.3365}},       {71, {0.5876, 0.32}},       {72, {0.5974, 0.242}},       {73, {0.5984, 0.2845}},       {74, {0.6044, 0.2865}},       {75, {0.5856, 0.397}},       {76, {0.5906, 0.3605}},       {77, {0.5916, 0.388}},       {78, {0.6014, 0.3385}},       {79, {0.6054, 0.388}},       {80, {0.6132, 0.299}},       {81, {0.6132, 0.2865}},       {82, {0.6142, 0.2745}},       {83, {0.6182, 0.375}},       {84, {0.6252, 0.245}},       {85, {0.6252, 0.3355}},       {86, {0.629, 0.3605}},       {87, {0.63, 0.371}},       {88, {0.63, 0.388}},       {89, {0.633, 0.474}},       {90, {0.635, 0.3535}},       {91, {0.641, 0.3525}},       {92, {0.639, 0.411}},       {93, {0.6438, 0.3585}},       {94, {0.6458, 0.4355}},       {95, {0.6488, 0.473}},       {96, {0.6548, 0.2695}},       {97, {0.6576, 0.38}},       {98, {0.6646, 0.4455}},       {99, {0.6736, 0.3685}},       {100, {0.6764, 0.4415}},       {101, {0.6774, 0.396}},       {102, {0.6902, 0.402}},       {103, {0.6932, 0.373}},       {104, {0.6962, 0.473}},       {105, {0.6972, 0.453}},       {106, {0.718, 0.389}},       {107, {0.7268, 0.292}},       {108, {0.7228, 0.4335}},       {109, {0.7288, 0.457}},       {110, {0.7426, 0.296}},       {111, {0.7406, 0.4235}},       {112, {0.7644, 0.295}},       {113, {0.7624, 0.457}},       {114, {0.7802, 0.4225}},       {115, {0.7802, 0.2855}},       {116, {0.7822, 0.3355}},       {117, {0.797, 0.4315}},       {118, {0.799, 0.4495}},       {119, {0.8028, 0.4415}},       {120, {0.8168, 0.1235}},       {121, {0.8088, 0.459}},       {122, {0.8226, 0.1045}},       {123, {0.8186, 0.3465}},       {124, {0.8168, 0.468}},       {125, {0.8286, 0.244}},       {126, {0.8256, 0.2825}},       {127, {0.8266, 0.329}},       {128, {0.8226, 0.38}},       {129, {0.8196, 0.4345}},       {130, {0.8394, 0.167}},       {131, {0.8532, 0.291}},       {132, {0.8602, 0.1245}},       {133, {0.8652, 0.1085}},       {134, {0.8898, 0.166}},       {135, {0.8938, 0.133}},       {136, {0.9164, 0.221}},       {137, {0.9244, 0.153}},       {138, {0.9284, 0.1845}},       {139, {0.1076, 0.4125}},       {140, {0.1224, 0.3445}},       {141, {0.15, 0.4205}},       {142, {0.4028, 0.4215}},       {143, {0.4642, 0.33}},       {144, {0.467, 0.3395}},       {145, {0.5362, 0.242}},       {146, {0.548, 0.2525}},       {147, {0.5638, 0.131}},       {148, {0.6102, 0.1775}},       {149, {0.629, 0.3435}},       {150, {0.64, 0.456}},       {151, {0.6458, 0.317}},       {152, {0.6488, 0.3535}},       {153, {0.6508, 0.385}},       {154, {0.6538, 0.3365}},       {155, {0.6636, 0.328}},       {156, {0.6626, 0.161}},       {157, {0.6764, 0.3555}},       {158, {0.6854, 0.456}},       {159, {0.7002, 0.465}},       {160, {0.708, 0.387}},       {161, {0.715, 0.4345}},       {162, {0.716, 0.2635}},       {163, {0.7812, 0.1815}},       {164, {0.8958, 0.1925}}      })


title: How to make the suggestion box appear?

text: When you type a function in Matlab, quickly a suggestion box comes up showing functions similar to the one you're typing. I thought that Mathematica didn't have this but one day, I typed half of a function and the went to the kitchen when I got back, the suggestion box was there. I'm not sure if it appears after some time or if I accidentaly pressed some key.


title: Progress indicator with shared variables

text: I'm trying to create a custom progress indicator for a parallelized computation, using `Dynamic` and `SetSharedVariables` to display and update the progress indicator during the calculation. Two questions:   1. **What is the best way to allow parallel kernels to update the progress?** Should I have a function which accepts a `Dynamic[x_]` argument and do something like this?              Monitor[PerformCalculations[Dynamic[progress]],       ProgressIndicator[Dynamic[progress]]];     (* or this: *)     ProgressIndicator[Dynamic[progress]]     PerformCalculations[Dynamic[progress]]          (* note: 'progress' here will be a list or some other custom structure         for indicating various aspects of the progress of each kernel *)          PerformCalculations[Dynamic[progress_]] := Module[{calc, ...},         SetSharedVariable[progress];         calc[stuff_] := Module[{...},           ...;           (* how does this part work? *) UpdateProgress[Dynamic[progress]];          ];         ParallelMap[calc, data];       ];   2. **How do I avoid race conditions of shared variables?** A quick test indicates that shared variables have some caveats when running with parallel kernels: ![](http://i.stack.imgur.com/i22Im.png) I would have expected the `test = Append[test, ...]` expression to be evaluated atomically so that each kernel would build on the results of the kernels that had already executed. However it seems like the kernels read the value of `test` before writing it, so there is a race condition that causes the final value to be simply `{8}`. What is the best way to avoid this issue?


title: Add Scroll bar to Panel or Column or Row?

text: This will be a simple question. Sometimes it is helpful to control the size of content displayed while having a scroll bar so content is not truncated. Is it possible to have a scroll bar attached to Panel[], Column[], Grid[] or Row[] element? So that I can at least specify a maximum width/height beyond which a scroll bar will appear. Thanks!


title: What should I do if the geographical map provided by Mathematica doesn't show some rivulets?

text: I have a list of geographical coordinates(maybe the coordinates are not that accurate, but the problem is not that vital):                geodata = {{"30\[Degree]16'38.43''N",       "120\[Degree]10'55.54''E"}, {"30\[Degree]16'18.17''N",       "120\[Degree]11'2.03''E"}, {"30\[Degree]15'58.53''N",       "120\[Degree]11'2.58''E"}, {"30\[Degree]15'38.9''N",       "120\[Degree]11'0.67''E"}, {"30\[Degree]15'29.61''N",       "120\[Degree]11'0.63''E"}, {"30\[Degree]15'21.84''N",       "120\[Degree]10'59.94''E"}, {"30\[Degree]15'10.91''N",       "120\[Degree]10'57.55''E"}, {"30\[Degree]15'52.85''N",       "120\[Degree]12'48.06''E"}, {"30\[Degree]15'46.65''N",       "120\[Degree]12'25.2''E"}, {"30\[Degree]15'36.61''N",       "120\[Degree]12'10.54''E"}, {"30\[Degree]15'26.53''N",       "120\[Degree]11'59.61''E"}, {"30\[Degree]15'16.68''N",       "120\[Degree]11'45.45''E"}, {"30\[Degree]15'1.32''N",       "120\[Degree]11'40.07''E"}, {"30\[Degree]14'51.96''N",       "120\[Degree]11'36.82''E"}, {"30\[Degree]14'35.73''N",       "120\[Degree]11'22.55''E"}, {"30\[Degree]15'40.19''N",       "120\[Degree]13'10.21''E"}, {"30\[Degree]15'28.39''N",       "120\[Degree]13'0.05''E"}, {"30\[Degree]15'9.78''N",       "120\[Degree]12'43.92''E"}, {"30\[Degree]14'58.1''N",       "120\[Degree]12'33.66''E"}, {"30\[Degree]14'38.61''N",       "120\[Degree]12'16.68''E"}, {"30\[Degree]14'33.41''N",       "120\[Degree]12'12.38''E"}, {"30\[Degree]14'21.62''N",       "120\[Degree]12'1.76''E"}, {"30\[Degree]14'51.43''N",       "120\[Degree]12'7.32''E"}, {"30\[Degree]14'59.66''N",       "120\[Degree]12'1.47''E"}, {"30\[Degree]15'7.55''N",       "120\[Degree]11'55.81''E"}, {"30\[Degree]15'13.21''N",       "120\[Degree]11'51.7''E"}} // GeoPosition;      And I want to show those points in one picture with the background being the local map. At first I tried               GeoGraphics[GeoMarker[geodata], ImageSize -> 600]      as you can see, ![here](http://i.stack.imgur.com/GMtZI.png) there should be a rivulet at every geomarker, just as the one on the left of the picture. But the map _Mathematica_ originally provided is not precise enough, the rest rivulets are not shown here( **Those rivulets are very important!** ). Then I used `GeoStyling["ReliefMap"]` and `GeoStyling["ContourMap"]` to specify a small region just to make it present better,               << "ComputationalGeometry`";     GeoGraphics[{GeoStyling["ContourMap"], Polygon[#]},ImageSize -> 600] &[     Extract[geodata[[1]], List /@ ConvexHull[geodata[[1]]]] //      GeoPosition]      (Here **ComputationalGeometry** package and `ConvexHull` are used to generate a convexhull, they don't matter much) but you will see that the polygon is just a piece of green, the same problem still remains. So what should I do to make the map more precise that can show the small rivulets? Thanks! **Edit:** I have thought to use google earth to screenshot the map, but the rivulets are too thin to distinguished from the background, it's hard to use image-processing method. And, if I use google map, but google map doesn't support multi-geomarkers like 26, I can't show every geomarkers on google map. Or else, I firstly take the screenshot, then add the geomarkers, but I think it's not easy to place the geomarkers at accurate places.


title: Dynamic[] and Print[]

text: > **Possible Duplicates:**   >  Intermediate display similar to PrintTemporary   >  Estimating progress on plots   >  How to create a progress bar?   >  How to determine how much of a table is generated? I'm trying to print an output from every iteration of a `Do[]` loop, but without it continuing down the notebook. I want the `Print[]` output to be overwritten in the same cell with the new value. Here is a MWE of what I'm trying, but I can't seem to get the expected behavior.               Do[       If[i==1,         Print["Output = ", Dynamic[i]]       ]     ,{i,10}     ]      So in other words, on the first iteration, I want to see "Output = 1", and then every subsequent iteration I want to see the 1 change to a 2, 3, 4, etc. in the same cell.


title: Industrial Level Applications. Recipe for mixed notation of equations set

text: I am working with large (linear) equations set within Mathematica in numerical notation. For example, set from 4056 eq. is solved for a second, no more. There is no doubt, result is great. But even simple mixed (both numeric and symbolic) data in 5-20 equation set is the problem... What is the reason? And what the way to solve it? Is it necessary to filter (provide) all data to symbolic form. Data are presented by three forms: 23.234 (float), 23/11 (aka fraction), F/w (symbolic). **Example**               Equations = {c1bXZ[1] - c1bXZ[2] + c1bXZ[5] == (-1)*0, -c1bXZ[1] +      c1bXZ[3] + c1bXZ[4] == (-1)*0,      c1bXZ[2] == (-1)*RX[3], -c1bXZ[3] == (-1)*     RX[4], -c1bXZ[4] == (-1)*0, -c1bXZ[5] == (-1)*F, -c1bYZ[1] +      c1bYZ[2] + c1sStr[5] == (-1)*0, -1000 + c1bYZ[1] - c1bYZ[3] +      c1sStr[4] == (-1)*0, -c1bYZ[2] == (-1)*RY[3],      c1bYZ[3] == (-1)*     RY[4], -c1sStr[4] == (-1)*0, -c1sStr[5] == (-1)*0, -c1bYZ[5] -      c1sStr[1] + c1sStr[2] == (-1)*0, -c1bYZ[4] + c1sStr[1] -      c1sStr[3] == (-1)*0, -c1sStr[2] == (-1)*RZ[3],      c1sStr[3] == (-1)*RZ[4], c1bYZ[4] == (-1)*0, c1bYZ[5] == (-1)*0,      c1bYZ[2] - c2bYZ[1] + c2bYZ[2] - c2bYZ[5] ==      0, -500 + c1bYZ[1] + c2bYZ[1] - c2bYZ[3] - c2bYZ[4] ==      0, -c2bYZ[2] == 0, c1bYZ[3] + c2bYZ[3] == 0,      c1bYZ[4] + c2bYZ[4] == 0, c1bYZ[5] + c2bYZ[5] == 0,      c1bXZ[2] - c1tTor[5] - c2bXZ[1] + c2bXZ[2] == 0,      c1bXZ[1] - c1tTor[4] + c2bXZ[1] - c2bXZ[3] == 0, -c2bXZ[2] == 0,      c1bXZ[3] + c2bXZ[3] == 0, 200 + c1tTor[4] == 0,      200 + c1tTor[5] == 0,      c1tTor[1] - c1tTor[2] - c2bXZ[5] ==      0, -c1tTor[1] + c1tTor[3] - c2bXZ[4] == 0,      c1tTor[2] == MZ[3], -c1tTor[3] == MZ[4],      200 + c1bXZ[4] + c2bXZ[4] == 0, -200 + c1bXZ[5] + c2bXZ[5] ==      0, -c4bXZ[2] ==      0, (-c1bXZ[3] - 3*c2bXZ[3] - 2400000*c3bXZ[3])/2400000 -      c4bXZ[3] == 0,      c4bYZ[2] ==      0, (c1bYZ[3] + 3*c2bYZ[3] + 2400000*c3bYZ[3])/2400000 + c4bYZ[3] ==     0, -c2sStr[2] == 0, -c1sStr[3]/2000000000 - c2sStr[3] ==      0, -c4bXZ[1] == (-c1bXZ[2] - 3*c2bXZ[2] - 2400000*c3bXZ[2])/      2400000 -      c4bXZ[2], (-c1bXZ[2] - 3*c2bXZ[2] - 2400000*c3bXZ[2])/2400000 -      c4bXZ[2] == -c4bXZ[      5], (-c1bXZ[1] - 3*c2bXZ[1] - 2400000*c3bXZ[1])/2400000 -      c4bXZ[1] == -c4bXZ[3], -c4bXZ[3] == -c4bXZ[4],      c4bYZ[1] == (c1bYZ[2] + 3*c2bYZ[2] + 2400000*c3bYZ[2])/2400000 +      c4bYZ[2], (c1bYZ[2] + 3*c2bYZ[2] + 2400000*c3bYZ[2])/2400000 +      c4bYZ[2] ==      c2sStr[5], (-250 + c1bYZ[1] + 3*c2bYZ[1] + 2400000*c3bYZ[1])/      2400000 + c4bYZ[1] == c4bYZ[3],      c4bYZ[3] ==      c2sStr[4], -c2sStr[1] == -c1sStr[2]/2000000000 -      c2sStr[2], -c1sStr[2]/2000000000 - c2sStr[2] ==      c4bYZ[5], -c1sStr[1]/2000000000 -      c2sStr[1] == -c2sStr[3], -c2sStr[3] == c4bYZ[4], -c2tTor[2] ==      0, -c1tTor[3]/140000 - c2tTor[3] == 0,      c3bYZ[1] == (c1bYZ[2] + 2*c2bYZ[2])/800000 +      c3bYZ[2], (c1bYZ[2] + 2*c2bYZ[2])/800000 + c3bYZ[2] ==      c3bYZ[5], (-1000 + 3*c1bYZ[1] + 6*c2bYZ[1])/2400000 + c3bYZ[1] ==      c3bYZ[3], c3bYZ[3] == c3bYZ[4],      c3bXZ[1] == (c1bXZ[2] + 2*c2bXZ[2])/800000 +      c3bXZ[2], (c1bXZ[2] + 2*c2bXZ[2])/800000 + c3bXZ[2] ==      c2tTor[5], (c1bXZ[1] + 2*c2bXZ[1])/800000 + c3bXZ[1] == c3bXZ[3],      c3bXZ[3] ==      c2tTor[4], -c2tTor[1] == -c1tTor[2]/140000 -      c2tTor[2], -c1tTor[2]/140000 - c2tTor[2] ==      c3bXZ[5], -c1tTor[1]/140000 -      c2tTor[1] == -c2tTor[3], -c2tTor[3] == c3bXZ[4]}      And Unknowns:               Unknows = {c1bXZ[1], c1bXZ[2], c1bXZ[3], c1bXZ[4], c1bXZ[5], c2bXZ[1],     c2bXZ[2], c2bXZ[3], c2bXZ[4], c2bXZ[5], c3bXZ[1], c3bXZ[2],      c3bXZ[3], c3bXZ[4], c3bXZ[5], c4bXZ[1], c4bXZ[2], c4bXZ[3],      c4bXZ[4], c4bXZ[5], c1bYZ[1], c1bYZ[2], c1bYZ[3], c1bYZ[4],      c1bYZ[5], c2bYZ[1], c2bYZ[2], c2bYZ[3], c2bYZ[4], c2bYZ[5],      c3bYZ[1], c3bYZ[2], c3bYZ[3], c3bYZ[4], c3bYZ[5], c4bYZ[1],      c4bYZ[2], c4bYZ[3], c4bYZ[4], c4bYZ[5], c1sStr[1], c1sStr[2],      c1sStr[3], c1sStr[4], c1sStr[5], c2sStr[1], c2sStr[2], c2sStr[3],      c2sStr[4], c2sStr[5], c1tTor[1], c1tTor[2], c1tTor[3], c1tTor[4],      c1tTor[5], c2tTor[1], c2tTor[2], c2tTor[3], c2tTor[4], c2tTor[5],      RX[3], RY[3], RZ[3], RX[4], RY[4], RZ[4], MZ[3], MZ[4]}      I see hard work of processor in Mathematica without any result And momentary result from Maple:               {MZ[3] = -200/3+(2/3)*F, MZ[4] = 200/3+(1/3)*F, RX[3] = -(2/3)*F+400/3, RX[4] = -(1/3)*F-400/3, RY[3] = 500, RY[4] = 500, RZ[3] = 0, RZ[4] = 0, c1bXZ[1] = -(1/3)*F-400/3, c1bXZ[2] = (2/3)*F-400/3, c1bXZ[3] = -(1/3)*F-400/3, c1bXZ[4] = 0, c1bXZ[5] = F, c1bYZ[1] = 500, c1bYZ[2] = 500, c1bYZ[3] = -500, c1bYZ[4] = 0, c1bYZ[5] = 0, c1sStr[1] = 0, c1sStr[2] = 0, c1sStr[3] = 0, c1sStr[4] = 0, c1sStr[5] = 0, c1tTor[1] = 400/3-(1/3)*F, c1tTor[2] = -200/3+(2/3)*F, c1tTor[3] = -200/3-(1/3)*F, c1tTor[4] = -200, c1tTor[5] = -200, c2bXZ[1] = (2/3)*F+200/3, c2bXZ[2] = 0, c2bXZ[3] = (1/3)*F+400/3, c2bXZ[4] = -200, c2bXZ[5] = 200-F, c2bYZ[1] = 500, c2bYZ[2] = 0, c2bYZ[3] = 500, c2bYZ[4] = 0, c2bYZ[5] = 0, c2sStr[1] = 0, c2sStr[2] = 0, c2sStr[3] = 0, c2sStr[4] = -11/9600, c2sStr[5] = -11/9600, c2tTor[1] = -1/2100+(1/210000)*F, c2tTor[2] = 0, c2tTor[3] = 1/2100+(1/420000)*F, c2tTor[4] = (1/1440000)*F-1/12000, c2tTor[5] = -(1/1800000)*F-1/12000, c3bXZ[1] = -(1/1800000)*F-1/12000, c3bXZ[2] = 1/12000-(1/720000)*F, c3bXZ[3] = (1/1440000)*F-1/12000, c3bXZ[4] = -1/2100-(1/420000)*F, c3bXZ[5] = 1/2100-(1/210000)*F, c3bYZ[1] = -7/9600, c3bYZ[2] = -13/9600, c3bYZ[3] = 7/9600, c3bYZ[4] = 7/9600, c3bYZ[5] = -7/9600, c4bXZ[1] = 1/36000-(1/900000)*F, c4bXZ[2] = 0, c4bXZ[3] = -(7/7200000)*F-1/36000, c4bXZ[4] = -(7/7200000)*F-1/36000, c4bXZ[5] = 1/36000-(1/900000)*F, c4bYZ[1] = -11/9600, c4bYZ[2] = 0, c4bYZ[3] = -11/9600, c4bYZ[4] = 0, c4bYZ[5] = 0}      By the word, Maple is more worse in numeric power. Last example was very simple. The simple example where I can not to get symbolic solution here Equation set solution problem


title: Simplify Binomial Function

text: The following input               Assuming[        (n ∈ Integers) && (n > 0) && (k ∈ Integers) && (k >= 0) && (k <= n),         FullSimplify[Binomial[n, k]/Binomial[n, k + 1]]     ]      returns               Binomial[n,k]/Binomial[n,k+1]      Why does it not give               (k+1)/(n-k)      and how do I make it do this?


title: Using Inset[..] to overlay a Graphics3D with its raster version

text: ## Preamble First let me explain the _why_. You can skip this and go directly to the question if want to answer it right away. We had more than one discussion about how to produce nice looking 3d plots which can be exported to pdf or some other vector format. Some details why this is not really possible are explained in a post of mine in the question _Exporting graphics to PDF - huge file_.   To solve this issue, there is in my opinion a lot of work to do, since to make it really fancy one would have to reimplement the rendering and 2d-projection process which is done by _Mathematica_ when it displays a `Graphics3D`.   A simple solution, which is maybe OK in a lot of cases, would be to separate the surface of a 3d plot from its box, labels and axes. Then one could create a high-resolution image of the surface and combine this again with the (still in vector format and infinitely high resolved) axes and labels. I showed in the linked post how to do this.   To make this working reliable one has to ensure, that it is possible to place the surface which is now a raster image at the _exact_ same position where the original surface was before. To place the image Wolfram gave us `Inset` at hand which kind of does a good job, but when you look at it closely, there is some behavior I don't understand. ## Question Please consider the following two `Plot3D` where I tried to deny any padding, margin or whatsoever. One plot is rasterized and I fixed the `ImageSize` so that the outcome should be completely equal               s = {300, 300};     opts = {ImageSize -> s,        PlotStyle -> None,        PlotRangePadding -> None,        ImagePadding -> None,        ImageMargins -> None,        Axes -> False,        Boxed -> False};     gr1 = Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2},        PlotStyle -> None,        Evaluate[Sequence @@ opts]        ];     img1 =       Rasterize[        Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2},         PlotStyle -> Opacity[0.4],         Evaluate[Sequence @@ opts]         ],        "Image",        Background -> None,        ImageSize -> s,        RasterSize -> s        ];      If you like, use `Framed` to put a frame around both graphics and try to see differences in placement or size. I could not find any. Creating now a combined `Graphics3D` with `Inset` where I used the `AbsoluteOptions` of `gr1` for the graphics does show, that the inset graphics is not correctly placed. I could have used `Show` for the joining, the outcome would have been the same. Please note, that I initialized the variables `{dx,dy,dz}` to values which give a nice match on my machine. The image shows the zero position.               Manipulate[      Graphics3D[{Inset[img1, {dx, dy, dz}], First[gr1]},        AbsoluteOptions[gr1]],      {{dx, -0.13`}, -.4, .4},      {{dy, -0.14`}, -.4, .4},      {{dz, -0.375`}, -.4, .4}     ]      ![enter image description here](http://i.stack.imgur.com/v6RPk.png) Can someone explain or solve this problem? Maybe someone has an idea where exactly these offsets come from. ## Solution It's worth looking at every answer below, because there are many valuable information, but the key point to the solution of my question was given by Heike who noticed, that the explicit setting of `SphericalRegion` influences the correct placement. Nevertheless, working with `Rasterize`, `ImageSize`, `ImageResolution`, `RasterSize` and all the options influencing margins and paddings around graphics often leads to surprising results. So be warned. With `SphericalRegion->True` in the plot commands, I could quite reliable create nice pdf's from various `Graphics3D`. Here the creation of a high- resolution pdf which has a filesize of 860Kb. I have not included an image, because the png image comes not even close to how brilliant this looks in the pdf. Try it!               RasterizedGraphics3D[gr_Graphics3D, rastersize_Integer] :=        Module[{dim = ImageDimensions[gr], factor},        factor = rastersize/First[dim];        Graphics3D[{Inset[           GaussianFilter[            Rasterize[Show[gr,              Boxed -> False, Axes -> False, AbsoluteOptions[gr]],             "Image", Background -> None, RasterSize -> factor*dim],            .5 factor            ],           {0, 0, 0}, {Center, Center}, dim]},         AbsoluteOptions[gr]]        ];          grout = RasterizedGraphics3D[       Plot3D[Im[ArcSin[(x + I y)^4]], {x, -2, 2}, {y, -2, 2},         Mesh -> None,         PlotStyle ->          Directive[Yellow, Specularity[White, 20], Opacity[0.8]],         ExclusionsStyle -> {None, Red}, SphericalRegion -> True], 2400]     Export["tmp/tmp.pdf", grout, "AllowRasterization" -> False]      The `GaussianFilter` does basically antialiasing because it smooths the high- res raster-image version of the surface a bit. Thank's for all the answers and comments.


title: How to predict some constant number of values with NeuralNetworks

text: Example:               << NeuralNetworks`     data = {Sin[#]} & /@ Range[0, 4 Pi, 0.5];     learn = data[[1 ;; 15]];      Now, lets fit our neural network:               {model1, fitrecord} = NeuralARFit[learn, 3, FeedForwardNet, {}, 0, CriterionPlot -> False]     p = NetPredict[learn, model1, PredictHorizon -> 1]     ListLinePlot[Flatten[learn~Join~p]] (* Plot it! *)      In the result the `Length@p == Length@learn == 15`. Is it true, that we predict 15 values? How can you predict only 1 or 2 or 3 values (e.g. `p[[1]], p[[1;;2]], p[[1;;3]]`) or an arbitrary `n` values? Is it right the idea to use `NeuralARXFit[d1,d2,...]` and `Dimensions@First@d2 = {N,3}` if we want to predict only 3 values ?


title: Saturated Density Plots

text: I am making some density and contour plots in Mathematica. These plots have very high peaks which saturate with color and prevent me from seeing differences in the peaks. Is there a way I can tone down the color scale so my peaks are not just white blobs? Trying other color schemes has not worked out, and playing with the range of color data has not been very useful. Is there some way to have the colors on a log scale??? Here is my code.               ListDensityPlot[photo, PlotLegends -> Automatic, Frame -> {True},      FrameLabel -> {"Electron Bunch Energy (MeV)", "Photon Energy (keV)",      "", "Yield (Photons/Sr e-KeV)" }, LabelStyle -> {15},      InterpolationOrder -> 10]      ![enter image description here](http://i.stack.imgur.com/oF9qi.png) Cheers, Ben


title: `PrimeNu` counting function

text: Building on this question, what is the most efficient counting function for **_distinct_** prime factors? It would obviously be more efficient if `Prime` and `PrimePi` were used instead of `PrimeNu`, as _ybeltukov_ and _Coolwater_ used in their brilliant solutions to the `PrimeOmega` counting function question. I was wondering whether there was any way to do something similar in this instance? The best I have so far is a (very) minor modification of _ubpdqn's_ reply to my previous question:               cnt[k_, n_] := Last@Reap[Sow[1, PrimeNu@#] & /@ Range[n], k, Total@#2 &]