title: RandomVariate from 2-dimensional probability distribution

text: A probability distribution can be created in Mathematica (I am using 8.0.1) with e.g.               distribution1 = ProbabilityDistribution[(Sqrt[2])/Pi*(1/((1+x^4))),      {x,-Infinity,Infinity}];      Random variates from this distribution can be created with RandomVariate easily:               dataDistribution1=RandomVariate[distribution1,10^3];     Histogram[dataDistribution1](*Just an optical control*)      How can I create random variates from a 2-dimensional probability distribution? Let's say my 2-dimensional distribution is of the following form (very similar to the previous one):               distribution2=ProbabilityDistribution[((((Sqrt[2] π^(3/2) Gamma[5/4])/     (Gamma[3/4]))^(-1)))/((1+x^4+y^4)),{x,-Infinity,Infinity},     {y,-Infinity,Infinity}];      I thought it would be logical to try               dataDistribution2=RandomVariate[distribution2,10^3];      But that does not work. I get the following message then:               RandomVariate::noimp: Sampling from ProbabilityDistribution[Gamma[3/4]…}] is not implemented.      I tried a lot of variations of this approach to create random variates from such a distribution but without any success. Either I am doing a lot of things wrong (very likely in my experience ;-) or Mathematica cannot deliver random variates from 2-dimensional probability distributions. But in the help of RandomVariate (under “Simulate a multivariate continuous distribution”) one can see that this should be possible. Perhaps somebody of you can tell me, how I can generate random variates from 2 dimensional probability distributions? I would be very happy about any help!


title: Using an Interpolating Function as a probability density function

text: I have seen a couple of similar questions but have not been able to figure out a solution for my particular problem. I have a probability density function of two variables `p[x,v]` which is an interpolating function. What I really want to do is to generate a set of random `{x,v}` values based on this distribution. I tried:               dist=ProbabilityDistribution[p[x, v], {x, -4, 4}, {v, -4, 4}]     RandomVariate[dist, 10]      but get the error: > RandomVariate::noimp: "Sampling from ProbabilityDistribution[<<1>>] is not > implemented." Any ideas how I can get this working?


title: How to generate absolute Directories in HTML

text: ExportString["Test","HTML"]     Export["Test.html","test","HTML"]           <link href="HTMLFiles/m-478f1adf-0b36-429c-9ee2-ff6f5c953e52.css" rel="stylesheet" type="text/css" />      the Directory is HTMLFiles How to make it be the absolute directory, For instance               Directory[]<>"\\HTMLFiles"      One reason is Windows-Live-Writer too dummy to recognize the Directory `HTMLFiles` but Absolute Directory is ok. I done it by `StringReplace` before. Is there any setting in Mathematica?


title: Plot with plot markers without using ListPlot

text: I would like to plot a continuous function with `Plot` with plot markers as if it were a `ListPlot` plot. Simple example: I have               f[x_]:=x     Plot[f[x],{x,0,10}]      but for external reasons I need the figure to look like that of               ListPlot[Table[{x,f[x]},{x,0,10}]]      It works well. But imagine now my `f[x]` function contains several functions:               f[x_]:={x,x^2,x^3}      Plotting with plot is the same:               Plot[f[x],{x,0,10}]      However, the conversion to a set of points with `Table` is now complicated. The question is: what would be the easiest way (the shortest code) to produce a plot marker plot for such `f[x]`? Can it be done directly with Plot without using ListPlot and Table ?


title: Programatically adding/retaining comments within a nested list

text: Is it possible to convert the following list of strings to computable numbers with the comments preserved?                str = {{{"8.0,1034(*g opx ksp pl ilm liq q *)"}, {"8.0,1035(*g opx ksp pl ilm liq q *)"},               {"8.0,1037(*g opx ksp pl ilm liq q *)"}, {"8.0,1038(*g opx ksp pl ilm liq q *)"},                 {"8.0,1039(*g opx ksp pl ilm liq q *)"}, {"8.0,1040(*g opx ksp pl ilm liq q *)"}},               {{"8.0,886(*g opx ksp pl ilm liq q  *)"}, {"8.0,889 (*g opx ksp pl ilm liq q *)"},                 {"8.0,891(*g opx ksp pl ilm liq q  *)"}, {"8.0,894 (*g opx ksp pl ilm liq q  *)"},                 {"8.0,896(*g opx ksp pl ilm liq q  *)"}, {"8.0,899 (*g opx ksp pl ilm liq q  *)"}}}      I'm after something like:               strc = {{{8.0,1034(*g opx ksp pl ilm liq q *)},....      Perhaps there is a way involving programatically adding the comments back onto the numbers after the numbers have been converted to an expression? Any Suggestions?


title: How to replace a variable that was assigned a value before

text: ## Question How to make the replacement $f[x] \to f[y]$ for an abitrary function $f$ if $x$ was assigned a value before? ### Example 1 How can I make the replacement $x +1 \to y + 1$ if I have assigned the variable $x$ a value before? **Problematic attempts** A first guess would be               x = 1;     x + 1 /. x -> y      > 4 This does not give $y + 1$ because $x + 1$ is evaluated to `4` before the replacement is attempted. I expected this would give $y+1$:               Unevaluated[1 + x] /. x -> y      > 4 My reasoning was that the replacement of $x$ with $y$ in               x + 1 // FullForm      Unevaluated[1 + x] // FullForm      > 4 > > Unevaluated[Plus[1,x]] gives '4' and `Unevaluated[Plus[1,y]]`, but it does not. Why? Is there a solution that works in this spirit? **Working Solution** In the post Symbolic computations with already assigned variables, I found the suggestion to use block. Indeed it works               Block[{x}, x + 1 /. x -> y]      > y + 1 ### Example 2 Let               x = {1, 3, 4};     f[x_] := Length[x];      How to replace `x` in `f[x]` with `{1, 2}`? We allready saw that `f[x] /. x -> {1, 2}` will not work. Here the construction with `Block` does not work either               Block[{x}, f[x] /. x -> {3, 2}      > 0 It gives 0 since the lefthand side of the rule is evaluated first, and gives 'Length[x] = 0'. Only then the rule is applied. I guess I need a rule in the spirit of the 'problematic attempts' in order to make the desired replacement.


title: How to make PlotMarkers constructed from Graphics track plot style?

