title: Plotting: DensityPlot produces artifacts

text: I am trying to plot the electric potentials of bouncing balls using the following code:               g = 0.1;     Tmax = 100;     n = 6;     pos = RandomReal[{-1, 1}, {n, 2}];     charge = RandomReal[{1, 10}, 10];          sol = NDSolve[         Flatten@Table[{             With[{i = i},                  {(x[i])''[t] == 0,                  (x[i])'[0] == 0,                  (y[i]'')[t] == -g,                  (y[i])'[0] == 0,                  x[i][0] == pos[[i, 1]],                  y[i][0] == pos[[i, 2]],                  WhenEvent[                      y[i][t] < -1, {y[i]'[t] -> -0.95 y[i]'[t],                       y[i][t] -> y[i][t] + 0.05}]                  }              ]      }, {i, 1, n}], Flatten@Table[{x[i], y[i]}, {i, 1, n}], {t, 0, Tmax}, PrecisionGoal -> 2];          Manipulate[Graphics[         Table[             With[{p = Evaluate[                 {x[i][t], y[i][t]} /. First[sol]]},             Disk[p, 0.05]], {i, 1, n}], PlotRange -> 1.05], {t, 0, Tmax}]          PotentialAnimated[x_, y_, t_] :=          Sum[charge[[i]]/             If[Norm[({x, y} - {x[i][t], y[i][t]} /. sol)] > 0.001,                 Norm[({x, y} - {x[i][t], y[i][t]} /. sol)], 0.001],         {i, 1, n}]          Manipulate[         DensityPlot[PotentialAnimated[x, y, t], {x, -1, 1}, {y, -1, 1}], {t, 0, 10}]      This^ last command should plot the potentials in my box caused by the charged balls jumping up and down, but I get an almost fractal looking artifact from my lower left to my upper right corner. Any ideas why this is happening ? // part 2 not directly related but I feel like it would be a waste to start a new question just for this. Im now trying to combine the two plots like this: Manipulate[ Show[{DensityPlot[ PotentialAnimated[x, y, t], {x, -10, 10}, {y, -10, 10}, ColorFunction -> "SunsetColors"], Graphics[ Table[ With[{p = {x[i][t], y[i][t]} /. First[sol]}, {ColorData["TemperatureMap", (charge[[i]] + 10)/20], Disk[p, 0.5]} ] , {i, 1, n}] , PlotRange -> 10.5, Background -> Black]}], {t, 0, Tmax}] for charges ranging from -10 to 10 , but it seems like the colors get "clipped" on the density plot![clipped](http://i.stack.imgur.com/Xl6dq.jpg) how can I fix it so colours near the balls dont just go white. thx for the help so far catadoxas


title: How to transform a 3D image by an affine transformation matrix

