title: Writing Fold in terms of Map or MapThread?

text: Consider               Fold[f,z,{a,b,c}]     ==> f[f[f[z,a],b,c]]      I'm looking for a way to write this (in general) using `Map` or `MapThread` (and perhaps `Flatten[#,1]&`, thinking of monadic `bind` a-la Haskell), and not using mutable variables. In other words, the following is too easy:               Module[{result = z},       Map[v \[Function]         result = f[result, v],        {a, b, c}]] // Last      and the following is not even wrong:               MapThread[f, {{z, f[z, a], f[f[z, a], b]}, {a, b, c}}] // Last      and the following is even more not even wrong (invoking Haskell's state monad); although it could be written recursively to be more general, the recursive form would just be a simulacrum of `Fold` with more functional garbage around the binding functions:               return[v_] := s \[Function] {v, s};     bind[m_, fv2m_] := s \[Function]       With[{vs0 = m[s]},         With[{          v0 = vs0[[1]],          s0 = vs0[[2]]},         fv2m[v0][s0]]]          bind[       bind[         bind[          return[z],          v \[Function] return[f[v, a]]],         v \[Function] return[f[v, b]]],        v \[Function] return[f[v, c]]][z] // First      I'm beginning to think that `Fold` is its own critter, kind of a state-monad- in-disguise, inherently recursive, and not representable by `Map` and friends, which are inherently iterative. But I haven't yet been able to prove that it's not possible, even though I haven't found a solution. Anyone happen to know? EDIT: the reason I'm looking for this is so I can build a reactive version around the Observable/Observer pattern, which is formally dual to the Iterable/Iterator pattern, and replaces `Map` with `Subscribe`, sort-of. I do not know a reactive partner to `Fold`, and that's the ultimate objective.


title: An easier way to find the properties of an ellipse from its equation?

text: In this Q&A about fitting an ellipse to a set of points, there are multiple answers that generated general equations of the ellipse, like this one by @ubpdqn: ![enter image description here](http://i.stack.imgur.com/MTLL1.png) However, the steps to find out the properties of the ellipse (namely, major axis, minor axis, center, and rotation) from its given equation seems pretty complicated. Therefore, my goal is to try finding these properties in a more intuitive way (if possible). Let's say I start with this general equation of a particular ellipse:               ellipse = -1.43328 - 0.281261 x + 0.00228797 x^2 - 0.832702 y +         0.00138781 x y + 0.00209387 y^2;     ContourPlot[ellipse == 0, {x, -500, 500}, {y, -500, 500}]      ![Mathematica graphics](http://i.stack.imgur.com/Ttgky.png) A way to find its properties is to start with a simple centered, axis-aligned ellipse with the general formula, where a and b represents the half-lengths of the ellipse' axes: $$\frac{x^2}{a^2}+\frac{y^2}{b^2}=1$$ The second step is to subtract the expression by 1 to convert our equation to the form expr=1 to expr=0, which is the way our general formula is written (see top of question). Then, this ellipse is rotated a certain degree, which means that each x and y in the equation is corrected with the rotation angle alpha [Ref], like so: $$x\to x \cos (\alpha )-y \sin (\alpha ),y\to x \sin (\alpha )+y \cos (\alpha )$$ This tilted ellipse is then brought off-center to make our original ellipse, which will transform x and y like so: $$x\to x-h,y\to y-k$$ where (h,k) represents the coordinate of the ellipse' center. This is the final formula as done via MMA: ellipseTransform =                Collect[#, {x,           y}] &@(x^2/a^2 + y^2/b^2 -            1 /. {x -> x Cos[\[Alpha]] - y Sin[\[Alpha]],            y -> x Sin[\[Alpha]] + y Cos[\[Alpha]]} /. {x -> x - h,           y -> y - k})      , which gives ![Mathematica graphics](http://i.stack.imgur.com/vfPPO.png) A plot of this formula confirms that this is indeed an ellipse               ContourPlot[(ellipseTransform /. {a -> 300, b -> 200, h -> 100,           k -> 50, \[Alpha] -> 30 \[Degree]}) == 0, {x, -500,        500}, {y, -500, 500}, Axes -> True]      ![Mathematica graphics](http://i.stack.imgur.com/LZLdB.png) As you can see the transformed equation of the simple ellipse now resembles the form of our given ellipse, which includes a constant term, an x term, y term, xy term, x^2 term, and y^2 term (6 terms) in total. My goal now is to somehow solve for a, b, h, k and alpha using the fact that these 2 expressions are basically equivalent. Now this is when I got stuck, as I've tried a few ways to equate these 2 expressions to look for what I want but to no avail: ![Mathematica graphics](http://i.stack.imgur.com/tKKKV.png) Another (perhaps related) problem is that there are 5 unknowns (a,b,h,k,apha) but 6 equations i.e. the 6 coefficients in my ellipse equation. I suppose this problem is more a mathematics one than of Mathematica but I'm wondering if there's any way to solve (or at least optimize) an overdefined set of equations.


title: Problem with boundary values for a partial differential equation

text: I have a PDE problem that I can't solve. and I wonder if you could help me with it. I have a Terzaghi Consolidation equation (similar to the heat equation) that is written as follows: $\frac{du}{dt}=c\frac{d^2u}{dt^2}$ $u$ is pore water pressure $z$ is depth $t$ is time $c$ is a constant pore water pressure is equal at all depth at $t = 0$, but it becomes $0$ at top and bottom directly after that. `u = u[z,t]` ($z$ is depth and $t$ is time) with boundary conditions as follows: `u[z, 0] = 100` ($u$ at all depth when $t = 0$) `u[2, t] = 0` ($u$ at top of the layer; in this case, $2$ is the height of the top layer) `u[0, t] = 0` ($u$ at bottom of the layer) I have solved this kind of problem before using a finite difference technique in a spread sheet, I wanted to find out whether _Mathematica_ can solve this problem directly, but unfortunately I failed. This is what I entered into _Mathematica_ :               NDSolve[{Derivative[0, 1][u][z ,t] == Derivative[2, 0][u][z, t],      u[0, t > 0] == 0, u[2,t > 0] == 0, u[2 > z > 0, 0] == 100}, u, {z, 0, 2},{t, 0, 100}]      Unfortunately, evaluating this expression leads gives the error: > DSolve::litarg: > > "To avoid possible ambiguity, the arguments of the dependent variable in > u[0,t>0]==0; should literally match the independent variables" I dont understand why I'm getting this message. I found a heat problem similar to this. I tried to use the that equation but changed the boundary problem, but that did not work. Can you help me detect which part of equation is wrong, and how I can fix the boundary values?


title: Any built-in function to generate successive sublists from a list?

text: Given               lst = {a, b, c, d}      I'd like to generate               {{a}, {a, b}, {a, b, c}, {a, b, c, d}}      but using built-in functions only, such as `Subsets`, `Partitions`, `Tuples`, `Permutations` or any other such command you can choose. But it has to be done only using built-in commands. You can use a pure function, if inside a built- in command, i.e. part of the command arguments. That is OK. It is of course trivial to do this by direct coding. One way can be               lst[[1 ;; #]] & /@ Range[Length[lst]]     (* {{a}, {a, b}, {a, b, c}, {a, b, c, d}}  *)      or even               LowerTriangularize[Table[lst, {i, Length[lst]}]] /. 0 -> Sequence @@ {}     (* {{a}, {a, b}, {a, b, c}, {a, b, c, d}}  *)      But I have the feeling there is a command to do this more directly as it looks like a common operation, but my limited search could not find one so far. Sorry in advance if this was asked before. Searching is hard for such general questions.


title: HorizontalGauge causes problem with ScalingFunctions -> "Log"

text: I am trying to use `HorizontalGauge[Dynamic[expt], {0.1, 100}, ScalingFunctions -> "Log"]`, i.e. a gauge with a logarithmic scale. This creates an error, a graph with a pink background. Monitoring the output with `Dynamic[expt]` and a second gauge `HorizontalGauge[Dynamic[expt], {0.1, 100}, ScalingFunctions -> None]` indicates that the logarithmic `HorizontalGauge` actually generates the expected output. Unless, somebody realizes a mistake in this rather simple code, I must assume this is a bug in Mathematica 9. **EDIT** Unluckily, this error has not been corrected in version 9.0.1               ... , ScalingFunctions -> {Exp, Log}      sort of works, but the locations of the tick marks are of course wrong. In the other order `{Log, Exp}` the error from above is reproduced. I reported this as an error.


title: ControlsRendering and operating systems

text: Controls, such as those appearing in `Manipulate` constructs, are by default rendered depending on the operating system. Wrapping everything in `Style[..., ControlsRendering->"Generic"]` makes sure that the controls' appearance is independent of the operating system (right?). My question now is split into three parts:   1. Does the rendering depend on the version of Mathematica es well? Specifically, is there a difference between versions 7, 8 and 9?   2. Is there a way to estimate how the controls will be rendered for another operating system? I.e. can I get a rough idea (I'm using Windows 7) how my `Manipulate` will look like on a machine with, e.g., Mac OS X 10.7? It would be enough for me to find out if any of the sizes of things like `Slider2D` or `SetterBar` objects change drastically. Does the `ImageSize` option for `Slider2D` ensure a consistent size even on different operating systems?   3. Can one define a function that makes sure that the default rendering is used on machines with windows, and the `"Generic"` style is used for non-Windows computers?


title: Can I use what "headerlines" removes from a CSV as TableHeadings for the table I create from that File?

text: I am reading in some data from a CSV file that has a line which gives titles to each "column". **Here is an example:**               Entry No,Val1,Val2,Val3,Val4     0,1.01,1.345,5.234,345.45     1,2.456,1.256,250.56,45.027      In reality this file has 20 or so values on each line, and therefore 20 column titles on the first line. I want to display this data in a table, so I first import the file and then display it like so:               dataSet1 = Take[Import["data_set_1.csv","CSV","HeaderLines"->1]]      TableForm[dataSet1]      I want to be able to manipulate and plot my data later so I am pretty sure I have to remove the line containing the labels using the "Headerlines->1" option. I would like the table to display the column titles that were on he first line of the CSV file. I know that I _could_ specify them manually, but I think there should be someway to do this because I deleted them the set using "HeaderLines"


title: Find the coefficients of a set of expressions in partial-derivatives

