title: Loop in solving multiple matrix calculation

text: I am wondering is there a way to use loop, like `Do`, `For`, to rewrite the last line in the code. I tried to use `Do` to make this work, but mathematica keeps telling me that "svars will be suppressed during this calculation". I want to do the loop way, not the `Table` way i used below, because `Tabel` gives me a really ugly format of eigenvector. ![enter image description here](http://i.stack.imgur.com/S1rv2.jpg) ![enter image description here](http://i.stack.imgur.com/Lygo1.jpg) ![enter image description here](http://i.stack.imgur.com/nu0LW.jpg)               Remove["Global`*"]          Nmax = 4;          T = 1/2 Sum[m[i] x[i]'[t]^2, {i, 1, Nmax}];     U = 1/2 Sum[k[i] (x[i][t] - x[i - 1][t])^2, {i, 1, Nmax + 1}];     L = T - U;          EL[q_] := D[L, q] - D[D[L, D[q, t]], t]          eigen = Table[EL[x[i][t]], {i, 1, Nmax}];          x[i_][t_] = a[i] E^(I \[Omega] t);          sim = eigen /. t -> 0;     x[0][t] = 0;     x[Nmax + 1][t] = 0;          For[i = 1, i <= Nmax + 1, i++, m[i] = m; k[i] = k; m[5] = 0]          matrix = D[sim, {Array[a, Nmax]}];          Print["\nThe reduced eigenmatrix looks like ", matrix // MatrixForm]          soln = \[Omega] /. Solve[Det[matrix] == 0, \[Omega]];          eigenval = Pick[soln, Resolve[ForAll[{k, m}, k > 0 && m > 0, Positive[#]]] & /@ soln];          Do[Print["\n\nThe positive eigenfrequencies we computed are " \[Omega][i] , " = ", eigenval[[i]]], {i, 4}]          b = Table[a[i], {i, Nmax}];          Table[Solve[matrix.b == 0 /. \[Omega] -> eigenval[[i]], b], {i, 1,Nmax}]


title: Creating Optimal "Smoothed" Contour-Type Plots (X,Y,Z) Using Mathematica 8.04

text: ### Update: data here Here is a contour plot produced in the SAS program: ![enter image description here](http://i.stack.imgur.com/Km8Yc.png) In this plot, variable 23405 forms the X axis, variable 20201 forms the Y axis, and outcome variable 50502 forms a pseudo Z axis via color and contour lines. As one can readily see, the red patch marks the "sweet spot" as far as combining 23405 and 20201. THE DATA: X and Y variables are continuous, with the range shown on both axes. The original Z data is continuous as well. However what is shown in the plot are not the original data. Z was "massaged" or "smoothed," based on the original Z data, so as to allow for the creation of the smooth-looking contour plot. In this sense, the surface shown itself does not pass through (precisely) the original Z points, but is an estimation. (Analagous to a single linear regression line not passing through all the data points.) This approximating process done by the particular program used (SAS vs. Mathematica vs. other) is what I'm particularly curious about. Bottom line -- will the supposed "sweet spot" arrived at be any different? Using the same data, I would like to create a similar -- or even better -- contour plot in Mathematica. At the very least, to compare it with the one from SAS, to see if the conclusions appear to be the same. There seem to be various ways of creating such plots in Mathematica, a few of the methods just recently added to the program in version 8. Some possible ways in Mathematica:   * ListContourPlot   * SmoothKernelDistribution   * SmoothDensityHistogram And other ways as well. I'm hoping someone here has had experience creating such contour plots in Mathematica, and can share insights as to which approach has worked well for him/her. Also, any added tricks or parameters needed to arrive at an optimal output?


title: Need help to finish this prime signature function?

text: I'm trying to create a prime signature for line segments.               lpfSignature[n_, k_] :=       Sort[Tally[Table[FactorInteger[m][[1, 1]], {m, n - k + 1, n }]]]     k = 10; n = k;     lpfSignature[n, k]     n = k^2;     lpfSignature[n, k]     n = k^2 + k;     lpfSignature[n, k]      $\\{\\{1,1\\},\\{2,5\\},\\{3,2\\},\\{5,1\\},\\{7,1\\}\\}$   $\\{\\{2,5\\},\\{3,2\\},\\{5,1\\},\\{7,1\\},\\{97,1\\}\\}$   $\\{\\{2,5\\},\\{3,1\\},\\{101,1\\},\\{103,1\\},\\{107,1\\},\\{109,1\\}\\}$ I want to strip the left-hand values to leave the following: $\\{1,5,2,1,1\\}$   $\\{5,2,1,1,1\\}$   $\\{5,1,1,1,1,1\\}$ How would I change the function to do this?


title: Version differences in Parallelize

text: I am having a problem which I guess is due to version difference. I have to generate a list of unitary matrices, which I can do easily. However I came to know about `Parallelize` command by which I wanted to speed the process. First the Hamiltonian (if anybody really wants to check)               X = 1/Sqrt[2] {{0, 1, 0}, {1, 0, 1}, {0, 1, 0}};     Y = I/Sqrt[2] {{0, -1, 0}, {1, 0, -1}, {0, 1, 0}};     Z = DiagonalMatrix[{1, 0, -1}];     Subscript[S, 1, x] = KroneckerProduct[X, IdentityMatrix[3], IdentityMatrix[3]];     Subscript[S, 2, x] = KroneckerProduct[IdentityMatrix[3], X, IdentityMatrix[3]];     Subscript[S, 3, x] = KroneckerProduct[IdentityMatrix[3], IdentityMatrix[3], X];     Subscript[S, 1, y] = KroneckerProduct[Y, IdentityMatrix[3], IdentityMatrix[3]];     Subscript[S, 2, y] = KroneckerProduct[IdentityMatrix[3], Y, IdentityMatrix[3]];     Subscript[S, 3, y] = KroneckerProduct[IdentityMatrix[3], IdentityMatrix[3], Y];     Subscript[S, 1, z] = KroneckerProduct[Z, IdentityMatrix[3], IdentityMatrix[3]];     Subscript[S, 2, z] =  KroneckerProduct[IdentityMatrix[3], Z, IdentityMatrix[3]];     Subscript[S, 3, z] = KroneckerProduct[IdentityMatrix[3], IdentityMatrix[3], Z];     H = Sum[Sum[(Subscript[S, i, x].Subscript[S, j, x] +            Subscript[S, i, y].Subscript[S, j, y] +            Subscript[S, i, z].Subscript[S, j, z]), {j, i + 1, 3}], {i, 1,          3}];      Now, the table               unitary = ParallelTable[Chop[N[MatrixExp[I θ H]]], {θ, 0, 1, 1/100}]; // Timing      The problem is, it is not working in _Mathematica_ 7 and gives the following errors:               MatrixExp::matsq: Argument 0 at position 1 is not a nonempty square matrix.      _Mathematica_ 8 gives result without any trouble and error! I guess it is due to some version difference. Can someone give me a workaround method for both _Mathematica_ 6 and 7? I can only use 6 for any lengthy calculation, and it seems to speed up the calculations a lot.


title: Solving System of Inequalities Relatively

text: I have been trying to figure out how to solve a system of inequalities relatively. I don't care about values, I just want all possible ordering. An example system might be:$${b > r,\; p > r,\; c - 1 = p,\; c < x,\; h > x,\; h < e, }$$ $${r < k,\; q > k,\; l - 1 = q,\; l < h,\; k > p}$$ I want to get all possible ways they could be arranged in order, satisfying the inequalities. If I am not explaining this well, please let me know, I'm not sure how to describe what I'm looking in a more mathematical way. Is there a straightforward way to do it? I tried using `Reduce` over the domain of `Integers`, but it choked. `FindInstance` was able to find a single instance, but not more than that. Edit: I tried:               FindInstance[{ b > r, p > r, c - 1 == p, c < x, h > x, h < e,                     r < k, q > k, l - 1 == q, l < h, k > p},                   { b, r, p, c, x, h, e, k, q, l}]      > >     {{b -> 0, r -> -1, p -> 0, c -> 1, x -> 2, h -> 3, e -> 4, k -> 1/2, q > -> 1, l -> 2}} >   This is basically what I'm looking for, but when I tried increasing `n`, I let it run for `5+` minutes and never got a solution. I also tried:               Reduce[{ b > r, p > r, c - 1 == p, c < x, h > x, h < e,               r < k, q > k, l - 1 == q, l < h, k > p},             {b, r, p, c, x, h, e, k, q, l}]      > >      b ∈ Reals && r < b && p > r && c == 1 + p && x > 1 + p && h > x && >      e > h && p < k < -1 + h && k < q < -1 + h && l == 1 + q >   when I tried `Reduce` over the domain `Integers`, the output was several hundred lines long. **Edit :** Sorting by the second element, the revised version is:                DeleteDuplicates[        Map[ First, Map[ SortBy[ #, Last] &,                          FindInstance[{ b > r, p > r, c - 1 == p, c < x, h > x, h < e, r < k,                                         q > k, l - 1 == q, l < h, k > p},                                         { b, r, p, c, x, h, e, k, q, l}, 10]                       ], {2}]]


title: How to use the Find and Replace Dialog Window?

text: The Find edit box in the Find and Replace Dialog Window shows a default word while opening. How do I tell it to show the word in which the mouse cursor is located in the Notebook, rather than the last word searched for? I want it to work like pressing F1 to open the right reference in Documentation Center does.


title: How to solve a "tensor equation"?

text: I am trying to solve equations which looks like this: $$ T_{ab} - T_{bc} = a_1 T_{ab} + a_2 T_{ac} + a_3 T_{bc}, $$ where $T_{xy}$ are tensors. I want to get the $a_i$'s (in this simple example $a_1=1$, $a_2=0$, $a_3=-1$). The problem is that the Mathematica solving routines (`Solve`, `LinearSolve`) divide the equation by $T_{xy}$ to obtain a solution (or solutions), which is (or some of them are), in turn, not a solution (solutions). What I tried to circumvent this problem: I know (from the construction of my equation) that all $a_i$'s are element $\\{-1,0,1\\}$. So I tried to set the domain to integers. But this gives me lots of condidtional solutions (like `if Tab=integer, then...`) which I don't want. Of course I could solve the above example equation by hand, but in the end I will need to solve a few hundred equations of this type with 70 tensors or so. Thanks in advance for any attempt to help me! Anton


title: Parallelization and Hadoop

text: The short question: Has anyone used _Mathematica_ in conjunction with Hadoop and does _Mathematica_ 's built in parallelization play well with Hadoop? The long version: So I have a _Mathematica_ program that I would like to do the following:   1. I have a kernel does some initial computations and produces some sets of equations which it outputs as context files to a bucket of some kind. The way it does this is essentially through searching a binary tree until it either a) finds a solution, b) finds a contradiction and thus prunes that branch, or c) it can't solve it for some reason.   2. I have several remote kernels running which monitor this directory and pick out context files (which are essentially sets of equations) to try and solve. If they succeed, they throw the solutions that they've found into a bucket for solutions. If they produce more equations to be solved I want them to put them into context files and put them back in the original bucket. If they fail for some reason (which is for all intents and purposes saying that the algorithm I just used to try and solve them did not work), I want them to save the context they are working on as is and put it in a separate bucket that I somehow mark "hard".   3. I want to have certain kernels which are marked to look into the "hard" bucket and try more intensive algorithms for solving them. I would like for them to do this in an "intelligent" way, whatever that ends up being.   4. I produce new sets of context files for computation by recursing further down the tree. I would like to (somehow) treat my bucket as a priority queue so that context files generated at greater depth are given priority over those closer to the root.   5. When all is said and done and I have (hopefully) produced all of the sets of solutions that I can to this system of equations, I want to have a kernel that goes through the sets of solutions and computes when they are equivalent. We (since this is certainly not a one person effort) have been looking at using the Parallelization capabilities built into Mathematica for this task. Some of the advantages to this are that when I initialize remote kernels, _Mathematica_ is supposed to have a means of making sure that the context running in that kernel has certain appropriate definitions. There are a few apparent problems we have identified: One is in handling the file distribution. Ideally we would like to make sure that two kernels are not trying to solve the equations in the same context at the same time. What also happens is that at some point all of the remote kernels are doing disk reads and writes from the same directory, which would probably be bad. Additionally, as it stands right now, the way we can think of to do this with the built in _Mathematica_ parallelization requires that all communication go through the original kernel which spawned the process. We would like to decentralize the algorithm to make it as modular as possible. Finally, not all of the problems that this software is used to solve are beyond the realm of a single kernel, however as it stands doing things in the current version using only a single kernel still requires treating the program as parallelized. I am basically familiar with Hadoop, its DFS, and the MapReduce paradigm that it uses. As I see it, steps 1-4 above could be considered as the map step of an algorithm and step 5 could be a reduce step. Additionally, the HDFS seems like it would provide a solution to the file system problems. The potential problem with hadoop is how to implement access through Mathematica. I have run across the HadoopLink (https://github.com/shadanan/HadoopLink) project, and it seems like the goal of the project could help provide some of the framework we desire. However, some of us have already done work on implementing a solution using the _Mathematica_ parallelization functions, and it is highly desirable to not have to abandon this code, especially since it's what's likely to be optimized for doing parallelization with _Mathematica_. My questions are as follows:   1. As above, has anyone had any experience with trying to get these two things to work together, and if so, was it worth it?   2. Does anyone have any experience with the HadoopLink project, and is it compatible with the _Mathematica_ parallelization? I'm emailing the github project owner, but there are also three other forks out there for the project.    3. Would this be killing a fly with a bazooka and using a 40 lb sledge where a 12oz claw hammer would do? Part of the reason for investigating this is that we anticipate having access to a moderate (few dozen) machines on which we can run kernels. On the one hand we would like to not get stuck thinking too small and having to implement something new all over again as we scale up, and on the other hand we don't want to waste time because we were trying to anticipate problems it was never reasonable to expect in the first place.   4. Is there a better way to do this? At this point, things are rather exploratory and I have no problems with taking new suggestions. Thanks!


title: Using ToExpression within Manipulate

text: I would like to use `ToExpression` (or `Symbol`) within `Manipulate`. Specifically, when running `Manipulate`, I want to build variables from strings, convert them to symbols (dynamic ones) and return values. But I guess I am missing something. Possibly very straight forward. Here's an example:               a2 = 37; (*GLOBAL*)          Manipulate[     Module[{a1 = 1, a2 = 2, a3 = 3, a4 = 4},      Column[{text, var, ToExpression[text <> ToString@var],a1}]], {{text,      "a"}, {"a", "b"}}, {var, 1, 2, 1, ControlType -> SetterBar}]      So I set a global `a2` (to visualize the effect), the rest is local and it returns: ![Manipulate 1](http://i.stack.imgur.com/dzN78.jpg)![Manipulate 2](http://i.stack.imgur.com/UUZUu.jpg) If I change to `a2`, the **global** value is retrieved in the third line, i.e. 37, see the screenshot on the right. So I think the contexts are confusing me. In order to solve my problem, here's what I tried then: I created a `Dynamic` `x`outside the `Manipulate` and well, consistently (to me), I can now use two different sliders to control the variables (both called `x`) within `Manipulate`, see here:               Column[{{Slider[Dynamic[x]], Dynamic[x]},        Manipulate[           Column[{            Style["Within Manipulate", Bold],               x, Dynamic[x],ToExpression[x], "",             Style["Context", Bold],               Context[x], Head[x],"",             Style["Converting String", Bold],               ToExpression["x"], Dynamic@ToExpression["x"],               ToExpression["Dynamic[x]", InputForm, Hold],               ToExpression["FE`x"], ToExpression["Global`x"],               ToExpression["x", InputForm, Dynamic]}],         {{x, 2.5}, 2, 3}]}]      resulting in: (note: running command in Mathematica directly returns context FE`, whereas it returns FE`Global` using export) ![Manipulate](http://i.stack.imgur.com/zKUfU.jpg) So, my question is: is there an easy way within `Manipulate` to go from strings to symbols? (outside `Manipulate`, it works just as I expect it to) Thanks in advance! **EDIT** To clarify: when I use a variable directly in `Manipualte`(such as `a1`) its (local) value is returned (i.e. `1`), if I use `ToExpression["a1"]` (i.e. from string) it retrieves the global value. And whats confusing: `ToExpression[a1]` yields local value. So the question: how to retrieve the local value of a variable in `Manipulate` when given the "name" (string) of the variable.


title: How to define a rule to simplify the notation for derivatives of chain rule?

text: Suppose that $u(x,y)$ is a function, and $x=r \cos t$, $y= r \sin t$, then we can define a new function $v(r,t):=u(x,y)$ with $x,y$ replaced by the above equations. It is quite easy to compute $v$'s derivatives, for example $\partial_{rr}v(r,t)$ can be computed in MMA as               v[r_, t_] := u[x, y] /. {x -> r Cos[t], y -> r Sin[t]}          D[v[r, t], {r, 2}] // Simplify      The output of which looks like ![enter image description here](http://i.stack.imgur.com/mhhqB.png) Then, my question is how to define a new rule, to make the output above look like: $$ \sin^2tu_{tt}+\sin(2t)u_{rt}+\cos^2tu_{rr}. $$


title: local logfiles for remote kernels

text: I'd like remote slave kernels to produce log files on my local machine, subject to the following constraints: 1) I don't want to install a distributed filesystem or do other administrative work on the remote machines. I am not their administrator. 2) I don't want to rewrite the interaction between master/slave kernels to support explicit passing of log messages. The slaves are doing long-running computations with lots of state; they need time to finish. On the other hand I need to see the log files as the computations are running. I know that it is possible to intercept a message (see here) and run a snippet of code, without disturbing the main line of computation (The answer in the link aborts the computation, but you could just as easily do something less intrusive). Is there some way, spiritually along these lines, to generate and then intercept an interprocess communication, which I can use to cause the master kernel to write log entries to files on my local machine?


title: How can I handle curve singularity in this NIntegrate integration?

text: Yesterday I asked a question about the **non converging integral**. Woods told me that it is due to the function which has a singularity along a line which passes through the integration region. (Why does this numeric integral fail to converge?) Now the question is that how can I find a correct answer for this integral? Should I eliminate these singularities from the integral bound? How can I understand it is integrable singularity and gives convergent value or not? I read **singularity handling** in documentation center, but I couldn't solve the problem using **Exclusions**.(http://reference.wolfram.com/mathematica/tutorial/NIntegrateIntegrationStrategies.html#122144792) function:                Msq2[w1_,         w2_] := (12.8228 + 10.518/(0.948338 - 2.0134 w1 - 2.0134 w2) -           6.69841/(1.72935 - 2.0134 w1 - 2.0134 w2) -           57.4434/(2.01348 - 2.0134 w1 - 2.0134 w2) -           13.4997/(3.45415 - 2.0134 w1 - 2.0134 w2) +           9.50782 (1/(-0.110612 + 2.0134 w1) +              1/(-0.110612 + 2.0134 w2)) -           82.5202 (1/(1.14046 + 2.0134 w1) + 1/(1.14046 + 2.0134 w2)))^2;      The region of the integral:               rpp = RegionPlot[        Re[r2] < mphy - w1 - w2 < Re[r1], {w1, .11, .4}, {w2, .11, .4},          BoundaryStyle -> Blue, FrameLabel -> {"w1", "w2"},         PlotRangePadding -> 0];      Where:               r1 = Sqrt[0.283 + (Sqrt[-0.018769 + w1^2] + Sqrt[-0.018769 + w2^2])^2];     r2 = Sqrt[0.283 + (Sqrt[-0.018769 + w1^2] - Sqrt[-0.018769 + w2^2])^2];     mphy = 1.007;      Integration:               NIntegrate[       Boole[Re[r2] < mphy - w1 - w2 < Re[r1]] 1/(64*Pi^3*mphy)*        Msq2[w1, w2], {w1, w1min, w1max}, {w2, w2min, w2max},        AccuracyGoal -> 14] // Chop      Where:                w1min = w2min = Min@rpp[[1, 1, All, 1]];      w1max = w2max = Max@rpp[[1, 1, All, 1]];      The green line is the singular curve which a part of it is in the integration region:               With[{sing = Solve[1/Msq2[w1, w2] == 0, {w1, w2}] /. Rule -> Equal},       Show[rpp, ContourPlot[sing, {w1, 0, 1}, {w2, 0, 1}]]]      ![enter image description here](http://i.stack.imgur.com/nLSNY.png) With the following code I can find the singular line, but I don't know how to eliminate this line from integration bound:               sing1 = Solve[         1/Msq2[w1, w2] == 0 && w1min < w1 < w1max && w2min < w2 < w2max &&           Re[r2] < mphy - w1 - w2 < Re[r1], {w1, w2}][[1, 1]] /.        Rule -> Equal      > ConditionalExpression[ w1 == 9.93345*10^-7 (474169.[VeryThinSpace]- > 1.0067*10^6 w2), 0.209029 < w2 < 0.261985]


title: Is it possible to model the piano key attack?

text: My purpose is to model the attack of a piano key. As the key is pressed a sound must be emitted. When the key is released the sound must stop with decreasing volume. I have a partial success when the time is fixed. For example, if time=2 then the following code simulates a key pressed for 2 seconds. But I don't know how to change it so that the sound stops (with a "natural feeling") immediately after the key is released!               Button[Graphics[{White, Rectangle[{0, 0}, {1, 2}]}],           EmitSound[SampledSoundList[{{0.}}, 8000], "Preemptive"]; EmitSound[            Play[(1 - E^(-30 t)) (1 - E^(-18 (time - t)))  Sin[           2 Pi 440  t], {t, 0, time}]       ]      ]


title: Can BoxWhiskerChart show both the median and outliers at the same time?

text: Is there an easy way to make `BoxWhiskerChart` show both the outliers and the median line? `g1` below shows outliers but not the median line, and `g2` shows the median line but not the outliers.               data = RandomReal[NormalDistribution[0, 1], 100];     g1 = BoxWhiskerChart[data, "Outliers"]     g2 = BoxWhiskerChart[data]      That is, can `BoxWhiskerChart` make a boxplot in the style of `BoxWhiskerPlot`?               Needs["StatisticalPlots`"]     data = RandomVariate[StudentTDistribution[5], 100];     BoxWhiskerPlot[data, BoxOutliers -> Automatic]      Thanks!


title: Followup question from "Temporarily redirect output of Print[ ] to a second file

text: I'm implementing the first answer to my earlier question about redirecting the output of Print[ ]. Opening a file with `OpenWrite[]` and assigning the stream to `$Output` seems to work satisfactorily. However, `Close[]` gives the error message shown below, and doesn't close the file. Does anyone know what's wrong? (Print statements and other code goes between opening the output stream and attempting to close it) ![enter image description here](http://i.stack.imgur.com/dwPTz.jpg)


title: Reassign Functions for Graphic Representation

text: How might I construct a function of the form `Rep[defs,code]`, `graphic[code]` and `display[code]` Such that the following outputs can occur?               Rep[      y[a__] := Graphics[{Circle[],         Inset[          graphic[a]          , Scaled[{0.498, 0.5020000000000002}], Center,           Scaled[{0.5, 0.5}]]}, ImagePadding -> 0,        PlotRangePadding -> 0];      Times[a_, b_] := Graphics[{RGBColor[1, 0, 0], Rectangle[{0, 0}],         Black, Inset[          display[a*b]          , Scaled[{0.498, 0.5020000000000002}], Center, Scaled[{0.5, 0.5}]]         }, ImagePadding -> 0, ImageSize -> {85., Automatic},         PlotRangePadding -> 0];      , graphic[y[y[a*b]]]      ]      ![enter image description here](http://i.stack.imgur.com/Yb2sq.png)               Rep[       Sum[f_, {i_, max_}] :=       Graphics[{Circle[],         Inset[          Sum[f, {i, max}]          , Scaled[{0.498, 0.5020000000000002}], Center,          Scaled[{0.5, 0.5}]]}, ImagePadding -> 0,        PlotRangePadding -> 0],      graphic[Sum[x^2 , {x, 10}]]      ]      ![enter image description here](http://i.stack.imgur.com/RDXQb.png) Here is my current attempt of creating `Rep[funs,code]`. The biggest problem that I have currently, is that I am trying to define custom functions on top of System attributes(`Times` & `Plus`). In addition I was originally going to add a namespace `Gr` to the passed in variables but I feel that there is likely a better way. Questions are welcome around the current implementation or a slightly better/different implementation. My question: **How can I construct the functions above such that they satisfy the graphic outputs?**


title: About Argument of complex numbers

text: Suppose my `z = x + iy` Now, if `y=0`, then `z = x` i.e it becomes a real number So, logically `Arg[z]` should be equal to zero for this case. If I assign the numeric value for `x`, then `Arg[z]` produces zero in _Mathematica_ easily. But if I do not assign the numeric value for `x` which is of course a real number always, then how to produce `Arg[z]=0` for this case ? Because assigning or not assigning numeric value to `x` should not prevent Argument of `z` to be zero i.e `Arg[z]=0`. Actually, my computation involves variables only i.e algebraic expressions, no numeric calculations. The final _Mathematica_ output has a term `Arg[r]`. The parameter `r` , radius, is always real. So, _Mathematica_ should understand that as `r` is always real number, so `Arg[r]` should be zero. Please guide me how to achieve this. (Pranjol Paul, Department of Mechanical Engineering, Indian Institute of Technology Guwahati, Assam, India)


title: Looking for a way to insert multiple elements into multiple positions simultaneously in a list

text: I would like to take the following data:               insertvalues = {r, x};     insertpositions = {{1}, {5}};     origlist = {a, b, c, d, e, f, g};      and generate output that looks like this:               {r,a,b,c,d,x,e,f,g}      Mathematica's `Insert` command seems limited in that it does not allow you to insert multiple elements simultaneously into different positions in a list. I wrote an ugly While loop to accomplish this, and it works, but seems inappropriate for Mathematica's functional approach to coding. Is there a "simpler" way to accomplish this goal with a functional approach? Thank you.               insertvalues = {r, x};     insertpositions = {{1}, {5}};     origlist = {a, b, c, d, e, f, g};          loopcounter = 0; poscounter = 0; final = origlist;     While[loopcounter < Length[insertvalues],       final =         Insert[final,          insertvalues[[loopcounter +             1]], (insertpositions[[loopcounter + 1]] + poscounter)];        loopcounter++; poscounter++];


title: Generating pairs of additive and multiplicative factors for integers

text: Given an integer $n$, I want to get two lists: > a) the set of pairs of the divsors $a,b$ into exactly two factors $n=a\cdot > b$, > > b) the set of pairs $a,b$ of two summands $n=a+b$. The code I came up with works, but I'd like to know if there is a more efficient/elegant or even build in alternative:                 Function[ int, {#,int/#}& /@ Divisors[int]][12]            Function[ int, {#,int-#}& /@ Range[int -1]][12]      Also, in case I want to do that later, how do I eliminate lists from a list, which only differ in order, e.g. how do I reduce `{{a,b},{b,a}}` to `{{a,b}}` ? (Side note: These problems arise in writing the code for this bigger problem)


title: Demonstrate aliasing effect in sound

text: I'm trying to demonstrate the aliasing effect using sound, that is, when the sample rate is fixed and the sound frequency is increased, we would hear the sound pitch go down when we pass the Nyquist frequency. Here is what I tried so far:               Manipulate[      EmitSound[       Play[Sin[ω* t], {t, 0, 0.2}, SampleRate -> 900]], {ω, 200, 6000, 10}]          Manipulate[      EmitSound[       Play[Sin[ω* t], {t, 0, 0.2}, SampleRate -> 8000]], {ω,200, 6000, 10}]      Question: The sound is a little bit lag to the slider. Is it possible to create a more responsive one like this               Manipulate[EmitSound[Sound[SoundNote[n, 3]]], {n, 1, 10, 1}]


title: Command line execution of Mathematica notebooks and conversion to .m

text: Sometimes one may want to execute a notebook via the command line (for example to run it remotely). As far as I know it's not possible to run notebooks directly, but `.m` files can be executed, typically with code like               math -noprompt -run "<<file.m"      So one needs to convert `.nb` to `.m`. One way to do this is to save the `.nb` as a Mathematica package and then to convert all cells to initialization cells. However, this conversion handles some of the typography (e.g. subscripts) improperly. Is there a less error-prone way to do this? * * * Edit: Examples for things that don't convert: Subscript part notation (`Ctrl+_+[[part]]`) The corresponding `FullForm` is `Part[list,n]`, the converted expression is `Subscript[list, [[n]]]`.


title: Different MeshStyle for different functions

text: By using `Plot` command I want to get one curve in form if circles and other like a solid line.               Plot[{Cos[x], Sin[x]}, {x, 0, 2 Pi},           PlotStyle -> {Opacity[0]}, Mesh -> 30, MeshStyle -> {PointSize[Large], Blue}]      ![enter image description here](http://i.stack.imgur.com/Iy7S4.jpg)


title: Example of Integrate applying a numerical evaluation N

text: Here is a minimal example:               Integrate[(a[1] + x)^2, {x, 1., 2.}]      > >     2.33333 + 3. a[1.] + 1. a[1.]^2 >   The problem is that `a[1]` has been turned into `a[1.]`, which is essentially different. A stranger result can be generated from               Integrate[(a[1] + x)^2, {x, 1., b}]      > >     -0.333333 + 0.333333 b^3 + 1. b^2 a[1] + 1. b a[1]^2 + 0.333333 a[1]^3 - >     1. a[1.] - 1. a[1.]^2 - 0.333333 a[1.]^3 >   That is, part of the result uses `a[1]` and another part uses `a[1.]`. Question: how to stop this behaviour and why is it happening?


title: How to convolve a Unit function (like "UnitTriangle") with a InterpolatedFunction

text: Recently discovered what `InterpolatingFunction`'s are in _Mathematica_...really amazing/useful. As I understand it, it's basically a curve fitter....sorta. So how would I use _Convolve_ with a unit triangle or some other analytical- esque function, to convolve over a _InterpolatingFunction_?? ![](http://i.stack.imgur.com/UafNj.png) In the image, the red triangle is `UnitTriangle[x]` (well, it's height and width are off, but you get the gist of it). So ideallly, I'd like to do something like `Convolve[ UnitTriangle[x], InterpolatedFunction, ?, ?]` But that won't work of course, since I don't know what the domains are (hence the ? ?) for the interpolated function.


title: Permuting indices to form fully symmetric tensor with repeated indices

text: I have written a function (version 8) that takes as an input a list of indices such as `{i,j,k}` and outputs a fully symmetric tensor function containing $p_i$ and $g_{ij}$ ($g_{ij}$ is itself understood to be symmetric under $i\leftrightarrow j$).               myFunc[tensorList_?ListQ] := Module[{rank = Length[tensorList], perms, i, j, k, r},       perms = Select[Permutations[tensorList, {rank}], Signature[#] == 1 &];            Return[Sum[If[rank <= 1, 1, 2^(1 - r)/(r! (rank - 2 r)!)]*         Factor[Sum[           Product[Subscript[p, perms[[i]][[j]]],             {j, 1, rank - 2 r}]            Product[Subscript[g, Times @@ perms[[i]][[2 k - 1 ;; 2 k]]],             {k, rank/2 - r + 1, rank/2}], {i, 1, Max[1, rank!/2]}]]          f[2 r, rank], {r, 0, rank/2}]]     ]      Example of usage: `myFunc[{i}]` returns $f[0, 1]p_i$ `myFunc[{i,j}]` returns $f[2, 2]g_{ij}+f[0,2]p_i p_j$. etc. **Problem:** My function only works when all elements of input list have unique names like `{i,j,k}`. I don't know how to modify it so that it can accept lists like `{i,j,j}`. for example, I'd like `myFunc[{i,i}]` to return $f[2,2]\,g_{i^2}+f[0,2]p_i p_i$. _and yes, I know that I'm multiplying indices of g, which I'd like to keep._ Any hints please? (and any pointers on ethics of function construction would be nice!)


title: How do you decompose a polynomial matrix into its matrix coefficients?

text: Let's say I have a matrix, $\mathbf{M}$, that is polynomially dependent on a single variable, such as               M = {{15 + a^2, a + 5 a^2}, {a - 5 a^2, 2}}      and I want to find the individual matrices, $\mathbf{A}_i$, such that $$\mathbf{M} = \mathbf{A}_0 + a \mathbf{A}_1 + a^2 \mathbf{A}_2 + \ldots$$ How do I do this? What do I use if there are multiple variables? Also, can I specify that certain symbols are not to be treated in this manner, e.g.               M = {{15 + a^2, a + 5 a^2}, {a - 5 a^2, 2 c}}      where the constant matrix would be `{{15, 0}, {0, 2 c}}`? Ideally, this should be applicable to vectors and tensors, also.


title: Redefine ArcCot to be inverse of range [0, Pi]

text: Mathematica implements `ArcCot` function as an inverse to `Cot` on range `[-Pi/2, Pi/2]`. I personally prefer the other definition (as it's used in courses I attend). Is it possible to redefine the function? Current implementation: ![range -Pi/2 to Pi/2](http://i.stack.imgur.com/Jr8Jc.gif) My prefered implementation: ![range 0 to Pi](http://i.stack.imgur.com/Z5vfv.gif) (images taken from http://intmstat.com/blog/2011/04/cotx_2.gif)


title: Web Browser Screen Shot

text: I have Safari, Opera, Chrome, Firefox and IE installed how might a get a browser screen shot of a set of HTML code from inside Mathematica(for any of those browsers)? ![enter image description here](http://i.stack.imgur.com/441Lu.png) (Image is optional) The shortest/leanest/fastest approach(within reason) is ideal. For example: Waiting for a website to serve a screen shot is to long. The solution should be local.                screenshot["<!doctype html><i>Italicized text</i>"]      screenshot["http://example.com"]      Possible ideas: SWT, HTMLunit ,http://watin.org/, Selenium (fairly certain Selenium will work with right install and code).


title: What summations can Mathematica do?

text: I was very pleased to discover that _Mathematica_ could do this summation and produce a symbolic result.               s1 =        1/nn Sum[Cos[2 π a (n - 1)] E^(-I (n - 1) (s - 1)/nn), {n, nn}] // Simplify      The answer is long but very useful for me. I also discovered that Mathematica could do some variants of this sum. However, _Mathematica_ cannot do this summation.               s2 =        1/nn Sum[              Cos[2 π ((a - ϵ) (n - 1) + ϵ/(nn - 1) (n - 1)^2)] E^(-I (n - 1) (s - 1)/nn),               {n, nn}]      This leads to the big question what summations can Mathematica do? Help suggest that "Sum can do essentially all sums that are given in standard books of tables". Is my sum s2 in some way pathological that it cannot be done? My second question is thus can my second sum be coerced into a solution? These sums come from Fourier analysis, where it is useful to have a symbolic expression for results that are often calculated numerically using the discrete Fourier transform (`Fourier` in _Mathematica_ ). In order to investigate my sum, I looked at the continuous Fourier transform in which time is equal to n -1 and frequency is (s - 1)/nn. The continuous Fourier transform is given by the integral               1/t2 Integrate[Cos[2 π ( (a - ϵ) t + ϵ/t2 t^2)] E^(-I 2 π f t), {t, 0, t2}]      _Mathematica_ can do this integral which comes out in terms of error functions. However, I can't see how to use this to help get the symbolic solution to the sum s2. In summary what summations can _Mathematica_ do? Is there any hope for getting an closed-form solution for my second sum?


title: Laplace: from differential equation to transfer function

text: First at all, this is trictly related to my own question: How to transform transfer functions into differential equations? How can I transfer my differential equation into a transfer function? For me (at the moment) the following works:               TimeDomain2TransferFunction[eqn_, y0_, u0_] :=      Solve[         LaplaceTransform[eqn, t, s] /. y0 /.            u0 /. {LaplaceTransform[y[t], t, s] -> Y[s],            LaplaceTransform[u[t], t, s] -> U[s]}         , Y[s]][[1, 1, 2]]/U[s]      So, let's say the differential equation is               sysEq = y'''[t] == -1/T2^2 y'[t] - T1/T2^2 y''[t] + Ki/T2^2 u[t]      Then the following gives me an satisfying result:               TimeDomain2TransferFunction[sysEq, {y[0] -> 0, y'[0] -> 0,        y''[0] -> 0}, {}]     ExpandDenominator[%]      Out: $\frac{\text{Ki}}{s \left(s^2 \text{T2}^2+s \text{T1}+1\right)}$ Out: $\frac{\text{Ki}}{s^3 \text{T2}^2+s^2 \text{T1}+s}$ Is there a more elegant way to do this? For example, for different letters (not only y and u).


title: Using Part within a Compiled Command

text: I'm looking to define a multi-line function that makes use of the "Part" command. A **_toy_** example:               f = Compile[{x, y}, (z = Sqrt[x^2 + y^2];      sol = NMinimize[zz^2, zz];      z + sol[[1]])-sol[[2]]]      The core idea is simply that I want to be able to take various parts of a list, produced by a previous command within the compiled function. When I attempt to do so, I get an error message like:               Compile::part: "Part specification sol[[1]] cannot be compiled since the argument is not a tensor of sufficient rank. Evaluation will use the uncompiled function. "      The command works fine if I don't try to use Part (for example):               f = Compile[{x, y}, (z = Sqrt[x^2 + y^2];      sol = NMinimize[zz^2, zz];      z]      I've seen this "not a tensor" error before in compile, when defining arguments, and it appears to be a common (and answered) question. This does not seem to be. Any light you could shed would be appreciated! **-Edit (Workaround)-** Silva's answer helped me come up with a workaround:               f = Compile[{x, y}, (z = Sqrt[x^2 + y^2];      sol2 = NArgMin[zz^2, zz];      sol1 = sol2^2;      z + sol1 - sol2)]      Works with compile.


title: ParallelTable of ParametricNDSolve objects fail

text: There seems to be a problem with ParametricNDSolveValue togeteher with ParallelTable First we create a ParametricNDSolveValue object               f = ParametricNDSolveValue[{x'[t] == -a x[t], x[0] == 1}, (x[1] - 1)^2, {t, 0, 2}, {a}]     ParametricFunction[SequenceForm["<", ">"]]      Then we make a table of derivatives, which works fine.               Table[D[f[a], a], {2}]      Now we do the same thing in a ParallelTable, which gives a huge amount of errors.               ParallelTable[D[f[a], a], {2}]     Internal`Bag::intpm: Positive machine-sized integer expected at position 3 in Internal`Bag[{{#1,#2},{#3,#4}},#5,#6].     Thread::tdlen: Objects of unequal length in {0}+{0,0,0,0,0,0,0,0,0}+<<11>>+0& (<<33>>^(<<1>>))[0,<<8>>,{1.}]+(Internal`Bag^({{0,0},{0,1}},0,0))[{{t$8850,a$8849},{t,a}},1,2] (NDSolve`NDSolveParametricFunction^(0,{0,1},<<6>>,{},{0}))[0,{ParametricNDSolveValue,Internal`Bag[<2>]},<<6>>,{},{1.}] cannot be combined.      If we use Deriviative this works fine               ParallelTable[Derivative[1][f][a], {2}]      Is this a bug in ParametricNDSolve?


title: Is it possible to export equations from Mathematica to Corel with full Latex quality

text: I am wondering is there any possible solution to export equations from mathematica to corel x5. I was trying first to export a equations as pdf from mathematica and then to import .pdf to corel, but many characters are missed. Maybe someone had success with this kind of problem. Thanks in advance.


title: How to make a package for buttons

text: I am trying to make a `Package` for a piece of code though it's not needed here as it is very small. But my actual code here is a little bit different from that code. When I tried to make a package for `Button`. I found that the symbol `True` is protected. I have made a package with the function `Buttonfun`                BeginPackage["package`"]      Buttonfun[g1_,g2_]:= Button["     ",(g1=!g1;),Background->g2,Appearance->                                    "Frameless",Method-> "Queued"];      EndPackage[]      but when I call this with                 Buttonfun[q1,Orange]      from my notebook, it is showing error message symbol `True` is protected.


title: Error message: Coordinate index 0 is out of range for the enclosing GraphicsComplex

text: I am unable understand following error message: Coordinate index 0 is out of range for the enclosing GraphicsComplex. How to fix it? Attached data here: pts and polygons. See also end of question.                Graphics3D[GraphicsComplex[pts, Polygon@poly], Boxed -> False]      returns following error :                Coordinate index 0 is out of range for the enclosing GraphicsComplex.      Data:               pts={{0, 1, 2}, {1, 0, 3}, {4, 5, 6}, {5, 4, 7}, {8, 9, 10}, {9, 8,        11}, {12, 13, 14}, {13, 12, 15}, {16, 17, 18}, {17, 16, 19}, {20,        21, 22}, {21, 20, 23}, {24, 25, 26}, {25, 24, 27}, {28, 29,        30}, {29, 28, 31}};          polys= {{0, 1, 2}, {1, 0, 3}, {4, 5, 6}, {5, 4, 7}, {8, 9, 10}, {9, 8,        11}, {12, 13, 14}, {13, 12, 15}, {16, 17, 18}, {17, 16, 19}, {20,        21, 22}, {21, 20, 23}, {24, 25, 26}, {25, 24, 27}, {28, 29,        30}, {29, 28, 31}};


Given a list of 2D points, i.e.                {p1, p2, ..., pn}      the list may contain equal points, i.e. pi = pj. In this case it may also be true that a sublist of consecutive points has an equal somewhere in the list, i.e.:                pi=pj and p(i+1)=p(j+1).      I am looking for the longest of such sublists in the list. For example, in                { {0,0}, {1,0}, {1,1}, {0,1}, {2,0}, {3,0}, {3,1}, {2,1}, {1,0}, {1,1}, {4,0}}      the sublist I am looking for is               {{1,0}, {1,1}}       has length 2 and occurs twice. I am looking for an efficient way to ( functionally ) code this in Mathematica. Question: **How to find the longest matching sublists in a list?** Answers sofar failed on the following testcase, which I shall add for your convenience:L                {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {2, 0}, {3, 0}, {3, 1}, {2, 1}, {1, 0}, {1, 1}, {4, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}, {2, 0}, {3, 0}, {3, 1}, {2, 1}, {1, 0}, {2, 2}, {4, 0}};      with as longest matching sublist                {{0, 0},{1, 0}, {1, 1},{0, 1},{2, 0},{3, 0},{3, 1},{2, 1},{1, 0}}


title: Getting an equation of particular curve

text: How can I get an equation of the similar shaped curve? ![enter image description here](http://i.stack.imgur.com/2ASTq.png) I've tried to get it like `y = a + c x^2 + d x^3`:               Fit[{{-3, -3}, {0, 3}, {6, 4}}, {1, x^2, x^3}, x]      But it lacks two roots. I can't use `PolynomialFit` because of the lack of points.


title: Solving a nonlinear system of recurrence equations

text: I am having two problems regarding _Mathematica_ , and both of them are happening because it does not accept such inputs:               RSolve[ g[n + 1] == g[n]^2 + 2*f[n]^2, f[n + 1] == 2f[n]*g[n]]      and               RSolve[ g[n + 1] == g[n]^2 + sum[ f[n - 1, i], i = 0..n-1], f[n,x]== (n!)/((x!)*(n-x)!)]      And I have no idea how to provide the correct input for such equations that _Mathematica_ understands.


title: List of different values which have to be formatted differently

text: I have a large list of values which – for presentation in my LaTeX document – I need to format. For instance: I have calculated growth rates which I now would like to have formatted in the form of:                  In[2260]:= Map[{First[First[#]],NumberForm[N[Last[#]],3,2}]}&,                     CompleteQuarterlyStatDataBySubjects[[1]][[1]]]              Out[2260]= {{Australia,{}},{Austria,-1.21},{Belgium,-1.46},{Canada,-1.30},            {Czech Republic,-1.67},{Denmark,-1.87},{Estonia,-3.97},{Finland,-2.53},            {France,-1.00},{Germany,-1.74},{Greece,-1.16},{Hungary,-1.45},            {Iceland,-1.83}, {Ireland,-1.67},{Israel,{}},{Italy,-1.42},{Japan,-0.69},            {Korea, {}},{Luxembourg,-1.67},{Netherlands,-0.98},{New Zealand,-0.50},            {Norway,-0.64},{Poland,{}},{Portugal,-0.40},{Slovak Republic,{}},            {Slovenia,-3.31},{Spain,-0.71},{Sweden,{}},{Switzerland,-0.82},            {Turkey,-3.39},{United Kingdom,-1.45},{United States,-1.28}}      (the original dataset `CompleteQuarterlyStatDataBySubjects[[1]][[1]]` is at the bottom of this post) Besides growth rates I have calculated `AbsoluteTime`-Values which I would like to format as follows:               In[2271]:= Map[                  {                   First[First[#]],                   Table[                     DateString[#[[2;;-1]][[i]],{"Quarter"," ","Year"}],                     {i,Length[#[[2;;-1]]]}                   ]                  }&,                  CompleteQuarterlyStatDataBySubjects[[1]][[5]]                ]          Out[2271]= {{Australia,{DateString[{},{Quarter, ,Year}]}},{Austria,{1 2008}},                 {Belgium,{2 2008}},{Canada,{3 2008}},{Czech Republic,{3 2008}},                 {Denmark,{2 2008}},{Estonia,{2 2008}},{Finland,{2 2008}},                 {France,{1 2008}},{Germany,{1 2008}},{Greece,{3 2008}},                 {Hungary,{1 2008}},{Iceland,{3 2008}},{Ireland,{4 2007}},                 {Israel,{DateString[{},{Quarter, ,Year}]}},{Italy,{1 2008}},                 {Japan,{1 2008,3 2010}},{Korea,{DateString[{},{Quarter, ,Year}]}},                 {Luxembourg,{1 2008}},{Netherlands,{1 2008}},{New Zealand,{4 2007}},                 {Norway,{2 2008}},{Poland,{DateString[{},{Quarter, ,Year}]}},                 {Portugal,{4 2007,3 2010}},{Slovak Republic,{DateString[{},                 {Quarter, ,Year}]}},{Slovenia,{3 2008}},{Spain,{1 2008}},                 {Sweden,{DateString[{},{Quarter, ,Year}]}},{Switzerland,{2 2008}},                 {Turkey,{1 2008}},{United Kingdom,{1 2008}},{United States,{2 2008}}}      To automate the process of getting the values into the right format, I thought to use the following approach:               In[2261]:= Formats[list_,x_]:=         If[x==1,         NumberForm[N[list],{3,2}]            If[x==5,            Table[DateString[list[[i]],{"Quarter"," ","Year"}],{i,Length[list]}]            ]         ]      And then to type for example:                   Map[           {             First[First[#]],             Formats[Last[#],1]           }&,           CompleteQuarterlyStatDataBySubjects[[1]][[1]]         ]      Unfortunately that did not work! Does anyone has an idea how I can program a procedure to get my data automatically formatted? The original data is:                In[2259]:= CompleteQuarterlyStatDataBySubjects[[1]][[1]]         Out[2259]= {{{Australia,AUS,other countries,GDP,quarterly data},{}},{{Austria,AUT,western European         countries,GDP,quarterly data},-1.2056},{{Belgium,BEL,western European         countries,GDP,quarterly data},-(7288960271654/4985881289361)},{{Canada,CAN,G7,GDP,quarterly data},-1.30053},{{Czech Republic,CZE,eastern European         countries,GDP,quarterly data},-(2134917223477606900/1282008490172233089)},{{Denmark,DNK,nothern European         countries,GDP,quarterly data},-(48057014595630800665/25700334274612164804)},{{Estonia,EST,eastern European         countries,GDP,quarterly data},-3.9659},{{Finland,FIN,nothern European         countries,GDP,quarterly data},-(33199059446612625/13128459048331036)},{{France,FRA,G7,GDP,quarterly data},-(5130109517723890585/5148852459134416857)},{{Germany,DEU,G7,GDP,quarterly data},-1.73904},{{Greece,GRC,southern European         countries,GDP,quarterly data},-1.164},{{Hungary,HUN,eastern European         countries,GDP,quarterly data},-(2225003087375671762980417961289391847/1539154631936274189423508152574973424)},{{Iceland,ISL,nothern European         countries,GDP,quarterly data},-1.83398},{{Ireland,IRL,nothern European         countries,GDP,quarterly data},-1.67021},{{Israel,ISR,other countries,GDP,quarterly data},{}},{{Italy,ITA,G7,GDP,quarterly data},-1.42009},{{Japan,JPN,G7,GDP,quarterly data},-(673269612770377724744620/262544695052599501095431),-(32760683814040103590/47201698472568566589)},{{Korea,KOR,other countries,GDP,quarterly data},{}},{{Luxembourg,LUX,western European         countries,GDP,quarterly data},-1.67073},{{Netherlands,NLD,western European         countries,GDP,quarterly data},-0.97505},{{New Zealand,NZL,other countries,GDP,quarterly data},-(152151059187768664247/302333262014074402254)},{{Norway,NOR,nothern European         countries,GDP,quarterly data},-(33596749386427335752225/52657796909983176600514)},{{Poland,POL,eastern European         countries,GDP,quarterly data},{}},{{Portugal,PRT,southern European         countries,GDP,quarterly data},-0.785963,-0.398132},{{Slovak Republic,SVK,eastern European         countries,GDP,quarterly data},{}},{{Slovenia,SVN,eastern European         countries,GDP,quarterly data},-3.31102},{{Spain,ESP,southern European         countries,GDP,quarterly data},-(2414923435622638997136189344226575/3392598745831412249336953513454508)},{{Sweden,SWE,nothern European         countries,GDP,quarterly data},{}},{{Switzerland,CHE,western European         countries,GDP,quarterly data},-0.820439},{{Turkey,TUR,other countries,GDP,quarterly data},-3.38638},{{United Kingdom,GBR,G7,GDP,quarterly data},-(2047013335956949212233044315/1411710881613564347284381614)},{{United States,USA,G7,GDP,quarterly data},-(2091354065961931475/1636350606517650408)}}      and for the AbsoluteTime-Values:               In[2265]:= CompleteQuarterlyStatDataBySubjects[[1]][[5]]     Out[2265]= {{{Australia,AUS,other countries,GDP,quarterly data},{}},{{Austria,AUT,western European     countries,GDP,quarterly data},3408134400},{{Belgium,BEL,western European     countries,GDP,quarterly data},3415996800},{{Canada,CAN,G7,GDP,quarterly data},3423859200},{{Czech Republic,CZE,eastern European     countries,GDP,quarterly data},3423859200},{{Denmark,DNK,nothern European     countries,GDP,quarterly data},3415996800},{{Estonia,EST,eastern European     countries,GDP,quarterly data},3415996800},{{Finland,FIN,nothern European     countries,GDP,quarterly data},3415996800},{{France,FRA,G7,GDP,quarterly data},3408134400},{{Germany,DEU,G7,GDP,quarterly data},3408134400},{{Greece,GRC,southern European     countries,GDP,quarterly data},3423859200},{{Hungary,HUN,eastern European     countries,GDP,quarterly data},3408134400},{{Iceland,ISL,nothern European     countries,GDP,quarterly data},3423859200},{{Ireland,IRL,nothern European     countries,GDP,quarterly data},3400185600},{{Israel,ISR,other countries,GDP,quarterly data},{}},{{Italy,ITA,G7,GDP,quarterly data},3408134400},{{Japan,JPN,G7,GDP,quarterly data},3408134400,3486931200},{{Korea,KOR,other countries,GDP,quarterly data},{}},{{Luxembourg,LUX,western European     countries,GDP,quarterly data},3408134400},{{Netherlands,NLD,western European     countries,GDP,quarterly data},3408134400},{{New Zealand,NZL,other countries,GDP,quarterly data},3400185600},{{Norway,NOR,nothern European     countries,GDP,quarterly data},3415996800},{{Poland,POL,eastern European     countries,GDP,quarterly data},{}},{{Portugal,PRT,southern European     countries,GDP,quarterly data},3400185600,3486931200},{{Slovak Republic,SVK,eastern European     countries,GDP,quarterly data},{}},{{Slovenia,SVN,eastern European     countries,GDP,quarterly data},3423859200},{{Spain,ESP,southern European     countries,GDP,quarterly data},3408134400},{{Sweden,SWE,nothern European     countries,GDP,quarterly data},{}},{{Switzerland,CHE,western European     countries,GDP,quarterly data},3415996800},{{Turkey,TUR,other countries,GDP,quarterly data},3408134400},{{United Kingdom,GBR,G7,GDP,quarterly data},3408134400},{{United States,USA,G7,GDP,quarterly data},3415996800}}


title: FindFit not giving a good fit despite good initial parameters

text: I'm having a problem with `FindFit` not giving a good fit to my data, even though the initial parameters I give look really good when plotted. The fitting function is               P1[Ω_, Δ_, t_] :=        ((Ω/Sqrt[Ω^2 + Δ^2])*Sin[(1/2)*Sqrt[Ω^2 + Δ^2]*t])^2;          fitfunction[Ω_, Δ_, t_, a_, b_, c_] :=        a + b*P1[Ω, Δ + c, t];      and I give the approximate starting parameters:               centrepeak = -91;     Ωapprox = 2 π 29 10^3;     amplitude = 0.8;     offset = 0.13;     pulsetime = 16 10^-6;      Then I fit using `FindFit`:               rabifit =       FindFit[scandata,        {fitfunction[Ω, Δ, pulsetime, voffset, amp, hoffset],         amp < 1, amp > 0, voffset > 0, voffset < 0.5 },        {{Ω, Ωapprox}, {amp, amplitude}, {voffset, offset}, {hoffset, centrepeak}}, Δ]      which gives               {Ω -> 187398., amp -> 0.216895, voffset -> 0.136962, hoffset -> 93.5922}      If I plot the fitting function with my starting parameters (red line) and the fitted parameters (orange line) against the data I get the following graph: ![Plot of data and fitting function for the initial parameters \(red\) and the fitted parameters \(orange\)](http://i.stack.imgur.com/Kf4Ls.jpg) As it can be seen the initial parameters seem to give a much better fit than the fitted ones. I've tried various things, e.g., changing the fitting method, but nothing seems to work. Any suggestions for anything else I could try? The code for generating the plot is               Show[Plot[{       fitfunction[Ωapprox, 2 π Δ 10^3, pulsetime, offset, amplitude, 2 π centrepeak 10^3],        fitfunction[Ω, 2 π Δ 10^3, pulsetime, voffset, amp, 2 π hoffset 10^3] /. rabifit},       {Δ, 0, 200},       PlotRange -> {All, {0, 1}},        PlotStyle -> {Directive[Thick, Red], Directive[Thick, Orange]},        Frame -> True, FrameStyle -> 30,        FrameLabel -> {"Frequency (kHz)", "Probability in |1>"},        ImageSize -> 30*30],       ListPlot[scandata, PlotStyle -> PointSize[0.007]]]


title: fit recursive function to data

text: I have a function $g(x, n)$, which is a recursive expression: $x$ is a variable and $n$ the number of iterations. In my case $n=3$ for all $x$. An example is the following:               f[__, 0] = 1;     f[x_, n_] := x*f[x, n - 1]     g[x_, n_] := ArcTan[f[x, n]] + Cos[f[x, n]]/Exp[f[x, n]/100];          data = Table[{i, 2*g[i, 3]}, {i, -3, 3, 0.1}];      I would like to fit a function $a\times g(x,3)$ to the generated data. A succesful fit should give $a=2$. Can I get an example of how to do this in Mathematica?


title: How to display the indices/element positions of a ragged array?

text: I have a three-level ragged array like so:               array = {{{a, a, a, a}, {a, a, a, a}, {a, a, a}}, {{a}, {a, a, a,           a}, {a, a, a, a}}, {{a, a}, {a, a, a}, {a, a, a, a}, {a, a, a,           a}}, {{a, a, a, a}, {a, a, a, a}, {a, a}, {a, a, a}}, {{a, a,           a}, {a, a, a, a}, {a, a, a}, {a, a, a, a}}};     Grid[array, Frame -> All]      ![Mathematica graphics](http://i.stack.imgur.com/6UFKC.png) I want to display the indices of this array by replacing each `a` element by the 3-digit positions of that element. I also want to preserve the structure of the array i.e. no flattening of the original array should occur. Below is an excerpt of what I want my result to be; notice that each number matches up with the position of the `a` that was previously in that position, and all the the curly brackets are preserved.               {{{111, 112, 113, 114}, {121, 122, 123, 124}, {131, 132, 133}}, ...}      I tried to use `Position[array, a]` but I only got back a flattened list of all the positions of `a`, which makes sense since `Position` is only supposed to show me the positions of `a` without preserving the list hierarchy.               Position[array, a]     (* {{1, 1, 1}, {1, 1, 2}, {1, 1, 3}, {1, 1, 4}, {1, 2, 1}, {1, 2, 2}, {1,        2, 3}, {1, 2, 4}, {1, 3, 1}, {1, 3, 2}, {1, 3, 3}, {2, 1, 1}, {2,        2, 1}, {2, 2, 2}, {2, 2, 3}, {2, 2, 4}, {2, 3, 1}, {2, 3, 2}, {2, 3,        3}, {2, 3, 4}, {3, 1, 1}, {3, 1, 2}, {3, 2, 1}, {3, 2, 2}, {3, 2,        3}, {3, 3, 1}, {3, 3, 2}, {3, 3, 3}, {3, 3, 4}, {3, 4, 1}, {3, 4,        2}, {3, 4, 3}, {3, 4, 4}, {4, 1, 1}, {4, 1, 2}, {4, 1, 3}, {4, 1,        4}, {4, 2, 1}, {4, 2, 2}, {4, 2, 3}, {4, 2, 4}, {4, 3, 1}, {4, 3,        2}, {4, 4, 1}, {4, 4, 2}, {4, 4, 3}, {5, 1, 1}, {5, 1, 2}, {5, 1,        3}, {5, 2, 1}, {5, 2, 2}, {5, 2, 3}, {5, 2, 4}, {5, 3, 1}, {5, 3,        2}, {5, 3, 3}, {5, 4, 1}, {5, 4, 2}, {5, 4, 3}, {5, 4, 4}} *)      * * * **My question is:** How do I display the indices of a (ragged) array elements--preferably concatenated instead of `{_,_,_}`\-- _and_ still keep the list structures intact? * * * **PS** : Here are some other things that I've tried which did not work: 1) `array /. a -> Position[array, a]` This did not work because each `a` is replaced by a huge list of _all_ positions of a in the array. ![Mathematica graphics](http://i.stack.imgur.com/Ezuo4.png) 2) `array /. array[[i_, j_, k_]] -> 100 i + 10 j + k` This would not work either because apparently `Part` does not take patterns. ![Mathematica graphics](http://i.stack.imgur.com/K0wp4.png)


title: Functional-Style Partial Application and the Accumulator Pattern?

text: Following up on Functional-style Fixed-Length Queue Object?, I want to generalize it to a functional-style accumulator pattern. Lots of things _look like_ accumulators, loosely defined as binary functions that take a state- carrying object as a first parameter, a datum as a second parameter, and return the state-carrying object. Such an accumulator can be scanned, mapped, or (theoretically, pending answer to the cited question) folded over sequences or streams of data to yield interesting results. Some things that look like accumulators are statistics, filters, smoothers, estimators, hidden Markov models (Kalman, Viterbi), controllers, I am sure many more. For elegance, I'm interested in a functional style. To keep the example small, consider the following:               newAccumulator[] := <|"runningSum" -> 0|>;     SetAttributes[accumulate, HoldFirst];     accumulate[accumulator_, datum_?NumberQ] :=       (accumulator[["runningSum"]] += datum;        accumulator);      This will just keep a running sum, but we could easily keep higher-order statistics and such a thing can be quite rich and useful. We can use this easily to compute Gauss's Day-of-Reckoning Sum, for example;               $myAccumulator = newAccumulator[];     Scan[accumulate[$myAccumulator, #] &, Range[100]];     $myAccumulator      > >     <|"runningSum" -> 5050|> >   Now, it occurred to me, "wouldn't it be nice if we could write               Scan[partial[accumulate, $myAccumulator], Range[100]]      where               SetAttributes[partial, HoldRest];     partial[f_, arg_] := (f[arg_,#]&);      which I can unit-test as follows               partial[f, x][y]      > >     f[x, y] >   and even generalize (just a little):               partial[f_, as__] := (f[Sequence @@ (Quiet @ Join[as, ##])] &);      and unit-test               partial[f, x, y][z, w]     partial[f, x][y]     partial[f, x][]      > >     f[x, y, z, w] >     f[x, y] >     f[x] >   But, lo and behold, it doesn't work on my example:               $myAccumulator = newAccumulator[];     Scan[partial[accumulate, $myAccumulator], Range[100]]     $myAccumulator      > >     <|"runningSum" -> 0|> >   This one has me clueless. **EDIT** : The `HoldRest` attribute on `partial` does not seem to make a difference. I put it in there out of habit -- side-effecting functions often work best when they hold their arguments against premature evaluation.


title: Graph and Markov Chain

text: I have the following code:               proc = DiscreteMarkovProcess[1, {{0.6, 0.4}, {0.3, 0.7}}]          Graph[{"A", "E"}, proc, GraphStyle -> "DiagramBlue"]      How can I 'force' to show the percentage values (0.6, 0.4 etc) on each arrow? I can see the values when I mouse hover it. Thank you.


title: Plotting a parametric graph and a normal one on the same grid with a legend option

text: Here is my simple code:               f0[y_] := PDF[NormalDistribution[-1, 1], y]     f1[y_] := PDF[NormalDistribution[1, 1], y]     ParametricPlot[{{f0[y], f1[y]}, {y, f1[y]}}, {y, 0, 0.5},          PlotStyle -> {Blue, Red}, BaseStyle -> 18, AxesStyle -> Arrowheads[0.03],          PlotLegends -> Placed[LineLegend[{             Style["density composite", FontSize -> 21],             Style["density only", FontSize-> 21]             },              LegendFunction -> (Framed[#, RoundingRadius -> 2, FrameStyle -> LightGray] &),              BaseStyle -> 18], {Right, Top}]]      ![enter image description here](http://i.stack.imgur.com/ra9E5.jpg) I only get the legend "density composite" but not "density only" part. I need them in the same plot. One is for the blue curve and the other for the red one. Thank you very much


title: How do I plot the unit normal field for a surface?

text: The question is pretty much in the title; I'm about to teach my multivariable calculus students about orientations on surfaces, and I would like to be able to show them pictures. Any ideas?


title: Using DistributionFitTest on custom distributions in Mathematica 8

text: I originally posted this question on Stack Overflow, but I didn't get any answers, and I'm hoping to have better luck here. * * * I'm trying to compute the goodness-of-fit of a bi-modal Gaussian distribution. To do this, Mathematica seems to require a symbolic distribution function to which to compare. Because such a bi-modal distribution is not a stock distribution, I'm trying to define one. The obvious use of               MixtureDistribution[{fs, (1-fs),       {NormalDistribution[μS, σS], NormalDistribution[μL, σL]}]      generates a distribution that can be plotted, but the analysis used by `DistributionFitTest[]` fails. This topic has been addressed in previous questions in discussions between @Sasha and @Jagra: http://stackoverflow.com/questions/6361647/distributionfittest-for-custom- distributions-in-mathematica http://stackoverflow.com/questions/9202531/minimizing-nexpectation-for-a- custom-distribution-in-mathematica?lq=1 but I was unable to find a resolution that enabled the use of               DistributionFitTest[data,dist,"HypothesisTestData"]      when `dist` is not a built-in distribution type. Because the distribution I'm modeling is composed of simple pieces, describing the properties of the distribution is not too difficult, and I have attempted to describe as many features as I know in order to create a well defined distribution that _Mathematica_ 8 would recognize as one of its own. My attempt to define every parameter I can think of follows:               modelDist /:      PDF[modelDist[fS_, μS_, σS_, μL_, σL_], x_] :=     PDF[MixtureDistribution[{fS, 1 - fS}, {NormalDistribution[μS, σS], NormalDistribution[μL, σL]}], x];          modelDist /:      CDF[modelDist[fS_, μS_, σS_, μL_, σL_], x_] :=     CDF[MixtureDistribution[{fS, 1 - fS}, {NormalDistribution[μS, σS], NormalDistribution[μL, σL]}], x];          modelDist /:      DistributionDomain[modelDist[fS_, μS_, σS_, μL_, σL_]] :=      Interval[{-Infinity, Infinity}];          modelDist /:      Random`DistributionVector[modelDist[fS_, μS_, σS_, μL_, σL_], n_, prec_] :=      RandomVariate[MixtureDistribution[{fS, 1 - fS}, {NormalDistribution[μS, σS], NormalDistribution[μL, σL]}], n, WorkingPrecision -> prec];          modelDist /:      DistributionParameterQ[modelDist[fS_, μS_, σS_, μL_, σL_]] :=      !TrueQ[Not[Element[{fS, μS, σS, μL, σL}, Reals] && fS > 0 && fS < 1 && σS > 0 && σL > 0]];          modelDist /:      DistributionParameterAssumptions[modelDist[fS_, μS_, σS_, μL_, σL_]] :=      Element[{fS, μS, σS, μL, σL}, Reals] && fS > 0 && fS < 1 && σS > 0 && σL > 0;          modelDist /:      MomentGeneratingFunction[modelDist[fS_, μS_, σS_, μL_, σL_], t_] :=      fS E^(t μS + (t^2 σS^2)/2) + (1 - fS) E^(t μL + (t^2 σL^2)/2);          modelDist /:      CharacteristicFunction[modelDist[fS_, μS_, σS_, μL_, σL_], t_] :=      fS E^(I t μS + (t^2 σS^2)/2) + (1 - fS) E^(I t μL + (t^2 σL^2)/2)          modelDist /:      Moment[modelDist[fS_, μS_, σS_, μL_, σL_], n_] :=      Piecewise[{{fS*σS^n*(-1 + n)!!*Hypergeometric1F1[-(n/2), 1/2, -(μS^2/(2*σS^2))] + (1 - fS) * σL^n*(-1 + n)!! * Hypergeometric1F1[-(n/2), 1/2, -(μL^2/(2*σL^2))], Mod[n, 2] == 0}}, μS*σS^(-1 + n)*n!!* Hypergeometric1F1[(1 - n)/2, 3/2, -(μS^2/(2*σS^2))] + (1 - fS) * μL*σL^(-1 + n)*n!! * Hypergeometric1F1[(1 - n)/2, 3/2, -(μL^2/(2*σL^2))]];          modelDist /:      Mean[modelDist[fS_, μS_, σS_, μL_, σL_]] :=      fS μS + (1 - fS) μL          modelDist /:      Expectation[expr_, x_ \[Distributed] modelDist[fS_, μS_, σS_, μL_, σL_]] :=      fS*Expectation[expr, x \[Distributed] NormalDistribution[μS, σS]] + (1 - fS)*Expectation[expr, x \[Distributed] NormalDistribution[μL, σL]]      Everything seems to work up through the definition of Expectation, which throws > TagSetDelayed::tagpos: Tag modelDist in Expectation[expr_, > x_\\[Distributed]modelDist[fS_, \μS_, \σS_, \μL_, \σL_]] is too deep for an > assigned rule to be found. I don't know that having a definition for the expectation will magically make everything work, but it's the next step to to try, as having the expectation allows computation of the variance, and for all I know, that is the last tag that I need to define. Is there a syntax that will properly define this `Expectation` in such a way that the expression will pass straight from my `modelDist` to its constituent `NormalDistribution`s? (And if this entirely the wrong way to go about this, some advice to that effect would be appreciated.)


title: Understanding execution time in nested loops

text: I have the following simple code               finalList = {};     For[i = 1, i <= myN - 3, i++,      For[j = i + 1, j <= myN - 2, j++,       For[k = j + 1, k <= myN - 1, k++,        l = RandomInteger[{k + 1, myN}];        AppendTo[finalList, {i, j, k, l}];        ]       ]      ] // Timing      for some value of myN I obtain the following execution times               30 0.056     40 0.356     50 1.436     60 4.296     70 12.083     80 43.012     90 116.903      that grow much faster than N^3 (it's about N^6 for the first point and it is increasing for the last two points), and I cannot understand why. Any insight of why this happens?


title: How can I simulate this toggle mechanism?

text: I've been introduced to _Mathematica_ very recently. Basically, I haven't actually "solved" anything in my Mathematica lifetime, but I've done some simulations. With my fractional knowledge, I tried simulating a toggle mechanism today. Here's what I did...               ω0 = .02; ω = .02; r = 2; r1 = 6; r0 = 1.5;     rA[θ_, r_] := r*{Cos[θ], Sin[θ]};     rAy[θ_, r_] := r*Sin[θ];     rAx[θ_, r_] := r*Cos[θ];     rC[θ0_, r0_] := r0*{Cos[θ0] + 1/r0, Sin[θ0] + 3/r0};     rCy[θ0_, r0_] := r0*Sin[θ0] + 3;     rCx[θ0_, r0_] := r0*Cos[θ0] + 1;     xB[θ_, r_] := r*Cos[θ] + Sqrt[(r1^2 - (r*Sin[θ])^2)];     rB[θ_, r_] := {xB[θ, r], 0};     rBx[θ_, r_] := xB[θ, r];     rBy[θ_, r_] := 0;     Manipulate[θ = ω*t; θ0 = ω0*t;       rAO = rA[θ, r]; rBO = rB[θ, r]; rDC = rC[θ0, r0];      Graphics[{{Thick, Darker[Green], Dashed, Circle[{0, 0}, r]}, {Thick,          Dashed, Blue, Circle[{1, 3}, r0]},        {Red, EdgeForm[{Thick, Black}], White,          Rectangle[{rBO[[1]] - 0.5, rBO[[2]] - 0.5}, {rBO[[1]] + 1,            rBO[[2]] + 0.5}]},        {Thick, Darker[Red], Line[{{0, 0}, rAO, rBO}]}, {Thick,          Darker[Red], Line[{{1, 3}, rDC, rAO}]},        {Black, Disk[{0, 0}, 0.1], Disk[{1, 3}, 0.1],          Disk[{rAO[[1]], rAO[[2]]}, 0.1], Disk[{rDC[[1]], rDC[[2]]}, 0.1],          Disk[{rBO[[1]], rBO[[2]]}, 0.1]}},       PlotRange -> {{-3, 9}, {-3, 5}},        ImageSize -> {600, 250}], {{t, 20, "Motion"}, 20, N[205*Pi],        N[Pi/16]}]      I think you can figure out that there's a big issue, due to my enormous expectation from the "visualizing" without even thinking of "solving"... ![](http://i.stack.imgur.com/mcHuZ.gif) Both the cranks have the same angular velocity. Because, that's the way I've defined. I've got no other choice. But, the mechanism should begin with the top crank. That crank makes the bottom one to rotate, by transferring power through the connecting rod. Given a connecting rod of constant length (especially, less than the sum of radii of the cranks), the bottom crank cannot complete one full rotation. It can go only halfway, and then turn back. The slider motion remains the same, but the crank is causing a big trouble to the mechanism due to the ridiculous "elastic behavior" of the connecting rod. I don't want to analyze this mechanism. So, I'm cool with any answer that essentially simulates the actual mechanism (even if that's a modification of mine) as I just need the simulation only for a video (at least, for now). At the same time, I'll be very happy with "solving" the equations with constraints, because I guess those solutions may help me in the future for other mechanisms.


title: How can I show a rotated PDF plot superimposed on a ListPlot of the underlying data?

text: I have a set of 3 lifetime datasets in lists called values1, values2 and values3. values1 = {53377., 16542., 31418., 5629., 17654., 7365., 15797., 862., 76906., 10073.}; values2 = {74412., 15620., 29650., 96951., 9252., 14257., 11684., 84461., 49724., 14903.}; values3 = {69174., 77036., 115837., 105497., 103195., 55433., 90053., 45861., 57840., 33875.}; The plot of this raw data is shown below. ![enter image description here](http://i.stack.imgur.com/VU74H.png) I now use EstimatedDistribution to fit the data to individual Weibull distributions and plot their PDFs. ![enter image description here](http://i.stack.imgur.com/plOIb.png) ![enter image description here](http://i.stack.imgur.com/mXhAv.png) ![enter image description here](http://i.stack.imgur.com/CFZxx.png) What I would like to do now is to locate and align the individual PDF curves on top of the raw data plot close to their corresponding data points. The PDFs would be rotated 90 degrees clockwise thereby ending up in a vertical orientation in the final plot. At this point I don’t necessarily need the frames and labels associated with the PDF plots to be included. What is most important is that the Age to Failure axes of the Raw Data plot be aligned with that of the PDF plots so that the resulting composite plot is a true mathematically accurate representation of the information in all 4 plots. Below is a depiction of the formatting I’m after (minus the inclusion of the boxes and whiskers]. I don’t know what software tool created this plot. ![enter image description here](http://i.stack.imgur.com/zW9OC.png) The closest I’ve seen to this is in Mathematica is the BoxWhiskerChart but that apparently is unable to show the PDF. Below is my code. Thanks for any help.               values1 = {53377., 16542., 31418., 5629., 17654., 7365., 15797., 862.,     76906., 10073.};          values2 = {74412., 15620., 29650., 96951., 9252., 14257., 11684.,      84461., 49724., 14903.};          values3 = {69174., 77036., 115837., 105497., 103195., 55433., 90053.,      45861., 57840., 33875.};          category1 = Table[1, {10}];     category2 = Table[2, {10}];     category3 = Table[3, {10}];     data1 = Transpose[{category1, values1}];     data2 = Transpose[{category2, values2}];     data3 = Transpose[{category3, values3}];          plot1 = ListPlot[{data1, data2, data3}, Frame -> True,      PlotRange -> {{0, 4}, {0, 150000}},      FrameLabel -> {"Category", "Age to Failure"},      FrameTicks -> {{1, 2, 3}, {0, 25000, 50000, 75000, 100000, 125000,       150000}, None, None}, PlotLabel -> "Raw Data"]          dist1 = EstimatedDistribution[values1,      WeibullDistribution[\[Alpha], \[Beta]]]          dist2 = EstimatedDistribution[values2,      WeibullDistribution[\[Alpha], \[Beta]]]          dist3 = EstimatedDistribution[values3,      WeibullDistribution[\[Alpha], \[Beta]]]          plotrange = {0, 5*10^-5};          plot2 = Plot[PDF[dist1, t], {t, 0, 75000}, Frame -> True,      FrameLabel -> {"Age to Failure", "PDF"},      PlotLabel -> "Distribution 1 PDF", PlotRange -> plotrange]          plot3 = Plot[PDF[dist2, t], {t, 0, 100000}, Frame -> True,      FrameLabel -> {"Age to Failure", "PDF"},      PlotLabel -> "Distribution 2 PDF", PlotRange -> plotrange]          plot4 = Plot[PDF[dist3, t], {t, 0, 150000}, Frame -> True,      FrameLabel -> {"Age to Failure", "PDF"},      PlotLabel -> "Distribution 3 PDF", PlotRange -> plotrange]      Edit 1: I also looked at DistributionChart which appears to return teardrop- like objects but not the actual PDF (probability density function) plot that I am seeking. DistributionChart draws a _representation_ of the distribution of values in each Subscript[data, i]. Edit 2: Here is another example showing “vertical PDFs”, this time on a semi- log plot. I believe one of the ReliaSoft products produced this. See here. ![enter image description here](http://i.stack.imgur.com/Nu6F3.png) Edit 3: Here is George's solution ![enter image description here](http://i.stack.imgur.com/0cVmb.jpg)


title: How to create a parallelepiped tiling?

text: I know how to create parallelepiped and combine them to form a parallelepiped tiling, but the tiles overlap... I started with this code:               P1 = Graphics3D[{GeometricTransformation[{Opacity[.85], Red,           Cuboid[]}, ShearingMatrix[Pi/4, {1, 0, 0}, {-1, 1, 0}]]},        Boxed -> False]             P2 = Graphics3D[{GeometricTransformation[{Opacity[.85], Red,           Cuboid[]}, ShearingMatrix[Pi/4, {1, 0, 0}, {-1, 1, 0}]]},        Boxed -> False]          P3 = Graphics3D[{GeometricTransformation[{Opacity[.85], Red,           Cuboid[]}, ShearingMatrix[Pi/4, {1, 0, 0}, {-1, 1, 0}]]},        Boxed -> False]          Show[P1,P2,P3]       ![](http://i.stack.imgur.com/XSBP9.png) I don't know how to fix the positions of the parallelepipeds (I prefer different shapes) so that they will not overlap and no gaps between them.


title: BubbleChart bubble scale depends on y position

text: I noticed that the scaling of bubbles in the BubbleChart function depends on the y position of a bubble. Compare these two examples.               BubbleChart[{{60.0, 20.0, 50.0}, {60.0, 90.0, 50.0}},       FrameLabel -> {Style["Count", 24], Style["Total Dollars", 24]},       BubbleScale -> "Diameter", PlotRange -> {{0, 250}, {0, 200}},       ImageSize -> {400, 400}]      ![Bubble chart with small bubbles](http://i.stack.imgur.com/AqDCF.png)               BubbleChart[{{60.0, 20.0, 50.0}, {60.0, 120.0, 50.0}},       FrameLabel -> {Style["Count", 24], Style["Total Dollars", 24]},       BubbleScale -> "Diameter", PlotRange -> {{0, 250}, {0, 200}},       ImageSize -> {400, 400}]      ![Bubble chart with large bubbles](http://i.stack.imgur.com/fFyPl.png) The only difference is the y coordinate. But the bubble size changes. Any ideas?


title: Colorize and the Four-Color Theorem

text: We can write:               MorphologicalComponents[image] // Colorize      To assign a random set of colors to each component in some image. The example used for reference by Mathematica is a map of the United States: http://reference.wolfram.com/mathematica/ref/Colorize.html?q=Colorize&lang=en My question is - is it possible to ask Mathematica to specify that any two adjacent colors should have some minimum threshold distance in in their hue or RGB values (e.g. http://en.wikipedia.org/wiki/File:Map_of_United_States_vivid_colors_shown.png)? I believe asking for a four-coloring of a map is computationally non-trivial, but are there any built-in routines, perhaps with the graph analytics packages in Mathematica, to allow for this? Let's define two morphological components as adjacent if the line segments spanning the shortest distance between the two components fails to intersect any other morphological components. We can also include a distance $D$ cutoff for defining two components as adjacent. I'm certainly open to stricter definitions.


title: How to get a sub range of a larger matrix?

text: This should be an easy question but I only found a partial solution using `All`. Say I have a matrix A = 1000 x 5, how to get only a part of that matrix, say B = _n_ x 5, where _n_ can be any positive integer that's less than 1000 or the original matrix A row?


title: How can I efficiently enter multiple instances of data?

text: I would like to plot the normal distribution for a population of human heights. My question is how can I input multiple frequencies for the same variable, without writing them out one by one. e.g. I have 17 instances of 5'10", 20 of 5'11", 4 of 6'.


title: Advanced SQL-type select statements (filtering) on Datasets

text: I'm trying to improve on mathematica's handling of datasets. I'm currently writing this function that should do the following. Suppose I have a dataset with columns, e.g.               cols = {col1, col2, col3}      and I want to remove all `NA` type entries from a subset of these columns, say               subcols = {col1, col2}      To create an example dataset, let's condider:               rows = {         {0.09, 0.53, 0.32},         {"NA", "NA", 0.19},         {0.52, 0.38, "NA"},          {"NA", 0.25, 0.20},         {0.03, 0.61, 0.52}     };          dataset = Dataset[Inner[Rule, cols, #, Association]& /@ rows];      Now, I know that I can select the rows I want by the selection rule:               dataset[Select[NumberQ[#"col1"] && NumberQ[#"col2"]&]]      but I would like to create a short-hand notation for this, so that it applies to bigger datasets (with many columns). In particular, I'd like write a function `DropNA` that takes a dataset and a list of columns as input and outputs a new dataset with all unwanted rows removed. For instance, a test could be:               DropNA[dataset, subcols] == dataset[Select[NumberQ[#"col1"] && NumberQ[#"col2"]&]]      > >     True >   This is what I have so far:               DropNA[dataset_, cols_] := Module[{allCols, GoodRow},            (* get the list of all columns: *)       allCols = dataset[All, Keys] // Union // Normal;            (* some precaution: *)       dropna::badcolumn = "Dataset has an ambiguous set of columns.";       If[Length[allCols] != 1, Message[dropna::ambiguouscolumns]; Abort[]];            dropna::subsetcolumns = "One or more columns provided do not appear in the dataset.";       If[Not[SubsetQ[allCols[[1]], cols]], Message[dropna::subsetcolumns];Abort[]];            (* returns True if it encounters good row: *)       GoodRow[row_] := And @@ (NumberQ[row[#]] & /@ cols);            (* select only the good rows: *)       dataset[Select[GoodRow]]       ]      As it stands now, `DropNA` only returns the entire dataset. Does anyone have any idea what I'm missing here?


title: Constraining a random function

text: This question is a follow-up from here. I have a function that generates a list of correlations between some random variables:               varparams = Table[i, {i, 0.1, 0.9, 0.1}];          var[i_] :=       RandomChoice[{varparams[[i]], 1 - varparams[[i]]} -> {1, 0}, 10]          corrcheck[i_, j_, n_] :=       Table[BlockRandom[SeedRandom[k];           Correlation[var[i], var[j]]], {k, n}]      Now, if by chance one or both of `var[i]`,`var[j]` is a list of all 1's, then `Correlation[var[i],var[j]]` is undefined. I want to improve `corrcheck[i_, j_, n_]` so that it automatically throws away all such `vars`. My idea was to do something like this:               corrcheck[i_, j_, n_] :=       Table[BlockRandom[SeedRandom[k];         If[Mean@var[i] != 1 && Mean@var[j] != 1,          Correlation[var[i], var[j]], "N/A"]], {k, n}]      Why doesn't this work? Have I missed a better alternative? Thanks in advance.


title: How to remove accents from text?

text: I would like to know how I can remove accents from a string. For example, how can I transform `"string test áéíóú"` into `"string test aeiou"`? I have to normalize some text to make comparisons, and this would be very helpful.


title: Equality and Quantifiers

text: I am new to _Mathematica_ and to Math. I do not study math in English, so please bear with me as I try to state my questions.. This is what I am trying to "solve": $$∃!x : A(x) ⇔ ∃x : ¬A(x)$$ In words: "Is 'there is exactly one x for which the assertion A is true' equivalent to 'there is at least one x for which assertion A is not true' ?" Referred to that I have questions:   * Is this something you would normally do with _Mathematica_?    * In the program I opened a "New Notebook" and typed in:               Equivalent[!Exists[x, a[x]], Exists[x, !a[x] ]]       and it - surprise! ;) - did not work. What have I done wrong ?   * How would the answer look like ?


title: equation solving problems

text: I have some equation: $$ veq=-2-lr-l^2r+2(r+ir^3\omega) v' + (-2+r)r^2v'^2 + (-2+r) r^2 v''==0 $$ or in Mathematica form:               -2 - l r - l^2 r +      2 (r + I r^3 \[Omega]) Derivative[1][v][r] + (-2 + r) r^2 Derivative[     1][v][r]^2 + (-2 + r) r^2 (v^\[Prime]\[Prime])[r]      then generate veqexp with the code               veqexp[n_] :=      Normal[Series[     veq /. {v[r_] :> Sum[c[i]/r^i, {i, 1, n}],        v'[r_] :> Sum[-i c[i]/r^(i + 1), {i, 1, n}],        v''[r_] :>         Sum[i (i + 1) c[i]/r^(i + 2), {i, 1, n}]}, {r, \[Infinity],       n - 2}]];      I sub into this an ansatz for solution $v=\sum^n c_i r^i$. Calling this new equation in terms of the $c_i$ 'veqexp' (i.e. veq expanded). The following chunk of code can solve this for my coefficients: (note I want to solve around infinity)               vcoeffs[nn_] :=      Block[{}, Clear[c];      Do[c[i] = c[i] /. Solve[          Limit[veqexp[nn] r^(i - 2),             r -> \[Infinity]] == 0, c[i]][[1]];, {i, 1, nn}]] ;      and out correctly pop the $c_i$ coefficients in terms of $(\omega,\ell)$ parameters of my 'veq', so far so good. The problem is that these functions of $(\omega,\ell)$rapidly grow in size until by about the 30th Mathematica's memory gives out and dies. However if I try to calculate for a given $(\omega,\ell)=(0.1,1)$ so that each c[i] is just a number, I also hit problems to do with recursion that I have no idea about. For example               vcoeffs[nn_] :=      Block[{}, Clear[c];      Do[c[i] =        c[i] /. Solve[          Limit[(veqexp[nn] /. {\[Omega] -> 0.1, l -> 1}) r^(i - 2),             r -> \[Infinity]] == 0, c[i]][[1]];, {i, 1, nn}]] ;      generates errors that read                $RecursionLimit::reclim: Recursion depth of 256 exceeded. >>      when I would have expected just a series of $nn$ complex coefficients which would take no memory for Mathematica to store. Can anyone suggest a way around this? thanks


title: How do I introduce a new variable in a trigonometric equation?

text: I have the trigonometric equation \begin{equation*} \sin^8 x + 2\cos^8 x -\dfrac{1}{2}\cos^2 2x + 4\sin^2 x= 0. \end{equation*} By putting $t = \cos 2x$, I have \begin{equation*} \dfrac{3}{16} t^4+ \dfrac{1}{4}t^3 + \dfrac{5}{8}t^2 -\dfrac{7}{4}t + \dfrac{35}{16} = 0. \end{equation*} How do I tell Mathematica to do that? Mathematica code is               Sin[x]^8 + 2 Cos[x]^8 - 1/2 Cos[2 x]^2 + 4 Sin[x]^2 == 0


title: Help generating dynamic manipulators?

text: I would like to generate dynamic Manipulators for each of the selected buttons in a ToggleBar. How can I keep the state of each Manipulator in a variable? I would like to later access the values of the Manipulators for each of the selected buttons. Thanks.               DynamicModule[{stakes = {}},       Column[{TogglerBar[Dynamic[stakes], {1.5, 3.5, 7, 15, 30, 60, 100,                                            200, 300, 500, 1000}],               Dynamic[Grid[({#, Manipulator[Appearance -> Labeled]}) & /@ Sort[stakes]]]}]]


title: How to calculate an improper integral

text: How can I find the range of the parameter `a` such that the improper integral               Integrate[(x^(a - 1))/(1 + x), {x, 0, ∞}]      converges?


title: Why does string completion work differently between functions?

text: The behaviour of string completion for functions that take strings as input is not entirely clear to me. For example, when I type a function `f` I tend to go through the following steps: first I type the name of the function and open- close square brackets:               f[]      then I take the cursor one place to the left and open close quotes if `f` takes string arguments:               f[""]      and, finally, I jump one place left again and I enter the string:               f["value"]      but string completion doesn't always work with this way of entering string arguments. Although with `CountryData` it does: ![enter image description here](http://i.stack.imgur.com/a5cWX.png) other functions like `Import` no string completion occurs if you type in the brackets before the argument (which is a useful way of not losing track of open brackets). ![enter image description here](http://i.stack.imgur.com/NBud4.png) ![enter image description here](http://i.stack.imgur.com/tjp48.png) So my question is > Is there a way to force string completion for `Import` so that it works like > `CountryData` does?


title: Generating a list of integers that roughly satisfy a distribution

text: Say I have a normal distribution,               NormalDistribution[25, 7]      I'd like integers from 1 to 50, not sampled at random from that distribution, but sampled in a way that the mean is more common than the bounds, following that distribution. What is that called, and is there a way of doing it concisely within Mathematica? I suppose one way to do it would be selecting a number from 1-50 with the probabilities given by               Table[NormalDistribution[25, 7], {x, 1, 50, 1}]     {0.00015967, 0.000257934, 0.000408253, 0.000633121, 0.000962014, \     0.00143223, 0.00208921, 0.00298598, 0.00418147, 0.0057373, 0.007713, \     0.0101596, 0.0131119, 0.0165803, 0.0205426, 0.0249376, 0.0296614, \     0.0345672, 0.0394707, 0.0441593, 0.0484068, 0.051991, 0.0547124, \     0.0564132, 0.0569918, 0.0564132, 0.0547124, 0.051991, 0.0484068, \     0.0441593, 0.0394707, 0.0345672, 0.0296614, 0.0249376, 0.0205426, \     0.0165803, 0.0131119, 0.0101596, 0.007713, 0.0057373, 0.00418147, \     0.00298598, 0.00208921, 0.00143223, 0.000962014, 0.000633121, \     0.000408253, 0.000257934, 0.00015967, 0.0000968449}      Where each position is the probability that that number would be selected: 1 would show up with p = .00015967, etc. Is that right? I'm not really sure how to map and select the integers 1-50 along these probabilities, or even if that's on track. I'm not sure because I don't want it to be left to probability: the function that makes these should be deterministic. I don't think I'm describing this very well. The idea is to have parameters vary normally around the mean, 25, but are integers and not randomly sampled, as I only need a few (though in this case 50) though that number may change. I hope this makes some semblance of sense. The end result would be a list               {1, 5, 10, 13, 17, 20, 22, 23, 24, 25, 25, 26, 27, 28, 30, 33, 37, 40, 45, 50}      Or something like that, but with whatever distribution and number of numbers (I'd like to do it for something like `MixtureDistribution[{1, 1}, {NormalDistribution[25, 7], NormalDistribution[75, 7]}]` as well).


title: Is there a more elegant and efficient way to write brainf*** style loops in Mathematica?

text: I'm having some fun writing a brainf*** interpreter in Mathematica. See this wiki article for more info. It works nicely but I'd like to find an elegant, preferably functional, way to handle the looping structures. This is a simple example of what I'm hoping to do with the solution I currently have in place. The variable `ptr` is the position of a pointer in the program. The variable `paren` is used to keep track of the brackets, it increments on "[" and decrements on "]" so it should be zero when I find the proper closing bracket.               ptr = 1;     paren = 1;     lst = {"[", "[", "-", "]", ">", ">", ">", ".", "<", "<", "<", "]",              ">", ">", ">", ">", ">", ">", "."};          While[paren > 0, ptr++;           Switch[lst[[ptr]], "[", paren++, "]", paren--, _, Null]]      Which tells me the closing "]" is located at position 12 in `lst`.               In[287]:= ptr          Out[287]= 12      Is there a more elegant and/or efficient way to do this?


title: Microsoft SQL DatabaseLink connection using Windows Authentication

text: For those who use _Mathematica_ with databases in companies, a common way to securely connect to those is using Windows Authentication (detailed here). _Mathematica_ doesn't seem to support this authentication method. How can you connect to a database securely using Windows authentication?


title: How can Magnify be forced to ignore the notebook's window width?

text: In a new notebook, I can illustrate how the action of `Magnify` is cut off by the window width:               SetOptions[EvaluationNotebook[], WindowSize -> {600, 1000}]     p = Plot[x^2, {x, -1, 1}]     Magnify[p, 4]      ![enter image description here](http://i.stack.imgur.com/SaEXX.png) At this point, the plot shows only the axis labels enlarged, whereas the documentation states that `Magnify` scales all aspects of the graphic. The expected behavior is recovered if we enlarge the window:               SetOptions[EvaluationNotebook[], WindowSize -> {1700, 1000}]      Notice how the previous plot is now scaled to twice the original size in all aspects. Is there a way to use `Magnify` in windows of arbitrary size and always get a consistent result with all aspects of a graphic scaled by the same factor, as the documentation states?


title: How can I create a function with optional arguments and options?

text: Is it possible to create a function with optional arguments that also takes options? Here is a simple example. I have a function `f` with option "g". It also has optional arguments `y` and `z` which are set to default values.               Options[f] = {"g" -> Identity};          f[x_, y_: 2, z_: 3, OptionsPattern[]] :=       OptionValue["g"][x + y + z]      Now, if I give values for all of the arguments and an option value it works just fine.               In[3]:= f[1, 2, 3, "g" -> (#^2 &)]          Out[3]= 36      If I give only the required argument, no problems.               In[4]:= f[1]          Out[4]= 6      However, if I give the required arg and an option value but don't give the optional arguments, I run into trouble..               In[5]:= f[1, "g" -> (#^2 &)]          Out[5]= 4 + ("g" -> (#1^2 &))      Is there a good way around this? **EDIT:** Obviously, it is possible to write multiple definitions...               f[x_, y_, z_, OptionsPattern[]] := OptionValue["g"][x + y + z]          f[x_, y_, OptionsPattern[]] := OptionValue["g"][x + y + 3]          f[x_, OptionsPattern[]] := OptionValue["g"][x + 2 + 3]      I'm curious if there is a clean way to do it with a single definition.


title: What is the comment shortcut?

text: I went to a Wolfram Technologies workshop a few weeks ago and the presenter showed us a keyboard shortcut that when a block of input is selected, the shortcut puts the block of selected input in `(* comment *)` brackets. I've forgotten what the shortcut is though. Does anyone know what it is?


title: How to get a uniformly distributed list of points from a B-spline function

text: I created a spline function from a list of points and made a plot as follows:                 list2 = {{3.93453, -0.623168}, {3.79708, -0.187231}, {3.72835,        0.0307369}, {3.65963, 0.248705}, {3.5909, 0.466673}, {3.52218,        0.684642}, {3.44186, 1.05816}, {3.36155, 1.29764}, {3.28124,        1.5219}, {3.20093, 1.73094}, {3.12061, 1.92474}, {3.0403,        2.10331}, {2.95999, 2.26666}, {2.87968, 2.41477}, {2.79937,        2.54766}, {2.71905, 2.66532}, {2.63874, 2.76774}, {2.55843,        2.85494}, {2.41254, 2.97924}, {1.98589, 3.2791}, {1.52249,        3.51828}, {1.27967, 3.61368}, {1.03092, 3.69235}, {0.777399,        3.75392}, {0.520275, 3.7981}, {0.260741, 3.82469}, {0., 3.83357}}          g = BSplineFunction[list2,            SplineWeights -> {50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,              50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50}]          ListPlot[Table[g[t], {t, 0, 1, 1/100}]]      I need my plot to have more evenly placed points. When I take the plot out of this sample table to a larger scale plot, there are gaping holes that are too extreme for my needs. Is there any way to adjust the density of my spline function without just adding more points? Adding more points is not proving to be an effective solution.


title: How one can make the boundary of the regionplot smaller or bigger?

text: Suppose we have a regionplot as follows:               mpion = 0.137;     meta = 0.548;     metap = 0.958;     con1 = Sqrt[meta^2 + w1^2 + w2^2 - 2  mpion^2 + 2 Sqrt[w1^2 - mpion^2]  Sqrt[w2^2 - mpion^2]];     con2 = Sqrt[meta^2 + w1^2 + w2^2 - 2  mpion^2 -2 Sqrt[w1^2 - mpion^2]  Sqrt[w2^2 -mpion^2]];          RegionPlot[      Re[con2] < metap - w1 - w2 < Re[con1], {w1, .13, .27}, {w2, .13, .27},        BoundaryStyle -> Directive[Red, Thick], FrameLabel -> {"w1", "w2"},       PlotStyle -> None, BaseStyle -> FontSize -> 16]      ![enter image description here](http://i.stack.imgur.com/wLNKO.jpg) Which we can plot it in x-y plane (x and y are defined as w1 and w2 functions):                Q = metap - meta - 2*mpion;     solw = Solve[x == Sqrt[3]/Q*(w1 - w2) && y == -(2 + meta/mpion)/Q*(w1 + w2) -            1 +  (2 + meta/mpion)/Q*(metap - meta), {w1, w2}];     w1funxy = w1 /. solw[[1]];     w2funxy = w2 /. solw[[1]];               RegionPlot[(Re[con2] < metap - w1 - w2 < Re[con1]) /.         w1 -> w1funxy /. w2 -> w2funxy, {x, -1.4, 1.4}, {y, -1.1, 1.2},        BoundaryStyle -> Directive[Blue, Thick], FrameLabel -> {"x", "y"},       BaseStyle -> FontSize -> 16, PlotStyle -> None]      ![enter image description here](http://i.stack.imgur.com/VUKZL.jpg) How can I make the boundary of the region in x-y plane smaller? just like this graph (The blue and green boundaries). I need the points in blue and green regions around x=y=0 point. I couldn't change the inequality equation of the region in the way that it gives what I want. ![enter image description here](http://i.stack.imgur.com/tHZUK.jpg)


title: How to find the zero of a function?

text: I want to find out when a function has a real root. I first made a `RegionPlot3D` when the function is zero.               Manipulate[       RegionPlot3D[(A*x)^(1 - s) -          NSum[B^(n)*(x^((1 - s)*z^n))*           Exp[(1 - z^(2 n))*(1 - s)^2*v^2/(2*(1 - z^2))], {n, 1, Infinity}] -          NSum[B^(n)*(y^((1 - s)*q^n))*           Exp[(1 - q^(2 n))*(1 - s)^2*p^2/(2*(1 - q^2))], {n, 1, Infinity}] == 0,          {x, 0.95, 1.05}, {y, 0.95, 1.05}, {z, 0.95, 0.99}],        {q, {0.95}},        {v,{0.0035}},        {p, {0.0035}},        {s,{2}},        {B,{0.95}},        {A,{0.96}}]      I got a blank cubic. As a check I plotted the function in 2D. However, the 2D plot shows that the function has a zero when `M = x =0.9528` and `K = y = 1.0396`.               Manipulate[       Plot[(A*M)^(1 - s) +          NSum[(B^n*(K^((1 - s)*(q)^n))*           Exp[(1 - (q)^(2*n))*((p)^2)*(1 - s)^2/(2*(1 - (q)^2))]), {n, 1, Infinity}] -          NSum[(B^n*(M^((1 - s)*r^n))*           Exp[(1 - r^(2*n))*(v^2)*(1 - s)^2/(2*(1 - r^2))]), {n, 1, Infinity}] ,          {r, 0.95, 0.99}],        {q, {0.95}},        {M, {0.9528}},        {K, {1.0396}},        {v,{0.0035}},        {p, {0.0035}},        {s, {2}},        {B, {0.95}},        {A, {0.96}}]      Further, I tried to zoom into the area where the 2D plot shows that a zero may exist and found that it is no longer a monotonic function (its zigzag and crosses the horizontal axis many times). What do I make of this? Does it mean that a zero exists in the complex plane?


title: Plot with sum and binomial command

text: A few days ago I asked about a problem with plotting a sum. You advise me to use Evaluate option, and that helped me very. But now I have a very similar problem, but i can't find the mistake. I have a equation: $$\sum_{i=0}^x {x\choose l}\cdot l^{10}\cdot(-1)^{(x-l)}$$ I want to draw this for $$x \in [0,10]$$ I used this command:               Plot[Evaluate[Sum[Binomial[x, l]*l^50*(-1)^(x - l), {l, 0, x}]], {x, 1,2}]      There are no errors, but also no graph. If I will expand the equation for $x=1$ I have: $${1\choose 0 }\cdot 0^{10}\cdot (-1)^{1-0} + {1 \choose 1}\cdot 1^{10}\cdot (-1)^{1-1} = 1$$ and for example for $x=5$ it is: $${5\choose 0 }\cdot 0^{10}\cdot (-1)^{5-0} + {5 \choose 1}\cdot 1^{10}\cdot (-1)^{5-1} + {5\choose 2 }\cdot 2^{10}\cdot (-1)^{5-2} + {5 \choose 3}\cdot 3^{10}\cdot (-1)^{5-3} + {5\choose 4 }\cdot 4^{10}\cdot (-1)^{5-4} + {5\choose 5 }\cdot 5^{10}\cdot (-1)^{5-5} = 5 103 000$$ So as you can see, there equation can be evaluated, so why I can't see any plotted points?


title: How to eliminate the backward play in Export of Manipulate?

text: I find that the `Export` of `Manipuate` contains backforward play, see a simplified example:               Export["try.swf",       Manipulate[       Plot[Sin[2 x + φ], {x, 0, 10}], {φ, 0, 2 π}]]      You can see the problem in the SWF file. (I'm sorry that the exported SWF file cannot be uploaded here) Actually, I have two questions here,   1. Is there any simple way to get a animation with **only forward** play? I can find nothing about this in the help documents.   2. Why is GIF not working in `Export`? That is to say, if I use `Export["try.gif", Manipulate[...]]`,the exported file, otherwise an animation, is only a static picture actually.


title: How to compute the inverse CDF properly?

text: Note: this has been fixed in version 9. * * * I want to compute the CDF and inverse CDF of the hyperbolic distribution:               α = 2; β = 3/2;     x = -3;     u = N[CDF[HyperbolicDistribution[α, β, 1, 0], x], 30]      The output of the above code is               5.36058384200167863956651004148*10^-6      A small, but not too small number. Now, since the CDF and inverse CDF are compositional inverses, I expect the output from the following line to be approximately $-3$:               xA = N[InverseCDF[HyperbolicDistribution[α, β, 1, 0], u], 30]      But _Mathematica_ instead returns               -23.0838707895835608942828900958      which is just way off. So, am I doing something wrong here? Or are _Mathematica_ 's `CDF[]` and `InverseCDF[]` functions not to be trusted for this distribution? When the above experiment is repeated with the normal distribution, there are no problems:               x = -12;     u = N[CDF[NormalDistribution[0, 1], x], 30]     xA = N[InverseCDF[NormalDistribution[0, 1], u], 30]      The output is $-12$ as expected.