Highlight the same symbol throughout notebook

Once I saw people using Matlab use a keystroke shortcut that made all the same symbols as a selected symbol become blue. I am wondering is there is a function in _Mathematica_ that is similar. If so, what's the keyboard convenient shortcut. (Of course, `Ctrl`+`F` can be made to do something a little similar, but that is not what I'm looking for.)


Mathematica won't solve equation I know is solvable

I'm just trying to solve the Schrodinger equation for hydrogen. We went through the solution by hand in class but Mathematica doesn't do anything when I try to solve it (it just re-displays what I typed in):               DSolve[-h^2/(2*mu)*(1/r^2*D[r^2*D[y[r,theta,phi],r],r] +          1/(r^2*Sin[theta])*D[Sin[theta]*D[y[r,theta,phi],theta],theta] +          1/(r^2*Sin[theta]^2)*D[D[y[r,theta,phi],phi],phi]) -          k*q^2/r*y[r,theta,phi] == energy*y[r,theta,phi],y,{r,theta,phi}]


find the real root

I have the following equation: \begin{equation} (y-1)^{b1} - C~~ y~~ \exp(a x)=0 \end{equation} where $a, b$ are real constants, $C$ may be a complex number. I need to find the real solution of the above equation for each choice of $x$, with $x \in [-100, 100]$.   I tried with $\mathbf{fzero, fsolve}$ in _Matlab_. But it does not work. I also tried to solve with the Newton - Raphson method. The outcome is negative. Is it possible to solve it in any other way. Any help/suggestion/advice, will be very useful. I tried with the below given mathematica code, but it almost give up as I increase the range of $x$. Here is my mathematica code:               k  = 0.5;   (*k is positive*)     b  = 0.01;  (*b is a positive number not greater than 1*)     a1 = bk;     b1 = 1 + b;     a2 = b1 + k;     a  = a1 / a2;     y0 = 0.5;     z  = ConstantArray[0, 11];     For[x = −5; i = 1,         x < 6,         x = x++; i++,      t = Solve[y0 (1 − y)^b1 − y (1 − y0)^b1 Exp[a x] == 0, y];      z[[i]] = y /. t]      I need the real solution, not the real part of the solution. Secondly my constants are dependent on parameters $k, b$ as stated in the code. And $C = \frac{(1-y0)^{b1}}{y0}$. Hope my question make sense in the mathematica category. Any further query / suggestions/ feedback, please let me know. Thank you all who show concern; I require your help.


Unexpected result when reading Cell with comment-lines by NotebookRead

When considering this question about re-formatting `Cell` (also this one), I encountered an issue which confuses me. I'll let the code itself speak: Consider the following simple `Cell` expression, which contains a comment line:               cellexpr =        Cell[BoxData[{RowBox[{RowBox[{"a", ";"}], "\[IndentingNewLine]",             RowBox[{"(*", RowBox[{"b", ";"}], "*)"}]}],           "\[IndentingNewLine]", "c"}], "Input"];      Write it to a `Notebook`:               testnb = NotebookCreate[];     NotebookWrite[testnb, cellexpr];      It looks like the following, which is what one would expect: ![enter image description here](http://i.stack.imgur.com/9ozU1.jpg) Now read the `Cell` expression back from `testnb`:               SelectionMove[testnb, Before, Notebook];     SelectionMove[testnb, Next, Cell];     NotebookRead[testnb]      ![Mathematica graphics](http://i.stack.imgur.com/DDMrU.png) Note the first `RowBox`, it has a structure as `RowBox[ item1, item2, ...]`, which is ill-posed since _the first argument to RowBox must be a list_. And the obtained `Cell` expression is therefor ill-posed, which can be seen by `CellPrint`-ing it: ![enter image description here](http://i.stack.imgur.com/PY050.jpg) I noticed that if the comment-line part is removed (e.g. by deleting `"(*"` and `"*)"` in `cellexpr`), everything works fine. And for the example in this question, the second comment is correctly obtained: ![Mathematica graphics](http://i.stack.imgur.com/rwS6u.png) # My question: Did I miss something? Or is this a bug? My system: **Mathematica 9.0.0.0** on **Windows 7 32-bit**


How to numerically integrate this integral?

I want to integrate the function funcin (spherical coordinates).               ϵ=78.36     λ=0.548881         funcin =        1/(ϵ*π)*Exp[-(2*r + λ*Sqrt[r^2 + ρ^2 -          2*r*ρ*Cos[θ]])]*r^2*Sin[θ]*1/Sqrt[ρ^2 + r^2 - 2*r*ρ*Cos[θ]]     intfuncing = Integrate[funcin, {r, 0, Infinity}, {θ, 0, π}, {ϕ, 0,2 π}]      If I use analytic calculation (`Integrate`), an integral over r is left, which must be numerically evaluated, e.g., by using `N[intfuncing]` for specific ρ. For example I can write:                Do[ρ = 0.1 + (i - 1)*0.05; int[[i]] = N[intfuncing], {i, 60}]      to calculate the integral at 60 points. But I get an error by that: > NIntegrate::slwcon: Numerical integration converging too slowly; suspect one > of the following: singularity, value of the integration is 0, highly > oscillatory integrand, or WorkingPrecision too small. If I try to evaluate the integral numerically with `NIntegrate`, I get: > the integral ... evaluated to non-numerical values for all sampling points > in the region with boundaries {{∞, 0.}, {0, 3.14159}, {0, 6.28319}}. Does anyone have an idea how to solve this problem?


Where can I find the Distributions Palette?

I was watching the "Statistics: Modeling with Statistical Distribution" Training Course http://www.wolfram.com/training/videos/DAT016/ and in one of the slides, the following image showed up. Does anybody know if this palette is available and where can it be found? ![enter image description here](http://i.stack.imgur.com/OohYD.png)


