title: How to place an image inside a notebook, with the minimum memory footprint?

text: When creating a notebook with images, like photos, the file tends to quickly get big, which makes it difficult to use the notebook format for training material containing a lot of images. Are there different ways of passing an image into a notebook, in what concerns memory used? (please note that the purpose is to show the images in the “middle” of other content, like text, etc, and not simply have the image information in some kind of abstract code) I've noticed that every time I copy an image to a notebook, its `FullForm` reveals that it is "stored" with an "exhaustive" description of each pixel color value(s).   * Is there a way of storing it with indexed color definition (like the GIF format)?   * Is there a way of storing it with some kind of compression (like JPG or similar)? **EDIT:** Meanwhile I discovered the following curiosity: if I `Import` a gif file (of my printscreen), and then save it, my file gets to 150 kb. If I save it again (without changing anything), it gets reduced to 32 kb. If instead of `Import`ing it, I just copy it from the clipboard to the notebook, it always keeps the 150 kb.


title: Quickly selecting for points in a set that are within a critical distance of points in another set

text: Imagine two lists of two-dimensional coordinates:               listA = RandomReal[{0,100},{202,2}];     listB = RandomReal[{0,100},{97,2}];      I'm attempting to quickly generate a new series of lists, `outputListA` and `outputListB` consisting of the indices for the set of points in `listA` and `listB`, respectively, that are within some Euclidean distance $D$ of a point in a list for which they are not a member (i.e. points in `listA` that are at most a distance `distCut` from at least one point in `listB` and vice versa). This isn't the right way to do things (it takes $\approx 88$ milliseconds for sizes of `listA` and `listB` shown), but it hopefully illustrates what I'm trying to do:               listA = RandomReal[{0, 100}, {202, 2}];     listB = RandomReal[{0, 100}, {97, 2}];          outputList = {};     distCut = 1;          For[x = 1, x <= Length[listA], x++,      For[y = 1, y <= Length[listB], y++,        If[EuclideanDistance[listA[[x]], listB[[y]]] <= distCut,          outputList = Append[outputList, {x, y}];          ];        ];      ];          outputListA = Intersection[outputList[[All, 1]], outputList[[All, 1]]];     outputListB = Intersection[outputList[[All, 2]], outputList[[All, 2]]];          Length[outputListA]     Length[outputListB]      A smarter way to proceed might be to round values in `listA` and `listB` to a multiple of `distCut`, and then check for values in the rounded lists that are equal. However, I can't think of a good way to do this that avoids unnecessary attrition / misses points. A thought - Can we repeatedly apply `Nearest` for each point $p_i$ in `listA` until we find a point that is more than a distance `distCut` from $p_i$? Is `Nearest` doing anything more sophisticated than sequentially scanning through all of the points in a comparison list and checking Euclidean distances? Update - I've specified now that `outputListA` and `outputListB` should consist of the indices of the points in `listA` and `listB` satisfying the distance cutoff criterion.


title: PlotMarkers doesn't inherit PlotStyle when first argument to Graphics isn't a list

