How to discretize a nonlinear PDE fast?

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?


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

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


running Mathematica installed in Windows, from Linux

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.


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

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?


Directing output of PrintTemporary to an additional OutputStream

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?


Problems with “Test Connectivity” and the Pacletserver

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


Variable variable names

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.


Increasing the tickrate of an ErrorListLogPlot

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)


Manipulating OptionsPatterns[]

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.


Pass list of options to Plot3D

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.


How to store standard plot settings?

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?


Substituting solution from Solve into the equation and making a plot

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?


How can I change a Slider's appearance?

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?


Automating sequential import of data from web

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?


How to compile a diagonal array efficiently?

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 >


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

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.


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

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!


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

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


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

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?


how to extract a matrix and a vector from a vector

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`


Tally repeated evaluation of function

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


Exporting string to MAT file

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.


Mathematica on a cluster

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[ ]


BoxWhiskerChart with logarithmic axes

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


CDF player Inputfield list

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.


Solving trig identities in specific terms

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.


How to generate a recurrent sequence

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?


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

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


What is the inside?

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


Defining my own invisible operator

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


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

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?


Creating a Mathieu stability diagram

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.


Asking Mathematica to produce a function of some variables

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]


Determinant of a large matrix and solution of a linear equation

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.


MapThread multiple functions onto multiple lists

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.


Convert list to sequence

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.


How to obtain a useful answer from integration when Simplify is insufficient?

I have been trying to integrate a function AND get an output that is sufficiently simple as to be usable. Simply using the `Simplify` and `FullSimplify` commands has not done nearly enough, and it takes me over 2 hours to get a result from this integration. Are there any further tricks I can use to force further simplifications? Any assumptions I can put in to make it simpler or faster? Maybe get more than one core involved (I have other similar integrals I need to do too so even if I can just set them all running at once on different cores that would be an improvement)? Be warned, the example output is stupidly long, so much so that it is impossible to read, much less manually simplify. Input (ai, bi, ci, and di are unit vectors, and so will be replaced with the appropriate cosine later. ki has a value but is still kept track of so the proper cosine can be used later. The cosines are independent of the integration, so it makes it marginally easier to read this way):               r = {r1, r2, r3};     a = {a1, a2, a3}/σa;     b = {b1, b2, b3}/σb;     c = {c1, c2, c3}/σc;     d = {d1, d2, d3}/σd;     k = {k1, k2, k3};     S = {{S11, S12, S13}, {S21, S22, S23}, {S31, S32, S33}};     FullSimplify[Integrate[(1/(2*Pi*σa*σb))*Exp[-(1/2)*((a.r)^2 + (b.r)^2)]*(1/(2*Pi*σc*σd))*Exp[-(1/2)*((c.r)^2 + (d.r)^2)],      {r1, -Infinity, Infinity}, {r2, -Infinity, Infinity}, {r3, -Infinity, Infinity},      Assumptions -> Element[{r1, r2, r3, a1, a2, a3, b1, b2, b3, c1, c2, c3, d1, d2, d3, k1, k2, k3, S11, S12, S13, S21, S22, S23, S31, S32, S33, σa, σb, σc, σd, τ}, Reals] && σa > 0 && σb > 0 && σc > 0 && σd > 0 && τ > 0 && 1 >= a1 >= -1 && 1 >= a2 >= -1 && 1 >= a3 >= -1 && 1 >= b1 >= -1 && 1 >= b2 >= -1 && 1 >= b3 >= -1 && 1 >= c1 >= -1 && 1 >= c2 >= -1 && 1 >= c3 >= -1 && 1 >= d1 >= -1 && 1 >= d2 >= -1 && 1 >= d3 >= -1]]]]      Output:                      ConditionalExpression[      1/(Sqrt[2 π] √(c3^2 (d2^2 σa^2 σb^2 + (b2^2 \     σa^2 + a2^2 σb^2) σd^2) -             2 c2 c3 (d2 d3 σa^2 σb^2 + (b2 b3 σa^2 +                   a2 a3 σb^2) σd^2) +             c2^2 (d3^2 σa^2 σb^2 + (b3^2 σa^2 +                   a3^2 σb^2) σd^2) + σc^2 ((a3 d2 -                   a2 d3)^2 σb^2 +                b3^2 (d2^2 σa^2 + a2^2 σd^2) -                2 b2 b3 (d2 d3 σa^2 + a2 a3 σd^2) +                b2^2 (d3^2 σa^2 +                   a3^2 σd^2))) √((b1^2 c3^2 d2^2 σa^2 \     - 2 b1^2 c2 c3 d2 d3 σa^2 + b1^2 c2^2 d3^2 σa^2 +               a3^2 c2^2 d1^2 σb^2 - 2 a2 a3 c2 c3 d1^2 σb^2 +               a2^2 c3^2 d1^2 σb^2 -               2 a3^2 c1 c2 d1 d2 σb^2 +               2 a2 a3 c1 c3 d1 d2 σb^2 +               2 a1 a3 c2 c3 d1 d2 σb^2 -               2 a1 a2 c3^2 d1 d2 σb^2 +               a3^2 c1^2 d2^2 σb^2 - 2 a1 a3 c1 c3 d2^2 σb^2 +               a1^2 c3^2 d2^2 σb^2 +               2 a2 a3 c1 c2 d1 d3 σb^2 -               2 a1 a3 c2^2 d1 d3 σb^2 -               2 a2^2 c1 c3 d1 d3 σb^2 +               2 a1 a2 c2 c3 d1 d3 σb^2 -               2 a2 a3 c1^2 d2 d3 σb^2 +               2 a1 a3 c1 c2 d2 d3 σb^2 +               2 a1 a2 c1 c3 d2 d3 σb^2 -               2 a1^2 c2 c3 d2 d3 σb^2 +               a2^2 c1^2 d3^2 σb^2 - 2 a1 a2 c1 c2 d3^2 σb^2 +               a1^2 c2^2 d3^2 σb^2 + a3^2 b1^2 d2^2 σc^2 -               2 a2 a3 b1^2 d2 d3 σc^2 + a2^2 b1^2 d3^2 σc^2 +               a3^2 b1^2 c2^2 σd^2 -               2 a2 a3 b1^2 c2 c3 σd^2 + a2^2 b1^2 c3^2 σd^2 +               b3^2 ((a2 d1 - a1 d2)^2 σc^2 +                  c2^2 (d1^2 σa^2 + a1^2 σd^2) -                  2 c1 c2 (d1 d2 σa^2 + a1 a2 σd^2) +                  c1^2 (d2^2 σa^2 + a2^2 σd^2)) +               b2^2 ((a3 d1 - a1 d3)^2 σc^2 +                  c3^2 (d1^2 σa^2 + a1^2 σd^2) -                  2 c1 c3 (d1 d3 σa^2 + a1 a3 σd^2) +                  c1^2 (d3^2 σa^2 + a3^2 σd^2)) -               2 b1 b2 ((a3 d1 - a1 d3) (a3 d2 - a2 d3) σc^2 +                  c3^2 (d1 d2 σa^2 + a1 a2 σd^2) +                  c1 c2 (d3^2 σa^2 + a3^2 σd^2) -                  c3 (c2 d1 d3 σa^2 + c1 d2 d3 σa^2 +                     a2 a3 c1 σd^2 + a1 a3 c2 σd^2)) -               2 b3 (b2 ((a2 d1 - a1 d2) (a3 d1 - a1 d3) σc^2 -                     c1 c3 (d1 d2 σa^2 + a1 a2 σd^2) +                     c1^2 (d2 d3 σa^2 + a2 a3 σd^2) +                     c2 (c3 d1^2 σa^2 - c1 d1 d3 σa^2 -                        a1 a3 c1 σd^2 + a1^2 c3 σd^2)) +                  b1 ((a2 d1 - a1 d2) (-a3 d2 + a2 d3) σc^2 +                     c1 c3 (d2^2 σa^2 + a2^2 σd^2) +                     c2^2 (d1 d3 σa^2 + a1 a3 σd^2) -                     c2 (c3 d1 d2 σa^2 + c1 d2 d3 σa^2 +                        a2 a3 c1 σd^2 +                        a1 a2 c3 σd^2))))/(c3^2 (d2^2 σa^2 \     σb^2 + (b2^2 σa^2 + a2^2 σb^2) σd^2) -               2 c2 c3 (d2 d3 σa^2 σb^2 + (b2 b3 σa^2 +                     a2 a3 σb^2) σd^2) +               c2^2 (d3^2 σa^2 σb^2 + (b3^2 σa^2 +                     a3^2 σb^2) σd^2) + σc^2 ((a3 d2 -                     a2 d3)^2 σb^2 +                  b3^2 (d2^2 σa^2 + a2^2 σd^2) -                  2 b2 b3 (d2 d3 σa^2 + a2 a3 σd^2) +                  b2^2 (d3^2 σa^2 +                     a3^2 σd^2))))), ((b1^2 c3^2 d2^2 σa^2 -              2 b1^2 c2 c3 d2 d3 σa^2 + b1^2 c2^2 d3^2 σa^2 +              a3^2 c2^2 d1^2 σb^2 - 2 a2 a3 c2 c3 d1^2 σb^2 +              a2^2 c3^2 d1^2 σb^2 - 2 a3^2 c1 c2 d1 d2 σb^2 +              2 a2 a3 c1 c3 d1 d2 σb^2 +              2 a1 a3 c2 c3 d1 d2 σb^2 -              2 a1 a2 c3^2 d1 d2 σb^2 + a3^2 c1^2 d2^2 σb^2 -              2 a1 a3 c1 c3 d2^2 σb^2 + a1^2 c3^2 d2^2 σb^2 +              2 a2 a3 c1 c2 d1 d3 σb^2 -              2 a1 a3 c2^2 d1 d3 σb^2 -              2 a2^2 c1 c3 d1 d3 σb^2 +              2 a1 a2 c2 c3 d1 d3 σb^2 -              2 a2 a3 c1^2 d2 d3 σb^2 +              2 a1 a3 c1 c2 d2 d3 σb^2 +              2 a1 a2 c1 c3 d2 d3 σb^2 -              2 a1^2 c2 c3 d2 d3 σb^2 + a2^2 c1^2 d3^2 σb^2 -              2 a1 a2 c1 c2 d3^2 σb^2 + a1^2 c2^2 d3^2 σb^2 +              a3^2 b1^2 d2^2 σc^2 - 2 a2 a3 b1^2 d2 d3 σc^2 +              a2^2 b1^2 d3^2 σc^2 + a3^2 b1^2 c2^2 σd^2 -              2 a2 a3 b1^2 c2 c3 σd^2 + a2^2 b1^2 c3^2 σd^2 +              b3^2 ((a2 d1 - a1 d2)^2 σc^2 +                 c2^2 (d1^2 σa^2 + a1^2 σd^2) -                 2 c1 c2 (d1 d2 σa^2 + a1 a2 σd^2) +                 c1^2 (d2^2 σa^2 + a2^2 σd^2)) +              b2^2 ((a3 d1 - a1 d3)^2 σc^2 +                 c3^2 (d1^2 σa^2 + a1^2 σd^2) -                 2 c1 c3 (d1 d3 σa^2 + a1 a3 σd^2) +                 c1^2 (d3^2 σa^2 + a3^2 σd^2)) -              2 b1 b2 ((a3 d1 - a1 d3) (a3 d2 - a2 d3) σc^2 +                 c3^2 (d1 d2 σa^2 + a1 a2 σd^2) +                 c1 c2 (d3^2 σa^2 + a3^2 σd^2) -                 c3 (c2 d1 d3 σa^2 + c1 d2 d3 σa^2 +                    a2 a3 c1 σd^2 + a1 a3 c2 σd^2)) -              2 b3 (b2 ((a2 d1 - a1 d2) (a3 d1 - a1 d3) σc^2 -                    c1 c3 (d1 d2 σa^2 + a1 a2 σd^2) +                    c1^2 (d2 d3 σa^2 + a2 a3 σd^2) +                    c2 (c3 d1^2 σa^2 - c1 d1 d3 σa^2 -                       a1 a3 c1 σd^2 + a1^2 c3 σd^2)) +                 b1 ((a2 d1 - a1 d2) (-a3 d2 + a2 d3) σc^2 +                    c1 c3 (d2^2 σa^2 + a2^2 σd^2) +                    c2^2 (d1 d3 σa^2 + a1 a3 σd^2) -                    c2 (c3 d1 d2 σa^2 + c1 d2 d3 σa^2 +                       a2 a3 c1 σd^2 +                       a1 a2 c3 σd^2))))/(c3^2 (d2^2 σa^2 \     σb^2 + (b2^2 σa^2 + a2^2 σb^2) σd^2) -              2 c2 c3 (d2 d3 σa^2 σb^2 + (b2 b3 σa^2 +                    a2 a3 σb^2) σd^2) +              c2^2 (d3^2 σa^2 σb^2 + (b3^2 σa^2 +                    a3^2 σb^2) σd^2) + σc^2 ((a3 d2 -                    a2 d3)^2 σb^2 +                 b3^2 (d2^2 σa^2 + a2^2 σd^2) -                 2 b2 b3 (d2 d3 σa^2 + a2 a3 σd^2) +                 b2^2 (d3^2 σa^2 + a3^2 σd^2))) ∈           Reals && (c3^2 (d2^2 σa^2 σb^2 + (b2^2 σa^2 \     + a2^2 σb^2) σd^2) -              2 c2 c3 (d2 d3 σa^2 σb^2 + (b2 b3 σa^2 +                    a2 a3 σb^2) σd^2) +              c2^2 (d3^2 σa^2 σb^2 + (b3^2 σa^2 +                    a3^2 σb^2) σd^2) + σc^2 ((a3 d2 -                    a2 d3)^2 σb^2 +                 b3^2 (d2^2 σa^2 + a2^2 σd^2) -                 2 b2 b3 (d2 d3 σa^2 + a2 a3 σd^2) +                 b2^2 (d3^2 σa^2 +                    a3^2 σd^2))) (b1^2 c3^2 d2^2 σa^2 -              2 b1^2 c2 c3 d2 d3 σa^2 + b1^2 c2^2 d3^2 σa^2 +              a3^2 c2^2 d1^2 σb^2 - 2 a2 a3 c2 c3 d1^2 σb^2 +              a2^2 c3^2 d1^2 σb^2 - 2 a3^2 c1 c2 d1 d2 σb^2 +              2 a2 a3 c1 c3 d1 d2 σb^2 +              2 a1 a3 c2 c3 d1 d2 σb^2 -              2 a1 a2 c3^2 d1 d2 σb^2 + a3^2 c1^2 d2^2 σb^2 -              2 a1 a3 c1 c3 d2^2 σb^2 + a1^2 c3^2 d2^2 σb^2 +              2 a2 a3 c1 c2 d1 d3 σb^2 -              2 a1 a3 c2^2 d1 d3 σb^2 -              2 a2^2 c1 c3 d1 d3 σb^2 +              2 a1 a2 c2 c3 d1 d3 σb^2 -              2 a2 a3 c1^2 d2 d3 σb^2 +              2 a1 a3 c1 c2 d2 d3 σb^2 +              2 a1 a2 c1 c3 d2 d3 σb^2 -              2 a1^2 c2 c3 d2 d3 σb^2 + a2^2 c1^2 d3^2 σb^2 -              2 a1 a2 c1 c2 d3^2 σb^2 + a1^2 c2^2 d3^2 σb^2 +              a3^2 b1^2 d2^2 σc^2 - 2 a2 a3 b1^2 d2 d3 σc^2 +              a2^2 b1^2 d3^2 σc^2 + a3^2 b1^2 c2^2 σd^2 -              2 a2 a3 b1^2 c2 c3 σd^2 + a2^2 b1^2 c3^2 σd^2 +              b3^2 ((a2 d1 - a1 d2)^2 σc^2 +                 c2^2 (d1^2 σa^2 + a1^2 σd^2) -                 2 c1 c2 (d1 d2 σa^2 + a1 a2 σd^2) +                 c1^2 (d2^2 σa^2 + a2^2 σd^2)) +              b2^2 ((a3 d1 - a1 d3)^2 σc^2 +                 c3^2 (d1^2 σa^2 + a1^2 σd^2) -                 2 c1 c3 (d1 d3 σa^2 + a1 a3 σd^2) +                 c1^2 (d3^2 σa^2 + a3^2 σd^2)) -              2 b1 b2 ((a3 d1 - a1 d3) (a3 d2 - a2 d3) σc^2 +                 c3^2 (d1 d2 σa^2 + a1 a2 σd^2) +                 c1 c2 (d3^2 σa^2 + a3^2 σd^2) -                 c3 (c2 d1 d3 σa^2 + c1 d2 d3 σa^2 +                    a2 a3 c1 σd^2 + a1 a3 c2 σd^2)) -              2 b3 (b2 ((a2 d1 - a1 d2) (a3 d1 - a1 d3) σc^2 -                    c1 c3 (d1 d2 σa^2 + a1 a2 σd^2) +                    c1^2 (d2 d3 σa^2 + a2 a3 σd^2) +                    c2 (c3 d1^2 σa^2 - c1 d1 d3 σa^2 -                       a1 a3 c1 σd^2 + a1^2 c3 σd^2)) +                 b1 ((a2 d1 - a1 d2) (-a3 d2 + a2 d3) σc^2 +                    c1 c3 (d2^2 σa^2 + a2^2 σd^2) +                    c2^2 (d1 d3 σa^2 + a1 a3 σd^2) -                    c2 (c3 d1 d2 σa^2 + c1 d2 d3 σa^2 +                       a2 a3 c1 σd^2 + a1 a2 c3 σd^2)))) >           0) || 2 Abs[          Arg[(b1^2 c3^2 d2^2 σa^2 -               2 b1^2 c2 c3 d2 d3 σa^2 + b1^2 c2^2 d3^2 σa^2 +               a3^2 c2^2 d1^2 σb^2 -               2 a2 a3 c2 c3 d1^2 σb^2 +               a2^2 c3^2 d1^2 σb^2 -               2 a3^2 c1 c2 d1 d2 σb^2 +               2 a2 a3 c1 c3 d1 d2 σb^2 +               2 a1 a3 c2 c3 d1 d2 σb^2 -               2 a1 a2 c3^2 d1 d2 σb^2 +               a3^2 c1^2 d2^2 σb^2 - 2 a1 a3 c1 c3 d2^2 σb^2 +               a1^2 c3^2 d2^2 σb^2 +               2 a2 a3 c1 c2 d1 d3 σb^2 -               2 a1 a3 c2^2 d1 d3 σb^2 -               2 a2^2 c1 c3 d1 d3 σb^2 +               2 a1 a2 c2 c3 d1 d3 σb^2 -               2 a2 a3 c1^2 d2 d3 σb^2 +               2 a1 a3 c1 c2 d2 d3 σb^2 +               2 a1 a2 c1 c3 d2 d3 σb^2 -               2 a1^2 c2 c3 d2 d3 σb^2 +               a2^2 c1^2 d3^2 σb^2 - 2 a1 a2 c1 c2 d3^2 σb^2 +               a1^2 c2^2 d3^2 σb^2 + a3^2 b1^2 d2^2 σc^2 -               2 a2 a3 b1^2 d2 d3 σc^2 + a2^2 b1^2 d3^2 σc^2 +               a3^2 b1^2 c2^2 σd^2 -               2 a2 a3 b1^2 c2 c3 σd^2 + a2^2 b1^2 c3^2 σd^2 +               b3^2 ((a2 d1 - a1 d2)^2 σc^2 +                  c2^2 (d1^2 σa^2 + a1^2 σd^2) -                  2 c1 c2 (d1 d2 σa^2 + a1 a2 σd^2) +                  c1^2 (d2^2 σa^2 + a2^2 σd^2)) +               b2^2 ((a3 d1 - a1 d3)^2 σc^2 +                  c3^2 (d1^2 σa^2 + a1^2 σd^2) -                  2 c1 c3 (d1 d3 σa^2 + a1 a3 σd^2) +                  c1^2 (d3^2 σa^2 + a3^2 σd^2)) -               2 b1 b2 ((a3 d1 - a1 d3) (a3 d2 - a2 d3) σc^2 +                  c3^2 (d1 d2 σa^2 + a1 a2 σd^2) +                  c1 c2 (d3^2 σa^2 + a3^2 σd^2) -                  c3 (c2 d1 d3 σa^2 + c1 d2 d3 σa^2 +                     a2 a3 c1 σd^2 + a1 a3 c2 σd^2)) -               2 b3 (b2 ((a2 d1 - a1 d2) (a3 d1 - a1 d3) σc^2 -                     c1 c3 (d1 d2 σa^2 + a1 a2 σd^2) +                     c1^2 (d2 d3 σa^2 + a2 a3 σd^2) +                     c2 (c3 d1^2 σa^2 - c1 d1 d3 σa^2 -                        a1 a3 c1 σd^2 + a1^2 c3 σd^2)) +                  b1 ((a2 d1 - a1 d2) (-a3 d2 + a2 d3) σc^2 +                     c1 c3 (d2^2 σa^2 + a2^2 σd^2) +                     c2^2 (d1 d3 σa^2 + a1 a3 σd^2) -                     c2 (c3 d1 d2 σa^2 + c1 d2 d3 σa^2 +                        a2 a3 c1 σd^2 +                        a1 a2 c3 σd^2))))/(c3^2 (d2^2 σa^2 \     σb^2 + (b2^2 σa^2 + a2^2 σb^2) σd^2) -               2 c2 c3 (d2 d3 σa^2 σb^2 + (b2 b3 σa^2 +                     a2 a3 σb^2) σd^2) +               c2^2 (d3^2 σa^2 σb^2 + (b3^2 σa^2 +                     a3^2 σb^2) σd^2) + σc^2 ((a3 d2 -                     a2 d3)^2 σb^2 +                  b3^2 (d2^2 σa^2 + a2^2 σd^2) -                  2 b2 b3 (d2 d3 σa^2 + a2 a3 σd^2) +                  b2^2 (d3^2 σa^2 + a3^2 σd^2)))]] < π]


Performance on Multinomial Deviate is slow

Most of the time in my program is spent on this single line of code:               out = RandomVariate[MultinomialDistribution[nt, tmp]];      `tmp` is a vector of `np+1` probabilities which sum to 1. `nt` is an integer. `out` is an np-component vector of integers that sums to `nt`. pseudo-code:               Loop:          Get new np and nt values     set up tmp.     out = RandomVariate[MultinomialDistribution[nt, tmp]];          Do stuff with out     End Loop      Here is an example with timing results. In the real problem `nt` and the length of `tmp` are random but this example is enough to illustrate the difficulty. Is there an obvious way to improve the performance?               tmp = {.1, .1, .8}     nt = 2;     timer = TimeUsed[];     For[i = 1, i < 10000, i++,        (* tmp may be changed here *)        out = RandomVariate[MultinomialDistribution[nt, tmp]];     ];     Print["time in loop=", TimeUsed[] - timer];      Sorry if this has been discussed before.


Placing Manipulate controls in multiple columns

I have a `Manipulate` construct with a square `Graphic` on the left side and all the controls placed on the right side. There are so many (and also pretty large) control items, however, that they take up about double the vertical space of the graphic. Is there a simple way to place the controls into two seperate columns (like in the sketch below)?                _________     |         | Control 1 | Control 4     | Graphic | Control 2 | Control 5     |_________| Control 3 | Control 6      I could do something similar using `Item` and `Grid`, but as far as I know, in such a construct the default control syntax wouldn't work and I'd have to re- program all the controls with `Dynamic`. It seems `ControlPlacement` also does not support multiple columns. **Edit:** To be clear: I'm trying to find a solution that preserves as much of `Manipulate`'s properties as possible, i.e. things like alignment, labeling and using default control types.


Solution of equation with power series (perturbation)

So I need to use _Mathematica_ to find the solution of $y=x- \epsilon \sin(2y)$ as a power series in terms of $\epsilon$. I'd assume I'd need to create an equation $f=x-y- \epsilon \sin(2y)$, then express $y(\epsilon)=\sum_n a_n \epsilon^n$, then input into series, but I can't seem to get it to work. Some help would be appreciated.


Generating Gelfand-Tsetlin patterns

I am doing some research on some combinatorial object called GT-patterns. They are generated from three parts of data. Two integer, partitions (sequences of weakly decreasing numbers), $\lambda = \lambda_1 \geq \lambda_2,\dotsc, \lambda_n \geq 0$ and $\mu = \mu_1 \geq \dotsc, \mu_n \geq 0$ such that $\lambda_i \geq \mu_i$, and vector of non- negative integers, $w = (w_1,\dotsc,w_k)$ such that $w_1+w_2+\dots + w_k = (\lambda_1+\dots + \lambda_n)-(\mu_1+\dots + \mu_n)$, generate all arrays where certain equalities and inequalities are satisfied, as in the example below: Here, $\lambda = (4, 3, 3, 2, 1, 1, 0, 0)$, $\mu = (2, 2, 1)$, and $w = (3, 3, 2, 1)$. Note that we pad $\mu$ with zeros so that it has the same length as $\lambda$. The arrays are constructed as follows: It consists of $k+1$ rows, the first row is $\lambda$ and the last row is $\mu$. The difference of the sum of the entries in row $i$ and $i+1$ must be equal to $w_{k-i+1}$. Thus, thus, in the example, going to 5th row to 4th row, the row sum increases by 3. 4th to 3rd is also an increase by 3, followed by 2 and 1. That are all equalities that are needed to be satisfied. Now, the inequalities we require to be fulfilled are that each down-right diagonal is weakly decreasing, and each down-left diagonal is weakly increasing. All entries should be non-negative integers. All solutions for the example is given below: ![GT-patterns](http://i.stack.imgur.com/YebAY.png) The output consists of the rows, (as a matrix). I am also interested in the case where instead of specifying the row sums, we only specify the number of rows. The number of patterns that fit the requirement is still a finite number. Thus, the method could be specified as follows:               FindGTPatterns[lambda_List, mu_List, w_List]     FindGTPatterns[lambda_List, mu_List, rows_Integer]      and the output is a list of matrices. The method I currently use is the one below. It is very straigthforward, it encodes the equalities and inequalities, and just use `Reduce`. This works ok, but when the number of solutions is large (>30000), `Reduce` cannot take it. Also, I strongly suspect that there is a more efficient solution that does not rely on `Reduce`.               (* ToTableauShape is a method that pads the partitions so that they have the same lenghts, and wars if total of lambda minus total of mu is not the total of w *)          GTPatterns[lambda_List, mu_List:{},weight_List:{}]:=GTPatterns[ToTableauShape[lambda,mu,weight]];     GTPatterns[lambda_List, mu_List:{},maxBox_Integer]:=GTPatterns[ToTableauShape[lambda,mu,{}],maxBox];     GTPatterns[lambda_List, maxBox_Integer]:=GTPatterns[ToTableauShape[lambda,{},{}],maxBox];          GTPatterns[TableauShape[lambda_, mu_, weight_],maxBoxIn_Integer:0]:=Module[         {w, h, x, gtp, bddconds, wconds=True, ineqs, sol,maxBox=maxBoxIn},              (* Calculate width, height, of GT-pattern. *)         w = Length[lambda];              (* If no weight or maxBox specified, then maxBox is the number of parts of lambda. *)         h = 1 + Which[             Length[weight] >0 , Length[weight],             maxBox > 0, maxBox,             True, w];              gtp = Table[x[r][c], {r, h, 1, -1}, {c, w}]; (* The GT-pattern *)              (* Boundary conditions. *)         bddconds = And @@ Table[x[h][c] == lambda[[c]] && x[1][c] == mu[[c]], {c, w}];              If[Length[weight]>0,             wconds = And @@ Table[ Sum[x[r + 1][c] - x[r][c], {c, w}] == weight[[r]], {r, h - 1}];         ];              (* Inequalities that must hold. *)         ineqs = And @@ Flatten[Table[             If[r < h, x[r + 1][c] >= x[r][c], True] &&             If[r < h && c < w, x[r][c] >= x[r + 1][c + 1], True] , {r, h}, {c, w}]];              sol = Reduce[bddconds && ineqs && wconds, Flatten@gtp, Integers];              If[sol===False, Return[{}]];              sol = gtp /. List[ToRules[sol]];         Return[GTPattern/@sol];     ];      On a side note, these patterns are called Gelfand-Tsetlin patterns, and are related to representation theory in mathematics. I asked another question related to these earlier here, and got some really nice algorithms related to doing computations on these types of patterns. _Side note:_ In what I am doing, I am trying things for $m=1,2,3,...$ and examine all $\lambda$ where the total is $m$, and for each such $\lambda$, examine all $\mu$ and $w$ that fits the requirements, I examine all patterns. Currently, up to $m=8$ is ok, but after that, it takes too much time. Of course, for some parameters $\lambda,\mu,w$ the set of patterns can be empty. If you have a nice description on WHEN this happens, you can write an article (but I think this is proven to be NP-hard in $m$).


How to pass composite function list to SortBy?

In order to sort alphanumeric-as-string data of the form `{"T3", "T14", "T1", "E2"}`, so that `"T14"` comes after `"T3"`, `SortBy` requires the tiebreaker function list:               {StringTake[#, 1] &, ToExpression@StringDrop[#, 1] &}      Which works as intended when this expression is inserted literally in `SortBy`. However, defining a utility function `mySort[x_String]:={StringTake[x, 1] , ToExpression@StringDrop[x, 1]}` doesn't work since the output is a list of expressions rather than a list of functions. The alternative - to define a function via               mySort := {StringTake[#, 1] &, ToExpression@StringDrop[#, 1] &}      only works when the list to be sorted is 1-dimensional (as above) but not with lists of the form `data2={"T3"->a, "T14"->b, "T1"->c, "E2"->d}` where it is necessary to use `SortBy[data2,mySort[#[[1]]]&]`. Any alternatives that will work for general expressions?


Faster alternatives for DayOfWeek

It has been noticed on several occasions that `DayOfWeek` function is rather slow when applied to a large list of dates, e.g. in this recent question. What faster alternatives do we have in such situations?


Background. See question Moving controls from Manipulate to a Palette ( or similar GUI object ). As suggested in the answer to this question I use a CreateDialog window to group and handle controls and added WindowFloating->True as an option. Clicking a second time on the external button creates an identical copy of the Window. Question: **What it is the best way to enforce that only one CreateDialog window can be created?**


Pattern test for variables during function definition

I am having a problem with pattern testing on variables during function definition               nfun[M : Repeated[_?(test1&&test2||test3..)&, {10}]]:= N@(Norm@(Sin[#] & /@ M))      I want to have a few tests on the vectors `M` that I want to feed `nfun`. One example that does not work if I want to test if `M` has `Integer` entries using `Repeated` is the following.               nfun[M : Repeated[_?IntegerQ, {10}]]:= N@(Norm@(Sin[#] & /@ M))      Here goes another filed trial with the same aim.               nfun[M_?((VectorQ[#, IntegerQ]) && (Length[#] == 10)) &]:= N@(Norm@(Sin[#] & /@ M))


Integrate perfomance

I have a notebook in Mathematica 4. I'm trying to convert it to use in Mathematica 9. One of the problem is the long computation of definite integral in the new version of Mathematica. Here's the example: ![enter image description here](http://i.stack.imgur.com/3lY6S.png) I understand that the new Mathematica produces more accurate answer, but even NIntegrate loses in speed of calculations. Is there any simple solution to make the integration work faster?


Remove versus ClearAll

What is the difference between `Remove` and `ClearAll`? I thought that " _not being recognized by Mathematica_ ", which is the effect of `Remove`, meant that there would be no " _values, definitions, attributes, messages, and defaults associated with symbols_ ", which is the effect of `ClearAll`. That naive equivalence is wrong as shown by the different output out of these two lines:               b := a; Remove[a]; b     b := a; ClearAll[a]; b      Which side effects of `Remove` are not shared by `ClearAll` (and viceversa)?


How can we multiply nested matrices?

If we have nested matrices, such as: $$ \begin{bmatrix} \begin{bmatrix} a_{1,1} & a_{1,2}\\ a_{2,1} & a_{2,2}\\ \end{bmatrix} \begin{bmatrix} b_{1,1} & b_{1,2}\\ b_{2,1} & b_{2,2}\\ \end{bmatrix} \\ \begin{bmatrix} c_{1,1} & c_{1,2}\\ c_{2,1} & c_{2,2}\\ \end{bmatrix} \begin{bmatrix} d_{1,1} & d_{1,2}\\ d_{2,1} & d_{2,2}\\ \end{bmatrix} \\ \end{bmatrix} $$ ...and we wish to multiply two of these matrices together, how can we accomplish this? Here I assume that the conventional rules of matric multiplication apply. For example, we treat each "sub-matrix" (or block matrix, if you prefer), for lack of a better term, as an entry in the main matrix. Then we recursively apply the rules of matrix multiplication. **AN ATTEMPT TO EXPLAIN** So, for example, the matrix from above could be represented as: $$ \begin{bmatrix} a & b\\ c & d\\ \end{bmatrix} $$ ...and multiplied by another matrix to get: $$ \begin{bmatrix} a & b\\ c & d\\ \end{bmatrix} * \begin{bmatrix} e & f\\ g & h\\ \end{bmatrix} = \begin{bmatrix} (ae+bg) & (af+bh)\\ (ce+dg) & (cf+dh)\\ \end{bmatrix} $$ Where each entry above is actually another matrix. For example, the entry $(ae+bg)$ is actually: $$ (ae+bg) = \begin{bmatrix} a_{1,1} & a_{1,2}\\ a_{2,1} & a_{2,2}\\ \end{bmatrix} * \begin{bmatrix} e_{1,1} & e_{1,2}\\ e_{2,1} & e_{2,2}\\ \end{bmatrix} + \begin{bmatrix} b_{1,1} & b_{1,2}\\ b_{2,1} & b_{2,2}\\ \end{bmatrix} * \begin{bmatrix} g_{1,1} & g_{1,2}\\ g_{2,1} & g_{2,2}\\ \end{bmatrix} $$


Interpolating a list with exclusion

I have a list, `data`, where the elements `data[[i]]` range over `i` from `-N` to `N`. I want to define a function interpolating this list at every point except for `i`=`0`. Is there a way to do this?


Tensor product involving Levi Civita symbol

I'm working with xAct package. I've defined the tensor component values and my issue is that I want an expression involving Levi Civita symbols and tensor components, I don't know how to deal with it. The expression is something like $\epsilon_{abc}$T$_{ade}$ and other two index tensor components. Does anybody know how to deal with it? I try multipling the tensor T to the Levi Civita, but my output writes 'T' instead of the components of the tensor. Can anybody help me please? Thank you


Sum with Levi-Civita

I'm trying to write the expression $$\sum_{\alpha,\beta = 1}^{4}\epsilon_{\mu \nu\alpha\beta}a^{\nu} b^{\alpha} c^{\beta}$$ in Mathematica, where $\epsilon$ is the Levi-Civita symbol and $a$, $b$, $c$ are 4-dimensional vectors. I tried this but the problem is with Levi-Civita as $\mu$ and $\nu$ are not specified in advance               a = {a1, a2, a3, a4};      b = {b1, b2, b3, b4};      c = {c1, c2, c3, c4};          Sum[       LeviCivitaTensor[4][[mu, nu, alpha, beta]] a[[nu]] b[[alpha]] c[[beta]],       {alpha, 1, 4}, {beta, 1, 4}     ]


White regions in DensityPlot — is this a bug with ColorFunctionScaling?

Is this a bug with `ColorFunctionScaling`? When I try to supply my own `ColorFunction` Mathematica seems to partially ignore it, and the white color "burns through" if the function is too "sharp":               mycf[z_] := RGBColor[z, 0, 0]          GraphicsRow[       {DensityPlot[(Sin[x] Sin[y])^4, {x, 0, Pi}, {y, 0, Pi},         ColorFunction -> mycf, ColorFunctionScaling -> False],        DensityPlot[(Sin[x] Sin[y])^5, {x, 0, Pi}, {y, 0, Pi},          ColorFunction -> mycf, ColorFunctionScaling -> False]}     ]      ![density plots](http://i.stack.imgur.com/gy5p0.png)


How to improve a DensityPlot?

Given that               x1 =        -((π^2 (x - x0) Cosh[π (x - x0)]) /        (2 (-Cos[π (y - y0)] + Cosh[π (x - x0)]))) + (π^2 (x - x0) Cosh[π (x - x0)]) /         ( 2 (-Cos[π (-1 + y + y0)] + Cosh[π (x - x0)])) + (π^2 (x - x0) Sinh[π (x - x0)]^2) /         ( 2 (-Cos[π (y - y0)] + Cosh[π (x - x0)])^2) - (π^2 (x - x0) Sinh[π (x - x0)]^2) /         ( 2 (-Cos[π (-1 + y + y0)] + Cosh[π (x - x0)])^2)      I want to do a density plot by using:               DensityPlot[ x1 /. {x0 -> 0, y0 -> 0.2}, {x, -0.5, 0.5}, {y, -0.5, 0.5}]      ![Mathematica graphics](http://i.stack.imgur.com/y6gfc.png) But there are some white regions which are not plotted by density color. How to plot the density color also in the white regions?


Debugging the context of a Package

I am working on a package of functions that complement the `NeuralNetworks`` package that Wolfram provides. I am having a problem with the following code, which is essentially a wrapper for two commands that I run frequently:               runNetwork[data_,desc_,dlist_,{tlist_,vlist_}]:= Module[{fdfwd,m,r},         fdfwd = InitializeRBFNet[                 desc[[tlist,dlist]],                 data[[tlist]],                 1,RandomInitialization->False];         {m,r} = NeuralFit[fdfwd,             desc[[tlist,dlist]],             data[[tlist]],             desc[[vlist,dlist]],             data[[vlist]],             100,Method->SteepestDescent,CriterionPlot->False];         {m,r}]      When I declare this function within my notebook, it runs as expected; however if I place it in a package (for instance, `MyNeuralNetworks``) then I get errors of the following type: > Set::shape: "Lists > {SolarNeuralNetwork`Private`m\$2436,SolarNeuralNetwork`Private`r\$2436} and > SolarNeuralNetwork`Private`NeuralFit[<<1>>] are not the same shape." which suggests to me that the list `fdfwd` that is returned by the first function is not being passed correctly to the second function. I have tried adding a `Needs["NeuralNetworks`"]` line in both the Public and Private portions of the package as well as in the `BeginPackage` line following this question and answer. I'm new to package writing, so there may be something obvious I'm missing. It's possible that the answer I'm looking for is hidden somewhere in this discussion but I don't know how to implement those suggestions in my context.


Table function with Part[] call misbehaving, but only after initial startup of Mathematica

I am getting errors like:               Part::partd:         Part specification standardBasis[[1]] is longer than depth of object.      with the following Manipulate expression:               Clear[  e1, e2, standardBasis, y]     e1 := {1, 0}     e2 := {0, 1}     standardBasis := {e1, e2}     y := 3     Manipulate[      p := {x, y} ;      Clear[j];      arrowsReference = Table[Arrow[{p, p + Part[standardBasis, j]}], {j, 2}]      , {{x, 1}, -10, 10} ]      The odd thing about it is that this only occurs immediately after starting Mathematica, on the source file that contains this manipulate. A second shift- enter on the expression after that works without complaint and I get the desired result. This appears to be related to the startup of mathematica using specific notebooks. The sequence I'm using is:   * go to windows explorer.   * double click on a .nb or .cdf file with this source.   * click enable-dynamics.   * get the error.   * shift-enter: error goes away. whereas if I take a notebook that is blank and already opened and then cut and paste this source into it, I don't get any errors about the `Part[]` expressions.


Efficient conditional Mean[] on a large data set

Consider a list, `AK6`, that has 382 sublists of length varying from 2500 to 3000. Each "subsublist" is as such : `AK6[[1,1]]={5.5,1001}` With `AK6[[All,1]]` going from 1001 to 4001 with gaps (missing points) I now need to compute the `Mean[]` for all the sublists with equal second value. That is `Select` with `Flatten[AK6,1]` all the list with 2005 as the second value (from 350 to 384 items approx) I do this using :               ParallelTable[                  Mean[Select[Flatten[AK6s, 1], #[[2]] == gazeNo &][[All,1]]],                   {gazeNo, Range[1000, 4000, 1]}]      It does what I need but this is very slow. Is there a way to do this computation faster? * * * Download the 13 MB list as               AK6 = Uncompress@Import["http://api2.ge.tt/0/9F8d6WD/0/blob/download", "String"];


NDSolve example - analytical vs numerical solution. How to specify initial conditions?

So, I have the following equation:               y[t]^-3 == w^2 y[t]/t^2 + y''[t]      where               w^2 = (t0 k0)^2.      Analytic solution is easy to obtain:               y[t] = a Sqrt[t]      where               a = 1/Sqrt[t0 k0]      Since the solution is singular in `0`, am I not sure how to specify the initial conditions for `NDSolve`. When I put this in `NDSolve` I expect to get a solution that behaves like `~t^(1/2))`, but I get a `~t` solution which doesn't make sense.               NDSolve[{-y''[t] - y[t]/t^2 + y[t]^(-3) ==                      0, y[?] == ?, y'[?] == ?}, y, {t, ?, ?}]      I don't have any constrains for `t0` and `k0` from physics (yet), I just want to understand better how the `NDSolve` really works. Edit: When I try with: w=1, k0, t0=1, it works fine: NDSolve[{-y''[t] - 1(y[t])/(t^2) + (y[t])^(-3) == 0, y[1] == 1, y'[1] == 1}, y, {t, 1, 100}] -> ~t^1/2 behaviour. But when I try with: w=10, k0=1, t0=10 NDSolve[{-y''[t] - 10*(y[t])/(t^2) + (y[t])^(-3) == 0, y[10] == 10, y'[10] == 0.045}, y, {t, 10, 100}], I get some kind of crazy periodic functions. Why? (IC for y'[10] == 0.045 follows directly from derivative.)


How to define a new copula distribution family

The function `CopulaDistribution` can be used with the most well known kernels. I was wondering how I can add a new family of kernels in a way that it works in the same way as the current function. For example as the documentation explains: > `CopulaDistribution` can be used with such functions as `Mean`, `PDF`, and > `RandomVariate`, etc. Do I need to define all these functions myself or is there a smart way of using the functions which are already defined in Mathematica? I wonder if anyone has done something similar and would like to share his/her experience on this.


What is a "Paclet"?

I often see references to "paclets", for example the `PacletManager`` context, the `PacletInfo.m` file in some packages and next to downloaded computable data, `$UserBaseDirectory/Paclets`, etc. **Question:** What are "paclets", what is their relevance to end users, and how can one use them with packages? **Clarification:** Since I saw a `PacletInfo.m` file in several third party packages as well, I assume that they must be useful in packages and there must be some documentation on how to use them somewhere. I am hoping someone could point me to the relevant documentation.


Sum does not converge, but I think it should

Why does _Mathematica_ return > Sum::div: Sum does not converge. >> When I input               Sum[Boole[!IntegerQ[x]], {x, 1, Infinity}]      The sum is obviously 0.


Is it possible to use Begin and End inside a Manipulate?

May be someone can explain why I can't use `Begin["context`"]` and `End[]` inside a `Manipulate` expression, or inside the initialization section? When I use it in the `Manipulate` expression, and close the notebook and restart, I get the error: ![enter image description here](http://i.stack.imgur.com/kzkr3.png) Here is the code, please feel free to modify as needed. I am just trying to see if the idea of different contexts can be used inside Manipulate. It is just not seeing `obj`f[]` at all.               Manipulate[           Begin["obj`"];      f[y_] := y^2 + 1;      End[];           {x, Date[], obj`f[1]},           {{x, 0, "x"}, 0, 10, 1, Appearance -> "Labeled"},      TrackedSymbols :> {x}      ]      I also tried in the initialization section, same problem. I think this is because `Manipulate` itself is a `Dynamic` module, it does not like new context created inside it? This is a snapshot of the above:               DynamicModule[{x = 5},           Begin["obj`"];           f[y_] := y^2 + 1;           End[];           {x, Date[], obj`f[1]}      ]      Outside `Manipulate`, it works fine of course: (restating kernel helps before running this below again after the above just in case)               Begin["obj`"];     f[y_] := y^2 + 1;     End[];          obj`f[2]      gives `5`


How to make a new analytic function work seamlessly with Mathematica's analysis functions?

I am defining a new analytic function of six variables. I have algorithms to evaluate it numerically, and have amassed a large catalog of analytic properties. It is easy for me to program the numerics using:               funcF[a_?NumericQ, b_?NumericQ, c_?NumericQ, d_?NumericQ, e_?NumericQ, f_?NumericQ] = (*...*)      I know the analytic expression for its derivative with respect to each argument. I also know the location of all the singularities and the Taylor/asymptotic series expansion of this function near these singularities in all six variables, and a bunch of other identities. **Question** : I want to make a package that incorporates this function into _Mathematica_. What do I need to do to to make it work as seamlessly as possible with its built-in functions like `Derivative`, `Limit`, `Series` `Simplify`, _etc._ Clearly, there will be a lot of coding to do, but I'm more than willing. * * * I already have a head-start from the answer to this question, which nicely makes the custom function `ln` work well with `Derivative` and `Series`. I stumbled upon this page: http://functions.wolfram.com/NB/StruveH.nb which includes functions like `DomainAndRange`, `Singularities`, etc. and thought this would be the key to accomplishing my task. Alas, these functions aren't `Mathematica` functions and can't be evaluated. Is there a template/guideline for this?


Why is FindInstance finding non-instances?

Consider this example:               FindInstance[Exists[{x, y}, x > 1 && y > 1 && x > Sqrt[x + y]], {x, y}]      which finds values of $x$ and $y$ such that $x>\sqrt{x + y}$. Why does Mathematica output `{{x->0, y->0}}`? The condition is obviously violated in all three parts: none of $x>1$, $y>1$, or $x>\sqrt{x+y}$ are satisfied by $(0,0)$. What's going on here? Am I misusing `FindInstance`? Or `Exists`?


Take the function f(x)=2x-x^2 and the open interval P=(0,2) why is f(P)=(0,1]? why is that 1 closed?

I would think it would be f(P)=(0,1). Why does it include the endpoint?


How to plot a list of lists with ListLinePlot?

(edited, after rasher comment, changing any detail and variable names) You can plot an evolution with 3 lines (up=maximmun, in the middle=mean, bottom=Minimum) with this code               historytargetmax = {10, 15, 20, 30, 35}     historytargetmean = {6, 8, 10, 13, 15}     historytargetmin = {6, 3, 5, 7, 8}          ListLinePlot[{historytargetmax, historytargetmean,        historytargetmin}, PlotStyle -> {Thickness[0.008]},       AxesLabel -> {"Generation", "Target"}, LabelStyle -> {24, Bold},       ImageSize -> Large]      My question is How do you do this with multiple (for example 3) series. For example... in the next lines... each list historytarget___ contains 3 list. Each list represent s the maximun/mean/minimun of target function trought iterations {1,2,3,4,5} We made 3 simulations and in the first simulation we obtain this evolution os maximun {10, 15, 20, 30, 35} and this evolution of mean {6, 8, 10, 13, 15} and this evolution of min {2, 3, 5, 7, 8} So we would like to view the maximun line in blue, the min-line evolution en green, and min-lin evo in red. The same in the other 2 simulations. So finally we can see 3 lines representing the evo of maximun (BLUE and UP) 3 lines representing the evo of mean (GREEN and middle) and 3 lines representing the evo of min (RED and BOTTOM) for example with               historytargetmax = {{10, 15, 20, 30, 35}, {12, 14, 17, 27,  31}, {11, 12, 22, 32, 32}}     historytargetmean = {{6, 8, 10, 13, 15}, {8, 9, 11, 12, 13}, {11, 12, 12, 13, 19}}     historytargetmin = {{2, 3, 5, 7, 8}, {2, 4, 5, 7, 8}, {6, 2, 5, 3, 7}}      Last thing.- I think that it would be interesting plotting all the maximun series in BLUE all the mean series in GREEN all the minimum series in RED how to do this?


List plot 3D not showing correct data

I have a list of values of the form `{{a_1,b_1,c_1},{a_2,b_2,c_2}...}` where `a` goes from 0 to 30, `b` goes from 0 to 30, and `c` goes from 0 to .05. For some reason, when I plot this using `ListPlot3D` I get ranges of 1 to 4, 0 to 40, and 0 to 500 respectively (the number of data points that I am plotting. The exact command that I am using is: `ListPlot3D[data,PlotRange->{Full,Full,Full},AxesLabel->{"Length","Distance","Time"}]` Does anyone know what might be the issue? Note: If anyone wants to look at the actual data, I posted it here.


Asymptotic series

I need to solve the following problem. I have the following function: `Erf[Sqrt[a x^2 + b y^2]]/Sqrt[a x^2 + b y^2]`, where x and y are variables and a and b parameters. I need to slightly modify the function (maybe adding an additional parameter, multiplying with the given parameters or modifying denominator, such as, that its major term in the series expansion about infinity for x and y would be 1/x and 1/y, respectively. This is what I get:               FullSimplify[Series[Erf[Sqrt[a x^2 + b y^2]]/Sqrt[a x^2 + b y^2], {x, Infinity, 2}]]      and the major term in the output would be `1/(Sqrt[a] x)` Also with the y:               FullSimplify[Series[Erf[Sqrt[a x^2 + b y^2]]/Sqrt[a x^2 + b y^2], {y, Infinity,     2}]]1/(Sqrt[a] x)      and the major term in the output would be `1/(Sqrt[a] y)` So I need a function similar to one here `(Erf[Sqrt[a x^2 + b y^2]]/Sqrt[a x^2 + b y^2])`, who will give both 1/x and 1/y respectively, for the given mathematica inputs. Has anybody got an idea how to modify the function? An intuitive way was to multiply it by `Square[a b]`, but I tried and it did not work. I tried the other things, but the problem to me didn't seem trivial. Has anyone got an idea? Also does anybody know what Mathematica does to make a series of a function of 2 variables around infinity? I know it is called the asymptotic series, but what would be practical way to get it. Having an insight about that some constraint can be found about the function, and therefore the above-mentioned problem can be solved.


Simplifying the trace of a matrix expression

I have a long expression involving matrices that I derived using the NCAlgebra package. Can I simplify the trace of the expression? For example, say `b` is a scalar (commutes with all) and `x` and `y` are matrices (non-commutative). Can I simplify `Tr[b x.y.y + b y.x.y]` to `2b Tr[x.y.y]` using the properties of the trace? * * * Thanks, that is what I am going for (although I don't quite understand the code) but I only have version 8. The expression is given below, where `e` and `r` are scalars, `q` and `v` are matrices and the double star (`**`) denotes products of non-commutative elements. I've done it by hand, but I want to be able to simplify the trace of this with _Mathematica_ (and others which are much longer).               e^2 q ** q - e r q ** v - e r v ** q + r^2 v ** v -       1/12 e^3 r q ** q ** q ** v + 1/12 e^3 r q ** q ** v ** q +       1/24 e^2 r^2 q ** q ** v ** v + 1/12 e^3 r q ** v ** q ** q -       1/12 e^2 r^2 q ** v ** q ** v - 1/12 e^2 r^2 q ** v ** v ** q +       1/24 e r^3 q ** v ** v ** v - 1/12 e^3 r v ** q ** q ** q +       1/6 e^2 r^2 v ** q ** q ** v - 1/12 e^2 r^2 v ** q ** v ** q -       1/24 e r^3 v ** q ** v ** v + 1/24 e^2 r^2 v ** v ** q ** q -       1/24 e r^3 v ** v ** q ** v + 1/24 e r^3 v ** v ** v ** q


Avoid making repeated Random Integer in different iterations

Assume following code :               Do[        i1 = RandomInteger[{1, 5}];        i2 = RandomInteger[{1, 5}];        While[i1 == i2,  i2 = RandomInteger[{1, 5}]]         , {k, 1, 4}];`      This code makes two `RandomIntegers` which are `i1` and `i2`. I have used `While` loop to avoid making repeated Random numbers in each iteration. But I don't know how it is possible to avoid making repeated Random numbers in whole iterations. For example, following result is the answer after 4 iteration and it is not acceptable : > >      i1=1, i2=2 >      i1=3, i2=2 >      i1=1, i2=2 >      i1,4, i2=1 >   `i1=1` and `i2=2` are repeated twice after 4 iterations. I would be appreciated if someone could help me with this problem.


How to efficiently select element in a list of lists?

How can I write an efficient version of the following statement?               Cases[list, {_, feature_} /; feature < constant]; // AbsoluteTiming      List is of the form, list = {{feature11,feature12},...,{featuren1,featuren2}}. It has a length in the order of 10^5. On my laptop, a Macbook pro from last year it takes around 0.25s. However, I need to evaluate this expression a lot of times. Any suggestion. Thank you.


Apply a function to each element of a list and sum it

I have a list               {-1.8, 1.44, 0.2736, -1.72514, 1.17612}      where each element stands for a value of x. e.g. $x1 = -1.8$, $x2 = 1.44$ and so on. How can I find the summation of $ln(2x)$ without manuall calculating it? That is: $ln(2(-1.8)) + ln(2(1.44)) + \ldots + ln(2(1.17612))$


4 circular arcs, how plot the minimal surface?

By using Sjoerd de Vries code for circular arcs:               ClearAll[splineCircle];      splineCircle[m_List, r_, angles_List: {0, 2 π}] :=       Module[{seg, ϕ, start, end, pts, w, k}, {start, end} =          Mod[angles // N, 2 π]; If[end <= start, end += 2 π];         seg = Quotient[end - start // N, π/2]; ϕ =          Mod[end - start // N, π/2];         If[seg == 4, seg = 3; ϕ = π/2];         pts = r RotationMatrix[start].# & /@           Join[Take[{{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1,               0}, {-1, -1}, {0, -1}}, 2 seg + 1],            RotationMatrix[seg π/2].# & /@ {{1,               Tan[ϕ/2]}, {Cos[ϕ], Sin[ϕ]}}];         If[Length[m] == 2, pts = m + # & /@ pts,          pts = m + # & /@            Transpose[            Append[Transpose[pts], ConstantArray[0, Length[pts]]]]];         w = Join[          Take[{1, 1/Sqrt[2], 1, 1/Sqrt[2], 1, 1/Sqrt[2], 1},            2 seg + 1], {Cos[ϕ/2], 1}];         k = Join[{0, 0, 0}, Riffle[#, #] &@Range[seg + 1], {seg + 1}];         BSplineCurve[pts, SplineDegree -> 2, SplineKnots -> k,          SplineWeights -> w]] /; Length[m] == 2 || Length[m] == 3          g1 = Graphics3D[        Table[{Hue@0.1,           GeometricTransformation[           Tube[splineCircle[{0, 0, 0}, 1, {0, 3.141592653589}],             1/12], {-1, 1, 1}]}, {1}], Boxed -> False];     g2 = Graphics3D[        Table[{Hue@0.1,           GeometricTransformation[           Tube[splineCircle[{0, -1, 0}, 1, {0, 3.141592653589}], 1/12],            RotationTransform[Pi, {1, 0, 1}]]}, {1}], Boxed -> False];     g3 = Graphics3D[        Table[{Hue@0.1,           GeometricTransformation[           Tube[splineCircle[{0, -1, -2}, 1, {0, 3.141592653589}], 1/12],            RotationTransform[Pi, {1, 0, 1}]]}, {1}], Boxed -> False];     g4 = Graphics3D[        Table[{Hue@0.1,           GeometricTransformation[           Tube[splineCircle[{0, 0, -2}, 1, {0, 3.141592653589}],             1/12], {-1, 1, 1}]}, {1}], Boxed -> False];     g4 = Show[g1, g2, g3, g4]      I plotted these four circular arcs: ![bent circle](http://i.stack.imgur.com/EhSoZ.jpg) How can I make a minimal surface that describes both the space inside it, and outside it stretching out to infinity? The minimal surface should describe the object as a whole and not the four arcs individually.


An equivalent in Mathematica

Let's say I have a $n$x$m$ matrix $M$ in Matlab and I want to substitute the elements of $M$ that exceed $15$ for $-1$. In Matlab I just write               M(M>15)=-1      and I'm done. I have been struggling to do this in Mathematica. Does Mathematica have an equivalent way to do this? Something that is easy to remember and that takes few lines will be appreciated Thank you


Is there a cleaner/shorter way to select-replace in matrices?

I love _Mathematica_ , but I find it oddly lacking when it comes to how matrices are handled. Here is an example of code that _works_ but seems like it should be a lot shorter (and minus the loop). I'm a super-newbie though so maybe one of you smart people has an idea for making this nicer. The point is to take all elements of the matrix that evaluate as `True` for some criterion (here, being less than 7) and re-assign them to a new value.               testmat = {{-1, 1, -3}, {10, 11, 5}, {15, -2, 7}};     MatrixForm[testmat]     badpos = Position[testmat, _?(# < 7 &)];     {nend, trash} = Dimensions[badpos];     For[i = 1, i <= nend, i++,       selpos = badpos[[i]];       p1 = selpos[[1]];       p2 = selpos[[2]];       testmat[[p1, p2]] = 0;     ]     MatrixForm[testmat]


MATLAB's "logical indexing" in Mathematica

% MATLAB code     A=reshape(1:16,4,[])'     k=logical([1 0 0 1; 0 1 1 0; 0 1 1 0;1 0 0 1 ])     A(k)=5-A(k)     %{      4     2     3     1      5    -1    -2     8      9    -5    -6    12     -8    14    15   -11     %}      I need _Mathematica_ code that works like the MATLAB code above. Is there a easy way do this?               A = Range[16]~Partition~4     k = {{1, 0, 0, 1}, {0, 1, 1, 0}, {0, 1, 1, 0}, {1, 0, 0, 1}}     A[[k]] = 5 - A[[k]]      **Updated** :               fA = Flatten[A];     p = Flatten@Position[Flatten@k, 1];     fA[[p]] = 5 - fA[[p]];     Partition[fA, 4]          (*{{4, 2, 3, 1}, {5, -1, -2, 8}, {9, -5, -6, 12}, {-8, 14, 15, -11}}*)


RefProp in Mathematica

`RefProp` by NIST is a program that calculates the thermodynamic properties of fluids. I need to call certain `RefProp` functions from inside _Mathematica_. Can any one here, who has experience calling `RefProp` functions from _Mathematica_ , tell me how to do this??


Fetching data from HTML source

I want to generate a couple of plots/graphs with Area51 statistics. Since Area51 doesn't work with the SE API, I'm forced to find another way to get the information I want. That other way is with `RegularExpression[]` (or _Mathematica_ 's string patterns). Let's start with a specific example, then move on to a more general case. _Mathematica_ lets me fetch the source of an `HTML` page with               src=Import["http://area51.stackexchange.com/proposals/4470/martial-arts","Source"];      `src` now contains a string, which is the source code of the page. **What am I looking for?** The information that interests me is the value inside each of the blue squares, as well as its textual counterpart, namely _Needs Work_ , _Okay_ , or _Excellent_. ![enter image description here](http://i.stack.imgur.com/tncq6.png) I would use something like               StringCases[a,       RegularExpression[        "regex"] ->        "$1"]      to get the data I want, but unfortunately I don't know how to write regexes. _Side question_ : should I use _Mathematica_ 's string patterns, or `RegularExpression[]`? **The more general case** Once I can fetch the data above for one site, it's a piece of cake to get it for every proposal in beta. My goal is to be able to plot this data, to see how our site compares against the others concerning SE's top 5 health indicators.


Running a package automatically when it's saved

When developing some new code (eg. a function to analyse something) I usually make a .m and .nb file. The code goes in to .m is then called from the .nb. But sometimes I forget to run the package after saving and then spend some time wondering why my code changes don't have the desired effect. **Is there a way to run a package automatically after it's saved?** Basically I would like that when I press [Ctrl]+S the package is saved and that the effect of this button being pressed is achieved. ![Mathematica graphics](http://i.stack.imgur.com/JfnBt.png) Currently I put `Import["MyPackage.m"]` at the top of the evaluation cell I'm currently working on in the notebook. Perhaps I could also abuse $Pre for this, but then the package would get imported on every cell evaluation (which is a bit needles). **EDIT** Well, this is what I have so far based on Chirs's answer               FrontEndExecute[      FrontEnd`AddMenuCommands[       "Save", {Delimiter,         MenuItem["Save and Run &Package",          FrontEnd`KernelExecute[NotebookSave[SelectedNotebook[]];          If[FileExtension[NotebookFileName[SelectedNotebook[]]] ==             "m",(*then*)           Get[NotebookFileName[SelectedNotebook[]]];           ];          ], MenuKey["S", Modifiers -> {"Control"}],          System`MenuEvaluator -> Automatic]}]]


Use selfdefined ColorFunction to encode z dimension with predefined limits

In my last question we defined a colorfunction `cf`. Now I want to use this `ColorFunction` for a number of different plots (`MatrixPlot`, `BarChart3D`, `ListContourPlot` and `ListPlot3D`) as encoding for the `z` value from a given table. For the `ListContourPlot` and `BarChart3D` it seems to work, but I don't know how to apply the color encoding for the remaining plots. An another problem is the definition of a interval for the color encoding - here I mean that my data ranges from e.g. 0...30 , but i want to define a limit for the `ColorFunction` such that values are encoded from 10...20 according to the `ColorFunction`, values below 10 and over 30 should be clamped to the extrema of the `ColorFunction`. Is it possible to achieve something like that?! Thanks in advance!               dataResponse = {{1, 1, 3.}, {2, 1, 3.5}, {3, 1, 5.5}, {4, 1, 9.}, {5, 1, 13.}, {6, 1,        30.}, {1, 2, 3.5}, {2, 2, 5.5}, {3, 2, 7.5}, {4, 2, 8.5}, {5, 2,        15.}, {6, 2, 30.}, {1, 3, 4.}, {2, 3, 5.5}, {3, 3, 8.5}, {4, 3,        10.}, {5, 3, 20.5}, {6, 3, 30.}, {1, 4, 4.5}, {2, 4, 7.5}, {3, 4,        12.5}, {4, 4, 30.}, {5, 4, 30.}, {6, 4, 30.}, {1, 5, 5.}, {2, 5,        8.}, {3, 5, 14.5}, {4, 5, 30.}, {5, 5, 30.}, {6, 5, 30.}, {1, 6,        7.5}, {2, 6, 13.}, {3, 6, 30.}, {4, 6, 30.}, {5, 6, 30.}, {6, 6,        30.}}          cbData = {{215, 48, 39},{252, 141, 89},{254, 224, 144}, {224, 243, 248}, {145, 191, 219}, {69, 117, 180}}     cbData = Reverse[cbData]     With[{rgb = RGBColor @@@(cbData/255)},      cf = Blend[rgb, #]&;     ]          ListPlot3D[ dataResponse,                 Mesh -> All,                  ColorFunction -> cf,                 Boxed -> False,                 FaceGrids -> {                                 {Bottom,{Range[0,5,1],Range[0,5,1]}},                                 {Back,{Range[0,5,1],Range[0,30,5]}},                                 {Left,{Range[0,5,1],Range[0,30,5]}}},                 AspectRatio->1,                 AxesLabel -> {"Scene Complexity","Object Coherence","Response Time"},                 Ticks -> {  {{0,20},{1,30},{2,40},{3,50},{4,60},{5,70}}, {{0,0.045},{1,0.054},{2,0.063},{3,0.072},{4,0.081},{5,0.09}} ,Range[0,30,5]}                 ]      As you can see the resulting mesh is color-coded along the y axis, but I want to have the z-axis color encoded and in addition the values from 0...10 should have the same blue and values 20...30 should be red --> so that they are clamped ![Mesh](http://i.stack.imgur.com/uRfkZ.jpg)


Make further objects blurry?

I have the following function:               normalSpheres =       Table[Sphere[RandomVariate[NormalDistribution[0, 10], 3], .2], {500}];          Manipulate[      Graphics3D[normalSpheres, Background -> Black, ViewAngle -> 1,        ViewVector -> {{50 Sin[t], 50 Cos[t], 0}, {0, 0, 0}},        ImageSize -> Large], {t, 0, 2 Pi}]      ![enter image description here](http://i.stack.imgur.com/la3jJ.gif) I want to imbue this with a feeling of depth though. The best way I can think of is by creating a blur effect for each `Sphere` that increases the further away the object is from the `ViewPoint` (or `ViewVector[[1]]` in this case). Does anybody have any tips on how I could achieve this? P.S. sorry if the GIF makes anyone dizzy... Keyword: depth of field


Disable alert message with internet connectivity off

I work in an environment that has mathematica's internet connectivity turned off under Help > Internet Connectivity. Recently, after installing mathematica 10.0, every time mathematica is loaded it complains about internet connectivity and put up messages saying               PacletInstall::offline: The Wolfram System cannot install paclet WolframAutoUpdate because it is currently configured not to use the Internet for paclet downloads. To allow internet access, use Help > Internet Connectivity....      is there a way to disable such alerts/disable the auto update?


Setting parts of a list

Suppose I have list               a = Range[10]      > `{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}` in which I want to set some elements to be a list               a[[4 ;; 7]] = {1, 2, 3};       > `{1, 2, 3, {1, 2, 3}, {1, 2, 3}, {1, 2, 3}, {1, 2, 3}, 8, 9, 10}` Which is fine and dandy unless my part span is the same length as my list:               a[[4 ;; 6]] = {1, 2, 3};      > `{1, 2, 3, 1, 2, 3, 7, 8, 9, 10}` How can I force the assignment to behave consistently? In my case, I always want the first behaviour. But conceivably someone might always want the second behaviour with errors if the lengths don't match.


Nest , Fold ... is there an extension for more than 2 arguments?

Fold is an extension of Nest for 2 arguments. How does one extend this concept to multiple arguments. Here is a trivial example:               FoldList[#1 (1 + #2) &, 1000, {.01, .02, .03}]      Say I want do something like:               FoldList[#1(1+#2)-#3&,1000,{.01,.02,.03},{100,200,300}]       where 100,200,300 are the values for #3. I know Fold doesn't work this way. I'm looking for an approach that will work like this... ((1000*(1.01)-100)*1.02-200)*1.03-300). Is there a way to extend Fold to more than 2 arguments? or is there a better approach for solving problems like this?


Animating a 2D Plot as a 3D Plot

This is a follow up question to the original question: Original Question The accepted solution (provided by @Mark McClure) can also be found in the original question. It is as follows.               u[x_, t_] = -(1/2) Cos[x - t]^2 + 1;     pics = Table[Plot[u[x, t], {x, -10, 10}, PlotRange -> {0, 1.5},      PlotStyle -> {Red, Thickness[0.005]}], {t, 0, 2 Pi, 2 Pi/50}];       Then, export as follows:               Export["anim.gif", pics]      Is there a way of creating a 3D animation from the 2D animation? Something along the lines of the following: Example Thanks, Radz.


Exporting BarChart3D as PDF produces artefacts

So I think the following image already shows the problem, similar to Avoiding white lines inside filled area in RegionPlot exported as PDF or PS the pdf export of the chart creates thin lines in the plot. The fixing rule proposed in the related question seems not to work (sorry I am really new to mathematica). Disabling the Antialiasing doesnt improves the situation! ![BarChart3D](http://i.stack.imgur.com/7yv57.png)


How to group certain symbolic expressions?

For example, I have the following expression :               A( 2 x1 + B(y1 + y2) + 2 x2 )      How do I make the output look like this (grouping `(x1 + x2)` and `(y1 + y2)` terms together) ?               2A (x1 + x2) + A B (y1 + y2)      I don't know why `Simplify` doesn't group `(x1 + x2)` together but just gives:               A (2 x1 + 2 x2 + B (y1 + y2))      I can use `Collect` to get `(y1 + y2)` after `Simplify` but how about `(x1 + x2)` ? Remember this is just a simple example, I would have a much more complicated terms involving `(x1 + x2)` and `(y1 + y2)`, so a method with no operation on the constants (`2A` and `A B`) would be great.


What's wrong with the following Plot in Manipulate?

I try to show the convolution of a step function and a triangle function is smooth with the following code:               Manipulate[f0 = UnitBox[p - t0]; f1 = 2 UnitTriangle[t0];       f2 = Convolve[f0, f1, t0, t1];      Plot[{f0, f1, f2} /. {t0 -> x, t1 -> x}, {x, -3, 3}],      {{p, -2}, Locator}]      It should be something like this: ![The original PIC](http://i.stack.imgur.com/PnT9w.png) But after have a click to locate the Locator, it seems Mathematica have plot some "non-necessary" curves (I have marked by red cross): ![After cilck](http://i.stack.imgur.com/Q22of.png) How the get the right plot?


Plot the solution complex transcendental equation

I'm trying to plot an implicit function satisfying a complex transcendental equation. The code is the following:               ContourPlot[(e (-1 + e^2) l (-3 + 2 e^2 - l^2) Cosh[2 Sqrt[1 - e^2]] +        (-1 + e^2) (-1 + l^2) (e l Cos[2] - I (1 + l^2) Sin[2]) + Sqrt[1 - e^2]       (I - I l^4 - 2 e (-2 + e^2) l Sqrt[-e^2 + l^2]) Sinh[2 Sqrt[1 - e^2]]) == 0,        {l, 1, 2}, {e, -2, 2}]      I need a real solution of `e` as a function of `l` and also `e<=Min{1,l}`. I don't know why it's empty in the plot. I don't think it's because the solution is out of the range since I tried `l=1`, and there are several solutions, one of which is `e = 0`. Thus I think there must be something wrong with the plot.


Importing HDF5 with compound data

I am looking to `Import` HDF5 data with compound data. It appears, at least from what I read, that Mathematica 8.0.4 (and previous versions) does not support reading HDF5 with compound data.               file = "someData.h5";     Import[file, "Data"]     Import[file, {"Datasets", 1}]      Returns:               {{"Unsupported Datatype Class", "Compound"}, ... }     Import::h5type: "The datatype of the dataset "\foobar" is not currently supported. "      It has been a while, since Oct 2011 when Mathematica HDF5 and compound arrays was last updated. It was update with info about Scot Martin's HDF5 package. Unfortunately that package appears be a solution for Windows which uses two .Net dlls (hdf5dll.dll and HDF5DotNet.dll) and I have a Mac. Just wondering if there has been any progress? I have looked at using h5dump to create an ASCII file and writing an importer. However there is the overhead of writing the file, reading it, and then parsing it.