title: Plotting Fourier spectrum versus frequency of a signal

text: I have looked around here, and i am sure this has been answered, but i don't understand it. The thing is, I have taken a introductory signal processing course, and we had to use Mathematica, and i had no previous experience in Mathematica, so this made a lot of things hard for me. Now i need to understand how to visually present the spectral content of a sampled signal. So i try something simple,               sampls = Table[Sin[n*(2 \[Pi])/1000*4], {n, 0, 2000}];      where we can assume that the sampling period is 1/1000s and we have a sinus with a frequency of 4 Hz. This signal is sampled for 2 seconds, meaning we get 8 periods of the signal. ![Plot of samples](http://i.stack.imgur.com/P5GBm.gif) Now my naive attempt is to do this (as i saw something like this in some example somewhere):                ListLinePlot[Abs[FourierDCT[sampls]], PlotRange -> {{0, 100}, {0, 30}}]      Now i end up with this: ![output from above statement](http://i.stack.imgur.com/yd0rb.gif) which i can't make any sense out of... What does it mean? My dream is to be able to plot frequency on the x-axis and amplitude on the y-axis, so that i could present the teacher with a nice narrow peak with height 1 right above 4 on such a plot. My mathematical knowledge is rather weak, i'm sorry to say, so be gentle with me and explain as concrete as possible. This is not primarily a mathematics course.


title: What is the fastest way to split a number into parts?

text: I have very large numbers (million digits). number = A*10^partlen + B As of now, I split the numbers by this way:                TotalLen = IntegerLength[a];       partlen = IntegerPart[TotalLen/2];      Print[First[Timing[A = IntegerPart[number/(10^partlen )]]]];      Print[First[Timing[B = Mod[number, 10^partlen ]]]]      And the timings for a 6 million digits number are:               4.703          0.36      Converting the number to strings and rebuilding the parts is even slower than this. Is there any faster way?


title: Appearance in Checkbox does not work

