Convert a number to a string to use in plot axes label, but keep the exponent

This seems to be a simple, but useful question. I am plotting a basic function:               multiplier = 10^11;     func = 10^-11 x^2;     Plot[func*multiplier, {x, 0, 5},        AxesLabel -> {x, "Distance, \!\(\*SuperscriptBox[\(10\), \(-11\)]\) m"}]      That gives the result I wish to see. Imagine now that I wish not to write the multiplier manually in `AxesLabel` when I change it. The inverse multiplier needs to be converted to a string with an exponent (so as to produce the same final appearance). I have tried the `ToString` function with some parameters. For example:               multiplier = 10^11;     func = 10^-11 x^2;     Plot[func*multiplier, {x, 0, 5},        AxesLabel ->          {x, "Distance, " <> ToString[multiplier^(-1), FormatType -> StandardForm] <> " m"}]      But I get an awful label.   1. Could you think of a solution to this problem?   2. Can anyone think of why conversion to real numbers by "N" is necessary and if not how can it be avoided?


CDF with numerous independent manipulate objects

I have been working on my senior project that involves the creation of a CDF with multiple `Manipulate`expressions. I need to protect my code so I have been trying to create/encode a package that will run the program. I have gotten the program to work flawlessly as a notebook in MMA, but as a CDF I get shadowing errors. I have 54 functions in the code and many of my functions use the same variables which are changed by the user input. I have tried to put all of the code in a single package then set the initialization of each `Manipulate` to the same package, but I get errors. It seems like I need to have a package for each `Manipulate`, then have a function at the beginning of the program to call each package. I am not sure. Here is a scaled-down version.               Manipulate[dummyFunctionToDefineNullSet[],        Initialization :> (SuccessfulShotsFor = {};)]          <someManipulateObject>            Manipulate[iSSF[],        Initialization :> (         iSSF[] :=           (PopupWindow[               Button[Style[SomeStyle], , Background -> SomeBackground],                Button[                 (ptevent0 :=                    (If[Extract[#, {1}] < 575, {1150, 740} - #, #]) &;                   Show[Image, ImageSize -> {1150, 740}]),                  AppendTo[SuccessfulShotsFor, ptevent0[MousePosition["Graphics"]]],                  Appearance -> Frameless],              WindowTitle -> "Successful Shots For", WindowFrame -> "Normal",              Background -> RGBColor[51/240, 163/240, 220/240],              Editable -> False, TextAlignment -> Center ,              WindowSize -> {1200, 825}, WindowFloating -> False,              WindowMargins -> {{0, Automatic}, {Automatic, 0}}]))]          <someManipulateObject>          Manipulate[      Quiet[dSSF[SuccessfulShotsFor]],       Initialization :> (        dSSF[          SuccessfulShotsFor_] :=             (Check[               ImageCompose[                 SmoothDensityHistogram[SuccessfulShotsFor,                    AspectRatio -> Full, PlotRange -> {{0, 1150}, {0, 740}},                    ColorFunction -> "GreenPinkTones", Frame -> False,                    PlotRangePadding -> 0, ImageSize -> {1150, 740}],                  SomeImage],                "ERROR: no user input"]             Check[              ImageCompose[                ListPlot[SuccessfulShotsFor,                   AspectRatio -> Full, PlotRange -> {{0, 1150}, {0, 740}},                   PlotMarkers -> {SomePlotMarker}, Frame -> False,                   PlotRangePadding -> 0, ImageSize -> {1150, 740},                   Background -> RGBColor[0, 62/240, 5/240], Axes -> False],                 SomeImage],               "ERROR: no user input"]))]          <someManipulateObject>      `SuccessfulShotsFor` has been giving me a ton of trouble. Once in a package, the value (which gets changed by the user input on the second `Manipulate`) takes on a different name which does not get passed on to the third `Manipulate`, which displays the images for the user to copy. I am running these CDFs in _Mathematica_. I read about the `$ContextPath`, and I think that is the where the problem lies, but I am not experienced enough to implement the fix.


Importing specific elements from JSON

I'm having trouble importing JSON in the way I expect, based on my reading of the documentation. The particular issue I'm having is with importing a specific element, or list of elements. From the doc: > `Import["file.json", "elem"]` imports the specified element from a JSON > file. To test this, I'm trying the following:               In[1]:= Export["out.json", {"x"->42,"y"->17.5}]     Out[1]= out.json      The resulting file looks like:               {"x" : 42,      "y" : 17.5}      Importing the entire file works, returning a list of rules:               In[2]:= Import["out.json"]     Out[2]= {x -> 42, y -> 17.5}      But, importing a specific element fails:               In[3]:= Import["out.json", "x"]     Import::noelem: The Import element "x" is not present when importing as JSON.     Out[3]= $Failed      What am I missing? Perhaps "element" doesn't mean what I think it means?


How can I rewrite my game without using Manipulate?

**Snake Games**               Module[     {dir = {-1, 0}, x = -1., y = 0., snake = Table[{i, 0}, {i, 0, 4}],     gameover = False,     target = {RandomInteger[17] - 9, RandomInteger[17] - 9},     timecount = 0,     score = 0},     Manipulate[     If[      Mod[timecount, 5] == 0 && u != {-1, -1} && gameover == False,     x = u[[1]];     y = u[[2]];     dir = If[      y >= x,      If[y >= -x, {0, 1}, {-1, 0}],      If[y >= -x, {1, 0}, {0, -1}]      ];      If[       MemberQ[snake,          snake[[1]] + dir] || (snake[[1]] + dir)[[          1]] < -10 || (snake[[1]] + dir)[[1]] >          9 || (snake[[1]] + dir)[[2]] < -10 || (snake[[1]] + dir)[[2]] >          9,       gameover = True;       score = Length[snake] - 5       ];      If[       (snake[[1]] + dir) == target,       target = {RandomInteger[17] - 9, RandomInteger[17] - 9},       snake = Most[snake]       ];      PrependTo[snake, snake[[1]] + dir]      ];     timecount++;     Framed[      Graphics[      If[       False == gameover,       Append[        Table[Rectangle[i, i + {1, 1}], {i, snake}],        Rectangle[target, target + {1, 1}]        ],       {Rectangle[{-10, -10}, {10, 10}],         Text[Style[" Game over! ", FontSize -> 36], {0, 3},          Background -> White],         Text[Style[" Score: ", FontSize -> 24], {0, 0},          Background -> White],         Text[Style[score, FontSize -> 24], {0, -2}, Background -> White]}        ],        Axes -> False, PlotRange -> {{-10, 10}, {-10, 10}},         ImagePadding -> 0        ],       FrameMargins -> 0      ],     {u, {-1, -1}, {1, 1}}, ControlPlacement -> Right     ]     ]      It is not convenient for the user to play this game in the above form. So how can I rewrite it without using `Manipulate`, but using other functions that can provide a better user interface?


Figuring when the minute and hour hand coincide on a clock

I would like to list all possible times in a 12-hour period, where the hour hand overlaps the minute hand completely. This is really a question about three distinct things - to be done in Mathematica - though only the first of the following points really interests me:   * Finding solutions to an equation with several variables, where each variable has _different_ restrictions on its domain;   * Formatting those solutions in a convenient format;   * Using those solutions to draw the actual clocks! So what we have is two different variables, $h$ and $m$. $h$ is an integer, between $0$ and $11$, and $m$ is a real number, between $0$ and $60$. We want solutions to when $$ 30h - \frac{11m}{2}=0 $$ within those domain restrictions. I have tried using both `Solve` and `Reduce`, but neither seems capable of giving me anything more than conditional expressions. So I would like to find all possible solutions, format them in a nice hour:minute format, and maybe even draw the actual clocks corresponding to these solutions. The formatting and drawing are actually not that hard (though elegant, efficient, and different solutions are certainly welcome); I am truly interested in mixing the domains for $h$ and $m$ above, and getting meaningful answers. Please feel free to tag as you feel appropriate.


How can I set a fixed cell height?

I did this often in previous versions of the Mathematica notebook front end. I would have a cell with lots of raw data, e.g. a very long list. The list might go on for pages. I would set the cell to have a fixed cell height using the options inspector. I could then drag a little box on the bottom of the cell bracket to show only a small fraction, say, the top three and half lines of the input. (I would cut it off in the middle of a line, showing the top half of the characters in the line, in order to make it clear that only a portion was visible.) I can no longer find this option in Mathematica 8 (Mac OS X). Does anyone know if it may be lurking somewhere else?


How do I save the last graphical output of Animate so as to make it the background for the next Animate?

I am making an instructional program in which a random number appears and moves across and down into the appropriate bin, landing on top of the existing stack. Then another number appears, repeating the animation sequence until it lands on top of its own stack. When any stack reaches the top, the animation stops and this example of the distribution can be observed. Thus,I wish to combine a sequence of animations, using the output of one to serve as the background to the next. How can I save the final graph of each `Animate` sequence so as to use it for the input of the next? The fact that animations are examples of `Manipulate` complicates matters. `Do` loops, etc. do not work here.


Why doesn't the FileNameSetter button work in my DialogInput?

I am new to _Mathematica_ , so it's probably a small error but I can't figure it out. Here is the code :               DialogInput[{TextCell["Choose your folder:"], InputField[Dynamic[x]],        FileNameSetter[Dynamic[x], "Directory"],        DefaultButton[DialogReturn[x]]}]      When I click on the browse button, nothing happen. Then, when I click on OK, the file system browsing window appears.


Can the general term my recurrence equations be written with Floor or Mod?

I want to know the formula for the general term of the following recurrence system. I guess it can be written with `Floor` or `Mod`. How can I find it?               RSolve[{a[n + 5] == a[n] + 6, a[1] == 1, a[2] == 3, a[3] == 2, a[4] == 1, a[5] == 1}, a[n], n]          DiscretePlot[-2 + (6 n)/5 +        2/5 Sqrt[28 + 53/Sqrt[5]]         Sin[(2 n \[Pi])/5 - ArcTan[15/Sqrt[85 + 38 Sqrt[5]]]] +        2/5 Sqrt[28 - 53/Sqrt[5]]         Sin[(4 n \[Pi])/5 - ArcTan[3 Sqrt[5 (85 + 38 Sqrt[5])]]], {n, 1,        20}]      **Updated** I would like to have the formula for the general term without using recursion just as               RecurrenceTable[{y[n + 5] == y[n] + 1,        Sequence @@ Table[y[i] == i, {i, 5}]}, y, {n, 1, 30}]      can be written               n - 4 Floor[(n - 1)/5] /. n -> Range@30


Copy TraditionalForm output to TraditionalForm input while keeping formatting

When I want to copy a scientific notated number from a TraditionalForm output to an input it formats it in a weird way: ![enter image description here](http://i.stack.imgur.com/yRa83.png) Another thing I want to do is only copy a few number of decimals, and remove the accent (`), at the end: ![enter image description here](http://i.stack.imgur.com/wMPbY.png)


Programmatic formatting for Mathematica code - possible?

It seems to be both an interesting programming challenge and a very useful practical application to have a Mathematica program which would allow one to pretty-print Mathematica code, so that it is easy to read and understand. Some of the desirable features of such a program:   * Works both on string and box level   * Covers many or most common cases for Mathematica code   * Is robust   * Is customizable   * Is extensible Is this possible?


How to catch the "Preemptive" evaluations from within the main loop?

When trying to make an optimized version of my `plotRange` fonction I faced a problem of catching the `"Preemptive"` evaluations generated by the FrontEnd from withing the main evaluation loop. Consider the following:               ClearAll["Global`*"]     xr[r__] := (xRange = {r}; None);     yr[r__] := (yRange = {r}; None);     nb = CreateDocument[{Plot[Sin[x], {x, 0, 6 Pi}, Ticks -> {xr, yr}]}];     {xRange, yRange}     Pause[1];     {xRange, yRange}     NotebookClose[nb]      > {xRange, yRange} > > {{-0.392699, 19.2423}, {-1.04167, 1.04167}} One can see that the first evaluation of `{xRange, yRange}` returns undefined symbols because at the moment of its evaluation the functions `xr` and `yr` are still not evaluated via a `"Preemptive"` link by the FrontEnd. But after waiting one second these functions are already evaluated and `xRange`, `yRange` are defined. Because I need these values for further evaluations I need to delay the main loop until the `"Preemptive"` evaluations will be done. (An alternative solution would be to force the FrontEnd to perform its evaluations in the main loop.) One possible way to solve the problem is to initiate a `Dialog` which will wait for the `Return` generated by the FrontEnd. But `"Preemptive"` evaluations go past the `Dialog` and do not allow the return from it (the following code freezes the kernel):               Dialog[xr[r__] := (xRange = {r}; None);      yr[r__] := (yRange = {r}; None; NotebookClose[nb];         Return[{xRange, yRange}]);      nb = CreateDocument[{Plot[Sin[x], {x, 0, 6 Pi},           Ticks -> {xr, yr}]}];]      Is it possible to catch the `"Preemptive"` evaluations from the main loop in some way? ## UPDATE Here is a comparison of my original `Rasterize`-based version and the new `FinishDynamic`-based:               gr = Plot[Sin[x], {x, 0, 6 Pi}];     plotRange[plot : (_Graphics | _Graphics3D)] :=       Quiet@Last@        Last@Reap[          Rasterize[           Show[plot, PlotRangePadding -> None, Axes -> True,             Ticks -> (Sow[{##}] &), DisplayFunction -> Identity],            ImageResolution -> 1]]     Table[plotRange[gr], {100}]; // AbsoluteTiming          plotRange[plot : (_Graphics | _Graphics3D)] :=       Quiet@Last@        Last@Reap[(nb =             CreateDocument[{Show[plot, Axes -> True,                Ticks -> (Sow[{##}] &), PlotRangePadding -> None,                DisplayFunction -> Identity]}, ShowCellBracket -> False,              WindowFrame -> "Frameless", WindowElements -> {},              WindowSize -> 1, Antialiasing -> False, Editable -> False,              Magnification -> 1, Saveable -> False,              WindowClickSelect -> False, WindowFloating -> False,              WindowFrameElements -> {}, WindowMovable -> False,              WindowSelected -> False, WindowTitle -> ""];           FinishDynamic[]; NotebookClose[nb])]     Table[plotRange[gr], {100}]; // AbsoluteTiming      > {2.828125, Null} > > {8.406250, Null} The original `Rasterize`-based version is 3 times faster.


Forcing FindRoot to return only real solutions

`FindRoot` documentation reports that if the equation and the initial point are reals, the solutions are searched in the real domain. However, in the following case I get a complex solution               FindRoot[eq, {h, 1.7}]        {h -> -0.990042 - 0.689686 I}      Same for               Assuming[Reals, FindRoot[eq, {h, 1.7}]]      Where `eq` is the following. What can I do to force _Mathematica_ to return only real solutions?               eq = 0.2888960456513873` \[Sqrt](0.4149486782073932` + (0.5637605604986459` +              h)^2) \[Sqrt](0.4756674436221575` + (0.9900423417575865` +              h)^2) + 2.2076945564517114` h \[Sqrt](0.4149486782073932` +      (0.5637605604986459` +              h)^2) \[Sqrt](0.4756674436221575` + (0.9900423417575865` +              h)^2) + 6.735521430523215` h^2 \[Sqrt](0.4149486782073932` +      (0.5637605604986459` +              h)^2) \[Sqrt](0.4756674436221575` + (0.9900423417575865` +              h)^2) + 10.54153050379155` h^3 \[Sqrt](0.4149486782073932` +      (0.5637605604986459` +              h)^2) \[Sqrt](0.4756674436221575` + (0.9900423417575865` +              h)^2) + 8.93280406600778` h^4 \[Sqrt](0.4149486782073932` +      (0.5637605604986459` +              h)^2) \[Sqrt](0.4756674436221575` + (0.9900423417575865` +              h)^2) + 3.8752891330788843` h^5 \[Sqrt](0.4149486782073932` +      (0.5637605604986459` +              h)^2) \[Sqrt](0.4756674436221575` + (0.9900423417575865` +              h)^2) + 0.666148416209407` h^6 \[Sqrt](0.4149486782073932` +      (0.5637605604986459` +              h)^2) \[Sqrt](0.4756674436221575` + (0.9900423417575865` +              h)^2) + 0.4167441738314279` \[Sqrt](0.4756674436221575` +      (0.9900423417575865` +              h)^2) \[Sqrt](1 - (0.4444444444444444`      (-0.022551321792606827` + (0.5637605604986459` +                   h)^2)^2)/(0.4149486782073932` + (0.5637605604986459` +                 h)^2))


Network database access - How do I connect to a remote database?

I am able to connect to a specific MS Access Database when it is on the same Windows computer as _Mathematica_ via the command               << DatabaseLink`;     conn = OpenSQLConnection[JDBC["odbc", "Databasename"]];      However, I cannot figure out how to connect to this database over a local area network -- disregarding trivial network problems (the computers can ping eachother), is this even possible?


Find Definition (F3) doesn't work within workspace or referenced projects

For a single project in Workbench, the "Find Definition" feature (F3, when a function name is selected) takes you to the place where the function was defined, see documentation. According to this documentation, Workbench should find your definition in any .m file in current workspace, which is not the case for me. Even for project 'App1' which has reference to function from 'App2', the Find Definition cannot find function in 'App2' (which also shows as blue color of the function, meaning Workbench doesn't know its definition). ADDED according to @magma: When I tried to get the definition of a function written in a different .m file, the Find Definition feature did not work. I even tried with all relevant .m files open in different tabs, to no avail. Anybody has a clue? thanks Peter


NDSolve does not give me the expected solution

I have an assignment where I need to compute chemical reactions by solving ODEs. I use `NDSolve` to do this. However, for one problem it does not give me the predicted answer. My friend uses MATLAB's `ode15s` function to solve it and he gets the correct solution. Is there any option in `NDSolve` that I should play with to match the correct solution? Sorry if I don't give much information on the nature of the problem since that would be tedious. However, here is the code I am using:               sol[To_?NumericQ] := NDSolve[{        T'[t] == (-q[t]/V - (uCO[T[t]] nCO'[t] + uO[T[t]] nO'[t] + uO2[T[t]] nO2'[t] + uCO2[T[t]] nCO2'[t]) / ((CvCO[T[t]] nCO[t] + CvO[T[t]] nO[t] + CvO2[T[t]] nO2[t] + CvCO2[T[t]] nCO2[t]))),        q[t] == 4 Pi r Koil (T[t] - Tenv[t]),        Tenv[t] == To,        nCO'[t] == -nCO[t] nO[t] m[t] r1[T[t]] - nCO[t] nO2[t] r2[T[t]] + nCO2[t] m[t] r1b[T[t]] + nCO2[t] nO[t] r2b[T[t]],        nO'[t] == -nCO[t] nO[t] m[t] r1[T[t]] + nCO[t] nO2[t] r2[T[t]] - 2 nO[t] nO[t] m[t] r3[T[t]] + nCO2[t] m[t] r1b[T[t]] - nCO2[t] nO[t] r2b[T[t]] + 2 nO2[t] m[t] r3b[T[t]],        nO2'[t] == -nCO[t] nO2[t] r2[T[t]] + nO[t] nO[t] m[t] r3[T[t]] + nCO2[t] nO[t] r2b[T[t]] - nO2[t] m[t] r3b[T[t]],        nCO2'[t] == nCO[t] nO[t] m[t] r1[T[t]] + nCO[t] nO2[t] r2[T[t]] - nCO2[t] m[t] r1b[T[t]] - nCO2[t] nO[t] r2b[T[t]],        m'[t] == nCO'[t] + nO'[t] + nO2'[t] + nCO2'[t],        T[0] == To,        q[0] == 0.,        nCO[0] == nCOinit,        nO[0] == 0.,        nO2[0] == nO2init,        nCO2[0] == 0.,        m[0] == nCOinit + nO2init        },       {T, q, Tenv, nCO, nO, nO2, nCO2, m},       {t, 0.00, tfinal},       MaxStepSize -> 0.001,       MaxSteps -> Infinity       ]


Internal "Periodical" functions in version 7

In version 7 there exist these `Internal`` context functions:               ?Internal`*Periodical*      > AddPeriodical   Periodicals   RemovePeriodical   $ThisPeriodical In a comment to this answer Szabolcs stated that these "seem to provide very similar (the same?) functionality" to `ScheduledTasks` in version 8.   * How do I use them?   * To what extent is is possible to mimic version 8 functionality using these?


How to start simulating physical problems?

I'm quite new to Mathematica, I have version 9. I need to use it to simulate some physical problems. I know the equations (like Maxwell's equations and Newton's laws and so on), but I have no real idea on how to get some nice visual simulating output. Maybe let's start with some example: If I have two stars rotating around each other, what is the best way in Mathematica to simulate and display the gravitational vector field of this problem (dynmically depending on the location of the stars)? Or if I have some charges (not just points, but spheres, for example, ideally with some properties like polarity and permitivity) in an external electric field, how can I calculate and visualise the resulting field and the infleunce of movements and positions of the charges? Where do I have to start here? Just by hacking the genereral equations that I have on paper into Mathematica I won't get some dynamic output. I know the basics about `Manipulate` and on how to enter equations and on how to do some basic calculations (like `DSolve`). But I have no idea on how to get these things dynamical and visual so that I can just "move around" my stars and charges and see the resulting fields visually and in numbers.


Syntax for prefix mode with multiple arguments using @ shorthand

Is it possible to use the @ symbol with multiple arguments? The `Prefix` command suggested not. If so, why?


Giving JLink Huge Memory by Default

I have noticed that _Mathematica_ makes use of Java by way of JLink, for example, in the extensions such as DatabaseLink and (I think) RLink. It also seems like Java is a first-class citizen for writing our own extensions. An issue that I almost always run in to is that my data sets are too large for the default Java heap size (-Xmx). Almost all of my notebooks have `ReinstallJava` at the top, where the maximum Java memory is set to some large fraction of the 256 gigabytes of RAM in my computer. On computers of this size, the default Java setting seems like the 640K memory limit (who could need more than that?) Sometimes, it seems hard to figure out how to set the Java memory for certain packages (e.g. in RLink, apologies, this could be made into a separate question for that.) My question: is there a place where I can "hard-wire" the maximum Java memory for a given computer so that I don't need the boiler plate code?


Graph layout on a grid

Is it possible for _Mathematica_ to layout a graph so that the connections lie on a grid? Furthermore, for graphs with multiple edges per vertex, is it possible to specify the location on the vertex for each connection? The context of this question is to use _Mathematica_ 's graph functionality to represent / visualize networks of circuit components. Each component has some number of input and output ports and I would like to be able to generate a network layout based on a connectivity map (netlist). I've been using `GraphPlot` and `LayeredGraphPlot` and have looked through quite a few different options but none that quite address these issues. ===== EDIT (by @VitaliyKaurov): ==== Reading @Szabolcs and @gsarma comments I am posting the image they to refer and which is approximately what is needed. ![enter image description here](http://i.stack.imgur.com/R2Uim.png)


What is this character: [esc][comma][esc]?

What is the character obtained with they key sequence `Esc``,``Esc` called? On my front end it is not displayed, but there's something there messing up my input. It's a bit annoying when I'm after a $\mu$ but hit the wrong key.


presenting a real number as real instead of imaginary

I have an equation which results in an answer of the form $\frac{i a}{\sqrt{c-d}}$ is there any way to get Mathematica to present it in it's real form? like $\frac{a}{\sqrt{d-c}}$ I know that I can simply take Re[f[x]] to get the real _part_ , but I don't just want the real part. If the answer is complex, I definitely want to know that, but when it is not complex and can be written as a fully real number, I would like it to give me that form. My actual is example is far more complicated than this and the inside of the radical will always be positive if it is written as d - c, but I don't think i can put that assumption in because it is so complicated. The actual example is :               (I*2^(5/2 + l)*Subscript[a, 1]^(5/2 + l)*       (Subscript[a, 0] + Subscript[a, 1])^(4 + 2*l))/      Sqrt[Gamma[4 + 2*l]*(16^(2 + l)*(3 + 2*l)*Subscript[a, 0]^(3 + 2*l)*        Subscript[a, 1]^(5 + 2*l) - 2*(2 + l)*        (Subscript[a, 0] + Subscript[a, 1])^(8 + 4*l))]      where I already have the assumptions :               {Subscript[a, 0] > 0, Subscript[a, 1] > 0, l >= 0, Element[l, Integers]}      and obtained the result (written above) when using `FullSimplify` on my system of equations.


Defining arbitrary order derivatives function

I have a function $\phi(t)$ and I want to define a function $\phi D(t,r):=\phi^{(r)}(t)$, in other words evaluate the $r$'th derivative of $\phi$ at $t$. The naive code that I have is: `phiD[t_, r_] = D[phi[t], {t, r}]` which doesn't work, because Mathematica doesn't know to evaluate the $r$ part first and then the $t$ part. What's the easiest way to implement this?


Expressions to functions, and evaluation

When calculating derivatives a expression is the result:               in:= f[x_,y_]:= 1 + 2 x + 3 x^2 y + 4 x y^2     in:= D[f[x,y],x]     out= 2 + 6 x y + 4 y^2      how do i make this result into a function? What i would like to do (syntax is illustrative):               in:= fx[x_,y_]:= D[f[x,y],x]     in:= fx[2,1]     out= 18      Also, how do i evaluate a list of expressions?               in:= D[f[x, y], {{x, y}}]     out= {2 + 6 x y + 4 y^2, 3 x^2 + 8 x y}      E.g what i would like to do (syntax is illustrative):               in:= {2 + 6 x y + 4 y^2, 3 x^2 + 8 x y}[2,1]     out= {18,28}      I am very new to mathematica and i don't find the official reference to be of much help on this subject, even though i think it is quite basic, and nothing closely resembling on google.


How do you explicitly define Box Operator (D'Alembert operator)?

I wanted to see how one can define a box operator in mathematica? $$ \Box\phi=(-\frac{\partial^{2}}{\partial t^{2}}+\frac{\partial^{2}}{\partial x^{2}}+\frac{\partial^{2}}{\partial y^{2}}+\frac{\partial^{2}}{\partial z^{2}})\phi $$ and then $$ \Box\psi(\phi) $$ Thanks.


Interpretation of output derivative expression

I am trying to write _Mathematica_ file to find `Div`, `Grad`, `Laplacian`, etc. in coordinates given by a metric tensor w.r.t Euclidean coordinates. In test my file, I am first trying it on cylindrical coordinates $(r,\theta,z)$. Here $f$ is defined as a scalar valued function dependent on these coordinates. I am running into the following problem. In one of the steps, I get terms like the following: $2f^{(0,1,0)}\lbrack r,\theta,z\rbrack^{(0,1,0)}\lbrack r,\theta,z\rbrack$ $2f^{(0,1,0)}\lbrack r,\theta,z\rbrack\lbrack r,\theta,z\rbrack$ How do I interpret these? Are they different or do they mean the same thing? I know that the superscripts refer to derivative with respect to the coordinate that is non-zero.


How to write a differential operator in Mathematica

I have a very basic question. I am trying to code the LHS of the differential equation: $$\Big[\frac{1}{\sin\theta}\frac{d}{d\theta}\big(\sin\theta\frac{d}{d\theta}\big)-\frac{m^2}{\sin^2\theta}+n(n+1)\Big]f(\theta)=0$$ into _Mathematica_. As you can see, in the first term, the differential operator is nested and is to properly act on the function $f(\theta)$. I tried to use `#1`, but (lol) I don't know how to use it! This is what I have:               Sin[θ]^(-1) D[Sin[θ] D[#1, θ], θ] - m^2*#1/Sin[θ]^2 + n (n + 1) #1      What next?! **Also** : I don't want to just stick in `f[θ]` into where I have `#1`, because eventually I would like to be able to make change of variables!


Definition of differential operators

I am curious how differential operators are defined in Mathematica. More specifically, if the Laplacian function wasn't available, how would one go on to define such a function in Mathematica directly without reference to Grad or Div? I am thinking of pure functions, but I haven't been able to reproduce the effect of the Laplacian.


Monte Carlo integration with random numbers generated from a Gaussian distribution

I want to do numerical integration of some functions using the Monte Carlo method. The default setting for the Monte Carlo method is to use a uniform distribution as far as I know. How can I change the random number generation to Gaussian when doing numerical integration?


How to make underscript like underscript in InlineFormula of lim in Notebook and (inline)Latex

This question maybe a little tiny. Firstly, Let's input underscript `Ctrl+4` in an inline cell. `InlineFormula` inline cell $\underset{n\to\infty}{\text{li}}$ However, if we use lim, we get $\lim_{n\to \infty }$ . Note: it looks the same in my `Notebook` as `Subscript` by `Ctrl+-` $\lim _{n\to \infty }$ ### TextStyleCell with InlineFormula Inline cells: * * * subscript $\lim _{n\to \infty }$underscript $\lim_{n\to \infty }$               cellExpression=Cell[TextData[{"subscript",Cell[BoxData[SubscriptBox["lim",RowBox[{"n","->","\[Infinity]"}]]],"InlineFormula"],"underscript",Cell[BoxData[UnderscriptBox["lim",RowBox[{"n","->","\[Infinity]"}]]],"InlineFormula"]}],"Text"];CellPrint@cellExpression      So how to show `$\underset{n\to\infty}{\text{lim}}$` $\underset{n\to\infty}{\text{lim}}$ in Notebook's `InlineFormula` cell? Further, you'll see that when export to Tex, they are same.               StringCases[ExportString[cellExpression, "Tex"],  "\\begin{document}" ~~ x__ ~~ "\\end{document}" -> StringTrim@x]          (*         {subscript \(\lim _{n\to \infty }\)superscript \(\lim_{n\to \infty }\)}     *)


Find the list of weather stations for specified cities

I wrote some code which retrieves temperature data from three cities every hour for five days. My problem is that the default station from which `WeatherData[]` gets its data is sometimes unavailable. Therefore, I want to know how I can find the list of weather stations for a city so I can retrieve data from an alternative station when the default station is unavailable.


how to draw a moving point on a curve?

I almost remember an example that has a moving red point on a given curve, which will moving time and time again, with no controls... now, here is my question: given a curve by               u[y_] := y^4 - 4 y^2 + 3     v[y_] := 2 y - y^3     curv=ParametricPlot[{u[y], v[y]}, {y, -2, 2}]      then, how to attach a "big red" moving point on it, which are moving again and again?


Testing for continuity over a given domain

Is there any way to use _Mathematica_ to test whether a function is continuous over a given domain?


BarChart with BarOrigin->Left: axis on top

This question is somewhat related to this one. Let's say this is the `BarChart` i want to make:               BarChart[Range[5], ChartStyle -> "Rainbow", BarOrigin -> Left,      ChartLegends -> Map[ToString, Range[5]]]      ![BarChart reflected](http://i.stack.imgur.com/dQQw3.jpg) The `BarChart` runs from the bottom and the legend starts at the top. The related question (linked above) gives a solution to reverse the legend, but i'd rather have the axis (and thus the purple bar) on top. It should look like this (made with `ImageReflect[]`): ![BarChart reflected](http://i.stack.imgur.com/KU79U.jpg) I tried `AxesOrigin`, but that doesn't work. My question seems pretty trivial, but i haven´t found a solution for it yet. **Question: is there a way to specify the origin of a`BarChart`?**


Manipulate Locator warping (snap to cursor)

I'm looking to have a Manipulator Locator that moves in discrete steps and requies the user to click on/near the locator position.. consider these two examples:               Manipulate[              Graphics[Line[{{0, 0}, q}],              PlotRange -> {{-1, 1}, {-1, 1}}], {{x,                  0}}, {{q, {0, 0}}, {-1, -1}, {1, 1}, .2, Locator}]      The locator moves in discrete steps, but _warps_ wherever you click. Alternately this does nearly the same:               p = {0, 0};     Manipulate[           Graphics[{Line[{{0, 0}, p}], Locator[Dynamic[p]]},                  PlotRange -> {{-1, 1}, {-1, 1}}], {{x, 0}}]      Here you need to click _on_ the locator to drag, but I have no way to specify the grid snap.. Any way to achieve both effects? ( this hack comes to mind as I'm posting ..               p = {0, 0};         Manipulate[q = Round[5 p]/5;             Graphics[{Line[{{0, 0}, q}], Circle[q, .1], Locator[Dynamic[p]]},                PlotRange -> {{-1, 1}, {-1, 1}}], {{x, 0}}]      not very satisfactory though.. ) Edit: Two working solutions based on Kuba's answer, plus a bit of tinkering:               p = {0, 0}; Manipulate[            Graphics[{Line[{{0, 0}, p}],             Locator[Dynamic[            p, (p = Round[ MousePosition["Graphics", {0, 0}], .2] ) &]]},                PlotRange -> {{-1, 1}, {-1, 1}}], {{x, 0}}]      ..                 Manipulate[           DynamicModule[{p = {0, 0}},                Deploy@Graphics[{Line[{{0, 0}, p}],                Locator[Dynamic[p, (p = Round[ #, .2] ) &]]},                PlotRange -> 1]], {{x, 0}}]      I remain a bit puzzled why this doesnt work:                       p = {0, 0}; Manipulate[                 Graphics[{Line[{{0, 0}, p}],                  Locator[Dynamic[p, (p = Round[#, .2] ) &]]},                  PlotRange -> {{-1, 1}, {-1, 1}}], {{x, 0}}]      (The incremental rounding causes the locator to drift away from the mouse pointer). I should rather say I see why this doesnt work, I dont see why DynamicModule fixes it.


Too much whitespace in a GraphicsGrid containing Legended Plots

Where is all the vertical whitespace coming from, and how do I get rid of it?               plot = Plot[{Sin[x], Cos[x]}, {x, 0, 10}, Frame -> True,        PlotLegends -> Placed[LineLegend["Expressions"], {1, 0.5}]];     GraphicsGrid[{{plot, plot}, {plot, plot}}, Spacings -> {0, 0}]      ![enter image description here](http://i.stack.imgur.com/St7zU.png) **EDIT** Okay, `AspectRatio` is definitely the key for the `GraphicsGrid` option (which I'm pursuing in case I don't want to rasterize). It seems I get rid of all whitespace if:   1. Use `AspectRatio->Full` in both the plot and the `GraphicsGrid`   2. Use numerical placement of the legends...not tags like "Before", etc. What I've come up with so far would get with hairy frame labels, or tick/legend text that varied in length, but I think those things are beyond the scope of this post:               leftPlot =        Plot[{Sin[x], Cos[x]}, {x, 0, 10}, Frame -> True, FrameTicks -> All,         AspectRatio -> Full, Background -> Green,         PlotRange -> {{-0.5, 10.5}, {-1.1, 1.1}},         PlotLegends ->          Placed[LineLegend["Expressions"], {{0, 0.5}, {1, 0.5}}]];     rightPlot =        Plot[{Sin[x], Cos[x]}, {x, 0, 10}, Frame -> True, FrameTicks -> All,         AspectRatio -> Full, Background -> Green,         PlotRange -> {{-0.5, 10.5}, {-1.1, 1.1}},         PlotLegends ->          Placed[LineLegend["Expressions"], {{1, 0.5}, {0, 0.5}}]];     GraphicsGrid[      {{        Show[leftPlot,          ImagePadding -> {{Automatic, None}, {None, Automatic}}],        Show[rightPlot,          ImagePadding -> {{None, Automatic}, {None, Automatic}}]        },       {        Show[leftPlot,          ImagePadding -> {{Automatic, None}, {Automatic, None}}],        Show[rightPlot,          ImagePadding -> {{None, Automatic}, {Automatic, None}}]        }},      Spacings -> {0, 0}, Frame -> True, AspectRatio -> Full,       ImageSize -> 72*{8, 4}]      ![enter image description here](http://i.stack.imgur.com/OHM6d.png)


Change the colour of a ListPlot element in each iteration of Manipulate

I would like to modify the colour of dots in a `ListPlot[Table[function]]`, e.g               Manipulate[       ListPlot[Table[{co, se}, {n, nmax}],          PlotMarkers -> {Automatic, Tiny},                            AspectRatio -> Automatic],        Style["Compacting the circle", 16, Bold],       {{nmax, 5, "Nmax (step 5)"}, 5, 250, 5, Appearance -> "Labeled"},       Dynamic[         ParametricPlot[{co, se}, {n, 1, nmax},           ImageSize -> 300,           AspectRatio -> 1]],       ControlPlacement -> Left]      The `Manipulate` runs over the variable `nmax`, and the `ListPlot` runs over `n`. This means that when n`max` varies, the number of dots also varies. What I want is to change the color of those dots when `nmax` varies.


Efficiently generating histograms with large numbers of bins

I'm trying to generate a histogram for a large data set with the following lines of code:               MaxSideLength = Ceiling[Max[data]];     Export["Histogram.png",      Image[ArrayPlot[HistogramList[data, {1, MaxSideLength, 1}][[2]],        ColorRules -> {0 -> Black, 1 -> Red, 2 -> Yellow}], ImageSize -> MaxSideLength]];      Where ImageMatrix has something like $O(10^6)$ datapoints and I want to have maybe $50,000 \times 50,000$ bins (where each bin corresponds to a pixel in the output PNG image). Unfortunately, my memory usage goes through the roof with the above script (exhausting over 200 GB of RAM). I can pull off having maybe $20{\rm k} \times 20{\rm k}$ bins, but anything above this fails. Is there a more efficient way to proceed? If need by, I can properly round all of the values in data. I know this comparison is unfair, but given that the typical output size for a $20,000 \times 20,000$ pixel output PNG is something like 40 Mb, it seems a little odd to me that the binning and image creation process would require over $2500x$ the memory in RAM. Ok, let's run a little analysis script provided by ssch:               mmu = MaxMemoryUsed[];     n = 20*10^6;     {w, h} = {5000, 5000};     data = RandomVariate[NormalDistribution[], {n, 2}];     bins = BinCounts[data,      {Min[data], Max[data], (Max[data] - Min[data])/w},      {Min[data], Max[data], (Max[data] - Min[data])/h}];     i = Image[bins /. {0 -> {0, 0, 0}, 1 -> {1, 0, 0}, 2 -> {1, 1, 0},                        3 -> {0, 0, 1}, _?IntegerQ -> {1, 1, 1}}];     mmu2 = MaxMemoryUsed[];     mmu2 - mmu      The result for my value of `n` is $\approx 600*10^6$. Increasing `n` by an order of magnitude to $20*10^7$ yields a memory usage of $\approx 12*10^9$, however, if we run the script again, overwriting the "data" data structure, the memory usage reported is again only $\approx 600*10^6$. However, if we increase the bin sizes to `{w, h} = {10000, 10000}`, the memory usage jumps to $\approx 3.5*10^9$ (for the first run), and then oddly $\approx 2.5*10^9$ for subsequent runs (since I suppose we're overwriting previous data structures). My conclusion is that an increase in the number of bins is responsible for the blowup in RAM usage.


WhenEvent in NDSolve

How come this doesn't work as I intended?               s[{x0_, y0_}, a_, v_] := NDSolveValue[{        x'[t] == vx[t], WhenEvent[x[t] > 0, vx[t] -> -vx[t]],        y'[t] == vy[t] - t, WhenEvent[y[t] < 0, vy[t] -> -vy[t]],        x[0] == x0, vx[0] == v Cos@a,        y[0] == y0, vy[0] == v Sin@a},       {x[t], y[t]}, {t, 0, 10},       DiscreteVariables -> {vx, vy}]      Simulating falling and bouncing of a 2D mass point.               With[{r0 = {-5, 7}},      ParametricPlot[Evaluate@s[r0, -.9, 2],       {t, 0, 10},       PlotRange -> {{-10, 10}, {-10, 10}},       Epilog -> {Point@r0}]]      ![Fall](http://i.stack.imgur.com/WgExY.png) I can't understand why it doesn't bounce on the x-axis first, and what _does_ happen there anyway? Event `x[t]>0` works fine.


Save variables values and definition

I used to do a lot of programming in R and recently switched to _Mathematica_. One thing that bothers me is that I haven't found a way to save variables, their values and definition! Let's look at an example:               idx = Partition[RandomSample[Range[20], 20], 3];     Table[Subscript[vars, idx[[i]]] = Total[idx[[i]]], {i, 1,      Length[idx]}];     Subscript[vars,{9,15,8}]     (*32*)      Is there a way to save the variable names as well as the corresponding values. And how would I read them into a new file? So that in a new file I can access with `Subscript[vars,{9,15,8}]` the value. I tried it with `Table[...]>>values.mx` and read it in with `values=<<values.mx` but that only gives me the values, whereas I also need the definitions. I also tried:               DumpSave["values.mx",       Table[Subscript[vars, idx[[i]]] = Total[idx[[i]]], {i, 1, Length[idx]}]]      but got an error > DumpSave::bsnosym: "Table[..] is not defined as a symbol or a context"


Efficient way of identifying the indices of first occurrences

It seems to me like identifying the first occurrence of unique elements should take about the same amount of time as it takes to delete duplicates. My data sets are much larger than this (`a` is 10-20k and `b` is 1-10k).               With[{a = 1000, b = 10}, list = RandomInteger[a, b a]];     Timing[uniques = DeleteDuplicates@list;]     Timing[firstOccurrenceIndices = Position[list, #, 1, 1] & /@ uniques // Flatten;]      > {0.000116, Null} > > {0.653104, Null} Any ideas?


Interpolating data with a step

Suppose I have some data with a step in it:               data = {{1, 1}, {2, 2}, {3, 3}, {3, 4}, {4, 5}, {5, 6}};      ![step](http://i.stack.imgur.com/g8K4B.png) Interpolation will complain about this and not give you an interpolation function:               Interpolation[data, InterpolationOrder -> 1]          Interpolation::inddp: The point 3 in dimension 1 is duplicated.      Is there any way to easily avoid this? Can I get Mathematica to give me `Piecewise` instead, or jiggle my points?


Implementing Newton's method

I have this question on coding Newton's method in _Mathematica_. ![enter image description here](http://i.stack.imgur.com/bCHim.jpg) I have some code to go by but I have no clue if it's computing the functions in the right order. The book is the numerical methods 4th edition by Faries.               NewtonsMethodList [f_, {x_, x0_}, n_] := NestList[# - (Function[x, f][#]*Derivative[1][Function[x, f]][#])/(         Derivative [1] [Function[x, f]^2][#] -           Function[x, f][#]*Derivative[2][Function[x, f]][#]) &, x0, n]


Avoid crash in recursive Dynamic

With the following `Dynamic` cell, I can reproducibly crash Mathematica, so do not try this unless you have saved all your work!               l=1;     Dynamic[Sin[l = l + 1]]      This will harmlessly run forever, or **until** you try to _right-click_ on the dynamic output (to get the context menu and perhaps to copy the current value). When you right-click on it, Mathematica crashes. Is there a simple way to avoid or catch this error before it occurs? **Edit** I also see this crash when literally using the example from the documentation for `Dynamic` (under "Applications"):               {Trigger[Dynamic[x, (a = FractionalPart[#]; x = Round[#]) &], {0,         Infinity}],       Dynamic[{Quotient[x, 60], Mod[x, 60], SetPrecision[10 a, 2]}]}      and again trying to right-click. So it's not like I'm doing something outlandish here. **Edit 2** The link Szabolcs found does indeed answer my question:               EventHandler[Dynamic[Sin[l = l + 1]], {"MouseUp", 2} :> Null]      seems to prevent the crash.


Can one find the beat of a tune with Fourier analysis?

I'm trying to find out if it's possible to find the beat of a tune by Fourier analysis with Mathematica. I'm taking a 44.1 kHz sample sound and hoping that I might get a nice peak for a frequency somewhere in the window of reasonable bpm (so, 60 to 100 per minute).               s = Import["Eleanorrigbylive.wav"];     raw = First@First@First@s;     avg = Table[Mean[Abs /@ raw[[i ;; i + 127]]], {i, 1, Length@raw/128}];     avg = Drop[avg, Floor[Length@avg/10]];      So, I'm importing the raw data and storing one channel's samples into `raw`. Because 44.1 kHz is way to much for what I want to do, I downsample it by averaging over blocks of size 128, so `avg` corresponds to samples at 344.5 Hz (which should be enough for my measurement of a 1 to 2 Hz phenomenon). Then, I'm dropping the intro of the song :) However, Fourier analysis in the expected window is more than disappointing:               ListLinePlot[      MapIndexed[(First@#2)^2*#1 &, FourierDST@avg[[1 ;; 1000]]]]      ![enter image description here](http://i.stack.imgur.com/BDFxY.png) Thus, my questions are:   * am I missing some Mathematica functionality which would not require me to do this the hard way?   * is my analysis incorrect? how could I determine the beat of a sound sample?


How to solve this equation with positive integers as a solutions?

This is a problem of United Kingdom Mathematical Olympiad. Find all triples $(x,y,z)$ of positive integers such that $$\biggl(1+\dfrac{1}{x}\biggr)\cdot \biggl(1+\dfrac{1}{y}\biggr)\cdot \biggl(1+\dfrac{1}{z}\biggr)=2.$$ I tried               Reduce[ (1 + 1/x)(1 + 1/y)(1 + 1/z) == 2 && x > 0 && y > 0 && z > 0,             {x, y, z}, Integers]      And I get               (x | y | z) ∈ Integers && x >= 2 && y > (1 + x)/(-1 + x) &&       z == (1 + x + y + x y)/(-1 - x - y + x y)      How do I tell _Mathematica_ to do that? O.K,               Reduce[ (1 + 1/x)(1 + 1/y)(1 + 1/z) == 2 && x > 0 && y > 0 && z > 0 &&              x >= y && y >= z, {x, y, z}, Integers]


Why won't Mathematica plot my function?

I'm using a theoretical answer found on the official Wolfram site as a reference to ensure my code isn't faulty (even though I'm fairly confident that my original code is half decent).               sol = DSolve[y'[x] + x*y[x] == Cos[x^2], y, x]      > >     {{y -> Function[{x}, E^(-(x^2/2)) C[1] + 1/2 E^(-(x^2/2)) Sqrt[π/10] >              (Sqrt[1 + 2 I] Erfi[Sqrt[1/2 - I] x] + Sqrt[1 - 2 I] > Erfi[Sqrt[1/2 + I] x])]}} >                 Plot[Evaluate[y[x] /. sol /. {C[1] -> 1}], {x, -7, 7}, PlotRange -> All]      The output shown of the Wolfram site actually shows a nice looking plot. On my display all I get is `-Graphics-`. There is no plot. Why is this?


How to draw line connecting points on circle

Consider the list {1,2,3,4,3,4,2,1}. I want to label these points on circle the way they appear on list(clockwise, counter clock wise doesn't matter). After that I want to connect same points by straight lines. I am not sure how to do this. Any comment appreciated. I tried:               a = {1, 2, 3, 4, 3, 4, 2, 1};      b = DeleteDuplicates[a];      c1 = Flatten[Position[a, #, 1][[1]] & /@ b];     c2 = Flatten[Position[a, #, 1][[2]] & /@ b];     pts = Table[{2 Cos[t], 2 Sin[t]}, {t, 0, 2 Pi, 2 Pi/8}];      f[x_] := Graphics[Line[{pts[[c1[[x]]]], pts[[c2[[x]]]]}]];      But this give lines separate from each other. Also How do you add circle to that? After @cormullion answer I removed my function. Now I have what I want but without labels.               a = {1, 2, 3, 4, 5, 1, 2, 3, 5, 4};     b = DeleteDuplicates[a];     c2 = Flatten[Position[a, #, 1][[2]] & /@ b];     c1 = Flatten[Position[a, #, 1][[1]] & /@ b];     r = 2;(*radius*)     pts = Table[{r*Cos[t], r*Sin[t]}, {t, 0, 2 Pi, 2 Pi/Length[a]}];     Graphics[{Circle[{0, 0}, r],        Line[{pts[[c1[[#]]]], pts[[c2[[#]]]]}] & /@ Range[Length[b]]} ]      ![enter image description here](http://i.stack.imgur.com/50nRK.gif)


How can I stop the blinking when rotating a Graphics3D?

I wrote a function `interactiveDesign` that returns different `Graphics3D` items in a list. Then I call the function `interactiveDesign`, create a textured part (`add`), and show everything in one plot.               interactiveDesign[innerColors_,outerColors_,width_,length_,wallsHeight_,middleHeight_,viewPoint_,click_,procedureButton_]:=                       (lines={};                        For[i=1,i<= Round[((N[length/10])-1)],i++,(lines=Append[lines,Polygon[{{0,((10*i)-0.5),wallsHeight},{(width/2),((10*i)-0.5),middleHeight},{(width/2),(10*i),middleHeight},{0,(10*i),wallsHeight}}]])];                        lines1={};                        For[i=1,i<= Round[((N[length/10])-1)],i++,(lines1=Append[lines1,Polygon[{{width,((10*i)-0.5),wallsHeight},{(width/2),((10*i)-0.5),middleHeight},{(width/2),(10*i),middleHeight},{width,(10*i),wallsHeight}}]])];                        gridLines1=Graphics3D[{LightBlue,lines},RotationAction->"Clip",Lighting->{innerColors},ViewPoint->viewPoint,Boxed-> False];                        gridLines2=Graphics3D[{LightBlue,lines1},RotationAction->"Clip",Lighting->{innerColors},ViewPoint->viewPoint,Boxed-> False];                        rightWall=Graphics3D[{innerColors,Polygon[{{0,0,0},{0,0,wallsHeight},{0,length,wallsHeight},{0,length,0}}]},Boxed-> False,Lighting->{{"Ambient",innerColors}},RotationAction->"Clip",ViewPoint-> viewPoint];                        leftWall=Graphics3D[{innerColors,Polygon[{{width,0,0},{width,0,wallsHeight},{width,length,wallsHeight},{width,length,0}}]},Boxed-> False,Lighting->{{"Ambient",innerColors}},RotationAction->"Clip",ViewPoint-> viewPoint];                        backWall=Graphics3D[{innerColors,Polygon[{{0,length,0},{0,length,wallsHeight},{N[width/2],length,middleHeight},{width,length,wallsHeight},{width,length,0}}]},Boxed-> False,Lighting->{{"Ambient",innerColors}},RotationAction->"Clip",ViewPoint-> viewPoint];                        shad1=Graphics3D[{outerColors,Polygon[{{0,0,wallsHeight},{N[width/2],0,middleHeight},{N[width/2],length,middleHeight},{0,length,wallsHeight}}]},Boxed-> False ,Lighting->{{"Ambient",outerColors}},RotationAction->"Clip",ViewPoint-> viewPoint];                       shad2=Graphics3D[{outerColors,Polygon[{{width,0,wallsHeight},{N[width/2],0,middleHeight},{N[width/2],length,middleHeight},{width,length,wallsHeight}}]},Boxed-> False,Lighting->{{"Ambient",outerColors}},RotationAction->"Clip" ,ViewPoint-> viewPoint];                       floor=Graphics3D[{LightBlue,Polygon[{{0,0,0},{0,length,0},{width,length,0},{width,0,0}}]},Boxed-> False,Lighting->{{"Ambient",LightBlue}},RotationAction->"Clip",ViewPoint-> viewPoint ];                       frontDoom=Graphics3D[{outerColors,Polygon[{{0,0,wallsHeight},{N[width/2],0,middleHeight},{width,0,wallsHeight}}]},Boxed-> False,Lighting->{{"Ambient",outerColors}},RotationAction->"Clip",ViewPoint-> viewPoint];                       frontEnd1=Graphics3D[{outerColors,Polygon[{{0,0,0},{0,0,wallsHeight},{N[width/4],0,wallsHeight},{N[width/4],0,0}}]},Boxed-> False ,Lighting->{{"Ambient",outerColors}},RotationAction->"Clip",ViewPoint-> viewPoint];                       frontEnd2=Graphics3D[{outerColors,Polygon[{{N[(width-(width/4))],0,0},{N[(width-(width/4))],0,wallsHeight},{width,0,wallsHeight},{width,0,0}}]},Boxed-> False,Lighting->{{"Ambient",outerColors}},RotationAction->"Clip",ViewPoint-> viewPoint];                       {gridLines1,gridLines2,rightWall,leftWall,backWall,shad1,shad2,floor,frontDoom,frontEnd1,frontEnd2});           parts = interactiveDesign[LightGreen, Gray, 500, 300, 300, 400, {2, -2, 0}, 1, ""];           add = {Graphics3D[{EdgeForm[Gray], Gray,Texture[Style["Subbu", Bold, 25]], Opacity[1],                         Polygon[      Inner[Plus, {{30, 0, 10}, {100, 0, 10}, {100, 0, 70}, {30, 0, 70}}, {-5, -5, 0},List],                    VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}           ]},                        Boxed -> False, Lighting -> {Gray}, RotationAction -> "Clip"                      ]};            Show[parts, add]       ![enter image description here](http://i.stack.imgur.com/yO4Ro.png) Everything is fine but the item with `Texture`(`add`) is blinking whenever the `Graphics3D` is rotated. How can I prevent this blinking during rotation?


Is there a function to calculate studentized range?

Is there a built-in function for studentized range or do I have to build it myself? Is there a test of normality for the studentized range?


How to use WhenEvent with a vector ODE in NDSolve

I have an ODE system I'd like to specify as a vector equation in `NDSolve`. I'm not clear on how to use `WhenEvent` for a system specified in this way. Ultimately I'd like `WhenEvent` to change the value of one of the state variables in the vector equation when it reaches a threshold. For example, the following code doesn't work because `WhenEvent[y[t]==0, ...]` is applying a conditional test to a list of values. Replacing this with `y[t][[1]]==0` also doesn't work.               sol = NDSolve[{y'[t] == {{.1, -.2}, {-.1, .2}}.y[t], y[0] == {1, 1},       WhenEvent[y[t] == 0, y[t] -> 1]}, y, {t, 0, 10}]      Ideas anyone?


How can I allow a user to input a list using parentheses and convert this to Mathematica notation dynamically?

I have the following dynamic module. It works. The problem is that whenever I try to make the variable _list_ or the variable _s_ dynamic the code doesn't work. My goal is to allow students to enter a list of points using familiar mathematical notation. That is, user inputs "(4, 5), (9, 0)" and this gets converted to {{4, 5}, {9,0}} Suggestions would be greatly appreciated. I can not for the life of me figure this out.               DynamicModule[{list = "((5, 6), (9, 0))", s},        Panel[         Column[           {            Labeled[InputField[Dynamic[list], String, FieldSize -> {50, 5}],StringForm["Data Points"], Left],            s = ToExpression[StringReplace[list, {"(" -> "{", ")" -> "}"}] ],            ListPlot[s]           }          ]        ]      ]


Rook walk and RecurrenceTable in Mathematica

This appears in a combinatorics book: $a(m,n)=2 a(m,n-1)+2 a(m-1,n)-3 a(m-1,n-1)$ It is a recurrence equation for the number of rook walks from $(0,0)$ to $(m,n)$. The initial conditions are: $ a(0,0)=1,\;a(0,1)=1,\;a(1,0)=1,\;a(1,1)=2 $ The following is my implementation in _Mathematica_ :               RecurrenceTable[{ a[m,n] == -3a[m-1,n-1] + 2a[m1,n] + 2a[m,n1],                       a[0,0] == 1, a[0,1] == 1, a[1,0] == 1, a[1,1] == 2},                      a, {m, 1, 10},{n, 1, 10}]      That will not work and just returns the function. I tried entering more initial conditions and changing the iterators to `0,10` and `2,10` etc. I know I can do this with loops or recursive functions and memoization, but I am wondering what I am doing wrong with `RecurrenceTable`


Inaccurate plot

Could someone please tell me how I can increase the accuracy of this plot, please? Or is there some other reason the lines are breaking up?               m = 60;     ContourPlot[{Re[Table[BernoulliB[n, (x + I y)], {n, m, m}]],      Im[Table[BernoulliB[n, (x + I y)], {n, m, m}]]}, {x, -5, 6}, {y, -10, 10},      AspectRatio -> Automatic]      ![enter image description here](http://i.stack.imgur.com/zRWfa.gif)


How to define a function with different types of arguments by setting conditions on function's domain?

I need help in order to properly define a function of $4$ variables. Given that:                   beta[k_Integer /; k == 1] := {0.088, -0.029, -0.010, -0.029, 0.019, 0.012};         beta[k_Integer /; k >= 2] := {0.227, -0.098, -0.024, -0.060, 0.027, 0.000};         size = {"low", "medium", "high"};         type = {"a", "b", "c"};      The "incomplete" definition for my function `f` looks like this:                   f[k_Integer, x_, y_, z_] :=           Total[beta[k]*{1, Log[x], DiscreteIndicator[y, "medium", size],              DiscreteIndicator[y, "low", size],              DiscreteIndicator[z, "b", type], DiscreteIndicator[z, "a", type]}]      I'm using `Table` to iterate values of function's arguments:                   Table[f[k, x, y, z], {k, 1, 2}, {z, Reverse[type]}, {y, size}] // MatrixForm      The output result is:                  (* {{{0.059 - 0.029 Log[x], 0.078 - 0.029 Log[x],             0.088 - 0.029 Log[x]}, {0.078 - 0.029 Log[x], 0.097 - 0.029 Log[x],             0.107 - 0.029 Log[x]}, {0.071 - 0.029 Log[x], 0.09 - 0.029 Log[x],             0.1 - 0.029 Log[x]}}, {{0.167 - 0.098 Log[x],             0.203 - 0.098 Log[x], 0.227 - 0.098 Log[x]}, {0.194 - 0.098 Log[x],             0.23 - 0.098 Log[x], 0.254 - 0.098 Log[x]}, {0.167 - 0.098 Log[x],             0.203 - 0.098 Log[x], 0.227 - 0.098 Log[x]}}} *)      The problem is that the function `f` should not be defined for a specific combination of argument values:                   k=1  &&  y="low"    && z="b"         k=1  &&  y="high"   && z="b"         k=1  &&  y="medium" && z="a"         k=1  &&  y="high"   && z="a"         k>=2 &&  y="high"   && z="b"         k>=2 &&  y="medium" && z="a"         k>=2 &&  y="high"   && z="a"      The first condition is actualy saying that there are no `"low"` objects (or whatever) in the category `"b"`, for `k==1`. How can I define the function `f` exactly, so that `f` would not be defined for the conditions listed above? I think that the solution is to restrict the domain of function `f`, by setting conditions on its arguments, but I have no idea how to do this. This is what I ended up with (worst code ever):                   {{{f[1, x, "low", "c"], f[1, x, "medium", "c"],             f[1, x, "high", "c"]}, {"not defined", f[1, x, "medium", "b"],             "not defined"}, {f[1, x, "low", "a"], "not defined",             "not defined"}}, {{f[2, x, "low", "c"], f[2, x, "medium", "c"],             f[2, x, "high", "c"]}, {f[2, x, "low", "b"],             f[2, x, "medium", "b"], "not defined"}, {f[2, x, "low", "a"],             "not defined", "not defined"}}}      Output:                   {{{0.059 - 0.029 Log[x], 0.078 - 0.029 Log[x],             0.088 - 0.029 Log[x]}, {"not defined", 0.097 - 0.029 Log[x],             "not defined"}, {0.071 - 0.029 Log[x], "not defined",             "not defined"}}, {{0.167 - 0.098 Log[x], 0.203 - 0.098 Log[x],             0.227 - 0.098 Log[x]}, {0.194 - 0.098 Log[x], 0.23 - 0.098 Log[x],             "not defined"}, {0.167 - 0.098 Log[x], "not defined",             "not defined"}}}      I appreciate any suggestion.


Obtaining a function from the function

Assume that;               w[n_] :=Expand[Sum[Binomial[n - k - 1, k]*(-1)^k*A^(n - 2*k - 1), {k, 0, n - 1}]]     f[x_,y_, z_]:=PolynomialRemainder[(w[z] - 1)*(w[y] - 1), (w[x] - 1), A]      According to the above definitions, the function `f` depends on `x,y,z` and `A`. I want to have a new function only depends on `A` for any `x,y,z`. For example, when i put some values for `x,y,z`, i want a function such `g[A_]:=.........`How can i obtain? Thanks...


Problem with dynamic MouseAppearance updating while "MouseDown"

my problem is with combining `EventHandler` and `MouseAppearance`. I want to change cursor appearance if I have primary button pressed over on item. But only then, after releasing it should be "Arrow" back. I thought it should work:               Dynamic@MouseAppearance[#, mysz]&@EventHandler[       Framed["A"], {"MouseUp" :> (mysz = "Arrow"), "MouseDown" :> (mysz = "A")}]      but it doesn't. The strange thing is, using "MouseClicked" it works, of course effect is different, it works like it should. Second thing is variable "mysz" is updated to "A" while button is pressed... but appearance doesn't change.


Solving the wave PDE using the Fourier method

I am trying to solve the wave PDE using the Fourier method and I need to animate the plots of the partial sum of order 45 -- U45(x,t) with initial conditions U45(x,t0), {t0, 0, 12, .2}. I am confused: should I define the function f[x, t, k_] or should I do it as f[x, k_] and later access the 't'.               a[k_] :=        Piecewise[{         {2/(k*π) Integrate[Cos[(k*π*x)/6] (2 - x) Sin[π*x]^2, {x, 1, 3}], k != 0},         {1/6 Integrate[(2 - x) Sin[π*x]^2, {x, 1, 3}], k == 0}}]          f[x, t, k_] :=        a[0]*t + Sum[a[i] Cos[(i*π*x)/6] Sin[(i*π*t)/6], {i, k}]          sol = f[x, t, 45];      Anyway, the above is the piece of code I've written so far. Tried a dozen different Plot3D combinations, but the error I receive tells me I can not replace t. I am open to everything tutorials, papers, tips, plain solutions, everything.


Plotting a function, x = 1024

The function                s12 = 1/(Log[2^x]*((7.537/(x^2)) + (30.148/((2 + x)^3))))      returns expected function values for `0 < x < 10,000` but the graph drops to 0 at `x = 1024`. I am using the home version 9.0. Am assuming operator error unless told otherwise, but an older version plots without problems. Any advice welcome.


Encoding format used by GraphicsData?

I am trying to extract some graphics stored in PICT format from a Mathematica notebook, using a platform that doesn't support PICT. If I look at the `.nb` file in a plain text editor, or if I use `FullForm`, then I can see that the picture is stored as a `GraphicsData` head with a text string encoding the picture. It doesn't appear that the `GraphicsData` head uses Base64 or any other binary-to-text encoding that I know of off the top of my head, but I would like to be able to copy-and-paste the `GraphicsData` string and decode it manually. Is this possible? Does `GraphicsData` use a well-known encoding scheme?


Possible to batch WolframAlpha queries?

Sometimes I want some country data not available from `CountryData`. And issuing things like:               WolframAlpha[ToString[#]<>" | whatever data",                   {{"Result", 1}, "ComputableData"}                 ]&/@CountryData["Countries"]      is both incredibly slow and I'm sure to hit my daily API limit. Can I do all these requests in one go?


Difference between FindInstance and NSolve

Assume that               w[n_] :=Expand[Sum[Binomial[n - k - 1, k]*(-1)^k*A^(n - 2*k - 1), {k, 0, n - 1}]]     f[y_, z_]:=PolynomialRemainder[(w[z] - 1)*(w[y] - 1), (w[i] - 1), A]     h[{y_, z_}] :=Quiet[N[FindRoot[Abs[f[y, z]] - w[i] + 1 == 0, {A, 10000000}]]]     For[i = 153, i < 210, i++,Print[{i}, Max[ParallelMap[h, Subsets[Range[i + 1, 210], {2}]]]]]      According to above code, there are lots of roots. But, when I try to find them with `NSolve`, there is no root. Why?


MUnit test debug breakpoints in Workbench not working

When I create a breakpoint in Workbench 2 for an MUnit test, and run a debug build, the breakpoints are not breaking execution. The MUnit output is updated like a normal run without breakpoints. Why is this happening?


How to solve an inequality

I am trying to solve the following inequality:               Assuming[{R[k] >= 0, R[k + 1] = R[k] - 2^N Y, Y >= 0 && N >= 0},       Refine[Re[R[k + 1] >= 0]]      I want check whether R[k+1] >=0 is true or not, but I am getting Re[True < 0] and I don't know what this means.               R[k + 1] = R[k] - 2^N Y     Y >= 0     N >= 0     Simplify[R[k + 1] < 0, R[k] >= 0]      In this case i am getting R[k] < 2^k Y. I want true or false as result.


Order imported files by their alteration date

Probably a very easy question, but I could not find the answer, so it would be very nice if you can help me: Let us say I have 10 files, all with the extension `.dat`. Using               data = Import[#, "Table"] & /@ FileNames["*.dat"];       I can import all .dat files in a folder. However, I want _Mathematica_ to order these .dat files by their alteration date just like I can do it under Windows with a right click > Sort by > alteration date. I want _Mathematica_ to import the files in exactly this order. How might I do this?


Solving a system of ODEs with the Runge-Kutta method

I´m trying to solve a system of ODEs using a fourth-order Runge-Kutta method. I have to recreate certain results to obtain my degree. But I'm a beginner at _Mathematica_ programming and with the Runge-Kutta method as well.               {A=0.30, B=1, C=40, D=1, E=0.75, F=0.11,      r=2.5, a=2, e=0.475, g=2, d=0.03, n=0.01, p=-0.00005}          x'[t]/x[t]=(A+B x[t]-Cx[t]^2-F)/(D+E^(r y[t]));        y'[t]/y[t]=g(((a s[t] x[t] k[t])/m[t])-e)(1-y[t]);      m'[t]/m[t]=n;     k'[t]/k[t]=x[t]-d;     s'[t]/s[t]=-p;      I'd appreciate any kind of help. For over a month now, I've tried to solve this system myself but have only gotten bad results. This model is suppose to fluctuate around the equilibrium point but in the code I have so far, this doesn't happen.


Reduce - Most efficient expression - Using FullSimplify

I am trying to solve complicated inequalities using `Reduce`, in order to determine whether certain mixed equilibria in game theory are stable. My first question regarding this function is the following: I noticed that `Reduce[expr, {p,e1,e2,e3},Reals]` is, in fact, substantially slower than `Reduce[expr,Reals]` - at least, in my case. I have attached the following .nb to illustrate the problem (https://dl.dropboxusercontent.com/u/118904317/GameTheory.nb). The expressions are too long to copy the code here. Please look at the difference between `myConditionsReduced` and `myConditionsReducedb`. Can someone explain why it is the case that the second option is faster? What is the fundamental difference, and can someone explain whether the result obtained using the faster option is just as good? My second question refers to the combined use of `FullSimplify` and `Reduce`. I originally figured putting the `expr` into `FullSimplify` before putting it into `Reduce` would speed things up. This is not always true, as can be seen by comparing `myConditionsReduced` and `myConditionsReducedc` in my attached notebook. Can someone explain why `FullSimplify` sometimes works well for reducing inequalities, and why it sometimes only slows things down? Thank you, Laurens PS. I have not been able to reach the end of my notebook in terms of evaluation. The final line doesn't produce an output, even after 1 hour for me. If you know a way to make things more efficient, thank you for helping me out.


Sum of first n items in a sequence

What's a way to sum over the first n items in a sequence, for example the sequence defined by $2^{k-1}\cdot k$ for $k\in\mathbb{Z},k>0$? I do these by hand all the time but am a bit tired of doing this, so I'm looking for a way in mathematica. Sorry if someone already asked this before, couldn't find any similar questions.


Export data of a 3D histogram

I want to export the data of a three dimensional histogram in the format               #   x     y     z        with a blank line between different lines, so that one can plot the histogram in gnuplot simply using               splot 'data.dat' u 1:2:3 w l      What is the right way to obtain that?


Save output of NDSolve to a file

I am solving following differential equation using Mathematica,               s = NDSolve[{u''[x] == (42/10)*Sin[x]*Sin[x]*u[x], u[-3] == 0,         u'[3] == 1}, u, {x, -3, 3}, WorkingPrecision -> 22,        InterpolationOrder -> All]     Plot[Evaluate[{u[x] /. s}, {x, -3, 3}], AxesLabel -> {"x", "v(x)"},       PlotStyle -> {Thickness[0.005]}, PlotRange -> All]      I would like to plot this output with gnuplot (as all of the other figure in my report are generated using gnuplot) to be consistent. How can I generate file with $x$ and $u(x)$ values written in 2 columns? I tried to write output in a file,                 sW = OpenWrite["out.dat", FormatType -> TraditionalForm];         $Output = {sW};         Write[sW, x, Evaluate[u[x] /. s], {x, -3, 3, 1}]         Close[sW];      But this does not print values of $u(x)$


Visual Studio Express 2010 on x86-64: libcmt.lib missing

The CCompilerDriver documentation explains that to use visual studio express on 64-bit targets, it's necessary to install the windows SDK after installing visual studio. I have done this, first installing visual studio express 2010 and then installing v7.1 of the windows SDK. However, I still have a problem due to a missing LIBCMT.LIB > >     Compiler`$CCompilerOptions={"ShellOutputFunction"->Print}; >     cFun=Compile[{{x}},x^2, CompilationTarget->"C"]; >                 C:\Users\lev\AppData\Roaming\Mathematica\ApplicationData\CCompilerDriver\BuildFolder\lev-think-5052\Working-lev-think-5052-7032-1>call "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64           Setting SDK environment relative to C:\Program Files\Microsoft SDKs\Windows\v7.1\.     Targeting Windows 7 x64 Debug          Microsoft (R) C/C++ Optimizing Compiler Version 16.00.30319.01 for x64     Copyright (C) Microsoft Corporation.  All rights reserved.          compiledFunction0.c     Microsoft (R) Incremental Linker Version 10.00.30319.01     Copyright (C) Microsoft Corporation.  All rights reserved.          /out:compiledFunction0.dll      /dll      /implib:compiledFunction0.lib      /implib:C:\Users\lev\AppData\Roaming\Mathematica\ApplicationData\CCompilerDriver\BuildFolder\lev-think-5052\Working-lev-think-5052-7032-1\compiledFunction0.lib      "/LIBPATH:C:\Program Files\Wolfram Research\Mathematica\8.0\SystemFiles\Links\MathLink\DeveloperKit\Windows-x86-64\CompilerAdditions\mldev64\lib"      "/LIBPATH:C:\Program Files\Wolfram Research\Mathematica\8.0\SystemFiles\Libraries\Windows-x86-64"      ml64i3m.lib      /out:C:\Users\lev\AppData\Roaming\Mathematica\ApplicationData\CCompilerDriver\BuildFolder\lev-think-5052\Working-lev-think-5052-7032-1\compiledFunction0.dll      compiledFunction0.obj      LINK : fatal error LNK1104: cannot open file 'LIBCMT.lib'      Has anyone managed to get this configuration working? How about with visual studio express 2008 and v7.0 of the SDK? It took me several tries to get even this far, because I made the mistake of letting windows update install SP1 for visual studio express and this prevented installing the SDK, and I had had uninstall and reinstall everything a few times (it's not possible to simply uninstall SP1), so it's possible I've messed up my installation somehow. I can see that there is a LIBCMT.LIB in `C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib` which I presume is a 32-bit version of the library and not what the linker is looking for in this case.


Programmatically opening a palette from the Palettes menu

How can I programmatically open a palette from the Palettes menu? Is there a Front End token for this? * * * Motivation: Certain settings for the palettes that are installed into standard locations and show up in the Palettes menu are stored in the `"PalettesMenuSettings"` global option (accessible through the Option Inspector or `CurrentValue[$FrontEnd, "PalettesMenuSettings"]`). These settings become active only if the palette is opened through the Palettes menu. If the palette notebook is opened directly (through the operating system's file manager or `File -> Open...`), then these settings do not take effect. Use case: I need to re-open the image uploader palette after it has updated itself. The upload history is stored in the `"PalettesMenuSettings"`.


Remove controls in Animate with exception of PlayPauseButton

I'd like to retain the `PlayPauseButton` in the `Animate` and remove all other `Controls` available by default. I've looked at How can I completely remove the ListAnimate controls?, but haven't had success with these methods in my complex example. This works:               Animate[Plot[Sin[x + a], {x, 0, 10}], {a, 0, 5},        AnimationRunning -> False] /.       HoldPattern[        AppearanceElements -> _] -> (AppearanceElements -> \     {"PlayPauseButton"})      but this does not:               Dynamic@Animate[     If[j == 1, Clear[DataTable2, DataTable3]; DataTable2 = {};       DataTable3 = {}];      AppendTo[DataTable2, {steps[[2, 1, j]], f@steps[[2, 1, j]]}];     AppendTo[DataTable3, {steps[[2, 1, j]], steps[[2, 1, j]]}];      AppendTo[DataTable3, {steps[[2, 1, j]], f@steps[[2, 1, j]]}];     Dynamic@      Plot[{f[x], y = x}, {x, interval[[1]], interval[[2]]},        PlotLabel ->         Style[StringForm["``. The orbit of x is\n``\n", explanation,           textCell], 12, TextAlignment -> Center],        ImagePadding -> {{Automatic, Automatic}, {Automatic, 1}},        PerformanceGoal -> "Quality",       ImagePadding -> 25, PlotRange -> {interval[[1]], interval[[2]]},        AspectRatio -> 1, ImageSize -> {400, 400},        Epilog -> {Gray, Line[DataTable3], Black, PointSize[0.015],          Point@{DataTable2}, Red, PointSize[0.015],          Point@{steps[[2, 1, j]], f@steps[[2, 1, j]]}}], {j, locate,       Length[steps[[2, 1]]], 1}, DisplayAllSteps -> True,      AnimationRunning -> False, LabelStyle -> White] ]]/.       HoldPattern[        AppearanceElements -> _] -> (AppearanceElements -> \     {"PlayPauseButton"})


How to draw quantum circuit with mathematica?

How to draw quantum circuit as the following one with mathematica? ![enter image description here](http://i.stack.imgur.com/1HRpa.png) I only find the quantum package which is designed for MMA 7.0 as the author said. But the version of my Mathematica is 9.0 and when I try that package there is an error as following ![enter image description here](http://i.stack.imgur.com/Lbcka.png) How to get over this problem? Is there any other method or package to draw quantum circuit? Ps: the mathematica file including the above error


KernelObject::rdead on local kernels

I'm trying to parallelize some tasks which involve fetching data from a URL and processing it. This is the code:               keyId = 1;     SetSharedVariable[keyId];     Clear[keyLock];          EncodeURL[str_String] :=       StringReplace[str,        x : Except[Alternatives @@ Characters@";/?:@=&$-_.+!*'()"] :>         ExternalService`EncodeString[x]]     ApiKeys =        {        "key1",        ...        ...        "lastKey"        };          Api[urlNoKey_] :=       TimeConstrained[ApiInternal[urlNoKey], 5, Api[urlNoKey]]          ApiInternal[urlNoKey_] :=       Block[{content, code,         url = EncodeURL[          baseURL <> urlNoKey <> "?api_key=" <> ApiKeys[[keyId]]]},       {content, code} =         Check[URLFetch[url, {"Content", "StatusCode"}], {$Failed, $Failed}];       PrintTemporary[url];       CriticalSection[{keyLock},        If[keyId == Length@ApiKeys, keyId = 1, keyId++];        ];       Switch[code,        200, ImportString[content, "JSON"],        404, {},        429 , LolApiInternal[urlNoKey], (* Rate time limit exceeded *)        $Failed, Print["Api::error -> URLFetech returned $Failed"]; {},        code, Print["Api::error -> Unkown code: ", code,          ".Content was: ", content]; {}        ]       ]      I am using a 4 core machine but since the computing is small and URLFetch is involved, I am using 8 kernels (using `LaunchKernels[8]`) I am trying to distribute the processing of a list of about 10.000 urls:               ParallelMap[Process@Api[#] &, urlList];      I get the following errors (and more) during the computation (usually, near the end) ![http://i.imgur.com/PdC2ORK.png](http://i.stack.imgur.com/ZNE1w.png) Any idea why and how to solve it? Note that I am using FetchURL and ImportString (I think this last one uses a Java link)


How can i integrate over a set of data

i need to integrate over my data, which is denoted as {q, I},here I is the Intensity i need to obtain the form of the following integration( its not a numeric integration, because it contain x, next we need to plot over x ranges）                gamma[x_]:=Integrate[i*q^2*Cos[q*x],{q,0,Infinity}]/Integrate[i*q^2,{q,0,Infinity}]      and here problems come, the data i posted next is just from q ranges 0.1-1.8, how can i Integrate from o to Infinity, i need to extrapolation. function I1 is the extrapolation function of q ranges 0-0.1                I1 = 11922 Exp[-217.2136 q^2];      function I3 is the extrapolation function of q ranges 1.8-Infinity                I3 = 23.6631/q^4      and I2 is from the data set in the following i hope i expressed it clear               data={{0.06781, 8484.9}, {0.07145, 8104.34}, {0.07508, 7511.06}, {0.07872,        6941.88}, {0.08236, 6731.36}, {0.08599, 5949.97}, {0.08963,        5077.74}, {0.09327, 4354.2}, {0.0969, 3756.52}, {0.10054,        3259.68}, {0.10418, 2853.38}, {0.10781, 2504.39}, {0.11145,        2212.84}, {0.11509, 1959.85}, {0.11873, 1746.78}, {0.12236,        1563.75}, {0.126, 1407.37}, {0.12964, 1268.35}, {0.13327,        1146.27}, {0.13691, 1042.39}, {0.14055, 953.417}, {0.14418,        870.465}, {0.14782, 799.707}, {0.15146, 737.023}, {0.15509,        679.906}, {0.15873, 628.893}, {0.16237, 584.248}, {0.16601,        545.282}, {0.16964, 507.971}, {0.17328, 475.35}, {0.17692,        444.392}, {0.18055, 416.804}, {0.18419, 392.803}, {0.18783,        371.445}, {0.19146, 351.733}, {0.1951, 334.393}, {0.19874,        315.427}, {0.20237, 300.287}, {0.20601, 285.826}, {0.20965,        273.292}, {0.21329, 262.379}, {0.21692, 251.135}, {0.22056,        239.252}, {0.2242, 230.232}, {0.22783, 222.497}, {0.23147,        213.946}, {0.23511, 205.512}, {0.23874, 197.638}, {0.24238,        191.972}, {0.24602, 186.409}, {0.24965, 180.46}, {0.25329,        175.138}, {0.25693, 169.796}, {0.26056, 165.13}, {0.2642,        161.325}, {0.26784, 157.513}, {0.27148, 153.733}, {0.27511,        149.522}, {0.27875, 146.791}, {0.28239, 143.153}, {0.28602,        140.23}, {0.28966, 137.172}, {0.2933, 134.419}, {0.29693,        132.738}, {0.30057, 130.481}, {0.30421, 129.09}, {0.30784,        126.987}, {0.31148, 124.435}, {0.31512, 121.708}, {0.31876,        120.509}, {0.32239, 118.925}, {0.32603, 117.507}, {0.32967,        116.602}, {0.3333, 114.86}, {0.33694, 114.622}, {0.34058,        113.327}, {0.34421, 112.26}, {0.34785, 110.94}, {0.35149,        110.31}, {0.35512, 109.351}, {0.35876, 109.165}, {0.3624,        107.605}, {0.36604, 107.1}, {0.36967, 107.072}, {0.37331,        106.396}, {0.37695, 105.881}, {0.38058, 105.079}, {0.38422,        104.814}, {0.38786, 104.518}, {0.39149, 104.239}, {0.39513,        104.218}, {0.39877, 104.616}, {0.4024, 104.247}, {0.40604,        104.502}, {0.40968, 104.512}, {0.41332, 104.647}, {0.41695,        104.856}, {0.42059, 104.842}, {0.42423, 104.808}, {0.42786,        106.149}, {0.4315, 106.071}, {0.43514, 106.709}, {0.43877,        107.227}, {0.44241, 107.229}, {0.44605, 108.764}, {0.44968,        109.394}, {0.45332, 110.322}, {0.45696, 110.856}, {0.4606,        111.624}, {0.46423, 112.749}, {0.46787, 114.406}, {0.47151,        115.42}, {0.47514, 116.616}, {0.47878, 117.699}, {0.48242,        119.237}, {0.48605, 121.019}, {0.48969, 123.189}, {0.49333,        124.483}, {0.49696, 125.923}, {0.5006, 128.118}, {0.50424,        129.74}, {0.50788, 131.626}, {0.51151, 133.838}, {0.51515,        136.143}, {0.51879, 138.442}, {0.52242, 141.053}, {0.52606,        143.342}, {0.5297, 145.457}, {0.53333, 147.548}, {0.53697,        149.772}, {0.54061, 152.372}, {0.54424, 154.745}, {0.54788,        156.967}, {0.55152, 159.494}, {0.55516, 161.299}, {0.55879,        163.617}, {0.56243, 166.065}, {0.56607, 168.23}, {0.5697,        169.203}, {0.57334, 170.825}, {0.57698, 172.429}, {0.58061,        173.287}, {0.58425, 174.083}, {0.58789, 175.532}, {0.59152,        176.836}, {0.59516, 177.118}, {0.5988, 176.328}, {0.60244,        176.706}, {0.60607, 175.924}, {0.60971, 175.741}, {0.61335,        175.363}, {0.61698, 175.389}, {0.62062, 174.525}, {0.62426,        173.079}, {0.62789, 171.666}, {0.63153, 170.46}, {0.63517,        168.736}, {0.6388, 167.342}, {0.64244, 165.309}, {0.64608,        163.865}, {0.64972, 161.676}, {0.65335, 159.474}, {0.65699,        157.696}, {0.66063, 155.701}, {0.66426, 153.095}, {0.6679,        150.474}, {0.67154, 148.005}, {0.67517, 145.32}, {0.67881,        143.644}, {0.68245, 141.367}, {0.68608, 138.666}, {0.68972,        136.463}, {0.69336, 133.792}, {0.697, 131.181}, {0.70063,        128.582}, {0.70427, 126.332}, {0.70791, 123.564}, {0.71154,        121.367}, {0.71518, 118.912}, {0.71882, 116.346}, {0.72245,        113.677}, {0.72609, 110.937}, {0.72973, 108.678}, {0.73336,        106.565}, {0.737, 104.007}, {0.74064, 101.485}, {0.74427,        99.3778}, {0.74791, 96.6665}, {0.75155, 94.4102}, {0.75519,        92.0078}, {0.75882, 89.8159}, {0.76246, 87.9642}, {0.7661,        86.4317}, {0.76973, 84.2645}, {0.77337, 82.3022}, {0.77701,        80.6899}, {0.78064, 78.6728}, {0.78428, 76.7569}, {0.78792,        75.3695}, {0.79155, 73.8918}, {0.79519, 72.5105}, {0.79883,        71.0565}, {0.80247, 69.4262}, {0.8061, 67.8192}, {0.80974,        66.4008}, {0.81338, 65.1667}, {0.81701, 63.8111}, {0.82065,        62.6912}, {0.82429, 61.6939}, {0.82792, 60.6722}, {0.83156,        59.6988}, {0.8352, 58.3351}, {0.83883, 57.1573}, {0.84247,        56.3272}, {0.84611, 55.2564}, {0.84975, 54.3547}, {0.85338,        53.3978}, {0.85702, 52.1346}, {0.86066, 51.3827}, {0.86429,        50.4844}, {0.86793, 49.6377}, {0.87157, 48.8713}, {0.8752,        48.2443}, {0.87884, 47.7294}, {0.88248, 46.8157}, {0.88611,        46.0304}, {0.88975, 45.1212}, {0.89339, 44.7745}, {0.89703,        43.9961}, {0.90066, 43.0952}, {0.9043, 42.5257}, {0.90794,        42.2893}, {0.91157, 41.8312}, {0.91521, 40.9686}, {0.91885,        40.3532}, {0.92248, 39.7576}, {0.92612, 39.4586}, {0.92976,        38.8747}, {0.93339, 38.4161}, {0.93703, 37.7528}, {0.94067,        37.3574}, {0.94431, 36.8382}, {0.94794, 36.3011}, {0.95158,        35.9058}, {0.95522, 35.4485}, {0.95885, 34.9093}, {0.96249,        34.32}, {0.96613, 34.0316}, {0.96976, 33.591}, {0.9734,        33.3216}, {0.97704, 33.0267}, {0.98067, 32.4282}, {0.98431,        32.3091}, {0.98795, 32.0845}, {0.99159, 31.6361}, {0.99522,        31.2284}, {0.99886, 30.7767}, {1.0025, 30.4388}, {1.00613,        30.2196}, {1.00977, 29.8235}, {1.01341, 29.5197}, {1.01704,        29.344}, {1.02068, 29.0606}, {1.02432, 28.5289}, {1.02795,        28.102}, {1.03159, 28.0264}, {1.03523, 28.0783}, {1.03887,        27.6681}, {1.0425, 27.5522}, {1.04614, 27.1552}, {1.04978,        26.8587}, {1.05341, 26.6213}, {1.05705, 26.3301}, {1.06069,        26.1524}, {1.06432, 25.8047}, {1.06796, 25.5832}, {1.0716,        25.5029}, {1.07523, 25.203}, {1.07887, 24.9392}, {1.08251,        24.9243}, {1.08615, 24.8342}, {1.08978, 24.4551}, {1.09342,        24.0326}, {1.09706, 23.5549}, {1.10069, 23.5307}, {1.10433,        23.4796}, {1.10797, 23.2503}, {1.1116, 23.079}, {1.11524,        23.1125}, {1.11888, 22.941}, {1.12251, 22.6978}, {1.12615,        22.4483}, {1.12979, 22.5276}, {1.13343, 22.0572}, {1.13706,        22.0038}, {1.1407, 21.9636}, {1.14434, 21.7319}, {1.14797,        21.4474}, {1.15161, 21.4931}, {1.15525, 21.2675}, {1.15888,        20.9086}, {1.16252, 20.9773}, {1.16616, 20.7104}, {1.16979,        20.607}, {1.17343, 20.5066}, {1.17707, 20.5538}, {1.18071,        20.4422}, {1.18434, 20.2128}, {1.18798, 20.0675}, {1.19162,        20.1379}, {1.19525, 19.774}, {1.19889, 19.5749}, {1.20253,        19.4279}, {1.20616, 19.1179}, {1.2098, 19.1727}, {1.21344,        19.2947}, {1.21707, 18.9027}, {1.22071, 18.7805}, {1.22435,        18.6712}, {1.22798, 18.5499}, {1.23162, 18.4297}, {1.23526,        18.612}, {1.2389, 18.4414}, {1.24253, 18.1845}, {1.24617,        17.9992}, {1.24981, 18.079}, {1.25344, 17.7912}, {1.25708,        17.7384}, {1.26072, 17.474}, {1.26435, 17.475}, {1.26799,        17.5717}, {1.27163, 17.2923}, {1.27526, 17.2294}, {1.2789,        17.2249}, {1.28254, 17.2097}, {1.28618, 16.8087}, {1.28981,        16.8752}, {1.29345, 16.8982}, {1.29709, 16.8445}, {1.30072,        16.847}, {1.30436, 16.5705}, {1.308, 16.4896}, {1.31163,        16.4364}, {1.31527, 16.3896}, {1.31891, 16.213}, {1.32254,        16.2278}, {1.32618, 16.0167}, {1.32982, 16.1231}, {1.33346,        16.0964}, {1.33709, 16.0232}, {1.34073, 15.7609}, {1.34437,        15.8084}, {1.348, 15.6584}, {1.35164, 15.6287}, {1.35528,        15.6796}, {1.35891, 15.7029}, {1.36255, 15.546}, {1.36619,        15.2124}, {1.36982, 15.2086}, {1.37346, 15.0757}, {1.3771,        14.923}, {1.38074, 15.1161}, {1.38437, 14.9677}, {1.38801,        15.0016}, {1.39165, 14.8281}, {1.39528, 14.8684}, {1.39892,        14.6861}, {1.40256, 14.5675}, {1.40619, 14.4593}, {1.40983,        14.6113}, {1.41347, 14.5008}, {1.4171, 14.3918}, {1.42074,        14.3476}, {1.42438, 14.3555}, {1.42802, 14.3623}, {1.43165,        14.339}, {1.43529, 14.2684}, {1.43893, 13.9455}, {1.44256,        13.9627}, {1.4462, 14.0328}, {1.44984, 13.8979}, {1.45347,        13.7776}, {1.45711, 13.8756}, {1.46075, 13.6197}, {1.46438,        13.7516}, {1.46802, 13.647}, {1.47166, 13.6387}, {1.4753,        13.5843}, {1.47893, 13.649}, {1.48257, 13.5493}, {1.48621,        13.3301}, {1.48984, 13.3416}, {1.49348, 13.3377}, {1.49712,        13.2524}, {1.50075, 13.0905}, {1.50439, 13.1987}, {1.50803,        13.1023}, {1.51166, 13.162}, {1.5153, 13.0719}, {1.51894,        13.1163}, {1.52258, 12.9534}, {1.52621, 12.9181}, {1.52985,        12.8718}, {1.53349, 12.9131}, {1.53712, 12.8463}, {1.54076,        12.7041}, {1.5444, 12.7167}, {1.54803, 12.458}, {1.55167,        12.4296}, {1.55531, 12.5131}, {1.55894, 12.556}, {1.56258,        12.5933}, {1.56622, 12.5091}, {1.56986, 12.4594}, {1.57349,        12.4128}, {1.57713, 12.3223}, {1.58077, 12.2438}, {1.5844,        12.324}, {1.58804, 12.1571}, {1.59168, 12.1936}, {1.59531,        12.2051}, {1.59895, 12.2231}, {1.60259, 12.1543}, {1.60622,        12.0448}, {1.60986, 12.1679}, {1.6135, 11.9565}, {1.61714,        11.9209}, {1.62077, 12.0175}, {1.62441, 11.9823}, {1.62805,        11.8246}, {1.63168, 11.8108}, {1.63532, 11.7502}, {1.63896,        11.9085}, {1.64259, 11.8103}, {1.64623, 11.7951}, {1.64987,        11.7338}, {1.6535, 11.7665}, {1.65714, 11.9399}, {1.66078,        11.7594}, {1.66442, 11.6693}, {1.66805, 11.6262}, {1.67169,        11.545}, {1.67533, 11.5728}, {1.67896, 11.6337}, {1.6826,        11.5396}, {1.68624, 11.5791}, {1.68987, 11.4263}, {1.69351,        11.4017}, {1.69715, 11.4476}, {1.70078, 11.4972}, {1.70442,        11.4669}, {1.70806, 11.245}, {1.7117, 11.266}, {1.71533,        11.2994}, {1.71897, 11.2909}, {1.72261, 11.2059}, {1.72624,        11.0628}, {1.72988, 11.1528}, {1.73352, 11.0958}, {1.73715,        11.1332}, {1.74079, 11.0329}, {1.74443, 11.1295}, {1.74806,        10.9499}, {1.7517, 10.9342}, {1.75534, 11.01}, {1.75897,        10.9982}, {1.76261, 11.1398}, {1.76625, 10.951}, {1.76989,        10.8068}, {1.77352, 10.868}, {1.77716, 10.9951}, {1.7808,        10.8887}, {1.78443, 10.8111}, {1.78807, 10.8324}, {1.79171,        10.6965}, {1.79534, 10.8346}, {1.79898, 10.772}, {1.80262,        10.7567}, {1.80625, 10.739}, {1.80989, 10.7422}, {1.81353,        10.7291}, {1.81717, 10.9083}, {1.8208, 10.7915}, {1.82444,        10.6635}, {1.82808, 10.6627}, {1.83171, 10.7432}, {1.83535,        10.7494}, {1.83899, 10.7241}, {1.84262, 10.6604}, {1.84626,        10.6429}, {1.8499, 10.4885}, {1.85353, 10.4682}, {1.85717,        10.5412}, {1.86081, 10.481}, {1.86445, 10.609}, {1.86808,        10.4196}, {1.87172, 10.4364}, {1.87536, 10.2673}, {1.87899,        8.81155}, {1.88263, 7.66905}}


How to add a graphics frame to an image without resampling

Using `Inset` to place an image inside a `Graphics` expression with `Frame -> True` provides a simple way to add a scale bar, or ruler, to the image. However, I cannot find a way to get the resulting graphics to display with a one-to-one correspondence between image pixels and screen pixels. For certain images this creates nasty artifacts. Here's an example of an image which shouldn't be resampled:               i = Image[Array[Boole[OddQ[#1 + #2]] &, {200, 200}]]      ![enter image description here](http://i.stack.imgur.com/8nZki.png) Suppose this image represents a region of space 0.2 m wide. To show a "ruler" I can insert the image into a graphics frame like this:               With[{x = 0.2},       Graphics[Inset[i, {0, 0}, Center, x], Frame -> True, PlotRange -> x/2]]      ![enter image description here](http://i.stack.imgur.com/Ftvl0.png) The problem is quite clear - that checkerboard effect is not present in the original image. By adding an `ImageSize` option or manually resizing the graphics I can change the unwanted pattern, but I can't get rid of it completely. My question is whether there is a way to embed an image into graphics so that the image is displayed at its "natural" size, i.e. with one image pixel per screen pixel. Alternatively, is there a better way to display a scale bar or ruler alongside the image?


Plot3D missing a zone

I am trying to plot a simple graph using `Plot3D`:               Plot3D[0.25*(1/(1 - 0.9* (1 - bn))) ((1 - bn)/(1 - 0.5* bn))^2, {bn, 0, 1}, {bu, 0, 1},        RegionFunction -> Function[{bn, bu}, bn > bu]]      Which gives the output: ![enter image description here](http://i.stack.imgur.com/v7i1L.jpg) Why is there a triangle where `Plot3D` keeps the function flat while it is clearly increasing. Here is the graph without limit on the region: ![enter image description here](http://i.stack.imgur.com/txYbz.jpg) I also tried different approaches. For instance:               Plot3D[0.25*(1/(1 - 0.9* (1 - bn))) ((1 - bn)/(1 - 0.5* bn))^2*If[bn > bu, 1, 0],        {bn, 0,1}, {bu, 0, 1}]      with even worst outcome: ![enter image description here](http://i.stack.imgur.com/RSrBR.jpg) Many thanks for your help.


Peak Signal to Noise Ratio of Images

I am filtering a blurred image, and want to evaluate the performance of Peak Signal to Noise Ratio (PSNR) in _Mathematica_ version 9.0. But I am facing the problem of evaluating the PSNR. Could anyone explain how to do this?


Fixed color scale in multiple density plots

I think there should be a simple solution for my current problem, but neither StackOverflow (or the help of Mathematica) or Google have it. I have to plot multiple density plots with a color function.               ListAnimate[Table[         ListDensityPlot[ListOfResults[[i]],              ColorFunction -> "TemperatureMap", PlotRange -> All,              PlotLabel -> i],          {i, 1, Length[ListOfResults]}], AnimationRunning -> False]      The main problem is that for each plot, the extreme colors are assigned to the maximum and minimum values of the current plot. I want the extreme values of the color function to be the global maximum of minimum of my complete data set.


different densityplots with same color range

for example, lets say there're two functions f1 and f2. 0<=f1<=1, 2<=f2<=3 but the two differs only by constants. (e.g. f1[x_,y_]:=(Sin[x]Sin[y])^2, f2[x_,y_]:=(Sin[x]Sin[y])^2+2) what i want is to get densityplots of f1 and f2 with same color range of 0 to 3. in this way, the plot of f1 will show more purple colors and f2 will show more red colors. help me!


Scaling at density plot

I have two data set: One's range is between 0 and 0.5 and another's range is between -0.2 to 0.3. I want to draw two density plots with common scale: from -0.5 to 0.5. How can I fix the scale? Thanks.


Color scaling in ListDensityPlot

I've a simple question, surely aleredy asked, but I can't find a simple answer to it. I've got 3 lists               listA = {{x1, y1, fA1}, {x2, y2, fA2}, ...}          listB = {{x1, y1, fB1}, {x2, y2, fB2}, ...}          listC = {{x1, y1, fC1}, {x2, y2, fC2}, ...}      `x` and `y` are the same for all, but the values of the funcions at each `(x, y)` are different. How can I plot the the lists using `ListDensityPlot` and scale colors in such a way that equal `f` have equal color?


Scaled ColorData Function

I have a four-dimensional array `c`, in which the first dimension represents time and the other three dimensions represent `(x,y,z)` (space). The values represent the density of a gas at the coordinates. I want to plot the 3D values with `Manipulate[]`:               Manipulate[ListContourPlot3D[c[[a, All, All, All]],PlotRange->{-4, 4},ImageSize->800,     Mesh->None,ColorFunction->(ColorData["TemperatureMap"][#4]&),Contours->7,     ContourStyle->Opacity[0.4]],{a,1,150,1}]      The problem is that at `c[[1,All,All,All]]` the values range between 0 and 16, while the values at `c[[150,All,All,All]]` all hover around 4. (This is a simulation of a gas diffusion.) I'd like the scale to remain steady, so that eventually around `a = 150`, the entire plot is more or less light blue over the entire domain.


How to use the same color bar for different DensityPlot

> **Possible Duplicate:**   >  Fixed color scale in multiple density plots I want to normalize different `DensityPlot`s. The scale for the color bar is from 0 to 1. I can do the job in Origin after I get all the data, but I think Mathematica can do it also. I am not very familar with `ColorFunctionScaling`--could you show me an example?


Using Export[] sends the file where?

I am trying to use the `Export` command to convert a list of plots into a *.gif file, and the command runs and executes well, but I can't find the file! Where is it supposed to go? Did it even work? Here is my code :                 q[n_, x_] := x (1 + x)^n + x^n;       points = Table[          Map[{Re[#], Im[#]} &,         Flatten[NSolve[q[n, x] == 0, x][[All]] /. Rule -> (#2 &)]], {n, 1, 20}];            Export["domniationrootsstargraph.gif",          Table[ListPlot[points[[i]], PlotRange -> {{-15, 4}, {-10, 10}}], {i, 1, 20, 1}]             ]      Thanks in advance =)


Why is the test in my ColorFunction not behaving as expected?

In my code I have a `ColorFunction` that is meant to highlight all values of $f(x)$ that are greater than $x$               ColorFunction -> (If[#1 >= #2, Red, Black] &)      so that, for example, the parts of the plot of $3\sin^3(x)$ in the figure below that lie above the line $y=x$ should be red, and the parts below, black, but that's not what I get: ![enter image description here](http://i.stack.imgur.com/4rEM5.png) What am I missing? I expect I've make some simple (and embarrassing) mistake here, but I'm not seeing it. * * *               Show[      ParametricPlot[{u, 3 Sin[u]^3}, {u, 0, 2 Pi}, ColorFunction -> (If[#1 >= #2, Red, Black] &),        PlotStyle -> {Thickness[.01]}, PlotRange -> All],      Plot[x, {x, 0, Pi}, PlotStyle -> {Gray, Dashed}]]


Why does this function fail when a non-function version of the same code works?

This works:               dogs = {{"chow", "medium", "brown"}};     dogs = Append[dogs, {"poodle", "small", "white"}];     dogs//TableForm         chow   medium brown         poodle small  white      but this doesn't:               add[name_, fields_] := (name = Append[name, fields])       add[dogs, {"pug", "small", "tan"}]     Set::shape: Lists {{chow,medium,brown},{poodle,small,white}} and {{chow,medium,brown},{poodle,small,white},{pug,small,tan}} are not the same shape. >>        The problem is probably very obvious, but I don't see it.


Ellipsoid in spherical cordinates

I am trying to plot in spherical coordinates the ellipsoid defined as $$(x/3a)^2+(y/2a)^2+(z/4c)^2=1$$ This is my code:               ParametricPlot3D[{Cos[u] Sin[v], Sin[u] Sin[v], (1/3 Cos[u] Sin[v])^2 +          (1/2 Sin[u] Sin[v])^2 + (1/4 Cos[v])^2 == 1}, {u, 0, 2 π}, {v, -π, π}]      What am I doing wrong? No errors are displayed and an empty frame is all I see.


How to combine DSolve and FindRoot

As my differential function is relatively complex I do not want to do the detour of finding an explicit solution via DSolve for it but rather use an FindRoot-like approach by guessing initial starting values. Following example: Let `z[t]` be the differential where the start and end values are known: `z[0]=z0` and `z[tmax]=zend`, but the end time `tmax` is unknown. The (simplified) differential (where the paths of `l2[t]`and `l3[t]` as well as their end values `l2final` and `l3final` are well-defined) is:               DSolve[{z[0] == z0, z[tmax] == zend, z'[t]==f[l20[t],l3[t]],l2[tmax]==l2final, l30[tmax]==l3final}, z[t],t]      The only unkown is `tmax`. So I don't want to do the `DSolve` described as I don't care about an explicit solution of z[t]. But I rather want to search for something like:               FindRoot[z[t]-zend,{t,0,100}]      Does anybody have an idea how to combine both approaches EFFICIENTLY? Btw: `z[t]` is continously increasing as well as `l2[t]` and `l3[t]`


Syntax formatting when Condition is used with Blank

Consider the following codes:               x_/;x>y     Condition[x_,x>y]     Condition[Pattern[x,Blank[]],x>y]      All the three codes are equivalent. As we can see, in the first code, `x` and `x_` are italicized and highlighted: ![enter image description here](http://i.stack.imgur.com/VDUgi.png) In the second code, `x` and `x_` are neither highlighted nor italicized but `x_` is black (instead of blue): ![enter image description here](http://i.stack.imgur.com/IKtZ1.png) The same thing goes for the third code: ![enter image description here](http://i.stack.imgur.com/VRCCu.png) What is the reason of these diffrences?


Problem evaluating results of DSolve (Power::infy)

So, after browsing through older posts to see if anybody else could have had the same problem, I have come to the conclusion that I am stuck. That bothers me, especially because it should be straight forward. I am trying to solve a Differential Equation. The equation is: ![Image of the Differential Equation to be solved, including the time domain](http://i.stack.imgur.com/zakEH.png) I would like to find X(t), and hence plot X as a function of time. It is known that X = 0 when t = 0. I write this the following way:               solOpg13a1 =         DSolve[{D[X[t], t] == (k*(1 - X[t])*(t*Fa - X[t]*nB0))/(V0 + t*v0), X[0] == 0}, X[t], t];      Next, I prepare it for plotting by the following:               eqOpg13a1 = X[t] /. solOpg13a1 //. {k -> 5.1 , V0 -> 1500 , nB0 -> 1125 , Fa -> 6.0, v0 -> 4} // First;      Please note that V0 and v0 are not the same. X(t) works OK for values above 150 (more or less). For values of t less than around 150, I get a series of Power::infy and Infinity::indet errors. ![Screendumpt of errors and plot](http://i.stack.imgur.com/cB6J6.png) It should be straight forward, and so I am sorry to call for help, but I just can't put a finger on where I go wrong. The time to t_full is approximately 250 Hours (which is the unit of t). I am using Mathematica 9.