title: Revolution plot with 2 variable

text: I'm having trouble with RevolutionPlot3D with two variables. I have this parabola                ContourPlot[0 == y^2 + x + y + 5, {x, -15, 5}, {y, -10, 10}, AxesLabel -> {x, y, z}]      but when I try to do RevolutionPlot3D with the equation               RevolutionPlot3D[{(y^2 + y + x + 5)}, {y, -5, 5}, {x, -5, 5},                      RevolutionAxis -> {1, 0, 0}, PlotRange -> All, AxesLabel -> {x, y, z}]      it won't work, because x should be an Theta. How can I have something similar to               RevolutionPlot3D[{(y^2 + y + 5)}, {y, -5, 5}, {\[Theta], 0, 2 \[Pi]},                       RevolutionAxis -> {1, 0, 0}, PlotRange -> All, AxesLabel -> {x, y, z}]      with a second variable?


title: Play in Linux causes mathematica to freeze

text: It seems that when I run `Play` in Mathematica, something as basic as               Play[Sin[440 * 2 π * t], {t, 0, 1}]      the output generates correctly. However, when I actually hit the sideways triangle to play the sound, the user interface freezes, and I have to kill Mathematica. This isn't an issue where everything works but the sound doesn't play. It freezes and I have to kill the program. I tried emulating OSS using ALSA by running `aoss mathematica` (I have `alsa- oss` installed.) The sound still didn't play, but several errors appear on standard out/error:               ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear     ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe     ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side     bt_audio_service_open: connect() failed: Connection refused (111)     bt_audio_service_open: connect() failed: Connection refused (111)     bt_audio_service_open: connect() failed: Connection refused (111)     bt_audio_service_open: connect() failed: Connection refused (111)     ALSA lib pcm_dmix.c:961:(snd_pcm_dmix_open) The dmix plugin supports only playback stream      **Does anyone know how I can get my sound to play in Mathematica 9.0.1, given that I tried emulating oss in alsa and it still doesn't work? Thanks.** Note: I'm looking for a solution that makes Mathematica compatible with notebooks someone sends me. I found solutions that use `$SoundDisplayFunction` to play the sound using alsa rather than display a sound dialog, but this doesn't work for notebooks I receive from people with working sound.


title: Does Mathematica compute free-form-input on Wolfram servers?

text: I've just started to use _Mathematica_ and I'm using the free-form input a lot. The computation time for simple problems seems to take a lot of time and my CPU isn't really used at all. I first thought that the f-f-input would be transferred to a Wolfram server, converted into the _Mathematica_ programming language and computed on my PC. Is that really the case? I didn't find anything about this on the _Mathematica_ website and I'd like to know how that and Wolfram Alpha-queries in _Mathematica_ 9 works.


title: Define a second name for a function

text: I'm working with an own package of functions. During development I noticed, that my naming scheme is not that clever; for example some of my functions are starting with capital letters. But I have several files working with that package, that I would like to be able to use further on with as few as possible. So my idea is, to write a small package named `loadOldNams`or something like that, providing the old function names additionally. Therefore I'm facing the following problem: Having a function with my new name - for simplification just `f`, e.g.               f[x_] := x^2;     f[x_, y_] := x^2 y^2;     f::usage = "A test usage text";      I would like to define a function having the old name (say `g`), such that all cases 'g[x], g[x,y]`and the`::usage`also work with`g`. Just `f=g;` or `f:=g;` won't work, so How do I get a function with the name `g` doing exactly the same as `f` (just having another name)?


title: How to export and import Graphs with additional data?

text: I'm trying to export and then later import graphs with additional data added such as `VertexLabels` and `EdgeLabels`. When I export a graph, such as the following, and then import it, I find that some information has been lost.               g=Graph[{1->2,2->3,3->1},VertexLabels->"Name",VertexStyle->Purple,VertexShapeFunction->"Diamond"];     Export["graph.gml",g];     r=Import["graph.gml"]      This will maintain some of the options, e.g. `VertexShapeFunction` and `VertexStyle`, but will lose `VertexLabels`.               PropertyValue[r,VertexLabels]      The above returns `{}`,showing that the data was not retained. I have tried .graphml and .gxl formats as well, with the same issues.               Import["graph.gml",{{VertexLabels}}]      The above returns the following error:               Import::noelem: The Import element "VertexLabels" is not present when importing as Graphlet. >>      What is the best way to export and then import graphs while retaining all additional data?


title: Solve 1-D function that has 2-D interpolating functions

text: I need some helps on NDSolve. Here are my equations:               k1 = 0.000192;     k2 = 0.000159;          Clear[x, y, z, h]     eqnf1 = {x'[t] == -k1*x[t]*y[t]/h[t] + k2*z[t],        y'[t] == 3*(-k1*x[t]*y[t]/h[t] + k2*z[t]),        z'[t] == k1*x[t]*y[t]/h[t] - k2*z[t],        h'[t] == -3*(-k1*x[t]*y[t]/h[t] + k2*z[t]),        x[0] == .001, z[0] == 0, y[0] == 0.2, h[0] == .001};          sol2 = NDSolve[eqnf1, {x, y, z, h}, {t, 0, 1000}][[1]]          X[t_] = x[t] /. sol2;     Y[t_] = y[t] /. sol2;     Z[t_] = z[t] /. sol2;     H[t_] = h[t] /. sol2;      I used this part to solve y[t], which will be using later for my other function. And here is 2nd part of my function:               Da = 1.33*10 - 4;     eqnm1 = {D[yc[x, t], {t, 1}] ==          Da* D[ D[yc[x, t], {x, 1}], {x, 1}] ,        yc[x, 0] == 0,         yc[0, t] == Z[t], (D[yc[x, t], {x, 1}] /. x -> 1) == 0};     solmem1 =       First[yc /. NDSolve[eqnm1, yc, {x, 10^-20, 1}, {t, 0, 1000}]]      Here I obtained another interpolating function, yc[x,t], which will be used in the last part of the problem that I'm not able to solve. The last part of the problem needs function from the 1st and 2nd parts - y[t] & yc[x,t] which both are interpolating functions. And the 3rd part is only 1D function, which is xs[t]. I tried               eqns1 = {xs'[t] == -k1*xs[t]*First[Evaluate[y[t] /. eqnf1]]/hs[t] +           k2*First[Evaluate[yc[x, t] /. x -> 1 /. solmem1]],        hs'[t] == -3*(-k1*xs[t]*First[Evaluate[y[t] /. eqnf1]]/hs[t] +             k2*First[Evaluate[yc[x, t] /. x -> 1 /. solmem1]]),        xs[0] == 0, hs[0] == 1};      But it has some errors that I think is caused by the 2nd part of the problem that is 2-D (ys[x,t]). Does anyone know how to solve xs(t) and hs(s)? TThanks


title: Extract desired solutions from Reduce