text: Could somebody explain, why `Circle` does not inherit the `PlotStyle` of the plot when used as `PlotMarkers`? Here is an example:               l1 = RandomInteger[100, {20, 2}]     cross = Graphics[{Line[{{-1, 1}, {1, -1}}], Line[{{1, 1}, {-1, -1}}]}];     circle = Graphics[Circle[{0, 0}, 1]];     ListPlot[l1, PlotStyle -> Thick, PlotMarkers -> {cross, .03}]     ListPlot[l1, PlotStyle -> Thick, PlotMarkers -> {circle, .03}]      ![Mathematica graphics](http://i.stack.imgur.com/jOTjD.png) This seem to work as expected, but the only difference is that Graphics is given a list of primitives:               circle1 = Graphics[{Circle[{0, 0}, 1]}];     ListPlot[l1, PlotStyle -> Thick, PlotMarkers -> {circle1, .03}]      ![Mathematica graphics](http://i.stack.imgur.com/qAgyO.png)


title: Mathematica presentations - will the Apple infra-red remote change slides?

text: I have a presentation to do and i am thinking about using _Mathematica_ instead of Powerpoint/Keynote as i have quite a few animations i would like to show. When using _Mathematica_ in slideshow mode, will the Apple remote work and let me move between slides ?


title: Numerical integration with purely numerical integrand

text: I'm trying to perform a numerical integral with an integrand that should not be manipulated with any symbolic preprocessing whatsoever. Consider the following simple test :               test[a_]:=If[NumericQ[a],a*a,Abort[] (*Meaning the parameter a is not numerical*)]      So if the parameter of `test` is numerical, this function should only return `a*a`. Now if I try to integrate this as follows:               NIntegrate[test[a],{a,-0.5,0.5},Method -> {Automatic, "SymbolicProcessing" -> 0}]      this does not work (it will be aborted). **Is there any way around this ? I.e. some option I haven't considered for NIntegrate ?** Note that an easy way to fix this would be to use:               test[a_?NumericQ]:=If[NumericQ[a],a*a,Abort[]]      But **I want to avoid using** `?NumericQ`since this slows down your numerical integration by a lot...


title: JewishNewYear date limitation

text: The documentation for the function "JewishNewYear" in the "calendar" package declares that the year argument must be between 1900 and 2100. No explanation is given for this limitation. The function continues to produce seemingly correct dates for years outside of that range. The Jewish calendar is mathematically determined, so there should be no reason for the algorithm to fail outside that range. Moreover, a recreation of the function using CalendarChange produces the same answers as JewishNewYear, for any Gregorian year:               JewishNewYear2[year_] :=  CalendarChange[{First[CalendarChange[{year, 8, 1},      Gregorian, Jewish]] + 1, 7, 1}, Jewish, Gregorian]      Anyone have any idea why the documentation would say that JewishNewYear doesn't work outside of 1900 to 2100?


title: How can I get the exact real solution of this equation?

text: I want to solve the equation               Sqrt[x] + Sqrt[1 - x^2] == Sqrt[2 - 3 x - 4 x^2]      with real solutions (in the real domain).   I tried               Solve[ Sqrt[x] + Sqrt[1 - x^2] == Sqrt[2 - 3 x - 4 x^2], Reals]      > >     {{x -> Root[-1 + 10 #1^2 + 9 #1^4 &, 2]^2}} >   and also               Reduce[ Sqrt[x] + Sqrt[1 - x^2] == Sqrt[2 - 3 x - 4 x^2] && x ∈ Reals, x, Complexes]      > >     x == -1 - Sqrt[2] || x == 1/9 (-5 + Sqrt[34]) >   The real solution of the given equation is `x == 1/9 (-5 + Sqrt[34])` With _Maple_ I got ![enter image description here](http://i.stack.imgur.com/5BLkr.jpg)


title: Problems with NMinimize

text: I have written some functions that take a matrix and find its minimum inner product with a specific set of vectors               LowerBound3d[M_] :=      NMinimize[{1/4 xy3d[\[Alpha], \[Beta], \[Gamma], \[Delta]].M.xy3d[\[Theta], \     \[Phi], \[Chi], \[Eta]], \[Alpha] >= 0 && \[Alpha] <= Pi && \[Beta] >=       0 && \[Beta] <= 2 Pi && \[Gamma] >= 0 && \[Gamma] <=       Pi && \[Delta] >= 0 && \[Delta] <= 2 Pi && \[Phi] >=       0 && \[Phi] <= 2 Pi && \[Theta] >= 0 && \[Theta] <=       Pi && \[Chi] >= 0 && \[Chi] <= Pi && \[Eta] >= 0 && \[Eta] <=       2 Pi}, {\[Alpha], \[Beta], \[Gamma], \[Delta], \[Theta], \[Phi], \     \[Chi], \[Eta]}]      I am trying to find matricies that are "positive definite" for these vectors "xy3d" (which are product vectors in two spherical subspaces). In the above function, I scan over all values the left and right vectors independently, but this of course should contain the case where one vector is the same as the other. I used this code to get a list of "positive definite" matrices. The problem is, the minimization is completely untrustworthy. When I rewrite the function with the vectors being the same (i.e. the same polar variables)               LowerBound3dtest[M_] :=      NMinimize[{1/4 xy3d[\[Alpha], \[Beta], \[Gamma], \[Delta]].M.xy3d[\[Alpha], \[Beta], \[Gamma], \[Delta]], \[Alpha] >= 0 && \[Alpha] <= Pi && \[Beta] >=       0 && \[Beta] <= 2 Pi && \[Gamma] >= 0 && \[Gamma] <=       Pi && \[Delta] >= 0 && \[Delta] <= 2 Pi}, {\[Alpha], \[Beta], \[Gamma], \[Delta]}]      Suddenly, matrices that worked before (inner product always positive) no longer work. This confused me because the second code is a special case of the first code, and they should give the same results (i.e. positive definite). Im a physics phd so woefully untrained in coding - any advice would be massively appreciated. Ive been stuck on this for weeks! UPDATE: thanks for all the comments. Here is a sample matrix to try out {{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}}


title: Plot function on different intervals with different colors

text: ![Sin\[x\]](http://i.stack.imgur.com/Xui8H.png)               Show[Plot[Sin[x], {x, 0, \[Pi]}, PlotStyle -> Red,                PlotRange -> {{0, 2 \[Pi]}, {-1, 1}}],           Plot[Sin[x], {x, \[Pi], 2 \[Pi]}, PlotStyle -> Green,                PlotRange -> {{0, 2 \[Pi]}, {-1, 1}}]]      Is there a simpler way of doing this? Especially, one that does not require repeating the Plot command 2 times ;)


title: NDSolve: Reinitialize fails with If condition

text: I have found a weird problem using If conditions containing an state inequality of the form `state<=`. First consider the simple ODE with an If condition `t<=2`. We first process the equations.               state = First@NDSolve`ProcessEquations[{r'[t] == If[t <= 2, 2, 0], r[0] == 0},r, t]     NDSolve`StateData[SequenceForm["<", 0., ">"]]      Then we reinitialize the system by               newstate = NDSolve`Reinitialize[state, {r[0] == 1}]     NDSolve`StateData[SequenceForm["<", 0., ">"]]      which works absolutely fine. Now consider another ODE system with a slightly different If condition, namely `If[r[t] <= 2, 2, 0]`. We process the equations with               state2 = First@NDSolve`ProcessEquations[{r'[t] == If[r[t] <= 2, 2, 0], r[0] == 0},r, t]     NDSolve`StateData[SequenceForm["<", 0., ">"]]      which works fine. Now when we try to reinitialize this system we get an error message!               newstate2 = NDSolve`Reinitialize[state2, {r[0] == 1}]     NDSolve`Reinitialize::ntcs: Cannot solve constraint equations for initial conditions.      It seems like when I try to reinitialize Mathematica has a problem due to the condition `r[t]<=2`. I have noticed the same problem with for example PieceWise functions, as noted in this post: NDSolve: ProcessEquations and Reinitialize with Piecewise functions


title: NIntegrate and NumericQ

text: I need to do numerical integration --> differentiation --> numerical integration. I tried to apply the technique described in the accepted answer to a similar question:               y = t^2 x^2;     f[t_?NumericQ] := NIntegrate[y, {x, 1, 2}]     g[t_?NumericQ] := D[f[t], t]     NIntegrate[g[t]*t, {t, 1, 2}]      However, it still generates the error:               NIntegrate::inumr: The integrand g[t] has evaluated to non-numerical values for all sampling points in the region with boundaries {{1,2}}. >>      This approach won't work due to the differentiation in between. What am I missing?


title: How to find the zeros of a Complex trigonometric function

text: I tried this               ContourPlot[(-100 -           50 Cos[γ]) Sin[β] (50 Cos[γ] Sin[β] - (          50 Cos[β] Cos[γ] (-200 +              Cos[β] (50 + 50 Sin[γ])))/Sqrt[          6400 - (200 - Cos[β] (50 + 50 Sin[γ]))^2]) +        50 Cos[β] Sin[γ] (Cos[β] (50 +              50 Sin[γ]) + (          Sin[β] (50 + 50 Sin[γ]) (-200 +              Cos[β] (50 + 50 Sin[γ])))/Sqrt[          6400 - (200 -              Cos[β] (50 + 50 Sin[γ]))^2]), {β, 0,        2 Pi}, {γ, 0, 2 Pi}]      but it does not produce anything. Could someone explain why and how to fix it?


title: Compare elements in a list

text: Assume that there are three different points in x-y coordinate like:               p1={4, -1};     p2={5, -2};     p3={1, 5};      In order to compare these points to each other in a specific criteria, I have first built `List1` which includes the whole possible states:               List1={{{4, -1}, {5, -2}}, {{4, -1}, {1, 5}}, {{1, 5}, {5, -2}}};      The criteria is: > If any of these two points has an x value bigger than the x value of the > other point and a y value smaller than the y value of the other point, add > this point to a different list. Otherwise move on to the next pair of > points. Give a number which shows how many times point1 from List1 satisfies > the criteria. In order to clarify the problem : > first element of `List1` includes two points : `{{4, -1}, {5, -2}}` `point1 > = {4, -1}` and `point2 = {5, -2}`. x1 = 4 < x2 = 5 and y1 = -1 > y2 = -2. So > point `{5, -2}` dominates point `{4, -1}` : ( 5>4 and -2<-1 ) > > Now put point {5, -2} in a list and give a number which shows how many times > point {5, -2} satisfy the criteria. The final results have to be like bellow: > >     DominatePoint1 = {{5, -2},2} >     DominatePoint2 = {{4, -1},1} >     DominatePoint3 = {{1, 5},0} >   How can this be implemented in _Mathematica_?


title: Boundary Value Problem- using NDSolve or another method

text: I am trying to solve a set of coupled partial differential equations, with defined boundary conditions using mathematica. Here are the equations and the boundary conditions. $0=\frac{\partial}{\partial y} \left(\frac{1}{2} \frac{\partial v(y,t)}{\partial y} \left(\alpha \cos ^2(\theta (y,t))+\beta \sin ^2(\theta (y,t))\right)+\frac{\partial \theta (y,t)}{\partial t} \sin ^2(\theta (y,t))\right)$ $\frac{\partial \theta (y,t)}{\partial t}=\text{EE}^2 \sin (\theta (y,t)) \cos (\theta (y,t))-\frac{1}{2} \frac{\partial v(y,t)}{\partial y}+\frac{\partial^2 \theta (y,t)}{\partial y^2}$ $v(0,t)=0$ $v(1,t)=0$ $\theta(0,t)=0$ $\theta(1,t)=\frac{\pi}{2}$ Here is my attempt at solving this in mathematica:               EE = 100; A = 10^6; \[Alpha] = -.63; \[Beta] = -2.7;     Eqns = {D[\[Theta][y, t], {t}] ==         EE^2*Sin[\[Theta][y, t]]*Cos[\[Theta][y, t]] -           (1/2)*D[v[y, t], {y}] + D[D[\[Theta][y, t], {y}], {y}],       0 == D[(1/2)*D[v[y, t], {y}]*(\[Alpha]*Cos[\[Theta][y, t]]^2 +                  \[Beta]*Sin[\[Theta][y, t]]^2) +       D[\[Theta][y, t], {t}]*              Sin[\[Theta][y, t]]^2, {y}]}     y0 = {v[0, t] == 0, \[Theta][0, t] == 0}     NDSolve[{Eqns, y0, y1}, {v[y, t], \[Theta][y, t]}, {y, 0, 1}, {t, 0, 10}]      And I get this error:               NDSolve::ivone: Boundary values may only be specified for one independent variable. Initial values may only be specified at one value of the other independent variable. >>      What's odd, is that it seems that I have only specified boundary values for one independent variable, $y$. I also understand that `NDSolve` is designed for use with Initial Value Problems, and not Boundary Value Problems. I've consulted this Wolfram Resource which presents some methods for solving BVPs with `NDSolve`, but I have been unable to figure out how to put those methods to use in attacking this problem. Does anyone know of a good way of solving this type of BVP with Mathematica, or do I need to turn to an iterative approach too integrating solving this in Matlab? I know that there are some expensive packages for solving BVPs with Mathematica, but I'm looking to do something out of the box, or with free extensions. Thanks in advance for any help you might have.


title: FindRoot with units error: Message text not found

text: This is sort of embarrassing. I'm working on a document to extol the virtues of Mathematica, and I can't get it to solve a relatively simple system of equations involving units. In this code, when I use <<<1 atm>>> I mean I'm using the ctrl-= method of adding units.               Keq = <<<3 /atm^2>>>     P0N2 = <<<10 atm>>>     POH2 = <<<20 atm>>>      Now I define the equations I want to solve, a straightforward equilibrium system:               eq1 = PN2 == P0N2 - z     eq2 = PH2 == P0H2 - 3*z     eq3 = PNH3 == 2*z     eq4 = PNH3^2 / (PN2*PH2^3) == Keq      Now, I want to solve these equations, knowing about where the solutions lie:               FindRoot[{eq1, eq2, eq3, eq4}, {{z, <<<6 atm>>>}, {PN2, <<<11 atm>>>}, {PH2, <<<4 atm>>>}, {PNH3, <<<2 atm>>>}}]      I get: > FindRoot:nlu: -- Message text not found -- ({6. atm, 11. atm, 4. atm, 2. > atm})({z, PN2, PH2, PNH3})({7. atm, 2. atm, -10. atm, > -2.99432/atm^2})({4})(Removed[$$Failure]) > > FindRoot[{eq1, eq2, eq3, eq4}, {{z, 6 atm}, {PN2, 11 atm}, {PH2, 4 atm}, > {PNH3, 2 atm}}] I am really at a loss for that error. Any ideas about what Mathematica wants? Cheers, Charles.


title: Converting format of list

text: I have a 2D array,               data = {{0,1}, {1,2}, {2,3}};      I would like to convert it such that I get the x- and y-values separately, specifically               x[0]=0; x[1]=1; x[2]=2;     y[0]=1; y[1]=2; y[2]=3;      Is there a way to obtain this?


title: Understanding distribution chart

text: How to explain DistributionChart function in mathematica, For example: if I have               nd1 = RandomVariate[NormalDistribution[], 25];     nd2 = RandomVariate[NormalDistribution[2, 10], 25];          DistributionChart[nd1, BarOrigin -> Right]      ![enter image description here](http://i.stack.imgur.com/29fQG.png)               DistributionChart[nd2, BarOrigin -> Right]      ![enter image description here](http://i.stack.imgur.com/teWv2.png) 1) what is the importance or application of representing data as distribution chart as compare to Normal distribution 2) How to quantify it? or differentiate from 2nd chart in quantitative way or can i estimate probability of middle fatter region


title: Plot columns of table if some condition is fulfilled

text: I have a table with data, for example               MT = {{1, 80.3, 1, 4, 68}, {2, 80.5, 1, 5.5, 102}, {3, 80.0, 0, 4.2,          78}, {4, 80.4, 0, 3, 17}, {5, 80.2, 1, 5, 180}};      I can plot column 1 against column 2 with               L1 = Table[MT[[i, 1]], {i, 1, 5}];     L2 = Table[MT[[i, 2]], {i, 1, 5}];     ListPlot[Table[{L1[[i]], L2[[i]]}, {i, 1, 5}]]      Now I want to do is the following: I want to plot column 1 against column 2 if the entry in column 3 is == 1. (So that only the points of rows 1,2,5 are shown) Does anyone know how to do that? Thanks alot!


title: Zooming into Parametric Animation Plot that Uses InterpolatingFunctions

text: I have an interplanetary trajectory solver that calculates a spacecraft route from Earth to Mars, and I am trying to zoom into the spacecraft when it reaches its Mars intercept orbit but am having some trouble. I originally asked a question of a similar nature on these forums (Zooming into animated plot), but used a simple parametric function as an example, and although I was given a good answer, I was unable to translate that solution to the trajectory solver as it is a bit more involved. Here is a stripped down version of the code which shows the orbits of Earth (inner circle), Mars (outer circle) and the spacecraft (line joining the inner and outer circles). Although what I tried hasn't worked, if you look at the PlotRange code I used when making the trajectory animation, I used an if function to change the PlotRange and essentially "zoom-in" to the spacecraft when it got close to Mars; unfortunately this code did not work, but I have left it in as it is essentially what I want to do in pseudo-code if you will. Any help would be appreciated, thanks guys.               Remove["Global`*"]     (*Gravitational Constant*)     G = 6.672*10^-11;     (*Simulation running time*)     tmax = (800) (86400);     (*Spacecraft TOF between Earth and Mars*)     dt = (254) (86400);     (*Time at which Mid-course correction is applied*)     dtmcc = dt/2;     (*Mass of Sun, Earth, Mars and spacecraft*)     m[0] = 1.988544*10^30 ;(*Mass of Sun*)     m[1] = 5.97219*10^24 ;(*Mass of Earth*)     m[2] = 6.4185*10^23 ;(*Mass of Mars*)     m[3] = 1000;     (*Planetary radii of Sun, Earth and Mars*)     r[0] = 6.963*10^8 ;(*Mean radius of Sun*)      r[1] = 6.37101 *10^6;(*Mean radius of Earth*)      r[2] = 3.3899*10^6 ;(*Mean radius of Mars*)     (*Heliocentric positions of Earth and Mars on 26 November 2011*)     p[1] = 149597870700 {4.416639858432274*10^-1,         8.798967504313304*10^-1} ;     p[2] = 149597870700 {-8.159382724017646*10^-1, 1.414986880765974*10^0};     p[3] = {6.6078363676586365`*^10, 1.3162870491119447`*^11}     (*Heliocentric velocities of Earth and Mars on 26 November 2011*)     v[1] = 149597870700/        86400 {-1.563974110293042*10^-2, 7.690252775639107*10^-3} ;     v[2] = 149597870700/        86400 {-1.160326991502370*10^-2, -5.778933879736245*10^-3} ;          vLambert[1] = {-8473.224022968232`, -23353.77562466311`};     vLambert[2] = {17642.608238929563`, -11842.147739330356`};     mindr = 4.660029187323423`*10^6 + 1000000;     theta = 2.1223566349593104`;     v2x = 20874.193923950195`;     v2y = -11635.115234375`;          Soln = NDSolve[{        x[1]''[t] == -((G m[0] x[1][t])/(x[1][t]^2 + y[1][t]^2)^(3/2)),        y[1]''[t] == -((G m[0] y[1][t])/(x[1][t]^2 + y[1][t]^2)^(3/2)),        x[2]''[t] == -((G m[0] x[2][t])/(x[2][t]^2 + y[2][t]^2)^(3/2)),        y[2]''[t] == -((G m[0] y[2][t])/(x[2][t]^2 + y[2][t]^2)^(3/2)),        x[3]''[t] == -((G m[0] x[3][t])/(x[3][t]^2 + y[3][t]^2)^(3/2))        - (G m[1] (x[3][t]- x[1][t]))/((x[3][t] - x[1][t])^2 + (y[3][t] - y[1][t])^2)^(3/2)        - (G m[2] (x[3][t] - x[2][t]))/((x[3][t] - x[2][t])^2 + (y[3][t] - y[2][t])^2)^(3/2),        y[3]''[t] == -((G m[0] y[3][t])/(x[3][t]^2 + y[3][t]^2)^(3/2))        - (G m[1] (y[3][t] - y[1][t]))/((x[3][t] - x[1][t])^2 + (y[3][t] - y[1][t])^2)^(3/2)         - (G m[2] (y[3][t] - y[2][t]))/((x[3][t] - x[2][t])^2 + (y[3][t] - y[2][t])^2)^(3/2),             x[1][0] == p[1][[1]], y[1][0] == p[1][[2]], x[2][0] == p[2][[1]],         y[2][0] == p[2][[2]], x[3][0] == p[3][[1]], y[3][0] == p[3][[2]],         x[1]'[0] == v[1][[1]], y[1]'[0] == v[1][[2]],         x[2]'[0] == v[2][[1]], y[2]'[0] == v[2][[2]],         x[3]'[0] == v[1][[1]] + 3373.0439329044348`,         y[3]'[0] == v[1][[2]] + 10880.11479034743`,         WhenEvent[         t == dtmcc, {x[3]'[t] -> vLambert[1][[1]],           y[3]'[t] -> vLambert[1][[2]]}],         WhenEvent[         t == ((253*86400) + 81460), {x[3]'[t] ->            v2x - Sqrt[(G m[2])/mindr] Sin[theta],           y[3]'[t] -> v2y + Sqrt[(G m[2])/mindr] Cos[theta]}]}, {x[1][         t], y[1][t], x[2][t], y[2][t], x[3][t], y[3][t]}, {t, 0, tmax},        StartingStepSize -> 0.001, AccuracyGoal -> 15, PrecisionGoal -> 15,        Method -> "StiffnessSwitching", MaxSteps -> 10000000]          Orbits = ParametricPlot[{{x[1][t], y[1][t]}, {x[2][t],           y[2][t]}, {x[3][t], y[3][t]}} /. Soln, {t, 0, tmax},        AxesLabel -> {x, y}, ImageSize -> Large,        PlotRange -> {{-0.25*10^12, 0.25*10^12}, {-0.25*10^12, 0.25*10^12}}]          OrbitAnimation =       Animate[ParametricPlot[{{x[1][t], y[1][t]}, {x[2][t], y[2][t]},       {x[3][t], y[3][t]}}/. Soln /. t -> a, {t, 0, a},         AxesLabel -> {x, y}, ImageSize -> Large, PlotRange ->If[t>=253*86400, {{x[3][t]-1000000,x[        3][t]+1000000},{y[3][t]-1000000,y[3][t]+1000000}},{{-0.25*10^12,        0.25*10^12},{-0.25*10^12,0.25*10^12}}]], {a, 0, tmax},        AnimationRate -> 1000000]      ![enter image description here](http://i.stack.imgur.com/WH4BR.png)


title: Adjusting the legend colors to match that in MatrixPlot

text: I am trying to show the legend with a `ColorData` for a discrete Fourier transform coefficient table. Here's a sample data table:               f={{0,26.6185,6.54197,1.32902,0.862353},       {12.3854,4.09068,3.39286,0.208909,0.340049},       {1.86011,1.79171,0.294318,0.930939,0.13115},       {0.402539,0.448201,0.176836,0.240318,0.162534},       {0.107348,0.0917102,0.13862,0.278679,0.0561954}}      The `MatrixPlot` of the above data is as such: `MatrixPlot[f]` ![enter image description here](http://i.stack.imgur.com/fq3ad.png) The `MatrixPlot` with `ColorData` (as in the help manual at PlotLegends/ref/ShowLegend) is as follows:               Needs["PlotLegends`"];     ShowLegend[      MatrixPlot[f,        BaseStyle -> {FontWeight -> "Plain",          FontSize -> 25}], {ColorData["TemperatureMap"][1 - #1] &, 20,        "-1", "1", LegendPosition -> {1.1, -.4}}      ]      Obviously, changing the `"-1", "1"` would change the limits on the legend. How should I have the maximum and the minimum of `f` show up instead of the non- sensical (for this case) `1` and `-1`? ![enter image description here](http://i.stack.imgur.com/VcqZk.png) I tried changing the `ShowLegend` to               ShowLegend[     MatrixPlot[f, BaseStyle->{FontWeight->"Plain",FontSize->25}],     {ColorData["TemperatureMap"][1-#1]&,20,Max[f],Min[f],     LegendPosition->{1.1,-.4}}     ]      but to no avail. I have looked around and there has to be an easier way out than this dissertation!


title: Dt acting on symbolic notational forms

text: This one must be simple, but I can't figure out a decent solution. Suppose, I have a symbol with a notational form applied to it, say `OverHat[A]`. Now, if I didn't specify anything about `A`, I would expect `Dt[OverHat[A]]` staying unevaluated. But in reality `OverHat` gets evaluated: `Dt[OverHat[A]] (* ---> Dt[A] Derivative[1][OverHat][A] *)` What are possible ways to prevent this from happening? **EDIT** To state more clearly, I want `OverHat[A]` to behave like ordinary symbol under action of `Dt`: `Dt[symb] (* ---> Dt[symb] *)`


title: What does LinearModelFit depend on except for its' arguments?

text: I thought this would be always true, but most likely it returns false.               random = {RandomReal[{-1, 1}, {500, 5}], RandomReal[{-1, 1}, 500]};     SameQ @@ Table[LinearModelFit[random], {100}]     (*False*)      How is this explained?


title: Overloading conjugate operator for a particular function

text: I trying to modify the behaviour of the built-in `Conjugate[]` operator on a particular function I have defined, to take into account that some of its variables are real.               ClearAll[f];     f /: Conjugate[f[k_]] := Conjugate[F[r]] Exp[I k r]     f[k_] := F[r] Exp[-I k r]      The problem with using `UpValues` in this way is that the `DownValues` for `f[k]` are evaluated before, resulting in:               Conjugate[f[k]]=Exp[I Conjugate[k r]] Conjugate[F[r]]       Using non-standard evaluation seems to do the trick               Conjugate[Unevaluated[f[k]]]=Exp[I k r] Conjugate[F[r]]      However, I want to use my function inside expressions like               f[k1] + f[k2] + Conjugate[f[k3]]      without having to manually replace `f[_]` by `Unevaluated[f[_]]`.


title: Indirect transformation based on a list of data points

text: I have a set of data which describes the Intensity function $Int(q)$ as a function of $q$. The data list provided below provides the shape of $Int(q)$ versus $q$.How can I use this information to obtain a profile of the distribution function $P(r)$ which is given by Int[q_] := 4*Pi*Integrate[P[r]*(Sin[q*r]/(q*r)), {r, 0, Infinity}]               data =        {{0.020024338`, 5.2050893`}, {0.022380134`,      4.5086694`}, {0.024735928`, 3.9553359`}, {0.027091718`,      3.5031466`}, {0.029447506`, 3.136435`}, {0.031803289`,      2.8969679`}, {0.034159069`, 2.720232`}, {0.036514845`,      2.5742439`}, {0.038870616`, 2.4916894`}, {0.041226383`,      2.4135635`}, {0.043582144`, 2.3849718`}, {0.0459379`,      2.3480797`}, {0.048293651`, 2.3245857`}, {0.050649396`,      2.2766608`}, {0.053005134`, 2.2146618`}, {0.055360866`,      2.11396`}, {0.057716592`, 1.9738159`}, {0.06007231`,      1.8161727`}, {0.062428021`, 1.6357164`}, {0.064783725`,      1.4384744`}, {0.06713942`, 1.2478508`}, {0.069495108`,      1.0708938`}, {0.071850787`, 0.92539427`}, {0.074206457`,      0.80211808`}, {0.076562119`, 0.70167624`}, {0.078917771`,      0.61047034`}, {0.081273413`, 0.53489188`}, {0.083629045`,      0.47277132`}, {0.085984668`, 0.42150623`}, {0.08834028`,      0.37787423`}, {0.090695881`, 0.34278684`}, {0.093051471`,      0.31405959`}, {0.09540705`, 0.28720344`}, {0.097762617`,      0.26768603`}, {0.10011817`, 0.24819699`}, {0.10247372`,      0.23306143`}, {0.10482925`, 0.21905138`}, {0.10718476`,      0.20982442`}, {0.10954027`, 0.19673289`}, {0.11189576`,      0.18747296`}, {0.11425124`, 0.18110339`}, {0.1166067`,      0.17339579`}, {0.11896215`, 0.16572`}, {0.12131759`,      0.16089015`}, {0.12367301`, 0.15379156`}, {0.12602842`,      0.15027508`}, {0.12838381`, 0.14365307`}, {0.13073918`,      0.14074507`}, {0.13309454`, 0.13529032`}, {0.13544988`,      0.13080442`}, {0.13780521`, 0.12837494`}, {0.14016052`,      0.12438591`}, {0.14251581`, 0.11990755`}, {0.14487109`,      0.11814154`}, {0.14722634`, 0.11381641`}, {0.14958158`,      0.11098607`}, {0.1519368`, 0.10826816`}, {0.15429201`,      0.10610327`}, {0.15664719`, 0.10442405`}, {0.15900236`,      0.10108521`}, {0.1613575`, 0.097974014`}, {0.16371263`,      0.096837303`}, {0.16606774`, 0.092660264`}, {0.16842282`,      0.090975641`}, {0.17077789`, 0.089248284`}, {0.17313293`,      0.087246505`}, {0.17548796`, 0.085425973`}, {0.17784296`,      0.08372304`}, {0.18019794`, 0.081506071`}, {0.1825529`,      0.079802714`}, {0.18490784`, 0.078130558`}, {0.18726275`,      0.075548811`}, {0.18961764`, 0.074480295`}, {0.19197251`,      0.072223406`}, {0.19432736`, 0.070366774`}, {0.19668218`,      0.068165596`}, {0.19903698`, 0.068293295`}, {0.20139175`,      0.066839873`}, {0.2037465`, 0.06539873`}, {0.20610123`,      0.063254469`}, {0.20845593`, 0.062264695`}, {0.2108106`,      0.06122402`}, {0.21316525`, 0.059284872`}, {0.21551987`,      0.058103587`}, {0.21787447`, 0.057846178`}, {0.22022904`,      0.056534087`}, {0.22258358`, 0.055681804`}, {0.2249381`,      0.054555308`}, {0.22729259`, 0.053447653`}, {0.22964705`,      0.050985052`}, {0.23200148`, 0.05112098`}, {0.23435589`,      0.050515905`}, {0.23671026`, 0.049462284`}, {0.23906461`,      0.048852687`}, {0.24141893`, 0.047111266`}, {0.24377322`,      0.046178586`}, {0.24612748`, 0.045303114`}, {0.24848171`,      0.045024691`}, {0.25083591`, 0.04453976`}, {0.25319008`,      0.0435324`}, {0.25554422`, 0.043386064`}, {0.25789833`,      0.042628797`}, {0.26025241`, 0.041504444`}, {0.26260645`,      0.040537487`}, {0.26496046`, 0.040452459`}, {0.26731445`,      0.039493138`}, {0.26966839`, 0.03839103`}, {0.27202231`,      0.037801358`}, {0.27437619`, 0.037234967`}, {0.27673004`,      0.036755139`}, {0.27908386`, 0.035998536`}, {0.28143764`,      0.035237672`}, {0.28379139`, 0.035419304`}, {0.2861451`,      0.034571123`}, {0.28849878`, 0.033495659`}, {0.29085242`,      0.033491305`}, {0.29320603`, 0.032608865`}, {0.2955596`,      0.033281853`}, {0.29791314`, 0.031811092`}, {0.30026664`,      0.031652453`}, {0.30262011`, 0.031097333`}, {0.30497353`,      0.030427169`}, {0.30732692`, 0.030131797`}, {0.30968028`,      0.02974402`}, {0.31203359`, 0.028764876`}, {0.31438687`,      0.028740458`}, {0.31674011`, 0.028269577`}, {0.31909331`,      0.028133016`}, {0.32144647`, 0.027667524`}, {0.3237996`,      0.026724803`}, {0.32615268`, 0.026212851`}, {0.32850573`,      0.026603364`}, {0.33085873`, 0.026516127`}, {0.3332117`,      0.025608039`}, {0.33556462`, 0.025019638`}};


title: How accurate is Collect?

text: Background: I am trying to compute the Lyapunov exponent for the logistic map given by \begin{equation*} x_{n+1}=F(x_n)=ax_n(1-x_n) \end{equation*} The formula for the Lyapunov exponent for a given initial condition $x_0$ is given as \begin{equation*} \lambda(x_0) = \lim_{n\rightarrow\infty}\frac{1}{n}\ln\left|{\frac{dF^n(x_0)}{dx_0}}\right| \end{equation*} While I do not intend to check for large values of $n$, as the degree of $F^n$ increases as $2^n$, I would like to check up to $n=10$ or so. I would also like to plot $\lambda$ vs $n$ (removing the limit) but that part is not included in the code. My entire code is as follows ( `a`, `nmax` are taken as inputs earlier):               forwardList = NestList[ a # (1 - #)&, x, nmax];     derivatives = Table[ D[ forwardList[[2]], x], {i, nmax}]     Do[derivatives[[i]] = a (1 - 2forwardList[[i]]) derivatives[[i - 1]], {i, 2, nmax}]     Log[ Abs[ derivatives]] /. x -> 0.3      I did not divide by $n$ just for convenience. Problem: Once I tried using Collect for checking the numbers and I got different answers. Consider the following code snippet:               forwardList = Collect[NestList[ a # (1 - #)&, x, nmax], x];     Collect[forwardList - NestList[ a # (1 - #)&, x, nmax], x]      I noted that the latter collect is giving me a non-zero list for list elements after the fourth one or so. Since the logistic map is chaotic, making precise calculations is very important. An example: for `a = 3.9`, `nmax = 10` the last element of forwardList turns out to be `~ 5.5`.   Instead of we replace the definition of forwardList (the topmost one) as follows, we get `~ 809`.               forwardList = Collect[ NestList[ a # (1 - #)&, x, nmax], x];      Which of the answers is correct and why? Does `Collect` work properly on lists? A correct alternative implementation would be welcome. My current algorithm uses a lot of RAM :( so I think there must be a better way.


title: how can tangent half angle substitution be done in Mathematica?

text: Is it possible to replace sine and cosine in terms of tangent half-angles and again the tangent half-angles by a variable say `t`?


title: Function giving negative value when it should be positive

text: I am trying to evaluate $$\displaystyle J=A\sum_{k=0}^{n-2}(-1)^k{n-2 \choose k}B^{n-2-k}\left(\frac{C_1}{k+n}-\frac{C_2}{k+n+1}+\frac{C_3}{k+n+2}-\frac{2}{k+n+3}\right)$$ in _Mathematica_ as a function of n (i.e. `J[n]`) Note that B, C1, C2, etc are just coefficients for some parameters I have in the model. I assign their values before I enter the function. They are given below for reference $$\left\{\begin{array}{cc}\left((n-1)nv^{-2n}\lambda^{-n}\right)=A \\ v+\lambda v=B\end{array}\right.$$ $$\left\{\begin{array}{cc}(v^2B\lambda)=C_1 \\ (vB+(B+2v)\lambda v)=C_2 \\ (2\lambda v+B+2v)=C_3 \end{array}\right.$$ Currently I have `J[n]` coded as:               J[n_] :=        a Sum[(-1^k) Binomial[n - 2, k] (b^(n - 2 - k))            ((c1/(k + n)) - (c2/(k + n + 1)) - (c3/(k + n + 2)) - (2/(k + n + 3))),          {k, 0, n - 2}]      But when I call it by `J[5]` with `{v, lambda} = {1.3, 2.1}`, for instance, I get a negative value when it should be positive! Another user, Dolma, who helped me derive the function (it's a definite integral of another function) claims it is positive here. I trust that I am doing something wrong more so than Dolma's derivation being wrong, though I should mention _Mathematica_ provides a MUCH more complex answer to this integral than in the post above. Can anyone spot where I am making a mistake? I appreciate your time and insight!


title: Collapsible Group of Control Objects

text: I did what I believe was a thorough search on this topic, but still ended up fruitless. Apologies if there is a trivial solution to this. Is there a way to group control objects together to form collapsible groups, much like cells in notebooks and the animation controls of manipulators? That is, the objects would form a group bound together, so that a click on a "plus" or an equivalent symbol would expand the group so that the objects can be seen and manipulated and another click would collapse the group again so that the objects are hidden. If not, is there another way to handle a large number of controls/graphic objects?


title: LiftingWaveletTransform with irregular grids

text: One of the properties mentioned in the literature about the lifting wavelet transform is that it can be applied on irregular meshes or grids (i.e. not equally spaced samples); but I don't seem to see that as an option in `LiftingWaveletTransform`. Any ideas on how to do that using _Mathematica_ 's wavelet analysis tools?


title: A symbol occurs in more than one context:one of the definitions is shadowed

text: I started _Mathematica 10_ and run as the tutorial says:               trainingset = {1 -> "A", 2 -> "A", 3.5 -> "B", 4 -> "B"};     c = Classify[trainingset]      but the outut is : > >     Classify[{1 -> "A", 2 -> "A", 3.5 -> "B", 4 -> "B"}] >   which is not expected. System: _Windows 7, x64_ `$Packages` gives: > >     {"QuantityUnit`", "HTTPClient`", "HTTPClient`OAuth`", >      "HTTPClient`CURLInfo`", "HTTPClient`CURLLink`", "Utilities`URLTools`", > "JLink`", >      "WolframAlphaClient`", "GetFEKernelInit`", "ResourceLocator`", > "PacletManager`", >      "System`", "Global`"} >


title: Draw network graph and get the coordinates of each node

text: I would like to draw an undirected graph by specifying the nodes and the edges among them. This is currently done by, for example:               GraphPlot[{1 -> 2, 2 -> 3, 3 -> 4, 4 -> 5, 5 -> 6, 6 -> 7, 7 -> 8, 8 -> 1}]      In addition, I would like to lay out the graph within a specified region of x-y coordinate system. Imagine this specified region as the 'canvas' in which the above circle is drawn. For instance, such a canvas can be specified by four points such as `(0, 0), (100, 0), (100, 100), (0, 100)`. Lastly, I would like to get the coordinates for each of the nodes of the graph drawn within the specified 'canvas'. What is the right workflow in Mathematica to accomplish each of the steps above?


title: Solve equation with two different sets of replacement rules

text: I want to solve eqn for c0. I want to do it with both replacement rules. I realize I could just use solve twice, once for subsCoke, and once for subsPepsi. I'm trying to do it in just one Sovle to learn how to use mathematicas functional style better.               eqn = c0/(c0 + cs) == Iunk/Is     subsCoke = {cO -> c0, cs -> 2, Iunk -> 0.3995, Is -> 0.7339};     subsPepsi = {c0 -> c0, cs -> 2, Iunk -> 0.3915, Is -> 0.7645};     Solve[eqn  /. {subsCoke, subsPepsi}, c0]


title: Diagonal Tick Marks

text: I would like to draw diagonal tick marks around a plot, and simultaneously rotate the tick labels as well. I've mocked up what this would look like: ![enter image description here](http://i.stack.imgur.com/xc2Dz.png) Is there an easy way to do this in Mathematica? I believe this is beyond the capabilities of the CustomTicks package. **Edit:** I would like this to be general enough to work for arbitrary plot ranges, and perhaps it would be easiest to generate the plot first with the normal tick marks, and then apply a replacement to the final graphics object?


title: How can I extract coordinates of the nodes of my graph?

text: I have this output for my graph.               In[85]:= PropertyList[{g, 1}]          Out[85]= {"TerminalsCoordinates", VertexCoordinates, VertexShape, VertexShapeFunction, VertexSize, VertexStyle}`      How can I extract the vertices info separately to different sets?


title: Solving parametric equations by eliminating the common variable

text: I'm trying to solve simple parametric equations using mathematica, but I'm having trouble finding a function to do this... what is the simplest way to solve for a common variable? For example, I have `y=t x=t`, and I want to solve for `y=x`.


title: Generating list of functions from list of expressions

text: I know how to create a function from concrete expression like               Function[{x, y}, x^2 + y^2]      But what if I have a list of expressions list1 and I know the set of variables which can occur in this list. I want to map all expressions of list1 to curresponding functions from these variables. Like               {x^2 + y^2, z^2, x, y}      should be mapped to               {       Function[{x,y,z}, x^2 + y^2],        Function[{x, y, z}, z^2],        Function[{x,y,z}, x],        Function[{x,y,z}, y]     }      I've tried               Function[{x,y,z}, #] &/@ list1      but this doesn't work. Can someone help me with solution?


title: Font Issues: "Like Resource 58" error

text: I'm running Mathematica 9.0.0 on a Macbook Air with OSX 10.6.8 and I've recently started having issues with the font in the program. All special characters are being replaced with other characters in the INPUT and OUTPUT cells. So for example I would type "[ ]" and in Mathematica it would show as "@ D". Also a "LikeResource|c|58" error appears during each startup. Here are a few other examples of where the font is being switched: Other examples: "[ ]" ----> "@ D" "{ }" ----> "8 ?" "( )" ----> "H L" "{9}" ----> ";9?" This doesn't affect the processing of Mathematica at all but it makes it Very difficult to use and read other peoples notebooks. I've already tried clearing the BaseDirectory and reinstalling the program and even looking through FontBook to ensure none of the fonts are corrupted or duplicated. Can anyone help me out with this issue, thanks for any help you can provide!


title: Output to preserve dot product

text: I am fairly new to Mathematica and I am faced with a problem. I tried to search for the solution but it seems that I don't know how to formulate the short search request. I need to perform a matrix product of               g = -I*Pi {{I1[x], 0}, {0, I2[x]}}.{{1 + G[x].Gt[x], 2*G[x]}, {-2*G[x], -1 - Gt[x].G[x]}}      However, I know that all the entries are matrices themselves, so I would like the dot product to be preserved in the output, i.e. to get something like               {{-I \[Pi] (1 + G[x].Gt[x]).I1[x], -2 I \[Pi] I1[x].G[x]},       {2 I \[Pi] I2[x].G[x], -I \[Pi] (-1 - Gt[x].G[x]).I2[x]}}      as opposed to               {{-I \[Pi] (1 + G[x].Gt[x]) I1[x], -2 I \[Pi] I1[x] G[x]},      {2 I \[Pi] I2[x] G[x], -I \[Pi] (-1 - Gt[x].G[x]) I2[x]}}      Is there any way to do this in Mathematica? N.B.: I don't want to specify the entire form of `G[x],Gt[x]` and other matrices at this stage.


title: Align a plot and a text at top using Row or Grid

text: I'm a little embarrassed asking such a simple question, but it's a problem I'm having since a long time. I want to e.g. have a plot beside some text. Now, I want that the top line of the plot and the top line of the text are at the same hight. I can't get this to work. When I use Alignment -> Top the text is always aligned at the middle and I don't know why. This sounds all very simple, so any help is appreciated. E.g.               Row[{ListPlot[{1, 2, 1, 3}, Joined -> True, Frame -> True,ImageSize -> 400], "    ", Framed@Grid[{{"test"}, {"test2"}}]}, Alignment -> Top]      The result is> ![enter image description here](http://i.stack.imgur.com/xXS2Y.png) So top line of plot and of text not at the same height.


title: ListDensityPlot performance when scaling axes

text: I need to visualize 3D data having 200*200 data points. `ListDensityPlot` is a good candidate, but it seems to have strange performance issues. I created a small test that plots 40000 points. It has three cases: using 2D array as input, using array of 3D points with integer coordinates $(x,y)$ and using array of 3D points with float coordinates $(x,y)$.                   TestFunction[x_, y_] := Sin[Pi/20* Sqrt[x^2 + y^2]];         testdata = Table[TestFunction[i, j], {i, -100, 100}, {j, -100, 100}];         testdataPoints =            Flatten[Table[{i, j, TestFunction[i, j]}, {i, -100, 100}, {j, -100,               100}], 1];         testdataPoints2 =            Flatten[Table[{i*0.01, j*0.01, TestFunction[i, j]}, {i, -100,               100}, {j, -100, 100}], 1];     Benchmark[d_, n_] :=        Timing[ListDensityPlot[d, ColorFunction -> "Rainbow",          PlotRange -> Full, InterpolationOrder -> n]];     TableForm[      Table[Benchmark[data,         n], {data, {testdata, testdataPoints, testdataPoints2}}, {n, 0,         2}], TableHeadings -> {{"Array", "Integer", "Float"}, {0, 1, 2}}]      ![density plots of different data](http://i.stack.imgur.com/VArqI.png) It gives pretty strange result. When I simply scale axes and my coordinates are not integer anymore (the case is called "Float"). The performance drops almost 10 times (3 seconds vs 25 seconds). Here's the output timing:                           0         1         2     Array   0.834276 2.96802    3.05685       Integer 4.84968  3.42562    3.19835     Float   27.5574   26.1669   25.9262      Any explanation for such behavior? # **Edit** As alternative to Michael's solution one can use `ArrayPlot` (as Silvia suggested) if interpolation is not important. It can be easily scaled to look like "Float" case.


title: Render dynamic Graphics objects static

text: As was discussed in the comments of another question (MathLink Graphical Output (Plots) to File), `Graphcis` objects produced by commands such as `Plot` could be used to plot graphics independent of the presence of a connection with the _Mathematica_ kernel which generated it; i.e., it could be displayed in a separate instance of _Mathematica_. This would be useful to realize the display of plots in custom front ends connected to _Mathematica_ with `MathLink`. The `Graphics` objects would in this case serve as exchange format between the kernel and the frond end. However, as was pointed out to me, `Graphics` can contain dynamic content which is evaluated by the native front end by calling the kernel. Consider the example               SetOptions["stdout", FormatType -> InputForm];     myf1[min_?NumericQ, max_?NumericQ] := Table[count, {count, min, max}];     Plot[x^2, {x, 1, 5}, Ticks -> myf1]      which generates the output > >     Graphics[{{{}, {}, {Hue[0.67, 0.6, 0.6], Line[{ ...}]}}}, >       {AspectRatio -> GoldenRatio^(-1), Axes -> True, >        AxesLabel -> {None, None}, AxesOrigin -> {1., 0}, Method -> {}, >        PlotRange -> {{1, 5}, {0., 25.}}, PlotRangeClipping -> True, >        PlotRangePadding -> {Scaled[0.02], Scaled[0.02]}, Ticks -> myf1}] >   Note the final `Ticks -> myf1`. Is it possible make the kernel evaluate this output such that it is rendered static? In this case the `Graphics` should be made a static list of tics, however the solution would need to be generic enough to produce static output for all possible commands which generate graphics.


title: How to format the data in a table to have only numbers

text: This question is in continuation of my earlier query, how to store output of a function in a table for future use. I am able to store the output of my function in a table, however the table consists of various brackets and variable headings which I do not require. A clean table with only values in two columns will help me to further evaluate the table. I have many such codes, resulting in about 15 tables each containing 600 rows of data. A easy way to have the table in required format as above will help me avoid lot of formatting. Further the code as below also gives 2 values for a single input value. I will like both the values to be given in two separate rows. The code is as given below. Request for help to solve this.               Remove["Global`*"]     Clear[A, r, v, u, p, γ , ug, Nx, Ny, Nz, EM]     x = 2 r Cos[v + u + γ] - r Cos [(2 v) + u + γ]     Nxu = D[x, u]     Nxv = D[x, v]     Nx = Nxu Nxv          y = 2 r Sin[v + u + γ] - r  Sin[(2 v) + u + γ]     Nyu = D[y, u]     Nyv = D[y, v]     Ny = Nyu Nyv          z = p u     Nzu = D[z, u]     Nzv = D[z, v]     Nz = Nzu Nzv          re = 27.5     r = 16.5     g = ArcCos[((5 r^2) - (re^2))/(4 r^2)]     p = 108/(2 π)     γ = 45 ° 2 Pi / 360     A = 50 + r     γc = 46 ° 2 Pi / 360          EM [u_, v_] = Simplify[(A - x + p Cot[γc]) Nz + (A Cot[γc]) Ny + z Nx ]     ug[thet_] := With[{u = thet}, NSolve[EM[u, v] == 0 && 0 <= v <= g, v, Reals]]          myTable = Map[{#, ug[#]} &, Range[0, 2 Pi, 0.1]]          Export["coordinatesM13.xls", myTable]      The output for the table is currently as below:               {{0., {}},       {0.1, {}},       {0.2, {}},       {0.3, {}},       {0.4, {}},       {0.5, {}},       {0.6, {}},       {0.7, {}},       {0.8, {}},       {0.9, {}},       {1., {}},       {1.1, {}},       {1.2, {{v -> 0.877726}}},       {1.3, {{v -> 0.757594}}},       {1.4, {{v -> 0.616049}}},      {1.5, {{v -> 1.48929*10^-17}, {v -> 0.418666}}},       {1.6, {}},       {1.7, {{v -> 4.32695*10^-17}, {v -> 0.94549}}},       {1.8, {{v -> 9.4028*10^-17}, {v -> 0.879002}}},       {1.9, {{v -> 1.4318*10^-16}, {v -> 0.812557}}},       {2., {{v -> 1.94556*10^-16}, {v -> 0.746152}}},       {2.1, {{v -> 2.50387*10^-16}, {v -> 0.679788}}},       {2.2, {{v -> 3.13018*10^-16}, {v -> 0.613464}}},       {2.3, {{v -> 3.85566*10^-16}, {v -> 0.54718}}},       {2.4, {{v -> 4.72647*10^-16}, {v -> 0.480935}}},       {2.5, {{v -> 5.8166*10^-16}, {v -> 0.414731}}},       {2.6, {{v -> 7.25488*10^-16}, {v -> 0.348566}}},       {2.7, {{v -> 9.28936*10^-16}, {v -> 0.282443}}},       {2.8, {{v -> 1.24694*10^-15}, {v -> 0.216362}}},       {2.9, {{v -> 1.83073*10^-15}, {v -> 0.150324}}},       {3., {{v -> 3.30427*10^-15}, {v -> 0.0843294}}},       {3.1, {{v -> 1.52413*10^-14}, {v -> 0.0183812}}},       {3.2, {}},       {3.3, {}},       {3.4, {}},       {3.5, {}},       {3.6, {}},       {3.7, {}},       {3.8, {}},       {3.9, {}},       {4., {}},       {4.1, {}},       {4.2, {}},       {4.3, {{v -> 0.944253}}},       {4.4, {{v -> 0.828585}}},       {4.5, {{v -> 0.697065}}},       {4.6, {{v -> 2.7593*10^-17}, {v -> 0.531873}}},       {4.7, {{v -> 0.0583604}, {v -> 0.125963}}},       {4.8, {{v -> 0.960336}}},       {4.9, {{v -> 5.11674*10^-17}, {v -> 0.894928}}},       {5., {{v -> 1.088*10^-16}, {v -> 0.829509}}},       {5.1, {{v -> 1.63611*10^-16}, {v -> 0.764084}}},       {5.2, {{v -> 2.20467*10^-16}, {v -> 0.698659}}},       {5.3, {{v -> 2.82376*10^-16}, {v -> 0.633237}}},       {5.4, {{v -> 3.5243*10^-16}, {v -> 0.567823}}},       {5.5, {{v -> 4.34721*10^-16}, {v -> 0.502421}}},       {5.6, {{v -> 5.35437*10^-16}, {v -> 0.437036}}},       {5.7, {{v -> 6.64873*10^-16}, {v -> 0.37167}}},       {5.8, {{v -> 8.41904*10^-16}, {v -> 0.306328}}},       {5.9, {{v -> 1.10567*10^-15}, {v -> 0.241014}}},       {6., {{v -> 1.5532*10^-15}, {v -> 0.175731}}},       {6.1, {{v -> 2.51035*10^-15}, {v -> 0.110485}}},       {6.2, {{v -> 6.17841*10^-15}, {v -> 0.0452779}}}}


title: Can ParametricNDsolve be used for coupled PDEs with 5 parameters?

text: I have a system of coupled PDEs with five parameters that I only know ranges for rather than explicit values, and I was wondering if I could define a parametric equation with ParametricNDSolve and then use FindFit with some data to estimate these parameters? My problem is that I have some coupled equations. Firstly I have a set up equation which seems to work fine, given by               (*Constants!*)     a = 10*10^-7; omega = 3.0138*10^7; Do2 = 2*10^-9; po = 106;     ro = 263*10^-6; micron =       1*10^-6; k = 1; (*eo = 100;*)(* qm = 10^-4;*)     mic = 1*10^-6; De = 5.5*10^-11;          (*First equation - set up eq!*)     s = Quiet[        NDSolve[{D[Ox[r, t], t] -             Do2*(D[Ox[r, t], r, r] + (2/r)*(D[Ox[r, t], r])) + (a*               omega)*((Ox[r, t])/(Ox[r, t] + k)) == 0, Ox[r, 0] == 0,           Ox[micron, t] == 0, Ox[ro, t] == po},          Ox, {r, micron, ro}, {t, 0, 14400}]];     p = Ox /. First[s];      Which gives me a function p[r,t] . I then use this in a parametric set up with parameters $eo,qm,kme,kmn$ and $j$ and initial / BC conditions to solve parametrically for $Ef1$;               (*Second equation*)     eqnDe = D[Ef1[r, t], t] -         De*(D[Ef1[r, t], r, r] + (2/r)*(D[Ef1[r, t], r])) +         qm*((kme)/(kme +            p[r, t])*((p[r, t])/(p[r, t] +             kmn)) + (1 - (p[r, t])/(p[r, t] + kmn))*j)*Ef1[r, t];          l = ParametricNDSolve[{eqnDe == 0, Ef1[r, 0] == 0,      Derivative[1, 0][Ef1][micron, t] == 0, Ef1[ro, t] == eo},         Ef1, {r, micron, ro}, {t, 0, 14400}, {kme, kmn, j, qm, eo}];          b = Ef1 /. l;      This seems to work so far (though Im unfamiliar with ParametricNDSolve) but my problem is that I want to use the output of this and the parameters to find a new value Eb1, related to the above solution by; $\frac{dEb1}{dt} = qm\left(\frac{p}{p + kmn}\frac{kme}{p + kme} + (1 - \frac{p}{p + kmn})j \right)Ef1$ with the initial condition $Eb1[r, 0] == 0$ - the problem is I have tried coded this in and have had no luck. I tried               eqnBo = D[Eb1[r, t],      t] - (b[r,        t])*(((p[r, t])/(p[r, t] + kmn))*((kme)/(kme +             p[r, t])) + (1 - (p[r, t])/(kmn + p[r, t]))*j);           x = ParametricNDSolve[{eqnBo == 0, Eb1[r, 0] == 0},          Eb1, {r, micron, ro}, {t, 0, 14400}, {kme, kmn, j, qm, eo}];      And this produces an error; ParametricNDSolve::fpct: "Too many parameters in {kme,kmn,j,qm,eo} to be filled from {r,t}" Anyone have any idea if what I want to do is possible, and whether this error simply means there's too much to fit? The data I want to fit it to is here. I'd be really grateful for any guidance I can get on this, or improved methods of finding the data I want!


title: Converting structured data to a dataset

text: A Dataset seems perfect to represent structured data. Has anyone already thought about how to convert as efficiently/elegantly as possible an XML or JSON file to a Dataset in Mathematica 10 ?


title: Determine types of input, output and internal variables in compiled functions

text: I am trying to speedup the computation of a longer function using `Compile`. For illustration consider the following short example:               procTest = Compile[{{x, _Real}},         res = Log[-x];         Im[res]     ];      The input and output are both real valued. But Mathematica `Compile` seems to assume that this means that it can use the real `Log` function inside the routine. At least the following commands               procTest[-1.]     procTest[1.]      output reads               0     CompiledFunction::cfse:  Compiled expression 0. + 3.14159 I should be a machine-size real number.     CompiledFunction::cfex:  Could not complete external evaluation at instruction 2; proceeding with uncompiled evaluation.     3.141592653589793      Of course I can change the type `_Real` to `_Complex` which makes this example work, but the output is then a complex quantity with zero imaginary part. Is there a way to tell `Compile` that it should assume real input and outputs, but complex quantities can appear inside the function? If not, can I convert the output type from complex to real? I am worried about the output type because it seems to confuse other parts of my computation (not sure, but probably `FindRoot` tries to perform a complex root search if the arguments are not reals).


title: How to define the irrational domain or any other arbitrary domain?

text: I have found no way to define the domain of `Irrational` numbers. I can easily define a test to see if a number is irrational by defining:               IrrationalQ[z_] := Element[z, Reals] && ! Element[z, Rationals]          IrrationalQ /@ Sqrt /@ Range[10]          > >     {False, True, True, False, True, True, True, True, False, True} >   My question is how can I define a domain that would work with `Element`, something like               Element[Sqrt[2], Irrationals]      I am aware that the documentation list possible domains as `Booleans, Complexes, Integers, Primes, Rationals, Reals`, but it is not clear to me if that list is exclusive or not.


title: AndersonDarlingTest and DistributionFitTest Leaking Memory

text: I believe `AndersonDarlingTest` and probably all other tests are keeping a copy of data somewhere and not freeing it:               Quit[]; (*Must be run in different cell*)               $HistoryLength = 0;     memdata = {{MemoryInUse[], MaxMemoryUsed[]}}~Join~Table[          data =            RandomVariate[            MultinormalDistribution[{0, 0}, {{1, 1/2}, {1/2, 2}}], 1000000];          dist = MultinormalDistribution[{ux, uy}, {{a, c}, {c, b}}];          AndersonDarlingTest[data,            dist, {"FittedDistributionParameters", "PValue"}];          Clear@data; Clear@dist;          ClearSystemCache[];          {MemoryInUse[], MaxMemoryUsed[]}          , {10}]/1024.^2;          ListPlot[Transpose@memdata, Joined -> True,       PlotLegends -> Placed[{"MemoryInUse", "MaxMemoryUsed"}, Top],       AxesLabel -> {"Iteration", "Memory (MB)"}]      ![example of memory leak](http://i.stack.imgur.com/Qx7H0.png) **Questions:**   * **Am I missing something obvious or is this a bug?** Just want to make sure before I report it...   * **Is there a work around?** I've been spelunking with the excellent spelunking package, but so far no luck... Heavy symbols gives some candidates, but clearing the symbols in the loop gives me various errors.               heavySymbols["Statistics`*`"]          {"Statistics`GoodnessOfFitTestingDump`iHypothesisTestFunction",       "Statistics`StableEstimationDump`iLogPDF17",       "Statistics`StableEstimationDump`iPDF05b1"}      Using MMA 9.0.1 on Win7 64 bit.


title: How to specify the centre or PlotRange of a Graphics3D?

text: When I create a `Graphics3D`, I often want to place an object right at the centre of the box. Initially I thought that the centre was specified by `{0, 0, 0}`, but I soon realised that this is actually the corner. I've realised that I can find the centre by dividing the dimensions of the box in half. For example if               PlotRange -> {{0, 100}, {0, 100}, {0, 100}}      then if I want to put my `Sphere` dead centre I'll put it at:               Sphere[{100/2, 100/2, 100/2, 1]      This is all very well if I explicitly know the dimensions of the box, but if I don't know the `PlotRange`, how can I ensure that my object is placed right at the centre? Is there a way to tell the size of the `PlotRange` if you haven't specified it explicitly? For example, consider this function:               balls = Table[Sphere[RandomReal[{0, 100}, 3], 1], {50}]~        Join~{Sphere[{50, 50, 50}, .05]};     Manipulate[      Graphics3D[       balls,       ViewPoint -> {1.3*10^-zoom, -2.4*10^-zoom, 2*10^-zoom},        SphericalRegion -> True,        PlotRange -> {{0, 100}, {0, 100}, {0, 100}}],      {zoom, 0, 3}]      ![enter image description here](http://i.stack.imgur.com/V2XzR.png) The slider controls the zoom, which in this function zooms in all the way until you hit a very small sphere. For this to work though, the sphere needs to be precisely at the centre of the plot. To ensure this precision, I manually entered the size of the plot (`PlotRange -> {{0, 100}, {0, 100}, {0, 100}}`), as well as manually control the placement of the middle sphere (`Sphere[{50, 50, 50}, .05]`). Is there a way to make sure that this sphere is placed right at the very centre of the box without needing to manually specify either the dimensions of the `PlotRange` or the coordinates of the centre sphere? I hope this clarifies what I'm trying to get at.


title: Replace inside a Held expression separate context

text: How do I replace content inside a Held expression without local values coming through? For example if you run the following code you get `g[2]` instead of `g[x]`(the intended form).               x = 2;     Replace[HoldComplete[g["x"]], {       y_String :> With[{          eval = Symbol[y]},         eval /; True]       }, {0, Infinity}]      The following questions are related   * Constructing a Sandbox   * Replace inside Held Expression **EDIT:** Although rm-rf's trick is clever it partially works. His current code adds an additional defer to the current code.               InputForm@HoldComplete[g["x"]] /.        s_String :> With[{x = ToExpression[s, InputForm, Defer]}, x /; True]      returns `HoldComplete[g[Defer[x]]]` instead of `HoldComplete[g[x]]`. Ultimately you could strip out the `Defer`s which is likely what I will end up doing.


title: Generate random points in a region with higher probability in a sub-region

text: I am trying to generate random samples of points in the unit square in such a way that points inside a given circle are twice as likely to be selected as points outside that circle. I tried to approach the problem by the 2D distribution. To do that I need to turn the function               f[x_,y_]:= If[ (x-.5)^2 + (y-.5)^2 < .1, 1, .5]      into a probability distribution for both x and y between 0 and 1. Then I would use the PDF to generate points and eventually plot them. My main struggle comes from turning the If function into a two-variable PDF.


title: Solving an inequality that contains Log expressions

text: How can I solve the following inequality:               Log[1/2 + c^2] > (1.4) (30^5) 2^(4.5) 9 (0.6) (2.8) (1 + Log[3]) (1 +Log[ Log[c + 1]])      ? I tried `Reduce`, but my computer is still computing it (c is a real number).


title: Does it make sense to ask for the color of a Graphics3D "voxel"?

text: Say I generate some Graphics3D object, e.g.:               Graphics3D[{Red, Sphere[{0, 0, 0}, 1], Blue, Sphere[{1, 0, 0}, 1]}]      Does it make sense to ask for the color of a "voxel" / volumetric pixel in this image? In other words, is it possible to call some three-dimensional analogue of PixelValue or ImageValue to determine what region in the 3D box is red or blue? What might happen at the intersection of the red and blue spheres? Shouldn't this be possible given that I can select a subregion of the graphics3D object to display in some bounding box? And if so, couldn't I just make the bounding box around the area of interest arbitrarily small, save the output as a TIFF and call ImageValue[] or PixelValue[] on the center of the TIFF image? Surely there's a better way to proceed? Update: george2079 hits the nail on the head in my opinion with his suggestion that we should think about this problem as a problem of making a 3D implementation of Rasterize[]. A problem that may or may not be relevant, though, is that most of the Graphics3D objects are hollow. To see this, try zooming around a Graphics3D output using some amazing code written by the user rm -rf: Implementing a first person view of 3D objects in a scene


title: Visualizing vector-spherical waves

text: This is a follow-up question to this one on visualizing vector-spherical harmonics. This time, I would like to visualize the vector spherical waves (including the radial dependence). The functions that I would like to plot, `VectorSphericalWaveE[J, M, kr, θ, ϕ]` and `VectorSphericalWaveM[J, M, kr, θ, ϕ]` are defined below. **Please note there was a typo in`ϵ[λ_]`, in the linked question, which I have corrected**.               Clear[ϵ]; (*Polarization vector*)     ϵ[λ_] = Switch[λ,        -1, {1, -I, 0}/Sqrt[2],         0, {0, 0, 1},         1, -{1, I, 0}/Sqrt[2]   ];          Clear[VectorSphericalHarmonicV];     VectorSphericalHarmonicV[ℓ_, J_, M_, θ_, ϕ_] /;        J >= 0 && ℓ >= 0 && Abs[J - ℓ] <= 1 && Abs[M] <= J :=        Sum[         If[Abs[M - λ] <= ℓ, ClebschGordan[{ℓ, M - λ}, {1, λ}, {J, M}], 0]*         SphericalHarmonicY[ℓ, M - λ, θ, ϕ]*ϵ[λ], {λ, -1, 1}   ]          Clear[RadialR, VectorSphericalWaveE,VectorSphericalWaveM];     RadialR[kr_, ℓ_] = I^ℓ SphericalBesselJ[ℓ, kr];     VectorSphericalWaveE[J_, M_, kr_, θ_, ϕ_] /;  J >= 0 && Abs[M] <= J :=        If[J > 0, -Sqrt[((J + 1)/(2 J + 1))] SphericalBesselJ[J - 1, kr] VectorSphericalHarmonicV[J - 1, J, M, θ, ϕ],  0]      + Sqrt[J/(2 J + 1)] SphericalBesselJ[J + 1, kr] VectorSphericalHarmonicV[J + 1, J, M, θ, ϕ];     VectorSphericalWaveM[J_, M_, kr_, θ_, ϕ_] /; J >= 0 && Abs[M] <= J :=        I SphericalBesselJ[J, kr] VectorSphericalHarmonicV[J, J,          M, θ, ϕ];      The functions `VectorSphericalWaveE` and `VectorSphericalWaveM` takes two integer arguments $J\geq 1$ and $-J\leq M \leq J$, and three continuous arguments: the radial coordinate $kr>0$, and the angular coordinates $\theta$ and $\phi$. The output is a _real_ vector. Because these functions give out real-valued vectors, I would like to visualize them using vector plot. I tried the following:               VectorPlot3D[      Re[VectorSphericalWaveM[2, 1,       Sequence @@ CoordinateTransform["Cartesian" -> "Spherical", {x, y, z}]]],          {x, -5, 5}, {y, -5, 5}, {z, -5, 5},          RegionFunction -> ((#1^2 + #2^2 + #3^2 <= 5^2) &)]      But got a crummy output (see below). I can hardly tell what's going on. I know these vector fields are supposed to be circulatory only, so it would be nice if that aspect can be emphasized in the plot. Also, is there a way to include some kind of _distance fog_ , so that arrows in the back, are greyed out? ![enter image description here](http://i.stack.imgur.com/3RjjB.jpg)


title: I want to draw a graph using a weighted Adjacency matrix

text: I have a weighted adjacency matrix as follows:               myAdjacencyMatrix = {{0, 3, 1, 3, 3, 8, 0, 0, 3, 4},       {1, 0, 2, 0, 0, 16, 5, 3, 0, 6, 1},       {2, 3, 0, 0, 1, 1, 4, 1, 1, 0, 0},       {5, 3, 3, 0, 5, 0, 2, 2, 2, 2, 1},       {1, 0, 0, 6, 0, 1, 2, 6, 10, 2, 4},       {0, 11, 3, 0, 1, 0, 8, 3, 1, 3, 3},       {2, 4, 1, 7, 6, 7, 0, 6, 0, 8, 2},       {1, 2, 1, 3, 8, 4, 4, 0, 4, 3, 0},       {0, 0, 0, 1, 4, 1, 3, 4, 0, 6, 4},       {0, 3, 0, 0, 0, 5, 2, 2, 6, 0, 4},       {0, 1, 0, 0, 2, 1, 2, 0, 1, 2, 0}}      I want to draw a graph with 11 nodes and the edges weighted as described above. If this is impossible, then I will settle for making a graph with the non-weighted adjacency matrix. If you could just give me the simple code as I am new to mathematica and am working on a tight schedule.


title: How can I write a Do loop that iterates over N iterators when N is not known a-priori?

text: For any positive integer $n$ which is not specified _a priori_ , I can make $n$-tuple vector $v$ by `v = Array[a, 1, n]`. Now, given that $n$ is a positive integer which is not specified _a priori_ , I want to write an iteration sentence which performs over $1\leq a_1,\ldots, a_n\leq 3$. ($a_i$ are integers and hence I will get $3^n$ iterations). For example, if $n=2$, my sentence plays the same role as the following loop:               Do[EXPERIMENT, {i, 3}, {j, 3}]      If $n=3$, my sentence plays the same role as the following:               Do[EXPERIMENT, {i, 3}, {j, 3}, {k, 3}].      I can do it for any given SPECIFIED integer $n$, but I want to write the universal looping sentence which iterates for $1\leq a_1,\ldots, a_n\leq 3$ ($a_i$ are integers.)


title: Constraint syntax compaction

text: Is there a more compact way to represent these constraints: `NMaximize[{a+b+c,` **`a<= 5 && b <= 5 && c <= 5`**`}, {a,b,c}]` like `for x in {a,b,c}, x <= 5` or something.


title: Change Ticks in PairedBarChart

text: I am using the PairedBarChart feature as follows:               PairedBarChart[Range[5], Range[5], BarOrigin -> "XAxis"]      ![enter image description here](http://i.stack.imgur.com/jWRWa.png) How can I (i) remove and (ii) change the number of the small tick marks on the y-axis (i.e., the ones between the numbers 1, 2, 3, ...)? Thanks for your help!


title: How do I determine the original aspect ratio of an imported image?

text: Say I import a TIFF, JPEG, or PDF image. How can I quickly determine the original aspect ratio of the image so that I can properly scale its size? I have thus far been unable to find an answer looking through the manual.


title: How to calculate scalar curvature Ricci tensor and Christoffel symbols in Mathematica?

text: I am seeking a convenient and effective way to calculate such geometric quantities. I've used packages like `TensoriaCalc`, but they don't work at all time. Sometimes, I run into the following error: > Symbol `Tensor` is Protected.   >  Symbol `TensorType` is Protected.   >  Symbol `TensorName` is Protected.   > Here is the code I'm using:               Clear [i, j, φ, τ, σ]      q["case"] = Metric[ SubMinus[i], SubMinus[j],          E^(2 φ[σ]) (\[DifferentialD]τ^2 + \[DifferentialD] σ^2),          CoordinateSystem -> {τ, σ}, TensorName -> "T", StartIndex -> 1 ]      I think the above is correct, since I merely modified the example from the package manual. It gives me the correct answer sometimes (if I only use one notebook). Also, I ran the codes from the chapter "General Relativity" in the book " _Mathmatica_ for theoretical physics" by Gerd Baumann, but none of them work Is there more efficient way to calculate them? Please give me some suggestions about this.


title: Define customised distribution with discontinuous CDF

text: I have the following CDF:                F[x_] = Piecewise[{          {0, x < 0},          {0.1 x^2, 0 <= x <= 2},          {0.4, 2 < x <= 5/2},          {0.5, 5/2 < x <= 4},          {-0.5 E^-(x - 4)^2 + 1, 4 < x}         }];      ![enter image description here](http://i.stack.imgur.com/7BPii.png) Now I define the a probability distribution as follows:                dist = ProbabilityDistribution[{"CDF", F[x]}, {x, 0, Infinity}];      G[x_] = CDF[dist, x];      But the plot of G now looks different: ![enter image description here](http://i.stack.imgur.com/Wdas4.png) It seems I lose the discontinuity point and on top of that the CDF G doesn't even go up to 1 anymore. * * * Question: Why do I lose the discontinuity of my CDF, and is there a way to avoid this issue?


title: Introduction of bias during brightness and contrast manipulation of an image

text: Quoting from Nature magazine's "Image integrity" guidelines: > Processing (such as changing brightness and contrast) is appropriate only > when it is applied equally across the entire image and is applied equally to > controls. Contrast should not be adjusted so that data disappear. Excessive > manipulations, such as processing to emphasize one region in the image at > the expense of others (for example, through the use of a biased choice of > threshold settings), is inappropriate, as is emphasizing experimental data > relative to the control. When I change the brightness and contrast of an image, say, with the following command:               ImageAdjust[ExampleImage, {contrast, brightness}]      Is it fair to say that contrast and brightness transformations are "applied equally across the entire image" in the spirit of the above quotation? Of course common sense is required in terms of not purposefully obscuring meaningful data, but are there pitfalls / issues I should otherwise be aware of specifically with regards to this sort of image manipulation in Mathematica?


title: Nested for loop in mathematica

text: I have a code in mathematica with a loop which iterates over a variable i and calculates a list of numbers h given the start parameter f:               For[i==1,i<100,i++,     h=Append[h,f*g(i)]]      Now what I want to do is to vary the parameter f. How I would have done it in Matlab (which is the only other programming language I know - yes, I suck at programming basically) is that I would have made a nested loop, so we would have something like this:               For[j==1,j<10,j++,     f=Append[f,k(j)]     For[i==1,i<100,i++,     h=Append[h,f(j)*g(i)]]     x=Append[x,Max[h]]]      Where the last line is supposed to give me Max[h] for successive iterations over j, i.e. first one is max[h] for j=1, then for j=2 etc. But this structure does not seem to work. What are my alternatives/ how can I fix it? Ps: I would love to submit my code, but it's completely unreadable due to a heavyamount of subscripts etc. Can I attach the Mathematica file somewhere?


title: How do I seamlessly migrate from the older Units package to Mathematica 9's Quantity objects?

text: I have several notebooks that make use of the `Units` package and would like to be able to work simultaneously with the older units and `Quantity` objects introduced in version 9. What is my lowest-overhead method for updating units to `Quantity` objects?


title: LinearProgramming behavior

text: Consider the following linear programming problem:               LinearProgramming[-{10, -57, -9, -24}, -( {          {0.5, -5.5, 2.5, 9},          {0.5, -1.5, -.5, 1},          {1, 0, 0, 0}         } ), -{0, 0, 1}]      (* {0., 0., 0., 0.} *)      Why is this answer being returned? Taking $\textbf{x}=\begin{pmatrix}1&0&1&0\end{pmatrix}^T$ satisfies $\textbf{x}\ge 0\land A\textbf{x}\ge \textbf{b}$, but the value of the objective function for this solution is $-1$, which is clearly smaller than $0$, the suggested "optimal" solution by _Mathematica_. I would expect _Mathematica_ to be able to solve such a small LP problem, even if it is degenerate. Am I doing something wrong here?


title: How can I transform a quadratic into an factored equation?

text: How can I transform a quadratic polynomial in x and y into an equation of the form $(x-a)^2+(y-b)^2=c$?               f = -9 x + (3 x^2)/4 + (3 y^2)/4;      Completing the Square               CompleteSquare[f_, x_] :=       Module[{a, b, c},         {c, b, a} = CoefficientList[f, x];           a (x + b/2/a)^2 + Simplify[(c - b^2/4/a)]]          CompleteSquare[f, x]          (*         3/4 (-6 + x)^2 + 3/4 (-36 + y^2)     *)      What I want is the following:               (x - 6)^2 + y^2 == 36


title: How can I replace part of list and have the replacement affect the initial list?

text: I have a list:               list = {{1,1,0.05,0.05}, {2,2,0.05,0.05}};      and I want to do this change               Replace[#[[1]], #[[1]] -> (#[[1]] + #[[3]])]& /@ list         Replace[#[[2]], #[[2]] -> (#[[2]] + #[[4]])]& /@ list       The problem is that the initial list doesn't change. My list represents $\{\{x, y, v_x, v_y\}, \{x, y, v_x, v_y\}\} $ and I want to use a replacement rule to change the position of the objects and thereby represent movement.


title: Visualizing directories

text: How do I plot the content of a directory and all its subdirectories into infinity using TreeForm? I've tried using a mix of FileNames, StringSplit and GatherBy but in the end I couldn't find even a promising start.


title: How to change machineprecision digits

text: I am trying to compute `t0`:               eq[n_, β_, λ_] := Hypergeometric1F1[1/2 (1 - λ/β), n + 1, β/2]     EDL[n_, β_, k_Integer: 1] := λ /. FindRoot[eq[n, β, λ] == 0, {λ, (2 k - 1) β}]     t0 = Table[EDL[0, β, 1], {β, 50, 100}]      When I tried this code I have a problem for $\beta$=(82, ..., 97), the answer is not accurate and I got the error message: > FindRoot::lstol: The line search decreased the step size to within tolerance > specified by AccuracyGoal and PrecisionGoal but was unable to find a > sufficient decrease in the merit function. You may need more than > MachinePrecision digits of working precision to meet these tolerances. So, I want to change the machine precision, so I tried:               t0 = SetPrecision[Table[EDL[0, β, 1], {β, 50, 100}], 30]      But I still have a problem. Please help me to change and set the machine precision.


title: Faster GCD Implementation

text: Is there any chance to write a faster GCD than the built-in one in Mathematica? @Mr.Wizard has written one in this question (although it's not for this purpose) which is 6 times slower on a 100k digits:               In[1]:= whileGCD=Module[{a=#,b=#2},While[b!=0,{a,b}={b,Mod[a,b]}];a]&;     In[2]:= Primo[n_]:=Product[i,{i,Prime[Range[n]]}]          In[10]:= prod=Primo[500000];     In[17]:= m=22Primo[20500] +1;          In[16]:= Timing[GCD[m,prod]]     Out[16]= {0.25,1}          In[12]:= Timing[whileGCD[m,prod]]     Out[12]= {1.609,1}


title: How can I use NestWhileList instead of While in this case?

text: OK, the problem occurred when I challenged with Project Euler No. 10 > The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all > the primes below two million. My code is:               ClearAll[primelist, i]     primelist = {}; i = 1     While[Prime[i] < 2*10^6, AppendTo[primelist, Prime[i]];i++]     Plus @@ primelist      And I get the answer correct. I think using `While` is not a good habit in functional programming, but I can not modify my code to `NestWhileList`(or others FP-like functions). One of the proper manner is:               Plus @@ (Prime /@ NestWhileList[# + 1 &, 1, (Prime[# + 1] < 2*10^6 &)])      But I think it is not efficient, because when evaluating the `NestWhileList`, `Prime[1],Prime[2],Prime[3],...` ran the first time(in order to compare with 2*10^6), and then when mapping Prime to the list which was the result of `NestWhileList`, the same thing went once again! MMA evaluate `Prime[1],Prime[2],Prime[3],...` one more time.   1. Is there any method (or SOP) that can always change `While` to `NestWhile` or `NestWhileList`?   2. And I found that the second code above run faster much more than code 1, unbelievable.


title: Converting Excel serial dates with NETLink

text: Excel serial dates are not straightforward to convert since they include non- existent dates, e.g.               {DatePlus[{1990, 1, 0}, 59], DatePlus[{1990, 1, 0}, 60]}      > {{1990, 2, 28}, {1990, 3, 1}} ![enter image description here](http://i.stack.imgur.com/KcKuw.png) As shown, Mathematica finds date 60 is March 1st while Excel converts it to Feb 29th. To do the conversion I would like to use .NETLink with               DateTime dt = DateTime.FromOADate(60);      as given here. Can anyone help? I imagine something of the following form would work:               Needs["NETLink`"];          convertDate[serialdate_] :=      NETBlock[       InstallNET[];       (Mathematica form of DateTime.FromOADate (serialdate))       ]      **Edit** As Sjoerd pointed out, the problem is caused by an Excel bug, but only for year 1900. Conversion can be done using this:               convertDate[serialdate_] :=       If[serialdate < 61, "N/A", DatePlus[{1901, 1, 0}, serialdate - 366]]      I would still be interested to see how it would be implemented in NETLink, for future reference for applications making quick calls to .NET.


title: Labelling objects in a picture with numbers

text: I need help processing a biology bacteria picture. I just started learning _Mathematica_ and I hope you guys can use a simple method to help me solve the problem, please do not use super complicated methods. Below is what I want to do, it was done by my friend and he refuses to teach me. I want to label each bacteria cell on the picture with numbers. My thoughts are as follows:   1. Binarize the image and use `ComponentMeasurements` to find the centroids of all bacteria cells.    2. Convert the centroids (coordinates) to numbers 1 to 12 and make it into a graphic.   3. Show my original picture together with the picture numbered 1 to 12 to get my end result. However, my problem is that I do not know how to convert centroids (which are coordinate positions) into numbers. ![enter image description here](http://i.stack.imgur.com/ZmRE3.jpg) * * * Thanks Simon Woods! Here is my code and my attempt. Please correct me and see which part am I wrong. Firstly, This is the picture I started off with (named " **bacteria** ") and I want it to be labelled as shown on the above picture. ![enter image description here](http://i.stack.imgur.com/IoK07.jpg) And this is my code. I did not include how I sharpen and binarize the picture because it is quite straightforward. I will only start with the part whereby I get the centroids. i named my binarized picture as " **image** ".               morpData = MorphologicalComponents[image]     Tally@Flatten@morpData     cenData = ComponentMeasurements[morpData, {"Centroid"}]     getCenData = centroidData[[All, 2, 1]]      After these 4 steps, I managed to get the list of centroid coordinates which are               {{483.727, 478.227}, {422., 442.5}, {289.862, 331.534}, {245.261, 299.542}, {140.959, 259.041}, {404.427, 224.821}, {538.261, 223.39}, {56., 174.192}, {41., 140.844}, {190.529, 95.6238}, {277.262, 65.4048}, {491.833, 34.2778}}      This is good because I managed to identify all 12 bacteria in the picture. However, I need to know how to convert centroid coordinates to labeled numbers!! I tried, but I still cannot do it. And to prove that I really tried, this is my latest effort at trying to convert the 12 centroid coordinates into numbering and overlay with the original image. Please tell me where I went wrong:               Show[bacteria,Map[Graphics[Text[Style[getCenData[[1]], Red], getCenData[[2]]]], getCenData]]      And please, do not tell me to convert one by one, that is too troublesome.


title: How to match a pattern with a pattern?

text: **UPDATED** This question is about: "What is the pattern to match a pattern-definition, exactly as it is written?" My original question is now split according to Mr.Wizards insightful answer below. This question is about simple cases which can be solved with `Verbatim`. The other question (here) is what I should have asked originally: how to generally match and unify patterns and how to find their most general unifier. Therefore the following examples contain cases for both this and the other question. I won't modify these as it would ruin the understandability of the answers. Consider the following pattern comparisons, which intuitively suggest a matching, though all returning `False`:               MatchQ[a | b, b | a]     MatchQ[{a ..}, {a ..}]     MatchQ[{a ..}, {a ...}]      The output I would like to have is `True`. The idea is that the first argument specifies an object that can either be `a` or `b`. I scan through a lot of these objects looking for those that can stand in for either `a` or `b`, see toy example:               rules = {a -> 1, b -> 2, c -> 3, a | b -> 4, c | d -> 5, d | b | c -> 6};     Cases[rules, _?(MatchQ[First@#, a | b] &)]      > `{a -> 1, b -> 2}` Instead, I need the output to be: > `{a -> 1, b -> 2, a | b -> 4, d | b | c -> 6}`


title: Selecting polynomial roots and plotting against parameters

text: An implicit function $f(x,k)=0$ is quadratic in $x$ and contains one parameter $k$ which I must vary. Using `Solve`, I get two real solutions for each specific $k$: $x_1$ and $x_2$, of which I must choose the one that lies within $[0, 0.5]$. I must do this for a continuum of parameters $k$ between, say, $0$ and $1$. I then must plot the relevant $x$ solution against the parameter $k$ in a smooth curve. Note: I also tried the unglorious method i.e. if $k$ took discrete values, I thought I could manually select say 30 points and interpolate. But any curve fitting command I tried, using various polynomial and exponential expansions, could not give me smooth curve? Of course I hope to learn the elegant method, but under time pressure anything that gives me a smooth curve is welcome!


title: How to input formula embedded in text

text: I'm creating a styled notebook showing a simple theorem. I can set cell style as text or theorem or code to satisfy my requirement. But when I explain the theorem, I need to embed formula (not necessary for a whole line) into text. How can I do that. I didn't find any style for that.


title: How to remove an expression from a file?

text: To read in expressions from a file, one can do `ReadList[file, Expression, 3]`. How to do the opposite, i.e. remove a number of expressions from a file, modifying the file on the disk?


title: How to create Locator[] hierarchies?

text: I'd like to 'parent' Locators to one another, ideally organized in any arbitrary tree. The simplest case: If I have two Locators, A and B, then moving A will move both together, but moving B will only move that one. Any simple suggestions?


title: Using ImageCapture to access a USB webcam in linux

text: Is it possible to access a USB webcam through Mathmatica on Linux? When I run               ImageCapture[]      I get the following output               ImageCapture::notsupported: Image acquisition is not supported on Unix. >>      A quick search on Google does not return any useful solutions :(


Use _Mathematica_ to obtain an approximate value for the area between the curve $y=1/4$ and the x-axis over the interval $[1,2]$ with 50 subintervals using the left endpoint, midpoint and right endpoint approximations. Note: the entire calculation needs to be shown in _Mathematica_. Here's what I've tried:               a = 1; b = 2; n = 20;      Ln = (b - a[f)/n*Sum[f[a + (i - 1) (b - a) / n], {i, 1, n}]     LeftSum[f_, a_, b_, n_] := (b - a)/n* Sum[f[a + (i - 1) (b - a)/n], {i, 1, n}]     f[x_] := 1/xLeft = N[LeftSum[f, 1, 2, 20]]


title: Producing a bar chart with height and color determined by two distinct lists

text: I am trying to visualize a list of positive integers using a bar chart. In general, integers in that list may appear more than once. For example, I may have               list=Sort@RandomInteger[{1,10},20]      > >     {1, 2, 2, 2, 3, 4, 5, 5, 6, 7, 8, 8, 8, 8, 8, 8, 8, 9, 10, 10} >   The bar chart I have in mind has the shape of               BarChart[DeleteDuplicates[list], BarSpacing -> 0, ChartBaseStyle -> EdgeForm[]]      > ![enter image description here](http://i.stack.imgur.com/mf8bH.png) It basically forgets about the multiplicity of each integer. I prefer to have the multiplicity reflected in the color of the bars, so               BarChart[Tally[list][[All, 2]], BarSpacing -> 0,          ChartBaseStyle -> EdgeForm[], ColorFunction -> "Rainbow"]      > ![enter image description here](http://i.stack.imgur.com/jLY8r.png) has the color scheme I want on my first bar chart. Here is a slightly more general problem: > Given two lists containing the same number of positive integers, to produce > a bar chart with heights and colors determined by the respective lists.


title: Drawing Graph Products

text: I need to draw graphs that are Cartesian products of 2 graphs. I need them to look like this: ![enter image description here](http://i.stack.imgur.com/EYWYC.gif). So each copy of the factors can have `LinearEmbedding`, but the whole drawing should be based on grid-like skeleton. Clearly, vertices should be on nodes of the grid, and edges can be arbitrary. Are there any solutions? In particular, for Grid Graphs the `SpringEmbedding` gives similar result, but even for Torus Graphs result is very different. I need to draw Cartesian products of complete graphs, cycles, paths, complete bipartite graphs, and add labels to edges of the products.


title: Second level depth pure function?

text: I have the following working construction:               Select[ln125, # == Nearest[ln125, 551.748][[1]] &]      Here, `ln125` is a one dimensional list. What I want further is to apply this construction not only to `ln125`, for example, but for a list of `{ln125,ln126,ln127}`. Let's say,               f[list_]:=Select[list, # == Nearest[list, 551.748][[1]] &]      I want to do this:               f /@ {ln125,ln126,ln127}.      The question is: is it possible to acheive my goal only using pure functions? That is, without defining dummy function (`f` in my case)? The problem is that definition of `f` already has pure function (as a criteria for `Select`) and, thus, there should be two pure function of different depths (don't know how to name it correctly) at once. In other words, I want to turn the `list` variable into `#` but in a way that _Mathematica_ can distinguish which `#` goes with each different pure function.


title: Different Plot Filling for multiple curves

text: _Warning: possibly dumb question :-(_ I have two functions I want to plot with the `Filling` option, like:               Plot[{Sin[t], Cos[t]}, {t, 0, 4 Pi}, Filling -> Axis]      That's OK. But if I only want the sine filled, and try               Plot[{Sin[t], Cos[t]}, {t, 0, 4 Pi}, Filling -> {Axis, None}]      MMA returns error messages that `Axis` and `None` are not valid Filling specifications. How can I selectively apply `Filling`?


title: Can individual locators in LocatorPane be temporarily disabled?

text: This follows up on another question about the sensitivity of Locators in a a LocatorPane. I would like to be able to enable/disable individual locators in a LocatorPane. In the simplified version of the applet, pictured below, I would like to be able to disable the locators that set the slope of the red line, while allowing the locators that set the slope of the blue line to remain enabled. ![locators](http://i.stack.imgur.com/FvA81.png) Using individual `Locator`s, rather than a `LocatorPane`, is not an option. (There are some subtle issues that arise with individual locators. Essentially, multiple `Locator`s can behave in a "flaky" fashion in complex applets, in ways that `LocatorPane` does not.) Code below:               Manipulate[m = 15;      LocatorPane[Dynamic[pts],       Dynamic[ Module[{x = pts[[1, 1]], y = pts[[2, 2]], x2 = pts[[3, 1]], y2 = pts[[4, 2]]},       Graphics[{       {Blue, Line[{-m*{x2, y2}, m*{x2, y2}}]},       Line[{{x2, 0}, {x2, y2}}], Line[{{x2, y2}, {0, y2}}],       {Red, Line[{-m*{x, y}, m*{x, y}}]},       Line[{{x, 0}, {x, y}}], Line[{{x, y}, {0, y}}]},       PlotRange -> m, Axes -> True, ImageSize -> {300, 300}]]],       {{{-m, 0}, {m, 0}, {1, 0}},         {{0, -m}, {0, m}, {0, 1}},         {{-m, 0}, {m, 0}, {1, 0}},         {{0, -m}, {0, m}, {0, 1}}},      Appearance -> {Automatic, Automatic, Automatic, Automatic}],       {{pts, {{6, 0}, {0, 9}, {3, 0}, {0, 7}}}, ControlType -> None}]      The **visibility** of the locators can be individually controlled by toggling the respective locator's `Appearance` between `None` and `Automatic`. But even when the locator is invisible (i.e. `Appearance -> None`) it continues enabled. For example, the red sliders will continue to set the slope of the red line. A possible solution would be to obtain the `Appearance` setting of the red sliders and make the assignment of `x` and `y` contingent on the Appearance setting.


title: Under what conditions does FinancialData return a ::notent message?

text: I tried retrieving `FinancialData` for a few companies but when I tried doing it for NTDOY, I couldn't. As of 25/12/2012, querying                FinancialData["PK:NTDOY"]      yields > FinancialData::notent: PK:NTDOY is not a known entity, class, or tag for > FinancialData. Use FinancialData[] for a list of entities. However, this is weird for two reasons. Firstly, `PK:NTDOY` is included in the list of financial instruments Mathematica supposedly has data for:                FinancialData["*NTD*"]      yields                {"JK:INTD", "NASDAQ:GKNTD", "NASDAQ:UNTD", "PK:ANTD", "PK:NTDMF", "PK:NTDOF", "PK:NTDOY"}      Secondly, if I try using free-form input, e.g. > = NTDOY price from 25 December 2011 to 25 December 2012 I get the same (notent) output; on the other hand, if I click on the orange "Show all results" plus symbol, I get a WA-like tab filled with meaningful data, even though sometimes Mathematica crashes while computing. So my question is: what does `FinancialData` truly mean when it states that something is not "known"? Is this a software bug or is it simply that more data is available to WolframAlpha than is to Mathematica? (I'm using Mathematica 8.0.1.0, by the way.)


title: How to draw a great circle on a sphere?

text: I apologize for the text description, but new users are not allowed to post images. I want to draw a circle that cuts through the center of a sphere and has an inclination of 15 degrees with the horizontal axes (equator). Actually, there are infinite number of great circles that can satisfy this requirement. If someone can show me how to make a `Manipulation`, that will be better.


title: Find the dimensions of a cylindrical can that will minimize the cost of the material

text: > A cylindrical can is to be made to hold 1 L of oil. Find the dimensions that > will minimize the cost of the metal to manufacture the can. This is a standard calculus problem. The volume of the cylinder is: `V == π r^2 h` The area of the cylinder is: `A[r_] := 2 π r^2 + 2 π r h /. h -> V/(π r^2)` Find `r` when the slope of the area is zero:               Reduce[A'[r] == 0]      Result:               (r == -(-(1/(2 π)))^(1/3) V^(1/3) ||         r == V^(1/3)/(2 π)^(1/3) ||         r == ((-1)^(2/3) V^(1/3))/(2 π)^(1/3)) && r != 0      As you can see, when I defined `A[r]`, I replaced `h` with an expression produced by solving the volume equation for `h`. My question is, is there a way to express the problem in terms of Reduce and a set of equations, without the manual solving for `h`? I.e. something along the lines of:               A[r_] := 2 π r^2 + 2 π r h          Reduce[{A'[r] == 0, V == π r^2 h}]      Of course, that doesn't yield the correct answer because `A'[r]` doesn't treat `h` as being in terms of `r`.


title: Selecting elements from a list one by one

text: I have an list:               l = {{4,5},{7,8},{9,5},{3,2},{1,2},{13,12}}.       I want to take the elements in the list in the sequential order. For example the first element in the list is `{4,5}` and I want to select the first member in the sub-list, `4`, then I want to go to the second element in the list `{7,8}` and to take the first element `7`. This process continues up to `{13,12}` and selecting `13`. How can I do this?


title: Solve matrix equation A*X=X*B using LeastSquares

text: I want to solve matrix equation `A*X=X*B` using LeastSquares method, but it is suited for equation like A*X=B. All matrices are 3x3               A = {{a11, a12, a13}, {a21, a22, a23}, {a31, a32, a33}}          B = {{b11, b12, b13}, {b21, b22, b23}, {b31, b32, b33}}          X = {{x11, x12, x13}, {x21, x22, x23}, {x31, x32, x33}}          a33=b33=x33=1, a31=0,a32=0.      How can I do this? **Update:** I figure out that it's special type of equation I'm trying to solve a special case of Sylvester equation in my case it looks like $$A*X=X*B$$ so it can be write in form $$A*X+X*(-B)=C$$ where C consist of all 0 items. I tried to solve it in Mathematica with LyapunovSolve but it gives me a all- zero trivial solution. So I want to check if a non-trivial solution exists. It seems I find out how to test matrices A,B for non-trivial solution (but I'm not sure) if resultant equals to 0, then such solution exist.$$\mathrm{resultant}(\mathrm{det}(A-λE),\mathrm{det}(B-λE),λ)=0$$ I tried real matrices for example `A = {{0 -1 300}, {1 0 0}, {0 0 1}}`, `B = {{-0.4009 -1.0787 446.1463}, {1.6180 0.8875 -159.2272}, { 0.0003 0.0029 1}}` but there is maybe a problem because B matrix was defined experimentally and it has some small errors, with these matrices I have resultant -6.79 , but due to erorrs I don't know may be it close enough to 0? My question is: Can you write condition of existence of non-trivial solution of Sylvester equation not in abstract form but in particular formula, preferably in Mathematica. Also I don't understand why Mathematica gives me only trivial solution, when I try to solve this equation with parameters. For example I tried               am = {{a11, a12, a13}, {a21, a22, a23}, {a31, a32, a33}}          bm = {{b11, b12, b13}, {b21, b22, b23}, {b31, b32, b33}}          cm = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}          LyapunovSolve[am,bm,cm]      which gives me all 0. Also I tried to multiply matrices and get 9 equations and solve them with function Solve which also give me all 0.


title: Grid without lines, but with dots

text: I want to build a grid to look like the top-left table shown below, but without an outside frame. ![enter image description here](http://i.stack.imgur.com/3csys.jpg) Here is what I've tried to do:               a = {         {, , 2, 2, 2, 2,},         {, , 3, , 2, 0, 3},         {, 2, 2, , 3, , 3},         {2, 2, 2, , , , 2},         {2, 3, , , 1, ,},         {2, , 1, 3, , ,},         {3, 3, 3, 2, 3, , 3}         };          f = Riffle[#, "\[CenterDot]", {1, -1, 2}] &;          f /@ Transpose[f /@ a] // Transpose // Grid      ![enter image description here](http://i.stack.imgur.com/TMtEC.png) What I don't like in my result is that I have three times more dots than I need. And I don't know how to fix it. Suggestions?


title: Selectively clear DownValues

text: How can I clear a subset of a symbol's `DownValues` ? For example, suppose I have created some DownValues for $f$ like this:               (f[Sequence @@ #] = Plus @@ #) & /@ Subsets[{1, 2, 3}];     f[x_, y_] := x y          DownValues[f]         (*  {HoldPattern[f[]] :> 0, HoldPattern[f[1]] :> 1,       HoldPattern[f[2]] :> 2, HoldPattern[f[3]] :> 3,       HoldPattern[f[1, 2]] :> 3, HoldPattern[f[1, 3]] :> 4,       HoldPattern[f[2, 3]] :> 5, HoldPattern[f[1, 2, 3]] :> 6,       HoldPattern[f[x_, y_]] :> x y}  *)      I now wish to clear all the downvalues for which $f$ has exactly $n$ numerical arguments. In other words I would like to have a function `selectiveClear[f,n]` such that this would happen:               selectiveClear[f,2]     DownValues[f]     (*  {HoldPattern[f[]] :> 0, HoldPattern[f[1]] :> 1,       HoldPattern[f[2]] :> 2, HoldPattern[f[3]] :> 3,       HoldPattern[f[1, 2, 3]] :> 6, HoldPattern[f[x_, y_]] :> x y}  *)      I have tried using `Cases` to pick a subset of the `DownValues`, but I can't seem to get the pattern correct.