title: variable sized lists and using lists as variables

text: I am trying to scan a parameter space of varying numbers of parameters subject to some constraints (I am interested in any number of constraints just out of curiosity, but in reality no more than 2 constraints in the actual). So it would look something like :                TestScan[c1,...,cm,{list1,....listn}]      Where the ci are constraints and the list_i's take the form                {x_i,x_i_initial, x_i_final, x_i_increment}       that will be fed to a Do loop. The problem is that I want to change the actual value of the x_i so that the c_j's (which are a function of x_i) know that x_i has changed value. For example I might have a constraint like                x^2+y^2+z^2=1,      I want to scan over values of y and z, solve for the corresponding values of x, then store all the possible solutions in a list. By putting the variables I want to scan over in an array it seems easier since then I can have Mathematica see the size of the array, and run the proper number of loops. Obviously if I just put the variables in a function like                TestScan[c1,...,cm,x_i,x_i_initial, x_i_final, x_i_increment,....]      and then I would call it like                     TestScan[c[x1,x2],x1,x1initial, x1final, x1increment,x2,x2initial, x2final, x2increment]      it works since know Mathematica knows that the argument of c is that same thing as the x1 that appears elsewhere, but I would have to change the code every time I change the number of variables in the constraints. My naive straightforward generalization of the just above does't work when I try to pass all                {x_i,x_i_initial, x_i_final, x_i_increment}       in a list. In this case mathematica might replace the 1 element in the list with something else, but I need to be able to change the value of x_i itself.


title: Getting slightly different results in fitting a logit model in R and Mathematica

text: I'm fitting some data to a Logit model in both _Mathematica_ and `R` and I'm getting slightly different results. `R` code:               data = read.table("http://www.rni.helsinki.fi/~kja/epid12/BCG.dat",header=T)     logitmodel = glm(cbind(D,H)~BCG,data=data,family=binomial(link="logit"))     summary(logitmodel)      _Mathematica_ code:               {d, h, bcg, age} =       Transpose@       Rest@Import["http://www.rni.helsinki.fi/~kja/epid12/BCG.dat",          "Data"];     logitmodel =       GeneralizedLinearModelFit[Transpose@{bcg, d/h}, BCG, BCG,        ExponentialFamily -> "Binomial", LinkFunction -> Automatic,        Weights -> d + h]     logitmodel["ParameterTable"]      The results are estimates that are almost the same but differ in a few decimals. For example, the `R` estimate and standard error for BCG are -0.74152 and 0.12744 respectively. The corresponding _Mathematica_ results are -0.742492 and 0.127755. Am I making a subtle mistake somewhere or is this the result of some numerical approximation?


title: Using Compile to speed up Function with PermutationProduct

text: I have the following fairly simple routine `dot` involving `PermutationProduct` that I wish to speed up using `Compile` or otherwise. I am applying the `Function` simultaneously to large `Lists` of arguments               X={x1,x2,...}; Y={y1,y2,...}      using `ParallelTable` in the format               ParallelTable[dot[X[[i]], Y[[j]]], {i, Length[X]}, {j, Length[Y]}]      The `Function` is defined:               dot[x_, y_] := Block[       {l = Length[x]}, Cases[Select[#, ! (l < # <= 3 l) &] & /@          PermutationProduct[            Cycles[y + 2 l],            Cycles[Table[{2 l - i + 1, 2 l + i}, {i, l}]],            Cycles[x]            ][[1]], Except[{}]]        /. Table[3 l + i -> i + l, {i, l}]]      The arguments `x` and `y` are `Lists` of the same `Length` consisting of partitions of the set {1,2,...,2n} into pairs where `n` is the `Length` of the arguments; and `dot[x,y]` is a `List` of the same form. For example, where `n == 4`, the `dot` of elements               x = {{1, 2}, {3, 8}, {6, 5}, {4, 7}}     y = {{2, 3}, {5, 6}, {4, 1}, {8, 7}}      is               dot[x, y] == {{1, 2}, {3, 4}, {5, 6}, {7, 8}}      The order of the elements and subelements of `x`, `y` and `dot[x,y]` are irrelevant. Any and all suggestions on improving the efficiency of this code will be enormously appreciated! Thanks and regards, Daniel


title: Bitwise operators - Hamlet for Mathematica

text: What is the best way to check this famous equation:               0x2b || ~0x2b == 0xff      _Mathematica_ doesn't seem to have a handy bitwise negation operator. The best thing I did come up was:               FromDigits[IntegerDigits[16^^2B, 2, 8]     ~BitOr~(IntegerDigits[16^^2B, 2, 8] /. {1 -> 0, 0 -> 1}), 2] == 16^^FF      which is rather terse. Or:               2^^00101011~BitOr~2^^11010100 == 16^^FF      which is ok. But it's not the same. My naive hope was that something like this would work but it doesn't:               16^^2B~BitOr~BitNot@16^^2B == 16^^FF      Which yields `False` and reveals that I do not understand what bitwise negation in _Mathematica_ parlance means... I had hoped that `BitNot[16^^2B]` would yield `16^^D4`, but I was utterly wrong. How can you force _Mathematica_ to use bytes? Because `IntegerDigits[16^^2B,2,8]` yields `{0, 0, 1, 0, 1, 0, 1, 1}` which is ok, but `IntegerDigits[BitNot[16^^2B], 2, 8]` yields `{0, 0, 1, 0, 1, 1, 0, 0}`. Apparently not really a bitwise negation. Help, tips, etc. appreciated. **EDIT:** So due to Daniel Lichtblau's answer the best result so far might be:               NOT[bits_Integer, len_Integer: 8] /; bits >= 0 && len >= 0 := BitXor[bits, 2^len - 1]     OR = BitOr          16^^2B~OR~NOT@16^^2B == 16^^FF      :) Hilarious! **EDIT 2** I'd say the `BitNot` should have an optional argument, if 2's-complement is wanted, defaulting to `True`. As such:               protected = Unprotect[BitNot];     $BitNotActive = True;         Options[BitNot] = {Compl -> True, Len -> 8};         BitNot[n_Integer, OptionsPattern[]] /; $BitNotActive :=         Block[{$BitNotActive = False},             If[OptionValue[Compl], BitNot[n],                  BitXor[n, 2^OptionValue[Len] - 1]]         ]     Protect[Evaluate[protected]];      So the big question (which is actually no question at all, since it's always true...) in _Mathematica_ would become:               16^^2B~BitOr~BitNot[16^^2B, Compl -> False] == 16^^FF      I demand overloaded operators and number representation without the "base^^" syntax!


title: Typing (and executing) expressions with multiple superscripts

text: I am trying to type (and evaluate) expressions of the following form: $$ G^{a,b} $$ into a mathematica. I've tried the obvious               G^(a, b)      or               Superscript[G,a,b]      But both of these give the same error               Syntax::tsntxi: "a,b" is incomplete; more input is needed.      I know one solution is to use Symbolize from the Notation package               << Notation`     Symbolize[ParsedBoxWrapper[SuperscriptBox["G", RowBox[{"_", ",", "_"}]]]]      however this solution will not suffice as I want to perform operations such as the following:               In[3]:= Sum[G^(a, b), {a, 1, 2}, {b, 1, 2}]     Out[3]= 4 G^(a, b)      Is there any sensible way to get around this? Why is Superscript so much more picky than Subscript? Thanks in advance.


title: How to draw an infinitely long line that automatically scales with the plot?

text: I'm trying to plot a function inside a `Manipulate` and draw a vertical line at some $x$ position. The scale of the plot can vary a lot depending on the `Manipulate` settings. Example:               h = 1;     Manipulate[      Plot[10^f*x^3, {x, -1, 1},        Epilog -> {Line[{{0.5, -h}, {0.5, h}}]}], {{f, 0}, -5, 5}]      Now the problem is to choose a good value for `h`: If it's too small, it's not as high as the plot. If it's too large, the line isn't drawn at all. (Sidenote: Don't try to make the line dashed or dotted. Apparently the dashing/dotting is done _before_ the clipping, so _Mathematica_ just freezes up if `f` gets too small.) Ideally, I'd just want to draw a line from $y=-\infty \ldots +\infty$. Is there a simple way to do that?


title: Make the selection become the button you click

text: Let's assume I want a button that, when you click it, get the cell that contains it selected. This approach won't work, it selects the cell containg the selection previous to the click.               Button["Select this cell", SelectionMove[ButtonNotebook[], All, Cell]]


title: How to rescale a Graphics3D object?

text: I've created a `Graphics3D` object by extruding a binary 2D image (as shown here).               pts = ImageData[ColorNegate@Binarize@Import["http://i.stack.imgur.com/UWO6k.png"], "Bit"];     g = RegionPlot3D[pts[[Sequence @@ Round@{i, j}]] == 1, {i, 1, #1}, {j, 1, #2},       {z, 0, 300}, PlotPoints -> 100, Mesh -> False, Axes -> True,        Boxed -> False] & @@ Dimensions[pts]      ![enter image description here](http://i.stack.imgur.com/EpGBT.png) This object has dimensions 600 $\times$ 600 $\times$ 300 and it is centered on (300, 300, 150). In other words, all coordinates are within the ranges of the given dimensions. My need is to be able to rescale this object by preserving the same `Graphics3D` structure (i.e., including vertices, polygons, vertex normals, etc.). The new ranges of dimensions I'm looking for are ((-0.5, 0.5), (-0.5, 0.5), (-0.25, 0.25)). I had no troubles to rescale the coordinates of the `GraphicsComplex`, but these are not enough to then export the `Graphics3D` as an .obj file. A second approach that I took was to use `TetGenLink` to recompute the needed information, but since my object has also concavities this did not work as expected. Has anyone done this before? Any suggestion is more than welcome.


title: Plot the results of integrating a complicated Dirac-delta function

text: Plot[Integrate[Sin[6.28*10^10 x]/(-x + t)        (1 + (-0.99995*(3.33*10^-8 - 0.99995 x) +           22.4 Sin[1.256*10^11 x])/         ((3.33*10^-8 - 0.99995 x)^2 +            7.13*10^-10 (Sin[6.28*10^10 x])^2)^0.5)*       DiracDelta[       x -  t + ((3.33*10^-8 - 0.99995 x)^2 +             7.13*10^-10*(Sin[6.28*10^10 x])^2)^(1/2)], {x,0, 0,5*10^-9}], {t, 0, 0.001}]       I tried evaluating the above expression, but takes forever. Am I doing it right? Should I use `NIntegrate` * * *               Plot[f[t], {t, 0, 0.0001}]      Then (took~20hrs) ![enter image description here](http://i.stack.imgur.com/ViELd.gif) Could I get better plot from this?


title: Function to compute the probability of exactly one event occurring out of N independent events

text: Is there a built in function (or a function in one of the standard packages) that allows you to compute the probability of exactly one event occurring out of some known set of probabilities for N independent events? Ideally what I'd want is something with a signature like:               Pr[independentProbabilities__] := ...       To give an example, suppose I have a process that produces a letter from the set {A, B, C, D, X} with probabilities: $$P(A) = 0.1\text{, } P(B) = 0.22\text{, } P(C) = 0.17\text{, } P(D) = 0.28$$ what is the probability that _exactly one_ of the possibilities (A, B, C, or D) occurs?


title: Palette with editable InputField

text: I need a Palette with editable InputField. When I try the code `CreatePalette[Pane[InputField["Enter a string"]]]` it makes the pallete but all input goes into an open notebook, not into the InputField. I just need a Palette with editable InputField. How it can be done?


title: Returning an unevaluated expression with values substituted in

text: Let's say I have a function               formula[x_List] := (x[[1]] - x[[2]]) + (x[[3]] - x[[4]]);      and I want to pass it a variable and get back the unevaluated formula with these inputs in place, so for example with input {1,2,3,4} I would get back               Out[]= (1-2)+(3-4)      I do not want it to return strings; if I copy the output and paste it somewhere, I want it to be executable. I also don't want it to do any math on the function; if `x[[1]]==x[[2]]`, it should not collapse `x[[1]]-x[[2]]` to 0. All I want is pattern substitution. I figure the answer involves `Hold[]`, but I have not been able to get the results I want.


title: How can I fix my code so NIntegrate doesn't produce error message?

text: I get this error when trying to integrate a seemingly simple expression:               eradius = 2.8179403267*10^-15;     n = 10^-10/(1.6*10^-19);     gamma = 1600/0.511;     lb = 0.549267;     theta2 = 0.046892183133281855;     eta3 = -(theta1*lb) - (theta1*d);     rho2 = lb/theta2;          CSR3linear =        (0.22*eradius*n)/(gamma*rho2^(2/3)*(s/lb (sigma3end - sigma3beg) + sigma3beg)^(4/3));          kick3 = NIntegrate[(eta3 + s^2/(2 rho2))*CSR3linear, {s, 0, lb}] /.              {theta1 -> {0.06},               d -> {8.60435},              sigma3beg -> {1.300512*10^-004},              sigma3end -> {1.472289*10^-005}};      > NIntegrate::inumr: The integrand has evaluated to non-numerical values for > all sampling points in the region with boundaries {{0,0.549267}}. What am I doing wrong here? Also, the choice to have the parameters theta1, d sigma3beg and sigma3end as lists in the integration is because its actually a long list of numbers for each parameter (~20) that would take forever to input separately and record each output; would much prefer the solution to outputed in one list.


title: Interpolation of data on non-rectangular grid

text: I have a smooth data distribution on a 2D regular grid that is not a rectangular (it is a cross-section of a channel) and I need to find an Interpolating function `f[x,y]`. I have tried `Interpolation[{{x1,y1},f1},{x2,y2},f2},...}]` but it doesn't work. Does `Interpolation` work only on rectangular grid? Thanks Giovanni


title: Question about $\LaTeX$ generated by Mathematica

text: I saved a Mathematica Notebook as a `*.tex` file. When compiling in TeXnicCenter I get the an error on the following generated code.               \begin{doublespace}     \noindent\(\(\{0,10,1\}\)\)     \end{doublespace}      The error is just: `Bad math environment delimiter`. Question: How to get rid of the above error? ( Perhaps, this is one for the $\TeX$ group? ) By the way, most of the notebook is readable in the PDF that has been generated despite the error message. By request.               Cell[CellGroupData[{Cell["Isometries", "Section",      CellChangeTimes->{{3.537693172799428*^9, 3.5376931780345087`*^9}}],          Cell[CellGroupData[{          Cell["Rotation r( c, \[Theta] )", "Subsection",      CellChangeTimes->{{3.53769767043847*^9, 3.5376976976887302`*^9}}],          Cell[CellGroupData[{          Cell[BoxData[      RowBox[{       RowBox[{"r", "[",         RowBox[{         RowBox[{"{",           RowBox[{"0", ",", "0"}], "}"}], ",",          FractionBox["\[Pi]", "2"]}], "]"}], ".",        RowBox[{"{",         RowBox[{"10", ",", "0", ",", "1"}], "}"}]}]], "Input",      CellChangeTimes->{{3.5376977167764263`*^9, 3.537697742754182*^9}, {       3.537697791774678*^9, 3.5376978287525744`*^9}, {       3.5376978660254316`*^9, 3.53769787910806*^9}, {3.537697978108968*^9,        3.53769804034195*^9}, {3.5376984660418816`*^9,        3.5376984703793983`*^9}}],          Cell[BoxData[      RowBox[{"{",        RowBox[{"0", ",", "10", ",", "1"}], "}"}]], "Output",      CellChangeTimes->{       3.537697802907297*^9, {3.5376978586153617`*^9,         3.537697880345572*^9}, {3.537697981996502*^9,         3.537697992024061*^9}, 3.53769802411933*^9, 3.537698072699666*^9,         3.5376984781344557`*^9, 3.5378633219215155`*^9}]     }, Open  ]]     }, Open  ]]     }, Open  ]]


