title: Complex queries to MS SQL Server

text: I'm using DatabaseLink to query MS SQL Server with SQLExecute which works totaly fine, for ex.:               SQLExecute[conn, "declare @dt date;     select * from ttable where date=@dt"]      However the problem starts when i try to use table variable and try to return it, for ex.:               SQLExecute[conn, "declare @dt date;     declare @tab table(     var1 int     date date)     insert into @tab     select * from ttable where date=@dt;     select * from @tab"]      It returns the number of rows and not the table. Is there a way to solve that? It seems that Mathematica returns results for the 'insert' statement, not the final results.


title: Exporting a sequence of graphs as video efficiently

text: I have a sequence of graphs that are being created within Mathematica which I'm exporting to create an animated plot of the graph, as follows. ![animation example](http://i.stack.imgur.com/uM411.gif)               startTime = 0;     endTime = 5;     secondsPerFrame = 1/30;          sampleData = {#, #^3 - 5*#^2 + #} & /@ Range[startTime, endTime, secondsPerFrame];     {tList, xList} = sampleData\[Transpose];          timeInformationLocation = {0.2 + Min@tList, 0.9*Max@xList};     timeInformation =         Graphics[Text[           "Time: " <> ToString[NumberForm[N[#1], {10, 2}]] <> " s",            timeInformationLocation, {-1, 0}, BaseStyle -> {Black, 16}]] &;           evaluationInitialTime = AbsoluteTime[];           graphListForExport =         ParallelTable[         Show[ListPlot[Select[Transpose[{tList, xList}], #[[1]] < tdummy &],            PlotRange -> {1.1*{0, Max@tList}, 1.1*{Min@xList, Max@xList}},            AxesOrigin -> {0, 0}, AxesLabel -> {"time / s", "position / m"},            LabelStyle -> {Black, 16}, ImageSize -> 440,            PlotMarkers -> {Automatic, 6}],           timeInformation[tdummy]], {tdummy, startTime + secondsPerFrame,           endTime, secondsPerFrame}];      Print[Row[{"List of graphs completed at ", AbsoluteTime[] - evaluationInitialTime}]];           SetDirectory[NotebookDirectory[]];      Export["sample.mov", graphListForExport];           Print[Row[{"Export completed at ", AbsoluteTime[] - evaluationInitialTime}]];      Unfortunately, exporting the images is very slow; for the sample code above to export 150 frames, my system takes ~9s to generate the list of graphs, but another ~90s to export the list into the .mov format. > The question is, how can I optimize exporting a list of `Graphics` as a > video? There are several things which possibly could be done to improve the code. Firstly, when making the list of graphs, I could have chosen to use `Graphics` instead, which is likely to be faster. However, as most of the time seems to be taken up in the export step, I would like to focus on that first. Since I would be processing the video in other software afterwards, I considered encoding the video in another format. However, while saving the video as `.avi` leads to some performance improvements (~60s for export versus ~90s), it is still rather slow. Other formats seem to be even slower than .mov, although I don't have the hard numbers for this specific example. I also attempted to export the graphs immediately as a list of images that I could string together again via `ffmpeg`. Again, there was no significant performance improvement, and considering the additional work that has to be done to produce the final video, I'm not sure whether it is worth it. Halirutan suggested in chat to rasterize the images first, and YvesKlett added to that by pointing out that the process of rasterization could in fact be parallelized. However, when I attempt to rasterize the images in my system my system crashed. The two approaches I used to try to rasterize the image were inserting a `Rasterize` within my `ParallelTable` and inserting the code `graphListForExport=Rasterize\@graphListForExport`. For my final application, I will be exporting about 30s worth of graphs at 60fps, which means a total of 1800s. Each export takes about an hour, meaning that modifying elements in the video is very time-consuming. I'm running Mathematica 9.0 on a system with a Dual Core 1.86 Ghz CPU, and 2.50 GB of RAM.


title: ReplaceRepeated seemingly omits some rules

text: Is there a simple way in Mathematica to prevent rule reordering? Let me give an example:               a -> b //. {b -> c, (x_ -> y_) -> (x -> Expand[y])}     (* a -> b *)      though               a -> b /. {b -> c}     (* a -> c *)      works fine, of course. (I think that) _Mathematica_ has determined that the second rule in expression 1 is more specific than the first rule and so has ordered it first. But, in the `ReplaceRepeated`, _Mathematica_ now never checks the first rule. I realize that there are ways to rewrite this so that it works fine but is there a simple way to tell _Mathematica_ not to reorder the rules? It seems like there should be.


title: Using Element[]

text: Can the Element[] function only be used for the domains given in the documentation? I am trying to use it to determine if a value is contained in a previously defined list. Thanks!


title: Is there a way to plot the derivative of an implicit function in mathematica?

text: After having read the manuals and searched extensively, I could not find a way to do the following. Suppose you have an implicit equation of the form $y^4 + y^5 = x$, and $y$ is a function of $x$. Now, using `ContourPlot`, one can easily graph y against x. However, I would like to know if there is a method to graph `y'` against `x` (i.e. $dy/dx$ against `x`). I haven't come across any such thing yet.


title: Using Map in a function definition

text: I want to calculate the hessian of a matrix. So each element gets replaced by a 2 by 2 matrix.               hessian[im_, s_] :=        {{gD[im, 2, 0, 2], gD[im, 1, 1, 2]}, {gD[im, 1, 1, 2], gD[im, 0, 2, 2]}};      Now `im = My matrix`. I want to modify my hessian function in some way (using `Map`) such that when I calculate the hessian of `im`, 1 element at a time is calculated by `gD`. At this time `gD` works on the entire `im` matrix. How do I do this? Any help (preferable code) will be very helpful. I am new to _Mathematica_ , struggling, and very frustrated.


title: How to change the format of all inline cells

text: `DefaultNewInlineCellStyle` only take effect for newly generated inline cells. for example                   Cell[TextData[{Cell[BoxData[FormBox[RowBox[{RowBox[{"f","",RowBox[{"(","x",")"}]}],"","=","",RowBox[{"a","",FormBox[SubscriptBox["f","1"],StandardForm],"",RowBox[{"(","x",")"}]}]}],TraditionalForm]],"DisplayFormula"],",",Cell[BoxData[FormBox[RowBox[{RowBox[{"g","",RowBox[{"(","x",")"}]}],"","=","",RowBox[{"r","",FormBox[SubscriptBox["g","1"],StandardForm],"",RowBox[{"(","x",")"}]}]}],TraditionalForm]],"DisplayFormula"],",",Cell[BoxData[FormBox[RowBox[{RowBox[{"h","",RowBox[{"(","x",")"}]}],"","=","",RowBox[{"s","",FormBox[SubscriptBox["h","1"],StandardForm],"",RowBox[{"(","x",")"}]}]}],TraditionalForm]],"DisplayFormula"],","}],"Text"]      Here, for some reasons, $f(x),a,f_1(x)$ in Notebook are not in an consistent style. Choose them, set same font/clear format/apply an stylesheet does not take effect, because of different values of `StandardForm` and `TraditionalForm` and other. If I do the following               SetOptions[$FrontEnd,DefaultNewInlineCellStyle->{"Section",FontFamily->"Mathematica",Background->Red}]      How to make the previous inline cells,or further, all inline cells in the notebook the same formatting style?


title: Create list via checkboxes

text: I am trying to achieve the following: Three (dynamically updated) `Checkboxes` (a, b and c) can be toggled on or off individually. Depending on their status, a resulting list shall be set to `{a,b,c}`, `{a,c}`, `{b,c}`, etc. I am currently using the following code:               {"a:" Checkbox[Dynamic[a]],      "b:" Checkbox[Dynamic[b]],       "c:" Checkbox[Dynamic[c]],      Dynamic[{If[a, "a",], If[b, "b",], If[c, "c",]}]}      But this yields, depending on the setting, a list of the kind `{a,b,Null}`, etc. - that is, if a checkbox is set to `False`, the list element is set to `Null` rather than left out entirely. Is there any way to achieve my goal in a not-so-cumbersome way (i.e., avoiding something like a 8-cases `Piecewise` or `Which` function)? Thanks in advance!


title: Different Chapters in Different Files

text: I was wondering if there is a command to change the counter to adjust its numbeing to having different chapters saved as separate files. This seems possible with page numbers but not section numbers.


title: How could I use Mathematica to remove finger tips that appear in images?

