Converting ConditionalExpression to Piecewise

I have `Solve[]` return a list like `{{F->ConditionalExpression[EXPR1, 0<z<a1]},{F->ConditionalExpression[EXPR2, a1<z<a2]},...}` and so on -- `EXPR*` and `a1,a2,...` are somewhat complicated expressions, containing things like `Root[]`:               EQ = F^4 (138880 z + 318688 F z + 98415 F^10 z + 6561 F^9 (5 + 4 z) +          405 F^5 (625 + 1136 z) + 243 F^6 (-2500 + 5077 z)) ==          1024 z + 11008 F z + 40192 F^2 z + 33536 F^3 z + 46944 F^6 z +          709776 F^7 z + 368388 F^8 z + 4374 F^12 (50 + 43 z) +          4374 F^11 (-125 + 202 z);          ftz = Solve[EQ && 0 < F < 1 && 0 < z < 1, F];      e.g. the first conditional:               In[100]:= N[(F /. ftz[[1]])]          Out[100]= ConditionalExpression[      Root[-1024 z - 11008 z #1 - 40192 z #1^2 - 33536 z #1^3 +          138880 z #1^4 + 318688 z #1^5 - 46944 z #1^6 - 709776 z #1^7 -          368388 z #1^8 + (253125 + 460080 z) #1^9 + (-607500 +             1233711 z) #1^10 + (546750 - 883548 z) #1^11 + (-218700 -             188082 z) #1^12 + (32805 + 26244 z) #1^13 + 98415 z #1^14 &,        2], 0. < z < 0.674139]      I need to (numerically) integrate this function for given parameter values, which Mathematica refuses to do. However, if I convert the expression into a Piecewise function: for example as               ff = Piecewise[{{ftz[[1]][[1]][[2]][[1]], ftz[[1]][[1]][[2]][[2]]},         {ftz[[2]][[1]][[2]][[1]], ftz[[2]][[1]][[2]][[2]]},         {0, z == 0},         {1, z == 1}}];      it easily computes the integral. Unfortunately, the number of intervals and the breakpoints are parameter dependent, and this must be done automatically as the function is called inside another function. Does anyone have any suggestions on how to convert such a list of conditionals into a Piecewise function, or how to otherwise compute the integral? Thanks!


Error Interpretation in NIntegrate

I am using a recursion algorithm developed by Migdal for Lattice Field Theory, and I have the following code:               (** The dimension of the representation **)     dim[r_] := 2 r + 1      (**The trace of a product around the loop, also the sum of the eigenvalues **)     χ[r_] := Sin[dim[r] θ/2]/Sin[θ/2]      (** The main equation in the paper I went out to 12 terms in the above sum **)     migdal[a_] := Sum[        ((1/dim[r]) NIntegrate[(Sin[θ/2]^2)/(2 π) a χ[r], {θ, 0, 4 π}])^(λ^2)       * dim[r] χ[r], {r, 0, 3, 1/2}     ]^(λ^(d - 2))           (** The λ used as expansion parameter **)     λ = 2^(1/10)           d = 4                l6 = Table[Table[Simplify[      Re[NIntegrate[       Log[Nest[        migdal,         Exp[(9/1000) (χ[1/2] - dim[1/2]) - (3/100000) (χ[1] - dim[1])             + 0 (χ[3/2] - dim[3/2])],        i]] χ[j] Sin[θ/2]^2/(2 π), {θ, 0, 4 π}]]     ], {i,0, 20}] , {j, 1/2, 1, 1/2}]      and it says that               NIntegrate::ncvb: "NIntegrate failed to converge to prescribed accuracy      after 9 recursive bisections in θ near {θ} = {9.71911}. NIntegrate obtained     6.127043317150083`*^-15 and 1.1472584029987046`*^-16 for the integral and     error estimates."      I have tried to change the MinRecursion, on the first NIntegrate, but then the integral converges too slowly, and there are further errors. Mathematica makes a number of recommendations having to do with changing error estimates, however I don't understand what it is referring to. In my code $a$ is where my Boltzmann factor goes, more or less, as an initial input, followed by subsequent recursion of that factor. The factor itself depends the trace, $\chi$, and so depends on $\theta$. FYI the initial conditions that are variable in this are the 9/1000, 3/100 000, and 0. The first two numbers are initial points that are plotted against each other with the first number corresponding to the x-axis, and the second corresponding to the y-axis. I have been varying their range andwhere from the current numbers to (1.2, 0.1) respectively. If someone would be so kind as to help me with these error messages I would be grateful. Thanks,


CUDALink with Nvidia GTX770

We are running a _Windows 7_ machine with _Nvidia GTX 770_. According to this reference GPU Hardware: _CUDA_ for _Mathematica 9_ is not supported on that hardware. Is there any way to get it running?               CUDAQ[]      > >     False >                 CUDAInformation[]      > >     During evaluation of In[8]:= CUDAInformation::syslibfld: CUDA failed to > load system >     libraries.  Refer to CUDALink System Requirements for system > requirements. >> >                 CUDADriverVersion[]      > >     "320.57" >


Polar Plotting in Complex Plane

How would I plot the following functions in the polar complex plane? $$ \phi={-k\over 2\pi r}cos(\theta_0-\theta) $$ and $$ \psi={-k\over 2\pi r}sin(\theta_0-\theta) $$ Please provide the function calls if possible. I realize that I need to pick values for k and $\theta_0$. It would be even better if someone knew how to sketch the flow.


How to extract a specific element from EXIF photographic metadata?

It's now possible to import photographs into _Mathematica_ and import the EXIF data at the same time:               i = Import["ExampleData/coneflower.jpg", "ImageWithExif"]      ![coneflower](http://i.stack.imgur.com/wvzxz.png) You can now look at all the metadata:               Options[i, MetaInformation]      > {MetaInformation -> {"Exif" -> {"ImageDescription" -> " ", "Make" -> > "NIKON", "Model" -> "E950", "Orientation" -> 1, "XResolution" -> 300, > "YResolution" -> 300, "ResolutionUnit" -> 2, "Software" -> "Adobe Photoshop > CS3 Macintosh", "DateTime" -> "2008:08:19 11:29:05", etc... So how would I extract - say - the exposure time ("ExposureTime")? I was trying something like this:               "ExposureTime" /. Options[i, MetaInformation] ...      but I don't know enough about the structure of the stored metainformation. Can you do this without knowing that structure?


Export Grayscale Bitmap

I have a grayscale (one channel) image in Mathematica. How can I export it as a grayscale Bitmap? Every single option I tried so far does not have an influence on the Bitmap exported using `Export`. If I export the image as PNG, Mathematica exports the grayscale image as expected. **Simple Example** Let's create a simple grayscale image:               image = Image[RandomReal[{0, 1}, {100, 150}]];      Simple export via:               Export["test.bmp",image];      shows exactly the problem mentioned above. Additional options like setting `ColorSpace->"Grayscale"` does not seem to have any effect. Any kind of color- conversion before doing the export did not work either, which is not surprising to me because the image already clearly carries the information that it is a grayscale image and export via               Export["test.png",image];      does export a grayscale PNG. Verification can for example be done by simple reimporting the ColorSpace Element of the exported image:               Import["test.bmp","ColorSpace"];


Difficulty with computing a limit

I meet some difficulties when trying to compute this limit,               Limit[1/n*Integrate[1/(Cos[x]^2 + 4 Sin[2 x] + 4), {x, 0, Pi*n}],   n -> Infinity,Assumptions -> n \[Element] Integers]      The output is,               Limit::cas: Warning: Contradictory assumption(s) (n\[Element]Integers&&(Re[n]<=1/2||n\[NotElement]Reals))&&n>4096 encountered. >>      The limit is finite though.


ArrayPlot copied to PDF shows blurred mesh

Certain (but not all) images displayed in `ArrayPlot`, and then copied to PDF, show what appear to be fuzzy mesh lines in white areas. An example is shown below. I am aware of previous answers regarding viewing in Preview, but this happens when the copied image is viewed in Pages, TextEdit, or even Mathematica! It persists in these when the preview smoothing option is turned off, though the problem goes away in preview. Also, the PDF file is very large, takes long time to copy. Is it representing all the elements of the array as graphic rectangles? Here is a simple example:               ArrayPlot[1. - IdentityMatrix[4], ColorFunction -> GrayLevel,       ColorFunctionScaling -> False, Mesh -> None]      Copy the output as PDF, then paste back into the Mma notebook, and `Mesh` lines will be evident.


Is it possible to frame a group of cells?

Is it possible to put a frame around a group of cells (e.g. a numbered list)? My problem is, that if I select the cell group and then click frame on the writing assistant, then it puts a frame around each cell in stead of one frame around all the cells in the marked group. Merging the cells into one does not work either, as that removes the item numbers in lists.


Animated Wave Propagation using Fourier & InverseFourier

This is a continuation off of previous help on the first part of my project: fourier issue arising from input miscommunication Now I want to go one step further in the current code. Here's the code from earlier with some comments to explain the thought-process:               xdomain = Table[i, {i, -10, 10, .1}];     initialState= E^-2#^2 & /@ xdomain;          f1 = E^-I #^2*Δt & /@ xdomain;      (* For the first step, I want to multiply my initial function by a second function and then fourier transform it. So I'm breaking down both function into a table of points and then fourier-transforming the product of the multiplied-points, because (I think) this is the most efficient way of doing this numerically.*)               f2 = E^-I #^2*Δt & /@ xdomain;      (* The second step is the same principle. We then take this fourier'd result, multiply it by another function, and then Inverse-fourier transform back *)               finalstate=InverseFourier[Fourier[f1*initialState]*f2];       (* ^This line is doing the two steps mentioned in the above two comments. *) My result represents a wave that is propagated 1-unit-delta-t forward in time. To find out what this wave looks like 2-units in time, we need to take our "finalstate" function and use that instead of our intial state. (so to find something 10-units in time forward, I would have to run this 10 times, each time replacing the output with the input.) Eventually I'd want to have a series of plots that I would assemble to form a movie of the wave's behavior. This is what I have so far:               xdomain = Table[i, {i, -50, 50, .05}];     initialState = E^-#^2 & /@ xdomain;          cache = {initialState};     (*For 1\[Rule]10 *)     Δt = .001;          f1 = E^-I #^2*Δt & /@ xdomain;     f2 = E^-I #^2*Δt & /@ xdomain;          For[i = 0, i < 15, i++,      ftot = Abs@InverseFourier[Fourier[f1*initialState]*f2];      initialState = ftot;      cache = Join[cache, {ftot}];      ListLinePlot[        Partition[Riffle[xdomain, cache[[i + 1]]]/Norm[cache[[i + 1]]],          2]] // Print]      So there are two things that I'm looking for answers for:   1. If my method numerically fourier-transforming these functions by turning them into points and multiplying the points individually, makes sense and is the best way of handling it numerically in Mathematica.   2. How can I export these printed for-loop pictures into an animation. (I eventually will decrease the value of delta_t, and increase the amount of pictures taken, so I won't be able to export the animation by hand.)  Thanks again everyone for your help so far! Let me know what you think. P.S. In case anyone's interested, what I'm constructing is a program that numerically performs the Split-Operator method for solving the wave equation in an arbitrary potential (that commutes with p).


How to define Similarity Rules?

I have a question about _Mathematica_ 's `SimilarityRules` defining (for e.g. `SequenceAlignment` function). So help centre clearly stands for > `SimilarityRules -> {{a_, a_} -> 1, {a_, b_} -> -1}`, giving a score of `+1` > for any pair of identical elements, and a score of `-1` for any mismatch, > deletion or insertion. Ok, I get it, but what if I want to give different score for mismatch, and different for indeles? I tried:               SimilarityRules -> {{a_, a_} -> 3, {{a_, b_} && {{a_!=""} && {b_ != ""}}} -> -8}       and many other combination of `{}`, `&&` positions, but it doesn't seem to help. Any suggestions, is it just a typo I'm doing, or it's rather a silly idea to define it like this?


How to Dynamically Locate (get coordinates) of a point, inside a Manipulate?

I've been searching all around the "Documentation Center" and other forums and just can't get to solve this issue. I'd like to dynamically locate a point (get it's coordinates) inside a Manipulate. This point is in fact a function of another parameter (hence the Manipulate). Here's the setup. First I create the functions that will provide with the points coordinates :               T01[q1_] = {{Cos[q1 Degree], 0, Sin[q1 Degree], 0}, {0, 1, 0,      0}, {-Sin[q1 Degree], 0, Cos[q1 Degree], 0}, {0, 0, 0,      1}}; (*Matrice de passage de R0 à R1*)           T12[q2_, l1_] = {{Cos[q2 Degree], 0, Sin[q2 Degree], 0}, {0, 1, 0,          0}, {-Sin[q2 Degree], 0, Cos[q2 Degree], -l1}, {0, 0, 0,          1}}; (*Matrice de passage de R1 à R2*)          T02[q1_, q2_, l1_] =        T01[q1].T12[q2, l1]; (*Matrice de passage de R0 à R2*)          E2[l2_] = {0, 0, -l2, 1}; (*position de l'effecteur dans le repère R2*)          E0[q1_, q2_, l1_, l2_] =        T02[q1, q2, l1].E2[l2]; (*position de l'effecteur dans R0*)          O22 = {0, 0, 0, 1};(*position du centre articulaire O2 dans R2*)          O20[q1_, q2_, l1_] = T02[q1, q2, l1].O22;(*position de 02 dans R0*)          O11 = {0, 0, 0, 1};(*position de O1 dans R1*)          O10[q1_, q2_] = T01[q1].O11;(*position de O1 dans R0*)      I'm in fact interested in showing the $E_0$ coordinates dynamically if possible inside the manipulate window... So then I create the Manipulate environment which shows a double pendulum parameterized by the $q_1$ and $q_2$ variables :               Manipulate[      ListLinePlot[       {        {O10[q1, q2][[1]], O10[q1, q2][[3]]}, {O20[q1, q2, 400][[1]],          O20[q1, q2, 400][[3]]}, {E0[q1, q2, 400, 300][[1]],          E0[q1, q2, 400, 300][[3]]}        }, PlotRange -> {{-710, 710}, {-710, 710}},        AspectRatio -> Automatic, PlotMarkers -> Automatic, Ticks -> None       ], {{q1, 5, "\!\(\*SubscriptBox[\(q\), \(1\)]\)"}, -170,        170}, {{q2, 5, "\!\(\*SubscriptBox[\(q\), \(2\)]\)"}, -170, 170}      ]      I tried the Locator function without success, also I tried the Dynamic function but I just couldn't get to make it work for the $E_0$ variable... Does anybody has any idea that might help? Thanks in advance.


Gradient Filter Function

I am trying to understand EXACTLY what the GradientFilter function in Mathematica is doing. As far as I can tell, it appears to be doing a convolution of a first derivative of a Gaussian with the user supplied data using some kind of padding on the edges because, I can replicate the results of the GradientFilter almost exactly by doing this except for the behavior at the edges due to the padding. However, one of my colleagues (a MATLAB user by the way) disagrees and thinks it is doing more than just that. Also, is there any way to see the convolution kernel that the GradientFilter is using given a certain radius and standard deviation? The documentation is somewhat ambiguous. So, if anyone out there has any insight to this, I would really appreciate it.


The correct pattern for Cases

I have a problem that, admittedly, I have already solved using `Select` instead, but it is irking me that I cannot seem to construct the right pattern to solve it using `Cases`. I would like the output of               Cases[         {{{1, 2}, {3}, {4, 5}}, {{6}, {}}, {{}, {}}},         (* THE CORRECT PATTERN HERE *)     ]      to be               {{{1, 2}, {3}, {4, 5}}, {{6}, {}}}      In other words, I would like a pattern that picks up all the elements of the outer list that have at least one non-empty list as an element. Thanks in advance for your help.


How can I recreate Trott's Riemann Surface plot in Mathematica?

In reading Michael Trott's Visualization of Riemann Surfaces of Algebraic Functions, he has:               ParametricPlot3D[{r Cos[φ], r Sin[φ], Sqrt[r] Sin[φ/2],        SurfaceColor[Hue[φ/(4 π)]]}, {r, 0, 1}, {φ, 0, 4 π},       PlotPoints -> {20, 60}, Boxed -> False, Axes -> False]      How would you do this coloring now in _Mathematica 9_ ?


Defining a formal Primitive Recursion

I'm searching for a way to define the function this wikipedia article call **Primitive Recursion**. It should have two functions as argument and it should return a function. I need this as helping in studying mathematical recursion theory. I need another help with a similar problem; this time i want a "primitive minimization", that is a function called primMin a try i made inspired by @Rojo is.               primMin[f_] := Module[{h},         h[x___Integer] := Module[{}, For[i = 0, f[x, i] != 0, i++,]; i];         h]      this take f a two argument function and return a one argument function that given x as an argument and search for the first second argument so that f[x,#] == 0. this code work but i couldn't find a way to substitute the For with a Map or something similar. I need that given x there is no y so that f[x,y] == 0 then program will crash or continue to run forever. thank


how to get a linearized curve in some intervals

in below picture I draw a graph base on weight of a controller system against cost function. I want to linearise and divide this curve to for example 5 five intervals. is there any function in mathematica to give me such a thing. I thinking first maybe I can get gradient of function and choose the nearest amount together. ![enter image description here](http://i.stack.imgur.com/uW5VP.jpg)


Counting instances where the two identical characters are at the same positions in two strings

Let $s_a$ and $s_b$ be two strings over a $q$-ary alphabet. For each character $(c_1,...c_q)$ in the alphabet, I'd like to return a pair of values $(r,k)$ where $r$ represents the count for the character in $s_a$ and $k$ represents the number of instances where this character is in the same position in $s_a$ and $s_b$. For example, if we have two binary strings:               sa="00011001";     sb="11001001";      For the character $0$, we'd return the value $(r_0,k_0) = (5,3)$. For the character $1$, we'd return $(r_1,k_1) = (3,2)$. What is the fastest way to carry out these string operations? Should we be using arrays instead of strings?


Mathematica Plotting of complex and convolution integrals

I was trying to plot the following:               j = 10;      a = 0; b = 0; s = 0;           B[n_] = Integrate[2*Sin[n*Pi*x]*x, {x, 0, 1}];     u[x_, t_] = Sum[B[n]*Sin[n*Pi*x]*Exp[-(n*Pi)^2*t], {n, 1, j}];          K[x_, t_] = (1/(2*Pi))*        Integrate[         Exp[I*x*psi]*(Exp[-I*b*psi]*Exp[-I*a*psi^2]*             Exp[-I*t*psi^2])/((1 + psi^2)^s), {psi, -10, 10}];          S = (Total[u[x, t]]/Length[u[x, t]]);          T[x_, t_] = Integrate[K[x - y, t]*y*S, {y, -10, 10}]          Plot3D[T[x, t], {x, 0, 1}, {t, 0.01, 1}, AxesLabel -> {"x", "t", "y"}, Boxed -> False, Mesh -> False]      The problem is that this is a really complicated solution and I would like to get the results numerically, but it ran for a long time and nothing plotted -- just empty axis. In my definition of all the variables -- I have also used the := statement, but it didn't help! If anyone can please help me with this then I'll greatly appreciate it. Thanks!


Formatting data tables with Grid + Dividers vs. SplitBy --> GridBy?

A quick method to format human-readable data tables with headers, is to use `Grid`, eg:               Grid@ColSel[        PACE["PRE"], {"VISIT_ID", "PHYSICIAN_ID", "PT_DROPOUT_Q",          "DUAL_MONITOR_Q", "VOICE_RECOG_Q", "COMPANION_Q",          "CAM_TRUNCATED_Q"}] /. {0 -> ""}       Which yields this table of which only the top portion is shown (note the horizontal spacing induced by the header) ![enter image description here](http://i.stack.imgur.com/kxudE.jpg) It is desirable to segment the data by PHYSICIAN_ID, which can have _variable_ number of visits. Is there a convenient expression to map such a rule to positional information required by `Grid` and `Dividers`? A more verbose alternative is to space by first applying SplitBy #[2] (2nd column = PHYSICIAN_ID), then Grid, and finally Column:               Column[#, Automatic, 2] & @(Grid /@         SplitBy[ColSel[           PACE["PRE"], {"VISIT_ID", "PHYSICIAN_ID", "PT_DROPOUT_Q",             "DUAL_MONITOR_Q", "VOICE_RECOG_Q", "COMPANION_Q",             "CAM_TRUNCATED_Q"}] /. {0 -> ""},         #[[2]] &])      Which yields (again only showing data for the first 3 physicians): ![enter image description here](http://i.stack.imgur.com/zoE39.jpg) Vertical spacing is visually less satisfactory than horizontal grid lines (which visually guide the eye). Also note the header has been split from the data so the vertical alignment is lost. So overall Grid and Dividers is preferable; What are the issues in developing a "GridBy" functionality analogous to SplitBy?


How to install packages?

This is always a problem when I distribute my packages to colleagues working on different platforms. I have my packages installed into a private directory and I autoload some of them when _Mathematica_ starts, but since everyone has a different folder hierarchy and different customs on where to put files/what to autoload, this is always a bottleneck. Should non-power-users simply use the menu option: `Install...`? Can a foolproof script be defined, that - no matter what platform is in use - installs these packages in a way that both the user and both _Mathematica_ (and the code I wrote and distributed) can find it? That is, packages are not added to the system-default package directory. Or would it be better to put packages into the default directory of _Mathematica_ (e.g. `C:\Applications\Mathematica 8.0.1\AddOns`)? If yes, then which directory should hold them: `LegacyPackages`, `ExtraPackages` or `Packages`? **Further questions:** What if the package that I send consists of multiple packages, in a delicate directory structure? Can the menuitem `Install...` deal with that?


How to use initial fixed timestep, then decrease it according to dependent variable, while spatial stepsize is fixed

I am trying to solve an advection equation. I want to force constant spatial step size (x dimension) with the “MethodOfLines” option, whereas I want to use initially fixed time step size 0.01 then decrease the time step size to be (0.001, 0.0001) when the minimum value of u(t,x) is less than (-6, -7). I tried the following code, and adopt ImplicitRungeKutta method to integrate with respect to time. I even can not set time step size in the ImplicitRungeKutta method. I try this               WhenEvent[{u[t, x]<=-6}, stepsize -> 0.001];     WhenEvent[{u[t, x]<=-7}, stepsize -> 0.0001];      But how can I combine this event trigger in my time integration method? Anyone can help me?               mdfun = First[u /. NDSolve[{D[u[t, x], t] ==        0.5 D[u[t, x], x, x] + u[t, x] D[u[t, x], x],       u[t, -Pi] == u[t, Pi] == 0, u[0, x] == Sin[x]},      u, {t, 0, 10}, {x, -Pi, Pi},      Method -> {"MethodOfLines",        Method -> {"ImplicitRungeKutta", DifferenceOrder -> 2,          "ImplicitSolver" -> {"Newton", "IterationSafetyFactor" -> 1}},        "SpatialDiscretization" -> {"TensorProductGrid",          "MinPoints" -> 100, "MaxPoints" -> 100,          "DifferenceOrder" -> 2}}]]      Then Plot it               Plot3D[Evaluate[mdfun[t, x]], {t, 0, 10}, {x, -Pi, Pi}, PlotPoints -> 100, PlotRange -> All]


Why is JLink loaded every time I start Mathematica?

When I start a Mathematica 8 session (either command line or with the notebook front end), I notice that there are several packages that have already been loaded for me (using `SystemInformation[]`):               PackagesLoaded -> {JLink`, PacletManager`, WebServices`, System`, Global`}      I understand System` and Global` and even WebServices`, but why JLink`? Does Mathematica have a primary dependency on Java? What does it use it for?


Controlling plots with sliders without using Manipulate

Why are the sliders in the following code not affecting the plot? (Without using `Manipulate`)               Module[{t, o, z}, f[t]];     {Slider[ Dynamic[o], {1, 5, 0.1}], Dynamic[o]}     {Slider[ Dynamic[z], {0.1, 1.4, 0.1}], Dynamic[z]}     {Slider[ Dynamic[Ts], {5, 20, 1}], Dynamic[Ts]}     tf[o_, z_] := TransferFunctionModel[ω^2/(s^2 + 2 z o s + o^2), s];     f[t] = OutputResponse[tf[o, z], UnitStep[t], t];     Plot[f[t], {t, 0, T}, PlotRange -> {{0, T}, {0, 2}}]


downloading home version for mac

This is I think a trivial question but I did check against those already asked. I am downloading Mathematica (home use). Very slow connection. So my Mac displayed the progress bar but this morning the bar is replaced in the downloads window with "mounting failed." When I double-click this icon it informs me the program can't be accessed because it is still downloading. When I right-clicked "get info" on the dmg file it went from 2.07G to 4 KB over the course of a few minutes. a. Has the download stopped? Been reversed? b. Is it possible to get the progress bar back to see what's happening? Thanks for any advice.


Why does SocialMediaData return such a small FollowerNetwork?

I have hooked up my Twitter account to Mathematica and I have 1468 followers               myfollowers = Length[SocialMediaData["Twitter", "Followers"]]          1468      I wondered what my follower network would look like but the returned graph was far too simple looking:               a = SocialMediaData["Twitter", "FollowerNetwork"]      ![enter image description here](http://i.stack.imgur.com/R5cpx.png) The graph only has 32 vertices:               VertexCount[a]      Looking at the names of the Twitter users it has included, it seems that it has only considered the most recent people who have followed me. So, how do I get Mathematica to consider all of my followers?


Interpolation Problem

I have the following list:               AA1 = {{55.3346, 694.253}, {55.3373, 691.275}, {55.34,         688.323}, {55.3426, 685.396}, {55.3453, 682.494}, {55.348,         679.617}, {55.3506, 676.765}, {55.3533, 673.936}, {55.356,         671.131}, {55.3565, 668.277}, {55.3565, 665.428}, {55.3565,         662.604}, {55.3565, 659.803}}      By interpolating the data, I get an error:               AA2 = Interpolation[AA1, InterpolationOrder -> 1]      "Interpolation::inddp: The point 55.3565` in dimension 1 is duplicated. >>" Therefore, I want to delete the duplicated terms:               DeleteDuplicates[AA1[[All, 1]]]      But how do I merge these values with the **correct** values of the second part in list AA1 (694.253 until 659.803?


Dynamic with RegionNearest keeps one CPU core at 100% - Is this a bug?

Normally, when you use `Dynamic` with a CPU-intensive expression, the expression only gets evaluated when a symbol in the expression changes. This doesn't seem to work with `RegionNearest`:               d = RegionIntersection[Ellipsoid[{2., 2.}, {5, 3}],         Ellipsoid[{5., 3.}, {4, 3}]];         nf = RegionNearest[d];     pt = {0, 0};      `Timing[nf[pt]]` tells me that this takes .6s on my PC (side question: why does this take so long? I thought this would be equivalent to finding the nearest point to each of the two ellipsoids, then checking if that point is contained in the other.) Now when I write:               Dynamic[nf[pt]]      The Mathematica kernel goes to 25% CPU utilization (one core) and stays there, even when nothing changes. Is this a bug? **ADD:** as @Nasser remarked in a comment, `Dynamic[nf[pt]]` doesn't make much sense on it's own. My actual code was:               LocatorPane[Dynamic[pt],      Show[       Graphics[Dynamic[Line[{pt, nf[pt]}]]],       RegionPlot[d]]]      But `Dynamic[nf[pt]]` is the simplest way to reproduce the problem.


Modifying imported 3D file

Since I am visualizing my work using Mathematica, I import some 3D models of molecules to my notebook. So, the question is, is there any way to modify somehow that imported models inside Mathematica to, for example, label bonds' length? Currently I use .mol2 format, but maybe some others formats provide that ability? Or can Mathematica process that models to `Graphics3D`? Thanks.


How to integrate a function which is only known at discrete points

I have an integration to do. I want to integrate. $\int_0^\infty sin^2(2\pi t)f(t)dt$ where $f(t)$ takes values from an array in the form $\\{t,f(t)\\}$ The time steps in the array is 1.1s. Can you please suggest a method to do this? I tried using the Trapezoidal method for numerical integration but gave a bad approximation. Is there an easy method with inbuilt function or another method?


How can I turn off generation of Dynamic elements by Histogram?

By default `Histogram` generates `Graphics` expression with embedded `Dynamic` constructs as can be seen by looking on its `InputForm`. Is it possible to switch off generation of any `Dynamic` constructs and get non-interactive `Graphics` from `Histogram`? P.S. There are two reasons to turn off interactivity: 1) Interactivity is not needed when preparing graphics for `Export`. 2) Unnecessary `Dynamic` elements complicate generated `Graphics` expression and make difficult to modify it.


Multidimensional array reduction through summation over one of its dimensions

## 1\. Introduction I am using an array of dimension 3 (might become more) to store some values. I would like to implement a function that takes as argument the array and a couple of numbers smaller than the array dimension and returns a standard matrix (dim=2) which is obtained by reduction or "projection" (I don't really know how to call it) of the array along all the "other" dimensions. First a quick example with an array of dimension/depth 3               data=Table[10 (i - 1) + 3 (j - 1) + k, {i, 2}, {j, 3}, {k, 4}]     --> data = {{{1, 2, 3, 4}, {4, 5, 6, 7}, {7, 8, 9, 10}},                {{11, 12, 13, 14}, {14, 15, 16, 17}, {17, 18, 19, 20}}}      My desired function would do, for example, the following               Myfunction[data,{1,2}] = {{10,22,34},{50,62,74}}      After this brief introduction, let me explain where I've arrived. First let's generalize a little bit, as it is my goal, eventually. ## 2\. Definitions Let $M \in \mathbb{R}^{\Pi d_i}$ be an array of dimension $N \in \mathbb{N}$. Let $d_i \in \mathbb{N}, \quad i=1,\dots,N\quad$ be the sublengths of each of the dimensions. What I will call in the following the **projection** of the array along the dimension $q$ is the following surjective function : $$ \textrm{For } q\leq N \in \mathbb{N}_0,\quad P(M,q) : \mathbb{R}^{\Pi d_i} \rightarrow\mathbb{R}^{\frac{\Pi d_i}{d_q}} : M(n_1,\dots,n_N) \mapsto \sum_{j=1}^{n_q}M(n_1,\dots,n_{q-1},j,n_{q+1},\dots,n_N) $$ ## 3\. Goal The goal is to write a function that takes any multidimensional array as well as a list of all the dimensions that will be "kept" in the final array. For the sake of any representation, the obtained array should be of dimension $\leq$ 2 but I would like to stay as general as I (we) could. The dimensions ordering should simply be the one used to implement the array, and the code should be consistent in order to keep the dimensions in the same order at any time. ## 4\. Implementation               ProjectedColumns[len_,cols_]:= Complement[Range[len],cols]      ProjectedColumns is a function that returns a list of the dimensions to project, where `cols` is the list of dimensions to be kept and len is the dimension of the array.               CompoundProjection[data_, cols_] :=     Module[{len, vect},         len = Depth[data] - 1;         vect = ProjectedColumns[len, cols];         Do[             SingleProjection[data, vect[[i]]],             {i, Length[vect]}         ]     ]      CompoundProjection is a function that will project all the dimensions sequentially in order to arrive to the final result (The projection is commutative).               SingleProjection[data_, dimnumber_] := ???      Now what I need and I don't manage to get is the function that will actually perfom a one-dimensional projection. In my mind, I would need to have a number of `Do` loops which equals the dimension of the array. In that case, I simply parse through the array and do the summation over the one I'm interested in. Is it possible to set up such a structure with all the commands that Mathematica offers and that I probably don't know ? ## 5\. In summary   1. Has anyone followed this nonsense ?   2. Is there a Mathematica command that makes what I want directly ? (If Yes then No to the previous questions, then I'm happy)   1. Is there a way to improve the correctness or elegance of what I did ?   2. Is there a way to intricate a dynamic number of Do loops ?   3. Or, in general, is there another way to achieve the goal described in 3.


Obtain input expression from history without evaluating

I typed and evaluated an expression, but deleted it from the notebook. For instance, suppose it was               In[1]:= Round@SessionTime[]     Out[1]= 2      I now want to retrieve the input so that I can edit it again. I know Mathematica keeps the history of evaluated expressions in `In`. But if I try to access it directly `In[123]`, rather than giving the unevaluated input expression, it evaluates it again:               In[2]:= In[1]     Out[2]= 10      If I use `Hold` to suppress evaluation, then `In[...]` doesn't get evaluated, so I don't see the input:               In[3]:= Hold[In[1]]     Out[3]= Hold[In[1]]      How can I retrieve the input expression in an editable form, without evaluating it?


E-mail and password

I've just learned Mathematica can send e-mails using external servers: this is great... ! Now, using this link, I've set this up using my Gmail account. But is it possible to incorporate somewhere my Gmail password, so as not to have to add it every time in the               SendMail[..., "Password"-> ... ]      command? Thanks all for your help!


A one-liner to place some number of Graphics3D polytopes on a plane and to randomly assign colorations

I'm looking for a nice one- or two-liner to randomly place some number, $N$, of `Graphics3D` polytopes on a plane with dimensions $X \times Y$, and to specify that $k \leq N$ of them should be one color (e.g. `Red`) and the remaining $N-k$ another color (e.g. `Blue`). If possible, I would also like the option to randomly reassign colors an arbitrary number of times (perhaps by clicking a mouse) without changing the coordinates of the polytopes. Is this possible? We can get started by placing a single red colored Dodecahedron at the coordinate $(0,0,0)$ with the following line of code:               Graphics3D[{Red, Scale[Translate[PolyhedronData["Dodecahedron", "Faces"], {0, 0, 0}], 3]},               Boxed -> False, Background -> Gray]      Perhaps we would want to use `Map` here?


How does the built-in debugger decide what to highlight?

How does the built-in debugger decide which definition to highlight in the notebook when Break on messages" is enabled? Here's an example to illustrate what I mean. First, enable the debugger (Evaluation -> Debugger), then define a function that issues a message:               f::boo:="Boo!!!";     f[]:=Module[{a,b,c,d},       a=1;       b=a;       Message[f::boo];       c=b;       d=c;       a+b+c+d     ]      When running `f[]`, evaluation will pause on the message and the point where the break occurred will be highlighted: ![](http://i.stack.imgur.com/Wq2L0.png) Now let's re-assign its own DownValues to `f`, and re-run it. Now this second definition will be highlighted, but not the original one. ![](http://i.stack.imgur.com/55y9R.png) **The question:** How does the debugger know what to highlight and can we influence this somehow? I would like the definition printed by this spelunking tool to be highlighted, if possible.


How to find first list element that differs from average of N previous elements by more than a given amount?

Given a list of real numbers, I need to write a function that returns the value of the first element in the list that differs from the mean of the previous $N$ elements by greater than $P$ standard deviations of those same elements. (I use mean and standard deviation as sample functions, I may decide to use something else.) Clearly, I can write a loop to do this, but I'd like to use functional programming techniques to do this, and continue to learn better Mathematica programming style. `Select[ ]` looked promising, but I see no way to involve the previous list elements in the selection criterion. Thanks in advance for your help! Tom


Summation matrix

I have problem with summation when it is in matrices. I want to make mathematica compute this: ![enter image description here](http://i.stack.imgur.com/MAYyb.png) Large X I have added dataset for as well as e. Would anyone be able to show me how to compute this in mathematica. Due to comments Ill explain a bit more, X' is Transpose[X] so yes it would be a 2 by 2 matrix.               X= {{20.08, 1}, {19.78, 1}, {19.86, 1}, {19.4, 1}, {19.66, 1}, {19.32,        1}, {18.99, 1}, {19.29, 1}, {19.43, 1}, {19.52, 1}, {20.07,        1}, {20.13, 1}, {20.02, 1}, {19.9, 1}, {20.11, 1}, {20.44,        1}, {20.37, 1}, {20.31, 1}, {19.7, 1}, {20.12, 1}, {19.63,        1}, {19.76, 1}, {19.34, 1}, {19.66, 1}, {19.85, 1}, {20.32,        1}, {20.5, 1}, {20.9, 1}, {21.21, 1}, {21.15, 1}, {21.18,        1}, {21.02, 1}, {21.29, 1}, {20.92, 1}, {20.83, 1}, {21.22,        1}, {20.73, 1}, {20.76, 1}, {21.16, 1}, {21.31, 1}, {21.94,        1}, {22.7, 1}, {22.95, 1}, {22.8, 1}, {22.7, 1}, {22.9, 1}, {22.6,        1}, {22.4, 1}, {22.34, 1}, {22.43, 1}, {22.07, 1}, {22.01,        1}, {22.17, 1}, {22.1, 1}, {22.86, 1}, {23.26, 1}, {23.38,        1}, {23.59, 1}, {23.59, 1}, {23.53, 1}, {23.5, 1}, {23.78,        1}, {23.38, 1}, {23.52, 1}, {23.3, 1}, {23.48, 1}, {23.83,        1}, {24.2, 1}, {24.49, 1}, {24.69, 1}, {23.98, 1}, {23.79,        1}, {23.7, 1}, {23.26, 1}, {23.47, 1}, {23.95, 1}, {24.38,        1}, {24.75, 1}, {25.2, 1}, {24.68, 1}, {24.43, 1}, {24.73,        1}, {24.3, 1}, {24.97, 1}, {25.07, 1}, {25.17, 1}, {26.07,        1}, {26.41, 1}, {26.24, 1}, {26.83, 1}, {26.39, 1}, {26.64,        1}, {27.34, 1}, {26.58, 1}, {26.52, 1}, {26.58, 1}, {27.,        1}, {26.54, 1}, {26.02, 1}, {26.33, 1}, {26.07, 1}, {25.81,        1}, {26.33, 1}, {26.3, 1}, {26.39, 1}, {26.26, 1}, {25.75,        1}, {26.21, 1}, {27.04, 1}, {26.74, 1}, {26.4, 1}, {25.89,        1}, {26.37, 1}, {26.28, 1}, {26.54, 1}, {26.66, 1}, {26.24,        1}, {25.35, 1}, {25.19, 1}, {24.07, 1}, {24.96, 1}, {25.29,        1}, {25.47, 1}, {25.13, 1}, {25.24, 1}, {24.99, 1}, {25.59,        1}, {25.68, 1}, {25.53, 1}, {26.68, 1}, {26.56, 1}, {27.04,        1}, {27.23, 1}, {27.34, 1}, {26.88, 1}, {29.66, 1}, {29.66,        1}, {29.11, 1}, {27.86, 1}, {27.36, 1}, {27.84, 1}, {28.27,        1}, {28.11, 1}, {27.93, 1}, {28.05, 1}, {28.09, 1}, {27.96,        1}, {27.65, 1}, {27.67, 1}, {27.32, 1}, {27.39, 1}, {27.48,        1}, {27.68, 1}, {28.35, 1}, {28.34, 1}, {28.05, 1}, {27.14,        1}, {27.32, 1}, {26.91, 1}, {27.12, 1}, {27.06, 1}, {27.9,        1}, {27.99, 1}, {27.7, 1}, {27., 1}, {27.11, 1}, {27.3, 1}, {27.12,        1}, {27.78, 1}, {28.07, 1}, {28.23, 1}, {28.17, 1}, {29.24,        1}, {29.48, 1}, {29.19, 1}, {29.65, 1}, {29.26, 1}, {29.62,        1}, {30., 1}, {30.44, 1}, {31.03, 1}, {30.93, 1}, {30.26,        1}, {31.27, 1}, {31.34, 1}, {32.75, 1}, {33.55, 1}, {33.17,        1}, {34.31, 1}, {34.14, 1}, {33.88, 1}, {34.89, 1}, {34.14,        1}, {32.93, 1}, {33.01, 1}, {33.87, 1}, {34.15, 1}, {34.,        1}, {33.38, 1}, {33.09, 1}, {32.74, 1}, {33.43, 1}, {34.06,        1}, {33.94, 1}, {33.1, 1}, {33.08, 1}, {32.25, 1}, {32.35,        1}, {33.17, 1}, {32.57, 1}, {32.94, 1}, {33.18, 1}, {33.19,        1}, {32.97, 1}, {32.88, 1}, {32.11, 1}, {33.12, 1}, {33.82,        1}, {34.07, 1}, {35.1, 1}, {35.69, 1}, {35.47, 1}, {34.98,        1}, {34.63, 1}, {35.62, 1}, {36.3, 1}, {36.49, 1}, {36.29,        1}, {36.64, 1}, {36.96, 1}, {36.98, 1}, {37.01, 1}, {36.56,        1}, {38.13, 1}, {38.87, 1}, {38.86, 1}, {38.87, 1}, {40.22,        1}, {39.16, 1}, {39.35, 1}, {39.73, 1}, {39.73, 1}, {39.51,        1}, {40.04, 1}, {40.2, 1}, {40.12, 1}, {40.77, 1}, {40.85,        1}, {40.65, 1}}                        e={-39.5086, -34.3476, -21.3119, -17.2624, -22.8212, -12.6281, \     -4.05305, -10.284, -29.2365, -28.9788, -47.4106, -52.2288, -57.3004, \     -57.044, -21.7327, -14.2378, -13.6716, -15.6634, -3.07337, -9.56075, \     0.0428573, 17.8984, 7.95581, 9.61876, 11.0461, 7.3986, 15.974, \     6.7027, 0.0836829, 3.19188, 7.67778, 15.2763, 24.9694, 16.4266, \     20.9189, 18.9357, 17.7393, 16.6252, 19.9538, 19.0034, 14.0373, \     17.3368, 30.486, 25.6365, 28.4368, 24.1961, 32.2371, 28.1878, 26.836, \     21.6437, 20.0929, 14.5311, 15.5325, 20.0288, 4.56828, -2.70303, \     -5.26942, -5.80811, -15.5681, -23.0899, -15.6158, -8.19073, -8.70942, \     -22.0519, -30.5952, -41.6398, -44.3709, -37.6881, -42.0611, -45.5617, \     -42.4614, -28.0188, -37.4065, -47.103, -16.4617, -23.8073, -22.8127, \     -23.1099, -34.5714, -34.0337, -12.4429, -11.6738, -9.01844, -10.4266, \     4.10304, 18.3527, -0.190233, 10.8367, 11.3732, 10.7993, 15.0527, \     20.6719, 38.3996, 38.3901, 44.6483, 43.0501, 34.8527, 24.5722, \     26.1599, 11.7909, 23.8498, 14.9986, 9.23092, 10.165, 5.15272, \     -1.32286, 7.33681, 5.00731, 6.98059, 22.2116, 17.1747, 17.4044, \     14.8388, 14.3011, 21.4022, 33.8758, 40.5732, 38.6981, 37.4166, \     43.9763, 26.3214, 28.5563, 29.1317, 37.8048, 43.5765, 41.9573, \     36.5953, 42.233, 56.2035, 38.1798, 40.8262, 47.4906, 47.248, 47.1996, \     49.3891, 4.39601, -3.47399, -8.86219, 24.9919, 25.9935, 17.508, \     -4.48744, -4.30891, -4.54432, 2.20928, -1.59285, 16.9316, 24.1806, \     22.2945, 19.3957, 12.3694, 12.9571, 7.54649, -7.9417, -12.0437, \     -18.9007, -14.6697, -20.2643, -5.04498, -8.59367, -3.73548, -12.6302, \     -17.5525, -16.7896, -21.9673, -25.3056, -21.4283, -27.1137, -24.0638, \     -17.3968, -11.9953, -11.0271, -19.4666, -22.6394, -10.5365, -20.936, \     -18.7627, -25.7619, -33.4171, -23.1605, -37.4145, -31.1141, -37.136, \     -52.7573, -63.4735, -84.8161, -99.2387, -93.7135, -100.639, -96.9627, \     -104.754, -124.455, -119.213, -112.161, -111.235, -112.446, -113.121, \     -106.63, -90.9322, -70.3292, -74.0381, 37.6777, 19.6116, 25.208, \     62.8927, 57.3488, 60.1155, 58.3352, 66.6165, 70.2785, 64.5913, \     57.2585, 56.1704, 55.0572, 57.7095, 55.078, 47.1967, 30.6944, \     27.9336, 32.3462, 25.7823, 27.589, 33.3226, 32.5037, 13.9685, \     14.9823, 9.79964, 27.0003, 33.9492, 33.5921, 29.756, 24.1719, \     30.0634, 10.1723, -2.36215, 10.3259, 18.4378, 3.62343, 13.0049, \     2.67227, -12.503, -0.312969, 0.043751, 6.55802, 5.49949, 21.1638, \     25.3716, 20.8474, 29.628}      I have added the explanation from the book: ![enter image description here](http://i.stack.imgur.com/fqWmv.jpg)


Proper way to add vertices to an adjacency matrix

I'm looking for a robust way to add vertices to a graph by modifying its `AdjacencyMatrix`. Here's what I have so far:               addNode[matrix_,in_,out_]:=Module[{mod},         mod=ArrayPad[matrix,1];         mod[[1,2]]=1;         mod[[2,1]]=1;         mod[[Length@mod,-out]]=1;         mod[[-out,Length@mod]]=1;         mod     ]      This will add a vertex connected to `vertex 1` and another vertex connected to `vertex out`. Notice that I only add 1x1 0's to my matrix. This is because at the moment I only need to add 2 vertices to my graphs. * * * **Examples:** ![Mathematica graphics](http://i.stack.imgur.com/BdGfp.png) ![Mathematica graphics](http://i.stack.imgur.com/BtQcJ.png) * * * I've tried implementing a similar function that accepts the `in` argument, but I couldn't get it to work properly. It seems as if I have to program special cases for it to work. Is there a better way to do this?


How do I get java to recognize import com.wolfram.jlink

I'm trying to write a java program that uses mathematica code for processing and graphs while using java for the front end. From what I've been able to glean from the j/link tutorials on the wolfram site I will need to import com.wolfram.jlink in my java program like so:               import com.wolfram.jlink.*;      I can't seem to get it to work. When I try to compile my compiler says that the com.wolfram package does not exist. I'm guessing that I need to download and install the com.wolfram package somewhere but I don't know where to acquire it and google has been less than helpful. In case it's helpful I'm running JRE 1.6 on a machine running windows 7.


Evaluation inside Compile

here's a simple question: I have a function:               Compile[{T, μ, dq, ω, m},       Module[{s = 0.0 + 0.0 I, mu = -10*T},        Do[s = s + 0.1*T*(expr), {mu, -10.0 T, 10.0 T, 0.1 T}]; s], CompilationTarget -> "C"]      where `expr` is some long expression assigned before. I cannot make this work other that manually copy-pasting an explicit long expression for expr. I tried `Evaluate` and some combinations of `ReleaseHold`, but it did not work for me. Any ideas?


How to speed up calculations with large number of replacement rules?

In my program I have an expression which looks like:               AnalyticalExpression = 2^(-1-n-np)R^(-2+n+np)(8np1f[-2+n+np,-1+p1+p1p,1+p2+p2p,1+q1+q1p,3+q2+q2p]-8np1f[-2+n+np,-1+p1+p1p,3+p2p2p,1+q1+q1p,1+q2+q2p]-4np1f[-2+n+np,p1+p1p,p2+p2p,q1+q1p,4+q2+q2p]+...)      I gave here a short example; full expression is few pages long. From my point of view, this expression serves as a function of the integer variables n,np,p1,p1p,q1,q1p,... and two real variables R,x. My program evaluates the above expression by using a replacement rule, for instance:               tmp = AnalyticalExpression /. {n->2,np->3,p1->0,p2->4,...}      The problem is that the program has to evaluate this expression hundreds of thousands times with different values of these integer variables. This makes the whole program painfully slow. Is there a tricky way to perform this substitution efficiently? Tabulation of AnalyticalExpression for every combination of the integer variables seems quite weird to me... Thanks in advance for the answers and suggestions. Michal


Plotting the results of iterating a function

This is what I am stuck on               f[a_][x_] := x^2 + a;     w[a_] := Take[NestList[f[-1.8], 0, 1000], 100]      Now I want to evaluate this for different values of the constant $a$ from -1.8, to 0.3, store the results in a table, suppress the results because they will be very long, and then make a plot of $a$ versus $x$ using `ListPlot`. How can I evaluate for different values of $a$ and then plot? I have tried the `Do` function but can't get it to work.


Inlining calculations in a notebook

## Context In $\LaTeX$, I can write something like:                 Thus, we have $x = \sqrt{2}$, ...          the $ ... $, as opposed to $$ ... $$, inline the LaTeX symbols.      Now, with _Mathematica_ , I type a line of Input, I press `Shift``Enter`, and it produces the answer on a different line of output. However, I would like to type something like this:                 Thus, we get $c^2 - c = 1$, and solving it, we get $N[solve[c^2 - c = 1, c]]$, ...      The idea is that mathematica evaluates the command, takes the output, and _inlines_ it into the sentence, rather than have it as a separate line. I have no idea how to do this. From what I've read, this sounds like "cells", but from goofing around, it's not clear how to make this work. ## Question: How do I inline a mathematica expression, such that its output is displayed inline?


Does Mathematica have a "MATLAB Builder" equivalent?

I was wondering if _Mathematica_ has an equivalent of MATLAB's "MATLAB Builder" as seen here? I found this but it reads as if all programs using .NET/Link must have _Mathematica_ installed on them as well. I have several systems to replicate and it would be impossible to have _Mathematica_ installed on all 25-1000 computers. Thanks! **EDIT** Additional Information: I use C# applications to control various systems and I would like to use a bunch of _Mathematica_ 's functions (interactive plots, optimization, statistical analysis, etc.) within them. From the link, MATLAB's "MATLAB Builder" can create assemblies of user designed functions/scrips for standalone use in C#/.NET applications (i.e. MATLAB isn't required on the deployment PCs for the MATLAB assembly functions to run). I'm looking for a _Mathematica_ equivalent.


Creating a Mathematica executable that uses JLink

I am making a program in Mathematica that uses the Robot class of Java and some other Mathematica functions. I want the end product to be a standalone executable that can run even if a computer does not have Mathematica. Is this possible, and how so? Would CDFPlayer work, or is there some other way?


List of Mathematica textual symbols

## Context I am using _Mathematica_ to create live documents - documents that are both interactive and show mathematical derivations. Now, I'm aware that there are certain symbols that are available via:               \[CapitalSigma]      or `esc`S`esc` However, some of the symbols I want (`\in`: $\in$, `\subsetneq`: $\subsetneq$) do not belong in the greek letters. Is there a list of something similar to this but lists _Mathematica_ symbols instead of $\LaTeX$ symbols? Thanks!


Rebinding keys to define new keyboard shortcuts

I've checked **_Mathematica_** → **Preferences** , and poked around the options on the toolbar. However, I don't see a way to define new keyboard shortcuts in _Mathematica_. I've used VIM for 10+ years, and I've rebound `Ctrl`+`F` to be `Esc` for the last decade or so. I would like to also use this shortcut in _Mathematica_ , to have `Ctrl`+`F` be `Esc`, so hitting something like: `Ctrl`+`F` `S` `Ctrl`+`F` should give me capital Sigma. Question: how do I define new keybindings in _Mathematica_? (I have a CS background, so I'd prefer things that involve editing config files / writing scripts -- that would give me more power -- over clicking things in a GUI).


How to display each step of an A star algorithm?

I wrote a pathfinding program: A*, which is an extension of Dijkstra. I want to see the result of each step at a time. Which function should I use? The main program is the notebook Astar, which is implemented based on a data structure called priority queue. The package `PriorityQueue.m` is put in location F:\ by default. For example, here are some results of a whole run. ![enter image description here](http://i.stack.imgur.com/HeScT.gif) ![enter image description here](http://i.stack.imgur.com/r5R3T.gif) ![enter image description here](http://i.stack.imgur.com/fBd9c.gif)


Contour plot of complex function: problem in choosing argument

I have a complex function F[x,y], and now I want to plot the contour F[x,y] = 0. What can I do in order to have the contour plot vs Re[x] and y (That is, I want to treat y a real variable and x a complex one)? Thanks you very much!


Plotting double inequality only for integer values

`RegionPlot` is plotting for all values. And using `ListPlot` I can only evaluate one inequality. How can I plot this type of inequality: $$\frac{1}{\alpha+1} \leq \frac{\sum_{i=0}^k i^a}{\sum_{i=0}^k i^b} \leq 1+\alpha$$. $a$,$b$ are const (I know values $a$ and $b$). I want to plot dependency between $\alpha$ and $k$ only for integer values of $k$ and $\alpha$ is only from $(0,1]$. So I tried to use `ListPlot` (as you suggested me in previous post).               ListPlot[Table[{k, (-1) + (Sum[i^a, {i, 0, k}]/            Sum[i^b, {i, 0, k}])}, {k, 1, n}], PlotRange -> {0, 1},       Filling -> Top]      But I don't know how to add here the second inequality. I tried also to use `RegionPlot`. This commend is easier for me, because I know how to add the second inequality, but I don't know how to restrict that `k` should be only integer               RegionPlot[(Sum[i^a, {i, 0, k}]/           Sum[i^b, {i, 0, k}]) <=         1 + f && (Sum[i^a, {i, 0, k}]/           Sum[i^b, {i, 0, k}]) >= 1/f, {k, 1, n}, {f, 0, 1}]


Paste data into Mathematica with formatting

Select the following Mathematica code and paste it into a notebook. In Windows 7(Mathematica 8) the line breaks are not interpreted in the expression. In fact any data copipasted from stackexchange loses it's formatting. How do I paste content from stackexchange into Mathematica while keeping the formatting?               Print[       "text"     ]      **EDIT:** Now ideally Mathematica would support this natively. Solutions to integrate this into Mathematica would be great. I have 3 possible ideas.   1. modify Ctrl+V so this automatically occurs   2. assign a different modifier    3. create a button or palette I'm going to do the 3rd for now, but any other solutions are appreciated.


How to make a 3D-Plot from 2D-interpolated data

I have data of the form `{x,y}` for different concentrations. Therefore I added the concentration as `z`, resulting now in `{x,y,z}`. Example data (for concentrations A:1%, B:2%, C:4%):               dataA = {{1, 20, 1}, {2, 19, 1}, {3, 18, 1}, {4, 17, 1}, {5, 16, 1}};          dataB = {{1, 20, 2}, {2, 19.5, 2}, {3, 19, 2}, {4, 19.5, 2}, {5, 16, 2}};          dataC = {{1, 20, 4}, {2, 21, 4}, {3, 20.5, 4}, {4, 19.5, 4}, {5, 16, 4}};      Now I want to make a 3D surface plot from these traces (by 2D-interpolation). How to do that? **Edit:** the real data here: dropboxlink


Unsetting messages

The following code suggests that Mathematica stores the messages in cache:               (*1*)Remove[VariationalD]     (*2*)Messages[VariationalD]     (*3*)Message[VariationalD::args, OPS]     (*4*)Messages[VariationalD]      The output of the second line is `{}` as expected for a symbol that has just been removed. The output of the third line however is not the expected "-- Message text not found --". Instead, Mathematica seems to have pulled that message from some cache. In any case, **how can I reset the message cache (without resetting the whole installation)?** * * * **Update** I apologize because my previous example did not really work. In any case, the following is a better example. This code was executed on a freshly launched kernel.               before = Messages[General]; Message[General::dummies, OPS];     after = Messages[General]; Complement[after, before]      ![enter image description here](http://i.stack.imgur.com/gOhd5.png) The message `General::dummies` was not part of the original list of messages attached to `General`. Following the documentation, the next place to check would be `$NewMessage`, but `Messages[$NewMessage]` is empty. So, where did `General::dummies` come from?


Bug in handling backslashed Cyrillic symbols in v.10.0.0?

Consider:               "\бвгд" // FullForm     "\\бвгд" // FullForm      In v.8.0.4 I get this: > >     "\\:0431\:0432\:0433\:0434" >     "\\\:0431\:0432\:0433\:0434" >   But v.10.0.0 adds redundant backslash before the first backslashed Cyrillic symbol: > >     "\\\:0431\:0432\:0433\:0434" >     "\\\\:0431\:0432\:0433\:0434" >   ![screenshot](http://i.stack.imgur.com/HFbKC.png) As the result it is not possible to open any file which name (or name of a directory in the path) starts from a Cyrillic symbol. Also after evaluating the above (in the case the Cyrillic symbols were typed, not pasted in the Notebook) the following bugs appear:   * When I try to cut by pressing `Ctrl+X` any `Cell` or group of cells in this Notebook I get http://demonstrations.wolfram.com/ opened in my browser and nothing changed in the FrontEnd   * After some additional editing (entering backslashed Cyrillic symbols after the quote `"` but without entering the closing quote and without evaluation of the cell) an attempt to cut an input cell by pressing `Ctrl+X` results in commenting all the code in the selected input cell. Pressing `Ctrl+X` again uncomments the code. All the above manipulations with `Ctrl+X` give this result when English keyboard locale is selected. Does anyone also observe this? Is there a workaround? P.S. OS Win7 x64.


Animation - Autorun?

Reworking on a pre-made simulation, when I click the 'Play' button, it won't actually play and when I autorun the program, it just cycles through all the balloons in 10 seconds... is there a way in which I could slow down the time it takes to go through all the balloons as well as? I have not linked the actual graphic of the girl in the code (as it takes up a lot of space).. I've tried using AutorunSequencing yet I don't know where to place it within the code.. ![enter image description here](http://i.stack.imgur.com/OrLko.png)                Manipulate[SeedRandom[236175234];        With[{rp = Prepend[RandomReal[UniformDisk[2], n + 1], {0, -35}]},       Graphics[GraphicsComplex[rp,        {Translate[{Inset[, {2.5, -39.5}, Automatic, {6, 9.5}],       {Opacity[.5], Thickness[.001],          Line[{1, #}],          Hue[RandomReal[]],          Disk[#, 2.8]} & /@ Range[2, n + 1]},       If[n > 83, {0, Up}, {0, 0}]], Darker@Red, Thickness[.04],      Line[{{-25, -44.8}, {25, -44.8}}]}],       PlotRange -> {{-23, 23}, {-46, 25}}, Background -> LightOrange]],          {{n, 1, "Balloons"}, 1, 150, 1, Appearance -> "Labeled"},     {Up, 0, 50, ControlType -> Trigger},      Initialization :> ({UniformDisk /:      Random`DistributionVector[UniformDisk[r_?Positive], n_Integer,        prec_?Positive] :=      r*Sqrt[RandomReal[1, n, WorkingPrecision -> prec]]*       Transpose[        10 {Cos[#], Sin[#]} &[         RandomReal[2 Pi, n, WorkingPrecision -> prec]]]})]


How to search a file in a particular system using Mathematica

I want to know if there is any function which can search a file from the whole system and gives the whole path for that particular file. I have tried `$Path` but it gives some default paths also. * * * Addendum: If the file is stored in multiple locations and I want only one location out of all, how can I get that? I want to stop the search as soon as the file is found.


How to add label to a plot in PopupMenu which does not change the plot size

I am facing a problem in adding a label to a `PopupMenu`. I have two plots a and b of same size. But when I am adding label to them in `PopupMenu`, it is changing the size of the plot. When the `Label` size is bigger, it compresses the plot so that it adjust to the `FieldSize` of `PopupMenu`. But I dont want this.                a = Manipulate[            l = DiscretePlot[Cos[a t], {t, 0, 2 Pi, Pi/6}, ExtentSize -> Full,             ImageSize -> Scaled[1], AspectRatio -> .25, ImageMargins -> 0,             ImagePadding -> 0],             Mouseover["vertical", Control[{{a, 1, "a Manipulator"}, 1, 20}]],             ControlPlacement -> Bottom];     b = Manipulate[q = Graphics[          DiscretePlot[Sin[g t], {t, 0, 2 Pi, Pi/6}, ExtentSize -> Full,           PlotStyle -> Orange, AspectRatio -> .25, ImageSize -> Scaled[1],           ImageMargins -> 0, ImagePadding -> 0]], {g, 1, 10}];          Grid[{{PopupMenu[             Dynamic[p], {a ->Labeled[l, (Framed["pop_up_window Plot"]), {Right},                         LabelStyle -> Directive[Bold, FontFamily -> "Helvetica"]],                       b -> Labeled[q, (Framed["mouseover Plot"]), {Right},                     LabelStyle -> Directive[Bold, FontFamily -> "Helvetica"]]},             FieldSize -> {24, 8}, ImageMargins -> 0,             FrameMargins -> 0, ContentPadding -> False,             Alignment -> {Center, Center}]}, {Dynamic[p]}}, Spacings -> 20,             Alignment -> {Left, Top}]      ![enter image description here](http://i.stack.imgur.com/ZBhTc.png) When I am adding label, then the first plot becomes smaller than the second. I want that `Label` size should not affect the `Plot`size.


Can RowReduce work in this matrix?

The matrix $Q$ with dimensions $n\times2*n*m$ is structured by $$Q=[B|AB|\cdots|A^{2*n-1}B]$$ where $Q$ is an augmented matrix built from a $3\times3$ matrix, $A$, and a $3\times2$ matrix, $B$. I need $\DeclareMathOperator{\rank}{rank}\rank(Q)<n$ but I get $\rank(Q)=n$. If I `RowReduce` matrices $A$ and $B$ before that calculation the $Q$ matrix has $\rank<n$ as I want, but its elements aren't the ones I need to continue, but 0's and 1's. Any Idea on how to get the desired $Q$ matrix? If I multiply $Q$ by $Q_\text{reduced}$ (with dimensions $2*n*m\times n$) I get an $n\times n$ matrix, $W$ with $\rank(W)=n$, so that's not what I want. I've no Idea how to implement the _Mathematica_ code here. Any suggestions would be helpful.               CellGroupData[{       A0 = RandomInteger[{1, 10}, {4, 4}],       B0 = RandomInteger[{1, 10}, {4, 3}],       A1 = RowReduce[A0],       B1 = RowReduce[B0],       m = 3,       n = 4,            (*Original Matrices Proc *)       Do[Lnn[j] = MatrixPower[A0, j - 1].B0, {j, 2*n}],       Do[Flatten[Lnn[j][[i]], m], {i, n}, {j, 2*n}],           M222 = Table[Lnn[j][[i]], {i, n}, {j, 2*n}],       R222 = Flatten[M222],       Qnn = Partition[R222, 2*n*m],       η1 = MatrixRank[Qnn],       {p1, r1} = Dimensions[Qnn],       QN11 = RowReduce[Qnn],            (*RowReduced Matrices used now *)       Do[Lnn1[j] = MatrixPower[A1, j - 1].B1, {j, 2*n}],       Do[Flatten[Lnn1[j][[i]], m], {i, n}, {j, 2*n}],           M22 = Table[Lnn1[j][[i]], {i, n}, {j, 2*n}],       R22 = Flatten[M22],       Qn = Partition[R22, 2*n*m],       η = MatrixRank[Qn],       {p, r} = Dimensions[Qn],       QN = RowReduce[Qn],            Print[MatrixForm[Qnn], MatrixForm[QN11]],       Print[MatrixForm[Qn], MatrixForm[QN]]}];


Simulated Annealing InitialPoints option

I have a cost function that depends on 4 parameters: `CostFunction[{tx,ty,tz,ox}]`. I used `NMinimize[]` function with `SimulatedAnnealing` method to determine its minimum. I looked for an example that uses the `InitialPoints` option but I did not find any. For this reason I am posting my question. My code is like this (I cannot post the `CostFunction[]`):                 NMinimize[{             CostFunction[{tx, ty, tz, ox}],             tx >= 0 && tx <= a, ty >= 0 && ty <= b, tz >= 0 && tz <=c, ox >=0 && ox <= d},       {tx,ty,tz,ox},       Method -> {"SimulatedAnnealing", "PerturbationScale" -> 3, "SearchPoints" -> 10}]       The above code works correctly but when I add the `"InitialPoints"->{0,0,0,0}`, I receive the following error: > `NMinimize::parchange: "Inappropriate parameter: \!\(\"InitialPoints\"\) -> > {0,0,0,0}, changed to Automatic"` Another option is not very clear `"RandomSeed"` ? What is wrong, please?


Executing C programs within mathematica

I have a requirement for executing a C program within Mathematica. The user will provide the inputs and the expected results on a front end. Mathematica runs the C file, obtains the result for the provided inputs and compares with the user provided expected results. Further, a green pass button will be displayed if the results matched else a red failed button will be displayed. Later, I want to be able to do the same for C++, Python, Java, and Perl programs. Anyone has worked on this before ? Warm regards, Anuk


Changing the default font size

Hey I have problems reading my mathematica notebooks due to the small fonts. I'd like to change their default values for the input and output. I already figured out that everything seems to be defined in core.nb but I couldn't find any definitions inside. It just states things like: ![enter image description here](http://i.stack.imgur.com/URduf.png) But I don't see any definition, also I couldn't find them in the FormatType Styles section that looks like: ![enter image description here](http://i.stack.imgur.com/KUOjY.png) An easy solution to my problem is to change the magnification but this is only possible in too huge steps. I also played around with the Option Inspector, but I could't find any place that effetcs the font size of my input/output. Changing the FontSize in Global options also didn't change anything: ![enter image description here](http://i.stack.imgur.com/j8T6T.png) Any ideas? I know there are many similar threats already but I couldn't find a working answer. And I doubt that the solution has to be super complicated. Edit: Just realized that the last way changes the fonts as expected but only inside the documentation center.


Cell copy results in jaggy, aliased output

When I copy a cells by selecting them from the collapse bars on the right, then using the context menu option "Copy", the pasted image of plots is not anti-aliased and in general the text seems to have bad styling compared to a screen. For example, here is a plot which is copied using the built-in copy command:               Manipulate[Plot[Cos[a x], {x, 0, 3 \[Pi]}], {a, 1, 10, 0.3}]      ![copied plot](http://i.stack.imgur.com/13VxF.png) and here is a screen shot of the same command and plot: ![enter image description here](http://i.stack.imgur.com/ArIPX.png) As you can see the screen shot looks a lot better. For example, compare the graphical quality of the buttons in the animation panel.


Using levels in MapIndexed

I am trying to use `MapIndexed` to manipulate a matrix of data but I am having trouble getting the levels parameter to work the way I would like. Suppose that my data looks like this, with every odd column being a count and the even columns being some piece of data:               a = {{11, d11, 21, d21, 31, d31},          {12, d12, 22, d22, 32, d32},          {13, d13, 23, d23, 33, d33},          {14, d14, 24, d24, 34, d34}};          b = {{11, d11, 0, Null, 31, d31},          {12, d12, 0, Null, 32, d32},          {13, d13, 0, Null, 33, d33},          {14, d14, 0, Null, 34, d34}};          c = {{0, Null, 0, Null, 31, d31},          {0, Null, 0, Null, 32, d32},          {0, Null, 0, Null, 0, Null},          {0, Null, 0, Null, 34, d34}};      As you can see, some odd columns will have a zero count and the corresponding data column will be `NULL`. Edit: _I have changed`c` to reflect some new bits of information about the data. There may be some rows that contain the `0, NULL` pattern, but I only want to eliminate columns in which the first row is like this. The first row is a sum of the following rows, and I only want to eliminate a column if it has no data at all. This is why I structured the `For` loop in the way I did. Based on the responses, I felt I needed to clarify._ I'd like to eliminate both the count and data columns any time this is the case. For example, after some operation I'd like to have:               a0 = {{11, d11, 21, d21, 31, d31},           {12, d12, 22, d22, 32, d32},           {13, d13, 23, d23, 33, d33},           {14, d14, 24, d24, 34, d34}};          b0 = {{11, d11, 31, d31},           {12, d12, 32, d32},           {13, d13, 33, d33},           {14, d14, 34, d34}};          c0 = {{31, d31},           {32, d32},           {0, NULL},           {34, d34}};      I accomplished this using a hack with a `For` loop but this is obviously not the proper way to use Mathematica and I was directed to `MapIndexed`:               a0 = For[i = 1, i < Length @ a[[1]], i = i + 2,               If[a[[1, i]] == 0,                  a = Drop[a, None, {i, i + 1}];                  i = i - 2              ]          ];      How can I get `a0` with something of this form?:               a0 = MapIndexed[f, a, list];


Building conditional lists with Manipulate

I'm trying to select elements of a list that satisfy some criteria using `Manipulate[]`. Given 2 lists:               list1 = {{a, b, c}, {d, e, f}, {g, h, i}};     list2 = {{9, 0}, {2, 1}, {9.5, 3}};      I want to build a function that, when some criteria are `True`, will look for them at a specific position in `list2`. Let me show with an example: Consider the case in which I only want to find if elements in position 1 of `list2` are `>=9` and then take the corresponding position from `list1`. I would write               Pick[list1, Map[#[[1]] >= 9 &, list2]]     (*{{a, b, c}, {g, h, i}}*)      However, if I was to look into elements in position 1 being `>=9` and elements of position 2 being `<2` I would write               Pick[list1, Map[#[[1]] >= 9 && #[[2]] < 2 &, list2]]     (*{{a, b, c}}*)      **But what I want is** to have a manipulable function that uses the `And` function in the second case, but without excluding the possibility that only one of the criterion may be desired. I.e., when only `c1 = True` I want the first case to be analyzed; when only `c2 = True` I only want the second case; when both are true, I want the both conditions to be analyzed. I was thinking about using the following function, but this doesn't work mainly because the new list is not even created.               Manipulate[      Block[{conditional, condlist, c1, c2},       condlist = {};       If[c1, Insert[condlist, #[[1]] > 9, -1]];       If[c2, Insert[condlist, #[[2]] > 3, -1]];       condlist             (*Pick[list1, Map[condlist &, list2]]*)       ], {c1, {True, False}}, {c2, {True, False}}]      Anyone has any tips on how I can solve this? Thanks in advance! **Edit:** though the example I present here only considers 2 conditionals `c1` and `c2`, this is to be applied to a much larger set of conditions. It includes 8 conditionals, and may have any combination among it (e.g. `c1 AND c2 AND c4`, or `c7`, or `c5 AND c6 AND c7`, etc).


Arranging and combining multiple plots and graphics

I have 4 plots/schematics. They are either created with ArrayPlot[], ParametricPlot3D[] or Graphics[]. As I play with calculation resolutions their absolute sizes will change. I would like a neat way to arrange them inside a YouTube sized box (1920 x 1080) using relative positioning so that when/if they change size the final combination still looks more or less how I want. To simplify the question let's say I have:               videoBox = Graphics[{EdgeForm[Thick], White, Rectangle[{0, 0}, {1920,1080}]}];     plot1 = Graphics[{Blue, Rectangle[{0, 0}, {2, 3}]}];     plot2 = Graphics[{Red, Disk[{0, 0}, 2]}];     plot3 = Graphics[{Orange, Disk[{0, 0}, 2]}];     plot4 = Graphics[{Gray, Rectangle[{0, 0}, {2, 1}]}];     GraphicsRow[{videoBox, plot1, plot2, plot3, plot4}]      ![](http://i.stack.imgur.com/JDFnN.png) Using relative positioning I would like to combine them to look something like: ![](http://i.stack.imgur.com/WbatV.png) Any suggestions? **Update 1** The answers and suggestions have certainly helped, but I still need more control over the positioning. For example here is the actual image I have created using the suggestions so far: ![](http://i.stack.imgur.com/9fz0B.jpg) Close but no cigar. I would like to move the blue and red dots schematic up so that the bottom lines up with the bottom of the rectangular box plot.


Computing polynomial eigenvalues in Mathematica

MATLAB offers a function polyeig for computing polynomial eigenvalues, which appear, for instance in quadratic eigenvalue problems (see here for some applications) such as: \begin{equation} (M\lambda^2 + R\lambda + K)x =0 \end{equation} where $M$, $R$ and $K$ are matrices. Any realistic way of accomplishing this in _Mathematica_? By realistic I mean one that actually employs specialized algorithms. * * * P.S. If anyone from Wolfram is reading this: any perspectives on whether this may appear in future releases of _Mathematica_?


Changing background colour of a Manipulate element

Please consider the following:                Manipulate[Plot[Sin[x (1 + a x)], {x, 0, 6}], {a, 0, 2}];      Now, I would like to change the background colour to yellow. I tried the following, but in this case the nice looking rounded corners of the manipulate element get lost:               Panel[#, Background -> Yellow] &@      Manipulate[Plot[Sin[x (1 + a x)], {x, 0, 6}], {a, 0, 2},        Paneled -> False]      Maybe somebody has a better idea. **EDIT** The background colour of `Manipulate`is by default grey. ![Manipulate](http://i.stack.imgur.com/mz8fw.png) In addition the graphical element in which the `Manipulate` is embedded has rounded corners ![rounded corner](http://i.stack.imgur.com/ICUH7.png) which I would like to keep. Applying my approach will change the colour but I loose the rounded corners.


What is the best way for an application to provide customisation options for the user?

Suppose that an application needs to be configured specifically for a user's system. e.g. the application needs to be told the location of certain data directories. What is the best way to provide this possibility to the user, so that the user doesn't have to enter this information every time they load the package?


pH calculations, speeding up code involving Solve

I'm trying to calculate pH values of solutions containing water and acetic acid. The relevant equations have been defined and I now want to find a solution using Mathematica. For a specific acid concentration (0.0001) I can do the following.               Solve[(concentrations && equilibrium && requirements) /. {c2 -> 0.0001}]      But I would prefer to solve the system of equations once and then insert the acid concentration. But the following code does not work               Solve[(concentrations && equilibrium && requirements)] /. {c2 -> 0.0001}      Which throws the following error               Solve::ratnz: Solve was unable to solve the system with inexact      coefficients. The answer was obtained by solving a corresponding      exact system and numericizing the result. >>"      My working code so far is shown here               concentrations = cHp == c1 + c3 && cOHm == c1 && cCH3COOm == c3 && cCH3COOH == c2 - c3;     equilibrium = 10^-14 == cHp cOHm && 1.1614 10^-5 == cCH3COOm cHp/cCH3COOH;     requirements = cHp > 0 && cOHm > 0 && cCH3COOH > 0 && cCH3COOm > 0;     Plot[-Log[10, cHp] /.        Solve[(concentrations && equilibrium && requirements) /. {c2 ->            x}], {x, 0, 0.00010}, PlotRange -> {2, 9}]


Why I can not get the plot when I use NDSolve`ProcessSolutions? Anyone can give me a cue. Thanks a lot!               state = First[NDSolve`ProcessEquations[{D[u[t, x], t] == D[u[t, x], x, x],u[0, x] == Cos[\[Pi] /2 x], u[t, 0] == 1, u[t, 1] == 0}, u, t, {x, 0, 1}]];     NDSolve`Iterate[state, {0, 4}];     NDSolve`ProcessSolutions[state, "Forward"];     Plot[Evaluate[u[4, x] /. %], {x, 0, 1}]


Clean-up Code / Reduce variables

I'm writing a playing card simulator of sorts, and everything works fine, but some `Module`s use a disgusting amount of variables. For Example:               randomHand[x_] :=      Module[{hand, kings, cards, suits, value, suitsK, valueK, cardList},     hand = PadLeft[IntegerDigits[RandomInteger[{1, 52}, x], 13]];     kings = Cases[hand, {___, 0}, 2];     cards = DeleteCases[hand, {___, 0}, 2];     suits = First /@ cards;     value = Last /@ cards;     suitsK = First /@ kings;     valueK = ReplaceAll[Last /@ kings, 0 -> "King"];     suits = suits /. {0 -> "Hearts", 1 -> "Diamonds", 2 -> "Clubs",       3 -> "Spades"};     suitsK = suitsK /. {1 -> "Hearts", 2 -> "Diamonds", 3 -> "Clubs",       4 -> "Spades"};     value = value /. {11 -> "Jack", 12 -> "Queen"};     cardList = Partition[Riffle[value, suits], 2];     Map[ToString[cardList[[#]][[1]]] <> " of " <> cardList[[#]][[2]] &, Range[Length[cardList]]]]      My Mathematica knowledge is not as fluent as I'd like it to be, so I'm wondering if it is bad to use so many variables, and if it is, how would I go about cleaning up the above excerpt?


How to make MousePosition be referenced by a coordinate system established over an image?

In the question of How to make a curve selectable from a scaned image and convert it to a list of coordinates, thanks to the excellent answer of Alexei Boulbitch, I knew how to select a series of points from a curve in a scaned image. However, to get a wanted point, sometimes we should control the horizontal or vertical position of the cursor during the selection. For example, ![enter image description here](http://i.stack.imgur.com/C7XL3.png) to compare the y-values of each curve at the same x-position 0.05, I have to control the position of my cursor during the selection of the points on each curve. To do this, I can use the function MousePosition to control my selection. like this : ![enter image description here](http://i.stack.imgur.com/xRi7y.png) I showed the dynamic mouse position below the image. Here, the MousePosition is referenced by the screen display, this is useful but not quite convenient for I want to know whether the actual x-position of my cursor is 0.5. How can I convert such a MousePosition to its coordinates over the image (scales X and Y have already been set memorized in the answer of question How to make a curve selectable from a scaned image and convert it to a list of coordinates) ?


Exporting a histogram to PDF in without rasterising it

How can I export a histogram without rasterising it? The labels and axes seem unaffected, but the bars themselves are pixelated when I zoom into them in a PDF viewer. For example, if I run               Export["~/test.pdf", Histogram@RandomVariate[NormalDistribution[], 1000]];      I get a PDF that looks like this when zoomed in: ![Histogram](http://i.stack.imgur.com/Wz3Q2.png) This is a problem when I try to run it through `pdf2ps` and `ps2pdf` (to work around some font problems when including the PDFs in a LaTeX document), since the whole image gets rasterised, including the text.


How to control the layering of graphics displayed with Show

I am trying to combine two graphics objects using `Show`. The first one is an isosurface:               data = Import["/PATH/furan-ks.sdat", "Table"];     ALEE = Nearest[data[[All, {1, 2, 3}]] -> Rescale[data[[All, 4]]]];     cfALEE = ColorData["Rainbow"]@First@ALEE[{#1, #2, #3}] &;     isosurface=ListSurfacePlot3D[data[[All, {1, 2, 3}]], BoxRatios -> Automatic,      ColorFunction -> cfALEE, ColorFunctionScaling -> False,      Boxed -> False, Axes -> False, Mesh -> None, MaxPlotPoints -> 25,      ImageSize -> 500]      ![isosurface](http://i.stack.imgur.com/2KBWW.jpg) The second one is a sequence of points:                geom = Import["/PATH/furan.geom", "Table"];      AngToAu = 1.88971616463;      Function[x, x*AngToAu];      geom = Map[%, geom, {2}];      Show[Graphics3D[{Black, PointSize[0.05], Point[geom]}, Boxed -> False]]      ![points](http://i.stack.imgur.com/T7jes.jpg) I want the points to appear on the same plot as the surface and be plotted at the appropriate scale. A command I am using:               Show[isosurface, Graphics3D[{Black, PointSize[0.05], Point[geom]}, Boxed -> False]]      The catch is that the points effectively appear inside the surface and are NOT visible. I need to somehow project them on the surface or make them visible through the surface. How do I deal with this? Any suggestions? **EDIT** : attached the files isosurface geom


How to plot several functions without jumping? (multiple eigenvalues of a system as functions of 2 parameters)

I've been working on this research problem for months with some success by no global/proper solution to the problem. So I have square, Hermitian matrices of various sizes ($8,20,38$ dimensions) with functional dependence on two variables, call them `x` and `y`. I am interested in plotting all the eigenvalues as functions of the $2$ variables `x` and `y`. Let's call `M` the $8 \times 8$ hermitian matrix.               Plot3D[ Eigenvalues[M], {x,-1,1}, {y,-1,1}]      gives $8$ sheets corresponding to the eigenvalues of `M` as functions of `x` and `y`. However, there will be many "jumps" between the sheets which totally obscure the plots. Basically, I think that during the plotting of the eigenvalues, for certain regions of the parameter space, _Mathematica_ organizes the $8$ values differently, so the different sheets swap places, so we get tons of random garbage vertical bits between sheets. I have spent months trying to resolve this in different ways, mostly involving methods to force _Mathematica_ into a consistent sorting method. Here are some examples of failed methods:               Plot3D[ Sort[Eigenvalues[M]], {x,-1,1}, {y,-1,1}]          Plot3D[ Sort[Eigenvalues[M], Abs[#1] <= Abs[#2]&], {x,-1,1}, {y,-1,1}]          Block[{set=Ordering[ Eigenvalues[ M/.x->0 /. y->0], All, Abs[#1] <= Abs[#2]&]},       Plot3D[ Eigenvalues[M][[set]], {x,-1,1}, {y,-1,1}]]          Block[{set=Ordering[ Ordering[Eigenvalues[ M/.x->0 /.y->0], All,              Abs[#1] <= Abs[#2]&]]},       Plot3D[ Eigenvalues[M][[set]], {x,-1,1}, {y,-1,1}]]          Block[{set = Ordering[Eigenvalues[ M /.x->0 /.y->0], All, Abs[#1] <= Abs[#2]&]},       Plot3D[ Sort[ Eigenvalues[M][[set]]], {x,-1,1}, {y,-1,1}]]          Block[{set = Ordering[ Ordering[ Eigenvalues[ M /.x->0 /.y->0], All,            Abs[#1] <= Abs[#2]&]]},       Plot3D[ Sort[ Eigenvalues[M][[set]]], {x,-1,1}, {y,-1,1}]]      as well as other permutations of similar ideas and more. Some of these methods have worked somewhat, reducing the jumping or working in certain regimes of the parameter domain. But nothing works consistently. Please help me understand the proper solution to this problem!


Error Interpretation with NIntegrate, max. possible accuracy/precision

I guess the right question to this is: Which method is used at `NIntegrate` with _Mathematica_ 8 as default and which is used with _Mathematica_ 9 as default? _Mathematica_ 8 works fine; _Mathematica_ 9 doesn't.


Plotting & Solving

I'm trying to plot replicate a graph from one of the articles and it has series of equations it has solved. here is my code so far:               Tan [o] == 2 Cot[B]*(M^2*Sin[B]*Sin[B] - 1)/(M^2*(1.4 + Cos[2 B]) + 2);           Pr1[o_, M_] := 1 + 2*1.4/2.4*(M^2*Sin[B]*Sin[B] - 1)     Plot[Table[Pr1[o, M], {o, {10*Pi/180}}] // Evaluate, {M, 1, 3}, AxesOrigin -> {1, 0}]      The variables `o`, `B` and `M` are related to the tangent expression. After that I'm trying to solve the next equation and plot that with certain value of `o` and as `M` varies from 1 to 3. For some reason, I'm not getting any error but my graph isn't showing up at all. Also note that the tan expression produces 6 roots for given `M` and `o`, I want to only take the lowest positive value out of the 6 roots. * * * ### Edit Here is my new code. I used the 4th root instead of 1st one. Thank to belisarius for helping out:               s = Solve[Tan[o] == 2 Cot[B]*(M^2*Sin[B]*Sin[B] - 1)/(M^2*(1.4 + Cos[2 B]) + 2), {B}];          Pr1[o_, M_] := 1 + 2*1.4/2.4*(M^2*Sin[B]*Sin[B] - 1)     Plot[Table[Evaluate[Pr1[o, M] /. s[[4]]], {o, {10*Pi/180}}], {M, 1, 3},        AxesOrigin -> {1, 0}, Evaluated -> True]      ![enter image description here](http://i.stack.imgur.com/WRKbE.png) The plot shows a step near the value of ~1.4 of M. I want to eliminate this. Any suggestions?


Working in a team in Workbench

Imagine the following scenario: user A is developing a project with documentation in workbench. She wants to share her (unfinished) work with a small group (4-5) of users (B,C,D,E) , so that all users can work on the project simultaneously. The users might have different operating systems and work in different places, connected on internet. The users have heard that WB supports CVS technology, but they know next to nothing about it, assuming that it is the right thing to use. The users have Workbench (not Eclipse + WB plugin or other fancy setting) and would like to stay that way. So what is the best way to accomplish all this with Workbench? Please assume that the users only know Mathematica and Workbench and little else in this field, and that they would prefer to use WRI tools only. There is a similar question here in MMA.SE, but it looks to me more like a high level discussion between experts and does not seem to be very helpful for absolute beginners in this area


Use of the option EvaluationElements

When trying to answer this question, I ran into the following problem. In the help documentation of EvaluationElements, it is claimed that we can use EvaluateNotebook to evaluate only cells that have a certain tag using EvaluationElements, which is an Option. However, I could not get it to work. I have made a piece of code to show you what I have tried. Because the problem was that NotebookEvaluate would evaluate an entire notebook, instead of just a few (or no) cells, there can be a problem with infinite loops. The piece of code I made creates a new notebook with which to manipulate the original notebook. I have taken the opportunity explain things further in a generated text cell. Maybe all this was not the most efficient way to go about asking this question, so you may not want to bother if you don't like fun. Otherwise, please run the code in a new notebook.               nb = EvaluationNotebook[];     If[       TrueQ[defaultFalseBool]       ,       Null       ,       defaultFalseBool = True;       nb2 = NotebookPut@         Notebook[          {           Cell[            "The cell below has been evaluated for your convenience! But \     as you can see, even though clearly no cells matched the specified \     tag, the entire other notebook got evaluated. To prove it, a message \     was generated in the other notebook (which was printed there because \     of the option InsertResults-> True). Placing curly brackets {} around \     \"blabla\" wont help. Use the cell containing the Clear below if you \     want to try again!", "Text"]           ,           Cell[BoxData[{               RowBox[{                  RowBox[{"NotebookEvaluate", "[",                      RowBox[{"nb", ",",                         RowBox[{"InsertResults", "\[Rule]", "True"}], ",",                     " ",                         RowBox[{"EvaluationElements", "\[Rule]",                            RowBox[{"\"\<Tags\>\"", "\[Rule]", " ",                         "\"\<blabla\>\""}]}]}], "]"}],                   ";"}], "\[IndentingNewLine]",                RowBox[{"CellPrint", "[",                   RowBox[{"Cell", "[",                      RowBox[{                        RowBox[{"BoxData", "[", "\n", " ",                            RowBox[{"RowBox", "[",                               RowBox[{"{",                                 RowBox[{                                "\"\<Clear\>\"", ",", " ", "\"\<[\>\"",                          ",", " ", "\"\<defaultFalseBool\>\"", ",", " ",                                  "\"\<]\>\""}], "}"}], "]"}], "]"}], ",",                     " ", "\"\<Input\>\""}], "]"}],                   "]"}]}], "Input"]           }          ];       CellPrint[         Cell[BoxData[           RowBox[{"Print", "[",              "\"\<this cell should not have been evaluated, as it lacks \     the specified tag\>\"", "]"}]], "Input"]]             NotebookEvaluate[nb2, InsertResults -> True];            ];      The question is: How can we evaluate only specific cells using the option EvaluationElements in NotebookEvaluate?


StringExpression: pattern reapeted one or more times matches pattern repeated zero times

I try to construct patterns using Riffle and Except               StringExpression@Riffle[{"a", "b", "c"}, Except[{"=", ","}] ..]      and expect it to match "a_b_c", but not "a_bc" because Except is repeated .. one or more times. However,               StringMatchQ["a_bc", StringExpression@Riffle[{"a", "b", "c"}, Except[{"=", ","}] ..]]      returns True. Could anyone explain why is it so?


shade plane with a color function color(x,y)

I am making a RGB color function which assigns an RGB color to each point in the plane. To check if it does what I think it should do (i.e. debugging it), it is helpful to be able to plot the function to see how the problematic areas are arising. How can I plot this function? i.e. is there something along the lines of               Plot[RGB[f[x,y],g[x,y],h[x,y]],{x,0,10},{y,0,10}]


Distribution of 10 points within a unit square

Related to some packing problems, following problem arose: **Distribute 10 points within a square of sides 1, so that minimal distance between them is maximized.** With the help of random simulation, or any other method, please provide example of such distribution, with graphical representation of square and points, and value of minimal distance between points for such distribution. The answer with distribution with largest minimal distance wins the "answer badge"! :) _(This problem so far to my knowledge couldn't be solved by pure mathematics, so I am coming here for valuable and desperately needed help regarding simulations etc.)_


How to plot a 3D surface with a simple black and white style?

_Mathematica_ has great plotting capabilities. However, sometimes what is needed is a very basic black and white plot without textures, lighting, glow and other complex features. So, here is my question: what kind of `Plot3D` options will allow me to get something similar to ![](http://i.stack.imgur.com/KCO3l.png)


Checking connectedness of a graph

I am trying to use the Combinatorica package in a Mathematica version 8 in the following code:               gp = Graph[{1-> 3, 1 -> 2, 3 ->1}]     << Combinatorica`     ConnectedQ[gp]      But this gives me an error message: General::compat: Combinatorica Graph and Permutations functionality has been superseded by preloaded functionality. The package now being loaded may conflict with this. Please see the Compatibility Guide for details. I have checked the guide but, the recommendation given could not solve this problem. Any suggestion please?


How to evaluate an integral

I am trying to evaluate this integral               Integrate[(kx^2/2)*Sin[\[Lambda]x], x]      from -pi/2(lamda) to pi/2(lamda) Everything there is a constant, and the only variable is x. this is the output i get               1/2 kx^2 x Sin[\[Lambda]x]      which i do not think is correct.


Can the elements of a list always be sorted into a canonical order?

As the title states - does a unique order exist for any _Mathematica_ list to be sorted by the `Sort[]` function (or as returned by a function that treats lists as sets)? While I'm pretty sure the answer is yes, the kinds of elements you can throw into a _Mathematica_ list seems so general and varied (numbers, strings, symbols, images, graphs, other lists, etc., etc.) that I thought to make sure. (The reason this question occurred to me is an exercise question asked in the book I just started learning _Mathematica_ from: Write a function `SubsetQ[list1, list2]` that checks whether `list1` is a subset of `list2`. My solution is               SubsetQ[lis1_, lis2_] := Intersection[lis1, lis2] == Union[lis1, {}]     (* thanks to Simon Woods' correction, and assuming Intersection and Union sort canonically *)       but that implicitly assumes that the two lists on either side of the equality check will be sorted in the same order.)


ListVectorPlot3D

I try to plot a 3D Vector plot. All Vectors start at (0,0,0) and point in directions given in spherical coordinates:               While[n < 100,x = RandomReal[];      AppendTo[rs, x]; AppendTo[Thetas, ArcCos[x]]; AppendTo[Psis, 2*Pi*x]; n++]      How do I convert the coordinates (`Thetas`, `Psis`, `rs`) into a List compatible with `ListVectorPlot3D`? Best and thanks for your help! * * * # Edit Thanks for your help. Putting the array into the right shape is exactly my problem. Could you show me how this has to be done? I used:               n = 0;     Origin = {};     Spherical = {};          While[n < 3, x = RandomReal[];      AppendTo[Origin, {0, 0, 0}];      AppendTo[Spherical, {x,ArcCos[x], 2*Pi*x}];     n++]          SphericalT = CoordinateTransform["Spherical" -> "Cartesian", Spherical]          cords = Transpose[{Origin, SphericalT}]      but it doesn't work to plot cords by               ListVectorPlot3D[cords]      the output looks like               ListVectorPlot3D[{{{0, 0, 0}, {0.0435796, 0.204158, 1.31166}}, {{0, 0,      0}, {0.0774815, 0.267354, 1.74896}}, {{0, 0, 0}, {0.466032,      0.498845, 4.28931}}}]      which in my eyes fits               ListVectorPlot3D[{{{x1, y1, z1}, {vx1, vy1, vz1}}, ...}]      proposed in: http://reference.wolfram.com/mathematica/ref/ListVectorPlot3D.html


general plotting/graph questions related to legend positions and text size

I have the following MWE               Show[      Plot[x, {x, 0, 2}, Frame -> True,        FrameLabel -> {Style["frequency", Medium],          Style["\!\(\*SubscriptBox[\(v\), \(mean\)]\)", Medium]},        PlotLegends -> {"asd"}],      ListPlot[{{0.5, 0.25}, {1, 0.5}}, PlotStyle -> Red,        PlotLegends -> {"asd"}]]      There are several things I am trying to do, which I can't get to work. I will list them here   1. How can I make the two legends be inside the graph, not outside?   2. How can I make the legends be aligned over/under eachother, exactly? Now the are aligned to the left.   3. I am really interested in finding a way to alter the size of the `FrameLabel`, ticks and legends in a easy way. So far I have only been able to do it by using `Small`, `Medium` and `Large`, but that is not very dynamic.


Why is `D[a[b][c],a[b]]` equal to `1[c]`?

**Background:** I had the same issue as described here, and I went to extend Mr.Wizard’s code such that `a[b][c]` would be shown as $a_b^c$. **Issue:** To my surprise, Mathematica evaluates `D[a[b][c],a[b]]` to `1[c]` instead of `0`. Here, `a[b]` and `a[b][c]` are meant to be unrelated variables. **Example:** I have an expression which contains a[b][c], which stands for (is printed as, thanks to the code linked in Background) $a^c_b$, where $c$ is an index, not a power. When I take partial derivatives with respect to a[b], which is supposed to stand for an _unrelated_ variable $a_b$, the term containing a[b][c] should be zero. I was expecting the result to be simply `0`, which would   * be consistent with `D[f[x],f]` evaluating to `0`, which I find sensible, given that f in the first argument is an identifier of a function (which involves only the variable x), while the right one is a variable   * make sense assuming that in general, e.g., `c` and `c[1]` and `c[2]` are completely distinct variables, even if they share the same `Head`.   * make sense given that the actually returned result `1[c]` seems to have no use case. **Questions:**   1. Why does Mathematica interpret it that way? I am a Mathematica Newbie and eager to learn, so don’t gloss over details, please. It seems as if `[c]` was a factor, while it isn’t, because this is evidently disallowed:              D[a[b]*[c],a[b]]     Syntax::sntxf: "a[b]*" cannot be followed by "[c]".     Syntax::tsntxi: "[c]" is incomplete; more input is needed.     Syntax::sntxi: Incomplete expression; more input is needed .        2. What can I do to make Mathematica interpret it such that this derivative is zero? I would like to continue to be able to define functions such as `a[t_][b] := f[t]`.


How to remove redundant {} from a nested list of lists?

There are numerous examples here, whose end result is the removal of empty brackets `{}` and empty lists. I still can't find an example of simply removing redundant brackets though. It's hard for me to believe there isn't already a common solution to this problem. Please point me there if I missed it. As I am new to _Mathematica_ I am learning primarily by example so when I ran into this problem I was at a loss of where to even start. For example I have this list as INPUT to a new function: > {   >  {{{0, 5}, {1, 4}, {2, 3}, {3, 2}, {4, 1}, {5, 0}}},   >  {{{1, 5}, {2, 4}, {3, 3}, {4, 2}, {5, 1}}},   >  {{{2, 5}, {3, 4}, {4, 3}, {5, 2}}},   >  {{{3, 5}, {4, 4}, {5, 3}}},   >  {{{4, 5}, {5, 4}}},   >  {{{5, 5}}, {{5, 5}}}   >  } I would like the new function to generate this list as OUTPUT: > {   >  {{0, 5}, {1, 4}, {2, 3}, {3, 2}, {4, 1}, {5, 0}},   >  {{1, 5}, {2, 4}, {3, 3}, {4, 2}, {5, 1}},   >  {{2, 5}, {3, 4}, {4, 3}, {5, 2}},   >  {{3, 5}, {4, 4}, {5, 3}},   >  {{4, 5}, {5, 4}},   >  {{5, 5}, {5, 5}}   >  } * * * The actual input TO new function:               {{{{0, 5}, {1, 4}, {2, 3}, {3, 2}, {4, 1}, {5, 0}}}, {{{1, 5}, {2, 4}, {3, 3}, {4, 2}, {5, 1}}}, {{{2, 5}, {3, 4}, {4, 3}, {5, 2}}}, {{{3, 5}, {4, 4}, {5, 3}}}, {{{4, 5}, {5, 4}}}, {{{5, 5}}, {{5, 5}}}}      The actual output FROM new function:               {{{0, 5}, {1, 4}, {2, 3}, {3, 2}, {4, 1}, {5, 0}}, {{1, 5}, {2, 4}, {3, 3}, {4, 2}, {5, 1}}, {{2, 5}, {3, 4}, {4, 3}, {5, 2}}, {{3, 5}, {4, 4}, {5, 3}}, {{4, 5}, {5, 4}}, {{5, 5}, {5, 5}}}


Combining Graphics & ContourPlot using Show

I was recently experimenting in _Mathematica_ and was combining graphics and a contour plot and discovered the order of elements in show matters. Why would the order matter here?               Remove[g,c];     g = Graphics [Arrow[{{0,0},{1,1}}],PlotRange->{{-5,5},{-5,5}}];     c = ContourPlot[x^2+y^2,{x,-5,5},{y,-5,5}];     {Show[g,c],Show[c,g]}      ![enter image description here](http://i.stack.imgur.com/vrRt2.gif) ![enter image description here](http://i.stack.imgur.com/xm3Fj.gif)


Adding and summing overlapping Airy (or Gaussian) disks on a plane

In a previous question of mine, I asked how one might draw an Airy disk on a plane: Generating an Airy disk on a plane, and recieved some impressive answers from the users Timothy Wofford and m_goldberg Might it be possible to have a 2D plane in the contexts of a Graphics3D environment, and generate an Airy disk wherever one clicks (a simpler 2D Gaussian curve would also be just fine)? Or, perhaps more simply, to generate such disks at a specified set of two-dimensional coordiantes? The hope is that this can be done s.t. overlapping sections of one or more curves can be summed.


Comparative Statics on Mathematica

Let me first explain what I am doing then I will mention my little problem that I could not figure out. I am using Mathematica version 7. I have an equation named " ** _fd_** " and I took the derivative of " ** _fd_** " with respect to **_t_** which I will note the outcome as **_Dfdt_**. Basically, I am trying to understand if **_Dfdt_** is negative or positive (Comparative Statics) and in order to do this I put some assumptions on the parameters in the simplify function which will be seen in my code below. However, as a outcome I get a general restriction outcome which satisfies **_Dfdt_** being positive or negative. Are there any possible methods/codes to take out the parameters values which satisfies **_Dfdt_** being positive or negative ?                     In[54]:=           Remove["Global`*"]           q = 1 - p;           fd = (b d (p - q) Y1 Y2 (p Y1 - q Y2) +            a p q t (Y1 + Y2)^2 (p (-1 + Y1^2) Y2 +            q Y1 (-1 + Y2^2)))/(a p q t (Y1 + Y2)^2 (p (-1 + Y1^2) Y2 +            q Y1 (-1 + Y2^2)));           Dfdt = D[fd, t]           Simplify[Dfdt > 0,  Y2 > Y1 > 0 && t > 0 && 1 > a > 0 && 1 > b > 0 && 1 > d > 0               && 1 > p > 0 ]           Simplify[Dfdt < 0,  Y2 > Y1 > 0 && t > 0 && 1 > a > 0 && 1 > b > 0 && 1 > d > 0               && 1 > p > 0 ]                     Out[55]:= 1/t - (b d (-1 + 2 p) Y1 Y2 (p Y1 - (1 - p) Y2) +            a (1 - p) p t (Y1 + Y2)^2 (p (-1 + Y1^2) Y2 + (1 - p) Y1 (-1 + Y2^2)))/(a (1 - p) p t^2 (Y1            + Y2)^2 (p (-1 + Y1^2) Y2 + (1 - p) Y1 (-1 + Y2^2)))                   Out[56]:= (-1 + 2 p) (-Y2 + p (Y1 + Y2)) (p Y2 - p Y1^2 Y2 + (-1 + p) Y1 (-1 + Y2^2)) > 0           Out[57]:= (-1 + 2 p) (-Y2 + p (Y1 + Y2)) (p Y2 - p Y1^2 Y2 + (-1 + p) Y1 (-1 + Y2^2)) < 0