text: Is there a way to find the coefficients of these (terms within the square brackets) expressions using mathematica? \begin{align} \hat{l}^2=&\sum\limits_{a=1}^{4}\left[\left(\frac{\partial \chi_a}{\partial \theta_1}\right)^2+\frac{1}{sin^2\theta_1}\left(\frac{\partial \chi_a}{\partial \phi_1}\right)^2\right]\frac{\partial^2}{\partial \chi_a^2}+\\\ &\sum\limits_{a=1}^{4}\left[\frac{\partial^2 \chi_a}{\partial \theta^2_1}+\frac{1}{sin^2\theta_1}\frac{\partial^2 \chi_a}{\partial \phi_1^2}+cot\theta_1\frac{\partial \chi_a}{\partial \theta_1}\right]\frac{\partial}{\partial \chi_a}+\\\ & 2\mathop{\sum\sum}_{a>b=1}\left[\frac{\partial \chi_a}{\partial \theta_1}\frac{\partial \chi_b}{\partial \theta_1}+\frac{1}{sin^2\theta_1}\frac{\partial \chi_a}{\partial \phi_1}\frac{\partial \chi_b}{\partial \phi_1}\right]\frac{\partial^2}{\partial \chi_a\partial \chi_b} \end{align} where for $a=1,2,3,4\quad \chi_a$, refers to $\alpha,\beta,\gamma,\Theta_{12}$ and considering the following relations between $\alpha$, $\beta$, $\gamma$, $\Theta_{12}$ and $\theta_1$, $\theta_2$, $\phi_1$, $\phi_2$: $sin\Theta_{12}cos\beta=sin\theta_1sin\theta_2sin(\phi_2-\phi_1)$, $sin\Theta_{12}sin\beta sin\alpha= sin\theta_1sin\phi_1cos\theta_2- cos\theta_1sin\theta_2sin\phi_2$, $sin\Theta_{12}sin\beta cos\alpha= sin\theta_1cos\phi_1cos\theta_2- cos\theta_1sin\theta_2cos\phi_2$, $2sin\frac{\Theta_{12}}{2}cos\gamma= sin\theta_2cos(\phi_2-\alpha)-sin\theta_1cos(\phi_1-\alpha)$, $2sin\frac{\Theta_{12}}{2}sin\gamma= (cos\theta_2-cos\theta_1)sin\beta + [sin\theta_2 sin(\phi_2-\alpha)-sin\theta_1sin(\phi_1-\alpha)cos\beta$, $cos\Theta_{12}= cos\theta_1cos\theta_2+sin\theta_1sin\theta_2cos(\phi_1-\phi_2)$ As well as the relations between $\theta_1$, $\theta_2$, $\phi_1$, $\phi_2$\, and $\alpha$, $\beta$, $\gamma$ and $\Theta_{12}$: $cos\theta_1= -sin\beta cos(\gamma-\frac{\Theta_{12}}{2}),\\\ cos\theta_2= -sin\beta cos(\gamma+\frac{\Theta_{12}}{2}),$ $sin\theta_1cos\phi_1=cos\alpha sin(\gamma-\frac{\Theta_{12}}{2})+cos\beta sin\alpha cos(\gamma-\frac{\Theta_{12}}{2})$, $sin\theta_2cos\phi_2=cos\alpha sin(\gamma+\frac{\Theta_{12}}{2})+cos\beta sin\alpha cos(\gamma+\frac{\Theta_{12}}{2})$, $sin\theta_1sin\phi_1=sin\alpha sin(\gamma-\frac{\Theta_{12}}{2})-cos\beta cos\alpha cos(\gamma-\frac{\Theta_{12}}{2})$, $sin\theta_2sin\phi_2=sin\alpha sin(\gamma+\frac{\Theta_{12}}{2})-cos\beta cos\alpha cos(\gamma+\frac{\Theta_{12}}{2})$ For example, I know that the first coefficient is for $a=1$ $\frac{sin^2(\gamma+\frac{\Theta_{12}}{2})}{sin^2\Theta_{12}}$ for $\frac{\partial^2}{\partial\Theta^2}$ However, I don't exactly know how to obtain it, and of course the rest coefficients. If you can give me some hints for the first coefficient i'll find the other 13 for shure.


title: Quickly differentiate and evaluate a function of several variables

text: How can I differentiate a function with respect to several variables and evaluate it at the same time ? I want to specify also the variable index that I want to differentiate and the number of times I do it for each one.


title: How to control dependent PopupMenus?

text: I created three interdependent `PopupMenu`s with names `demographic`, `region` and `custom`:               DynamicModule[{demographic = "Demographic", region = "Region", custom = "Custom"},      Dynamic@Grid@{{          PopupMenu[Dynamic[demographic], {"Demo1", "Demo2", "Demo3"}, "Demographic"],          PopupMenu[Dynamic[region], {"Region1", "Region2", "Region3"}, "Region"],          PopupMenu[Dynamic[custom], {"Custom1", "Custom2", "Custom3"}, "Custom"]          }}]      ![enter image description here](http://i.stack.imgur.com/RtMnx.png) These controls should depend on each others' values. I want the followings:   1. `region` and `demographic` should be reset to `"Region"` and `"Demographic"` if any from `custom` is selected   2. `custom` should be reset to `"Custom"` if either `demographic` or `region` is changed I tried it with `If` and `Which` but it still won't work. How can I control these three `PopupMenu`s?


title: Option to change cursor/caret shape

text: While editing on a Mathematica notebook, I often find myself needing to do something else outside of Mathematica for a few hours. After finishing such outside tasks, I resume to work on the notebook. However, it is often difficult to find where the cursor/caret (text insertion point) is because blinking vertical bar is not visually prominent enough. Of course, I can set the cursor at an arbitrary location in the notebook by using mouse and clicking somewhere. The downside of this approach is that I lose context of my previous edits. After several hours, I still remember what I was editing generically, but I can't recall specific edits that I was making. Finding the cursor at the last position helps me to recall details of such specific edits. I want to make the cursor easier to find by making it visually more prominent such as blinking box or using different color. Is there such option? If the answer is yes, how can I set the option globally? Alternatively, can I highlight the current (physical) line? This would also make a point of last edit easy to locate.


title: How to get updates for Mathematica V10

text: As you know, _Mathematica_ V10 has just been released and I think a lot of updates will be released. However, I don't see any command in the help menu to update (which is present in most other software). How would we know if an update is available or not? I am using trial version of V10. ![enter image description here](http://i.stack.imgur.com/dTwd2.jpg)


title: What's the most "functional" way to do Cholesky decomposition?

text: I can do Cholesky in a procedural style, such as:               ProceduralCholesky[matrin_List?PositiveDefiniteMatrixQ] :=       Module[{dimens,        ll},       dimens = Length@matrin;       ll = ConstantArray[0, {dimens, dimens}];       Do[        Do[          If[i == j,            ll[[i, i]] =               Sqrt[matrin[[i, i]] -                 Sum[Conjugate[#]*# &@ll[[i, k]], {k, 1, i - 1}]];,            ll[[i,                j]] = (matrin[[i, j]] -                  Sum[ll[[i, k]]*Conjugate[ll[[j, k]]], {k, 1, j - 1}])/               Conjugate[ll[[j, j]]];];,          {i, j, dimens}];,        {j, dimens}];       ll       ]      Moreover, I've seen a "half-functional" implementation, which, however, features a `Table` function and an outer `For` loop. So far I have managed to address the need for the Table function by writing:               HalfFunctionalCholesky[matrin_List?PositiveDefiniteMatrixQ] :=       Module[{dimens,        uu},       dimens = Length@matrin;       uu = ConstantArray[0, {dimens, dimens}];       Do[uu[[i]] = makerow[matrin, i, uu, dimens], {i, dimens}];       uu       ]          makerow[matrin_List, rowindex_Integer, uu_, dimens_Integer] :=       PadLeft[       (Join[           {#},           offdiagonalelements[matrin, uu, rowindex, dimens, #]]) &@        diagonalelement[matrin, uu, rowindex],       dimens]          diagonalelement[matrin_, uu_, rowindex_] :=       Sqrt[matrin[[rowindex, rowindex]] - Conjugate[#].# &@        uu[[;; (rowindex- 1), rowindex]]]          offdiagonalelements[matrin_, uu_, rowindex_, dimens_,        diag_] := (matrin[[rowindex, (rowindex+ 1) ;; dimens]] -         Conjugate[           uu[[;; (rowindex - 1),             rowindex]]].uu[[;; (rowindex - 1), (rowindex + 1) ;;             dimens]])/diag      I am not satisfied yet. Can I avoid using the outer `Do` loop by turning it into a `Fold` or a `Nest`? The only idea I was able to come up with involved a `Nest`ed `ReplacePart` function, but I think it would be just some pretentious sweeping under the rug. Am I mistaken? Thank you in advance!


title: Extract a list of all built-in functions used in a notebook

text: I am writing my code documentation and need to list all the _Mathematica_ built in functions I have used - explicitly written functions only. Is there a way to extract a list of all built in functions that I have used in my code? For example               Insert[{a, b, c}, x, 3]     a=1     Style["this text",Bold]     Range[1,20]     b=3     a*b      I would require a list containing `Insert`, `Style` and `Range`.


title: How to get a solution involving logs in the right form?

text: How do I get               Solve[(1/9)^(r/2) == 1/n , r]       to give me                Log[n]/Log[3]      and not `-Log[1/n]/Log[3]`?


title: Change Style of Points

text: I was wondering if it's possible to change the style of a`Point` with another symbol e.g.: cross, x etc... It may sound weird-it is a Point after all, but I would like to have crosses instead of points in the following code                 Manipulate[Module[{data, inside, insidepts}, SeedRandom[n];       data = RandomReal[{-1, 1}, {m, 2}];       insidepts = Cases[data, {x_, y_} /; x^2 + y^2 < 1];       inside = Length[insidepts];       Text@        Style[         Column[          {Graphics[{PointSize[0.0001], Red, Disk[{0, 0}, 1], Blue,             Point[data]}, ImageSize -> If[format, 500, 350]],           Row[{"inside: ", inside, "\toutside: ", m - inside, "\ttotal: ",              m}],           Row[{"π=4 x ", inside, "/", m, " = ", 4. inside/m}]}], "Label"]],      {{n, 1, "random seed"}, 1, 1000, 1, Appearance -> "Labeled"},      {{m, 1, "sample size"}, 1, 100000, 1, Appearance -> "Labeled"},      {{format, False, "large format"}, {True, False}},      AutorunSequencing -> {1, 2}]


title: how to extract some terms out from an expression

text: I have an expression as below： > $-\frac{1}{2} A[a,v] A[b,h] A[c,v] A[d,h] \text{Cos}[\theta ]^2+\frac{1}{2} > A[a,h] A[b,v] A[c,v] A[d,h] \text{Cos}[\theta ]^2+\frac{1}{2} A[a,v] A[b,h] > A[c,h] A[d,v] \text{Cos}[\theta ]^2-\frac{1}{2} A[a,h] A[b,v] A[c,h] A[d,v] > \text{Cos}[\theta ]^2+\frac{1}{2} A[a,v]^2 A[b,h] A[d,h] \text{Cos}[\theta ] > \text{Sin}[\theta ]-\frac{1}{2} A[a,h] A[a,v] A[b,v] A[d,h] > \text{Cos}[\theta ] \text{Sin}[\theta ]+\frac{1}{2} A[b,v] A[c,h] A[c,v] > A[d,h] \text{Cos}[\theta ] \text{Sin}[\theta ]-\frac{1}{2} A[b,h] A[c,v]^2 > A[d,h] \text{Cos}[\theta ] \text{Sin}[\theta ]-\frac{1}{2} A[a,h] A[a,v] > A[b,h] A[d,v] \text{Cos}[\theta ] \text{Sin}[\theta ]+\frac{1}{2} A[a,h]^2 > A[b,v] A[d,v] \text{Cos}[\theta ] \text{Sin}[\theta ]-\frac{1}{2} A[b,v] > A[c,h]^2 A[d,v] \text{Cos}[\theta ] \text{Sin}[\theta ]+\frac{1}{2} A[b,h] > A[c,h] A[c,v] A[d,v] \text{Cos}[\theta ] \text{Sin}[\theta ]-\frac{1}{2} > A[a,v] A[b,v] A[c,h] A[d,h] \text{Sin}[\theta ]^2+\frac{1}{2} A[a,v] A[b,h] > A[c,v] A[d,h] \text{Sin}[\theta ]^2+\frac{1}{2} A[a,h] A[b,v] A[c,h] A[d,v] > \text{Sin}[\theta ]^2-\frac{1}{2} A[a,h] A[b,h] A[c,v] A[d,v] > \text{Sin}[\theta ]^2$ There are 16 terms here and every term has for function $A$. In some terms the first parameter of four function $A$ are different from each other( a,b,c,d), in the other terms the four first paramenter are partial overlap(a,a,b,d;...). how can I get the first kind. (the result is as below:) > $-\frac{1}{2} A[a,v] A[b,h] A[c,v] A[d,h] \text{Cos}[\theta ]^2+\frac{1}{2} > A[a,h] A[b,v] A[c,v] A[d,h] \text{Cos}[\theta ]^2+\frac{1}{2} A[a,v] A[b,h] > A[c,h] A[d,v] \text{Cos}[\theta ]^2-\frac{1}{2} A[a,h] A[b,v] A[c,h] A[d,v] > \text{Cos}[\theta ]^2-\frac{1}{2} A[a,v] A[b,v] A[c,h] A[d,h] > \text{Sin}[\theta ]^2+\frac{1}{2} A[a,v] A[b,h] A[c,v] A[d,h] > \text{Sin}[\theta ]^2+\frac{1}{2} A[a,h] A[b,v] A[c,h] A[d,v] > \text{Sin}[\theta ]^2-\frac{1}{2} A[a,h] A[b,h] A[c,v] A[d,v] > \text{Sin}[\theta ]^2$ this is the input form for our mma:                -(1/2) A[a, v] A[b, h] A[c, v] A[d, h] Cos[\[Theta]]^2 +       1/2 A[a, h] A[b, v] A[c, v] A[d, h] Cos[\[Theta]]^2 +       1/2 A[a, v] A[b, h] A[c, h] A[d, v] Cos[\[Theta]]^2 -       1/2 A[a, h] A[b, v] A[c, h] A[d, v] Cos[\[Theta]]^2 +       1/2 A[a, v]^2 A[b, h] A[d, h] Cos[\[Theta]] Sin[\[Theta]] -       1/2 A[a, h] A[a, v] A[b, v] A[d, h] Cos[\[Theta]] Sin[\[Theta]] +       1/2 A[b, v] A[c, h] A[c, v] A[d, h] Cos[\[Theta]] Sin[\[Theta]] -       1/2 A[b, h] A[c, v]^2 A[d, h] Cos[\[Theta]] Sin[\[Theta]] -       1/2 A[a, h] A[a, v] A[b, h] A[d, v] Cos[\[Theta]] Sin[\[Theta]] +       1/2 A[a, h]^2 A[b, v] A[d, v] Cos[\[Theta]] Sin[\[Theta]] -       1/2 A[b, v] A[c, h]^2 A[d, v] Cos[\[Theta]] Sin[\[Theta]] +       1/2 A[b, h] A[c, h] A[c, v] A[d, v] Cos[\[Theta]] Sin[\[Theta]] -       1/2 A[a, v] A[b, v] A[c, h] A[d, h] Sin[\[Theta]]^2 +       1/2 A[a, v] A[b, h] A[c, v] A[d, h] Sin[\[Theta]]^2 +       1/2 A[a, h] A[b, v] A[c, h] A[d, v] Sin[\[Theta]]^2 -       1/2 A[a, h] A[b, h] A[c, v] A[d, v] Sin[\[Theta]]^2


title: FeynRules vs FeynCalc (or anything else?)

text: I was looking for a Mathematica package that can take Lagrangians and calculate Feynman diagrams for any given n-point function. (..like if a software can draw and calculate arbitrary loop corrections to the Fermion correlation function in a theory..) Is FeynRules or FeynCalc capable of such?   If yes how? Which is easier to use? If no, then are there other softwares?


title: Why does $Failed have attribute HoldAll?

text: Why does `$Failed` have attribute `HoldAll`? Are there typical situations where `$Failed` is returned as a head that must not evaluate further, or is this just a relic from Mathematica's early times?               In[1]:= Attributes[$Failed]     Out[1]= {HoldAll, Protected}


title: How can I solve a difference-differential equation?

text: How do I ask _Mathematica_ to try to solve a recursive relation that defines a sequence of functions? For example, suppose I know that $g_n(x) = g_{n-1}'(x)$ for $n > 0$ and that $g_0(x) = e^{2x}$. How can I ask _Mathematica_ to find a closed form for $g_n(x)$? (This is just a placeholder equation to highlight my question; I know the answer of $g_n(x) = 2^n e^{2x}$, $n\geq 0$.) A less trivial instance of the problem would be the Hermite polynomial recursion, $$H_{n+1}(x) = 2xH_n(x) - H_n'(x)$$ I don't see how to convince either `DSolve` or `RSolve` to solve it for me. `DSolve` is unhappy because $n-1$ is used on the RHS:               DSolve[{g[n, x] == 2*D[g[n - 1, x], x]}, g, {n, x}]      `RSolve` just echoes my input:               RSolve[{g[n, x] == 2*D[g[n - 1, x], x], g[0, x] == Exp[2*x]}, g, {n, x}]      I know finding a closed-form solution is going to be hopeless in most instances, but it seems like some cases like the above $g_n(x)$ should be doable. I have been unable to find any examples in the _Mathematica_ documentation addressing this type of problem.


title: Is there a function that, given a fraction, will return the general term of its infinite series expansion?

text: Is here some way to expand a fraction to an infinite sum in mathematica, i.e., a series? I want the general term of the series. For example, $\frac{2}{3(x-1)^3}$


title: Problem with WordBoundary in string patterns

text: I am trying to extract from a string all words that end with "-man", but the problem is that `WordBoundary` does not seem to work as it returns whole string ignoring actual word boundaries. Here is the code:               mystring = "I am a big fan of Superman, Spiderman and Batman.";     StringCases[mystring, WordBoundary ~~ __ ~~ "man"];


title: Same Mathematica 9.1 Student License on both Ubuntu and Windows 7

text: Is it possible to install Mathematica 9.1 on both Ubuntu 12.04.3 LTS and Windows 7 Home Premium on the same machine. I want to be able to use Mathematica on Ubuntu since I wrote some numerical codes there. I would like to know if this is possible and a GUI is present in UNIX operating systems. Thanks


title: Solution of Non-Linear Equations using Simulation

text: How I can solve these five non-liner equations where `n=3`, `x=1,3,8` (e.g), and `a,b,c, Alpha` and `Beta` should be estimated.               x = {1, 3, 8}; n = Length[x]; eqn1 = n*D[Beta[a, b], a]/Beta[a, b] -      alpha*c*Sum[x[[i]]^(-beta), {i, 1, n}] == 0;  eqn2 = Sum[Log[1 - Exp[-alpha*c*x[[i]]^(-beta)]], {i, 1, n}] - n*D[Beta[a, b], b]/Beta[a, b] == 0; eqn3 = n/c - alpha*a*Sum[x[[i]]^(-beta), {i, 1, n}] + alpha*(b - 1)*Sum[(x[[i]]^(-beta)*Exp[alpha*c*x[[i]]^(-beta)])/(1 - Exp[-alpha*c*x[[i]]^(-beta)]), {i, 1, n}] == 0; eqn4 = n/alpha - c*a*Sum[x[[i]]^(-beta), {i, 1, n}] + c*(b - 1)*Sum[(x[[i]]^(-beta)*Exp[-alpha*c*x[[i]]^(-beta)])/(1 - Exp[-alpha*c*x[[i]]^(-beta)]), {i, 1, n}] == 0; eqn5 = n/beta - Sum[Log[x[[i]]], {i, 1, n}] + alpha*a*c*Sum[Log[x]*x[[i]]^(-beta), {i, 1, n}] + alpha*beta*c*(b - 1)*Sum[(x[[i]]^(-beta)*Exp[-alpha*c*x[[i]]^(-beta)])/(1 - Exp[-alpha*c*x[[i]]^(-beta)]), {i, 1, n}] == 0; FindRoot[{eqn1, eqn2, eqn3, eqn4, eqn5}, {{a, 0.1}, {b, 0.1}, {c, 0.1}, {alpha, 0.1}, {beta, 0.1}}]      This is not working, and not sure {a,0.1} etc 0.1 is the initial value.


title: Implementation of the Vector Autoregressive Model

text: I need to code/write a Vector Autoregressive Model VAR(p) as a function of the parameters. There is no estimation, nor Data involved, this is a "population" exercise: Assume X and Y are univariate, scalar random variables. I need to write the two following time-series models: [Model 1] $\quad X_{t} = \sum_{j=1}^{p}a_{j}X_{t-j} + u1_{t,}, \quad\quad\quad\quad\quad\quad$ where $\;\mathbb{E}[u1_{t}]=0, \; Var[u1_{t}]=\Sigma1$ [Model 2] $\quad X_{t} = \sum_{j=1}^{p}b_{j}X_{t-j} + \sum_{j=1}^{p}c_{j}Y_{t-j} + u2_{t}, \quad$ where $\; \mathbb{E}[u2_{t}]=0, \; Var[u2_{t}]=\Sigma2$ In the first model, X only depends only on it's own past, while in the second model X depends on both the past of X and the past of Y. EXAMPLE: if $p=2$ these models become [Model 1] $\quad X_{t} = a_{1}X_{t-1} + a_{2}X_{t-2}+ u1_{t,}$ [Model 2] $\quad X_{t} = b_{1}X_{t-1} + b_{2}X_{t-2} + c_{1}Y_{t-1} + c_{2}Y_{t-2} + u2_{t}$ I need to do this in symbolic terms so that I can compute a population measure of Granger Causality: $C_{Y \to X} = \frac{1}{2}\; \log\frac{\det \Sigma_{1}}{\det \Sigma_{2}}$ $\quad\quad\;\, = \frac{1}{2}\; \log\frac{Var(X_{t}) - Cov(X_{t},Z_{t})Var(Z_{t})^{-1}Cov(Z_{t},X_{t})}{Var(X_{t}) - Cov(X_{t},\tilde{Z}_{t})Var(\tilde{Z}_{t})^{-1}Cov(\tilde{Z}_{t},X_{t})}$ where $\;\;Z_{t} := [X_{t-1},..., X_{t-p}]'$ (vector that has the past X's) and $\quad\quad\quad\tilde{Z}_{t}:= [X_{t-1},..., X_{t-p}, Y_{t-1},..., Y_{t-p} ]'$ (vector that has the past X's and Y's) MY OBJECTIVE: code $C_{Y \to X}$ as a function of the parameters $p$ and $a,b,c$ so that I can show how it changes for different values of the parameters. (There is no data, no simulation of data either) NOTE: for people familiar with OLS (Ordinary Least Squares), this is a similar idea to doing population OLS: $\beta = \frac{Cov(X,Y)}{Var(X)}$ where $Y = \alpha + \beta X + \epsilon $, no estimation involved. Do you have ideas how to start ?


title: String pattern matching & replacement

text: I would like to find all occurrences of a full stop "." followed by a capital letter in a string and have these replaced with a "; ". How do I do this in Mathematica? e.g. `string="this is a test.A new sentence here"` -> output               "this is a test; A new sentence here"      Edit: and also one other pattern matching question - in a string I would like to have every other line occuring before a next line (\n) being deleted - how do I do that one? e.g.               string="this line should be deleted\nthis one not\nbut this one should be deleted too\nthis one not"      -> output               "this one not\nthis one not"


title: How to Normalise / Normalize eigenvectors?

text: I have a matrix and am trying to find the normalised eigenvectors of it. I am using the Eigensystem command and am getting a result. There is a normalize command, but as far as I can see this involves applying it to each vector individually. Is there by any chance an option that anyone has come across so that Mathematica does this automatically? Many thanks!


title: Connection between Mathematica Connector/J and XAMPP MySQL Database

text: I have been fiddling around with a problem for a while now, and hope you can help me. Have searched for previous solutions, but nothing seems to work. My problem is as follows: I have _XAMPP_ installed on my _Mac_ , as I use it as a localhost for some webpages. One day I got the idea that I wanted to connect _Mathematica_ to the _MySQL_ database, such that I could pull some data from the database, and work with it. I have tried, following the documentation, and write:               Needs["DatabaseLink`"];     JDBCDrivers["MySQL(Connector/J)"]      > > >>     JDBCDriver["Name" -> "MySQL(Connector/J)", >>      "Driver" -> "com.mysql.jdbc.Driver", "Protocol" -> "jdbc:mysql://", "Version" -> 2., >>      "Description" -> "MySQL using Connector/J - Version 5.1.13 - This supports all known >>          MySQL server versions.", "Location" -> "/Applications/Mathematica.app/ >>          SystemFiles/Links/DatabaseLink/DatabaseResources/mysql.m"] >>                 OpenSQLConnection[ JDBC["MySQL(Connector/J)", "localhost:3306/kbm"],                         "Username" -> "username", "Password" -> "*******"]      > > >>     During evaluation of In[6]:= JDBC::error: Communications link failure >>   >>     The last packet sent successfully to the server was 0 milliseconds ago. >>     The driver has not received any packets from the server. >> >>   >>     $Failed >>   I am certain that _MySQL_ listens on pot `3306`, I am certain that the database `"kbm"` exists, and I am certain that username and password is correct. So why doesn't it connect? I have with success connected to the _MySQL_ database through Terminal, and can conclude that it works. I have also read somewhere that sometimes replacing `"localhost"` by `127.0.0.1` works, but having tried that out, it still didn't work. Hope someone can help. **Edit** The config.inc.php file looks as follows:               /* Authentication type */     # commented out by xampp security     #$cfg['Servers'][$i]['auth_type'] = 'config';     $cfg['Servers'][$i]['auth_type'] = 'cookie';     $cfg['Servers'][$i]['user'] = 'root';     $cfg['Servers'][$i]['password'] = '';     /* Server parameters */     //$cfg['Servers'][$i]['host'] = 'localhost';     //$cfg['Servers'][$i]['connect_type'] = 'tcp';     $cfg['Servers'][$i]['compress'] = false;     /* Select mysql if your server does not have mysqli */     $cfg['Servers'][$i]['extension'] = 'mysqli';     $cfg['Servers'][$i]['AllowNoPassword'] = true;          /*     * phpMyAdmin configuration storage settings.     */          /* User used to manipulate with storage */     // $cfg['Servers'][$i]['controlhost'] = '';     $cfg['Servers'][$i]['controluser'] = 'pma';     # commented out by xampp security     #$cfg['Servers'][$i]['controlpass'] = '';     $cfg['Servers'][$i]['controlpass'] = '*******';      The rest is commented out.


title: Table of Variables

text: I use a list of variables `{x1, x2, x3}` to `Solve` a particular set of equations. I am now trying to generalise this depending on the number of equations. I need something along the lines of `Table[{"x" i}, {i,1,Length[equations]}]` which prints `{x1, x2, x3, x4,...}` etc. However, `"x" i` obviously does not work. Nor does `x[[i]]` as `{x[[1]], x[[2]], x[[3]]}` won't work in `Solve`. Any quick thoughts? Thank you.


title: Details of automatic cell-grouping w.r.t. cell-style

text: What determines how a specific cell-style influences grouping of cells? For example `"Text"` following `"Subtitle"` is grouped but not following `"Text"`               nbtitle = CreateDocument[];     NotebookWrite[nbtitle, Cell["subtitle", "Subtitle"]]     NotebookWrite[nbtitle, Cell["this text gets grouped", "Text"]]          nbtext = CreateDocument[];     NotebookWrite[nbtext, Cell["some text", "Text"]];     NotebookWrite[nbtext, Cell["this text is not grouped", "Text"]];      ![title](http://i.stack.imgur.com/j9Rid.png) * * * ![text](http://i.stack.imgur.com/Orxmu.png) All I can find in the documentation is: > Within a given notebook, there is always a collection of styles that can be > used to determine the appearance and behavior of cells. Typically the styles > are named so as to reflect what role cells which have them will play in the > notebook.


title: How to insert an expression in a Mathematica program?

text: I need to insert a very large expression in a _Mathematica_ program. So I first Put[large expression,"file"] and then use               Block[{}, Get["file"];...]      to implement the function. But the variables here is not local variables and may interact with other programs. I have tried to use               Module[{},Get["file"];...],      but it does not work. Do you know a clever way to do this?


title: (N)Solve does not solve equation

text: I am trying to calculate where a beam hits a mirror. The mirror is described by this curve (two facing spherical mirrors):               Mirror[x_] := Piecewise[{        {{Sin[-87.5 °] + 0.5, Cos[-87.5 °]}, x < 0},        {{Sin[-x ° - 87.5 °] + 0.5,           Cos[-x ° - 87.5 °]}, x >= 0 && x < 5},        {{Sin[x ° + 82.5 °] - 0.5,           Cos[x ° + 82.5 °]}, x >= 5 && x < 10}        }, {Sin[92.5 °] - 0.5, Cos[92.5 °]}]      Now, I am just trying to get the crossing point with a line:               p = {0, 0};     v = {1, 0};     Solve[Evaluate[       Simplify[Mirror[s].{1, 0}] == (p + v t).{1, 0} &&        Simplify[Mirror[s].{0, 1}] == (p + v t).{0, 1}        ], {s, t}]      The manual projection (.{1, 0}) is done because of the piecewise defined function, as they do not work with the usual Thread - we worked this out here. This code has been working well since then, but it does not for the current Mirror function. I have no idea what the problem could be. Any ideas?


title: RandomVariate returns values outside the support of a PDF

text: Let $X$ be a random variable with pdf:               dist = ProbabilityDistribution[1/(Abs[x]*Log[Abs[x]]^2), {x, -E^-2, E^-2}]      Here are some pseudo-random drawings from it:               data = RandomVariate[dist, 500000];      The domain of support for this random variable is:               {x, -E^-2, E^-2} // N     {x, -0.135335, 0.135335}      and all the generated data should lie within this domain of support. But, if I try something like:               Max[data]     0.15312      _Mathematica_ 9 returns a number which lies outside the domain of support. So, the _Mathematica_ random number generator is failing — it is generating values that lie outside the domain of support: i.e. not from this pdf. I reported this under version 8 to WRI, and again under version 9 pre-testing and since it is still here, I am beginning to wonder whether it is just me? Do others get this problem as well? I am running a Mac Pro with OS X 10.6.8


title: Exporting interpolating functions to excel

text: I have a question about exporting an InterpolatingFunction to excel. I checked the forum, but I still couldn't completely understand how to solve my problem. Could someone help me with this problem?               a = 10^-2;     eq1 = {hf'[t] == -a*(hf[t] - hs[t]),hs'[t] == a*(hf[t] - hs[t]), hf[0] == 20, hs[0] == 0};     sol1 = NDSolve[eq1, {hf, hs}, {t, 0, 100}]      The I got solution for `hf[t]` & `hs[t]` :               {{hf -> InterpolatingFunction[{{0.,100.}},<>],       hs -> InterpolatingFunction[{{0.,100.}},<>]}}      I'm wondering how I can export `hf[t]` & `hs[t]` values to excel as t ranges from 0 to 100.


title: How to construct pairs in a list?

text: I have an expression like this,                   input = x[1] x[2]^3 x[5]^2;      Fist step, we can get a list from the input expression,                   list0={x[1],x[2],x[2],x[2],x[5],x[5]};              list1 = {1, 2, 2, 2, 5, 5};      Second step, I want to get all possible pairs in a new list2. Namely, we divide Length[list1]/2 parts in list1 and combine the possible sublist in a new list. Of course, Length[list1]===Even.                  list2 = {{{1, 2}, {2, 2}, {5, 5}}, {{1, 2}, {2, 5}, {2, 5}} , {{1, 5}, {2, 2}, {2, 5}}};      Last step, we get the output expression,                  output = f[1, 2] f[2, 2] f[5, 5] + f[1, 2] f[2, 5]^2 + f[1, 5] f[2, 2] f[2, 5];      How can I transform the input expression into the output result? Can you show me a simple method that will work for the general problem as well as my example? In addition, we take another example,                   list1 = {1, 1, 2, 4};      the list2 should be                  list2 = {{1, 1}, {2, 4}}, {{1, 2}, {1, 4}};


title: Force Plot Area size to be equal excluding axes

text: I have two plots, both with the exact same formatting (frame, text style, etc.). One of them has 2-digit values for the y axes, the other has scientific notation because the value are large. In addition, they can have a different number of lines for the Axes labels. I set ImageSize->250, and the bounding boxes of the images (plots) are set to 250 pixels. Cool. Normally this is fine. However, when the two plots have different axes or labels, this results in: ![ImageSize->250. Bounding boxes of images are the same](http://i.stack.imgur.com/L60oj.png) What I want is the actual plot area to be the same, without manually adjusting ImageSize for the 2nd image: ![The Plot areas are the same size, but the bounding box for the entire image is different.](http://i.stack.imgur.com/kYDUM.png) Notice how the labels make the bounding box grow outward, but the plot area size is the same (also in width, just not shown). In this particular example, the right image has ImageSize->280. Does anyone know how to set the plot area size rather than the ImageSize? **EDIT 1:** @anononononomous mentioned a function to get the max padding size, and then apply it to each plot. This is getting closer! But it's clipping the FrameLabel: (Also, sorry for adding more data, it doesn't change the question though). ![anononononomous's solution](http://i.stack.imgur.com/jZMNO.png)


title: Efficient code for solve this equation

text: We have $a*b*c=-1$, $\frac{a^2}{c}+\frac{b}{c^2}=1$, $a^2 b+a c^2+b^2 c=t$ What's the value of $a^5 c+a b^5+b c^5$? I tried               Eliminate[{a b c == -1, a^2/c + b/c^2 == 1, a^2 b + b^2 c + c^2 a == t,        a b^5 + b c^5 + c a^5 == res}, {a, b, c}]      It's much slower than Maple's eliminate. How do I solve this efficiently?


title: How to evaluate this indefinite integrate $\csc(4x)\sin(x)$

text: I tried to integrate the following integral using `Integrate[Sin[x]Csc[4x],x]` and I am getting a strange result. $$\frac{1}{8 \sqrt{2}}\left(-2 i \text{ArcTan}\left[\frac{\text{Cos}\left[\frac{x}{2}\right]-\left(-1+\sqrt{2}\right) \text{Sin}\left[\frac{x}{2}\right]}{\left(1+\sqrt{2}\right) \text{Cos}\left[\frac{x}{2}\right]-\text{Sin}\left[\frac{x}{2}\right]}\right]-2 i \text{ArcTan}\left[\frac{\text{Cos}\left[\frac{x}{2}\right]-\left(1+\sqrt{2}\right) \text{Sin}\left[\frac{x}{2}\right]}{\left(-1+\sqrt{2}\right) \text{Cos}\left[\frac{x}{2}\right]-\text{Sin}\left[\frac{x}{2}\right]}\right]+2 \sqrt{2} \text{Log}\left[\text{Cos}\left[\frac{x}{2}\right]-\text{Sin}\left[\frac{x}{2}\right]\right]-2 \sqrt{2} \text{Log}\left[\text{Cos}\left[\frac{x}{2}\right]+\text{Sin}\left[\frac{x}{2}\right]\right]+2 \text{Log}\left[\sqrt{2}+2 \text{Sin}[x]\right]-\text{Log}\left[2-\sqrt{2} \text{Cos}[x]-\sqrt{2} \text{Sin}[x]\right]-\text{Log}\left[2+\sqrt{2} \text{Cos}[x]-\sqrt{2} \text{Sin}[x]\right]\right) $$ While the answer is `(1/8) Log[Sin[x] - 1] + (1/4) Sqrt[2] ArcTanh[Sin[x] Sqrt[2]] - (1/8) Log[1 + Sin[x]]` $$\frac{\text{ArcTanh}\left[\sqrt{2} \text{Sin}[x]\right]}{2 \sqrt{2}}+\frac{1}{8} \text{Log}[-1+\text{Sin}[x]]-\frac{1}{8} \text{Log}[1+\text{Sin}[x]] $$ Why am I getting this strange result? Are those two answers equivalent? How to avoid such strange results? Sorry if the question is inappropriate!


title: PDE combined with ODE 1D

text: I try to solve the following system of PDE coupled with ODE: $$\theta_t - a\theta_{xx} + b\kappa_a(\theta^4-\varphi)=0,$$ $$-\alpha\varphi_{xx} + \kappa_a(\varphi - \theta^4) = 0,$$ $$-a\theta_x + \beta\theta|_{x=0} = 0,\;\;a\theta_x + \beta\theta|_{x=L} = 0$$ $$-\alpha\varphi_x + \gamma\varphi|_{x=0} = 0,\;\;\alpha\varphi_x + \gamma\varphi|_{x=L} = 0$$ $$\theta|_{t=0} = \theta_0, \;\;\varphi_{t=0} = \varphi_0$$ for functions $\theta, \varphi$. I use the following code ($\zeta = \theta - \theta_s$, $\xi = \varphi - \varphi_s$ where $\theta_s, \varphi_s$ is the solution of the stationary problem):               s = NDSolve[{D[zeta[t, x], t] - a*D[zeta[t, x], x, x] +       b*kappaa*(((thetas[x] + zeta[t, x])^4 - thetas[x]^4) -          xi[t, x]) == 0,        -alpha*D[xi[t, x], x, x] +           kappaa*(xi[t, x] - ((thetas[x] + zeta[t, x])^4 - thetas[x]^4)) ==          0,        zeta[0, x] == zeta0[x], xi[0, x] == xi00[x],        -a*Derivative[0, 1][zeta][t, 0] + beta*zeta[t, 0] == 0,         a*Derivative[0, 1][zeta][t, ll] + beta*zeta[t, ll] == 0,        -alpha*Derivative[0, 1][xi][t, 0] + gamma*xi[t, 0] == 0,        alpha*Derivative[0, 1][xi][t, ll] + gamma*xi[t, ll] == 0},       {zeta, xi}, {x, 0, ll}, {t, 0, tt}]      The initial condition for $\theta$ is prescribed, the initial condition for $\varphi$ was computed. Wolfram Mathematica doesn't solve this system. How can I solve it?


title: Slider resistance and Play-Pausing with Manipulate, TabView, and attempt an granular TrackedSymbols?

text: Attempting to implement @Nasser's answer for How to avoid an expensive subset of a Manipulate computation when dependent variables have not changed?, using a `Manipulate` that includes a `TabView`, I wrote the following               Manipulate[tick;      TabView[{         "not continuous slider: b" -> Grid[{           {"b",            Manipulator[             Dynamic[b, {activeTab = 1 ; b = #; f = preCalculateStuff[b];                tick = Not[tick]} &], {0, 1, 0.01},             ContinuousAction -> False], Dynamic[b]}}]        , "Plot; continous slider: t" -> Grid[{           {"t",            Manipulator[             Dynamic[t, {activeTab = 2 ; t = #; tick = Not[tick]} &], {0,              1, 0.01}], Dynamic[t]},           {Row[{"f=", f, " b=", b, " t=", t}]},           {Plot[(f t) Sin[t + r], {r, 0, 2 Pi}, ImagePadding -> 30,             ImageSize -> 400, Frame -> True]}           }, Spacings -> {.5, .5}]        }, activeTab, Alignment -> Center]      , {{tick, False}, None}      , {{b, .4}, None}      , {{t, .7}, None}      , {{f, .5*.4}, None}      , {{activeTab, 1}, None}      , TrackedSymbols :> {tick}      , Initialization :> (preCalculateStuff[b_] :=         Module[{},(*heavy computation goes here*)0.5 b])]      This displays fine: ![tab B](http://i.stack.imgur.com/hM5ZF.jpg) ![tab T](http://i.stack.imgur.com/O3Ipl.jpg) I had an issue with `TabView` resetting to the first Tab after any Manipulator change, but solved that by adding the activeTab variable. Without a `TabView` (i.e. just a `Grid`) this works fine, but when I use the `TabView`:   * the slider that does not include `ContinuousAction -> False` will only slide by a small amount at a time.   * either slider automatically goes into "Pause" state if the `Play` arrow of the control is used. Nasser's sample that uses `Grid` handles Play without this pausing issue, so I'm thinking that the trouble is with something like a temporary change of Tab focus happening somewhere under the covers. EDIT: Note that one of my end goals was to have a fairly large set of control variables all in one tab (ones associated with preCalculateStuff), without cluttering up the rest. This is attempt to conform to the size restrictions imposed on wolfram demonstrations submissions. Here's an example of a TabView with the Manipulates distributed between them. This works fine, but doesn't use the Tick method that allows the change of the variables to act as callbacks as in Nasser's code:               Manipulate[      pts1 = p;      pltrng = {{-1, 1}, {-1, 1}};           pnts = LocatorPane[ Dynamic[p, {(pts1 = p; p = #) &, (p = #) &}],        Dynamic@Graphics[Point[p], PlotRange -> pltrng], LocatorAutoCreate -> True ];           slider = Grid[{ { "q", Manipulator[ Dynamic[q, {q = #} &] , {0, 1, 0.01} ], Dynamic[q] },         { "r", Manipulator[ Dynamic[r, {r = #} &] , {0, 1, 0.01} , ContinuousAction -> False ], Dynamic[r] } }] ;           tbl = Dynamic[ Grid[ { { (Table[              With[{i = i}, {i, Dynamic[pts1[[i]]]}], {i, Length@pts1}] // TableForm) , Dynamic[q] } } ]];           ln = Dynamic@Graphics[{Red, Thick, Line[pts1]}, PlotRange -> pltrng];           TabView[{ "table" -> tbl , "locators" -> pnts , "line" -> ln , "slider" -> slider }, Alignment -> Center]      , {{p, {{-.5, -0.5}, {-.25, .5}, {.6, 0.6}}}, None}      , {{q, 0.5}, None}      , {{r, 0.5}, None}      ]      (This is based on: http://mathematica.stackexchange.com/a/5515/10)


title: Do Mathematica notebooks include personal metadata?

text: I am about to send a Mathematica notebook to someone and I would like to make sure it does not contain any information that could personally identify me. I would also like to produce pdf files from the notebook and would like them to be metadata-free. Do I need to 'scrub' the file from some intrinsic metadata (as you would need to do, carefully, say, for an MS Word file), or do they generically not include any such information? If they do contain metadata,   * what can it be?   * where is it? and   * how can I scrub it?


title: Schedule programing problem with integer linear programming

text: I know how to model this question on paper, but I don't know how doing it in Mathematica. Imagine , there is a university student who want to choose courses for this semester and he got the university program chart that looks like below in excel format : ![University program chart](http://i.stack.imgur.com/uKNWP.png) Lecturers Rating is out of 10 and it means which lecturer is giving a better score in the final exam and teaches better. Course Credit is a restriction, each semester each student should choose courses that total of course credit must be greater than 7 and less than 12: ![](http://i.stack.imgur.com/Vk6QW.png) It is not allowed to pick two courses with the same name. He/She wants to optimize two things :   1. He/She wants to maximize course credits that he/she could use (12)   2. He/She wants to pick up courses with better Lecturers Also He/She wants to get the result like a schedule table like this: ![](http://i.stack.imgur.com/7MJWs.png) Here is excel File form university.


title: Image fading from one corner to the other

text: I'm preparing a presentation where I want to place a background image on each slide (for aesthetics). These are extremely color filled images (like photos; lets use "ExampleData/lena.tif" as example), which means that once they are the background, the text becomes hard to read. So, I wanted to have some fading, like white at the top left corner (my background is not white: {253,253,251}, which means that the background color is important to be an option), and then **fading in** in the direction of the bottom right corner. This fading should not change the color in itself (if you understand what I mean: not brighter, but more or less "transparent"). Transparent fading would be the best, since it would cover for whichever slide layout we have; but not sure how to pass it correctly to another program (using MS Powerpoint). It would be great to be able to change each extremity fade value (that is, not from 0 to 1 all the time), and to change direction. To change the fading function is a plus, but I think that not needed at this time (I mean: linear in the chosen direction, or power, or etc.)


title: Graphics3D: Finding intersection of 3d objects and lines

text: I found these two nice links 1) intersecting graphics 2) Implementation of Balaban's Line intersection algorithm in Mathematica which works for 2d. However, I need to find whether a ray(line) intersects with a 3d object (it can be the bounding box np) and count how many of the lines intersect with a particular object. **The code so far**               gr1 = Graphics3D[{         Green,          Polygon[{{-10, -15, 0}, {-10, 10, 0}, {10, 10, 0}, {10, -15, 0}}],         }];     gr2 = Graphics3D[{         Yellow, Cylinder[{{4, 0, 3}, {4, 0, 6}}],         Red, Sphere[{6, 5, 2}, 2],         Blue, Cuboid[{-2, -1, 0}, {2, 2, 2}],         Blue, Cuboid[{-6, -2, 0}, {-3, 2, 4}]         }];          grR = Graphics3D[        Line[{{0, -10, 2}, #}] & /@ RandomReal[{-5, 10}, {50, 3}]];     Show[gr1, gr2, grR]      ![the scene](http://i.stack.imgur.com/GCwve.png) **Question** What is an efficient way of finding intersections in 3d and counting based on the objects. **Some useful links for people who might be interested. In computer graphics the subject falls under 'Line clipping'**   * Line clipping   * Liang–Barsky algorithm   * Liang–Barsky algorithm 3d    * Liang–Barsky algorithm java   * Line Box Intersection c


title: How can I rewrite my code to make it simpler?

text: Two months ago,I written a function `IRobot` to caculate the $I_{xx},I_{yy},I_{zz}$ and $I_{xy},I_{xz},I_{yz}$,shown as below:                 IRobot[IStyle_String, ρ_, VaribleRange_List] := Module[        {IRobotResult},         IRobotResult =         Which[             IStyle == "xx", Integrate[ρ (y^2 + z^2),               {z, VaribleRange[[1, 1]], VaribleRange[[1, 2]]},                {y, VaribleRange[[2, 1]], VaribleRange[[2, 2]]},               {x, VaribleRange[[3, 1]], VaribleRange[[3, 2]]}],             IStyle == "yy", Integrate[ρ (x^2 + z^2),               {z, VaribleRange[[1, 1]], VaribleRange[[1, 2]]},                {y, VaribleRange[[2, 1]], VaribleRange[[2, 2]]},                {x, VaribleRange[[3, 1]], VaribleRange[[3, 2]]}],             IStyle == "zz", Integrate[ρ (x^2 + y^2),               {z, VaribleRange[[1, 1]], VaribleRange[[1, 2]]},               {y, VaribleRange[[2, 1]], VaribleRange[[2, 2]]},               {x, VaribleRange[[3, 1]], VaribleRange[[3, 2]]}],             IStyle == "xy", Integrate[ρ x y,                {z, VaribleRange[[1, 1]], VaribleRange[[1, 2]]},                {y, VaribleRange[[2, 1]], VaribleRange[[2, 2]]},                 {x, VaribleRange[[3, 1]], VaribleRange[[3, 2]]}],             IStyle == "xz", Integrate[ρ x z,                {z, VaribleRange[[1, 1]], VaribleRange[[1, 2]]},                 {y, VaribleRange[[2, 1]], VaribleRange[[2, 2]]},                {x, VaribleRange[[3, 1]], VaribleRange[[3, 2]]}],            IStyle == "yz", Integrate[ρ y z,                {z, VaribleRange[[1, 1]], VaribleRange[[1, 2]]},                 {y,VaribleRange[[2, 1]], VaribleRange[[2, 2]]},                {x,VaribleRange[[3, 1]], VaribleRange[[3, 2]]}]         ]       ]      And I can use it correctly.                IRobot["xx", ρ, {{-h1, 0}, {-r1, r1}, {-L1 - Sqrt[r1^2 - y^2], Sqrt[r1^2 - y^2]}}]      (*===>*)      1/12 h1 r1 (4 h1^2 (2 L1 + \[Pi] r1) + r1^2 (8 L1 + 3 \[Pi] r1)) ρ      However,I would like to simplify my code by `Similarity`,my trail as below:                Flatten /@Thread@List[{z, y, x},        Apply[Part[VaribleRange, ##] &, Table[{i, j}, {i, 1, 3}, {j, 1, 2}], {2}]]     (*==>*)      {{z, VaribleRange[[1, 1]], VaribleRange[[1, 2]]},       {y, VaribleRange[[2, 1]], VaribleRange[[2, 2]]},       {x, VaribleRange[[3, 1]], VaribleRange[[3, 2]]}}      ## Trial 1               IRobot[IStyle_String, ρ_, VaribleRange_List] := Module[        {IRobotResult,intlist},        intlist=         Flatten /@Thread@List[{z, y, x},        Apply[Part[VaribleRange, ##] &, Table[{i, j}, {i, 1, 3}, {j, 1, 2}], {2}]];         IRobotResult =         Which[             IStyle == "xx", Integrate[ρ (y^2 + z^2),intlist],             IStyle == "yy", Integrate[ρ (x^2 + z^2),intlist],             IStyle == "zz", Integrate[ρ (x^2 + y^2),intlist],             IStyle == "xy", Integrate[ρ x y,intlist],             IStyle == "xz", Integrate[ρ x z,intlist],             IStyle == "yz", Integrate[ρ y z,intlist]         ]       ]      Unfortunately,it failed. ## Trail2                IRobot[IStyle_String, ρ_, VaribleRange_List] := Module[        {IRobotResult,intlist},        intlist[z_,y_,x_,range_]:=         Flatten /@Thread@List[{z, y, x},        Apply[Part[range, ##] &, Table[{i, j}, {i, 1, 3}, {j, 1, 2}], {2}]];         IRobotResult =         Which[             IStyle == "xx", Integrate[ρ (y^2 + z^2),intlist[z,y,x,VaribleRange]],             IStyle == "yy", Integrate[ρ (x^2 + z^2),intlist[z,y,x,VaribleRange]],             IStyle == "zz", Integrate[ρ (x^2 + y^2),intlist[z,y,x,VaribleRange]],             IStyle == "xy", Integrate[ρ x y,intlist[z,y,x,VaribleRange]],             IStyle == "xz", Integrate[ρ x z,intlist[z,y,x,VaribleRange]],             IStyle == "yz", Integrate[ρ y z,intlist[z,y,x,VaribleRange]]         ]       ]      Also it ends in failure! ## Or I want to by                Which@@(      Flatten@{IStyle == #1, Integrate[ρ #2, intlist[z,y,x,VaribleRange]]} & @@@      {{"xx", (y^2 + z^2)}, {"yy", (x^2 + z^2)}, {"zz", (x^2 + y^2)},       {"xy", x y}, {"xz", x z}, {"yz", y z}})       (*==>*)      ![enter image description here](http://i.stack.imgur.com/oQTHi.png) to achieve                 Which[             IStyle == "xx", Integrate[ρ (y^2 + z^2),intlist[z,y,x,VaribleRange]],             IStyle == "yy", Integrate[ρ (x^2 + z^2),intlist[z,y,x,VaribleRange]],             IStyle == "zz", Integrate[ρ (x^2 + y^2),intlist[z,y,x,VaribleRange]],             IStyle == "xy", Integrate[ρ x y,intlist[z,y,x,VaribleRange]],             IStyle == "xz", Integrate[ρ x z,intlist[z,y,x,VaribleRange]],             IStyle == "yz", Integrate[ρ y z,intlist[z,y,x,VaribleRange]]         ]      **So my question is why and how to revise it.**


title: How to convert the following list into a LaTeX table?

text: How to convert the output of the following code               In[43]:= Func[x_]:=Select[Range[x],Total[IntegerDigits[#]^3]==#&];     Func[1000]      which is > Out[44]= {1,153,370,371,407} to the following form ![enter image description here](http://i.stack.imgur.com/qVtMN.png) such that I can copy it and paste to my LaTeX document without significant hassle. ## Edit I want the output of Mathematica to be consumable for LaTeX engine.               1^3 & 1\\     1^3+5^3+3^3 & 153\\     3^3+7^3+0^3 & 370\\     3^3+7^3+1^3 & 371\\     4^3+0^3+7^3 & 407\\


title: Having trouble assigning the result of a Solve to a function

text: Can anyone see what is wrong with my syntax? It looks like I have successfully assigned the result of Solve to a function. I want _Mathematica_ to return me an numeric value of the function `fc1`.               eq1 = (x - Subscript[c, 1])^2 + (Subscript[τ, c] +            Tan[Subscript[ϕ, LIN]] x)^2 == (Subscript[σ, SF] -            Subscript[c, 1])^2 + Subscript[τ, SF]^2;     eq2 = (x - Subscript[c,            1]) + (Subscript[τ, c] +             Tan[Subscript[ϕ, LIN]] x) Tan[Subscript[ϕ, LIN]] == 0;     sols = Solve[eq1 && eq2, {Subscript[c, 1], x}]          fc1[Subscript[τ, c] _, Subscript[ϕ, LIN] _, Subscript[σ, SF] _, Subscript[τ, SF] _] :=        Subscript[c, 1] /. sols[[1]][[1]]          ans = fc1[50, π/6*1.1, 1000, 800]     N[ans, 3]      ![enter image description here](http://i.stack.imgur.com/wVBWu.png)


title: How can I remove the bottom bar from Mathematica?

text: There is a bar with a zoom button on it, and it takes too much room. How can I disable it? Appreciate any help! Thank you!


title: How to make sure Table or Do only runs through specific values?

text: I often need to generate or run through very large numbers of integers (we're talking `{i, 1, 10^9}` and higher) and want to add certain integers to a list, say `list1`. So far what I've been doing is use the following structure:               list1 = {};     Do[If[PrimeQ[i] && Sort[IntegerDigits[i]] == Range[9], AppendTo[list1, i]], {i, 10^9}];     list1      (This is an example of a function that adds to `list1` only those values that are prime as well as pandigital from 1 to 9) Now I realise that this is probably a horribly inefficient way to generate lists. How can I ensure that my `Do` only runs through those functions which fulfil my criteria, e.g. being prime, or being divisible by 14, and so forth, and skips those which it doesn't need to run through - especially when I am running through 1 billion values for `i`? Is this even possible? Won't my function by definition have to run through every value anyway?


title: Finding all elements within a certain range in a sorted list

text: Suppose we have a sorted list of values. Let's use `list = Sort@RandomReal[1, 1000000];` for this example. I need a _fast_ function `window[list, {xmin, xmax}]` which will return all list elements $x$ for which $x_\textrm{min} \le x \le x_\textrm{max}$. How can this be implemented in _Mathematica_? I am looking both for _fast_ and for _elegant_ solutions. The direct solution is implementing binary search, but there are several ways to do this, and perhaps _Mathematica_ already has something built in that I am not aware of. * * * Here's the most naïve implementation:               window[list_, {xmin_, xmax_}] :=       list[[LengthWhile[list, # < xmin &] + 1 ;; LengthWhile[list, # <= xmax &]]]      * * * **Summary:** Here are the timings I get for the different solutions for some random data of a million machine reals which also contains duplicates:   * My original naive solution: 3.85 s   * Leonid, using binary search: 0.01 s (close to the measurable limit, $\log n$ complexity)   * R.M., using `Clip`: 0.59 s (linear time, no sorting required)   * faleichik, using `Nearest`: 1.29 s (strangely, this also runs in linear time, by measurement)   * kguler, using `Map` (which autocompiles) and `Pick`: 0.30 s (also linear time, the fastest simple linear time solution so far, does not require sorting either) For sorted data, the fastest solution is Leonid's, which uses binary search and has logarithmic complexity. For unsorted data, the fastest (and also one of the simplest) is kguler's. A not so obvious trick was using `Boole` on the condition to allow it to be automatically compiled.


title: How does NIntegrate evaluate a piecewise range of x,y?

text: Could someone explain to me how Mathematica evaluates the following integration.               NIntegrate[ ψ[x, y] mask[x,y],                  {x, 0, 25, 35, 65, 75, 100}, {y, 0, 25, 35, 65, 75, 100}]      How would this be expressed analytically?   `ψ` is non-zero and `mask` is zero in the `25 - 35` and `65 - 75` square region defined by               mask[x_, y_] := Piecewise[{{1 , y < 25}, {1, y > 75}, {1, x < 25},                                 {1, x > 75}, {1, 35 < y < 65 && 35 < x < 65}}, 0]      How would this be expressed analytically, and is it any different to               NIntegrate[ ψ[x, y] mask[x,y], {x, 0, 100}, {y, 0, 100}]       I don't have access to _Mathematica_ and am having discrepancies trying to port this to _Matlab_.


title: Computation of Hankel Transform using FFT (Fourier)

text: To address circular symmetric cases of 2D Fourier Transformations the so called Hankel Transform can be applied (for a detailed derivation of the relation between the 2D Fourier transform and the 1D Hankel transform see Link). For more complex or numerically tabulated radial functions, a numeric implementation of the Hankel transform (similiar to FFT) would come in handy.There has been an interesting proposal by Oppenheim from 1980 (full text is available on the Web), which explains the use of the highly optimized FFT algorithm to do the Hankel transform. Is anybody aware of such an implementation of the Hankel transform in Mathematica?


title: Opening new notebooks with a non-default window size

text: I'd like to set Mathematica (8.0.4.0) up so it opens new notebooks with the `"NaturalColor"` stylesheet and with a window size like {800,770}. I tried to change default stylesheet via:               " OptionInspector -> Global Preferences -> Global Options\File Locations\Default Style Definition "      and I get this ugly notebook instead of this one. And when I Change the value of `"WindowSize"` from `"Medium"` to `"{800,770}"` under `"Notebook Options\Window Properties"`, it just does nothing. This is driving me crazy, any ideas ?


title: How to manipulate web pages on Mathematica?

text: I wanted to input some data on this page through Mathematica: http://www.fundamentus.com.br/buscaavancada.php Then I would press the "buscar" button also through mathematica coding and get the results on mathematica. The most similar post i've found was this one: Web Browsing Automation with Mathematica I'm trying to import through the Import function:                   Import["http://www.fundamentus.com.br/buscaavancada.php", "Data"]      When i do that, it shows this:               {{{{"Página inicial", "Investimento consciente",      "Entre em contato"}, {"Detalhes", {"Balanço patrimonial",       "Demonstrativos de resultados",       "Indicadores fundamentalistas"}, {"Balanços em Excel",       "Proventos"},      "Histórico de cotações"}}, {{"Preencha apenas os campos que serão \     usados na pesquisa", "Use . (ponto) como separador decimal",      "Utilize o formato decimal para representar porcentagens. Ex: \     Para 15% digite 0.15"}, {{"? P/L (Preço sobre lucro)",       "min max"}, {"? P/VP (Preço sobre Valor Patrimonial)",       "min max"}, {"? PSR (Preço sobre Receita Líquida)",       "min max"} [...]      And from here i'm stuck. Any tips?


title: How to add big data into a CDF file, without it being loaded into memory

text: I have 1 GB of data that I would like to add to a CDF file, but I would like to avoid it being loaded into memory when someone opens the file (Free Player). One gigabyte of info takes a lot of computer memory, and the user of the file doesn't need to have it all in memory (specially when the way Mathematica or Player manages the opening of the file originates, for a couple of seconds, a double memory consumption which will go above a 32 bit process limit). So, this would work as something like a DB included in the CDF file. A dynamic structure interface will then allow the user of the CDF file to load only a part of the data into memory (`Set` a variable to a part of the total data).


title: Different colors for nodes in tree plot

text: I have some list of numbers which I am plotting using TreePlot. This is the code:               Plotting[S_, u_, d_, n_] :=        Module[{coor = Flatten[Table[Table[{i, j - 1 - i/2}, {j, 1, i + 1}], {i, 0, n}],            1],               steps = Flatten[Table[ Table[              {S*u^k*d^(l - k) -> S*u^k*d^(l - k + 1), S*u^k*d^(l - k) -> S*u^(k + 1)*d^(l - k)},                               {k, 0, l}], {l, 0, n - 1}]]},         TreePlot[steps, DirectedEdges -> True, VertexLabeling -> True,                  VertexCoordinateRules -> coor, PlotLabel -> S]];          Plotting[S, u, d, 4]      And now, i need some of the nodes to be painted in different color. For example dSu, Su^3 and d^4S. Is there a way to do it?


title: No values in plot

text: I am trying to plot the following function:               Plot[(0.014901060131333028` ((2 - 0.1` x)^2.5`)^2.5`)/((1 +          0.1` x Sin[Pi])^1.5`)[0.185903200617956`], {x, 0, 10}]      However, when I do I get nothing on graph. But if I plug in specific numbers then it is clear there is a value. Any help would be great


title: Using only two colors in a ListPlot3D

text: The data I have given here will plot the data in `ListPlot3D` function and gives the visualization of bars on the plot. I want to customize the color for the bars in the plot. I need to plot them in two colors — one for side of the bar and another for the top surface of the bar. How can I set the color function to achieve this?               finalData = {{14.38, 18.1, 70}, {14.385714285714286`, 54.`,      70}, {42.857142857142854`, 18.1`, 70}, {42.857142857142854`, 54.`,      70}, {14.385714285714286`, 54.1`, 20}, {14.385714285714286`,      90.`, 20}, {42.857142857142854`, 54.1`, 20}, {42.857142857142854`,      90.`, 20}, {14.385714285714286`, 90.1`,      15}, {14.385714285714286`, 126.`, 15}, {42.857142857142854`,      90.1`, 15}, {42.857142857142854`, 126.`,      15}, {14.385714285714286`, 126.1`, 25}, {14.385714285714286`,      162.`, 25}, {42.857142857142854`, 126.1`,      25}, {42.857142857142854`, 162.`, 25}, {14.385714285714286`,      162.1`, 30}, {14.385714285714286`, 180, 30}, {42.857142857142854`,      162.1`, 30}, {42.857142857142854`, 180,      30}, {42.957142857142856`, 18.1`, 14}, {42.957142857142856`, 54.`,      14}, {71.42857142857143`, 18.1`, 14}, {71.42857142857143`, 54.`,      14}, {42.957142857142856`, 54.1`, 60}, {42.957142857142856`, 90.`,      60}, {71.42857142857143`, 54.1`, 60}, {71.42857142857143`, 90.`,      60}, {42.957142857142856`, 90.1`, 14}, {42.957142857142856`,      126.`, 14}, {71.42857142857143`, 90.1`, 14}, {71.42857142857143`,      126.`, 14}, {42.957142857142856`, 126.1`,      24}, {42.957142857142856`, 162.`, 24}, {71.42857142857143`,      126.1`, 24}, {71.42857142857143`, 162.`,      24}, {42.957142857142856`, 162.1`, 34}, {42.957142857142856`, 180,      34}, {71.42857142857143`, 162.1`, 34}, {71.42857142857143`, 180,      34}, {71.52857142857142`, 18.1`, 18}, {71.52857142857142`, 54.`,      18}, {100.`, 18.1`, 18}, {100.`, 54.`, 18}, {71.52857142857142`,      54.1`, 28}, {71.52857142857142`, 90.`, 28}, {100.`, 54.1`,      28}, {100.`, 90.`, 28}, {71.52857142857142`, 90.1`,      23}, {71.52857142857142`, 126.`, 23}, {100.`, 90.1`, 23}, {100.`,      126.`, 23}, {71.52857142857142`, 126.1`, 33}, {71.52857142857142`,      162.`, 33}, {100.`, 126.1`, 33}, {100.`, 162.`,      33}, {71.52857142857142`, 162.1`, 38}, {71.52857142857142`, 180,      38}, {100.`, 162.1`, 38}, {100.`, 180, 38}, {100.1`, 18.1`,      12}, {100.1`, 54.`, 12}, {128.57142857142858`, 18.1`,      12}, {128.57142857142858`, 54.`, 12}, {100.1`, 54.1`,      22}, {100.1`, 90.`, 22}, {128.57142857142858`, 54.1`,      22}, {128.57142857142858`, 90.`, 22}, {100.1`, 90.1`,      17}, {100.1`, 126.`, 17}, {128.57142857142858`, 90.1`,      17}, {128.57142857142858`, 126.`, 17}, {100.1`, 126.1`,      27}, {100.1`, 162.`, 27}, {128.57142857142858`, 126.1`,      27}, {128.57142857142858`, 162.`, 27}, {100.1`, 162.1`,      32}, {100.1`, 180, 32}, {128.57142857142858`, 162.1`,      32}, {128.57142857142858`, 180, 32}, {128.67142857142858`, 18.1`,      16}, {128.67142857142858`, 54.`, 16}, {157.14285714285714`, 18.1`,      16}, {157.14285714285714`, 54.`, 16}, {128.67142857142858`,      54.1`, 26}, {128.67142857142858`, 90.`, 26}, {157.14285714285714`,      54.1`, 26}, {157.14285714285714`, 90.`,      26}, {128.67142857142858`, 90.1`, 21}, {128.67142857142858`,      126.`, 21}, {157.14285714285714`, 90.1`,      21}, {157.14285714285714`, 126.`, 21}, {128.67142857142858`,      126.1`, 31}, {128.67142857142858`, 162.`,      31}, {157.14285714285714`, 126.1`, 31}, {157.14285714285714`,      162.`, 31}, {128.67142857142858`, 162.1`,      36}, {128.67142857142858`, 180, 36}, {157.14285714285714`, 162.1`,      36}, {157.14285714285714`, 180, 36}, {157.24285714285713`, 18.1`,      20}, {157.24285714285713`, 54.`, 20}, {185.71428571428572`,      18.1`, 20}, {185.71428571428572`, 54.`, 20}, {157.24285714285713`,      54.1`, 90}, {157.24285714285713`, 90.`,      90}, {185.71428571428572`, 54.1`, 90}, {185.71428571428572`, 90.`,      90}, {157.24285714285713`, 90.1`, 25}, {157.24285714285713`,      126.`, 25}, {185.71428571428572`, 90.1`,      25}, {185.71428571428572`, 126.`, 25}, {157.24285714285713`,      126.1`, 35}, {157.24285714285713`, 162.`,      35}, {185.71428571428572`, 126.1`, 35}, {185.71428571428572`,      162.`, 35}, {157.24285714285713`, 162.1`,      40}, {157.24285714285713`, 180, 40}, {185.71428571428572`, 162.1`,      40}, {185.71428571428572`, 180, 40}};     ListPlot3D[finalData, Filling -> Bottom, RotationAction -> "Clip",AxesLabel -> {x, y, z}, PlotRange -> {{0, 200}, {0, 200}, {0, 100}}]


title: Troubleshooting an NDSolve::ndfdmc error message

text: Τhe following code               Ay[ξ_] := A0*(1 - κ^2)^.5*Exp[-(δ ξ - φ)^2/2] Sin[ξ]     Az[ξ_] := A0*κ*Exp[-(δ ξ - φ)^2/2] Cos[ξ]     Ay1[ξ_] := D[Ay[ξ], ξ]     Az1[ξ_] := D[Az[ξ], ξ]     j1 = DSolve[{y''[ξ] + r^2 y[ξ] == r/Δ (α2 - Az[ξ]) - 1/Δ Ay1[ξ],          z''[ξ] + r^2 z[ξ] == -1/Δ Az1[ξ] - r (α1 - Ay[ξ]), y[0] == yo,          y'[0] == Pyo/Δ, z[0] == zo, z'[0] == Pzo/Δ}, {y, z}, ξ]          Py[ξ_] := D[y[ξ] /. j1, ξ]     Pz[ξ_] := D[z[ξ] /. j1, ξ]     P1[ξ_] := Py[ξ]^2 + Pz[ξ]^2     A0 = 7; δ = 1/15; r = 1; φ = 5; κ = 1/Sqrt[2]; α1 = 0; α2 = 0; Δ = 1;      yo = 0; zo = 0; Pyo = 0; Pzo = 0;     j2 = NDSolve[{x'[ξ] == P1[ξ], x[0] == 0}, x[ξ], {ξ, 0, 1.6*2 π/δ}]      produces the message > NDSolve::ndfdmc: Computed derivatives do not have dimensionality consistent > with the initial conditions. >> How can I fix this so that I can plot `x[ξ]`?               Plot[x[ξ] /. j2, {ξ, 0, 1.6*2*π/δ},       PlotStyle -> Automatic, PlotRange -> All, AxesOrigin -> {0, 0}]


title: Why does Mathematica evaluate Sin[2.0] but not Sin[2]?

text: I can't understand why is it that               In[88]:= Sin[2]     Out[88]= Sin[2]      while               In[89]:= Sin[2.0]     Out[89]= 0.909297      I even tried               In[90]:= 2 + Sin[2]     Out[90]= 2 + Sin[2]      thinking that it might force the evaluation, but apparently not... Now, I know that I can just do this               In[91]:= N[Sin[2]]     Out[91]= 0.909297      but I am curious why doesn't just `Sin[2]` work. Even though the _Documentation Center_ page for `Sin[x]` contains _Possible Issues_ examples this behavior is not mentioned. I know from some experience with **Python** and **C** that expressing a integer number, e.g. **2** , as a rational number, i.e. **2.0** , can influence the way an expression is evaluated, e.g.               #Python code         >>> 5 / 2     2     >>> 5 / 2.0     2.5      Even though I personally don't agree with this behavior (I think there should be different operators for _integer division_ and _rational division_ since it will always cause some confusion) if you just see some examples it becomes clear what happens. Here I don't have any idea what **Mathematica** thinks when it sees `Sin[2]` _**Note_** :   * I'm using **Mathematica v7.0**   * I'm basically a beginner.   * I don't plan and have time to go through a tutorial, I just wanted to play around. I expected the simple/common things to behave intuitively enough.   * I also appreciate if you point me to some resources where this behavior is explained.


title: three-dimensional graphic objects that are not simple cuboids

text: I am trying to draw some graphics with _Mathematica_. The objects I want to draw are just a little bit more complex than a cuboid -- the difference being that the top and bottom faces are of different depth. Below are two examples of the objects I would like to draw.               p01 = RegionPlot3D[ y <= 1 - 0.5 z, {x, 0, 1}, {y, 0, 1}, {z, 0, 1},        Mesh -> None]          p02 = RegionPlot3D[        y <= 0.5 + 0.5 (z - 1), {x, 0, 1}, {y, 0, 1}, {z, 1, 2},        Mesh -> None]       It would be great if I could make these objects using 3-D graphics primitives found in _Mathematica_. Then I would be able to make 3-D graphics, placing the objects in relation to one another. Below is an example of what I would like to do, basically creating a set of these 6-faced objects and stacking them in relation to one another.               cubeA = Cuboid[{0, 0, 0}, {1, 0.5, 1}];          cubeB =  Cuboid[{0, 0, 1}, {1, 1, 2}];          Graphics3D[{cubeA, cubeB}]      The example above uses the built-in `Cuboid` object. The objects I would like to make are (only so slightly) more complex than this. I can create the geometry I am interested in with RegionPlot3D, but I cannot easily combine these. For example, the following fails:               Graphics3D[{p01, p02}]      I tried to do this with Polygon function, but couldn't quite determine how to extend the examples provided to making a 6-faced objects. Any recommendations or suggestions would be welcome. Thanks.


title: How can I use assumptions with FindRoot?

text: I have something like               FindRoot[f[x], {x, a}]      Now I want `FindRoot` to constrain the solutions to 0 < x < 1\. How can I obtain this?


title: Connected components of a graph

text: I am trying to find the number of connected components of numerous named graphs within Combinatorica. The obvious answer seems to be:               Length[GraphData[G,"ConnectedComponents"]]        but this fails. What am I doing wrong? Does this property only work when the number of connected components is >= 2?


title: Use of RegionFunction with Graphics3D?

text: I'd like to plot in 3D a long list of polygons created with `TetGenConvexHull`, but only in regions specified by a function. Is that possible? As I have it my `RegionFunction` only applies to some points, and not to my `Graphics3D` `Polygon` data:               Show[{ListPointPlot3D[{{-0.57735, 0., 0.8165}, {-0.866025, -0.5, 0.}},         RegionFunction ->          Function[{x, y, z},z <= .6],         BaseStyle -> {Black, PointSize[Large]}, AxesLabel -> {x,y,z},Boxed -> False,        AxesOrigin -> {0,0,0}, BoxRatios -> {1, 1, 1},        PlotRange -> {{-1, .1}, {-.6, .6}, {-.1, 1}}],       Graphics3D[{Opacity[0.34], EdgeForm[], Red,                  Polygon[{{-0.57735, 0., 0.8165}, {0., 0., 0.}, {-0.866025, -0.5, 0.}}]}],        Graphics3D[{Opacity[0.34], EdgeForm[], Blue,                  Polygon[{{-0.57735, 0., 0.8165}, {-0.866025, 0.5, 0.}, {0., 0., 0.}}]}]}]      ![Output from above code](http://i.stack.imgur.com/jV87o.jpg) Notice that `RegionFunction` clips the first datum in `ListPointPlot3D` ({-0.57735, 0., 0.8165}), but not the `Graphics3D` `Polygon` as I would like. I'd like the `Polygon` surfaces to be clipped/truncated wherever they intersect the `RegionFunction` ( _not_ for the surface to be omitted entirely, given a single intersection location/coordinate). Perhaps there is a way to transform `Polygon` data into `ListSurfacePlot3D` data, which can be utilized with `RegionFunction`... Note: I'm actually plotting a lot of complex polygons (not just 2 planes as in the code above), making me want to stick with `Polygon` and `Graphics3D`.


title: NumberForm and units

text: NumberForm can be used to print Quantities to a specified precision. For example,               x=Quantity[5.123456789,"Meters"];     5.12346 m     Print[NumberForm[x,{4,2}]]     5.12 m      This does exactly what I want, but it has an undesirable effect for units with exponents. For example,               y=Quantity[5.123456789,"Meters"/"Seconds"^2];     5.12346 m/s^2     Print[NumberForm[y,{4,2}]]     5.12 m/s^2.00      I'd like the precision specification to apply to the quantity, not to the units. Is there a way to do that?


title: Changing size and color of a Text on version 9

text: I am running v9 on mac pro and think that I am doing something wrong. When commenting the solution of a particular exercise I add a text cell (command 7) and type the comment which is nothing more than a sentence with some mathematical expressions (control ( - expression- control )). To change the size and color of the whole comment, I simply highlight it and Format - Size or Color - to the desired size and color. The change does not apply to whole comment! Why? (I think that is due to the expressions). For instance, if the comment is as follows > Here is an example, if $P = 1$ then the whole solution depends on the number > of ... the change applies up to $P = 1$. The rest of the sentence is unchanged. Many thanks Ed


title: Module vs DynamicModule for a dynamic variables in a grid. || Spelling Bee

text: When my daughter asked me help with her spelling homework, for me the obvious thing to do was to write a _Mathematica_ program for it. The words:               words = {"lightning", "thunder", "cloudy"};      The code:               Grid[      Module[{x = 0, t = 0},         {          #,          Button["Start", t = Hold@AbsoluteTime[] - AbsoluteTime[]],           Button[Style["\[Checkmark]", Darker@Green], t = ReleaseHold[t]; x++],          Button[Style[    "\[Times]",        Red  ], t = ReleaseHold[t]; x--],          Dynamic[x],          Dynamic[Clock[]; ReleaseHold[t]]          }         ] & /@ words]      Which produces this output: ![screenshot](http://i.stack.imgur.com/2cuWe.png) So when I ask her a word, I click "start". Then I click ✔ or × if her answer is right or wrong respectively. I plan to keep track of time to answer, so the timer now shows how much time it took to answer. So my question is: Why do I have to use `Module` instead of `DynamicModule`? For some reason the `Grid` command does not work if I use `DynamicModule`. On the other hand, if I use `Module` (as it is shown), then the syntax highlighter shows my "t" and "x" variables in red as if I am doing something wrong: ![enter image description here](http://i.stack.imgur.com/TFkw6.png) **Update:** I have just realized that using `Module` instead of `DynamicModule` is not a viable option as the scores are lost when you reopen the notebook. **Update 2:** For the record, this is the finished program incorporating the advice from Mr.Wizard and kguler               DynamicModule[{x, t, status, h},      x[_] = 0;      t[_] = 0;      status[_] = False;      h[_] = {};      Column[{Grid[         MapIndexed[{            #,            Button["Start",                    Speak@#; status[#2] = True;                    t[#2] = Hold@AbsoluteTime[] -AbsoluteTime[],                    Enabled -> Dynamic[! status[#2]]],            Button[Style["\[Checkmark]", Darker@Green],                    t[#2] = ReleaseHold[t[#2]]; x[#2]++; AppendTo[h[#2], t[#2]];                    status[#2] = False,                   Enabled -> Dynamic[status[#2]]],            Button[Style["\[Times]", Red],                   t[#2] = ReleaseHold[t[#2]]; x[#2]--; AppendTo[h[#2], -t[#2]];                   status[#2] = False,                    Enabled -> Dynamic[status[#2]]],            Button["spell", Speak@StringJoin[Riffle[Characters[#], ","]]],            Dynamic[x[#2]],            Dynamic[Clock[]; ReleaseHold[NumberForm[t[#2], 2]]],            Dynamic@             If[Length@h[#2] > 0,               Module[{z = Transpose[{Abs[#], Sign[#]} & /@ h[#2]]},                Graphics[                (Rectangle @@@                  (Partition[{Accumulate[First@z],Last@z}\[Transpose],2,1,{2,2},{{0, 0}}] /.                  {{x1_, y1_Integer}, {x2_, y2_Integer}} -> {{x1 + 0.2, 0}, {x2, y2}})) /.                  {Rectangle[{x1_,0}, {x2_, 1}] -> {Darker@Green, Rectangle[{x1, 0}, {x2, 1}]},                    Rectangle[{x1_,0}, {x2_,-1}] -> {Red, Rectangle[{x1,0}, {x2, -1}]}},                ImageSize -> {Automatic, 20},                 PlotRange -> {-1, 1}]],               ""             ]         } &, words],         Alignment -> Left],         Row[{Button[           "reset", (x[{#}] = 0; t[{#}] = 0; h[{#}] = {}) & /@             Range@Length@words], Spacer[10]}]}]]      ![enter image description here](http://i.stack.imgur.com/J6OWs.png)


title: What's the kernel launch command syntax?

text: I want to configure a remote kernel, but the box it'll run on doesn't have a fixed hostname or IP address. I can however get its IP address by running a shell script. (For the moment I'm only worrying about unix-oid systems: linux and MacOS -- I'll deal with windows later if I figure this out.) Now, it seems this ought to be easy: all I need to do is use the standard backquote syntax to insert the output of the script into the link command in the appropriate place. But apparently Mathematica is already using backquotes in some other way. This is the generic Launch command it configures: > `java` -jar "`mathssh`" leon@hostname math -mathlink -LinkMode Connect > -LinkProtocol TCPIP -LinkName "`linkname`" -LinkHost `ipaddress` You see it's got java, mathssh, linkname, and ipaddress enclosed in backquotes. But these are not executables (or if they are, they're nowhere I can find). So, either it's using backquotes for some internal variable substitution, or it installs executables with those names somewhere in the path before passing this command to a shell. How can I find out what (if anything) actually gets passed to a shell?


title: How to mark an image?

text: How can I place a mark, like a cross-hair (to suggest "X marks the spot") and a text label associated with it, at a particular position on an image (mine in particular is `Colorize`d)?


title: Why can't I use Sequence to perform a Select like task?

text: Suppose I wanted to write down a list of $p^2$, for $p$ a prime between $1$ and $20$. I would expect               Table[If[PrimeQ[k], k^2, Sequence[]], {k, 1, 20}]      to work. In fact, this produces,               {Null, 4, 9, Null, 25, Null, 49, Null, Null, Null, 121, Null, 169, Null, Null, Null, 289, Null, 361, Null}      Why does this happen, and is there a variant which does work the way I expect? Of course, I can just do               Map[(#^2) &, Select[Range[20], PrimeQ]]      I don't have a real reason to avoid this, but it feels less readable to me. UPDATE: Given the answers I'm seeing, I should point out that this is meant to be a toy example and the actual code involves boolean functions much messier than `PrimeQ[]`, for which there is no analogue of `Prime[]` available. But Szabolcs answer is exactly what I was looking for, thanks!


title: ListLogLinearPlot logarithmic axis tickmarks

text: When using `ListLogLinearPlot` the abscissa labels every other decade. Is there a way to tell Mathematica to label each decade? I need to use this inside `Manipulate` where the axes will scale according to the chosen variable. ![enter image description here](http://i.stack.imgur.com/hVtf4.jpg) Here is some example code of the kind I am using:               s[x_] := (10^-9) x^2; t[x_] := (10^-3) x^2;      Manipulate[ ListLogLinearPlot[{ Table[{a s[T], T}, {T, 0, 1000}],       Table[{a t[T], T}, {T, 0, 1000}] },       GridLines -> None, PlotStyle -> {Thickness[0.005]}, Joined -> True,       PlotRange -> Automatic], {a, 10^-8, 10^8}]


title: Is there a way to globally set when to treat a very small number as zero?

text: I understand that I can use `Chop` to force a very small number to be treated as `0` and can use `PossibleZeroQ` to as a way to test whether such a number might effectively be `0`, but applying `Chop` every time a small number is close to zero in order to "make it be" zero is tedious and error prone; while `PossibleZeroQ` seems to have its own ideas about what constitutes `0`. Are there global settings that will let me   * treat every number smaller than some specified value as `0`, effectively applying `Chop` automatically to all results; and   * specify how large a number `PossibleZeroQ` should recognize as `0`?


title: LinearSolveFunction unusable if stored to disk?

text: I encounter a problem when saving a `LinearSolveFunction` to disk, where the LinearSolveFunction is obtained with `LinearSolve` for a non-square matrix. If I read the function object from disk, it can no longer be applied to an array. For example:               In[1]:= a = LinearSolve[{{1, 0}, {0, 1}, {1, 0}}];     In[2]:= a >> "tst.m";     In[3]:= b = << "tst.m";      At this point, `a===b` and the displayed `FullForm` of a and b are equal. However:               In[4]:= a[{0, 0, 0}]     Out[4]= {0, 0}          In[5]:= b[{0, 0, 0}]     Out[5]= LinearSolveFunction[{3,2},{2,False,{{{1,0},{0,1},{1,0}}},{0,Automatic,Automatic},0}][{0,0,0}]      I am using Mathematica 8.0.4 (64bit) on Linux. Is this a bug ? Is there a good workaround ? Of course, I could avoid caching the `LinearSolve` result altogether and save only the matrix to be "inverted".


title: Generating date ranges

text: How can I, in one line, generate all the dates with a constant day difference from one date to another? For example, if I'm interested in dates in the interval staring from 24.4.2012 till 2015 and a 28 day difference.


title: Rounding problems inside InputField

text: Consider the following `InputField`               InputField[Dynamic[h2,       If[# === Null, h2 = h2, h2 = Round[#, 0.001]] &], Number]      The purpose of the second argument of Dynamic is to avoid someone entering a value with more than 3 decimal places (or emptying the field after some value has been assigned). For example, entering 0.4691 immediately reassigns the `InputField` to 0.469. The problem is that entering the number 0.468 renders 0.4680000000000001. I imagine it’s something to do with the representation of 0.468 in binary, etc. How can I avoid this after rounding action? **EDIT:** After some more testings, I see that it is the `Number` part that is causing the problem. This works "badly":               InputField[Dynamic[h2], Number]      This works OK:               InputField[Dynamic[h2]]      ![enter image description here](http://i.stack.imgur.com/OsCUs.gif) If you do `Do[h2 = i; Pause[0.1], {i, 0.04, 0.08, 0.001}]`, you can get a good picture of the problem: ![enter image description here](http://i.stack.imgur.com/Rgx0h.gif) How can I avoid this `Number` side effect?


title: How can I make hatching filling of plot

text: How can I make hatching filling of plot Like this: ![hatching filling plot](http://i.stack.imgur.com/dYRYZ.png) I use another one plot with shifting to make filled area above:               plot := ListLinePlot[       Table[{x1[w], x2[w]}, {w, 1.5, 5, .005}],            Filling -> Top,       FillingStyle -> White       ]          fill := ListLinePlot[       Table[{x1[w] - 0.01, x2[w] - 0.02}, {w, 1.5, 5, .005}],       Filling -> Top,       FillingStyle -> LightGray,       PlotStyle -> LightGray       ]          Show[fill, plot]      ![plot](http://i.stack.imgur.com/pkgdl.png) How can I make hatching filling of fill-plot?


title: Plotting different PDFs of a distribution in the same graph

text: How would I plot the PDF (probability density function) of `WeibullDistribution[1/5, 50]`, `WeibullDistribution[1/4, 40]`, `WeibullDistribution[1/3, 30]` and `WeibullDistribution[1/2, 20]` in the same graph?


title: Change locator object appearance inside Manipulate

text: I have read earlier discussions of changing Locator appearance in Manipulate. I would like to change the rendered size of the locator object based on one of the manipulate variables. I can't get anything to work. Here is an attempt. source is an image, with dimensions {3716,3449}               isize = 240;     dim = ImageDimensions[source]     height = dim[[2]];     Manipulate[(       locator =         Graphics[{Red, FaceForm[Opacity[.1]],           EdgeForm[Directive[Thin, Red]], Rectangle[]},          ImageSize -> (isize size/height)];       sub = ImageTake[source, height - (pt[[2]] - {0, size - 1}),          pt[[1]] + {0, size - 1}];       Row[{Image[source, ImageSize -> isize],          Image[sub, ImageSize -> isize]}])      , {{pt, {820, 1810}}, Locator, Appearance -> locator}      , {{size, 100}, 10, 1000}]


title: Why is my answer being displayed with "Subscript^(0,1)[a,b]"?

text: I type in my equations using ctrl+- to make it look nice and my answer outputs in "Subscript^(0,1)[a,b]" form? What is going on? In the answer some bits are displayed with the actual subscripts and some are displayed in the above form, even for the same variable. Edit: more specifics I am taking the partial derivative of a function H wrt to b. H is a function of many variables one of which is a_b. Is it possible that Mathematica is trying to take the derivative of the subscript because there is a b in there?               H=d k2 + c^2 k4 + k5 s^2 + k1 U +       k3 \[Theta] + (g (1 - d - U - \[Theta]) \[Theta] -          U (1 + s Subscript[e, s])) Subscript[\[Lambda],        1] + (-c d + s U Subscript[e, s]) Subscript[\[Lambda], 2] +       U Subscript[\[Lambda], 3]      and               DHds = Simplify[D[H, s]]


title: Symbolically Expanding One-Variable q-hypergeometric Series

text: In general, how do I get Mathematica to symbolically expand various infinite series to an arbitrary degree of accuracy? I deal with q-hypergeometric series quite frequently, and specifically want to expand series like the following: $$\sum_{n=0}^{\infty}\frac{(-1)^nq^{6n^2}}{(q^3;q^3)_n(-q;q)_{3n}},$$ where $(a;q)_n$ denotes the standard QPochhammer symbol $\prod_{k=0}^{n-1}(1-aq^k)$. I would like to input a maximal degree, and for Mathematica to output the first few terms of the infinite series up until the specified degree. For example, if I inputted $13$, I would want Mathematica to output (I believe, doing this by hand) $q^6-q^7+q^{10}-q^{11}+q^{12}-q^{13}$. I cannot get the existing series functions to give something as clean as what I want. One preliminary input I tried was               FunctionExpand[Sum[(-1)^n/QPochammer[q^3,q^3,n],{n,0,10}]],      which returned               1 - 1/(1 -        q^3) + 1/((1 - q^3) (1 - q^6)) - 1/((1 - q^3) (1 - q^6) (1 -          q^9)) + 1/((1 - q^3) (1 - q^6) (1 - q^9) (1 - q^12)) - 1/((1 -          q^3) (1 - q^6) (1 - q^9) (1 - q^12) (1 - q^15)) + 1/((1 -          q^3) (1 - q^6) (1 - q^9) (1 - q^12) (1 - q^15) (1 -          q^18)) - 1/((1 - q^3) (1 - q^6) (1 - q^9) (1 - q^12) (1 -          q^15) (1 - q^18) (1 - q^21)) + 1/((1 - q^3) (1 - q^6) (1 -          q^9) (1 - q^12) (1 - q^15) (1 - q^18) (1 - q^21) (1 -          q^24)) - 1/((1 - q^3) (1 - q^6) (1 - q^9) (1 - q^12) (1 -          q^15) (1 - q^18) (1 - q^21) (1 - q^24) (1 - q^27)) + 1/((1 -          q^3) (1 - q^6) (1 - q^9) (1 - q^12) (1 - q^15) (1 - q^18) (1 -          q^21) (1 - q^24) (1 - q^27) (1 - q^30)),      which is not the form of output that I want because the sum is not fully expanded as a polynomial in $q$. Also, if I insert an additional `QPochhammer[-q,q,Infinity]` out front, it leaves the $(-q;q)_{\infty}$ unexpanded because there is no degree specification. (This is why I want to implement the degree specification rather than settling for expanded partial sums.) These are two central issues that I'm not sure how to address.


title: Need help with C Code Generator

text: I'm trying to use the _Mathematica_ C Code Generator package to generate code that is to be included in a web application by a developer. I don't know any C, and this seems to be the only way to integrate my model with the web-app. I am having a lot of difficulties getting off the ground. A persistent error seems to be that my iteration indices are not recognised as integers. Here's an example:               Needs["CCodeGenerator`"]     funct = Compile[{{M, _Real, 2}, {l, _Integer}},       Module[{matrix = M, lag = l },        columns = Length[Transpose[matrix]];         Flatten[            Join[ {{{Table[1, {columns - lag + 1}]}},            Table[matrix[[;; , lag - i + 1 ;; columns - i + 1]] , {i, 1, lag}]} ] , 2]         ], {{i, _Integer}}     ]      This produces the following error: > `Compile::cpintlt`: "1;;All at position 2 of > `matrix[[1;;All,lag-i+1;;columns+i+1]]` should be either a nonzero integer > or a vector of nonzero integers; evaluation will use the uncompiled > function." Finally when I export the C code, I get errors like > `CCodeGenerate::wmreq`: "The expression > `Function[{M,l,iCompile$18},Block[{i=iCompile$18},{All,i}]]` requires > _Mathematica_ to be evaluated. The function will be generated but can be > expected to fail with a nonzero error code when executed. " Any help would be greatly appreciated.


title: Problem with Plot and ParametricNDSolve

text: This is my first question on this site, I hope it is written in an understandable way. Let's start. My aim is to plot a certain parametric region, with $x$ and $y$ coordinates given by the following formulas. First of all I write down some functions that, once I define a particular potential $U$ of two variables **#1** and **#2** , will calculate some of its derivatives and things like that (since I will need them later for the construction of the plot). Here below are the formulas, the last three are the ones that will be appearing in the following lines of code:               epsilontemp[U_] = D[U[#1,#2],#1])^2/(U[#1,#2])^2/2&;          etatemp[U_] = D[U[#1,#2],{#1,#2}])/U[#1,#2]&;          inttemp[U_] = D[U[#1,#2],#1])/(U[#1,#2])&;          epsilonhelp[U_,a_] = epsilontemp[U][a,1];          etahelp[U_,a_] = etatemp[U][a,1];          inthelp[U_,a_] = inttemp[U][a,1];      Now I write down the potential: it is an infinite series, but Mathematica recognizes it as the sum of two _PolyLog_ functions:               U3=Sum[Cos[n*#1/#2]/n^5,{n,1,Infinity}]&;      in the following equations I will call always **#1** as $a$ and **#2** as $b$. Now: I must find the value of $\frac{a}{b}$ such that epsilontemp[U3][a,b]=1 (this equation can be written more simply in the way I did in the code right below), and I found that this piece of code does the job perfectly (the particular starting point was chosen after I did a "Plot of the equation", in order to find approximately the root):               phiendtemp[b_?NumericQ] := FindRoot[inthelp[U3,x]-Sqrt[2]*b,{x,48/10},MaxIterations->Infinity,Compiled->False][[1,2]];      and in order to work more easily with this quantity, I defined an _InterpolatingFunction_ in the following way:               phiend[b_] = FunctionInterpolation[phiendtemp[btemp],{btemp,3,5}][b];      Now the next step consist in solving numerically a differential equation, with two parameters: one enters simply in the equation while the other enters in the initial condition. The new command of Mathematica _ParametricNDSolve_ was used:               phicmbtemp1 = ParametricNDSolve[y'[eFolds]-b^{-2}*inthelp[U3,y[eFolds]]==0,y[0]==j,y,{eFolds,30,70},{b,j},Compiled->False]          phicmbtemp2[b_,j_,eFolds_] = y[b,j][eFolds]/.phicmbtemp1;      The last step is use the function I defined previously as the initial condition for the differential equation, and I did that in the following way.               phicmb[b_,eFolds_] = phicmbtemp2[b,phiend[b],eFolds];      Up to now the code works perfectly, I also tried to plot phicmb[b,eFolds] for $b=4$ and for $eFolds$ from 30 to 70 (the values I want) and it gives me the results that I expect from the "non numerical" analysis of the equations. Now I turn to the ParametricPlot: the functions that will be the $x$ and $y$ coordinates are the following (the parameters of the region will be $b$ and $eFolds$):               nsplot[U_,b_,eFolds_] = 1 + 2*b^{-2}*etahelp[U,phicmb[b,eFolds]] - 6*b^{-2}*epsilonhelp[U,phicmb[b,eFolds]];     rplot[U_,b_,eFolds_]=16*b^{-2}*epsilonhelp[U,phicmb[b,eFolds]]      After I wrote this, I can at last explain what's my problem. The problem is that if I try to calculate things like (in the actual plots, I will use $c$ for the quantity $b$, and $n$ for the quantity $eFolds$)               nsplot[U3,4,40]      Mathematica returns               0.85485 + 0.i      that (apart the imaginary part, that is a problem on its own) is compatible with what I expect from a "non numerical" analysis of the problem. However if I try to do something like               Table[nsplot[U3,4,n],{n,30,70,10}]      this gives out numbers like               {82.407, 131.036, -43.4576, -309.158, -510.697, -615.093, -660.662, -689.591, -725.895}      which are completely out of any possible result for that quantity (note that in this list appears again the quantity that I evaluated before, for $eFolds = 40$, and it is totally different). I chose to post the issue using _Table_ instead than _ParametricPlot_ , since the problems appear already using _Table_. Anyway, the code I tried to use also was               Plot[nsplot[U3,4,n],{n,30,70}]      that gives, like table, very strange numbers, and               ParametricPlot[{nsplot[U3, c, n],rplot[U3, c, n]}, {c, 3, 5}, {n, 30, 70}]      that gives, too, a very strange plot. To see if something was wrong with the code, I tried with a simpler potential (namely, $1-Cos[\frac{a}{b}]$) that can be solved "with pen and paper" and I tried to do the parametric plot firstly using the "analytical solution", and then using this code: the results are exactly identical. Maybe the problem is in the small imaginary parts? If there's and imaginary part the $Cos$ in the potential will turn into some $exp$ and maybe that messes up the calculations? But then again if I simply calculate something like               nsplot[U3,4,40]      it gives me the correct result. So I don't really know where's the problem. Anyway, I hope you can give me some hint... Thanks, Giovanni P.S.: I used " _Compile->False_ " in NDSolve because I recalled that it was sometimes best to use it when dealing with numerical calculations, I hope that's not the problem...