Choosing a branch of the square root when performing a series expansion

I have the following problem. Consider expression               f=Sqrt[(x-2y)^2]      There is an obvious ambiguity in the definition of `f` related to multivaluedness of the square root. Two possible interpretations for `f` are $x-2y$ or $2y-x$. My needs require to work with power series expansions of expressions like `f`. When asked to perform a series expansion _Mathematica_ automatically chooses a branch               In[106]:= Series[f, {x, 0, 1}, {y, 0, 1}] // Normal          Out[106]= -x + 2 y      I'm OK with that since I can adjust the sign of the square root manually and use `-f` instead of `f` if needed. The problem is that _Mathematica_ is not consistent in her choice. For example, evaluate               In[107]:= Series[f, {y, 0, 1}, {x, 0, 1}] // Normal          Out[107]= x - 2 y       now it's the other branch! In a real task I have a quite complicated function depending on many parameters under the square root. When I work with its series expansions naively, as described above, things just go wrong. How can the problem be handled? Any help is appreciated!


Does the operating system matter when using Encode[]?

I have a package I want to distribute. I wrote the package in Version 9 under a Mac OS X operating system. I want to `Encode[]` the package. The end user will run the package on a full Mathematica Version 9 license running on a Windows OS. As I don't have access to a Windows machine to test this I wondered if anyone knew whether Encode[] is operating system specific? Will a package encoded on OS X run on Windows?


Problems extending NelderMeadMinimize into 2D

**Update** The eventual route I followed was to adapt a version of the NM-simplex written in C and link to it with MathLink. Once I've tested this out fully I'll post it here. * * * I've been playing around with Oleksandr's compiled Nelder-Mead Minimization function presented here: Shaving the last 50 ms off NMinimize First, I'll create some sample data. This creates a noisy version of a Gaussian function.               gf1[x_] := 1/Sqrt[2 Pi 5^2] Exp[-((x - 25)^2/(2 5^2))];     addSomeGaussianNoise[x_, sig_] := Map[# + RandomVariate[         NormalDistribution[0., sig]] &, x, {1}];          interval = 0.01;     values = Range[0, 50, interval];     cleandata = gf1[#] & /@ values;     data = addSomeGaussianNoise[cleandata, 0.01];      ![enter image description here](http://i.stack.imgur.com/pYmk0.png) There are a few ways to minimise the model. I ran `NelderMeadMinimize` from the linked question:               fitter = Block[{data = #}, NelderMeadMinimize[Block[{x = values},            Norm[data - 1/Sqrt[2 Pi c^2] Exp[-((x - b)^2/(2 c^2))]]],           {b,c}]] &;     fitter2 = Block[{data = #}, NelderMeadMinimize[Block[{x = values},            EuclideanDistance[data, 1/Sqrt[2 Pi c^2] Exp[-((x - b)^2/(2 c^2))]]],           {b, c}]] &;     fitter3 = Block[{data = #}, NelderMeadMinimize[           Sqrt[Sum[             Abs[data[[x/interval + 1]] - 1/Sqrt[2 Pi c^2] Exp[-((x - b)^2/(2 c^2))]]^2,               {x,values}           ]],           {b, c}]] &;     fitter4 = With[{inter = interval, x = Range@Length[#]},          NelderMeadMinimize[           Sqrt[Total[             Abs[#[[x]] - 1/Sqrt[2 Pi c^2] Exp[-(((x - 1)*inter - b)^2/(2 c^2))]]^2]],            {b,c}]] &;          fits = fitter /@ {data} // AbsoluteTiming     (*{0.299809, {{0.712906, {b -> 24.985, c -> 5.0084}}}}*)          fits2 = fitter2 /@ {data} // AbsoluteTiming     (*{0.240542, {{0.712906, {b -> 24.985, c -> 5.0084}}}}*)          fits3 = fitter3 /@ {data} // AbsoluteTiming     (*{6.575716, {{0.712906, {b -> 24.985, c -> 5.0084}}}}*)          fits4 = fitter4 /@ {data} // AbsoluteTiming     (*{0.291925, {{0.712906, {b -> 24.985, c -> 5.0084}}}}*)      They all return the same result, but in varying times. Interestingly `EuclideanDistance` is slightly faster than `Norm`. Option 3 isn't well-written - Option 4 is better. Both 3 and 4 are the most obvious ones for me to choose to extend to a 2D (multivariate) Gaussian function, as I understand them better. Meanwhile, the first 2 options using `Norm` and `EuclideanDistance` are good, but don't allow for a different minimization function such as that in a question I asked recently. In that scenario I was happy using `NMinimize`, but now I'm looking to apply this alternative Nelder-Mead method to see what performance gains can be had. **My question is therefore:** _How can I get any of the options to work with 2D data rather than 1D data? i.e. fitting a Gaussian function in $x$ and $y$._ * * * Option 3/4 can be improved further, such that the fitting only takes 0.04 seconds, namely:               With[{        epsilon = $MachineEpsilon,        minimizer = NelderMeadMinimize`Dump`CompiledNelderMead[          Function[{b, c},           Block[{y = Range@Length[data]},            Sqrt[Total[              Abs[data[[y]] - 1/Sqrt[2 Pi c^2] Exp[-(((y - 1)*interval - b)^2/(2 c^2))]]^2]             ]]],{b, c},"ReturnValues" -> "AugmentedOptimizedParameters"]        },       serialFitter =          Compile[{{data, _Real, 1},{interval,_Real}},           minimizer[RandomReal[{0, 1}, {2 + 1, 2}], epsilon, -1],           CompilationOptions -> {"InlineCompiledFunctions" -> True},           RuntimeOptions -> {"Speed", "EvaluateSymbolically" -> False},           CompilationTarget -> "C"];       ];          serialFitter[data,interval] // AbsoluteTiming     (* {0.046861, {0.711633, 25.0001, 5.02656}} *)      * * * **Update #1** This creates the 2D data               gf[x_, y_] := 1/Sqrt[2 Pi 5^2] Exp[-((x - 25)^2/(2 5^2) + (y - 25)^2/(2 5^2))];     addSomeGaussianNoise[x_, sig_] :=             Map[# + RandomVariate[NormalDistribution[0., sig]] &, x, {2}];     interval = 1.;     cleandata = Table[gf[x, y], {x, 0, 50, interval}, {y, 0, 50, interval}];     data = addSomeGaussianNoise[cleandata, 0.01];      I then try and fit with this, where I've flattened the 2D data to a 1D vector prior to fitting.               fitter = Compile[{{data, _Real, 1}, {interval, _Real}},        NelderMeadMinimize`Dump`CompiledNelderMead[          Function[           {b, c, d},           Block[{x = Range@Length[data], n = Sqrt[Length[data]]},            Sqrt[             Total[              Abs[                data[[x]] -                  1/Sqrt[2 Pi c^2] Exp[-((Floor[Mod[x - 1, n]]*interval - b)^2/(2 c^2) +                     (Quotient[x - 1, n]*interval - d)^2/(2 c^2))]]^2]             ]            ]           ],          {b, c, d}, "ReturnValues" -> "AugmentedOptimizedParameters"]         [RandomReal[{0, 1}, {3 + 1, 3}], $MachineEpsilon, -1],        CompilationOptions -> {"InlineCompiledFunctions" -> True},         RuntimeOptions -> {"Speed", "EvaluateSymbolically" -> False},        CompilationTarget -> "C"];          fitter[Flatten[data], 1.] // AbsoluteTiming      However, I get errors: > CompiledFunction::cfte: Compiled expression > {0.874982,0.207452,-0.119287,0.635137} should be a rank 2 tensor of machine- > size real numbers. > > CompiledFunction::cfexe: Could not complete external evaluation; proceeding > with uncompiled evaluation. It's nearly there as a solution to my problem, but not quite! **Update #2** The first error (`cfte`) refers to the `"ReturnValues"` option - if I change it from `"AugmentedOptimizedParameters"` to `"OptimizedParameters"` the error now says > CompiledFunction::cfte: "Compiled expression {-0.053765,0.291736,0.432465} > should be a rank 2 tensor of machine-size real numbers. See how it's changed length? The function is expecting the return values to be a rank 2 tensor, but they're not...


Sometimes notation gets auto-converted from traditional to raw input and won't convert back

For example, I'm typing this: ![enter image description here](http://i.stack.imgur.com/JnIuX.png) When upon hitting the last character it gets converted to: ![enter image description here](http://i.stack.imgur.com/cOw3I.png) And trying to Convert To TraditionalForm has no effect. This glitch has happened a few times and on different characters each time. Is there a reason for this happening? **EDIT** \- By request from Mr. Wizard, here is the Cell Expression (and what was displayed) of the cell to which this just happened. **What was displayed:**               Subscript[     Overscript[u, .],        t] = \[DifferentialD]Subscript[u, t]/\[DifferentialD]t\[InvisibleComma],       where Subscript[u, \[Placeholder]]      **Cell Expression:**               Cell[TextData[Cell[BoxData[      FormBox[       RowBox[{        RowBox[{         RowBox[{"Subscript", "[", "\n",           RowBox[{           OverscriptBox["u",             StyleBox[".",             FontWeight->"Bold"]], ",", " ", "\n", "  ", "t"}], "]"}], " ",          "=", " ",          RowBox[{          RowBox[{"\[DifferentialD]",            RowBox[{"Subscript", "[",             RowBox[{"u", ",", " ", "t"}], "]"}]}], "/",           RowBox[{"\[DifferentialD]", "t"}]}]}], "\[InvisibleComma]",         RowBox[{",", " ", "\n", " ",          RowBox[{"where", " ",           SubscriptBox["u", "\[Placeholder]"]}]}]}], TraditionalForm]],      FormatType->"TraditionalForm"]], "Outline5",      CellChangeTimes->{{3.5589693713435035`*^9, 3.5589693812760715`*^9}, {        3.5589694358751945`*^9, 3.5589694980697517`*^9}, {        3.5589695385210657`*^9, 3.5589695520988417`*^9}, {        3.5589695873348575`*^9, 3.558969609079101*^9}, {        3.5589701806157913`*^9, 3.5589702522708893`*^9},         3.5589703063239813`*^9, {3.558990416805235*^9,         3.5589904721864023`*^9}}]


What should I call the messages that appear when the mouse moves over failed graphics output?

I attempted to evaluate the following               Plot[x^2, {x, 1, 2}, PlotStyle -> {RGBColor[a]}]      which, of course, failed. After the failure, putting my mouse over the graphics produced > RGBColor called with 1 argument; 3 or 4 arguments are expected. As far as I'm concerned, _Mathematica_ messages are in the syntax of `Symbol::Tag : Message`, yet these don't follow that format. I can also add the message to the Messages window by clicking on the red [+] at the top-right of the graphics cell. So what does _Mathematica_ call these messages and how are they generated?


How does DistanceFunction work with images in ClusteringComponents?