How to return matching sublists or empty list               m1 = {{1, 0.5}, {2, 0.4}, {3, 0.1}};     m2 = {{1, 0.5}, {0, 0.4}, {0, 0.1}};     Commonest[Join[m1, m2]]       out:               {{1, 0.5}}      But it fails to return 0 or empty list as the lists do not match               m1 = {{1, 0.5}, {2, 0.4}, {3, 0.1}};     m2 = {{0, 0.5}, {0, 0.4}, {0, 0.1}};     Commonest[Join[m1, m2]]       out:               {{1, 0.5}, {2, 0.4}, {3, 0.1}, {0, 0.5}, {0, 0.4}, {0, 0.1}}      how to return empty list?


Calculate expected value of custom pdf

I've a custom pdf in the sense that it's the convolution of several other PDFs               p[t_] := Convolve[p1[x],p2[x],x,t];      Now I want to calculate the expected value of this 'new' pdf w.r.t $t$ $\mu = \mathbb{E}_t [ p(t) ]$ How can I do this with mathematica?


How to get rid of the perspective effect in a 3D graphics

I have plotted a figure of MoS2 crytal structure. But the actual output looks like the spheres are not in the correct position due to the perspective effect. I obtained the correct position figure by setting the `ViewPoint` to `Infinity`. But when I rotate the figure, the infinity effect fails and the perspective effect takes place again. ![before and after rotation](http://i.stack.imgur.com/PI6Hk.png) I was wondering if there is a way to get rid of the perspective effect when you draw a graphic? Thank you. Here is my code               a0 = 1; ceng = 1; znn =3*ceng; ynn = 5; xnn = 5; a1 = 2; cznn = 3; hh = 2;     p1[θ_] := RotationTransform[θ, {0, 0, 1}];     posx1 = (nx1 - 1) a0 + ((ny1 - 1) a0)/2 + (Mod[nz1 - 1, 3] a0)/2;     posy1 = Sqrt[3]/2 (ny1 - 1) a0 + (Sqrt[3] Mod[nz1 - 1, 3] a0)/6;     posz1 = Sqrt[3]/2 (nz1 - 1) a0 + Floor[(nz1 - 1)/3] a0;     sinpq2 = Transpose[Table[{posx1, posy1, posz1}, {ny1, ynn}, {nz1, znn}, {nx1, -xnn, 0}]];     rr = 0.3 a0;     tom2 =        Table[         Graphics3D[{If[Mod[cc, 3] == 2, Pink, Yellow], Sphere[sinpq2[[cc, bb, aa]], rr]}],          {aa, xnn}, {bb, ynn}, {cc,znn}];     Show[tom2,        Axes -> False,        BoxStyle -> Directive[Orange, Opacity[0]],         BoxRatios -> Automatic,        PlotRange -> All,        Background -> Black,         ViewPoint -> {0, 0, ∞}]


two histograms ratio

I have two histograms and using listplot to draw both. Now, I want to draw a second plot, below the first, with the ratio of each bin. Does anyone know how to do this? Many thanks. This is the code I'm using to draw the histograms:               Needs["PlotLegends`"]          dadosGtop = Import["Gtop_PR.dat", "table"];          costhbGtop = Table[dadosGtop[[i]][[1]], {i, 1, Length[dadosGtop]}];          costhleGtop = Table[dadosGtop[[i]][[2]], {i, 1, Length[dadosGtop]}];               histPlot[data_, bins_, origin_, color_, label_, title_, nome_] :=        Module[{countBorder1 =           Partition[Riffle[Riffle[#1, #1[[2 ;;]]], Riffle[#2, #2]], 2] & @@            HistogramList[data[[1]], bins],          countBorder2 =           Partition[Riffle[Riffle[#1, #1[[2 ;;]]], Riffle[#2, #2]], 2] & @@            HistogramList[data[[2]], bins],         },        ListLinePlot[{countBorder1, countBorder2}, PlotRange -> All,          PlotStyle -> {{color[[1]]}, {color[[2]], Dashed}},          AxesLabel -> {Style[label[[1]], 14, Bold],            Style[label[[2]], 14, Bold]}, AxesOrigin -> origin,          LegendPosition -> {0.65, 0.1}, LegendSize -> 1,          LegendShadow -> None,          PlotLegend -> {Style[nome[[1]], 12, Bold],            Style[nome[[2]], 12, Bold]},          PlotLabel -> Style[title, Black, 14, Bold],          TicksStyle -> {16, Bold}, ImageSize -> Scaled[0.6]]];          histPlot[{costhbGtop, costhneGtop}, {-1, 1, 0.1}, {-1, 0}, {Green, Blue}, {"\[Eta]",        "\!\(\*FractionBox[\(dN\), \(d\[Eta]\)]\)"}, "Pseudorapidity of b", \     {"b", "ne"}]      Here is a data sample:               dadosGtop={        {-0.68, 0.536, 0.316}, {-0.394, 0.187, 0.287}, {-0.874, 0.753, 0.474},        {-0.202, 0.18, 0.066}, {-0.267,  0.894, -0.077}, {0.126, -0.144, -0.063},        {0.952,  0.63, -0.953}, {0.671, 0.073, -0.84}, {-0.344,  0.72, -0.024},        {0.824, -0.205, -0.741}, {0.718, -0.793, -0.268}, {-0.423, 0.568, -0.204},        {-0.192, -0.096, 0.357}, {-0.03,   0.865, -0.629}, {-0.784, 0.39, 0.588},        {0.98, 0.59, -0.953},   {-0.97,  0.682, 0.653}, {-0.654, 0.907, -0.201},        {-0.35,   0.712, -0.176}, {-0.929, 0.654, 0.48}, {-0.479, 0.826, 0.099},        {-0.54, 0.785,-0.724}, {-0.812, 0.818,-0.069}, {-0.988, -0.083, 0.89},        {-0.559, 0.976,-0.188}, {0.748, 0.211,-0.994}, {0.507, -0.527,-0.266},        {0.776, -0.025,-0.964}        }


How to introduce custom hot keys for the styles of cells?

In the JournalArticle StyleSheet there are useful hot keys Alt+6 for a DisplayFormulaNumbered and Alt+5 for the DisplayFormula. Such hot keys, however, are not present in the Default StyleSheet. Even more, there Alt+5 is reserved for the Section, and Alt+6 - for the subsection styles. Is it possible to introduce custom hot keys for (generally) any cell style for which there is no built-in one?


How to tell Mathematica not to simplify an expression

While there is this question with a very similar title, it does not answer my question, which is: I have part of an input, in my case               Re[Exp[I*x]]      which _Mathematica_ "simplifies" to > >     Cos[Re[x]]/E^Im[x] >   So I am wondering how to tell _Mathematica_ to leave this expression, whether it's alone or part of a longer formula, in its previous form rather than to change it as shown here. ### Update I should probably add I am still running version 6, hoping this is not causing the issue.


Gather list elements by index

The following list has some elements that are labeled. For example `{1, 2} -> 1, {-1, 3} -> 3`, etc:               list = {{1, 2}, {-1, 3}, {5, 6}, {-3, 4}, {7, 8}, {-9, 1}, {0, 1}};     labels = {1, 3, 2, 1, 2, 1, 3};      What is a good way to gather `list`'s elements clustered according to their labels?               clusters = {{{1 ,2}, {-3, 4}, {-9, 1}}, {{5, 6}, {7, 8}}, {{-1, 3}, {0, 1}}}


keyboard sequence for Magnify in version 8?

It used to be that you could find a Magnify item in the Format menu of the Mathematica front-end, at the very bottom if I remember correctly. You could get at the item in Windows by a keyboard sequence like `Alt-R`, `M`, then a number. Mac probably had something similar. This was really useful for mouse avoiders like me. That little tiny drop menu in the extreme lower right of a notebook is annoying to catch with a mouse on highest-speed setting, which you need on a high-def screen with 1920 or 2560 pixels width. My mouse movements end up looking like a plot of a strange attractor swirling around the target! I haven't been able to find the Magnify menu item in Mathematica 8 nor any other keyboard shortcut for notebook-magnify in the Mathematica documentation center. Would be grateful for anyone pointing out any means for accessing notebook magnify from the keyboard.


How to force the compilation language to be C++ (not C) in CreateExecutable or CreateLibrary

I'm trying to speed up a section of a Mathematica 9.0.1 notebook by performing some calculations in C++ with the Cilk Plus and Threading Building Blocks tools available for the Intel C++ 14.0 compiler [in Intel Parallel Studio XE 2013 SP1, installed with VS 2012 Professional, running under Windows 8.1 Pro]. I would like to avoid using MathLink to access the C++ code, if possible, and "get away with" using the CreateExecutable and CreateLibrary functions of Mathematica. I've had no success with CreateLibrary, as yet, but I have had one "success" and one failure with CreateExecutable. I'm trying to understand my one success as a way of possibly fixing the failures. The simple Cilk-enhanced C++ code below adds the number 7 to itself one trillion times in about 8 seconds on a 4-core, 3.5 GHz clock, laptop. This code is not useful from the standpoint of the result it computes, but it quickly makes the fan run and serves to test whether or not Cilk-enhanced C++ code can be incorporated within a Mathematica notebook. So, apparently, it is possible to run Cilk-enhanced C++ code from Mathematica. The code works if I first write the Cilk-enhanced C++ code string, CilkMain, to a file with the extension .cpp, and then use that .cpp file as the first (list) argument of CreateExecutable. When I use the ShellCommandFunction and ShellOutputFunction options of CreateExecutable to look at what happened, it seems that Mathematica looked at the .cpp extension, forwarded a .cpp file to the Intel compiler, and everything worked.               In[1]:= nbdir = NotebookDirectory[];         Needs["CCompilerDriver`"]         CCompilers[Full];         $CCompiler = {"Compiler" -> CCompilerDriver`IntelCompiler`IntelCompiler,         "CompilerInstallation" -> "C:\\Program Files (x86)\\Intel\\Composer XE 2013          SP1"};          In[5]:= cilkMain = "         #include<cilk/cilk.h>         #include<cilk/reducer_opadd.h>         #include<stdio.h>              int main()         {         cilk::reducer_opadd<long long>j(0);         long long size=(long long)(1000)*(long long)(1000*1000*1000);                       cilk_for(long long i=0;i<size;i++) j+=7;              printf(\"The value of j is %14lld\\n\",j.get_value());         return 0;         }";          In[6]:= Export[nbdir <> "cilkMain.cpp", cilkMain, "Text"];          In[7]:= cilkExe = CreateExecutable[{nbdir <> "cilkMain.cpp"}, "cilkExeFile"];          In[8]:= AbsoluteTiming[Import["!" <> QuoteFile[cilkExe], "Text"]]          Out[8]= {8.165778, "The value of j is  7000000000000"}          In[9]:= cilkExe = CreateExecutable[cilkMain, "cilkExeFile"]             cilkExe = CreateExecutable[cilkMain, "cilkExeFile", "Language" -> "C++"]          Out[9]= $Failed          Out[10]= $Failed      But if I give the Cilk-enhanced code string directly to CreateExecutable as its first (non-list form is required for a string) argument, with or without the "Language" option set to "C++", the code fails. The printed results from the ShellCommandFunction and ShellOutputFunction options show that for a string argument, a file with extension .c is forwarded to the Intel compiler, which leads to failure because the Cilk functions require C++ compilation. Is there a direct way to tell CreateExecutable and CreateLibrary to forward code for C++ (not C) compilation? There is little documentation of the "Language" option in the Mathematica help, and no examples. What you see in the notebook above is merely my best guess as to how to force C++ compilation. Clearly, it is an incorrect guess, likely based on incorrect understanding. I don't like resorting to tricks, such as writing a string to a file with a special extension, in order to fool a Mathematica function. What is the right way to do this? Learning the right way may well set me on the road to fixing the failures. P.S. Thanks for the quick replies. Will look at CCompilerDriver` code, then move on to trying to trick CreateLibrary in a similar way.


Bad fonts in Mathematica 10

In _Mathematica_ V10, the glyphs for mathematical and/or other special symbols are wrong. I see this in input cells and also in the Basic Math Assistant palette. How do I solve this problem?


Is pure pattern matching without PatternTest and Condition Turing-complete?

Note that this question is _not_ a duplicate of that one. It is specifically about the pattern-matching engine, and explicitly excluding those patterns which call back into the full evaluation (i.e. `PatternTest` and `Condition`; if there are others like those, consider them excluded as well). To state the problem more specifically: Given a problem with a yes/no answer which can be decided in finite time by an appropriate Turing machine, does there always exist a Mathematica pattern involving neither `PatternTest` nor `Condition` together with an appropriate encoding for the input data which matches iff the Turing machine would give "yes" for the input data? To make more clear what I mean, I give an example of a problem solvable both with a Turing machine and with the pattern matcher: Given a natural number, determine whether that number is even or odd. It is obvious that a Turing machine can solve this problem in finite time. Here's how pattern matching can solve that problem: Encode the natural number into a list of as many `1`, so that 0 is `{}`, 1 is `{1}`, 2 is `{1,1}` etc. Then the pattern implementing the test is simply `{PatternSequence[1,1]...}`.


Software for effectively modeling gears

Are then any applications for effectively modeling gears in mathematica?


What is the story with Removed symbols?

The system function `Remove` evidently exists primarily to turn a fatal problem into an annoying one, by giving the user a (rather blunt) instrument with which to resolve symbol clashes. Presumably, it works by removing the entry for a given symbol from whatever internal table Mathematica uses to look them up by name. However, there can be some interesting consequences when you have a reference to a symbol that you later `Remove`. First, we need to set up a symbol that we will remove, and give another symbol a reference to it:               In[1]:= y = 3     Out[1]= 3          In[2]:= x := y          In[3]:= x     Out[3]= 3          In[4]:= OwnValues[x]     Out[4]= {HoldPattern[x] :> y}      And then we can remove it:               In[5]:= Remove[y]          In[6]:= x     Out[6]= Removed["y"]      Now, we have `Removed["y"]`, which is the ghost of the symbol we just bludgeoned to death. However, contrary to appearances, `Removed` is not the head of the expression:               In[7]:= x // Head     Out[7]= Symbol       It's still a symbol. It appears to just have had all its values cleared when it was `Remove`'d. However, you need an elaborate incantation to contact a symbol that's moved on into the spirit world in order to verify this:               In[8]:= OwnValues[x]     Out[8]= {HoldPattern[x] :> Removed["y"]}          In[9]:= ReleaseHold[Hold[OwnValues[x]] /. OwnValues[x]]     Out[9]= {}      That's OK, though, because I can still give new values to the removed symbol!               In[10]:= With[{yy = x},               yy = 17]     Out[10]= 17          In[11]:= ReleaseHold[Hold[OwnValues[x]] /. OwnValues[x]]     Out[11]= {HoldPattern[Removed[y]] :> 17}      So, what _can't_ you do with a removed symbol that you can do with an ordinary symbol? And is there any reliable programmatic way to check whether a symbol really has been removed, seeing that it has a perfectly ordinary `Symbol` head? I suppose you can hack something together with `StringMatchQ`, but that just feels wrong and it's tough to get the evaluation order right if the removed symbol might have `OwnValues`.


Count Elements in Image

I have the following image: img1 ![enter image description here](http://i.stack.imgur.com/wOJps.png) I'm trying to count al these colored cells and draw a circle around them. I really don't now how I can use `SelectComponents` for this image. And `EdgeDetect` has the following result: img2 ![enter image description here](http://i.stack.imgur.com/hit12.png) Maybe some tips or examples. Greetings


How can I get even steps on x and y axes in a plot?

I'm plotting the shortest distance from a point to a line using the following code               Show[Plot[1/2 x + 1/2, {x, -6, 7}],           ListPlot[{{4, -2.5}, {2, 1.5}}, Joined -> True, PlotMarkers -> Automatic]]      As this is the shortest line from the point to the line, the angle between the two lines should be 90 degrees. It doesn't show up like that in _Mathematica_ , however, since the y-axis is incrementing in visually smaller steps than the x-axis. How can I get _Mathematica_ to automatically to use even steps on the two axes?


Extracting function calls from an expression

I have an expression like this:               expr = F[0, 1] + 2 F[0, 0] - 17*F[2, 0]      and I want to transform it to a list consisting of all function calls with its arguments:               MyList = {F[0, 1], F[0, 0], F[2, 0]}      Does anyone know a clever way to do this in _Mathematica_? My currently best solution is using ToString and do string-manipulations, but it is defintivly very slow and ugly.


NotebookWrite Cell with Grid

I'd like to `NotebookWrite` a `Cell` in `StandardForm` with a `Grid` to a new document. What I'd like to copy is               toCopy = TraditionalForm@Grid[{{a^2, b^2, c^2}, {d^2, e^2, f^2}}]      If I now use the following code               NotebookWrite[      CreateDocument[]      , toCopy]      I get a red rectangle in the new Notebookbook. I've tried to change all letters a to f to "a" ... "f", but nothing changed. I am somewhat puzzled... What I missing here? Thanks for all help, as always! Edit: With the answer of Alexey, it works good to copy the `Grid` to the new Notebook. But the TraditionalForm is lost: I get InputForm. Even using               NotebookWrite[      CreateDocument[],       ToBoxes[toCopy, TraditionalForm]]      doesn't seem to work. Any more help, as always, very much appreciated!


Drawing a series of circles with `MapThread` & `Graphics`

I'm attempted to use `MapThread` to draw a series of circles at coordinates correspond to some list, like so:               pointList = {{1, 0}, {1, 2}, {1, 3}};     Graphics[MapThread[{Circle[#1, 0.1]} &, pointList]];      However, this fails. Looking at the output for:               MapThread[{Circle[#1, 0.1]} &, pointList]      I see the following:               out -> {{Circle[1, 0.1]}, {Circle[0, 0.1]}}      MapThread is obviously not doing what I'd like it to do. Where's my error?


How to control variables of outer and inner Manipulates?

Consider the following ( working ) snippet:                 Manipulate[        Column[{         Manipulate[          vote,          {vote, {"Yes", "No"}},          Initialization :> {votes = 0}         ],         k,         Button["TEST", Print[votes]]        }],        {k, 1, 5, .5}       ]      My question concerns programming style and Outer/Inner Manipulate structures. What is the best way to handle code that is executed conditionally based on values in the inner Manipulate, but needs to be processed further in the outer Manipulate? I.e. checking thresholds, maintaining sub-totals, balancing, etc. To make my question 'answerable' I have translated it in terms of a simplified example: **how / where would you maintain a Yes vote counter that is used in the outer manipulate?** UPDATE: The requested pattern would also apply to synchronizing views in data on Tabs on a TabView.


Vertical alignment of FrameTicks Text

The text box of a FrameTick/Tick is, by default, vertically centered on the tick mark. ![Illustrating alignment of FrameTicks textbox](http://i.stack.imgur.com/uZgGg.png) Is there a way to adjust the vertical alignment of FrameTick text? Specifically, along the lines of Baseline, Top, etc. FrameTicksStyle in combination with TextAlignment/Alignment does nothing.


ArrayRules for a ragged list

Let there be a sample list as ,               l = {a, {{b, c}}, {d, e}, {f}, {{g, {y}, u, h}, {{{{k, j}}}}},k, {{{{q}, {w}, {r}, {x}}}}};     ArrayRules[l]      **ArrayRules::rect: Nonrectangular array encountered. >>** is the error thrown. So, I was just wondering that if someone needs to preserve list structure using a similar kind of functionality, than what might be the steps needed. My intention is to pass data to replace later rather than as rule in ArrayRules. I could parse list to find positions information like ArrayRules using following code,                ListRules[l_List] :=      Module[{l1 = l, l11, s1, pos, M, tpos, trpos, sp, ntrpos, temntrpos,         fin, fin2},        {l11 = {#} & /@ l1,         s1 = Map[{#, Position[l11, #]} &, l11,Infinity] /. {a_, {{s___}}} -> {s} //. {d___, {}, e___} -> {d,e},         pos = Table[s1[[i]] //. {___, {a___List}, ___} -> a, {i, 1,Length[s1]}],         M = Last[SortBy[pos, Length]] // Length,         tpos = Table[If[Length[pos[[i]]] < M, PadRight[pos[[i]], M, 1], pos[[i]]], {i, 1, Length[pos]}],         }; tpos]      listrules= ListRules[l]      > {{1, 1, 1, 1, 1, 1, 1}, {2, 1, 1, 1, 1, 1, 1}, {2, 1, 1, 2, 1, 1, 1}, {3, 1, > 1, 1, 1, 1, 1}, {3, 1, 2, 1, 1, 1, 1}, {4, 1, 1, 1, 1, 1, 1}, {5, 1, 1, 1, > 1, 1, 1}, {5, 1, 1, 2, 1, 1, 1}, {5, 1, 1, 3, 1, 1, 1}, {5, 1, 1, 4, 1, 1, > 1}, {5, 1, 2, 1, 1, 1, 1}, {6, 1, 1, 1, 1, 1, 1}, {5, 1, 2, 1, 1, 1, 2}, {5, > 1, 2, 1, 1, 1, 1}, {6, 1, 1, 1, 1, 1, 1}, {7, 1, 1, 1, 1, 1, 1}, {7, 1, 1, > 1, 2, 1, 1}, {7, 1, 1, 1, 3, 1, 1}, {7, 1, 1, 1, 4, 1, 1}} Than I tried to create it back to a list using following method,               CreateList[s_List] :=      Module[{tpos = s, trpos, sp, ntrpos, temntrpos, t, x, y,         h}, {trpos =Table[tpos[[i]] -> RandomInteger[100], {i, 1,Length[tpos]}],         sp = SparseArray[trpos],         ntrpos = Normal[sp],         temntrpos = ntrpos //. {a___, {h___, 0 ..}, b___} -> {a, h, b} //. {a___, {}, b___} -> {a, b}         }; temntrpos        ]     CreateList[listrules]      gives, > {{{{{{76}}}}}, {{{{{82}}, {{83}}}}}, {{{{{67}}}, {{{19}}}}}, {{{{{32}}}}}, > {{{{{51}}, {{22}}, {{60}}, {{1}}}, {{{{26,59}}}}}}, {{{{{12}}}}}, {{{{{6}, > {78}, {34}, {72}}}}}} It shows that it has been able to retain nesting structure but there are extra braces associated. I tried to use Dimension, Depth etc. I can get rid of nesting for single elements by associating dimension from original list with them and flattening all those with maximum dimension as 1 for Rest[sublist]. But in case of multiple nesting, I am failing. I have to keep number of braces same in both source and destination.


Plotting vectors originating from the origin in 3D

I have an array of data with 3D elements. Ex: `x = {{1,2,3}, {3,4,5}, {5,6,7}}`. I want to show this data in 3 dimensions, such that each point in the space is shown as a vector originating from the origin. There should be an arrow/line whose one end is at the origin $(0,0,0)$ and the other end at the point $(1,2,3)$. Which function should I use?


Efficient setting of properties of multiple vertices in Graph

The functions `SetProperty` and `PropertyValue` can only set a single property of a single vertex, as far as I know. How do I set a property for multiple vertices simultaneously? In the documentation, they recommend using `Do` to set multiple properties, but I've heard that `Do` is not the most efficient way to do things in _Mathematica_. Are there any alternatives? **EDIT :** The only approach seems to make several calls to `SetProperty` or `PropertyValue` (which is faster), one call for each distinct vertex property I want to set. From the answers so far it seems that there is no Mathematica equivalent to `SetProperty` or `PropertyValue` that sets several properties of distinct vertices at once. But I'd still hope that something could be done directly on the `Graph` object, bypassing `SetProperty` and `PropertyValue`.


Missing titles in palettes with Win 8

I just noticed that MMA (8 and 10) in Windows 8 on my machine does not display the title of any palette. For ex. Basic Math Assistant palette appears without title. Same with user-defined palettes Can you confirm this or it is just my Win 8? If it is just me, as I suspect, can anybody suggest any setting change to Win 8 that I may perform in order to show titles in palettes? Titles in notebooks are ok.


Numerical rule evaluation -> {True, False} to deviation of target equation

I solve some equations numerically with **FindRoot[]** returning a quadruple {1,2,3,4}. Because the solver sometimes do not find any roots depending on parameterization of these equations I select only those replacement rules "full filling" the equations:               Select[rules, ! MemberQ[eqns /. #1, False] &];      My question is the following: How can I easily calculate **the deviation of an application of a replacement rule** quadruples containing a False so i can check how "badly" some of my equations are not met. My problem is that as soon as I apply an rule to an equation the result is of type boolean and not numeric - which is needed for calculating the deviation. To note: I do back substitution of my previous solution into the solver as I'am variating some parameters. (see here) Thank you for your suggestions!


How to use summation to get the value of a binary number? I want to do this: $(x_{n}x_{n-1}...x_{0})=\sum_{i=0}^{n}x_{i}\cdot b^{i} $ But it seems that I can only do something like this: $\sum_{i=1}^{10}i^{2}$ I imagine that there is some indexation function which will help to do so, I also know how to do in another way, but is it possible to do this using summation?


Solve ODE $d^2u/dx^2 + u/A = 0$

How can I solve following ODE with Mathematical: $$d^2u/dx^2 + u/A = 0 \quad (\text{or } \ C),$$ with the conditions: $$ \left.\frac{d^2u}{dx^2}\right|_{x=0} = 0, $$ $$u(x=0) = B$$ and $$\left.\frac{du}{dx}\right|_{x=W} = 0, $$ $A$, $B$, and $C$ are constants.


Transform sequential cell operations to programmatic workflow

Let's say I have a workflow that involves importing images and turning them into an animated gif. Here's how I currently have it setup: Import Images:               imports = {};     importimages[] := Module[{a},        a = SystemDialogInput["FileOpen"];        If[ListQ[a], Table[Import[a[[i]]], {i, 1, Length[a]}], Import[a]]]     imports = Flatten[Append[imports, importimages[]]]      Allow for selection and rearranging:               sels = Range[Length[imports]];     CheckboxBar[Dynamic[sels], Table[i -> imports[[i]], {i, 1, Length[imports]}]]     imgs = Dynamic[imports[[sels]]]      Set animation rate and preview:               Manipulate[       displayrate = 1/rate;       ListAnimate[Setting[imgs], AnimationRate -> rate, AnimationRunning -> False],       {{rate, 1}, 0, 10, 0.1, LocalizeVariables -> False}]      Export to gif:               Export["~//Desktop//test.gif", Setting[imgs], "DisplayDurations" -> displayrate]      (By the way, feel free to improve code.) My question is, what is the best way I can smoothly and dynamically wrap this entire workflow into a graphical program where if I were to put a non- _Mathematica_ user in front of it, he/she can easily work it? This question mainly stems from my poor understanding of the dynamic constructs and roots in action-based programming. The gif routine is just an example for future implementations that involve concise sequential steps.


1D quasicrystal: points on a line nearest to points on a lattice

I have a simple lattice / line manipulation:               Manipulate[r = 10; b = {{0, r}, {r, 0}};     l1 = Flatten[Table[i b[[1]] + j b[[2]], {i, 0, r}, {j, 0, r}], 1]/r;     Clear[a, b]; b = a /. Solve[a + y == 90, a][[1]]; x = y Pi/180;     g = Graphics[Line[{{0, 0}, {If[y <= 45, r/Cos[x], r/Cos[b Pi/180]], 0}}]];     rot = l : Line[pts_] :> Rotate[l, x, {0, 0}];     Show[Graphics[Point[l1], Frame -> True, AspectRatio -> 1], g /. rot], {{y, 45}, 0, 90}]      and would like to add points (that move with the manipulation) on the line that are perpendicular to the nearest points of the lattice, as shown below: ![enter image description here](http://i.stack.imgur.com/79O89.png) It would be a bonus if the perpendicular joining lines appeared also. The only way I can think of pursuing this is to use something like `Nearest`, `FrobeniusSolve`, etc. (have been looking at the answers to this question with little success so far) to generate data for something along the lines of:               f = Graphics[Point[{{0, 0}, data, {If[y <= 45, r/Cos[x], 12], 0}}]];     rot1 = l : Point[pts_] :> Rotate[l, x, {0, 0}];     Show[Graphics[Point[l1], Frame -> True, AspectRatio -> 1], g /. rot, f /. rot1]      # Note: As noted by Vitaliy Kaurov below, the defining 'band' (dashed in the diagram) would not (necessarily) be symmetric about the main line. In this instance, the ratio of smaller to larger is the golden ratio. This is more obvious when looking at central red line in the above image - compare with: ![enter image description here](http://i.stack.imgur.com/NG1d7.png) I would ideally like this band width to be adjustable within the manipulation, but this is a minor concern. # Update A minor modification of george2079's code               a = N[1/2 (Sqrt[(2/(5 + Sqrt[5]))] + Sqrt[10/(5 + Sqrt[5])])];     b = N[Sqrt[2/(5 + Sqrt[5])]];     Manipulate[Module[{grid, f, lndat, near, lnpts, lines1, lines2}, band = 1;     grid = Flatten[Outer[List, Range[-4, 4], Range[-4, 4]], 1];     f[x_] := m x;     lines1 = Select[pointlinedis[{{{0, 0}, {4, f[4]}}, grid}],      Norm[Subtract @@ #] < a band &];     lines2 = Select[pointlinedis[{{{0, 0}, {4, f[4]}}, grid}],      Norm[Subtract @@ #] < b band &];     Show[Plot[f[x], {x, -4, 4}, PlotRange -> 4],      Plot[f[x] - b band/Cos[ArcTan[m]], {x, -4, 4}, PlotRange -> 4],      Plot[f[x] + a band/Cos[ArcTan[m]], {x, -4, 4}, PlotRange -> 4],      Graphics[{{Opacity[.5], PointSize[.015], Point[grid]},     {Orange, Thickness[.005], Line /@ lines1}, {Red, Opacity[.5],      PointSize[.03], Point[#[[1]] & /@ lines1]}, {PointSize[.015],      Blue, Point[#[[2]]] & /@ lines1}}], AspectRatio -> 1]], {{m, N[Pi/5]}, -10, 10}]      gives ![enter image description here](http://i.stack.imgur.com/TYEXg.gif) which is nearly what I was after, but I would really like to exclude the points outside the lower line. If I swap `lines1` for `lines2` in bottom 3 lines of code, they are excluded, but so are some of points in top band. I have tried playing around with various `If` combinations, but can't seem to select points in upper band separately to points in lower band. Also, point near $\{3,3\}$ shouldn't be included (though george2079 does note that this may happen in his answer).


Why is this list not a valid vector field dataset or a valid list of datasets?

a = 0.1     x = Pi/2     data = Table[With[{y = -1 + 0.5*i, z = -1 +0.5*j},        {{NIntegrate[-(z/(t^2 - 2 t x + x^2 + y^2 + z^2)^(3/2))          - (3 (y z Sin[t]) a)/(t^2 - 2 t x + x^2 + y^2 + z^2)^(         5/2) + (3 z (t^2 - 2 t x + x^2 - 4 y^2 + z^2) Sin[t]^2 a^2)/           (2 (t^2 - 2 t x + x^2 + y^2 + z^2)^(7/2)), {t, -∞, ∞},         Method -> {"GlobalAdaptive", "MaxErrorIncreases" -> 200,           Method -> "GaussKronrodRule"}, AccuracyGoal -> 20,         MaxRecursion -> 20],        NIntegrate[y/(t^2 - 2 t x + x^2 + y^2 + z^2)^(3/2)         + ((t Cos[t] - x Cos[t] - Sin[t])/(t^2 - 2 t x + x^2 + y^2 + z^2)^(3/2)           + (3 y^2 Sin[t])/(t^2 - 2 t x + x^2 + y^2 + z^2)^(5/2)) a +             ((3 y (t Cos[t] - x Cos[t] - Sin[t]) Sin[t])/(t^2 - 2 t x +               x^2 + y^2 + z^2)^(5/2) + (3 y (-t^2 + 2 t x - x^2 + 4 y^2 - z^2) Sin[t]^2)/         (2 (t^2 - 2 t x + x^2 + y^2 + z^2)^( 7/2))) a^2, {t, -∞, ∞},         Method -> {"GlobalAdaptive", "MaxErrorIncreases" -> 700,           Method -> "GaussKronrodRule"}, AccuracyGoal -> 20,         MaxRecursion -> 60] },        0.}], {i, 0, 4}, {j, 0, 4}];      a)               data5 = data /. {_Complex -> 0.}     data1 = Flatten[data /. {_Complex -> 0.}, 1]          By = data1[[All, 1, 1]]          Bz = data1[[All, 1, 2]]          B = Sqrt[By^2 + Bz^2]          data2 = Transpose[{By, Bz}]          data3 = Transpose[{data2, B}]          data4 = {data3}      /a)                ListStreamDensityPlot[data4, VectorScale -> Automatic,       Evaluated -> True, DataRange -> {{-1, 1}, {-1, 1}},       ColorFunction -> ColorData["Rainbow"]          ListStreamDensityPlot::vfldata: {{{1.00103,-0.998971},1.41421},     {{0.80244,-1.60145},1.79124},{{0.,-2.00492},2.00492},{{-0.80244,-1.60145},1.79124},      {{-1.00103,-0.998971},1.41421},<<15>>,{{1.00103,0.998971},1.41421},     {{0.80244,1.60145},1.79124},{{0.,2.00492},2.00492},{{-0.80244,1.60145},1.79124},     {{-1.00103,0.998971},1.41421}} is not a valid vector field dataset or a valid list of      datasets. >>      I plot with the function Edit: illustrating additional options but I didn't want to include the whole code here so the upper one is snipped. The post is already long enough but if you want I could add it. These additional errors appears when plotting with the whole function.               FindDivisions::fdargs: "The arguments in Developer`FindDivisions[{∞,-     ∞,0.5}, 10, 10] are not supported."     ∞::indet: "Indeterminate expression 0\ (-∞) encountered."     ∞::indet: "Indeterminate expression -∞+∞ encountered."       I don't understand where I get ∞. I put the complex element to 0. If you check the output there is no ∞ value. That could happen because of the error "is not a valid vector field dataset or a valid list of datasets." When I compare data5 and data4 I see no differences in format output. It works with data5 and not with data4. The code between a) was done that way so I could plot {{By,Bz}, Norm[By,Bz]}. I couldn't find a better way. Thanks in advance.


region plot in a 2-simplex

I want to plot a 2-dimensional region with constraint $x+y\le N$, i.e., I want to plot a sub-region inside a 2-simplex. As an example:               Module[{n = 300, p = 0.5},     RegionPlot[{y > (1/2)*(n - x) && y + x <= n && y > p/(1 - p)*x},      {x, 0, n}, {y, 0, n}, FrameLabel -> {"x", "y"},      PlotStyle -> {Yellow, Opacity[0.5]}]]      What should I do to transform the region to a 2-simplex? **Edit 1 & 2 & 3** The command above will give you the following plot: ![enter image description here](http://i.stack.imgur.com/LhfN1.png) which clearly satisfies the $x+y\le N$ constraint. So I want a coordinate transform that changes the shape of the yellow area into the shape of the red area in the plot below (it is from Matlab): ![enter image description here](http://i.stack.imgur.com/pMGxD.png)


Discrete 3D plots of median ratios of two 2D matrices of lists of values

Lets say I have 2 2D arrays where each cell contains a list of values: Example:               data_1[[1]][[1]] = {1,2,3}      data_1[[1]][[2]] = {1,2,3}      data_1[[2]][[1]] = {1,2,3}      data_1[[1]][[2]] = {1,2,3}           data_2[[1]][[1]] = {2,4,6}      data_2[[1]][[2]] = {3,6,9}      data_2[[2]][[1]] = {4,8,12}      data_2[[2]][[2]] = {5,10,15}       What's a neat way to make a discrete 3D plot of the ratio between medians of these data sets (assuming that the indices always mach, but can represent any value, not only consecutive natural numbers).For the following data I would expect a plot of:               x,y,z     1,1,2     1,2,3     2,1,4     2,2,5


Filling Fill incomplete in ListLinePlot

data = {{0., 0., 0}, {0.12, 0.04, 2}, {0.24, 0.08, 4}, {0.36, 0.11,          6}, {0.47, 0.15, 8}, {0.59, 0.19, 10}, {0.71, 0.23, 12}, {0.83,          0.26, 14}, {0.95, 0.3, 16}, {1.07, 0.34, 18}, {1.21, 0.38,          20}, {1.38, 0.41, 22}, {1.78, 0.45, 24}, {2.84, 0.49, 26}, {3.45,          0.52, 28}, {3.88, 0.56, 30}, {4.33, 0.6, 32}, {4.79, 0.64,          34}, {5.25, 0.64, 36}, {5.89, 0.3, 38}, {6.16, 0.68, 40}, {6.51,          0.84, 42}, {6.89, 0.98, 44}, {7.27, 1.14, 46}, {7.67, 1.39,          48}, {8.07, 1.95, 50}, {8.47, 5.3, 52}, {8.89, 5.82, 54}, {9.3,          6.14, 56}, {9.71, 6.48, 58}, {10.11, 6.9, 60}, {10.52, 7.56,          62}, {10.92, 8.18, 64}, {11.32, 8.55, 66}, {11.72, 8.86,          68}, {12.13, 9.16, 70}, {12.53, 9.46, 72}, {12.93, 9.77,          74}, {13.33, 10.07, 76}, {13.73, 10.38, 78}};          ListLinePlot[data[[;; , {#, 3}]] & /@ {1, 2}, Filling -> {1 -> {2}}, Frame -> 1]      My code gives this ![enter image description here](http://i.stack.imgur.com/K9cr7.png) but I want it look like this ![enter image description here](http://i.stack.imgur.com/sFHq3.png)


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

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.


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

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.


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

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)


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

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 ?


Numerical integration with purely numerical integrand

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...


JewishNewYear date limitation

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?


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

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)


Problems with NMinimize

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}}


Plot function on different intervals with different colors

![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 ;)


NDSolve: Reinitialize fails with If condition

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


NIntegrate and NumericQ

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?


How to find the zeros of a Complex trigonometric function

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?


Compare elements in a list

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_?


Boundary Value Problem- using NDSolve or another method

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.


FindRoot with units error: Message text not found

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.


Converting format of list

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?


Understanding distribution chart

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


Plot columns of table if some condition is fulfilled

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!


Zooming into Parametric Animation Plot that Uses InterpolatingFunctions

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)


Adjusting the legend colors to match that in MatrixPlot

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!


Dt acting on symbolic notational forms

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] *)`


What does LinearModelFit depend on except for its' arguments?

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?


Overloading conjugate operator for a particular function

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[_]]`.


Indirect transformation based on a list of data points

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`}};


How accurate is Collect?

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.


how can tangent half angle substitution be done in Mathematica?

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`?


Function giving negative value when it should be positive

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!


Collapsible Group of Control Objects

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?


LiftingWaveletTransform with irregular grids

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?


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

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`"} >


Draw network graph and get the coordinates of each node

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?


Solve equation with two different sets of replacement rules

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]


Diagonal Tick Marks

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?


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

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?


Solving parametric equations by eliminating the common variable

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`.


Generating list of functions from list of expressions

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?


Font Issues: "Like Resource 58" error

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!


Output to preserve dot product

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.


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

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.


ListDensityPlot performance when scaling axes

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.


Render dynamic Graphics objects static

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.


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

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}}}}


Can ParametricNDsolve be used for coupled PDEs with 5 parameters?

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!


Converting structured data to a dataset

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 ?


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

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).


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

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.


AndersonDarlingTest and DistributionFitTest Leaking Memory

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.