Help using NIntegrate

I need some help with NIntegrate. I pasted the code that I wrote below; I know that up to "de" is correct. What I would like to do is NIntegrate de w.r.t phi{0,0.1} and curlE{-10,10}. The final answer should be just a number, but I am not sure if I am going about this wrong.                e = 1.60217657*10^-19;      n = 10^-10/e;      r = 1.5;      sigma = 50*10^-6;      p[phi_] := (r*phi^3)/(24 sigma);      g[curlEprime_] := Exp[-((curlEprime)^2/2)];           gSomething[phi_, curlE_] :=  With[{p = p[phi]}, p^(-(1/3)) (g[curlE - p] - g[curlE - 4             p]) + NIntegrate[     1/(curlE - curlEprime)^(1/3) g'[curlEprime], {curlEprime, curlE - p, curlE}]]           de[phi_, curlE_] := (2*e^2*n)/(3^(1/3)*Sqrt[2 Pi]*r^(2/3)*      sigma^(4/3))*gSomething[phi, curlE]           de1[phi_, curlE_] := NIntegrate[de[phi, curlE], {phi, 0, 0.103}]           de2[curlE_] := NIntegrate[de1[curlE], {curlE, -1, 1}]      So, at the end de2 should give a numerical value.


How to get output from standard error in command line?

I'm trying to run some external command line program in Mathematica, and I have problem getting the output. For example,               Import["!echo hello world\nexit\n", "Text"]     (*"hello world"*)      run echo and get the output. However this doesn't work for me               Import["!g++ -v", "Text"]      I only get an empty line. In version 10, there is the `RunProcess` function which seems to work               RunProcess[$SystemShell, "StandardError", "g++ -v      exit      "]          (*     Configured with: --prefix=/Library/Developer/CommandLineTools/usr \     --with-gxx-include-dir=/usr/include/c++/4.2.1     Apple LLVM version 6.0 (clang-600.0.51) (based on LLVM 3.5svn)     Target: x86_64-apple-darwin14.0.0     Thread model: posix     *)      My question is, can we do the same thing in version 9, using other functions ?


DensityPlot Increase Information

I am trying to make a density plot in Mathematica, however the distribution of the plot is not as visible as I would like. I plotted the same function in python and it contains a greater visible range of information. This can be seen in the first picture below. ![enter image description here](http://i.stack.imgur.com/0t5ES.png) When I try the same plot in Mathematica some information is lost. I cant see the decrease in intensity on either side of the central bright spot. I am using PlotRange "All" and I can adjust the plot range but I get large white spots where I am outside of the plot range. I am not sure how to tackle the problem if anyone has any ideas I would appreciate your thoughts! My code is as follows               DensityPlot[di, {x, -5, 5}, {y, -5, 5}, PlotLegends -> Automatic,      ColorFunction -> "Rainbow", PlotRange -> All]      Thanks, Ben ![enter image description here](http://i.stack.imgur.com/HVQ5M.png)


Graphics`Mesh`FindIntersections[ ] fails to detect intersections

`Graphics`Mesh`FindIntersections[ ]` is an undocumented function for, well, detecting intersections very efficiently. Take a look:               i = Import@"http://i.stack.imgur.com/PcWcz.png";     perim = ImageValuePositions[Thinning@EdgeDetect@i, 1];     fcp = FindCurvePath[perim];     perimPts = perim[[First@fcp]];     Graphics`Mesh`MeshInit[]; (*not sure if needed*)     myLine = Line@{1.1 {750.5`, 955.5`}, {182.5`, 671.5`}};     pts = Graphics`Mesh`FindIntersections[{myLine, Polygon@perimPts}];     Graphics[{Line@perimPts, Red, myLine, Green, PointSize[Large],                Point@pts}, AspectRatio -> Automatic]      ![Mathematica graphics](http://i.stack.imgur.com/dg9uX.png) But it doesn't work consistently (here I change `myLine`):               myLine = {Line@{{750.5`, 955.5`}, {182.5`, 671.5`}},                Line@{{622.5`, 1031.5`}, {222.5`, 831.5`}}};     pts = Graphics`Mesh`FindIntersections[{#, Polygon@perimPts}] & /@ myLine;     Graphics[{Line@perimPts, Red, Sequence @@ myLine, Green,                PointSize[Large], Point /@ pts}, AspectRatio -> Automatic]      ![Mathematica graphics](http://i.stack.imgur.com/e4Y6q.png) Is there something that can be done about this behavior?


Trying to graph trajectory function in Mathematica? Won't Graph?

The exercise is: define the trajectory function `y(x)` in _Mathematica_. Pick the initial speed (in meters per second) equal to `2` and the angle equal to `30 degrees`. Plot this function from `x=0` to `x=0.5`. I approached this problem by typing               y[x_] := x*Tan[θ] - ((9.8*x^2)/(2*v^2*(.5 + (.5*Cos[2 θ]))))      I then assigned θ and initial speed:                θ==30          v==2      and then wrote the plot function:               Plot[y, {x,0,0/5}]      AND THEN GOT AN EMPTY GRAPH! HELP!


NotebookWrite Multiple Selected Objects

Lets say I select shapes in a `Graphics` diagram in the following picture. ![enter image description here](http://i.stack.imgur.com/pMWRi.png) Generated from the following set of code:               Print[      Button["NotebookWrite",        (* Write Triangle *)       NotebookWrite[EvaluationNotebook[],         PolygonBox[{{-1, 0}, {1, 1}, {1, -1}}]         ];       ],      Dynamic[Refresh[        NotebookRead[SelectedNotebook[]]        , UpdateInterval -> 1]]      ]     Graphics[{       CircleBox[{0, 0}], CircleBox[{0, 0}],       CircleBox[{1, 1 }], CircleBox[{1, 1 }],       Rectangle[{0, -1}, {2, 1}], Rectangle[{0, -1}, {2, 1}]       }, ImageSize -> {55, 55}]      Now if I press ![NotebookWrite](http://i.stack.imgur.com/kYsDz.png) it replaces `{CircleBox[{0,0}],RectangleBox[{0,-1}]}` with a Triangle. ![enter image description here](http://i.stack.imgur.com/jOwMG.png) My question: Is there a way to replace each shape (`CircleBox[{0,0}]` and `RectangleBox[{0,-1}]`) with separate objects instead of replacing both with one object?


Plotting multiple vector fields with different domains in a single graph

I have attached a scheme of the problem. Essentially what I need is to plot 2 different vector fields in a single graph with different domains. The underlying physical problem is to model electric current around and inside a sphere of a different material than the surroundings. ![enter image description here](http://i.stack.imgur.com/Z9ZKb.png) Thanks


Simplifying using assumptions

Is there a way to simplify the following equation                (-p(a-x)((a-b)P(b-x)+Q(b+x)(a-b+2x))+q(a+x)(-(a-b)Q(b+x)+P(b-x)(-a +b+2x)))/((b-x)(-a + x)(a+x)(b+x))      assuming                {p+q == 1, P + Q == 1}      in order to get               q/(-a + x) - p/(a + x) - Q/(-b + x) + P/(b + x)      ? Although FullSimplify works in this case when I am using instead of p,q,P,Q variables with subscripts according to the following substitution:               {p -> Subscript[A,1], q -> Subscript[B,1], P -> Subscript[A,2], Q -> Subscript[B,2],a-> Subscript[a,1],b-> Subscript[a,2]}      FullSimplify ceases to produce the desired result! This is pretty unexpected behaviour!


Finding the position of strings in a list that contain a particular word/string sequence

If I have a list of strings Like:               text = Select[       StringSplit[        StringReplace[         StringTake[ExampleData[{"Text", "AliceInWonderland"}], {25, 997}],          Alternatives @@ Characters["<>?;'|:\"()-_!&"] -> " "], "." | ","],        StringLength[#] > 2 &]      > {"Alice was beginning to get very tired of sitting by her sister on the > bank"," and of having nothing to do"," Once or twice she had peeped into the > book her sister was reading"," but it had no pictures or conversations in > it"," and what is the use of a book"," thought Alice"," without pictures or > conversations So she was considering in her own mind as well as she could"," > for the day made her feel very sleepy and stupid "," whether the pleasure of > making a daisy chain would be worth the trouble of getting up and picking > the daisies"," when suddenly a White Rabbit with pink eyes ran close by > her"," There was nothing so very remarkable in that"," nor did Alice think > it so very much out of the way to hear the Rabbit say to itself"," Oh dear > Oh dear I shall be too late But when the Rabbit actually took a watch out of > its waistcoat pocket and looked at it and then hurried on"," Alice started > to her feet"," for it flashed across her mind that she had never before seen > a rabbit with "} how do I find the positions of the list elements that contain the following words/character strings:               words = {"her", "she", "alice", "bbit"};      Following on from this question, I tried using `Position` like so:               Position[text,       s_ /; StringMatchQ[s, __ ~~ Alternatives @@ words ~~ __,          IgnoreCase -> True] &]      > {} but this doesn't produce the list of positions. The follwing seems to suggest that I have the right string-matching criteria:               StringMatchQ[text, __ ~~ Alternatives @@ words ~~ __,       IgnoreCase -> True]      > > {True,False,True,False,False,False,True,True,True,True,True,True,True,True,True} What am I missing?


Renaming a list with name obtained interactively

I have a list say:               m = {1, 2, 3}      The list is inside a package, and is the result of a calculation. I want to give the user the option to rename it, for example with an input:               new = Input["enter a new name"]      I have not enough experience, but I tried in several ways and failed. The most obvious failure is to make:               new -> m      I cannot define `new` as a list prior to this assignment. On the other hand, I cannot define the name of a list as a vector with super-index or sub-index, for example:               v^i_; j = {1, 2, 3}      Can somebody help me?


Dynamic visualization of Graph[] on a webpage

How can we embed a dynamic version of a `Graph` object on a web page, similar to the one showcased on the networkx home page? This sort of dynamic visualization can be very useful for presentations, especially if more information could be shown than just the node names by tooltips.


Calling Table with custom iterator

I often find myself in situations where I, for example, need to build a table for some expression, but want to set the number of points rather then the step size, so the code ends up looking like this               lower = 0.2;     upper = Pi^2;     points = 100;     Table[Sin[x], {x, lower, upper, (upper - lower)/(points - 1)}] // ListPlot      I think that the typical Table syntax is much nicer in cases where we want to set the stepsize, but would much rather prefer to just think of the iteration specifications to be of the form {var,min,max,num} in these cases. Initially I though I would to this by just defining a function that takes this other iteration specification and returns the traditional equivalent, but since Table has holdall, you'd need to wrap everything in Evaluate which isn't pretty either example:               myIter[L_]:={L[[1]],L[[2]],L[[3]],(L[[3]]-L[[2]])/L[[4]]}     Table[Sin[x], Evaluate@myIter[{x, 0.2, Pi^2, 100}]] // ListPlot      So to get around this I added a pattern to modify the way Table is called if the second argument was wrapped in linIter:               linIter /: Table[exp_, iterator_linIter] := Table[exp, Evaluate@myIter[List @@ iterator]]     Table[Sin[x], linIter[x, 0.2, Pi^2, 100]] // ListPlot      This then allows me to have somewhat nice syntax to specify a new iterator. So my questions are   * Whether others have a more elegant way of implementing this, that allows one to call the expression with multiple iterators mixing step size and number based?   * What capabilities of `Table` I might possibly be losing by calling it this way?   * Is it possible to retain the syntax highlighting of `Table` while doing this?   * Also I'd appreciate general feedback. Am I committing blasphemy by messing with the call syntax for a built-in, or is would you easily get the intention if you where reading though some code that relied on this type of tricks to sort of have custom iterators?


NIntegrate with an arbitrary number of variables

I need to evaluate `NIntegrate` with a variable number of variables. Here's a concrete example. I'll accept an answer that finds a way to make the example work. I want to calculate the following integral: $$\int_0^1 \left( \sum_{i=1}^n x_i \right) \prod_{i=1}^n\mathrm{d}x_i = \frac{n}{2} $$ where $n$ is the number of variables. This particular integral can be separated into independent integrals, but in general this is not possible. I chose it because it is a simple example. In Mathematica, we start by defining `n`, say:               n = 4;      Then I try to evaluate the following command:               NIntegrate[Sum[x[i], {i, 1, n}],          Sequence@@Table[{x[i], 0, 1}, {i, 1, n}]]      and it gives an error. What I'm trying to do here is use `x[1], x[2], ...,x[n]` as variables of integration. Note that `Integrate` does work. So the problem is restricted to `NIntegrate`.


representing triplet data set with color on 2d plot

I have a huge list of data in the form of triplets numbers (e.g. {x,y,z}) and I want 2d plot. In which I want to plot y vs x on which values of z should be shown with color depending on the value of z for each x,y point. Means variation of z with color on x,y plot. Is it possible to show plot legend outside the plot boundaries? Please give me suggestions


ListPlot and ColorFunction

I've been searching for the use of ColorFunction as an Option for ListPlot, but haven't found anything about it in the documentation. When trying the code               ListPlot[      RandomReal[5, {10}]      , ColorFunction -> Hue[#1, #2, 1] &      ]      I get the error message               ListPlot::nonopt: "Options expected (instead of ColorFunction->Hue[#1,#2,1]&) beyond position 3 in ListPlot[{2.14801,2.18933,<<6>>,3.48,0.566812},ColorFunction-><<1>>&]. An option must be a rule or a list of rules."      Is it possible, and if so, how, to use ColorFunction with ListPlot? What are the arguments of the function, then? Thanks for all help, as always!


Coloring Points in a List Plot

> **Possible Duplicate:**   >  ListPlot with each point a different color and a legend bar I want to color the points in a list plot using a function of the (x,y) values. I tried this (example with random data):               ListPlot[RandomReal[1, {100, 2}],      PlotStyle -> Thick,      Joined -> False,      ColorFunction -> Function[{x, y}, Hue[(x + y)/2]]      ]      ![Mathematica graphics](http://i.stack.imgur.com/CUxbH.png) But, apparently, `ColorFunction` requires the data to be joined.               ListPlot[RandomReal[1, {100, 2}],      PlotStyle -> Thick,      Joined -> True,      ColorFunction -> Function[{x, y}, Hue[(x + y)/2]]      ]      ![Mathematica graphics](http://i.stack.imgur.com/1SVnh.png) That's a big ugly mess that I don't want. How can I get the points colored without joining them, am I missing something simple here?


Linking points in separate lists in ListPlot (updated)

**Updated:** I have two lists (of different lengths) of co-ordinates, in the form `{x,y,"tag"}`, that I wish to plot so that one list is graphically linked to the other list via their tags. In other words, I want to show the parent- daughter relationships between two datasets on a plot. Here is some example code:               parents = {Flatten@{RandomReal[10, 2], "p1" (*parent 1*)},         Flatten@{RandomReal[10, 2], "p2" (*parent 2*)}}          daughters =        Partition[        Flatten@Thread@          List[Partition[RandomReal[10, 12], 2], {"d1", "d1", "d1", "d2", "d2", "d2"}], 3]          (* d1 corresponds to p1, etc. *)          ListPlot[{parents[[All, 1 ;; 2]], daughters[[All, 1 ;; 2]]},       PlotMarkers -> {{"\[FilledSquare]", 18}, {"\[FilledDiamond]", 18}},       AxesOrigin -> {0, 0}]      which produces the following: > >     {{3.89794, 6.38947, "p1"}, {2.97147, 2.27053, "p2"}} >   >     {{5.05879, 8.04477, "d1"}, {3.94848, 0.52971, "d1"}, {0.310406, 5.55621, > "d1"}, >      {8.058, 4.5872, "d2"}, {9.64885, 3.806, "d2"}, {9.63257, 7.76892, > "d2"}} >   > > ![enter image description here](http://i.stack.imgur.com/D5Ykz.jpg) What I want to end up with is something like this: ![enter image description here](http://i.stack.imgur.com/JCCgz.jpg) I think this may be achieved with `Epilog` but I am unsure about how to utilise the 'tags' effectively. Does anyone know how to do this? Also, the number `daughters` relative to `parents` (although consistent in the above example) needs to be variable (e.g. 1 parent - 10 daughters,1 parent - 2 daughters, etc.) * * * **EDIT:** Just to clarify/extend the usefulness of what i'm trying to achieve (taking on board what was said by Halirutan and Mr Wizard in their answers), here is an amended example:               parents = {Flatten@{RandomReal[10, 2], "cats" },        Flatten@{RandomReal[10, 2], "dogs"},        Flatten@{RandomReal[10, 2], "frogs" }}          children =       Partition[       Flatten@Thread@         List[Partition[RandomReal[10, 18], 2], {"kittens", "kittens",            "kittens", "puppies", "puppies", "puppies", "tadpoles",            "tadpoles", "tadpoles"}], 3]     (* kittens corresponds to cats, etc. *)          ListPlot[{parents[[All, 1 ;; 2]], children[[All, 1 ;; 2]]},       PlotMarkers -> {{"\[FilledSquare]", 18}, {"\[FilledDiamond]", 18}},       AxesOrigin -> {0, 0}]      The output is essentially the same as above, however, the tags are unique and need to be related to each other explicitly. How do I tell Mathematica that kittens come from cats? **Update2:** For those who are interested here is an example of one of the plots created as a result of the answers: ![enter image description here](http://i.stack.imgur.com/Tddyf.jpg) The filled circles are starting compositions (made from various natural and synthetic rocktypes) for melting experiments between 700 - 1100 degC and 1 - 15 kbar. The diamonds are partial melts resulting from the incongruent melting of the starting material. The darker diamonds are low-pressure experiments. The lighter diamonds are high-pressure experiments. The small dots in the background are natural granite compositions for comparison. A first order observation is that the melts are always less mafic (MgO+FeO) than the starting material (and generally more potassic). One would expect that this phenomena would lead to the formation of more mafic residue if melt is lost from the system. Thanks again!


How can I speed up this plot manipulation? Why does Evaluate not help?

If I were able to "Save" the computed inverse function somewhere and then plot it, the manipulation would become faster. As I understand, Evaluate should do the job, but for some reason it does not. Why?               f[x_] := Sqrt[x]; c[x_] := x^2; g[x_] := c'[x]/f'[x];     x[gamma_, δ_, φ_, ρ_, mode_] :=        InverseFunction[g][gamma/(1 - δ*φ*ρ)*mode];          Manipulate[       Plot[         {Evaluate@x[gamma, δ, φ, ρ, 1],           Evaluate@x[gamma, δ, φ, ρ, 2]},         {gamma, 0, 10},          PlotRange -> {{0, 10}, {0, 10}}],           {δ, 0, 1}, {φ, 0, 1}, {ρ, 0, 1}     ]


RSolve: Errors while solving Partial Difference Equation

I tried solving following partial difference equation in _Mathematica_ by typing               RSolve[{C[n, k] == C[n-1, k] + C[n-1, k-1], C[n, 0] == 1, C[n, n] == 1}, C[n, k], {n, k}]      but returns the following error message > RSolve::conarg: The arguments should be ordered consistently. >> but it does not work, please someone help me in this regard. Thanks and regards in advance.


NDSolve doesn't solve my system of ODEs

What is causing the error in this code?               N0 = 4; μ = 2; ρ = 1; d = 1; n = 1;     eqone = Flatten[                Join[                  Table[x[i]''[t] == ϵ*(1 - x[i][t]^2)*x[i]'[t] - x[i][t] + d (z[t] - x[i][t]),                         {i, 0, N0}],                   {z'[t] == ρ*d/n (Sum[x[i][t] - z[t], {i, 0, N0}])}, z[0]==0,                     x[0][0] == 1, x[0]'[0] == .5, x[N0/2][0] == 0, x[N0/2]'[0] == 0},                  Table[x[i]'[0] == 0, {i, 1, N0/2 - 1}],                   Table[x[i][0] == 0, {i, 1, N0/2 - 1}],                  Table[x[i]'[0] == 0, {i, N0/2 + 1, N0}],                   Table[x[i][0] == 0, {i, N0/2 + 1, N0}]                    ]                    ]      and once I get my equations, I should be able to solve the differential equation, but it isn't working. I get a message that starts out: > The function value is not a list of numbers with dimensions ... I think I have to flatten something again in the NDSolve, but I'm not entirely sure how to do that and why.               eqtwo = NDSolve[eqone, {Table[x[i], {i, 0, N0}],z}, {t, 100}]


Assigning numerical values to constants results in complex coefficients in Equations of Motion

I am using Mathematica to get the Equations of Motion (EOM) for a mechanical system (using Lagrangian Mechanics). While I get the EOM in symbolic form, on introducing the following code for assigning numerical values to constants, the resulting EOMs of the system end up having complex coefficients.               ClearAll["Global`*"];     Needs["Notation`"];     Symbolize[ParsedBoxWrapper[SubscriptBox["_", "_"]]];          (*Segment C*)     Subscript[ρ, Al] = 2.7;   (*Density of Aluminium 6061 in g/cc*)     Subscript[ρ, MS] = 7.85; (*Density of Mild Steel in g/cc*)     Subscript[ρ, Fl] = 0.9;  (*Density of hyraulic fluid in g/cc*)          Subscript[r, C1] = 0.5;     Subscript[l, C1] = 4.2;     Subscript[r, C2] = 2;     Subscript[t, C2] = 0.25;     Subscript[l, C2] = 16.4;     Subscript[l, C3B] = 17.8;     Subscript[r, C3Bouter] = 1;     Subscript[r, C3Binner] = 0.45;     Subscript[r, C3s] = 2;     Subscript[l, C3s] = 0.6;     Subscript[l, C2f] = Subscript[l, C2] - Subscript[l, C3s];          Subscript[m, C1] = Subscript[l, C1] Subscript[ρ, Al]      \!\(\*SubsuperscriptBox[\(r\), \(C1\), \(2\)]\) N[π];     Subscript[m, C3s] = Subscript[l, C3s] Subscript[ρ, MS]      \!\(\*SubsuperscriptBox[\(r\), \(C3s\), \(2\)]\) N[π];     Subscript[m, C3B] = Subscript[l, C3B] Subscript[ρ, MS] (\!\(     \*SubsuperscriptBox[\(r\), \(C3Bouter\), \(2\)] -      \*SubsuperscriptBox[\(r\), \(C3Binner\), \(2\)]\)) N[π];     Subscript[m, C2s] = Subscript[l, C2] Subscript[ρ, Al] ((Subscript[r, C2] + Subscript[t, C2])^2 -\!\(\*SubsuperscriptBox[\(r\), \(C2\), \(2\)]\)) N[π];     Subscript[m, C2f] = Subscript[l, C2f] Subscript[ρ, Fl] \!\(\*SubsuperscriptBox[\(r\), \(C2\), \(2\)]\) N[π];     Subscript[m, C3] = Subscript[m, C3B] + Subscript[m, C3s];     Subscript[m, C] =  Subscript[m, C1] + Subscript[m, C2f] + Subscript[m, C2s] + Subscript[m, C3];          (*Segment B*)     Subscript[λ, P5] = 4.8; (*Linear mass density of Profile 5 \bars in g/cm*)     Subscript[b, B1] = 2;     Subscript[b, B2] = 4.367;     Subscript[l, B2] = 1.5;     Subscript[l, B1] = 32;     Subscript[l, B4] = 23.8;     Subscript[b, B4] = Subscript[b, B1];     Subscript[b, B3] = 8;     Subscript[l, B3] = 4;     Subscript[l, B] = 9.2;     Subscript[t, B2] = Subscript[b, B1];     Subscript[t, B3] = Subscript[b, B1];          Subscript[m, B1] = Subscript[λ, P5] Subscript[l, B1];     Subscript[m, B2] = Subscript[b, B2] Subscript[l, B2] Subscript[ρ, MS] Subscript[t, B2];     Subscript[m, B3] = Subscript[b, B3] Subscript[l, B3] Subscript[ρ, MS] Subscript[t,     B3];     Subscript[m, B4] = Subscript[λ, P5] Subscript[l, B4];     Subscript[m, B] = Subscript[m, B1] + Subscript[m, B2] + Subscript[m, B3] + Subscript[m, B4];          (*Segment D*)     Subscript[l, D1] = 36.8;     Subscript[b, D1] = 3;     Subscript[b, D2] = 6.8;     Subscript[l, D2] = 4;     Subscript[t, D2] = Subscript[b, B1];     Subscript[m, D1] = Subscript[λ, P5] Subscript[l, D1];     Subscript[m, D2] = Subscript[b, D2] Subscript[l, D2] Subscript[ρ, MS] Subscript[t,     D2];     Subscript[m, D] = Subscript[m, D1] + Subscript[m, D2];          (*Segment E*)     Subscript[l, E] = 75;     Subscript[b, E] = 22;     Subscript[m, E] = 50000; (*50 kg = 50,000 g*)          (*Terms used in the displacement constraints*)     Subscript[l, GB] = Subscript[l, B]/2;     Subscript[h, B] = Subscript[b, B1] + Subscript[b, B3] + Subscript[b, B4];     Subscript[h, GB] = Subscript[h, B]/2;     Subscript[l, GD] = Subscript[l, D1]/2;       Subscript[h, GD] = Subscript[b, D2]/2;     Subscript[l, GE] = Subscript[l, E]/2;     Subscript[l, D] = Subscript[l, D1];     α = 0.5;     Subscript[l, BL] = 2;     Subscript[h, BL] = Subscript[b, B2];     Subscript[l, DU] = 6;     Subscript[h, DU] = Subscript[b, D2];     g = 981; (*cm/sec^2*)     c = 3 10^7; (*3*10^4 is the average damping coefficient whilst using \kg and m*)     Subscript[W, g] = 15000 g;     Subscript[T, H] = 5*10^7; (*5 N-m = 5*10^7 when g and cm is employed instead of kg \and m*)     Subscript[T, K] = 5*10^7;      I guess I have made some mistake in this assignment due to which 'iota' somehow creeps into my resultant equations, but I am not able to figure out where the mistake is.


Summation with constraints

I am trying to do the summation shown below, $\sum_{i_1=0}^{imax_1} \sum_{i_2=0}^{imax_2} \dots \sum_{i_k=0}^{imax_k} f(i_1,\dots,i_k)$ $k$ is a variable. Therefore $i$ and $imax$ are defined as arrays of length $k$.               Array[i,k]     Array[imax,k]      Is there a way to accomplish this?


Selecting StyleBox with Cases

Continuing my question in this link, I would like to be able to select just a portion of the following expression:               Cell[TextData[{       "test ",       StyleBox["2+3", "Input"]      }], "Text"]      I wish now to select the part `"2+3"`. I've been thinking to do that with Cases, and have tried the following pattern for selecting the `StyleBox["2+3", "Input"]`:               _StyleBox      but that didn't seem to work. Any help with this? Thanks again for all the help!


Log of products to sum of logs

I have a log of products: $$\log \left(\prod _{i=1}^n \left( g(a(i,i)) \prod _{k=1}^i f(a(i,k))\right)\right)$$ That I turn into a sum of logs (I know everything involved is nice enough): $$\sum _{i=1}^n \left(\sum _{k=1}^i \log (f(a(i,k)))+\log (g(a(i,i)))\right)$$ I had to use a custom rule for this:               Log[Product[g[a[i, i]] Product[f[a[i, k]], {k, 1, i}], {i, 1, n}]] //.       {Log[Product[expr_, range_]] :> Sum[Log[expr], range],       Log[Times[a_, b_]] :> Log[a] + Log[b],       Log[Power[a_, n_]] :> n Log[a]}      Some observations: * * * `FullSimplify` does nothing, even with assumptions:               FullSimplify[      Log[Product[g[a[i, i]] Product[f[a[i, k]], {k, 1, i}], {i, 1, n}]],      {a[_, _] > 0 && g[_] > 0 && a[_, _] > 0 && f[_] > 0}]      * * * Not even with penalty for `Product` does it do anything:               FullSimplify[      Log[Product[a[i], {i, 1, n}]],      a[_] > 0,      ComplexityFunction ->       (20 Count[#, _Product, Infinity] + LeafCount[#] &)]      * * * But for `Times` it works:               FullSimplify[      Log[a b c],      a > 0 && b > 0 && c > 0,      ComplexityFunction ->       (20 Count[#, _Times, Infinity] + LeafCount[#] &)]     (* Log[a] + Log[b] + Log[c] *)      Unless I use `a[i]`               FullSimplify[      Log[a[1] a[2] a[3] ],      a[_] > 0 , (* a[1]>0 && a[2]>0 && a[3]>0 works *)      ComplexityFunction -> (20 Count[#, _Times, Infinity] + LeafCount[#] &)]      * * * Is there a more general way to do this that does not rely on making up a bunch of manual transformations?


Set all output to be of specific form

I want every output expression in a notebook to use `//PowerExpand` and also to format numbers as scientific. Is there a way to do this without explicitly calling `ScientificForm[]` and `//PowerExpand` on every input? i.e. I want to be able to enter               In: 4.3*^-5*Sqrt[M]*(L*n^2)^{3/4}     Out: {0.000043 \Sqrt[M] (L n^2)^(3/4)}      and instead get,               Out: 4.3e-5 M^(1/2} L^(3/4} n^(3/2)      ~~Aside: is there a way to make mathematica ** _never_** use radical symbols, and to use exponents instead?~~


Strategies to avoid LessEqual::nord in NMinimize?

When using `NMinimize` on functions with complex intermediate expressions (but a real end result), quite often one gets the error `LessEqual::nord`. Example:               NMinimize[Abs[(a+I b)^(3/2)],{a,b}]     (*     LessEqual::nord: Invalid comparison with 0.306069 + 0. I attempted.          LessEqual::nord: Invalid comparison with 0.306069 + 0. I attempted.          LessEqual::nord: Invalid comparison with 0.306069 + 0. I attempted.          General::stop: Further output of LessEqual::nord          will be suppressed during this calculation.          Less::nord: Invalid comparison with -0.0745302 + 0. I attempted.          NMinimize::cvmit:         Failed to converge to the requested accuracy or precision within 100          iterations.          {1.0635969220476164*^-12 + 0.*I, {a -> -8.71759358950322*^-9, b -> 5.707170335837908*^-9}}     *)      In some cases (not the one above; I didn't find a simple one where it happens) this also results in a clearly wrong result. Therefore it's desirable to remove the error messages. Now the only way to get rid of this error is to change the expression in a way that it doesn't trigger the error. However the expressions are generally complicated enough that it's not feasible by hand. I've found that a combination of the following strategies works _sometimes:_   * Use `ComplexExpand` with the option `TargetFunctions->{Re,Im}`.   * Put the entire expression into an `Abs` or `Re` (despite it being known to be real from construction) and use `Simplify` or `FullSimplify` with appropriate constraints (and hope it finishes in reasonable time). (`Abs` of course only works if the result is also nonnegative) However those strategies are not always sufficient. Therefore my question: What are other good strategies to get the expression into a form suitable to `NMinimize`?


How to convert comment in RowBox to DisplayForm string

ToExpression[RowBox[{"a","(*","what", "*)"}],StandardForm]      This conversion above ignores the commment content `(*what*)` The result I expected is something like the `DisplayForm` below.               RowBox[{"a","(*","what","*)"}]//DisplayForm      ![enter image description here](http://i.stack.imgur.com/Le4UJ.png) Update: one of my test code, how to improve it, and not use (`StringReplace`) if possible.               RowBoxtoString[x_]:=StringReplace[     ToString[ToExpression[x/.RowBox[{"(*",t_,"*)"}]:>"CommentLeft"<>(StringJoin@@t)<>"ComentRight"],     StandardForm],     Shortest["CommentLeft"~~t__~~"ComentRight"]:>"(*"<>t<>"*)"]          RowBoxtoString[RowBox[{"(*","Comment Content","*)"}]]     (*Comment Content*)


Negative probability?

I am trying to get the sum of the squares of seven random variables, all uniformly distributed. This is what I tried.               Probability[       a^2 + b^2 + c^2 + d^2 + e^2 + f^2 + g^2 < 1,       {a, b, c, d, e, f, g} \[Distributed]        UniformDistribution[{{0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}}]]      The output was > >     -π^3/840 >   How can I get _Mathematica_ to get the right answer? **Warning:** the code takes about seven minutes to run on my machine.


Improve TextRecognize on numbers

I have an image contain only numbers, and TextRecognize fail to recognize some numbers: img=![enter image description here](http://i.stack.imgur.com/cPRrY.png);               TextRecognize[img]     (*826718*)      The documentation says that "The quality of recognized text may improve by enlarging the image", but no luck on this example               TextRecognize[ImageResize[img, Scaled[2]]]     (*826718*)      also tried different language, also no help               TextRecognize[ImageResize[img, Scaled[2]], Language -> "French"]     (*826718*)      I also tried Walfram|Alpha, it also gave the same results as Mathematica: ![enter image description here](http://i.stack.imgur.com/GknU9.png) Are there some ways to solve the problem?


Animation of moving rectangles in 2D from data file

I am not very familiar with mathematica but I know the basics so I thought I give it a try. For a project I have to animate rectangles moving around in 2D (later also 3D). The data come from a C simulation I wrote so I can change the output as I want, but for now I have **N** files each looking like this:               t       x-coordinate      y-coordinate     length     1           1                 3              10     2           5                 3              10     3           10                3              10     ...         ...               ...            ...      the thickness of the rectangles should be const over time. How would you approach this? I found the help on importing data and making animations rather confusing so far. Please help me.


How can I make an InputField with a proper newline/carriage return?

The return key does not work as expected in an InputField, how can I overcome this?


Make Enter create new line break inside InputField

I would like to write multiple lines of text inside an `InputField`, using `ContinuousAction->True` to update some variable `x` (so I don't need `Enter`).               InputField[Dynamic[x], String, ContinuousAction -> True]      ![enter image description here](http://i.stack.imgur.com/kYKwI.png) To do the above image, I have to copy and past the text. The point is, if I press `Enter`, the standard behavior is to try to update `x` value. How can I change it in order to make `Enter` to create a new line break in the text inside the `InputField` instead of try to evaluate it?


Input text field GUI

Is there a way to input multiple rows of text and save it as a variable? Like an InputField, but with multiple rows? I would like to make a simple text redactor, so that I could enter a text and then use it as a variable.


why Level does not sort output according to their levels

Consider this example:               Level[a + f[x, y^n], {0, Infinity}]          (*{a, x, y, n, y^n, f[x, y^n], a + f[x, y^n]}*)      Why the output is sorted in this way. why not following their levels? I was expecting to get:               (*{a + f[x, y^n], a, f[x, y^n], x, y^n, y, n}*)


Copying each object in a plot as an image

I would like to copy a plot from _Mathematica_ as an image, into a powerpoint slide. This plot has two curves. When I try to do the (naïve) usual "copy graphics" and paste, I find the full plot (along with the two curves) as a single image. I wish to copy the image such that powerpoint can view the plot as three different objects:   1. The X-Y axes alone.   2. Curve 1   3. Curve 2 Here is an example of two functions and the plot:               f[x_] := (1 - x)^20 + 12*(1 - x)^19*x + 225*(1 - x)^18*x^2 + 1820*(1 - x)^17*x^3 + 13182*(1 - x)^16*x^4 + 16112*(1 - x)^15*x^5 + 15681*(1 - x)^14*x^6 + 15395*(1 - x)^13*x^7 + 15226*(1 - x)^12*x^8 + 15141*(1 - x)^11*x^9 + 15127*(1 - x)^10*x^10 + 15152*(1 - x)^9*x^11 + 15210*(1 - x)^8*x^12 + 15266*(1 - x)^7*x^13 + 15339*(1 - x)^6*x^14 + 15403*(1 - x)^5*x^15 + 15465*(1 - x)^4*x^16 + 15517*(1 - x)^3*x^17 + 15564*(1 - x)^2*x^18 + 15622*(1 - x)*x^19 + 15684*x^20;          g[x_] := (641135*(1 - x)^15*x^5)/171 + (802276*(1 - x)^14*x^6)/95 + (15581573*(1 - x)^13*x^7)/855 + (15099914*(1 - x)^12*x^8)/855 + (172649*(1 - x)^11*x^9)/10 + (14529139*(1 - x)^10*x^10)/855 + (5748121*(1 - x)^9*x^11)/342 + (950524*(1 - x)^8*x^12)/57 + (14169122*(1 - x)^7*x^13)/855 + (939301*(1 - x)^6*x^14)/57 + (1556712*(1 - x)^5*x^15)/95 + (27851407*(1 - x)^4*x^16)/1710 + (27665347*(1 - x)^3*x^17)/1710 + (305276*(1 - x)^2*x^18)/19 + (606145*(1 - x)*x^19)/38 + (2306804*x^20)/285;          Plot[{0.1 f[p], g[p]}, {p, 0, 1/2}, PlotStyle -> {{Thick, Blue}, {Thick, Red}}, LabelStyle -> Large, AxesStyle -> Thick]      Can I make _Mathematica_ output three objects separately ? In that case I can copy each one and paste them in powerpoint.


Creating an Adjacency Matrix to connect an undirected network

I used the locator pane to map a network, specifically the Maryland Power Grid. **What I would like is to have some sort of numbering of the vertices on the unconnected network, how to make an adjacency matrix for the network to then use that to connect the network, and show either in color or shape that some vertices are different (i.e. loads and generators).** It might be worthy to note that I first recorded the loads then the generators from left to right, consequently the last 13 vertices are generators. Here is the code I used for the locator pane, The Maryland Power Grid picture I imported to record vertices, and the resulting network. The locator pane code makes the x and y coordinates unitary. Locator Pane Code                im= Import["http://esm.versar.com/pprp/ceir16/Images/Figure2_20.jpg"];     Module[{picturesize,i,bigger,imagesizes},     picturesize=675;     values={};     i=1;     imagesizes=ImageDimensions[im];bigger=1;     DynamicModule[{pt={0,0}},     If[imagesizes[[1]]<imagesizes[[2]], bigger=2];     TableForm@{         Button["Record!",AppendTo[values,{i,pt}];i++;],         LocatorPane[             Dynamic@pt,             Dynamic@Graphics[                 Join[                     {Inset[im,{0,0},{0,0},{1,1}]}                      ],             PlotRange->{{0,imagesizes[[1]]/imagesizes[[bigger]]},{0,imagesizes[[2]]/imagesizes[[bigger]]}},             ImageSize->picturesize]     ],     Dynamic[N@pt],     Dynamic[MatrixForm@values]     }]     ]      The Maryland Power Grid I used with the locator pane ![enter image description here](http://i.stack.imgur.com/IUz0n.jpg) The resulting unconnected network ![enter image description here](http://i.stack.imgur.com/v4LcJ.jpg) The locator pane also returned an array of points in the form {n, {x,y}} where n is the vertex number recorded chronologically (I tried to do them from left to right) and the x and y are the x and y unitary coordinates.               ({       {1, {0.0996, 0.4195}},       {2, {0.1046, 0.392}},       {3, {0.1144, 0.468}},       {4, {0.1164, 0.4415}},       {5, {0.1432, 0.4455}},       {6, {0.1442, 0.376}},       {7, {0.147, 0.5085}},       {8, {0.16, 0.4965}},       {9, {0.1628, 0.5305}},       {10, {0.1708, 0.484}},       {11, {0.1776, 0.379}},       {12, {0.1836, 0.4335}},       {13, {0.1856, 0.408}},       {14, {0.1936, 0.4495}},       {15, {0.2034, 0.5295}},       {16, {0.1974, 0.3595}},       {17, {0.2122, 0.4395}},       {18, {0.2152, 0.4465}},       {19, {0.2252, 0.3555}},       {20, {0.229, 0.4415}},       {21, {0.2716, 0.3535}},       {22, {0.2952, 0.313}},       {23, {0.3258, 0.4265}},       {24, {0.3446, 0.475}},       {25, {0.3476, 0.4315}},       {26, {0.3536, 0.408}},       {27, {0.3584, 0.3545}},       {28, {0.3694, 0.3665}},       {29, {0.3732, 0.384}},       {30, {0.393, 0.3535}},       {31, {0.395, 0.4205}},       {32, {0.4028, 0.3625}},       {33, {0.4028, 0.378}},       {34, {0.4088, 0.3525}},       {35, {0.4108, 0.4345}},       {36, {0.4286, 0.4505}},       {37, {0.4336, 0.405}},       {38, {0.4434, 0.247}},       {39, {0.4542, 0.303}},       {40, {0.4532, 0.4415}},       {41, {0.4612, 0.3515}},       {42, {0.469, 0.3455}},       {43, {0.47, 0.3685}},       {44, {0.477, 0.391}},       {45, {0.4888, 0.31}},       {46, {0.4948, 0.3315}},       {47, {0.4958, 0.371}},       {48, {0.4986, 0.217}},       {49, {0.4918, 0.4375}},       {50, {0.5214, 0.376}},       {51, {0.5244, 0.3455}},       {52, {0.5284, 0.4315}},       {53, {0.5294, 0.457}},       {54, {0.5302, 0.471}},       {55, {0.5302, 0.2875}},       {56, {0.554, 0.243}},       {57, {0.554, 0.323}},       {58, {0.554, 0.299}},       {59, {0.559, 0.231}},       {60, {0.559, 0.2575}},       {61, {0.559, 0.2725}},       {62, {0.5628, 0.244}},       {63, {0.5668, 0.221}},       {64, {0.5668, 0.316}},       {65, {0.5708, 0.1755}},       {66, {0.5816, 0.2665}},       {67, {0.5836, 0.224}},       {68, {0.5916, 0.152}},       {69, {0.5806, 0.307}},       {70, {0.5826, 0.3365}},       {71, {0.5876, 0.32}},       {72, {0.5974, 0.242}},       {73, {0.5984, 0.2845}},       {74, {0.6044, 0.2865}},       {75, {0.5856, 0.397}},       {76, {0.5906, 0.3605}},       {77, {0.5916, 0.388}},       {78, {0.6014, 0.3385}},       {79, {0.6054, 0.388}},       {80, {0.6132, 0.299}},       {81, {0.6132, 0.2865}},       {82, {0.6142, 0.2745}},       {83, {0.6182, 0.375}},       {84, {0.6252, 0.245}},       {85, {0.6252, 0.3355}},       {86, {0.629, 0.3605}},       {87, {0.63, 0.371}},       {88, {0.63, 0.388}},       {89, {0.633, 0.474}},       {90, {0.635, 0.3535}},       {91, {0.641, 0.3525}},       {92, {0.639, 0.411}},       {93, {0.6438, 0.3585}},       {94, {0.6458, 0.4355}},       {95, {0.6488, 0.473}},       {96, {0.6548, 0.2695}},       {97, {0.6576, 0.38}},       {98, {0.6646, 0.4455}},       {99, {0.6736, 0.3685}},       {100, {0.6764, 0.4415}},       {101, {0.6774, 0.396}},       {102, {0.6902, 0.402}},       {103, {0.6932, 0.373}},       {104, {0.6962, 0.473}},       {105, {0.6972, 0.453}},       {106, {0.718, 0.389}},       {107, {0.7268, 0.292}},       {108, {0.7228, 0.4335}},       {109, {0.7288, 0.457}},       {110, {0.7426, 0.296}},       {111, {0.7406, 0.4235}},       {112, {0.7644, 0.295}},       {113, {0.7624, 0.457}},       {114, {0.7802, 0.4225}},       {115, {0.7802, 0.2855}},       {116, {0.7822, 0.3355}},       {117, {0.797, 0.4315}},       {118, {0.799, 0.4495}},       {119, {0.8028, 0.4415}},       {120, {0.8168, 0.1235}},       {121, {0.8088, 0.459}},       {122, {0.8226, 0.1045}},       {123, {0.8186, 0.3465}},       {124, {0.8168, 0.468}},       {125, {0.8286, 0.244}},       {126, {0.8256, 0.2825}},       {127, {0.8266, 0.329}},       {128, {0.8226, 0.38}},       {129, {0.8196, 0.4345}},       {130, {0.8394, 0.167}},       {131, {0.8532, 0.291}},       {132, {0.8602, 0.1245}},       {133, {0.8652, 0.1085}},       {134, {0.8898, 0.166}},       {135, {0.8938, 0.133}},       {136, {0.9164, 0.221}},       {137, {0.9244, 0.153}},       {138, {0.9284, 0.1845}},       {139, {0.1076, 0.4125}},       {140, {0.1224, 0.3445}},       {141, {0.15, 0.4205}},       {142, {0.4028, 0.4215}},       {143, {0.4642, 0.33}},       {144, {0.467, 0.3395}},       {145, {0.5362, 0.242}},       {146, {0.548, 0.2525}},       {147, {0.5638, 0.131}},       {148, {0.6102, 0.1775}},       {149, {0.629, 0.3435}},       {150, {0.64, 0.456}},       {151, {0.6458, 0.317}},       {152, {0.6488, 0.3535}},       {153, {0.6508, 0.385}},       {154, {0.6538, 0.3365}},       {155, {0.6636, 0.328}},       {156, {0.6626, 0.161}},       {157, {0.6764, 0.3555}},       {158, {0.6854, 0.456}},       {159, {0.7002, 0.465}},       {160, {0.708, 0.387}},       {161, {0.715, 0.4345}},       {162, {0.716, 0.2635}},       {163, {0.7812, 0.1815}},       {164, {0.8958, 0.1925}}      })


How to make the suggestion box appear?

When you type a function in Matlab, quickly a suggestion box comes up showing functions similar to the one you're typing. I thought that Mathematica didn't have this but one day, I typed half of a function and the went to the kitchen when I got back, the suggestion box was there. I'm not sure if it appears after some time or if I accidentaly pressed some key.


Progress indicator with shared variables

I'm trying to create a custom progress indicator for a parallelized computation, using `Dynamic` and `SetSharedVariables` to display and update the progress indicator during the calculation. Two questions:   1. **What is the best way to allow parallel kernels to update the progress?** Should I have a function which accepts a `Dynamic[x_]` argument and do something like this?              Monitor[PerformCalculations[Dynamic[progress]],       ProgressIndicator[Dynamic[progress]]];     (* or this: *)     ProgressIndicator[Dynamic[progress]]     PerformCalculations[Dynamic[progress]]          (* note: 'progress' here will be a list or some other custom structure         for indicating various aspects of the progress of each kernel *)          PerformCalculations[Dynamic[progress_]] := Module[{calc, ...},         SetSharedVariable[progress];         calc[stuff_] := Module[{...},           ...;           (* how does this part work? *) UpdateProgress[Dynamic[progress]];          ];         ParallelMap[calc, data];       ];   2. **How do I avoid race conditions of shared variables?** A quick test indicates that shared variables have some caveats when running with parallel kernels: ![](http://i.stack.imgur.com/i22Im.png) I would have expected the `test = Append[test, ...]` expression to be evaluated atomically so that each kernel would build on the results of the kernels that had already executed. However it seems like the kernels read the value of `test` before writing it, so there is a race condition that causes the final value to be simply `{8}`. What is the best way to avoid this issue?


Add Scroll bar to Panel or Column or Row?

This will be a simple question. Sometimes it is helpful to control the size of content displayed while having a scroll bar so content is not truncated. Is it possible to have a scroll bar attached to Panel[], Column[], Grid[] or Row[] element? So that I can at least specify a maximum width/height beyond which a scroll bar will appear. Thanks!


What should I do if the geographical map provided by Mathematica doesn't show some rivulets?

I have a list of geographical coordinates(maybe the coordinates are not that accurate, but the problem is not that vital):                geodata = {{"30\[Degree]16'38.43''N",       "120\[Degree]10'55.54''E"}, {"30\[Degree]16'18.17''N",       "120\[Degree]11'2.03''E"}, {"30\[Degree]15'58.53''N",       "120\[Degree]11'2.58''E"}, {"30\[Degree]15'38.9''N",       "120\[Degree]11'0.67''E"}, {"30\[Degree]15'29.61''N",       "120\[Degree]11'0.63''E"}, {"30\[Degree]15'21.84''N",       "120\[Degree]10'59.94''E"}, {"30\[Degree]15'10.91''N",       "120\[Degree]10'57.55''E"}, {"30\[Degree]15'52.85''N",       "120\[Degree]12'48.06''E"}, {"30\[Degree]15'46.65''N",       "120\[Degree]12'25.2''E"}, {"30\[Degree]15'36.61''N",       "120\[Degree]12'10.54''E"}, {"30\[Degree]15'26.53''N",       "120\[Degree]11'59.61''E"}, {"30\[Degree]15'16.68''N",       "120\[Degree]11'45.45''E"}, {"30\[Degree]15'1.32''N",       "120\[Degree]11'40.07''E"}, {"30\[Degree]14'51.96''N",       "120\[Degree]11'36.82''E"}, {"30\[Degree]14'35.73''N",       "120\[Degree]11'22.55''E"}, {"30\[Degree]15'40.19''N",       "120\[Degree]13'10.21''E"}, {"30\[Degree]15'28.39''N",       "120\[Degree]13'0.05''E"}, {"30\[Degree]15'9.78''N",       "120\[Degree]12'43.92''E"}, {"30\[Degree]14'58.1''N",       "120\[Degree]12'33.66''E"}, {"30\[Degree]14'38.61''N",       "120\[Degree]12'16.68''E"}, {"30\[Degree]14'33.41''N",       "120\[Degree]12'12.38''E"}, {"30\[Degree]14'21.62''N",       "120\[Degree]12'1.76''E"}, {"30\[Degree]14'51.43''N",       "120\[Degree]12'7.32''E"}, {"30\[Degree]14'59.66''N",       "120\[Degree]12'1.47''E"}, {"30\[Degree]15'7.55''N",       "120\[Degree]11'55.81''E"}, {"30\[Degree]15'13.21''N",       "120\[Degree]11'51.7''E"}} // GeoPosition;      And I want to show those points in one picture with the background being the local map. At first I tried               GeoGraphics[GeoMarker[geodata], ImageSize -> 600]      as you can see, ![here](http://i.stack.imgur.com/GMtZI.png) there should be a rivulet at every geomarker, just as the one on the left of the picture. But the map _Mathematica_ originally provided is not precise enough, the rest rivulets are not shown here( **Those rivulets are very important!** ). Then I used `GeoStyling["ReliefMap"]` and `GeoStyling["ContourMap"]` to specify a small region just to make it present better,               << "ComputationalGeometry`";     GeoGraphics[{GeoStyling["ContourMap"], Polygon[#]},ImageSize -> 600] &[     Extract[geodata[[1]], List /@ ConvexHull[geodata[[1]]]] //      GeoPosition]      (Here **ComputationalGeometry** package and `ConvexHull` are used to generate a convexhull, they don't matter much) but you will see that the polygon is just a piece of green, the same problem still remains. So what should I do to make the map more precise that can show the small rivulets? Thanks! **Edit:** I have thought to use google earth to screenshot the map, but the rivulets are too thin to distinguished from the background, it's hard to use image-processing method. And, if I use google map, but google map doesn't support multi-geomarkers like 26, I can't show every geomarkers on google map. Or else, I firstly take the screenshot, then add the geomarkers, but I think it's not easy to place the geomarkers at accurate places.


Dynamic[] and Print[]

> **Possible Duplicates:**   >  Intermediate display similar to PrintTemporary   >  Estimating progress on plots   >  How to create a progress bar?   >  How to determine how much of a table is generated? I'm trying to print an output from every iteration of a `Do[]` loop, but without it continuing down the notebook. I want the `Print[]` output to be overwritten in the same cell with the new value. Here is a MWE of what I'm trying, but I can't seem to get the expected behavior.               Do[       If[i==1,         Print["Output = ", Dynamic[i]]       ]     ,{i,10}     ]      So in other words, on the first iteration, I want to see "Output = 1", and then every subsequent iteration I want to see the 1 change to a 2, 3, 4, etc. in the same cell.


Industrial Level Applications. Recipe for mixed notation of equations set

I am working with large (linear) equations set within Mathematica in numerical notation. For example, set from 4056 eq. is solved for a second, no more. There is no doubt, result is great. But even simple mixed (both numeric and symbolic) data in 5-20 equation set is the problem... What is the reason? And what the way to solve it? Is it necessary to filter (provide) all data to symbolic form. Data are presented by three forms: 23.234 (float), 23/11 (aka fraction), F/w (symbolic). **Example**               Equations = {c1bXZ[1] - c1bXZ[2] + c1bXZ[5] == (-1)*0, -c1bXZ[1] +      c1bXZ[3] + c1bXZ[4] == (-1)*0,      c1bXZ[2] == (-1)*RX[3], -c1bXZ[3] == (-1)*     RX[4], -c1bXZ[4] == (-1)*0, -c1bXZ[5] == (-1)*F, -c1bYZ[1] +      c1bYZ[2] + c1sStr[5] == (-1)*0, -1000 + c1bYZ[1] - c1bYZ[3] +      c1sStr[4] == (-1)*0, -c1bYZ[2] == (-1)*RY[3],      c1bYZ[3] == (-1)*     RY[4], -c1sStr[4] == (-1)*0, -c1sStr[5] == (-1)*0, -c1bYZ[5] -      c1sStr[1] + c1sStr[2] == (-1)*0, -c1bYZ[4] + c1sStr[1] -      c1sStr[3] == (-1)*0, -c1sStr[2] == (-1)*RZ[3],      c1sStr[3] == (-1)*RZ[4], c1bYZ[4] == (-1)*0, c1bYZ[5] == (-1)*0,      c1bYZ[2] - c2bYZ[1] + c2bYZ[2] - c2bYZ[5] ==      0, -500 + c1bYZ[1] + c2bYZ[1] - c2bYZ[3] - c2bYZ[4] ==      0, -c2bYZ[2] == 0, c1bYZ[3] + c2bYZ[3] == 0,      c1bYZ[4] + c2bYZ[4] == 0, c1bYZ[5] + c2bYZ[5] == 0,      c1bXZ[2] - c1tTor[5] - c2bXZ[1] + c2bXZ[2] == 0,      c1bXZ[1] - c1tTor[4] + c2bXZ[1] - c2bXZ[3] == 0, -c2bXZ[2] == 0,      c1bXZ[3] + c2bXZ[3] == 0, 200 + c1tTor[4] == 0,      200 + c1tTor[5] == 0,      c1tTor[1] - c1tTor[2] - c2bXZ[5] ==      0, -c1tTor[1] + c1tTor[3] - c2bXZ[4] == 0,      c1tTor[2] == MZ[3], -c1tTor[3] == MZ[4],      200 + c1bXZ[4] + c2bXZ[4] == 0, -200 + c1bXZ[5] + c2bXZ[5] ==      0, -c4bXZ[2] ==      0, (-c1bXZ[3] - 3*c2bXZ[3] - 2400000*c3bXZ[3])/2400000 -      c4bXZ[3] == 0,      c4bYZ[2] ==      0, (c1bYZ[3] + 3*c2bYZ[3] + 2400000*c3bYZ[3])/2400000 + c4bYZ[3] ==     0, -c2sStr[2] == 0, -c1sStr[3]/2000000000 - c2sStr[3] ==      0, -c4bXZ[1] == (-c1bXZ[2] - 3*c2bXZ[2] - 2400000*c3bXZ[2])/      2400000 -      c4bXZ[2], (-c1bXZ[2] - 3*c2bXZ[2] - 2400000*c3bXZ[2])/2400000 -      c4bXZ[2] == -c4bXZ[      5], (-c1bXZ[1] - 3*c2bXZ[1] - 2400000*c3bXZ[1])/2400000 -      c4bXZ[1] == -c4bXZ[3], -c4bXZ[3] == -c4bXZ[4],      c4bYZ[1] == (c1bYZ[2] + 3*c2bYZ[2] + 2400000*c3bYZ[2])/2400000 +      c4bYZ[2], (c1bYZ[2] + 3*c2bYZ[2] + 2400000*c3bYZ[2])/2400000 +      c4bYZ[2] ==      c2sStr[5], (-250 + c1bYZ[1] + 3*c2bYZ[1] + 2400000*c3bYZ[1])/      2400000 + c4bYZ[1] == c4bYZ[3],      c4bYZ[3] ==      c2sStr[4], -c2sStr[1] == -c1sStr[2]/2000000000 -      c2sStr[2], -c1sStr[2]/2000000000 - c2sStr[2] ==      c4bYZ[5], -c1sStr[1]/2000000000 -      c2sStr[1] == -c2sStr[3], -c2sStr[3] == c4bYZ[4], -c2tTor[2] ==      0, -c1tTor[3]/140000 - c2tTor[3] == 0,      c3bYZ[1] == (c1bYZ[2] + 2*c2bYZ[2])/800000 +      c3bYZ[2], (c1bYZ[2] + 2*c2bYZ[2])/800000 + c3bYZ[2] ==      c3bYZ[5], (-1000 + 3*c1bYZ[1] + 6*c2bYZ[1])/2400000 + c3bYZ[1] ==      c3bYZ[3], c3bYZ[3] == c3bYZ[4],      c3bXZ[1] == (c1bXZ[2] + 2*c2bXZ[2])/800000 +      c3bXZ[2], (c1bXZ[2] + 2*c2bXZ[2])/800000 + c3bXZ[2] ==      c2tTor[5], (c1bXZ[1] + 2*c2bXZ[1])/800000 + c3bXZ[1] == c3bXZ[3],      c3bXZ[3] ==      c2tTor[4], -c2tTor[1] == -c1tTor[2]/140000 -      c2tTor[2], -c1tTor[2]/140000 - c2tTor[2] ==      c3bXZ[5], -c1tTor[1]/140000 -      c2tTor[1] == -c2tTor[3], -c2tTor[3] == c3bXZ[4]}      And Unknowns:               Unknows = {c1bXZ[1], c1bXZ[2], c1bXZ[3], c1bXZ[4], c1bXZ[5], c2bXZ[1],     c2bXZ[2], c2bXZ[3], c2bXZ[4], c2bXZ[5], c3bXZ[1], c3bXZ[2],      c3bXZ[3], c3bXZ[4], c3bXZ[5], c4bXZ[1], c4bXZ[2], c4bXZ[3],      c4bXZ[4], c4bXZ[5], c1bYZ[1], c1bYZ[2], c1bYZ[3], c1bYZ[4],      c1bYZ[5], c2bYZ[1], c2bYZ[2], c2bYZ[3], c2bYZ[4], c2bYZ[5],      c3bYZ[1], c3bYZ[2], c3bYZ[3], c3bYZ[4], c3bYZ[5], c4bYZ[1],      c4bYZ[2], c4bYZ[3], c4bYZ[4], c4bYZ[5], c1sStr[1], c1sStr[2],      c1sStr[3], c1sStr[4], c1sStr[5], c2sStr[1], c2sStr[2], c2sStr[3],      c2sStr[4], c2sStr[5], c1tTor[1], c1tTor[2], c1tTor[3], c1tTor[4],      c1tTor[5], c2tTor[1], c2tTor[2], c2tTor[3], c2tTor[4], c2tTor[5],      RX[3], RY[3], RZ[3], RX[4], RY[4], RZ[4], MZ[3], MZ[4]}      I see hard work of processor in Mathematica without any result And momentary result from Maple:               {MZ[3] = -200/3+(2/3)*F, MZ[4] = 200/3+(1/3)*F, RX[3] = -(2/3)*F+400/3, RX[4] = -(1/3)*F-400/3, RY[3] = 500, RY[4] = 500, RZ[3] = 0, RZ[4] = 0, c1bXZ[1] = -(1/3)*F-400/3, c1bXZ[2] = (2/3)*F-400/3, c1bXZ[3] = -(1/3)*F-400/3, c1bXZ[4] = 0, c1bXZ[5] = F, c1bYZ[1] = 500, c1bYZ[2] = 500, c1bYZ[3] = -500, c1bYZ[4] = 0, c1bYZ[5] = 0, c1sStr[1] = 0, c1sStr[2] = 0, c1sStr[3] = 0, c1sStr[4] = 0, c1sStr[5] = 0, c1tTor[1] = 400/3-(1/3)*F, c1tTor[2] = -200/3+(2/3)*F, c1tTor[3] = -200/3-(1/3)*F, c1tTor[4] = -200, c1tTor[5] = -200, c2bXZ[1] = (2/3)*F+200/3, c2bXZ[2] = 0, c2bXZ[3] = (1/3)*F+400/3, c2bXZ[4] = -200, c2bXZ[5] = 200-F, c2bYZ[1] = 500, c2bYZ[2] = 0, c2bYZ[3] = 500, c2bYZ[4] = 0, c2bYZ[5] = 0, c2sStr[1] = 0, c2sStr[2] = 0, c2sStr[3] = 0, c2sStr[4] = -11/9600, c2sStr[5] = -11/9600, c2tTor[1] = -1/2100+(1/210000)*F, c2tTor[2] = 0, c2tTor[3] = 1/2100+(1/420000)*F, c2tTor[4] = (1/1440000)*F-1/12000, c2tTor[5] = -(1/1800000)*F-1/12000, c3bXZ[1] = -(1/1800000)*F-1/12000, c3bXZ[2] = 1/12000-(1/720000)*F, c3bXZ[3] = (1/1440000)*F-1/12000, c3bXZ[4] = -1/2100-(1/420000)*F, c3bXZ[5] = 1/2100-(1/210000)*F, c3bYZ[1] = -7/9600, c3bYZ[2] = -13/9600, c3bYZ[3] = 7/9600, c3bYZ[4] = 7/9600, c3bYZ[5] = -7/9600, c4bXZ[1] = 1/36000-(1/900000)*F, c4bXZ[2] = 0, c4bXZ[3] = -(7/7200000)*F-1/36000, c4bXZ[4] = -(7/7200000)*F-1/36000, c4bXZ[5] = 1/36000-(1/900000)*F, c4bYZ[1] = -11/9600, c4bYZ[2] = 0, c4bYZ[3] = -11/9600, c4bYZ[4] = 0, c4bYZ[5] = 0}      By the word, Maple is more worse in numeric power. Last example was very simple. The simple example where I can not to get symbolic solution here Equation set solution problem


Simplify Binomial Function

The following input               Assuming[        (n ∈ Integers) && (n > 0) && (k ∈ Integers) && (k >= 0) && (k <= n),         FullSimplify[Binomial[n, k]/Binomial[n, k + 1]]     ]      returns               Binomial[n,k]/Binomial[n,k+1]      Why does it not give               (k+1)/(n-k)      and how do I make it do this?


Using Inset[..] to overlay a Graphics3D with its raster version

## Preamble First let me explain the _why_. You can skip this and go directly to the question if want to answer it right away. We had more than one discussion about how to produce nice looking 3d plots which can be exported to pdf or some other vector format. Some details why this is not really possible are explained in a post of mine in the question _Exporting graphics to PDF - huge file_.   To solve this issue, there is in my opinion a lot of work to do, since to make it really fancy one would have to reimplement the rendering and 2d-projection process which is done by _Mathematica_ when it displays a `Graphics3D`.   A simple solution, which is maybe OK in a lot of cases, would be to separate the surface of a 3d plot from its box, labels and axes. Then one could create a high-resolution image of the surface and combine this again with the (still in vector format and infinitely high resolved) axes and labels. I showed in the linked post how to do this.   To make this working reliable one has to ensure, that it is possible to place the surface which is now a raster image at the _exact_ same position where the original surface was before. To place the image Wolfram gave us `Inset` at hand which kind of does a good job, but when you look at it closely, there is some behavior I don't understand. ## Question Please consider the following two `Plot3D` where I tried to deny any padding, margin or whatsoever. One plot is rasterized and I fixed the `ImageSize` so that the outcome should be completely equal               s = {300, 300};     opts = {ImageSize -> s,        PlotStyle -> None,        PlotRangePadding -> None,        ImagePadding -> None,        ImageMargins -> None,        Axes -> False,        Boxed -> False};     gr1 = Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2},        PlotStyle -> None,        Evaluate[Sequence @@ opts]        ];     img1 =       Rasterize[        Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2},         PlotStyle -> Opacity[0.4],         Evaluate[Sequence @@ opts]         ],        "Image",        Background -> None,        ImageSize -> s,        RasterSize -> s        ];      If you like, use `Framed` to put a frame around both graphics and try to see differences in placement or size. I could not find any. Creating now a combined `Graphics3D` with `Inset` where I used the `AbsoluteOptions` of `gr1` for the graphics does show, that the inset graphics is not correctly placed. I could have used `Show` for the joining, the outcome would have been the same. Please note, that I initialized the variables `{dx,dy,dz}` to values which give a nice match on my machine. The image shows the zero position.               Manipulate[      Graphics3D[{Inset[img1, {dx, dy, dz}], First[gr1]},        AbsoluteOptions[gr1]],      {{dx, -0.13`}, -.4, .4},      {{dy, -0.14`}, -.4, .4},      {{dz, -0.375`}, -.4, .4}     ]      ![enter image description here](http://i.stack.imgur.com/v6RPk.png) Can someone explain or solve this problem? Maybe someone has an idea where exactly these offsets come from. ## Solution It's worth looking at every answer below, because there are many valuable information, but the key point to the solution of my question was given by Heike who noticed, that the explicit setting of `SphericalRegion` influences the correct placement. Nevertheless, working with `Rasterize`, `ImageSize`, `ImageResolution`, `RasterSize` and all the options influencing margins and paddings around graphics often leads to surprising results. So be warned. With `SphericalRegion->True` in the plot commands, I could quite reliable create nice pdf's from various `Graphics3D`. Here the creation of a high- resolution pdf which has a filesize of 860Kb. I have not included an image, because the png image comes not even close to how brilliant this looks in the pdf. Try it!               RasterizedGraphics3D[gr_Graphics3D, rastersize_Integer] :=        Module[{dim = ImageDimensions[gr], factor},        factor = rastersize/First[dim];        Graphics3D[{Inset[           GaussianFilter[            Rasterize[Show[gr,              Boxed -> False, Axes -> False, AbsoluteOptions[gr]],             "Image", Background -> None, RasterSize -> factor*dim],            .5 factor            ],           {0, 0, 0}, {Center, Center}, dim]},         AbsoluteOptions[gr]]        ];          grout = RasterizedGraphics3D[       Plot3D[Im[ArcSin[(x + I y)^4]], {x, -2, 2}, {y, -2, 2},         Mesh -> None,         PlotStyle ->          Directive[Yellow, Specularity[White, 20], Opacity[0.8]],         ExclusionsStyle -> {None, Red}, SphericalRegion -> True], 2400]     Export["tmp/tmp.pdf", grout, "AllowRasterization" -> False]      The `GaussianFilter` does basically antialiasing because it smooths the high- res raster-image version of the surface a bit. Thank's for all the answers and comments.


How to predict some constant number of values with NeuralNetworks

Example:               << NeuralNetworks`     data = {Sin[#]} & /@ Range[0, 4 Pi, 0.5];     learn = data[[1 ;; 15]];      Now, lets fit our neural network:               {model1, fitrecord} = NeuralARFit[learn, 3, FeedForwardNet, {}, 0, CriterionPlot -> False]     p = NetPredict[learn, model1, PredictHorizon -> 1]     ListLinePlot[Flatten[learn~Join~p]] (* Plot it! *)      In the result the `Length@p == Length@learn == 15`. Is it true, that we predict 15 values? How can you predict only 1 or 2 or 3 values (e.g. `p[[1]], p[[1;;2]], p[[1;;3]]`) or an arbitrary `n` values? Is it right the idea to use `NeuralARXFit[d1,d2,...]` and `Dimensions@First@d2 = {N,3}` if we want to predict only 3 values ?


Saturated Density Plots

I am making some density and contour plots in Mathematica. These plots have very high peaks which saturate with color and prevent me from seeing differences in the peaks. Is there a way I can tone down the color scale so my peaks are not just white blobs? Trying other color schemes has not worked out, and playing with the range of color data has not been very useful. Is there some way to have the colors on a log scale??? Here is my code.               ListDensityPlot[photo, PlotLegends -> Automatic, Frame -> {True},      FrameLabel -> {"Electron Bunch Energy (MeV)", "Photon Energy (keV)",      "", "Yield (Photons/Sr e-KeV)" }, LabelStyle -> {15},      InterpolationOrder -> 10]      ![enter image description here](http://i.stack.imgur.com/oF9qi.png) Cheers, Ben


`PrimeNu` counting function

Building on this question, what is the most efficient counting function for **_distinct_** prime factors? It would obviously be more efficient if `Prime` and `PrimePi` were used instead of `PrimeNu`, as _ybeltukov_ and _Coolwater_ used in their brilliant solutions to the `PrimeOmega` counting function question. I was wondering whether there was any way to do something similar in this instance? The best I have so far is a (very) minor modification of _ubpdqn's_ reply to my previous question:               cnt[k_, n_] := Last@Reap[Sow[1, PrimeNu@#] & /@ Range[n], k, Total@#2 &]


Why I only get 2X speedup when parallelized with 16 kernels

I'm trying to parallelize a function by ParallelTable, and it seems the speedup is not very good. I have 16 parallel kernels on my computer node:               $Version     (*"9.0 for Linux x86 (64-bit) (November 20, 2012)"*)          LaunchKernels[]     (*     {KernelObject[1, "local"], KernelObject[2, "local"], KernelObject[3, "local"],KernelObject[4, "local"], KernelObject[5, "local"], KernelObject[6, "local"], KernelObject[7, "local"], KernelObject[8, "local"], KernelObject[9, "local"], KernelObject[10, "local"], KernelObject[11, "local"], KernelObject[12, "local"], KernelObject[13, "local"], KernelObject[14, "local"], KernelObject[15, "local"], KernelObject[16, "local"]}     *)      And using a documentation example, I get about 16X speedup:               Table[Pause[0.5];f[i],{i,16}]//AbsoluteTiming     (*{8.003956, Null*)          ParallelTable[Pause[0.5];f[i],{i,16}]//AbsoluteTiming     (*{0.508174, Null*)      However, my code only get 2X speedup:               hz = 2*0.375*^-9; c = 2.997924580*^8; ht = hz/(1.01*c)*1.*^15; N0 = 60000; hbar = 1.0545716*^-34; ωx = 2.96265*^1; nx = 5.; Ex = 2.74*^8; Tx = 2 π/ωx; β2 = 226.161; d13 = 8.35066*^-31; Ti = 2.64516;          Ω13[t_, β1_] := Piecewise[{{((Ex*d13)/(hbar*1.*^15))*Cos[(ωx*(t - β1))/(2*nx)]^2* Sin[ωx*(t - β1)], β1 - nx*(Tx/2.) <= t <= β1 + nx*(Tx/2.)}, {0., True}}]          Ω13cf =        Compile[{{t, _Real}, {τ1, _Real}}, Evaluate@Ω13[t, τ1], RuntimeAttributes -> {Listable}];          Table[Ω13cf[t, τ1], Evaluate@{τ1, β2 - 80 Ti, β2 + 10 Ti, 0.05 Ti}, Evaluate@{t, ht, ht*N0, ht}] // Developer`PackedArrayQ // AbsoluteTiming     (*{14.805294, True}*)          Table[Ω13cf[t, τ1], Evaluate@{τ1, β2 - 80 Ti, β2 + 10 Ti, 0.05 Ti}, Evaluate@{t, ht, ht*N0, ht}] // Developer`PackedArrayQ // AbsoluteTiming     (*{14.799250, True}*)          ParallelTable[Ω13cf[t, τ1], Evaluate@{τ1, β2 - 80 Ti, β2 + 10 Ti, 0.05 Ti}, Evaluate@{t, ht, ht*N0, ht}] // Developer`PackedArrayQ // AbsoluteTiming     (*{7.714471, True}*)          ParallelTable[Ω13cf[t, τ1], Evaluate@{τ1, β2 - 80 Ti, β2 + 10 Ti, 0.05 Ti}, Evaluate@{t, ht, ht*N0, ht}] // Developer`PackedArrayQ // AbsoluteTiming     (*{3.088646, True}*)      Questions:   1. Is it possible to get about 16X speedup using ParallelTable, and how?   2. Why the second ParallelTable get a 2X speedup? **Update** Mr. Wizard suggested a very useful discussion on how to efficiently parallelize the problem. As I understand, the basic idea is to use `ParallelMap` instead of `ParallelTable`. So I tried this approach, but it turns out the result is not a PackedArray and `ParallelMap` more than 10X slower than the un-parallelized `Table`:               ls = Tuples[{Range[ht, ht*N0, ht],Range[β2 - 80 Ti, β2 + 10 Ti, 0.05 Ti]}];     Developer`PackedArrayQ[ls]     （*True*）          Map[Ω13cf @@ # &, ls] // Developer`PackedArrayQ // AbsoluteTiming     (*{181.030360,False}*)          ParallelMap[Ω13cf @@ # &, ls] // Developer`PackedArrayQ // AbsoluteTiming     (*no return before I kill it after running for 5 minutes*)


Programming Mathematica in plaintext, i.e. no formatting, non-notebook

I'm new to Mathematica and I've just begun reading Paul Wellin's _Programming in Mathematica_. The book, like many other books and online tutorials, revolves around using the notebook, with all its helpful formatting and other facilities. However, given my background as a C++ developer, mostly using vim and other "traditional" IDEs for development, Doxygen-style commenting for document generation, and Perforce, git, and svn for version control (all of which, as far as I'm aware, operate by diff-ing newline-delimited code), I'm anxious to know: **Is it possible (and more importantly, _not limiting_ ) to program Mathematica in "plaintext"? (And if so, how would one go about it, _i.e._ through a mode in Mathematica's front-end, or writing separate files and "running" them via terminal?)** For the record, I'm not at all opposed to learning a new way of doing things. I'd just like either (1) to ascertain that programming in plaintext is indeed an option and not limiting (at least, there are alternative techniques for getting around any limiting factors) or (2) to ascertain that there are clear advantages to using the notebook, in which case, I'm happy to commit to using the notebook.† Of course, it'd be _nice_ if I could touchtype Mathematica code in vim, but I'm sure there would be good reasons for preferring the notebook, if indeed it is preferred. * * * Perhaps I'm searching for answers using the wrong keywords (mainly "plaintext"), but these are some other threads I read here, on the meta, and on SO, before deciding to ask.   * http://stackoverflow.com/questions/5010346/mathematica-plain-text-notebook \- This hinted to me that it _is_ possible (and practiced) to program in plaintext, but there are no details on its merits or pitfalls, much less guidelines for doing so.   * Converting a notebook to plain text programmatically \- This again hints at plaintext programming (I think), but also again offers no insights into doing so.   * Mathematica as a normal programming language \- I _think_ this touches upon the subject but it's a bit abstract and maybe more about the language implementation rather than the _use_ of it.   * Is there an open source implementation of Mathematica-the-language? \- This is not relevant as I'm not looking for any alternative to Mathematica.   * Running a Mathematica program without Mathematica \- This is not really relevant, as I'm fine with running the kernel and MathLink-ing or whatever is necessary to program in plaintext. **If this question is defective, please help me improve my question.** I'm very much for asking only _relevant_ questions, and I'm happy to take this elsewhere, or rewrite the entire thing. * * * † The reason I'd like to ascertain one or the other is that in my current state of mind, uncommitted to _either_ style, I'm subconsciously resistant to _imagining_ myself programming in Mathematica as I read the book and online tutorials. That is, not having a clear idea of _how_ I'll be writing code, my mind seems to avoid even thinking about it! I think reading _actively_ (imagining myself applying what I'm learning) is a critical factor to learning, so I'd like to remove this mental barrier as early on as possible.


how to delete specific data from text file and then update it

I have a large text file. I read data from text file one at a time and check whether data agree with my condition. If not I want to delete that data in text file and update it. For example say my data text file is: 100 201 302 455 Suppose I want to delete second one. After deletion I want new text file to be look like 100 302 455 (without any gap between 100 and 302). Since my text file is large around 100MB, I want to read data one by one rather than loading all at once. Thanks


Moment central of a binary image

I am implementing the Hu set of invariant moments detailed here Hu set of invariant moments. I implemented the moment Image like this:                {i,j}={0,0}             m00 = Total[               Flatten[Table[                 x^i y^j ImageValue[imagetest, {x, y}], {x, 1, 800}, {y, 1, 600}]]]         {i,j}={1,0}             m10 = Total[               Flatten[Table[                 x^i y^j  ImageValue[imagetest, {x, y}], {x, 1, 800}, {y, 1,                   600}]]]     m10/m00=371.972         {i,j}={0,1}             m01 = Total[               Flatten[Table[                 x^i y^j ImageValue[imagetest, {x, y}], {x, 1, 800}, {y, 1, 600}]]]         m01/m00=472.923      I remark that the time computing is very high compared to                   {cx,cy}=Flatten[ComponentMeasurements[imagetest, "Centroid"][[All,2]]]          {cx,cy}={371.997, 473.198}      and the result is not the same. How can I reduce the time computing ? thanks! ![Hu set of invariant moments](http://i.stack.imgur.com/qZ4G5.png)


How to use a ConvexHull as RegionFunction?

I have a set of data supported over a region in 2D. I want to use RegionPlot and ContourPlot on interpolations of my data, but want to restrict the Plots to the region over which my data is supported. Paste of the supports of my data. I easily find the region with ConvexHull from the ComputationalGeometry package: > Graphics[Polygon[l2[[ConvexHull[l2]]]]] ![enter image description here](http://i.stack.imgur.com/mHv8V.jpg) Now I want to turn the information into something I can use as RegionFunction for the ContourPlots and as restrictions in RegionPlot. Can you show me a way?


Rounding only reals in an expression containing, reals, integers and symbols

I am trying to make a function that would make rounding real numbers in an expression possibly consisting of real numbers, integer numbers and symbols. An example of such an expression is below:               expr = 1.2345 + 3.2471*x + 4.3946*x^2 + 5.56789*x^3 + 3.4812*x^4 +         1.34682*x*Exp[-2.3467*x^3] + 13.25684*x^3*Exp[23.9476*x^7] +         Sin[34.876459*x^2];      What I want to achieve is the following. Let us say, I would like to have all real numbers to have not more that two figures after comma. The expression then should then look as follows:                   1.23 + 3.25 x + 1.35 E^(-2.35 x^3) x + 4.39 x^2 + 5.57 x^3 +       13.26 E^(23.95 x^7) x^3 + 3.48 x^4 + Sin[34.88 x^2]      Such a function is useful, to show dynamically and in a compact form a result obtained in the course of dynamic calculation. For example, I often fit data to a function, the both being dependent upon parameter(s). To show the fitting function dynamically in the same Panel or Manipulate window I need to cut number of figures after comma of real numbers. At present I am here:                   rnd[expr_, m_Integer] :=        Map[If[NumberQ[#],           If[Element[#, Reals], (Round[#*10^m]/10^m // N),            IntegerPart[#]], #] &, expr, {1, Depth[expr]}];      Here expr is any expression to subject the rounding, m is the integer equal to the number of figures after comma to be left. This function almost works. Its application to the expression given above yields the following:               rnd[expr, 2]              (*      1.23 + 3.25 x + 1.35 E^(-2.35 x^3.) x + 4.39 x^2. + 5.57 x^3. +           13.26 E^(23.95 x^7.) x^3. + 3.48 x^4. + Sin[34.88 x^2.]      *)      You may see that the difference between what I get and what I want is that the powers are 2., 3. and so on instead of 2, 3 and so on. I cannot understand, why these decimal points show up, and how to get rid of them.


How to do nor on matrices?

Supose I have matrices a b and c like                  a = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};        b = {7, 8, 9};        c = {{1},{4},{7}};      I want to get `{{1, 2, 3}, {4, 5, 6}}` from `a` and `b`, also `{{2,3},{5,6},{8,9}}` from `a` and `c` ? In other words, I want to delete the part which is the same as `b` or `c` from `a`.


How to force Manipulate to use preserve control settings over successive evaluations

I have this Manipulate:               Manipulate[Plot[Sin[a x], {x, 0, 2 Pi}], {a, 0, 3}]      ![Sin\[a x\]](http://i.stack.imgur.com/D3IgV.png) Now, I realize I had mistyped the expression and it's actually `x^2` instead. I go back and fix it, but when I evaluate the cell again, the value of `a` reverts to default/zero. ![Mathematica graphics](http://i.stack.imgur.com/X8LE8.png) I've tried multiple things from various Q&A: adding `SaveDefinitions -> True`, saving parameter to a global variable within the `Manipulate` block, using bookmarks, but none of them achieved the effect of having the `Manipulate` start up with a previously-set control value. Interesting, I find that saving the parameter to a global variable, and then initialize the parameter with the same global variable solves the problem, i.e., `Manipulate` can remember the manipulated parameter from a previous run. If I add the option `SaveDefinitions -> True`, the value is also saved between sessions. Below is an example: `a` remains at the same value even when the expression in `Manipulate` was changed and the cell was evaluated. ![Mathematica graphics](http://i.stack.imgur.com/Dvuv3.png) ![Mathematica graphics](http://i.stack.imgur.com/yKNMJ.png) I went to the chat room to ask people if doing this is OK. I was told that I should not do this. What kind of potential issues would I have with this method? And if it's bad, is there another method to achieve the same result, i.e., preventing `Manipulate` from resetting control values after each evaluation?


Order of operations for the Table function

> **Possible Duplicate:**   >  Using pure functions in Table I have run into a situation that I do not understand when trying to generate a nested list of pure functions. I have the following code.               Table[Function[x, i*x + j], {i, 1, 3}, {j, 1, 4}]      I expected to get a nested list of pure functions, but the values for `i` and `j` are not being input. I get               {{Function[x, i x + j], Function[x, i x + j], Function[x, i x + j],        Function[x, i x + j]}, {Function[x, i x + j], Function[x, i x + j],        Function[x, i x + j], Function[x, i x + j]}, {Function[x, i x + j],        Function[x, i x + j], Function[x, i x + j], Function[x, i x + j]}}      What is making this operation fail to behave as I expected?


How to create list of delayed rules?

I am trying to make a `ButtonBar` that prints the name of the card in question. ![enter image description here](http://i.stack.imgur.com/x50De.png) What I have so far is as follows:               myHand = {{1, "Spades"}, {4, "Hearts"}, {5, "Clubs"}, {8,         "Spades"}, {9, "Hearts"}, {9, "Spades"}, {11, "Spades"}};          ButtonBar[Table[       ToString[myHand[[i, 1]]] <> " of " <> ToString[myHand[[i, 2]]] :>        Print[myHand[[i]]],       {i, Length@myHand}]      ]      However, instead of working as expected and printing out the name of the card in question, it always prints out `{9, Hearts}`. When I looked into the `FullForm` for this it made sense why:               ButtonBar[List[RuleDelayed["1 of Spades", Print[Part[myHand, i]]],       RuleDelayed["4 of Hearts", Print[Part[myHand, i]]],       RuleDelayed["5 of Clubs", Print[Part[myHand, i]]],       RuleDelayed["8 of Spades", Print[Part[myHand, i]]],       RuleDelayed["9 of Hearts", Print[Part[myHand, i]]],       RuleDelayed["9 of Spades", Print[Part[myHand, i]]],       RuleDelayed["11 of Spades", Print[Part[myHand, i]]]]]      The rule is to print out `i`, not the actual number. How can I remedy this so that my `Table` generates a list of actual rules without holding the `i`s back from being evaluated in the `Table`?


Appending functions to a list

Could someone please explain the difference between these methods, and possibly a nicer way to get the first result? (This is a toy example and in my real program I'd like to use `Do` rather than `Table` or similar as there are imperative and global things going on). Method 1 (Desired result):               In[5]:= fsum[f_]=Total@Through[f@#]&;     fs={};     Do[     AppendTo[fs,#^n1&/.n1->n];     ,{n,0,10}]     fsum[fs][a]          Out[8]= 1+a+a^2+a^3+a^4+a^5+a^6+a^7+a^8+a^9+a^10      Method 2:               In[9]:= fsum[f_]=Total@Through[f@#]&;     fs={};     Do[     AppendTo[fs,#^n&];     ,{n,0,10}]     fsum[fs][a]     Out[12]= 11 a^n      Method 3:               In[13]:= fsum[f_]=Total@Through[f@#]&;     fs={};     Do[     n1=n;     AppendTo[fs,#^n1&];     ,{n,0,10}]     fsum[fs][a]     Out[16]= 11 a^10A


Defining functions in a loop

I have a symbolic solution to a linear system with respect to some variables a[i,j] which depend on a parameter t.               sol=Solve[...,Table[a[i,j],{i,0,n},{j,0,n}]]      I would like to make functions from the solutions. Something like               a[i,j][t_]:=a[i,j]/.sol[[1]]      When I do it by hand, everything is fine. But when I try to get it in any loop, like               Do[{a[i, j][t] := a[i, j] /. sol[[1]]}, {i, 0, n}, {j, 0, n}]      it doesn't work. For example, when I'm trying to look at a[0,1][t] it gives me               a[i,j]      How can one define a family of functions in a loop?


How to change front end setting "Parallel Kernel Configuration" in the code?

I'm trying to run Mathematica parallel on multiple nodes on a HPC, and I use the remote kernel tab in the "Parallel Kernel Configuration" settings to set the communication between different nodes(detailed setup here). Since every time I would get different nodes of the HPC, each time I have to manually change the setting in the "Parallel Kernel Configuration". So is it possible to change the settings within the code? Here is the detail where I want to change: ![enter image description here](http://i.stack.imgur.com/p5HGs.png) For example, how can I enable 16 kernels on a remote host named "mike123" and 10 kernels on a remote host named "mike234"


How to make Mathematica save all open files, or automatically ask to save each file when closing

Here is the scenario: You have number of open notebooks at the same time, and made some changes in all or some of them but have not yet saved the changes. Mathematica does not have something like _save all_ that will save all and any open files that needs to be saved before closing. (At least I do not see it under `File`) So I expected that when one clicks on the close all windows on the main icon, that it will prompt one to save or not save all the open notebooks that needs this action done on them, one by one. ![Mathematica graphics](http://i.stack.imgur.com/SPAHi.png) What happens is this: It asks about the first open notebook, then when answering the question, expecting it will now ask about the next open notebook, instead it does nothing. Leaving the remaining notebooks open as is. So one have to click and click and click again on `close all windows` until all open notebooks that needs to be saved are saved. So if one has 10 open notebooks, they have to click 10 times on `close all windows` and click again to answer the question. This is 10 additional clicks. Other apps I used would ask the user for each open file in turn, or provide a _save all_ or when closing, they would ask the user if they want to save all or discard all, etc... Is there a way to get Mathematica to do this so one does not have to keep clicking on things? A palette that does _save all_ open notebooks would be great. Finally, after closing all windows, and with all those clicks, the main Mathematica icon remains there! So one has to click again to quit. (I actually do not see this splash window below at all, until I have closed all windows. It seems to be hidden somewhere during normal operations or while a notebook is open and this only shows up if all notebooks are closed, not sure) ![Mathematica graphics](http://i.stack.imgur.com/T4bGF.png)


Solving simultaneous exponential equations

In[1]: Solve[{(1 + k)^n == 0.6, (1 + k)^(n + 1) == 0.3}, {n, k}]      > Solve::ifun: Inverse functions are being used by Solve, so some solutions > may not be found; use Reduce for complete solution information. >>               Out[1]: {{n -> 0.736966, k -> -0.5}}          In[2]: Solve[{2*(1 + k)^n == 1.2, (1 + k)^(n + 1) == 0.3}, {n, k}]      > Solve::inex: Solve was unable to solve the system with inexact coefficients > or the system obtained by direct rationalization of inexact numbers present > in the system. Since many of the methods used by Solve require exact input, > providing Solve with an exact version of the system may help. >>               Out[2]: Solve[{2 (1 + k)^n == 1.2, (1 + k)^(1 + n) == 0.3}, {n, k}]      Where is the problem with Mathematica, not able to divide by 2 in first equation?


Autoregressive distributed lag model

Could someone point me in the direction of creating an autoregressive distributed lag model in mathematica?


Is UndirectedEdge[a,b] the same edge as UndirectedEdge[b,a]?

Is `UndirectedEdge[a,b]` the same edge as `UndirectedEdge[b,a]`? Then please consider this.               g = CompleteGraph[4, VertexLabels -> "Name", ImagePadding -> 10]      ![tri1](http://i.stack.imgur.com/I2VNf.png) If we ask to delete `UndirectedEdge[1,4]` or `UndirectedEdge[4,1]` gives the same result:               EdgeDelete[g, {1 \[UndirectedEdge] 4}]     EdgeDelete[g, {4 \[UndirectedEdge] 1}]      ![tri2](http://i.stack.imgur.com/4poU3.png) ![tri3](http://i.stack.imgur.com/9KLsx.png) Yet if we ask whether these edges were in the original graph, we receive different answers.               MemberQ[EdgeList[g], 1 \[UndirectedEdge] 4]     (* True *)          MemberQ[EdgeList[g], 4 \[UndirectedEdge] 1]     (* False *)      This strikes me as inconsistent. * * * **Postscript: Should`UndirectedEdge` be orderless?** @R.M 's response makes a lot of sense: `MemberQ[EdgeList[g], b \[UndirectedEdge] a]` answers True if and only if `b \[UndirectedEdge] a`, is literally in `EdgeList[g]`. It will not respond True if that edge is listed in `EdgeList[g]` as `a \[UndirectedEdge] b`. However, `EdgeQ[g, b \[UndirectedEdge] a]` will respond True whether that edge is stored in `EdgeList[g]` either as `a \[UndirectedEdge] b` or `b \[UndirectedEdge] a`. Even so, it seems to me that `UndirectedEdge` ought to be `Orderless`. Wouldn't it be preferable to behave like `Plus`? Compare `Plus` and `UndirectedEdge`:               ClearAll[x, y]     Plus[x, y]     Plus[y, x]     Attributes[Plus]     Plus[x, y] == Plus[y, x]     Plus[x, y] === Plus[y, x]      ![plus](http://i.stack.imgur.com/GttLe.png)               ClearAll[x, y]     x \[UndirectedEdge] y     y \[UndirectedEdge] x     Attributes[UndirectedEdge]     UndirectedEdge[x, y] == UndirectedEdge[y, x]     UndirectedEdge[x, y] === UndirectedEdge[y, x]      ![undirectedEdge](http://i.stack.imgur.com/yMLzl.png)


Export long filename truncated

I am seeing a weird behavior on exporting at least one type of file (here, a QuickTime movie) to files with long names. If I do this:               In[19]:= Export["Lorem-ipsum-dolor-sit-amet-consectetur-adipisicing-elit.dat", {42}]     Export["Lorem-ipsum-dolor-sit-amet-consectetur-adipisicing-elit.mov", {42}]     FileNames["Lorem*"]      it hurts:               Out[19]= "Lorem-ipsum-dolor-sit-amet-consectetur-adipisicing-elit.dat"     Out[20]= "Lorem-ipsum-dolor-sit-amet-consectetur-adipisicing-elit.mov"     Out[21]= {"Lorem-ipsum-dolor-s#123C8BE.mov", \     "Lorem-ipsum-dolor-sit-amet-consectetur-adipisicing-elit.dat"}      The `.dat` file has the correct name and the `.mov` file hasn't, even though `Export` tries to make me think it has. My questions are:   * This is not on a MS-DOS box, but with Mathematica 8.0.0.0 on Mac OS 10.7.3 (64-bit kernel). Can you comment if other versions/operating systems reproduce this issue?   * Although I find nothing with Google, is this a known bug and is there a fix?


Is there a TwoColoring function of Graph object?

The following code shows the `GraphUtilities` package makes a problem for `Graph` object. I want to use a `TwoColoring` function without using the `GraphUtilities` package. Is there a `TwoColoring` function of `Graph` object ? _Mathematica_ version is 9.0.1.0.               g1 = {1 -> 2, 2 -> 3};          GraphPlot[g1, VertexLabeling -> True, ImageSize -> 200]              Graph[g1, VertexLabels -> "Name", ImagePadding -> 20]              Needs["GraphUtilities`"]         gc = ToCombinatoricaGraph[g1]         color = TwoColoring[gc]              GraphPlot[g1,               VertexRenderingFunction -> ({Text[Framed[#2, Background -> Hue[color[[#3]]/4],               FrameStyle -> RGBColor[0.94, 0.85, 0.36]], #1]} &)]              color2 = Position[color, 2][[1]]           HighlightGraph[Graph[g1, VertexLabels -> "Name"], {2}, ImagePadding -> 20]          > >     HighlightGraph[Graph[{1 -> 2, 2 -> 3}, VertexLabels -> "Name"], {2}, >                                              ImagePadding -> 20] >   No graphics.


Embedding StreamPlot in Graphics3D

I am trying to visualise the action of the infinitesimal generator of a Lie group on the solution of a 2-ODE system drawn in the 3D space (t,y1,y2): t is time and y1,y2 are the two dependent variables. The infinitesimal generator of a Lie group is a vector field and can be visualized nicely using StreamPlot. For a system like this it would normally be a 3D vector field. In this case, however, the symmetry corresponding to the vector field is 2D and (by design) perpendicular to the time axis. Therefore, the vector field can be drawn as a vertical plane (since I am drawing the time axis horizontally). In another post I found an answer that almost works: Can 2D and 3D plots be combined so that the 2D plot is the bottom surface of the 3D plot boundary?. In my case the 2D plot is at the back and vertical, rather than at the bottom, but it was easy to modify the code in that other post to obtain this effect. Preliminaries:               Clear[y1, y2S1, y2S2, y2S3, S, R0, X0]     X0 = 1.5;     R0 = 1.5;     y1[t_, S_] := S - (S - X0) Exp[-t]     y2S1[t_] := 1 + Exp[Exp[-t] - t]*     ((R0 - 1)/E - ExpIntegralEi[-1] + ExpIntegralEi[Sinh[t] - Cosh[t]])     y2S2[t_] := 1 - (1 - R0) Exp[-t/2]     y2S3[t_] := (1/3)*Exp[-2 Exp[-t] - 4 t]*(E^2 (3 R0 - 11) + 8 ExpIntegralEi[2] +        Exp[2 Exp[-t] + t]*(4 + 2 Exp[t] + 2 Exp[2 t] + 3 Exp[3 t]) -        8 ExpIntegralEi[2 Exp[-t]])          pp3d = ParametricPlot3D[{{t, y1[t, 0.5], y2S1[t]},                 {t, y1[t, 1], y2S2[t]},                 {t, y1[t, 2], y2S3[t]}}, {t, 0, 5},     PlotStyle -> {{Thickness[.007], RGBColor[1, 0, 0]},                     {Thickness[.007], RGBColor[0, .7, 0]},                     {Thickness[.007], RGBColor[0, 0, 1]}},     BoxRatios -> {2, 1, 1},     PlotRange -> {{0, 5}, {0, 2}, {0, 2}}]      Code:               S = 2;     test = StreamPlot[{x - S, 2 x*y - S}, {x, 0, 3}, {y, 0, 3}];     Make3d[plot_, height_] := Module[{newplot},        newplot = First@Graphics[plot];        newplot = N@newplot /. {x_?AtomQ, y_?AtomQ} :> {height, x, y}];     Show[{Graphics3D[Make3d[test, 0]], pp3d}, Axes -> True]      However, I got this error:               Encountered "1." where a Graphics was expected in the value of option Arrowheads.      With corresponding graphical output: ![3D_Space_Curve_error](http://i.stack.imgur.com/DIsh7.jpg) S is a parameter. The three curves in R, G, B are three solutions for three different values of S so the vector field is not mapping between these curves. It is acting on any one of these at a time, mapping it to some other solution not shown here. But no matter. It's clear that there is something wrong with the arrows. I am guessing StreamPlot defines them as 2D and they need to be converted to a 3D spec, but I have no idea how to go about that. I can guess that the code above (which I understand only roughly) is doing this kind of conversion, but perhaps it is not reaching the arrow data structure within StreamPlot. Can anyone help? Thanks (Using MMA 9)


How can I decimal-align tick labels at the left?

I use the `CustomTicks` package, because the built-in tick labeling leaves a lot to be desired. Even just putting the tick marks on the right instead of the left is a real pain without `CustomTicks`, from what I remember. I think this would be an issue even without this package, though. Here is what I type in:               << "CustomTicks`"     Plot[Sin[x], {x, 0, 2 π},        Frame -> True, Axes -> False,        FrameTicks -> {Automatic, StripTickLabels[LinTicks], Automatic, LinTicks},       BaseStyle -> 18]      and here is what I get: ![enter image description here](http://i.stack.imgur.com/tFmfP.png) I think the tick marks on the right look awful. They would be better if aligned on the decimal rather than on the left. But how do I fix this? My current workaround is to make another version of the plot with tick labels on the left, which usually are aligned properly because they align to the right. Then I cut the labels from that image and paste them onto the image I want. Any other solution?


Symbolic derivative of $n$-term product

I want to determine the relationship that must exist between the $x_i$ and $y_i$ such that $$ \frac{\partial}{\partial\theta} \prod_{i=1}^n \frac{f(x_i,\theta)}{f(y_i,\theta)} = 0, $$ where $$ f(x,\theta) = \frac{e^{-(\theta - x)}}{(1+e^{-(\theta - x)})^2}, \;\; \forall x \in {\mathbb R}, \theta \in {\mathbb R} $$ * * * Clarification: what I'm trying to find is a condition on the $x_i$ and $y_i$ such that the derivative above (viewed as a function of $\theta$) is zero for all $\theta$ _only if_ this condition holds. Clearly, this derivative is zero for all $\theta$ if, $\forall i\in\\{1,\dots,n\\}$, the condition $x_i = y_i$ holds, since then the product in the derivative expression above is identically 1. But this condition is not necessary: the derivative will be identically zero _also_ if there is an $n$-permutation $\sigma$ such that $\forall i,\,x_i = y_{\sigma(i)}$. My problem is to prove that the derivative is identically zero (i.e. it is zero for all $\theta$) _only if_ such a $\sigma$ exists, for given $x_i$ and $y_i$. * * * So, hoping to have a look at the derivative above, I input this into Mathematica:               Block[{f, θ, x, y, i, n},      f[x_][θ_] := E^(-x + θ)/(1 + E^(-x + θ))^2;      D[Product[f[x[i]][θ]/f[y[i]][θ], {i, n}], θ]     ]      ...but Mathematically basically spits back the last formula (after replacing the various expressions in `f`):               D[Product[(E^(-x[i] + y[i])*(1 + E^(θ - y[i]))^2)/(1 + E^(θ - x[i]))^2, {i, n}], θ]      If instead of using a symbolic product (with an unspecified number of terms) I attempt the same thing with a product of three terms, namely               (f[x1][θ]/f[y1][θ]) (f[x2][θ]/f[y2][θ]) (f[x3][θ]/f[y3][θ])      ...Mathematica does compute the derivative (though the resulting expression is hairy, and I can't extract any insight from it). So my first question is > How can I get Mathematica to produce the expression for the derivative for > the general case? (After all, the derivative of an $n$-term product has a form that Mathematica should be able to express relatively easily.) In any case, the results I got for a three-term product were not encouraging. Of course, I really don't care for the derivative per se, but rather, what I'm after are the conditions on the $x_i$ and $y_i$ that make this derivative vanish. > Is there a way that Mathematica can show me the relationship between the > $x_i$ and $y_i$ when this derivative is 0?


List plot joined with stair steps instead of diagonal lines

What's a simple way to plot a list of points so that they're joined with stair steps instead of straight lines between the points? I'd imagine something like...               stairStepListPlot[{{0,0},{1,1},{2,2}}]      ...would produce a flat line from {0,0} to {1,0}, then a vertical line from {1,0} to {1,1} and so on. Can you find a concise way of producing such a plot?


plotting xy, yz, zx plane at

I have a data list in the following form,               data = {x, y, z, f}      I would like to present three kinds of subdata set as a density (or contour) plot on the respective planes at once in one 3D graph.   1. `data1 = {x, y, f}`   2. `data2 = {y, z, f}`   3. `data3 = {x, z, f}` How could I make an above kind of plot? I really appreciate if anyone help me.


How to abbreviate context names?

It's convenient to abbreviate often-used function names, eg `Dim = Dimension`. Is it possible to abbreviate long context symbols, e.g. _Combinatorica_ when the context is not inserted in the context path, like with               Block[{$ContextPath}, Needs["Combinatorica`"]]      `Com = Combinatorica` doesn't work, eg: `Com`Star[6]` is fixed by the interpreter. Is there a way to abbreviate it?


Recovering vertex names from Combinatorica Graph

According to WRI tech support: _Combinatorica functionality is not technically deprecated, though it is our hope that future versions of Mathematica will subsume it entirely by incorporating its functionality with the built-in Graphs & Networks functionality._ Leaving aside that this seems to conflict with MMA's documentation, eg:               Block[{$ContextPath}, Needs["Combinatorica`"]]      warns: _General::compat: Combinatorica Graph and Permutations functionality has been superseded by preloaded functionality. The package now being loaded may conflict with this. Please see the Compatibility Guide for details._ In the meantime, in order to use Combinatorica functionality like TransitiveClosure on built in Graphs, it's necessary to take a detour through Combinatorica, eg:               AdjacencyGraph[#, VertexLabels -> "Name"] &@      Combinatorica`ToAdjacencyMatrix@       Combinatorica`RemoveSelfLoops@        Combinatorica`TransitiveClosure@         Combinatorica`FromAdjacencyMatrix@          Normal@AdjacencyMatrix@Graph[{"E0" -> "T0", "T0" -> "E1"}]      This yields (sorry for truncation): ![enter image description here](http://i.stack.imgur.com/fcBLA.jpg) How to recover the built in Graph's vertex names? (These are extracted from XML metadata and so it's not so convenient to project them to positional indices)


finding anagrams

What I'm trying to find are the 4 letter words in the _mathematica dictionary_ that have the most anagrams and the amount of anagrams these have each. But I can't seem to find all the 4 letter words in the mathematica dictionary. My output only results in 3-8 letter words. Input is below                wordperms =Flatten[Map[DictionaryLookup,Map[StringJoin, Permutations[Characters[#]]]]] &;      words = DictionaryLookup[];      sorted = Sort[Map[Sort, Map[Characters, words]]];      Part[Select[Tally@sorted, Part[#, 2] > 4 &], All, 1];      found = Part[Select[Tally@sorted, Part[#, 2] > 4 &], All, 1];      Map[wordperms, found]


Placing a contourPlot under and Plot3D

I would like to combine a 3-dimensional graph of a function with its 2-dimensional contour-plot underneath it in a professional way. But I have no idea how to start. I have a three of these I would like to make, so I don't need a fully automated function that does this. A giant block of code would be just fine. The two plots I would like to have combined are:               potential1 =        Plot3D[-3600. h^2 + 0.02974 h^4 - 5391.90 s^2 + 0.275 h^2 s^2 + 0.125 s^4,          {h, -400, 400}, {s, -300, 300}, PlotRange -> {-1.4*10^8, 2*10^7},          ClippingStyle -> None, MeshFunctions -> {#3 &}, Mesh -> 10,         MeshStyle -> {AbsoluteThickness[1], Blue}, Lighting -> "Neutral",         MeshShading -> {{Opacity[.4], Blue}, {Opacity[.2], Blue}}, Boxed -> False,         Axes -> False]      and               contourPotentialPlot1 =        ContourPlot[-3600. h^2 + 0.02974 h^4 - 5391.90 s^2 + 0.275 h^2 s^2 + 0.125 s^4,         {h, -400, 400}, {s, -300, 300}, PlotRange -> {-1.4*10^8, 2*10^7},        Contours -> 10, ContourStyle -> {{AbsoluteThickness[1], Blue}}, Axes -> False,         PlotPoints -> 30]      These two plots look like: ![The 3-D plot](http://i.stack.imgur.com/tvjcJ.png) ![The contour plot](http://i.stack.imgur.com/hc3qA.png) I would also love it if I could get 'grids' on the sides of the box like in http://en.wikipedia.org/wiki/File:GammaAbsSmallPlot.png


Compile Determinant

I would like to determine the determinant of a 4x4 matrix with the entries `a[i,j]` being functions of $i$ and $j$. I used Compile with code: * * *               m4 = Table[a[i, j], {i, 4}, {j, 4}];          variable = Det[m4];     soln = Compile[{{a[i, j], _Real}}, Evaluate[variable]];          soln       * * * How do I declare that the function `a[i_,j_]` can be an arbitrary real number? The terms of `Det[m4]` are output correctly but Mathematica does not recognise `a[i,j] = 0` for $i=j$. Can you help, please?


NDSolve: EventAction list specification using Table fails

I have an NDSolve problem that needs a list of a large number of events that are generated programmatically. Here is a simple example that demonstrates the problem on Mathematica 7 and 8 (the versions I have access to):               NDSolve[       {y''[t] == 10, y[0] == 0, y'[0] == 0},       {y},       {t, 0, 1},       Method -> {"EventLocator",         "Event" :> {y[t] - 2, y[t] - 1},         "EventAction" :>(*{Throw[Print["i=",1],"StopIntegration"],Throw[          Print["i=",2],"StopIntegration"]}*)          Table[Throw[Print["i=", i], "StopIntegration"], {i, 3}]         }       ];      The code as it is does not work (the second event should be triggered first, and it prints `i=1`), but if I use the commented block in `EventAction`, it does work, and prints `i=2`. What is the right syntax to make this work? Thanks for any help!