text: I'm experiencing strange behavior in `Checkbox` with `Appearance`:               Table[Checkbox[Appearance -> a], {a, {Tiny, Small, Medium, Large}}]      (Copied from the help file) doesn't give me any difference in size. Screenshot: ![checkbox sizes screenshot](http://i.stack.imgur.com/77k73.png) `CheckboxBar` has the same behavior. _Mathematica_ seems to ignore the `Appearance` setting. I'm running mma 8.0.4.0 on Ubuntu 12.10 (64-bit). **Question: Is this a bug or just a non-existing but nonetheless documented feature?**


title: Partial differential equation: unexpected result from changing boundary region size

text: I am trying to solve a PDE for heat diffusion, but I have a problem with the boundary region. When I change the boundary region size, the estimation of temperature increases even when no other parameter is changed. Here is my code. Boundary region [-10, 10] in x and y               eq1 = Derivative[0, 0, 1][f][x, y, t] -         0.14*(Derivative[2, 0, 0][f][x, y, t] +            Derivative[0, 2, 0][f][x, y, t]) == Exp[-(x^2/(2^2) + y^2/(2^2))]          ic = {f[x, y, 0] == 24};     bc = {f[-10, y, t] == 24, f[10, y, t] == 24, f[x, -10, t] == 24,         f[x, 10, t] == 24};     sol1 = NDSolve[{eq1, ic, bc},        f, {x, -10, 10}, {y, -10, 10}, {t, 0, 1200}]      Boundary region [-40,40] in x and y               Plot[Evaluate[{f[0, 0, t] /. sol1[[1]], u[0, 0, t] /. sol2[[1]]}], {t,        0, 1200}, PlotRange -> All, Frame -> True]          Plot[Evaluate[{f[x, 0, 1] /. sol1[[1]],         u[x, 0, 1] /. sol2[[1]]}], {x, -10, 10}, PlotRange -> All,       Frame -> True]      ![Mathematica graphics](http://i.stack.imgur.com/L8bSR.png) Time history of heat in the interior at (0,0) ![Mathematica graphics](http://i.stack.imgur.com/XVDtQ.png) Spatial distribution of heat at t = 1 and y = 0 for x in [-10, 10]


title: Sum over binary digits of integer

text: This might seem like a simple enough question but Mathematica seems to simplify inadequately here:   How would you sum over the digits of an arbitrary binary number?   I already tried this:               Total[IntegerDigits[j, 2]]      which immediately simplifies to an incorrect $j+2$   In fact all               Total[IntegerDigits[j, n]]      simplify to $j+n$   After that, I tried this:               Sum[i, {i, IntegerDigits[j, 2]}]      which simplifies to another incorrect               1/2 IntegerDigits[j, 2] (1 + IntegerDigits[j, 2])      Is there any way, I can prevent these erroreous simplifications?   I need a solution that will work if I use it in another sum which, I ultimately hope, simplifies to something correct. If you want to see what I need this for, it's for another now solved problem on Mathematics StackExchange.


title: How to color separate a colored-in-pencil drawing?

text: I'd like to pick out just the "pencil" color in some drawings done by a young member of the household (he'd like to print out copies of these pictures and distribute them to his class mates on the last day of school, but has already colored them). I tried `Binarize`, which allows me to craft a color selection function, picking levels of each of Red, Green, or Blue. For example:               Clear[ girl, boy ] ;     boy = Import[ "http://imgur.com/mRRhOgo.jpg" ]     girl = Import[ "http://imgur.com/Q5ReXSX.jpg" ]     Binarize[ girl, #[[1]] > 0.8 & ]     Binarize[ girl, #[[2]] > 0.8 & ]     Binarize[ girl, #[[3]] > 0.8 & ]      The last works fairly well, but happens to leave a really dark section by the red belt. I figure it should be possible to code a color selection function that picks only things in the range of the gray pencil colored text, but I'd have to figure out what that color is first, and am not sure of a good approach to do that (other than sampling specific pixel values). I'd imagine this problem could be solved by sorting the image points by color and picking the dominant ones. Then find the "gray colors" or ranges of those grays, and finally coding an image function selection for binarize to pick that color or range of colors. However, it's not clear to me exactly how to go about doing that. EDIT: It looks like http://mathematica.stackexchange.com/a/5415/10 provides reasonable looking instructions on how to pick out just one color, so the problem may be reduced to just finding that "pencil" color. I've tried the Manipulate sliders in some of the other answers for that question, but find them very slow to update ( especially that of http://mathematica.stackexchange.com/a/5407/10 ) EDIT2: I see http://mathematica.stackexchange.com/a/4795/10 provides a locator based way of picking a color, which can probably be used to solve the find the "pencil" color part of the problem (although I'm still not sure how various darknesses of the pencil lines would be dealt with).


title: A debug utility to print or extract intermediate data from a program

text: Is there a way to print variables using their names, or to extract the corresponding information for later analysis ?


title: Position of axes labels

text: I have a 2D parametric plot like the following:               ParametricPlot[       {Sin[t], Cos[t]}, {t, 0, 2 \[Pi]},       Frame -> True, AxesLabel -> {x, y}, AxesStyle -> Arrowheads[0.04], PlotRangePadding -> 0.2     ]      ![wrong labels](http://i.stack.imgur.com/AYko2.jpg) But I would like the axes labels `x, y` to be positioned besides the arrowheads (i.e. `y` left of the vertical arrowhead and `x` just below the horizontal one). Since I can't use the frame as a replacement for the axes (as the axes are in the middle, not at the edge), I believe I cannot use the approach suggested in this question. How could I achieve this?


title: Solving Coulomb Integral

text: I am trying to solve so-called Coulomb Integral of two Gaussians:               Integrate[Exp[(-b1 (-c1 + x1)^2 - b2 (-c2 + x2)^2)/Sqrt[(x1 - x2)^2]], {x1, -Infinity,      Infinity}, {x2, -Infinity, Infinity}],      where $b1$ and $b2$ must be positive parameters, and $c1$ and $c2$ any real parameters. The denominator seems to be very nasty so I could not solve the integral. Any ideas how to tackle this problem?


title: Dashed mesh behind 3D object

text: I am trying to create a simple, almost transparent 3D sphere with a mesh that is made of solid lines if they are on the front surface (i.e. if they are directly visible) and of dashed lines if those lines happen to be in the back of the sphere (i.e. not directly visible). I cannot think of an easy way of doing it without involving an explicit calculation of what part of the sphere is directly visible, given the viewpoint, and what part is not... Any ideas?


title: Evaluating InterpolatingFunction returned by NDSolve is very slow starting from some arguments

text: I use this code to solve a PDE:               a = 20;     F[x_, t_] = f[x, t] /. First@NDSolve[{D[f[x, t], x, x] == I D[f[x, t], t],          f[-a, t] == 0,          f[a, t] == 0,          f[x, 0] == Sin[Pi/a (x - a)]},          f[x, t], {x, -a, a}, {t, 0, 700}, MaxStepSize -> 0.005 a]      It gives the correct solution for all `t` until about 650. But if I take `t` higher, see what happens:               AbsoluteTiming[Table[F[x, 650], {x, -a, a}];]     AbsoluteTiming[Table[F[x, 695.1], {x, -a, a}];]      > {0.000925, Null} > > {2.382157, Null} Threshold for `t` appears to be about $666.6$. It appears to be orders of magnitude slower at evaluating the interpolating function. What's the reason for this? **EDIT** : Using `NDSolve` option `InterpolationOrder -> All` works around this.


title: How to keep some of the results of the NestList

text: I'm using some iterative arithmetics to calculate wave propagation with the help of NestList. I have to use a small step size for iteration to guarantee the accuracy, which lead to too much data (e.g, 10^6 points) for further plotting, and the results consumes too much memories. Is there any clever way to cope with it? I didn't intend to use loops. This is a simplified example:               NestList[Sin, 1, 10^6]      One of my idea is to use `Sow` and `Reap`. But I've no idea to integrate them with `NestList` or `Nest` Any idea???


title: String pattern search and replacement -- it works, but produces error messages only the first time it is called

text: I defined a function in _Mathematica_ to process a pre-generated string. More specifically, I'd like to process some parts of C codes generated from MMA. Basically what my function does is to expand the `pow` function in C, so it involves finding a string pattern and replacing it. I know using MMA is not the best way to solve this problem, but unfortunately the language I'm most familiar with is MMA...Anyway, here's my function:               ExpandPowInCode[code_] :=        StringReplace[code, Shortest["pow(" ~~ x__ ~~ "," ~~ y__ ~~ ")"] ->          If[StringMatchQ[x, ___ ~~ "+" ~~ __] ||             StringMatchQ[x, ___ ~~ "-" ~~ __],            Nest[StringJoin["(" <> ToString[x] <> ")", "*" ~~ #] &,              "(" <> ToString[x] <> ")", ToExpression[y, InputForm] - 1],            Nest[StringJoin[x, "*" ~~ #] &, x, ToExpression[y, InputForm] - 1]]]      It works as I expected, namely expanding , for example, `"pow(x,2)"` into `"x*x"`. The `If` condition will help when dealing with plus/minus sign in the first argument of `pow`. For example,               ExpandPowInCode["pow(a x+b,3)"]      > `"(a x+b)*(a x+b)*(a x+b)"` However, at the first time I executed `ExpandPowInCode`, I always got the following error messages: > `StringMatchQ::strse: String or list of strings expected at position 1 in > StringMatchQ[x,___~~+~~__]. >>` > > `StringMatchQ::strse: String or list of strings expected at position 1 in > StringMatchQ[x,___~~-~~__]. >>` Although `ExpandPowInCode` still gave me the correct result, the appearance of error messages was really annoying...Moreover, when I executed the function again later, the error messages no longer appeared as if everything were correct. Has anyone ever met this odd situation?


title: Fixed color scale in multiple density plots with Fixed PlotLegends scale

text: From the great answer of Mr. Wizard, I would like to learn how to implement the associated PlotLegends scaled too. Here is the simplest example with PlotLegends, which does not look to be scaled:               data = {{{2, 4, 5, 4}, {3, 3, 7, 2}, {7, 2, 6, 5}, {7, 4, 8, 2}},              {{2, 1, 7, 9}, {3, 2, 1, 8}, {3, 3, 9, 7}, {0, 9, 7, 9}},              {{2, 2, 9, 0}, {5, 7, 0, 9}, {6, 9, 1, 9}, {5, 3, 8, 8}}};          Table[ListDensityPlot[Rescale[data[[i]], {0, 9}],      ColorFunctionScaling -> False, Mesh -> All,      ColorFunction -> "TemperatureMap", PlotLegends -> Automatic], {i, 1, 4}]      The first legend shows a different scale from the other three.


title: How do I choose only one branch of ArcTan?

text: I have a problem concerning `ArcTan` drawing a graph using `ListPlot`. I import a table of data:               a = Import["D:\2_b=10a.txt", "Table"];      Then I write:               ListPlot[Table[{i*0.005 Pi, -ArcTan[(a[[i]][[1]] -         a[[i - 1]][[1]]), (a[[i]][[2]] - a[[i - 1]][[2]])]}, {i, 2, 401, 1}]], PlotRange -> {{0, Pi}, {-4, 4}}]      The returned graph looks like ![this](http://i.imgur.com/lBZ0jLt.png) I know from the nature of my calculations that the function must be continuous on the interval $[0,Pi]$, but at $3Pi/4$ the `ArcTan` function goes to another branch, since `ArcTan[x,y]` chooses a quadrant. How could I possibly try to move the bottom part of the plot up by Pi, so the function is smooth and continuous? I tried defining a function               myArcTan[x_] := Piecewise[{{ArcTan[x] + Pi, x < 0}, {ArcTan[x], x > 0}}];      but it doesn't work. Thank you very much.


title: choosing the fastest way of finding position

text: I have this list `{1,7,8,10}` for instance. and a second list which is always smaller or equal to the first one say `{10,7}`. How can I find the position of the elements of the second list in the first list: the answer to above example is `{2,4}`. but I want the answer in this form: `{0,1,0,1}` which implicitly gives `{2,4}`.


title: Equating coefficients in a non-power-series equation

text: How can I use _Mathematica_ to equate coefficients in a non-power-series equation? For example, I would like to take an equation like the following: $$af_x+\frac{b}{2}f_xf_y+chf_x=f_x+e^af_x+3f_xf_y+2bhf_x$$ and produce the following system: $$a=1+e^a$$ $$\frac{b}{2}=3$$ $$c=2b$$ **EDIT:** This is a rather small example. If possible, I would prefer a solution that requires minimal human inspection of the original equation. The equations I will be working with will have many, perhaps hundreds of partial derivative terms, and it would be unfeasible to do things like individually pick them out. Ideally, I would like to specify only the unknowns I am interested in (in this case, {a, b, c}) and let _Mathematica_ take it from there.


title: How to simulate the response of a linear parametric varying system in Mathematica?

text: Consider the following system \begin{align} \dot{x}(t)&=\sum_{i=1}^{2}\rho_{i}(x(t))\left[A_{i}x(t)+B_{i}u(t)\right]\\\ y(t)&=Cx(t) \end{align} with:               a1 = {{-3, 2}, {-0.25, 1}}     a2 = {{-1.9, -0.4}, {-2.24, -4.7}}          b1 = {{0.25}, {1}}     b2 = {{-2.5}, {1}}          c = {{1, 0.5}, {0, 1}}      where $$\rho_1(x_1(t))=\frac{1-\tanh(x_1(t))}{2},\quad\rho_2(x_1(t))=1-\rho_1(x_1(t))$$ How do I build the state-space LPV system? The response, for example, to a sinusoidal input? I want to translate this code from MATLAB to _Mathematica_               A(:,:,1)=[-3 2; -0.25 1];     A(:,:,2)=[-1.9 -0.4 ; -2.24 -4.7];     B(:,:,1)=[0.25;1] ; B(:,:,2)=[-0.25; 1];     C=[1 0.05; 0 1];%     xx=[0.1; 0]; %initial conditions     mus(1,:)=[0.5 0.5 1]; %initial rhos          %%simulation loop          for k=1:tmax/Te              %% System             t(k+1)=t(k)+Te; %%time vector;              mus(1)=(1-tanh(xx(1,k)))/10  ;  % weigting functions         mus(2)=1-mus(1);              u(k+1)=10*sin(t(k)); %%input         Aa=mus(1)*A(:,:,1)+mus(2)*A(:,:,2);         Ba=mus(1)*B(:,:,1)+mus(2)*B(:,:,2);              %%Euler to solve the ODES         xx(:,k+1)=xx(:,k)+Te*(Aa*xx(:,k)+Ba*u(k) );         y(:,k+1)=C*xx(:,k+1);  %output     end          plot(t,mus,t,mus(:,1)+mus(:,2) );     plot(t,y);


title: Efficiently determining if a morphological component overlaps a polygon with vertices at real number coordinates

text: I have a list of morphological components $m$, a set of vertices for a polytope $P$ (at real number coordinates), and I'd like to be able to calculate a list of morphological components $m'$ that anywhere overlap the area of $P$. I can do this by approximating each pixel as a point, and calculating a winding number for these points with respect to $P$ to determine if they fall within the polygon's area. However, this is hardly an efficient strategy, and it's not as exact as I would like. My hope is to have a scheme to detect if the polygon crosses _any_ square bright pixel region. Is there a clever way to do this that works very quickly?


title: How to tell mathematica not to resolve stiffness issues

text: Very often I solve partial differential equations that are nonlinear and could be up to 4th order. In these cases, it is usual for the solution determined by `NDSolve` to be stiff during a later stage. What I suspect `NDSolve` does in this case is to resolve the stiffness until the error/local accuracy is very poor. That is when it quits the problem and gives you an Interpolating function polynomial. Whilst using the BDF method to MaxOrder of 1 for instance, is there someway to tell Mathematica to quit as soon as stiffness is encountered in the solution so that I save time? I don't want to resolve the stiff portion and just stop my solution just as it gets stiff. The below example looks like a mess in plain text but it copies fine. It gets stiff at t=4806. However, is lots of problems, NDSolve lingers at the time at which stiffness is achieved to try and resolve the features that I would like to circumvent completely. I will obv. look into the stiffness switching stuff again. ## Example               {xMin,xMax}={-4\[Pi]/0.0677,4\[Pi]/0.0677};          k=0.0677/4;          TMax=5000;          uSolpbc[t_,x_]=u[t,x]/.NDSolve[{\!\(     \*SubscriptBox[\(\[PartialD]\), \(t\)]\(u[t, x]\)\)==-100\!\(     \*SubscriptBox[\(\[PartialD]\), \(x\)]\((     \*SuperscriptBox[\(u[t, x]\), \(3\)]\      \*SubscriptBox[\(\[PartialD]\), \(x, x, x\)]u[t, x])\)\)+1/3 \!\(     \*SubscriptBox[\(\[PartialD]\), \(x\)]\((     \*SuperscriptBox[\(u[t, x]\), \(3\)]\      \*SubscriptBox[\(\[PartialD]\), \(x\)]u[t, x])\)\)-5 \!\(     \*SubscriptBox[\(\[PartialD]\), \(x\)]\((     \*SuperscriptBox[\((     \*FractionBox[\(u[t, x]\), \(1 + u[t, x]\)])\), \(2\)]\      \*SubscriptBox[\(\[PartialD]\), \(x\)]u[t, x])\)\),u[0,x]==1-0.1 Cos[k*x],     u[t,xMin]== u[t,xMax],     Derivative[0,1]u[t,xMin]==Derivative[0,1]u[t,xMax],     Derivative[0,2]u[t,xMin]==Derivative[0,2]u[t,xMax],     Derivative[0,3]u[t,xMin]==Derivative[0,3]u[t,xMax]},     u,     {t,0,TMax},     {x,xMin,xMax},     MaxStepFraction->1/150][[1]]


title: Fitting parameters of user defined function returning discrete values

text: So, I'm fairly new to Mathematica (apologies in advance for the noobiness), and I'm having some problems regarding fitting the parameters of a user defined function to data. I'll give a representative toy example of what I'm trying to accomplish. Imagine that I have data that is comprised of two lists:               TestData = {       {1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15},       {4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}     };      And I have a model/function that itself produces discrete data such as this. This function would be something like:               TestFunction[A_, B_] :=          Module[{results = {}, vec1 = {}, vec2 = {}},              For[i = 1, i < 18, i++, Do;                [vec1 = Append[vec1, (A - i)];                 vec2 = Append[vec2, (B + i)]]];             results = Append[results, vec1];             results = Append[results, vec2];             results]      Now, I want to find the parameters A and B that give the best approximation to TestData (i.e., such as the distance between TestData and the results of the function would be minimized). I tried looking into the FindFit and NonlinearModelFit functions, but these would seem to be more suited for continuous functions(?), so I'm not sure how to use it with a function that returns specific and discrete values. How would you go about solving this question? Thank you very much in advance.


title: How to print prime numbers

text: I want to know how can I print out a list of prime numbers. Should I use `For`, `Do`, `If`, maybe `Mod`, but If I can - no prime. How should I approach this problem ?


title: Filtering and Replacing outliers

text: I have a set of data that measurements of temperature vs time (date). It is easy to realize when the sensor went wrong as one might see a blip on the data. How to teach to Mathematica to: 1) Detect the "Blip" 2) Delete this Blip 3) Replace the corrupted point for one derived as the mean of the previous data (before the corrupted one) and the one after (after the corrupted one). Thanks in advance !!! I have tried to setup a test in which each pair of data were compared and if the difference between them was greater than 3 C (or 5C depending how rigorous you want to be). But my reasoning did not work properly. Thanks in Advance Ed The dataset is:               l = {{"2013-11-20 23:00:00", 23.52}, {"2013-11-21 00:00:00",        23.55}, {"2013-11-21 01:00:00", 23.62}, {"2013-11-21 02:00:00",        23.61}, {"2013-11-21 03:00:00", 23.53}, {"2013-11-21 04:00:00",        23.45}, {"2013-11-21 05:00:00", 23.52}, {"2013-11-21 06:00:00",        23.4}, {"2013-11-21 07:00:00", 24.02}, {"2013-11-21 08:00:00",        26.7}, {"2013-11-21 09:00:00", 27.54}, {"2013-11-21 10:00:00",        29.67}, {"2013-11-21 11:00:00", 28.3}, {"2013-11-21 12:00:00",        17.94}, {"2013-11-21 13:00:00", 27.42}, {"2013-11-21 14:00:00",        25.82}, {"2013-11-21 15:00:00", 24.61}, {"2013-11-21 16:00:00",        23.91}, {"2013-11-21 17:00:00", 24.58}, {"2013-11-21 18:00:00",        24.31}, {"2013-11-21 19:00:00", 23.18}, {"2013-11-21 20:00:00",        28.99}, {"2013-11-21 21:00:00", 22.56}, {"2013-11-21 22:00:00",        22.01}}      ![TempPlot](http://i.stack.imgur.com/Xy3mJ.jpg)


title: How to reconstruct a missing data point

text: In the output of a large computer simulation(thousands of cpus for 3 days), I found that one data point is missing in the result. Is it possible to reconstruct the missing value using the remaining data? Assumptions: The dynamics in the data is generally smooth and there is no shape feature in it. Here is the data:               data={-0.0949456,-0.2232,-0.15012,0.0364052,0.0841621,-0.0920731,-0.273141,-0.183935,0.0656169,0.140269,-0.0843562,-0.332979,-0.228146,0.0969235,0.208076,-0.0696226,-0.402307,-0.284266,0.128555,0.287427,-0.0454046,-0.479687,-0.353367,0.158121,0.377113,-0.00921489,-0.56245,-0.43569,0.182807,0.474626,0.0409945,-0.646659,-0.530218,0.199767,0.576109,0.106226,-0.727344,-0.634338,0.206674,0.676612,0.185864,-0.799108,-0.743778,0.202287,0.770614,0.277269,-0.856969,-0.852921,0.18688,0.85286,0.,-0.897303,-0.955487,0.162245,0.919149,0.475145,-0.91851,-1.04548,0.131507,0.967006,0.568474,-0.921269,-1.11803,0.0983087,0.995824,0.649178,-0.908188,-1.17004,0.0660878,1.00669,0.711966,-0.883046,-1.20025,0.0374795,1.00158,0.753415,-0.849936,-1.20902,0.0140558,0.983158,0.772116,-0.8123,-1.19776,-0.00394007,0.953394,0.768557,-0.772323,-1.16867,-0.0170188,0.914086,0.744676,-0.731382,-1.12393,-0.0260316,0.866382,0.703393,-0.689571,-1.06621,-0.0322879,0.811196,0.648481,-0.646799,-0.997935,-0.0368642,0.74929,0.583615,-0.602475,-0.921481,-0.0407482,0.681664,0.513284,-0.555671,-0.839684,-0.0446284,0.609182,0.440653,-0.507031,-0.755086,-0.0489018,0.533683,0.369238,-0.456793,-0.669996,-0.0537497,0.457136,0.301312,-0.405981,-0.586799,-0.0589172,0.381381,0.238713,-0.355861,-0.507526,-0.064281,0.308536,0.182517,-0.30782,-0.433796,-0.0694734,0.240373,0.133182,-0.263169,-0.366831,-0.0741541,0.178336,0.0906948,-0.222976,-0.30744,-0.0780402,0.123434,0.0547048,-0.187986,-0.25604,-0.0809698,0.0762321,0.0246802,-0.158568,-0.212644,-0.0828802,0.0368173,0.};      Also from other output information, I can determined that the problem data is at the index 51, which is set to 0 in the above. So is it possible to reconstruct that value? * * * Here is my try: I use the wavelet transform to identify the abrupt changes in the data, and manually adjust the data value, until I get a relative smooth wavelet transform.               Manipulate[      data1 = data;      data1[[51]] = data[[51]] + Abs[Mean[{data[[50]], data[[52]]}]]*x;      cwd = ContinuousWaveletTransform[data1,         GaborWavelet[10], {Automatic, 12}];      values = Abs[cwd[All, "Values"]];      ListDensityPlot[values, ColorFunction -> "TemperatureMap",        PlotRange -> {All, {0, 50}, {0, 0.1 Max[values]}},        ClippingStyle -> Automatic, InterpolationOrder -> 0]      ,      {x, -10, 30, 1}      ]      ![enter image description here](http://i.stack.imgur.com/hKSUz.gif) Form above I determined by eye that when x=17 the wavelet is smoothest. So the missing data I get is 0.377765. And here is a plot of the data and the wavelet transform after the fix ![enter image description here](http://i.stack.imgur.com/cegjj.png) ![enter image description here](http://i.stack.imgur.com/TVe3b.png) **Question** :   1. What are the general ways of reconstruct missing data?   2. Are there other methods to reconstruct the missing data, without looking by eye?


title: Navier–Stokes equations

text: how write Stokes equation in mathematica? the Stokes equation is in in this link http://en.wikipedia.org/wiki/Navier- Stokes_Equations


title: Release the web camera after using CurrentImage[]

text: `CurrentImage[]` will capture an image from the webcam. It is even possible to create a live video in the notebook using               Dynamic@CurrentImage[]      After using this function even a single time, Mathematica will not switch off or release the webcam any more, making it impossible to use the webcam from other programs on some systems. How can I switch off / release the webcam from Mathematica, without quitting Mathematica completely?


title: Total weight of a graph

text: I need to find the total weight of an `WeightedAdjacencyGraph`. I have a graph in that form               a = WeightedAdjacencyGraph[{...},{...},{...}....etc]      How can I find its total weight?


title: Rearrange graph

text: I have to rearrange graph described by               j = {1 -> 2, 2 -> 3, 3 -> 1};      appling some function to all vertices on the right so rearrange[j] output should give me               {1 -> f[2], 2 -> f[3], 3 -> f[1]}      I guess I can use ReplaceAll, but can't guess how.


title: Extra factors appear when evaluating Euler integrals

text: **Note: this is fixed in version 9.** * * * When I perform the double integral in _Mathematica_ ,               Integrate[(x (1 - x))^z (y (1 - y))^z, {x, 0, 1}, {y, 0, 1}]      which should give $$B(z+1,z+1)^2 = \frac{\Gamma(z+1)^4}{\Gamma\left(2(z+1)\right)^2}$$ where $B(x,y)$ is the Beta function and $\Gamma(z)$ is the Gamma function because the integral is a product of two Beta functions, I instead get this ratio of Gamma functions _times the extra factor $(-1)^{2z}$_. What is going on here? To make matters stranger, if I do the integral instead using two nested calls to Integrate (one to integrate out $x$ and one to integrate out $y$), I get the ratio of Gamma functions without the incorrect extra factor.


title: What does "suitable for symbolic manipulation" in the documentation mean?

text: This question is related to this other one I posted on Stack Overflow some time ago. There, in a beautiful answer, acl (with some unhumble editing done by me) showed that the derivative of `IntegerPart` is calculated numerically by a centered difference method of eighth order. If you read the help for `IntegerPart[]` you'll find: > Mathematical function, suitable for both symbolic and numerical > manipulation. At that time I assumed it was just a documentation (or program) bug. I revisited the problem today because I needed to solve an equation that can be tracked down to something like:               Reduce[IntegerPart@x == x, x, Reals]     (*     -> Reduce::nsmet: This system cannot be solved with the methods available to Reduce. >>     *)      So again, Mma's failure to "symbolically manipulate" the `IntegerPart[]` function is bothering me. And this time, the derivative calculation is not the issue. All these functions `{IntegerPart, FractionalPart, Ceiling, Floor, Round, PrimePi}` share the > Mathematical function, suitable for both symbolic and numerical > manipulation. legend in their help reference. Look at their derivatives:               f = {IntegerPart, FractionalPart, Ceiling, Floor, Round, PrimePi};     GraphicsGrid[      Partition[        Plot[{#[u], D[#[x], x] /. x -> u}, {u, -1, 3},             PlotLabel -> Style[Framed[Hyperlink[#, "paclet:ref/" <> #] &@ToString@#], 16,                               Blue, Background -> Lighter[Yellow]]] & /@ f,        2],       Frame -> All]      > ![Mathematica graphics](http://i.stack.imgur.com/OpUIg.png) Moreover, the help file for `NextPrime[]` doesn't state anything about its symbolic manipulation suitability, and the help for `HeavisideTheta[]` says: > HeavisideTheta can be used in integrals, integral transforms and > differential equations. and its derivative is evaluated as `DiracDelta[]`. When you plot these functions you get: > ![Mathematica graphics](http://i.stack.imgur.com/yQMuy.png) So it seems that from the whole set, only `HeavisideTheta` is treated symbolically. However, when you try:               Reduce[HeavisideTheta@x == 1, x, Reals]     (*     -> Reduce::nsmet: This system cannot be solved with the methods available to Reduce. >>     *)      So the "symbolical manipulation" is not there (or so it looks like). So the question is: **What does it mean for a _Mathematica_ function to be "suitable for symbolic manipulation"?**


title: Strange Behavior when making Equal Listable in Pick

text: While trying to make this problem more efficient I tried different methods and dabbled with making `Greater` and `Equal` `Listable`. To my surprise, while `Greater` worked as expected, `Equal` on the other hand showed a strange behavior. Let's dig deeper: First let's look at `Greater`               Pick[#, DivisorSigma[1, #] > 2 #] &@Range[6]      Gives the error:               Pick::incomp: Expressions {1,2,3,4,5,6} and {1,3,4,7,6,12}>{2,4,6,8,10,12} have incompatible      shapes. >>      Now we make `Greater` `Listable`               SetAttributes[Greater, Listable]      And we can now evaluate the above command successfully               Pick[#, DivisorSigma[1, #] > 2 #] &@Range[20]      > {12, 18, 20} Okay, let's move on to `Equal`               Pick[#, DivisorSigma[1, #] == 2 #] &@Range[8]      > Sequence[] We now make `Equal` `Listable`               SetAttributes[Equal, Listable]     Attributes[Equal]      > {Listable, Protected} Now let's try again:               Pick[#, DivisorSigma[1, #] == 2 #] &@Range[8]      > Sequence[] Hmmm, what's going on here? Well, let's explicitly provide the list and see what happens:               Pick[{1, 2, 3, 4, 5, 6, 7, 8},       DivisorSigma[1, {1, 2, 3, 4, 5, 6, 7, 8}] == 2 {1, 2, 3, 4, 5, 6, 7, 8}]      > {6} Interesting, this works! okay now let's textually substitute using `With`, this should technically be the same thing right?               With[{p = Range[8]}, Pick[p, DivisorSigma[1, p] == 2*p]]      > Sequence[] I guess not. Finally, let's look at `Trace`. I'll shorten the input list here. First with explicit input of list:               Pick[{4, 5, 6}, DivisorSigma[1, {4, 5, 6}] == 2 {4, 5, 6}] // Trace      ![Mathematica graphics](http://i.stack.imgur.com/lKQal.png)               Pick[Range[4, 6], DivisorSigma[1, Range[4, 6]] == 2 Range[4, 6]] // Trace      ![Mathematica graphics](http://i.stack.imgur.com/FlHwM.png) We see that only in the explicit case does `Equal` act `Listable` What is going on here? Sorry about the tiny images.


title: How to get complete Documentation Center graph of guide pages?

text: On the very last image below you can see a typical path of walking through Documentation Center guide pages. **What is the best way to get the graph data and visualize the whole structure of these connections starting from the main table of contents page?** An obvious thing to do is to look for example into directory:               SetDirectory["C:\\Program Files\\Wolfram\\Research                   \\Mathematica\\8.0\\Documentation\\English\\System\\Guides"]          FileNames[] // Column      ![enter image description here](http://i.stack.imgur.com/FvyYQ.png) But I am not sure what is the next most efficient way to analyze the connections. **A walk through guide pages** ![enter image description here](http://i.stack.imgur.com/FhhTh.png) **\------------ UPDATE: image from @Leoind data ------------**               style = {VertexStyle -> White, VertexShapeFunction -> "Point",        EdgeStyle -> Directive[Opacity[.3], Hue[.15, .5, .8]],        Background -> Black, EdgeShapeFunction -> (Line[#1] &),        ImageSize -> 500};          gr = Graph[Union[Sort /@ data], style]      ![enter image description here](http://i.stack.imgur.com/UG4un.png) The origin of self-loops was explained by @R.M in his comment. Almost all guide pages have their own URL at the top navigation bar. Here is the final graph with removed self-loops:               am = AdjacencyMatrix[gr];(am[[#, #]] = 0) & /@ Range[Length[am]];     AdjacencyGraph[am, style]      ![enter image description here](http://i.stack.imgur.com/3nA8O.png)


title: Evaluating function only when its optional argument is numeric

text: I want to have the argument 'a' for myf2 in form of optional argument, but at the same time I need to evaluate the function only if 'a' is Numeric, see also my previous question.               Options[myf2] = {"a" -> 1};     myf2[b_?NumericQ, opts : OptionsPattern[]] := Module[{y, x, a},        a = OptionValue["a"];        If[NumericQ[a], First[y /.NDSolve[{a y'[x] == b y[x] Cos[x + y[x]], y[0] == 1},             y, {x, 0, 30}]][10]]        ];          datamyf2 = {#, myf2[1, #] + 0.01 RandomReal[]}&/@Range[0.5, 1.5,0.1]          model = NonlinearModelFit[datamyf2, myf2[b, "a" -> a], b, a]      When I tried to add the NumericQ test for 'a' in myf2, the problem is that it returns Null upon evaluating with symbol 'y' {myf2[1, "a" -> y]}, instead of leaving it unevaluated at all (as for the case when 'a' was specified as regular argument with a_?NumericQ) How can I than specify that it should have numeric value for 'a' in the option? Thanks!


title: Artistic image vectorization

text: The question is **how can we use Mathematica to create vectorized versions of low-resolution images?** The goal is to get an image suitable for quality printing at any resolution. Since "true" vectorization performed by various specialized software is a tough problem, I suggest to consider "artistic" approaches, which produce inexact, but beautiful version of the original. Colored implementations are highly appreciated.


title: Evaluator option for Mathematica Scripts

text: I have mathematica with many additional kernels besides Local ( e.g., core1, core2, core3, core4 ... ) added through Kernel Configuration Options. I have been running multiple copies of a simulation (mycalculation.nb) in these different cores. The kernel for each notebook was set using this function:               SetOptions[EvaluationNotebook[], Evaluator -> "corei"];      where corei is core1, core 2, .. etc. So all kernels run in parallel without interfering with each other. Now I am trying to automate this and use Mathematica Scripts to run each kernel with my code converted into Input Form (mycalculation.m). When I do that, the above line gives this error message since the "Evaluator" seems to be defined for front end and notebook interface only:               FrontEndObject::notavail: A front end is not available; certain operations require a front end.      Note that my code in "mathematica scripts" form works fine when I skip the "Evaluator" definition. Is there a corresponding option that I can put in the file (mycalculation.m) or in the command line, which is;                MathKernel -noprompt -run "<<mycalculation.m"      so that I can tell MathKernel to execute the rest of the code not in the local kernel but in some other kernel. I could not find it myself.


title: File output and race conditions

text: Is it possible to know when Mathematica is done writing a file? I'm looking to automate something and I'm wanting to have Mathematica put it in a file using `Put[]`, and maybe also `Export[]`. I need to know that the file is complete before dealing with it outside Mathematica, but I don't want to have to exit Mathematica first. How can I be **_sure_** that Mathematica is done writing the file? Any solution is on the table, from waiting for Mathematica to reprompt, to relying on a metafile. I'd like to avoid writing additional data to the file if at all possible, though.


title: Using FindInstance to Prove No Solutions Exist

text: For a small amount of background, I am currently working on an undergraduate research project in Combinatorial Geometry and I'm working on a case analysis for embedding spherical simplicial 2-complexes in $\mathbb{S}^2$ and looking at their properties as they relate to tuples of spheres in arbitrary sphere packings. If that made no sense, no problem. I want to show that there does _not_ exist a solution to the equation:               a + b + c + d + e + f + g + h + i == 16 π - 33 ArcCos[1/3] - ω      where               ω = π - 4 ArcCos[1/3] +      2 ArcCos[(2 (1/2 + 1/8 (-1 - 3 Cos[4 ArcCos[1/3]])))/Sqrt[     3 (1 - 1/16 (1 + 3 Cos[4 ArcCos[1/3]])^2)]]      With some bounds on $a,b,c,d,e,f,g,h,i$. I have tried inputting this into Mathematica as follows (with $\omega$ defined in a previous command)               FindInstance[         a + b + c + d + e + f + g + h + i == 16 π - 33 ArcCos[1/3] - ω &&          ArcCos[1/3] < a < 2 π - ArcCos[1/3] &&          ArcCos[1/3] < b < 2 π - ArcCos[1/3] &&          ArcCos[1/3] < c < 2 π - ArcCos[1/3] &&          ArcCos[1/3] < d < 2 π - ArcCos[1/3] &&          ArcCos[1/3] < e < 2 π - ArcCos[1/3] &&          ArcCos[1/3] < f < 2 π - ArcCos[1/3] &&          ArcCos[1/3] < g < 2 π - ArcCos[1/3] &&          ArcCos[1/3] < h < 2 π - ArcCos[1/3] &&          ArcCos[1/3] < i < 2 π - ArcCos[1/3],          {a, b, c, d, e, f, g, h, i}, Reals     ]      It returns an input of `{}` which means that _Mathematica_ couldn't find any solutions. This is a very good thing for me, but how can I formalize the fact that no such solutions exists other than "Mathematica couldn't find any solutions using the `FindInstance` command"?


title: How to make a list/matrix out of an expression?

text: I would like to make a matrix out out of the following expression: $$ (\Omega^2 (2 d\theta^2 + d\phi^2 - d\phi^2 \cos(2 \theta) \coth(\chi)^2) + (2 d\Omega^2 + (2 d\theta^2 + d\phi^2 - 2 d\chi^2) \Omega^2) \textrm{csch}(\chi)^2)/(2 \Omega^2) $$ so that I get for the 11-components all terms that belong to $d\Omega^2$, for the 22-component all the terms belonging to $d\chi^2$, etc. (As there are no 'cross-terms', the matrix in this case should be diagonal). How do I go about this in _Mathematica_? * * * Code for copying:               (Ω^2 (2 dθ^2 + dϕ^2 - dϕ^2 Cos[2 θ] Coth[χ]^2) +      (2 dΩ^2 + (2 dθ^2 + dϕ^2 - 2 dχ^2) Ω^2) Csch[χ]^2)/(2 Ω^2)


title: How to perform a multi-peak fitting?

text: I am wondering how to implement the multi-peak detecting and fitting in Mathematica. Following is an example of fitting the data using three peaks (such that the data ~ peak1 + peak2 + peak3). ![Illustration of a multi-peak fitting](http://i.stack.imgur.com/tZcHo.png) The peak model is given and fixed (all peaks are fitted by the same model), but its particular form (which will be input) can be Gaussian or Lorentzian or some other customized functions. The number of peaks is unknown and should be detected automatically, and the fitting model must also be built accordingly. Is there a Mathematica function that can simply do this? Or if anyone can give an idea of how to do the multi-peak fitting using Mathematica. (I am aware of fitting functions like `FindFit`,`NonlinearModelFit` etc., so my question is more about how to build the model and estimate the initial parameters for input of the fitting functions.) * * * I am expecting something like this:               PeakFit[data_, pfun_, x_]:=...      where the `data` is a list of points like `{{x1_,y1_}..}`, `x_` specifies the variable to be used, and the peak function `pfun` is a pure function whose first three parameters control the peak height, the peak width, and the central position, and the remaining (optional) parameters are for further control of the shape of the peak. For example a Gaussian model may be described as               pfun = Function[{x}, #1 Exp[-(x - #3)^2/(2 #2^2)]] &;      Given the data and the peak function, I wish `PeakFit` to return a `FittedModel` object containing the resulting model like `pfun[A_,w_,xc_][x]+...`.


title: How to plot a graph from it's incidence matrix?

text: I'm using Mathematica v9 and am trying to draw a graph by using it's incidence graph, but it won't draw it, which occurs an error "is not a valid incidence matrix.". But I've checked my matrix, and it's totally fine. I tried three matrices but error comes out every time. Here are my matrices in input forms. $6\times11$ incidence matrix:               ({{1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0},       {1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0},       {1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1},       {0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0},       {0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0},       {0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1}})         $9\times12$ incidence matrix:               ({{1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0},       {1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0},       {1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1},       {0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0},       {0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1},       {0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0},       {0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1},       {0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0},       {0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0}})      And here's a screenshot of my codes and their errors. ![enter image description here](http://i.stack.imgur.com/gKXzt.png) How do I fix this?


title: How to enlarge $\it{Mathematica}$'s knowledge about certain functions?

text: I'm often troubled with the following task. I need to carry out symbolical computations involving certain special functions. Let me take as an example Barnes gamma-function. It is included in _Mathematica_ 's standard tools under the name of `BarnesG[x]`. However, _Mathematica_ often does not deal with it efficiently. For instance, there is an identity stating `BarnesG[1+x]=Gamma[x]BarnesG[x]` where `Gamma[x]` is Euler gamma function. _Mathematica_ does not seem to "know" it. Execution of               Simplify[ BarnesG[1 + x] - Gamma[x] BarnesG[x]]       results in no real simplification. What is the most efficient way to "teach" _Mathematica_ such kind of identities? The only tool that I'm aware of is to create a corresponding transformation function and then use it in the process of simplification. In the case under discussion transformation function would be               tf[e_] := e /. {BarnesG[1 + x_] :> Gamma[x] BarnesG[x]};      Then evaluation of               Simplify[ BarnesG[1 + x] - Gamma[x] BarnesG[x], TransformationFunctions->{Automatic,tf}]      indeed gives zero. However, it does not help to work with numerical values. For example I still have no simplification for               Simplify[ BarnesG[7/6] - BarnesG[1/6] Gamma[1/6],                TransformationFunctions -> {Automatic, tf}]      So my questions are   1. What is the most convenient way of solving my problem?   2. If the one that I'm already using is OK, then how to extend it to numerical computations?    3. A little bit off topic: how can I bring _Mathematica_ to use new transformation function by default in opposite to explicit indication for this in every `Simplify` command? Any help is appreciated/ I'm sorry if I won't be quick enough with my replies.


title: Estimate parameters of the state space model

text: I'm using Mathematica 9 and its Control Systems functionality. I've searched the references extensively but seem not to be able to find any examples of state space model parameters estimation. All examples show models parametarized already or when they are given symbolic parameters they are not simulated. So my question is whether there're built-in functions that would estimate state space model paramters (including covariance matrices for stochastic inputs and measurements)? If there is none as of now may be you could give me some directions on implementing such procedures myself? **Example problem** Let me provide an example problem which I will borrow from (Zivot et. al, 2003): > Harvey (1985) and Clark (1987) provide an alternative to the BN > decomposition of an I(1) time series with drift into permanent and > transitory components based on unobserved components structural time series > models. For example, Clark's model for the natural logarithm of postwar real > GDP specifies the trend as a pure random walk, and the cycle as a stationary > AR(2) process: > > $y_t=\tau_t+c_t$ > > $\tau_t=\mu+\tau_{t-1}+v_t$ > > $c_t=\phi_1 c_{t-1}+\phi_2 c_{t-2}+w_t$ Now I want to try and estimate this example in Mathematica. First I get the data:               gdp = Differences[Log[CountryData["Russia", {"GDP", {1999, 2013}}][[All,2]]]]      Then I setup a state-space model as follows:               eq = {y[t] == c[t] + τ[t], c[t + 1] == α c[t] + β c[t - 1],      τ[t + 1] == μ + τ[t]}          StateSpaceModel[eq, {{y[t], 0}, {c[t], 0}, {τ[t], 0}},     {}, {y[t]}, t]      So what do I do next in order to estimate the parameters with data?   1. Zivot, E., Wang, J., Koopman, S.J. (2004) State Space Modeling in Macroeconomics and Finance Using SsfPack for S+FinMetrics


title: Is there a method to enumerate the keys/values of System`Utilities`HashTable

text: Lacking from the simple API of `System`Utilities`HashTable` is a method to enumerate the keys/values.               ?System`Utilities`Hash*          HashTable   HashTableAdd    HashTableContainsQ  HashTableGet    HashTableRemove      After creating a hash table               h = System`Utilities`HashTable[];     System`Utilities`HashTableAdd[h, "a", 1];      Various methods to extract its content fail.               h[[1]]     h     DownValues[h]      Any way out?


title: Solving an identity

text: I am trying to solve this identity using _Mathematica_ : $$3 \sqrt{5 \sqrt[3]{37}-16}=\sqrt[3]{a}-\sqrt[3]{b}-c $$ I know that `a`, `b` and `c` are positive integers. I want to find what `a`, `b` and `c` are. I tried               FindInstance[{a >= 1, b >= 1, c >= 1,      3*Sqrt[5*(37)^(1/3) - 16] == (a^(1/3) - b^(1/3) -  c)}, {a, b, c}, Integers]      That did not work. I tried a few more approaches using `FindInstance` but with no luck. Did I miss something or am I using the wrong function? The answer is `a = 1369`, `b = 296` and `c = 2`.


title: Transferring a large amount of data in parallel calculations

text: This question is inspired by one of @whuber's answers Consider the following code:               μ = RandomReal[{0, 1}, 100];     Σ = DiagonalMatrix[Exp[RandomReal[{0, 1}, 100]]];          AbsoluteTiming[      RandomVariate[MultinormalDistribution[μ, Σ], 400000];]      It runs in 3.5 seconds here. Now let's parallelize it:               LaunchKernels[]          AbsoluteTiming[      Join @@ ParallelTable[       RandomVariate[MultinormalDistribution[μ, Σ], 200000], {2}];]      This runs in 6.3 seconds on a 2-core machine---much _slower_. It also uses a lot of memory (which I checked using a process monitor). Now let's suppress returning the results from the subkernels by including a semicolon:               AbsoluteTiming[      Join @@ ParallelTable[       RandomVariate[MultinormalDistribution[μ, Σ], 200000];, {2}];]      This one runs in 2.6 seconds---a speedup. What is happening here? Why is the calculation that returns the result so much slower? Is it a general rule with parallel calculations that returning even moderately large data tends to lead to a significant slowdown? Is the slowdown due to MathLink's performance? Is there anything one could do to avoid the slowdown? **Warning:** This might eat all your memory and force your system to swap! This computer has 6 GB and everything was fine. If you have less memory, reduce the amount of data a bit. * * * ## Solution @Oleksandr's excellent analysis showed that the performance bottleneck is `MemberQ`, in particular that it unpacks all arrays inside the expression tested. This is completely unnecessary, and it's possible to define a more efficient (though more limited) version of `MemberQ`:               memberQ[list_, form_] := Or @@ (MatchQ[#, form] & /@ list)      Note that `MemberQ` only tests at level 1 by default (unlike `FreeQ` which tests at all levels). This made it easy to re-implement the two-argument form of `MemberQ`. We can temporarily change `MemberQ` while executing parallel operations:               ClearAll[fix]     SetAttributes[fix, HoldAll]     fix[expr_] := Block[{MemberQ = memberQ}, expr]          fix@AbsoluteTiming[       Join @@ ParallelTable[          RandomVariate[MultinormalDistribution[μ, Σ],            200000], {2}];]      This runs in 3.0 seconds now, a huge improvement. This is just an illustration of how to fix the performance problem, but the code I showed here is not completely safe to use in its current form. Some notes:   * Changing builtins is always risky, and can easily cause problems   * I used `Block` to localize the change, which reduces the risk. Note that `Block` will not affect calculations in the parallel kernels, so if `fix` is used _only_ on the parallelization functions, in the form `fix@ParallelTable[...]`, then it will only have an effect for these functions, but not for the code that is being parallelized. This reduces the risk further.   * I did not implement the 3-argument form of `MemberQ`. If this is used anywhere in the parallel tools, `fix` will break things. It'd take a bit more work to correctly implement this too, preferably just falling back to the builtin `MemberQ` for this case. There may always be some undocumented behaviour of `MemberQ` which we are not aware of and which differs from `memberQ`.   * I did not implement short circuiting, so `memberQ` will be slower in some cases. This can be fixed as well. These potential problems can largely be fixed with a bit of work, and I believe this method can work well for fixing this particular performance problem of parallel calculations.


title: Programmatically retrieving e-mails from a remote server

text: Mathematica has a function for sending mail (`SendMail`) and can import the `MBOX` format. But what I'd like to do is programmatically _retrieve_ mail from a Gmail account, from within _Mathematica_ on a Windows system. Is this possible? **Use case:** I use MarineTraffic.com's e-mail notifications about ship arrivals to watch interesting ships as they pass by. I'd like to filter incoming messages from them and use data from previous notifications to filter 'seen' ships. I may want to do some automated lookup on ship names too to find those that are more likely to be interesting. A perfect task for _Mathematica_ — if only I could periodically get the new mails and process them!


title: Compatibility of Mathematica Notebooks written on Mac with Windows

text: I wrote a notebook on Mac OS 10.7.4 and run it on Windows XP at work. On my Mac I use a full version of Mathematia 8.0.1.0, whereas on the Windows-system only a trial version (Version 8.0.4.0.). First of all I cannot run the following code on the Windows system (on Mac it works perfect):               ImportData={{"Test1", 5670.`, 0.`, 180.`, 2756.`, 2443.`, 180.`, 1008.`, 2007.`},                 {"Test2", 100.`, 0.`, 3006.`, 1235.`, 9874.`, 4543.`, 3241.`, 5004.`}};           WhitespaceCleaning[string_] :=           StringReplace[           string, (StartOfString ~~ Whitespace) | (Whitespace ~~                EndOfString) :> ""]          OriginalData =        Drop[ImportData, 1] /. {a_, b_, cc_, d_, e_, f_, g_, h_, i_} ->       {WhitespaceCleaning@a, {b, cc, d, e, f, g, h, i}};      However I can get the same result as on my Mac with the following code for my Windows system:               allData=ImportData;     numData=allData[[All,2;;]]     strings0=allData[[All,1]];     stringsWOSpacing=WhitespaceCleaning/@strings0;     OriginalData=Transpose[{stringsWOSpacing,numData}]      The rest of my code runs perfect (I get the same results on both operating systems). However, running my code on Windows provokes many messages (such as Divide::index, Divide::infy, Power::infy, General::stop, Less::nord, LessEqual::nord) which does not happen on my Mac. I don't understand why Mathematica on my Windows system is acting so odd. Does anyone has an idea?


title: RandomVariate with a Discrete Distribution

text: Nature has provided me with a random variable $Z$ taking on the values $0, 1, 2, \ldots$, with probabilities $z_0, z_1, \cdots$. I can sample from the distribution of $Z$ reasonably efficiently (I have done so $2^{28}$ times), and so I have estimates $\hat{z_0},\hat{z_1},\ldots$ of $z_0,z_1,\ldots$. I am interested in the number $f(z_0,z_1,\ldots,z_8)$, where $f$ is an explicit but involved function. Obviously, a good estimate is $f(\hat{z_0}, \hat{z_1}, \ldots,\hat{z_8})$, and a standard way to build a confidence interval is bootstrapping. To do this, I need to sample from the discrete distribution with probabilities $\hat{z_0}, \hat{z_1},\dots,\hat{z_8},q$, ($q$ chosen to make the probabilities add up to 1) and I need to sample $2^{28}$ times (I don't need the samples, just the number of times 1 comes up, 2 comes up, ...), and this process needs to be repeated, say, 1000 times. That's a lot of sampling, and it's going way too slowly. The first law of fast _Mathematica_ code is to use built-in functions. Is there a way to get `RandomVariate` to work with an arbitrary discrete distribution? Any other suggestions for rapidly sampling from an arbitrary distribution (again, I only need the `Tally` of the sampling, not the sample itself)?


title: How to make the Show function work in this case?

text: I can't get this to work, the Show function shows only the first plot. Why this happens and how to solve it?               Show[Plot[x^2, {x, 2, 10}], Plot[1 - x, {x, 1, -10}]]


title: Please explain this short code

text: l = {"BreuschPagan" -> BreuschPagan[data, lm, coords],         "WhitesHeteroskedasticity" -> WhitesHeteroskedasticity[lm, coords]};          f = {"BreuschPagan", "WhitesHeteroskedasticity"}          In[360]:= l /. Rule[f_, _] :> f          Out[360]= {"BreuschPagan", "WhitesHeteroskedasticity"}`      Have tried reading the support but i just dont get it. If I only apply `l /. Rule[f_, _]` the output becomes `_` And why does `l /. Rule[lof_, _] :> f` give the out               {{"BreuschPagan", "WhitesHeteroskedasticity"}, {"BreuschPagan",        "WhitesHeteroskedasticity"}}


title: Why won't my function plot?

text: If I define               g[z_] := Which[       0 <= z <= 0.9,     5*(Min[0.1, z] - Max[0, z - 1]),       0.9 <= z <= 1.1,   5*(Min[0.1, z] - Max[0, z - 1]) + 5*(Min[1, z] - Max[0.9, z - 1]),       1.1 <= z <= 2,                                       5*(Min[1, z] - Max[0.9, z - 1]),       True,              0       ]      and plot using               Plot[g[z], {z, 0, 2}]      I get ![enter image description here](http://i.stack.imgur.com/6Auvv.png) while if I plot using               ListPlot[{#, g[#]} & /@ (Range[1000]/500), PlotRange -> All, Joined -> True]      I get ![enter image description here](http://i.stack.imgur.com/EEG4F.png) which is what I expect. Why does `Plot` fail to plot my function as expected?


title: Extract data from DateListPlot, limited by PlotRange

text: Extracting the _points from a line_ in a ListPlot in this answer uses               points = Cases[Normal@plot, Line[pts_] :> pts, Infinity];      This works in DateListPlot (provided `Joined->True`) (example below, using `Last` to get the y-axis data only)               Clear[test,plot,points];     test={{"2010",1},{"2011",2},{"2012",3},{"2014",4},{"2015",5},{"2016",6}};     plot=DateListPlot[test,Joined->True]     points=Last/@Flatten[Cases[Normal@plot,Line[pts_]:>pts,Infinity],1]      ![enter image description here](http://i.stack.imgur.com/8c2Hx.gif)               (*OUTPUT     {1.,2.,3.,4.,5.,6.}      However, when the plot is limited by `PlotRange` using date values (lower plot), the function returns the entire list of points.               plot2=DateListPlot[test,Joined->True,PlotRange->{{"2012","2015"},{0,6}}]     points2=Last/@Flatten[Cases[Normal@plot2,Line[pts_]:>pts,Infinity],1]      ![enter image description here](http://i.stack.imgur.com/kXEYS.gif)               (*OUTPUT     {1.,2.,3.,4.,5.,6.}      Is there a function, like `points` which can return _only the points displayed on the plot_ in DateListPlot under 'PlotRange` ?


title: MathLink and a function of a real variable

text: I am trying to use a real function of a real variable written in C from Mathematica, my .tm file reads as follows:               :Begin:     :Function:       my_function     :Pattern:        MyFunction[ x_Real]     :Arguments:      { x }     :ArgumentTypes:  { Real }     :ReturnType:     Real     :End:          double my_function(double x) { /* snip */ return ret; }      I can compile with mcc, install the program from within Mathematica, and call my function as MyFunction[1.0], but it won't work if I call it with an integer argument, like MyFunction[1], as it is not automatically converted to a Real and then to a double. How can I make my function work well also with integer arguments? Also I have to apply some numerical Mathematica methods (like NMinimize, NIntegrate) and they fail when evaluating the function for integer values.


title: Numerically solving system of partial differential equation

text: I am trying to solve a system of partial differential equation with boundary conditions. But I got an error message saying `NDSolve::icfail:` Unable to find initial conditions that satisfy the residual function within specified tolerances. Try giving initial conditions for both values and derivatives of the functions. As I understand it, this is due to the absence of a system of equations of derivative with time of function G[t,x] and L[t,x] and solve this system can only be effected by The Numerical Method of Lines.                Remove["Global`*"];      pde = {       (-Derivative[1][Y21][t] - Derivative[1][Y31][t]) == -X20[t] -          X30[t] + Y21[t] - G1[t] (1 - Y21[t] - Y31[t]) + Y31[t],        Derivative[1][Y21][t] == 0.01` - Y21[t] - G1[t] Y21[t],       Derivative[1][Y31][t] == 9.9` + X30[t] - G1[t] Y31[t],       (-Derivative[1][X20][t] - Derivative[1][X30][t]) ==         0.2` + X20[t] - L0[t] (1 - X20[t] - X30[t]) + X30[t] - Y21[t] -          Y31[t],       Derivative[1][X20][t] == 0.79` - L0[t] X20[t] + Y21[t],        Derivative[1][X30][t] == 0.1` - X30[t] - L0[t] X30[t]}      with boundary condition:               BC = {       Y21[0] == 0, Y31[0] == 1,       X20[0] == 0.8, X30[0] == 0,         G1[0] == 10, L0[0] == 1        };          desired = {Y21, Y31, X20, X30, G1, L0};     NDSolve[{pde, BC}, desired, {t, 0, 1000}];      I tried to discretize the system in space using the finite-volume method. (http://reference.wolfram.com/mathematica/tutorial/NDSolvePDE.html). Maybe somebody knows the alternative method of solve that type of equations? It is a system of differential equations describing the process of countercurrent extraction. On top of the extraction column enters the two liquid components. The gas phase enters to the bottom of column. Liquid components have different solubility in the gas phase, due to which they are separated - coming out on top of the column the gas phase enriched by one component and the liquid phase exiting from the bottom - the other. This is the differential material balances for each component in the gas and liquid phases. The boundary conditions are taken from the known composition of the feed liquid phase on top of the column (z = 10) and the known composition of the gas coming from the bottom (z = 0) is also assumed that the initial time t = 0 corresponds to the equilibrium of the two streams at full lack of mixing. All constant parameters I removed for readability equations. Detailed description of the output of the system of equations described in the article: https://www.dropbox.com/s/v3oewg2w3etszbu/article.pdf. The authors solved a similar system using the method of lines in the software package gproms. The system was discretised in space using the finite-volume method. I'm trying to solve this problem in the software package Math, using "MethodOfLines" technique, but unfortunately so far without success. I would be very grateful for any help in this matter. I apologize for my English is not the native language for me.


title: What best practices or performance considerations are there for choosing between Cases, Position, Pick and Select?

text: `Cases`, `Select`,`Pick` and `Position` each have different syntaxes and purposes, but there are times when you can express the same calculation equivalently using either of them. So with this input:               test = RandomInteger[{-25, 25}, {20, 2}]          {{-15, 13}, {-8, 16}, {-8, -19}, {7, 6}, {-21, 9}, {-3, -25}, {21, -18}, {4, 4}, {2, -2}, {-24,  8}, {-17, -8}, {4, -18}, {22, -24}, {-4, -3}, {21, 0}, {19,    18}, {-23, -8}, {23, -25}, {14, -2}, {-1, -13}}      You can get the following equivalent results:               Cases[test, {_, _?Positive}]           {{-15, 13}, {-8, 16}, {7, 6}, {-21, 9}, {4, 4}, {-24, 8}, {19, 18}}          Select[test, #[[2]] > 0 &]           {{-15, 13}, {-8, 16}, {7, 6}, {-21, 9}, {4, 4}, {-24, 8}, {19, 18}}          Pick[test, Sign[test[[All, 2]] ], 1]           {{-15, 13}, {-8, 16}, {7, 6}, {-21, 9}, {4, 4}, {-24, 8}, {19, 18}}               test[[Flatten@Position[test[[All, 2]], _?Positive] ]]           {{-15, 13}, {-8, 16}, {7, 6}, {-21, 9}, {4, 4}, {-24, 8}, {19, 18}}      Are there performance or other considerations that should guide which you should use? For example, is the pattern-matching used in `Cases` likely to be slower than the functional tests used in `Select`? Are there any generic rules of thumb, or is testing the particular case you are using the only solution?


title: Can Mathematica find the discriminant formula?

text: This question is not really practical, but rather a curiosity question. Can _Mathematica_ solve a quadratic equation without its discriminant?   I mean, whenever it see a quadratic equation it tries to solve it with discriminant. (I use `Trace` for that)   But could it find it discriminant formula by itself?   I mean, the discriminant was found by human, and looking from how it was found, I see that was not very easy. I know that _Mathematica_ looks for patterns in equations. Can it found patterns, like discriminant?


title: Example from Mathematica documentation (ExtremeValueDistribution) seems to be evualting "forever"

text: I am referring to this example at the reference page for the extreme value distribution: http://reference.wolfram.com/mathematica/ref/ExtremeValueDistribution.html#6764486 The first three commands seem to be running ok, but the last line of code just will not stop evaluating on my machine (MathematicaMark9 result > 1.5) - somthing seems to be very wrong:               Show[DiscretePlot[Mean[max\[ScriptCapitalD]], {n, 2, 100}, PlotStyle -> Orange],       Plot[approxMean, {n, 2, 100}, PlotRange -> All, PlotStyle -> Directive[Thick, Dashed]]]      What am I doing wrong? Or is that a mistake in the documentation or an error in Mathematica 9.0.1? _Edit: I added the_ `bugs` _tag because it seems clear by now that this is really a bug in Version 9.0.1, see answer and comments below._


title: Speeding up a function

text: This is un updated version of a previous (now deleted) post of mine. I need to marginalize a distribution. I was suggested to use the code in this thread. This works just fine, but the problem is that the construction of tab (see below) is very slow: I tried with a pTab[i] with 100 elements and it took 2 days on my dual core 2GHz laptop to build it, and my actual pTab[i] are 180000 elements long. I guess you understand why I am worried. Does anyone have any idea about how to speed it up? Or a different code, maybe? Here is the code I am using (only the slow part):               dat = (*Import data from dat.txt*)     mat = (*Import matrix from matrix.txt*)     nosys = Inverse[mat];     z = dat[[All, 1]];     mu = dat[[All, 2]];     H = ConstantArray[1, 580];     chi[{a_, b_, c_,         e_}] = (5/           Log[10]*(Log[z] + 0.5*z*(3 - b) +              1/24*z^2*(21 + 9*b^2 - 2*b - 4*c)) -           mu).nosys.(5/           Log[10]*(Log[z] + 0.5*z*(3 - b) +              1/24*z^2*(21 + 9*b^2 - 2*b - 4*c)) -           mu) - (H.nosys.(5/              Log[10]*(Log[z] + 0.5*z*(3 - b) +                 1/24*z^2*(21 + 9*b^2 - 2*b - 4*c)) -              mu))^2/(H.nosys.H) + ((a - 0.742)/0.024)^2 + ((e - 0.315)/          0.017)^2;          ClearAll[pTab];          val = (*Import values needed for Ptab from ptab_values.txt*)          d = 4;(*number of parameters*)     Do[pTab[i] = val[[All, i + 1]], {i, d}];     tab = Module[{T, n},         With[{F = chi},          Replace[Hold[            Array[Append[T, F[T]] &, Length[pTab[#]] & /@ Range[d]]] /.            T -> Table[Hold[pTab[n][[Slot[n]]]] /. n -> i, {i, d}],           Hold[x_] :> x, {0, Infinity}, Heads -> True]]];     Print["packing array"]     tab // Developer`PackedArrayQ;      The needed files are: for ptab (these are the numbers needed for building pTab (skip the first column: that is needed for another work)) matrix (a 580 x 580 matrix) for dat (only the first 2 columns are needed in this code) Those are rapidshare links: I hope you allow it because the matrix is 580 X 580, and dat is 580 rows long: I can't write them in a post. **EDIT:** I was thinking can `Parallelize` be of any help in this case?


title: Opening a pipe with OpenRead

text: My question is if it is possible to directly open a (named) pipe using `OpenRead`. **Introduction** In the docs of OpenRead, we have, under details and options, > If OpenRead does not succeed in opening a particular file or pipe, it > generates a message, and returns $Failed. suggesting that we can open a pipe with `OpenRead`. However, we also have > On systems that support pipes, OpenRead["!command"] runs the external > program specified by command, and opens a pipe to get input from it. This last text adds to my suspicion that maybe it is only possible to open a stream indirectly. For example using something like `OpenRead["!cat fifo"]` (this may actually be a terrible command, but you maybe you get the gist. I.e. it seems that cat sometimes "terminates" and but mostly it doesn't, so that the kernel gets stuck waiting for the command to finish). However, this answer by rcollyer quite explicitly does what I have failed to do. It reads a fifo using `OpenRead`. **My attempt** If I do (sorry about wasting your time with Pause, it is probably not necessary)               dir = FileNameJoin[{$TemporaryDirectory, "MMAIO"}];     CreateDirectory[dir]     Run["cd" <> " " <> dir <> " && mkfifo fifo"]     Pause[1]     OpenRead[FileNameJoin[{dir, "fifo"}]]      Then I simply get `$Failed` and a message that it cannot be opened. Also when I connect some input to the fifo or when I just append some string to the fifo, it wont work. **Questions** Am I doing something wrong or is this just impossible? Might it depend on the system? I am using Mac OSX and version 9. Also, is there any other way to get input from a pipe directly, or do we have to resort to something like `OpenRead["!cat fifo"]`? **Etc** This Q&A is related, but it is about MathematicaScript. _Background_ : The reason I bother with a fifo in the first place is to make a connection between Mathematica and other applications without writing on the hard disk. I am aware that MathLink might be something to look into.


title: Horizontally compress a picture with varying compression ratio

text: I have a function `c[x]` whose domain and range are both [0,1]. And I have a picture with width `W`, height `H`. Now I want the picture to be compressed horizontally, with `c[x]` being the compression ratio for the part of the picture whose x-coordinate is `x.W`. To achieve this I have to discretize `c[x]`, which could be fussy and problematic. Besides since it's compression, it's hard to decide which row of pixels should be abandoned. So is there any good way to do this?


title: How can I make a plot of data saved in a .txt file?

text: My file. Txt has only two columns, where the 1st column is the time that the data was generated by the 2nd column has decimal values 1-100. Example:               19/06/2013 at 14:31:43 ------ 75 .19     19/06/2013 at 14:31:54 ------ 62 .46     19/06/2013 at 14:32:04 ------ 55 .62     19/06/2013 at 14:32:14 ------ 48 .28     19/06/2013 at 14:32:24 ------ 33 .15      I would like to plot this data on a graph that represents the axis yo time on the x axis while the decimal values ... these graphics could be in columns in which the maximum value is 100.


title: Nest for large value of n

text: I am working on a problem to find the Feigenbaum constant. In this problem I have to get $f^{2^n}(1/2)$ with $f(x) = kx(1-x)$. I use `Nest` to get $f^{2^n}(1/2)$ but it takes Mathematica forever to run with $n>5$ but my goal is to get to $n=14$. Does any body know any function or trick to get $f^{2^n}(1/2)$ with large value of $n$? Thank you very much.


title: Conjugate and simplify

text: I want to get a cosine from taking the real part of a complex exponential: $cos(x) = Re(exp(i x))$. What I do in _Mathematica_ is               (1/2)*(Exp[x*I] + Conjugate[Exp[x*I]]) // TraditionalForm // FullSimplify      but this gives me `1/2 (E^(-I x^\[Conjugate]) + E^(I x))` instead of `cos(x)`. Why is that?


title: How can one type a box with "x" marked?

text: In some text portion of my notebook, I would like to be write check boxes which are empty, check marked or "x" marked. The following commands work for the first two:               \[CheckmarkedBox]     \[EmptySquare]      But I am unable to find the command that would place an "x" inside the box. Thanks.


title: Search the neighborhood area along a line in an image

text: I am trying to search for the black areas along a line (the horizontal line shown below). Though it is straight in this picture, it could be of irregular shape in other cases. It seems that the ImageTake function can only take rectangle areas. Can anyone tell me how to limit the processing within the line neighborhood area, and mark the black area in the left part? ![enter image description here](http://i.stack.imgur.com/4s4ji.png) Update: Several raw images without red marks: ![enter image description here](http://i.stack.imgur.com/KjTp9.png) ![enter image description here](http://i.stack.imgur.com/AuHP7.png) ![enter image description here](http://i.stack.imgur.com/jFkNM.png) Update2: Other cases with bigger black area somewhere else ![enter image description here](http://i.stack.imgur.com/Yksk9.png)


title: Is this the correct method in using bootstrapping to determine a lower confidence bound?

text: Quite often in industry, due to cost and schedule constraints, decisions must be made on small sample size data. I have 4 cycles-to-failure values resulting from running samples to failure in a fatigue test; 947, 1183, 1063 and 583. It is not possible to obtain any more samples to test. From this data I believe I can say : I am 95% confident that the probability of any given part in the population surviving to 500 cycles is 0.82 or greater. My code is below. Is my approach the correct way to accomplish this using Mathematica ? Can someone verify these results using another tool ? Many Thanks.               cycles={947,1183,1063,583};     plot1=BarChart[cycles,Frame->True,ChartLabels->{"Sample 1","Sample 2","Sample 3","Sample 4"},LabelingFunction->Above,FrameLabel->{None, "Cycles to Failure",None,None},PlotRange->1750,PlotLabel->"Plot 1"]      ![enter image description here](http://i.stack.imgur.com/3rx0b.jpg)               dist = TruncatedDistribution[{0, Infinity},      SmoothKernelDistribution[cycles]]  (* Nominal Distribution *);     pdf[x_] := PDF[dist, x];     ps[x_] := SurvivalFunction[dist, x];     plot2 = Plot[pdf[x], {x, 0, 2000}, Frame -> True,      FrameLabel -> {"Cycles to Failure", "PDF", None, None},      PlotLabel -> "Plot 2\nNominal PDF", PlotStyle -> Red]     plot2a = Plot[ps[x], {x, 0, 2000}, Frame -> True,      FrameLabel -> {"Cycles to Failure", "PS", None, None},      PlotLabel -> "Plot 2a\nNominal Probability of Survival",      PlotStyle -> Red]      ![enter image description here](http://i.stack.imgur.com/TuN0T.jpg) ![enter image description here](http://i.stack.imgur.com/GqpUs.jpg)               n = 1000;  (* number of bootstrapped samples *)     bSamp = RandomChoice[     cycles, {n,      Length[cycles]}]  (* bootstrapped samples, each sample is 4 \     values long *);     sampleddistributions =      TruncatedDistribution[{0, Infinity},       SmoothKernelDistribution[#]] & /@ bSamp;       (* n fitted distributions *)     psvaluesTable =      Table[SurvivalFunction[i, rng = Range[0., 2000]], {i,      sampleddistributions}]  (* n PS lists, each PS list coresponds to \     cycles to failure values that range from 0 to 2,000 on a 1 cycle \     increment producing 2001 PS values in each list *);          psdata=Table[Null,{n}];     psplot=Table[Null,{n}];     cyclelist=Range[0.,2000];     i=0;     Do[{     i=i+1;     If[i>n,Break[]];     psdata[[i]]=Transpose[{cyclelist,psvaluesTable[[i]]}];     psplot[[i]]=ListPlot[psdata[[i]],Joined->True,PlotStyle->Green];},     {n}]     Dimensions[psplot]     psplot;     combinedPSlistplot=Show[psplot,FrameLabel->{"Cycles to Failure (cycles)","Probability    of Survival"},Frame->True,FrameLabel->{"Cycles to Failure","PS",None,None},PlotLabel->"Plot    3\nCombined PS ListPlot"]     plotindex=Range[1,n];     psplotdata=Transpose[{plotindex,psplot}];      ![enter image description here](http://i.stack.imgur.com/DNre4.jpg)               lower=Table[Quantile[i,.05],{i,Transpose[psvaluesTable]}]  (* Determines the lower 95%     single-sided confidence limit values *);lowerdata=Transpose[{rng,lower}];     plot4=ListLinePlot[lowerdata,PlotRange->All,PlotStyle->{{Dashed,Blue}},Frame- >True,PlotLabel->"Plot 4\nLower 95% Single-Sided Confidence Level"]     lowerinterp=Interpolation[lower];     Show[combinedPSlistplot,plot4,plot2a,PlotLabel->"Final Plot"]      ![enter image description here](http://i.stack.imgur.com/Pac9p.jpg) ![enter image description here](http://i.stack.imgur.com/LXBuc.jpg)               cyclesOfInterest = 500;     {lowerinterp[cyclesOfInterest], ps[cyclesOfInterest]}      {0.821289, 0.918629}


title: ContourPlot3D using a Matlab function through MATLink

text: I have a Matlab function which accepts a 3 dimensional vector and returns a single number. I want to use this through MATLink to make a 3d plot. A unit sphere:               ContourPlot3D[      Norm[{x, y, z}, 2]^2 == 1, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}]      I now want to replace the Norm with my function:               myfunc= MFunction["myfunc"];     ContourPlot3D[myfunc[{x, y, z}] == 1, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}]      but I get errors: > MSet::unsupp: Unsupported data type. The expression "x" can't be converted. > MFunction::args: The arguments at positions {1} to "myfunc" could not be > translated to MATLAB.... I am fairly certain I'm missing something obvious but I this is my first time with MATLink.


title: NetLink Exporting Images doesn't work (Unknown string escape)

text: Exporting Image files (intermittently) doesn't work: ![enter image description here](http://i.stack.imgur.com/C18mr.png) I get messages back indicating the error is to do with escaping characters:               Syntax::stresc: Unknown string escape \\U.


title: Split A text-style cell to multiple cells by a fixed width

text: > Sample Cell 1               Cell["Much of point set topology consists in developing a convenient language to talk about when various points in a space are near to one another and about the notion of continuity. The key is that the same definitions can be applied to many disparate branches of math.", "Text"]      Split to multiple cells like > Sample Cell 2               Cell["Much of point set topology consists in developing a convenient", "Text"]     Cell[" language to talk about when various points in a space are near", "Text"]     Cell[" to one another and about the notion of continuity. The key is", "Text"]     Cell[" that the same definitions can be applied to many disparate ", "Text"]     Cell["branches of math.", "Text"]      Though, in this example, they are all plaint text, maybe much simpler, the problem might be harder when there are many inline math cells. * * * Here is an sample post for why I need this, I wanna make first light-green block text into multiple framed lines like what below `Definition 4.1.1`. http://quaternions.blog.163.com/blog/static/206082147201356102512774/ * * * Bill's present method will not able to deal with the inline cells. > Upadte sample Cell 3 with inline cells               Cell[TextData[{"Much of point set topology", Cell[BoxData[\(TraditionalForm\`\(\ consists\ \)\)], FormatType -> "TraditionalForm"], "in developing a convenient language to  talk about ", Cell[BoxData[\(TraditionalForm\`when\)], FormatType -> "TraditionalForm"], " various points in a space are near to one another and about the notion of ", Cell[BoxData[\(TraditionalForm\`\(continuity\^2\)\)], FormatType -> "TraditionalForm"], ". The key is that the same definitions can be applied to many disparate branches of math."}], "Text"]


title: How to check if a given expression is an "explicit algebraic number"?

text: The documentation for `PossibleZeroQ` says: >   * With the setting `Method``->"ExactAlgebraics"`, `PossibleZeroQ` will use > exact guaranteed methods in the case of explicit algebraic numbers. > Unfortunately, there is no formal definition of what expressions are considered _explicit algebraic numbers_. I noticed that trig functions of rational multiples of `π` are not considered explicit algebraic numbers. Neither are `RootSum` expressions with algebraic functions as a second argument, nor `Re`, `Im` parts of `Root` expressions.               In[1]:= PossibleZeroQ[      Root[-7 + 56 #1^2 - 112 #1^4 + 64 #1^6 &, 4] - Sin[π/7], Method -> "ExactAlgebraics"]          PossibleZeroQ::ztest1: Unable to decide whether numeric quantity Root[-7 + 56 #1^2 - 112 #1^4 + 64 #1^6 &, 4,] - Sin[π/7] is equal to zero. Assumіng it is. >>          Out[1]= True          In[2]:= PossibleZeroQ[      Root[25 + 3300 #1^4 - 530 #1^8 + 20 #1^12 + #1^16 &, 16] -        RootSum[5 - 20 #1^2 + 16 #1^4 &, Sqrt], Method -> "ExactAlgebraics"]          PossibleZeroQ::ztest1: Unable to decide whether numeric quantity Root[25 + 3300 #1^4 - 530 #1^8 + 20 #1^12 + #1^16 &, 16] - RootSum[5 - 20 #1^2 + 16 #1^4 &, Sqrt[#1] &] is equal to zero. Assumіng it is. >>          Out[2]= True          In[3]:= PossibleZeroQ[Re[Root[5 + 20 #1^2 + 16 #1^4 &, 1]], Method -> "ExactAlgebraics"]          PossibleZeroQ::ztest1: Unable to decide whether numeric quantity Re[Root[5 + 20 #1^2 + 16 #1^4 &, 1]] is equal to zero. Assumіng it is. >>          Out[3]= True      Could you suggest a function that can determine if a given expression is considered an explicit algebraic number from `PossibleZeroQ`'s point of view?


title: How accurate is GeoDistance?

text: Two years ago I tried an evaluation copy of _Mathematica_. I reported various inaccuracies in the `GeoDistance` routine to which I never received any fix. Could someone check whether `GeoDistance` is any more accurate now? Thanks. Here are the problems I reported on June 20, 2011:                                                    Mathematica   Correct     Error     GeoDistance[{30, 0}, {-30, 180}]  -> 19928486.7   20003931.5  -75444     GeoDistance[{0.4, 0}, {0.4, 180}] -> 19915473.0   19915472.0       1     GeoDistance[{0, 0}, {0.5, 179.5}] -> 19936426.5   19936288.6     138


title: Find subexpression to minimize leafcount after replacment with temporary variable

text: Given an expression `expr`, is there an automated way to find a subexpression `subexpr` such that replacing `subexpr` with a temporary variable `v` minimizes `LeafCount[expr//.subexpr->v]+LeafCount[subexpr]` over all possible `subexpr`? To provide a concrete example to work with, here is a cleaned up small fragment of an expression that someone asked an unrelated question about recently:               (1/Sqrt[2](Sqrt[((Sqrt[((-x3 - (1/2 Cos[a] (m-h Cos[a]) + x3 Tan[a] - x3 (-m Sec[a]/(x2-x3) + Tan[a]) - Tan[b])/(-m Sec[a]/(x2-x3) + Tan[a]))^2 + (-1/2 Cos[a] (m-h Cos[a]) - x3 Tan[a] + Tan[b])^2)] + Sqrt[((-x3 - Cos[a] (m-h Cos[a])/(2 (Tan[a]-Tan[b])))^2 + (-1/2 Cos[a] (m-h Cos[a]) - x3 Tan[a] -     (Cos[a] (m-h Cos[a]) Tan[b])/(2 (Tan[a]-Tan[b])))^2)] + Sqrt[((-(Cos[a] (m-h Cos[a]))/(2 (Tan[a]-Tan[b])) + (1/2 Cos[a] (m-h Cos[a]) + x3 Tan[a] - x3 (-m Sec[a]/(x2-x3) + Tan[a]) - Tan[b])/(-m Sec[a]/(x2-x3) + Tan[a]))^2 + (-Tan[b] -     (Cos[a] (m-h Cos[a]) Tan[b])/(2 (Tan[a]-Tan[b])))^2)])(-Sqrt[((-x3 - (1/2 Cos[a] (m-h Cos[a]) + x3 Tan[a] - x3 (-m Sec[a]/(x2-x3) + Tan[a]) - Tan[b])/(-m Sec[a]/(x2-x3) + Tan[a]))^2 + (-1/2 Cos[a] (m-h Cos[a]) - x3 Tan[a] +     Tan[b])^2)] + 1/2 (Sqrt[((-x3 - (1/2 Cos[a] (m-h Cos[a]) + x3 Tan[a] - x3 (- m Sec[a]/(x2-x3) + Tan[a])-Tan[b])/(-m Sec[a]/(x2-x3) + Tan[a]))^2 + (-1/2 Cos[a] (m-h Cos[a]) -x3 Tan[a] + Tan[b])^2)] + Sqrt[((-x3 - (Cos[a] (m-h Cos[a]))/     (2 (Tan[a]-Tan[b])))^2 + (-1/2 Cos[a] (m-h Cos[a]) - x3 Tan[a] -(Cos[a] (m-h Cos[a]) Tan[b])/(2 (Tan[a]-Tan[b])))^2)] +Sqrt[((-(Cos[a] (m-h Cos[a]))/(2 (Tan[a]-Tan[b])) +(1/2 Cos[a] (m-h Cos[a]) + x3 Tan[a] - x3 (-m Sec[a]/(x2-x3) +     Tan[a])-Tan[b])/(-m Sec[a]/(x2-x3) + Tan[a]))^2 + (-Tan[b] -(Cos[a] (m-h Cos[a]) Tan[b])/(2 (Tan[a]-Tan[b])))^2)])))]))      The original problem had a LeafCount of almost 6000. Fumbling with manual substitutions I was finally able to make the structure clear and that happened to enable `Simplify` to reduce the total LeafCount to about 250 in a few seconds. Is there a simple method of automating this? It would be even better if it could recognize and handle `-subexpr` and `1/subexpr` as containing `subexpr`, but that may be too much to ask. Note: I'm trying to actually see the result, not just have Mathematica do subexpression sharing behind the scenes where I cannot see what happened.


title: Common subexpression from two expressions

text: I am working with some unpleasantly tedious polynomials, which need to be manipulated in various ways (integrate with respect to some variable, differentiate with respect to another). Since these will eventually be part of numeric routines, I'd like to pull out common subexpressions that I can reuse, e.g.               (G u^2 (6 p (2 h + p) - 8 (h + p) u + 3 u^2))/(12 h^2)     (G (3 h + 3 p - 2 u) u^2)/(3 h^2)      should at least note that both have a common factor of               (G u^2)/(3 h^2)      Is there a convenient way to instruct Mathematica to look for this sort of computational-expense-reduction in pairs of expressions? Ideally it would notice even in the case where it's not just a factor multiplied by both, e.g. if I added `+ 1` to the second equation, I'd still like it to find that common subexpression. * * * Just for clarification, this is what I do by hand:               e1 = (G u^2)/(12 h^2) * (6 p (2 h + p) - 8 (h + p) u + 3 u^2))     e2 = (G u^2)/( 3 h^2) * (3 h + 3 p - 2 u)          A = (G u^2)/(12 h^2)     e1 = A * (6 p (2 h + p) - 8 (h + p) u + 3 u^2))     e2 = A * (12 (h + p) - 6 u)          B = u^2     C = h + p     A = (G B)/(12 h^2)     e1 = A * (6 p (2 h + p) - 8 C u + 3 B)     e2 = A * (12 C - 6 u)      to go from 6 additions, 20 multiplications, 2 divisions, and 2 assignments, to 5 additions, 14 multiplications, 1 division, and 5 assignments (the extra three of which are temporary so can be in registers and cost essentially nothing).


title: Find repeated groups in a long algebraic expression

text: I have an algebraic output (a solution to a de) similar to, but far longer than: {y->(x+3)^2/sin(7*(x+3))+(x+3)^3/7} I'd like to get Mathematica to notice that the group x+3 appears repeatedly, define a new parameter par1=x+3, and rewrite the original output as: {par1=x+3, par1^2/sin(7*par1)+par1^3/7} The new expression would be far simpler and faster to evaluate than the original if par1 is, say 40 characters long, and appears say 6 times in the original expression. Ideas on how to accomplish this? Eric


title: How to reduce the number of operations needed to evaluate an expression?

text: For some numerical calculations in C++ I have, for example, this complicated expression to evaluate. Given as Mathematica input, in its original form it is               w - 4(w - y)((w - y)^2 y + 6(1 + y)((w - y)y + (1 + y)^2)) /     ((w - y)^2 ((w - y)y + 6y^2 + 8y(1 + y)) + (1 + y)^2 (36(w - y)y + 24(1 + y)^2))      The goal is to reduce the number of required floating point operations to evaluate it in C++. Using useful code from Counting multiplications (complexity function) we can see it requires the following operations and their respective counts: `{{Times, 22}, {Plus, 18}, {Power, 7}}`. The `FullSimplify`'ed expression is a bit shorter               w - 4(w - y)(6 + y(18 + 6w + w^2 + 4(3 + w)y + y^2)) /     (24 + y(w^3 + w^2 (8 + 11y) + (2 + y)(48 + y(30 + y)) + w(36 + y(56 + 11y))))      and requires the following operation counts: `{{Times, 16}, {Plus, 18}, {Power, 5}}`. One way to reduce the number of operations is to identify common components and evaluate them beforehand as temporaries. After staring at the expression for an hour I could find the following substitutions:               f0 = w - y;     f1 = 1 + y;     f00 = f0 f0;     f11 = f1 f1;     f0y = f0 y;      and the expression now reads               w - 4f0(6f1(f11 + f0y) + f00 y) / (f11(24f11 + 36f0y) + f00(6y y + 8f1 y + f0y))      The operation count is now: `{{Times, 19}, {Plus, 9}, {Power, 0}}`. Is there a way to express this process of finding sub-expressions more formally in Mathematica? And automatize it at least for such simple expressions involving only multiplication and addition?


title: How to correct this, `f[a_] := FindRoot[eq == 0, {x, 0.5}]`, where `eq` contains a parameter $a$, without using `eq[a]`?

text: I want to solve an equation with a parameter $a$, and define the result as a function of $a$. It is something like this:               f[a_] := FindRoot[x^2 + 2 x + a == 0, {x, 0.5}]     f[0.2]     (* -> {x -> -0.105573} *)      The equation I want to solve is a large expression, so I do not want to put it explicitly inside the `FindRoot`. But this does not work:               eq := x^2 + 2 x + a;     f[a_] := FindRoot[eq == 0, {x, 0.5}]     f[0.2]     (* -> FindRoot::nlnum: The function value {1.25 +a} is not a list of numbers with dimensions {1} at {x} = {0.5}. *)      I do not want to define the equation as `eq[a]`, because this equation is also used to do other things, for which it is better to just use `eq`. The following ways also do not work:               f[a_] := FindRoot[Evaluate[eq] == 0, {x, 0.5}]     f[a_] := Evaluate[FindRoot[eq == 0, {x, 0.5}]]      (However, if we want to solve the above equation analytically, `f[a_] := Evaluate[Solve[eq == 0, x]]` works, and `f[a_] := Solve[Evaluate[eq] == 0, x]` does not. How to explain this?)


title: Import iTunes xml data and convert it into a dataset or table

text: I have an xml file with song data from iTunes (https://dl.dropboxusercontent.com/u/1012958/iTunes%20Library.xml) and I'd like to import it to _Mathematica_ to do some statistics. I get an XMLObject like this:               XMLObject[       "Document"][{XMLObject["Declaration"]["Version" -> "1.0",         "Encoding" -> "UTF-8"],        XMLObject["Doctype"]["plist",         "Public" -> "-//Apple Computer//DTD PLIST 1.0//EN",         "System" -> "http://www.apple.com/DTDs/PropertyList-1.0.dtd"]},       XMLElement[       "plist", {"version" -> "1.0"}, {XMLElement[         "dict", {}, {...}], {}, "Valid" -> True]      How can I convert it to a _Mathematica_ 10 dataset or table?


title: How to add rows to a Grid in front end?

text: I created a grid `g1` with `Grid[]` and then a separate grid `g2`. `g1` and `g2` have same number of columns. How to put the rows of `g2` at the end of `g1` purely using front-end? I tried to highlight `g2`, Ctrl+C, and move my curser to various positions in `g1` and Ctrl+V. But it always resulted in something not desirable such as the entire `g2` being copied into a cell of `g1`. Any suggestions?


title: Having Dynamic evaluated when off screen

text: As the title says, I want a cell containing the dynamic solution of a DAE- System to be available over the whole document. I use a lot of different Plots and Sliders scattered over the document and it is pretty annoying that after the cell scrolled off screen, the dynamic stuff stops working altogether (as this is the nature of `Dynamic` as the documentation explains it). If I copy `Dynamic[Solution]` and insert it all over the place everything works perfectly fine but does of course look unprofessional. Therefore I tried `DynamicWrapper["This is a text", Dynamic[Solution]]` to hide `Dynamic[Solution]` inside titles and texts that are scattered around anyway. This does however not work as I imagined it must. If someone has an idea how to comfortably solve the issue I would be glad. Edit: The system is a scale that works by compensation method; some code: This is my variable called solution               solution =      Dynamic[sol2 =      Quiet[NDSolve[{d1'[t] == d2[t],      d2'[t] == k*d1[t] + b*d2[t] + (ki*l)/\[Theta][t]*d3[t] + (l*g)/\[Theta][t]*              (mersatz - mass[t, offset, Mass]),      d3'[t] == -((ki*l)/L)*d2[t] - R/L*d3[t] + (U[t] + Uoffset)/L,      U[t] == kP*U2[t] + kI*IntegralPart[t] + kD*U2'[t],      U2[t] == -ks*l* d1[t],     D[IntegralPart[t], {t, 1}] == U2[t],     d1[0] == 0, d2[0] == 0, d1'[0] == 0,      d2'[0] == (l*ki)/\[Theta][0]*Uoffset/R + (l*g)/\[Theta][0]*               (mersatz - mass[0, offset, Mass]),        d3'[0] == 0, d3[0] == Uoffset/R , U[0] == 0, U2[0] == 0,        IntegralPart[0] == 0}, {d1, d2 , d3, U, U2, IntegralPart}, {t,        0, duration}      ]]]      After that follows a big plot of the measured / calculated load on my scale               PlotWeight =      Manipulate[     Quiet[Plot[{measuredweight[t] /. sol2,       If[referencew == 1, mass[t, offset, Mass], ""]} , {t, 0,       duration}, PlotStyle -> {Automatic, Darker[Green]},      ImageSize -> {1200, 400}, AspectRatio -> Full,       ExclusionsStyle -> {Darker[Green], None},      AxesLabel -> {Style["time [s]", FontFamily -> font1],        Style["measured weight [kg]", FontFamily -> font1]},      PlotRange -> {{0, duration}, If[scale == 1, Full, {0, scale}]}]],     Style["      +", 12]     , {{scale, 1,      Rotate[Style["AxisScale", FontFamily -> font1, FontSize -> 12],       90 \[Degree] ]}, 0.01, 1, ControlType -> VerticalSlider},      Style["      -",      12], {{referencew, 0,      Style["activate weight reference", FontFamily -> font1,       FontSize -> 12]} , {0, 1}},      ControlPlacement -> {Left, Left, Left, Top}, Alignment -> Center ]      Other variables displayed in interactive Plots are current, voltage, angular velocity, angle, etc. All those are coming from the DAE that is fitted in solution (in the variable sol2 inside of solution). ![Mathematica graphics](http://i.stack.imgur.com/wcadK.png) A full picture in this Pdf.


title: Remap Ctrl+Space?

text: The `Ctrl`+`Space` keyboard shortcut is really important in _Mathematica_ for using `Placeholder[]` boxes in input templates. Unfortunately, `Ctrl`+`Space` occupies the significantly more important role of the system-wide Quicksilver shortcut that I'm not really willing to part with, not even while _Mathematica_ is running. Can I change this shortcut in _Mathematica_ to some other key sequence?


title: Place symbols from small to big

text: I am wondering how to compare the different values of `ω` I derived in this code, and place them in order as follows. (use `Print` or something?) I would like to have `ω` placed in order in the output, instead of the values of `ω`. > $$\omega_{11} < \omega_{22} < \omega_2 < \omega_1$$ I would like to have `ω` placed in order in the output, instead of the values of `ω`.               Remove["Global`*"]          x1[t_] = A1 E^(I ω t);     x2[t_] = A2 E^(I ω t);          eqn1 = m x1''[t] + 2 k x1[t] - k x2[t] == 0 /. t -> 0;     eqn2 = m x2''[t] - k x1[t] + k x2[t] == 0 /. t -> 0;          org = k/m SparseArray[{{1, 1}, {1, 2}, {2, 1}, {2, 2}} -> {2, -1, -1, 1}];          eigena = Sqrt[org // Eigenvalues];          "The charactersitic frequencies are: "     Column[Subscript[ω, #] & /@ Range@2 == eigena // Thread,       Spacings -> 2]     For[i = 1, i < 3, i++, Subscript[ω, i] = eigena[[i]]]          "When the upper mass m1 is fixed, x1[t]=0, for all t values"          eqn11 = x2''[t] == -k/m x2[t];          "Just by observation, the frequency is:"          Subscript[ω, 11] == Sqrt[k/m]     Subscript[ω, 11] = Sqrt[k/m];          "When the upper mass m2 is fixed, x2[t]=0, for all t values"          eqn22 = x1''[t] == -2 k/m x1[t];          "Just by observation, the frequency is:"          Subscript[ω, 22] == Sqrt[2 k/m]     Subscript[ω, 22] = Sqrt[2 k/m];               Sort[{Subscript[ω, 1], Subscript[ω, 2], Subscript[ω, 11], Subscript[ω, 22]}             ] /. k -> 1 /. m -> 1


title: Symbolic integral including Hermite polynomial does not evaluate

text: I am trying to evaluate the following integral:               Integrate[HermiteH[n, Sqrt[a]* x] * Exp[- (c/2)* (x^2 + y^2) + b* x * y - (a * x^2)/2], {x, - Infinity, Infinity}]      but Mathematica just returns the function, e.g. does not evaluate it. It does evaluate for specific values of n, but I need a general result. I have considered using FindSequenceFunction, but I believe that this only works for integer sequences (?) Is there some way I can get Mathematica to evaluate this integral, or is it impossible to do? Thanks in advance for any replies.


title: How to Derive Tuples Without Replacement

text: Given a couple of lists like `a={1,2,3,4,6}` and `b={2,3,4,6,9}` I can use the built-in Mathematica symbol `Tuples [{a,b}]` and get all the arrangements easilly enough. But I am struggling with how to eliminate the generation of replacement results, for example: `{2,2}` and `{4,2}` and `{4,4}` are not desired but all the totally unique results like `{1,2}` and `{1,3}` are desired. So essentially I want to find all the combinations of numbers that do not have any ordering repeats such as `{4,2}` where I already have `{2,4}` and no number repeats such as `{2,2}` and `{4,4}`. Any ideas would be appreaciated!


title: How do I write "such that" in mathematica?

text: I have a mathematical statement as follows : > Tri := {(t1,t2): t1,t2>=0,t1+t2<=1} How can I tell _Mathematica_ that I need to define vectors `(t1,t2)` 'such that' (`:`) they satisfy the above condition?


title: converting between forms - symbols/subscripts - matrix products

text: If I have a vector of the form (xp+y, x+yp) do you have a simple way of creating the following matrix and vector from it: `{{p, 1}, {1, p}} * {x, y}`, such that after multiplying the matrix with the vector, I get the original vector back. If I have the following variables defined as such:               v1 = (a1 + 1) *(b1 + 1) *(c1 + 1)*(d1 + 1) *(e1 + 1)  -1          a1 = (x11*f11 + x21*f21 )          b1 = (x11*f12 + x21*f22 )          c1 = (x11*f13 + x21*f23 )          d1 = (x11*f14 + x21*f24)          e1 = (x11*f15 + x21*f25)      is there a fast way to convert all the numbers appearing next to letters for example 11 next to x in to subscript? My goal is to create a vector consisting of several elements that look like V1.


title: How can I prevent ColorFunction from disabling antialiasing in graphics?

text: When I use `ColorFunction`, the appearance of my plots is ruined, changing from this ![Nice antialiased plot](http://i.stack.imgur.com/y4be4.png) which has the normal smooth lines and antialiased fonts, to this ![Ugly plot](http://i.stack.imgur.com/BUDZm.png) in which the line for the plot has become jagged and thin, and the fonts have lost their clear appearance, and the points have become jagged and have even shifted position a bit. The latter figure is useless to me. How do I prevent this behavior? Is there a setting somewhere that I missed? Setting the "Antialiasing Quality" to "Highest Quality" in Preferences, partly remedies the problem with the line, but points, fonts, and axes still shift, as if the scale of the figure has been changed: ![enter image description here](http://i.stack.imgur.com/sEstj.png) * * *               Manipulate[Show[       {If[showcf,          ParametricPlot[{u, Sin[u]}, {u, 0, 2 Pi},           ColorFunction -> (White &), PlotStyle -> {Thickness[.02]}], {}],        ParametricPlot[{u, Sin[u]}, {u, 0, 2 Pi}],        Graphics[{Black, PointSize[Large], Point[{Pi, 0.5}], White,           PointSize[Medium], Point[{Pi, 0.5}]}]}],      {{showcf, False, "Show ColorFunction"}, {True, False}}]


title: Can Mathematica do two evaluations at the same time?

text: When one evaluation is running, if I want do another evaluation, Mathematica will put the second one in the queue and run it after the first evaluation finish. However, the first evaluation may take very long time and the second one may just a easy calculation. It is possible that running the second evaluation without giving up or waiting the first evaluation? BTW, I am using Mathematica 9 in Windows 8(64 bit), but I am also happy to use Ubuntu. Any suggestions are welcome.