text: I have the function               a = 1 - 3 Sin[theta]^2 Cos[phi]^2;      which I solve for 'phi' when $a=0$               sol = Reduce[a == 0, phi]      which gives me the result ![](http://i.stack.imgur.com/x1Om6.png) How do I turn this output into a nice list of results for desired values of C[1], much like Solve[ ] would give me, so that I can use Plot[ ] and visualise the functions?


title: Highlighting Mathematica code in LaTeX document

text: I was thinking about the best way to include Mathematica code in a LaTeX document with a nice syntax highlighting. I have tried the packages listings and minted (with pygments), which both claim to include Mathematica syntax highlighting. There is also a separate Mathematica lexer for pygments on github. Having looked at the output from these packages, I'm not entirely happy. I was hoping to obtain a result resembling as closely as possible Mathematica's native syntax highlighting or the highlighting used here on mma.SE (is that halirutan's prettify extension?) My question is: What are users' preferred ways to include Mathematica code in LaTeX files that preserve syntax highlighting?


title: Protecting function definitions only for particular inputs

text: I would like to be able to define the values of a particular function for new inputs.               f[x1]=f1;     f[x2]=f2;      I would also like to be able redefine the values for most inputs.               f[x1]=f3;     f[x2]=f0;      But there are certain definitions I would like to protect.               f[x0]=f0;      Protect[f] protects all definitions and prevents me from defining the values for new inputs. I could set/remove/set the Protected attribute for f but that isn't any fun because there are very few definitions I would like protected, and many that get defined and redefined. My other thought would be to modify Set:               Unprotect[Set]     f::fixeddef="The definition of f for this value cannot be modified"     Set[f[x0],_]:=(Message[f::fixeddef]; $Failed)     SetAttributes[Set,Protected]      This doesn't completely work though:               f[x0]=f1 (* fails appropriately *)     {f[x0],f[x1]}={f3,f4} (* returns {f3,f4} instead of {f0,f4} *)      I assumed Set threads itself over nested lists, recursively calling Set until the lhs is a Symbol, but apprently I assumed wrong. How does Set work and how can I protect the function definitions only for particular inputs?


title: hyperlink in label

text: In a `FrameLabel` for `Manipulate`, I would like part of the string to be a hyperlink. Is this possible? I have tried various things (e.g. insert hyperlink, and the Hyperlink function) but nothing has worked.


title: How to control frame thickness in Grid object exported to .pdf?

text: I would like to export a _Grid_ object to a .pdf document (preferably as part of a notebook). Here's an example:               data = Notebook[        {Cell[          BoxData[           ToBoxes[            Grid[             {              {11, 22},              {33, 44}              },             Frame -> All,             FrameStyle -> Directive[Thickness[.1], Orange]             ](* end of Grid *)            ]           ]          ](* end of Cell *)         }];          Export[NotebookDirectory[] <> "grid.pdf", data];     SystemOpen[NotebookDirectory[] <> "grid.pdf"];      However, setting thickness of a grid in _FrameStyle_ has little to do with the outcoming table (only the upper line is ok). I've encountered a similar problem concerning _Dividers_ here: How to fix a PDF line rendering problem in V9 They say it's a bug appearing in MMA9 only (MMA8 is free of this problem. Sadly, it's not the version I get to use). Possible solution would be to export a _Notebook_ to .eps first, and then convert it to .pdf, which works for simple examples, however there are two reasons I can't use it. First - as I try to export my _Notebook_ to .eps, Mathematica crashes and quits to Windows (i use XP 32bit SP3). Secondly - I'd very much appreciate, if using programs other than MMA could be avoided. Is there another way of exporting a _Notebook_ to .pdf? Or meybe there's some unknown global option which can prevent aliasing? I will be grateful for any help. PS The thickness is broken only in .pdf - the notebook looks ok.


title: Difficulty finding Expectation of a special function

text: I have a special function given as: $${\rm f}\left(r\right) ={1 \over \beta\lambda}\,2^{r/\beta} \exp\left({\left[2^{r/\beta} - 1\right]K \over \lambda}\right)$$ I should find the Expectation of the random variable $r$. Mathematica was not able to solve the associated Integral function. So it returns: $$ \int_0^{\infty}\left\\{{1 \over \beta\lambda}\,2^{r/\beta} \exp\left({\left[2^{r/\beta} - 1\right]K \over \lambda}\right)\right\\}\ r\,{\rm d}r $$ Does anyone recognize how I can reduce this function so I can solve it further? ==== Edit ===== This is the code I tried:               Integrate[ r*fr, {r, 0, \Infinity}, Assumptions->{K>=1, \lambda >=0, \beta >=0}]


title: Strange result using NIntegrate with Max and PDF

text: This is really trivial and I appologise in advance if I have made a stupid error somewhere. I have been chasing down some strange results when using `NIntegrate` with integrands involving `Max` and `PDF`. A simple example follows.               f[x1_, x2_] := PDF[MultinormalDistribution[{0, 0}, {{1, .5}, {.5, 1}}], {x1, x2}];     NIntegrate[Max[Exp[x1] + Exp[x2] - 3, 0] f[x1, x2],      {x2, -Infinity, Infinity}, {x1, -Infinity, Infinity}]      This gave the answer 0.804628. However, when I tried MATLAB I got 1.2255. So I then used Monte Carlo.               Block[{rho = 0.5, data, rv1, rv2, paths = 1000000, sum, sumSquared, mean, var, stdError},      data = Table[        rv1 = Random[NormalDistribution[0, 1]];        rv2 = rho rv1 + Sqrt[1 - rho^2] Random[NormalDistribution[0, 1]];        Max[Exp[rv1] + Exp[rv2] - 3, 0], {i, paths}];      sum = Total[data];      sumSquared = Total[data^2];      mean = sum/paths;      var = (sumSquared/paths - mean^2) paths/(paths - 1);      stdError = Sqrt[var/paths];      {mean, stdError}     ]      One run of this gave {1.22509, 0.0031105}, agreeing with the MATLAB result. I have also noticed that if I replace `Max[Exp[rv1] + Exp[rv2] - 3, 0]` with `Exp[rv1] + Exp[rv2] - 3` the issue does not arise. Any idea what is going on here?


title: Whats Mathematica exactly is?

text: Is it a software to learn mathematics and programing? Or what? Sorry for my ignorance and my English. I'm not clear about what is.


title: Fourier Transform Help

text: I'm trying to do a Fourier Transform of the following Data, but I'm completely stuck. Here's what I've done so far:               data = Drop[data, 1];     dat = data /. {x_, y_, z_, w_} -> {x + y/12., 10 z};     ListLinePlot[Abs[Fourier[dat]], PlotRange -> {Automatic, {0, 40}}]      I don't understand why it keeps displaying this weird plot ![enter image description here](http://i.stack.imgur.com/i28k4.jpg) Anyone have any clue what I'm doing wrong? I'm just learning this Fourier thing so I'm real lost.


title: Computing Smith Normal form of a matrix with mod p coefficients

text: I would like to compute the Smith Normal form of a matrix with coefficients in GF(p). In particular, I am interested in GF(2). I have used the Smith normal form packages for integer and polynomial matrices before. Can these be adapted to work for matrices with finite field coefficients? Is there another way to compute the Smith normal forms mod p in Mathematica?


title: Generating a list of cubefree numbers

text: I am trying to generate a list of cubefree numbers (i.e. numbers when prime factorized contain no tripled factors) within a given range. Of `DivisorSigma`, `PrimeOmega`, `Divisors`, `PrimeNu` and `FactorInteger`, `FactorInteger` seems to me to be the best suited to the task (please feel free to suggest more suitable methods). For example,               FactorInteger[630]      outputs               {{2, 1}, {3, 2}, {5, 1}, {7, 1}}      From this, I would like _Mathematica_ to focus on the second number in each pair (the exponent) and determine which has the highest value. In this case, it is `{3,2}`, indicating that `630` is a cubefree number (i.e. - having no prime factor with a greater exponent than `2`). Is it possible to do this with a range of numbers, so that _Mathematica_ evaluates each number in this way within a range, and then outputs that list of numbers?


title: Internal self-test error MLParseStream|c|297

text: I have been plotting time-dependent vectors. Earlier I used the following plotting options:               CLB4D[t_] := {CLBx[t], CLBy[t], CLBz[t], t};          tempdata = Table[CLB4D[t], {t, 0, d, (0.01/\[Omega])}];     tempdata[[All, 4]] = Rescale[tempdata[[All, 4]], {0, d}];     clrfnct[x_, cf_] := ColorData[cf][1 - x[[4]]];     Graphics3D[{PointSize[0.013],      Point[#[[1 ;; 3]], VertexColors -> clrfnct[#, "SolarColors"]] & /@      tempdata, Opacity[0.01], Sphere[{0, 0, 0}]}, Boxed -> False,      Axes -> True, AxesLabel -> {x, y, z}]      where CLB4D[t] is the vector, specifying a point in 3D-space, with a color that corresponds to a time-coordinate. The components of this vector are defined in the same module, which then plots the answer. Actually, I have several different modules with different definitions for vectors that I am comparing. It worked well, but I wished to tweak the options to get a clearer plot (changing the visual appearance wasn't just my wish, either). I am happy with the following options:               CLB4D[t_] := {CLBx[t], CLBy[t], CLBz[t], t};          tempdata = Table[CLB4D[t], {t, 0, 2*pi/f, (2*pi/f)/150}];     tempdata[[All, 4]] = Rescale[tempdata[[All, 4]], {0, 2*pi/f}];     clrfnct[x_, cf_] := ColorData[cf][1 - x[[4]]];     Graphics3D[{PointSize[0.010],      Point[#[[1 ;; 3]], VertexColors -> clrfnct[#, "SolarColors"]] & /@      tempdata, Opacity[0.5], pic[[1]], pic2[[1]]}, Boxed -> False,      Axes -> False,      PlotLabel ->      Style["text and "<>ToString[variables_from_the_module], FontSize -> 16, FontFamily -> "STIX"],       ViewPoint -> {1.14, -3.09, 0.77}]      There, pic and pic2 are parametricplot3d's of unit circles, and the coordinate axes from 0 to 1. These are always plotted as a reference. The trouble is that whenever I have any plot that takes, say, 20 minutes or an hour from the local computer to calculate (or would take in the previous style), after evaluating it for a long while, Mathematica just freezes, and most of the time I have to kill it, or it crashes. Finally, it gave me the **Self-test error MLParseStream|c|297** instead of crashing. It fails to evaluate with both Linux and Mac. I got this message on a Mac. If the plot only takes for a couple of seconds to evaluate, it manages to do this. Sometimes it has managed to evaluate a heavier plot, but will crash when I try to save .nb or export the plot as a PDF. I have no idea what goes wrong, nor have I found out what the message is about. I have not changed any other definitions in the module. I also noticed that taking away the option "viewpoint" does not remove the problem. Any suggestions? I am using version 9 of Mathematica.


title: Using Refresh[..] with TrackedSymbols

text: This is a very basic question, but I don't understand the following behavior. The usage to `Refresh` reads > represents an object whose value in a Dynamic should be refreshed at times > specified by the options opts. Although the word _times_ was mentioned explicitly the examples suggest, that `Refresh` can also be used to restrict the `TrackedSymbols` in an expression inside `Dynamic`. Here is a basic example from the help, which works like a charm               Manipulate[      {x, Refresh[y, TrackedSymbols :> {x}]},      {x, 0, 1},      {y, 0, 1}     ]      ![Mathematica graphics](http://i.stack.imgur.com/kgYGd.png) When you move the `y`-slider, nothing happens because the second expression containing `y` is restricted to keep only track of `x`. When you then move `x`, the `y` values jumps to it's current value. Now, let's extend this example a bit               Manipulate[      {Refresh[{x, y}, TrackedSymbols :> {y}],        Refresh[{x, y}, TrackedSymbols :> {x}]},      {x, 0, 1},      {y, 0, 1}     ]      What I had hoped for was, that when I move the `x`-slider, only the `x`-value in the second `{x,y}` is updated because the first `{x,y}` tracks only `y`. Equivalent for the `y`-slider. Unfortunately, all values are always updated. Solutions to this is can be found at the end of the post, but first my question: **Can someone explain what I have missed in the documentation of`Refresh` and how this is supposed to be used?** Several solutions to the toy-example can be found. The most prominent one is to wrap each `Refresh` in `Dynamic`               Manipulate[{       Dynamic@Refresh[{x, y}, TrackedSymbols :> {y}],        Dynamic@Refresh[{x, y}, TrackedSymbols :> {x}]},        {x, 0, 1},        {y, 0, 1}     ]      This goes along with the suggestion of andre's answer, when I understood him right. Further solutions are               Manipulate[      {Dynamic[{x, y}, TrackedSymbols :> {y}],        Dynamic[{x, y}, TrackedSymbols :> {x}]},      {x, 0, 1},      {y, 0, 1}     ]          DynamicModule[{},      Column@{Dynamic[{x, y}, TrackedSymbols :> {y}],         Dynamic[{x, y}, TrackedSymbols :> {x}],        Slider[Dynamic[x]],        Slider[Dynamic[y]]     }]               DynamicModule[{},      Column@{Dynamic@Refresh[{x, y}, TrackedSymbols :> {y}],         Dynamic@Refresh[{x, y}, TrackedSymbols :> {x}],        Slider[Dynamic[x]],        Slider[Dynamic[y]]     }]      This leaves the question, when I have to use `Dynamic` anyway, why does the documentation suggest `Refresh` can do this alone. I still think I'm missing something.


title: ToNumberField won't recognize Root as an explicit algebraic number

text: In _Mathematica 9.0.1_ , it appears that `ToNumberField` will not always recognize a `Root` object as an explicit algebraic number.               ToNumberField[         Root[{ 1 - #1 + #1^2 - #1^3 + #1^4 - #1^5 + #1^6 &,                 #1^5 + #1^3 #2 + #1 #2^2 + #2^3 - #1 #2^3 + #1^2 #2^3 - #1^3 #2^3 + #1^4 #2^3                - #1^5 #2^3 - #1^4 #2^4 - #1^2 #2^5 - #2^6 &},  {6, 6}] ]      > >     ToNumberField::nalg: >     "Root[{1 -#1 + #1^2 - #1^3 + #1^4 - #1^5 + #1^6&, >             #1^5 + #1^3 #2 + #1 #2^2 + #2^3 - #1 #2^3 + #1^2 #2^3 -#1^3 #2^3 > + #1^4 #2^3 >            - #1^5 #2^3 - #1^4 #2^4 - #1^2 #2^5 - #2^6 &}, {6,6}] >       is not an explicit algebraic number. >>" >   A different root of the same polynomial works just fine:               ToNumberField[         Root[{1 - #1 + #1^2 - #1^3 + #1^4 - #1^5 + #1^6 &,                #1^5 + #1^3 #2 + #1 #2^2 + #2^3 - #1 #2^3 + #1^2 #2^3 - #1^3 #2^3 + #1^4 #2^3                - #1^5 #2^3 - #1^4 #2^4 - #1^2 #2^5 - #2^6 &},  {6, 1}] ]      > >     AlgebraicNumber[Root[1 + #1 + #1^2 + #1^3 + #1^4 + #1^5 + #1^6 &, 2], > {0, 1, 0, 0, 0, 0}] >   Is this a bug, and is there any way I can work around it? **Edit** : In case it matters, that first `Root` expression will `FullSimplify` to `1`.


title: ContourPlot refuses to show in-figure PlotLegends after turn on ContourShading

text: I would like to do a contour plot with a label inside the figure. For example, the following works well. Note there is a small "example" at the right bottom figure.               ContourPlot[Cos[x] + Cos[y], {x, 0, 4 Pi}, {y, 0, 4 Pi},       PlotLegends -> Placed["example", {0.8, 0.1}]]      ![enter image description here](http://i.stack.imgur.com/QHy0b.png) However, I don't want contour shading. But after I set `ContourShading -> None`, the PlotLegends disappeared.               ContourPlot[Cos[x] + Cos[y], {x, 0, 4 Pi}, {y, 0, 4 Pi},       PlotLegends -> Placed["example", {0.8, 0.1}], ContourShading -> None]      ![enter image description here](http://i.stack.imgur.com/NlPB8.png) Would you be so kind to see if it is a bug? And is there a workaround? (I am using Mathematica 9.0.1)


title: Defining regions for `Exclusions`

text: I have the following function I want to plot in 3D (For simplicities sake we can say $a=5,b=-1,c=3$.)               f[x_, y_, a_, b_,c_] := ((E^(b x) - E^(b y)) x)/((c E^(a b) + E^(b x)) (x - y))      However, when I plot it I get error messages for Intermediate values. To try to solve this I used `Exclusions`, but despite this I still get the same error messages.               Plot3D[{f[x, y,5,-1,3]}, {x, 9, 10}, {y, 9, 10}, Exclusions -> {x - y == 0}]      I thought I should maybe exclude the values `-0.1<=x-y<=0.1`, but I don't really know how to do it or if it works. Another thought I had was maybe use the conditions that result from using reduce. However, I'm not sure how to use the results to exclude intermediate values.               Reduce[f[x, y,5,-1,3] == 0, x]      Any suggestions on other ways to do it would be greatly appreciated.


title: FindRoot finds a solution not found by NSolve

text: I am trying to solve a polynomial equation of higher order with non-integer exponents. When the order of the system is greater than 4, FindRoot provides a correct solution that is not found by NSolve. Here is a minimal example: In:               Clear[k,sol1, a, G, j, l, equ];     a=0.3; G=4;     equ := k^(G(1 - a)) == (1-a)/G Sum[(G-j+1) a^(j-1) k^((G-j)(1-a)), {j, G}];     NSolve[equ, k]     sol1 = FindRoot[equ, {k, 1}]     equ /. sol1      Out:               {{k -> -0.0654054 + 0.0537165 I}, {k -> -0.0654054 - 0.0537165 I}}     {k -> 0.881805}     True      How can that be? Thanks for any help! PS: for G<4 everything is fine, for G>4 the same problem seems to persist


title: References on functions FindGraphPartition and FindGraphCommunties

text: Does somebody have some interesting references on the `FindGraphPartition` and `FindGraphCommunties[.., Method -> "Spectral"]` functions and their algorithms as implemented by _Mathematica_ 9.


title: Number of complex roots for the system of polynomials

text: I have a system of algebraic equations. For example: $$ \left\\{ \begin{aligned} x^2 y + 2 x y + 2 &= 0,\\\ y^3 + 2 x + 1 &= 0. \end{aligned} \right. $$ (In my problem the system contains 16 equations of degrees 1–3). I need to know the number of complex roots (the system in question has a finite number of roots). I believe, the number of roots can be determined using `GroebnerBasis`. But what is the most elegant way to do it?


title: When I can assume that all decimal digits returned by Mathematica are provably correct?

text: How to Control the Precision and Accuracy of Numerical Results   Arbitrary-Precision Numbers > _Mathematica_ works with exact numbers and with two different types of > approximate numbers: machine-precision numbers that take advantage of > specialized hardware for fast arithmetic on your computer, and arbitrary- > precision numbers that are correct to a specified number of digits. > > * * * > > To be sure of `n` correct digits, use `N[expr, n]`. > > * * * > > When you do a computation, _Mathematica_ keeps track of which digits in your > result could be affected by unknown digits in your input. It sets the > precision of your result so that no affected digits are ever included. This > procedure ensures that all digits returned by _Mathematica_ are correct, > whatever the values of the unknown digits may be. > > * * * > > _Mathematica_ automatically increases the precision that it uses internally > in order to get the correct answer Of course, this sounds very reassuring, but I still have some doubts that all decimal digits ever returned by _Mathematica_ when working with arbitrary- precision numbers are always provably correct, no matter what functions I invoked. What are those cases when I can be certainly sure all displayed digits are correct? * * * _Update:_   Here is an example when some incorrect decimal digits are returned when working with arbitrary-precision arithmetic:               a = 1`7     (* 1.000000 *)          a // Precision     (* 7. *)          d = Derivative[0, 1][StieltjesGamma][0, a]     (* -1.6450 *)          MachineNumberQ[d]     (* False *)          d // FullForm     (* 1.64501552391043694947251282378009083269`5.155856939311388 *)          d // Precision     (* 5.15586 *)      So, _Mathematica_ claims that at least 5 (hence, all) decimal digits of the result `-1.6450` are correct. But in fact, the exact result is `-Pi^2 / 6` that is `-1.644934...`, so only 3 digit are correct. I am also concerned that `Precision[...]` itself returns a machine-precision number, that is subject to uncontrolled error-accumulation that possibly can result in claiming more digits of precision in a number than there actually are. Can I assume that _Mathematica_ always errs on the safe side when computing a precision? * * * _Update 2:_   Another (gross) example:               a = 2`6     (* 2.00000 *)          Derivative[0, 1][StieltjesGamma][0, a]     (* 0.324 *)          d // FullForm     (* 0.32399522609896337580027385456880978489`3.339102855094484 *)          Precision[d]     (* 3.3391 *)      Here, one would expect that at least `0.32` are correct digits. But in fact, the exact result is `1 - Pi^2/6` that is `-0.644934...`. No correct digits, even the sign is wrong.


title: Smooth out contour in RegionPlot/ContourPlot

text: I would like to smooth out the jagged edges in the outermost contours in the following plot: ![Plot with jagged edges.](http://i.stack.imgur.com/bSsYx.jpg) I have data of values as a function of variables (x,y) in the form               data = {{{x1,y1},z1},{{x2,y2},z2},...};      The figure is produced by               data = << "data.dat";     fnct = Interpolation[data];         RegionPlot[{fnct[x, y] > 2, fnct[x, y] > 100, fnct[x, y] > 140}, {x, 10^-2, 10^1}, {y, 0, 3},MaxRecursion->5]      The outer edges seem jagged I guess because the data is not very good there. I need to fit a smooth contour instead. I've looked at some other questions like Smoothing ListContourPlot contours but that uses ListContourPlot which for me takes ages and produces a bad result even for the original figure. Any help appreciated. The data can be found here: https://dl.dropboxusercontent.com/u/34796693/data.dat


title: Creating ODBC connection on mac

text: Iam not able to create a ODBC connection on mac through mathematica even though i have created a connection successfully through ODBC Administrator. The error message iam getting was: JDBC::error: ""File input/output error conHR10.properties java.io.FileNotFoundException: conHR10.properties.new (Read-only file system)". ## Problems in detail: My back end was microsoft sql server(2012) which was in a windows 8 machine. My front end was mathematica which was in MAC PRO(OS X 10.9.3). Iam trying to connect to my database through LAN. Iam able to make a connection in MAC using ODBC Administrator. But when i try to use the connection in mathematica the error above keeps coming.


title: How can I find the boundary function in RegionPlot?

text: I have a problem with finding the function that gives the boundary curve in `RegionPlot` comamnd. I use the following code to make the regions in which two inequalities are held simultaneously               RegionPlot[{{x^3 - y^2 > 2 y && x^2 + y^3 > 2 x },                  {x^3 - y^2 < 2 y && x^2 + y^3 > 2 x }}, {x, -1, 1}, {y, -1, .1},                 PlotStyle -> {Green, Yellow}, BoundaryStyle -> {Black, Thick}]      ![enter image description here](http://i.stack.imgur.com/s7XLJ.jpg) Here we see a black thick curve between the green and yellow regions, I mean the boundary that separates these regions (I showed it with a red arrow) . Now, how can I find its equation or at least the list of points living on this curve?


title: Conceal GUI source code

text: I'm working with a simple software application written in _Mathematica_ , composing of several .nb and .m files. The application is centered around a simple mathematica GUI, which includes several numerical input fields and selection options, and produces output graphs. What I wish to do is keep this GUI, but somehow hide the source code so that a user (who would access the machine remotely) cannot edit or see the algorithm producing the GUI. I know two potential options may be converting to .CDF or recompiling the mathematica code into C. I'm interested in any other possibilities, but I have two specific questions based on these options:   * Can I export multiple .m and .nb files into a single .CDF, and if so would there be any way to view the algorithms underlying the GUI?   * If I compile the mathematica code into C, would it still be able to produce a GUI?


title: Sketch-type graphics with transparency and dashed hidden lines?

text: I'd like to create transparent graphs like the following from P1095, _Calculus_ 6th Ed, by James Stewart. Can _Mathematica_ accomplish this? By "transparent," I mean the ability to see the interior, intersection, boundaries etc. preferrably with dashed hidden lines. ![enter image description here](http://i.stack.imgur.com/GL2Pl.jpg) Would someone please explain how to do this for a function like \begin{cases} (4 - z^2) = x^2 + y^2, 2 \le z \le 4 \\\ x^2 + y^2 = 4, -2 \le z \le 2 \end{cases} http://reference.wolfram.com/mathematica/howto/AddTransparencyToPlots.html doesn't appear to be very helpful in that respect.


title: Plotting solutions of differential equations with different parameters

text: I want to plot x[t], when i manipulate w from 0.1 to 1.5. Here is what I've attempted, which does not work as expected.               c = 0.05; f = 0.7;     diffeq = {x''[t] + c x'[t] + Sin[x[t]] + F Cos[w t] == 0};     inicond = {x'[0] == 0, x[0] == 1};     eqnlist = Join[diffeq, inicond];     soln := NDSolve[eqnlist, x, {t, 0, 10}]     Manipulate[                 Plot[Evaluate[{x[t] /.soln}, {t, 0, 10}], PlotRange ->All, AxesLabel-> {t, x}],                {w, 0.1, 1.5, 0.1}]      What is the appropriate way to plot the numerical solution of a differential equation while varying a parameter?


title: Animating moving surface of torus

text: I would like to try to recreate something similar to Paolo Čerić's torus animation: ![](http://www.thisiscolossal.com/wp-content/uploads/2013/01/3.gif) I have isolated the moving surface torus section form this Wolfram Demonstration by Kevin Sonnanburg:               t = s; s = .001; θ = 0; Manipulate[     Show[{ParametricPlot3D[{Cos[u] (3 + Cos[t]), Sin[u] (3 + Cos[t]),      Sin[t]}, {u, Cos[θ] s - .5 + a,      Cos[θ] s + .5 + a}, {t, Sin[θ] s - .5 + b,      Sin[θ] s + .5 + b}, PlotPoints -> 4, PlotStyle -> Red,      PerformanceGoal -> "Quality", PlotPoints -> 6, Axes -> None,      Boxed -> False, Mesh -> None, PlotRange -> 4],      ParametricPlot3D[{Cos[     a + v Cos[θ]] (3 + Cos[b + v Sin[θ]]),      Sin[a + v Cos[θ]] (3 + Cos[b + v Sin[θ]]),      Sin[b + v Sin[θ]]}, {v, 0, s}, PlotPoints -> 20]},      PlotRange -> 4, ImageSize -> {200, 200}, ViewAngle -> π/10],     {{a, π, "shift X"}, 0, 6 π},     {{b, π, "shift Y"}, 0, 6 π},     AutorunSequencing -> {2, 3, 4}, SaveDefinitions -> True]      and have tried to apply a texture to the section, and extend it over the whole torus, but haven't made as much progress as I'd hoped.


title: Exporting data extensions in fits file

text: **Context** In Astronomy the de facto standard for images and data is FITS. I would like to export heterogenous data sets into a single fits file. **Attempt** I am interested in exporting into a fits file some data, say.                dat = Table[i, {i, 5}]      (* {1,2,3,4,5} *) and additionally some metadata, say a range of $\nu$s:                rnus = ("nu" <> ToString[#] -> 0.5 + # & /@ ( Range[5]))      (* {nu1->1.5,nu2->2.5,nu3->3.5,nu4->4.5,nu5->5.5} *) Following closely the documentation I can write:                Export["image.fits", {"Data" -> dat,       "Metadata" -> Join[rnus, {"Object" -> "something"}]}, "Rules"]      (* image.fits *) and read back accordingly both the data:                Import["image.fits", "RawData"][[1]]      (* {1,2,3,4,5} *) and the metadata:                 "NU1" /. Import["image.fits", "Metadata"]       "OBJECT" /. Import["image.fits", "Metadata"]      (* 1.5 _) (_ Something *) BUT, what I would like to do is to write different (large) tables of different sizes into a single fits file. So using a single keyword for each element is unrealistic. If the table were of the same size I could join them into a single list, as in                  Export["image.fits", {"Data" -> {dat,dat}}, "Rules"]           but in my case the tables are not of the same size. In principle the documentation says _"For FITS files that contain multiple images or data extensions, the above elements are taken to be lists of the respective expressions."_ **Question** How can I write multiple images or data extensions into a unique fits file? Or in other words, what does the documentation mean? **Update** As requested, here is an example of fits with an extension containing {1,2,3,4,5} and {1,2,3,4,5,6} : > https://dl.dropboxusercontent.com/u/659996/test.fits or it can be produced in python as               python     import pyfits     import numpy     data=numpy.array([1.,2.,3.,4.,5.])     pyfits.writeto("test.fits",data)     data=numpy.array([1.,2.,3.,4.,5.,6.])     pyfits.append("test.fits",data)     exit


title: Solution of an ODE in implicit form

text: For some non-linear ODEs there is only implicit form of solution using DSolve. For example               DSolve[(y[x] + x - 1)*y'[x] - y[x] + 2 x + 3 == 0, y[x], x]      gives implicit solution               Solve[2/3 (Sqrt[2]ArcTan[(-2 + (2 (2 + 3 x))/(-1 + x + y[x]))/(2 Sqrt[2])]-Log[((-1 + x +y[x])^2 (3 + ((2 + 3 x) (-2 + (2 + 3 x)/(-1 + x +y[x])))/(-1 + x + y[x])))/(2 + 3 x)^2]) == C[1] + 4/3 Log[2 + 3 x], y[x]]      I'm solving a non-linear second-order ODE that has 4 explicit solutions. The formulas for these solutions are gigantic so I would like to see it in the implicit form because I hope it might be simpler. Is there a way how to show the implicit form of solution of ODE even though the equation has the explicit solution? (Just to be specific - the equation I'm solving reads               DSolve[(1 + G (A + y[x])^3) y''[x] + 3*G (A + y[x])^2 (y'[x])^2 + R == 0, y[x], x]      where $A,G,R \in \mathbb{R}$.) Thank you for any kind of help.


title: Slow work of TimeSeriesWindow

text: I have financial data (list of time-values pairs). There are more than `13000` elements.               data = FinancialData["KO", "OHLCV", {1000, 12, 31}];      I need extract from there some part of data which fall into the time interval. These parts are much. I use function `TimeSeriesWindow`, but it`s too slow. For example on this data               TimeSeriesWindow[data,{{2013,8,22},{2013,8,26}}];//AbsoluteTiming     (*{0.618035,Null}*)      Is the any faster function with the similar functionality? Or how do that operations fater?


title: What does ImageSize -> 1 -> 1 mean?

text: On the page http://www.wolfram.com/language/gallery/blur-faces-in-an-image/ the example code has `ImageSize -> 1 -> 1`. I am unfamiliar with this chaining of rules... What does it mean? Note I know what `ImageSize` does, it is the TWO arrows that I don't understand.


title: Plot FindRoot for non-trivial function

text: I would like to plot the results of FindRoot over certain range of inputs. I tried to do this with the code:               Plot[Evaluate[FindRoot[f[m, b], {m, 1}][[1, 2]]], {b, 0,2}]      where I want to plot the roots of f[m,b] vs. b ranging over [0,2]. I'm not sure this code is working, because although I do get a plot, I also get this error: > FindRoot::nlnum: "The function value > {1.[VeryThinSpace]-(2.\Gamma[2.,0.,(1.[VeryThinSpace]+1. > b)/Sqrt[b]])/(1.[VeryThinSpace]+1.\b)}\n is not a list of numbers with > dimensions {1} at {m} = {1.`}." Note the function I'm trying to find the roots for is:               f[M_, b_] := 1 - (2 M Gamma[2, 0, (1/M + b M)/Sqrt[b]])/(1/M + b M)      Thanks!


title: How to break graph to fill in the gap in pdf

text: I've printed my notebook into a pdf. There is a huge gap in the left page, due to the fact that the graph in the right page isn't divided to fill in the gap. Is there a way to fix it, preferably without resorting to do something like:               drawOrbits[deq1];     drawOrbits[deq2];     drawOrbits[deq3];      Currently, although it may not be evident, I'm doing something like:               drawOrbits /@ {deq1, deq2, deq3};      and show the result via Grid[]. ![enter image description here](http://i.stack.imgur.com/rlapx.png)


title: Implementing nested subtotals

text: Inserting a nested subtotal in a spreadsheet is a facility that Excel performs very well.   But if a subset of this facility can be implemented in MMA for a table which needs it the hassle of its export/import will be avoided.   As an example I have the following 3-columns matrix, the first two columns of which I want subtotals values for. The matrix was sorted so that the rows I want subtotaled are grouped together:.               data = {{Pi, A, 15}, {Pi, B, 20}, {Pi, B, 10}, {Pi, C, 20}, {Pi/2, A,      1}, {Pi/2, B, 2}, {Pi/2, B, 3}, {Pi/3, B, 10}}      And I want this result in separate matrix from the input data.               result = {{π, A, 15}, {π, B, 30}, {π, C, 20}, {π,      "∑", 65}, {π/2, A, 1}, {π/2, B, 5}, {π/2,      "∑", 6}, {π/3, B, 10}, {π/3, "∑",      10}, {"∑", "∑", 81}} // MatrixForm      ![Mathematica graphics](http://i.stack.imgur.com/N4aUr.png) I came up with a partial result,and what remains is too challenging for me (it is wrong to group results only on breaks in column 2.)               {#[[1, 1]], "∑", Total[#[[All, 3]]]} & /@ SplitBy[data, First] (* subtotals col1 *)     { "∑", "∑", Total[#[[All, 3]]]} & /@ {data} (*grand total *)      I would like to have a generalised answer, valid for more than two columns for subtotals as in the example I gave here.


title: StreamPlot for Bifurcation Diagram

text: When we do a `StreamPlot`, I want to show the bifurcation when $a = 0$ transitions to $a >0$, but do not see a better way to do this than the following.                   Animate[StreamPlot[{1,-x^4 + 5 a x^2-4 a^2}, {y,-5,5}, {x,-4,4},                             PlotLabel -> Row[{"a = ", a}]], {a,-1,1}]      Is there a better way to show this bifurcation? Maybe an animated gif like this Bifurcation diagrams for multiple equation systems) (this is a system and my example is not a system)? **Update** To be more clear, the original system is $$x'(y) = -(x(y))^4 + 5a(x(y))^2 - 4a^2$$


title: Why does a heavy background slow LocatorPane from updating, even if only the locators are Dynamic?

text: I'm having some trouble getting a dynamic plot to operate efficiently, and I think I've tracked down at least part of the problem to some pretty weird behaviour on the part of `LocatorPane`. Take two different image backgrounds, which can be quite similar except for their size on disk:               image1 = ContourPlot[x^2-y^2, {x, -1, 1}, {y, -1, 1}, ImageSize -> 250];          image2 = ContourPlot[x^2-y^2, {x, -1, 1}, {y, -1, 1}, ImageSize -> 250, PlotPoints -> 200];      where the `ByteCount` of `image2` is, in this case, about twenty times bigger than that of `image1`, and now use these images as the background for a `LocatorPane`:               point = {0.4, 0};     Row[{       LocatorPane[        Dynamic[point],        image2        ],       Dynamic[point]       }]      which produces something like this ![enter image description here](http://i.stack.imgur.com/FJw0e.gif) As you can see, the version with the heavier background is a huge lot more sluggish than the lighter one (though this is much more evident if you run it yourself). **Why is this?** Both occurrences of `point` are inside a `Dynamic` command but the background is not, so I don't really see a reason for the background of the pane to be re-loaded every time the locators are changed. More importantly, **how can this be avoided?** I have a byte-heavy background which I would like to only calculate once and then display without it slowing me down. I should also note that raster-based solutions will most likely prove unsatisfactory, particularly because I want to deploy a fair bit of information in the tooltips associated with the background contours.


title: Extract coefficients of differential form in package RGTC

text: I am using the Package RGTC to do some calculations in Supergravity. It allows to define differential forms after specifying a co-frame. I am working in with the 10d coordinates $\\{t,x,y,z,r,\phi_1,\ldots,\phi_5\\}$ and the coframe $\\{dt,dx,dy,dz,d\phi_1,\ldots,d\phi_5\\}$ and have the 5-form $F_5=-\frac{4L^2}{(1+\frac{L^4}{r^4})^2 r^5}\sqrt{R^4+r_0^4}(1+\star)dt\wedge dx\wedge dy\wedge dz\wedge dr$   where $R$ and $r_0$ are constants. Computing the Hodge dual in the expression is not a problem, since there is a function Hstar[_] in the package that does the job. What I need to compute is $F_{MPQRS}F_N{}^{PQRS}$, i.e. I need to extract the components from the differential form in order to perform the contractions. The actual code is a bit cryptic, because the space-time I am considering is a bit complicated, but I will include it anyways: J is the Jacobian for changing from Cartesian to spherical coordinates, xSugra my set of coordinates and g3branes the metric tensor               << EDCRGTCcode.m     J = D[{Cos[ϕ1], Sin[ϕ1] Cos[ϕ2],      Sin[ϕ1] Sin[ϕ2] Cos[ϕ3],      Sin[ϕ1] Sin[ϕ2] Sin[ϕ3] Cos[ϕ4],      Sin[ϕ1] Sin[ϕ2] Sin[ϕ3] Sin[ϕ4] Cos[ϕ5],      Sin[ϕ1] Sin[ϕ2] Sin[ϕ3] Sin[ϕ4]\     Sin[ϕ5]}, {{ϕ1, ϕ2, ϕ3, ϕ4, ϕ5}}];     H[r_] := 1 + L^4/r^4;     f[r_] := 1 - r0^4/r^4;     xSugra = {t, x, y, z, r, ϕ1, ϕ2, ϕ3, ϕ4, ϕ5};     coFrame = {d[t], d[x], d[y], d[z], d[r], d[ϕ1], d[ϕ2], d[ϕ3],     d[ϕ4], d[ϕ5]};     d[L] = 0; d[r0] = 0;     g3branes =      ArrayFlatten[{{H[r]^(-(1/2)) DiagonalMatrix[{-f[r], 1, 1, 1}], 0,       0}, {0, H[r]^(1/2)/f[r], 0}, {0, 0,       FullSimplify[H[r]^(1/2) r^2 Transpose[J].J]}}];     simpRules = TrigRules;     RGtensors[g3branes, xSugra, coFrame]     F5 = Simplify[-((4 L^2)/(H[r]^2 r^5)) Sqrt[     L^4 + r0^4] (d[t]⋀d[x]⋀d[y]⋀d[z]⋀d[r] +       HStar[d[t]⋀d[x]⋀d[y]⋀d[z]⋀d[r]])]      where I have not included output. Maybe I am lucky and there is someone who has worked with this package or a similar one before. Cheers, physicus


title: automatic coloring of function names

text: Usually, when I define a function and then use it later, the function name is colored in black. But every once in a while, the function color is blue, both in its definition and when I use it later. The blue colored functions work as expected. I can't find any difference in the way I define them or any pattern. What does the blue coloring mean?


title: Add Pattern to List Removing Duplicates

text: Lets say I have a list of patterns               p={       HoldPattern[f[x___]] :> {x},       HoldPattern[f[a_,b_]] :> {a,b},       HoldPattern[f[a_,a_]] :> {a,a},       HoldPattern[f[x_]] :>x     }       what is the most elegant way to add another pattern to the list while removing all duplicates? For example let's say I what to add `f[c_,d_]:>code` then `f[a_,b_]` should be mapped as a duplicate but not `f[a_,a_]`.


title: Assigning colors to Graphics3D objects from an ordered list

text: I'd like to draw a set of spheres with colors assigned from a defined set. To provide an example, say I wish to draw a set of three spheres of radius 2 at the positions: {{6, 5, 10}, {1, 4, 20}, {2, 4, 15}}. I might write:               pos = {{6, 5, 10}, {1, 4, 20}, {2, 4, 15}};     Graphics3D[{Sphere[pos, 2]}]      If I define an ordered set of colors for the three spheres, e.g. SphereColors={Red,Blue,Red}, how can I use this list to color the spheres as desired using Graphics3D?


title: Numbering nested list according with Depth (or Level)

text: (This question is slightly similar with _Sequentially numbering a nested list_, but not exactly the same.) # What I want Say I have a nested list               lst = {{"X", {{"X", "X"}, {{"X", "X"}, "X"}, "X"}, "X"}, "X", "X"};      What I would like to do is to label each `"X"` with a number according with its `Depth`/`Level`, that is something like this               {{{2,"X"},{{{4,"X"},{4,"X"}},{{{5,"X"},{5,"X"}},{4,"X"}},{3,"X"}},{2,"X"}},{1,"X"},{1,"X"}}      # What I tried I used a dumb way to achieve my goal. First I label each `"X"` with a unique label:               labelLst = lst /. "X" :> RandomReal[]      Then get their positions:               posSet = Position[labelLst, #][[1]] & /@ Flatten[labelLst]      Then label `"X"`s with its `Depth`:               ReplacePart[lst, Function[pos, pos -> {          Length[pos], lst[[##]] & @@ pos          }] /@ posSet]      # My question I think taking the aid of extra real-number labels is a bit cheating and inelegant, so I want to ask for a more elegant method for this. By saying _elegant_ , I'm thinking of something pure list-manipulations. Any idea would be helpful. * * * **Why I need this:** I'm trying to format the result of `Trace` for external plain-text viewer. Label numbers according with `Level`s eventually lead to human friendly indents.               Clear[levelIndentFunc]     levelIndentFunc[lst_] :=      Module[{labelLst, posSet},       labelLst = lst /. e_HoldForm :> RandomReal[];       posSet = Position[labelLst, #][[1]] & /@ Flatten[labelLst];       ReplacePart[lst, Function[pos, pos -> StringJoin[Flatten@{                 ConstantArray["\t", Length[pos] - 1],                 StringTake[                  ToString[lst[[##]] & @@ pos, InputForm], {10, -2}]                 }]] /@ posSet] // Flatten // Riffle[#, "\n"] & // StringJoin       ]      Example:               traceRes = Trace[Reduce[x^2 == -1, x], TraceInternal -> True, TraceDepth -> 3];     Export["tracePrintTest.txt", levelIndentFunc@traceRes, "String"]      Open _tracePrintTest.txt_ in external text viewer (here _Sublime Text_ with Mathematica syntax highlight plugin): ![traceprint](http://i.stack.imgur.com/z0lBh.png) **Edit:** With the help of Mr.Wizard's `MapIndexed` function, the formatting function `levelIndentFunc` can be simplified to               Clear[levelIndentFunc]     levelIndentFunc[lst_] :=      MapIndexed[         {ConstantArray["\t", Length[#2] - 1], #1, "\n"} &,         lst /. e_HoldForm :> StringTake[ToString[e, InputForm], {10, -2}],         {-1}] // Flatten // StringJoin


title: Finding real roots for an eigth-degree polynomial

text: The context for this problem is identical to my first question. Unfortunately my previous result for $L$ was inexact since it was a relatively simple approximation. This time I have managed to produce a very convincing approximation for $L$. Alike last time, solving for $W$ provides the $n$th solution if you find the $n$th root of a specific [octive] polynomial: $96x^8-192Lx^7+(768π^2 A^2+128L^2 ) x^6+(-64L^3-640A^2 π^2 L) x^5+(2655π^4 A^4-640L^2 π^2 A^2+32L^4 ) x^4+(384A^2 L^3 π^2-578A^4 Lπ^4 ) x^3+(4476π^6 A^6-2760L^2 π^4 A^4+128L^4 π^2 A^2 ) x^2+(456A^6 Lπ^6-278A^4 L^3 π^4 )x+(3136π^8 A^8-3700L^2 π^6 A^6+1089L^4 π^4 A^4 )=0$ Since my investigation is based on the assumption that there is only one value for $W$, given the values of $A$ and $L$, ergo there should only be two real roots (one should be the positive value for $W$ and the other should be the negative value for $W$.) My question is, can you find the positive real root for the eight order polynomial above?


title: About how Mathematica understands the branchcuts of the complex logarithm [Part 3]

text: One understands that for the function $\log(z^2+a^2)$ Mathematica implicitly puts the branch cuts to be starting at $\pm ia$ and going up/down respectively on the imaginary axis. The phase of this function approaches $i\pi$ on the right and above $ia$ and it approaches $-i\pi$ on the right and below $-ia$. Now I put in the following sequence of commands,               a = 2; y = 0.0000000001; d = y ;      z = I a + I y + d - I t;          Plot[ Im [ Log[z^2 + a^2] ], {t, 0, 5}]      I am trying to track the imaginary part of the function, `Log[z^2 +a^2]` as $z$ moves along a straight line parallel to and very close to the branch cuts of this function starting at $z=ia +iy + d$ (at $t=0$) to $z=-ia -iy +d$ (at $t= 2(y+a)$) One can see that the graph goes to $\pm 2.35619 $ at $t=0$ and at $t= 2(y+a)$ - Why? Shouldn't it be going toward $\pm \pi$ at these two values of $t$? (given that the imaginary part of the function $\log(z^2+a^2)$ approaches $\pm i\pi$ on the right and above/below $\pm ia$) * * * If I don't set a value for $d$ (the distance from the branchcut) and take the limit of $d \rightarrow 0$ at $t=0$ and $t=2(y+a)$ then Mathematica returns the expected values of $\pm \pi$ - but no matter how small a value of $d$ I fix (now independent of the value of $y$) the graphs still can't show the value of $\pi$ at $t=0$ though it gets the other end right.


title: How can I get a PieChart to be colored as I wish?

text: How to use the value of a funtion[label] to assign color to a piece of the pie? (edited after answer of kguler ) My dude is how to control the colors in ranges of a function of [labels] In this way I can show: 1.- the percentage of Data(labels), using pieces of pie and 2.- the value f of labels, with range colors (similar to TemperatureMap but customized) ![Use a funcion of Data-Labels to control the color os pieces](http://i.stack.imgur.com/CTHs3.jpg) \------ Original Post ------ I want to use a "gradient" or "a reduce (5-6) list of colors"(similar to DarkRainbow with a little colors)? I was trying with ColorData and ColorDataFunction ( here you can see that I obtain errors with the same code as the reference doc ) but I have no succes!!               percent = {12, 18, 24, 46}     labels = {1, 9, 15, 22}     f = {8, 7, 1, 4}     PieChart[percent, ChartLabels -> labels, ImageSize -> 200, PlotLabel -> "Test-Grad",  ChartStyle -> ColorData["TemperatureMap" {0, 8}]]     PieChart[percent, ChartLabels -> labels, ImageSize -> 200, PlotLabel -> "Test-Comic", ChartStyle -> ColorData[9, "ColorList"]]      In the image you can see any more about explanation: ![enter image description here](http://i.stack.imgur.com/HJCIR.jpg)


title: Get positions of all non zero matrix elements

text: I want to find all non zero elements of a table and I want to create a list that contains the name of the table the element was removed from, the position of the element, and the value of the element. Then to the generated list I would like to apply a replacment rule to the row and the column.               rule = {1 -> "a", 2 -> "b", 3 -> "c"}          { {tablename, row, col, value} }      For example I have tried               dataTable1 = {{1,0,0}, {0,1,0}, {0,0,-1}}           Position[Abs[dataTable1], # > 0 &]      but I am unable to get get the position. I would like the final out put to be                { {"dataTable1", 1,1,1}, {"dataTable1", 2,2,1}, {"dataTable1", 3,3,-1} }      If we apply the replacment.                 { {"dataTable1", 1,1,1}, {"dataTable1", 2,2,1}, {"dataTable1", 3,3,-1} } /. rule       Then the output should be                { {"dataTable1", "a","a",1}, {"dataTable1", "b","b",1}, {"dataTable1", "c","c",-1} }


title: Why TeXForm[] do not display to notebook if followed by OutputForm[] in same cell?

text: Can someone please explain to me the logic of this: In one cell, when writing               eq = D[y[x], x] + a*y[x] - b*Sin[c*x];     sol = DSolve[eq == 0, y[x], x];     TeXForm[sol]     OutputForm[TeXForm[sol]]      I see only the result of `OutputForm`: ![Mathematica graphics](http://i.stack.imgur.com/7iLnb.png) But in separate cells, then I see both outputs ![Mathematica graphics](http://i.stack.imgur.com/ps1kB.png) ps. I was trying to find how to remove the "\" at the end of the `OutputForm` compared to `TeXForm` output, and that is why I am doing the above, to compare the outputs. This happens on both V9 and 10. Should not both output show up, even if in the same cell?


title: How to get rid of the blank areas around alphabetical images?

text: I attempt to test the mean graylevels of the alphabets "W" and "Z". I used the following code to create the images of them.               imW = Rasterize@       Graphics[         Text[Style["W", 24, FontFamily -> "Helvetica",           TextAlignment -> Center, Antialiasing -> True], {0, 0}],         ImagePadding -> 0, ImageSize -> 24]          imZ = Rasterize@       Graphics[         Text[Style["Z", 24, FontFamily -> "Helvetica",           TextAlignment -> Center, Antialiasing -> True], {0, 0}],         ImagePadding -> 0, ImageSize -> 24]      However, there are blank areas around the images. How can I get rid of them? Is there a trim function built in for this purpose? ![enter image description here](http://i.stack.imgur.com/Grr5I.gif) I tried `ImageCrop[imW ]`, however, the top and bottom blanks still left. @kirma I did follow your suggestions, both increasing the `ImagePadding` to 20, and `ImagePad[img, -BorderDimensions[img]]`. Somehow, I still can't get rid of the top and bottom blanks. What I got was something like this: ![enter image description here](http://i.stack.imgur.com/2zVxo.gif)


title: I need to cite the same reference several times. Mathematica citation manager messes up

text: Mathematica cannot seem to properly number citations when there are several citations to the same reference. Is there some trick to make this work?


title: Data filtering using Butterworth filter

text: I want to filter data using Butterworth filter. I am currently using Matlab and I want to know how to do it in Mathematica. I have the following data:               data1 = Table[        PDF[NormalDistribution[3.5, .8], i] +          PDF[NormalDistribution[6, 1], i], {i, -5, 15, .01}];     noise = RandomReal /@ RandomReal[{-0.2, .2}, Length[data1]];     data2 = data1 + noise;      I filtered this data using Matlab as follows:               [b,a] = butter(8,0.04);          filtfilt(b,a,data2 );      In the previous question's answer, bill s suggested to do it as follows in Mathematica:               RecurrenceFilter[      ToDiscreteTimeModel[ButterworthFilterModel[{2, 0.04}], 1], data2      ]      The result is as follows: ![enter image description here](http://i.stack.imgur.com/9JyX7.jpg) The problem I am facing is whatever I change the filter order and frequency, I am not able to produce the same filtered data as I am getting from Matlab. Can someone suggest for me what to do and what values to use to get the same filtered data as I am getting from Matlab? Thanks


title: Evaluate differentiation after replacement

text: The problem is Find two linearly independent solutions of $2x^2y'' -xy' + (-4 x + 1)y = 0, \, x>0$ of the form $y_1 = x^{r_1}(1 + a_1 x + a_2 x^2 + a_3 x^3 + \cdots)$ and $y_2 = x^{r_2}(1 + b_1 x + b_2 x^2 + b_3 x^3 + \cdots)$. What I have done is below:               2 x^2*D[y, {x, 2}] - x D[y, x] + (-4 x + 1) y == 0 /. y -> x^r*(Sum[C[n]*x^n, {n, 0, 5}])      The result mathematica gave is               (1 - 4 x) x^r (C[0] + x C[1] + x^2 C[2] + x^3 C[3] + x^4 C[4] + x^5 C[5]) == 0      from which I conclude that `D[y,x]`is excuted before the replacement. How can I make `D[y,x]` excute after the replacement?


title: Why is Mathematica getting this modular root wrong?

text: First, note that $4^{96}\equiv96\ (mod\ 100)$. _Mathematica_ claims that `PowerMod[96, 1/96, 100]` has no integer solutions. Even more obviously wrong, I get `{}` for               Solve[4^96 == x^96, Modulus -> 100]      which obviously has at least one solution (4). Is this a known bug? Can I work around it somehow? EDIT: I'm on _Mathematica_ 9.0.1, running on OSX 10.10 Yosemite developer beta. Perhaps that could be the cause of this issue for me (also, mathematica crashes whenever I try to paste.).


title: Multiple Mathematica notebooks in a tabbed window with line numbers

text: I have the following questions: Is there a way to open multiple mathematica notebooks in tab group rather that each mathematica notebook opened in separate window? Is there a way to display line numbers in mathematica notebooks as line numbers are displayed in differnt text editors?


title: Change appearance of ConvexHullMesh

text: I'm struggling to understand the behaviour of `ConvexHullMesh` (or rather the non-behaviour). I have a polynom `p`               p = { {0, 0}, {1, 0}, {1/2, 1/2}, {1, 1}, {0, 1}}      which I can display in a nice way like by e.g.:               Show[Graphics[{LightBlue, EdgeForm[Gray], Polygon[p]}],  Graphics[ {PointSize[Large], Red, Point[#]}] & /@ p]      Now I construct the convex hull               q = ConvexHullMesh[p];      which displays a somewhat featureless rectangle. Having a closer look at `q`               q // InputForm      I get > BoundaryMeshRegion[{{0., 0.}, {0., 1.}, {1., 0.}, {1., 1.}}, {Line[{{1, 3}, > {3, 4}, {4, 2}, {2, 1}}]}, Method -> {"EliminateUnusedCoordinates" -> True, > DeleteDuplicateCoordinates" -> Automatic, "VertexAlias" -> Identity, > "CheckOrientation" -> True, "CoplanarityTolerance" -> Automatic, > "CheckIntersections" -> Automatic, "BoundaryNesting" -> {{0, 0}}, > "SeparateBoundaries" -> False, "PropagateMarkers" -> True, "Hash" -> > 1136472811504667718}] so the obvious (?) idea is to replace the head of `q` (i.e. `BoundaryMeshRegion`) by a suitably defined function `f` that uses the argument to display the convex hull in a 'nicer' way. Ignoring the exact implementation of `f`, the 'usual' way fails, as               f @@ q       just redisplays the rectangle. `Head[q]` gives the expected `BoundaryMeshRegion`, but `Apply` (or `@@`) somehow fails to replace the head. Similarly, the alternative `q[[1]]` to access the argument of the head fails. What am I missing? Or to be more precise:   * How do I change the appearance of `ConvexHullMesh`?   * Why does the above solution not work?


title: How can I track the execution time of an evaluating Manipulate cell?

text: In Wolfram's tutorial on Advanced Manipulate Functionality, a nice example of a continually evaluating `Manipulate` cell is presented:               Manipulate[       f[x_] := x^3;       Graphics[{Thickness[0.01], Line[{{0, 0}, {n, f[n]}}]},          PlotRange -> 1],       {n, -1, 1}]      If I wrap `Timing[]` around this example I get list of `0.` along with the continually evaluating `Manipulate` cell. Now can anybody make a clock that will show increasing time of evaluation of such a `Manipulate` cell? In case the `Manipulate` cell has finite execution time, the clock would show time elapsed for this execution. The motivation behind is to have measure of slow `Manipulate` cell execution.


title: How to create 'help' `?` for a function (as documentation)

text: I have defined a function `PassVeltB` in some complicated way. But now I would like to add a little documentation that gives the user information on how it is to be used. I know that the `?` symbol could be placed before a built-in function to generate useful information about that built-in function. Is there a way I can add helpful information about my `PassVeltB` function in a similar way?


title: A notebook created on demand from a main document showing executable input along with output cells

text: I would like to make _Mathematica_ documents with hidden calculations, such that they can be visualized on demand. In general it can be done in several forms and I actually use some. I would like to ask about one specific way of doing that. Namely, I would like to make a button incorporated into either inline or input cell. Upon pressing on this button a separate notebook should open containing the calculations. It is easy to make this, if the document only contains output cells. For instance, this               button1[expr_, sz_] := Button["Evaluate expression",        CreateDocument[expr, WindowSize -> {sz, sz}]];          button1[Expand[(x + y)^2], 300]      makes a button which opens the window with the result `x^2+2xy+y^2`. It is easy to make a notebook with a cell that can be later evaluated:               button2[expr_, sz_] := Button["Evaluate expression",        CreateDocument[         ExpressionCell[expr, "Input"],         WindowSize -> {sz, sz}]];     button2[Expand[(x + y)^2], 300]      but it also returns the already evaluated result. For whatever reason this:               SetAttributes[button2, HoldFirst];      does not help. One can also show the both unevaluated input and the output like this:               button3[expr_, sz_: 300] :=       Button["Show expression",        nb = CreateDocument[            {ExpressionCell[Unevaluated[expr], "Input"],            ExpressionCell[Button["Evaluate", Print@Evaluate[expr]],             "Input" ]},          WindowSize -> {sz, sz}          ]];     button3[Expand[(x + y)^2]]      However, I would like to get rid of the operator `Unevaluated` in the first cell. My aim is to get a separate notebook that is generated from the initial document. This notebook should have an input and the corresponding output cell (or cells), which a) shows how some result has been achieved in the past and what was this result and b) in which I could try to change something in the input cell(s) and see what would happen, while the source code lays somewhere unchanged. Thank you, Alexei


title: FindMaxValue vs FindMaximum

text: I'm studyng the maximum value of the following function               k = hbar^2*rhoc/(2*m)          Esf2[x1_?NumericQ, zeta_?NumericQ] :=          k*NIntegrate[(1. - r^2)*(Tanh[(1./zeta)*Sqrt[(4.*Log[2.] - 1.)/3.]*         Sqrt[(1. - x1^2) (Abs[r Sin[t]]^2 + (x1 - r Cos[t])^2)]]^2          Tanh[(1./ zeta)*Sqrt[(4.*Log[2.] - 1.)/3.]* Sqrt[(1. - x1^2)          (Abs[ r Sin[t]]^2 + (x1 + r Cos[t])^2)]]^2)*((4 x1^2 (-1. + x1^2)^2          (1. + r^4 + 2 r^2 Cos[2. t]))/((r^2 + x1^2 - 2 r x1 Cos[t])          (1. + r^2 x1^2 - 2 r x1 Cos[t])(r^2 + x1^2 + 2 r x1 Cos[t])          (1. + r^2 x1^2 + 2 r x1 Cos[t]))),         {r, 0., 1.}, {t, 0., 2.*Pi}]      with FindMaximum:               maxEvalue[zeta_?NumericQ] := FindMaximum[{Esf2[x1, zeta], 0 <= x1 < 1}, {x1, 0.02}]      The problem with FindMaximum is that it strongly depends on my starting point (in this case 0.02). For Example, if you run the following:               Do[Print[maxEwaarde[zeta]], {zeta, 0.01, 0.1, 0.01}]      you see that the maximum is always on the same x1 position. And if you plot the Esf function, you see that FindMaximum gives the wrong position!               zetac = 0.0311     Plot[Esf2[x1, zetac], {x1, -0.2, 0.2}, AxesOrigin -> Automatic]      When I use FindMaxValue, it looks like its giving me the right maximum, only now I can't study the evolution of the x position.               maxblabla[zeta_?NumericQ] := FindMaxValue[Esf2[x1, zeta], {x1, 0.001, 0.002}]     maxblabla[zetac]      Does somebody now what I am doin wrong with FindMaximum? Or how i can get FindMaxValue to give me the x position? Thanks a lot!!!


title: Limit of a subsequence

text: I am trying to calculate limit for a subsequence <${ a }_{ {n }^{ 2} }$> because I was trying to see that limits of sequences and subsequences are both same. I was able to generate the sum for square values as,               N[ Sum[ 1/(n (n + 1)), {n, Table[n^2, {n, 1, 1000}]}]]      But I want to know how I shall find limit to a subsequence of square integers.


title: Defining a non-commutative operator algebra in Mathematica

text: I am trying to develop a function(s) to do some commutator algebra to compute the enveloping algebra and ideals of a Lie algebra. For example if I have $SU(2)$ algebra generated by $L_i$ ($i=1,2,3$), I would like to evaluate commutators between polynomials of type $L_1^mL_2^nL_3^p$ where $m,n,p$ are integers. Now I think I should start by defining a commutator function as a mapping which is: (a) antisymmetric, (b) is a derivation (Leibniz property), and (c) satisfies Jacobi identity. Since I do not want to plug in explicit realizations for the operators, defining commutator $[A,B] = AB - BA = C$ would not really help. I want to define commutator as a rule which would just assign $[A,B] \rightarrow C$ and when computing $[A,BC] \rightarrow [A,B]C + B[A,C]$ and so on. I tried by defining something with Leibniz property as follows:               Comm[a_**b_, c_**d_] := a**Comm[b, c]**d + a**c**Comm[b, d] + Comm[a, c]**d**b +                              c**Comm[a, d]**b;      This works fine for evaluating $[a,bcd]$ but it doesn't do anything to $[abc,d]$ for example. So I am wondering what should I do to correctly define this and how would I go about to define this mapping with the desired properties.


title: How to find a particular solution using NDSolve

text: I'm looking for a way to find a specific solution to a differential equation. As a simplified version of my problem, here's a similar setup for a simple harmonic oscillator problem.               aargh =        NDSolve[{        -0.000000000001 + q''[x] == -q[x],         q'[π] == q'[-π], q[-π] == q[π]},         q, {x, -π, π}];     Plot[Evaluate[q[x] /. aargh], {x, -π, π}]      The reason for the 0.00000000001 is to perturb the system slightly to ensure that I get a nonzero solution. This gives a beautiful harmonic function as a solution. Now, what I want to do, is specify a starting trial solution for `NDSolve` to look around. For example, say I wanted to find the $\sin(x)$ solution to the differential equation. Is there any way by which I can specify this and ask _Mathematica_ to look around a particular function for my solution. My actual problem is far more complicated, but is essentially the same. It is also homogenous, so I've added a perturbation there as well to find the non zero solution. Once again, _Mathematica_ is returning an approximately valid solution, but I know that there exists another solution somewhere else. How do I tell _Mathematica_ to look there?


How to let output and message be print to two separate external files? Also, I'd like the content print out to have similar look as when it's print inside the notebook, i.e. it should be in OutputForm or whatever proper form.


title: How to extract expression from ConditionalExpression

text: p1 := y /. {First[Solve[x^2 + y^2 + x == 1, y, Reals]]}      > >     {ConditionalExpression[-Sqrt[1 - x - x^2], >        1/2 (-1 - Sqrt[5]) < x < 1/2 (-1 + Sqrt[5])]} >   I want to get the `-Sqrt[1 - x - x^2]` out of the conditional expression and assign it to a variable. I don't care about the conditions, I'm aware of them and need the expression for use out of the `ConditionalExpression`. How do I do that? I tried list commands combinations (`Flatten`, `First`, etc.) but they don't work with this. Am I just supposed to copy-paste?


title: How to obtain a function from a implicit equation?

text: I have               (60 - r/2) (70 - ca - r/2) - (60 - r/2 - ca + (4/25) (70 - r/2 - ca))*(70 - r/2)==0     Reduce[%, {ca}]      But How could I obtain directly a function as ca[r_] :=...?


title: Create Table of replacement rules

text: I want to create a table of replacement rules.               g[a_, b_] := a -> b          t1 = Table[10 i + j, {i, 5}, {j, 3}]     t2 =  Table[ i + j, {i, 5}, {j, 3}]           g[  # & @@@ t1, # & @@@ t2 ]      The correct output is below:               {{11 -> 2, 12 -> 3, 13 -> 4},      {21 -> 3, 22 -> 4, 23 -> 5},      {31 -> 4, 32 -> 5, 33 -> 6},      {41 -> 5, 42 -> 6, 43 -> 7},      {51 -> 6, 52 -> 7, 53 -> 8}}      Instead I am getting:                 {11, 21, 31, 41, 51} -> {2, 3, 4, 5, 6}      Which shows two concepts I am still trying to wrap my mind around how to accomplish in _Mathematica_. In a 2-d list how to you select each row, and then perform an operation on each element of that row ( in this case take that element and make a rule replacment a -> b). Then iterate through every row.


title: efficient way to give nearest neighbour and next nearest neighbour of every point in a point set

text: Suppose we have a point set, the points are labeled 1,2,3,....n. And `p[i]` is the coordinate of the point. Now I want the label of nearest and next nearest point (maybe several) corresponding every point in this point set. For example:               p[1] = {0, 0};     p[2] = {0, 1};     p[3] = {1, 0};     p[4] = {0, 5};      and I want a list for nearest neighbour like this:               {{2, 3}, {1}, {1}, {2}}      it means that `p[2]` and `p[3]` is nearest to `p[1]`, `p[1]` is nearest to `p[2]`, etc. And I need a similar next nearest neighbour list. I write the following code:               num = 5000;     Do[p[i] = RandomInteger[{1, 100}, 2], {i, 1, num}];          coolist = Table[p[i], {i, 1, num}];          Clear[position];     position[expr_] :=        With[{positionData =           SortBy[#[[1, 1]] -> #[[All, 2]] & /@              GatherBy[              Extract[expr, #, Verbatim] -> # & /@                Position[expr, _, Depth[expr]], First],             Min[Length /@ #[[2]]] &] // Dispatch},         Replace[#, positionData] &];          poscoolist = position[coolist];          Clear[nnsite];     nnsite[k_, coolist_] := Module[{nncoolist},        nncoolist = Nearest[Complement[coolist, {p[k]}], p[k]];        Flatten@         Table[poscoolist[nncoolist[[i]]], {i, 1, Length[nncoolist]}]];          nearestlist = Table[nnsite[i, coolist], {i, 1, num}]; // AbsoluteTiming          Clear[nnlabel];     Thread[Evaluate@Array[nnlabel, num] = nearestlist];          Clear[nnnsite];     nnnsite[k_, coolist_] := Module[{nnncoolist},        nnncoolist =          Nearest[Complement[           Delete[coolist, Partition[nnlabel[k], 1]], {p[k]}], p[k]];        Flatten@         Table[poscoolist[nnncoolist[[i]]], {i, 1, Length[nnncoolist]}]];          nextnearestlist =         Table[nnnsite[i, coolist], {i, 1, num}]; // AbsoluteTiming      the function `position` in the above code is provide by Mr.Wizard (see here). `nearestlist` and `nextnearestlist` give the result. Notice to use my code, supply every coordinate p[i] of points. For 5000 points, it takes 1 minutes. But for 10000 points, it takes 6 minutes. Quite long! I feel that my code is so simple, there must be better ways that are more efficient.


title: Extracting data values from a plot

text: I found that the fact is very useful that a plot sometimes contains all the original data needed to reconstruct that plot. This is very helpful for me because sometimes I need to retrieve and analysis the numerical data in plots I produced in the past. It's much easier for me(in the sense of organization of projects) to just save the plots in notebooks rather than save the numerical data in some separated files. For example:               data1 = {{1., 2.}, {2., 3.}, {3., 1.}};     pic1 = ListPlot[data1, Joined -> True]      ![enter image description here](http://i.stack.imgur.com/0hqvW.png) I can get the data back using               Cases[pic1, Line[x__] -> x, ∞]     (* {{{1., 2.}, {2., 3.}, {3., 1.}}} *)      This works great most of the time, but sometimes when I specified a plot range, some data are lost:               data2 = Table[{x, Cos[x]^2}, {x, -π/2, π/2, π/8}] // N;     ListPlot[data2, Joined -> True]     pic2 = ListPlot[data2, PlotRange -> {{0, 1.5}, {0, 0.5}}, Joined -> True]      ![enter image description here](http://i.stack.imgur.com/D9K9y.png) ![enter image description here](http://i.stack.imgur.com/aqUzt.png)               Graphics[Cases[pic2, _Line, ∞], AspectRatio -> 1/GoldenRatio, Axes -> True]      ![enter image description here](http://i.stack.imgur.com/fsVg8.png) Note that the data are lost only at the vertical direction. So are there ways to tell Mathematica to save all the data into the plot?


title: Import Excel data forcing links (ie workbooks) to be updated

text: We have noticed importing data from an Excel spreadsheet doesn’t update links. The problem with this is if you import a spreadsheet that comprises of linked workbooks data and those workbooks have been updated then stale data is retrieved. ![enter image description here](http://i.stack.imgur.com/SFHa6.png) Opening workbooks using the Excel Object Model does support a parameter to UpdateLinks. ![enter image description here](http://i.stack.imgur.com/kpJUf.png) Is there an undocumented way to force Mathematica to open spreadsheets and update the links?               Import["c:\\temp\\Exercises.xlsx",{"Sheets","Sheet1"}][[1;;18;;1, 1;;16;;1]];


title: ScientificForm problem

text: Consider this code:               ScientificForm[1., 8, NumberFormat -> (Row[If[#3 == "", {#1, "E", 0}, {#1, "E", #3}]] &)]     (* 1.E0 *)          ToString@ScientificForm[1., 8, NumberFormat -> (Row[If[#3 == "", {#1, "E", 0}, {#1, "E", #3}]] &)]     (* 1.E0E0 *)      Why is there an extra "E0" in the second output?


title: Editable keyframe curves

text: Any suggestions for a good approach to implementing a zoomable 'keyframe' based curve editor? Essentially, something akin to the functionality of the graph editor in animation packages such as Maya. (see here). I can see how to get started on something simple using Locators, but the ability to zoom and pan on long time ranges is something that looks tricky to me, and I suspect starting out with the right concept in the first place will save a lot of headaches...any ideas much appreciated.


title: How to combine notebook into one cell

text: I want to have my entire notebook be a conditional while statement. However, I don't want to merge all of my cells together, as it is a long and detailed process. Is there a way to create another cell that encompasses all of the smaller cells in my notebook?


title: Is it possible to plot a function using Plot3D and a curve using ParametricPlot3D in the same picture?

text: I'd like to plot a graph of a function using e.g. `Plot3D` and then a line (in general a curve, in my case a straight line, tangent at some point to the surface just drawn), using e.g. `ParametricPlot3D` _in the same picture_. Is it possible? If yes, how?


title: How can I set the tick marks of the x axis in RectangleChart?

text: By default, the x-axis in `RectangleChart` is not labeled. Using `Axis -> {True, True}` does not help. Can I set the ticks manually?


title: Is there possibility of exporting mathematica code directly into Latex?

text: I'm novice very user of Mathematica - is there possibility of exporting mathematica code directly into Latex - I'm interested only in exporting mathematical formulas ? And from which version of program is it possible ?


I have a question about using a recursive function in a module. I made the following example to illustrate the question. The followwing code works:               Clear[fib]     fib[1] = 1;     fib[2] = 1;     fib[n_] := fib[n - 1] + fib[n - 2]     f[a_, b_, n_] := Module[{x, y},     fib[1] = a;     fib[2] = b;     x = fib[n];     Print[x];     fib[1] = 2 a;     fib[2] = 2 b;     y = fib[n];     Print[y];     x + y     ]     f[1, 1, 3] = 6.      but is slow, I want to use memoization, i.e.               fib[n_] := fib[n] = fib[n - 1] + fib[n - 2]       but in that case               f[1, 1, 3] = 4.       **Question: How can I use a recursive function in a Module?**


title: Evaluating an ItoProcesss function

text: The following is my Stochastic D.E.:               proc = ItoProcess[{\[DifferentialD]n[t] ==          sigma*Sqrt[(2*Um)/(Pi*L)]*\[DifferentialD]w[             t] - (\[DifferentialD]t*(Um*n[t]))/L}, n[t], {n, 1}, t,           Distributed[w, WienerProcess[]]]      I would like to find the value of `n[0.1]`. Can someone kindly guide me as to how I can do so? Thanks!


title: Solving recurrence sequence using an ODE

text: I'm trying to solve the recurrence               a[n] == 0 for n < l     a[l] == 1     a[n] == (l + 2(n - l) a[n - l] + (n - l)(n - 1) a[n - 1])/n(n - l + 1) for n >= l      using the ODE               l = 2;     DSolve[(x^2 y''[x] + (2 - l) x y[x]) (x - 1) + 2 x^(l + 1) y'[x] + (l x^l)/(1 - x) == 0,        y[x], x]      For `l = 2` it works, but not for `l > 2`. Is it possible to do it? Maybe there is another way to solve this recurrence ?


title: ListPlot3D of a set of points in a non-convex region

text: I would like to plot a set of points in the same style as `ListPlot3D` does, but only in a non-convex region that I can specify (e.g. using a `RegionFunction`). Is there a simple solution for this? Let me illustrate with an example. Let's generate some sample points ...               Clear[regionFun]     regionFun[{x_, y_}] := y < x^2          fun[{x_, y_}] := -Norm[{x, y} - {.5, .5}]          pts = Select[Tuples[Range[0, 1, 0.01], 2], regionFun];      ... and try to plot then in the region we're interested in:               ListPlot3D[      Append[#, fun[#]] & /@ pts,      RegionFunction -> Function[{x, y}, regionFun[{x, y}]],      InterpolationOrder -> 1     ]      ![enter image description here](http://i.stack.imgur.com/HJoc1.png) Notice that the plot occupies the complete convex hull of the points because of how the Delaunay triangulation was constructed for the interpolation. What I would like to see instead is this:               Plot3D[fun[{x, y}], {x, 0, 1}, {y, 0, 1},       RegionFunction -> Function[{x, y}, regionFun[{x, y}]]]      ![enter image description here](http://i.stack.imgur.com/NyhSR.png) The only possible solution I see at the moment is to use an external tool to "manually" construct a Delaunay triangulation which is confined within a region and build the plot from that data. This, however, is a lot of work, so I thought I'd ask first if there's a simple solution. Note that this is just a generated example dataset, not my real data. I can't use `Plot3D` for my real application, only `ListPlot3D` and related functions.


title: How to draw a tangent to a surface in a given direction?

text: It seems quite embarrassing for me, but somehow I can't draw a tangent line to a surface in a given direction. Assume that I want to visualize directional derivative of the function, say, $(x,y)\mapsto x^2+y^2$, at the point, say, $(1,0.5)$. I tried this:               F[x_, y_] := x^2 + y^2          Manipulate[      Show[{Plot3D[F[x, y], {x, -2, 2}, {y, -2, 2}]},           {ParametricPlot3D[{Cos[phi]*t,Sin[phi]*t,              ((D[F[x, y], x] /. x -> 1 /. y -> 0.5)*Cos[phi]              + (D[F[x, y], y] /. x -> 1 /. y -> 0.5)*Sin[phi])*t},           {t, 0, 2}, PlotStyle -> Thick]}], {phi, 0, 2*Pi, Pi/4}]      to no avail. (I am a bit afraid that I did make some stupid _mathematical_ error; unfortunately, Mathematica's syntax is a bit "perlish" to me: I'm learning to write in it, but have serious difficulties reading it...) My question is twofold: (1) what is wrong with the above code and (2) what is a "canonical" (read: elegant and possibly fast) way of doing this?


title: How to get monomials multiplied by each other?

text: Suppose `Subscript[x, #] & /@ {1, 3, 7}` that returns `{x_1,x_3,x_7}`. Now how can I get `x_1x_3x_7`? **Tried it already**... > ![enter image description here](http://i.stack.imgur.com/sNyDN.png) _P.s. I am trying to understandthis thread deeper about converting binary mlfs to mlfs._


title: Conversion of binary matrix of mlf into multilinear function, any ready function for this?

text: I convert here only one term $x_1x_3x_7$ from the binary matrix by first getting the reversed binary 1010001 and then miggling with the data. I know I could convert the columns into binaries and then use solutions here but I feel there must be something builtin: I am trying to convert binary form of multilinear function simply to its symbolic form where the MLF is expressed as a matrix below.. > **Is there anything built in to convert the binary matrix into the > corresponding multilinear function?** **Input** > ![enter image description here](http://i.stack.imgur.com/1YkK8.png) **Intended output** > > $x_1x_3x_7+x_1x_3x_5x_6+x_1x_4x_7+x_1x_4x_5x_6-x_2x_3x_7-x_2x_3x_5x_6-x_2x_4x_7-x_2x_4x_5x_6$


title: Already solved DE, now I need to rearrange and plot

text: I have solved for $z(w,x,y)$ in a differential equation: $$ 3\frac{\partial z}{\partial y} = 2(z-1) + (1-wy^2 )x $$ And I obtained the general solution: $z = f(w,x,y)$ Now putting in $x=0$, we have $z_0 = f(w,0,y) = g(w,y)$ Then I am trying to solve for $x^*(w,y)$ this final equation and contour plot it: $$ f(w,x^*,y) = 2.7 \times g(w,y)$$ I've managed to obtain $f(w,x,y)$ and $g(w,y)$, which should be the hardest part. Then I'm not sure why the last part of the code is not working, as the last part should be rather straightforward.               pde1 = 3*D[z[w, x, y], y]  == 2 (z[w, x, y] - 1)  + (1 - y^2 w) x     soln1 = DSolve[pde1, z[w, x, y], {w, x, y}]     soln5 = soln1 /. {x -> 0}     eqn1 = soln5  == 2.7*soln1     ContourPlot[      x /. Solve[eqn1, x, Method -> Reduce], {w, 1, 5}, {y, 1, 5},       PlotRange -> All]


title: Cell format for screen headers

text: If one picks the menu option Format->Edit Stylesheet and then one opens the "Default.nb" link, the newly opened notebook has a header that reads "Deafult.nb" style definitions. In one navigates down in the page, that header stays in place. However, none of the header styles defined in Default.nb produce that specific header. What is the style to produce that type of static header? What are the menu commands (if any) to dock cells?


title: How do you put a plot inside a popupmenu that is inside another popupmenu?

text: I have the next code                Manipulate[          Switch[x, a, If[selection =!= None, selection = None], b,              If[selection === None, selection = None], c,              If[selection === None, selection = "Hola"]      ];      selection, {x, {a, b, c}, ControlType -> PopupMenu},        {{selection, None},           Switch[x, a, {"recta", "parabola"}, b, {"hiperbola", "absoluto"},           c, {"Seno", "Coseno"}], ControlType -> PopupMenu}      ]      but I need you to choose the second popupmenu I plot the function chosen.


title: Kinect on Mathematica

text: I saw on the internet a lot of nice experiments with Microsoft Kinect. I just bought one and would like to know if someone here has been able to use it with Mathematica. The main idea is to been able to use it as another controller device. So you could get it state using `Dynamic@ControllerState` Mathematica command. In some way, it's necessary to install a driver that make this possible. I installed zigfu and synapse-kinect on my mac (see links below). They demo worked just nice, but no additional device appeared on my Mathematica. You can list connected devices using the `ControllerInformation[]` command. ![enter image description here](http://i.stack.imgur.com/iq2ld.png) Here are some links with potential starting points, as suggested in the comments: http://zigfu.com/en/downloads/browserplugin/ http://www.shiffman.net/p5/kinect/ http://developkinect.com/resource/application/synapse-kinect http://glovepie.org/forum/viewforum.php?f=32


title: Implementation of Decompose

text: I'm curious as to how `Decompose` works so I decided to use `Trace` with the option `TraceInternal -> True`. For `NextPrime`, this works well:               AppendTo[$ContextPath, "NumberTheory`NextPrimeDump`"];     Trace[NextPrime[45],TraceInternal->True]          {NextPrime[45],     {Block[{res},res=integerNextPrime[45];RuleCondition[res,IntegerQ[res]]],     {res=integerNextPrime[45];RuleCondition[res,IntegerQ[res]],     {{integerNextPrime[45],{Block[{res},res=45+1+Mod[45,2];     While[!PrimeQ[res],res+=2];RuleCondition[res,IntegerQ[res]]],     {res=45+1+Mod[45,2];While[!PrimeQ[res],res+=2];RuleCondition[res,IntegerQ[res]],     {{{Mod[45,2],1},45+1+1,47},res=47,47},{While[!PrimeQ[res],res+=2],     {{{res,47},PrimeQ[47],True},!True,False},Null},     {{{res,47},IntegerQ[47],True},RuleCondition[res,True],res,47},47},47},47},res=47,47},     {{{res,47},IntegerQ[47],True},RuleCondition[res,True],res,47},47},47},47}      Above, we can see some code and get an idea of how `NextPrime` works. But when I do this with `Decompose` I get something weird:               With[{p = Expand[(x^2+x+1)^2+2(x^2+x+1)+1]},       Trace[Decompose[p, x], TraceInternal -> True]     ]          {Decompose[4+4 x+5 x^2+2 x^3+x^4,x],{BitAnd[29,8],BitAnd[8,29],8},     {BitAnd[29,4],BitAnd[4,29],4},{BitAnd[29,2],BitAnd[2,29],0},     {BitAnd[29,1],BitAnd[1,29],1},{BitAnd[14,4],BitAnd[4,14],4},     {BitAnd[14,2],BitAnd[2,14],2},{BitAnd[14,1],BitAnd[1,14],0},     {BitAnd[31,8],BitAnd[8,31],8},{BitAnd[31,4],BitAnd[4,31],4},     {BitAnd[31,2],BitAnd[2,31],2},{BitAnd[31,1],BitAnd[1,31],1},     ....,     {4+4 x+x^2,x+x^2}}      Is there any way to tell where these bitwise ANDs are coming from? Isn't `TraceInternal` supposed to show all workings during an execution?


title: Highlighting bracketing in Mathematica

text: I'm working with lists of lists of lists. Each box with information has a specific format like                 information = {{a},{{b}},{{{c},{d}},{e,{f}}},{g}}      and so together they look like                 {{{a},{{b}},{{{c},{d}},{e,{f}}},{g}},{{h},{{i}},{{{j},{k}},{l,{m}}},{n}},...      and this goes over the whole screen. I want to make the inner and outer brackets in an expression like **{{** a **}}** look different, possibly down to all levels. Is there a way to highlight the bracketing in such a way that I can _see_ the different levels of the list?


title: Creating a Dynamic MSSQL connection

text: Hello i am trying to create a notebook that automatically connects to a database on MSSQL server and would then query this to create a sort of personal report. I have connected to this database and run a few queries ok but i am having trouble with getting it to load when i open the notebook.               Needs["DatabaseLink`"];     Dynamic[         conn=OpenSQLConnection["TSQL2012"]]          myOrder =SQLExecute[Dynamic[conn], "select custid, shipcountry from Sales.Orders where orderid = '10248'", "ShowColumnHeadings" ->True] //TableForm      I have been trying code such as the above but i think the Dynamic connection is trying to open to many connections to the database and then it crashes. Running the code above without the Dynamic elements in place works fine. is there a way to connect to DB when a notebook is opened and use this in SQLExecute statements?


title: Why doesn't FullSimplify get rid of the common factor in this expression?

text: `FullSimplify` does not get rid of the `z` factor in the following expression:               FullSimplify[(E^(-I x) y z + (1 + E^(I y)) (x + y) z)/z, z != 0]      Upon removing a single piece of the expression, such as the first `y` factor or the `1+` in the brackets, the simplification suddenly succeeds. As far as I can tell it is only this special combination of variables that fails. Is there any obvious problem with simplifying this?   Is there a way to tweak the `FullSimplify` function to make it succeed? (this is just a part of a longer expression - and I want to avoid looking for such problems manually). I'm using _Mathematica_ version 9.0.0.0 on Win7 64 bit.


title: Nonsense Data with Wolfram Alpha + Mathematica?

text: I am trying to learn how to interface with WolframAlpha. When I try using the Mathematica interface I get nonsensical data. I don't know if this is a bug or if I'm doing it wrong. My goal is to extract the elevation around the Austrian Province of Upper Austria. Perhaps to assert that Upper Austria is not actually the highest Austrian province, if this doesn't work I will attempt to challenge the status of Lower Austria. My Wolfram Alpha reference query is:               http://www.wolframalpha.com/input/?i=average+elevation+around+upper+austria+Austria      My Mathematica code is:               WolframAlpha["average elevation around Upper Austria, Austria \     (state)", {{"ElevationStatistics", 1}, "ComputableData"}]      which gives               {{"average", -(27896275/24384)}, {"lowest", -(3662500/        381)}, {"highest", 2585000/381}}      which can't be right by any measure. What's going on?


title: Represent Plot Scale with an offset

text: I want to know how to represent the axis on my 3dplot with a scaled offset. Please see the image below, I just want to show in the plot as {X-Axis*0.1} and {Y-Axis*0.1} ... ![enter image description here](http://i.stack.imgur.com/vKEnC.png)


title: Speeding up trigonometric integral

text: **Context** On a possible non trivial toric topology for the Universe (nothing less!). **Problem** I would like to carry out the following integral for $\ell=2,4\cdots 20$. $$\int _0^{\pi }\int _0^{2 \pi } \sin(\theta ) P_{\ell }\left(\frac{1}{2} \sin(\theta ) (\cos(\phi )-\sin(\phi ))\right) P_{\ell }\left(\frac{1}{2} \sin(\theta ) (\cos(\phi )+\sin (\phi ))\right) \times $$ $$P_{\ell }\left(\frac{\sin (\theta ) ((K+1) \cos (\phi )+(1-K) \sin (\phi ))}{2 \sqrt{K^2+2 \mu K+1}}\right)d\phi d\theta$$ where $P_\ell$ are Legendre Polynomials. For $\ell$ larger than say 8, _Mathematica_ takes forever and runs out of memory. I have found out a method to circumvent the memory problem (see attempt below) but it still takes very long time to carry out the integration for $\ell>10$. **Question** Is there a way to be smart about this class of integral? Another approach to the one below? **Attempt** I have defined the integrant as               integ[ℓ_] :=       LegendreP[ℓ, (Cos[p] - Sin[p]) Sin[t]/          2] LegendreP[ℓ, (Cos[p] + Sin[p]) Sin[t]/          2] LegendreP[ℓ, ((1 + K) Cos[p] + (1 - K) Sin[p]) Sin[            t]/2/Sqrt[1 + 2 K μ + K^2]] Sin[t]      And the following integration rule:               r1 = {Exp[ Complex[0, b_] t +  p Complex[0, c_] ] ->         Integrate[Exp[ I b  t + I c p], {t, 0, Pi}, {a, 0, 2 Pi}],       Exp[ Complex[0, b_] t ] ->         Integrate[Exp[ I b  t], {t, 0, Pi}, {a, 0, 2 Pi}],       Exp[   p Complex[0, c_] ] ->         Integrate[Exp[ I c p], {t, 0, Pi}, {a, 0, 2 Pi}]}      so that I expand my integrant into sines and cosines into complex exponentials, and carry out the integration via substitution:                  integ[2] // TrigToExp // Expand //             Collect[#, Exp[_]] & // (# /. r1) & // Apart // Simplify           (*-((Pi*(43*K^2 + 84*K*μ + 43))/       (560*(K^2 + 2*K*μ + 1))) *)      A simple timing               Table[{i, integ[i] // TrigToExp // Expand //                       Collect[#, Exp[_]] & // (# /. r1) & // Apart //         Simplify;//Timing}, {i, 2, 6,2}]      suggest a $n^{4.5}$ scaling.


title: Replace elements in list not matching elements of another list at the same position

text: I would like to compare two arrays:               m = {a,b,c,d,d,f};     n = {b,b,a,d,d,e};      and get:               {0,b,0,d,d,0}      I have tried all kinds of things, like:               m = {a,b,c,d,d,f};     n = {b,b,a,d,d,e};     Transpose[{m, n}];     If[{x_ == y_} :> x, 0]      but clearly, I have no idea what I am doing! I am (obviously) very new to _Mathematica_ , and would greatly appreciate any help.


title: How to copy/paste an OverHat symbol into Microsoft Word 2010 properly?

text: I have problem with output traditional form of sign above the constant. When I copy/paste in word it is far away up. Is there solution for this?                BB /: MakeBoxes[BB[n_], TraditionalForm] :=       RowBox[{SubscriptBox["\!\(\*      StyleBox[OverscriptBox[      StyleBox[\"A\",\nFontFamily->\"Times New Roman\",\n\      FontWeight->\"Plain\",\nFontSlant->\"Italic\"], \"^\"],\nFontFamily\      ->\"Times New Roman\",\nFontWeight->\"Plain\",\nFontSlant->\"Italic\"\       ]\)", RowBox[{Sequence @@         Riffle[Table["\!\(\*SubscriptBox[\(c\), \(1\)]\)", {1}], 2]}]]}]          BB[1] // TraditionalForm     BB[2] // TraditionalForm


title: Showing a forest with root of the trees on the top

text: I have a Graph object that contains a forest with directed trees. I want to draw the forest such that the root of the trees are on the top and the leaves are on the bottom. If I use the following line of code:               Graph[{1, 2, 3, 4, 5, 6, 7}, {1 \[DirectedEdge] 2,        2 \[DirectedEdge] 3, 4 \[DirectedEdge] 6, 5 \[DirectedEdge] 6,        7 \[DirectedEdge] 4}, VertexLabels -> "Name",       GraphLayout -> "LayeredDrawing"]      I get this image: ![forest](http://i.stack.imgur.com/XSARB.png) Everything looks fine except the root (#3) is not on top. How can I resolve the issue?


title: Working of Date[]

text: `Date[]` returns the current date of local system, `Date[1]` returns {2012, 11, 15, 17, 41, 0.3161629}, `Date[2]` returns {2012, 11, 15, 18, 41, 0.3161629}, and `Date[3]` returns {2012, 11, 15, 18, 41, 0.3161629} and so on and why? Also, I tried this code                   a = DateList[] (*line 1*)         a = a + {0, 0, 0, 1, 0, 0} (*Line 2*)      After executing Line 2 for a few more times I get {2012, 11, 15, 25, 41, 0.3161629}. How can I fix this as I want to use increment time by 1 hour or 30 min in a `For` loop


title: Diagonalization in parallel

text: I would like to diagonalize one unitary non-sparse matrix of size 12870 with complex number entries (not symbols, this is really a numerical problem). Is is possible to make eigensystem run in parallel - I have access to a HPC cluster with many kernels - so that the diagonalization runs as fast as possible?


title: Binarize turning image completely black?

text: Running Binarize (or EdgeDetect) on a filled black and white image is resulting in an all black image. The image has the following color distribution (with most images points falling in either a zero or one bucket)               image = Import["http://imgur.com/HhsMeDc.png"] ;     ImageLevels[ image, 10 ]     ...     {{{0., 640000}, {0.1, 0}, {0.2, 0}, {0.3, 0}, {0.4, 0}, {0.5,        0}, {0.6, 0}, {0.7, 0}, {0.8, 0}, {0.9, 0}},      {{0., 640000}, {0.1,        0}, {0.2, 0}, {0.3, 0}, {0.4, 0}, {0.5, 0}, {0.6, 0}, {0.7,        0}, {0.8, 0}, {0.9, 0}},      {{0., 640000}, {0.1, 0}, {0.2, 0}, {0.3,        0}, {0.4, 0}, {0.5, 0}, {0.6, 0}, {0.7, 0}, {0.8, 0}, {0.9,        0}},      {{0., 370003}, {0.1, 809}, {0.2, 605}, {0.3, 555}, {0.4,        612}, {0.5, 550}, {0.6, 580}, {0.7, 616}, {0.8, 764}, {0.9,        264906}}}      ![dragon](http://i.stack.imgur.com/Gwwvq.png) This binarize attempt:               b = Binarize[ image ]      ImageLevels[ b ]      produces an all black image, with the levels showing only zero values:                {{0, 640000}, {1, 0}}      I tried various thresholds, including the default and some explicit values (or 0.5, 0.9, 0.1, ...), but still get the all zero levels?


title: Understanding CDF

text: **Update** Since more and more issues are revealed as I venture deeper into the world of CDF, I decided to make this thread more general and hopefully more useful. I know posted my findings as an answer, but please feel free to edit this post or my answer below if you know something useful. **Questions** I have a quite large project that I want to deploy to the web. I expect users to only have the browser plugin or _Mathematica_ Player, but not Player Pro.   1. Can I use `DynamicModule` in a CDF that is to be viewed by the plugin or the _Mathematica_ Player? Does it always have to be a `Manipulate` in focus in the dynamic interface that is generated?   2. Can I deploy the dynamic output somehow without piling all the used functions and data into the `DynamicModule`-s body or `Initialization` option? `Manipulate` has the option `SaveDefinitions` but `DynamicModule` does not. Does `SaveDefinitions` work with packaged functions as well?   3. What exactly happens when only the dynamic output is selected and deployed (and not the whole document) to CDF via the wizard? What is the difference between deploying only the output or deploying the whole notebook, but with all the code cells being hidden? What is the technical difference between demonstrations and CDFs?   4. Is there any difference (and if so, what) between _Mathematica_ Player, Player Pro and the browser plugin?   5. What are the differences between CDFs intended for _Mathematica_ Player or Player pro, i.e. free CDFs and non-free CDFs (see discussion here)?   6. How to overcome security issues (discussed here and here): when the deployed CDF shows up as a gray box because dynamic updating is disabled for security reasons?


title: How to get .cdf format to work with functions?

text: I would like to create simple functions and then pass them into a Manipulate function that can be used in a .cdf file. eg               f[x_] := x^2 + 4;     Manipulate[                Plot[f[x], {x, -c, c}]                , {c, 1, 5}]      works fine as a notebook but crashes as a .cdf