title: Invalid comparison in RegionPlot

text: I'm trying to plot something like this:               RegionPlot[0 < (.5*a2 - .25*a1)/(a2 - a1) < 1 && 0 < a1 < a2 < 1, {a1, 0, 1}, {a2, 0, 1}]      The above code yields an error message (it tries to use 1/0 in the inequality). I can solve the problem by simply starting the plot at an arbitrarily low value of `a2`. My question is: is there a more "elegant" way of doing that? I would expect the inequality `0 < a1 < a2 < 1` to take care of that.


title: Integral of a transcendental equation

text: I have taken the following derivative of a transcendental equation using the `D[...]` function, as part of an approximation:               Solve[y'[x] == -D[-t*Log[2*Cosh[(a* y'[x] + x)/t]] , x], y'[x]]      And the result is then               y'[x] == Tanh[(x + a y'[x])/t] (1 + a y''[x])      For simplification reasons I then just ignore the `(1 + a y''[x])` term, leaving me with               y'[x] == Tanh[(a* y'[x] + x)/t]      but now I want to find the integral of that simplified function. How do I do that in _Mathematica_? I haven't been able to find a function that is the obvious counterpart to `D[...]`, to calculate the integral of my simplified `y'[x]` numerically to find my new `y[x]` \- the challenge of course being that `y'[x] == Tanh[(a* y'[x] + x)/t]` is a transcendental equation.


title: How can I fill a wire-frame structure with gas in a Graphics3D drawing?

text: I am very poor at visualization. I want to make a transparent "building" filled with gas. I wrote the following code for the building and it's fine.                w = 100;      l = 200;      h = 30;      m = 70;      backwall = {{0, l, 0}, {w, l, 0}, {w, l, h}, {0, l, h}};      side1 = {{0, 0, 0}, {0, 0, h}, {0, l, h}, {0, l, 0}};      side2 = {{w, 0, 0}, {w, 0, h}, {w, l, h}, {w, l, 0}};      floor = {{0, 0, 0}, {w, 0, 0}, {w, l, 0}, {0, l, 0}};      top = {{0, 0, h}, {w, 0, h}, {w, l, h}, {0, l, h}};      front = {{0, 0, 0}, {w, 0, 0}, {w, 0, h}, {0, 0, h}};      leftRoof = {{0, 0, h}, {w/2, 0, m}, {w/2, l, m}, {0, l, h}};      rightRoof = {{w, 0, h}, {w/2, 0, m}, {w/2, l, m}, {w, l, h}};      fig = Graphics3D[{        Transparent, Style[Polygon[{backwall, side1, side2, floor, front, leftRoof,rightRoof}],        Lighting -> {{"Ambient", Green}}]},        Boxed -> False,        RotationAction -> "Clip"]      But in a second step, I want to fill the building with gas, which is also transparent. Why? Because after filling it with the gas, I will put points inside the building. For this purpose, I wrote the following code.               data = RandomReal[60, {10, 3}];     data1 = RandomReal[60, {10, 3}];     redPoints = Graphics3D[{PointSize -> Large, Style[Point[#], Blue]} & /@ data,        Boxed -> False];     bluePoints = Graphics3D[{PointSize -> Large, Style[Point[#], Red]} & /@ data1,        Boxed -> False];     Show[{fig, redPoints, bluePoints}]      After evaluation of the above code, I am getting an image like this: ![enter image description here](http://i.stack.imgur.com/YQY7G.png) Transparent-building-wise and point-placement-wise this is fine; my problem is filling the building with gas. How can get the gas (light gray color) to fill the inside of the entire building. Can anyone help me?


title: Remove Removed From Output

text: How might I remove `Removed[..]` symbols from the output of an expression? For example               Clear[b]; b := Sin[a + a]; Remove[a];     b      > Sin[2 Removed[a]] Now as discussed in the story of removed symbols, `Removed[a]` aren't functions with `Heads` but symbols with special forms. This works for catching the symbols.               b /. Cases[b, s_Symbol :> (s :> a), {0, Infinity}, Heads -> True]      But how might I generalize this to all symbols? Here is my evolving code. `ToString[s] == Removed` should likely be generalized, but more importantly I can't seem to prevent `s:>newHead` from going unevaluated.               Replace[b,      HoldPattern[s_Symbol] :>       With[{newHead = If[ToString[s] === "Removed[a]"             a, b           ]},         s :> newHead /; True], Infinity      ]


title: Compatibility issues for Combinatorica package

text: I am trying to use the Combinatorica package in a Mathematica version 9 in the following code :               graph = {{0, 1, 0, 0, 1}, {1, 0, 1, 0, 0}, {0, 1, 0, 1, 0}, {0, 0, 1,          0, 1}, {1, 0, 0, 1, 0}};         Needs["Combinatorica`"]        ChromaticNumber[AdjacencyGraph[graph]]      The output for this code is               ChromaticNumber[<graph>]      I think Mathematica does not recognize the function ChromaticNumber. The compatibility guide here does not list the function too. How do I use this function ?


title: CompiledFunction crashes kernel

text: This crashes my kernel               Compile[{{x, _Real}, {center, _Real, 1}, {point, _Real, 1}},      (1` + (x - 1`) Exp[-Norm[point - center] 10`]),      RuntimeAttributes -> Listable][3`, {0`, 0`}, {{1`, 1`}, {{1`, 1`}}}]      Changing the input parameters doesn't seem to change anything. Changing `(x - 1`)` to `x` or to `(3` - 1`)` solves it. Passing a proper matrix `{{1`, 1`}, {1`, 1`}}` solves it too. Removing the `10`` solves it too What could be going on?


title: Misaligned DensityHistogram, DistributionAxes & PlotRange

text: data = RandomReal[NormalDistribution[0.5, 0.1], {10000, 2}];     DensityHistogram[data, PlotRange -> 1, Method -> {"DistributionAxes" -> "Histogram"}]      The problem I have is that the histogram on the axes is not aligned with the density plot because of the PlotRange. I tried using Mathematica 8 and 9. Can someone please help me fix this? ![Problem Graph](http://i.stack.imgur.com/vCf2B.png)


title: Transformation of the NDSolve result into new dependent variables

text: I have solved a set of coupled differential equations and now I need to convert them into different dependent variables and sketch their trajectories. Here is the code I have written so far:               zeta1 = x[t] + I y[t];     Eqn1 = (I/zeta1 + 1/Im[zeta1])/(8 Pi Conjugate[zeta1]);     s = NDSolve[{x'[t] == Re[Eqn1], y'[t] == -Im[Eqn1], x[0] == 1,      y[0] == 1}, {x, y}, {t, 0, 10}];      The new coordinates are obtained as follows:               p[t] = -x[t]^2 + y[t]^2          q[t] = -2 x[t] y[t]      Any ideas how should I do this ?


title: Parallel Licenses

text: I am using Mathematica 9 on a university computer. I am trying to use the basic commands for parallel evaluation. ProcessorCount evaluates to 4, but commands such as ParallelMap simply evaluate sequentially. MaxLicenseProcesses evaluates to infinity. MaxLicenseSubprocesses evaluates to 1. Under Evaluation>>"Parallel Kernel Configuration", there is a checkbox "Limit by license availability (1)". Checking or unchecking appears to change the number of configured kernels between 0 and 4. What does this mean? Does the university license make parallel computations impossible? Why is this even a checkbox if it's a license restriction?


title: Replace rule does not match

text: I have the following expression               -3 I Ez Re[Ex] + 3 I Ex Re[Ez]      And I wish to write this in the form `-3 Re[I Ez Conjugate[Ex]]`. So I have made the rule               f_ I x_ Re[y_] - f_ I y_ Re[x_] -> f Real[I x Conjugate[y]]      But my expression does not seem to match that expression. What is wrong?


title: Malliavin Derivative with Mathematica is it possible?

text: Is it possible to define a Malliavin calculus with _Mathematica_ 9? Consider a random variables on the Wiener-space $\Omega=\mathcal{C}([0,1])$ of the form $$F=F(\omega)=\displaystyle\int_{0}^{T}h_{t}dW_{t}$$ for some deterministic $h(.)$ in $L^{2}[0,T].$ Here, $\omega$ is a path in the Wiener- space, $\omega \in \Omega$. We define the Malliavin derivative by $$ DF=h,\text{ and }D_{t}F=h_{t}. $$ Let say `MalliavinDer` is this derivative. We have the following rules   1. `MalliavinDer[F_ + G_] := MalliavinDer[F]+MalliavinDer[G]`;   2. `MalliavinDer[F_G_]:=MalliavinDer[F]G+ MalliavinDer[G]F`   3. `MalliavinDer[f(F)]:=f'[F]MalliavinDer[F].` On the other hand, we have for example:   1. `MalliavinDer[\int_0^T h(t)dWt] := h(t)`   2. `MalliavinDer[W_s] := Piecewise[{{1, s <t}, {0, s >t}}]`   3. `MalliavinDer[f(W_s] := f'[W_s])Piecewise[{{1, s <t}, {0, s >t}}]`


title: How to work around Mathematica hanging when showing a large SparseArray?

text: **Note:** This is fixed in 9.0.1. * * * In Mathematica 9, if I display any large `SparseArray` object in the default way (which looks something like `SparseArray[<97293>, {25000, 25000}]`), the MathKernel process will keep using 100% CPU, the Front End will hang and eventually display the "Kernel is not responding to a dynamic evaluation; Abort or Continue waiting?" dialog. Pressing Abort will kill the kernel process. I am looking for a way to avoid / work around this. ### Reproducing the problem Try               g = RandomGraph[{25000, 50000}];     AdjacencyMatrix[g]  (* note missing semicolon *)      In a few seconds after the result is displayed Mathematica 9 will hang in the sense that:   * the beachball cursor shows intermittently (on OS X)   * the kernel uses 100% CPU (one core)   * subsequent evaluations will be impossible until the kernel is killed Mathematica 8 will not hang. ### Observations   * Not displaying the SparseArray (putting a semicolon after `AdjacencyMatrix[g];`) avoid the problem.   * The displayed form of the SparseArray is very short. This is true even for the cell expression. The problem is not caused by an overwhelming amount of data being sent to the front end.   * I still want to keep track of how many non-zero elements there are in the SparseArray so I would like to display it   * Disabling Dynamic updating from the Evaluation menu does not change anything. That would have been a usable temporary workaround.   * The problem does not appear when using the command line version (kernel only) of Mathematica   * Killing the kernel manually (not using the front end) causes `INTERNAL SELF-TEST ERROR: Kernels|c|6568` I believe this to be a bug and I'll contact support, but some analysis of why the problem happens would be useful to work around it. Or perhaps just a way to find the number of non-zero elements quickly. Then maybe I could write an alternate `Format` for `SparseArray` objects. ### Version & system info This happens with Mathematica 9.0.0.0 on OS X 10.8.2, 16 GB RAM. Can someone on OS X try to reproduce the problem?


title: How to extract the probability density function from SmoothHistogram?

text: I have some data.I plot the histogram with `SmoothHistogram` in _Mathematica_. If the y-axis of the histogram is my p(x) function, I want to plot f(x)=(1/n)ln(p(x)) with _Mathematica_. I don't know how?!               data = Import["Desktop/kmc final result.txt", "List"];     d = SmoothHistogram[data, Automatic, "PDF"];     time = 200;          f[x_] := -1/time Log[d, x]


title: Using Solve but getting no output

text: I am trying to solve a model using a constant-elasticity-of-substitution production function, but when I try to solve the first order conditions, I just keep getting back what I typed.               Solve[-i - q + p s^(-1 + a) (1 + s^a)^(-1 + 1/a) - t == 0, s]      > >     Solve[-i - q + p s^(-1 + a) (1 + s^a)^(-1 + 1/a) - t == 0, s] >   Any help on how to tackle this problem would be great.


title: How to visualize the structure of this dynamic programming code

text: I am studying Mr. Wizard's answer to this question which tries to identify elementary circles in a graph. That answer uses dynamic programming technique to simplify the code. The underlying guideline in the code is that, in Mathematica, more specific rules are applied before more general rules. Thus, the three functions with the same name `f`:               (* case 1 *)     f[x_, b___, x_] := (        (f[##] = {}) & @@@ NestList[RotateLeft, {x, b}, Length@{x, b} - 1];        {{x, b}}     );          (* case 2 *)     f[circle__] /; Signature@{circle} === 0 = {};          (* case 3 *)     f[circle___, vertex_] :=        Join @@ (f[circle, vertex, #] & /@ ReplaceList[vertex, edges]);      will always be checked and evaluated in the order case1 -> case2 -> case3. Where the `circle___` is initially an nonexistent expression and I slightly modify the variable names to make the code easier to understand. For example, when we evaluate `f[1]`, firstly the pattern of case1 doesn't apply, so we come to case2 which is also not applicable due to the fact that`Signature@{1}` is not `0`. Finally we check that case3 is applicable and duo to `SetDelayed` we need to temporarily leave the evaluation of `f[1]` and try to compute `f[1,2]` and `f[1,4]` instead, and so on. We can use `Trace[f[1]]` or `Trace[f[1], f[__]]` to get a sense of the evaluation progress. But the results are nested expressions and not easy to recognize. It will be helpful for us to understand the code better if we can find a way to visualize the dynamic progress. A first try can be made like this               op = {{1, 2}, {1, 4}, {2, 3}, {2, 5}, {3, 1}, {3, 6}, {4, 1}, {4,          6}, {5, 4}, {5, 2}, {6, 5}, {6, 3}};     vertices = Union @@ op;     edges = Rule @@@ op;          traceRes = Trace[f[1], f[__]];     traceResIndex = traceRes /. MapIndexed[#1 -> #2[[1]] &,          DeleteDuplicates@Flatten@traceRes];     pos = First@Position[traceResIndex, #] & /@ Flatten[traceResIndex];     pos = Sort[pos, Length[#1] <= Length[#2] &];     pos = Gather[pos, Length[#1] == Length[#2] &];          length = Length[pos];     i = 1;     linkedVretices = {};     With[{cmuopt = SystemOptions["CompileOptions"]},       Internal`WithLocalSettings[        SetSystemOptions[{          "CompileOptions" -> "ListableFunctionCompileLength" -> Infinity,          "CompileOptions" -> "MapCompileLength" -> Infinity          }], (         While[i + 1 <= length,           linkedVretices = {             linkedVretices,             Map[              Block[{subList, subLength, link, var},                subList = pos[[i, #]];                subLength = Length[subList];                subList[[-1]] += 1;                link = Select[pos[[i + 1]], #[[;; subLength]] == subList &];                Thread[Rule[var, link]] /. var -> pos[[i, #]]                ] &, Range@Length@pos[[i]]              ]};           i += 1;           ];),        SetSystemOptions[cmuopt]        ]];     linkedVretices = Flatten[linkedVretices];     linkedVretices = Apply[traceRes[[##]] &, linkedVretices, {2}]          GraphPlot[linkedVretices, VertexLabeling -> True]      ![enter image description here](http://i.stack.imgur.com/kVptg.png) We can clearly understand the progress from the above graph. However, as the input data `op` gets a bit more complex, for example,               op = {{1, 2}, {1, 9}, {2, 3}, {2, 17}, {3, 4}, {3, 13}, {4, 1}, {4,          5}, {5, 4}, {5, 6}, {6, 16}, {6, 7}, {7, 8}, {7, 22}, {8, 5}, {8,          10}, {9, 1}, {9, 10}, {10, 8}, {10, 11}, {11, 12}, {11, 21}, {12,          9}, {12, 18}, {13, 14}, {13, 3}, {14, 15}, {14, 20}, {15,          16}, {15, 23}, {16, 13}, {16, 6}, {17, 2}, {17, 18}, {18,          19}, {18, 12}, {19, 24}, {19, 20}, {20, 17}, {20, 14}, {21,          11}, {21, 22}, {22, 7}, {22, 23}, {23, 15}, {23, 24}, {24,          19}, {24, 21}};      Then the result will be               GraphPlot[linkedVretices, VertexLabeling -> Tooltip]      ![enter image description here](http://i.stack.imgur.com/848No.png) or if we use `CommunityGraphPlot` ![enter image description here](http://i.stack.imgur.com/wYPUk.png) Now it is too complex for extracting useful information. I wonder if we can find a way to clearly visualize the progress, like only show some "local graph" in-progress? Such technique, although not very important for actually solving problems, can still be valuable for tracking.


title: How to interpret and show an input number with the amount of significant digits given?

text: what can I do to have Mathematica intepret and show a number with exactly the amount of digits I gave as an input? I have a larger talbe with numbers (text file, whitespace seperated) which are formatted in the way that the prescission is given by the number of digits. To I can't work around using the same number of digits for the whole input. For example if I give the input               In: 2.414000         2.550      Mathematica will retun               Out1: 2.414     Out2: 2.55      I would instead like to exactly the nuber, or more precisely the amount of digits I had as an input. So in this case I would like to have see the number including the three zeros, or one zero respectively at the end of them. Here one addition: I very much like the appraoch that was proposed to import strings and convert them! But what will I need to change to convert for example this table here for calculations? I imported it as strings before. \begin{array}{lrr} \text{En[MeV]} & 0 & 1 \\\ 0 & .0317223 & .0237898 \\\ 1 & .1717071 & .1555525 \\\ <\nu > & 22.4140000 & 2.5236700 \\\ \text{$<\nu $($\nu $-1)$>$} & 4.6382 & 5.1013758 \\\ \text{$<\nu $($\nu $-1)($\nu $-2)$>$} & 6.8176 & 8.0012201 \\\ \end{array} Or given as a List:               {{"En[MeV]", "0", "1"}, {"0", ".0317223", ".0237898"}, {"1", ".1717071", ".1555525"}, {"<\[Nu]>", "22.4140000", "2.5236700"}, {"<\[Nu](\[Nu]-1)>", "4.6382", "5.1013758"}, "<\[Nu](\[Nu]-1)(\[Nu]-2)>", "6.8176", "8.0012201"}}


title: How Do I Perform Simple Operations On The Elements of a Table?

text: I have been using the function `HistogramList` to generate frequency tables off a data set. The code looks like this:               frequencytable=HistogramList[dataA,{-0.5, 6.5, 1},"PDF"][[2]]      with a numerical output of: > 0.0152, 0.0937, 0.0234, 0.2969, 0.2500, 0.0781, 0.0312 Here is my question. I would like to add the three numbers at the right hand side to one another. Next, I would like to add the three numbers at the left hand side to one another. Last, I would like to subtract the sum of the three numbers on the left from the sum of the three numbers on the right. How do I do that?


title: Is garbage collection broken in version 10.0.0?

text: In version 10.0.0 under Windows I am observing the following behavior:               Do[Module[{foo}, foo[x_] := 1; foo[0]], {10}]          Names["foo$*"]      > >     {"foo$593", "foo$594", "foo$595", "foo$596", "foo$597", "foo$598", >      "foo$599", "foo$600", "foo$601", "foo$602"} >   I am aware that in past versions `Module` Symbols were sometimes not garbage collected but never in such a simple case as this as far as I know. The code above returns `{}` in version 7, as one would expect. Do I have something wrong with my configuration or is this behavior reproducible?   Assuming the latter is there an explanation for this other than a bug?


title: Series plot will not display properly (Fourier Series)

text: c1[n_] := 1/2/Pi Integrate[Sign[x] Exp[-I n x], {x, -Pi, Pi}];      c2[n_] = Simplify[c1[n], Assumptions -> Element[n, Integers]];      c[n_] := If[n == 0, c1[0] = 0];     f5[x_] = Sum[c[k] Exp[I k x], {k, -10, 10}];      Plot[{f5[x], Sign[x]}, {x, -Pi, Pi}]      I am trying to plot the $Sign[x]$ function and the series: $\displaystyle\sum_{n=-\infty}^\infty \dfrac{i(-1)^n - i}{n\pi}e^{inx} $ (which should be the answer to the integral in the code) on the same graph, but I cannot seem to get it to work. It displays no error, just an empty graph.


title: Integral of GeneratingFunction

text: I know that GeneratingFunction can be used to compute the generating function $\sum_{n=0}^\infty a_n x^n$ of a sequence $(a_n)_n$ via               GeneratingFunction[a[n],n,x]      I also know that polynomial (in $n$) coefficients of the general term $a_n$ of the sequence result in an expression involving derivatives of the generating function, e.g.               GeneratingFunction[n a[n],n,x]     (* x (GeneratingFunction^(0,0,1))[a[n],n,x] *)      This does not seem to happen with rational (in $n$) coefficients, which would lead to indefinite integrals of the generating function. For example I would expect the input               GeneratingFunction[a[n]/(n + 1), n, x]      to result in               (*1/x Integrate[GeneratingFunction[a[n],n,y],{y,0,x}]*)      or               (*1/x GeneratingFunction^(0,0,-1))[a[n],n,x]*)      but this does not seem to be the case. **I thus have the following question:** Is it possible to get Mathematica to compute the generating function of a linear combination of lagged values of $a_n$ with rational (in $n$) coefficients in terms of derivatives and integrals of the generating function of the sequence $(a_n)_n$?


title: How to set Block local variables by code?

text: I need to create a user defined Block function where the Block variables values are defined by code. For example, imagine I have:               SetAttributes[myBlock1,HoldAll]     myBlock1[args_]:=Block[{a=1,b=2,c=3,d=4},args]     myBlock1[{a,b,c,d}]      > {1, 2, 3, 4} Now, what I need is something like:               SetAttributes[myBlock2,HoldAll]     varList={"a","b","c","d"};          myBlock2[args_]:=Module[{varArgs},         varArgs=MapIndexed[ToString@Row[{#1,"=",#2[[1]]}]&,varList];         ToExpression@ToString@Row[{"Block[",varArgs,",",ToString@args,"]"}]     ]          myBlock2[{a,b,c,d}]      > {1, 2, 3, 4} The above function works, but it's very clumsy (using `ToExpression`) and error susceptible. I tried something like:               SetAttributes[myBlock3,HoldAll]     varList={"a","b","c","d"};          myBlock3[args_]:=ReleaseHold[Hold@Block[varDef,args]/.varDef:>MapIndexed[(Evaluate@Symbol[#1]=#2[[1]])&,varList]]     myBlock3[{a,b,c,d}]      But without success in the "variables injection". One important point is that a, b, c and d should not scape from the block scope. How can I do that?


title: Is there a way to speed up Simplify and/or PolynomialReduce Modulus-> 2?

text: I'm trying to simplify a series of equations with at most 64 input terms. As the number of terms involved in the equations increase, the runtime seems to grow exponentially.   Does anyone know of ways to decrease the running time of a process like this?: http://pastebin.com/LJrdsCVD (had to use pastebin because the equation is long. the below example uses FullSimplify and is also very slow.)               FullSimplify[Last[Last[PolynomialReduce[      {(a10*(b10+a01 b01 (a02+b02) (a03+b03)(a04+b04)         (a05+b05) (a06+b06) (a07+b07) (a08+b08) (a09+b09) (1+b10)+a00 b00 (a01+b01)         (a02+b02) (a03+b03) (a04+b04) (a05+b05) (a06+b06) (a07+b07) (a08+b08) (a09+b09)         (1+b10)+(a04 a05 a06 a07 a08 a09 b04+a05 a06 a07 a08 a09 b05+a04 a06 a07 a08 a09 b04         b05+a06 a07 a08 a09 b06+a04 a05 a07 a08 a09 b04 b06+a05 a07 a08 a09 b05 b06+a04 a07         a08 a09 b04 b05 b06+a07 a08 a09 b07+a04 a05 a06 a08 a09 b04 b07+a05 a06 a08 a09 b05         b07+a04 a06 a08 a09 b04 b05 b07+a06 a08 a09 b06 b07+a04 a05 a08 a09 b04 b06 b07+a05         a08 a09 b05 b06 b07+a04 a08 a09 b04 b05 b06 b07+a08 a09 b08+a04 a05 a06 a07 a09 b04         b08+a05 a06 a07 a09 b05 b08+a04 a06 a07 a09 b04 b05 b08+a06 a07 a09 b06 b08+a04 a05         a07 a09 b04 b06 b08+a05 a07 a09 b05 b06 b08+a04 a07 a09 b04 b05 b06 b08+a07 a09 b07         b08+a04 a05 a06 a09 b04 b07 b08+a05 a06 a09 b05 b07 b08+a04 a06 a09 b04 b05 b07         b08+a06 a09 b06 b07 b08+a04 a05 a09 b04 b06 b07 b08+a05 a09 b05 b06 b07 b08+a04 a09         b04 b05 b06 b07 b08+(a09+a08 (a07 b07+a06 b06 (a07+b07))+(a08+a07 b07+a06 b06         (a07+b07)) b08+a05 b05 (a06+b06) (a07+b07) (a08+b08)+a04 b04 (a05+b05) (a06+b06)         (a07+b07) (a08+b08)) b09+a03 b03 (a04+b04) (a05+b05) (a06+b06) (a07+b07) (a08+b08)         (a09+b09)+a02 b02 (a03+b03) (a04+b04) (a05+b05) (a06+b06) (a07+b07) (a08+b08)         (a09+b09)) (1+b10)))},            {a00^2 - a00, b00^2 - b00, a01^2 - a01, b01^2 - b01, a02^2 - a02, b02^2 - b02,         a03^2 - a03, b03^2 - b03, a04^2 - a04, b04^2 - b04, a05^2 - a05, b05^2 - b05,        a06^2 - a06, b06^2 - b06, a07^2 - a07, b07^2 - b07, a08^2 - a08, b08^2 - b08,        a09^2 - a09, b09^2 - b09, a10^2 - a10, b10^2 - b10, a11^2 - a11, b11^2 - b11,         a12^2 - a12, b12^2 - b12, a13^2 - a13, b13^2 - b13, a14^2 - a14, b14^2 - b14,         a15^2 - a15, b15^2 - b15, a16^2 - a16, b16^2 - b16, a17^2 - a17, b17^2 - b17,        a18^2 - a18, b18^2 - b18, a19^2 - a19, b19^2 - b19, a20^2 - a20, b20^2 - b20,         a21^2 - a21, b21^2 - b21, a22^2 - a22, b22^2 - b22, a23^2 - a23, b23^2 - b23,        a24^2 - a24, b24^2 - b24, a25^2 - a25, b25^2 - b25, a26^2 - a26, b26^2 - b26,        a27^2 - a27, b27^2 - b27, a28^2 - a28, b28^2 - b28, a29^2 - a29, b29^2 - b29,         a30^2 - a30, b30^2 - b30, a31^2 - a31, b31^2 - b31},            {a00, b00, a01, b01, a02, b02, a03, b03, a04, b04, a05, b05, a06, b06, a07, b07,         a08, b08, a09, b09, a10, b10, a11, b11, a12, b12, a13, b13, a14, b14, a15, b15,         a16, b16, a17, b17, a18, b18, a19, b19, a20, b20, a21, b21, a22, b22, a23, b23,         a24, b24, a25, b25, a26, b26, a27, b27, a28, b28, a29, b29, a30, b30, a31, b31},     Modulus -> 2]]]]


title: How to generalize and speed up this program?

text: There is a vector whose length is $n*m$, we can part it into $n$ sections in order. I want to define a function to compare the $i$-th and $i+1$-th section and find the minimum. The program for $n=m=3$ is as following:               f[x_] := Min[     Total[Total[Boole[Thread[x[[1 ;; 3]] < ##]]] & /@ x[[4 ;; 6]]],      Total[Total[Boole[Thread[x[[4 ;; 6]] < ##]]] & /@ x[[7 ;; 9]]],      Total[Total[Boole[Thread[x[[7 ;; 9]] < ##]]] & /@ x[[1 ;; 3]]]];      Could we generalize it to               f[x_,n_,m_] := Min[     Total[Total[Boole[Thread[x[[1 ;; m]] < ##]]] & /@ x[[m+1 ;; 2*m]]],      Total[Total[Boole[Thread[x[[m+1 ;; 2*m]] < ##]]] & /@ x[[2*m+1 ;; 3*m]]],      ....     Total[Total[Boole[Thread[x[[(n-1)*m+1 ;; n*m]] < ##]]] & /@ x[[1 ;; m]]]];      By the way, could we speed up this code? Any help or suggestion will be appreciated!


title: Differentiating a Cumulative Distribution Function which has a discontinuity at $0$

text: I want to take the derivative of a distribution function which has a discontinuity at $0$. Here is the function:               temp0[x_] :=If[Element[x, Reals], Sqrt[Pi]*(Erfc[(-2 + Log[2])/(2*Sqrt[2])] + (1 + Erf[(1 +Piecewise[{{(x - Log[2])/2, x < 0}}, (x + Log[2])/2])/Sqrt[2]] - Erfc[(-2 + Log[2])/(2*Sqrt[2])])*UnitStep[-Log[2]/2 - Piecewise[{{(x - Log[2])/2, x < 0}}, (x + Log[2])/2]]) + Sqrt[(2*Pi)/E]*(Erf[Log[2]/(2*Sqrt[2])] - Erf[Piecewise[{{(x - Log[2])/2, x < 0}}, (x + Log[2])/2]/Sqrt[2]])*UnitStep[-Log[2]/2 + Piecewise[{{(x - Log[2])/2, x < 0}}, (x + Log[2])/2]] + 2*Sqrt[Pi]*(-Erf[(2 + Log[2])/(2*Sqrt[2])] + Erf[(1 + Piecewise[{{(x - Log[2])/2, x < 0}}, (x + Log[2])/2])/Sqrt[2]])*UnitStep[-Log[2]/2 + Piecewise[{{(x - Log[2])/2, x < 0}}, (x + Log[2])/2]] + Sqrt[(2*Pi)/E]*(Erf[Log[2]/(2*Sqrt[2])] + Erf[Piecewise[{{(x - Log[2])/2, x < 0}}, (x + Log[2])/2]/Sqrt[2]])*UnitStep[Log[2]/2 + Piecewise[{{(x - Log[2])/2, x < 0}}, (x + Log[2])/2]], Integrate[(Sqrt[2]*UnitStep[-y - Log[2]/2] + 2*((Sqrt[2] - E^y)*UnitStep[y - Log[2]/2] + E^y*UnitStep[y + Log[2]/2]))/E^((1 + y)^2/2), {y, -Infinity, Piecewise[{{(x - Log[2])/2, x < 0}, {(x + Log[2])/2, x >= 0}}, 0]}, Assumptions -> NotElement[x, Reals]]]/(Sqrt[Pi]*(2*Sqrt[2/E]*Erf[Log[2]/(2*Sqrt[2])] + Erfc[(-2 + Log[2])/(2*Sqrt[2])] + 2*Erfc[(2 + Log[2])/(2*Sqrt[2])]))      If I plot it I get ![enter image description here](http://i.stack.imgur.com/mmQsg.png) The result of the derivation should be a density function. I used               fx0[x_] := D[temp0[x], x]      to get the density function but it didnt help me. Do you know how can I ignore the discontinuity at $0$ for the derivation? Thank you very much.


title: How can I simulate this animation of checking for prime numbers?

text: ![enter image description here](http://i.stack.imgur.com/PuK0W.gif) I can only implement a very simple one, I want to make my code look like that. Any better ideas?               Manipulate[       Partition[ Table[ If[ PrimeQ @ i, Framed @ i, Style[i, Gray]], {i, 1, j, 1}], 10],       {{j, 10}, 1, 100, 1}]


title: Integrating special functions

text: I would like to integrate the following function with Legendre polynomial and Gamma function. I am open to suggestions.               (* assumptions = {s > 0, α > 0} *)          Φ[s_, x_, α_] := (-1)^s Sqrt[(s α)/Gamma[1 + 2*s]]                       LegendreP[s, s, Tanh[α x]]          a1 =  Integrate[x Φ[s, x, α]^2, {x, -∞, ∞}]


title: Why does ParallelTable give different answer than Table

text: Consider the following code               a0 = 6.;     ls1 = ParallelTable[k, {k, -π/a0, π/a0, π/a0/100}];     ls2 = Table[k, {k, -π/a0, π/a0, π/a0/100}];     ls1 == ls2     (*False*)      Why does `ParallelTable` give different answer than `Table` and how to fix it?


title: Unexpected Behaviour with local variables and ToExpression

text: I encountered an unexpected behaviour in my mathematica-code, and want to understand whether that's a mathematica bug, or a misinterpretation on my side.               MainVar = 1;     Carrier = "MainVar";     f[] := (       Module[{MainVar},          MainVar = 3;         Print[MainVar];         Print[Carrier];         Print[ToExpression[Carrier]]     ])     f[] (* 3, MainVar, 1 *)      I would have expected that `Print[ToExpression[Carrier]]` gives me `3`, because `Carrier` points to `MainVar`, which has the value `3`. When I use `MainVar` as global variable (as Eldo suggested below), I get the expected `3`. So my question is: > Why does `ToExpression[Carrier]` give me `1` when I use `MainVar` as a local > variable, even if both `MainVar` and `Carrier` have the correct values?


title: I have the roots; how can I find an equation that they will satisfy?

text: I have two solutions; I want is to find an equation that these solutions satisfy using mathematica. The solutions are $x= \frac{{(26-k)}^2}{26}$ and $y= \frac{{k}^2}{26}$. I know by hand computing that $x$ and $y$ satisfy $\sqrt{x}+\sqrt{y}=\sqrt{26}$; How can I show this using _Mathematica_?


title: Does it help to do any preprocessing before `FindSequenceFunction`?

text: I am always amazed how smart `FindSequenceFunction` can be in discovering general term formula for a sequence of rational numbers. The documentation says it can work not only with rational sequences (and if fact I saw this in several simple cases).   * Have you found it useful to do some preprocessing of a sequence when it consists not of rational numbers? For example, if every element has a form $p_n+q_n\sqrt2$, do you try to separate sequences $p_n$ and $q_n$.   * How do you handle sequences of symbolic polynomial `Root`s?    * Do you use any standard code for preprocessing?    * Maybe you noticed that some preprocessing helps with rational sequences as well?


title: Arrowhead as MeshStyle or PlotMarkers for ListLinePlot

text: Is it possible to use the `Meshstyle` option of the `PlotMarkers` option in `ListLinePlot` to have `Arrowheads` as a point marker, obviously pointing in the positive direction of the line at that point? Using the example below, what sort of function would I need in the `MeshStyle` option.               ListLinePlot[Range[10]^2]      If not, what alternative solution might exist?


title: Solving an Equation (Recursively)

text: I have the following Values: $a[0]=1;a[1]=0;a[2]=0;a[3]=0;a[4]=\frac{g_2}{20};a[5]=0$. I need to compute the value of $b[n]$ in the following equation $$a[n]=\sum _{m=0}^{n} (m-2) \;\;a[m] \;\;b[n-m]$$ where $n=0,1,2,3,4,5$. For $n=0$, I get the value of $b[0]$. For $n=1$, I get the value of $b[1]$ using the value of $b[0]$. For $n$th iteration, I get the value of $b[n]$ using the values of $b[n-1],b[n-2],\dots,b[0]$. The values of $b[n]$ will then be used to solve for another variable, say, $c[n]$, for $n=0,1,2,3,4,5$. Is there any simple way of doing this in Mathematica? I am basically doing one iteration at a time (using the Solve command), which is very tedious. Thanks, Radz.


title: Is there an equivalent of "shiftdim" of MATLAB?

text: Recently I'm spending my time implementing some computer vision algorithms, which usually handle a large amount of data. The problem I'm facing now is that I have to reform my video data to pass it to `Fourier`. To be precise, I'm trying to apply a temporal filter to video, whose dimension is **Time*X*Y*Channel** , while I want to apply `Fourier` to `video[[All, x, y, c]]` (`x`,`y`,`c` are some integers). I've already tried to naively reform the data using `Table`. It works like charm for small data, but for large data, reforming alone takes long and consumes too much memory. (Took about 4 minutes and 3~4 GB of memory to handle data < 100 MBytes) MATLAB's `shiftdim` sounds like a nice solution, while I failed to find an equivalent or workarounds for _Mathematica_. (Or maybe my approach is wrong?) ## In short: > Is there any way to efficiently reform a multi-dimensional array, just like > `shiftdim`?


title: Mathematica not responding

text: I am working in the field of applied physics. Some body suggested me to use Mathematica for plotting graphs and programming. After going through some tutorials, I have written the following code but whenever I am trying to evaluate the notepad, it takes forever to evaluate. I have halted the code after half an hour. Kindly suggest, how to evaluate the following code?               (*Define all parameters and constants*)     (* For Copper material*)     Clear[xi, s];     lmd = 9.4*10^10 ;(*Lambda*)     mu = 4.0*10^10;   (*mu*)     kp = 10^10; (*kappa*)     eps0 = 10^(-9)/(36*Pi);     mu0 = 4*Pi*10^(-7);     H0 = 10^7;     nu = 0.0268*10^8; (*Nu*)     T0 = 293; (*Initial value of temperature*)     ro = 1.74*10^3; (*rho*)     gm = 0.779*10^(-5); (*gamma*)     j = 0.2*10^(-19); (*microintertia*)     ce = 383.1; (*Ce*)     ks = 1.7*100; (* K* *)     a = 0.1; (*two temperature parameter*)     sig0 = 2.2*10^7;(*sigma_not*)     (*xi=0.2; (*fourier parameter*)     s=0.7;(*laplace parameter*)*)     tau1 = 0*8.765*10^(-13); (*relaxation parameter*)     tau0 = 6.131*10^(-13); (*relaxation parameter*)     eta = ro*ce/ks;(*eta*)     c0 = Sqrt[(lmd + 2*mu + kp)/ro];          (*Define all coefficients of partial differential equations*)     a1 = lmd + 2 mu + kp;     a2 = c0^2*eps0*mu0*H0^2;     a3 = nu*T0;     a4 = ro*c0^2;     a5 = mu + kp;     a6 = kp^2/(gm*eta^2*c0^2*(mu + kp));     a7 = 2 kp/(c0^2*eta^2*gm);     a8 = ro*j*c0^2*eta/gm;     a9 = ro*ce/(ks*eta);     a10 = nu/(ks*eta);     a11 = a*c0^2*eta^2;     a12 = lmd/(lmd + 2 mu + kp);     a13 = mu/(lmd + 2 mu + kp);     a14 = (mu + kp)/(lmd + 2 mu + kp);     a15 = eta/sig0*mu0;     a16 = eta/(sig0*mu0*c0);     a17 = c0^2*eps0*eta^2/(sig0^2*mu0);     (* Now define the coefficients of total differential equation*)     alp1 = xi^2 + (a2 + a4)*s^2/a1;     alp2 = a3*(1 + tau1*s)/a1;     alp3 = xi^2 + (a2 + a4)*s^2/a5;     alp4 = xi^2 + a7 + a8*s^2;     alp5 = a9*(s + tau0*s^2);     alp6 = a10*(s + tau0*s^2);     alp7 = xi^2 + 1/a11;     alp8 = 1 + a11*alp5;     alp9 = xi^2 + a11*alp5*alp7;     alp10 = a11*alp2*alp6 + alp2;     alp11 = a11*alp2*alp6*(xi^2 + alp7) + alp1*alp2 + alp9;     alp12 = a11*alp2*alp6*alp7*xi^2 + alp9*alp11;     alp13 = alp3 + alp4 + alp6;     alp14 = alp3*alp4 + a6*xi^2;     alp15 = alp11/alp10;     alp16 = alp12/alp10;          (* Now define the roots of total differential equation*)     m1 = Sqrt[(alp13 + Sqrt[alp13^2 - 4*alp14])/2];     m2 = Sqrt[(alp13 - Sqrt[alp13^2 - 4*alp14])/2];     m3 = Sqrt[(alp15 + Sqrt[alp15^2 - 4*alp16])/2];     m4 = Sqrt[(alp15 - Sqrt[alp15^2 - 4*alp16])/2];          (*Now define the constants obtained after solving boundary conditions*)               theta0 = 0.1;(*magnitude of temperature taken in boundary conditions*)               alp17 = -I*(xi^2*a13 + alp3*a14) (alp1 - xi^2*a12)/(xi*(1 - a12));     alp18 = I*xi*(a14 + a13);     del1 = alp17*(m2^2 - alp3) - alp18*m1*m3*(m1^2 - m2^2);     del2 = alp17*(m1^2 - alp3) + alp18*m2*m4 (m1^2 - m2^2);     aa1 = I*alp2*(alp1 - xi^2*a12)*(m2^2 - alp3)*(del1 + del2)*        theta0/(xi*           m1*(1 - a12)*(m1^2 -              m2^2)*((m3^2 - alp1)*del2 + (m4^2 - alp1)*del1));     aa2 = -I*alp2*(alp1 - xi^2*a12)*(m1^2 - alp3)*(del1 + del2)*        theta0/(xi*           m2*(1 - a12)*(m1^2 -              m2^2)*((m3^2 - alp1)*del2 + (m4^2 - alp1)*del1));     aa3 = alp2*del2*theta0/((m3^2 - alp1)*del2 + (m4^2 - alp1)*del1);     aa4 = alp2*del1*theta0/((m3^2 - alp1)*del2 + (m4^2 - alp1)*del1);               (* Now define the functions to be plotted*)          phi[x3_] := (m1^2 - alp3)*aa1*E^(-(m1*x3)) + (m2^2 - alp3)*aa2*         E^(-(m2*x3));     theta[x3_] :=        1/alp2*((m3^2 - alp1)*aa3*E^(-(m3*x3)) + (m4^2 - alp1)*aa4*           E^(-(m4*x3)));     u1[x3_] := (m1*aa1*E^(-(m1*x3)) + m2*aa2*E^(-(m2*x3))) +         I*xi*(aa3*E^(-(m3*x3)) + aa4*E^(-(m4*x3)));     u3T[x3_] :=        Re[I*xi*(aa1*E^(-(m1*x3)) + aa2*E^(-(m2*x3))) - (m3*aa3*            E^(-(m3*x3)) + m4*aa4*E^(-(m4*x3)))];      u3L[x3, x1] := Evaluate[InverseFourierTransform[u3T[x3], xi, x1]];     u3[x3, x1, t] := Evaluate[InverseLaplaceTransform[u3L[x3, x1], s, t]];     (* Now evaluate the function *)     x1 = 0; t = 0.1;     u3[x3, x1, t]


title: Specifying Range of RSolve

text: When I input               RSolve[{0 == q[n + 1]^2 + 3 q[n + 1] + 2 q[n + 1] q[n] - 6 q[n] + q[n]^2, q[0] == 1}, q[n], n]      I get two complicated-looking complex solutions:               {{q[n] -> 1/4 I ((-2 + I) + 4 I^n - (2 + 5 I) I^(2 n) - (2 + 2 I) I^n Sqrt[5] + (2 + 2 I) I^(2 n) Sqrt[5])}, {q[n] -> -(1/4)I ((2 - I) - 4 I^n + (2 + 5 I) I^(2 n) - (2 + 2 I) I^n Sqrt[5] + (2 + 2 I) I^(2 n) Sqrt[5])}}      There should be just one solution for each $n$ that is between 0 and 1, and I'd like only to see those. How can I achieve that?


title: How to partition MatrixPlot graphics?

text: Is there an easy approach - hopefully built-in - to partitioning `MatrixPlot` graphics into rows or columns (or both) of graphics sharing the same underlying options? For example, in the following graphic, the red rectangles indicate where partitions should occur, and the respective sub-Rasters (along with `FrameTicks` etc) can then be reorganized using `Row` ![enter image description here](http://i.stack.imgur.com/CmSYk.png) This particular graph (excluding the rectangles which were generated in `Epilog`) has `Length` 6, of which all but the first `Part` are related to options. But it's tedious to even list what parts of the partitions component correspond to which parts, which subsequently must be modified - for example `FrameTicks` are to be repositioned (reindexed). Obviously, because the "heatmap" color scale is shared among all the members of the desired partition, it's not feasible to partition the matrix prior and then mapping through `MatrixPlot`


title: How to localize symbols on the right-hand side of Rule when using ReplaceAll?

text: I am frustrated by the following:               {1, 2, 3.0} /. a_Integer -> a + 1      The `a` on the left side of the arrow is localized and appears in green whereas its sibling on the right side is blue. Consequently, I have to write:               Block[{a}, {1, 2, 3.0} /. a_Integer -> a + 1]      to avoid naming conflicts. It doesn't make sense to me that, within one inbuilt function, a variable is treated differently. I already got some hard to find errors because I forgot to block. What did I overlook here?


title: How can I propagate an asymmetric error in a function about the central value?

text: If I have some asymmetric error about the central value in x and y, then how can it be propagated in a function `f[x, y, z]`? For example, given               f[x, y, z] = 2*x^2 + 3*y^3 + z       and `x = 1.2` with error (+0.4,-0.3) and `y = 2.3` with error (+0.3, -0.5), how can I plot `f` as a function of `z` showing these errors?


title: Find maximum value of interpolation function - obviously wrong result

text: Minimizing and maximizing interpolation function has already been asked and answered, see here for example. Yet, I observe a strange behaviour. Well, I can understand that the wrong guess of Mathematica is due to several maxima, but still I'm surprised I don't manage to get a better result. ## Generation of the considered function Here is how I get the interpolation function `Theta[t]`:               OmegaS = 1.32; OmegaP = 1; l0 = 1; tmax = 100;          eqn1[t_] = r''[t]/l0 - r[t]*theta'[t]^2/l0 + OmegaS^2*(r[t]/l0 - 1) - OmegaP^2*Cos[theta[t]];     eqn2[t_] = r[t]*theta''[t]/l0 + 2 r'[t]*theta'[t]/l0 + OmegaP^2*Sin[theta[t]];          sol = NDSolve[{eqn1[t] == 0, eqn2[t] == 0, r[0] == .9, r'[0] == 0,      theta[0] == 0.001, theta'[0] == 0}, {r, theta}, {t, 0, tmax}][[1]];          Theta[t_] = theta[t] /. sol      This is what `Theta` looks like:               Plot[Theta[t], {t, 0, 100}, PlotRange -> All,  AxesLabel -> {"t", "Theta(t)"}]      ![plot Theta](http://i.stack.imgur.com/iIIKh.png) ## Attempts to identify the maximum I now want to find the maximum of `Theta[t]` for $t\in[0,100]$. I underline that the peak could be _anywhere_ in $[0,100]$ so I cannot indicate any relevant initial guess. I tried all the following solutions, which obviously give an incorrect result:               MaxValue[{Theta[t], 0 <= t <= tmax}, t]     (* 0.243314 *)     NMaxValue[{Theta[t], 0 <= t <= tmax}, t]     (* 0.243314 *)     FindMaximum[{Theta[t], 0 <= t <= tmax}, t]     (* {0.000999881, {t -> 0.0146385}} *)     Maximize[{Theta[t], 0 <= t <= tmax}, t]     (* {0.243314, {t -> 92.1206}} *)     NMaximize[{Theta[t], 0 <= t <= tmax}, t]     (* {0.243314, {t -> 92.1206}} *)      The best (inelegant) way I found to approximate the maximum is brute-force:               Max[Table[Theta[i], {i, 0, tmax, .001}]]     (* 0.687071 *)      ## Question Do you know:   * why my attempts fail?   * a good way to find the (global!) maximum?


title: How are parameters evaluated for a Plot in Manipulate

text: I am trying to get my head around how `Manipulate` evaluates functions in a Plot. I have read the introduction to Manipulate, and introduction to Dynamic, but I still can't figure it. For my specific example, I have a function `bigA` parameterised by `m1` and `m2` (this relates to question),               bigA[t_]:= (m1+m2) ((m1 m2 t)/(m1+m2)^3)^0.25      So when I try to plot it in Manipulate,               Manipulate[      Plot[bigA[t], {t, 1, 10}],      {{m1, 1.4}, 0.8, 3},      {{m2, 1.4}, 0.8, 3}]      Nothing appears. I presume this is because `m1` and `m2` aren't being evaluated. But I don't know what the order is supposed to be. # Edit The thing is, this seems to work when I `Evaluate` and don't plot, i.e,               Manipulate[Evaluate@bigA[t],      {{m1, 1.4}, 0.8, 3},      {{m2, 1.4}, 0.8, 3}]      So couldn't I just stick a `Plot` command in there somewhere?


title: Manipulate using a variable defined outside of the manipulate function

text: I want to do something like this:               expr := x^e;     Manipulate[Plot[expr, {x, 0, 4}], {e, 1, 3}]      But the plot shows up empty. Yes, it works if I do:               expr[x_,e_] := x^e;     Manipulate[Plot[expr[x,e], {x, 0, 4}], {e, 1, 3}]      But I don't want to do that. Why? Because the function I'm actually working with has about a dozen variables. I want to be able define my function just as as expression (that I use in many places throughout my notebook, in addition to this particular Manipulate) so that I don't have to bother with remembering the order in which I defined the dozen or so variables that comprise the function definition. This way I can substitute values into my function using ReplaceAll as I see fit. My approach has been working fine as I continue to shape this function, but using Manipulate becomes very cumbersome. I want to manipulate several of these variables without having to worry about typing a whole lot of code. Is there a way I can keep the definition of my function as a simple Set or SetDelayed (without the pattern matching) but change something about my Manipulate expression to make the Manipulate function actually manipulate symbols that are not do not explicitly occur within the Manipulate expression? Thanks!


title: Evaluation in Manipulate

text: I have an expression assigned to a variable. For example:               exp1 = a*x+b      Now I would like to plot it using something like this               Manipulate[      Plot[Evaluate[ex99], {x, 0, 1}],      {a, 0, 1},      {b, 0, 1}]      I can see 'a' and 'b' being properly substituted by 'Evaluate', but Plot does not work as expected. I suspect it has something to do with 'x' substitution. How can I fix that? Thanks!


title: Abridging Lists of Equations within NDSolve, Manipulate

text: I have a pretty little `NDSolve` function that I've finally decked out with manipulatable (by sliders) coefficients, which changes the graph in real time. However, I used dummy equations in making sure I could set up the system I want, which I have as you can see by simply copy-pasting:               Manipulate[      Plot[       Evaluate[{a[t], b[t], c[t]} /.         NDSolve[          {a'[t] == -k1f*a[t] + k1r*b[t],           b'[t] == k1f*a[t] - k1r*b[t] - k2f*b[t],           c'[t] == k2f*b[t],           a[0] == a0,           b[0] == 0.0,           c[0] == 0.0},          {a, b, c}, {t, 0, 1500}, MaxSteps -> 1000, AccuracyGoal -> 10]],       {t, 0, 1500}, PlotRange -> {{0, 1500}, {0, 0.11}},        AxesLabel -> {"Time (Seconds)", "Concentration"},       PlotStyle -> {{Red, Thickness[0.008]}, {Green,           Thickness[0.008]}, {Blue, Thickness[0.008]}}],      {{k1f, 0.01, Subscript[k, 1]}, 0, 0.02},      {{k1r, 0.01, Subscript[k, -1]}, 0, 0.02},      {{k2f, 0.01, Subscript[k, 2]}, 0, 0.02},      {{a0, 0.1, Subscript[a, init]}, 0, .2}]      All I want is to rename my equations `(a'[t], b'[t], c'[t])` in the first argument of `NDSolve` to a nickname, eqns, to simplify looking at them when they aren't the dummy 3 equations but are my real 150 equations, instead. But `eqns = {a'[t] == -k1f*a[t] + k1r*b[t], ...` as is done in the first argument of `NDSolve` above, followed by `NDSolve[z,{a, b, c}, etc.] returns a ridiculous number of errors. Where am I going wrong? _**Answered!_** For those of you still confused after reading the original question's answer (linked above), please see the comments for a short answer as to how to address my scenario specifically.


title: Manipulate gives the output as a blank plot, but I'm not sure why

text: I'm using Mathematica 9 to try to manipulate a 3D plot. My code is:               Clear[f, α, n]     n = 0;     f = (1/Pi)*(-1)^n*Exp[-2*H/h]*LaguerreL[n, 4 H/h] - (2/3)*α*     p^3*D[(1/Pi)*(-1)^n*Exp[-2*H/h]*LaguerreL[n, 4 H/h], p,      p] - (1/3)*α*p^2*     D[(1/Pi)*(-1)^n*Exp[-2*H/h]*LaguerreL[n, 4 H/h],      p] + (1/2)*α^2*((39/9)*p^4*       D[(1/Pi)*(-1)^n*Exp[-2*H/h]*LaguerreL[n, 4 H/h], p, p] + (28/9)*       p^5*D[(1/Pi)*(-1)^n*Exp[-2*H/h]*LaguerreL[n, 4 H/h], p, p,         p] + (4/9)*p^6*       D[(1/Pi)*(-1)^n*Exp[-2*H/h]*LaguerreL[n, 4 H/h], p, p, p,         p] + (6/9)*p^3*       D[(1/Pi)*(-1)^n*Exp[-2*H/h]*LaguerreL[n, 4 H/h], p])     Manipulate[Plot3D[f, {x, -10, 10}, {p, -10, 10}, PlotPoints -> 200, PlotRange -> All], {α, 0, 1, 1}]      where $h=1$ and $H=\frac{1}{2}(x^2+p^2)$. This, however, just gives a blank plot. ![enter image description here](http://i.stack.imgur.com/a3x8j.png) Evaluating the function manually, I find that it is equal to: $\frac{e^{-p^2-x^2}}{\pi }-\frac{1}{3} 2 \alpha p^3 \left(\frac{4 p^2 e^{-p^2-x^2}}{\pi }-\frac{2 e^{-p^2-x^2}}{\pi }\right)+\frac{2 \alpha p^3 e^{-p^2-x^2}}{3 \pi }+\frac{1}{2} \alpha ^2 \left(\frac{13}{3} p^4 \left(\frac{4 p^2 e^{-p^2-x^2}}{\pi }-\frac{2 e^{-p^2-x^2}}{\pi }\right)-\frac{4 p^4 e^{-p^2-x^2}}{3 \pi }+\frac{4}{9} p^6 \left(-\frac{48 p^2 e^{-p^2-x^2}}{\pi }+\frac{12 e^{-p^2-x^2}}{\pi }+\frac{16 p^4 e^{-p^2-x^2}}{\pi }\right)+\frac{28}{9} p^5 \left(\frac{12 p e^{-p^2-x^2}}{\pi }-\frac{8 p^3 e^{-p^2-x^2}}{\pi }\right)\right)$ In Manipulate, if I manually replace f with this function, I get exactly what I want.               Manipulate[ Plot3D[E^(-p^2 - x^2)/π -    2/3 p^3 (-((2 E^(-p^2 - x^2))/π) + (       4 E^(-p^2 - x^2) p^2)/π) α + (   2 E^(-p^2 - x^2) p^3 α)/(3 π) + 1/2 (13/3 p^4 (-((2 E^(-p^2 - x^2))/π) + (         4 E^(-p^2 - x^2) p^2)/π) +        28/9 p^5 ((12 E^(-p^2 - x^2) p)/π - (         8 E^(-p^2 - x^2) p^3)/π) +        4/9 p^6 ((12 E^(-p^2 - x^2))/π - (         48 E^(-p^2 - x^2) p^2)/π + (         16 E^(-p^2 - x^2) p^4)/π) - (4 E^(-p^2 - x^2) p^4)/(      3 π)) α^2, {x, -10, 10}, {p, -10, 10},   PlotPoints -> 200, PlotRange -> All], {α, 0, 1, 1}]      ![enter image description here](http://i.stack.imgur.com/3rAuy.png) Does anyone know why this difference occurs? How would I bypass this so that my first piece of code will work, that is, without having to manually input f i.e. get my second image as an output using my first piece of code? My goal is to be able to have Manipulate control the values of both n and $\alpha$. Thanks


title: Manipulate and ListPlot

text: I have a $300$ by $2$ matrix called `r` which its elements depend on parameter `g`. I would like to plot this matrix and change the `g` to see how the graph changes. I have used this code:               Manipulate[ListPlot[r], {g, 0, 10}]       However, nothing happens. If I determine the parameter `g`, then I can plot it with `ListPlot[r]`. But, when I use manipulate, I cannot plot it. Any suggestion? Thank you in advance.


title: Scoping problem with Manipulate

text: Consider the following simple code:               f = Sin[a x];     Manipulate[       Plot[f, {x, 0, 10}],        {a, 0, 10}]      Manipulate takes `f` to be a variable which has no value. I tried to evaluate `f` as follows:                Manipulate[        Plot[Evaluate @ f, {x, 0, 10}],         {a, 0, 10}]      but now I still have a problem with the scope of `a`. I know one way to do what I want, which is to define `f` as a function of `a` as follows:               f[a_] := Sin[a x];     Manipulate[       Plot[f[a], {x, 0, 10}],        {a, 0, 10}]      But what if I have many variables and I want to manipulate over all of them? Is there any way to make `Manipulate` substitute `f` by its value and take all of its symbols as a variables to be manipulated?


title: Manipulate and global assignments

text: I've a (perhaps too) basic questions that has been bugging me for a while. Manipulate seems to ignore global assignments. For instance the following does not result in the obvious output one would expect:               a = x*b;     Manipulate[Plot[a, {x, 0, 1}], {b, 1, 2}].      Instead, to had a 45 degree line, one had to redefine the a object within manipulation:               Manipulate[x*b;Plot[a, {x, 0, 1}], {b, 1, 2}].      Is there a way to have `Manipulate` to use the global assignment `a=x*b`? Thanks!!


title: Efficient JSON parser for Mathematica

text: Im looking for a efficient way of parsing JSON data in _Mathematica_. I am having a lot of problems with `ImportString` because it uses Java, is too slow, and uses too much memory (and, also, sometimes it just returns Null). Do you know how to write a function for JSON parsing in _Mathematica_ , or how to use any C/C++ (or other efficient) library from _Mathematica_?


title: How do I define the domain of a function?

text: I have a function of two variables, `f[x_, y_]`, and I would like to restrict the domain to values of `x` and `y` greater than zero. How do I do this? I also want to plot the function for restricted values. I have tried to use `RegionFunction -> Function[{x, y}, ...]`, but this doesn't work.


title: Arbitrary depth patterns/rules

text: _Temporary message: I am now really confused. I am not sure how using Power and Unevaluated together works in the examples below._ While answering this question, I stumbled upon the following. We have               Power[Unevaluated[       Power[Power[Power[Power[Power[Times[1, a1], a2], a3], a4], a5],         a6]], a7]      -> Power[Power[Power[Power[Power[Power[a1,a2],a3],a4],a5],a6],a7] Where there seems to be some rule involving deeply nested patterns at work (correct me if I'm wrong). Compare this with               Power[Unevaluated[       Power[Power[Power[Power[Power[Times[2, a1], a2], a3], a4], a5],         a6]], a7]      -> Power[Unevaluated[Power[Power[Power[Power[Power[Times[2,a1],a2],a3],a4],a5],a6]],a7] Where nothing happens. Note also that               a2 = 3;     Power[Unevaluated[Power[Times[2, a1], a2]], a3]      -> Power[Unevaluated[Power[Times[2, a1], a2]], a3] But that               Clear[a1, a2];     a1 = 3;     Power[Unevaluated[Power[Times[2, a1], a2]], a3]      -> Power[Power[6,a2],a3] **Most importantly** , note that               Clear[a1, a2, a3, f];     f[1] = 2;     Power[Unevaluated[Power[f[1], a2]], a3]      -> Power[Power[2,a2],a3] Whereas               Clear[a1, a2, a3, f];     f[] = 2;     Power[Unevaluated[Power[f[], a2]], a3] // FullForm      -> Power[Unevaluated[Power[f[],a2]],a3] We have               FullForm /@        Trace[Power[Unevaluated[Power[Power[Times[1, b], c], d]], e],         TraceOriginal -> True] // Column      ->               (*output*)     HoldForm[Power[Unevaluated[Power[Power[Times[1,b],c],d]],e]]     List[HoldForm[Power]]     List[HoldForm[e]]     HoldForm[Power[Power[Power[Times[1,b],c],d],e]]     HoldForm[Power[Power[Power[b,c],d],e]]     List[HoldForm[Power]]     List[HoldForm[Power[Power[b,c],d]]]     List[HoldForm[e]]     HoldForm[Power[Power[Power[b,c],d],e]]      I am not sure if what to conclude from this. Note that               Power[Hold[Times[1, 2]], 2] // FullForm      -> Power[Hold[Times[1,2]],2] so that Times is of course not cleared if there is a function with attribute HoldAll surrounding it. Note that the test functions below also depend on this. **Not so important: Tools** The following are tools to play with larger expressions like this               (*warning! might clear unexpected variables!*)     Clear @@ Names["arg*" | "a" | "b"]          SetAttributes[holderToken, HoldAll];     tester = And[First[#] == {}, Length[#[[2]]] == kkkk + 1,          Last[#] == {}] &;     headFinder =       Function[        ReplaceAll[         Unevaluated@Unevaluated@           Cases[            #,            head, Infinity, Heads -> True            ]         ,         {{head -> Unevaluated}, {head -> Power}, {head -> Times}}          ]        ];          expression :=       With[{compoWithHeldArg =          Unevaluated @@           (            DeleteCases[             Hold@              Evaluate[(Composition @@                       Array[With[{argu = Symbol["arg" <> ToString[#]]},                      Function @@ {argu, Power[argu, a[#]]}] &, kkkk])[                holderToken[Times[1, b]]]]             ,             holderToken, Infinity, Heads -> True             ]            )         }        ,             Power[compoWithHeldArg, a[0]]             ];      We then have               kkkk = 12;     tester@headFinder@expression      -> True and               kkkk=12;     expression // FullForm      -> Power[Power[Power[Power[Power[Power[Power[Power[Power[Power[Power[Power[Power[b,a[12]],a[11]],a[10]],a[9]],a[8]],a[7]],a[6]],a[5]],a[4]],a[3]],a[2]],a[1]],a[0]] and we see that                    Unevaluated @@           (            DeleteCases[             Hold@              Evaluate[(Composition @@                       Array[With[{argu = Symbol["arg" <> ToString[#]]},                      Function @@ {argu, Power[argu, a[#]]}] &, kkkk])[                holderToken[Times[1, b]]]]             ,             holderToken, Infinity, Heads -> True             ]            )//FullForm      -> Unevaluated[Power[Power[Power[Power[Power[Power[Power[Power[Power[Power[Power[Power[Times[1,b],a[12]],a[11]],a[10]],a[9]],a[8]],a[7]],a[6]],a[5]],a[4]],a[3]],a[2]],a[1]]] Where the Times is still present. So indeed applying Power[#,2]& to the expression above clears the Times. **Deep pattern** If we don't want to make any replacements, but just a deep pattern, we can recursively define a pattern as follows               Clear[patt];     patt = (_?AtomQ) | f[x_ /; MatchQ[x, patt]];      We then have               MatchQ[f[f[1]], patt]      (-> True) **A function that acts a bit like Power** Maybe something similar is going on with Power. That is, there is some pattern that searches in a deep way (maybe some kind of expressions that it can simplify), but the rule applied is trivial. I am confused and I thought the Times that was found was actually replaced by the same rule that (/whose pattern) found it. Now I am not sure if we should even speak of a rule in this case. I can make a function that works (at least a bit) like Power in very limited cases.               ClearAll[shortCondition]     SetAttributes[shortCondition, HoldAll]     shortCondition[x_] :=       MatchQ[Unevaluated[x],        HoldPattern[        Times[___, 1, ___] | power[xxxx_ /; shortCondition[xxxx], _]]]          ClearAll[power]     power[x_ /; shortCondition[x], n_] := power[x, n]      We then have               power[Unevaluated[power[Times[1, 2], e]], d]      -> power[power[2, e], d] -> power[2, 2] Whereas               power[Unevaluated[power[Times[2, 2], e]], d]      -> power[Unevaluated[power[Times[2, 2], e]], d] However, I think we should conclude from the Trace further above that Power works a little differently. **The new question is** : How can we simulate the behavior of Power, especially the aspect of it that seems to apply rules deeply in the expression that is one of its arguments. . . . . . **Old text, which seems to distract now** The more complicated problem of also making a non trivial replacement seems very difficult, but I'd still like to know if somebody knows if there is a way. If we also want to make a replacement , that makes things difficult. In the example in which f has a recursive pattern, we might want to replace the atom found by 0. In the example of power we might want to replace Times[a_ **,1,b_** ] by Times[a,b]. I think it is pretty unlikely that there is an elegant way of doing things. I had some hope that there would be a way make replacements in a general way, as I believed Power might work in this way. Now I don't think Power works in this way, but I still curious. As a small remark, not that we of course have               MatchQ[f[f[1]], (___f)[1]]      -> False and               MatchQ[Unevaluated[Sequence[f, f, f][1]], ___[1]]      Repeated and PatternSequence also seemed like they were maybe the way to go. But maybe not. **The question was** : Is it possible to define a rule in such a way that it determines whether an expression is of the form               f[___, f[___, ...[f[___, x_head ,___]] ,___], ___]      where the ...[] means that f is applied an arbitrary number of times in this way, and "do something with x on the RHS"? To clarify, we might want to define something like               f[___, f[___, ...[f[___, x_Integer ,___]] ,___], ___]:= x      Or in case of power               power[power[z...[Times[1,x_]],y_],z1_]:=power[power[z[x],y],z1]      where I have given the pattern of "repetitively applying power" the name z. A way of writing this in that might be parseable by Mathematica could be               z...power[Times[1,x_],y_]:=z[x,y]      Possibly the answer is: maybe in version 13. But any feedback is welcome :)


title: How make f[{x,y}] evaluate as f[x,y]?

text: I frequently encounter the situation where I have a function of two real variables defined, e.g.:               f[x_, y_] := 9 - x^2 - y^2      But then I need to feed into `f` not just two numbers but rather a pair, i.e., a 2-element list, e.g.:               p = {3, 4};     f[p]      How might this be done simply -- _without_ having to make a separate definition               f[{x_, y_}] := f[x, y]       Naively I used to expect that the following would work:               f[Sequence[p]]      But it doesn't. What does work, though, is:               f[Sequence @@ p]      Are there other, simpler techniques? I bring this up as an advocate for relatively new users of _Mathematica_ , because I think `Sequence` along with `Apply` is much too sophisticated for them! Note: The root cause is the typical "abuse of notation" in math, where a "function of two real variables" is really a function of ordered pairs of reals but the notation $f(x, y)$ obscures that.


title: How does FindShortestTour work?

text: How are `FindShortestTour` and the algorithms therewithin implemented internally? Also: Can I access some form of incremental, in-progress result during evaluation? _(e.g.: PCB autorouting)_ ![enter image description here](http://i.stack.imgur.com/74boo.png)


title: Using a variable for two different purposes

text: I want to name a bunch of tables after the OEIS entries which describe them. Is there any way to use these names for both the table name and the link at the same time? The second line uses the entry number as a variable: could I use the hyperlink in its place? This would allow clicking the link to reference the documentation from any place the file is referenced.               lcm[n_] := Module[{a = 1}, For[b = n, b > 1, b--, a = LCM[a, b]]; a]     A002944 = Table[lcm[n]/n, {n, 1, 15}]     Hyperlink["A002944", "http://oeis.org/A002944"]     Hyperlink[A002944[[1 ;; 6]], "http://oeis.org/A002944"]        **Edit** The last line displays the first few characters of the sequence, so I can click it to see more.


title: Is there an open source implementation of Mathematica-the-language?

text: I've seen questions before such as "What is the best open-source equivalent for Mathematica?", but that specific question (and that line of inquiry in general) cares more about the computer algebra system and less about the core language and its unique and powerful features. My interest in Mathematica come from a slightly different angle--namely, I find a tremendous amount of value in the power and flexibility of the _language_ that Mathematica implements (I think of it as a slightly less scary looking syntax for Lisp with some very novel additions such as the powerful pattern matching system). **Are there any projects that have made a concerted effort to build a Mathematica-the-language work-alike instead of focusing on the Computer Algebra System?** Mathics is the closest project I've found so far (since it does, in fact, try to stay faithful to Mathematica syntax where it can), but even it pitches itself as a computer algebra system. And it was written in Python, which isn't bad by itself, but it sets itself up to not be as fast as Mathematica for computationally intensive tasks. It seems to me that Wolfram Research would actually benefit tremendously from having an even bigger programmer community around Mathematica as a language and developer platform, because more packages would be produced to solve more off-the-shelf programming problems (just like almost any other programming language). An open (or at least freely available) implementation of the core programming language wouldn't even dilute their secret sauce which I would say primarily lies in Mathematica's base of mathematical rules and algorithms, in the scientific computing tools that they've bundled into one enormous and broad package, and into the insanely well-integrated notebook experience that they should have no trouble keeping ahead of any kind of open source project.


title: How to take conjugate of a function?

text: Naïvely this is what happens and it obviously is not helpful!               In[7]:= Conjugate[SphericalHarmonicY[1, 1, θ, ϕ]]          Out[7]= -(1/2) E^(-I Conjugate[ϕ]) Sqrt[3/(2 π)] Conjugate[Sin[θ]]      So I tried stating initially that $\theta$ and $\phi$ are reals - but still that doesn't seem to have helped any bit,                In[8]:= θ ∈ Reals; ϕ ∈ Reals;             In[9]:= SphericalHarmonicY[1, 1, θ, ϕ]            Out[9]= -(1/2) E^(I ϕ) Sqrt[3/(2 π)] Sin[θ]            In[10]:= Conjugate[SphericalHarmonicY[1, 1, θ, ϕ]]            Out[10]= -(1/2) E^(-I Conjugate[ϕ]) Sqrt[3/(2 π)] Conjugate[Sin[θ]]      Kindly tell me how to do this? (...I want to calculate sums like $\sum\limits_{m=-\ell}^{\ell}\vert Y_{l,m} (\theta,\phi)\vert^2$...)


title: Is there anything like a C pointer (or returning a reference) in $Mathematica$?

text: I want to do in _Mathematica_ what the following does in C.               int array[7] = {0, 0, 0, 0, 0, 0, 0};          int& foo(size_t idx)     {         return array[idx];     }          foo(4) = 43;          // array should now be {0, 0, 0, 0, 43, 0, 0}      In other words, I'd like to use `=` to assign to a reference (to some variable outside the scope of the function) returned by a function. I did read a few threads about references, but it seemed I'd have to "overload" the `=` operator (if that's even possible) to make things work. * * * ### Background I wouldn't be surprised if such practice were discouraged in _Mathematica_ , but would still appreciate the knowledge, as well as alternatives. My motivation for this is in trying to write a tool for non-programmers (or those with mostly C backgrounds but completely unfamiliar to _Mathematica_ ) for rapid testing of hypotheses, and the tool must be _intuitive, familiar, and easy to pick up_ (else I'm afraid my pitch to use _Mathematica_ wouldn't gain traction). To be more specific, the tool would analyze time-series data, the user specifying an expression to be run per time-step; and that expression would have "access" to a (pseudo-)array, say, `price`, such that `price[0]` refers to the _current_ price, `price[-1]` refers to the _previous_ price, etc.--so `price[0]` refers to a different price at each timestep. Of course C doesn't allow negative indexing; I just thought it'd be most intuitive that way--so my plan was to implement `price` as a function, and retrieve values from an array behind-the-scenes. You can probably see already where this is going: I'd also like for users to be able to _assign_ to `price[0]`, and that's where I'm stuck. I know I could (and perhaps _should_ ) just write a separate function like `set_price[0, val]`, but this would take away from the aesthetic goal I'm trying to achieve to win everyone over. I'm open to alternative ideas that may keep aesthetic though not in the same way.


title: Creating a 3D List Line Plot From Discrete Points

text: Given the following Runge-Kutta ODE solver and the graphical output below, how do I get a 3D line plot instead of a 3D point plot? I see that there is no ListLinePlot3D function, so I thought it might be possible to convert the tables of values T1, T2 and T3 into interpolating functions and then use the ParametricPlot3D function to plot the solution in its line form instead of point form. Currently though I'm having a little trouble with the interpolating function + ParametricPlot3D output, as I just get an empty box.               Remove["Global`*"]     (*dx/dt=*)f[t_, x_, y_, z_] := \[Sigma] (y - x);     (*dy/dt=*)g[t_, x_, y_, z_] := x (\[Rho] - z) - y;     (*dz/dt=*)p[t_, x_, y_, z_] := x y - \[Beta] z;     \[Sigma] = 10;     \[Rho] = 28;     \[Beta] = 8/3;     t[0] = 0;     x[0] = 1;     y[0] = 1;     z[0] = 1;     tmax = 2000;     h = 0.01;          Do[      {t[n] = t[0] + h n,            k1 = h f[t[n], x[n], y[n], z[n]];       l1 = h g[t[n], x[n], y[n], z[n]];       m1 = h p[t[n], x[n], y[n], z[n]];            k2 = h f[t[n] + h/2, x[n] +  k1/2, y[n] + l1/2, z[n] + m1/2];       l2 = h g[t[n] + h/2, x[n] +  k1/2, y[n] + l1/2, z[n] + m1/2];       m2 = h p[t[n] + h/2, x[n] + k1/2, y[n] + l1/2, z[n] + m1/2];            k3 = h f[t[n] + h/2, x[n] + k2/2, y[n] + l2/2, z[n] + m2/2];       l3 = h g[t[n] + h/2, x[n] + k2/2, y[n] + l2/2, z[n] + m2/2];       m3 = h p[t[n] + h/2, x[n] + k2/2, y[n] + l2/2, z[n] +  m2/2];            k4 = h f[t[n] + h, x[n] + k3, y[n] + l3, z[n] + m3];       l4 = h g[t[n] + h, x[n] + k3, y[n] + l3, z[n] + m3];       m4 = h p[t[n] + h, x[n] + k3, y[n] + l3, z[n] + m3];            x[n + 1] = x[n] + 1/6 (k1 + 2 k2 + 2 k3 + k4);       y[n + 1] = y[n] + 1/6 (l1 + 2 l2 + 2 l3 + l4);       z[n + 1] = z[n] + 1/6 (m1 + 2 m2 + 2 m3 + m4);       }, {n, 0, tmax}]          T1 = Table[{t[i], x[i]}, {i, 0, tmax}];     T2 = Table[{t[i], y[i]}, {i, 0, tmax}];     T3 = Table[{t[i], z[i]}, {i, 0, tmax}];          ListLinePlot[T1]     ListLinePlot[T2]     ListLinePlot[T3]          ListPointPlot3D[Table[{x[t], y[t], z[t]}, {t, 0, tmax}]]          I1 = Interpolation[T1]     I2 = Interpolation[T2]     I3 = Interpolation[T3]     ParametricPlot3D[{I1[t], I2[t], I3[t]}, {t, 0, tmax}]      What I'm looking to do is essentially get the following Lorenz Attractor point graph into a line graph form: ![enter image description here](http://i.stack.imgur.com/EJ4sb.png) Any help would be appreciated, thanks guys.


title: Will custom fonts in my notebook be carried over?

text: In my notebook, I have Open Sans (a free font) as a text font and Consolas (a paid font) as a code font. Those fonts are coded into the stylesheet of my notebook. My question is: if I send someone a copy of my notebook, will it be rendered in those fonts or will they become default Mathematica fonts (IIRC Arial and Courier--yuck!)?


title: Stacked Line Graph with fragmented data

text: Let's start with what I already found on the internet:               data = {{10, 4, 3, 0, 8, 8, 10, 8, 9, 10},              {2, 1, 2, 15, 5, 8, 7, 10, 9, 15},             {1, 4, 8, 1, 2, 8, 12, 10, 9, 15}};          ListLinePlot[Accumulate[data], Filling -> {1 -> {Axis, LightRed},          2 -> {{1}, LightOrange}, 3 -> {{2}, LightBlue}}, PlotStyle -> {Red, Orange, Blue}]      This one will produce a stacked graph like the one i want: ![enter image description here](http://i.stack.imgur.com/23Wnu.png) but the data I have is not directly usable like in this example because accumulate wouldn't work unless I process data in some way. * * * Let's say the data i have is something like this:               data = {      { {1, 10}, {3, 94.94}, {5, 41.52}, {10, 15.25}, {100, 2.19} },      { {4, 2.35}, {8, 10.64}, {12, 90.28}, {36, 50.74} },      { {2, 11.55}, {10, 15.65}, {20, 41.81} },      { {1, 20.13}, {3, 57.44}, {5, 42.74}, {10, 3.59}, {40, 2.05}, {100, 2.05} },      { {4, 13.74}, {20, 65.49}, {40, 112.62}, {80, 10.42} }};      If plot all together with a `ListLinePlot`, this is what I will get:               ListLinePlot[Table[data[[i]], {i, 1, Length[data] - 1}], Filling -> Axis]      Where each line is the junction of points for each set.. ![enter image description here](http://i.stack.imgur.com/4D477.png) I would like to obtain a stacked graph exactly with these lines. Could you help me to achieve this result? Best Regards PS: if possible would be cool see both cases where the values outside domains gives 0 contribute or the case were we continue using the same angular coefficient for the borders like in this image: ![enter image description here](http://i.stack.imgur.com/Z5S8K.png) With the functions gets anyways = 0 if value < 0 :)


title: Neumann boundary conditions in NDSolve over nontrivial region

text: The problem I would like to solve involves diffusion in the following region               reg = ImplicitRegion[-5 <= x <= 5 && -5 <= y <= 5 && x^2 + y^2 >= 1^2, {x, y}];     RegionPlot[reg, AspectRatio -> Automatic]      ![Region over which to solve PDE](http://i.stack.imgur.com/oYg6S.gif) Additionally, there is an interaction potential $v$ acting in this region:               v = Function[{x, y}, -E^(-x^2 - y^2)];     Plot3D[v[x, y], {x, -5, 5}, {y, -5, 5}, RegionFunction -> Function[{x, y, z}, x^2 + y^2 > 1^2], PlotRange -> {-1, 1}, PlotPoints -> 50]      ![plot of interaction potential](http://i.stack.imgur.com/AwIcF.gif) Physically, I would like to model 2D diffusion confined to this region, in the presence of the biasing potential given by $v$. So what I need to do is solve the PDE $\vec{\nabla} \cdot \left[\vec{\nabla}u(x,y) + u(x,y) \vec{\nabla}v(x,y)\right] = 0$ subject to the boundary conditions $u(x,-5) = 1$ $u(x,5) =0$ to impose an overall flux, and with zero-flux boundary conditions at the boundary where $x^2 + y^2 = 1$, (as well as on the sides where $x = \pm 5$). So I proceed as follows in Mathematica (10.0.0):               op = Div[Grad[u[x, y], {x, y}] + u[x, y] Grad[v[x, y], {x, y}],{x, y}];     bc = {DirichletCondition[u[x, y] == 1, y == -5],DirichletCondition[u[x, y] == 0, y == 5]};      Note that I did not specify boundary conditions for the circular boundary, nor for the sides $x = \pm 5$, because according to the NDSolve/NeumannValue documentation, these should default to zero-flux boundary conditions.               sol = NDSolve[{op == 0, bc}, u, {x, y} \[Element] reg, Method -> {"FiniteElement","MeshOptions" -> {MaxCellMeasure -> 0.005}}]      The solution looks like this:               Plot3D[Evaluate[u[x, y] /. sol], {x, y} \[Element] reg, PlotRange -> All, AxesLabel -> {"x", "y"}]      ![Solution of the PDE](http://i.stack.imgur.com/kpXug.gif) Now, this is not quite what I expected, for the following reason:if the PDE is solved correctly, with zero-flux boundary conditions, then the flux into the box (at y = -5) should equal the flux out of the box (at y = 5). You can sort of tell that this is not the case from the plot above, but plotting the normal derivative at the boundaries $y = \pm 5$ makes it clear:               Plot[{Evaluate[(Derivative[0, 1][u][x, 5] + u[x, 5] Derivative[0, 1][v][x, 5]) /.sol],     Evaluate[(Derivative[0, 1][u][x, -5] + u[x, -5] Derivative[0, 1][v][x, -5]) /. sol]}, {x, -5, 5}, PlotRange -> {-0.2, 0}]      ![normal derivatives](http://i.stack.imgur.com/RaMm4.gif) Integrating these will give the flux in and the flux out. Clearly the flux in is not equal to the flux out. Since I have checked to make sure that the PDE $\vec{\nabla} \cdot \left[\vec{\nabla}u(x,y) + u(x,y) \vec{\nabla}v(x,y)\right] = 0$ is obeyed in the interior of the region, it seems that I am not correctly setting the Neumann boundary condition at the circular boundary $x^2 + y^2 = 1$. The boundary condition that I _want_ is $\left[\vec{\nabla}u(x,y) + u(x,y) \vec{\nabla}v(x,y)\right] \cdot \vec{n} = 0$ but I _believe_ that the boundary condition that I'm _getting_ is simply $\left[\vec{\nabla}u(x,y)\right] \cdot \vec{n} = 0$ How can I impose the correct boundary condition? Have I misunderstood the documentation, which seems to say that my desired boundary condition is the default?


title: Why does the function Evaluate speed up one function by orders of magnitude and another function not at all?

text: I've got two functions, one sample function (function 1) i've created for demonstartion purposes here, and my actual function. The function Evaluate speeds up the sample function by orders of magnitude but it doesn't do anything with my actual function (function 2). Function 1:               a[x_] := x^2     g[b_, x_, y_, z_] := b a[x] + x y^2 + x z^2;     f[b_, y_, z_] := (buffer = Minimize[g[b, x, y, z], x];        xmin = x /. buffer[[2]];        g[b, xmin, y, z]);          start = SessionTime[];     Plot3D[f[2, y, z], {y, 0, 4}, {z, 0, 4 - y}, PlotPoints -> 3]     SessionTime[] - start          start = SessionTime[];     Plot3D[Evaluate@f[2, y, z], {y, 0, 4}, {z, 0, 4 - y}, PlotPoints -> 3]     SessionTime[] - start      First Plot:               start = SessionTime[];         Plot3D[f[2, y, z], {y, 0, 4}, {z, 0, 4 - y}, PlotPoints -> 3]         SessionTime[] - start      takes about 16 seconds. Second Plot:               start = SessionTime[];     Plot3D[Evaluate@f[2, y, z], {y, 0, 4}, {z, 0, 4 - y}, PlotPoints -> 3]     SessionTime[] - start      takes only 0.2 seconds. $$$$ $$$$ Function 2:               bindeaa[e0_] := e0;     c[e0_] := 40 e0;     bindeab[e0_] := 1.27 e0;          alpha[gamma_, p_, epsilon_] := p (gamma - epsilon);     beta[b_, epsilon_, n2_] := b epsilon^2 n2^(3/2);                    eisl[b_, e0_, g_, gamma_, p_, epsilon_, n2_, x_] :=        g c[e0] (epsilon)^2 - bindeaa[e0] +         e0 ((-2 Log[E^(1/2) x])/x^2 + alpha[gamma, p, epsilon]/x +            beta[b, epsilon, n2]/x^(3/2));          eislminx[b_, e0_, g_, gamma_, p_, epsilon_, n2_?NumericQ] :=       Module[{minxzwischen, minx,         x}, (minxzwischen =          FindMinimum[{eisl[b, e0, g, gamma, p, epsilon, n2, x],            0 < x }, x];        minx = x /. minxzwischen[[2]];        eisl[b, e0, g, gamma, p, epsilon, n2, minx])]           start=SessionTime[]      Plot[eislminx[10, 1, 0.7, 0.3, 4.9, 0.05, n2], {n2, 0, 10},       PlotPoints -> 3, PlotRange -> {-.93, -.82}]      SessionTime[] -start      Both Plots take the same time, about 3.2 seconds. Does anybody know why Evaluate speeds up function 1 but not function 2?


title: PolarPlot render oddities

text: I apologize if this is a obvious question and answer, I don't often use _Mathematica_ to display plots or graphics in general to be honest. So, I was tutoring my cousin yesterday in relation to Polar functions and decided to bring up _Mathematica_ to illustrate some of the ideas we were discussing. I quickly typed a one line command into _Mathematica_ 8 and got an odd result. When rendering a polar function, _Mathematica_ took a few seconds to make it smooth. Prior to this it has too many lines (see picture, before is on left and after is on the right.) The code is:               Manipulate[PolarPlot[Sin[nS*t], {t, -5 Pi, 5 Pi}], {nS, 1, 20, 1}]      ![Mathematica graphics](http://i.stack.imgur.com/muNQP.png) Does anyone know why this is happening and if there is a way to make Mathematica render smooth at first?


title: How to maintain a smooth surface in CDFs while playing?

text: I created a CDF for viewing the Möbius Band, and its generation. https://www.dropbox.com/s/e3af0xelbbqjfhd/Cinta_Moebious_Rafa.cdf But: 1.- When it´s PAUSED the surface is soft and you can see with quality. 2.- But when you are playing and move the segmente that generate Möbius Band, .... the band seems to be less quality, and you can see point-squares, instead a soft line in the border. ...as you can see: ![enter image description here](http://i.stack.imgur.com/yWkJ9.jpg) How can i do to maintain the surface .... soft!! Any option in SaveDefaults?.... to save more points??? \------------- This code is edited after cormullion message f[u_] = {2 Sin[u], 2 Cos[u], 0} g[u_] = {0, Sin[u/2], Cos[u/2]} Manipulate[ Show[ ParametricPlot3D[f[u] + v g[u], {v, -1, 1}, {u, 0, 2 Pi}, PlotRange -> {-3.2, 3.2}, Axes -> True, AxesLabel -> {x, y, z}, Mesh -> None, ExclusionsStyle -> {None, Red}, PlotStyle -> Directive[Green, Opacity[0.75`], Specularity[White, 20]], PerformanceGoal -> "Quality"],                 ParametricPlot3D[f[u] + v g[u], {v, -1, 1},         PlotRange -> {-3.2, 3.2}, Axes -> True, AxesLabel -> {x, y, z},         Mesh -> 1, MeshShading -> {Red, Blue}, PlotStyle -> Thick],         PerformanceGoal -> "Quality"], {u, 0, 2 \[Pi], Appearance -> "Open"},            Style[" En Verde vemos la famosa Cinta de Mobius", Darker@Green],       Style[" También vemos la barra que la genera, al ir girando su \       centro sobre el plano z=0, a la vez que la barra gira un ángulo de \      180º. Dicha barra la pintamos de dos colores para ver su \      orientación", Darker@Gray],      Style[" La Parte Azul=Parte positiva", Darker@Blue ],       Style[" La Parte Roja=Parte Negativa", Darker@Red],      Style["IMPORTANTE: Fijarse como la barra comienza cabeza arriba, \      pero, tras completar el movimineto de los 360º, llega cabeza abajo",        Darker@Orange],      Style["Creado y Diseñado por: Rafaorly@gmail.com", Darker@Blue],        SaveDefinitions -> True]      * * *


title: Plot using Manipulate or Animate

text: > **Possible Duplicate:**   >  PolarPlot render oddities When I use manipulate or animate function, the result shows a non-smooth plot. How to make the manipulate or animate commands show good and smooth plot?


title: Extracting the integers from a list

text: I have a list where the elements are Reals and Integers. How can I extract the Integer? For example, if I have `{1, 2, 3.4, 9.9}`, how can I get `{1, 2}`?


title: Documentation searches hang frequently: Anyone else dealing with this?

text: I've been struggling with a number of hangs, dynamic timeouts, and outright crashes when using the search/documentation center in version 9. I've tried uninstalling/reinstalling and clearing preferences/cache on start-up, praying for a paclet update---but nothing seems to help. One easily reproducible crash involves searching via the F1 key. On my machine (Windows 7, 64-bit), following the steps below, fails 100% of the time. (This is the simplest example I've taken the time to document; there seem to be many others.)   1. With a fresh session (not always reproducible with just a fresh kernel), type something in the front-end. This could be text (in a text cell) or input (in an input cell) such as: `something` (and leave it unevaluated---if in an input cell)   2. Now highlight that input and hit "F1" to perform a search. This will either return a dynamic timeout warning, or momentarily freeze the front-end and do nothing.   3. Now use your cursor to select `something` again and try "F1" a second time. This will perform the search as desired. _Can anyone reproduce this issue?_ **UPDATE 1:** Upgrading to 9.0.1 only partially addresses the issue. To illustrate, start a fresh session/kernel, type `something` and then hit F1 ( _without_ manually highlighting `something`). A similar hangup will occur. As Albert points out in his answer, this hangup does not seem to occur with F1 searches on built-in symbols, highlighted or not. Finally, FWIW, I suspect Albert's observation relates to another way I've encountered errors. Quite often when I come across some unfamiliar mathematical terminology on stackexchange, I reflexively copy and paste the term---from my browser, to the search field of the documentation center (which is almost always open when I'm working). Frequently this will generate the same type of error or worse. I suspect it has to do with whether or not the search term is either a built-in symbol or already indexed somehow. **UPDATE 2:** I recently decided to wipe my machine and reinstall everything from the OS up. Eventually I got around to installing Mathematica (from the exact same installer used previously). Much to my surprise, even without applying either of the two fixes, the hangups seem to be gone (or at least below what I can perceive). Just wanted to document this. Will report back if anything changes.


title: Simplifying fractions

text: What `ComplexityFunction` (or other technique) can I use to have Mathematica pull things out of fractions? I have a rational function of several variables and I'd like to have Math'ca simplify, e.g.,               x(... + y(... + wz)) + ...     --------------------------                 xyz      to               x(... + y(...)) + ....     ---------------------- + w               xyz      ? I've already told it that the relevant variables (in the denominator) are nonzero. I was thinking of counting complexity as `LeafCount` plus the `LeafCount` of numerators, but I'm not sure how to do that.


title: Solve Differential equation system

text: I've tried to solve this differential equation system, buy without any luck. ![enter image description here](http://i.stack.imgur.com/1VaGh.png) This is my code:               RSolve[{x'[t] == x[t] - y[t], y'[t] == 5 x[t] - 3 y[t], x[0] == 1, y[0] == 2}, {x[t],     y[t]}, t]      Can anyone tell me what I've done wrong?