Does anyone know the syntax to `DistanceFunction`? I am trying to define my own function to use with `ClusteringComponents`; e.g.,               ClusteringComponents[img, DistanceFunction -> (Norm[#1 - #2] &)]      Needless to say it does not work as shown (it overflows for some reason). I also tried using `ImageData@img` but that does not even terminate.


How to add more levels to Outline notebooks

The Outline stylesheet only seems to cover 6 levels of depth. Is there any way to increase that? Here's an example. Hitting tab on the last level just indents its content, but doesn't add another level of depth. ![enter image description here](http://i.stack.imgur.com/17Shy.png)


Finding the best way to visualize rather complicated data

I have the following data               data = {{7.5, 12.45, 12.45, 12.75, 12.75, 12.25, 12.25, 12.53, 12.53},     {8.5, 12.22, 12.22, 12.23, 12.23, 13, 13, 12.54, 12.54},      {9.5, 11.58, 11.53, 12.75, 13.48, 12.39, 12.52, 12.17, 13.56},      {10.5, 11.76, 11.82, 12.97, 13.55, 12.15, 11.88, 13.07, 12.79},      {11.5, 11.18, 11.85, 13.27, 13.02, 12.32, 13, 12.72, 12.63},      {12.5, 11.04, 11.61, 13.70, 14.17, 12.77, 12.79, 12.13, 11.78},      {13.5, 11.64, 10.68, 13.52, 14.03, 13.14, 13.21, 11.64, 12.13},      {14.5, 12.04, 12.12, 13.23, 13.67, 12.58, 13.02, 11.26, 12.05},      {15.5, 14.10, 14, 11.65, 11.68, 12.17, 12.36, 12.19, 11.85},      {16.5, 14.85, 14.54, 10.94, 11.62, 12.17, 11.72, 11.84, 12.31},      {17.5, 15.78, 15.78, 10.62, 10.62, 11.72, 11.72, 11.88, 11.88},      {18.5, 17.18, 17.18, 9.53, 9.53, 11.66, 11.66, 11.63, 11.63}};      but I can't find a way to visualize them. Let me explain the structure of the data and also what I want to plot. `data` contains 12 sub-lists and each one contains 9 elements. The first element, let's say, is the x-coordinate and all the other eight represent percentages. I would like to plot these percentages with vertical lines (something like a histogram). So, at the axis there should be 7.5, 8.5, 9.5, ... , 18.5 and above of every number eight vertical lines (with different colors and indicators 1, 2, 3, ..., 8 if possible) of the corresponding percentages. Any ideas how to implement this? **EDIT** Following @Pinguin Dirk 's method I added some style options using               B0 = BarChart[Rest /@ data, Frame -> True,      FrameTicks -> {{True, False}, {False, False}},      FrameLabel -> {"h", "Percentage %"},      FrameStyle -> Directive[FontSize -> 18, FontFamily -> "Helvetica"],      ChartLabels -> {data[[All, 1]], None}, BarSpacing -> {1, 3},      ChartLegends -> Range[8], PlotRange -> {-1, 18}, ImageSize -> 550]      This is the output ![enter image description here](http://i.stack.imgur.com/kVpBX.jpg) Some minor issues: (a). How can we manipulate the size/fonts of the numbers at the horizontal axis (7.5, 8.5, etc)? (b). How can we manipulate the size/fonts of the chart's legends? Is there a way to increase the size of the squares or change the used colors?


Parsing subscripts when loading package files via the FrontEnd

I am working on some code, and have found it easier to use a _Mathematica_ package because   * it is easier to run via command-line (lightweight)   * it allows for easier source versioning (Git), and    * it allows me to use another text editor for indentation alignment (for me, the FrontEnd does not behave too well in this regard). I notice that it parses the package files and substitutes symbol escape sequences `\[MathSymbol]`, but it does not parse out subscripts. I can add subscripts in when editing via the FrontEnd, but once I save it and reload it, the subscripts are simply represented as `InputFormat[]`. I looked through the Option Inspector for parsing options and found the `DefaultPackageStyleDefinitions` at               $InstallationDirectory/SystemFiles/FrontEnd/StyleSheets/Package.nb


Having Problem with Importing Excel file to Mathematica Notebook?

I have solved some equations and exported the final results, which they are several Matrices, as a EXCEL file ( .Xls ). Now, I want to use these EXCEL files as my inputs to solve some other equations. I use `Import[]` to read these EXCEL files. But when I import them, these Matrices appears like this : `{"ÐÏ\.11à¡\[PlusMinus]"}` When I use `Import[exp,"Table"]` or `Import[exp,"List"]` the results are exactly same as previous one. I don't know what the problem is ?! This is part of the code :               AA = Import["C:\\Users\\Com\\Desktop\\EXCEL\\AA.Xls", "List"];          BB = Import["C:\\Users\\Com\\Desktop\\EXCEL\\BB.Xls", "List"];          CC = Import["C:\\Users\\Com\\Desktop\\EXCEL\\CC.Xls", "List"];          ssm = StateSpaceModel[{AA, BB, CC}]       The results : > >     During evaluation of In[8]:= StateSpaceModel::farg: > {{ÐÏ\.11à¡\[PlusMinus]}, >     {ÐÏ\.11à¡\[PlusMinus]},{ÐÏ\.11à¡\[PlusMinus]}} is not a valid > TransferFunctionModel >     or a list of state-space matrices in the form {a, b, ...}. >>` >   >     During evaluation of In[8]:= StateSpaceModel::farg: > {{ÐÏ\.11à¡\[PlusMinus]}, >     {ÐÏ\.11à¡\[PlusMinus]},{ÐÏ\.11à¡\[PlusMinus]}} is not a valid > TransferFunctionModel >     or a list of state-space matrices in the form {a, b, ...}. >> >   >     StateSpaceModel[{{"ÐÏ\.11à¡\[PlusMinus]"}, {"ÐÏ\.11à¡\\[PlusMinus]"}, >     {"ÐÏ\.11à¡\[PlusMinus]"}}]` >


How to disable half-hiding output, when the corresponding input cell is modified

I think it has become less easy to compare the new output, now that the output font color turns gray as soon as something is modified in the input cell. Is there any solution?


How to Clear variables with apostrophe?

An apostrophe `'` is often used when we want to distinguish two variables. For example, if we already have a variable `t` and we may want define another variable `t'`. What I found weird is that, in *Mathematica` it is legitimate to define a variable with apostrophe but it just can't clear a variable which has an apostrophe in the usual way. For example, if we write the following               t'=8      and `3t'` will correctly give `24` but `Clear[t']` will prompt an error says > Clear::ssym: t' is not a symbol or a string Can anyone help?


Manipulate in modal mode with data return

I like to use Manipulate[] in modal mode. That means the next cell should be evaluated **after** Manipulate[] has finished!


Looking for feedback on this function

I'm not sure this is an appropriate question; if not, I'm sure someone will close it :) I've got the following function, listed below; its job is to accept a graph (function) presented either as a single-variable function (e.g., `x^2`), or as a parametrized function (e.g. `{t Cos[t], t Sin[t]}`) and compute its curvature at some set of values of the variable:               SetAttributes[curvature,HoldAll];     SyntaxInformation[curvature]={"LocalVariables"->{"Table",{2,2}},         "ArgumentsPattern"->{_,_}};     curvature[f_, pts_] := Block[{extvar,var,fn,i,res},         extvar = ReleaseHold[Hold[pts]/.{x_,y__}:>HoldPattern[x]];         fn = ReleaseHold[Hold[f]/.extvar:>var];         If[!ListQ[fn], fn={var,fn}];         res = Table[1/Sqrt[Total[D[fn,var]^2]]/.var->i,                     Evaluate[Join[{i},Rest[pts]]]];         If[Length[res]==1,res=res[[1]]];res]      The second parameter is in "`Table`" form, and is interpreted as for `Table`. The first two lines of the function extract the formal variable used in `f` and substitute occurrences of it in `f` by a local variable. The third line converts a single-variable function to parametric form. The next line actually does the work, computing the relevant formula over the set of values defined by the second parameter. Finally, if the result is a singleton, it gets converted back to a scalar by the final line of the function. So for example               curvature[ x^2, {x,3} ]     {1/Sqrt[5], 1/Sqrt[17], 1/Sqrt[37]}      I'm looking for feedback on the way this function is written. For example (but not only), have I properly extracted the formal parameter (`x` in the example above) and the function? Is there a better way to evaluate the formula at the values specified by the second parameter? Finally, how about the manipulation in the last line? Any other feedback is welcome as well.


Simple manipulation of imported data

I am importing 2 columns of numeric data from a data file in the way defined in this answer:               data = Import["C:\\Users\\md\\Desktop\\myfile.txt", {"Data",  {All}, {1, 3}}];      These are my `x` and `y` values for a graph I'm plotting with `ListPlot`. But I also need to apply some simple manipulations to the `y` values (the second column), like multiplying by 2 or taking the absolute value. From the documentation I know it's possible by defining a function which takes a pair of values as arguments and then applying that function to `data` with `Map`, but that seems awfully troublesome when all I want is to multiply the `y` column by 2. Is there a quick and simple way to do that? _This could either be done while importing, after importing, or while plotting, either way is fine._   _I also don't care about which format I'm importing to, as long as it supports several thousand points._


Mathematica copies extra characters at the end of text blocks

This is something I've been noticing for some time, but I haven't found any mention of this online, so I'd like to know if it's been seen before, if it is a (known?) bug, and whether there exist workarounds. Mathematica (I've observed this in v10.0.0 and v9.0.1 over Ubuntu 14.04) tends to add extra characters at the tail end of copied text blocks, like               Integrate[Erf[a + b*x]/E^(p*x^2), {x, -Infinity, Infinity}]%@ð¿1¸7=&å -¾å0      where the `%@ð¿1¸7=&å -¾å0` (which typically starts with several invisible characters) gets tacked on to the end. To illustrate: ![enter image description here](http://i.stack.imgur.com/nlG6I.gif) The length of the added text roughly increases with the length of the copied text, though the neither the added text nor its length are consistent. Here are two addenda from immediate but separate copy-pastes of some longer text:               ð¿Û!¸7=&å`  Ð34P#è8`À8@Ã`x88bSeh1`vg=&E=1Oâ0K  1Why the Coloring?...±Ð34òæ8`À8@Ã          ÐAAä(Empty)@pPåÊAscrollbar_groove10000000000000000000000092000000200000000100000017000000-addpage¸7=&å¸7=&åH8=&å088=&å1÷î ò'1p®1Àn0      It is mostly gibberish but you do see some commands and context names in there. So: what is this text, and can one stop it appearing? (I'm submitting this as a bug report concurrently, and will update this if I receive a response.)


Mathematica 9: installation of "Extras" fails

I installed Mathematica 9 on my Windows 7 system (installed the font patch afterwards so the BSOD are gone) but the "Extras" package installation fails claiming it can't de-install the Mathematica 8 packages. I de-installed Mathematica 8 and tried re-installing Mathematica 9 again but it keeps claiming the Mathematica 8 add-ons can't be removed. At the end CDF (amongst other stuff?) is not working in the browser. Any thoughts?


How to access Mathematica license server (being outside of the local network)

This is no _Mathematica_ -language specific question but rather a network problem, so if this is the wrong place to ask, I apologize. I am running _Mathematica_ on Windows 7, the license manager `mathlm` is running in a local network. How can I access _Mathematica_ when being outside the local network. Is there some tool like license checkout for let's say two hours? If this is not possible with _Mathematica_ , is there some way to forward the ports for license manager via `ssh` and are there problems/restrictions with Windows 7? Btw, contacting the server via `ssh` is possible.


How is the dimensionality of an OpenCL problem specified?

When writing an OpenCL kernel, calls to `get_global_id()` are used to determine the "position" within the problem that a particular instance of the kernel is working on. However, I'm confused about how the dimensionality of a problem is specified or determined to begin with. I can write simple kernels that do the right thing, but I don't know _why_ they're doing the right thing! When moving to more complex kernels to do real work, I'm going to need to understand what's actually happening. Am I right in saying that if a kernel takes $n$ arguments that are qualified as `__global`, then I can call `get_global_id(0)`, …, `get_global_id(` $n-1$ `)`? Am I further correct in saying that each `__global` argument is treated as a one-dimensional array and that Mathematica runs one kernel (i.e., one OpenCL thread) for each element of the longest such array (but that I can specify the number of threads as the last argument to the Mathematica function created by `OpenCLFunctionLoad` if I want to control the dimensionality of the problem)? Assuming this, and $k$ threads, presumably values returned by `get_global_id(0)` will range from 0 to $k-1$; but if so, what values could `get_global_id(1)`, `get_global_id(2)`, etc. take? How can this be specified when running a kernel via the OpenCLLink Mathematica functions? Alternatively, does Mathematica look at the dimensionality of the largest `__global` argument, somehow pass this to the underlying OpenCL, such that `get_global_id(0)` return values that index the first dimension of this argument, `get_global_id(1)` return values that index the second dimension of this same argument, and so on? If this is the case, how do I specify the dimensionality of the problem when running a Mathematica function created by `OpenCLFunctionLoad`? So, in short, how is the dimensionality of a problem specified and what values can be taken by `get_global_id(`$i$`)`? Many thanks in advance.


Product of non-zero elements in sparse array

How can I multiply the non-zero elements of a `SparseArray`? Example:               a = SparseArray[{1 -> 1, 3 -> 2, 7 -> 3}]     Times @@ a (* this returns 0, but I need 6! *)


Defining five-parameter Pearson distribution by moments

How do you derive (or where can I find a derivation of) the equations to match the five parameters of a general Pearson distribution to a mean, variance, skewness, kurtosis, and condition that the function integrate to one? I have been using the method described in the Mathematica documentation under "Examples" and then "Applications". It provides the equations but no derivation. The four equations for the moments are set up as:               eq[r_] := r*Subscript[b, 0]*Moment[r - 1] + (r + 1) Subscript[b, 1]*Moment[r]      + (r + 2) Subscript[b, 2]*Moment[r + 1] - Subscript[a, 1]*Moment[r + 1]      - Subscript[a, 0]*Moment[r]      and               meq = Table[MomentConvert[eq[r], CentralMoment], {r, 0, 3}] /.          {Moment[1] -> μ, CentralMoment[2] -> σ^2, CentralMoment[3] -> Sqrt[Subscript[β, 1]] σ^3,              CentralMoment[4] -> Subscript[β, 2] σ^4}      These set up four linear equations in five unknowns. I am interested in the equation added to fix the normalizing coefficient (so the distribution integrates to one):               meq = Join[meq, {Subscript[a, 0] + (12 μ Subscript[β, 1] +         2 μ (9 - 5 Subscript[β, 2]) + σ Sqrt[Subscript[β, 1]] (3 + Subscript[β, 2]))}];      The equations for the moments themselves are pretty easy to derive, but I have not figured out the fifth equation for normalization.


boolean return value in mathematica

why does the following instruction ok in mathematica, and it returns a boolean value               In[398]:= catenary[x, 1, 0, 0] == catenary[-x, 1, 0, 0]     Out[398]:= True      and not this one?               In[406]:= catenary[-x, 1, 0, 0] == -catenary[x, 1, 0, 0]     Out[406]:= Cosh[x] == -Cosh[x]      I wanted to have a boolean value too.. to prove the symmetry.. Thanks for your help!


How can I manipulate with elements inside sublists if sublists of different lenght?

I have some kind of output like this: {{1, 5}, {1, 13}, {1, 5, 25}}. I would like to be able to enter in each sublist and make sums of every two elements in sublists, for example my desired output would be {{6}, {14}, {6, 30, 26}}. I can export these sublists in txt file, but I don't know if this is even necessary. Is this possible? Thank you very much on your help!


How to uncompress only the compressed elements in a matrix

I have data in a rectangular structure – something like `matrix={{a,b,c},{d,e,f},{g,h,i}}`. The problem is that some of the columns consist of uncompressed data and some not. Now I'm looking for an elegant way to uncompress the whole matrix. Unfortunately `Uncompress[matrix]` doesn't work.


How to get the new font in Mathematica 10?

Trying out Mathematica 10 and I still get the Courier font, not the new font shown in all of the examples on Wolfram's website. Anybody have any ideas how to get the new font working? Running on Mac OS X if that helps. I also deleted my entire Library/Mathematica folder, but that did not help.


Function that counts the number of arguments of other functions

I have a newbie question: is it possible to write a function that counts the arguments (total and optionals) of a given function? Possibly it should be able to work with built-in and custom functions as well. For example, if I define               f1[x_Integer] := x + 1;     f2[x_Integer, y_Integer: 1] := x + y;     g[x_Real, y_] := x - y;      I would like to have               countArgs[f1]     {1,0}     countArgs[f2]     {2,1}     countArgs[g]     {2,0}      and also, for example,               countArgs[Sin]     {1,0}      thank you. @celtschk Well, I didn't even know the use of UpValues, but basically what I am asking is the number of inputs the function needs, I don't care what the function does with those inputs. In your examples I would say   * {Infinity,0} for foo? It's more a question than an answer, sorry, but I had not thought aboute these unusual cases.   * this is nasty, I didn't think of a case like that either, I would say {3,{2}}, the {2} meaning exactly 2, to avoid bar[1,2], which is not legal.   * {2,0} but just because you wrote f[g,g], so it's practically a guess, I don't know what are UpValues and if they go against the spirit of my question by messing with the function. I hope I was clear.   * the last one I would say {3,0} as they were flattened. Thank you, I start seeing that my question is not so obvious because there are too many complicated definitions for functions to take into account. For now I understood that is possible with built-in functions with               SyntaxInformation[f]      (thank you Heike) but that mybe is a little too much asking for a general custom function.


How to align two overlayed plots, one being rotated?

I have two plots which I want to present on a single figure. ![enter image description here](http://i.stack.imgur.com/uq9k1.png) The bottom left corner is a point of origin of the first plot. The top right corner is a point of origin of the second plot. Also, the second plot's axes have reversed directions. That image presents those two plots - the rightmost function belongs to the second plot. I am using `Epilog->Inset[Rotate[plot2,180 Degree]]`. The result I posted was obtained after tweaking `ImageSize`, `ImagePadding`, `AspectRatio` and `Inset` coordinates with some arbitrary numbers. Is there a different, perhaps more elegant way? **edit** : Code snippet:               T = {{"100", 12.23, 2.675, 1}, {"140", 35.2, 3.5, 1.4}, {"180", 81.3,4.275, 1.9},           {"220", 162, 5.05, 2.4}, {"260", 288, 5.8,2.9}, {"300", 451, 6.4, 3.3},           {"340", 674, 7, 3.8}, {"360", 818,7.25, 4.1}, {"400", 1160, 7.825, 4.6}};          p1 = Plot[(Pi^2*205*10^9*T[[2, 2]]*10^(-8)/x^2)/1000, {x, 0, 10}, ImageSize -> 1000,            PlotRange -> {0, 3000}, ImagePadding -> {{6, 5}, {5, 6}}, AspectRatio -> 0.595];          Show[Table[{                 Plot[(Pi^2*205*10^9*T[[n, 2]]*10^(-8)/x^2)/1000, {x, 0,T[[n,3]]},                      PlotStyle -> {Thick}],                 Plot[(Pi^2*205*10^9*T[[n, 2]]*10^(-8)/x^2)/1000, {x, T[[n,3]],10},                      PlotStyle -> {Dashed}]}              , {n, Dimensions[T][[1]]}],          PlotRange -> {0, 3000}, GridLines -> {Range[0, 10, 1], Range[0, 3000, 100]},          GridLinesStyle -> Directive[GrayLevel[0.7], Dashed], ImageSize -> 1000,            ImagePadding -> {{6, 5}, {5, 6}},           Epilog -> {             Table[Inset[Framed[T[[n, 1]], RoundingRadius -> 10, Background -> White],                          {T[[n, 4]], 250*T[[n, 4]]}],                  {n,Dimensions[T][[1]]}],             Inset[Rotate[p1, 180 Degree], {5.01, 1490}]                     }          ]


Why do I keep getting 0.06 with WorkingPrecision->1?

I'm trying to generate a list of 1000 random numbers with WorkingPrecision->1. Is there any particular reason that I'm getting some entries as 0.06? I have tested the following lines:               X=RandomReal[UniformDistribution[],1000,WorkingPrecision->1]      or               X=RandomVariate[UniformDistribution[],1000,WorkingPrecision->1]      Is there a way to omit 0.06 and get true 1 precision, or am I missing something?


How to count number of observations/rows within each group

I have a huge unbalanced panel data. I want to count number of rows within each group. For example, I have the following data:               data ={{AA,1,10},{AA,2,20},{CC,3,30},{CC,4,40},{CC,5,50},{CC,6,60},{CC,7,70},{DD,8,80},                {DD,9,90},{DD,10,100}};      I want to calculate number of rows within each group without using do loop. My result should be               result={{AA,2},{CC,5},{DD,3}};      Any help is greatly appreciated.


Smoothing a function

NDsolve gives me a solution to a certain NL PDE. I want to evaluate the rate of exponential decay of the maxima of the solutions in time. So, I plot               Max1[t_?NumericQ] := First[Maximize[sol1[[1]][x, t], 0 <= x <= L, x]]     data1 = Table[{y, LMax1[y]}, {y, T0, Tfit}];     efit1 = FindFit[data1, Exp[a*t], {a}, t];     Plot[{Max1[y], Exp[efit1[1]*y]}, {y, T0, Tfit}, PlotRange -> All, Frame -> True]       and it looks like this: ![](http://i.stack.imgur.com/u3y75.jpg) Now, since I would like to fit this exponentially, or take the logarithm to evaluate the slope, how can I smooth that little jump which creates me a lot of trouble? Here is what I get if I take the Log:               LMax1[t_?NumericQ] := Log[Abs[First[Maximize[sol1[[1]][x, t], 0 <= x <= L, x]]] - 1]     data1 = Table[{y, LMax1[y]}, {y, T0, Tfit}];     fit1 = Fit[data1, {1, y}, y];     Plot[{LMax1[y], fit1}, {y, T0, Tfit}]      ![enter image description here](http://i.stack.imgur.com/UciNA.jpg)


Parsing a CSV file using Interpreter

The new `Interpreter` functionality in version 10 looks like it has the potential to make parsing custom data formats very easy. I'm trying to create a CSV parser. * * * **Requirements:**   1. Rows are delimited by newlines, columns are delimited by commas.   2. Entries can be numbers, strings (everything that's quoted or can't be interpreted as a number is a string).   3. Commas in quoted strings must be ignored.   4. Empty elements are allowed, e.g. this row contains three empty elements: `,,`. They're delimited by two commas. These can be parsed to either `Null` or `""`. My actual problem doesn't have requirement 3. I put in more requirements in the hopes to make the question more generally useful, and I meant to accept answers that satisfy only a subset of these. (Perhaps this was misguided.) In the meantime Carlo's answer explains that requirement 3. can't be met. **Test data:**               ,"one","2"     "a",1,2     "b",3,"4c"     "c",5,x     "d",6,"seven, eight"      Or ready to paste Mathematica string:               csv = ",\"one\",\"2\"\n\"a\",1,2\n\"b\",3,\"4c\"\n\"c\",5,x\n\"d\",6,\"seven,eight\""      **Parsed result should`MatchQ` this pattern:**               {{Null | "" | Missing[___], "one", "2"},       {"a", 1, 2},       {"b", 3, "4c"},       {"c", 5, "x"},       {"d", 6, "seven, eight"}}      How close can we get to this result, using `Interpreter`? * * * Here's a first try:               int = Interpreter[       DelimitedSequence[        DelimitedSequence[         Restricted["String", "\"" ~~ ___ ~~ "\""] | "Number" | "String",         ","         ],        "\n"        ]       ]          int[csv]      What it gets wrong:   * fails on point 4. (this is actually important for me)   * fails on point 3.   * doesn't unquote strings It may not be possible to implement all the features I request using `Interpreter`, but how close can we get? How much time and effort can `Interpreter` save when attacking this problem? Preferably it should be possible to offload most of the processing to interpreter and reach the desired result by adding minimal pre and/or post-processing.


Exporting data which includes rule as number only and use lhs as label

I use `listD1 = Table[FindRoot[(*my eqns depending on k*), {k, conc}]` to get a list of solutions for the different values of `conc = {0.03, 0.06, 0.1, 0.4, 1, 3}`. `listD1` has the form               {{s1 -> 0.000405499, s2 -> 0.000265293, s3 -> 0.000194383, V1 -> 0.019469, V2 -> 0.00823285, V0 -> 0.0366434, V3 -> 0., eef -> 0.715569},      {s1 -> 0.000974929, s2 -> 0.000464154, s3 -> 0.000291268, V1 -> 0.0319949, V2 -> 0.0123363, V0 -> 0.0732868, V3 -> 0., eef -> 0.704852},      {s1 -> 0.00186423, s2 -> 0.000654623, s3 -> 0.000365062, V1 -> 0.0431875, V2 -> 0.0154618, V0 -> 0.122145, V3 -> 0., eef -> 0.698868},      {s1 -> 0.00972514, s2 -> 0.00127244, s3 -> 0.000538089, V1 -> 0.0766826, V2 -> 0.0227901, V0 -> 0.488579, V3 -> 0., eef -> 0.688587},      {s1 -> 0.0182276, s2 -> 0.00154438, s3 -> 0.000595658, V1 -> 0.0906385, V2 -> 0.0252284, V0 -> 0.862647, V3 -> 0., eef -> 0.685893},      {s1 -> 0.0194252, s2 -> 0.00157279, s3 -> 0.000601234, V1 -> 0.0920781, V2 -> 0.0254645, V0 -> 0.914809, V3 -> 0., eef -> 0.685646}}      I tried to export `listD1` as `Export["file.txt", Transpose[Prepend[Transpose[listD1], conc]], "CSV"]` which gives me in principle the right output but contains the `s1->` etc. Is there an option to export without the `s1->` but instead use it in the first row as label? the output should be e.g.               conc, s1, s2, s3, .....     0.03, 0.000405499,  0.000265293, 0.000194383     0.06, 0.000974929,  0.000464154, 0.000291268     ...


Detecting operator Set in Assumptions

Here is a typical issue: `Simplify[x + y, x = y]` produces `2 True`. Is there a way to detect operator `Set` in assumptions and issue a warning? **Update:** As Mr.Wizard suggested it is possible to write a wrapper for `Simplify` that will check the second argument. But since there are many built-in functions which use assumptions it will be cumbersome to overload them all. Maybe there is a more simple way?


Counting the population of integers

Suppose that `myData` is a list of sublists. Each sublist has a length of one or greater and contains any number of replicates of the integers 1, 2, 3, and 4. I would like to create a function `myFun` that counts the number of each integer in the sublist. As an example, suppose that I have the following `myData`:               myData = {{2, 3, 3, 1, 1, 3, 2, 2, 4, 1, 1, 1, 2, 2, 2, 2, 2, 1, 1, 1},       {2, 2, 3, 1, 1, 3, 2, 2, 3, 1, 1, 1, 2, 2, 1, 2, 2, 1, 1, 1},       {1, 2, 2, 1, 1, 3, 2, 1, 3, 1, 1, 2, 2, 2, 2, 3, 1, 1},       {2, 3, 3, 1, 1, 2, 3, 2, 3, 1, 2, 1, 2, 1, 2, 2, 2, 1, 1, 1}};      I would like `myFun /@ myData` to return the output: > >     {{{1, 8}, {2, 8}, {3, 3}, {4, 1}}, >       {{1, 9}, {2, 8}, {3, 3}, {4, 0}}, >       {{1, 8}, {2, 7}, {3, 3}, {4, 0}}, >       {{1, 8}, {2, 8}, {3, 4}, {4, 0}}} >   In other words, sublist 1 has eight `1`s, eight `2`s, three `3`s, and one `4`, and similarly for the other three sublists. The key feature here is that all of `1`, `2`, `3`, and `4` are listed, even if one or more of them have zero population. Using the following (taking advantage of `Tally`) gets me close:               myFun[sublist_] := SortBy[Tally[sublist], First]     myFun /@ myData      > >     {{{1, 8}, {2, 8}, {3, 3}, {4, 1}}, >      {{1, 9}, {2, 8}, {3, 3}}, >      {{1, 8}, {2, 7}, {3, 3}}, >      {{1, 8}, {2, 8}, {3, 4}}} >   But `Tally` does not list members with zero population, so the above does not satisfy the key feature. On the other hand, the following (using `Count`) seems to accomplish my goal:               myFun[sublist_] := Map[{#, Count[sublist, #]} &, {1, 2, 3, 4}]     myFun /@ myData      > >     {{{1, 8}, {2, 8}, {3, 3}, {4, 1}}, >      {{1, 9}, {2, 8}, {3, 3}, {4, 0}}, >      {{1, 8}, {2, 7}, {3, 3}, {4, 0}}, >      {{1, 8}, {2, 8}, {3, 4}, {4, 0}}} >   But, is there a more succinct, more elegant way to do this? Thanks for your time!


Legends in a combined Plot and ListPlot

This question is related to the previously asked question Legends in combined Plot and ListPlot. Since _Mathematica_ 9 introduced new option `PlotLegends`, I was tempted to use built-in facility. (With the previous versions, I used the LevelScheme package). Consider a data set               A = {#, #^2} & /@ Range[100];     B = {#, #^1.8} & /@ Range[100];      and its theoretical prediction               A1 = x^2;     B1 = x^1.8;      I want to plot them together using `ListPlot` and `Plot`, respectively. And show them together with a single, combined legend. Also, I want to have user defined markers (e.g, filled-diamond, size = 15, joined -> false and so on) and set the style of the plot (e.g., Red, Thickness[0.01], Dashed and so on). I wonder if these requirements can be achieved by the built-in `PlotLegends` in _Mathematica_ 9. ### Edit The code below is what I tried, but I could not get the desired result.               MakeExponent[x_Integer] := "\*SuperscriptBox[10," <> ToString[x] <> "]"     tick = {10^#, MakeExponent[#]} & /@ Range[-10, 10, 1];          A = {1/#, #^2} & /@ Range[100];     B = {1/#, #^1.5 - 1} & /@ Range[100];     A1 = {1/#, #^2} & /@ Range[100];     B1 = {1/#, #^1.5 - 1} & /@ Range[100];     ALegend = Style[ "Legend A", 12, Black, FontFamily -> "Courier"];     BLegend = Style[ "Legend B", 12, Black, FontFamily -> "Helvetica"];     A1Legend = Style[ "Legend A1", 12, Black, FontFamily -> "Courier"];     B1Legend = Style[ "Legend B1", 12, Black, FontFamily -> "Courier"];     AMarker  = Style["\[FilledCircle]", 10, Orange];     BMarker  = Style["\[FilledDiamond]", 10, Purple];     A1Marker  = Style["\[LongDash]", 15, Blue];     B1Marker  = Graphics[Line[{{0, 0}, {1, 0}}]];     XLabel = Style[ Sqrt[x^2], 17];     YLabel = Style[t^2 , 17];      And then I tried               pic1 = ListLogLogPlot[ {A, B, A1, B1},       Axes -> False,       Frame -> True,       Joined -> {False, False, True, True},       PlotStyle -> {, , Blue, Red},       FrameLabel -> {XLabel, YLabel} ,       PlotMarkers -> {AMarker, BMarker, ,},       PlotLegends ->        Placed[         PointLegend[          {ALegend, BLegend, A1Legend, B1Legend},          LegendMarkers -> {AMarker, BMarker, A1Marker, B1Marker},          LegendMarkerSize -> {30, 10},          ], {0.8, 0.7}         ],       FrameTicks -> {{tick, None}, {tick, None}},       FrameTicksStyle -> 16     ]


NDSolve::ndcf: Repeated convergence test failure. How to solve?

I am trying to simulate a system of $n$ pendulums with some friction in _Mathematica_ 9\. This is the code I am using:               nPendulos = 3;     tiempoFinal = 20;     fps = 30;     g = 9.81;     r = 0.5;     x[0][t_] := 0     y[0][t_] := 0     CondicionesIniciales =                 Join[Table[x[n][0] == n, {n, 1, nPendulos}], Table[y[n]'[0] == 0, {n, 1, nPendulos}]];     Restricciones = Table[(x[n][t] - x[n-1][t])^2 + (y[n][t] - y[n - 1][t])^2 == 1, {n, 1, nPendulos}];     EqNewton = Join[Table[x[n]''[t] == λ[n][t]     (x[n][t] - x[n - 1][t]) -                            λ[n + 1][t] (x[n + 1][t] - x[n][t]) - r x[n]'[t], {n, 1, nPendulos - 1}],                     Table[y[n]''[t] == λ[n][ t] (y[n][t] - y[n - 1][t]) - λ[n + 1][t]                                        (y[n + 1][t] - y[n][t]) - g - r y[n]'[t], {n, 1, nPendulos - 1}],      {x[nPendulos]''[t] == λ[nPendulos][ t] (x[nPendulos][t] - x[nPendulos - 1][t]) - r x[nPendulos]'[t]},      {y[nPendulos]''[t] == λ[nPendulos][t] (y[nPendulos][t] - y[nPendulos - 1][t]) - g                           - r y[nPendulos]'[t]}];     Vars = Flatten@Table[{λ[n], x[n], y[n]}, {n, 1, nPendulos}];          Sol = NDSolve[{EqNewton, Restricciones, CondicionesIniciales}, Vars,                    {t, 0, tiempoFinal}, AccuracyGoal -> 2, PrecisionGoal -> 2, MaxStepSize -> 0.01,                    Method -> {"IndexReduction" -> {True, "ConstraintMethod" -> {"Projection",                                                      "Invariants" -> Restricciones}}}];      It works fine when the friction is high or `nPendulos` (number of pendulus) is low. But for example for `nPendulos = 4` and `r = 0.5` or `nPendulos = 3` and `r = 0.15`, I get things like               NDSolve::ndcf: Repeated convergence test failure at t == 0.93296875`; unable to continue.          NDSolve::ndsz: At t == 2.5562500630525498`, step size is effectively zero; singularity or stiff system suspected.      I am almost sure that the physics behind the system is right, because the results for example when `nPendulos = 2` or `3` are nice (see https://dl.dropboxusercontent.com/u/35192406/3_con_rozamiento.gif with friction or https://dl.dropboxusercontent.com/u/35192406/test2.gif with no friction) Why is `NDSolve` failing? How can I make it work?


Shortest polygonal path

I'd like to find the shortest distance between some points (every point must be visited), such as between these 3 points:                points = { {-0.9, -0.89}, {.99, .97}, {0.1, .0}}      I am sure there must be a built-in way of doing this automatically (or using _Combinatorica_ ), rather than calculating all the combinations manually. I had a quick play with:               FindShortestTour[points]      which returned: {5.30686, {1, 2, 3}} whereas the shortest path would be {1, 3, 2} and the Euclidean distance would be about 2, so I am clearly missing something basic ... probably related to graphs and how to set them up when the points are not on a grid?? In brief: is there an easy automated way to find the shortest distance between a set of given points? * * * **UPDATE** Since there doesn't seem to be a built-in form, I just had a quick go at doing one manually ... I only need it for small list size $n$, so I'm not too worried about checking all permutations etc.                PolygonPathMinDistance[points_] :=  Module[{orderings, pointorderings, pathsToCheck},            orderings = Union[Permutations[Range[Length[points]]],                          SameTest -> (#1 == Reverse[#2] &)];       pointorderings = Map[points[[#]] &, orderings];       pathsToCheck  = Map[Partition[#, 2, 1] &, pointorderings];       Min[Map[Total[Map[EuclideanDistance @@ # &, #1]] &, pathsToCheck]]      ]      Examples:                points = {{x1, y1}, {x2, y2}, {x3, y3}};      PolygonPathMinDistance[points]      ![](http://www.tri.org.au/se/PolygonPathMin3.png)                points = {{x1, y1}, {x2, y2}, {x3, y3}, {x4, y4}};      PolygonPathMinDistance[points]      ![](http://www.tri.org.au/se/PolygonPathMin4.png) Just comparing with the solution posted by ssch below, we have agreement for the 3 case:               points = {{-0.9, -0.89}, {.99, .97}, {0.1, .0}};     PolygonPathMinDistance[points]      > 2.65513 ... and we have agreement for a 4 part list:               points = {{-0.9, -0.89}, {.99, .97}, {0.1, .0}, {.7, -.1}}     PolygonPathMinDistance[points]      > 3.05557 and ssch gets (adding magicpoint is necessary):                mpoints = {{-0.9, -0.89}, {.99, .97}, {0.1, .0}, {.7, -.1}, magicPoint}      FindShortestTour[mpoints, DistanceFunction -> d]      > {3.05557, {1, 3, 4, 2, 5}} Cool - time for bed ... will follow up tomorrow. Many thanks! On the plus side, I am sure the ssch solution will be much faster ... but I assume it will be numeric (rather than symbolic).


Filter bright dots from the gradient of the image

I am wondering how to filter out bright dots in the picture, which are caused by background noise. I have used gradient filter in mathematica but it doesn't help. Is there anyway, that I can plot intensity versus background noise with threshold control or filter it in a better way. ![enter image description here](http://i.stack.imgur.com/YOfqP.png)


Covariance of a P x M x N matrix

I have a stack of tiff files. When imported to _Mathematica_ , they form a $P \times M \times N$ matrix, where $P$ is the number of single images in the stack, $M$ is the number of horizontal pixels and $N$ vertical pixels. I want to calculate the covariance of each vector $P_{mn}$ with the rest of the vectors, where $ m $ and $n$ go from 1 to $ M $ and $N$ respectively. In the end, I should have $M*N$ matrices with dimension $M \times N$. To get an idea of the data size, I will give some numbers $P\geq50 000$, $M=N=20$.


Get the current iteration count

I would like to be able to get the current iteration count, the one that if exceeds `$IterationLimit` makes the evaluation stop. After not finding a magical variable that stores this value, or a magical built-in that retrieves it, I thought about `TraceScan`. According to the documentation of `$IterationLimit`, > >     $IterationLimit gives an upper limit on the length of any list that can > be generated by Trace >   However, a quick test shows that this is not so simple. Let's define               ClearAll[f]     f[i_] := f[i - 1]     f[0] := "Yeah"      Now,               Block[{$IterationLimit = 20},      Trace[f[18]] // Length//Print;      Trace[f[18], TraceDepth -> 1] // Length//Print;      f[18]      ]      prints 56 and 38 respectively, while `f[18]`'s evaluation finishes successfully. Looking at the output of the last trace, we see that the before and after argument evaluation are being traced. So,               Trace[f[3], TraceDepth -> 1]        (* {f[3],f[3-1],f[2],f[2-1],f[1],f[1-1],f[0],Yeah} *)      Notice that the "two outputs per iteration" rule doesn't hold if we add a definition like `f[3]=f[1]`, in which case               Trace[f[5], TraceDepth -> 1]     (* {f[5],f[5-1],f[4],f[4-1],f[3],f[1],f[1-1],f[0],Yeah} *)      If this happened, a hacky workround could exist along the lines of               SetAttributes[trackIterations, HoldFirst];     trackIterations[code_] := Block[{iterationCounter = 0},       TraceScan[iterationCounter += 1/2, code, TraceDepth -> 1]       ]      **Question** How can I get that counter, or alternatively, how can I make `Trace` only trace once each iteration?


Buggy Reduce/Resolve function?

It seems to me that this is a clear-cut case of Mathematica actually producing the wrong answer (with no warnings). I'm trying to express the fact that for any integer, there exists a factorization (even if that factorization is just n = n * 1). But Mathematica says no. If I replace the domain with Reals or Complexes, then it says True. Is this a bug or am I using these functions incorrectly?               Resolve[ForAll[n, Exists[{p, q}, p*q == n]], Integers]          (*Out[1]= False*)          Reduce[ForAll[n, Exists[{p, q}, p*q == n]], {n, p, q}, Integers]          (*Out[2]= False*)


Defining commutation relations with Flat functions

Here is a minimal example of the problem I am having.               f[a___, b_, c_, d___] /; Not@OrderedQ[{b, c}] := h[b,c]f[a, c, b, d]     f[b, a, B, c, A]     SetAttributes[g, Flat]     g[a___, b_, c_, d___] /; Not@OrderedQ[{b, c}] := h[b,c]g[a, c, b, d]     g[b, a, B, c, A]      The `f` function works great. The `g` function goes into an infinite loop. How can I work around this problem? Perhaps an alternative to the `Flat` attribute or some other way of defining the commutation relation? By the way, I set the attribute `Flat` because `G[b, a, B, c, A]` is often built up as follows:               SetAttributes[G, Flat]     G[b, G[G[a, B, c], A]]      Thanks to @alephalpha for explaining what the problem is and suggesting the following fix. EDIT: ~~Actually the implementation below still runs an infinite loop on the second test cases below, independent of the order of definitions.~~ EDIT: found a fix for that loop.               (* Flatten g instead of declaring Flat attribute *)     (* The next line was a failed attempt and gets overwritten *)     g[a___, b_g, c___] := Flatten[g[a, b, c]]     (* This line works *)     g[a___, b_g, c___] := Module[{temp},       temp = Flatten[Hold@g[a, b, c], \[Infinity], g] // Release]     g[a___, b_, c_, d___] /; Not@OrderedQ[{b, c}] := h[b, c] g[a, c, b, d]     g[b, a, B, c, A]     g[b, g[g[a, B, c], A]]      I am not sure how this will affect the pattern matching of other definitions, so I will leave the question open to see what others come up with and possibly get a discussion of the pros and cons of `Flat` vs `Flatten`.


How can I save as PDF without file size getting too large?

> **Possible Duplicate:**   >  Graphics exported from Mathematica 9 are very large because even standard > fonts are embedded I have a text only notebook that I saved as PDF. The file size is 2.8 mb. The actual notebook is 12 kb. There are no graphics or special fonts. Is there a way to get a PDF file without the file size being so large?


findroot, derivative in defined functions

I apologize for my unclear question, I will write it in a more detailed way. I first define:               g[τ_, ϵ_] := c /. FindRoot[2.` c^4 - 1.6931471805599454` c^4 τ -      0.8611473146305157` τ^2 +      0.25` τ^2 Log[ϵ^(1/6)/c^(       2/3)] + (1.` c^4 +         0.6732867951399863` τ) τ Log[τ] -      0.125` τ^2 Log[τ]^2 -      0.25` τ^2 Log[-0.6931471805599453` + Log[τ]], {c, 1000}]      The function I am trying to solve is as follows: ![!\[I am still learning how to type equations here, in order not to cause to many problems for you guys to read. I use picture to express my equtions](http://i.stack.imgur.com/R8m51.gif) ]1 I can plot $\zeta_2 (r)$ in the region $1<r<\tau/2$ for different values of $a, \tau, \epsilon$, where $a>0$, $\tau>2$, $10^{-7}<\epsilon<10^{-2}$. what I need to do is to find the smallest value of r satisfying $\zeta_2(r)=0$. I use Findroot to do it. but it does not work well all the way through the parameter region. The second question is that supposing we find the smallest value of $r$, which is $h[a,\tau,\epsilon]$, I need to do a integration, which is defined as:               w[a_, τ_, ϵ_] := Integrate[Evaluate[{Subscript[ζ, 2][r]^2} /. f[a, τ, ϵ]], {r, 1, h[a,τ, ϵ]}]      As a test, I choose $a=1, \tau=5, \epsilon=10^{-6}, h(a,\tau,\epsilon)=1.2$, but $w(1,5,10^{-6})$ does not return me a number. So how should I define $w$ to get a number? The last question is if I have got the right definition of $w$, set the derivative $D[w,{a,1}]=0$, and find $a$ in terms of $\tau, \epsilon$. I am getting stocked by doing the derivative of functions. Thanks very much. By the way, I hope this time that Mr.Wizard won't wasting time on revising my writing. I am really sorry


Remove anything between () except for ; in a string

A simple question but I can't find the answer. I'm scanning a huge pile of mails and would like to get rid of anything between () in the email adresses since this normally contains just info that varies over time. As a delimiter I use the ; between the email addresses. So this is basically the only character not allowed between ().               tst = "James, Jekyll (The.nice.guy@gmails.com \n); Hannibal, Hyde (from@hell ...)"      Obviously this doesn't work.               StringReplace[tst, "(" ~~ __ ... ~~ ")" -> ""]      It only leaves me James, Jekyll So I assume I need a pattern like "("~~Anything Except ";"~~")" but how?               StringReplace[tst,"(" ~~ (DigitCharacter|WordCharacter|WhitespaceCharacter|"@"|"!"|".") ... ~~ ")" -> ""]      Will work but then to be safe I would need to get all characters in the ( | | etc) construct at seams unefficient. Any thougths?


Use ColorFunction in ListLinePlot with If

The following code               ListLinePlot[{2, 4, 6, 8, 10, 12},       ColorFunction -> Function[{x, y}, If[x <= 3, Blue, Red]]]      should produce blue lines for $x\le3$ and red lines for $x\ge3$. But instead, the plot contains only blue lines. Where are my red lines?


How to remove duplicate characters from a string?

How do you remove duplicate characters in a string **without converting the string to a list**. I want to delete all duplicate characters in a string (i.e. get the unsorted union of characters). For example string like `"113233454766"` should give me string `"1324576"`. Note order. I tried this:                StringReplace["113233454766", a___ ~~ x_ ~~ b___ ~~ x_ ~~ c___ :> a ~~ x ~~ b ~~ c]      But it won't give me answer. I think I'm not fully understand about pattern.


ParametricPlot3D Question

When I graph:               ParametricPlot3D[       If[11*Cos[t] <= 5,          {9*Cos[s]*Sin[t], 10*Sin[s]*Sin[t],          11*Cos[t]}, Null],      {s, 0, 2*Pi}, {t, 0, Pi}]      I get ![http://i.stack.imgur.com/Ug5HR.gif](http://i.stack.imgur.com/Ug5HR.gif) but I want to get: ![enter image description here](http://i.stack.imgur.com/BSMlR.gif) Why does my code generate those spike and etches on top of the partially cut ellipsoid, instead of giving a smooth top like the second picture?


How do I simplify expressions with square roots?

I want $\left\\{\frac{1}{1+\sqrt{2}-\sqrt{3}},\sqrt{5-2 \sqrt{6}},\sqrt{4+\sqrt{15}}\right\\}$ to be simplified to $\left\\{\frac{1}{4} \left(2+\sqrt{2}+\sqrt{6}\right), \sqrt{3}-\sqrt{2}, \frac{1}{2} \left(\sqrt{6}+\sqrt{10}\right)\right\\}$ But I haven't been able to get that result with Mathematica. How could I get it?


I am using Mathematica 8.0.4.0 running under Windows 7. Is there a way to programmatically do a "save as " on an init.nb file to save it as init.m? In the documentation center under tutorial/FrontEndTokens I found               FrontEndExecute[{FrontEndToken[FrontEnd`InputNotebook[],"SaveRenameSpecial", "Text"]}]      but it doesn't seem to work? I am looking for a working variation of this where "Text" is replaced by "Package" or somesuch. Thanks for your help.


How to produce multiple plots from a multiple data sets

I have a number of lists and want to plot all of them vs each other. E.g.:               l={     {a,2,5,4,6},     {b,4,6,6,2},     {c,2,8,3,5},     {d,1,5,2,5}     }      Now I want multiple plots with a vs b a vs c a vs d b vs c etc. I know there is a function in Mathematica, which does exactly this – because I have used it before. Unfortunately I can't remember the function name and didn't find it in the help menu or here after extensive searching. So I hope someone can remind me of the function name – which I will immediately write down and never forget!


Hovering mouse cursor over a plot to display a "corresponding" point in another plot

_(Apologies for not having gotten around to responding to and accepting answers on my other recent questions --as a meticulous and thorough type, I'd like to take my time to fully comprehend and play with all answers before responding. I'll definitely follow up.)_ I'm trying to reproduce a variant of this view, where hovering the mouse over a point highlights its "corresponding" point on all plots: ![Google Finance page for AAPL, with a volume chart and the "Slow Stochastic Oscillator"](http://i.stack.imgur.com/UEnRA.png) In my case, the additional complexion is that the x-axes are not the same ( _i.e._ they're not all time), though they do all increase monotonically. I'm in the process of reading, experimenting, and further exploring based on comments on these threads:   * Display function value on hover?   * Display position information out of ListPlots inside a Manipulate   * Extracting the coordinate of a particular point of interest from a ListPlot   * Items known by CurrentValue   * How to manipulate 2D plots?   * Dynamically updating interactive objects in Mathematica   * Adding custom GridLines to the "automatic" ones However, I've yet to understand (though perhaps the answer may be in one of those threads) how one would affect a plot based on an event triggered on another plot. Any pointers would be greatly appreciated. I'll post my solution when I figure it out, though I'm sure it won't be the best one could do, as I'm still new to Mathematica. * * * After @ssch's answer was posted, I realized I left out some critical details/clarifications. First, I'm working with discreet data, _i.e._ two `ListPlot`s. That doesn't seem to matter, though. @ssch's example worked for me, using `ListPlot`. Second, and more importantly, the two x-axes are _not_ linear images-- _i.e._they do _not_ increase uniformly. For example: ![Non-uniform example](http://i.stack.imgur.com/Ucuz4.png) The above plots graph the same y-axes, but based on different x-axes. (The dotted gray lines correspond, so one can see how certain areas are "stretched" or "compressed" in the second graph.) Is there a way to get a corresponding cursor in such a case?


Building a molecule viewer: aesthetic rotations

I am working on building a molecule viewer in _Mathematica_ and am running in to problems with controlling rotation of the molecule (which is rendered as a `Graphics3D` object). I apologize in advance for the lengthy code used to build the sample molecule; however the form of the graphics object is representative of real molecule objects generated by my molecule viewer package. I've moved this code to the end of the question so it hopefully does not distract from the real question. Ultimately, I would like to be able to use the mouse or controllers to adjust the orientation of a 3D object. Then I would like to be able to rotate that object around the vertical axis. The animated gif below demonstrates the rotation: ![rotating molecule](http://i.stack.imgur.com/sVSxS.gif) I have started from the following point:               Manipulate[      Graphics3D[{        Specularity[GrayLevel[1], 100], gr        },       Boxed -> False,       Lighting -> "Neutral",       SphericalRegion -> True, Background -> Black,        ViewVertical -> {Cos[a], 0, Sin[a]}], {a, 0, 4 Pi}]      which demonstrates two problems:   1. Clearly, the rotation is out of the viewing plane, and unless I've missed it, no permutation of the `ViewVertical` values gives me the desired rotation axis.    2. When the graphic is altered using the mouse, changing the slider no longer changes the graphic. Next, I tried using `ViewVector`. I thought about being smart (no claims that I actually was) and noticed:               ParametricPlot3D[{Cos[a], Sin[a], 1}, {a, 0, 4 Pi}]      should give me the appropriate rotation: ![rotation plot](http://i.stack.imgur.com/HYZyk.png) Using               Manipulate[      Graphics3D[{        Specularity[GrayLevel[1], 100], gr        },       Boxed -> False,       Lighting -> "Neutral",       SphericalRegion -> True, Background -> Black,        ViewVector -> 1000 {Cos[a], Sin[a], 1}], {a, 0, 4 Pi}]      comes close to the rotation I'm looking for and it doesn't seem to be affected by problem (2) above. However when I do move the graphic with the mouse, the rotation axis changes in a way that makes no sense to me. I suspect my code needs to capture the current `ViewVector` and perform a rotation based on that information; however I'm having a hard enough time grasping the various `View*` options in `Graphics3D` that I can't begin to formulate that level of dynamic interactivity. ## Update Since posting this question and reviewing this reference which was provided in the comments I am able to rotate the camera which provides a decent means to view the molecule. As alluded to in one of the possible answers, rotating the molecule as opposed to rotating the viewpoint may be a better approach. (I put this code here only because I was stumped by the conditional that is needed for `ViewVertical`, preventing the molecule from jumping.)               Manipulate[       Graphics3D[{Specularity[GrayLevel[1], 100], gr}, Boxed -> False,        Lighting -> "Neutral",       ViewPoint -> 2 {Sin[a] Sin[b], Cos[a] Sin[b], Cos[b]},        ViewCenter -> Automatic,        ViewVertical -> If[b > 0, {0, 0, 1}, {0, 0, -1}], ViewRange -> All,        ViewAngle -> All, SphericalRegion -> True,        Background -> Black], {{a, 0}, 0, 4 Pi}, {{b, .01}, -Pi, Pi}]      ## The molecule {and a caveat for all the chemists out there - this is **not** a real molecule}               gr = GraphicsGroup[{EdgeForm[None],        GraphicsComplex[{{-7.53741, 11.3862, 4.91147}, {146.654, 5.10132,           2.65685}, {200.92, 7.38748, 138.895}, {199.898,           116.382, -68.4703}, {188.424, -110.427, -58.9037}}, {{{RGBColor[            0.4, 0.4, 0.4], Sphere[1, 34]}, {RGBColor[0.4, 0.4, 0.4],            Sphere[2, 34]}, {RGBColor[0.29, 0.44, 0.89],            Sphere[3, 32]}, {RGBColor[0.8, 0.2, 0.2],            Sphere[4, 31]}, {RGBColor[0.58, 0.86, 0.41], Sphere[5, 30]}}}],        GraphicsComplex[{{-7.53741, 11.3862, 4.91147}, {146.654, 5.10132,           2.65685}, {146.654, 5.10132, 2.65685}, {146.654, 5.10132,           2.65685}, {69.5583, 8.24374, 3.78416}, {173.787, 6.2444,           70.7759}, {173.276,           60.7416, -32.9067}, {167.539, -52.6626, -28.1234}}, {{RGBColor[           0.4, 0.4,            0.4], {GeometricTransformation[            Cylinder[{1, 5},              10], {{{1., 0., 0.}, {0., 1., 0.}, {0., 0., 1.}}, {0.0418653,               5.9645, -13.7631}}],            GeometricTransformation[            Cylinder[{1, 5},              10], {{{1., 0., 0.}, {0., 1., 0.}, {0., 0.,                1.}}, {-0.0418653, -5.9645, 13.7631}}]},           RGBColor[0.4, 0.4,            0.4], {GeometricTransformation[            Cylinder[{2, 6},              10], {{{1., 0., 0.}, {0., 1., 0.}, {0., 0., 1.}}, {0., 0.,               0.}}]}, RGBColor[0.4, 0.4,            0.4], {GeometricTransformation[            Cylinder[{3, 7},              10], {{{1., 0., 0.}, {0., 1., 0.}, {0., 0., 1.}}, {0., 0.,               0.}}]}, RGBColor[0.4, 0.4,            0.4], {GeometricTransformation[            Cylinder[{4, 8},              10], {{{1., 0., 0.}, {0., 1., 0.}, {0., 0., 1.}}, {0., 0.,               0.}}]}}}],        GraphicsComplex[{{146.654, 5.10132, 2.65685}, {200.92, 7.38748,           138.895}, {199.898,           116.382, -68.4703}, {188.424, -110.427, -58.9037}, {69.5583,           8.24374, 3.78416}, {173.787, 6.2444, 70.7759}, {173.276,           60.7416, -32.9067}, {167.539, -52.6626, -28.1234}}, {{RGBColor[           0.4, 0.4,            0.4], {GeometricTransformation[            Cylinder[{1, 5},              10], {{{1., 0., 0.}, {0., 1., 0.}, {0., 0.,                1.}}, {-0.0418653, -5.9645, 13.7631}}],            GeometricTransformation[            Cylinder[{1, 5},              10], {{{1., 0., 0.}, {0., 1., 0.}, {0., 0., 1.}}, {0.0418653,               5.9645, -13.7631}}]},           RGBColor[0.29, 0.44,            0.89], {GeometricTransformation[            Cylinder[{2, 6},              10], {{{1., 0., 0.}, {0., 1., 0.}, {0., 0., 1.}}, {0., 0.,               0.}}]}, RGBColor[0.8, 0.2,            0.2], {GeometricTransformation[            Cylinder[{3, 7},              10], {{{1., 0., 0.}, {0., 1., 0.}, {0., 0., 1.}}, {0., 0.,               0.}}]}, RGBColor[0.58, 0.86,            0.41], {GeometricTransformation[            Cylinder[{4, 8},              10], {{{1., 0., 0.}, {0., 1., 0.}, {0., 0., 1.}}, {0., 0.,               0.}}]}}}], Null, Null}]


How do I replace a missing value in a column with the value immediately above throughout a table?

I have a large table (7000 rows × 17 columns) of terse textual data. In many of the columns, empty entries have been replaced with "." as a marker. Working from the top of the columns downward, I want to replace each successive "." with the data value (non-".") from above until the next data value is found; at which time I want to replace the next sequence of "." with the new data value etc. E.g.               x     -->  x       "."   -->  x       y     -->  y       "."   -->  y       "."   -->  y       z     -->  z       "."   -->  z        I need to do this for all rows of data. Any help would be greatly appreciated. -k-


xkcd: Geohashing in Mathematica

On May 21, 2008, an xkcd comic proposed a method for creating a random, local meeting place that can't be determined until the day of the meeting. ![Geohashing comic](http://i.stack.imgur.com/PYW6d.png) This method is usually used for xkcd fan events, but can also be a fun way to create a random adventure (kinda like Geocaching without the cache.) More info about the specifics can be found on the Geohashing Wiki. Since the random part of the hash is created from the Dow Jones Industrial Average, I thought it would be a fun algorithm to implement in _Mathematica_. I also wanted to create an excuse to learn about the Google Maps API and processing JSON data in general. Given only a user's "home" coordinates, how would one compute the Geohash location in _Mathematica_?


How to change coordinates of integration?

Is there some built-in routine, some easier method to change variables of integration, without/before solving the integral? Say I have               Integrate[expression1[x, y, z], x, y, z]      how to change it to               Integrate[expression2[r, theta, phi], r, theta, phi]


Can I return lists with different dimensions from a compiled function?

Sometimes I'll need several lists with different dimensions to be returned by a compiled function, but compiled function will fail if an irregular list contained:               (* The real case is of course much more complex. *)     a1 = ConstantArray[0., {10}];     a2 = ConstantArray[0., {9}];     Compile[{},        (* for the real case, a lot of low level calculations will be done on a1 and a2 here *)                {a1, a2}][]      > CompiledFunction::cflist: Nontensor object generated; proceeding with > uncompiled evaluation. >> A possible (and maybe the simplest) work around is to add some extra elements to the lists and delete them(or just ignore them) later:               a1 = ConstantArray[0., {10}];     a2 = ConstantArray[0., {10}];     Delete[Compile[{}, {a1, a2}][], {2, -1}]      But it's a waste of memory (especially when lists are big and have higher dimensions). So I wonder if other solution exists? Of course that solution should work on high dimensional lists like:               a1 = ConstantArray[0., {300, 299, 300}];     a2 = ConstantArray[0., {299, 300, 299}];      * * * To avoid possible confusion I'd like to add a more specific example:               ie = 200;     ez = ConstantArray[0., {ie + 1}];     hy = ConstantArray[0., {ie}];          (* Notice the following function hasn't been fixed yet *)     fdtd1d = Compile[{{steps}},         Module[{ie = ie, ez = ez, hy = hy},          Do[          ez[[2 ;; ie]] = ez[[2 ;; ie]] + (hy[[2 ;; ie]] - hy[[1 ;; ie - 1]]);           ez[[1]] = Sin[n/10];           hy[[1 ;; ie]] = hy[[1 ;; ie]] + (ez[[2 ;; ie + 1]] - ez[[1 ;; ie]]),            {n, steps}];          {ez, hy}]];          fdtd1d[1000]      * * * Er… maybe I should add one more multidimensional sample?:               ie = 100; je = 100;     c = 1/Sqrt[2];     ez = ConstantArray[0., {ie + 1, je + 1}];     hx = ConstantArray[0., {ie + 1, je}];     hy = ConstantArray[0., {ie, je + 1}];          (* Notice the following function hasn't been fixed yet *)     fdtd2d = Compile[{{steps}},         Module[{ez = ez, hx = hx, hy = hy, ie = ie, je = je, c = c},         Do[          ez[[2 ;; ie, 2 ;; je]] +=            c (hx[[2 ;; ie, 1 ;; je - 1]] - hx[[2 ;; ie, 2 ;; je]] +               hy[[2 ;; ie, 2 ;; je]] - hy[[1 ;; ie - 1, 2 ;; je]]);          ez[[Floor[ie/2], Floor[je/2]]] = Sin[n/10];          hx += c (ez[[All, 1 ;; je]] - ez[[All, 2 ;; je + 1]]);          hy += c (ez[[2 ;; ie + 1, All]] - ez[[1 ;; ie, All]]),          {n, steps}];         {ez, hx, hy}]];          AbsoluteTiming[dat = fdtd2d[1000];]     ArrayPlot /@ {ez2, hx2, hy2}


How to generate Koch curve in mathematica

How is done in Mathematica to generate the curve? Exists in the fractal geometry Koch curve, consisting of partitioning a line segment of lngitud 1 in three equal parts, by removing the central part and replaced by an isosceles triangle whose sides are the same length as the length of the extracted segment.


Different delays in notebook and command-line?

I was surprised by the following sequence of expressions:               Remove[foo$, bar$];     foo$ = Function[Set[bar$, 42]];      At this point, I expected `foo$` to be defined and `bar$` _not_ to be defined, because I had not called the function named `foo$` yet. Indeed, the notebook interface shows `bar$` in blue (undefined) and `foo$` in black (defined). However, bad news, `bar$` has a value:               foo$     (* (bar$ = 42) & *)     bar$     (* 42 *)      Running the command-line version of Mathematica produces different results:               Remove[foo$, bar$]     foo$ = Function[bar$ = 42];     foo$     (* (bar$ = 42) & *)     bar$     (* bar$ *)      The following does not help; in the notebook:               Remove[foo$, bar$]     bar$     (* bar$ *)     foo$ = Function[SetDelayed[bar$, 42]]     (* (bar$ := 42) & *)     bar$     (* 42 *)      and in the command-line:               Remove[foo$, bar$]     foo$ = Function[SetDelayed[bar$, 42]]     (* (bar$ := 42) & *)     bar$     (* bar$ *)      I found only the following to work, but it's unacceptable because I want a functional way to delay and to force evaluation, that is, a method that uses the construction and calling of functions: In the notebook:               Remove[foo$, bar$]     foo$ = Hold[Set[bar$, 42]]     (* Hold[bar$ = 42] *)     bar$     (* bar$ *)     ReleaseHold[foo$]     (* 42 *)     bar$     (* 42 *)      and identical results in the command-line.


Exporting twice crashes Mathematica on Ubuntu 12.04 with Unity

I'm trying to work out if it's a Mathematica, Ubuntu or setup specific bug. I've asked some colleagues to try it on other Linuxes. This also crashes on OS X with Mathematica 8.0 and fails with 9.0, so it looks like it could be a Mathematica bug (output on request). It may be an artefact of running on the CLI (my tests on 9.0 so far have had to be via ssh), though the full 8.0 .app crashes, too. Warning: it may suddenly end your session, so close all other programs and save your work, etc, first. logMeOut.m               p = ListDensityPlot[Table[RandomReal[], {i, 1, 128}, {j, 1, 128}]];     Export["myPlot.jpg", p, ImageSize -> Scaled[2]]     Export["myPlot.jpg", p, ImageSize -> Scaled[2]]      run it with               $ /path/to/MathKernel -noprompt -script logMeOut.m      Interestingly, when I run either of               $ strace -f /path/to/MathKernel -noprompt -script logMeOut.m &> mathematicabug.strace      (output on request) or               $ /path/to/MathKernel -noprompt -script logMeOut.m &> mathematicabug.log      I don't get logged out. The second gives no output. Per the strace, the library accessed before the crash (it still seg faults) is terminfo (/lib/x86_64-linux-gnu/libtinfo.so.5), so given the above suppresses output, it may be related to that. Any ideas from a Mathematica rather than system perspective why it doesn't work? System perspectives are also welcome, though maybe don't go here.


Why isn't Simplify doing more simplification of this expression?

When I try this               Simplify[(1-a)*(1/(1+x*m))^(1-a)(1+m)^(1-a) +               (1-a)*(x*m)^a*((x*m)/(1+x*m))^(1-a)*(1+m)^(1-a)]      the output is $$\frac{(1-a) (1+m)^{1-a} \left(\left(\frac{1}{1+m x}\right)^{-a}+m x (m x)^a \left(\frac{m x}{1+m x}\right)^{-a}\right)}{1+m x}$$ But a little hand-done algebra shows this reduces to $(1-a) (1+m)^{1-a} (1+mx)^a$. I tried `FullSimplify` but get the same results. Is there something I can do to get Mathematica find this simpler form?


Can Mathematica check spelling during typing?

I can't see a way to get _Mathematica_ to check my spelling as I type. Is this feature not supported? I've done everything I can think of with my options: ![enter image description here](http://i.stack.imgur.com/ChpSc.png) Is there a setting I'm missing?


How do I change a ColorFunction filling to be top-down as opposed to left-right?

I've been stuck on a seemingly simple Graphics issue for quite a while now... I am trying to make a temperature distribution Plot that will have a colorFunction filling to show red when at a higher temperature, then fading to blue as it gets colder, etc. My plot has temperature in the y-axis, and length (of a fin) in the x-axis. When I try to put it into effect, the filling is filled with the gradient but it goes from left to right, along the x-axis. However, I want it to be fading top to bottom, to illustrate how the temperature decreases. One of my cells of test code is included below:                   Manipulate[      Plot[T[x, length, h, P, A, k, Tinf, T0], {x, 0, length},       ColorFunction ->         Function[{x, T},          Directive[          Opacity[0.7], (ColorData["DeepSeaColors"][Rescale[T, {0, 50}]])]],       ColorFunctionScaling -> False,       ImageSize -> 200,       PlotRange -> {0, T0},        Filling -> Axis,       PlotStyle -> Thick,        AxesLabel -> {x, \[Theta]}],           {{length, 5}, 1, 30, 1, Appearance -> "Labeled"}      ]      ![graph of the code](http://i.imgur.com/qknhBz8.jpg) I've tried a lot of convoluted methods like making a customized Raster image for the filling color, but I'm sure there has to be a simpler way to do this! EDIT: I want to be able to do this with the Plot function, so it is easier to Manipulate for the user. Right now I was able to get it to work by creating the data separately and then using a ListLinePlot, like so:               heatData = Transpose[{Range[100], Table[-0.5 x + 50, {x, 1, 100}]}];     bands = 50;          ListLinePlot[Table[{1, i} # & /@ heatData, {i, 0`, 1`, 1/bands}],       Background -> White, ColorFunction -> "TemperatureMap",      Filling -> True]      ![graph of the code](http://i.imgur.com/htUKRDQ.jpg) Thank you so much!


Running a shell script within Mathematica

The title pretty much explains it and I have not found something similar already posted. Perhaps I am not searching for the correct title or maybe this is something very basic, but I would appreciate any help! Is there a way within the Mathematica front-end to run a command line argument into the terminal? I am using bash and Mathematica 9.0. Thanks!


Return Functions from parallel execution of module

I wrote a module which numerically solves an ODE using `NDSolve`. The result from this is e.g. either `InterpolatingFunction[{{0.,1000.}},<>][t]` or `InterpolatingFunction[{{0.,1000.}},<>][t$1062]`, depending whether the independent varialbe `t` is global or local in the module. So far, I didn't care that it is global and everything worked fine. As this is imho is a source of upcoming trouble, I would like to switch to the local variable-version. As therefore I can't use a replacement rule like `InterpolatingFunction[{{0.,1000.}},<>][t] /. t->3` to extract single values or to plot the function any more, I tried to wrap it into a function as the following minimal example demonstrates.               compute[] := Module[{res, f},        points = Table[{x, x}, {x, 0, 10}];        res = Interpolation[points];        f[x_] := res[x];        f     ];      Using this code works fine.               In[109]:= ex = compute[];               ex[3]     Out[110]= 3      I now want to run this computation with different parameters so I put it into a `ParallelTable`. The resulting list then does not contain the correct functions anymore but only their symbols.               In[111]:= a = ParallelTable[compute[], {i, 0, 100}];               a[[1]][3]          Out[112]= f$1870[3]      Note that this works perfectly when `ParallelTable` is replace by a normal `Table`. Can you explain to me why this happens? Has this something to do with the definitions of the functions "living" on the sub-kernels and not being passed back to the main kernel? **Edit** Another aspect of the problem, a solution to which would help me too, is the following. If I multiply the `InterpolatingFunction` by a number and try to then extract values from it, it doesn't work as I would expect. Using the above example and assuming tha `res` is returned (indicated by the use of `res` in the following).               In[150]:= fcn=5*res;               fcn[3]          Out[151]= (5 InterpolatingFunction[{{0,10}},<>])[3]      Is there maybe a workaround for this?


Is there an option to plot the Z axis reversed (as shown in the figure)?

Normally the Z axis is plotted from bottom-to-top as shown below : ![normal z-axis running bottom-to-top](http://i.stack.imgur.com/lnoQ0.jpg) I got a plot with the axis ( **axes** to be more precise) reversed as shown below:![enter image description here](http://i.stack.imgur.com/mqQmh.jpg) Is there a way to **force the axes to be plotted top-to-bottom**? Thanks!


Organizing similar datasets using Contexts or otherwise

I often import several long time series to analyze something about a city. When I have multiple cities, I use contexts. As a simple example,               Begin["paris`"];     dataRaw=Import["Paris.csv"];     data=Differences[dataRaw];     dataMax=Max[dataRaw];     End[];     Begin["madrid`"];     dataRaw=Import["Madrid.csv"];     data=Differences[dataRaw];     dataMax=Max[dataRaw];     End[];      Now I can for instance do plots, so               ListLinePlot[{paris`data,madrid`data}]      and this seems much less sloppy than keeping everything in the `Global` context and manually adding the city name to the end of every symbol name. But I would like to write a function to take care of the importing and processing. Naively,               importCity[cityName_String] := (         Begin[ToLowerCase[cityName]~~"`"];         dataRaw=Import[cityName~~".csv"];         data=Differences[dataRaw];         dataMax=Max[dataRaw];         End[];     )      but this doesn't appear to create the context as intended. If contexts are a good way of organizing this sort of thing, how can I make a function that creates a context and puts results in it? And if this is an abuse of contexts, what's the proper way to do this?


Typeset unbalanced brackets

In LaTeX, you can typeset expressions containing unbalanced brackets, by balancing them with an invisible delimiter `\left.` or `\right.`. Some such notations are common in calculus; for example, the two common notations for applying an expression at two points: $$\int_a^b x^2 \mathrm{d} x = \left. \frac{x^3}{3} \right]_a^b \equiv \left. \frac{x^3}{3} \right|_a^b $$ Applying a function at one point: $$\left. \frac{\partial f}{\partial x} \right| _{x=0}$$ The alternative notation for an open interval endpoint: $$\left[a,b\right) \equiv \left[a, b\right[$$ But in the Mathematica symbol list, I don't see any invisible brackets. If you simply leave out the delimiter, it results in an unmatched bracket, messing up the formatting if you have multiple such expressions in the same cell. How do you typeset such expressions in Mathematica? (This is in display formulas; it doesn't have to be evaluatable.)


How to monitor the progress of Read?

I use               f = OpenRead["largefile.m"]     x = Read[f];     Close[f];      to read in a _Mathematica_ expression from a large file `largefile.m` (about 3 GB) and assign it to `x`. The `Read[f]` step takes very long time. How to monitor its progress? BTW, if the file `largefile.m` is larger than `4.1 GB` (as `ls -la` displays), will this approach work?


Model fitting to noisy data with a custom minimization function

I'm looking into fitting some data with Mathematica. I've got my head around how `NonlinearModelFit` works (I've been using the Levenberg-Marquardt algorithm for some other work). But my data this time is Poisson distributed, and I want to see if using the appropriate MLE for Poisson data is better for my scenario than nonlinear least squares fitting. According to the paper Efficient Levenberg-Marquardt minimization of the maximum likelihood estimator for Poisson deviates, then the minimization for least-squares fitting, for data $y_{i}$ and the model $f_{i}$ is $$ \chi^{2}=2\sum_{i=1}^{N} \frac{\left ( f_{i}-y_{i} \right )^{2}}{\sigma_{i}^{2}} $$ whereas for Poisson distributed data according to the paper, the minimization is $$ \chi^{2}=2\sum_{i=1}^{N}f_{i}-y_{i}-2\sum_{i=1,y\neq 0}^{N}y_{i}\ln \left ( \frac{f_{i}}{y_i} \right ) $$ Is it possible to run a model-fitting in Mathematica using this minimization? And can a (modified?) Levenberg-Marquardt algorithm still be used? **Edit** There's an associated Nature Methods letter at http://dx.doi.org/10.1038/nmeth0510-338, with a revised version of the above link: http://www.nature.com/nmeth/journal/v7/n5/extref/nmeth0510-338-S1.pdf (courtesy of @belisarius) **Update #1** So here's the sort of data/model I'm looking to fit: the sum of two (or more) Gaussians, which may sometimes overlap as shown in the example below. The amount of Poisson noise is deliberately significant as I'm dealing with very low counts. I've only posted a one-dimensional example here, but the data is in 2D, so there are more variables (x,y,means,heights,sigma...). I'm happy with using `NonlinearModelFit` to solve the problem, but I'm curious about dealing with the Poisson noise "more appropriately".               twoGaussianFunction[x_, A1_, sigma1_, mean1_, A2_, sigma2_, mean2_] :=          A1 Exp[-((x - mean1)^2/(2 sigma1^2))] +          A2 Exp[-((x - mean2)^2/(2 sigma2^2))];          cleandata = Table[twoGaussianFunction[i, 10, 10, 30, 10, 10, 60], {i, 0, 100}];          noisydata = RandomVariate[PoissonDistribution[0.5 #]] & /@ cleandata;     ListLinePlot[{cleandata, noisydata}, PlotRange -> Full]      ![enter image description here](http://i.stack.imgur.com/W7QDT.png)


Sharp background image in plot

How do I get rid of blurry transitions between pixels of the background image below. It's the fault of `Texture[]`, previously discussed in this answer. I haven't been able to get good results with `ImageCompose[]` or the other answers in this question. I'd like to avoid manual white margins that have to be adjusted if the image size changes or the font size of tick marks changes. The best solution I've found so far is to manually scale `a` up using `ImageResize[]` before using it as Texture. It reduces blurry transitions, but does not get rid of them.               a = Import["http://i.imgur.com/PiLKV6S.png"];     Show[ParametricPlot[{20 + 1.4 x - 40 y, x}, {x, 0, 200}, {y, 0, 1},       BoundaryStyle -> Directive[Purple, Thick],        PlotRange -> {{0, 201}, {0, 144}},       Prolog -> {Texture[a],         Polygon[{Scaled[{0, 0}], Scaled[{1, 0}], Scaled[{1, 1}], Scaled[{0, 1}]},          VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]         }]]      ![enter image description here](http://i.stack.imgur.com/H8UHL.png)


How to plot listpointplot3D

list = {{51.11667, 99.66667, 319.622}, {50.43333, 100.15000, 316.612         }, {49.60000, 90.35000, 307.908        }, {49.80000, 92.08333, 318.402         }, {49.65000, 94.40000, 319.435        }, {48.93333, 89.93333, 308.08         }, {49.01667, 91.71667, 313.293        }, {48.81667, 93.10000, 312.595        },             {48.41700, 90.30000, 314.71        }, {48.01667, 91.56667, 310.996         }, {48.51667, 94.30000, 311.186        }, {49.65000, 95.78300, 319.099         }, {48.76667, 96.00000, 317.284        }, {48.08300, 99.55000, 316.186         }, {49.56667, 102.00000, 315.924        }, {49.63333, 100.16667, 312.756         }, {49.38333, 102.70000, 319.406        }, {48.53333, 101.38333, 316.598         }, {48.80000, 103.55000, 316.959        }, {48.91667, 106.06667, 319.909         }, {49.45000, 107.20000, 318.043        }, {49.83333, 107.73333, 319.615         }, {48.85000, 111.45000, 313.156        }, {49.55000, 114.40000, 319.228         }, {48.61700, 110.60000, 319.228        }, {48.08333, 114.55000, 319.228         }, {46.11667, 91.46667, 315.531        }, {46.31700, 93.90000, 313.402         }, {47.75000, 96.85000, 313.38        }, {46.83333, 98.08333, 316.459         }, {47.45000, 101.46667, 309.152        }, {46.70000, 100.13333, 315.996         }, {46.96700, 103.80000, 311.505        }, {46.13333, 100.68333, 310.823         }, {46.26667, 102.78333, 310.060}, {47.85000, 106.75000, 315.524         }, {47.30000, 107.48333, 314.092        }, {46.45000, 108.21667, 312.438         }, {47.78333, 112.11667, 314.492        }, {47.31667, 110.63333, 312.578         }, {46.68333, 113.28333, 314.22        }, {47.61667, 118.61667, 318.395         }, {47.16667, 115.63333, 310.232        }, {45.90000, 115.36667, 314.814         }, {45.15000, 97.76667, 312.814        }, {44.61700, 98.70000, 312.377         }, {45.45000, 103.90000, 309.342        }, {45.76667, 106.28333, 308.962         }, {44.41667, 105.31667, 304.975        }, {44.56667, 107.18333, 314.49         }, {45.73333, 112.36667, 315.824        }, {44.90000, 110.11667, 310.748         }, {43.73333, 111.90000, 315.309        }, {43.58333, 104.41667, 305.358         }, {42.90000, 100.21700, 301.69        }, {43.20000, 107.16667, 303.857         }, {43.18333, 109.21667, 312.96        }};          Show[ListPointPlot3D[list[[All, {2, 1, 3}]], PlotStyle -> PointSize[Large]],                           Boxed -> True, ViewPoint -> {0, 0, -∞}]       How to show List points value in graphic???


2D Gaussian distribution of squares coordinates

I would like to imitate the structure of this great painting from Ellsworth Kelly in Mathematica. Yet with all the colored squares in Black and the beige one in white. ![enter image description here](http://i.stack.imgur.com/wgMtl.png) Below is what I have wrote to generate a square made out of 100 squares but I am confused about the next step : How could I "Gaussianly sample" from the center How could I then assign different colors to the ones selected ?               Graphics@Flatten[                      Table[Rectangle @@@                             Table[{{i, j}, {i + 1, j + 1}},                                   {i, Range[0, 10, 1]}],                        {j,Range[0, 10, 1]}], 1]


Is there a way to specify custom domains in mathematica?

I want to solve for all solutions to the system of equations $a_1 a_2 a_3 b_4 + a_1 a_2 b_3 + a_1 b_2 + b_1 = 0$ and $a_1 a_2 a_3 a_4 = 1$ where the $a_i$'s and $b_i$'s take on values from $\\{-1,1\\}$. Is there a way to efficiently solve this besides exhaustive casework? Also, is there a way to specify a custom domain for $\\{-1,1\\}$ in Mathematica so I can just do this on my computer?


Cannot colour in my graph like I want

So I tried               SyrianGovernment = {"Al-Safira"};     FSA = {"Atarib"};      ISIS = {"Al-Bab","Dayr Hafir","Jarabulus", "Manbij"};      YPG = {"Afrin","Ayn Al-Arab"};      Contested = {"South Mount Simeon", "North Mount Simeon", "Aleppo", "Azaz"};          vs = Join @@ MapThread[Thread[#1 -> #2] &, {{SyrianGovernment, FSA, ISIS, YPG},                                                  {Red, Green, Black, Yellow, Gray}}];     mm = RandomChoice[{0, 1}, {65, 65}];          AdjacencyGraph[mm, VertexSize -> 0.4, VertexStyle -> vs]      I'm sure you can see what I'm trying to do here (I'm trying to colour the vertices or nodes of a `Graph`). I'm trying to colour my `Graph` four colours depending on what _group_ they're in. I'd also like to know if I can program it such that nodes which I do not name can be coloured a certain colour as _the rest_. This works:               SyrianGovernment = {"Al-Safira", "Al-Nabk", "Qatana", "Al-Qutayfah", "Al-Tall","Yabrud", "Zabadani", "Izra", "Al-Sanamayn"};FSA = {"Atarib", "South Mount Simeon", "Abu Kamal", "Mayadin"};ISIS = {"Al-Bab", "Dayr Hafir", "Jarabulus", "Manbij"};YPG = {"Afrin", "Ayn Al-Arab"};Contested = {"South Mount Simeon", "North Mount Simeon", "Aleppo","Azaz", "Darayya", "Duma", "Qudsaya", "Markaz Rif Dimashq","Daraa", "Deir ez-Zor"};          SeedRandom@5;     list = Flatten[{SyrianGovernment, FSA, ISIS, YPG, Contested}, 1];     vs = Flatten[MapThread[Thread[Rule[#1, #2]] &, {{_, SyrianGovernment, FSA, ISIS,YPG}, {Gray, Red, Green, Black, Yellow}}], 1];     g = Graph[(DirectedEdge @@@ DeleteDuplicates@RandomChoice[list, {65, 2}]), VertexSize -> .5,VertexLabels -> "Name", ImagePadding -> 20, VertexStyle -> vs]      But when I add say `"Hama"` to `SyrianGovernment` (or anything more for that matter), the graphic disappears. So this doesn't work:               SyrianGovernment = {"Al-Safira", "Al-Nabk", "Qatana", "Al-Qutayfah", "Al-Tall","Yabrud", "Zabadani", "Izra", "Al-Sanamayn","Hama"};FSA = {"Atarib", "South Mount Simeon", "Abu Kamal", "Mayadin"};ISIS = {"Al-Bab", "Dayr Hafir", "Jarabulus", "Manbij"};YPG = {"Afrin", "Ayn Al-Arab"};Contested = {"South Mount Simeon", "North Mount Simeon", "Aleppo","Azaz", "Darayya", "Duma", "Qudsaya", "Markaz Rif Dimashq","Daraa", "Deir ez-Zor"};          SeedRandom@5;     list = Flatten[{SyrianGovernment, FSA, ISIS, YPG, Contested}, 1];     vs = Flatten[MapThread[Thread[Rule[#1, #2]] &, {{_, SyrianGovernment, FSA, ISIS,YPG}, {Gray, Red, Green, Black, Yellow}}], 1];     g = Graph[(DirectedEdge @@@ DeleteDuplicates@RandomChoice[list, {65, 2}]), VertexSize -> .5,VertexLabels -> "Name", ImagePadding -> 20, VertexStyle -> vs]


NMaximize issue and regularization

I want to maximize over the space (output of NDSolve, in appendix to the question) but I do not think this is strictly important in this case), to get the maxima of the solution as a function of time:               MAX11[t] = NMaximize[{Evaluate[SolVec1[[1]][[1]]], 0 <= x <= L}, x]          NMaximize::nnum: The function value -     InterpolatingFunction[{{0.,10.},{0.,500.}},{3,10,1,{25,254},{6,4},0,0,0,0},{<<1>>},     {Developer`PackedArrayForm,{<<1>>},{<<1>>}},{Automatic,Automatic}] is not a number at      {x} = {1.30494}. >>      But, in fact, at that point, the function doesn't diverge:                Plot[SolVec1[[1]][[1]][1.304935615948057, t], {t, 0, T}]      ![enter image description here](http://i.stack.imgur.com/aykcw.jpg) Now, I wonder whether the problem is the fact that I don't impose at any point to maximize only for $t$ between $0$ and $T$. How can I solve this? **Appendix:**               sol1 = {\[Theta], \[Phi]} /.         First[NDSolve[{eqn1[\[Lambda], w, \[Beta], \[Alpha]j, 1, 0, g] == 0,             eqn2[\[Lambda], w, \[Beta], \[Alpha]j, 1, 0, g] == 0,        \[Theta][0, t] == 0, \[Theta][L, t] == 0,                \[Theta][x, 0] == First[InitialMode[x, 1, 0.5]],        Derivative[1, 0][\[Phi]][0, t] == 0,             Derivative[1, 0][\[Phi]][L, t] == 0, \[Phi][x, 0] ==         Last[InitialMode[x, 1, 0.5]]}, {\[Theta], \[Phi]},              {x, 0, L}, {t, 0, T}, AccuracyGoal -> 4,       PrecisionGoal -> 5]];       Where:               InitialMode[x_, kk_, fact_] := {fact Sin[ Pi kk x / L],                                  Subscript[\[Phi], 0] - Cos[ Pi kk x / L]};      and eqn1, eqn2 are two higly nonlinear expressions in $\theta(x,t)$ and $\phi(x,t)$. Here is the link to the minimal version of my code: Code


NMinimize holding problem

I have a function that I want to minimize numerically through an NMinimize command (because it's very complicated analytically). The minimizer call looks as follows:               NMinimize[{mat = func0[a, b, c, d, e, f]; Print[mat];      {ac0t, ac1t, ac2t, ac3t} = mat.{Ac0, Ac1, Ac2, Ac3};      {as0t, as1t, as2t, as3t} = mat.{As0, As1, As2, As3};      Total[({       a+b,       a^2+b^2,       ...       })^2], constraints}, {a, b, c, d, e, f},  Method -> "NelderMead"]      So notice that I'm minimizing a sum of squares, but before calculating the sum of squares, I have to calculate stuff using a function `func0`. `func0` is defined as a numerical function:               func0[a_?NumericQ,b_?NumericQ,c_?NumericQ,d_?NumericQ,e_?NumericQ,f_?NumericQ]:=Module[{},...]      However, when it gets evaluated in the minimizer, it gets evaluated and held. So Print[mat] will result in `func0[a, b, c, d, e, f]`, and not in a numerical value. While if I calculate this function outside NMinimze, it works fine. I can imagine that NMinimize is calling it with variables, and that's why it isn't working. How can I tell NMinimize to take this only numerically? Please advise. Thank you. * * * EDIT: As requested in comments, I'm adding an executable example of the problem:               func0[a_?NumericQ] := {{Sin[a Degree], Cos[a Degree]},{Sin[a Degree], Cos[a Degree]}}     NMinimize[{var = func0[a];      Print[var]; {aa, bb} = var.{1/Sqrt[2], 1/Sqrt[2]};      Total[{aa - bb, aa + bb      }^2], a > 0}, {a}, Method -> "NelderMead"]       If you execute this code, you'll see that an error will be thrown:               Set::shape: Lists {aa,bb} and func0[a].{1/Sqrt[2],1/Sqrt[2]} are not the same shape. >>      Which happens because func0[a] is being evaluated symbolically, while I must evaluate it numerically. Please note this is a simple example for the sake of argument. My `func0` is very complicated and cannot be evaluated symbolically.


Why does Mathematica not give simple solutions to simple system of equations with powers

I trt to get Mathematica getting me the simple solutions for x and y from this system of two power equations: $$\text{Eq. 1: } z=x^{m}y^{n}$$ $$\text{Eq. 2: }z=\tau x^{m-1}y^{1-n},$$ The simple solutions are $$x=\left(z^{1-2n}\tau^{-n}\right)^{\frac{1}{n-2nm+m}}$$ $$y=\left(z\tau^{m}\right)^{\frac{1}{n-2nm+m}},$$ but I cannot make Mathematica find them. Entering in Mathematica               Solve[z == x^m y^n && z == \[Tau] x^(m - 1) y^(1 - n), {x, y}]      or, e.g.,               FullSimplify[Solve[z == x^m y^n && z == \[Tau] x^(m - 1) y^(1 - n), {x, y}]]      I get back               x -> E^((-Log[z] + 2 n Log[z] - n Log[\[Tau]])/(-m - n + 2 m n)),      y -> E^((-Log[z] + m Log[\[Tau]])/(-m - n + 2 m n))      that is, $$x\to e^{\frac{-n \log (\tau )+2 n \log (z)-\log (z)}{2 m n-m-n}},y\to e^{\frac{m \log (\tau )-\log (z)}{2 m n-m-n}}.$$ Why does even FullSimplify (or Simplify) not give me back the simple solution? Even after imposing the simple result, i.e. defining               x = (z^(1 - 2 n) \[Tau]^-n)^(1/(n - 2 n m + m)); y = (z\[Tau]^m)^(1/(n - 2 n m + m));      Mathematica doesn't tell confirm to me that the difference between the LHS and the RHS of Equation 1,               x^m y^n - z      is zero:               FullSimplify[x^m y^n - z]      yields               -z + ((z\[Tau]^m)^(1/(m + n - 2 m n)))^n ((z^(1 - 2 n) \[Tau]^-n)^(1/(m + n - 2 m n)))^m      This is easily seen to be zero, but it puzzles me that Mathematica doesn't tell me that.


How can I get the time steps chosen by NDSolve when the Method -> "ExplicitRungeKutta" option is given?

I am trying to solve an ODE with `NDSolve` using the `"ExplicitRungeKutta"` method. I need to know exactly which time steps `NDSolve` chooses, i.e., which points in the interval $[tmin, tmax]$ it chooses when it implements the Runge- Kutta method before the interpolation is made). What should I do?


Implementing key-value associations in Mathematica 9 with inexact numbers for keys

I'm not sure of what type of problem my issue falls into, so I haven't been able to search forums with any success. If this has already been solved then my apologies! Essentially I'm trying to set a list equal to a calculated value then call that list back.               -15*0.1 + 6*0.1          (* -0.9 *)          -15*0.1 + 6*0.1 == -0.9          (* True *)          a[-15*0.1 + 6*0.1] = 5          (* 5 *)          a[-0.9]          (* a[-0.9] *)          a[-0.8999999999999999`]          (* 5 *)      I've reset _Mathematica_ 9.0.1.0 according to this guide http://support.wolfram.com/kb/3274 to no avail.