text: In this plot the `Disk[]` markers are not colored according to the style of the line to which they belong:               SeedRandom[12]     data = Accumulate /@ RandomReal[3, {4, 10}] {1, 2, 3, 4};          ListLinePlot[data,       PlotMarkers -> Graphics[Disk[], ImageSize -> 13],       PlotLegends -> Automatic     ]      ![enter image description here](http://i.stack.imgur.com/dmRVQ.png) Curiously, note that they are colored in the legend. How can I make the lines match the legend?


title: is it possible to modify BaseStyle of Manipulate dynamically?

text: I can't decide what is a best color for the background for a Manipulate I am writing. So, I thought since this is Manipulate, why not make this part configurable as well, so one can change the RGB color (using something like 3 sliders, one for each channel), so depending on the mood at that moment, one can choose different background color until they find one that they prefer. But I am not sure how this can be done since `BaseStyle` is set when Manipulate itself is created. BaseStyle is an option and not a command. Here is a small example of a Manipulate. I did not show the sliders for selecting the RGB color, since I do not know if it is even possible to modify the BaseStyle yet. This is just a toy Manipulate that just plots a sin function with greenish color for background of the Manipulate.               Manipulate[      {},      {m, 1, 10},           Grid[{{Dynamic[          Plot[Sin[x], {x, -m, m}, ImageSize -> 200, Frame -> True,ImagePadding -> 30]]}}       ],           Paneled -> False,      ContentSize -> {0},      Frame -> False,      Alignment -> Center,      AppearanceElements -> "ManipulateMenu",      BaseStyle -> {Background -> RGBColor[.80, .80, .90]}      ]      ![Mathematica graphics](http://i.stack.imgur.com/nT0JU.png) **The question is** : How to modify the Background color dynamically using an input from the user (via sliders, not shown). Is it possible? I just like to know the syntax if possible, and I can do the rest. http://reference.wolfram.com/mathematica/ref/BaseStyle.html http://reference.wolfram.com/mathematica/ref/Background.html I am using V9. Please note that any solution can't use global variables. This is for a demo for WRI web site, and one of the rules is that no global variables are allowed (since they will interact with other copies of the Manipulate). **update** Using the official demonstration style sheet, when using `ContentSize -> {0}` and `Paneled -> False`, , Manipulate background is white by default. I thought that giving it little color might be nice. Here is an example               Manipulate[      {},      {m, 1, 10},           Grid[{{Dynamic[          Plot[Sin[x], {x, -m, m}, ImageSize -> 200, Frame -> True,            ImagePadding -> 30]]}}       ],      Paneled -> False,      ContentSize -> {0},      Alignment -> Center,      AppearanceElements -> "ManipulateMenu"      ]      ![Mathematica graphics](http://i.stack.imgur.com/g8ads.png) You might ask, well, this is because I set `Paneled->False` and this is true. But this was the only way to get rid of the small mark that remain there as result of doing `ContentSize -> {0}`. And there is no way to remove this mark. Here is an example               Manipulate[      {},      {m, 1, 10},           Grid[{{Dynamic[          Plot[Sin[x], {x, -m, m}, ImageSize -> 200, Frame -> True,            ImagePadding -> 30]]}}       ],      Paneled -> True,      ContentSize -> {0},      Alignment -> Center,      AppearanceElements -> "ManipulateMenu"      ]      ![Mathematica graphics](http://i.stack.imgur.com/x14yY.png) That little square there at the corner, is impossible to get rid off. Only way is to do `Paneled->False`. That marker is a big problem, and here is a related question I asked about it before. http://stackoverflow.com/questions/8556234/how-to-not-show-the-scrollbars- when-contentsize-does-not-fit-the-content-in-mani If I can figure a way to remove this tiny white spot, then I can leave `Paneled->True`. ps. I have to use `ContentSize -> {0}`. This is how I did the whole demo. Everything in the control area. No way to change this. Looking now at the demo I have, this white spot is very small, may be no one will notice it. At least this way I do not have to change the 'official' background color. I will check on this and see. It is just annoying one can't get rid of it. Here is a screen shot, where I set `Paneled->True` again. I put small circle around it. If the demo editor says it is ok, then I am all set, do not need to change background color. Will ask. **Update 12/23/12** Ok, figured how remove last piece of code from the Manipulate expression and replaced it with `None`. So finally the white line marker is gone. Problem resolved. Using `None` was the trick that was needed thanks to Michael E2. Here it is (it is 2 panels, and one can select full screen or not using a checkbox). One of the hardest things, is getting the sizes of the different plots correct and to fill the whole space in the grid. I spend half the time trying different values (aspect ratio, image sizes, padding, margins, etc.. for many things until I find the right combination. There got to be better way to do this but if there is, I do not know what it is). But this one is now finally done. ![enter image description here](http://i.stack.imgur.com/Adrzn.png) thanks,


title: How to find the sum all even numbers of this sequence?

text: I have a sequence $(u_{n})$ $$u_1= 1, \quad u_2 = 2, \quad u_3 = 3, \quad u_{n}= -u_{n-3} + 3u _{n-2} +2 u_{n-1}, \quad \forall n \geqslant 4.$$ I want to list the first $20$ terms of this sequence and find the sum of all terms and sum of all even numbers of $20$ terms. I tried               Clear[u];     u[1] := 1; u[2] := 2;     u[3] := 3;     u[y_] := -u[y - 3] + 3u[y - 2] + 2u[y - 1]     A := Table[ u[k], {k, 1, 20}]          Sum[ A[[i]], {i, 1, Length[A]}]      I can't find sum of even numbers. How do I tell _Mathematica_ to do that ?


title: How does TensorReduce use assumptions?

text: I would like to use `TensorReduce` by assuming that certain patterns of functions are tensors. From documentation of `TensorReduce`: > If `TensorDimensions[ten]` does not return a list of dimensions, then the > expression ten is returned unchanged. I would have inferred from above that if I modify `TensorDimensions[ten]`, `TensorReduce` should work. Thus I did               Unprotect[TensorDimensions];     TensorDimensions[f_[g__]] := d & /@ {g};     Protect[TensorDimensions];          Assuming[ t ∈ Arrays[{d, d}, Antisymmetric[All]] ,      TensorReduce @ TensorContract[ t\[TensorProduct]f[DN, DN], {1, 4}]]      However, this doesn't work. i.e. `TensorReduce` does nothing, and the result is               TensorContract[ t\[TensorProduct]f[DN, DN], {{1, 4}}]      To compare, having defined               Assuming[ t ∈ Arrays[{d, d}, Antisymmetric[All]] &&                f[DN, DN] ∈ Arrays[{d, d}],      TensorReduce @ TensorContract[ t\[TensorProduct]f[DN, DN], {1, 4}]]      > >     - TensorContract[ t\[TensorProduct]f[DN, DN], {{2, 4}}] >   the result is indeed simplified as desired: I'd like to understand what are the assumptions that `TensorReduce` really uses. Is there a way that I can work with `TensorReduce` as above, with pattern like declaration of tensors? PS: Currently I generate a list of assumptions of `f_[g__]` using `Cases`, and put those assumptions together in `Assuming`. This makes the code slow and ugly.


title: How NDSlove run with central difference in space, Crank-Nicolson in time, eqn is solved by Newton-Raphson iteration, and control spatial/time step?

text: I want to solve the following partial differential equation (PDE) by NDSolve in MMA. ![enter image description here](http://i.stack.imgur.com/M9BKg.png) I want to plot the profile of h(x,t) and find out the time at which h=0 or h->0. I tried the following code, but it does not work. There seems some singularity near h=0 and the grid spacing is too large according to the warning messages given by MMA.               mdfun = First[     h /. NDSolve[{D[h[x, t], t] + D[h[x, t]^-1*D[h[x, t], x], x] +      D[h[x, t]^3*D[h[x, t], {x, 3}], x] == 0,      h[-Pi*2^0.5, t] == h[Pi*2^0.5, t],      h[x, 0] == 1 + 0.1*Sin[x/2^0.5]},      h, {x, -Pi*2^0.5, Pi*2^0.5}, {t, 0, 10},      MaxStepSize -> 8.8857658763167324940317619801214/40]]     Plot3D[Evaluate[mdfun[x, t]], {t, 0, 4.05}, {x, -Pi*2^0.5, Pi*2^0.5},      PlotPoints -> 100]      Now I have three questions:   1. I am wondering whether MMA solves a PDE numerically by Finite Difference Method, or some other method?   2. Is there any possible to assign explicitly the method using by MMA? For example, I want to use space central difference scheme, Crank-Nicolson Method in time, and the resulting difference equation is solved by Newton-Raphson iteration.   3. NDSolve works by taking a sequence of spatial steps in x and time steps in t, then using an adaptive procedure to determine the size of these steps. How to control the spatial mesh size and time step in my program? For example, I want to firstly fix the spatial grid while reducing the time step for successive iterations until the change in the computed value is negligible, then the time step is fixed and the spatial grid is refined to run the iterations to find the solution.


title: Joining some strings in a list of strings

text: So, say I have a list of strings, representing lines in a file, like so:               Pillsy`testLines =      {"foo",       "bar\\",       "baz\\",       "quux",       "wongle\\ bongle",       "wingle",       "pringle\\",       "prongle",       "blort"};      These use the (common?) convention that if a line ends with a backslash, it should be appended to the following line, giving a result like this:               Pillsy`testResult =       {"foo", "barbazquux", "wongle\\ bongle", "wingle", "pringleprongle", "blort"};      Now, the naïve way to accomplish this is to use pattern matching, but the performance is likely to be really awful if you've got a lot of lines:               Pillsy`naiveCatenateContinuedLines[lines : {___String}] :=      lines //.       {before___, line1_, line2_, after___} /;         StringMatchQ[line1, ___ ~~ "\\" ~~ EndOfString] :>        {before, StringDrop[line1, -1] <> line2, after};      You've got two potential performance hits, one with repeated breaking of the list into `BlankNullSequence`s, and the other with repeated `StringJoin`s (I'm actually not 100% sure that the last is avoidable, but it's certainly **possible** that `StringJoin`ing many strings at once is efficient, and that would explain why `StringJoin` has the `Flat` attribute). I ended up doing what any functional programmer does when confronted with a problem they don't know how to solve: I used `Fold` to accumulate a linked list. This solution works, and seems like it could be efficient (in part by exploiting the `Flat`ness of `StringJoin`), but I haven't done actual performance testing. **EDIT** : Now I have a file to test with (linked below), and this solution runs in about 4 milliseconds. The naive solution takes about 25 milliseconds, and scales quadratically with length.               Pillsy`catenateContinuedLines[lines : {___String}] :=      Module[{catenating},       Attributes[catenating] = {HoldAllComplete};            Flatten@Fold[         Function[{acc, line},          With[{            (* This allows me to avoid repeating myself, but is a bit nuts. *)            thunk =             If[              0 < StringLength@line && StringTake[line, -1] == "\\",              With[{dropped = StringDrop[line, -1]},               catenating@StringJoin[#, dropped] &],              StringJoin[#, line] &]            },           acc /. {             {init_, catenating[arg_]} :> {init, thunk[Unevaluated@arg]},             _ -> {acc, thunk[""]}             }]],         {},         lines]]      I checked briefly to see if there was an option for `Import[file, {"Text", "Lines"}]` that would allow you to specify a line continuation character, but nothing jumped out at me. I have a solution, but it seems needlessly convoluted. **EDIT** to add: I have a semi-realistic test file that's long enough that I can do some timing, but unfortunately can't make it public. **EDIT** again to add: OK, I munged any identifying information in the file beyond all recognition, so if you want something for test timings, you can find it here.


title: Using Sort vs SortBy

text: So I have two lists, A and B. I put them into `lists = {A,B}`I want to sort A such that `Im[#1]<Im[#2]&` which I can do fine through `Sort[]` .The problem is that I want to keep the order the same so that A[[1]] stays with B[[1]] and A[[n]] stays with B[[n]]. When I try `SortBy[lists\\[Transpose],Im]` it does not sort in the same order as the sort function does, but it keeps the A[[n]] with the B[[n]] EDIT::Example (I still can't figure out how to nicely format)               A={0.651301, 0.671298, -0.000107956 + 0.735512 I,  9.93631*10^-6 + 0.764605 I, 0.965926,     0.97048, 0.0344992 + 1.4214 I,  0.0028631 + 1.4505 I, -0.0626803 + 1.78014 I, -0.12443 + 1.98252 I,  0.167724 + 2.24691 I}                    B={{-2.44558*10^-6 - 1.01111*10^-6 I, -5.65309*10^-6 + 0.000018407 I,        0.000141659 + 0.0000359384 I,        0.000116428 - 0.000796561 I, -0.00506101 - 0.000580627 I,        0.000125772 + 0.0163992 I, 0.0817805 + 9.02056*10^-16 I,        0.000126129 + 0.0177878 I, 0.00153561 - 0.000581627 I,        0.000126597 + 0.000582107 I, -9.00118*10^-7 -         0.0000107003 I, -0.0000285126 - 0.0000117884 I, -0.0000659084 +         0.000214604 I, 0.00165158 + 0.000419 I,        0.00135741 - 0.00928697 I, -0.0590055 - 0.00676943 I,        0.00146635 + 0.191195 I, 0.953465 + 0. I, 0.00147052 + 0.207385 I,        0.0179034 - 0.00678109 I,        0.00147597 + 0.00678669 I, -0.0000104943 -         0.000124753 I}, {0.000116916 - 0.000811922 I, -0.00509776 -         0.000578293 I, 0.000129979 + 0.0163556 I,        0.079143 - 1.63203*10^-14 I, 0.000130143 + 0.0177879 I,        0.00147459 - 0.000580172 I,        0.00013056 + 0.00059606 I, -2.43588*10^-6 - 0.0000107979 I,        4.37224*10^-6 + 9.43651*10^-6 I, -3.88572*10^-7 + 7.61008*10^-9 I,        7.14058*10^-8 + 9.11373*10^-8 I,        0.00140496 - 0.00975669 I, -0.0612586 - 0.00694921 I,        0.00156193 + 0.196542 I, 0.951044 + 0. I, 0.0015639 + 0.213753 I,        0.0177198 - 0.0069718 I,        0.00156891 + 0.00716271 I, -0.0000292714 - 0.000129756 I,        0.0000525402 + 0.000113396 I, -4.66939*10^-6 + 9.14486*10^-8 I,        8.58068*10^-7 + 1.09518*10^-6 I}, {-0.00335176 - 0.00246906 I,        0.000695327 + 0.0163725 I, -0.00001055 -         0.0718776 I, -0.000733202 + 0.0162968 I,        0.00326678 - 0.00242532 I, -0.000740926 + 0.000255124 I,        0.00011033 + 0.0000490118 I, -0.0000121133 - 0.0000148216 I,        2.39696*10^-8 + 2.36464*10^-6 I,        1.63148*10^-7 - 2.69095*10^-7 I, -3.15697*10^-8 + 1.27853*10^-8 I,        0.0325148 - 0.0441254 I, -0.215566 + 0.00912321 I,        0.94636 + 0. I, -0.214567 - 0.00968502 I,        0.0319261 + 0.0430159 I, -0.0033576 - 0.00975571 I, -0.000645516 +         0.00145253 I,        0.000195169 - 0.000159459 I, -0.0000311336 + 3.1102*10^-7 I,        3.54266*10^-6 + 2.14857*10^-6 I, -1.68274*10^-7 -         4.1568*10^-7 I}, {-1.79728*10^-7 -         3.0708*10^-7 I, -8.50791*10^-8 + 2.61365*10^-6 I,        0.0000132867 - 0.0000158544 I, -0.000117531 + 0.0000495126 I,        0.000766382 + 0.000269089 I, -0.00325494 - 0.0024853 I,        0.000752542 + 0.0162187 I,        8.95415*10^-7 - 0.0689027 I, -0.000751796 + 0.0162166 I,        0.0032569 - 0.00249056 I, -0.000776443 + 0.000265907 I,        4.20299*10^-6 - 2.46001*10^-6 I, -0.0000357732 - 1.16402*10^-6 I,        0.000217003 + 0.000181853 I, -0.000677703 -         0.00160864 I, -0.00368289 + 0.0104896 I,        0.0340159 - 0.0445509 I, -0.221987 + 0.010303 I,        0.943075 + 0. I, -0.221957 - 0.010287 I,        0.0340891 + 0.0445769 I, -0.00363963 -         0.0106272 I}, {-0.0000127475 + 0.0000447811 I,        0.000264418 + 0.0000598865 I,        0.000164152 - 0.0012308 I, -0.00570662 - 0.000548632 I,        0.000189568 + 0.0156506 I, 0.0523487 - 2.28983*10^-16 I,        0.000191336 + 0.0176777 I, 0.000560154 - 0.000551883 I,        0.000187274 + 0.000764703 I, -0.0000430526 - 5.84824*10^-6 I,        8.05585*10^-6 + 0.0000148798 I, -0.000220415 + 0.000774304 I,        0.00457202 + 0.00103549 I,        0.00283833 - 0.0212815 I, -0.0986724 - 0.00948632 I,        0.0032778 + 0.270612 I, 0.905154 + 0. I, 0.00330836 + 0.305662 I,        0.00968555 - 0.00954253 I,        0.00323813 + 0.0132224 I, -0.000744416 - 0.000101121 I,        0.000139292 + 0.000257285 I}, {0.000262801 + 0.0000592442 I,        0.000164475 - 0.00123486 I, -0.00571449 - 0.00054799 I,        0.000190521 + 0.015638 I, 0.0520548 - 1.61329*10^-16 I,        0.000192306 + 0.0176744 I, 0.000545908 - 0.000551356 I,        0.000188135 + 0.000766815 I, -0.0000438809 - 5.72083*10^-6 I,        8.14335*10^-6 + 0.0000150479 I, -1.6632*10^-6 + 4.54164*10^-7 I,        0.00456548 + 0.00102921 I,        0.00285732 - 0.0214524 I, -0.0992743 - 0.00951989 I,        0.0033098 + 0.27167 I, 0.904315 + 0. I, 0.00334081 + 0.307047 I,        0.00948372 - 0.00957837 I,        0.00326835 + 0.0133214 I, -0.000762316 - 0.0000993844 I,        0.000141469 + 0.000261419 I, -0.0000288938 +         7.88991*10^-6 I}, {0.00324399 + 0.0151276 I,        0.000797234 - 0.0328468 I, -0.00205405 + 0.0139652 I,        0.00309583 - 0.0034084 I, -0.00125203 + 0.000542748 I,        0.000308022 + 0.0000414382 I, -0.0000545185 - 0.0000426274 I,        4.65124*10^-6 + 0.0000121837 I,        4.78853*10^-7 - 2.32735*10^-6 I, -2.68691*10^-7 + 2.83621*10^-7 I,        6.02922*10^-8 - 1.38336*10^-8 I, -0.382907 + 0.0918831 I,        0.836255 + 0. I, -0.356603 - 0.0436393 I,        0.088636 + 0.076666 I, -0.014583 - 0.0315217 I, -0.000864141 +         0.00786298 I,        0.00105095 - 0.00141351 I, -0.000307133 + 0.000125871 I,        0.0000595133 + 0.0000107468 I, -7.38245*10^-6 - 6.66148*10^-6 I,        3.8922*10^-7 + 1.52555*10^-6 I}, {2.82086*10^-7 +         2.97789*10^-7 I, -4.59823*10^-7 -         2.41021*10^-6 I, -5.01508*10^-6 + 0.0000122796 I,        0.0000564073 - 0.0000412174 I, -0.000307185 + 0.000029994 I,        0.00120889 + 0.000596331 I, -0.00288513 - 0.00343464 I,        0.00114029 + 0.0135455 I,        0.0000642005 - 0.0325252 I, -0.0009149 + 0.0138614 I,        0.00312207 - 0.00369177 I, -7.71767*10^-6 + 7.33966*10^-6 I,        0.0000625579 - 0.0000120629 I, -0.000319098 - 0.000129588 I,        0.00107311 + 0.00146251 I, -0.000794541 -         0.00797456 I, -0.0154218 + 0.0314195 I,        0.089033 - 0.0750887 I, -0.351653 + 0.030302 I,        0.844524 + 0. I, -0.359961 - 0.0230451 I,        0.0960172 + 0.0808758 I}, {-0.000892536 - 0.0253483 I,        0.00398093 + 0.0167517 I,        0.00137243 - 0.00591337 I, -0.0015116 + 0.00179952 I,        0.000585214 - 0.000258793 I, -0.000165802 - 0.0000248498 I,        0.0000301279 + 0.0000234092 I, -2.58394*10^-6 -         7.57878*10^-6 I, -3.51243*10^-7 + 1.52852*10^-6 I,        2.06661*10^-7 - 1.94772*10^-7 I, -4.87722*10^-8 + 8.31709*10^-9 I,        0.808747 + 0. I, -0.538275 + 0.10806 I,        0.186895 + 0.0503687 I, -0.0556474 - 0.0501875 I,        0.00759005 + 0.0189387 I,        0.000977896 - 0.00525555 I, -0.000779761 + 0.000933787 I,        0.000244404 - 0.000073836 I, -0.0000483136 - 0.0000129077 I,        5.9747*10^-6 + 6.80398*10^-6 I, -2.10308*10^-7 -         1.5635*10^-6 I}, {-2.51454*10^-7 - 1.09646*10^-7 I,        8.24658*10^-7 + 1.17552*10^-6 I, -5.98381*10^-7 -         7.07371*10^-6 I, -0.0000140755 + 0.0000294825 I,        0.000112869 - 0.0000806044 I, -0.000523179 + 0.0000579476 I,        0.00169884 + 0.000648417 I, -0.00347909 - 0.00374662 I,        0.00369489 + 0.0120913 I, -0.00129613 - 0.020651 I, -0.00517517 +         0.0120722 I,        4.45129*10^-6 - 8.67954*10^-6 I, -0.0000435543 + 0.0000266477 I,        0.000252369 - 5.47974*10^-6 I, -0.00101494 - 0.00056519 I,        0.00260914 + 0.00418509 I, -0.000891151 - 0.018696 I, -0.0267954 +         0.0588452 I, 0.140712 - 0.115123 I, -0.437333 + 0.104194 I,        0.735762 + 0. I, -0.4169 - 0.210549 I}, {1.30427*10^-7 +         1.21266*10^-7 I, -2.01494*10^-7 -         8.56205*10^-7 I, -1.39899*10^-6 + 3.95881*10^-6 I,        0.0000142534 - 0.0000114838 I, -0.0000753911 + 9.27582*10^-6 I,        0.000259802 + 0.000101574 I, -0.000571574 - 0.000745225 I,        0.000756398 + 0.00272191 I,        0.00135245 - 0.0061366 I, -0.00737014 + 0.0139213 I,        0.00132698 - 0.0177768 I, -4.48592*10^-6 + 5.61005*10^-6 I,        0.0000338329 - 0.0000106751 I, -0.00016343 - 0.0000443834 I,        0.000504691 + 0.000538816 I, -0.000599442 -         0.0030045 I, -0.00330544 + 0.0107546 I,        0.028258 - 0.025227 I, -0.107208 + 0.0385957 I,        0.250884 + 0.035973 I, -0.582065 - 0.254641 I, 0.718994 + 0. I}}


title: Strange Tilt on error notification

text: I was testing the source code of the answers to this question. And when I tried this response and maxed out most of the manipulators, this is what I got. ![enter image description here](http://i.stack.imgur.com/5pBFl.png) ![enter image description here](http://i.stack.imgur.com/mqx7H.png) ![enter image description here](http://i.stack.imgur.com/lCDDa.png) ![enter image description here](http://i.stack.imgur.com/SVeP3.png) What went wrong that the errors are tilted. Can anyone explain? Here’s the link for the Notebook. P.S. These are not Photoshopped.


title: How do I upload a graph as an adjacency list and find the betweenness centrality?

text: I have an undirected simple graph in a .txt file formatted as an adjacency list like this:               100 200     200 300     300     400 500 600 700 800 900     ...      Every number is a node id and the graph is unweighted. The first number in each row is that row's node and any following numbers are adjacent nodes. In this example node 100 has node 200 as its neighbor, node 200 has nodes 100 and 300 as its neighbors, and node 300 has node 200 as its neighbor. I am trying to find the betweenness centrality of each node. I found out about the `Input`, `BetweennessCentrality`, and `FromAdjacencyLists` functions but I cannot seem to use them correctly.   Does my data need to be formatted differently?   How do I get from inputing my data to using `BetweennessCentrality`? I don't know much about using _Mathematica_ so I might be missing something obvious.


title: NIntegrate failling on floating value

text: I'm trying to take the following integral               NIntegrate[         ((Sin[Q 1]-Q 1*Cos[Q 1])/(Q 1)^3)^2          * S[Q,0.4,2]          * Q BesselJ[0,0.5Q]         , {Q,0,Infinity}]      but it fails with the following error message               First::first: "{} has a length of zero and no first element."      However, if I replaced the 0.5 in the Bessel function with a 1/2               NIntegrate[((Sin[Q 1] - Q 1*Cos[Q 1])/(Q 1)^3)^2                 * S[Q, 0.4, 2]                 * Q BesselJ[0, Q/2]                , {Q, 0, Infinity}]      I get back the result (0.046852). S[Q,0.4,2] is included below for completeness, but it's mostly just trig functions and polynomials, so I'd be surprised if it was the issue. It certainly doesn't contain a call to first. Why would the calculation fail for the floating point value but succeed on the rational one? Also, what does any of this have to do with First?               S[Q,0.4,2]==(1+0.095493 (-(0.000127501 (118891. +208412. Q^2-(392972. Q^4-104206. Q^2 (-2+3.93305 Q^2)+4953.78 (24-47.1966 Q^2+15.4689 Q^4)) Cos[1.98319 Q]+2 Q (-117892.-30305.8 Q^2) Sin[1.98319 Q]))/(Q^6 (1+1/Q^60.0000121755 (118891. +208412. Q^2-(392972. Q^4-104206. Q^2 (-2+3.93305 Q^2)+4953.78 (24-47.1966 Q^2+15.4689 Q^4)) Cos[1.98319 Q]+2 Q (-117892.-30305.8 Q^2) Sin[1.98319 Q])))-1/Q^40.00681547 ((-16109.8 Q^2+138.778 (144+31.4644 Q^2)) Cos[1.98319 Q]-4 (-4061.58 Q^2+138.778 (36+7.3277 Q^2)) Cos[2 Q]+8 Q (3217.18 Sin[1.98319 Q]-3259.16 Sin[2 Q]))+(10.0812 (Q^3 Cos[2 Q]-3.6092 (26.0526 +Q^2) Sin[2 Q]))/(678.74 Q+Q^5)))/(1-0.904507 (-(0.000127501 (118891. +208412. Q^2-(392972. Q^4-104206. Q^2 (-2+3.93305 Q^2)+4953.78 (24-47.1966 Q^2+15.4689 Q^4)) Cos[1.98319 Q]+2 Q (-117892.-30305.8 Q^2) Sin[1.98319 Q]))/(Q^6 (1+1/Q^60.0000121755 (118891. +208412. Q^2-(392972. Q^4-104206. Q^2 (-2+3.93305 Q^2)+4953.78 (24-47.1966 Q^2+15.4689 Q^4)) Cos[1.98319 Q]+2 Q (-117892.-30305.8 Q^2) Sin[1.98319 Q])))-1/Q^40.00681547 ((-16109.8 Q^2+138.778 (144+31.4644 Q^2)) Cos[1.98319 Q]-4 (-4061.58 Q^2+138.778 (36+7.3277 Q^2)) Cos[2 Q]+8 Q (3217.18 Sin[1.98319 Q]-3259.16 Sin[2 Q]))+(10.0812 (Q^3 Cos[2 Q]-3.6092 (26.0526 +Q^2) Sin[2 Q]))/(678.74 Q+Q^5)))


title: FullSimplify Over Reals Automatically

text: Frequently, Mathematica will produce some expression in a complicated form, with a number of unset variables. For me, it is rare that I would be interested in solutions that are generalized to both real and imaginary arguments, so my method is usually to run a FullSimplify on the expression, with every unset variable being assumed be an element of the reals:               FullSimplify[a+Log[Exp[b^2 - c^2]]-Log[d],         Assumptions->{a \[Element] Reals, b \[Element] Reals,                       c \[Element] Reals, d \[Element] Reals}]      This is quite cumbersome, especially if the expression has many unset parameters. My question is: Can someone write a function that automatically extracts all unset parameters in an expression, and then uses that to set the Assumptions parameter automatically? The second part I know how to do (`Element[#, Reals] & /@ pars`), but not the extracting the unset parameters part. Ideally it would only take the function itself as its argument:               fullSimplifyReals[a+Log[Exp[b^2 - c^2]]-Log[d]]      **Edit:** I am accepting Szabolics' answer for now, as it seems to do what I want it to in my limited testing. For convenience, here is the functional form of Szabolics' answer:               fullSimplifyReals[x_] := Assuming[_Symbol \[Element] Reals, FullSimplify@x];


title: Graph with $\{a,b\}$ as Vertex Instead of Number

text: I'm trying to create a graph which has $\{a,b\}$ as labels:               g := Graph[{1 \[UndirectedEdge] 9, 1 \[UndirectedEdge] 10,         1 \[UndirectedEdge] 8, 10 \[UndirectedEdge] 2,         10 \[UndirectedEdge] 5, 9 \[UndirectedEdge] 3,         9 \[UndirectedEdge] 6, 8 \[UndirectedEdge] 7,         8 \[UndirectedEdge] 4, 7 \[UndirectedEdge] 3,         7 \[UndirectedEdge] 2, 6 \[UndirectedEdge] 2,         6 \[UndirectedEdge] 4, 5 \[UndirectedEdge] 3,         5 \[UndirectedEdge] 4}]      Any help would be appreciated.


title: Can I define a "postfix map" operator with comparable precedence behavior to //

text: I am trying to define a "postfix map" operator (denoted `$OP$` for now) that behaves thus:               {1, 2, 3} $OP$ # + 1 & == {2, 3, 4}      and               {1, 2, 3} // RotateLeft $OP$ # + 1 & == {3, 4, 2}      and               {1, 2, 3} // RotateLeft $OP$ # + 1 & // Total == 9      I hope not to need parentheses when I pipe results forward using a combination of // and my custom `$OP$`. Is this possible? My guess is that it is not because there is no operator with the same precedence as `//`. I understand that I will need to use either an unassigned operator (e.g., CirclePlus) or another symbol as an infix operator; that I cannot modify precedence; and that the ability to define custom syntax is limited (e.g., `@//` can't be defined). Looking at "Operator Input Forms", it seems the closest I can get to `//` with regard to precedence is either Colon or VerticalSeparator, as               Precedence /@ {Colon, Postfix, VerticalSeparator} == {80., 70., 60.}      **Does this mean that there is simply no way to define the operator I seek in a way that will never require parentheses when it is chained with`//`?** For example, given               SetAttributes[VerticalSeparator, HoldAll];     VerticalSeparator[l_, f_] := f /@ l;      this does not work               {1, 2, 3} \[VerticalSeparator] # + 1 & // Total == {(1 + #1)[1], (1 + #1)[2], (1 + #1)[3]}      Similarly, with               SetAttributes[Colon, HoldAll];     Colon[l_, f_] := f /@ l;      this does not work               {1, 2, 3} // RotateLeft \[Colon] # + 1 & == {2, 3, 1}      I have read, for example, Prefix operator with low precedence , http://stackoverflow.com/questions/5304858/custom-postfix-notation-apply- function .


title: custom precedence for custom infix operator with InfixNotation

text: I am trying to define several custom operators with custom precedence to implement geometric algebra. Loading the notation package               << Notation`      I can define custom infix operators, e.g.               InfixNotation[ParsedBoxWrapper["\[Wedge]"],exteriorProd]      but they will inherit the precedence of [Wedge]. Next I tried to define               InfixNotation[ParsedBoxWrapper[TagBox["\[Wedge]",ext,SyntaxForm->"a\[Vee]b"]], exteriorProd]      which does the job for output, but I can not find a way whatsoever to enter this operator by keyboard (e.g. as an alias). When I try to convert the tag box to an expression it will just apply the tag to first argument... Is there any other box (besides InterpretationBox) that accepts the SyntaxForm option and does what I want? By the way,   1. SyntaxForm seems to depend very much on the argument that you write next to the "example operator", even when it looks like the operator is usually a binary/infix operator.   2. The function Infix[] (not to be confused with InfixNotation[]) seems not to be able to deal correctly with the precedence option.   3. (slightly out of context) it seems to me the function Symbolize[] shows a different behaviour than it is shown in the documentation. is it correct to assume that the Notation package is not yet very mature? Thanks a lot, Hendrik Edit: Is it viable to use "non-infix" operators instead, then "parse" (convert) the input to an "infix" form like exteriorProd[a,b,c,d] and deal with displaying it in an infix way in a separate effort?


title: Graphics, PlotRange and/or PlotRegion

text: Consider the following snippet of code:                 Module[{pts},        pts = {{0, 0}, {0, 2}, {6, 0}};        Graphics[{Blue, Polygon[pts]}, PlotRange -> {{0, 4}, {0, 4}}]       ]      A graphic is displayed that doesn't entirely fall within the plotrange. Question : I have a Panel that displays graphics of different shapes and size. When automatic resizing of the graphic is not an option what is the best way to calculate the plotrange ( or any other suitable option ) so that graphics fit ?


title: How to use ImageMultiply[] over a list of strings?

text: I'm trying to do the following:               l = FileNames[];     s[x_] := ToString[l[[x]]]     t = Table[s[x], {x, 1, Length[l]}];     i[x_] := Import[t[[x]]]     m[x_] := ImageMultiply[i[x], i[x + 1]]      This is supposed to take two images of one folder and multiply them. But I want to take two images and multiply them, then I want to take the next two, multiply them and multiply to the last multiplied images and proceed like this for all the images in the folder. I already have a table with all the file locations, the problem is that `ImageMultiply[]` doesn't take lists as inputs. I wasn't able to do something like:               ImageMultiply[t]      Which would solve the problem, but the input of this function is:               ImageMultiply[image1,image2,...]      And not:               ImageMultiply[{image1,image2, ...}]      Perhaps there is some way of _drop_ all the elements out of the list into that function, I don't know about it. I've also looked some functions that look extremelly similar to what I'm trying to do, I guess that there's some way to use `NestList[]` or `Nest[]` to do it, but I've tried a few experiments and it resulted in hazard...$^1$ $1$ - I don't remember precisely which arguments (then I chose arbitrary ones) I used in that function, but it really froze my computer.


title: Connecting to Raspberry Pi's Wolfram Language kernel from a PC's Mathematica front end

text: Recently I bought a Raspberry Pi and I installed the Wolfram Language on it. Comparing WL 10.0's commands with _Mathematica_ 9.0.1.0's commands, I found 328 additional commands and variables. I understand that WL is in a preliminary version so more commands may be added (or removed) in the near future but since this seems to be the future, I believe learning as quickly as possible the new possibilities would be a strong asset. Since my PC's front end is much faster than the RPi's, I would like to call these through my _Mathematica_ 9.0.1 front end and get the results in the same front end. This would save a lot of time lost in going forward-backward between them. So how can I call the WL kernel from my PC (I have attached both to an Ethernet LAN)?


title: Under what conditions does Mathematica give a natural antiderivative when integrating?

text: Natural antiderivative is defined as follows, using Fourier transform: $$f^{(-1)}(x)=\frac{i}{2\pi}\int_{-\infty}^{+\infty} \frac{e^{- i \omega x}}{\omega} \int_{-\infty}^{+\infty}f(t)e^{i\omega t}dt \, d\omega$$ Particularly, if $x=0$, $$f^{(-1)}(0)=\frac{i}{2\pi}\int_{-\infty}^{+\infty} \frac{1}{\omega} \int_{-\infty}^{+\infty}f(t)e^{i\omega t}dt \, d\omega$$ Expressed as _Mathematica_ code:               (I/Sqrt[2*Pi])*Integrate[(1/w)*FourierTransform[f[t], t, w], {w, -Infinity, Plus[Infinity]}]      That said, I wonder if _Mathematica_ always adheres to the rule of providing the antiderivative which would satisfy this condition. For instance, `Integrate[Sin[x], x]` gives `-Cos[x]`, which satisfies the condition as `-Cos[0] == -1`. I wonder how much this rule is adhered to in the output of `Integrate`.


title: Extracting counts of contiguous zeros and ones from a binary array

text: I'm a novice with _Mathematica_ , but you guys have been very helpful to me in the past. I have a binary array [100, J repetitions] consisting of zeroes and ones. I'd like to extract a histogram of the number of contiguous ones in these individual columns. Assuming I have some variable `f[i, j]` containing these data what I have is:               Do[       bhist = SparseArray[{1, 1} -> 0, {1, 100}, 0];        index = 1;        Do[If[f[[j, i]] == 1, index++, bhist[[index]] + 1; index = 1],          {i, 1, 100}];        bhista[j] = bhist;,        {j, 1, rep}];      where `bhist` will record the number of contiguous 1s and how many times that ensemble occurs. This will loop over all j repetitions of the monte carlo. The problem is that I seem to only be generating zeroes despite the fact that my simulation does generate contiguous 1s. Is my `If` expression setting the index to 1 before it records the value in my `bhist` variable? Or is something else going on? Furthermore, if I wanted to then extract a histogram from `bhista`, is there a more efficient way of doing this than flattening it and bin counting?


title: Correct way to use Notation

text: I have tried to create some Notation declarations as follows               << Notation`     Notation[Subscript[x_, i_] \[DoubleLongLeftRightArrow] x[i]]     Notation[OverBar[x_] \[DoubleLongLeftRightArrow] mean[x]]      Mathematica9 throws the following errors for the declarations > Notation::noexbtag: The external representation Subscript[x_, y_] does not > have an embedded TemplateBox with tag NotationTemplateTag. The Notation > statement Notation[Subscript[x_, y_][DoubleLongLeftRightArrow]x[y]] may not > have been entered using the palette, or the embedded TemplateBox may have > been deleted. The embedded TemplateBox ensures correct parsing and retention > of proper styling and grouping information. >> and > Notation::noexbtag: The external representation Overscript[x_, _] does not > have an embedded TemplateBox with tag NotationTemplateTag. The Notation > statement Notation[Overscript[x_ , _][DoubleLongLeftRightArrow]mean[x]] may > not have been entered using the palette, or the embedded TemplateBox may > have been deleted. The embedded TemplateBox ensures correct parsing and > retention of proper styling and grouping information. >> respectively. It is not really clear to me what is going on. I read the documentation for `TemplateBox` and looked up `NotationTemplateTag` which seems to have been replaced by `ParsedBoxWrapper`. After following some related function I thought the following might be what is required:               Notation[ToBoxes[Subscript[x_, y_]]\[DoubleLongLeftRightArrow] x[y]]     Notation[ToBoxes[OverBar[x_]] \[DoubleLongLeftRightArrow] mean[x]]      or perhaps               Notation[MakeBoxes[Subscript[x_, y_]]\[DoubleLongLeftRightArrow] x[y]]     Notation[MakeBoxes[OverBar[x_]] \[DoubleLongLeftRightArrow] mean[x]]      but both of those throw errors as well. So what is the right way to declare these notations? I am aware that setting up subscripts as a notation for function application is not something you would want to do in practice, but I am just experimenting. Also do I actually need to import the Notation package or `Notation` buit-in with Mathematica9?


title: Is there a way to riffle more than two lists?

text: I thought `Riffle` would generalize such that               Riffle[{a,b,c},{1,2,3},{x,y,z}]      would return               {a,1,x,b,2,y,c,3,z}      It turns out that's not the case. What's the easiest way to do a multi-list riffle?


title: triple NIntegrate fails

text: Here's m problem simpler in terms of codes               Clear["Global`*"]     e = 0.454648; A = 1.6297; rs = 3.68888; kb = 0.001872041; Na =       6.02214129*10^23;     ep = 0.2961; p = 3.78;     pot[r_] := -e (1 - (1 - Exp[-A (r - rs)])^2)          B[T_] := -2 \[Pi] Na NIntegrate[(Exp[-pot[r]/(kb T)] - 1) r^2, {r, 0,          Infinity}] 10^-24     C2[T_] := 8 \[Pi]^2 /3 Na ^2 10^-48 NIntegrate[        NIntegrate[         NIntegrate[          r12^2 (1 - Exp[-pot[r12]/(kb T)]) r13^2 (1 -              Exp[-pot[r13]/(kb T)]) (1 -              Exp[-pot[Sqrt[r12^2 + r13^2 - 2 r12 r13 n]]/(kb T)]), {r13, 0,            150}], {r12, 0, 150}], {n, 1, 150}]      My problem is that second integration function C2[T_] keeps giving me zero with 3 warnings of > NIntegrate::izero: Integral and error estimates are 0 on all integration > subregions. Try increasing the value of the MinRecursion option. If value of > integral may be 0, specify a finite value for the AccuracyGoal option. >> and if I use one NIntegrate function               C2[T_] :=       8 \[Pi]^2 /3 Na ^2 NIntegrate[        r12^2 (1 - Exp[-pot[r12]/(kb T)]) r13^2 (1 -            Exp[-pot[r13]/(kb T)]) (1 -            Exp[-pot[Sqrt[r12^2 + r13^2 - 2 r12 r13 n]]/(kb T)]), {r13, 0,          150}, {r12, 0, 150}, {n, 1, 150}]      I get 3 of this warning > NIntegrate::errprec: Catastrophic loss of precision in the global error > estimate due to insufficient WorkingPrecision or divergent integral. >> any ideas how to fix it? The original integration is ![enter image description here](http://i.stack.imgur.com/vex2k.gif)


title: ListPointPlot3D with connected points?

text: With the command `ListPlot[data,Joined -> True]` I can visually connect adjacent data points in the array with lines. However, this option appears to be missing in `ListPointPlot3D`? Is there some manner with which to join with to join (with a line) adjacent three-dimensional points? There will be a large number of points in my data structure, and I'd really like to keep the standard output format of `ListPointPlot3D`.


title: Is there an easy way to create a "IntensitySquaredCentroid" using ComponentMeasurements?

text: One of the options in ComponentMeasurements is to compute a centroid based on the pixel values of some underlying image. We can write:               ComponentMeasurements[{MorphologicalComponents[image], image}, "IntensityCentroid"][[All, 2]];      Is it possible, however, to have something like an intensity squared or cubed centroid?


title: PixelValue with pixel indices

text: How Can we use PixelValue with pixel indices?


title: Non linear model fit mathematica

text: I want to fit experimental data (temp,alpha) to the following equation for calculating k and Ea                   -Log[alpha]^n = function(k,Ea,temp)      However i do not know exact value of "n". By this time i am using trial and error for "n" and select value based on the maximum r^2 , but this is time consuming and value of may be inaccurate. Is there any method, through which i can get the optimum value on "n" based on a specified range i.e. 2 to 3, along with k and Ea for which r^2 is the best one. Here is my code. i am sorry if it seems messy                   data = Import["data.xlsx", {"Sheets", "control", All, {1, 2, 3}}];         R = 0.008314; Ea =.; k =.; RHS =.; T =.; n =.; b = 10; n =.; temp =.;         alpx =.;         RHS = Integrate[k/b Exp[-(Ea/R) (1/T - 1/370)], T];         model = RHS;         n = 3.1;         alpx = data[[All, 2]]^(1/n);         temp= data[[All, 1]];         alp = data[[All, 3]];         bb = Table[{(alpx[[i]]), temp[[i]]}, {i, 1, Length[temp]}];         sol = NonlinearModelFit[bb, model, {k, Ea}, T] //Chop;         newRHS = Normal[sol];         sol[{"BestFitParameters", "ParameterTable", "EstimatedVariance",          "ANOVATable", "RSquared"}]              Plot[(Exp[-newRHS^n]), {T, 360, 400}, PlotStyle -> {Black, Thick},          Frame -> True,          FrameLabel -> {Style["Temperature(K) ", 16],          Style["Relative crystallinity  ", 16]}, GridLines -> Automatic,          PlotLabel -> "Control", ImageSize -> Medium];


title: need help rotating an object about the z-axis using animation

text: This should be an easy question for anyone familiar with 3D animations. I have a 2D shape denoted by the equation                      ((x-1)^2+y^2) ((x+1)^2+y^2)==1      and I want to illustrate its relation to a Horn Torus. To do this, I would like to rotate it about the $z$-axis in 3-space and have an outline of the shape be created behind it. I appreciate any help you guys can give me.


title: How to discretize a nonlinear PDE fast?

text: I wish to numerically solve the following PDE. Although there are some complete discussions for solving PDEs in tutorial/NDSolvePDE, there is no hint for the nonlinear case by discretization. Thus, I will be thankful to receive some helps on the following NPDE where $x \in [0,1]$, $t \in [0,2]$, The equation is $$\frac{\partial u(x,t)}{\partial t}+u(x,t) \frac{\partial u(x,t)}{\partial x}=c \frac{\partial ^2u(x,t)}{\partial x^2}$$ with initial condition $$u(x,0)=\frac{2 \pi \beta c \sin (\pi x)}{\alpha +\beta \cos (\pi x)}$$ and boundary conditions $$u(0,t)=u(1,t)=0$$ I tried the backward finite difference (FD) for $\frac{\partial u(x,t)}{\partial t}$ and the central FD for the others. I wrote the following code, but I think there are some gaps in it. Because, the approximate solutions do not match the exact one $$u(x,t)=\frac{2 \pi \beta c e^{-c \pi ^2 t} \sin (\pi x)}{\alpha +\beta e^{-c \pi ^2 t} \cos (\pi x)}$$ Note that `Subscript[w, i, j]` stands for the approximation in the grid point $(x_i,t_j)$.               M = 8; NN = 8; m = M - 1;      n = NN - 1; alpha = 5.;      beta = 4.; c = 0.05;      T = 2.; h = (1. - 0.)/M;      k =T/NN;          (*Defining the Grid points*)     Table[Subscript[x, i] = 0 + i h, {i, 0, M}];      Table[Subscript[t, j] = 0 + j k, {j, 0, NN}];          (*Defining the Initial Conditions*)     For[i = 1, i <= m, i++,        Subscript[w, i, 0] = (2. c beta Pi Sin[Pi Subscript[x, i]])                          / (alpha + beta Cos[Pi Subscript[x, i]])     ];          (*Defining the Boundary Conditions*)     For[j = 1, j <= n, j++,        Subscript[w, 0, j] = 0     ];      For[j = 1, j <= n, j++,        Subscript[w, 1, j] = 0     ];          (*Defining the nonlinear equations due to discretization*)     For[i = 1, i <= m, i++,       {        For[j = 1, j <= n, j++,          f[i, j] = Subscript[w, i, j]             + (k/(2 h)) Subscript[w, i, j] (Subscript[w, i + 1, j] - Subscript[w, i - 1, j])             - (c k/(h^2)) (Subscript[w, i + 1, j] - 2 Subscript[w, i, j]                            + Subscript[w, i - 1, j])             - Subscript[w,i, j - 1]        ]       }     ];          F = Flatten[Table[f[i, j], {i, 1, m}, {j, 1, n}]];      Dimensions[F];     F // MatrixForm;     Vec = Flatten[Table[Subscript[w, i, j], {i, 2, M}, {j, 1, n}]];          (*Finding the solutions*)     Sol = Part[NSolve[F, Vec, Reals], 1]      Any suggestion is appreciated. In fact, what would be the final nonlinear system of equations resulting of discretization?


title: Placing a zero at coordinate center when plotting with Ticks -> None

text: I'd like to plot a certain function where only its qualitative progession shall be emphasized. Thus, using the `Ticks->None` option seems to be appropriate. However, I need to place a zero at the axes origin. My first choice was to put it in the epilog.   As a toy example, consider the code               Manipulate[       Plot[(a + x)*Sin[a*x], {x, 0, 4*Pi}, Ticks -> None,               Epilog -> Text[0, {-.1, .5}]       ],{a, 1, 5}     ]      As you can see, the zero gets closer to the x-axis as _a_ increases and in my real case, the zero is striked out by the x-axis for some parameter values. How can I place a zero to indicate the axis origin, such that it is independent of the function drawn? Ideally, the x-axis is only drawn for non negative _x_ and a zero would be placed right left to the point _(0,0)_.


title: running Mathematica installed in Windows, from Linux

text: Both the operating systems are installed side by side on my computer. The Windows hard drive mounts as an external hard drive on running Linux and I can access all the Windows files, as you'd know. So is it possible to run Mathematica from the terminal or any other way? It will be very useful if possible.


title: How to tell Mathematica that a function is dependent on other variables?

text: I am trying to derive some turbulence model dependencies and I am using Reynolds averaged Navier-Stokes equations. What I am trying to do is to tell Mathematica that OverBar[u] is dependent on x,y,z coordinates and time. However when doing further derivations I would like to avoid writing for example               D[ OverBar[u][x,y,z,t],t]      But rather write just               D[ OverBar[u], t]       But Mathematica should be aware that OverBar is dependent on other variables, because in other case it just writes that D[ OverBar[u],t] is zero. EDIT: OverBar[u] is not any particular function. It is just time averaged velocity vector which is in general dependent to spatial coordinates and time. There are no any expressions describing it. It is just bare $\bar u$ that I will find using numerical methods. But for now I want to adjust the turbulence model and derive the difference equation, and I do not want to have D[$\bar{u}$,t] output as zero, but rather $\frac{\partial\bar{u}}{\partial{t}}$. Is that possible in Mathematica?


title: Directing output of PrintTemporary to an additional OutputStream

text: I want to log messages that I send to the screen, even temporary ones. By setting `$Output` appropriately, it is possible to log `Print` messages, but not `PrintTemporary` messages:               oldout = $Output;         logfile = FileNameJoin[{$TemporaryDirectory, "example.log"}];         log = OpenWrite[logfile];         $Output = Append[oldout, log];     Print["Log message printed on screen."];     PrintTemporary["Log message printed temporarily on screen."]; Pause[1];     $Output = oldout;     Close[log];     Print["Contents of file:"];     FilePrint[logfile];      gives > Log message printed on screen. > > (Log message printed temporarily on screen.) > > Contents of file: > > "Log message printed on screen." Perhaps this is not surprising, but if you start Mathematica in non-gui mode (i.e., "MathKernel" on MacOsX), the `PrintTemporary` output stays permanently on the screen. How can one direct the output of `PrintTemporary` permanently to an additional output stream?


title: Problems with “Test Connectivity” and the Pacletserver

text: I know there has been a similar questions to this already but the solution did not work for me so here again: I have internet connection and I can execute such commands like:               Import["http://www.google.com"]      I am also able to use the functionality of Wolfram Alpha such as               == GDP of the USA      but when I do               CountryData["France", "Population"]      it tells me that there is no connection and that I should test the connectivity which I did via "Edit->Preferences->Internet Connectivity->Test Connectivity". When I tried testing it it returned:               "PacletSiteUpdate::err: An error occurred attempting to update paclet information from site http://pacletserver.wolfram.com. Failed writing received data to disk/application"      When I tried to ping the `pacletserver.wolfram.com` directly in the cmd it tried to ping `pacletserver2.wolfram.com` which failed. When I did the same with `pacletserver1.wolfram.com` and `pacletserver3.wolfram.com` it worked just fine. So I tried Nikita's Solution with the windows host file which did not work for me. After that I tried to change the server address within Mathematica with               $PacletSite = pacletserver1.wolfram.com      After that the Connectivity Test returned success. The CountryData-function did still not work, though. When I re-started Mathematica the `$PacletSite` contains the original value `(http://pacletserver.wolfram.com)` and the Connectivity Test fails again. Even though the CountryData-function did not work, I think that the problem is that Mathematica tries to connect to `pacletserver2.wolfram.com` and the `$PacletSite`-Value does not influence the CountryData-function. So is there a way to change the way Mathematica tries to connect to the pacletserver and tell it only to connect to `pacletserver1.wolfram.com` or `pacletserver3.wolfram.com`? Thank you very much for your help


title: Variable variable names

text: I have two variables, $ u \in \{0,40\}$ and $\gamma \in \{0,1\}$. I take $10$ values of $u$ and $5$ values of $\gamma$ and using their combinations as a pair of input parameters, I perform some mathematical operations a total of $10*5 =50$ times. Now, say for $u=40$ and $\gamma=0.5$, I performed my mathematical operations and generated a $120 \text{x}9$ matrix of data. I would like to be able to call this Matrix, $\mathrm{DataU40G5}$ so I can keep track of where the data came from. Now               "Data" <> "U" <> ToString[Evaluate[u]] <> "G" <> ToString[Evaluate[gamma]]      creates a string that looks like $\mathrm{DataU40G5}$ but I am unable to use it as a variable name and feed data into it. How would I go about this? Also, as I write this, I'm thinking that instead of doing all this, I can simply add the variables $u$ and $\gamma$ as columns to my records and have just one $(120*50)\text{x}(9+2)$ dimensional Matrix as my dataset. Is this a better Idea? Even if it is, please answer the first question just so I can learn how to do that.


title: Increasing the tickrate of an ErrorListLogPlot

text: I'm new to Mathematica and am trying to do an `ErrorListLogPlot` using the "ErrorBarLogPlots" package (from the Wolfram Library) for a graphical evaluation.                   Needs["ErrorBarLogPlots`"];          ErrorListLogPlot[          {           {           {{1/8.85, 43.59`}, ErrorBar[{0, 0}, {-0.42, 0.42}]},           {{1/11.30, 38.19`}, ErrorBar[{0, 0}, {-0.42, 0.42}]},           {{1/12.4, 33.48`}, ErrorBar[{0, 0}, {-0.42, 0.42}]},           {{1/13.5, 29.84`}, ErrorBar[{0, 0}, {-0.42, 0.42}]},           {{1/14.75, 25.74`}, ErrorBar[{0, 0}, {-0.42, 0.42}]},           {{1/15.6, 23.44`}, ErrorBar[{0, 0}, {-0.42, 0.42}]},           {{1/16.00, 22.61`}, ErrorBar[{0, 0}, {-0.42, 0.42}]},           {{1/16.6, 21.70`}, ErrorBar[{0, 0}, {-0.42, 0.42}]},           {{1/17.3, 20.44`}, ErrorBar[{0, 0}, {-0.42, 0.42}]},           {{1/19, 2.3, 17.74`}, ErrorBar[{0, 0}, {-0.42, 0.42}]},           {{1/19.85, 17.00`}, ErrorBar[{0, 0}, {-0.42, 0.42}]},           {{1/20.0, 16.92`}, ErrorBar[{0, 0}, {-0.42, 0.42}]},           {{1/18.5, 18.68`}, ErrorBar[{0, 0}, {-0.42, 0.42}]}}        },       GridLines -> Automatic, GridLinesStyle -> GrayLevel[.9],        AxesLabel -> {"\!\(\*FractionBox[\(1\), \(T\)]\)", "t"}       ]      ![Mathematica graphics](http://i.stack.imgur.com/KmGTX.png) Now I'd like to let Mathematica show more ticks on the y-axes, at the moment there are two. May there's anybody who can help? :) Edit: Thanks a lot! :) I got some nice results by combining it with the table function, and it makes my life so much easier.               Needs["ErrorBarLogPlots`"];     ErrorListLogPlot[     {       {             {{1/282.05, 43.59`}, ErrorBar[0, 0.42]},        {{1/284.50, 38.19`}, ErrorBar[0, 0.42]},        {{1/285.60, 33.48`}, ErrorBar[0, 0.42]},        {{1/286.70, 29.84`}, ErrorBar[0, 0.42]},        {{1/287.95, 25.74`}, ErrorBar[0, 0.42]},        {{1/288.80, 23.44`}, ErrorBar[0, 0.42]},        {{1/289.20, 22.61`}, ErrorBar[0, 0.42]},        {{1/289.80, 21.70`}, ErrorBar[0, 0.42]},        {{1/290.50, 20.44`}, ErrorBar[0, 0.42]},        {{1/292.40, 17.74`}, ErrorBar[0, 0.42]},        {{1/293.05, 17.00`}, ErrorBar[0, 0.42]},        {{1/293.20, 16.92`}, ErrorBar[0, 0.42]},        {{1/291.70, 18.68`}, ErrorBar[0, 0.42]}}      },      AxesLabel -> {"\!\(\*FractionBox[\(1\), \(T\)]\)", "t"},       Ticks -> {Table[n, {n, 0, 0.0036, 0.00001}], Table[n, {n, 0, 40}]},       GridLines -> {Table[n, {n, 0, 0.0036, 0.000001}], Table[n, {n, 0, 100, 0.5}]}      ]      ![enter image description here](http://i.stack.imgur.com/eUNmd.png)


title: Manipulating OptionsPatterns[]

text: How do you combine `OptionsPatterns`? For example, I would like to have a function that can take both options that I specify, and options for all graphs:               Options[f]={"a"->b} + OptionsPattern[LogPlot]     f[...,OptionsPattern[]] := LogPlot[..., ImageSize->OptionsValue[ImageSize]]      A related question, how do I remove options from an `OptionsPattern`, and pass on the remainder to another function. For example:               f[...,OptionsPattern[LogPlot]] := LogPlot[..., (* pass on all the options EXCEPT Frame *)]      Thanks for the help.


title: Pass list of options to Plot3D

text: Consider the example               plotOptions = {PlotPoints -> 10, MaxRecursion -> 2}          Plot3D[x y , {x, 0, 10}, {y, 0, 10}, plotOptions]      Why does this causes the error:               Plot3D::nonopt: Options expected (instead of plotOptions) beyond position 3 in      Plot3D[x y,{x,0,10},{y,0,10},plotOptions]. An option must be a rule or a list of rules. >>      ? I would say that plotOptions _is_ as list of rules... If I use               Plot3D[x y , {x, 0, 10}, {y, 0, 10}, {PlotPoints -> 10, MaxRecursion -> 2}]      it works... What is then the correct way of passing a list of options to a plot? One situation on when this happens is when I want to create several plots with the same options.


title: How to store standard plot settings?

text: If I plot many graphs with some standard set of options. Is there a way to store this set so that i can have better overview/structure over my plotting commands? example, I plot a function f[x] with a set of options:               Plot[f[x], {x, 0, 1}, PlotRange -> All, Axes -> False, Frame -> True,         PlotStyle ->Black, LabelStyle -> Directive[FontFamily -> "Symbol"],          FrameStyle -> AbsoluteThickness@1, BaseStyle -> {PrivateFontOptions ->         {"OperatorSubstitution" -> False}}, AspectRatio -> 0.5/GoldenRatio, ImageSize -> 226]      I would like to reduce the above to something like:               plotoptions1={PlotRange -> All, Axes -> False, Frame -> True,           PlotStyle -> Black, LabelStyle -> Directive[FontFamily -> "Symbol"],           FrameStyle -> AbsoluteThickness@1, BaseStyle -> {PrivateFontOptions ->          {"OperatorSubstitution" -> False}}, AspectRatio -> 0.5/GoldenRatio, ImageSize -> 226}      and then make a graph:               Plot[f[x], {x, 0, 1}, plotoptions1]      This structure does not work, I get the error:               Plot::nonopt: "Options expected (instead of plotoptions1) beyond position 3 in      Plot[f[x], {x, 0, 1}, plotoptions1]. An option must be a rule or a list of rules"      But I thought plotoptions1 was a list of rules, so what should I do?


title: Substituting solution from Solve into the equation and making a plot

text: I want to solve an equation and substitute it into a Plot expression. My code looks something like this               a[b_, x_] := bx + 1;     sol = Solve[(1 + b)x + 1 == 0, b]      I want to use the solution of b and substitute it to get the value of a and then plot it. I expect the result to be -x and I expected to see a plot of `y = -x`.               Plot[a[b /. sol, x], {x, 1, 1000}]      However, I don't get anything. Can anyone please help?


title: How can I change a Slider's appearance?

text: I am using _Mathematica_ 9.0 and Windows 7. I want to create a `Slider` that looks like the following: ![enter image description here](http://i.stack.imgur.com/5J3xN.png) I tried the following:               Slider[Dynamic[n], {1, 9, 1}, Appearance -> Large,         ImageSize -> {300, 40}, ContinuousAction -> False, Background -> Black]      and got this: ![enter image description here](http://i.stack.imgur.com/FTlq1.png) How can I get this to look like the first image?


title: Automating sequential import of data from web

text: I am trying to import data from multiple web pages hosted by a single online source. The data is posted by the source as one data set per web page for each week of the year. I would like to import the data for all 52 weeks in a year at the same time rather than modifying my code for each of the weeks and importing one at a time. Here is my code to import one week's data:               week012012 =        Import["http://www.boxofficemojo.com/weekend/chart/?yr=2012&wknd=01&\p=.htm", "Data"]      If it is of interest or relevance here is the further processing I do with the data after it has been imported:               week012012B = Cases[week012012, {_, _, _, _, _, _, _, _, _, _, _, _?NumericQ}, ∞];          Grid[week012012B, Frame -> All]      The site uses a consistent naming scheme for each week of the year and indeed from year-to-year as well. If I were looking to get just a few weeks data I could manually change the URL for the weekend from 01 to 02, 03, 04..., but I want all 52 weeks for 2012. The approach I have been playing with is to use string manipulation to modify the URL and then import and save the data for each of the weeks. Any suggestions?


title: How to compile a diagonal array efficiently?

text: For example, if we use some functions defined prior to `Compile`, we usually have the main evaluators in the compiled codes, pointing to the definition of the function.               f[t_] := If[t <= 1., Cos[t]*Sin[t], 0.]          CompilePrint@      Compile[{{t, _Real}}, IdentityMatrix[2] -  f[t],        CompilationOptions -> {"InlineCompiledFunctions" -> True,          "InlineExternalDefinitions" -> True}]      > >           1 argument >           1 Integer register >           3 Real registers >           2 Tensor registers >           Underflow checking off >           Overflow checking off >           Integer overflow checking on >           RuntimeAttributes -> {} >   >           R0 = A1 >           I0 = 2 >           Result = T(R2)1 >   >     1 T(I2)0 = MainEvaluate[ Hold[IdentityMatrix][ I0]] >     2 R1 = MainEvaluate[ Hold[f][ R0]] >     3 R2 = - R1 >     4 T(R2)1 = R2 + T(I2)0 >     5 Return >   We can avoid main evaluator by using `Evaluate` in the function, which specifically substidue the definition of the function. However, sometimes this introduces repeated code in the compiled results. For instance, in the following example, `Evaluate` simplify expands a number into a matrix and repeatedly calculated this expression for two times. We can see that the 26-50 lines of the compiled code are essentially the same as 1-25 lines.               CompilePrint@      Compile[{{t, _Real}}, Evaluate[IdentityMatrix[2] - f[t + 1./2.]],        CompilationOptions -> {"InlineCompiledFunctions" -> True,          "InlineExternalDefinitions" -> True}]      > >           1 argument >           1 Boolean register >           1 Integer register >           12 Real registers >           3 Tensor registers >           Underflow checking off >           Overflow checking off >           Integer overflow checking on >           RuntimeAttributes -> {} >   >           R0 = A1 >           I0 = 1 >           R3 = 1. >           R4 = 7. >           R1 = 0.5 >           R7 = 0. >           Result = T(R2)2 >   >     1 R2 = R1 + R0 >     2 B0 = R2 <= R3 (tol R4) >     3 if[ !B0] goto 10 >     4 R2 = R1 + R0 >     5 R5 = Cos[ R2] >     6 R6 = Sin[ R2] >     7 R5 = R5 * R6 >     8 R6 = R5 >     9 goto 11 >     10    R6 = R7 >     11    R5 = - R6 >     12    R6 = I0 >     13    R6 = R6 + R5 >     14    R5 = R1 + R0 >     15    B0 = R5 <= R3 (tol R4) >     16    if[ !B0] goto 23 >     17    R5 = R1 + R0 >     18    R8 = Cos[ R5] >     19    R9 = Sin[ R5] >     20    R8 = R8 * R9 >     21    R9 = R8 >     22    goto 24 >     23    R9 = R7 >     24    R8 = - R9 >     25    T(R1)0 ={ R6, R8 } >     26    R6 = R1 + R0 >     27    B0 = R6 <= R3 (tol R4) >     28    if[ !B0] goto 35 >     29    R6 = R1 + R0 >     30    R8 = Cos[ R6] >     31    R9 = Sin[ R6] >     32    R8 = R8 * R9 >     33    R9 = R8 >     34    goto 36 >     35    R9 = R7 >     36    R8 = - R9 >     37    R9 = R1 + R0 >     38    B0 = R9 <= R3 (tol R4) >     39    if[ !B0] goto 46 >     40    R9 = R1 + R0 >     41    R10 = Cos[ R9] >     42    R11 = Sin[ R9] >     43    R10 = R10 * R11 >     44    R11 = R10 >     45    goto 47 >     46    R11 = R7 >     47    R10 = - R11 >     48    R11 = I0 >     49    R11 = R11 + R10 >     50    T(R1)1 ={ R8, R11 } >     51    T(R2)2 ={ T(R1)0, T(R1)1 } >     52    Return >   **So is there a way to fix this repeating?** Note that change only the argument of the external function, the behavior changes, **why**?               CompilePrint@      Compile[{{t, _Real}}, Evaluate[IdentityMatrix[2] - f[t]],        CompilationOptions -> {"InlineCompiledFunctions" -> True,          "InlineExternalDefinitions" -> True}]      > >           1 argument >           1 Boolean register >           1 Integer register >           6 Real registers >           3 Tensor registers >           Underflow checking off >           Overflow checking off >           Integer overflow checking on >           RuntimeAttributes -> {} >   >           R0 = A1 >           I0 = 1 >           R1 = 1. >           R2 = 7. >           R5 = 0. >           Result = T(R2)2 >   >     1 B0 = R0 <= R1 (tol R2) >     2 if[ !B0] goto 8 >     3 R3 = Cos[ R0] >     4 R4 = Sin[ R0] >     5 R3 = R3 * R4 >     6 R4 = R3 >     7 goto 9 >     8 R4 = R5 >     9 R3 = - R4 >     10    R4 = I0 >     11    R4 = R4 + R3 >     12    T(R1)0 ={ R4, R3 } >     13    T(R1)1 ={ R3, R4 } >     14    T(R2)2 ={ T(R1)0, T(R1)1 } >     15    Return >


title: How can I get the right hand side of a delayed expression?

text: Imagine there is a given function f, defined with `SetDelayed`, say               f[x_] := Sin[x]^2 + Cos[x]^2.      Is it possible to get rhs of this function before evaluation? For instance of f[5] I want to get expression               Sin[5]^2 + Cos[5]^2.


title: Probability: proportion of 1000 random lists for x that contain the same nrs

text: Give a function which calculates for each x a random list of birthdays (which can be x=1 to x=365)               birthdays[x_] := RandomInteger[{1, 365}, x]      is my answer. Take x=25 and determine whether `birthdays[x]` contain equal numbers.               bday1 = birthdays[25]          Length[bday1]          ubday1 = Union[bday1]      `Length[ubday1]` is my answer These 2 questions were no problem but i cant find a formula for: I want to estimate for groups of x persons, the probability that at least two of them have the same birthday, and i want to repeat this process 1000 times. so im looking for the proportion of 1000 random birthday lists for x that contain the same numbers. (so i need the probability) This is my answer so far; and I don't know whether its correct or not.               birthprob[x_] := Count[Table[RandomInteger[{1, 365}, x], {1000}],       Could someone help me? Thanks in advance!


title: Plot Option Precedence while combining Plots with `Show[]`

text: I like to build sophisticated plots by combining simpler ones with `Show[]`. Typically this involves setting non-default Plot-Options with the different Plot-Commands, like               Show[ ListPlot[ ,Op1], Plot[ ,Op2], Op3]      Unfortunately the `Show[]` command is not commutative, as               Show[ Plot[ ,Op2], ListPlot[ ,Op1], Op3]      can produce different results. My expectation was that putting settings in `Op3` should overwrite the ones in `Op1` and `Op2` however this does not work with options like `PlotMarkers` which are only available within `ListPlot[]`. The description of the `Show[g_1, g_2, g_3, ... ,g_i]`-command gives only two hints: > Options explicitly specified in Show override those included in the graphics > expression. and > The lists of non-default options in the `g_i` are concatenated. I’m not sure what this precisely means. Is               Show[ ListPlot[ ,Op1], Plot[ ,Op2], Op3]      equivalent to `Show[ ListPlot[ ,Union[Op1,Op2]], Plot[ ,Union[Op1,Op2]], Op3]`? while `Op3` overwrites whatever is in `Union[Op1,Op2]`? And there is one more question: In               Show[ g_1, g_2, g_3, ..., g_i ]      the Plot in `g_1` seems to be treated specially as it defines the `PlotRange` for the final image generated. **I would like to know the full set of rules how the Plot-Options are combined and to which Plot or Plots they are applied.**


title: How to read off coefficients of tensor-like expression in a speedy way?

text: I am considering identities involving `t[a, b, c, d, ...]`, where number of indices is fixed. `t` has the cyclic property so that `t[3, 4, 1, 2]` is equal to `t[1, 2, 3, 4]`. When $k=4$, all possible elements are generated by               basis = (# /. {List -> t}) & /@ Permutations[Range[4]];     basis = basis /. {t[a___, 1, b___] -> t[1, b, a]} // Union      Here comes the output:               {t[1, 2, 3, 4], t[1, 2, 4, 3], t[1, 3, 2, 4], t[1, 3, 4, 2], t[1, 4, 2, 3], t[1, 4, 3, 2]}      I want to convert expressions like `t[1, 2, 3, 4] + t[1, 3, 2, 4] - t[1, 4, 3, 2]` into a coefficient matrix to do some linear algebra. I tried the following code:               identity = {t[1, 2, 3, 4] + t[1, 3, 2, 4] - t[1, 4, 3, 2],        t[1, 2, 4, 3] + t[1, 3, 2, 4],        t[1, 3, 4, 2] - t[1, 2, 3, 4] - t[1, 4, 2, 3]};          coeffmatrix = Coefficient[identity, #] & /@ basis // Transpose      The output is               {{1, 0, 1, 0, 0, -1}, {0, 1, 1, 0, 0, 0}, {-1, 0, 0, 1, -1, 0}}.      Efficiency does not matter for this small example. However, when I increase number of indices and identities, getting `coeffmatrix` becomes very slow and spends a huge amount of memory. For the real case, `t` has 10 indices and the size of `coeffmatrix` is approximately $362880 \times 362880$. Here comes my question: Coefficients are always restricted to `{-1, 0, 1}` for some reasons. Would this fact probably help me to boost up the performance? Could anyone give me a suggestion for better efficiency?


title: how to extract a matrix and a vector from a vector

text: I have a vector like this:               V = {a*exp1+b*exp2+c*exp3, a*exp4+b*exp5+c*exp6, a*exp7+b*exp8+c*exp9}      and I want to get : > >     mat = {{exp1, exp2, exp3}, {exp4, exp5, exp6}, {exp7, exp8, exp9}} >   from vector               var = {a, b, c}      so : `mat.var === V`


title: Tally repeated evaluation of function

text: How can I tally the result of repeated evaluation of a function?               n=100000;     f[]:=RandomInteger[{1, 4}]     Tally@Table[f[], {n}]      When `n` is really big this needs an unnecessary amount of memory, how do I get rid of the `Table` without slowing it down significantly?               fTally[f_, n_] := Module[{ c },       c[_] = 0;       Do[c[#] += 1 & @ f[], {n}];       Most[DownValues[c] /. HoldPattern[_@c[y_] :> m_] :> {y, m}]       ]     AbsoluteTiming[fTally[f, n];]              (* 0.6s   *)     AbsoluteTiming[Tally@Table[f[], {n}];]     (* 0.009s *)


title: Exporting string to MAT file

text: I'm trying to export a string to a Matlab mat file. Is it possible? The straightforward way               Export["file.mat", {{"1"}}, {{"Data"}}]      with any number of surrounding braces does not work for me, as I get the error message               Export::type: ({"1"}) cannot be exported to the ("MAT")format.      Any clues? **Edit** To make this a little clearer: I'd like to save some matrices **and** a string to the same MAT file.


title: Mathematica on a cluster

text: I try to run mathematica on a grid. Since this is my first time working on a cluster, I have no plan what to do. I have to run a job (pbs-file).               #!/bin/sh     #     #PBS -q express          module load math/mathematica/9.0.1          echo "Started"     mathematica 'pi.m'     echo "Ended"          exit 0      I got always the error : "Can not open display". Anyone know what to do? The file pi.m looks like:               N[ Pi, 1000 ] >>"pi_result.txt"     Quit[ ]


title: BoxWhiskerChart with logarithmic axes

text: I would like to make a following chart ![BoxWhiskerChart with log y-axis](http://i.stack.imgur.com/AWr5t.png) Ideally I would also like to control the boxes position on a logarithmic x-axis. Some inspiration how to do the latter may be found in the answer to my other question: How to controll position on the x-axis of a boxWhiskerChart TIA:)


title: CDF player Inputfield list

text: I want to work with lists within the CDF player. A very simple example, which works inside a notebook is               DynamicModule[{x = {1, 2, 7}},       Panel[Column@{InputField[Dynamic@x, Expression], Dynamic@func@x}],       Initialization :> (func[x_] := 2*ToExpression[x])]      Exported as a stand alone CDF application this does not work. Changing input `x` results in nothing! If `x` is a Number then it works also in the CDF player.


title: Solving trig identities in specific terms

text: How would you solve a problem like "write csc(x) in terms of sec(x)" in Mathematica? The best I can get is "True." http://math.stackexchange.com/questions/167935/write-cscx-in-terms-of-secx I'm asking in order to better understanding of Mathematica, and as a way to verify I'm solving my trig identities correctly. It's been a while since I've done identities, and I'm trying to brush off the cobwebs before its too late. I was told that I'll need this skill later on in Calculus.


title: How to generate a recurrent sequence

text: How to generate this type of sequence? $$ f(n, x) = x f'(n-1, x) \hspace{2 mm}, f(0, x) = e^x$$ How do I evaluate it for numerical values for $x = 1$ or any number?


title: Declare local variable when defining a function to mimic Table[]

text: **The problem:**   I want to define a function `tab` to replace the long line               Table[f[i,j,k,l],{i,3},{j,3},{k,3},{l,3}]      by a shorter line               tab[f[i,j,k,l],i,j,k,l]      Then I need to declare `i,j,k,l` in `tab` to be local variables, just like in `Table`. **My trial:**               tab[f_, jlist__] := Module[{jlist2 = {jlist}, jlist3},       jlist3 = Sequence @@ ({#1, 3} & ) /@ jlist2;        Table[f, Evaluate[jlist3]]]      Then I succeeded in               (*Input := *) tab[h[i, j], i, j]     (*Output:=  {{h[1, 1], h[1, 2], h[1, 3]}, {h[2, 1], h[2, 2], h[2, 3]},  {h[3, 1], h[3, 2], h[3, 3]}}*)          whose output is the same as from `Table[h[i,j],{i,3},{j,3}]`. But I failed in               (*Input := *) tab[(f[i, j] = g[i, j]), i, j]     (* {{g[1, 1], g[1, 2], g[1, 3]}, {g[2, 1], g[2, 2], g[2, 3]}, {g[3, 1], g[3, 2], g[3, 3]}} *)      in which `f[i,j]=g[i,j]` is evaluated first. I wanted it to behave as `Table[f[i,j]=g[i,j],{i,3},{j,3}]`. * * * **Update:** Below rcollyer's answer leads to the correct output by using `SetAttributes[tab,HoldAll]` first. However, I still want to know if I can declare `i` and `j` as local variables. So far they are not local variables and I would have errors like:               (*Input :=*) i=3; tab[f[i],i]     (* Error message "Table::itraw: Raw object 3 cannot be used as an iterator. >>"       Output:= Table[f[i], {3, {0, 1, 2, 3}}] *)      Can anyone solve this?


title: What is the inside?

text: What is the inside of the Mathematica command, solve, for a system of equations like the following? $$\eqalign{ (x +2\phantom{3} z)^2 + (y +\phantom{3} w)^2 &= 52\cr (x + 30z)^2 + (y + 3w)^2 &= 296\cr }$$


title: Defining my own invisible operator

text: There are some invisible operators in Mathematica (`\\[ImplicitPlus]`,`\\[InvisibleTimes]`,`\\[InvisibleComma]`,`\\[InvisibleApplication]`). How can I make my own that would not interfere with built-in functions (`Plus`,`Times`,`Sequence`,`Apply`)? Is there some invisible character like those different kinds of spaces (`\\[RawSpace]`,`\\[ThinSpace]`,`\\[VeryThinSpace]`, etc.) that won't be interpreted as multiplication, so that I can define my own patterns and behaviour with it? **EDIT** : OK, I think this is it:               TemplateBox[{}, "op",       InterpretationFunction :> (RowBox@{"~op~"} &),        DisplayFunction :> (RowBox@{"\[InvisibleSpace]"} &)];     SetOptions[EvaluationNotebook[], InputAliases -> {"op" -> %}]     SetAttributes[op, Flat];      Now if I type `1[ESC]op[ESC]2[ESC]op[ESC]3` it will be interpreted as `1~op~2~op~3` which means `op[1,2,3]` if `op` has `Flat` attribute, but will be displayed as `123`. I wonder why nobody came up with it, what all the gurus doing? Whatever, now I can finally create pretty EDSLs in Mathematica :D


title: Can we ask ComponentMeasurements to use NonLinearModelFit to return a covariance matrix for underlying intensity data?

text: I'd like to be able to calculate a covariance matrix for some data underlying a morphological component. Provided this data, I can write something like:               nlm = NonlinearModelFit[data, a*3^(b*r), {a, b}, r]     nlm["CovarianceMatrix"]      To retrieve a covariance matrix given some model and a dataset. Is there some way for me to ask ComponentMeasurements to do this for me for each morphological component in some set m? What about the fitting parameters for the model? Of course, one can go ahead and grab the intensity values for the pixels by passing "IntensityData" to ComponentMeasurements, but I'd really like to know how pass a function to ComponentMeasurements to have it do the model fitting and return the covariance matrix or fitted parameters automatically in it's typical output format. Surely there's a neat way of doing this?


title: Creating a Mathieu stability diagram

text: I am attempting to re-create a Mathieu stability diagram like the one shown here: ![enter image description here](http://i.stack.imgur.com/A2oCf.png) I expected that I could use `MathieuC` to generate this graph by assuming that instability occurs when the function returns a complex number, so I try               Quiet@DiscretePlot[Re@a /. FindRoot[MathieuC[a, q, 1], {a, 0.2}], {q, 0, 1, 0.1}]      which is wrong for two reasons - it produces a plot not even close to the desired output and the output is dependent on what value I use for z (in the example above, 1). For those interested, the impetus behind this problem is to explore how Mathematica can be used to simulate the behavior of a quadrupole mass spectrometer.


title: Asking Mathematica to produce a function of some variables

text: Given $$l_0=\sqrt{\frac{\lambda_1(\lambda_0+\mu_0)}{\lambda_0(\lambda_1+\mu_1-1)}}$$ and $$l_1=\sqrt{\frac{\lambda_0(\lambda_1+\mu_1)}{\lambda_1(\lambda_0+\mu_0-1)}}$$               l0 = Sqrt[(λ1*(λ0 + μ0))/(λ0*(λ1 + μ1 - 1))]         l1 = Sqrt[(λ0*(λ1 + μ1))/(λ1*(λ0 + μ0 - 1))]      Is there any way to ask mathematica to determine if some functions $f_0$ and $f_1$ exist such that $$f_0(l_0,l_1)=\frac{1}{\sqrt{\frac{\lambda_0+\mu_0}{\lambda_0}}}$$ and $$f_1(l_0,l_1)=\frac{1}{\sqrt{\frac{\lambda_0+\mu_0-1}{\lambda_0}}}$$               f0[l0, l1] = 1/Sqrt[(λ0 + μ0)/λ0]     f1[l0, l1] = 1/Sqrt[(λ0 + μ0 - 1)/λ0]


title: Determinant of a large matrix and solution of a linear equation

text: I am trying to solve a linear equation in x, where the equation is given by Det[M]==0. The M is a symmetric matrix (dimensions 47x47) with an element equal to x and all other elements are equal to numbers ranging from 1 to 10^4. So, Det[M] is a linear equation in x. I could get a solution for a 11x11 matrix using 'Solve', but when the dimensions goes to 47 the program does not return anything for the time I let it run (about a day). I suspect it is the large size that causes the problem, any suggestion to solve it quickly (~ mins) using Mathematica? Thanks. Jayajit


How can I reorder the factors in the terms of a polynomial? Consider               poly1 = \!\(\*SubsuperscriptBox[\(x\), \(1\), \(3\)] + \*SubsuperscriptBox[\(x\), \(2\), \(3\)] + \*SubsuperscriptBox[\(x\), \(3\), \(3\)]\  - \ \(TraditionalForm\`\*SuperscriptBox[SubscriptBox[\(σ\), \(1\)], \(3\)]\)\) /.    Subscript[σ,     1] -> (Subscript[x, 1] + Subscript[x, 2] + Subscript[x, 3]) //   Expand      $$\begin{align*}-3 x_2 x_1^2-3 x_3 x_1^2-3 x_2^2 x_1-3 x_3^2 x_1-6 x_2 x_3 x_1-3 x_2 x_3^2-3 x_2^2 x_3\tag{1}\end{align*}$$               MonomialList[poly1, {Subscript[x, 1], Subscript[x, 2], Subscript[x,   3]}, "Lexicographic"]      $$\begin{align*}\left\{-3 x_1^2 x_2,-3 x_1^2 x_3,-3 x_1 x_2^2,-6 x_1 x_2 x_3,-3 x_1 x_3^2,-3 x_2^2 x_3,-3 x_2 x_3^2\right\}\tag{2}\end{align*}$$               % /. List -> Plus      $$\begin{align*}-3 x_2 x_1^2-3 x_3 x_1^2-3 x_2^2 x_1-3 x_3^2 x_1-6 x_2 x_3 x_1-3 x_2 x_3^2-3 x_2^2 x_3\tag{3}\end{align*}$$ Question1: How can I get $$\begin{align*}-3 x_1^2 x_2-3 x_1^2 x_3-3 x_1 x_2^2-6 x_1 x_2 x_3-3 x_1 x_3^2-3 x_2^2 x_3-3 x_2 x_3^2\tag{4}\end{align*}$$ Question2: Even better if possible, how can I get $$\begin{align*}-3\left( x_1^2 x_2+x_2^2x_1+\text{...}\right)-6 x_1 x_2 x_3\tag{5}\end{align*}$$ My goal is to keep the order of the terms in (2) unchanged when I copy (4)/(5) into an inline formula cell.


title: MapThread multiple functions onto multiple lists

text: I'm trying to learn the functional style which seems to prevail in Mathematica. I'm having trouble accomplishing the following: Let's say I have multiple lists of arbitrary data (using two lists here to keep it simple):               a = {1,2,3,4,5,6}     b = {1,1,2,2,3,3}      I also have multiple arbitrary functions (again using two to keep it simple) which all take the same inputs in the same order, but use them to generate different outputs:               f = Function[{u,v},{{u^2,u*v},{-u*v,v^2}}]     g = Function[{u,v},{{u^2,1},{-1,v^2}}]      I understand how to build lists of results, threading over lists a,b, with MapThread:               fOut = MapThread[f,{a,b}]     gOut = MapThread[g,{a,b}]      However, because in reality there are dozens of functions (f,g,etc.) and dozens of lists of data (a,b,etc.), I end up with dozens of MapThread commands, each with the same long list of arguments, creating a wall of text that is far from elegant-looking. So I tried to merge it into a single MapThread command, which didn't work:               {fOut,gOut} = MapThread[{f,g},{a,b}]      Is there a way to MapThread many functions onto many lists of data (assuming each function expects the data in the same order)? If possible, I would like to avoid creating new variables because the functions are intended to be compiled, and I think it would create redundant data.


title: Convert list to sequence

text: I was just thinking how `Tuples` was created so , I came up with this,               Flatten[Outer[List, {a, b}, {a, b}, {a, b}], 2] == Tuples[{a, b}, 3]      > True Now, I want to convert it to a function,               fun[x_List] := Block[{}, Flatten[Outer[List, x], Length[x] - 1]]      But the problem is the I need to put this `List` as a sequence but I am not finding a work around.