text: I used my photo camera to "scan" a heavy dictionary. I tried to have flat images by pressing the margins of the pages with my fingers. The color of the background is (normally) black and my fingers have different colors from the color of the page margins. My questions is: Is it possible to apply Mathematica photo tools to automatically remove the finger tips from the scanned pages? For experiments, you can freely use the following photo               img = Import["http://i.stack.imgur.com/oY9cp.jpg"]      ![photo](http://i.stack.imgur.com/oY9cp.jpg)


title: Where will I put packages?

text: Recently,I got _WebMathematica_. Initially I searched _WebMathematica_ documentation in _Mathematica_ documentation, but it doesn't return any results. For this I read tutorials; finally I placed the `webMathematicaDocumentation` folder in the following link.               FileNameJoin[{$InstallationDirectory, "AddOns", "Applications"}]      After that, I reopen _Mathematica_ and search for _webMathematica_ functions in the _Mathematica_ documentation center. It shows all the results. Out of all functions, I read `HTMLTableForm` description, if you want to call this function, first you should evaluate the `MSP HTML` package. This package corresponds to _webMathematica_ layout. So I copied all the packages, which are under `webMathematica\WEB- INF\Applications` and placed them in `FileNameJoin[{$UserBaseDirectory, "Applications"}]`. Again, I reopen _Mathematica_ , directly searched for `HTMLTableForm` and evaluated `MSP HTML` package. It's working fine. But my doubt was, is this a good way for placing all the packages in `Application` folder. Or is there an efficient way?


title: Hodrick–Prescott filter (one-sided version)

text: I am interested in implementing Hodrick–Prescott filter (HP filter) on my time series data in _Mathematica_. I know that there is already a version of two-sided original filter for _Mathematica_ (see Demo 5161), however wanted to know if anyone has implemented the one-sided version of the filter and would like to share? So far I found only an implementation for Matlab.


title: How to generate 2D FEM mesh in Mathematica?

text: To generate 3D mesh TetGen can be easily used. Are there similar functions (or a way to use TetGen) to generate 2d mesh? I know that such functionality can be easily implemented but I would like to use a Mathematica provided function, as I need to experiment with number of nodes in elements and so on. I just want to solve PDE using FEM not really to play around with mesh generation.


title: Incorrect numerical derivative of function that uses FindRoot

text: I am trying to plot the derivative of function `g[x]` below where `g[x]` is defined as the root of another equation. However, I am getting nonsensical answers for the derivative. Any advice would be much appreciated! Simplified code is below:               jRa[T3_] := 10^-5/(1 + 5*10^-8/T3)           jRb[x_, T3_] :=       x*1.3*10^-4/(10^-4 +           x*(1 + 10^-6/(10^-5 - T3)))          g[x_?NumericQ] := (T3 /.          FindRoot[{jRa[T3] == jRb[x, T3]}, {{T3, 10^-7}},           MaxIterations -> 1000])/Ttot          s1 = Plot[(g[x]), {x, 10^-7, 2*10^-5}, PlotRange -> All]          s2 = Plot[g'[x], {x, 10^-7, 2*10^-5}, PlotRange -> All]          g'[.9*10^-5]


title: Changing the tick labels in a BarLegend

text: In the following plot, the colors mean the phase, so I need to label the color bar not in integers, but in increments of $\pi$. I searched, but could not find how to change the ticks. Does anyone have an idea?               ListDensityPlot[         Table[ArcTan[Cos[x + y], Sin[x + y]], {x, 0, 10, 0.01}, {y, 0, 1.2, 0.01}],          DataRange -> {{0, 10}, {0, 1.2}}, PlotLegends -> Automatic, ColorFunction -> Hue]      ![](http://i.stack.imgur.com/PyLhk.png)


title: global variables in compile statement

text: sorry for posting multiple questions about compile, but this is giving me some headache lately. This time my question is about using globally defined variables in a compile statement. The problem is that when I define a compiled function that uses a global variable like this:               a = 1; (*global variable*)     GlobalVariableCompile = Compile[{{n, _Integer}}, For[i = 1, i < n, i++, a + Cos[i*Pi] + Sin[i*Pi]]];      The function is way slower then the noncompiled version:               GlobalVariable[n_] := For[i = 1, i < n, i++, a + Cos[i*Pi] + Sin[i*Pi]];      which can be easily verified by calling for example:               AbsoluteTiming[GlobalVariableCompile[100000];]     AbsoluteTiming[GlobalVariable[100000];]      What is the reason for this and how can I fix it? **My current solution** : My solution right now is to define an additional parameter of the compiled function and pass the global variable `a`, then everything is very fast as expected (way faster than the noncompiled version):               GlobalVariableCompile = Compile[{{n, _Integer},{a, _Real}}, For[i = 1, i < n, i++, a + Cos[i*Pi] + Sin[i*Pi]]];     AbsoluteTiming[GlobalVariableCompile[100000,a];]


title: Exporting XML Data

text: I am trying to convert a bunch of text files into structured XML files. Using string expressions I have extracted data, so I have:               title={"https://www.ometz.ca/event/abiletes-dentrevue-1-678/?langID=1"};`     date={2011,7,14,13,22,22.`};`     content=": text/html; charset=UTF-8 Ometz A community of services for life Employment Job Seekers Job Listings Job Seeker Registration Career Counselling Employers Cocktails & Conversation Candidate Profiles Employers - Submit a Job Posting ProMontreal Entrepreneurs Fund ProMontreal Entrepreneurs Mentors Calendar You & Yours Community Assistance Counselling Services Administered Funds Orthodox Community We";`      So far I have done the following to generate XML objects, for title, date, and content in turn. It is a bit messy but seems to work.               a = ExportString[       XMLElement[        "title", {}, {StringReplace[          ToString[title], {"{" -> "", "}" -> ""}]}], "XML"]          b = ExportString[       XMLElement[        "date", {}, {StringReplace[          ToString[date], {"{" -> "", "}" -> ""}]}], "XML"]          c = ExportString[XMLElement["body", {}, {content}], "XML"];      The output is thus:               <title>https://www.ometz.ca/event/abiletes-dentrevue-1-678/?langID=1</title>     <date>2011, 7, 14, 13, 22, 22.</date>     <body>: text/html; charset=UTF-8 Ometz A community of services for life Employment Job     Seekers Job Listings Job Seeker Registration Career Counselling Employers Cocktails &     Conversation Candidate Profiles Employers - Submit a Job Posting ProMontreal Entrepreneurs     Fund ProMontreal Entrepreneurs Mentors Calendar You & Yours Community Assistance     Counselling Services Administered Funds Orthodox Community We</body>      So far so good, but I need to get it exported to an XML file, say `text.xml`. For some reason I'm hitting a wall in how to get this working, despite reading docs & some supplementary material. How would you do this? (also, any advice on the above code is appreciated)


title: What's wrong with my code for finding primes?

text: From here I found a fast method to make prime list, the python version works well, but my _Mathematica_ version does not. Obviously ,`169` is not a prime number. What's wrong with my program?               '''Python code'''     n = 200     sieve = np.ones(n / 3 + (n % 6 == 2), dtype = np.bool)     sieve[0] = False     for i in xrange(int(n**0.5)/3+1):         if sieve[i]:             k=(3 * i + 1) | 1             sieve[      ((k*k)/3)      :: 2 * k] = False             sieve[(k * k + 4 * k - 2 * k * (i & 1))/3 :: 2 * k] = False         print ((3 * np.nonzero(sieve)[0] + 1) | 1)      * * *               (*Mathematica code*)     Clear["`*"];     n = 200;     p = ConstantArray[1, Quotient[n, 3] + Boole[Mod[n, 6] == 2]];     p[[1]] = 0;     Do[       If[p[[i]] != 0,          k = BitOr[3 (i - 1) + 1, 1];         p[[Quotient[k^2, 3] + 1 ;; -1 ;; 2 k]] = 0;         p[[Quotient[(k^2 + 4 k - 2 k BitAnd[i - 1, 1]), 3] + 1 ;; -1 ;; 2 k]] = 0;],       {i, 1, Floor[n^0.5]/3}];     res = BitOr[3 (Flatten@SparseArray[p]["NonzeroPositions"] - 1) + 1, 1];        Pick[res, PrimeQ @ res, False]


title: Changing the background color of one element in a Grid

text: Consider the following code:               Grid[Table[x, {4}, {7}], Background -> {4 -> LightRed}]      This highlights column 4: ![enter image description here](http://i.stack.imgur.com/3hg3h.png)               Grid[Table[x, {4}, {7}], Background -> {None, {4 -> LightRed}}]      This highlights row 4: ![enter image description here](http://i.stack.imgur.com/mszCW.png) How do you highlight an individual cell, say row 3, column 5?


title: Finding the midpoints of an ordered list of numbers

text: Suppose that I have an _ordered_ list of numbers. The numbers in the list may be evenly spaced, but they may not be. Here are two examples, `list1` and `list2`:               list1 = {0, 0.2, 0.4, 0.6, 0.8, 1};     list2 = {0, 0.3, 0.4, 0.7, 0.9, 1};      I would like to write a function to determine the midpoints (or "midvalues"). So, I would like to write `fun` such that with the following input I will obtain the following output:               fun[list1]     fun[list2]      > >     {0.1, 0.3, 0.5, 0.7, 0.9} >     {0.15, 0.35, 0.55, 0.8, 0.95} >   Is there any built-in way to do this in Mathematica 8? I am looking for a simple method. I came up with the following, which seems to work fine, but I am afraid I may be overcomplicating it:               midpoint[a_, b_] := (a + b)/2     fun[list_List] := Map[Apply[midpoint, #] &, Partition[list, 2, 1]]      where               fun[list1]     fun[list2]      gives > >     {0.1, 0.3, 0.5, 0.7, 0.9} >     {0.15, 0.35, 0.55, 0.8, 0.95} >   Do you have any suggestions to make this simpler?


title: How can I improve my code for drawing a tree?

text: This code draws a tree, but it's not in the functional style.               tree[set_, m_] :=        Module[{θ, mz, my, temp, k, i, p1, p2, a, b, c, d, e, f},        θ = Pi/6;        mz = {{Cos[θ], -Sin[θ]}, {Sin[θ], Cos[θ]}};         my = {{Cos[-θ], -Sin[-θ]}, {Sin[-θ], Cos[-θ]}};        temp = set;        p1 = {};(*store branch*)        p2 = {};(*store leaf*)        For[k = 1, k <= m, k++, p2 = {};         For[i = 1, i <= Length[temp], i++, a = temp[[i, 2]];          b = temp[[i, 1]];          c = 1/3*a + 2/3*b;          d = c + mz.(a - b)*(1/3);          e = c + my.(a - b)*(1/3);          AppendTo[p1, {Brown, Thickness[0.035/k], Line[{b, c}]}];          AppendTo[p2, {c, a}];          AppendTo[p2, {c, d}];          AppendTo[p2, {c, e}];          ];         temp = p2;         ];             Show[Graphics[{p1, {RGBColor[0.1, 0.42, 0.17], Line[p2]}},           Axes -> 1, PlotRange -> {{-0.2, 0.2}, {-0.2, 1.}}]]];          tree[{{{0., 0.}, {0., 1.}}}, 7]      ![Mathematica graphics](http://i.stack.imgur.com/pU5bT.png) A friend of mine tried rewrite it with `Nest`, but it worked slower than the original code.               (leaf = Nest[Apply[Transpose[{Table[(2 #1 + #2)/3, {3}],                 {RotationTransform[-5 Pi/6, (2 #1 + #2)/3][#1],                RotationTransform[                 5 Pi/6, (2 #1 + #2)/3][#1], #2}}] &, #, {-3}] &,                  {{{0, 0.}, {0, 1}}}, 7];        Graphics[Map[{RGBColor[0.1, 0.42, 0.17], Line[#]} &, leaf, {-3}]]) // AbsoluteTiming      ![Mathematica graphics](http://i.stack.imgur.com/w1Jp2.png) I think `Nest` is slower than loops. How do I rewrite it to make it faster? If possible, use `Fold`, `Nest` or similar functional constructs.


title: Convolving data set with gaussian profile

text: I have a spectrum looking like List, and I want to convole it with a gaussian of the form               PDF[NormalDistribution[μ, σ], x]      (where σ also depends on x). The raw spectrum is convolved with the (gaussian) instrument profile. So I assume I should use `ListConvolve` rather then using Fourier transformations. `ListConvolve` takes two lists as its arguments, so I need to define my kernel. I tried               ker = Table[PDF[NormalDistribution[μ, C*x], x], {x, 4021, 4024, 0.05}]     ListConvolve[ker, data]      But the result doesn't seem correct. There must be a Gauss-function for every data point to get to the new dataset. Is there a better way to get the convolution done? I hope I could make my problem clear to everyone.


title: Why won't Mathematica obtain eigenvectors for this symmetric matrix?

text: The matrix is a real symmetric 4x4:               ({{0, Sin[x + y], Sin[z + y], Sin[x + z]},       {Sin[x + y], 0, Sin[x - z], Sin[z - y]},       {Sin[z + y], Sin[x - z], 0, Sin[y - x]},       {Sin[x + z], Sin[z - y], Sin[y - x], 0}})      Mathematica can find the eigenvalues fine, and they are degenerate for x, y, and/or z equal to zero. No eigenvectors can be found: Eigenvectors::eivec0: Unable to find all eigenvectors. And it seems to me that Mathematica should be able to handle the degeneracy, but I would be interested to know why it is encountering trouble. Is there some obvious property about this matrix that I am not accounting for (such as restricting values of x, y, z for the trigonometric functions) or is there something I can do inside of Mathematica to specify some starting point for an eigenvalue?


title: Plotting blends of colors over lists of lists in 3D

text: I have a list of lists containing spectral data, many thousands of points long. Each sublist contains 13 parts, and I need to plot them in 3D with a blend of RGB colors derived from the spectral data. So no problem until I get to coloring the plots. How can I use the list of 13 RGB triplets to create a blend to color each list plot? Here are two datasets, one for a plot and one for the corresponding colors:               spectral = {{{48.76`, 63.49`, 72.76`, 76.78`, 78.02`, 78.96`, 79.73`,       80.41`, 81.21`, 81.83`, 82.39`, 83.03`, 83.56`, 84, 84.42`,       84.53`, 84.69`, 84.74`, 84.55`, 84.73`, 84.56`, 84.47`, 84.31`,       84.25`, 84.09`, 83.81`, 83.67`, 83.58`, 83.39`, 83.05`, 82.76`,       82.49`, 82.35`, 82.33`, 82.16`, 82.06`}, {42.08`, 57.42`, 67.24`,       72.1`, 73.91`, 75.4`, 76.73`, 77.54`, 77.96`, 77.76`, 77.04`,       75.64`, 74.02`, 72.55`, 71.15`, 70.15`, 70.04`, 69.92`, 69.35`,       69.21`, 69.33`, 69.99`, 70.29`, 70.17`, 69.92`, 69.77`, 70.09`,       70.87`, 71.69`, 72.08`, 71.95`, 71.48`, 70.77`, 70.14`, 69.89`,       70.46`}, {42.03`, 56.78`, 66.37`, 70.92`, 72.63`, 74, 75.27`,       76.02`, 76.44`, 76.32`, 75.7`, 74.46`, 72.96`, 71.53`, 70.1`,       69.06`, 68.94`, 68.84`, 68.22`, 68.03`, 68.19`, 68.93`, 69.25`,       69.12`, 68.84`, 68.71`, 69.1`, 69.89`, 70.76`, 71.15`, 71.03`,       70.59`, 69.92`, 69.35`, 69.18`, 69.79`}, {39.03`, 53.63`, 63.5`,       68.37`, 70.26`, 71.8`, 73.19`, 73.93`, 74.24`, 73.92`, 72.91`,       71.04`, 68.78`, 66.59`, 64.33`, 62.75`, 62.43`, 62.19`, 61.25`,       60.78`, 61.04`, 62.1`, 62.66`, 62.45`, 62.06`, 61.91`, 62.52`,       63.73`, 65.08`, 65.81`, 65.78`, 65.28`, 64.36`, 63.57`, 63.44`,       64.42`}, {31.22`, 46.21`, 57.41`, 63.54`, 66.14`, 68.43`, 70.44`,       71.39`, 71.38`, 70.37`, 68.2`, 64.36`, 59.76`, 55.23`, 50.36`,       46.94`, 45.98`, 45.24`, 43.14`, 41.64`, 42.14`, 44.33`, 45.51`,       45.06`, 44.19`, 44.02`, 45.32`, 47.88`, 50.81`, 52.62`, 52.78`,       52.06`, 50.5`, 49.01`, 49.26`, 51.58`}, {26.44`, 40.79`, 52.46`,       59, 61.93`, 64.58`, 66.88`, 67.92`, 67.76`, 66.38`, 63.6`,       58.72`, 52.92`, 47.21`, 41.06`, 36.78`, 35.48`, 34.49`, 31.86`,       29.83`, 30.43`, 33.14`, 34.6`, 34.03`, 32.93`, 32.74`, 34.34`,       37.51`, 41.2`, 43.52`, 43.79`, 42.96`, 41.05`, 39.21`, 39.61`,       42.46`}, {22.15`, 36.49`, 49.02`, 56.44`, 59.88`, 62.99`, 65.73`,       66.93`, 66.45`, 64.57`, 60.92`, 54.74`, 47.62`, 40.78`, 33.58`,       28.71`, 27.21`, 26.08`, 23.15`, 20.89`, 21.54`, 24.47`, 26.08`,       25.45`, 24.24`, 24.08`, 25.86`, 29.41`, 33.6`, 36.35`, 36.72`,       35.8`, 33.66`, 31.63`, 32.2`, 35.6`}, {20.01`, 33.94`, 46.53`,       54.05`, 57.59`, 60.8`, 63.56`, 64.79`, 64.3`, 62.28`, 58.44`,       51.89`, 44.29`, 36.94`, 29.19`, 23.96`, 22.35`, 21.13`, 18.05`,       15.69`, 16.37`, 19.42`, 21.11`, 20.41`, 19.13`, 18.95`, 20.8`,       24.56`, 29.03`, 31.97`, 32.39`, 31.44`, 29.18`, 27.01`, 27.62`,       31.29`}, {18.84`, 32.74`, 45.29`, 52.81`, 56.47`, 59.72`, 62.63`,       63.89`, 63.37`, 61.31`, 57.38`, 50.67`, 42.9`, 35.39`, 27.53`,       22.23`, 20.58`, 19.35`, 16.25`, 13.85`, 14.51`, 17.54`, 19.22`,       18.53`, 17.25`, 17.06`, 18.91`, 22.67`, 27.19`, 30.17`, 30.61`,       29.66`, 27.37`, 25.16`, 25.81`, 29.51`}, {18.4`, 32.15`, 45.16`,       53.05`, 56.88`, 60.39`, 63.55`, 64.83`, 64.16`, 61.86`, 57.5`,       50.25`, 42.03`, 34.26`, 26.29`, 21.02`, 19.39`, 18.18`, 15.16`,       12.84`, 13.47`, 16.4`, 18, 17.31`, 16.04`, 15.85`, 17.63`,       21.31`, 25.79`, 28.79`, 29.22`, 28.25`, 25.92`, 23.72`, 24.38`,       28.08`}, {17.83`, 31.87`, 44.91`, 53, 56.88`, 60.41`, 63.52`,       64.85`, 64.22`, 61.88`, 57.5`, 50.17`, 41.77`, 33.79`, 25.52`,       20.04`, 18.35`, 17.08`, 13.94`, 11.54`, 12.2`, 15.23`, 16.93`,       16.21`, 14.92`, 14.73`, 16.6`, 20.44`, 25.11`, 28.25`, 28.72`,       27.72`, 25.33`, 23.07`, 23.77`, 27.65`}, {17.54`, 31.72`, 45.01`,       53.08`, 57, 60.61`, 63.78`, 65.09`, 64.41`, 62.05`, 57.6`,       50.13`, 41.53`, 33.28`, 24.72`, 19.04`, 17.29`, 15.99`, 12.78`,       10.36`, 11.05`, 14.16`, 15.9`, 15.16`, 13.82`, 13.64`, 15.58`,       19.54`, 24.4`, 27.63`, 28.12`, 27.11`, 24.64`, 22.28`, 23.06`,       27.08`}, {17.39`, 31.68`, 45.1`, 53.25`, 57.15`, 60.74`, 63.93`,       65.22`, 64.55`, 62.22`, 57.77`, 50.24`, 41.55`, 33.19`, 24.5`,       18.73`, 16.96`, 15.64`, 12.41`, 10, 10.71`, 13.83`, 15.58`,       14.83`, 13.47`, 13.31`, 15.26`, 19.27`, 24.16`, 27.44`, 27.9`,       26.86`, 24.37`, 22, 22.75`, 26.82`}}};       color={{{0.73, 0.73, 0.7}, {0.63, 0.64, 0.68}, {0.62, 0.63, 0.67}, {0.57, 0.59, 0.66}, {0.44, 0.48, 0.65}, {0.36, 0.41, 0.63}, {0.3, 0.35,0.62}, {0.26, 0.32, 0.61},      {0.25, 0.31, 0.6}, {0.24, 0.3,0.61}, {0.23, 0.29, 0.61}, {0.22, 0.28, 0.61}, {0.22, 0.28, 0.61}}};       Using ListPlot3D for the plots, How can I plot these colors as blends over ListPlot3d?


title: FindFit for a differential equation model with multiple variables?

text: I'm trying to figure out how to use `FindFit` with a multivariable differential equation model and data. I've successfully made it work for the one-variable version of the model by following the example on the Help page:               DNA = 10;          model[ a_?NumberQ, b_?NumberQ, c_?NumberQ, d_?NumberQ, f_?NumberQ,             g_?NumberQ, Km1_?NumberQ, Km2_?NumberQ, Km3_?NumberQ, NTP0_?NumberQ] :=        (model[a, b, c, d, f, g, Km1, Km2, Km3, NTP0] =           First[MG /. NDSolve[{ MG'[t] == a*DNA*NTP[t]/(Km1 + NTP[t]) - b MG[t],                                NTP'[t] == -f*a*DNA*NTP[t]/(Km1 + NTP[t]) -                                 d MG[t] NTP[t]/(Km2 + NTP[t]) - c NTP[t]/(Km3 + NTP[t]),                                 GFP'[t] == g*d MG[t] NTP[t]/(Km2 + NTP[t]),                                NTP[0] == NTP0, MG[0] == 0, GFP[0] == 0},                              {MG, NTP, GFP}, {t, 0, 800}, Method -> StiffnessSwitching]]);          fit = FindFit[ data, {model[a, b, c, d, f, g, Km1, Km2, Km3, NTP0][t],                             a > 0, b > 0, c > 0, d > 0, f > 0, g > 0,                             Km1 > 1000, Km2 > 1000, Km3 > 1000, NTP0 > 100000},                     {{a, 6.8}, {b, 0.012}, {c, 247}, {d, 1.54}, {f, 19.6}, {g, 22.2},                      {Km1, 352200}, {Km2, 127882}, {Km3, 5134.5}, {NTP0, 611628}}, t]      where the data looks like:               data = {{1.65, 111}, {4.65, 141}, {7.65, 130}, {10.65, 247}, {13.65, 301},              {16.65, 395}, {19.65, 444}, {22.65, 652}, ...};      But now I'd like to do it with `DNA` being an additional variable included in the data like:               newdata = {{1.65, 10, 111}, {4.65, 10, 141}, {7.65, 10, 130}, ..., {1.65, 5, -4},                {4.65, 5, 118}, {7.65, 5, 86}, {10.65, 5, 85}, {13.65, 5, 110}, ...};      so that I could fit multiple curves with different values of `DNA` simultaneously. I imagine that this is something that's possible, but I'm not sure on the syntax. Anyone have any thoughts on this? \------ EDIT -------- so now I've tried to follow the example that bobthechemist gave on the linked page, but I think I'm getting hung up on the syntax:               model[ c_?NumberQ, d_?NumberQ, f_?NumberQ, Km1_?NumberQ, Km2_?NumberQ, Km3_?NumberQ,      Km4_?NumberQ ][ DNA_?NumberQ, t_?NumberQ] :=      (model[c,d,f, Km1,Km2,Km3,Km4][t,DNA] =  First[MG/.ParametricNDSolve[{     MG'[t,DNA]==a*DNA*NTP[t,DNA]^n/(Km1^n+NTP[t,DNA]^n)b(Km4^n/(Km4^n+NTP[t,DNA]^n))MG[t,DNA],     NTP'[t,DNA]==-a*f*DNA*NTP[t,DNA]^n/(Km1^n+NTP[t,DNA]^n)-d*MG[t,DNA]NTP[t,DNA]^n/(Km2^n+NTP[t,DNA]^n)-c NTP[t,DNA]^n/(Km3^n+NTP[t,DNA]^n),     NTP[0]==NTP0,MG[0]==0}/.{n->1,b->0.012,a->3.5,NTP0->1500000},{MG,NTP},{t,0,800},{DNA},Method->StiffnessSwitching]]);          fit=FindFit[newdata10,{model[c,d,f, Km1,Km2,Km3,Km4][t,DNA],c>0,0<d,0<f,Km1>100000,Km2>100000,Km3>100000,Km4>100000},{{c,91.0400},{d,8.4986},{f,0.000018697},{Km1,1000100},{Km2,5005020},{Km3,5000150},{Km4,7000000}},{t,DNA},Method->"NMinimize"]      gives a whole bunch of errors. perhaps this kind of problem is a bit beyond someone with my limited grasp of Mathematica syntax \------ EDIT 2 -------- a more complete set of data:               data = {{2.65,5,86}, {5.65,5,85}, {8.65,5,110}, {11.65,5,153}, {14.65,5,187}, {17.65,5,293}, {20.65,5,321}, {23.65,5,320}, {26.65,5,402}, {29.65,5,355}, {32.65,5,593}, {35.65,5,589}, {38.65,5,653}, {41.65,5,687}, {44.65,5,752}, {47.65,5,858}, {50.65,5,882}, {53.65,5,933}, {56.65,5,1033}, {59.65,5,1043}, {62.65,5,1144}, {65.65,5,1178}, {68.65,5,1239}, {71.65,5,1264}, {74.65,5,1317}, {77.65,5,1452}, {80.65,5,1449}, {83.65,5,1465}, {86.65,5,1480}, {89.65,5,1500}, {92.65,5,1529}, {95.65,5,1531}, {98.65,5,1676}, {101.65,5,1626}, {104.65,5,1632}, {107.65,5,1699}, {110.65,5,1560}, {113.65,5,1651}, {116.65,5,1756}, {119.65,5,1767}, {122.65,5,1715}, {125.65,5,1716}, {128.65,5,1715}, {131.65,5,1732}, {134.65,5,1705}, {137.65,5,1740}, {140.65,5,1759}, {143.65,5,1698}, {146.65,5,1653}, {149.65,5,1628}, {152.65,5,1677}, {155.65,5,1711}, {158.65,5,1608}, {161.65,5,1670}, {164.65,5,1481}, {167.65,5,1563}, {170.65,5,1562}, {173.65,5,1588}, {176.65,5,1540}, {179.65,5,1480}, {182.65,5,1462}, {185.65,5,1424}, {188.65,5,1446}, {191.65,5,1412}, {194.65,5,1380}, {197.65,5,1341}, {200.65,5,1338}, {203.65,5,1263}, {206.65,5,1244}, {209.65,5,1237}, {212.65,5,1164}, {215.65,5,1050}, {218.65,5,1109}, {221.65,5,1041}, {224.65,5,1071}, {227.65,5,908}, {230.65,5,940}, {233.65,5,1013}, {236.65,5,913}, {239.65,5,976}, {242.65,5,886}, {245.65,5,847}, {248.65,5,819}, {251.65,5,784}, {254.65,5,818}, {257.65,5,815}, {260.65,5,807}, {263.65,5,704}, {266.65,5,705}, {269.65,5,816}, {272.65,5,758}, {275.65,5,757}, {278.65,5,633}, {281.65,5,708}, {284.65,5,675}, {287.65,5,632}, {290.65,5,617}, {293.65,5,621}, {296.65,5,594}, {299.65,5,558}, {2.65,10,130}, {5.65,10,247}, {8.65,10,301}, {11.65,10,395}, {14.65,10,444}, {17.65,10,652}, {20.65,10,701}, {23.65,10,840}, {26.65,10,922}, {29.65,10,1074}, {32.65,10,1154}, {35.65,10,1209}, {38.65,10,1326}, {41.65,10,1470}, {44.65,10,1628}, {47.65,10,1600}, {50.65,10,1679}, {53.65,10,1759}, {56.65,10,1856}, {59.65,10,1887}, {62.65,10,2057}, {65.65,10,2078}, {68.65,10,2182}, {71.65,10,2128}, {74.65,10,2034}, {77.65,10,2257}, {80.65,10,2337}, {83.65,10,2362}, {86.65,10,2330}, {89.65,10,2423}, {92.65,10,2471}, {95.65,10,2440}, {98.65,10,2388}, {101.65,10,2544}, {104.65,10,2436}, {107.65,10,2538}, {110.65,10,2402}, {113.65,10,2406}, {116.65,10,2423}, {119.65,10,2365}, {122.65,10,2345}, {125.65,10,2391}, {128.65,10,2412}, {131.65,10,2375}, {134.65,10,2309}, {137.65,10,2321}, {140.65,10,2389}, {143.65,10,2212}, {146.65,10,2211}, {149.65,10,2276}, {152.65,10,2188}, {155.65,10,2112}, {158.65,10,2223}, {161.65,10,1980}, {164.65,10,2046}, {167.65,10,2045}, {170.65,10,2022}, {173.65,10,1933}, {176.65,10,1901}, {179.65,10,1925}, {182.65,10,1829}, {185.65,10,1873}, {188.65,10,1840}, {191.65,10,1855}, {194.65,10,1752}, {197.65,10,1682}, {200.65,10,1639}, {203.65,10,1752}, {206.65,10,1784}, {209.65,10,1661}, {212.65,10,1608}, {215.65,10,1563}, {218.65,10,1462}, {221.65,10,1563}, {224.65,10,1543}, {227.65,10,1448}, {230.65,10,1376}, {233.65,10,1384}, {236.65,10,1383}, {239.65,10,1340}, {242.65,10,1263}, {245.65,10,1362}, {248.65,10,1201}, {251.65,10,1206}, {254.65,10,1220}, {257.65,10,1185}, {260.65,10,1164}, {263.65,10,1133}, {266.65,10,1154}, {269.65,10,1115}, {272.65,10,1122}, {275.65,10,1028}, {278.65,10,1049}, {281.65,10,1042}, {284.65,10,960}, {287.65,10,1011}, {290.65,10,940}, {293.65,10,927}, {296.65,10,877}, {299.65,10,888}};      in each triplet of numbers, the first is the time, second is the DNA parameter value, and the third is the value of the function.


title: Delayed evaluation of assignment

text: I have a set of PDE's that depend on parameters. They depend on many parameters, but for simplicity we can here assume that they depend only on one, say `a`. I want to solve them for many parameter sets, using something of the form `With[{a=1},NDSolve[...]]` But since I have many sets of parameters, and it is very inconvenient to enter them each time, I want to have something like               p1 = {a=1};     p2 = {a=Pi+4};     ...     With[p1,NDSolve[...]]     With[p2,NDSolve[...]]      This clearly doesn't work because evaluating `p1={a=1}` assigns a value for `a`, and I don't want that (because I want to continue doing symbolic manipulations in other parts of the notebook). `SetDelayed` and `RuleDelayed` don't seem to work neither. Any ideas? _**EDIT_** I was asked to improve the description of my problem, so I try (and, on the way, thank all the people who tried to help). The situation is this. I have a notebook that contains many formulas, which depend on many parameters. For example, I have                f[x_]:= Sin[a x^b];      g[x_]:= a/x +Exp[-b]x;      diffEq={x'[t]==f[x[t]] x[t]^2-x/g[x[t]], x[0]==123};      I want to do symbolic manipulations on the formulas, so I don't want to assign numerical values to `a,b`. At the same time, I want to to solve the differential equation `diffEq`, and for this I want numerical values, and I want to solve it for different sets of paramters `a,b`. So I want to have variables which are assignments, something like               ass1={a->1,b->3};     ass2={a->123,b->Pi};     ass3={a->-32,b->1241203853};     ...      So that I could easily do               With[ass1,NDSolve[...]]     With[ass2,NDSolve[...]]     ....      and play around with the variables. I hope this better describes what I want to do.


title: Plotting multiple lists of complex numbers

text: The user #Nasser showed an elegant way to plot complex numbers:               data = Table[RandomReal[{-1, 1}] + I RandomReal[{-1, 1}], {30}];          p = ListPlot[{Re[#], Im[#]} & /@ data,         AxesOrigin -> {0, 0},         PlotRange -> {{-1.2, 1.2}, {-1.2, 1.2}},         ImagePadding -> 40,         AspectRatio -> 1,         Frame -> True,         FrameLabel -> {{Im, None}, {Re, "complex plane"}},         PlotStyle -> Directive[Red, PointSize[.02]]];          Show[p, Graphics@Circle[{0, 0}, 1]]      How can I change this code so that an input of multiple lists is possible and they are plotted each in a different color?


title: Trouble with fonts when exporting a 2D-plot to vector formats

text: I've set up my plot to look exactly how I like it. At least it does so on screen. Upon export though, only the bitmap formats look the same. For PDF and EPS, the FontSize seems to get ignored and the lines aren't outlined so when downscaling the whole plot the lines get thicker in relation. Isn't there a simple way to just render the whole thing as a proper PDF with everything (including fonts) outlined and at correct size?! EDIT: So there were two different problems I ran into: First was Adobe Illustrator somehow couldn't display all the text that Mathematica output into the PDF. Therefore the option to outline from within Mathematica is very convenient. Second was my (newbish) mistake to specify the font size with `Scaled[0.02]` wich was clearly not what I wanted. I now changed it to fixed point sizes.


title: How to obtain non-trivial solution of equal ratios

text: How can I obtain a non-trivial solution of the following: $$\frac{a}{b+c}=\frac{b}{c+a}=\frac{c}{a+b}$$ The answer is $a=b=c=1$.


title: Have transformation rules to be explicitly set?

text: I think this problem is not the hardest one, but I can't hit on it. I want to NSolve an equation. For this equation I use a transformation rule "ampTimes". First I used it like this:               ampTimes = {tf -> .03, th -> .002}     NSolve[E^(th/t) + E^((tf + th)/t) == 2 E^(tf/t) /. ampTimes, t, Reals]      > >     {tf -> 0.03, th -> 0.002} >     {{t -> 0.00288552}} >   and it worked. I get a solution for `t`. Due to clearity, I switched to this expression:               ampTimes = {tf -> (.315 - .285), th -> (.287 - .285)}     NSolve[E^(th/t) + E^((tf + th)/t) == 2 E^(tf/t) /. ampTimes, t, Reals]      > >     {tf -> 0.03, th -> 0.002} >     {} >   The output for `ampTimes` stays the same, but I didn't get a solution for my equation. I thought, the transformation rule may couldn't handle the difference, so I changed it to               (.315 - .285);     (.287 - .285);     ampTimes = {tf -> %%, th -> %}     NSolve[E^(th/t) + E^((tf + th)/t) == 2 E^(tf/t) /. ampTimes, t, Reals]      > >     {tf -> 0.03, th -> 0.002} >     {} >   Again, the output fpr `ampTimes` seems right, but I didn't get a solution. It wouldn't be a problem to use the transformation rule explicitly, but as said, wouldn't be supporting for clearity. Plus the problem get me and I realy want to know WHY it doesn't work the way I thought. EDIT: I guess it has something to do with the precision.


title: How to I display the value of my plot function?

text: I've plotted a function that varies with respect to time. It's inside a manipulate box, which can vary the time. And I'd like to display the value of the function at the time on the slider on my plot. I've seen it done before, but I've been trying unsuccessfully for the last 40 or so minutes to find out how. Any ideas?


title: What is the fastest way to replace all zeros in a matrix?

text: In the following matrix `m` every 0 should be replaced with a 1:               m = {{0,1,2},{5,0,3},{8,0,0}}      Desired result:               m' = {{1,1,2},{5,1,3},{8,1,1}}      What is the fastest way to do this for a matrix with 200-1000 elements?


title: Navigation a la XPath for Mathematica notebooks

text: In Mathematica, notebooks (in fact all expressions) have a tree-like structure. In this regard, they are similar to XML files. For XML, one can travel through the document structure using tools like XPath. What would be the equivalent in Mathematica so that beginning with `NotebookSelection` one navigates towards the outermost `Notebook` until one reaches a parent that matches certain pattern (say `Cell[__,”Input”,___]`). If the pattern is reached, the selection is enlarged; otherwise, the selection stays the same. To make the problem more interesting: is it possible to do it without changing the selection (the highlighted region should stay the same unless enlarged to avoid flickering) and without copying the notebook to a hidden one (the original notebook might be really large)? Any pointers will be appreciated.


title: Uniformly distributed n-dimensional probability vectors

text: What's the right way to generate a random probability vector $p={p_1,\ldots,p_n} \in {(0,1)}^n$ where $\sum_i p_i=1$, uniformly distributed over the $(n-1)$-dimensional simplex? What I have is               Intervals = Table[{0, 1}, {i, n}]     RandomPoint := Block[{a},         a = RandomVariate[UniformDistribution[Intervals]];         a/Total[a]];      But I am unsure that this is correct. In particular, I'm unsure that it's any different from:               RandomPoint := Block[{a},         a = Table[Random[], {i, n}];         a/Total[a]];      And the latter clearly will not distribute vectors uniformly. Is the first code the right one?


title: How does Mathematica understand branchcuts of the complex logarithm? [Part 2]

text: I observe that the answer generated by the first integration is not in any simple way related to the next two answers. (some simple jump of i 2\pi across the branchcut of the logarithm is not helping either - as discussed in the previous question _Mathematica_ puts the branchcut of the function $log(z^2 +4)$ as being along the positive imaginary axis starting at 2i ) Can someone help understand what _Mathematica_ is doing mathematically?               Integrate [ Exp[I p] Log [ (3 Exp [I p])^2 + 4] , {p, 0, π}]      > >      2/3 I (-6 + π + 4 ArcTan[3/2] + Log[2197]) >                 Integrate [ Exp[I p] Log [ (3 Exp [I p])^2 + 4] , {p, 0, π/2}]      > >      -2 + I π + 4/3 ArcTanh[3/2] + Log[5] +  1/3 I (-6 + 4 ArcTan[3/2] + > Log[2197]) >                 Integrate [ Exp[I p] Log [ (3 Exp [I p])^2 + 4] , {p, π/2, π}]      > >     1/3 I ((-6 - 6 I) + π + 4 ArcTan[3/2] + 5 I Log[5] + Log[2197]) >


title: How to make text flash for a short period

text: How could I display text that flashed red for a half second or so and then reverted to black? (Or was put in bold and reverted to normal, etc.)


title: Defining new Cellular Automata rule

text: I want to define a new Cellular Automata rule as follows               {{1, _, 1} -> 0, {1, _, 0} -> 1, {0, _, 1} -> 1, {0, _, 0} -> 0}      where _ represents Blank in mathematica. How can I code this in mathematica?


title: Minimize: How to work with specific numeric types

text: This is a question about the use of symbols in `Minimize` and how to persuade _Mathematica_ to treat them in a specific way (as integers or rationals) that I have not been able to achieve, but analysis of the results of `Minimize` suggests ought to be possible. The context is this: I have the following equation and wish to find the minimum value of `t0` in closed form for a, b in terms of vx, vy, vz _without numeric values_ (as you will see below I can find a minima for specific numeric values of `vx`, `vy`, `vz`).               t0 = g (-vz Cos[a] - vy Cos[b] Sin[a] - vx Sin[b] Sin[a])      In the code block below, you will see in part 1 an attempt to do this symbolically in terms of the ratio `c/d` assigned to the key variables `vx`, `vy`, `vz`; `Minimize` will not do it. In part 2 `vx`, `vy` and `vz` are given a specific exact numerical values and `Minimize` then delivers a result. However, inspection of the result clearly shows (thanks to the relative primaility of the numerators of `vx` etc.) that _Mathematica_ is handling the numerators separately. **Code**               Block[{g, vx, vy, vz, t0, mint,  a, b , c, d},      t0 = g (-vz Cos[a] - vy Cos[b] Sin[a] -           vx Sin[b] Sin[a]); (* eqn to minimize *)       g = 1/Sqrt[1 - (vx^2 + vx^2 + vx^2)]; (* common initialisation *)      (* Part 1 *)      vx = vy = vz = c/d; (* would like vx etc. elements of Rationals... how? *)      mint = Minimize[{t0, 0 <= b < 2 Pi, 0 <= a < Pi}, {b, a},         Reals]; (* fails *)      Print["t0 minimum = ", mint];      mint = Minimize[{t0, 0 <= b < 2 Pi, 0 <= a < Pi, ,          c ∈ Integers, d ∈ Integers}, {b, a},         Reals]; (* fails *)      Print["t0 minimum = ", mint];      (* Part 2 *)      vx = 7/100; vy = 3/100;       vz = 11/100; (* all v made specific rationals *)      mint = Minimize[{t0, 0 <= b < 2 Pi, 0 <= a < Pi}, {b, a},         Reals]; (* succeeds *)      Print["t0 minimum = ", mint];      ]      **Result of Part 2:** > >     t0 minimum = {(1/Sqrt[9853])100 (-(11/100) Cos[2 ArcTan[1/58 >                         (-11 Sqrt[58]+Sqrt[10382])]]-3/100 >                     Cos[2 ArcTan[1/7 (-3+Sqrt[58])]] Sin[2 ArcTan[1/58 >                         (-11 Sqrt[58]+Sqrt[10382])]]-7/100 Sin[2 ArcTan[1/7 > (-3+Sqrt[58])]] >                     Sin[2 ArcTan[1/58 (-11 Sqrt[58]+Sqrt[10382])]]), >                     {b -> 2 ArcTan[1/7 (-3+Sqrt[58])], >                      a -> 2 ArcTan[1/58 (-11 Sqrt[58] + Sqrt[10382])]}} >   where the coefficients are clearly related to the values of the denominators `vx` etc. as follows:               58 = 7^2 + 3^2     10382 = (7^2+3^2+11^2) * (7^2 +3^2)      **Question** Is it possible to perform the minimisation symbolically and if so, how? Can one declare `vx` etc. as `Rationals` directly or by assignment as the ratio of two `Integers`? I have tried including equivalent constraints within `Minimize` (one example given in code above), but to no effect. I also tried defining a function accepting appropriate `Integers` and `Reals`, also without success.               f[a_Real, b_Real, c_Integer, d_Integer] :=       g (-vz Cos[a] - vy Cos[b] Sin[a] - vx Sin[b] Sin[a]);      vx = vy = vz = c/d;     Print["Minimize by defined function of integers = ",       Minimize[{f[a, b, c, d], 0 <= b < 2 Pi, 0 <= a < Pi}, {b, a},        Reals]];      I believe that the answer to this may also have a bearing on the use of `Solve` and simialr functions.


title: How to enable-dynamics on CDF's on web?

text: Went through the wizard to export cdf /w embed code: ![deployment](http://i.stack.imgur.com/lAr7d.png) The positions and sizing are correct, but there's no interactive side to it: ![bubblechart](http://i.stack.imgur.com/TTUKq.png) data I'm using:               {{"acerbic", 3, 5, 1.3*10^6}, {"acetic", 3, 7, 213000}, {"acetonic",        1, 4, 2000}, {"achromatic", 3, 6, 16000}, {"acidic", 3, 6,        500}, {"acoustic", 3, 7, 2000}, {"acrobatic", 3, 6,        3000}, {"acrostic", 4, 8, Null}, {"acrylic", 3, 5,        220000}, {"acyclic", 6, 8, 270000}, {"adiabatic", 6, 7,        40000}, {"aerobatic", 3, 6, 2000}, {"aerobic", 7, 4,        1.6*10^6}, {"aerodynamic", 7, 7, 160000}, {"aeronautic", 2, 2,        5000}, {"aesthetic", 5, 3, 500}, {"agnostic", 3, 5,        5000}, {"agoraphobic", 7, 3, 200000}, {"agronomic", 3, 5,        5000}, {"alcoholic", 2, 1, 1000}, {"alembic", 2, 1,        20000}, {"algebraic", 6, 3, 5000}, {"algorithmic", 5, 2,        2500.}, {"aliphatic", 7, 2, 13000}, {"allegoric", 5, 2,        1000}, {"allelic", 8, 5, 2400.}, {"allergenic", 8, 5,        48000}, {"allergic", 8, 3, 1000}, {"allotropic", 7, 6,        3000}, {"almanac", 6, 7, Null}, {"alphabetic", 7, 2,        Null}, {"alphanumeric", 6, 7, 1000}, {"altruistic", 4, 7,        7000}, {"amnesiac", 5, 6, 4000}, {"amnesic", 6, 5,        500}, {"amniotic", 4, 2, 500}, {"amoebic", 2, 1, 1000}, {"anabolic",        4, 7, Null}, {"anachronistic", 4, 7, 1500.}, {"anaerobic", 3, 5,        10000}, {"anagrammatic", 8, 10, Null}, {"analgesic", 3, 7,        60000}, {"analytic", 7, 7, 3000}, {"anamorphic", 2, 6,        3000}, {"anapestic", 3, 5, 90000}, {"anaphoric", 6, 4,        1000000}, {"anarchic", 7, 5, 12000000}, {"anarchistic", 4, 4,        50000}, {"anatomic", 2, 2, 30000}, {"androgenic", 2, 4,        60000}, {"anechoic", 3, 4, 50000}, {"anemic", 2, 1,        200000}, {"anesthetic", 2, 6, 40000}, {"angelic", 3, 6,        44000}, {"anharmonic", 4, 7, Null}, {"animistic", 3, 5,        100000}, {"anionic", 3, 7, 2.2*10^6}, {"anisotropic", 3, 6,        2.8*10^6}, {"anorectic", 6, 1, 60000}, {"anorexic", 5, 6,        4000}, {"antagonistic", 1, 5, 550000}, {"antarctic", 3, 4,        320000}, {"anthropic", 5, 5, 8000}, {"anthropocentric", 2, 5,        10000000}, {"anthropogenic", 1, 5, 12000000}, {"anthropometric", 3,        6, 103000}, {"anthropomorphic", "", "", Null}, {"antibiotic", "",        "", Null}, {"antic", "", "", Null}, {"anticlimactic", "", "",        Null}, {"anticyclonic", "", "", Null}, {"antidemocratic", "", "",        Null}}      And the code:               label = Tooltip[{##2},          Grid[{{"Name", #}, {"Usability ", #2}, {"Relevancy", #3}, \     {"Market Size", #4}}, Frame -> All, Alignment -> Left]] &;     BubbleChart[label @@@ data, ChartStyle -> 24];      this is the live url


title: What replaced ListWaveform?

text: My old _Mathematica_ code used `ListWaveform` to produce a sound file from a table of amplitudes and frequencies; this seems to no longer exist. What replaced it?


title: How to binarize a matrix

text: I have this matrix               A = {{17/25, 3/25, 5/25, 0, 0}, {5/18, 5/18, 7/18,1/18, 0}, {4/21, 9/21, 4/21, 0, 4/21},         {0, 0, 3/4, 1/4, 0}, {3/4,1/4, 0, 0, 0}}      And i would like to have this matrix binarize, i wanted it to be like this               {{1, 1, 1, 0, 0}, {1, 1, 1,1, 0}, {1, 1, 1, 0, 1}, {0, 0, 1, 1, 0}, {1, 1, 0, 0, 0}}      Is any function in mathematica that does that? Or I have to programmate it? If so can un help me please? Thanks (:


title: How to manipulate lists of parameters?

text: Suppose I have a function of a variable `f`, depending on some other parameters `a` and `b`, for example: `fun[f_,a_,b_] := Sin[a*f] + Cos[b*f]` I can plot and manipulate this function for some independent values of the parameters `a` and `b`: `Manipulate[Plot[fun[f,a,b], {f, 0, 10}], {a,0,5},{b,0,5}]` ![enter image description here](http://i.stack.imgur.com/YD0A2.png) Now, suppose I would like to give discrete values to these parameters, and change both at the same time. For example,I define two points: `A = Sequence[1,1];` and `B = Sequence[4,2];` I can do this plots: `Plot[fun[f,A], {f, 0, 10}]` or `Plot[fun[f,B], {f, 0, 10}]` but when I try to combine them, in order to include the possibility to manually choose between 'A' or 'B', `Manipulate[Plot[fun[f, X], {f, 0, 10}], {X, A, B}]` I obtain an empty plot... Instead, I would like to get a plot with two button, 'A' and 'B', corresponding to two different pairs of values for the parameters a and b. I tried to use `List[ ]` instead of `Sequence[ ]`, but it failed to work too! I also tried `Row[ ]`, adding some braces but nothing happened... :( What should I do? Where is the problem with my code? Thank you all in advance!


title: Finding first instance of a relationship between elements in two lists

text: Suppose I have two lists, say:               A = {1,5,10,200,50,7}     B = {4,3,19,78}      For each element in A, I would like to find the index of the first element in B which exceeds that element, (or 0 if none do) i.e. :               result = {1,3,3,0,4,3}      Clever syntax much appreciated!


title: NSolve for system of polynomial equations

text: I would like to find all the solutions to the following system of 8 polynomial equations for the variables `w1, w2, w3, w4, w5, w6, w7, w8`               eqs = {1/162 (-1 + 2^(1/3))^3 (-27 w1^3 - 27 w1^2 w3 + 54 w1 w2 w3 +          18 w1 w3^2 + w3^3 - 216 w1^2 w4 + 216 w1 w2 w4 -          72 w1 w3 w4 - 108 w1^2 w5 + 54 w1 w2 w5 - 72 w1 w3 w5 +          36 w2 w3 w5 - 3 w3^2 w5 - 144 w1 w4 w5 + 72 w2 w4 w5 -          24 w3 w4 w5 - 27 w1 w5^2 - 9 w3 w5^2 - 24 w4 w5^2 - 2 w5^3) - 1/2 w1 Log[2] == 0,             -(1/54) (-1 + 2^(1/3))^3 (27 w1^2 w2 - 18 w2^3 + 18 w1^2 w3 +          18 w1 w2 w3 - 36 w2^2 w3 + 12 w1 w3^2 - 9 w2 w3^2 + 2 w3^3 +          72 w1 w2 w4 - 72 w2^2 w4 + 24 w2 w3 w4 - 18 w1^2 w5 +          54 w1 w2 w5 - 18 w2^2 w5 + 18 w2 w3 w5 + 2 w3^2 w5 +          24 w2 w4 w5 - 12 w1 w5^2 + 15 w2 w5^2 - 2 w3 w5^2 - 2 w5^3) - 1/2 w2 Log[2] == 0,              1/54 (-1 + 2^(1/3))^3 (27 w1^2 w2 - 9 w1^2 w3 + 18 w1 w2 w3 +          18 w2^2 w3 - 9 w1 w3^2 + 33 w2 w3^2 + 5 w3^3 - 72 w1^2 w4 +          72 w1 w2 w4 - 144 w1 w3 w4 + 120 w2 w3 w4 - 40 w3^2 w4 -          63 w1^2 w5 + 36 w1 w2 w5 + 18 w2^2 w5 - 96 w1 w3 w5 +          48 w2 w3 w5 - 26 w3^2 w5 - 24 w2 w4 w5 - 32 w3 w4 w5 -          6 w1 w5^2 - 9 w2 w5^2 - 15 w3 w5^2 + 8 w4 w5^2 + w5^3 -          27 w1^2 w6 - 54 w1 w2 w6 + 54 w2^2 w6 - 54 w1 w3 w6 +          18 w2 w3 w6 - 15 w3^2 w6 + 72 w1 w4 w6 - 72 w2 w4 w6 +          24 w3 w4 w6 + 54 w1 w5 w6 - 54 w2 w5 w6 + 6 w3 w5 w6 +          24 w4 w5 w6 + 9 w5^2 w6 + 72 w1^2 w7 - 144 w1 w2 w7 +          72 w2^2 w7 + 48 w1 w3 w7 - 48 w2 w3 w7 + 8 w3^2 w7 +          48 w1 w5 w7 - 48 w2 w5 w7 + 16 w3 w5 w7 + 8 w5^2 w7) - 1/2 w3 Log[2] == 0,              1/108 (-1 + 2^(1/3))^3 (9 w1^2 w3 + 3 w1 w3^2 + w3^3 -          18 w1^2 w4 + 18 w2^2 w4 + 12 w1 w3 w4 + 24 w2 w3 w4 +          18 w3^2 w4 - 144 w1 w4^2 + 120 w2 w4^2 - 56 w3 w4^2 +          27 w1^2 w5 + 18 w1 w3 w5 + 6 w2 w3 w5 + 6 w3^2 w5 -          60 w1 w4 w5 + 36 w2 w4 w5 - 28 w3 w4 w5 - 32 w4^2 w5 -          6 w1 w5^2 + 6 w2 w5^2 - 3 w3 w5^2 - 14 w4 w5^2 - w5^3 +          6 w3^2 w6 - 24 w3 w4 w6 + 24 w4^2 w6 - 18 w1^2 w7 -          36 w1 w2 w7 + 36 w2^2 w7 - 60 w1 w3 w7 + 36 w2 w3 w7 -          18 w3^2 w7 + 96 w1 w4 w7 - 96 w2 w4 w7 + 32 w3 w4 w7 +          36 w1 w5 w7 - 36 w2 w5 w7 - 4 w3 w5 w7 + 32 w4 w5 w7 +          6 w5^2 w7 + 216 w1^2 w8 - 432 w1 w2 w8 + 216 w2^2 w8 +          144 w1 w3 w8 - 144 w2 w3 w8 + 24 w3^2 w8 + 144 w1 w5 w8 -          144 w2 w5 w8 + 48 w3 w5 w8 + 24 w5^2 w8) - 1/2 w4 Log[2] == 0,              1/54 (-1 + 2^(1/3))^3 (9 w1^2 w3 + 12 w1 w3^2 + 3 w2 w3^2 +          3 w3^3 + 72 w1^2 w4 + 72 w1 w3 w4 + 16 w3^2 w4 + 9 w1^2 w5 +          9 w1 w2 w5 + 33 w1 w3 w5 + 12 w2 w3 w5 + 16 w3^2 w5 -          84 w1 w4 w5 + 48 w2 w4 w5 - 32 w3 w4 w5 - 36 w1 w5^2 +          15 w2 w5^2 - 16 w3 w5^2 - 12 w4 w5^2 - 5 w5^3 - 27 w1^2 w6 +          54 w1 w2 w6 + 18 w1 w3 w6 + 18 w2 w3 w6 + 9 w3^2 w6 -          72 w1 w4 w6 - 24 w3 w4 w6 - 81 w1 w5 w6 + 27 w2 w5 w6 -          33 w3 w5 w6 + 12 w4 w5 w6 - 54 w1 w6^2 + 27 w2 w6^2 -          18 w3 w6^2 - 144 w1^2 w7 + 108 w1 w2 w7 - 120 w1 w3 w7 +          48 w2 w3 w7 - 24 w3^2 w7 + 12 w1 w5 w7 - 24 w2 w5 w7 +          4 w3 w5 w7 + 4 w5^2 w7 + 72 w1 w6 w7 - 36 w2 w6 w7 +          24 w3 w6 w7) - 1/2 w5 Log[2] == 0,             -(1/162) (-1 + 2^(1/3))^3 (-9 w1 w3^2 - 9 w2 w3^2 - 8 w3^3 -          72 w1 w3 w4 - 48 w3^2 w4 - 27 w1 w2 w5 - 9 w1 w3 w5 -          18 w2 w3 w5 - 18 w3^2 w5 + 36 w1 w4 w5 + 48 w3 w4 w5 +          54 w1 w5^2 - 27 w2 w5^2 + 39 w3 w5^2 - 12 w4 w5^2 - 2 w5^3 +          108 w1 w3 w6 - 108 w2 w3 w6 + 18 w3^2 w6 + 432 w1 w4 w6 -          216 w2 w4 w6 + 288 w3 w4 w6 + 243 w1 w5 w6 - 81 w2 w5 w6 +          207 w3 w5 w6 - 36 w4 w5 w6 - 27 w5^2 w6 + 81 w2 w6^2 +          54 w3 w6^2 - 216 w4 w6^2 - 162 w5 w6^2 - 54 w6^3 +          216 w1^2 w7 - 108 w1 w2 w7 + 360 w1 w3 w7 - 144 w2 w3 w7 +          120 w3^2 w7 - 108 w1 w5 w7 + 72 w2 w5 w7 - 36 w3 w5 w7 -          12 w5^2 w7 - 648 w1 w6 w7 + 324 w2 w6 w7 - 360 w3 w6 w7 +          216 w6^2 w7) - 1/2 w6 Log[2] == 0,               1/108 (-1 + 2^(1/3))^3 (w3^3 + 12 w1 w3 w4 + 12 w2 w3 w4 +          8 w3^2 w4 + 96 w1 w4^2 + 64 w3 w4^2 + 15 w1 w3 w5 +          9 w3^2 w5 + 84 w1 w4 w5 + 12 w2 w4 w5 + 68 w3 w4 w5 -          32 w4^2 w5 + 30 w1 w5^2 + 6 w2 w5^2 + 29 w3 w5^2 -          40 w4 w5^2 - 14 w5^3 + 27 w1^2 w6 + 54 w1 w3 w6 +          15 w3^2 w6 + 36 w1 w4 w6 + 36 w2 w4 w6 + 36 w3 w4 w6 -          96 w4^2 w6 + 63 w1 w5 w6 + 18 w2 w5 w6 + 63 w3 w5 w6 -          144 w4 w5 w6 - 60 w5^2 w6 + 27 w1 w6^2 + 45 w3 w6^2 -          72 w4 w6^2 - 81 w5 w6^2 - 54 w6^3 + 90 w1^2 w7 +          36 w1 w2 w7 + 144 w1 w3 w7 + 36 w2 w3 w7 + 58 w3^2 w7 -          480 w1 w4 w7 + 192 w2 w4 w7 - 256 w3 w4 w7 - 336 w1 w5 w7 +          120 w2 w5 w7 - 196 w3 w5 w7 + 32 w4 w5 w7 + 14 w5^2 w7 -          396 w1 w6 w7 + 72 w2 w6 w7 - 252 w3 w6 w7 + 288 w4 w6 w7 +          204 w5 w6 w7 + 180 w6^2 w7 + 336 w1 w7^2 - 168 w2 w7^2 +          168 w3 w7^2 - 168 w6 w7^2 - 648 w1^2 w8 + 432 w1 w2 w8 -          720 w1 w3 w8 + 288 w2 w3 w8 - 192 w3^2 w8 + 144 w1 w5 w8 -          144 w2 w5 w8 + 48 w3 w5 w8 + 24 w5^2 w8 + 864 w1 w6 w8 -          432 w2 w6 w8 + 432 w3 w6 w8 - 216 w6^2 w8) - 1/2 w7 Log[2] == 0,              1/324 (-1 + 2^(1/3))^3 (3 w3^2 w4 + 9 w2 w4^2 + 3 w3 w4^2 +          52 w4^3 + 12 w3 w4 w5 + 48 w4^2 w5 + 6 w3 w5^2 + 30 w4 w5^2 +          8 w5^3 + 54 w1 w4 w6 + 18 w3 w4 w6 - 9 w4^2 w6 +          27 w1 w5 w6 + 9 w3 w5 w6 + 18 w4 w5 w6 + 27 w5^2 w6 +          27 w4 w6^2 + 54 w5 w6^2 + 27 w6^3 + 36 w1 w3 w7 +          12 w3^2 w7 + 180 w1 w4 w7 + 36 w2 w4 w7 + 132 w3 w4 w7 -          204 w4^2 w7 + 144 w1 w5 w7 + 18 w2 w5 w7 + 108 w3 w5 w7 -          228 w4 w5 w7 - 108 w5^2 w7 + 108 w1 w6 w7 + 108 w3 w6 w7 -          216 w4 w6 w7 - 252 w5 w6 w7 - 216 w6^2 w7 - 468 w1 w7^2 +          108 w2 w7^2 - 276 w3 w7^2 + 264 w4 w7^2 + 180 w5 w7^2 +          360 w6 w7^2 - 112 w7^3 + 324 w1^2 w8 + 432 w1 w3 w8 +          144 w3^2 w8 - 1296 w1 w4 w8 + 648 w2 w4 w8 - 648 w3 w4 w8 -          648 w1 w5 w8 + 216 w2 w5 w8 - 360 w3 w5 w8 + 36 w5^2 w8 -          648 w1 w6 w8 - 432 w3 w6 w8 + 648 w4 w6 w8 + 432 w5 w6 w8 +          324 w6^2 w8 + 1728 w1 w7 w8 - 864 w2 w7 w8 + 864 w3 w7 w8 -          864 w6 w7 w8) - 1/2 w8 Log[2] == 0}      I tried               NSolve[ eqs, {w1, w2, w3, w4, w5, w6, w7, w8}, Reals]      because I am interested only in real solutions for `w1, ..., w8` but it takes a very long time without producing an output. Do you have any suggestions to overcome this problem?


title: Parallel computing NInverseFourierTransForm

text: I am running the code below, and it works perfectly. I have some function in Fourier space, and I take the numerical `InverseFourierTransform`. However, I will have to repeat this calculation often, and therefore I want to use `ParallelTable`. I've tried this, by replacing `Table` in the code below by `ParallelTable`. I am running the code on a computer with 8 kernels. Surprisingly, using `ParallelTable` doesn't speed up the calculation. I simply find almost the same computation time (not roughly a factor 8 difference)! Can anybody explain to me what the reason for this is? I've tested the `ParallelTable` with commands like                 ParallelTable[Pause[1]; f[i], {i, 4}] // AbsoluteTiming      and for this case it works fine, but not for the `NInverseFourierTransform`.               ClearAll["Global`*"];     f[q_] := Sqrt[2/Pi]*(-Sinc[q] + Cos[q]);     k[q_] := Sqrt[Pi/2]/Abs[q];     a = 10^-2;     b = 10^-2;     Needs["FourierSeries`"]     hfourierdomain[ω_] = a*f[ω]*k[ω]/(1 + b*ω^2*k[ω]);     displ = Table[{j, NInverseFourierTransform[hfourierdomain[ω], ω, j]}, {j, -5, 5, 1/60}];


title: Discriminant of Characteristic Polynomial

text: I'm doing a calculation which finds the characteristic polynomial of a matrix with rather complex entries and then determines the discriminant of that polynomial. For smaller matrices up to around 7x7 it finishes evaluating the Discriminant command within a few hours, but at a 10x10, which is what I need, it takes days to evaluate. Running in parallel won't work for the built in Discriminant command. I was wondering if there was a more efficient way to evaluate the discriminant of high-order polynomial, as I know my code is basic.                   CPHH = Collect[CharacteristicPolynomial[HH, x],x]];         DD = Discriminant[CPHH, x, Method -> SylvesterMatrix];         Simplify[DD, TimeConstraint -> Infinity]      If the rest of the code would be useful in determining a solution I'd be happy to post it


title: computation of gradient vector field in 3D using GradientOrientationFilter

text: I want to compute a 3D gradient vector field of an `Image3D` object using the built-in GradientOrientationFilter function in _Mathematica_. From the documentation I extracted the example for computing the gradient vector field for the 2D case and put it into a module:               computeGradientField2D[image_Image] := Module[        {dims, dirs, magnitudes},             dims = ImageDimensions[image];        dirs = ImageData[GradientOrientationFilter[image, 5]];        magnitudes = ImageData[GradientFilter[image, 5]];         MapThread[#1 {-Sin[#2], Cos[#2]} &, {magnitudes, dirs}, 2]        ];      For drawing the vectors I also use the method from the documenation:               Show[ImageAdjust@img,       ListVectorPlot[       MapIndexed[{{#2[[2]], dims[[2]] - #2[[1]]}, #1} &, or, {2}],        VectorColorFunction -> (Yellow &), VectorPoints -> Fine],       ImageSize -> 256]      This gives me the following output for a grayscale image of cell nuclei (left: raw image, right: raw image with overlayed vector field): > ![enter image description here](http://i.stack.imgur.com/CU22p.png) ![enter > image description here](http://i.stack.imgur.com/uEdW6.png) So far so good. Now I am struggeling with the computation of the gradient vector field for `Image3D` objects. My current function looks like the following:               computeGradientField3D[image_Image3D] := Module[        {img, dims, dirs, magnitudes},        dims = ImageDimensions[image];        dirs = ImageData[GradientOrientationFilter[image, 5]];        magnitudes = ImageData[GradientFilter[image, 5]];         MapThread[#1 {Cos[#2[[1]]], Sin[#2[[1]]] Cos[#2[[2]]],             Sin[#2[[1]]] Sin[#2[[2]]]} &, {magnitudes, dirs}, 3]        ];      I am particularly not sure about the last line with the `MapThread` where the orientations of the vectors are created and multiplied with the magnitudes. The documentation of `GradientOrientationFilter` contains the following information about how to interprete the orientation angles: > ![enter image description here](http://i.stack.imgur.com/ZB9EV.png) **Questions:** **1\. Am I misinterpreting the documentation?** **2\. How do I visualize the gradient vector field in the end ( _e.g._ using `ListVectorPlot3D`)?**


title: When event and "stop integration"

text: I am using NDSolve, to solve for an equation. At some point, I want it to stop integrating and keep a constant value for the solution from the point it stopped changing. I tried setting the derivative of the solution to 0 (using whenevent), but it won't let me. So I tried using "stop integration" in the "when event", which basically makes the curve diverge. UNLESS I set the value of a function to the function itself (f[x]->f[x]) which for some reason makes IT STAY constant. But, from that point on, none of the conditions I set for whenevent are ever met again (I would like that the integration continues after uf[t]>uc[t]. Can someone explain to me what is going on? How could I resolve this problem?, Is there a better way to do that?               uf[t_] := U/\[Pi] + U/2 Sin[t] - (2*U)/\[Pi] Sum[1/((2 n - 1) (2 n + 1))*Cos[2 n*t],{n, 50}];          a = Last[         NDSolve[{uf[t] == R c uc'[t] + uc[t], uc[0] == 0,                  WhenEvent[uf[t] - uc[t] < 0 && t != 0, {"StopIntegration", uc[t] -> uc[t]}],                  WhenEvent[uf[t] - uc[t] > 0, "RestartIntegration"]}, uc, {t, 0, 10}]          //. Rule -> List // Flatten];


title: Dynamically apply a function fed by Input[]

text: Here is a bit of code:               funlist = {Plot,ListPlot};     Input[Panel[PopupMenu[Dynamic@whichfun, funlist], "blabla"],Dynamic@whichfun]      The idea here is to select what function you want to use (`Plot` or `ListPlot` in that case) and to give the expression you want to be evaluated by this function (for example `x,{x,0,1}` for `Plot`). I have been struggling with this code for a few hours so if anyone has an idea. I am aware that something like:               PopupMenu[Dynamic@whichfun, funlist]     InputField[Dynamic[expr], String, ContinuousAction -> True]     Dynamic@(whichfun @@ (ToExpression@expr))      with `InputField` fed by `{x, {x, 0, 1}}` would work.


title: Operations on expressions within Hold

text: I want to convert `{Hold[1 + 2], Hold[3 + 4], Hold[5*6]}` into `Hold[{1 + 2, 3 + 4, 5*6}]`. I have tried               {Hold[1 + 2], Hold[3 + 4],  Hold[5*6]} /. {Hold[a_], Hold[b_], Hold[c_]} -> Hold[{a, b, c}]      > >     Hold[{1 + 2, 3 + 4, 5 6}] >   Is there a simpler way?


title: Problem With NDsolve trying to simulate n-body-gravity problem

text: Im Trying to model a cloud of point masses that act according to gravity, what im strugeling with is the exclusion of cases where euclidian distance = 0, If I try to do it with an If statement in my forces function, NDsolve complains about too many dependant variables I think, but I think its rather a fault in my usage/understanding of NDsolve Any help is appreciated edit: im aware that the equations arent yet in working order               n = 20;     g = 1;     pos = RandomReal[{-10, 10}, {n, 3}];     masses = RandomReal[{1, 50}, n];     Tmax = 20;          Forces[xp_, yp_, zp_] :=       Sum[       masses[[i]]/        EuclideanDistance[{xp, yp, zp}, {x[i][t], y[i][t], z[i][t]}]^2       , {i, 1, n}]          Graphics3D[      Table[       Sphere[pos[[i]], ((masses[[i]]*4)/(3*Pi))^(1/3)/5]       , {i, 1, n}]      , PlotRange -> 11.5]          sol = NDSolve[       Flatten@Table[         {          (x[i])''[t] == Forces[x[i][t], y[i][t], z[i][t]][[1]]/masses[[i]],          (y[i])''[t] == Forces[x[i][t], y[i][t], z[i][t]][[2]]/masses[[i]],          (z[i])''[t] == Forces[x[i][t], y[i][t], z[i][t]][[3]]/masses[[i]],          (x[i])'[0] == 0,          (y[i])'[0] == 0,          (z[i])'[0] == 0,          x[i][0] == pos[[i, 1]],          y[i][0] == pos[[i, 2]],          z[i][0] == pos[[i, 3]]          }         , {i, 1, n}]       ,       Flatten@Table[         {          x[i][t], y[i][t], z[i][t]          }         , {i, 1, n}]       , {t, 0, Tmax}]


title: What is the order of faces on a D20? How can I optimize the order of faces on a D-n?

text: I am creating a customizable D20 for 3D printing using OpenSCAD, with the following code:               factor=5;     $fn=10;     PHI=(1+sqrt(5))/2;     //Taken from: http://en.wikipedia.org/wiki/Icosahedron#Cartesian_coordinates     //Specifically: http://en.wikipedia.org/w/index.php?title=Icosahedron&oldid=568753314#Cartesian_coordinates     POINTS =    [   [0,-1,-PHI] , [0,-1,+PHI] , [0,+1,-PHI] , [0,+1,+PHI] ,                     [-1,-PHI,0] , [-1,+PHI,0] , [+1,-PHI,0] , [+1,+PHI,0] ,                          [-PHI,0,-1] , [+PHI,0,-1] , [-PHI,0,+1] , [+PHI,0,+1]                  ]*factor;          FACES =[    [1,3,11],[1,11,6], [1,6,4], [1,4,10],[1,10,3],                  [3,5,7], [3,7,11], [3,5,10],[11,6,9],[11,7,9],                 [0,6,9], [0,6,4],  [0,8,4], [10,8,4],[10,8,5],                 [2,8,5], [0,2,9],  [0,2,8], [7,2,9], [5,2,7]];          function normal(n) =     //Calculates the position of the center of the nth face (also called the normal vector of the face)         POINTS[FACES[n][0]]/3 +         POINTS[FACES[n][1]]/3 +         POINTS[FACES[n][2]]/3 ;          //spheres at each vertex     hull(){         for(i=[1:12]){             translate(POINTS[i-1]) sphere(.0001);             }         }      An icosahedron has 12 vertices given by POINTS, and the faces (triangles) are formed by the triplets in FACES where each number i is the i-th element in the list POINTS. OpenSCAD uses the C convention where the first element is 0, not 1. Typical dice are numbered so that for an N-sided die, the number on a given side, and the number on an opposite side add up to N+1. How can I tell Mathematica to find the order of faces so that "ONE" should be placed at the face given by FACES[[1]], and all the other numbers should have the N+1 property above. For a given solid that would work as a die, is there another condition I have to apply? e.g. is it necessary or optimal to enforce or check that the sum of numbers around a given vertex (or edge?) is not more than a certain amount than the sum from another vertex or edge? From this picture (https://en.wikipedia.org/wiki/Dice#mediaviewer/File:6sided_dice.jpg) it seems that on a normal D6 that there is a vertex that is adjacent to 4,5,6 and therefore the opposite vertex is adjacent to 1,2,3. Here are the data in Mathematica format:               PHI=(1+Sqrt[5])/2;     POINTS = { {0,-1,-PHI} , {0,-1,+PHI} , {0,+1,-PHI} , {0,+1,+PHI} ,{-1,-PHI,0} , {-1,+PHI,0} , {+1,-PHI,0} , {+1,+PHI,0} , {-PHI,0,-1} , {+PHI,0,-1} , {-PHI,0,+1} , {+PHI,0,+1} };     FACES ={ {1,3,11},{1,11,6}, {1,6,4}, {1,4,10},{1,10,3}, {3,5,7}, {3,7,11}, {3,5,10},{11,6,9},{11,7,9}, {0,6,9}, {0,6,4}, {0,8,4}, {10,8,4},{10,8,5}, {2,8,5}, {0,2,9}, {0,2,8}, {7,2,9}, {5,2,7}};


title: Mathematica gives wrong result while Wolfram|Alpha is correct

text: ![Mathematica and Wolfram|Alpha output](http://i.stack.imgur.com/nIJ08.png) Why does _Mathematica_ and _Wolfram|Alpha_ give different results based upon the same code? I know _Wolfram|Alpha_ 's `7.85` is correct.


title: How to create a list of pre-defined functions?

text: I would like to create a list of Cauchy distribution pdf's, having different locations of their maxima, and being multiplied by different factors; then I'd like to calculate those functions' values for different values of `x`. I have searched on the Internet and tried various things, and I seem to be able to set up the list, but then I fail miserably when it comes to actually using the functions on arguments. Here's some code:               pos     = RandomReal[10,2]     factors = RandomInteger[{1,5},{2}]          gamma1 = 0.5          peaks = Table[factors[[i]]*PDF[CauchyDistribution[pos[[i]],gamma1],x], {i,1,2}]     Print[ peaks ]     Print[ peaks[0.1][[1]] ]      This gives me               SetDelayed::noval: Symbol peaks in part assignment does not have an immediate value.          SetDelayed::noval: Symbol peaks in part assignment does not have an immediate value.     {3.183098861837907/(1 + 4.*(-6.1318667717670134 + x)^2), 0.6366197723675814/(1 + 4.*(-1.3741656250222944 + x)^2)}     0.1      How can I use each element of my array `peaks` like an individual function? (I'm an absolute Mathematica-beginner, so in advance: sorry for the noob- question...)


title: Automatizing PSfrag export

text: I'm in the early phase of creating a Mathematica function (or package) that exports graphics such that they can be used with $\LaTeX$'s PSfrag. ## The goal Ideally, the function should take a graphic created in Mathematica, replace all text elements with labels and export the labeled graphic along with a text file containg the corresponding `\psfrag` commands. It should be possible to do all the layouting in Mathematica, preserving as much of the style, font size/weight/color and positioning of the text in the graphic. The only things that should be affected are the font family (so that everything appears in $\LaTeX$ font) and the typesetting of mathematical expressions. * * * ## Problem 1: Placing text in EPS Consider a plot that somewhere has the number 10000 as a tick (or frame tick). If you export this plot to EPS, and then import it again, the resulting Mathematica `Graphics` object features two text elements `10` and `000`. This makes replacing single numbers with PSfrag quite a lot harder than one would think. Is there a way to force Mathematica to insert `10 000` as a single text element? * * * ## Problem 2: Extracting frame ticks As a first try, I tried extracting all `Ticks` or `FrameTicks`from a graphic using `AbsoluteOptions`. This works nicely for many cases, but I encountered some strange behavior. Consider the two plots               frPlot1 = Plot[x^2, {x, 0, 1000}, Frame -> True, FrameTicks -> True];     frPlot2 = Plot[x^2, {x, 0, 1000}, Frame -> True, FrameTicks -> All];      Their output looks just as one would expect from reading the documentation of `FrameTicks`:               True    tick marks placed automatically on bottom and left edges     All     tick marks placed automatically on all edges      Determining the ticks for `frPlot1` using `AbsoluteOptions[frPlot1, FrameTicks]` works just fine. But trying the same with `frPlot2` results in an error:               Ticks::ticks: All is not a valid tick specification.      How can `All`not be a valid specification when the documentation states that it is? * * * ## Future Problems Depending on the answers to the two questions above, there will probably arise some new questions. I will keep this post updated. I can also post the code of my first try with automatizing the tick extraction, if that is wanted.


title: How to further process a 2 dimensional list created with tuples

text: I created with `Tuples[{{USD, EUR, JPY}, {UP, DOWN}}]` the following result: `{{USD, UP}, {USD, DOWN}, {EUR, UP}, {EUR, DOWN}, {JPY, UP}, {JPY, DOWN}}` I want to further have a 3 dimensional list of all combinations - but the same currency does not appear twice. Example output `{{{USD, UP}, {EUR, UP}, {JPY, UP}}, {{USD, UP}, {EUR, UP}, {JPY, DOWN}}, {{USD, UP}, {EUR, DOWN}, {JPY, UP}}, {{USD, UP}, {EUR, DOWN}, {JPY, DOWN}}, ... {{USD, DOWN}, {EUR, DOWN}, {JPY, DOWN}}}` Is there a simple way to do it?


title: High Contrast Syntax-Highlighting

text: I have a neurological disorder which causes me to have migraines if I look at a white computer screen. To combat this, I have put the following at the top of all of my Mathematica notebooks:               SetOptions[EvaluationNotebook[],     Background -> RGBColor[0.0, 0.0, 0.0],     FontColor -> RGBColor[1.0, 1.0, 1.0],     FontSize -> 16     ]      This turns the background black and the letters white. However, Mathematica's built-in Syntax highlighting does not change. In order to read the Syntax Highlighing I have to manually go into: In Edit -> Preferences -> Syntax Coloring -> Other:   * Comments -> Megenta   * Strings -> Light Yellow   * Global -> Bright Blue In Edit -> Preferences -> Syntax Coloring -> Local Variables;   * The local variables of Module With -> Bright Green;   * Function arguments and patter names -> Bright Green;   * Variables made special by use in arguments -> Sky Blue; The above commands permanently change the syntax highlighting. If possible, I would like to be able make the above changes in the Mathematica Notebook so that the changes only affect the notebook I am working in. So, my question is... QUESTION: Rather than do the above steps manually, is there a command I can put at the top of the file that will make these changes for me?


title: How do I determine astronomical transit times?

text: _Mathematica_ , through the "legacy" _Scientific Astronomer_ package, used to have the ability to easily determine accurate transit times of astronomical objects simply, with `Culmination[object, neardate]`; but now lacks this feature. Is there a way to use `AstronomicalData` to do this?


title: How to see abstract syntax tree of Wolfram Language expression

text: I mean, suppose I have this expression: 2 + 2 I want to get something like this: Plus[2, 2] as an output. I've tried FullForm, but this just evaluates 2+2 and returns 4. Is this even possible?


title: No Tukey Test on ANOVA package

text: I'm trying to use the ANOVA package and have mathematica display the Tukey PostTest, but all I get is this:               ANOVA[Tratamientos, PostTests -> Tukey]          ANOVA::nottest: Tukey is not a valid PostTests entry, and will be ignored. Valid PostTests entries are Bonferroni, Tukey, StudentNewmanKeuls, Duncan, and Dunnett. >>      Any advice? Am I missing something? Thanks in advance


title: Selecting a Point that has the Lowest Absolute x/y-coordinate From a List of Points

text: Given that there is a set of points, for example, `{{3,4,2},{5,2,-1}}`. How do I go about selecting the point that has the lowest absolute x, y or z-coordinate from the list? In this case, the point selected should be `{{5,2,-1}}` as 1 is the lowest absolute value among all the points. Would the command `Select[{{3,4,2}, {5,2,-1}}, ...]` be good enough to perform such operation? Specifically, my understanding is that `Select[{{3,4,2}, {5,2,-1}}, ...]` is useful for selecting each individual point that satisfies certain condition stated in the command, so the question is whether it would be possible to compare 2 different points to select the desired point under the `Select[...]` operation. Or would there be a better alternative to getting the desired point?


title: Density plot for data with a wide dynamic range

text: I'm generating some figures for a paper. One of them has a pattern like the following figure:               DensityPlot[      Abs[Exp[-Sqrt[x^2 + y^2]/5] BesselJ[0, Sqrt[x^2 + y^2]]], {x, -20,        20}, {y, -20, 20}, ColorFunction -> "SunsetColors",       PlotPoints -> 100, PlotRange -> All, PlotRangePadding -> 0,       FrameTicksStyle ->        Directive[FontFamily -> "Arial", 12, Plain, Thick],       ImageSize -> {Automatic, 150}]      ![modulated Bessel beam](http://i.stack.imgur.com/OAawn.png) Since the magnitude in the middle could be much higher than that in the outer region, some rings cannot be seen if I print it. In addition, since the pattern represents magnitude, I prefer a kind of "hot" color map to render these data. How can I solve the problem such that the pattern can be seen clearly on a printed copy?


title: Computing the bounding boxes for Text objects

text: Regardless of `AspectRatio`, the `Text` boxes overlap.               TreeForm[#, AspectRatio -> 1/3, ImageSize -> 700]& @      Cases[        Import["http://www.weather.gov/data/current_obs/KOAK.xml", "XMLObject"],        XMLElement[tag:_, _, value:_] :> (tag -> value), Infinity     ]      ![Mathematica graphics](http://i.stack.imgur.com/mmbNF.png) More generally, I've asked Wolfram Research, Inc. about exposing bounding box coordinates for `Text` objects so that layout manager or engine can test overlap or compute tilings or disjoint positioning, but it appears to be complicated by the various `Text` options. Does anyone know how to at least conservatively approximate the `Text` bounding box?


title: Why doesn't Cases match all instances of XMLElement, given Infinity levelspec?

text: Why doesn't `Cases` match all instances of `XMLElement`, given `Infinity` levelspec?               Column@ Cases[     Import["http://www.weather.gov/data/current_obs/KOAK.xml","XMLObject"],     XMLElement[tag:_,_,value:_]:> (tag-> value),Infinity     ]           (* ==>     credit->{NOAA's National Weather Service}     credit_URL->{http://weather.gov/}     url->{http://weather.gov/images/xml_logo.gif}     title->{NOAA's National Weather Service}     link->{http://weather.gov}     image->{XMLElement[url,{},{http://weather.gov/images/xml_logo.gif}],XMLElement[title,{},{NOAA's National Weather Service}],XMLElement[link,{},{http://weather.gov}]}     suggested_pickup->{15 minutes after the hour}     suggested_pickup_period->{60}     location->{Oakland, CA}     station_id->{KOAK}     latitude->{37.7}     longitude->{-122.22}     observation_time->{Last Updated on Apr 11 2012, 12:53 pm PDT}     observation_time_rfc822->{Wed, 11 Apr 2012 12:53:00 -0700}     weather->{Mostly Cloudy}     temperature_string->{60.0 F (15.6 C)}     temp_f->{60.0}     temp_c->{15.6}     relative_humidity->{62}     wind_string->{Southwest at 13.8 MPH (12 KT)}     wind_dir->{Southwest}     wind_degrees->{220}     wind_mph->{13.8}     wind_gust_mph->{0.0}     wind_kt->{12}     wind_gust_kt->{0}     pressure_string->{1014.2 mb}     pressure_mb->{1014.2}     pressure_in->{29.95}     dewpoint_string->{46.9 F (8.3 C)}     dewpoint_f->{46.9}     dewpoint_c->{8.3}     windchill_string->{58 F (14 C)}     windchill_f->{58}     windchill_c->{14}     visibility_mi->{10.00}     icon_url_base->{http://weather.gov/images/fcicons/}     two_day_history_url->{http://www.weather.gov/data/obhistory/KOAK.html}     icon_url_name->{bkn.jpg}     ob_url->{http://www.weather.gov/data/METAR/KOAK.1.txt}     disclaimer_url->{http://weather.gov/disclaimer.html}     copyright_url->{http://weather.gov/disclaimer.html}     privacy_policy_url->{http://weather.gov/notice.html}     current_observation->{XMLElement[credit,{},{NOAA's National Weather Service}],XMLElement[credit_URL,{},{http://weather.gov/}],XMLElement[image,{},{XMLElement[url,{},{http://weather.gov/images/xml_logo.gif}],XMLElement[title,{},{NOAA's National Weather Service}],XMLElement[link,{},{http://weather.gov}]}],XMLElement[suggested_pickup,{},{15 minutes after the hour}],XMLElement[suggested_pickup_period,{},{60}],XMLElement[location,{},{Oakland, CA}],XMLElement[station_id,{},{KOAK}],XMLElement[latitude,{},{37.7}],XMLElement[longitude,{},{-122.22}],XMLElement[observation_time,{},{Last Updated on Apr 11 2012, 12:53 pm PDT}],XMLElement[observation_time_rfc822,{},{Wed, 11 Apr 2012 12:53:00 -0700}],XMLElement[weather,{},{Mostly Cloudy}],XMLElement[temperature_string,{},{60.0 F (15.6 C)}],XMLElement[temp_f,{},{60.0}],XMLElement[temp_c,{},{15.6}],XMLElement[relative_humidity,{},{62}],XMLElement[wind_string,{},{Southwest at 13.8 MPH (12 KT)}],XMLElement[wind_dir,{},{Southwest}],XMLElement[wind_degrees,{},{220}],XMLElement[wind_mph,{},{13.8}],XMLElement[wind_gust_mph,{},{0.0}],XMLElement[wind_kt,{},{12}],XMLElement[wind_gust_kt,{},{0}],XMLElement[pressure_string,{},{1014.2 mb}],XMLElement[pressure_mb,{},{1014.2}],XMLElement[pressure_in,{},{29.95}],XMLElement[dewpoint_string,{},{46.9 F (8.3 C)}],XMLElement[dewpoint_f,{},{46.9}],XMLElement[dewpoint_c,{},{8.3}],XMLElement[windchill_string,{},{58 F (14 C)}],XMLElement[windchill_f,{},{58}],XMLElement[windchill_c,{},{14}],XMLElement[visibility_mi,{},{10.00}],XMLElement[icon_url_base,{},{http://weather.gov/images/fcicons/}],XMLElement[two_day_history_url,{},{http://www.weather.gov/data/obhistory/KOAK.html}],XMLElement[icon_url_name,{},{bkn.jpg}],XMLElement[ob_url,{},{http://www.weather.gov/data/METAR/KOAK.1.txt}],XMLElement[disclaimer_url,{},{http://weather.gov/disclaimer.html}],XMLElement[copyright_url,{},{http://weather.gov/disclaimer.html}],XMLElement[privacy_policy_url,{},{http://weather.gov/notice.html}]}     *)


title: PieChart with radial coloring/color function

text: I am trying to visually compare multiple functions that depend on a single argument running from $0$ to $1$. They describe a radial property and so I thought it would be nice to use a kind of `PieChart` plot where the function values are used as a color function to fill the pie. The best I could come up with is the following:                SectorPlot[func_List, label_List, colorrange_: {0, 66.7},        opts : OptionsPattern[]] /; Length[func] == Length[label] :=       Module[{div, len, sectors, size, wedge, colorbar},      len = Length[func];      sectors = makesectors[len];      size = 300;      colorbar[colorFunction_: Automatic, range_: colorrange, divs_: 25] :=      DensityPlot[y, {x, 0, .1}, {y, First@range, Last@range},      (* Remove possible PlotRange specification from the options,       which would mess up the bar*)      Evaluate[      FilterRules[{opts},        Cases[Options[DensityPlot], Except[PlotRange -> _]]]],      AspectRatio -> 10,      PlotRangePadding -> 0,      PlotPoints -> {2, divs},      MaxRecursion -> 0,      FrameTicks -> {None, Automatic, None, None},      ColorFunctionScaling -> False,      ColorFunction -> colorFunction];      (* now the pie function*)      wedge[fun_, {minangle_, maxangle_}, lab_] := Show[{      ParametricPlot[{v Cos[u], v Sin[u]}, {u, minangle, maxangle}, {v,         0, 1},       Evaluate[FilterRules[{opts}, Options[ParametricPlot]]],        ColorFunction -> (ColorData[{"Rainbow", colorrange}][fun[#4]] &),       ColorFunctionScaling -> False,       Mesh -> False,       ImagePadding -> All,       BoundaryStyle -> Directive[Thick, Black],       Frame -> False,       Axes -> False,       PlotRange -> {-1.2, 1.2},       Background -> Transparent],       Graphics@Text[        Style[lab, Bold, FontFamily -> "Times"], {         1.1 Cos[Mean[{minangle, maxangle}]],         1.1 Sin[Mean[{minangle, maxangle}]]},        {         -Cos[Mean[{minangle, maxangle}]],         -Sin[Mean[{minangle, maxangle}]]}        ]}];      Row[{      Show[Table[       wedge[func[[i]], sectors[[i]], label[[i]]], {i, 1, len}],      ImageSize -> {Automatic, size},       ImagePadding -> 20],       Show[colorbar[ColorData[{"Rainbow", colorrange}], colorrange],       ImageSize -> {Automatic, size},       ImagePadding -> 20]}]]      I used the answers to this post to set up the colorbar in a `Row`. Here is an example.               SectorPlot[{       (60 Sin[4.3 # + 0.3]) &,       (50 Sin[12 # + 0.1]) &,       (66 Cos[7.3 # + 0.3]) &,       (60 Tan[1.2 #]) &,       (60 Cos[23.5 # - 0.1]) &},       {"1", "2", "3", "4", "5"}, {0, 70},       BoundaryStyle -> Directive[Thick, Darker@Gray],        PlotRange -> {-1.2, 1.2}]      ![output](http://i.stack.imgur.com/9n1fL.png) Everything looks OK, but it looks like a lot of effort given the fact that we have very powerful `PieChart` functionalities. Imagine I have to provide longer labels:                SectorPlot[{       (60 Sin[4.3 # + 0.3]) &,       (50 Sin[12 # + 0.1]) &,       (66 Cos[7.3 # + 0.3]) &,       (60 Tan[1.2 #]) &,       (60 Cos[23.5 # - 0.1]) &},      {"12345678901234567890", "12345678901234567890",        "12345678901234567890", "12345678901234567890",        "12345678901234567890"}, {0, 70},      BoundaryStyle -> Directive[Thick, Darker@Gray], PlotRange -> {-2, 2}]      ![output](http://i.stack.imgur.com/3FxzL.png) Note the rescaled pie chart. I am sure I could pimp my function a lot more to handle this automatically, all suggestions are welcome. But my main question would be: Is there an easier way that uses the built-in `SectorChart`, `PieChart`, etc. commands together with a radial color function? (of course I still need the colorbar.)


title: How to match a sequence of complex patterns?

text: I have list with the form `{{a1,b1}->{x1,y1},{a2,b2}->{x1,y2},...}` where the `{ai,bi}`'s can be `{}`. I know the elements of the list can be matched by `{___} -> {_, _}`, but I don't know how to match a list of this form. So how can I match it? **UPDATE** : I meant a pattern test: To test whether a list is in this form


title: Only final result from NDSolve

text: Finally I started to play with differential equations in _Mathematica_. And I have faced the problem, which seems too me so basic that I'm afraid this question is going to be closed soon. However, I've failed in finding solution here or in documentation center. **My question is: how to set that`NDSolve` will not save whole `InterpolationFunction` for the result?** I'm only interested in final coordinates or for example each 100th. Is there simple way to achieve that? * * * Anticipating questions:   * I know I can do something like `r /@ Range[0.1, 1, .1] /. sol` at the end, but still, there is whole interpolating function in memory. I want to avoid it because my final goal is to do N-Body simulation where N is huge and I will run out of the memory quite fast. What is important to me is only the set of coordinates as far in the future as it can be, not intermediate values.   * I can write something using `Do` or `Nest` but I want to avoid it since `NDSolve` allows us to implement different solving methods in handy way.   * I saw WolframDemonstrations/CollidingGalaxies and it seems there is an explicit code with `Do` :-/   * Another idea would be to put `NDSolve` into the loop but this seems to be not efficient. Could it be even compilable? * * * Just in case someone want to show something here is the sample of code to play with:               G = 4 Pi^2 // N ;          sol = NDSolve[{                    r''[t] == -G r[t]/Norm[r[t]]^3,                    r[0] == {1, 0, 0},                    r'[0] == {0, 2 Pi // N, 0}                   },                   r,                   {t, 0, 1}, Method -> "ExplicitRungeKutta", MaxStepSize -> (1/365 // N)                  ]           ParametricPlot3D[Evaluate[r[t] /. sol], {t, 0, 1}]            (* Earth orbiting the Sun. Units: Year/AstronomicalUnit/SunMass           in order to express it simply*)


title: Does OpenCL/Cuda memory leak if not Unloaded? Problem with allocating/loading GPU memory in Module

text: The GPU memory manager documentation is not too clear, does GPU memory leak if not explicitly unloaded or if the symbol that holds the reference to the GPU memory gets collected, the GPU memory gets freed too? In my experience, MemoryInUse doesn't grow if I keep loading GPU memory (but losing the symbols, e.g., the memory is in temporary variables), but MathKernel.exe memory usage does! My problem in this matter is that I have to allocate GPU memory in Module[] temporary variables, so I don't have (well know) any way of unloading it manually afterwards... Is there a way to add a "destructor" to Mathematica symbols, so I can manually call Unload when the symbol is reclaimed? This MathKernel behaviour is observed on Mathematica 8.0


title: DirectAgglomerate not working for Large Matrices

text: I am trying to graphically display a distance matrix with similar elements visually clustered into groups. My original matrix has the elements in a random order so the first thing I do is to change the ordering of those elements using `DirectAgglomerate`               Needs["HierarchicalClustering`"]          ClusteringPermutation[distanceMatrix_, linkage_] :=       Module[{indices, cluster},         indices = Range[Length @ distanceMatrix];         cluster = DirectAgglomerate[distanceMatrix, indices, Linkage -> linkage];         Reverse @ ClusterFlatten[cluster]       ]      My overall function to permute the matrix then looks like this:               PermuteMatrix[distanceMatrix_, linkage_] :=       Module[{newOrder},         newOrder = ClusteringPermutation[distanceMatrix, linkage];         distanceMatrix[[newOrder, newOrder]]     ]      Given an example matrix:               sampleMatrix =        {{1, 1, 0, 0, 1}, {1, 1, 0, 0, 1}, {0, 0, 1, 1, 0}, {0, 0, 1, 1, 0}, {1, 1, 0, 0, 1}};     PermuteMatrix[sampleMatrix, "Single"]      > >     {{1, 1, 0, 0, 0}, {1, 1, 0, 0, 0}, {0, 0, 1, 1, 1}, {0, 0, 1, 1, 1}, {0 > ,0, 1, 1, 1}} >   The matrix is now rearranged with the similar clusters being together. I then plot the result as a heat map while applying the same permutation to the element labels. Everything works fine until I get to matrices over `250 x 250` in size. In this case, the _Mathematica_ kernel crashes for some reason when evaluating `DirectAgglomerate`. Is this the limitation of the function or am I doing something clearly wrong? Any help would be greatly appreciated. I am definitely no expert on clustering; perhaps there is a completely different way to go about this? UPDATE (09.10.13) Tried to use `MinimumBandwidthOrdering` as suggested by bill s but quickly ran into issues with larger matrices where groups of similar samples were broken up. Here's an example:               mSubset={{0, 0, 0.272352, 0, 0.272364, 0.272261, 0, 0.272269}, {0, 0,      0.272501, 0, 0.272514, 0.272411, 0, 0.272419}, {0.272352, 0.272501,      0, 0.272038, 0, 0, 0.272158, 0}, {0, 0, 0.272038, 0, 0.272049,      0.271947, 0, 0.271955}, {0.272364, 0.272514, 0, 0.272049, 0, 0,      0.272169, 0}, {0.272261, 0.272411, 0, 0.271947, 0, 0, 0.272068,      0}, {0, 0, 0.272158, 0, 0.272169, 0.272068, 0, 0.272075}, {0.272269,     0.272419, 0, 0.271954, 0, 0, 0.272075, 0}}          permutedMatrixOrig = PermuteMatrix[msubset, "Single"]     {r, c} = MinimumBandwidthOrdering[msubset, Method -> "Sloan"];     {r2, c2} = MinimumBandwidthOrdering[msubset, Method -> "RCMD",      RefinementMethod -> None];     {ArrayPlot[msubset],      ArrayPlot[permutedMatrixOrig],      ArrayPlot[msubset[[r, c]]],      ArrayPlot[msubset[[r2, c2]]]}      ![MatrixImage](http://i1161.photobucket.com/albums/q504/mikachu12/MatrixExample_zps517644fb.png) I have tried playing around with the method and refinement options but was still unable to fully group all my samples. I have also noticed that for very large matrices my indices for rows and columns were different - could this have something to do with my matrices not being fully symmetrical?


title: Export multiple graphics into same file

text: I have a plot and a table that I am trying to plot in a single file together. I have a "working" example, but it is not perfect. I export a list, but it keeps the commas and brackets, that is the only problem so far. Export[dir, {plot, table}]; I have tried using CreateDocument, but this comes with formatting issues that are unacceptable. Plot being cut off etc. I know a way that works, but it is not automated. Manually merging the output cells for plot and table, then saving the selection as. **Update w/ solution:** As per mfvonh's suggestion I used row and it solved my problem. Export[dir, Row[{plot, table}]]


title: TimeConstrained dynamic change of maximum time

text: I would like to run a time consuming function:               TimeConstrained[f[x],maxseconds]      and be able to change maxseconds during running (increasing or decreasing max time) using a slider. Ideally when i decrease maxseconds below the time it has already consume it will stop. I could implement such a functionality inside f but i would have to do this for all f i want to create , so this way is out of the question. Thanks in advance, Theodore.


title: Error in using EventLocator in NDSolve

text: I have a problem in using EventLocator in Mathematica 9. However, this error doesn't show up in Mathematica 8 on my labtop. My code is,               η=G[x[n],y[n]];          pde = {x''[n] == -(1 - (x'[n]^2 + y'[n]^2)/(4*x[n]^2))*(3*x'[n] +              2*x[n]^2*\!\(     \*SubscriptBox[\(\[PartialD]\), \(x[n]\)]V\)/V) + (x'[n]^2 - y'[n]^2)/          x[n], y''[n] == -(1 - (x'[n]^2 + y'[n]^2)/(4*x[n]^2))*(3*y'[n] +              2*x[n]^2*\!\(     \*SubscriptBox[\(\[PartialD]\), \(y[n]\)]V\)/V) +           2*(x'[n]*y'[n])/x[n]};     bc = {x[0] == saddle, y[0] == 0.01, x'[0] == 0, y'[0] == 0};     Sol = NDSolve[{pde, bc}, {x, y}, {n, 0, 1000}, MaxSteps -> 50000,        AccuracyGoal -> Automatic,        Method -> {"EventLocator", "Event" -> η - 1,          "EventCondition" -> (n > 60)}]      The error message is, > NDSolve::evboo: The value of the event function at n = 61.76853457162405` > was not True or False. When not True, the value will be considered as False. > >> This is quite strange as there is no problem in running this on Mathematica 8.


title: merge daily and hourly time series data

text: I have two lists of time series data. One of the lists is daily and is formatted like this;               daily={{{2011, 7, 1, 6, 0, 0.}, 284606., 16735.3}, {{2011, 7, 2, 6, 0, 0.},      285283., 16669.9}, {{2011, 7, 3, 6, 0, 0.}, 287529., 16445.5}}      And another list which is hourly;               hourly={{{2011, 7, 1, 6, 0, 0.}, {3, 861, "", 2 ""}}, {{2011, 7, 1, 7, 0,      0.}, {3, 270, "", 2 ""}}, {{2011, 7, 1, 8, 0, 0.}, {3, "", "",2 ""}}}      I would like to merge the two list so the two values in the daily list repeat in the corresponding hourly list. For the data given the result would look like this;               merged={{{2011, 7, 1, 6, 0, 0.},3, 861, "", 2 "", 284606., 16735.3},        {{2011, 7, 1, 7, 0,0.}, 3, 270, "", 2 "", 284606., 16735.3},     {{2011, 7, 1, 8, 0, 0.}, 3, "", "",2 "", 284606., 16735.3}}}      I would like to match the two sets by the year-month-day data. The time part of the daily data can be ignored. I ended up coding a for loop that iterated through both lists to do the merge (after several attempts at doing this in a more elegant way). What I'm looking for is the proper way to do this in Mathematica, not a For loop that I could have done in C. Any help would be greatly appreciated. Finding the intersection of two date lists


title: Monochrome PNG (and GIF) Export

text: Is there a way to `Export` expressions to a monochrome PNG? I have tried the `ColorQuantize` function which is mentioned in comments to this question. However, the resulting PNG image of `ColorQuantize[TraditionalForm[MyExpression], 2]` is still of depth 24b. GIF file's depth appears to be 2, which is OK but it still looks like a cheat, and yes, PNG is more desired in my case. Rasterizing formulas before exporting also seems to be an unnatural hack that could and should be avoided in some way. I could `Export` my expressions to PDF and then GhostScript them (say, via `Run`) using GhostScript's _pngmono_ device but _Mathematica_ 's current PDF Export is quite buggy. (It doesn't even print \\[Bullet] correctly; TraditionalForm is lost, etc.) Printing selection to PDF and GhostScripting the result would do the thing for me… but there seems to be no way to do it ‘in a background mode’ using _Mathematica_ commands.


title: A matrix-vector cross product

text: I want to do a cross product involving a vector of Pauli matrices $\vec \sigma = \left( {{\sigma _1},{\sigma _2},{\sigma _3}} \right)$; for example, $\vec \sigma \times \left( {1,2,3} \right)$.               s:= Table[PauliMatrix[i], {i, 1, 3}];     Cross[s,{1,2,3}]      The code above will not work. The only way I can think of is to use the method which I have just learned from Mr. Wizard:               ReleaseHold @ Block[{PauliMatrix}, Hold @@ {Cross[s,{1, 2, 3}]}]      But I feel uncomfortable writing such long code to realize such a simple cross product. Is there any better way or not? * * * **Update** J.M. give the method               Cross[Unevaluated /@ PauliMatrix[Range[3]], {a,b,c}]      But it turns out that when one of the a,b,c is zero, the code will give error. a Remedy is given by J.M in his comment. But I am asking here why it gives right answer when a b c are all nonzero while failed with a zero component?


title: Using transfer function model to generate state space model

text: I am trying to generate the state space model for the following system: ![enter image description here](http://i.stack.imgur.com/rPXbw.png) However, the following code does not generate the state space model I expect:               tf = TransferFunctionModel[{{1/s}, {1/(s + 2)}}, s]     ssm = StateSpaceModel[tf]      What I'm expecting is $A = \begin{bmatrix} -2 & 0 \\\ 1 & 0 \end{bmatrix}$ $B = \begin{bmatrix} 0 \\\ 1 \end{bmatrix}$ $C = \begin{bmatrix} 0 & 1 \\\ 1 & 0 \end{bmatrix}$ $D = \begin{bmatrix} 0 \\\ 1 \end{bmatrix}$ but what I'm getting is $A = \begin{bmatrix} 0 & 1 \\\ 0 & -2 \end{bmatrix}$ $B = \begin{bmatrix} 0 \\\ 1 \end{bmatrix}$ $C = \begin{bmatrix} 2 & 1 \\\ 0 & 1 \end{bmatrix}$ $D = \begin{bmatrix} 0 \\\ 0 \end{bmatrix}$ The state equations are: $$\dot{x_1}(t) = -2 x_1 (t) + w_1 (t) $$ $$\dot{x_2}(t) = x_1(t) + u(t)$$ $$y_1(t) = x_2(t)$$ $$y_2(t) = \dot{x}_2(t)$$ where $w_1(t)$ denotes the white noise added to the system, and $x_2(t)$ denotes the system error, $e$. How should I enter my transfer function model to generate such a state space model?


title: gridlines in a plot

text: Please, someone to help me to abbreviate this commmand > ContourPlot[{x^2 - 2 y^2 == 1, x^2 - 5 y^2 == 1, x^2 - 10 y^2 == 1}, {x, > -15, 15}, {y, -15, 15}, GridLines -> {{-15, -14, -13, -12, -11, -10, -9, -8, > -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, > 14, 15}, {-15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, > 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}}] This deploys: ![enter image description here](http://i.stack.imgur.com/k6woL.png)