text: I have a question concerning Image Processing: I have a stack of images, which I can compose to a 3D image using Image3D. Additionally I have a 4x4 affine transformation matrix. I would like to transform the 3D image using my transformation matrix. In 2D this would be possible using ImageTransformation[image, transformationMatrix]               t = AffineTransform[{{{RandomReal[{-0.5, 5}],       RandomReal[{-0.5, 5}]}, {RandomReal[{-0.5, 5}],       RandomReal[{-0.5, 5}]}}, {RandomReal[{0.2, 0.2}],      RandomReal[{-0.2, 0.2}]}}]     ImageTransformation[ExampleData[{"TestImage", "Lena"}], t, PlotRange -> All, Padding -> None]      So this works fine for 2D images, but unfortunately ImageTransformation is not applicable to Image3D-objects. My first attempt was to decompose the matrix into several matrices and transform the image stack in 2 steps:   1. transforming each image of the image stack   2. transpose the image stack and transform with the transformation matrix for the third dimension. As an example I do the following steps for translation:               image3D = Import["ExampleData/CTengine.tiff", "Image3D"]     slices = Image3DSlices[image3D];     translation3D = TranslationTransform[{0.2, 0.1, 0.3}]     translation3D1 = TranslationTransform[{0.2, 0.1}]     translation3D2 = TranslationTransform[{0, 0.3}]     tempimageslices = ImageTransformation[#, translation3D1] & /@ slices;     transposedtempimageeslices =  Image /@ (Transpose[ImageData[#] & /@ tempimageslices]);     tempimageslices2 =   ImageTransformation[#, translation3D2] & /@ transposedtempimageeslices;     final = Image /@ (Transpose[ImageData[#] & /@ tempimageslices2, {2, 1, 3}]);     Image3D[final]      The Steps in this example are:   1. I cut the image into several slices.   2. I split the 4 x 4 transformation matrix "translation3D" into 2 3 x 3 matrices "translation3D1" and "translation3D2".   3. I transform every image in slices using ImageTransformation and the matrix "translation3D1"    4. I transpose the imageData and create new images in the new dimensions   5. I transform the images in the new dimensions using the matrix "translation3D2"   6. I transpose the images in order to have the original ImageDimensions For a translation or a scaling, the two transformation matrices i need, are easy to read from the matrix. The problem I have with this method is that I can't compute the decomposition of an affine transformation matrix. Is there an easy way to decompose the affine transformation or another solution in which the full affine transformation can be used to transform the image stack?


title: Notebook stops using extra kernels after some time

text: Have a mathematica .nb job where I've programmed to run on parallel. Everything goes fine for about an hour but after this most kernels just stop being used by the program. I can see this happing in most of my routines. I'll leave a link where most can take a look at the notebook Well, it's in portuguese, but you guys don't have to worry about that...most words are kind of readable.. !![Definitions 1](http://i.stack.imgur.com/34kt6.png) !![Definitions 2](http://i.stack.imgur.com/nxH60.png) !![Routine](http://i.stack.imgur.com/iIikU.png) !![Program Block](http://i.stack.imgur.com/vRU2L.png) https://onedrive.live.com/redir?resid=8F3E863A924D47BC%2114489


title: Can Eigenvalues[] and Eigenvectors[] be assumed to return the same ordering?

text: If I do back to back calls of `Eigenvalues[]` and `Eigenvectors[]` can these be assumed to order the values and vectors the same, or is each independent? Related to this is a curiosity about the performance of a pair of calls like this. Are Mathematica optimizations done at an expression level, or if a result from one could help another later (or previous) calculation, is it able to reorder internally and/or make use of previous calculations?


title: Order of eigenvectors

text: I have a matrix               A = {{5, 4, 2}, {4, 5, 2}, {2, 2, 2}}      The eigenvalues are `1, 1, 10` and I need to find the eigenvectors. Solving for `1` would result in two eigenvectors. Using _WolframAlpha_ I get `(-1, 0, 2)` and `(-1, 1, 0)` This comes from `x3 = -2 (x1 + x2)` For instance I could have: > >     x1 = 1, x2 = -1, x3 = 0 >   > > or >   >   >     x1 = -1, x2 = 1, x3=0 >   and > >     x1 = 0, x2 = -1, x3 = 2 >   > > or >   >   >     x1=-1, x2=0, x3=2 >   How to properly order those values?


title: Convert number to exponent form with highest power possible

text: As a school assignment we have to write a program which solves this issue. Since the program has to run efficient I am wondering what the best way is to approach this issue. Of course there you can just guess and try if it works, but that would not be efficient at all. Could someone push me in the right direction how to solve: n = b ^ e where e is the largest number possible? For example, n = 16 would result in 2 ^ 4 instead of 4 ^ 2.


title: Forcing contours to close at edge

text: I have some data that I am plotting with `ListContourPlot` and I would like my contours to be closed at the edge (closing around the high value region). A simple example:               ListContourPlot[{{3, 2, 1, 0}, {2, 1, 1, 0}, {1, 0, 0, 0}, {0, 0, 0, 0}},                      Contours -> {1}, ContourShading -> None, ContourStyle -> Thick]      > ![!\[plot of unclosed > contours\]\(http://i.imgur.com/B8eMa5d.png\)](http://i.stack.imgur.com/L4KLf.png) I know you can add e.g. `BoundaryStyle -> Black`, but it closes the whole region: > ![enter image description here](http://i.stack.imgur.com/WD0Mu.png) Note that I have tried the answer here, but that method changes the plotting method from plotting a matrix to plotting `{x,y,f(x,y)}` values, which has some undesirable results on my (much more complicated than the above example) data.


title: How to change the appearance of a Cell GroupOpener?

text: I would like to change the Cell GroupOpener appearance. ![Cell GroupOpener](http://i.stack.imgur.com/VJoPt.png) In the present Mathematica design it is too small and can be missed by a reader unfamiliar with Mma. I know, how to change its color through the OptionInspector. Now, how can I put there something instead of the check-mark that is there at present? For example, a gray triangle that has been there previously, of something more complex, some graphics of my own design **Edit** : To answer the question of Silva below: This is how the Cell GroupOpener looks like at my machine operating on Windows XP, Mma 9.0.1. ![enter image description here](http://i.stack.imgur.com/HjB2Y.png) Now on my other machine with Windows 7 and same Mma version the GroupOpener looks like a tiny check-mark. It is hardly visible and it is more difficult to operate (i.e. to open and close). For example, visually it is difficult to distinguish the closed from the open one. I am sorry, being presently at the machine with the XP I cannot provide an image for the GroupOpener at Win7. Now, it is not too bad, as long as it concerns myself, this or that GroupOpener presentation is it. However, I am creating documents to give away, and need that inexperienced people would easily identify the GroupOpener and easily operate with it. So I would like to be able to control its appearance.


title: How to export results of an analysis in table format into MS word file

text: I'm working on a simulation study using Mathematica 8. At the end of the analysis I'll have a matrix of data containing my results (assume for three variables like x,y & z). I used these codes for integrating labels (e.g. x,y & z) into data matrix and creating a table format:               data = Table[Random[], {i, 3}, {j, 3}] (* as an example of data*)     label= {"x","y","z"}     Text@Grid[Insert[data, lab, 1], Frame -> All]      resulting in (I don't know why frames don't appear here but do in Mathematica): \begin{array}{ccc} \text{x} & \text{y} & \text{z} \\\ 0.0047326 & 0.877782 & 0.924523 \\\ 0.188628 & 0.171809 & 0.317739 \\\ 0.775678 & 0.0886559 & 0.336866 \end{array} I wan to how I can export this table into Ms Word as a table not an equation. Any help and idea is appreciated. Thanks, Amin.


title: Unable to convert $\TeX$ input into mathematica

text: The input               ToExpression["\\sqrt{x y}", TeXForm]      gives me the `$Failed` output. Maybe my very old computer is the problem, but that's the only command that has caused me problems, and that input is from the tutorials.


title: Function returning Null along with other unexpected expressions

text: When I use some function, at the end along with the output I get some NULLs returned that I don't understand the reason for and are highly undesirable. For example, when I define the reversal of list with               ReverseList[ele_List] := Module[{list = List[], i, k = 1},       {For[i = Length[ele], i > 0, {i--, k++}, {AppendTo[list, ele[[i]]]}],        Print[list],        Return[list]}       ]      The output I get                ReverseList[{1, 2, 3, 4, 5}]      is               {5,4,3,2,1} {Null, Null, Return[{5, 4, 3, 2, 1}]}      I am also have a problem with returning the list. Can someone please help me with these two problems?


title: AR(1) Process first term

text: I'm trying to generate a very simple AR(1) Process with _Mathematica_ using the `ARProcess[]` function. The process must have the following format: $Y_t = \alpha + \beta Y_{t−1} + ϵ_t$ However, after reading the _Mathematica_ help file and some posts about `ARProcess[]` at MMA.SE, I couldn't find a way to correctly generate the process. I seems that the `ARProcess[]` function cannot deal with the $\alpha$ term of the process. For instance, consider the process described below: $Y_t = 10 + .6Y_{t−1} + ϵ_t$ , where $ϵ_t$ is Normally distributed with mean $0$ and variance $4$ (i.e., $ϵ_t \sim N(0,2)$). If I use `ARProcess[{.6},4]` I get               Mean[ARProcess[{.6}, 4][t]]     Variance[ARProcess[{.6}, 4][t]]      > Out[1]= 0 > > Out[2]= 6.25 which are consistent with an AR(1) process of the form $Y_t = 0 + .6Y_{t−1} + ϵ_t$ I would like to be able to, though the `ARProcess[]` function, calculate the **mean** and the **variance** of the process $Y_t = 10 + .6Y_{t−1} + ϵ_t$ in order to get a **Mean** of $25$ and a **Variance** of $6.25$. Is there any way to achieve this in _Mathematica_?


title: How does one use StandbyDistribution to model the reliability of an M of N warm standby system when M > 1?

text: I am modeling the reliability of a system with four units, numbered 1 through 4. The system needs at least two of the four units to be operational. Initially units 1 and 2 are active and units 3 and 4 are in warm standby. If either unit 1 or unit 2 fails, unit 3 becomes active (unless it has already failed while in standby). If a second active unit fails, unit 4 becomes active (again unless it has already failed while in standby). When a unit fails it remains failed. Unit 1 has reliability distribution d1, unit 2 has reliability distribution d2, unit 3 has reliability distribution d3a when active and d3s when in standby, and similarly for unit 4. `StandbyDistribution` handles cases where initially there is only one active unit. However, in `StandbyDistribution[dist1, {..., {distxstandby, distxactive}, ...}, ...]`, it is not at all obvious to me what the expression `dist1` should be for the case I am looking at. At the same time, `BooleanCountingFunction` is well suited for an M of N system where all of the units are active, but there doesn't seem to be any way of specifying that `N - M` units are initially in warm standby. Has anyone successfully dealt with the case I am looking at?


title: Matrix of given size with unspecified elements

text: I want to generate a Matrix of given size whose elements are not specified I can use               Array[a, {3, 2}]      to get               {{a[1, 1], a[1, 2]}, {a[2, 1], a[2, 2]}, {a[3, 1], a[3, 2]}}      however i would like to have               {{a[[1, 1]], a[[1, 2]]}, {a[[2, 1]], a[[2, 2]]}, {a[[3, 1]], a[[3, 2]]}}


title: Where does Mathematica install command line tools on OS X Lion?

text: I've read the documentation and tutorials on using _Mathematica_ and the kernel from the command line, and all of these materials suggest that I ought to be able to simply type either               $ mathematica      or               $ math      in Terminal, assuming these these commands have been installed in (variously) `/usr/local/bin` or `/usr/bin`. But I get the usual "command not found" error message that results when this is not the case, even though these directories are in my PATH. Where does _Mathematica_ (9.0) really install `mathematica` and `math` on OSX Lion?


title: How can I check if one expression implies another?

text: Say I have one expression, for example $x^3-3 + c = y$, and I want to check if it implies another with some set of explicitly stated assumptions. With the previous example, assuming all variables are positive real numbers, we might ask if $x^3-3 + c = y$ implies $c = -x^3 + y$. This example is trivial, but I'd like to do the same where, perhaps, choices can be made about the use of various special functions or identities and there can also be inequalities. Is there something like `ImpliesQ[{exp1,exp2}]`?


title: Why am I getting an error from MLPutFunction after getting the MathLink from LibraryLink?

text: Based on the example on the documentation page for `processMathLink`, I've got the following C++ code:               void MathematicaFunctionDescriptor::Register(WolframLibraryData lib_data) const     {         MLINK link = lib_data->getMathLink(lib_data);         Checked(&MLPutFunction, link, "EvalutatePacket", 1, "MLPutFunction(EvaluatePacket, 1) failed");         Checked(&MLPutFunction, link, "Set", 2, "MLPutFunction(Set, 2) failed");         Checked(&MLPutSymbol, link, maFunctionName.c_str(), "MLPutSymbol(" + maFunctionName + ") failed");         Checked(&MLPutFunction, link, "LibraryFunctionLoad", 4, "MLPutFunction(LibraryFunctionLoad, 4) failed");         Checked(&MLPutString, link, "MaCALFrontEnd", "MLPutString(\"MaCALFrontEnd\") failed");         Checked(&MLPutString, link, mgFunctionName.c_str(), "MLPutString(\"" + mgFunctionName + "\") failed");         PutSymbolList(link, input);         Checked(MLPutSymbol, link, output.c_str(), "MLPutSymbol(" + output + ") failed");         int errorCode = lib_data->processMathLink(link);         if (errorCode != 0)             throw GMathematica::CallBackError(errorCode, "Cannot register function " + maFunctionName);         int nextPacket = MLNextPacket(link);         if (nextPacket == RETURNPKT)             MLNewPacket(link);     }      This is called from a function `initializeAll` which catches all exceptions, and converts them into error returns to Mathematica. `Checked` is a simple template function which wraps a call to its first arguement, checking its return status, and throwing an exception with its last argument as a message if the call fails. I've invoked this from Mathematica by:               LibraryFunctionLoad[ "MaCAL", "initializeAll", {}, Integer ]     %[]      The `LibraryFunctionLoad` seems to work; the dll "MaCAL" contains the function "initializeAll", which loads all of the necessary DLLs (about 20) in the correct order, then invokes the wrapper for the above function in the DLL "MaCALFrontEnd". I get back the error message `"MLPutFunction(EvaluatePacket, 1) failed"`. Regretfully, I don't know how to find out why it failed. More generally: I'm trying to execute "LibraryFunctionLoad" for all of my functions, from the C++ code invoked by the first function. (I actually tried this first in `WolframLibrary_initialize`; I moved it to a separate function when this failed, but with no noticeable difference.) Is it possible to do this from `WolframLibrary_initialize`? And is this the correct technique, or is there a better solution? And more generally, is there some good literature, on the net or in the form of a book, which explains how to do these sort of things. The Wolfram documentation is some of the worst I've encountered--they seem to confuse quantity with quality.


title: FindFaces: how to improve the results of the face recognition feature

text: In _Mathematica 9_ , the `FindFaces` command offers an easy way to detect faces. In some experiments, I've been getting reasonable results, but I'd like to know if there are ways to improve the success rate. As with the online help example, I thought the 1927 Solvay Conference photograph was a good place to start. You can find it on the Wikimedia here, at 3000 by 2171 pixels.               solvay = Import["http://upload.wikimedia.org/wikipedia/commons/6/6e/Solvay_conference_1927.jpg"];     faces = FindFaces[solvay]      which returns a list of rectangles:               {{{81.5, 1105.5}, {262.5, 1286.5}}, {{133.5, 1038.5}, {231.5, 1136.5}}, ...      Using these to chop out some passport photographs:               passports = ImageTrim[solvay, #] & /@ faces      gives this: ![solvay faces](http://i.stack.imgur.com/KlNI1.png) I can get rid of the images that are too large by using the optional minimum and maximum sizes:               faces1 = FindFaces[solvay, {85, 130}];     passports1 = ImageTrim[solvay, #] & /@ faces1      But it's still not perfect. (The online help example seems to miss more people than I do, but there are no false positives, unlike my interesting collection of masonry people. How would I improve these results? Is `Mathematica`'s built-in function capable of better results, or is it just, well, a toy?


title: How to extract a consecutive list of substring from a string?

text: Given a list of strings:               data = {      "2894;Hot Pink;53:09:44;1449714",      "17456;Dark Cyan;19:06:42;6929227",      "5147;Lime;54:11:55;5247632"     }      (Words are separated by `";"`, the number of words in strings are equal. Number of characters in strings are unequal. Number of characterss in words are unequal.) How to extract the $m^{th}$ through $n^{th}$ words, so that e.g. $m=2, n=3$ should return:               {     "Hot Pink;53:09:44",     "Dark Cyan;19:06:42",     "Lime;54:11:55"     }        **UPDATE** Final solution was found for the task.   I like to share it here.               inlist = RandomChoice[     {"7270;Deep Pink;04:14:55;0027354",      "2871;Dark Orchid;54:21:23;1182263",      "4021;Silver;04:00:58;6940040",      "3521;Dark Slate Gray;18:42:43;5828275"},      400000];            delim = ";";     fromWord = 2;     numberOfWords = 2;            from = 2 fromWord - 1;     to = 2 (fromWord + numberOfWords - 1) - 1;     outlist = List /@ StringJoin /@           StringSplit[inlist, delim -> delim][[All, from ;; to]]; // Timing            {0.92, Null}        The honor goes to the very concerned in this task. Every detail of their conception was vital to the solution. Keep'n rocking.


title: Discrepancy with TakeWhile between RandomInteger result and list on Linux

text: I have to following code that solves a problem for me. The example that is given to us is as follows: `lst = {1,-2, 3, 4,5,-3, -4, 9,7,0,8}`, predicate = `Positive`. The maximal Predicate-segments of `lst` are `{1}, {3,4,5}, {9,7}`, and `{8}`.               getSegments[lst_,predicate_] :=       Module[{res= {},seg, lstcopy=lst},         While[Length[lstcopy]>0,           seg = TakeWhile[lstcopy,predicate[#]&];           If[Length[seg] > 0,             (* True *)             AppendTo[res,seg];              lstcopy=Drop[lstcopy,Length[seg]],             (* False *)             lstcopy=Drop[lstcopy,Length[TakeWhile[lstcopy,!predicate[#]&]]];            ] (* If *)         ] ;(* While *)         Return[res];       ];      The above code works fine for the following input:               In[1]:= getSegments[RandomInteger[{-100,100},10],Positive]     Out[1]= {{68,13},{59},{16},{41}}          In[2]:= getSegments[RandomInteger[{-100,100},10],Negative]     Out[2]= {{-26},{-77,-60},{-11,-78}}      Yet something very strange happens with the following:               In[3]:= getSegments[RandomInteger[{1,2},10],EvenQ]     Out[3]= {}          In[4]:= getSegments[{1,1,2,2,1,2,2,1,2,2},EvenQ]     Out[4]= {{2,2},{2,2},{2,2}}      This is the same for OddQ. **Why does it treat the RandomInteger result so differently from the list?** The input for `In[4]` is also generated with a call to RandomInteger[{1,2},10]. I did find that `seg` is always empty with the `In[3]` case, while the `False` branch of the `If` takes all the elements in the list. **EDIT** It is of note that I run Mathematica 8 on Linux. The above works fine on Windows versions of Mathematica. **EDIT 2**               In[76]:= getSegments[RandomInteger[{1,2},5],EvenQ] // Trace     Out[76]= {{RandomInteger[{1,2},5],     {1,2,1,2,1}},getSegments[{1,2,1,2,1},EvenQ],SplitBy[{1,2,1,2,1},EvenQ]     [[If[EvenQ[First[{1,2,1,2,1}]],1,2];;All;;2]],     {SplitBy[{1,2,1,2,1},EvenQ],Split[{1,2,1,2,1},EvenQ[#1]===EvenQ[#2]&],     {(EvenQ[#1]===EvenQ[#2]&)[1,2],EvenQ[1]===EvenQ[2],{EvenQ[1],False},     {EvenQ[2],True},False===True,False},{(EvenQ[#1]===EvenQ[#2]&)     [2,1],EvenQ[2]===EvenQ[1],{EvenQ[2],True},     {EvenQ[1],False},True===False,False},{(EvenQ[#1]===EvenQ[#2]&)     [1,2],EvenQ[1]===EvenQ[2],{EvenQ[1],False},     {EvenQ[2],True},False===True,False},{(EvenQ[#1]===EvenQ[#2]&)     [2,1],EvenQ[2]===EvenQ[1],{EvenQ[2],True},     {EvenQ[1],False},True===False,False},{{1},{2},{1},{2},{1}}},     {{{{First[{1,2,1,2,1}],1},EvenQ[1],False},If[False,1,2],2},2;;All;;2},     {{1},{2},{1},{2},{1}}[[2;;All;;2]],{{2},{2}}}      I've trimmed down to problem to the following:               lst = RandomInteger[{1, 2}, 10]     TakeWhile[lst, EvenQ]     TakeWhile[lst, OddQ]      One of the TakeWhile calls should always return some value. Yet they both give an empty list. This works fine on Windows, yet fails on Linux.


title: Trying to calculate a sum within a module - why is the iterator not creating integers?

text: Suppose I have the code:               #!/usr/local/bin/MathematicaScript -script     SetOptions[$Output, FormatType -> OutputForm];          foo[bar_?IntegerQ, baz_?IntegerQ] = bar;          M[g_?IntegerQ] = Module[         {sum},         sum = Sum[foo[i, g], {i, 1, 4} ];         N[sum]     ];          Print[M[1]]      Why does this output:               foo[1., 1] + foo[2., 1] + foo[3., 1] + foo[4., 1]      When simply changing the `g` to a `1` as following correctly interprets the iterator as an integer?               #!/usr/local/bin/MathematicaScript -script     SetOptions[$Output, FormatType -> OutputForm];          foo[bar_?IntegerQ, baz_?IntegerQ] = bar;          M[g_?IntegerQ] = Module[         {sum},         sum = Sum[foo[i, 1], {i, 1, 4} ];         N[sum]     ];          Print[M[1]]      This outputs (as expected):               10


title: Mathematica for linear algebra course?

text: I'm taking a linear algebra / matrix theory course and we are free to use any software we want, and will be "expected to use MATLAB or an equivalent" for homework. The professor and textbook (Applied Linear Algebra) prefer MATLAB, some students seem to like R, but I'm already familiar with Mathematica and have a student license. Are there any possible limitations of Mathematica to watch out for, if used as a learning device (i.e. not for work or intensive computation) for a linear algebra course? e.g. Are there some operations which the other software packages can do which Mathematica cannot out-of-the-box?


title: Is there a way to make an interactive plot so one can pan and zoom?

text: My googling efforts returned nothing so I thought I'd ask here. I often make a ListPlot[] with a huge array, and sometimes it has smaller features that I'd like to take a closer look at, but aren't very visible zoomed all the way out. Obviously I can just change the parameter PlotRange, but that's kind of cumbersome. Ideally, I'd like to be able to select a box around the part I want to zoom in on, and even more ideally maybe use my mousewheel to zoom in on where the cursor is, and be able to "grab" the plot to shift around where I'm looking at, when I'm zoomed in. Most programs that plot things have this functionality, so I'm guessing MM must too. It seems like I might be able to do something similar using Manipulate cleverly (like, at least make sliders to control the zoom and center), but I don't see how to do it easily. Is there any way?


title: Trouble with CDF on Mac OSX

text: My problem seems to be very strange. I've created a CDF file and am trying to upload it to a Google site, and I've been almost completely successful! My only problem is that I cannot correctly view/interact with the CDF on my Mac. If I view in Safari, I cannot interact with the CDF, and if I use Firefox I can, but the CDF flashes near the top and bottom. However, if I view the exact same webpage on my desktop (running Windows 7), everything works fine across Firefox and Chrome! It seems that I've narrowed the issue down to spacing. If I take my original `.nb` file and save it as a `.cdf`, I preserve the spacing that I inteded to have, but I encounter the website embedding issues. However, if I run the "deploy as HTML" option, my spacing shrinks and becomes more compact, and my Mac browsers can handle the CDF. Problem is, I want to keep the spacing. Also, I am trying to give the embedded CDF a pixel size of 800x800. Any ideas? The two files can be downloaded from here:   * Spaced webpage   * Compact webpage


title: Need tips on improving this directed graph

text: First we define a function that returns the least odd prime factor.               lopf[n_] := FactorInteger[n][[2, 1]]      Then we craft a routine that performs the 3x+1 steps using only primes               t = {};     z = 4;     While[z < 501,      y = Prime[z++];      prev = y;      u = {};      x = y;      While[x >= y,       prev = x;       x = lopf[3 x + 1];       u = AppendTo[u, {DirectedEdge[prev, x]}];       t = AppendTo[t, u];       ]      ]     t = Union[Flatten[t]];      Then we graph it               Graph[t]      ![Mathematica graphics](http://i.stack.imgur.com/SoXZ2.png) How can we structure this graph in a more civilized manner? I would like to have the first 5 primes {7,11,17,13,5} placed vertically down the center of a .pdf page and the remaining primes clustered about them. Also, Is there a way to use a rollover to identify a prime represented by a dot? This would be handy within an interactive document.


title: Numerically integrating solution obtained from NDSolve method

text: In the following example, $u(x)$ is found numerically using NDSolve method.                F = 1/1000         h = 12000/1000         d = 10/10         L = 1000         W = 3         phi[x_] :=           Piecewise[{{(1/2)*(1 - Tanh[((L*x)/(d))]),              x <= 1/2}, {(1/2)*(1 + Tanh[((L*(x - L/L))/(d))]), x > 1/2}}]         vE[x_] := x*(1 - x)*4         s = NDSolve[{u''[x] == (h*L*L/(d*d))*phi[x]*phi[x]*u[x] -               F*L*L*(1 - phi[x]), u[-W*d/L] == 0, u[1 + W*d/L] == 0},            u, {x, -W*d/L, 1 + W*d/L}, Method -> "StiffnessSwitching",            WorkingPrecision -> 40, InterpolationOrder -> All]         diff[x_] := (u[x] - vE[x])*(u[x] - vE[x])         Plot[Evaluate[{diff[x]} /. s], {x, W*d/L, 1 - W*d/L},           PlotRange -> All]      Which works perfectly. I need to see what is mean square error between obtained solution and another function $vE(x)$.               sum = 0;     Do[      first = W*d/L;      second = 1 - W*d/L;      {sum = sum + diff[first + (i/100)*(second - first)]},      {i, 0, 100, 1}]     Evaluate[sum]      but this gives only expression but not value. I think this is because $u(x)$ is obtained at discrete points only and is not defined on the points on which I have calculated error. I also tried using integration,               intVal = NIntegrate[({u[x]} /. s - vE[x])*({u[x]} /. s - vE[x]), {x,         W*d/L, 1 - W*d/L}]      but this gives long error message ending with,                "...is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing"      How can I evaluate this integral?


title: Is there a way to require confirmation for execution of certain cells?

text: Often I have Notebooks where I generate several images and export them into files. Now when I want to change one image, I'd like to just re-evaluate the complete notebook, however I generally do _not_ want all images to be exported again, but only selected ones. For this, it would be useful if I could make _some_ cells confirmation-only. Ideally it would highlight the cell in question, but that's optional (I can just look at which cell is the first unevaluated). It should however make sure that the cell is visible (because Mathematica dialogs unfortunately tend to _completely_ block the underlying notebook). It should ask me if I want to execute the cell, and if I say no, just skip it and continue at the next cell. Is this possible, and if yes, how? Bonus points if it doesn't trigger when doing Shift-Enter from _within_ the cell in question (because in that case, it's obvious that I want it executed)


title: How to Solve or LinearSolve $A = I$ matrix equation?

text: I'd like to solve this equation for $A = B$ where $B = I$, which represents 3 systems of 3 linear equations, for $a, b, c, d, e, f$, without writing `LinearSolve` 3 times. What is a simple way to accomplish this? Input:                  A = {        {a + b, -a + b, a + 2 b},         {c + d, -c + d, c + 2 d},         {e + f, -e + f, e + 2 b}        };     MatrixForm[A]     B = IdentityMatrix[3]     (*want to solve A == B, but probably wrong...*)     M = LinearSolve[A, IdentityMatrix[3]]     MatrixForm[M]


title: No Syntax Highlighting of Package Functions

text: Lately, my installation of Mathematica has decided not to highlight any symbols loaded from packages. The picture below is a good representation of this: ![enter image description here](http://i.stack.imgur.com/AJEEY.png) where after loading both `PhysicalConstants`` and `Units`` `BohrRadius`, `Meter`, and `Angstrom` should all be black. Yet, they retain their "unknown symbol" color. This occurs for all packages and is persistent across restarting the front-end and rebooting the entire system. Any suggestions for correcting this? I am running the student version of 8.0.4 on MacOS 10.6.8.


title: Non-linear trend reduction with missing data

text: How can I reduce a non-linear trend of some data series if there are parts of "no data", represented by the value 99999? For example:               data={{124.55,368.632}, {124.6,281.976}, {124.65,200.952}, {124.7,91.384}, {124.75,-60.424},     {124.8,-282.504}, {124.85,-541.448}, {124.9,-378.76}, {124.95,99999}, {125,99999},     {125.05,99999}, {125.1,99999}, {125.15,99999}, {125.2,99999}, {125.25,99999}, {125.3,99999},     {125.35,265.46}, {125.4,376.75}, {125.45,462.54},...,{178.95,284.46}}      Normally, I am successful in reducing the non-linear trend of the data via               lm = LinearModelFit[data, {a, a^2, a^3, a^4, a^5},a];     Do[aha = Last[Take[data, {m, m}]]; y = Last[aha];        x = First[aha]; new[m] = y - lm[x], {m, idim}];      but have no idea how to do the trend-reduction between those data gaps (i.e., outside of the regions with data = 99999). The position of those regions is not constant. After the reduction is performed, the position of the "no data"-values should be the same as before. Due to answer 1, unfortunately there is no periodically or cyclically behaviour in the data at all. Here, for example, is another, but complete data set:                {{100.00,       0.303999        },        {100.05,       0.303999        },        {100.09,       0.176000        },        {100.15,       0.303999        },        {100.20,       0.176000        },        {100.25,       0.303999        },        {100.30,       0.431999        },        {100.34,       0.431999        },        {100.40,       0.559999        },        {100.45,       0.687999        },        {100.50,       0.687999        },        {100.55,       0.943999        },        {100.59,        1.07200        },        {100.65,        1.20000        },        {100.70,        1.32800        },        {100.75,        1.32800        },        {100.80,        1.20000        },        {100.84,        1.20000        },        {100.90,        1.20000        },        {100.95,        1.07200        },        {101.00,        1.07200        },        {101.05,        1.07200        },        {101.09,        1.07200        },        {101.15,        1.07200        },        {101.20,        1.07200        },        {101.25,        1.07200        },        {101.30,       0.943999        },        {101.34,       0.943999        },        {101.40,       0.943999        },        {101.45,       0.687999        },        {101.50,       0.431999        },        {101.55,       0.303999        },        {101.59,       4.800009E-002   },        {101.65,      -8.000003E-002   },        {101.70,      -0.207999        },        {101.75,      -0.464000        },        {101.80,      -0.719999        },        {101.84,      -0.847999        },        {101.90,      -0.847999        },        {101.95,      -0.975999        },        {102.00,       -1.10400        },        {102.05,       -1.23200        },        {102.09,       -1.36000        },        {102.15,       -1.36000        },        {102.20,       -1.36000        },        {102.25,       -1.36000        },        {102.30,       -1.36000        },        {102.34,       -1.23200        },        {102.40,       -1.10400        },        {102.45,       -1.10400        },        {102.50,      -0.975999        },        {102.55,      -0.847999        },        {102.59,      -0.719999        },        {102.65,      -0.591999        },        {102.70,      -0.464000        },        {102.75,      -0.207999        },        {102.80,       4.800009E-002   },        {102.84,       4.800009E-002   },        {102.90,       0.431999        },        {102.95,       0.687999        },        {103.00,       0.943999        },        {103.05,        1.20000        },        {103.09,        1.32800        },        {103.15,        1.32800        },        {103.20,        1.58400        },        {103.25,        1.71200        },        {103.30,        1.84000        },        {103.34,        1.96800        },        {103.40,        2.09600        },        {103.45,        2.22400        },        {103.50,        2.22400        },        {103.55,        2.35199        },        {103.59,        2.35199        },        {103.65,        2.48000        },        {103.70,        2.48000        },        {103.75,        2.60800        },        {103.80,        2.86399        },        {103.84,        2.86399        },        {103.90,        2.86399        },        {103.95,        2.86399        },        {104.00,        2.99200        },        {104.05,        2.86399        },        {104.09,        2.73600        },        {104.15,        2.60800        },        {104.20,        2.60800        },        {104.25,        2.73600        },        {104.30,        2.48000        },        {104.34,        2.48000        },        {104.40,        2.48000        },        {104.45,        2.35199        },        {104.50,        2.22400        },        {104.55,        2.09600        },        {104.59,        1.96800        },        {104.65,        1.84000        },        {104.70,        1.84000        },        {104.75,        1.71200        },        {104.80,        1.58400        },        {104.84,        1.71200        },        {104.90,        1.45600        },        {104.95,        1.45600        },        {105.00,        1.32800        },        {105.05,        1.32800        },        {105.09,        1.07200        },        {105.15,        1.07200        },        {105.20,       0.943999        },        {105.25,       0.943999        },        {105.30,       0.943999        },        {105.34,       0.815999        },        {105.40,       0.559999        },        {105.45,       4.800009E-002   },        {105.50,      -0.336000        },        {105.55,      -0.975999        },        {105.59,       -1.36000        },        {105.65,       -2.00000        },        {105.70,       -2.51200        },        {105.75,       -2.89599        },        {105.80,       -3.02400        },        {105.84,       -3.02400        },        {105.90,       -2.89599        },        {105.95,       -2.12800        },        {106.00,       -1.23200        },        {106.05,      -0.464000        },        {106.09,      -8.000003E-002   },        {106.15,       0.303999        },        {106.20,       0.559999        },        {106.25,       0.687999        },        {106.30,       0.943999        },        {106.34,        1.07200        },        {106.40,        1.32800        },        {106.45,        1.45600        },        {106.50,        1.58400        },        {106.55,        1.58400        },        {106.59,        1.58400        },        {106.65,        1.58400        },        {106.70,        1.58400        },        {106.75,        1.45600        },        {106.80,        1.32800        },        {106.84,        1.45600        },        {106.90,        1.32800        },        {106.95,        1.32800        },        {107.00,        1.32800        },        {107.05,        1.20000        },        {107.09,        1.07200        },        {107.15,       0.943999        },        {107.20,       0.943999        },        {107.25,       0.815999        },        {107.30,       0.815999        },        {107.34,       0.687999        },        {107.40,       0.559999        },        {107.45,       0.559999        },        {107.50,       0.559999        },        {107.55,       0.431999        },        {107.59,       0.431999        },        {107.65,       0.559999        },        {107.70,       0.431999        },        {107.75,       0.687999        },        {107.80,       0.815999        },        {107.84,        1.07200        },        {107.90,        1.07200        },        {107.95,        1.32800        },        {108.00,        1.45600        },        {108.05,        99999.0        },        {108.09,        99999.0        },        {108.15,        99999.0        },        {108.20,        99999.0        },        {108.25,        99999.0        },        {108.30,        99999.0        },        {108.34,        99999.0        },        {108.40,        99999.0        },        {108.45,        99999.0        },        {108.50,        99999.0        },        {108.55,        99999.0        },        {108.59,        99999.0        },        {108.65,        99999.0        },        {108.70,        99999.0        },        {108.75,        99999.0        },        {108.80,        99999.0        },        {108.84,        99999.0        },        {108.90,        99999.0        },        {108.95,        99999.0        },        {109.00,        99999.0        },        {109.05,        99999.0        },        {109.09,        99999.0        },        {109.15,        99999.0        },        {109.20,        99999.0        },        {109.25,        99999.0        },        {109.30,        99999.0        },        {109.34,        99999.0        },        {109.40,        99999.0        },        {109.45,        99999.0        },        {109.50,        99999.0        },        {109.55,        99999.0        },        {109.59,        99999.0        },        {109.65,        99999.0        },        {109.70,        99999.0        },        {109.75,        99999.0        },        {109.80,        99999.0        },        {109.84,        99999.0        },        {109.90,        99999.0        },        {109.95,        99999.0        },        {110.00,        99999.0        },        {110.05,        99999.0        },        {110.09,        99999.0        },        {110.15,        99999.0        },        {110.20,        99999.0        },        {110.25,        99999.0        },        {110.30,        99999.0        },        {110.34,        99999.0        },        {110.40,        99999.0        },        {110.45,        99999.0        },        {110.50,        99999.0        },        {110.55,        99999.0        },        {110.59,        99999.0        },        {110.65,        99999.0        },        {110.70,        99999.0        },        {110.75,        99999.0        },        {110.80,        99999.0        },        {110.84,        99999.0        },        {110.90,        99999.0        },        {110.95,        99999.0        },        {111.00,        99999.0        },        {111.05,        99999.0        },        {111.09,        99999.0        },        {111.15,        99999.0        },        {111.20,        99999.0        },        {111.25,        99999.0        },        {111.30,        99999.0        },        {111.34,        99999.0        },        {111.40,        99999.0        },        {111.45,        99999.0        },        {111.50,        99999.0        },        {111.55,        99999.0        },        {111.59,        99999.0        },        {111.65,        99999.0        },        {111.70,        99999.0        },        {111.75,        99999.0        },        {111.80,        99999.0        },        {111.84,        99999.0        },        {111.90,        99999.0        },        {111.95,        99999.0        },        {112.00,       4.800009E-002   },        {112.05,      -8.000003E-002   },        {112.09,      -8.000003E-002   },        {112.15,      -8.000003E-002   },        {112.20,      -8.000003E-002   },        {112.25,      -8.000003E-002   },        {112.30,      -0.336000        },        {112.34,      -0.464000        },        {112.40,      -0.336000        },        {112.45,      -0.336000        },        {112.50,      -0.336000        },        {112.55,      -0.336000        },        {112.59,      -0.336000        },        {112.65,      -0.336000        },        {112.70,      -8.000003E-002   },        {112.75,       4.800009E-002   },        {112.80,       0.176000        },        {112.84,       0.303999        },        {112.90,       0.559999        },        {112.95,       0.687999        },        {113.00,       0.943999        },        {113.05,        1.07200        },        {113.09,        1.20000        },        {113.15,        1.45600        },        {113.20,        1.71200        },        {113.25,        1.96800        },        {113.30,        2.35199        },        {113.34,        2.86399        },        {113.40,        3.12000        },        {113.45,        3.37599        },        {113.50,        3.63200        },        {113.55,        3.88799        },        {113.59,        3.88799        },        {113.65,        3.88799        },        {113.70,        4.01600        },        {113.75,        3.88799        },        {113.80,        4.01600        },        {113.84,        3.88799        },        {113.90,        3.75999        },        {113.95,        3.50400        },        {114.00,        2.99200        },        {114.05,        2.48000        },        {114.09,        1.96800        },        {114.15,        1.58400        },        {114.20,       0.943999        },        {114.25,       0.431999        },        {114.30,      -0.336000        },        {114.34,      -0.847999        },        {114.40,       -1.23200        },        {114.45,       -1.61600        },        {114.50,       -2.00000        },        {114.55,       -2.25599        },        {114.59,       -2.38399        },        {114.65,       -2.51200        },        {114.70,       -2.64000        },        {114.75,       -2.89599        },        {114.80,       -3.02400        },        {114.84,       -2.89599        },        {114.90,       -2.76799        },        {114.95,       -2.64000        },        {115.00,       -2.38399        },        {115.05,       -2.25599        },        {115.09,       -2.00000        },        {115.15,       -1.74400        },        {115.20,       -1.48800        },        {115.25,       -1.23200        },        {115.30,      -0.975999        },        {115.34,      -0.719999        },        {115.40,      -0.464000        },        {115.45,      -0.207999        },        {115.50,      -0.207999        },        {115.55,       4.800009E-002   },        {115.59,       4.800009E-002   },        {115.65,       4.800009E-002   },        {115.70,       4.800009E-002   },        {115.75,      -8.000003E-002   },        {115.80,       4.800009E-002   },        {115.84,      -8.000003E-002   },        {115.90,      -0.207999        },        {115.95,      -0.464000        },        {116.00,      -0.719999        },        {116.05,      -0.847999        },        {116.09,      -0.975999        },        {116.15,       -1.10400        },        {116.20,       -1.36000        },        {116.25,       -1.23200        },        {116.30,       -1.23200        },        {116.34,       -1.23200        },        {116.40,       -1.10400        },        {116.45,       -1.10400        },        {116.50,       -1.23200        },        {116.55,       -1.10400        },        {116.59,       -1.10400        },        {116.65,       -1.23200        },        {116.70,       -1.23200        },        {116.75,       -1.36000        },        {116.80,       -1.10400        },        {116.84,      -0.847999        },        {116.90,      -0.847999        },        {116.95,       -1.10400        },        {117.00,       -1.23200        },        {117.05,       -1.36000        },        {117.09,       -1.36000        },        {117.15,       -1.23200        },        {117.20,       -1.10400        },        {117.25,       -1.10400        },        {117.30,      -0.975999        },        {117.34,      -0.847999        },        {117.40,      -0.591999        },        {117.45,      -0.719999        },        {117.50,      -0.719999        },        {117.55,      -0.591999        },        {117.59,      -0.719999        },        {117.65,      -0.719999        },        {117.70,      -0.719999        },        {117.75,      -0.719999        },        {117.80,      -0.591999        },        {117.84,      -0.591999        },        {117.90,      -0.591999        },        {117.95,      -0.464000        },        {118.00,      -0.464000        },        {118.05,      -0.207999        },        {118.09,      -8.000003E-002   },        {118.15,       4.800009E-002   },        {118.20,      -8.000003E-002   },        {118.25,      -8.000003E-002   },        {118.30,      -8.000003E-002   },        {118.34,      -8.000003E-002   },        {118.40,      -8.000003E-002   },        {118.45,      -8.000003E-002   },        {118.50,      -8.000003E-002   },        {118.55,       4.800009E-002   },        {118.59,       4.800009E-002   },        {118.65,       4.800009E-002   },        {118.70,       4.800009E-002   },        {118.75,       4.800009E-002   },        {118.80,       4.800009E-002   },        {118.84,       0.176000        },        {118.90,       0.176000        },        {118.95,       0.176000        },        {119.00,       0.176000        },        {119.05,      -8.000003E-002   },        {119.09,      -0.207999        },        {119.15,      -0.207999        },        {119.20,      -0.207999        },        {119.25,      -8.000003E-002   },        {119.30,      -8.000003E-002   },        {119.34,       4.800009E-002   },        {119.40,       0.303999        },        {119.45,       0.559999        },        {119.50,       0.815999        },        {119.55,        1.07200        },        {119.59,        1.32800        },        {119.65,        1.58400        },        {119.70,        1.58400        },        {119.75,        1.84000        },        {119.80,        2.09600        },        {119.84,        2.35199        },        {119.90,        2.48000        },        {119.95,        2.73600        },        {120.00,        2.99200        },        {120.05,        3.24800        },        {120.09,        3.24800        },        {120.15,        3.24800        },        {120.20,        3.12000        },        {120.25,        2.99200        },        {120.30,        2.73600        },        {120.34,        2.60800        },        {120.40,        2.60800        },        {120.45,        2.73600        },        {120.50,        2.73600        },        {120.55,        2.99200        },        {120.59,        3.12000        },        {120.65,        3.24800        },        {120.70,        3.24800        },        {120.75,        3.24800        },        {120.80,        3.12000        },        {120.84,        3.12000        },        {120.90,        2.86399        },        {120.95,        2.86399        },        {121.00,        2.73600        },        {121.05,        2.60800        },        {121.09,        2.48000        },        {121.15,        2.60800        },        {121.20,        2.60800        },        {121.25,        2.60800        },        {121.30,        2.86399        },        {121.34,        2.86399        },        {121.40,        2.99200        },        {121.45,        2.86399        },        {121.50,        2.99200        },        {121.55,        2.99200        },        {121.59,        2.86399        },        {121.65,        2.86399        },        {121.70,        2.86399        },        {121.75,        2.86399        },        {121.80,        2.99200        },        {121.84,        3.12000        },        {121.90,        3.37599        },        {121.95,        3.50400        },        {122.00,        3.63200        },        {122.05,        3.50400        },        {122.09,        3.50400        },        {122.15,        3.50400        },        {122.20,        3.50400        },        {122.25,        3.50400        },        {122.30,        3.50400        },        {122.34,        3.37599        },        {122.40,        3.24800        },        {122.45,        3.24800        },        {122.50,        3.12000        },        {122.55,        3.12000        },        {122.59,        3.24800        },        {122.65,        3.37599        },        {122.70,        3.37599        },        {122.75,        3.50400        },        {122.80,        3.75999        },        {122.84,        4.01600        },        {122.90,        4.27200        },        {122.95,        4.65599        },        {123.00,        4.65599        },        {123.05,        4.78399        },        {123.09,        5.04000        },        {123.15,        5.29600        },        {123.20,        5.55199        },        {123.25,        5.80799        },        {123.30,        5.80799        },        {123.34,        5.80799        },        {123.40,        5.93599        },        {123.45,        6.06400        },        {123.50,        6.19200        },        {123.55,        6.06400        },        {123.59,        5.93599        },        {123.65,        6.19200        },        {123.70,        6.57599        },        {123.75,        6.83199        },        {123.80,        6.57599        },        {123.84,        6.44800        },        {123.90,        6.32000        },        {123.95,        6.32000        },        {124.00,        6.32000        },        {124.05,        6.32000        },        {124.09,        6.19200        },        {124.15,        6.32000        },        {124.20,        6.19200        },        {124.25,        6.32000        },        {124.30,        6.19200        },        {124.34,        6.06400        },        {124.40,        5.93599        },        {124.45,        5.80799        },        {124.50,        5.42400        },        {124.55,        4.78399        },        {124.59,        4.27200        },        {124.65,        4.27200        },        {124.70,        4.40000        },        {124.75,        4.52799        },        {124.80,        4.14400        },        {124.84,        3.75999        },        {124.90,        3.50400        },        {124.95,        3.37599        },        {125.00,        3.37599        },        {125.05,        3.12000        },        {125.09,        2.48000        },        {125.15,        1.96800        },        {125.20,        1.58400        },        {125.25,        1.07200        },        {125.30,       0.815999        },        {125.34,       0.431999        },        {125.40,       0.176000        },        {125.45,      -8.000003E-002   },        {125.50,      -0.207999        },        {125.55,      -0.719999        },        {125.59,       -1.61600        },        {125.65,       -2.38399        },        {125.70,       -3.15200        },        {125.75,       -4.04800        },        {125.80,       -4.94400        },        {125.84,       -5.58399        },        {125.90,       -5.96800        },        {125.95,       -6.35200        },        {126.00,       -6.60799        },        {126.05,       -6.86399        },        {126.09,       -7.88799        },        {126.15,       -8.91200        },        {126.20,       -9.67999        },        {126.25,       -9.80800        },        {126.30,       -10.1920        },        {126.34,       -10.8320        },        {126.40,       -11.6000        },        {126.45,       -12.6240        },        {126.50,       -13.6480        },        {126.55,       -15.1839        },        {126.59,       -17.7440        },        {126.65,       -19.6640        },        {126.70,       -21.3279        },        {126.75,       -22.6080        },        {126.80,       -23.8880        },        {126.84,       -24.9119        },        {126.90,       -25.8080        },        {126.95,       -26.4480        },        {127.00,       -26.9600        },        {127.05,       -27.0880        },        {127.09,       -27.6000        },        {127.15,       -28.7519        },        {127.20,       -29.6480        },        {127.25,       -30.2880        },        {127.30,       -31.3120        },        {127.34,       -32.3359        },        {127.40,       -32.8479        },        {127.45,       -33.6160        },        {127.50,       -34.6400        },        {127.55,       -36.1760        },        {127.59,       -37.8400        },        {127.65,       -39.3759        },        {127.70,       -40.6559        },        {127.75,       -41.9360        },        {127.80,       -42.0640        },        {127.84,       -42.1920        },        {127.90,       -42.0640        },        {127.95,       -42.1920        },        {128.00,       -42.4480        },        {128.05,       -42.5760        },        {128.09,       -42.7040        },        {128.15,       -42.8320        },        {128.19,       -43.0880        },        {128.25,       -43.6000        },        {128.30,       -44.3680        },        {128.34,       -45.0080        },        {128.40,       -45.6480        },        {128.44,       -45.9040        },        {128.50,       -46.0319        },        {128.55,       -46.0319        },        {128.59,       -46.2879        },        {128.65,       -46.7999        },        {128.69,       -47.1839        },        {128.75,       -47.5679        },        {128.80,       -47.6959        },        {128.84,       -47.9519        },        {128.90,       -47.8239        },        {128.94,       -47.6959        },        {129.00,       -47.4399        },        {129.05,       -47.1839        },        {129.09,       -46.9279        },        {129.15,       -46.6719        },        {129.19,       -46.6719        },        {129.25,       -46.7999        },        {129.30,       -46.5439        },        {129.34,       -46.4159        },        {129.40,       -46.2879        },        {129.44,       -45.7760        },        {129.50,       -45.3920        },        {129.55,       -45.0080        },        {129.59,       -44.2400        },        {129.65,       -43.9840        },        {129.69,       -43.4720        },        {129.75,       -42.9600        },        {129.80,       -42.7040        },        {129.84,       -42.3200        },        {129.90,       -42.0640        },        {129.94,       -41.5520        },        {130.00,       -40.7839        }}


title: Is it possible to interact with an external program's command-line interface?

text: I am performing a calculation in _Mathematica_ which relies on calls to an external program that acts as a black box for calculating a function $f$, and I would like to know if it is possible for Mathematica to interact with a command-line interface that asks for user input. At the moment I am writing the arguments to my function $f$ in some external file `inputFile.txt`, and then running the external executable using one of the Run-related syntaxes:               inputstream=OpenRead["! ./external-program.x < inputFile.txt"]     ReadList[inputstream]      For the record, I'm running Mathematica 9 on Ubuntu 12.04. While this is a perfectly OK way to do things, it does mean I need to write to a file, have `external-program` read it, and then delete the file. For a long calculation with many such calls, it is overhead that I'd like to avoid. My external program does allow for command-line interaction, at least with a human user on a terminal, and this does not require piping in an already- written file. In practice, you run               ./external-program.x      on a command line, and you are then required to input the multiple arguments and press `Enter` after them. **Is it possible to automate this sort of behaviour from within _Mathematica_?**


title: Solution of numerical vector equation

text: Suppose I have a vector equation:               Y'[t]==rhs[Y[t]]       and               Y[0]==ConstantArray[0,n]      where "rhs[Y[t]]" is a black box function which numerically calculates a N-length vector given a N-length vector Y[t]. How can I solve such an equation in "NDSolve" ? Update: Say my rhs is :               rhs[{x_?NumberQ,y_?NumberQ]={x,y}


title: FeynArts not working properly

text: So I have installed all FeynArts folders (from 3.5 to 3.7) with FeynCalc 8.0.1., and none of it is working properly :\ First I load the path to specific FeynArts package (3.5 for instance), then, by:               << HighEnergyPhysics`FeynCalc`;      I load FeynCalc, and he says               Loading FeynCalc from C:\Users\*****\AppData\Roaming\Mathematica\Applications\HighEnergyPhysics     FeynCalc 8.1.0 For help, type ?FeynCalc, open FeynCalcRef8.nb or visit www.feyncalc.org     Loading FeynArts, see www.feynarts.de for documentation     FeynArts 3.5 patched for use with FeynCalc      So everything seems nice, right? Wrong! I even load FeynArts package, and no errors. But when I want to initialize the proper model I get:               In[9]:= InitializeModel[SM]          During evaluation of In[9]:=           During evaluation of In[9]:= loading generic model file C:\Users\*****\AppData\Roaming\Mathematica\Applications\HighEnergyPhysics\FeynArts-3.5\Models\Lorentz.gen          During evaluation of In[9]:= TagSetDelayed::tagnf: Tag FourVector not found in \!     \(TraditionalForm\`\(-\(TraditionalForm\`mom_\)\^\(TraditionalForm\`\(TraditionalForm\`\(Pattern[\(\(mu___, _\)\)]\)\)\)\)\)     . >>          During evaluation of In[9]:= Pattern::patvar: First element in pattern Pattern[b_,_] is not a valid pattern name. >>          During evaluation of In[9]:= Pattern::patvar: First element in pattern Pattern[b_,_] is not a valid pattern name. >>          Out[9]= $Aborted      And I can't do anything! I can plot topology, but I can't insert fields. I've been doing everything by the book :\ What seems to be wrong? :\


title: Programming Multipolar Expansions in Spherical Tensors

text: We have that a density matrix can be written in a basis of spherical tensors: $\rho =\sum _{K=0}^S\sum_{q=-K}^K \rho _{\text{Kq}}^{(S)} T_{\text{Kq}}^{(S)}$ for example for a 3x3 matrix, $S=1$, dimension of the matrix is $2S+1$, I will drop superscript (S) for simplicity $\rho =\rho_{00}T_{00}+\rho_{1-1}T_{1-1}+\rho_{10}T_{10}+\rho_{11}T_{11}+\rho_{2-2}T_{2-2}+\rho_{2-1}T_{2-1}+\rho_{20}T_{20}+\rho_{21}T_{21}+\rho_{21}T_{21}$ Now, I have a command that gives me the matrix representation of $T_{Kq}^{(S)}$ I want to know now how to make a program so that if you give as an imput the parameter S, they write you the resultant matrix dependent of the coefficients $\rho_{Kq}$. Also as $\rho_{Kq}=(-1)^q\rho_{Kq}^*$, this should also be implemented so that the final matrix depends on fewer parameters. **Edit:** Answering to Hector below. I have not programmed the command which gives $T_{Kq}^{(S)}$, to say the truth I have not made code in Mathematica never, and hardly ever elsewhere. Well command is sphtens[K,q,S] I've been thinking about the algorithm to get the desired result. To me the step are the following:   * Input the value of S   * Create a square matrix of zeros of dimension 2S+1. Call it $\rho$ for example.   * Create two loops one for the K and another one for the q for $K=0$ till $2S$ for $q=-K$ till $K$ if $q\geq 0$ $\rho=\rho + \rho_{Kq}$ \times sphtens[K,q,S] if not $\rho=\rho + (-1)^q\rho_{Kq}^* \times$ sphtens[K,q,S] end for end for Basically what I don't know is to write this in Wolfram language


title: import complete date string to mathematica

text: Based on an example from here I try to parse dates from a table including the time, but it fails. This is the modified example:               Export["test.dat", {{"2010-05-19 22:23:43", 17}, {"2010-05-20 22:23:43", 20}, {"2010-05-21 22:23:43", 19}}, "FieldSeparators" -> " "];          Import["test.dat", "Table", "DateStringFormat" -> {"Year", "-", "Month", "-", "Day", " ", "Hour", ":", "Minute", ":", "Second"}]      Does anyone understand why it doesn't work in analogy to the other case? thanks


title: Multiple simultaneous events in EventLocator method for NDSolve

text: I'm using NDSolve to integrate a system of ODEs, and EventLocator to stop the integration when it leaves a certain region in phase space. This works perfectly as it should. However, I've also added in another couple of events to Sow some bits of data (e.g, the locations of extrema of some variable). Almost all the time, this works perfectly as well. However, occasionally, both sorts of event occur simultaneously (or in the same integration step). In this case, it seems that only one of the event actions is evaluated. In particular, the integration isn't stopped when it should be. The documentation doesn't seem to mention this situation at all, so it's hard to know if this is a bug, or whether there's a good way round it. Can anyone throw some light on this? Thanks! Schematic form of the code:               NDSolve[         {ODEs for r and v}, {r, v}, {s, s0, \[Infinity]},                               Method -> {"EventLocator",  "Event" :> {edgeOfPhaseSpace,anotherEvent},            "EventAction" :> {Throw[{something;}, "StopIntegration"],                              doSomething;}}     ]      EDIT: The actual code I'm interested in is pretty complicated, with lots of spurious detail, so I've made a simpler model which illustrates concretely what I'm on about:               solution[theta_] := Module[{sol, , tf, tx = 0},       sol = First@NDSolve[          {x''[t] == 0, y''[t] == -1, x[0] == 0, y[0] == 0,            x'[0] == Cos[theta], y'[0] == Sin[theta]}, {x, y}, {t,            0, \[Infinity]},          Method -> {"EventLocator", "Event" :> {y[t], x[t] - 1/2},            "EventAction" :> {Throw[tf = t;, "StopIntegration"], tx = t;}            }, MaxStepSize -> 0.1];       sol~Join~{stopTime -> tf, xTime -> tx}]      This solves for a particle moving under gravity, sent at an angle theta, and stops the integration when the particle hits y=0 again. It also returns data about the time when the particle hits x=1/2. It works as expected most of the time. The exception is when the particle hits x=1/2 before it hits y=0, but in the same time step (e.g. theta=1.308). In this case the integration doesn't get stopped, but runs until max steps is reached.


title: See Local Variable at breakpoint within MODULE?

text: Within the debugger, can we watch local variables within a Module? As the screenshot shows, the “i” only display its global value (12) upon a message breakpoint. Is there a way to show its local value? ![enter image description here](http://i.stack.imgur.com/MeC8f.jpg)               Clear[i];      i = 12; f[] := Module[{i}, For[i = 1, i < 10, i++, Print[i]; Print[":\t"]; Print[i/0]]; ]; f[] Jimmy


title: Dynamic lists as function arguments

text: Suppose I have a function that requires a list is as input. I.e.               f[list_]:=DoSomethingWithList      Now, if I pass a variable as Dynamic like this               pts={{0.1,0.1} , {0.5,0.1}, {0.1, 0.5}};     f[Dynamic[pts]]      everything works as expected as long as I don't use parts of the list. If I use a part of a list then things no longer work as expected ( by me ). Another example               g[point_] := Slider2D[point]     p = {.1, .1}     g[Dynamic[p]]     Dynamic[p]      that works as expected, and this one               g[point_] := Slider[point[[1]]]     p = {.1, .1}     g[Dynamic[p]]     Dynamic[p]      that does not. **Question: What behaviour of Dynamic explains the above?**


title: Is it possible to make the Button execute two or more actions?

text: According to the help: > Button[label,action] Is it possible to make the button execute two actions?


title: NotePad++ User defined language

text: I know there is a xml file with language for Mathematica notebook (nb or m files). The link is http://sourceforge.net/apps/mediawiki/notepad- plus/?title=User_Defined_Language_Files Now I want a xml file to format not the code of nb file but what the user see when he opens the nb file in mathematica. Any idea before I customize this language??? Regards,


title: Finding the number of solutions to a diophantine equation

text: I want to count total number of the natural solutions (different from 0) of the equation $2x + 3y + z = 100$, but don't know how. How can I calculate it using _Mathematica_? I tried:               Solve[{2*x + 3*y + z == 100, x > 0, y > 0, z > 0}, {x, y, z}, Integers]


title: How to plot a "pressed" hemisphere

text: What I'd need is to draw an hemisphere of given radius but then it should have a reduced height. I don't mean a section of an hemisphere, I mean that the hemisphere should be pressed/flattened...so that it keeps on having the given radius but it is much less high, more flattened. I can't fine the right values or the relations between theta and phi to correctly use this formula:               SphericalPlot3D[5, {\[Theta], 0, Pi/5}, {\[Phi], 0, 2 Pi}, AspectRatio -> Automatic]      Any help? Remember, I don't want the radius/diameter to change, it only must be flattened.


title: How to obtain xyz-axes of same length?

text: > **Possible Duplicate:**   >  Controlling the 2D $x–y$ aspect ratio of a 3D plot I am plotting 1000 points in a 3-dimensional cartesian coordinate system, the plotting range for the x, y, z axes is set to {-1,1} respectively. Mathematica code:               points1 = RandomReal[{-1, 1}, {500, 3}];     points2 = RandomReal[{-1, 1}, {500, 3}];          sphere = Graphics3D[{Opacity[0.1], Sphere[{0, 0, 0}]}];     plot1 = ListPointPlot3D[points1, PlotStyle -> Green];     plot2 = ListPointPlot3D[points2, PlotStyle -> Black];     Show[{plot1, plot2, sphere}, Axes -> False,          PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}, AspectRatio -> Automatic]      ![plot](http://i.stack.imgur.com/0pxE3.png) Why does Mathematica plots axes of different lengths? Since I have given the same plotting range, I would expect and want to see a cube. How do I achieve this?


title: A weird thing about ListPlot3D

text: I plot the function f(x,y). x goes from 0 to 25 and y goes from 0 to 12. So, my plot should look elongated since the range of x is twice as long as the range of y. The problem is that, mathematica rescales the size of the axes, so that I see a square plot eventhough I see x->[0,25] and y->[0,12]. This is what I do: ListPlot3D[Abs[list], ColorFunction -> "Rainbow", AxesLabel -> {xx, yy, f(xx,yy)}, PlotRange -> All] Does anybody know how could I see an elongated plot? Thanks alot!


title: Taking class notes with a Mathematica Notebook

text: Dose anyone take notes in a technical class using a _Mathematica_ notebook? If anyone does, how does it compare to paper and are there useful commands? I have a hard time remembering ctrl/alt/esc commands. I normally type faster than I write but typing equations is a pain. Especially considering that _Mathematica_ (without Wolfram|Alpha) doesn't show the steps to a solution, which I sometimes want to copy down.


title: About the wrong evaluation of an integral

text: Here is an integral I've been studying in my research and I've just realized that Mathematica $8.0$ is unable to correctly compute it. I have 2 simple questions to ask: $1)$. Is my code below correct?                             Integrate[x^(a - 1)/(1 - x) - c x^(b - 1)/(1 - x^c), {x, 0, 1}]      $2)$. Are the newer Mathematica versions able to correctly compute it (how about W|A)? Please do not provide with mathematical solutions, I like to attend this part on my own.


title: Dynamically link cell content in Mathematica?

text: Is it possible to dynamically link the content of two cells? For example, can I set up a Notebook with two text cells that display the same value, and if the user types in one the other updates, etc.? I am familiar with Mathematica's dynamic functionality and at least the key concepts of the FrontEnd, and it seems like I should be able to assign a dynamic symbol to certain parts of a cell and just use that in an expression elsewhere, but I can't figure out how to programmatically access a cell's current content. The best I have been able to do is get a CellObject using `Cells[]`, e.g. where the first cell is a text cell containing "This is a test!", `Cells[][[1]]` gives               Cell[BoxData[     TemplateBox[{6849,"6849","\"Text\""},     "CellObject"]], "Output",     CellChangeTimes->{{3.5653627710636687`*^9, 3.5653627797706504`*^9}, {     3.5653628101959224`*^9, 3.5653628192779245`*^9}, 3.5653630492614017`*^9}]      but this doesn't include the cell's content.


title: Why is this semicolon in red?

text: I have a piece of code that works well, but when I put a semicolon after a plotting statement, the semicolon appears in red. What's the error? ![](http://i.stack.imgur.com/WXRUM.jpg)


title: Make mathematica treat $e_i^2$ as numeric

text: With `NumericQ[symbol] = True`, I can declare that a symbol is numeric. I want the expressions matching: $$e_{\text{i$\\_$}?\text{IntegerQ}}^2$$ to be treated as numerical expressions too.               e /: NumericQ[Subscript[e, i_?IntegerQ]^2] = True;      doesn't work. Also, I can't use `NumericFunction` because it's too restrictive. Is there something like `NumericPattern`?


title: How to speed up this TDSE code?

text: I'm trying to build a 1D time-dependent Schrodinger equation solver, using the Crank-Nicholson method. And I think the code is kind of working now, but the speed is still slow for me. Here is the code that calculates the wave function $\psi(x,t)$ at certain time given initial wave function $\psi(x,0)$ and a position dependent potential $V(x)$.               TDSE1[V_Function, Ct0_, {xmin_, xmax_}, {tmin_, tmax_, dt_}] :=       Module[{I0, Tmtx, Vmtx, Hmtx, Ct, Cls, dx, tls, xls,         N0Grid = Length@Ct0},       dx = (xmax - xmin)/(N0Grid - 1);       xls = Range[xmin, xmax, dx];       tls = Range[tmin + 0.5 dt, tmax, dt];       Tmtx = -(1/(2 (dx)^2))           SparseArray[{{i_, i_} -> -2, {i_, j_} /; Abs[i - j] == 1 -> 1}, {N0Grid, N0Grid}];(* kinetic energy *)       I0 = SparseArray[{{i_, i_} -> 1.}, {N0Grid, N0Grid}]; (*identity matrix*)       Ct = Ct0;       Vmtx = SparseArray[Band[{1, 1}] -> V /@ xls];(*potential energy*)       Hmtx = Tmtx + Vmtx;(*total Hamiltonian*)       Cls = Table[         Ct = LinearSolve[(I0 + I/2. (Hmtx)*dt), (I0 - I/2. (Hmtx)*dt).Ct]         , {t, tls}];       Cls       ]      and here is an example of calculating a wave function using this solver               Ct0 = Array[Exp[-#^2] &, 400, {-10, 10}] // N;(*initial wave function*)     Cls1 = TDSE1[Function[{x}, 0.5 x^2], Ct0, {-10, 10}, {0., 50., 0.01}]; // AbsoluteTiming     (*{1.329230,Null}*)          ListPlot[Re[Cls1[[1 ;; 1000 ;; 100]]], Joined -> True, PlotRange -> All]      ![enter image description here](http://i.stack.imgur.com/9PUbp.jpg) And I'm pretty satisfied with this speed. However, I'm more interested in a time-dependent potential, ie, $V=V(x,t)$, than a time independent one. So I changed the code a little bit so that at every time step, it recalculates the potential `Vmtx` at that time.               TDSE2[V_Function, Ct0_, {xmin_, xmax_}, {tmin_, tmax_, dt_}] :=       Module[{I0, Tmtx, Vmtx, Hmtx, Ct, Cls, dx, tls, xls,         N0Grid = Length@Ct0},       dx = (xmax - xmin)/(N0Grid - 1);       xls = Range[xmin, xmax, dx];       tls = Range[tmin + 0.5 dt, tmax, dt];       Tmtx = -(1/(2 (dx)^2))           SparseArray[{{i_, i_} -> -2, {i_, j_} /; Abs[i - j] == 1 -> 1}, {N0Grid, N0Grid}];        I0 = SparseArray[{{i_, i_} -> 1.}, {N0Grid, N0Grid}];       Ct = Ct0;       Cls = Table[         Vmtx = SparseArray[Band[{1, 1}] -> (V[t] /@ xls)];         Hmtx = Tmtx + Vmtx;         Ct = LinearSolve[(I0 + I/2. (Hmtx)*dt), (I0 - I/2. (Hmtx)*dt).Ct]         , {t, tls}];       Cls       ]      and the function call is also changed slitly               Cls2 = TDSE2[Function[{t}, Function[{x}, 0.5 x^2]], Ct0, {-10, 10}, {0., 50., 0.01}]; // AbsoluteTiming     (*{9.446716, Null}*)      but now it is about **7X slower** than before! I tried to compile the function inside the module, replacing the `Vmtx` line by something like               Vmtx = SparseArray[Band[{1, 1}] -> (VCpf[t, xls])];      where VCpf is a compiled function defined by               VCpf = Compile[{{t, _Real}, {x, _Real}}, V[t][x], RuntimeAttributes -> {Listable}]      and that makes the problem even worse, with about **20X** slower than `TDSE1`. **So my question is, is it possible to speed up`TDSE2` to get about the same speed as `TDSE1` or even faster?**


title: FrameTicks and GridLines in DateListPlot

text: I would like to know what is the best way to configure one `GridLine` for the hour in `LightGray` and another for the days in `Gray`. In my tests, the `FrameTicks` are superposed by the GridLines and I don't know how to control the color. The data label should appear just for days. Here is my attempt that I consider very clumsy.               data={#,RandomVariate[NormalDistribution[0,1]]}&/@RandomReal[{3564979299,3565355902},1000];          DateListPlot[data        ,AspectRatio->0.2        ,DateTicksFormat->{"Day","/","Month"}        ,GridLines->{{#,LightGray}&/@DateRange[{2012,12,12},{2012,12,31},"Hour"],None}        ,FrameTicks->{Automatic,{DateRange[{2012,12,12},{2012,12,31},"Day"],None}}        ,Epilog->{Gray,Line[{{#,Min@data[[All,2]]},{#,Max@data[[All,2]]}}]&/@AbsoluteTime/@DateRange[{2012,12,12},{2012,12,31},"Day"]}     ]      ![enter image description here](http://i.stack.imgur.com/cMXPW.png) I don't like to use `Epilog` for that. It would be nice if I could have subticks between the days ticks too, one subtick for each hour, with no label.


title: How to avoid page break appearing between the table title and the table in Mathematica?

text: I'm wring a thesis which has quite amount of tables. When the thesis gets printed, Mathematica often breaks pages between the table title and table. I would like to keep the title and table in the same page. How can I do so by editing the Stylesheet? Details regarding this problem: First I chosen the initial style sheet to be Artical -> Preprint. Then I selected "TableTitle" for the cell style of the title, and self-defined "TableText" for the cell style of the table. The self- defined "TableText" basically inherits the definition of the existing cell style "Text" as follows:               Cell[StyleData["TableText", StyleDefinitions -> StyleData["Text"]], TextAlignment->Center,      MenuSortingValue->1911,      FontSize->12]      The problem is even if I group the cells of titles and tables, Mathematica still often breaks the page between the cell "TableTitle" and the cell "TableText" when the Screen Environment is in Printout and I choose Printing Settings -> Show Page Breaks. I wouldn't like to add the page break lines manually. I'm wondering how to tell Mathematica not to add the page break lines between the cells "TableTitle" and the cells "TableText". Is it possible to do so by adding something to the StyleData of "TableTitle" in the environment of "Printout":               Cell[StyleData["TableTitle", "Printout"],      PageWidth->PaperWidth,      Hyphenation->False,      FontSize->12]      I tried to add `PageBreakBelow -> False` but it did not work.


title: How can I avoid a scoping problem when differentiating?

text: I simplify my real problem as follows: I define a rule function as               Clear[rule];      rule[i_] := tt -> i;      the real rule function is not this simple. I define a matrix function as               Clear[hh];     hh[x_, y_, i_] := {{tt, x}, {y, 1}}/. rule[i];      I want to define a function `hhpar` that will differentiate `hh` with respect to `x`, so I write               Clear[hhpar];     hhpar[x_, y_, i_] := D[hh[x, y, i], x];      This doesn't work and I know why. But I still can't figure out a way to write a proper `hhpar`. How would I do that?


title: How to format dynamic InputField value using NumberForm?

text: Background: I want all numbers in `InputField`'s displayed as `NumberForm[num,2]`; Now, consider the following the snippet of code:                latsy = 1.1;      latparshx = 32;      piet = NumberForm[latsy*Tan[latparshx*Pi/180], 2];      InputField[Dynamic[piet], FieldSize -> 3]      This code produces an inputfield with a number between double quotes, which is not what I expected. I basically want 0.69 displayed. **Question: How can I ( what is the best way to ) control the display format of a number in an InputField ?** EDIT: The InputField resizes itself on the Panel it is positioned on and thus messes up the other GUI elements.


title: Correct way to compare arrays and do conditional evaluations

text: I would like to compare two arrays a=: ![enter image description here](http://i.stack.imgur.com/BR6jR.png) and b= ![enter image description here](http://i.stack.imgur.com/DehGc.png) and get: ![enter image description here](http://i.stack.imgur.com/9S737.png) using:               (b/.(b_?Positive->a+b))//MatrixForm       but this doesn't seem to work? Can anyone tell me what I am doing wrong? Basically the conditional only updates b to be sum of a and b only when a non zero is detected in b or else it should do nothing, but can't work out why it is not summing. Or must I first flatten it?


title: Applying an ArrayPlot as a texture to the surface of a cylinder

text: I would like to apply a matrix plot to the surface of a 3D cylinder. The matrix plot is the output from a custom cellular-automata, and it would be nice to see the lefthand side of the plot connected to the righthand side. ### Edit This is the solution I ended up using:               mrt =       ArrayPlot[CellularAutomaton[30, RandomInteger[{0, 1}, 100], 30],         Frame -> False,         ImagePadding -> 0,         PlotRangePadding -> 0];     ParametricPlot3D[{Sin[t]/2Pi, Cos[t]/2Pi,u},{t,0,2Pi},{u,0,2},       Boxed -> False,       Axes -> False,       PerformanceGoal -> "Quality",       ImageSize -> {300, 300},       Lighting -> "Neutral",       PlotStyle -> Texture[mrt],       Mesh -> None,       ViewPoint -> {0, 3, 1}]      ![enter image description here](http://i.stack.imgur.com/IKy4B.png)


title: Plotting a multivariable function

text: m[x_, y_] :=       0.9*Exp[-((x - 1)^2 + (y - 1)^2)] +        0.5 Exp[-(3^2 ((x - 2.5)^2 + (y - 1.5)^2))]      I'm trying to create a 3d plot for the function above. I tried `Plot3D`, but all i got was a blank. my plot attempt : `Plot3D[m, {x, -1, 1}, {y, -1, 1}]`


title: Retrieve values of InterpolatingFunction

text: While analyzing a large system of ODE's, I defined a particular ratio `p`, which contains some variables that are represented by `InterpolatingFunction`s by `NDSolve`.               p = Sum[(c[i][t] + ac[i][t] + ct[i][t] + bmct[i][t] +       ambmct[i][t]) i, {i, 0, 6}]/(6*0.58)      To plot `p`, I put `p` with a transformation rule inside of a `Plot[]`, like so:               Plot[p/.tsol,{t, 0, timeduration}]      where `tsol` stores `NDSolve`'s output. Plotting of `p` works fine and yields a nicely oscillating plot. How do I extract values of this new InterpolatingFunction `p` for certain time points `t`? Ironically enough, I do manage to calculate the derivative of this function, along with the points where the slope is 0. This more trivial looking problem, however, is giving me headaches... Thanks!!


title: How do I combine the data from two tables according to a rule of my own devising?

text: I have two matrices a = m x 5 and b =m x 5 (m is large, say 1,000) which are already sorted as below: ![enter image description here](http://i.stack.imgur.com/BRXlm.png) How to generate a new matrix c = m x 5 which consists: Column 1: exact replica of Column 1 of matrix a.   Column 2: Depends on non-zero elements of b as shown   so that it is adjusted by it's left hand side row of a - b + present row.   Zeros are not evaluated. (example: 3.7107 - 2.96856 + 23.2988 = 24.0409 ) Columns 3 4 and 5, not sure yet so maybe start off with a SparseArray of m x 5? But most likely to be an extension of Column 2. i.e. Column 3,4 and 5 will be also adjusted once I have worked out how they need to adjusted by. EDITED 31/12/2012 03:25am UK time: Solution from @halirutan is partially correct because my input matrix a: ![enter image description here](http://i.stack.imgur.com/q0Xli.png) and matrix b: ![enter image description here](http://i.stack.imgur.com/qBEU2.png) gives matrix c: ![enter image description here](http://i.stack.imgur.com/4yvYy.png) Not sure how to do conditional check for column b to be non-zero before evaluating?


title: MapAt and generic Functions on Associations and Datasets

text: These are distinct but related questions about mapping functions to Associations and Datasets. Given:               assoc = <| a -> 1, b -> 2, c -> 3|>       And               data =       Dataset@{<| a -> 1, b -> 2, c -> 3|> , <|a -> 4, b -> 5, c -> 6|>}      Re MapAt:               MapAt[Framed, Key[b]][assoc]       ![enter image description here](http://i.stack.imgur.com/WMKvE.jpg) Although Dataset is not explicitly mentioned in the doc page for MapAt, it's supposed to apply to generic expressions. However:               MapAt[Framed, Key[b]][data]      ![enter image description here](http://i.stack.imgur.com/cvR8u.png) Next, consider mapping over a named `Key` with this syntax:               data[All, {Key[b] -> Framed}] // Normal      ![enter image description here](http://i.stack.imgur.com/aOdkY.png) Why don't the following variations work on `Dataset`?               data[All, Key[b] -> Framed] // Normal      ![enter image description here](http://i.stack.imgur.com/wpseG.png)               data[All, Key[b] -> Framed[#] &] // Normal      ![enter image description here](http://i.stack.imgur.com/3H6Em.png) Finally, back to Association:               assoc[Key[b] -> Framed] // Normal      ![enter image description here](http://i.stack.imgur.com/JvPh5.png)


title: How to export 3D plot, without losing the specified view of rotation?

text: Sorry I am not sure if I got anything wrong with this version of Mathematica and Mac OS X i am running. But every time I export a 3D graph, to png or tiff, I lost the view angle, view vector viewpoint information immediately. To let you know what I meant, here is a simple code: I typed:               x = RevolutionPlot3D[Sqrt[((t/5)^2 - 1)*2], {t, 5, 20}]      And I got a plot               out[1]=       ![Original Plot](http://i.stack.imgur.com/Lv5O3.png) Then I manually rotate the plot so that it looks better, for example like this: ![Manually rotated view](http://i.stack.imgur.com/S5gyA.png) Ok, now, I used Export to export it to png:               Export["test.png", %];      What I got is pathetically, the un-rotated png plot!: ![Exported png](http://i.stack.imgur.com/2r6GR.png) This is driving me crazy and dead.. I also tried to set Viewpoint and view vector, stuff to the code, it doesn't work for me either. I also tried Export["test.png",x] too, no luck. I understand I could easily right-click to save, But I need a background-none option to make the graph transparent.. Can any one confirm (this bug?) or i am doing something stupidly wrong? I checked the documentation and googled for 1 hour, nothing found. So the question is, how can I export the graph as it is shown on the notebook (if I can not, then what's the point of allowing us to rotate it..)


title: Finding the maximum of a gradient vector

text: Im trying to find the maximum of my gradient vector G[x,y], I've tried several options including FindMaximumValue, FindMaximum etc. but i couldn't find it. The full function is shown below, any help would be greatly appreciated               G[x_,y_]:= {-5.4 E^(-2.25 ((-4 + x)^2 + (-2.5 + y)^2)) (-4 + x) -        6.4 E^(-4 ((-3.5 + x)^2 + (-1.5 + y)^2)) (-3.5 + x) -        8 E^(-4 ((-3 + x)^2 + (-3.5 + y)^2)) (-3 + x) -        9. E^(-9 ((-2.5 + x)^2 + (-1.5 + y)^2)) (-2.5 + x) -        5.5125 E^(-3.0625 ((-2 + x)^2 + (-3 + y)^2)) (-2 + x) -        1.8 E^(-(-1 + x)^2 - (-1 + y)^2) (-1 + x) -        30. E^(-25 ((-0.75 + x)^2 + (-2 + y)^2)) (-0.75 +           x), -8 E^(-4 ((-3 + x)^2 + (-3.5 + y)^2)) (-3.5 + y) -        5.5125 E^(-3.0625 ((-2 + x)^2 + (-3 + y)^2)) (-3 + y) -        5.4 E^(-2.25 ((-4 + x)^2 + (-2.5 + y)^2)) (-2.5 + y) -        30. E^(-25 ((-0.75 + x)^2 + (-2 + y)^2)) (-2 + y) -        6.4 E^(-4 ((-3.5 + x)^2 + (-1.5 + y)^2)) (-1.5 + y) -        9. E^(-9 ((-2.5 + x)^2 + (-1.5 + y)^2)) (-1.5 + y) -        1.8 E^(-(-1 + x)^2 - (-1 + y)^2) (-1 + y)}


title: How can I convert a formatted text cell to latex code?

text: I have a formatted text cell, I want to export it as latex. How can I do that? Since copy as LaTeX doesn't work, I thought of pasting it into a string and exporting, but it's a no go:                ExportString["Let M be a TM and let \!\(\*FormBox[\(A \[SubsetEqual] \     \*SuperscriptBox[\({0, 1}\), \(*\)]\),     TraditionalForm]\). We say that \!\(\*FormBox[\(M decides A\),     TraditionalForm]\) if \!\(\*FormBox[\(\[ForAll] \\\ x \[Element] \     \*SuperscriptBox[\({0, 1}\), \(*\)]\),     TraditionalForm]\), \!\(\*FormBox[\(x \[Element] A\\\  \[Implies] \\\ \     M(x) = 1\),     TraditionalForm]\), \!\(\*FormBox[\(x \[NotElement] A\\\  \[Implies] \     M(x) = 0. \),     TraditionalForm]\) We say that  \!\(\*FormBox[\(A \[SubsetEqual] \     \*SuperscriptBox[\({0, 1}\), \(*\)]\),     TraditionalForm]\) is \!\(\*     StyleBox[\"decidable\",\nFontWeight->\"Bold\"]\) if there is a TM \     that accepts it.", "TeX"]


title: Docked Cell lesson chooser

text: I have a question about creating a docked cell that will let me choose files. This is just as much a "design" question as a Mathematica question. I'm a math teacher and I want to bundle a bunch of Mathematica lesson content into a unit. I have a whole bunch of files that make up a unit. We'll call them simply Lesson1.cdf, Lesson2.cdf, Lesson3.cdf etc. We'll say there are 10 of them. I wanted to build the unit in smaller pieces , since it seems logical not to have a huge amount of info in one file. So, create in pieces. I can see how to use ActionMenu to do this... at least it's one way, not saying it's the best way!!               b1 = ActionMenu["Open a lesson",        {"Lesson 1" :>          NotebookOpen[FileNameJoin[{NotebookDirectory[], "lesson1.cdf"}]],        "Lesson 2" :>          NotebookOpen[          FileNameJoin[{NotebookDirectory[], "lesson2.cdf"}]]},       Appearance -> "PopupMenu"       ]      It works... I then create a docked cell in the Notebook...                   SetOptions[SelectedNotebook[],        DockedCells -> Cell[BoxData[ToBoxes[b1]], "DockedCell"]];      This too works... so far so good! So , sadly, that's as far as my knowledge will take me. I tried using hyperlinks to open the lesson notebooks from a main document, but it seemed really cluttered , having more than one notebook open on screen. This method seems potentially better, but can I have it close the "calling" notebook when it opens the selected lesson? Would there be an easy way to write this docked cell to all the other lessons? (Yes, I think I could do that by just getting a list of lesson files and setting their options for docked cells) Finally, this way of opening the notebooks generates the "unsafe" content warning. That will be bad since then every lesson notebook will have this issue. Way over my depth here, but hoping someone can give some "design" advice for packaging up a bunch of notebooks into a nice unit, and being able to get from one to another easily. My students do not have Mathematica and are using CDFPlayer to view my lessons. It's interesting that bundling a "NotebookOpen" inside a Button does NOT trigger the warning, which is a big thing. So, buttons aren't as elegant, but they do work and allow students to move between lessons with no issues. ![Current Progress with buttons](http://i.stack.imgur.com/z2mpR.png) But I know that can't be right... I've probably managed to add that path to my TrustedDirectories or something... it's a real nuisance not to be able to do this in a straightforward way...


title: Nested NIntegrate

text: Suppose that we have the given simple integral expression $$ \int_{-5}^{5} x \int_{-\infty}^{x} e^{\int_{0}^{z} -y dy} dz dx $$ Writing this out in _Mathematica_ we obtain:               Integrate[x Integrate[Exp[Integrate[-y, {y, 0, z}]], {z, -\[Infinity], x}], {x, -5., 5}]     30.0795      ### Question: Is it possible to do a numerical integration on this expression by using `NIntegrate`? A very naive attempt gives us the following errors:               NIntegrate[x NIntegrate[Exp[NIntegrate[-y, {y, 0, z}]], {z, -\[Infinity], x}], {x, -5, 5}]      > NIntegrate::nlim: y = z is not a valid limit of integration Notice that we want everything to be a numerical integration, this includes the inner integrals. The problem is that one of the `NIntegrate`s is an argument to the exponential function and this does not allow us to write the double integral with only one `NIntegrate` as mentioned in here ### Motivation I'm trying to evaluate an expression that is too complicated for Mathematica to do symbolically and it is composed on integrals of the kind mentioned above.


title: Plotting a region with thin cusps in high-definition via RegionPlot

text: I want a high-definition picture the real solutions $(s_1,s_2,s_3)$ of the system of inequalities $3 s_1^2 < (s_2 - s_3)^2 + 2 s_1(s_2 + s_3)\\\ 3 s_2^2 < (s_1 - s_3)^2 + 2 s_2(s_1 + s_3)\\\ 3 s_3^2 < (s_1 - s_2)^2 + 2 s_3(s_1 + s_2)$ such that $s_1+s_2+s_3=1$ and $s_1>0$, $s_2>0$, $s_3>0$. I would also like to emphasize the solutions for which at least two $s_i$'s are equal. For this, I wrote the following code:               s1 = r/Sqrt[2] - s/Sqrt[6] + 1/3;(*Parametrization of plane s1+s2+s3=1 *)     s2 = -r/Sqrt[2] - s/Sqrt[6] + 1/3;     s3 = 2 s/Sqrt[6] + 1/3;          reg = RegionPlot[6 r (Sqrt[2] + 3 r - 4 Sqrt[3] s) < 1 + 2 Sqrt[6] s + 6 s^2 && 18 r^2 < 1 + 2 Sqrt[6] s + 6 s^2 + 6 r (Sqrt[2] - 4 Sqrt[3] s) && 4 Sqrt[6] s + 30 s^2 < 1 + 18 r^2, {r, -Sqrt[2]/2, Sqrt[2]/2}, {s, -Sqrt[6]/6, Sqrt[6]/3}, PlotStyle -> LightGray, Axes -> False, Frame -> None, PlotPoints -> 500];          boundary = Plot[{Sqrt[3] r + Sqrt[6]/3, -Sqrt[3] r + Sqrt[6]/3, -Sqrt[6]/      6}, {r, -Sqrt[6]/3, Sqrt[6]/3}, AspectRatio -> 1, AxesOrigin -> {0, 0}, Axes -> False, PlotStyle -> {{Black, Dashed}}];          line1 = Plot[{r/Sqrt[3]}, {r, -(1/(10 Sqrt[2])), 1/(2 Sqrt[2])}, AspectRatio -> 1, AxesOrigin -> {0, 0}, Axes -> False, PlotStyle -> {{Black}}];     line2 = Plot[{-(r/Sqrt[3])}, {r, -(1/(2 Sqrt[2])), 1/(10 Sqrt[2])}, AspectRatio -> 1, AxesOrigin -> {0, 0}, Axes -> False, PlotStyle -> {{Black}}];     line3 = ParametricPlot[{0,s}, {s, -(Sqrt[(2/3)]/5) - Sqrt[3/2]/5, -(Sqrt[(2/3)]/5) + Sqrt[3/2]/5}, AspectRatio -> 1, AxesOrigin -> {0, 0}, Axes -> False, PlotStyle -> {{Black}}];     pic = Show[reg, boundary, line1, line2, line3];     Export["pic.pdf", pic];      obtaining the following image: ![Image](http://i.stack.imgur.com/SZVYn.gif) The region above should have the obvious symmetries, given by rotations of $120^\circ$. However, my plot looks slightly non-symmetric, since the lower cusp seems to "stop" before the top cusps. The cusps go up to the boundary of the outer triangle, but the plots don't quite make justice to that -- unless one adds a thick boundary to the region, which I don't really like (since it is supposed to represent an _open_ set). Although raising the PlotPoints to 500 rendered it a lot better, it still looks a bit strange when it is zoomed in. I tried raising PlotPoints to more than 500, but it froze my computer and I had to forcefully restart the machine (3 attempts, ranging between 550 and 1000). I would like to know if there is a better way to make the above plot, that is, something that makes Mathematica **draw the cusps more accurately, arriving all the way to the boundary, and such that all of them look the same**. Eventually I want to export it as a PDF.


title: Importing an mx file into a context

text: Consider the following simple code which dumps the global context:               var = 5;     DumpSave["test.mx", "Global`"];      Now, in a new notebook, I would like to import var in another context. Trying               Begin["myContext`"]     << "test.mx"     End[]      does not work because var remains in the global context. Is there a solution? Thank you.


title: Represent more nested dataset with the same color in the PieChart

text: I have multiple dataset that I want to plot in PieChart, as in               PieChart[{{2, 2}, {1, 2, 4}}, ChartLayout -> "Stacked"]      Now here is the catch: I want the color of the chart to be "similar" if the corresponding data belong to the same set. In my example, the regions corresponding to `{1,2,4}` would have different shades of Blue, while the ones relative to `{2,2}` would be plotted with different intensities of Red. Finally, since the original data set is more nested than this one, it would be nice to be able to specialize such color function further I have tried with ColorFunction -> Function[x, ...] but I don't manage to have info about the originating dataset. Example or more nested data set:               {{2, 2}, {1, 2, {3,1}}}     {{2, 2}, {1, 2, {{2,1},1}}}


title: List manipulation, replace a value

text: I have the following list:               AA= {300., 150., 100., 76.8421, 64.0909, 55.567, 49.1935, 44.2262,          40.2247, 36.9355, 34.1667, 31.8138, 29.7887, 28.0087, 26.4537,          25.0612, 23.8186, 22.7059, 21.6854, 20.7663, 19.9265, 19.1519,          18.4323, 17.7739, 17.1672, 16.6007, 16.0648, 15.5605, 15.098}      If a value of AA is higher than 100, I want replace this value with a an arbitrary value, e.g. 50. Has anyone any idea how to do this?


title: Replacing all values in a table > $T$

text: I want to generate a table of Euclidean distances from the points in a list to a given point, e.g.:               Table[EuclideanDistance[MyList[[i]], c], {i, 1, Length[MyList]}]      Moreover, when `EuclideanDistance` returns a value greater than $T$, I'd like to replace that value with a given real number $R$. Is there a simple way to do this?


title: How to change specific values in a List

text: In a list `lst` I want to change all values > 255 to 255. Why is this code not working?               lst= {336, 315, 395, 337, 411, 309, 408, 338, 576, 377, 508, 386, 545, \     477, 453, 424, 425, 286, 363, 248, 298, 268, 221, 162, 184, 121, 164, \     124, 161, 109, 165, 150, 183, 111, 154, 132, 136, 88, 123, 388, 387, \     382, 375, 340, 325, 374, 324, 372, 295, 398, 361, 547, 418, 483, 381, \     517, 465, 454, 432, 414, 288, 342, 241, 281, 261, 218, 172, 165, 127, \     532, 392, 397, 345, 403, 375, 400, 342, ...}          inf = Flatten@Position[lst, _?(# > 255 &)];     ReplacePart[lst, inf -> 255]      It seems that it doesn't effect the list at all. Thanks a lot for opening my eyes...


title: Replacing values above a threshold with 1

text: I have a list with some values and I want to replace a value which is greater than 1 with 1 otherwise keep the value. In this case 10562:                  list[[1]]= {0.61975, 10562., 0.43274, 0.15068, 0.13703, 0.057564}      I tried this approach:               Table[If[list[[1, x]] > 1, list[[1, x]] = 1, list[[1, x]]], {x,        1, Length[list[[1]]]}]      It works, but I'm wondering if there is a much simpler solution with mathematica. Can anybody help me out?