Plot 3D vector that is a function of one variable

I have a function, `r[t]`, which is a piecewise function that generates a 3D vector. It looks like this:               r[t_] = Piecewise[{{{5 t, 0, 3 (1 + Cos[t])}, 0 <= t <= π},      {{5 Cos[t - 3  π/2] + 5*π, 5 Sin[t - 3 π/2] + 5, 0},  π < t <= 2 π},      {{5*π + 3*Cos[t - 3 π/2], 2*5 - 3 + 3*Sin[t - 3 π/2],  1/(2 π) (t - 2 π)^2},       2 π < t <= 4 π},      {{-3 (t - 17 π/3), 10, -1/π t^2 + 10 t - 22 π},   4 π < t <= 5 π},      {{-3 t + 17 π, 10, -972 π + 540 t - (99 t^2)/π + (6 t^3)/π^2},        5 π < t <= 6 π},      {{-π - 3 Sin[t], 9/40 (1/3 (20 + 18 π) - t)^2, 3 Cos[t] - 3}, 6 π < t <= 8 π},      {{-25 π + 25 t - (19 t^2)/(4 π) + t^3/(4 π^2),  -(25/2) (140 - 132 π + 27 π^2) +      (15 (80 - 74 π + 15 π^2) t)/(2 π) -  (3 (180 - 164 π + 33 π^2) t^2)/(8 π^2) -      ((-50 + 45 π - 9 π^2) t^3)/(20 π^3), 1056 - (360 t)/π + (81 t^2)/(2 π^2) - (3 t^3)/(2 π^3)},        8 π < t <= 10 π}}];      I am very new to Mathematica (this is my first day using it), and I am unsure of how to plot this function in a 3D space. I have tried `Plot3D` and `VectorPlot3D`, but neither seems to offer a good way to do this (that I can think of). How might I go about plotting the function?


Exported PDF copy-and-pastable

Is it possible to export pdf documents that allow the user to copy and paste the exported code/text? The following table demonstrates what is pasted after copying the example symbols from a pdf exported from Mathematica.               pasted actual      @       [     8       {     ®       →      If this isn't possible an explanation of why not(what about pdfs prevents this functionality) would be appreciated. **EDIT:** After reading Alexey's answer, it has become clear that the pdf editor that you use to copy the text makes a big difference. When you copy text from the pdf reader Foxit or from Google Chrome's built in reader the clipboard stores the following. If you copy the data from the pdf using Adobe Reader 11(W7 and M9) in addition you get a RTF format on the clipboard. The RTF format allows Mathematica to reconstruct the original data.


Ordered indices of a multiple product or sum

Given a summation like $$\sum_{1 \leq i_1 < i_2 < \dotsc < i_k \leq n} f(i_1, i_2, \dotsc , i_k)$$ how can the lists of indices be enumerated? For example, if $n=4$ then the possible lists of indices are               k=1: {1}, {2}, {3}, {4}     k=2: {1,2}, {1,3}, {2,3}, {2,4}, {3,4}     k=3: {1,2,3}, {1,2,4}, {2,3,4}     k=4: {1,2,3,4}      It doesn't matter in what order the lists appear in, and it doesn't matter if they are separated by $k$, i.e., this function could give the lists of indices for a given $k$ value, or list all lists for $k=1 \dotsc n$ (the 14 in the example) in arbitrary order. This is similar to the question Sequential Subsets of a list except that in the example given there, given a list               {1, 2, 3, 4}      the output is               {1}, {2}, {3}, {4},      {1,2}, {2,3}, {3,4},     {1,2,3}, {2,3,4},     {1,2,3,4}      (in some order) and in this case, we additionally need               {1,3}, {2,4}, {1,2,4}      to appear in the output.


How can I build an inline documentation utility?

I often have a large function to which I add inline comments, but then I can't see the forest for the trees. How can I make a tool that extracts the comments and tokens within them to generate an overview or structured outline of the large complex function? For instance:                BigNastyFunction[input_List, xSpecArg_, ySpecArg_, OptionsPattern[]] :=       Module[      {         (*1:1 Local variables*)        data, ySpecContinousQ, xSpecContinousQ, groupsQ, joinedCounts, colors, ymin, ymax, xmin,              (*1:2 Option variables*)        axesLabelsQ, barOrigin, background, diskSizeScaling, displayFunction, frameQ      }            (*2:1 Check for null Input*)       If[times === {}, Return[$Failed]];            (*2:2:1 Check for groups *)       check1 = Depth[input] === 4;         (*2:2:2 Check for nongroups *)       check2 = Depth[input] === 3;              etc...      Would be transformed into something like: Outline of BigNastyFunction Part 1. .....Step 1. Local variables .....Step 2. Option variables Part 2. .....Step 1. Check for null Input .....Step 2. ..........a) Check for groups ..........b) Check for nongroups


Problems with FindMinimum for Constrained Optimization

I am trying to define a simple optimization problem, arising from the discretization of a simple Optimal Control problem. The problem that results is essentially linear, with bilinearities only appearing in some equality constraints. The problem is not big and should be solvable by `FindMinimum`. However I get the following message:               Power::infy: Infinite expression 1/0. encountered. >>       Min::nord: Invalid comparison with ComplexInfinity attempted. >>       FindMinimum::conv: Interior point method fails to converge. >>      I note that the constraints do not contain divisions at all, and the objective is totally linear. The complete model is given below: > Simple car problem   >  $\begin{align*}\frac{dv}{dt} &= u\\\ \frac{dx}{dt} &= v\end{align*}$   >  $x(0)=0,\quad v(0)=0,\quad x(t_f)=300,\quad v(t_f)=0, \qquad \text{minimize > } t_f$.   >  $-2 \leq u\leq +1$.               In[51]:= (* try to define the car problem directly below *)     (* v is velocity and x is distance, h is the stepsizes, u are the controls *)          nsteps = 10;          vlist = Table[v[i], {i, 0, nsteps}]          Out[52]= {v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9], v[10]}          In[53]:= xlist = Table[x[i], {i, 0, nsteps}]          Out[53]= {x[0], x[1], x[2], x[3], x[4], x[5], x[6], x[7], x[8], x[9], x[10]}          In[54]:= hlist = Table[h[i], {i, 1, nsteps}]          Out[54]= {h[1], h[2], h[3], h[4], h[5], h[6], h[7], h[8], h[9], h[10]}          In[55]:= ulist = Table[u[i], {i, 1, nsteps}]          Out[55]= {u[1], u[2], u[3], u[4], u[5], u[6], u[7], u[8], u[9], u[10]}          In[56]:= varslist = Join[vlist, xlist, hlist, ulist]          Out[56]= {v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9], v[10], x[0],       x[1], x[2], x[3], x[4], x[5], x[6], x[7], x[8], x[9], x[10], h[1], h[2],       h[3], h[4], h[5], h[6], h[7], h[8], h[9], h[10], u[1], u[2], u[3], u[4],       u[5], u[6], u[7], u[8], u[9], u[10]}          In[57]:= obj0 = Sum[h[i], {i, 1, nsteps}]          Out[57]= h[1] + h[2] + h[3] + h[4] + h[5] + h[6] + h[7] + h[8] + h[9] + h[10]          In[58]:= odes = Flatten[       Table[{x[i] - x[i - 1] == v[i]*h[i], v[i] - v[i - 1] == h[i]*u[i]}, {i, 1,          nsteps}]]          Out[58]= {-x[0] + x[1] == h[1] v[1], -v[0] + v[1] == h[1] u[1], -x[1] + x[2] ==        h[2] v[2], -v[1] + v[2] == h[2] u[2], -x[2] + x[3] ==        h[3] v[3], -v[2] + v[3] == h[3] u[3], -x[3] + x[4] ==        h[4] v[4], -v[3] + v[4] == h[4] u[4], -x[4] + x[5] ==        h[5] v[5], -v[4] + v[5] == h[5] u[5], -x[5] + x[6] ==        h[6] v[6], -v[5] + v[6] == h[6] u[6], -x[6] + x[7] ==        h[7] v[7], -v[6] + v[7] == h[7] u[7], -x[7] + x[8] ==        h[8] v[8], -v[7] + v[8] == h[8] u[8], -x[8] + x[9] ==        h[9] v[9], -v[8] + v[9] == h[9] u[9], -x[9] + x[10] ==        h[10] v[10], -v[9] + v[10] == h[10] u[10]}          In[59]:= ubounds = Flatten[Table[{u[i] <= 1.0, u[i] >= -2.0}, {i, 1, nsteps}]]          Out[59]= {u[1] <= 1., u[1] >= -2., u[2] <= 1., u[2] >= -2., u[3] <= 1., u[3] >= -2.,       u[4] <= 1., u[4] >= -2., u[5] <= 1., u[5] >= -2., u[6] <= 1., u[6] >= -2.,       u[7] <= 1., u[7] >= -2., u[8] <= 1., u[8] >= -2., u[9] <= 1., u[9] >= -2.,       u[10] <= 1., u[10] >= -2.}          In[60]:= hbounds = Flatten[Table[{h[i] <= 100.0, h[i] >= 0.01}, {i, 1, nsteps}]]          Out[60]= {h[1] <= 100., h[1] >= 0.01, h[2] <= 100., h[2] >= 0.01, h[3] <= 100.,       h[3] >= 0.01, h[4] <= 100., h[4] >= 0.01, h[5] <= 100., h[5] >= 0.01,       h[6] <= 100., h[6] >= 0.01, h[7] <= 100., h[7] >= 0.01, h[8] <= 100.,       h[8] >= 0.01, h[9] <= 100., h[9] >= 0.01, h[10] <= 100., h[10] >= 0.01}          In[61]:= boundary = {x[0] == 0.0, v[0] == 0.0, v[nsteps] == 0.0, x[nsteps] == 300.0}          Out[61]= {x[0] == 0., v[0] == 0., v[10] == 0., x[10] == 300.}          In[62]:= constr0 = Join[odes, ubounds, hbounds, boundary]          Out[62]= {-x[0] + x[1] == h[1] v[1], -v[0] + v[1] == h[1] u[1], -x[1] + x[2] ==        h[2] v[2], -v[1] + v[2] == h[2] u[2], -x[2] + x[3] ==        h[3] v[3], -v[2] + v[3] == h[3] u[3], -x[3] + x[4] ==        h[4] v[4], -v[3] + v[4] == h[4] u[4], -x[4] + x[5] ==        h[5] v[5], -v[4] + v[5] == h[5] u[5], -x[5] + x[6] ==        h[6] v[6], -v[5] + v[6] == h[6] u[6], -x[6] + x[7] ==        h[7] v[7], -v[6] + v[7] == h[7] u[7], -x[7] + x[8] ==        h[8] v[8], -v[7] + v[8] == h[8] u[8], -x[8] + x[9] ==        h[9] v[9], -v[8] + v[9] == h[9] u[9], -x[9] + x[10] ==        h[10] v[10], -v[9] + v[10] == h[10] u[10], u[1] <= 1., u[1] >= -2.,       u[2] <= 1., u[2] >= -2., u[3] <= 1., u[3] >= -2., u[4] <= 1., u[4] >= -2.,       u[5] <= 1., u[5] >= -2., u[6] <= 1., u[6] >= -2., u[7] <= 1., u[7] >= -2.,       u[8] <= 1., u[8] >= -2., u[9] <= 1., u[9] >= -2., u[10] <= 1., u[10] >= -2.,       h[1] <= 100., h[1] >= 0.01, h[2] <= 100., h[2] >= 0.01, h[3] <= 100.,       h[3] >= 0.01, h[4] <= 100., h[4] >= 0.01, h[5] <= 100., h[5] >= 0.01,       h[6] <= 100., h[6] >= 0.01, h[7] <= 100., h[7] >= 0.01, h[8] <= 100.,       h[8] >= 0.01, h[9] <= 100., h[9] >= 0.01, h[10] <= 100., h[10] >= 0.01,       x[0] == 0., v[0] == 0., v[10] == 0., x[10] == 300.}          In[63]:= nvars0 = Dimensions[varslist][[1]]          Out[63]= 42          In[64]:= vars0 = Transpose[{varslist, Table[Random[Real, {0., 1.}], {nvars0}]}]          Out[64]= {{v[0], 0.994273}, {v[1], 0.132455}, {v[2], 0.7492}, {v[3], 0.422551}, {v[4],        0.3127}, {v[5], 0.734046}, {v[6], 0.386862}, {v[7], 0.95813}, {v[8],        0.319134}, {v[9], 0.0195711}, {v[10], 0.547824}, {x[0], 0.126578}, {x[1],        0.91368}, {x[2], 0.385664}, {x[3], 0.195437}, {x[4], 0.589594}, {x[5],        0.369296}, {x[6], 0.437719}, {x[7], 0.205286}, {x[8], 0.210231}, {x[9],        0.145847}, {x[10], 0.225091}, {h[1], 0.572089}, {h[2], 0.681713}, {h[3],        0.151574}, {h[4], 0.0926365}, {h[5], 0.822889}, {h[6], 0.259161}, {h[7],        0.838874}, {h[8], 0.35859}, {h[9], 0.436027}, {h[10], 0.301031}, {u[1],        0.51974}, {u[2], 0.339019}, {u[3], 0.888204}, {u[4], 0.174453}, {u[5],        0.60606}, {u[6], 0.953355}, {u[7], 0.692767}, {u[8], 0.584859}, {u[9],        0.236764}, {u[10], 0.515636}}          In[65]:= constr0 = Apply[And, constr0]          Out[65]= -x[0] + x[1] == h[1] v[1] && -v[0] + v[1] == h[1] u[1] && -x[1] + x[2] ==        h[2] v[2] && -v[1] + v[2] == h[2] u[2] && -x[2] + x[3] ==        h[3] v[3] && -v[2] + v[3] == h[3] u[3] && -x[3] + x[4] ==        h[4] v[4] && -v[3] + v[4] == h[4] u[4] && -x[4] + x[5] ==        h[5] v[5] && -v[4] + v[5] == h[5] u[5] && -x[5] + x[6] ==        h[6] v[6] && -v[5] + v[6] == h[6] u[6] && -x[6] + x[7] ==        h[7] v[7] && -v[6] + v[7] == h[7] u[7] && -x[7] + x[8] ==        h[8] v[8] && -v[7] + v[8] == h[8] u[8] && -x[8] + x[9] ==        h[9] v[9] && -v[8] + v[9] == h[9] u[9] && -x[9] + x[10] ==        h[10] v[10] && -v[9] + v[10] == h[10] u[10] && u[1] <= 1. && u[1] >= -2. &&       u[2] <= 1. && u[2] >= -2. && u[3] <= 1. && u[3] >= -2. && u[4] <= 1. &&       u[4] >= -2. && u[5] <= 1. && u[5] >= -2. && u[6] <= 1. && u[6] >= -2. &&       u[7] <= 1. && u[7] >= -2. && u[8] <= 1. && u[8] >= -2. && u[9] <= 1. &&       u[9] >= -2. && u[10] <= 1. && u[10] >= -2. && h[1] <= 100. && h[1] >= 0.01 &&       h[2] <= 100. && h[2] >= 0.01 && h[3] <= 100. && h[3] >= 0.01 &&       h[4] <= 100. && h[4] >= 0.01 && h[5] <= 100. && h[5] >= 0.01 &&       h[6] <= 100. && h[6] >= 0.01 && h[7] <= 100. && h[7] >= 0.01 &&       h[8] <= 100. && h[8] >= 0.01 && h[9] <= 100. && h[9] >= 0.01 &&       h[10] <= 100. && h[10] >= 0.01 && x[0] == 0. && v[0] == 0. && v[10] == 0. &&       x[10] == 300.          In[66]:= FindMinimum[      {obj0, constr0}, vars0, Method -> "InteriorPoint"      ]          During evaluation of In[66]:= Power::infy: Infinite expression 1/0. encountered. >>          During evaluation of In[66]:= Min::nord: Invalid comparison with ComplexInfinity attempted. >>          During evaluation of In[66]:= FindMinimum::conv: Interior point method fails to converge. >>          Out[66]= FindMinimum[{obj0, constr0}, vars0, Method -> "InteriorPoint"]


Rotated text in "plot" cannot be copied  to MS Word

When I add some text to a simple plot with drawing tools, the text cannot be copied and pasted out with the graphic itself to Microsoft Word. Do you know how to copy the manually added text out to Word? Thank you! This is what I did in Mathematica plot with drawing tool (I got this by output it as a .bmp file): ![](http://i.stack.imgur.com/S8EaY.png) This is what was copied and pasted to Word (result of direct copy and paste): ![](http://i.stack.imgur.com/ECkGy.png) After a few tries, I think it works for newly added text, but once I rotate & move the text to align with my curves it disappear again. The following screenshot shows how bmp image lose resolution when the document coverted to PDF eventually. ![](http://i.stack.imgur.com/Nau16.png) The topic has been a little diverted. We still haven't solve the problem "copy & paste do not work for rotated text in plot". I think it's a MMA bug. Any hints?


Problem in RegionPlot3D

I tried to plot the region bounded by the three planes. This is supposed to give me a pyramid type of shape (actually two, but I am just taking one of them). The code is given by               RegionPlot3D[      x - Sqrt[2]*z >= 0 && Sqrt[2]*x + Sqrt[3]*y + z >= 0 &&        Sqrt[2]*x - Sqrt[3]*y + z >= 0, {x, 0, 12}, {y, -20, 20}, {z, -20,        20}, AxesLabel -> Automatic, Mesh -> None,       PlotStyle -> Directive[Yellow, Opacity[0.5]]]      I am getting kinkiness in the lines created by joining of two planes, ![plot of pyramid](http://i.stack.imgur.com/MfMsB.png) Is it a problem in my graphics card? However, I have checked in different machines and in versions 6, 7 and 8. I got the same situation in all of them. May be it is the similar kind of problem as posted here. I am not sure exactly what modification has to be made. Advanced thanks for any help.


Export and Import with graphics characters

I exported a list of characters say: Export["hello.txt", {t, r, $\theta$, $\phi$}, "List"]; the file has the correct symbols when opened with a text editor, however, when I imported it with Mathematica: old = Import["hello.txt", "List"] I get: {t, r, Î¸, Ï} Any idea of How can I recover the original symbols?


Is it possible to add page break in front-end?

**Description** : I have accomplished my undergraduate paper as a _Mathematica_ notebook. In this condition, I find it convenient to typeset formula and words in a notebook environment. However, I feel that the front-end is lacking a `page break` tool, so I cannot make good page-breaking that I need. Namely, the front-end of _Mathematica_ always breaks the page automatically when been printed. **Question** :   1. How can I break a page manually when saving the notebook as a PDF file?   2. Is it possible to add a `page break` in the `notebook environment`, for example like in _Microsoft Word_ , where the words jump to the next page when there is no space left in the current page ? ![enter image description here](http://i.stack.imgur.com/VD0cU.jpg)


Evaluation of elements in a list and then sorting them

This is probably a simple problem, but I'm having a lot of issues with it because I'm unfamiliar with _Mathematica_ syntax. I have a list               S = {{-1 + x + y}, {x^2 + y}, {x + 2y}}      I am trying to create a function `f` which returns a sorted list _after_ substitution, I've tried variations of the following:               f[x_, y_] := Sort[Evaluate[Table[u, {u, S}]]];      but it simply returns the original list. Any help would be much appreciated!


How to expand set of fonts for mathkernel.exe?

If I am running standard Mathematica and I am choosing from the menu Format->Font, I've got everything I need. All necessary scripts are present (Western, Central European,etc.). Whereas If I run mathkernel.exe and I am choosing Edit->Set Font, I've got only "Western" script. I would like to change it and have this same state like in main application Mathemathica.exe. Does anybody know how to do it?


The Flat Attribute, Unevaluated and the Evaluation Process

To make this question easy to follow let's give some symbols a couple attributes.               Attributes[f] = {Flat};     Attributes[s] = {Orderless};      Now consider the following: `f[a, b, g[c, d], f[e, h], j, k]` gives > `f[a, b, g[c, d], e, h, j, k]` as expected since f is `Flat` Now, we wrap `Unevaluated` around `f`               f[a, b, g[c, d], Unevaluated[f[e, h]], j, k]       This gives > `f[a, b, g[c, d], Unevaluated[e], Unevaluated[h], j, k]` To understand what happened here, we use `Trace`               f[a, b, g[c, d], Unevaluated[f[e, h]], j, k] // Trace      > >      {f[a, b, g[c, d], f[e, h], j, k], f[a, b, g[c, d], e, h, j, k], f[a, >      b, g[c, d], Unevaluated[e], Unevaluated[h], j, k]} >   Finally, let's also wrap `Unevaluated` around `s`.               f[a, b, g[c, d], Unevaluated[f[e, h]], Unevaluated[s[n, m]], j, k]      > >     f[a, b, g[c, d], Unevaluated[e], Unevaluated[h], >      Unevaluated[s[n, m]], j, k] >   Now, here comes my question/confusion. In the case of `f`, the `Unevaluated` head was removed, so the elements of `f`( that has a `Flat` attribute ) was now spliced in and the `Unevaluated` head replaced on the elements of `f`. According to the standard evaluation process, if any part of an expression has the form `Unevaluated[expr]`, we replace that part with `expr` and keep a record of the original expression (So we can later replace the `Unevaluated` head). Now as I've shown, if the expression `expr` has a head with `Flat` `Attribute`, then the expression gets spliced in (i.e. it actually gets evaluated) but as we saw with `s` that has the `Orderless` `Attribute`, the expression remains unevaluated as described by the Evaluation process. So why does the `Flat` attribute supersede `Unevaluated`? This shouldn't be the case according to the standard evaluation process. What am I missing?


How can I get the function of a plotted trajectory?

I solved two ODEs, which are a function of `t`, numerically. The first ODE is the vertical equation of motion and the second one is the horizontal equation of that motion. Then I tried to find the path equation. I used `ParametricPlot` to plot the path. Now I want the equation of that path. How can I express it using the solutions of my ODEs? * * * The Point of my question is as follows: Assuming that we solved an ODE Numerically and I got the answer like this: > >     {{y-> InterpolatingFunction[{{0.,0.386145}},<>]}} >   How can I `Approximate` the function to do some calculus on it?               γ = 6;      g = -9.8;      NDSolve[{y''[t] + γ*(y'[t])^2 == g, q''[t] == -γ*(q'[t])^2,        y[0] == 0, q[0] == 0,        y'[0] == 1.5, q'[0] == 7}, {q, y}, {t, 0, 10}]


Vertically aligning two separate plots

How do I vertically align plots so that the two plots are displayed in a way that lines up with respect to the axes? The code I have so far is:               GraphicsColumn[      {       Plot[0.125 x^2 + 0.05 x^3 + 0.005 x^4, {x, -8.0, 3.0},          AspectRatio -> .4, PlotRange -> {-.19, .7}, Frame -> True,         FrameStyle -> Thickness[.003],         FrameLabel -> {Null, "V(x)", "m=1.0,   w=0.5,   y=2.0,   g=1.0"},          FrameTicks -> {{Automatic, Automatic}, {None, All}}],        Plot[0.5 + 0.2 x, {x, -8.0, 3.0}, AspectRatio -> .4,          PlotRange -> {-1, .9}, Frame -> True,  FrameStyle -> Thickness[.003],          FrameLabel -> {"x", "B(x)", Null},          FrameTicks -> {{Automatic, Automatic}, {Automatic, Automatic}}]      },       ImageSize -> 500, Frame -> None, Spacings -> -20]      ![My horrid attempt to align plots](http://i.stack.imgur.com/3UMRH.png) I'm looking at this right now, and realized how ugly this is... like why is the lower frame thicker than the upper one???


How to plot stacked curves with sharing the horizontal axis

![enter image description here](http://i.stack.imgur.com/yhlLm.gif) How to plot the curves in the image.


How can I stack plots so that they are aligned nicely?

Suppose that I have two plots (e.g., `Plot`, `ListPlot`, etc) that cover two regions of space. I would like to display them "stacked" vertically, so that they align nicely in publication-quality form. Suppose that I am dealing with `ListPlot` and I have the following data:               xdata = Range[0, 2 Pi, 0.2];     ydata1 = Sin[xdata];     ydata2 = 1 + Sin[xdata];      So for plot1, I will plot `Transpose[{xdata, ydata1}]`; for plot2, I will plot `Transpose[{xdata, ydata2}]` (both using `ListPlot`). Plot1 covers both negative and positive $y$ values, whereas plot2 covers only positive $y$ values; this fact will be important later. For both plots, I will use `BaseStyle -> {18, FontFamily -> "Arial"}` so that the labels are large and legible. I will also use `Frame -> True` and will include frame labels with `FrameLabel -> {"x (Meter)", "y (Meter)"}`. Now if I do the following...               plot1 = ListPlot[Transpose[{xdata, ydata1}], Frame -> True,        FrameLabel -> {"x (Meter)", "y (Meter)"},        BaseStyle -> {18, FontFamily -> "Arial"}, PlotStyle -> Red, ImageSize -> 375]          plot2 = ListPlot[Transpose[{xdata, ydata2}], Frame -> True,        FrameLabel -> {"x (Meter)", "y (Meter)"},        BaseStyle -> {18, FontFamily -> "Arial"}, PlotStyle -> Blue, ImageSize -> 375]      ...I get the following... ![Image1](http://i.stack.imgur.com/40AKD.png) Notice that above, the frames are not aligned. To fix this, I can specify the same `ImagePadding` for both plots...               plot1 = ListPlot[Transpose[{xdata, ydata1}], Frame -> True,        FrameLabel -> {"x (Meter)", "y (Meter)"},        BaseStyle -> {18, FontFamily -> "Arial"}, PlotStyle -> Red, ImageSize -> 375,       ImagePadding -> {{70, 10}, {55, 10}}]          plot2 = ListPlot[Transpose[{xdata, ydata2}], Frame -> True,        FrameLabel -> {"x (Meter)", "y (Meter)"},        BaseStyle -> {18, FontFamily -> "Arial"}, PlotStyle -> Blue, ImageSize -> 375,       ImagePadding -> {{70, 10}, {55, 10}}]      ...which gives me the following output... ![Image2](http://i.stack.imgur.com/hAIjv.png) Now the frames are nicely aligned. **_However_** , the $y$ axis frame labels are not aligned. This is because plot1 includes negative $y$ values in addition to positive ones, and the negative signs "push away" the $y$ axis frame label (i.e., `"y (Meter)"`) in plot1. So, **_my question is:_** is it possible to somehow align the $y$ axis frame labels? Apparently, `ImagePadding` does not do the trick for that particular issue. Thanks for your time.


Aligning axes labels on multiple plots

I'm trying to create some "publication quality" figures, but _Mathematica_ is fighting me all the way. So my question is: **Should I switch to Origin?** Please help! * * * Well, all joking aside: I'm trying to create a multipanel figure. Here is an example:               p1 = Plot[100 Sin@x, {x, -5, 5}, Frame -> True,         FrameLabel -> {"XXX", "YYY"}, LabelStyle -> Large,         ImageSize -> 400, ImagePadding -> {{100, 1}, {0, 10}}];     p2 = Plot[5 Sin@x, {x, -5, 5}, Frame -> True,         FrameLabel -> {"XXX", "TTTT"}, LabelStyle -> Large,         ImageSize -> 400, ImagePadding -> {{100, 1}, {40, 0}}];     Column[{p1, p2}, Spacings -> 0]      ![Example image](http://i.stack.imgur.com/Skpd1.png) So the real question is: **How can I align the TTTT and YYYY axes labels?** I also tried using grid, with separate labels but then the TTTT is not centered on the axis, but is too low.


Solving linear equation

I want to solve following linear equations: \begin{align*} 3 x - y &= 0\\\ y + 2 z &= -1\\\ x + y + z &= 3 \end{align*} The output will be `{x == 7/5, y == 21/5, z == -(13/5)}` I don't know the way of solve this. What function can be used. How can I solve this? Also it will be very thankful if you let me know the ways as many as possible. Also especially, is there any specific way that using 'LU decomposition' to solve this equation??


Adapting CoefficientList (and the related functions) to work with Laurent polynomials

Is there a slick way to make CoefficientList (and the other similar functions, CoefficientRules etc) work for Laurent polynomials (i.e. where negative exponents can occur), if I don't know a priori what the largest negative exponents are? I can of course do some ugly ad hoc thing by hand, but I'm looking for a method that works generally. Any tips?


BubbleChart Text Tooltip's

Is it possible to display "name" in the tooltip? It won't chart the full dataset, so I can't make a custom labeling function that takes it in.               data3 = {{"acerbic",3,5,1.3*10^6},     {"acetic",3,7,213000},{"acetonic",1,4,2000},{"achromatic",3,6,16000},     {"acidic",3,6,500},{"acoustic",3,7,2000},{"acrobatic",3,6,3000},     {"acrostic",4,8,Null},{"acrylic",3,5,220000},{"acyclic",6,8,270000},     {"adiabatic",6,7,40000},{"aerobatic",3,6,2000},{"aerobic",7,4,1.6*10^6},     {"aerodynamic",7,7,160000},{"aeronautic",2,2,5000},{"aesthetic",5,3,500},     {"agnostic",3,5,5000},{"agoraphobic",7,3,200000},{"agronomic",3,5,5000},     {"alcoholic",2,1,1000},{"alembic",2,1,20000},{"algebraic",6,3,5000},     {"algorithmic",5,2,2500.},{"aliphatic",7,2,13000},{"allegoric",5,2,1000},     {"allelic",8,5,2400.},{"allergenic",8,5,48000},{"allergic",8,3,1000},     {"allotropic",7,6,3000},{"almanac",6,7,Null},{"alphabetic",7,2,Null},     {"alphanumeric",6,7,1000},{"altruistic",4,7,7000},{"amnesiac",5,6,4000},     {"amnesic",6,5,500},{"amniotic",4,2,500},{"amoebic",2,1,1000},     {"anabolic",4,7,Null},{"anachronistic",4,7,1500.},{"anaerobic",3,5,10000},     {"anagrammatic",8,10,Null},{"analgesic",3,7,60000},{"analytic",7,7,3000},     {"anamorphic",2,6,3000},{"anapestic",3,5,90000},     {"anaphoric",6,4,1000000},{"anarchic",7,5,12000000},     {"anarchistic",4,4,50000},{"anatomic",2,2,30000},     {"androgenic",2,4,60000},{"anechoic",3,4,50000},{"anemic",2,1,200000},     {"anesthetic",2,6,40000},{"angelic",3,6,44000},{"anharmonic",4,7,Null},     {"animistic",3,5,100000},{"anionic",3,7,2.2*10^6},     {"anisotropic",3,6,2.8*10^6},{"anorectic",6,1,60000},     {"anorexic",5,6,4000},{"antagonistic",1,5,550000},     {"antarctic",3,4,320000},{"anthropic",5,5,8000},     {"anthropocentric",2,5,10000000},{"anthropogenic",1,5,12000000},     {"anthropometric",3,6,103000},{"anthropomorphic","","",Null},     {"antibiotic","","",Null},{"antic","","",Null},     {"anticlimactic","","",Null},{"anticyclonic","","",Null},     {"antidemocratic","","",Null}};          labelingfunc[v : {x_, y_, w_}, i_, ___] :=       Placed[Grid[{{"Name"}, {"Usability ", x}, {"Relevancy",           y}, {"Market Size", w}}, Frame -> All, Alignment -> Left],        Tooltip]          BubbleChart[data3[[All, 2 ;; 4]], ChartStyle -> 24,       LabelingFunction -> labelingfunc]      ![bubble chart](http://i.stack.imgur.com/MTS1k.png)


How to effectively diff a notebook?

How to effectively diff a notebook with another version of it? This is usually needed/encountered in revision control, but can be generally useful. What i currently do is disable notebook history, use less styling, and diff them as text files.


"Hiding" cells until the first cell is evaluated

This question is based on my earlier question about randomizing labs for students in my computer lab courses. There a perfectly good solution was posted; however, because of privilege problems, I cannot use the exact method there, as I do not have the ability to modify global settings. So now I've decided on a different approach: having an input field at the top of the lab, where the student is prompted to enter their name, and hit a button "Begin Lab". The button will use the name (among other things) as a seed to randomize the lab. All well and good. However, before that button is clicked, I would like **to "gray out" or hide** all other cells in the lab. In other words, the only active, usable cell is this one containing the "Begin Lab" button, until that button is clicked! Is this possible? Can it be done without making changes to the global settings (preferably) ?


Problems getting clean sunrise, sunset, civil, nautical and astronomical twilight data

If in a notebook you enter:               WolframAlphaResult["Sunrise june 25, 2013", {{"DaylightInformation", 1}, "ComputableData"},                        PodStates -> {"DaylightInformation__More"}]        you get:               {{"begin astronomical twilight","3:16 am EDT"},     {"begin nautical twilight","4:07 am EDT"},     {"begin civil twilight", "4:50 am EDT"},     {"sunrise","5:24 am EDT"},      {"sunset", "8:31 pm EDT"},      {"end civil twilight","9:05 pm EDT"},     {"end nautical twilight","9:48 pm EDT"},      {"end astronomical twilight","10:39 pm EDT"},     {"duration of daylight", {15, 8}}}        as a result (I didn't know there was something called "nautical twilight," but now that I do, I want it). Unfortunately, the result is returned not as a nice list, but instead embedded in a complicated `WolframAlphaResult` format. Despite trying many different approaches, I have been unable to discover a way to get just a list of this data returned. It is possible?


How to remove a black border around Graphics3D[Texture[...]]

So I can create a 2D image that looks like               contourplot =       ContourPlot[       Sin[ x/2] Cos[y], {x, -4 \[Pi], 4 \[Pi]}, {y, -4 \[Pi], 4 \[Pi]},        PlotRange -> All, BaseStyle -> 30]      ![enter image description here](http://i.stack.imgur.com/o3Bx2.jpg) Notice there is no frame around the image as a whole. Now I want to use this in a 3D plot using the following command               backgroundimage =        Graphics3D[{Texture[contourplot],          Style[Polygon[{{-1000, -500, -500}, {-1000, 500, -500}, {-1000,              500, 500}, {-1000, -500, 500}},            VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}],           Lighting -> {{"Ambient", White}}]}];               Show[backgroundimage, Boxed -> False, ImageSize -> 800,       ViewPoint -> {2, -2, .3}]      ![enter image description here](http://i.stack.imgur.com/KfMpt.jpg) A black border has been added around the 3D object. How can I remove this border? Or is there some way to just make it white? Thanks


Dynamic matrix multiplication

I have the following problem: I want to multiply two matrices and sum them to another matrix C. A.B+ 2B Easy! The matrix A varies as a function of three inputs a,b and c. The second matrix, B, is a 2x2 identity matrix. here is the code                    Grid[{{"a", "b", "c"},            {InputField[Dynamic[a], FieldSize -> 1],             InputField[Dynamic[b], FieldSize -> 1],             InputField[Dynamic[c], FieldSize -> 1]}}]                  A = {{Dynamic[a]*Dynamic[b], 0}, {0, Dynamic[c]}};             B = IdentityMatrix[2];             A.B + 2 B      Let's say a=c=10 and b=2. Result But I don't want to get 10 2+2 and 10+2, I need 22 and 12! It just shows the value of a and c without multiplying. Using               A = {{Dynamic[a*b], 0}, {0, Dynamic[c]}};      instead of               A = {{Dynamic[a]*Dynamic[b], 0}, {0, Dynamic[c]}};      solves the first problem. I got 20+2 and 10+2, which is good but not enough. It seems that it not possible to simplify operation when using Dynamic... How can I solve the problem? Thx!


What is the full list of all font families?

I'm having trouble finding a complete list of the FontFamily strings that mathematica supports.


Help on how to write a function to be used with NMinimize

I need some help to write a proper function to be used as a parameter on NMinimize. Here is the code of the function to be minimized (Please correct, optimize and rewrite the code if you want to - I need to understand how to write proper Mathematica code).               plot[τ_, Ω_] := Module[{arg, abs, aux},         {arg, abs} =           Factor[Together[ComplexExpand[Through[{Arg, Abs}[(1 + I*2*Ω)/(1 + I*2*τ*Ω)]]]]];         aux = arg/Degree;        aux = If[aux < 0, aux = 360 - aux, aux];        {aux, 20*Log10[abs]}]          modFunction1[kc_, gp_, ω_, pm_, variable_:s] := Module[{arg, abs, aux},        {arg, abs} =          Factor[Together[ComplexExpand[Through[{Arg, Abs}[kc*gp /. variable -> I*ω]]]]];        aux = (-arg)*(180/Pi) + pm - 180;       aux = If[aux < 0, 360 + aux, aux];       {-20*Log10[abs], aux}];           functionF1[kc_, gp_, ω_, pm_, variable_:s, τ_, Ω_] := Module[{a, b, c, d},        {a, b} = N[modFunction1[kc, gp, ω, pm, variable]];       {d, c} = N[plot[τ, Ω]];       (a - c)^2 + (b - d)^2];       and finally               NMinimize[functionF1[50, 100/(s*(s + 5)*(s + 10)), 9, 42, τ, Ω],       {{τ, 10.5, 10.6}, {Ω, -0.1988, -0.1987}}]      NMinimize returns > NMinimize::nnum: "The function value 0.000459846 +(54.9326 -aux$584644)^2 is > not a number at {[Tau],[CapitalOmega]} = {10.5919,-0.198714}" but evaluating functionF1 on those same values returns a real number. What am I missing? Any comment on how to write the code is most welcome. I definitely need some guide on how to write proper functions.


Aborting from inside a Dialog

Suppose I got in a `Dialog` and wanted to not `Return` but `Abort` the computation. How could I do that? Using `Return[]` the computation continues, and sometimes that implies getting inside countless other `Dialog`s of which it is not easy to go out without killing the kernel. How do you handle those situations?


Compute percentages in a list

I have a data file which contains thousands of lines and each line has eight elements. Here is a small sample of the data file               -4.00      -0.80   0.1886024468848907E+01   0.1467147621657460E+01   -.1217067274319363E+01   0.7206100000000000E+03   0.7693457688734395E-12    5     -4.00      -0.70   0.1430357986632780E+01   -.1404093461650013E+01   -.1742223680347601E+01   0.1824700000000000E+03   0.8439003681169850E-12    8     -4.00      -0.60   -.1324719768465547E+01   0.1740130076002850E+01   0.1497978622206873E+01   0.5479900000000000E+03   0.4264485578634903E-14    2     -4.00      -0.50   0.1358536876189560E+01   -.1580696533502541E+01   0.1621539980382560E+01   0.2881100000000000E+03   0.1319885603098060E-13    4     -4.00      -0.40   -.1588487538231399E+01   0.1275577589608218E+01   0.1707607247015512E+01   0.1337500000000000E+03   0.1057878487713421E-12    2     -4.00      -0.30   0.1755414125374284E+01   0.1332710827520201E+01   0.1477984475201826E+01   0.6426400000000000E+03   0.1459764022611444E-13    1     -4.00      -0.20   0.1245972697710741E+01   0.1540633564543885E+01   0.1777167629372046E+01   0.6112200000000000E+03   0.5718386586661092E-13    1     -4.00      -0.10   -.1311461418732105E+01   -.1594149065989313E+01   0.1661344176980193E+01   0.3507800000000000E+03   0.6765588799377521E-14    3      I read this file using               data = ReadList["data.out", Number, RecordLists -> True];      The total length of the list is obtained, of course as               ntot = Length[data];      The list contains eight elements per row and the last of them is an integer taking values in the interval [0,8]. What I want is the following: (a). Count how many rows have 0 value at the last element (let's suppose there are `n0`), how many have 1, 2, 3, ... , 8. Then calculate the corresponding percentages `per0 = n0/ntot`, `per1 = n1/ntot`, etc. It could be nice if this was inside a DO loop with `i = 0,8`. (b). Count again percentages but using more than one criteria this time. For example, count how many rows have 1 at the last element and the value of the seventh element is smaller than `10^{-4}`. Any suggestions? **EDIT** Using's @Kuba's solution we have               {{5, 656}, {8, 640}, {2, 673}, {4, 663}, {1, 673}, {3, 663}, {6, 656}, {7, 640}, {0, 19}}      Is it possible to divide each sum automatically with `ntot` thus obtaining the percentages?               {{5, 656/ntot}, {8, 640/ntot}, {2, 673/ntot}, {4, 663/ntot}, {1, 673/ntot}, {3, 663/ntot}, {6, 656/ntot}, {7,640/ntot}, {0, 19/ntot}}      Also it would be great if they were sorted from 0 to 8 not randomly as they are now.


Mathematica not assigning variable correctly

So I have been fiddling with this the last hour and I just can't get it to work. I have 3 matrices of the same size which contain nothing but 0's in a list, I also have 3 matrices of the same size (not same as first 3) that have different values in them (also in a list). I have a Coordinate x and y value as well (x is right, y is down). I want to replace the values of a small part of the matrices containing 0's with their corresponding matrix (corresponding one is the ones with different values) e.g. $a=\begin{matrix}0&0&0&0&0\\\0&0&0&0&0\\\0&0&0&0&0\\\0&0&0&0&0\\\0&0&0&0&0\end{matrix}$ $b=\begin{matrix}1&2&3\\\4&5&6\end{matrix}$ $CoordX=2$, $CoordY=3$ When I use the function, I want the output to be $Output->\begin{matrix}0&0&0&0&0\\\0&0&0&0&0\\\0&1&2&3&0\\\0&4&5&6&0\\\0&0&0&0&0\end{matrix}$ This was my attempt at the function but for the three matrices instead               CreatePlaceholderMatrix[Matrix_,CoordX_,CoordY_]:=     (PlaceholderMatrix=Table[0,{3},{64},{64}];     For[i=CoordX,i==CoordX+Dimensions[Matrix[[1]][[1]]][[1]]-1,i++      For[j=CoordY,j==CoordY+Dimensions[Matrix[[1]][[1]]][[1]]-1,j++       For[k=1,k==3,k++,PlaceholderMatrix[[k,i,j]]=Matrix[[k,1,i,j]]       ]      ]     ];     PlaceholderMatrix)      The value of Matrix is in the form of (and if it helps is square):               MatrixForm/@ImageData[Image,"Byte",Interleaving->False]      and that is why I needed an extra [[1]] whenever I referred to Matrix (not sure exactly why but it was the only value that worked). Anyways, whenever I run the function, it just presents PlaceholderMatrix as 3 64*64 Matrices of 0's and nothing else. It seems as if it didn't even go through the for loop. I also want the final answer to be in the same Format as matrix, so I can do operations with it later and convert it to an image If anyone can explain why this is happening, or any alternative method that may work better, please tell.


How to color edges of a graph which has multiple edges connecting certain vertices

I'm studying BIBD(Balanced Incomplete Block Design) and want to draw some graphs by coloring their blocks in different colors, respectively. A block is a collection of edges (or vertices). For example, (10,4,2)-BIBD, with blocks               {{0,1,2,3},{0,1,4,5},{0,2,4,6},{0,3,7,8},{0,5,7,9},{0,6,8,9},      {1,2,7,8},{1,3,6,9},{1,4,7,9},{1,5,6,8},{2,3,5,9},{2,4,8,9},      {2,5,6,7},{3,4,5,8},{3,4,6,7}}      can be drawn by               GraphPlot[{0 -> 1, 1 -> 2, 2 -> 3, 0 -> 1, 1 -> 4, 4 -> 5, 0 -> 2, 2 -> 4,                 4 -> 6, 0 -> 3, 3 -> 7, 7 -> 9, 0 -> 6, 6 -> 8, 8 -> 9, 1 -> 2,                 2 -> 7, 7 -> 8, 1 -> 3, 3 -> 6, 6 -> 9, 1 -> 4, 4 -> 7, 7 -> 9,                 1 -> 5, 5 -> 6, 6 -> 8, 2 -> 3, 3 -> 5, 5 -> 9, 2 -> 4, 4 -> 8,                 8 -> 9, 2 -> 5, 5 -> 6, 6 -> 7, 3 -> 4, 4 -> 5, 5 -> 8, 3 -> 4,                 4 -> 6, 6 -> 7},        Method -> "CircularEmbedding",        BaselinePosition -> Top,        VertexLabeling -> True,        MultiedgeStyle -> 0.04]      ![enter image description here](http://i.stack.imgur.com/aBpcq.png) (This example is from the text book _Combinatorial Design - Stinson_ ). I want to draw each block in its own individual color. How do I do that?


Retrieving coordinate positions using ChemicalData for input to quanutm modelling software

I am trying to set up an input file for a quantum chemical modelling software. How do I obtain the (XYZ) coordinate positions in Angstroms using information obtained using ChemicalData. Have some initial input for fructose below:               ChemicalData["Fructose", "AtomPositions"]      What I expect in the output (just an example not the actual positions)                                Coordinates (Angstroms)      ATOM                X               Y               Z       1  C        2.5130891440   -0.0345557109   -0.2500995821       2  O         0.0459435630    3.3652982874    1.6477735205       3  H        0.0347565292    2.5110247340    0.2498797086     .......


DSolve results not what expected

I have the following formula:               s'[t] == 230.94 Tan[0.914743 - 0.138564 t]      When I solve this by hand I get:               s[t] == 1666.67*Log[Cos[0.914743-0.138564t]] + c      But Mathematica just returns:               DSolve[s'[t] == 230.94 Tan[0.914743 - 0.138564 t], s[t], t]      > s[t] == Integral[ 230.94 Tan[ 0.914743 - 0.138564t ]dt ] + c Do you know why it isn't solving the integral?


Finding 111 plane of Carbon Diamond

All, I looked at the example on the Mathematica Website with the Carbon Diamond Lattice. Example I am referring to I am wondering is there a way to highlight an individual plane such as the 111 or 110 plane? I like the example I am just not sure of my orientation. Cheers, BEn * * * Code:               Manipulate[      tet = PolyhedronData["Tetrahedron", "Faces"];      tetv = PolyhedronData["Tetrahedron", "VertexCoordinates"];      sp = {RGBColor[1, 1, 0.3], Sphere[{0, 0, 0}, sizes]};      bar1 = {RGBColor[0.2, 1, 1],         Cylinder[{{0, 0, 0}, {0, 0, Sqrt[2/3] - 1/(2 Sqrt[6])}}, sizec]};      bar2 = {RGBColor[0.3, 1, 1],         Cylinder[{{0, 0, 0}, {-(1/(2 Sqrt[3])), -(1/2), -(1/(2 Sqrt[6]))}},          sizec]};      bar3 = {RGBColor[0.4, 1, 1],         Cylinder[{{0, 0, 0}, {-(1/(2 Sqrt[3])), 1/2, -(1/(2 Sqrt[6]))}},          sizec]};      bar4 = {RGBColor[0.5, 1, 1],         Cylinder[{{0, 0, 0}, {1/Sqrt[3], 0, -(1/(2 Sqrt[6]))}}, sizec]};      sp4 = Map[Translate[sp, #] &, tetv];      base = {bar4, bar3, bar2, bar1, sp4, sp, If[tets, tet, {}]};      dia = Rotate[        Rotate[Map[Translate[base, #] &, tetv], -Cos[Sqrt[3]/3/2], {0, 1,           0}], Pi/4, {0, 0, 1}];           cub = If[cubs,         Scale[PolyhedronData["Cube", "Edges"],          Sqrt[2] {1, 1, 1}, {0, 0, 0}], {}];      diax = Table[Translate[{dia, cub}, {i Sqrt[2], 0, 0}], {i, n}];      diay = Table[Translate[{dia, cub, diax}, {0, i Sqrt[2], 0}], {i, n}];      diaz = Table[        Translate[{dia, cub, diax, diay}, {0, 0, i Sqrt[2]}], {i, n}];           Graphics3D[{dia, cub, diax, diay, diaz}, Boxed -> False,        SphericalRegion -> True, ImageSize -> 380],      {{n, 0, "frequency"}, 0, 2, 1, RadioButton},      {{sizec, 0.025, "cylinder size"}, 0, 0.5},      {{sizes, 0.1, "sphere size"}, 0, 0.5},      {{tets, False, "show tetrahedra"}, {True, False}},      {{cubs, False, "show cubes"}, {True, False}},       TrackedSymbols -> Manipulate]


How can I create a custom control which evaluates to a list of values or replacements?

I have a set of variables which are used in various places in my calculations (solving a system, initial conditions, etc.). In order to make this easier to deal with, I want to make a control-like thing which makes them easier to manipulate, rather than just using long lists of unlabeled values such as               calculateValues[{0, 0, π, 0.5, 3}]      So far I have something like this: ![](http://i.stack.imgur.com/FyYmo.png) This clearly doesn't work, and I expect in order to get it working properly I'll need to use `Interpretation` or more `Dynamic` incantations, but I can't figure out exactly what needs to happen. Any advice would be appreciated. Thanks in advance!


Mathematica: Retrieving PlotRange from Histogram

I know that one can retrieve PlotRange of a plot by using               AbsoluteOptions[plot,PlotRange]      but that won't work on Histogram. Here an example:               In[1099]:=          data = {-1.2056, -1.46192, -1.30053, -2.52879, -0.99636, -1.73904, -1.164,     -1.83398,-0.97505, -0.503256, -0.63802, -0.785963, -0.711821, -0.820439, -1.8699,     -3.9659, -1.4456, -1.67021, -1.42009, -2.5644, -1.45002, -1.27806, -1.66529,     -1.67073, -3.31102, -3.38638};     Histogram[%, PlotRange -> Automatic];     AbsoluteOptions[%, PlotRange]      When running the code I get the following message.               PlotRange::prng: Value of option PlotRange -> {{All,All},{-4.,0.}} is not All,     Full, Automatic, a positive machine number, or an appropriate list of range     specifications. >>      As I understood the documentation, PlotRange need to be of a certain format (e.g. two numbers) and `{{All,All},{-4.,0.}}` apparently does not fit to that format, for which reason Mathematica won't give me back the PlotRange of my histogram. Does anybody know how I can get the PlotRange of a Histogram anyway? By the way: In the first place, it will only make sense to get hold of the second value of PlotRange (in my example: `{-4.,0.}`) since one can calculate the first one for instance through `{0,Length[data]}`. Many thanks! John


How to use If to select arguments min & max in Range?

I want to call `Range[]` with its arguments depending on a condition. Say we have               checklength = {5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6}        I then want to call `Range[]` 13 times (the length of `checklength`) and do `Range[5]` when `checklength[[#]] == 5` and `Range[2, 6]` when `checklength[[#]] == 6`. `If[]` would seem an appropriate way to do it,               Range[If[checklength[[#]] == 5, 5, XXX]]& /@ Range[13]        but I don't know what to put for "XXX", since I need "2,6" there without any brackets. I've tried               Range[If[checklength[[#]]==5, 5, Flatten[{2,6}]]]& /@ Range[13]        but that doesn't help (in fact if you think about it, it shouldn't!). The problem is, I need an unbracketed pair of numbers to be treated as a single argument and I don't know how to do that. I can think of one quite messy solution,               Range[If[checklength[[#]] == 5, 1, 2], If[checklength[[#]] == 5, 5, 6]& /@ Range[13]        but I'd be disappointed if there's not a better way to do it. Even though this does the trick, the general question remains of how to treat unbracketed comma separated numbers as a single item.


How to export CSV from Mathematica?

I have previously been using               logf[x_, y_] := f[x, y] /. v_ :>(PutAppend[Unevaluated[f[x, y] = v;], "out.txt"];);      which produces output like `f[1,5]=2.566665345435;` on each line of the output file. How could I modify this to produce CSV file, i.e. output lines that look like               1, 5, 2.5666665345435     3, 4, 4.4353453453453     .     .      I tried the obvious guess                  logf[x_, y_] := f[x, y] /. v_ :>(PutAppend[Unevaluated[x, y, v], "out.txt"];);      but this does not work, as the word "Sequence" also gets exported. Also is this the best way I can export data from Mathematica to be read in by c++ code or is there a better way?


Button ImageSize x-dimension ignored

How can a small square button be created with `ImageSize -> {20,20}`? The x-dimension won't go below about 70. (Using version 9.0.1 on OS X.)               Grid[{       {Button["", ImageSize -> {10, 10}],        Button["", ImageSize -> {20, 20}]},       {Button["", ImageSize -> {30, 30}],        Button["", ImageSize -> {90, 30}]}},      Frame -> All, Alignment -> Left]      ![enter image description here](http://i.stack.imgur.com/R1eu6.png)


Efficient Langevin Equation Solver

This question is **not** about good algorithms for solving stochastic differential equations. It is about how to implement simple codes in Mathematica _efficiently_ exploiting Mathematica's programming methodology. (Hopefully, this may be useful in a stochastic processes course, for instance). A simple Langevin Eq. in a single random variable $X$ with additive noise reads \begin{equation} \dot{X} = f(X) + \zeta(t) \end{equation} where $f(X)$ is an arbitrary function and $\zeta(t)$ is a Gaussian white noise satisfying \begin{equation} E(\zeta(t)) = 0, \qquad \text{and} \qquad E(\zeta(t) \zeta(t')) = \Gamma \delta(t-t') \end{equation} To solve it we discretize time as $t = n dt$ and write \begin{equation} X_{n+1} = X_{n} + f(X_n)dt + \sqrt{\Gamma dt}\xi_n \end{equation} where $\xi_n \sim N(0,1)$. Here is my best implementation thus far:               Langevin[x0_, f_, G_, tf_, n_, m_: 1] :=          With[{dt = N[tf/n], s = N[Sqrt[ tf G/n]], xx0 = Table[x0, {m}]},          Transpose@NestList[ # + dt f[#] + RandomVariate[NormalDistribution[0, s], m] &, xx0, n]];      It takes as input a initial condition $x_0$, a function $f[x]$, the spectral density $\Gamma$ (here written as $G$), the final integration time $t_f$ and the number of integration points $n$. The time step is then $dt = t_f/n$. It also takes an optional argument $m$ corresponding to the number of realisations. The output consists of $m$ vectors $(X_0, X_1, X_2, \ldots,X_n )$ representing the stochastic realisations. Here is this program applied to the famous bi-stable potential given by $V(x) = -\frac{x^2}{2} + \frac{x^4}{4}$, so that $f(x) = - V'(x) = x-x^3$. It simulates a cold ($\Gamma=0.1$, in **data1** ) and a hot ($\Gamma=1$, in **data2** ) condition:               First@AbsoluteTiming[         data1 = Langevin[0, -#^3 + # &, 0.1, 10, 10^3, 2000];         data2 = Langevin[0, -#^3 + # &, 1, 10, 10^3, 2000];]     0.317665      To analyse the steady state I discard some initial points (80% in this example). This shows how the particle remains distributed close to the potential minima when it's cold, but spread out when it's hot:               Show[       Histogram[{Flatten[data1[[All, 800 ;; 1000]]], Flatten[data2[[All, 800 ;; 1000]]]}, Automatic, "PDF"],        Plot[-z^2/2 + z^4/4, {z, -1.8, 1.8}, PlotStyle -> Red],        AxesOrigin -> {0, 0}, PlotRange -> {-0.3, 1.2}]      ![enter image description here](http://i.stack.imgur.com/CYMG8.png) Now to the questions:   1. Any immediate improvements on this function?   2. Is there a better way through a different approach   3. Can I compile this function _as is_ to gain speed?    4. What about parallelisation?  A follow up would be to extend all this to systems of Langevin equations, replacing $X$, $f$ and $\zeta$ by vector valued functions. But, then, we loose the advantage of computing many realisations at once within the same NestList. I'll think more about this problem and if I come up with any ideas I'll update the question. Thank you all in advance and I hope this may be of use to other researchers as well. **Note:** here is an example using the idea of @R.M.: generate all random numbers at once and use an index through the iteration to move along:               LangevinBad[x0_, f_, G_, tf_, n_, m_: 1] := Block[{i = 1},          With[{dt = N[tf/n], r = RandomVariate[ NormalDistribution[0, N[Sqrt[ tf G/n]]], {n, m}], xx0 = Table[x0, {m}]},         Transpose@NestList[ # + dt f[#] + r[[i++]] &, xx0, n]]];      Maybe my coding is no good, but this version is really bad. Actually; Nest probably has an internal variable to keep track of what iteration step it is, but I have no idea if it is possible to access that. * * * ## ACL's version @ACL came up with a really efficient code, which I copy here for completeness.               (* This was originally called l4 by ACL *)          LangevinACL[fn_] := With[{f = fn},          Compile[{{x0, _Real}, {G, _Real}, {tf, _Real}, {n, _Integer}},          Module[{dt, s, state, r}, dt = N[tf/n];         s = N[Sqrt[tf G/n]];         state = ConstantArray[0., n];         state[[1]] = x0;         r = RandomVariate[NormalDistribution[0, s], n];         Do[state[[nc]] = state[[nc - 1]] + dt*f@state[[nc - 1]] + r[[nc - 1]], {nc, 2, n}];     state], CompilationTarget -> "C"]]      Then to compile for a given function use               ll = LangevinACL[(# - #^3) &];     AbsoluteTiming[dat = Table[ll[0, .1, 10, 10^3], {2000}];]      This code is always faster then the originally posted and allows for easy parallelisation. * * * ## Vector Equations In vector equations there are two possibilities; either all particles have the same fluctuating properties, in which case we usually write $E(\zeta_i(t) \zeta_j(t')) = \Gamma\delta_{i,j} \delta(t-t')$ for the components of the fluctuating vector; or each particle has a specific fluctuation: $E(\zeta_i(t) \zeta_j(t')) = \Gamma_{i,j} \delta(t-t')$, where $\Gamma_{i,j}$ are the entries of a covariance matrix. Here are two implementations of the former (all equations with the same fluctuation). The first is a simple variation of the original code, as suggested by @ACL, so that instead of computing several realisations at once, each function call evaluates only a single realisation, but for a vector system:               LangevinVec[x0_, f_, G_, tf_, n_] :=        With[{dt = N[tf/n], s = N[Sqrt[ tf G/n]], m = Length@x0},        NestList[ # + dt f[#] + RandomVariate[NormalDistribution[0, s], m] &, x0, n]];       Everything is exactly as in Langevin, except that on input $x_0$ should be an array of numbers. Note also that there is no failsafe to check if the function $f$ has the correct dimensionality! (it should be a mapping from $\mathbb{R}^m\rightarrow\mathbb{R}^m$, where $m$ is the length of $x_0$). The second implementation is again motivated by @ACL's code:               LangevinVecACL[fn_] :=        With[{f = fn},        Compile[{{x0, _Real, 1}, {G, _Real}, {tf, _Real}, {n, _Integer}},        Module[{dt, s, state, r, m},       m = Length@x0;       dt = N[tf/n];       s = N[Sqrt[tf G/n]];       state = ConstantArray[0., {n, m}];       state[[1]] = x0;       r = RandomVariate[NormalDistribution[0, s], {n, m}];       Do[state[[nc]] = state[[nc - 1]] + dt*f@state[[nc - 1]] + r[[nc - 1]], {nc, 2,        n}];       state], CompilationTarget -> "C"]]      Now to applications. Here is a model of ferromagnetism reminiscent of the 1D Ising system. There are $m$ random variables in $\vec{x} = (x_1,x_2,\ldots,x_m)$ representing spins in a linear chain of atoms. The interaction potential is given by \begin{equation} V(\vec{x}) = - \sum_{i=1}^m (\frac{a x_i^2}{2} - \frac{b x_i^4}{4}) - c \sum_{i=1}^m x_i x_{i+1} \end{equation} This refers to a bi- stable potential (as in the previous example) for each variable representing the magnetic order, plus a harmonic-type interaction between them. The corresponding force is \begin{equation} f_i = a x_i - bx_i^3 + c(x_{i-1}+x_{i+1}) \end{equation} In matrix notation I can write \begin{equation} f(\vec{x}) = A\vec{x} - b \vec{x}^3 \end{equation} where $\vec{x}^3$ stands for $(x_1^3,x_2^3,\ldots)$ and $A$ is an $m\times m$ tridiagonal matrix with of the form \begin{equation} A = \left( \begin{array}{ccccc} a & c & 0 & 0 & c \\\ c & a & c & 0 & 0 \\\ 0 & c & a & c & 0 \\\ 0 & 0 & c & a & c \\\ c & 0 & 0 & c & a \end{array} \right) \end{equation} Note that I am using periodic boundary conditions $x_{m+1}=x_1$ and thence the c's in the upper-right and lower-left corners. Here is $f(x)$ in Mathematica               m = 100; a = 2.0; b = 3.0; c = 3;     A = SparseArray[{         {m, 1} -> c, {1, m} -> c,          Band[{1, 1}] -> a, Band[{2, 1}] -> c, Band[{1, 2}] -> c},          {m, m}];     f[x_] := A.x - b x^3      The choice of parameters is somewhat arbitrary and perhaps this definition of $f(x)$ is not the fastest due to the dot product. I will use ACL's version LangevinVecACL, which is faster. So I first compile it               llvec = LangevinVecACL[f];      Here are two data sets for $\Gamma = 0.01$ (pretty cold) and $\Gamma = 10$ (pretty hot).               x0 = ConstantArray[0.0, m];     AbsoluteTiming[        data1 = llvec[x0, .01, 4, 10^4];        data2 = llvec[x0, 10, 4, 10^4];     ]      The following code shows the steady-state distribution of a single realisation               GraphicsGrid[{Map[       ListPlot[#, PlotRange -> {{-1, m + 1}, {Floor@Min@#, Ceiling@Max@#}},          Filling -> Axis, Frame -> True, BaseStyle -> 14,          FrameLabel -> {"Position", "Magnetization"}] &,       {Last@data1, Last@data2}]}, ImageSize -> {600}]      ![enter image description here](http://i.stack.imgur.com/AY7SQ.png) As can be seen, at cold temperatures the system tends to divide itself into domains with all spins chunked either "up" or "down"; conversely, at high temperatures the domain configuration is clearly degraded. The following function animates the time evolution of the system.               animateSpinChain[data_] :=  Animate[ListPlot[data[[i]],         PlotRange -> {{-1, m + 1}, {Floor[Min[data]], Ceiling[Max[data]]}},        Filling -> Axis], {i, 1, Length@data, Floor[Length@data/100]}]


Finding and interpreting errors

This sounds like a fairly trivial question, but I can't think of any way to solve it. I am doing an extensive parameter sampling where a set of ODEs is used together with `NDSolve` to find values of the dependent variables at certain time points. Yet, I am getting several different errors (e.g. convergence errors) when using **certain** parameters. Thus, I would like to ask your help in getting a way to **find which parameters yield the errors** , not how to fix the errors themselves. The algorithm uses the system of ODEs (with defined initial conditions) and defines the function to compute the concentrations at various time points. It is then used to do the parameter sampling               SysODEs={X'[t]==ba+k1 A - b1 X[t], Y'[t]==k2 X[t]-v1 Y[t]-k1,etc};          DFunction[{a1_,b1_,v1_,k1_},ba_]:=         Block[{sol1,c1,c2},         sol1=NDSolve[SysODEs/.k2->2,{X,Y},{t,0,300}];         c1=X[100]/.sol1;         c2=Y[300]/.sol1;         {c1,c2}         ]          SampleP=Flatten[         Table[{h, j, k, l}, {h, 0, 5, 1}, {j, 0.1, 0.9, 0.1}, {k, 1,10, 1}, {l, 5, 10, 1}],3];          ParallelMap[DFunction[#, 0.1] &, SampleP]      **Problem:** I want to know which values of `SampleP` yield errors. Because my original functions `SampleP`, `DFunction` etc. are much more complex, I didn't include them in here (`SampleP` has size ~200 000 in my problem). Is there any way of doing it? I was thinking about some kind of `Trace`, but this will give me too much unneeded information. **Edit:** I was searching and found this link with information about the functions `MLCreateMark()` and `MLSeekMark()` that are used in `MathLink`. Maybe this helps in finding something similar in Mathematica?


Creating Multi-Tabbed Grid with Preserved Contents and Overview Grid

I am in the process of creating an application/panel that will aide me in scheduling hours for my staff of ten or more. I am hoping to create a multi- tabbed grid within which I may collect data about my staff and ultimately create a final schedule based on their choices. I have started the code, but I find myself stuck in a couple places: creating a grid that pulls that data from the other grids to give an overview of the schedule (in order to find overlapping hours, holes in the schedule, etc.), saving the data in the input fields once entered, and counting the number of check boxes that are ticked on each tab. My code can be found below, any guidance, help, or thoughts would be very helpful at this point. Thank you. ![Mathematica graphics](http://i.stack.imgur.com/NL47R.png)               f = Enabled -> False;     m = ImageMargins -> 20;     week =       Grid[{         {"", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",           "Saturday", "Sunday"},         {"8:00 AM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m],           Checkbox[m], Checkbox[f], Checkbox[f]},         {"9:00 AM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m],           Checkbox[m], Checkbox[m], Checkbox[m]},         {"10:00 AM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m],           Checkbox[m], Checkbox[m], Checkbox[m]},         {"11:00 AM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m],           Checkbox[m], Checkbox[m], Checkbox[m]},         {"12:00 PM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m],           Checkbox[m], Checkbox[m], Checkbox[m]},         {"1:00 PM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m],           Checkbox[m], Checkbox[m], Checkbox[m]},         {"2:00 PM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m],           Checkbox[m], Checkbox[m], Checkbox[m]},         {"3:00 PM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m],           Checkbox[m], Checkbox[m], Checkbox[m]},         {"4:00 PM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m],           Checkbox[m], Checkbox[m], Checkbox[m]},         {"5:00 PM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m],           Checkbox[m], Checkbox[m], Checkbox[m]},         {"6:00 PM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m],           Checkbox[m], Checkbox[m], Checkbox[m]},         {"7:00 PM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m],           Checkbox[m], Checkbox[m], Checkbox[m]},         {"8:00 PM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m],           Checkbox[m], Checkbox[m], Checkbox[m]},         {"9:00 PM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m],           Checkbox[m], Checkbox[m], Checkbox[m]},         {"10:00 PM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m],           Checkbox[m], Checkbox[m], Checkbox[m]},         {"11:00 PM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m],           Checkbox[m], Checkbox[m], Checkbox[m]},         {"12:00 AM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m],           Checkbox[m], Checkbox[m], Checkbox[m]},         {"1:00 AM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m],           Checkbox[m], Checkbox[m], Checkbox[m]},         {"2:00 AM", Checkbox[f], Checkbox[f], Checkbox[f], Checkbox[m],           Checkbox[m], Checkbox[m], Checkbox[f]},         {"3:00 AM", Checkbox[f], Checkbox[f], Checkbox[f], Checkbox[m],           Checkbox[m], Checkbox[m], Checkbox[f]}         }, Frame -> All];     Clear[ln, fn, ws, ln2, fn2, ws2, ln3, fn3, ws3]     input =       Panel[        Grid[{          {""},          {Style["Front Desk Assignment Preferences", 14, Bold],            SpanFromLeft, SpanFromLeft, SpanFromLeft},          {""},          {"Last Name:", InputField[Dynamic[ln], String], SpanFromLeft,            SpanFromLeft},          {"First Name:", InputField[Dynamic[fn], String], SpanFromLeft,            SpanFromLeft},          {"-----------------------------------------------", SpanFromLeft,            SpanFromLeft, SpanFromLeft},          {"Workstudy:", RadioButtonBar[2, {1 -> "Yes", 2 -> "No"}],            SpanFromLeft, SpanFromLeft},          {"Workstudy Amount:  $",                InputField[Dynamic[n], Number, FieldSize -> 10], SpanFromLeft,                SpanFromLeft},              {"-----------------------------------------------", SpanFromLeft,                SpanFromLeft, SpanFromLeft},              {"Weekend Preference:",                RadioButtonBar[3, {1 -> "A", 2 -> "B", 3 -> "Either"}],                SpanFromLeft, SpanFromLeft},              {""},              {"-----------------------------------------------", SpanFromLeft,                SpanFromLeft, SpanFromLeft},              {Style[                "Please select the hours you are interested in working from \         the table below:", Bold], SpanFromLeft, SpanFromLeft, SpanFromLeft},              {week, SpanFromLeft, SpanFromLeft, SpanFromLeft},              {""}              }, Alignment -> Left]];         input2 =           Panel[            Grid[{              {""},              {Style["Front Desk Assignment Preferences", 14, Bold],                SpanFromLeft, SpanFromLeft, SpanFromLeft},              {""},              {"Last Name:", InputField[Dynamic[ln2], String], SpanFromLeft,                SpanFromLeft},              {"First Name:", InputField[Dynamic[fn2], String], SpanFromLeft,                SpanFromLeft},              {"-----------------------------------------------", SpanFromLeft,                SpanFromLeft, SpanFromLeft},              {"Workstudy:", RadioButtonBar[2, {1 -> "Yes", 2 -> "No"}],                SpanFromLeft, SpanFromLeft},              {"Workstudy Amount:  $",                InputField[Dynamic[n2], Number, FieldSize -> 10], SpanFromLeft,                SpanFromLeft},              {"-----------------------------------------------", SpanFromLeft,                SpanFromLeft, SpanFromLeft},              {"Weekend Preference:",                RadioButtonBar[3, {1 -> "A", 2 -> "B", 3 -> "Either"}],                SpanFromLeft, SpanFromLeft},              {""},              {"-----------------------------------------------", SpanFromLeft,                SpanFromLeft, SpanFromLeft},              {Style[                "Please select the hours you are interested in working from \         the table below:", Bold], SpanFromLeft, SpanFromLeft, SpanFromLeft},              {week, SpanFromLeft, SpanFromLeft, SpanFromLeft},              {""}              }, Alignment -> Left]];         input3 =           Panel[            Grid[{              {""},              {Style["Front Desk Assignment Preferences", 14, Bold],                SpanFromLeft, SpanFromLeft, SpanFromLeft},              {""},              {"Last Name:", InputField[Dynamic[ln3], String], SpanFromLeft,                SpanFromLeft},              {"First Name:", InputField[Dynamic[fn3], String], SpanFromLeft,                SpanFromLeft},              {"-----------------------------------------------", SpanFromLeft,                SpanFromLeft, SpanFromLeft},              {"Workstudy:", RadioButtonBar[2, {1 -> "Yes", 2 -> "No"}],                SpanFromLeft, SpanFromLeft},              {"Workstudy Amount:  $",            InputField[Dynamic[n3], Number, FieldSize -> 10], SpanFromLeft,            SpanFromLeft},          {"-----------------------------------------------", SpanFromLeft,            SpanFromLeft, SpanFromLeft},          {"Weekend Preference:",            RadioButtonBar[3, {1 -> "A", 2 -> "B", 3 -> "Either"}],            SpanFromLeft, SpanFromLeft},          {""},          {"-----------------------------------------------", SpanFromLeft,            SpanFromLeft, SpanFromLeft},          {Style[            "Please select the hours you are interested in working from \     the table below:", Bold], SpanFromLeft, SpanFromLeft, SpanFromLeft},          {week, SpanFromLeft, SpanFromLeft, SpanFromLeft},          {""}          }, Alignment -> Left]];     final = TabView[{"Worker 1" -> input, "Worker 2" -> input2,         "Worker 3" -> input3}]


Plotting plain data (single value lists) in 3D

**Some Chemistry data sets** I am trying to plot some titration data with Mathematica. I have done 4 experiments and gathered around 70 pH points (one for each milliliter) during each session, and therefore I have 4 sets of pH measurements. Now, in each experiment I used a different concentration of an extra compound (something that affects the titration), so the curves should, when plotted in 3D, show a nice behavior, since the precipitant forces the protons out of the acid (the Chemistry part here; may ignore). * * * Now, this curves are not meant to be plotted with equals distances, as in the image and what I've managed to do. ![H3PO4 titration with KOH and CaCl2](http://i.stack.imgur.com/Hmvzp.png) The standard why of plotting these 4 curves is by placing them at the $\log_{10}$ of the concentration of the extra compound ($\text{CaCl}_2$ for those who might be interested). My data looks like this:               L1 = {1.63, 1.67, 1.71, 1.76, 1.80, 1.85, 1.90, 1.94, 1.99, 2.03,        2.08, 2.11, 2.16, 2.21, 2.27, 2.35, 2.43, 2.52, 2.62, 2.72, 2.86,        3.05, 3.34, 4.06, 4.93, 5.28, 4.25, 4.26, 4.30, 4.37, 4.41, 4.48,        4.55, 4.60, 4.67, 4.78, 4.85, 4.94, 5.05, 5.19, 5.34, 5.49, 5.70,        5.99, 6.32, 6.76, 7.52, 8.49, 9.56, 10.61, 10.90, 11.09, 11.23,        11.33, 11.41, 11.48, 11.54, 11.59, 11.64, 11.68, 11.71, 11.73,        11.77, 11.80, 11.83, 11.85, 11.88, 11.89, 11.90, 11.91, 11.93}          L2 = {1.36, 1.44, 1.49, 1.55, 1.62, 1.68, 1.74, 1.82, 1.89, 1.98,        2.04, 2.09, 2.16, 2.26, 2.35, 2.47, 2.63, 2.83, 3.18, 4.23, 4.68,        4.89, 3.95, 4.12, 4.07, 4.07, 4.11, 4.15, 4.21, 4.27, 4.34, 4.42,        4.50, 4.59, 4.68, 4.81, 4.93, 5.11, 5.37, 5.78, 7.28, 10.28, 10.92,        11.17, 11.35, 11.45, 11.54, 11.62, 11.67, 11.72, 11.77, 11.81,        11.84, 11.91, 11.93, 11.95, 11.97, 11.98, 12.00, 12.02, 12.04,        12.05, 12.06, 12.08, 12.09, 12.10, 12.11, 12.12, 12.14, 12.14,        12.15, 12.16}          L3 = {1.48, 1.57, 1.62, 1.66, 1.72, 1.75, 1.81, 1.87, 1.92, 2.06,        2.10, 2.16, 2.21, 2.28, 2.35, 2.43, 2.51, 2.62, 2.75, 2.95, 3.19,        3.64, 4.10, 4.61, 4.84, 4.16, 4.11, 4.11, 4.00, 4.07, 4.12, 4.16,        4.19, 4.24, 4.32, 4.35, 4.40, 4.46, 4.53, 4.63, 4.70, 4.79, 4.92,        5.07, 5.23, 5.55, 6.23, 7.50, 7.87, 9.68, 10.49, 10.81, 11.01,        11.13, 11.24, 11.31, 11.37, 11.41, 11.46, 11.49, 11.50, 11.54,        11.57, 11.60, 11.62, 11.64, 11.67, 11.68, 11.70, 11.71, 11.72,        11.73, 11.74, 11.75, 11.5, 11.77, 11.78, 11.80, 11.81, 11.80, 11.82,        11.83}          L4 = {1.79, 1.84, 1.98, 2.01, 2.04, 2.08, 2.12, 2.16, 2.20, 2.24,        2.30, 2.34, 2.39, 2.43, 2.50, 2.58, 2.66, 2.76, 2.89, 3.02, 3.24,        3.72, 4.95, 5.47, 5.68, 4.77, 4.74, 4.82, 4.89, 5.00, 5.15, 5.33,        5.58, 5.89, 6.22, 6.46, 6.64, 6.80, 6.97, 7.11, 7.30, 7.52, 7.82,        8.55, 10.10, 10.70, 10.97, 11.13, 11.21, 11.33, 11.40, 11.46, 11.52,        11.58, 11.62, 11.66, 11.70, 11.70, 11.75, 11.77, 11.80, 11.83,        11.85, 11.87, 11.89, 11.91, 11.92, 11.94, 11.95, 11.97, 11.98}          L5 = {2.07, 2.09, 2.12, 2.17, 2.23, 2.26, 2.28, 2.31, 2.41, 2.45,         2.48, 2.52, 2.58, 2.63, 2.69, 2.76, 2.85, 2.95, 3.14, 3.28, 3.48,         3.82, 5.11, 5.76, 6.06, 6.23, 5.72, 5.83, 6.05, 6.28, 6.47, 6.50,         6.70, 6.82, 6.96, 7.08, 7.18, 7.22, 7.35, 7.47, 7.60, 7.74, 7.91,         8.15, 8.51, 9.54, 10.17, 10.63, 10.98, 11.22, 11.37, 11.49, 11.59,         11.68, 11.74, 11.79, 11.84, 11.90, 11.92, 11.95, 12.02, 12.07,         12.11, 12.15, 12.18, 12.20, 12.22, 12.24, 12.25, 12.28, 12.31,         12.34, 12.36}      So, each value there is the y-value, the number of item is the x-value and the z-value (or whatever it must be) is, for each complete set, the logarithm of the concentration. Any help is appreciated! * * * Example (extract from `L1`):               L = {{1.63,0,-0.7}, {1.67,1,-0.7}, {1.71,2,-0.7}, {1.76,3,-0.7}, {1.80,4,-0.7}, {1.85,5,-0.7}}      * * * The coordinates:               {{L3, L1, L2, L4, L5}, {Log10[0.199], Log10[0.099], Log10[0.15],        Log10[0.054], Log10[0.0265]}}


Manipulate embedded in a CDF ducument and started by a button

**Preamble** : I am working on a document that I plan to publish as a Supplementing in a regular scientific journal in the CDF form. In this document I fail to make the following thing: **Explanations** : There should be a button embedded in the text of a document referred below as the "main document". It is very much like in my recent question: How to specify a StyleSheet of a newly programmatically-created notebook? Upon its pressing, this button should bring up a notebook containing some text and an evaluated Manipulate statement. To be specific, here is a simplified example:                   Button["Show",      CreateDocument[       Column[{         TextCell["Some text" , "Text", FontSize -> 20],         ExpressionCell[          Manipulate[           Plot[Sin[a*x], {x, 0, 2 \[Pi]}], {a, 0, 1}]          ]         }],       WindowTitle -> "Some title", WindowSize -> {550, 400}],       ImageSize -> {50, 18}, BaseStyle -> {"GenericButton", Bold}]      Upon evaluation of this code a button appears. This button can be copy-pasted into any line of the text cell of the main notebook document. It should like like this:                                    Some text button some more text.       where instead of the word "button" the button should stay. Upon pressing this button the notebook opens. It contains the text "Some text" and should contain the dynamic demonstration defined by the Manipulate statement above. **The problem** : It works nicely in Mathematica. It does not, if I transform the main document into cdf. When I press the button in this cdf version of the document, the interactive part is not shown, instead a gray rectangle appears and a message comes up "This dynamic content cannot be displayed by the CDF player. To display this dynamic content requires Mathematica". However, it is a very innocent Manipulate statement, which is certainly displayed, if I put it in the CDF directly, not by such an oblique way. I guess that it is some CDF limitation here. However, **My questions** :   * Do you see any workaround here?    * May it be that it is since the document created this way is .nb, rather than .cdf, and it results in my attempts to use the CDF-Player to read the .nb document?   * If yes, most probably I cannot instruct Mathematica to create .cdf instead of .nb starting from the cdf main document, can I? Thank you in advance. Later edit: I indeed asked already this and have forgotten it completely. I am sorry. The outcome is that such a thing is impossible. That's a pity.


Alternatives pattern in a function definition

I thought that I remembered a way to write a function definition using "|", but can't find documentation for it. So for example, I'd want to define:               f[1, x_] := x^2;     f[2, x_] := x*12;      I thought there was a syntax, kind of like a "select case" or "switch" statement that used "|". Is there?


How to texturize a Disk/Circle/Rectangle?

The documentation for `Texture` states that " ** _other filled objects_** " can be texturized: > `Texture[obj]` is a graphics directive that specifies that _obj_ should be > used as a texture on faces of polygons and other filled graphics objects. And also: > Texture can be used in FaceForm to texture front and back faces differently. Though I fail to apply a simple texture to any of the following objects. It seems like that "other filled objects" only include `Polygon`s and `FilledPolygon`s, and `FaceForm` does not work with those.               img = Rasterize@        DensityPlot[Sin@x Sin@y, {x, -4, 4}, {y, -3, 3},          ColorFunction -> "BlueGreenYellow", Frame -> None,          ImageSize -> 100, PlotRangePadding -> 0];     {      Graphics[{Texture@img, Disk[]}],      Graphics[{FaceForm@Texture@img, Disk[]}],      Graphics[{Texture@img, Rectangle[]}],      Graphics[{FaceForm@Texture@img, Rectangle[]}],           (* Only this one works *)      Graphics[{Texture@img,         Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}},          VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]}],      Graphics[{FaceForm@Texture@img,         Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}},          VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]}]      }      ![Mathematica graphics](http://i.stack.imgur.com/3M0Id.png) **Edit:** It turns out that "Applying `Texture` to a disk directly isn't possible" (according to Heike, thanks s.s.o. for the link). This unfortunately means that:   1. the official documentation of `Texture` is wrong (or at least is misleading, as graphics objects usually include primitives);   2. either `Texture` is not fully integrated with the system, as it is not applicable for such primitives as a `Rectangle`, which seems to be just a very specific `Polygon`; or `Rectangle` is something else and is defined some other way at the lowest level than a `Polygon` (maybe it is some OS-dependent object). Frankly, it is quite hard to imagine what kept developers to include this functionality, but I must assume they had a good reason.


Problem with ListContourPlot feeding data format and WeatherData

With following code I am trying to show the mean wind speed patterns for a few geographic locations.               cords = Select[                 Reverse[CityData[#, "Coordinates"]] & /@ {"Oslo", "Vadso","Hammerfest"},                 Head@# == List &             ];      ListContourPlot[       Join @@ {#,List@WeatherData[#,                                   "MeanWindSpeed",                                    {{2013, 1, 25}, {2013, 5, 1}, "Day"}                       ][[1,2]]} & /@ cords     ]      How can I improve the code to solve following problems:   1. Even if the requested date window is wider (a few days), it only takes one day data from `WeatherData` and when I am changing the partitioning part to `[[All,2]]` the plot doesn't work and says the format it wrong.   2. For even wider data range (a few years), there are some missing data for some days. How can I also filter that bad data in the code? Remember, I need them exactly on the geographic location no matter how wide my data range is.


Options in a StringReplace rule

* case1              Options[f] = {"t" -> "0"};     f[___, OptionsPattern[]] :=  StringReplace["content", "t" :> OptionValue["t"]]          f[]          (*     con0en0     *)        * case2              rule = {"t" -> OptionValue["t1"]};          Options[gg] = {"t1" -> "T1", "t2" -> "1"};     gg[___, OptionsPattern[]] := StringReplace["content", rule]          gg[1]          (*     con~~OptionValue[t1]~~en~~OptionValue[t1]     *)      Here `OptionValue` couldn't get the value of "t1" So, how to make case 2 works like case 1? * * * I found one solution is               Options[gg]={"t1"->"T1","t2"->"1"};     gg[___,OptionsPattern[]]:=Hold[StringReplace]["content",rule]//ReleaseHold//Evaluate      Any simpler methods?


Install issue: Mathematica 9 on Ubuntu 13.10

I am trying to install Mathematica 9 on a Ubuntu 13.10 system. I had this working on my previous 13.04 version but now it breaks on when trying to unpack the sh archive:               $ sh Mathematica_9.0.0_LINUX.sh     Mathematica Secured 9.0.0 for LINUX Installer Archive          Verifying archive integrity.      Extracting installer. ...........................................................................     /home/stefan/Downloads/.3719     CRITICAL FAILURE: Fundamental Error      Installer text not found.      sudo sh ... produces same error, the md5 hash checks out ok. Anybody encountered this problem, and more to the point, figured out what is wrong? I submitted a ticket to Wolfram support but no luck there so far. Thanks for any ideas to try.


Removing pairs that meet a given criterion from a list

Let $(x_{min},x_{max})$ and $(y_{min},y_{max})$ represent lowerbound and upperbound acceptable values for some coordinate $c_i$. Setting $x_{min} = y_{min} = 1$ & $x_{max} = y_{max} = 9$, how can I take a list of values, e.g.:               val = {{0, 10}, {2, 10}, {4, 4}, {5, 6}, {10, 4}};      and use `DeleteCases` to get rid of coordinates such as `{0, 10}, {2,10}, & {10,4}` (the examples in the above list) where _either_ the $x$ or $y$ component of a pair is outside of the specified upper and lower bounds for acceptable values? Is `DeleteCases` an appropriate tool for large arrays?


Filling between parametric plots

I am new with Mathematica, but am trying to fill an area between two parametric plots               ParametricPlot[{{u + Sin[u], -Cos[u]}, {u + Sin[u + Pi], Cos[u + Pi]}},      {u, 0, Pi}, Axes -> True ]      which thus far are nice, clean curves: ![1](http://www.mat.univie.ac.at/~stuhlmeier/Trochoid.png) Thanks to the answers here: How do I fill in a circle made by ParametricPlot with one solid color? I became aware of `ListLinePlot`. However, my `ListLinePlot` for this situation               ListLinePlot[Table[{{u + Sin[u], -Cos[u]}, {u + Sin[u + Pi], Cos[u + Pi]}},     {u, 0, Pi, 0.0005}], Mesh -> All,      MeshStyle -> Directive[AbsolutePointSize[0.0005], Black],      PlotStyle -> Directive[Thin, LightGray]]      ![2](http://www.mat.univie.ac.at/~stuhlmeier/Filled_Trochoid.png) does not seem to give as good a resolution no matter how finely I subdivide the interval, and also produces problems with self-intersection near the boundaries when plotting several periods. In particular, the contrast with similar curves filled in `Plot` is striking. Is there a smarter way to fill the area between these parametric curves? Perhaps using something else than `ListLinePlot`? Thanks!


Calculating derivatives of roots of equation

I am interested in calculating how the roots of an equation change as one of the variables does, when the equation is evaluated numerically rather than symbolically. I have edited this code to be simpler than the original one.               Remove["Global`*"]     d = 1/1000; mig = 1/500; kappa = 1/10;     N1[x_] = 50*(1 + 17/100*x - mig);     Estar[x_] = (d)/(kappa*mig*N1[x]);     lambda[x_] = mig*N1[x]*(1 - Estar[x]);     I1star[x_] = kappa*Estar[x]*(1 - Estar[x])*mig*N1[x]/d;     M1[q_, t_, z_] = Sum[z^(n)*d*E^(-t*d)*E^(-N1[q]*mig*t)*(N1[q]*mig)^n*t^n/n!, {n, 0,      Infinity}];     Part1[q_, z_] := NIntegrate[M1[q, t, z], {t, 0, Infinity}]     RootFcn[q_, z_] := (1 - Estar[1]) + Estar[1]*((1 - kappa) + kappa*Part1[q, z]) - z      The question I'm interested in is how the solutions for z of (RootFcn[q,z]=0) change as q increases at the point q=1. There are two roots, 1 and a value between 0 and 1; the smaller value is the one that I'm interested in. If one uses Integrate in the above instead of NIntegrate, they can simply take the solution of Solve[RootFcn[q, z] == 0, z], and use D[] to get the derivative where q=1 (which yields -0.00124613). However unfortunately in my actual problem this is not possible to do as it's more complicated and cannot be evaluated symbolically; and NIntegrate must be used. Also I cannot use the definition of a derivative (Solving for RootFcn at arbitrarily close values and divide by some epsilon), because in my problem it is too time-consuming due to the very high precision required to get a reasonable answer. So each time I numerically evaluate Solve[RootFcn[q, z] == 0, z] it takes a few minutes but since I will have to solve an equivalent problem to this derivative question thousands of times, this is prohibitive. It seems like this is probably possible using numerical derivatives, but I'm not sure. Any help would be very appreciated.


Mathematica output doesn't work as input

Sometimes when I do, for example, a series expansion Mathematica gives me output that it won't take as input. For example if I do a series expansion:               Series[Hypergeometric2F1[a,x,y,z], {a,0,0} ]      produces:               Out[xx]= 1+ a Hypergeometric2F1^(1,0,0,0)[0,x,y,z] + O[a]^2      If I literally then click on this cell and evaluate it as input, or alternatively cut and paste this term into another input line and evaluate it returns the following error:               Syntax::sntxf: "(" cannot be followed by "1,0,0,0)".          Syntax::sntxi: Incomplete expression; more input is needed .      So it doesn't seem to like the exact form as input that it just gave me as output. What gives? EDITS: 1) I apologize for the formatting errors in the posting and the confusion that resulted, that should be fixed now. Thank you to those that pointed them out. 2) I have tried the suggestions to use `InputForm[%]`-the thing this, the expressions I am dealing with are very long, and when I put it into input-form they become unwieldy. I would prefer a way to retain the standard-form expression and manipulate that - but this might be impossible (it seems like it is impossible). Thanks for the help so far anyway.


symbolic solution for a system of nonlinear equations in mathematica

Would appreciate any help on the following in mathematica I cant figure it out. I have a system of equations that I am trying to solve symbolically. I have 9 equations and 8 unknowns (I have also tried a version of this with 6 equations and 6 unknowns with same result :(   Note this is after I had quit all applications and had mathematica running alone for about 20hours.   _No more memory available. Mathematica kernel has shut down. Try quitting other applications and then retry._ Below I am showing the version with 6eqns and 6 unknowns               (*setting these to reduce equations to 6 equations and 6 unknowns*)     Subscript[b, 11] = 1;     Subscript[b, 21] = 0;          y11 = (Subscript[a, 11] *Subscript[b, 11]) - (Subscript[a, 21]*       Subscript[b, 21]) ;     y21 = (Subscript[a, 21] *Subscript[b, 11]) + (Subscript[a, 11]*       Subscript[b, 21]);          y13 = ((Subscript[K, 1 R]*Subscript[a, 11]) *     \!\(\*SubsuperscriptBox[\(b\), \(11\), \(3\)]\)) + (Subscript[a, 11]       Subscript[b, 13]) - ((Subscript[K, 1 L]*Subscript[a, 21])*      \!\(\*SubsuperscriptBox[\(b\), \(11\), \(2\)]\) *Subscript[b,       21]) + ((Subscript[K, 1 R]*Subscript[a, 11])* Subscript[b, 11]      \!\(\*SubsuperscriptBox[\(b\), \(21\), \(2\)]\)) - ((Subscript[K,         1 L]*Subscript[a, 21])*      \!\(\*SubsuperscriptBox[\(b\), \(21\), \(3\)]\)) - (Subscript[a, 21]       Subscript[b, 23]);     y23 = ((Subscript[K, 1 L]*Subscript[a, 21])*      \!\(\*SubsuperscriptBox[\(b\), \(11\), \(3\)]\)) + (Subscript[a, 21]       Subscript[b, 13]) + ((Subscript[K, 1 R]*Subscript[a, 11])*      \!\(\*SubsuperscriptBox[\(b\), \(11\), \(2\)]\) Subscript[b,       21]) + ((Subscript[K, 1 L]*Subscript[a, 21])* Subscript[b, 11]      \!\(\*SubsuperscriptBox[\(b\), \(21\), \(2\)]\)) + ((Subscript[K,         1 R]*Subscript[a, 11]) *     \!\(\*SubsuperscriptBox[\(b\), \(21\), \(3\)]\)) + (Subscript[a, 11]       Subscript[b, 23]);          y15 = ((Subscript[K, 2 R]*Subscript[a, 11])*      \!\(\*SubsuperscriptBox[\(b\), \(11\), \(5\)]\)) + (3 *(Subscript[K,         1 R]*Subscript[a, 11])*      \!\(\*SubsuperscriptBox[\(b\), \(11\), \(2\)]\) Subscript[b,       13]) + (Subscript[a, 11] Subscript[b,       15]) - ((Subscript[K, 2 L]*Subscript[a, 11])*      \!\(\*SubsuperscriptBox[\(b\), \(11\), \(4\)]\) Subscript[b,       21]) - (2 *(Subscript[K, 1 L]*Subscript[a, 21])* Subscript[b, 11]       Subscript[b, 13] Subscript[b,       21]) + (2 *(Subscript[K, 2 R]*Subscript[a, 11])*      \!\(\*SubsuperscriptBox[\(b\), \(11\), \(3\)]\)      \!\(\*SubsuperscriptBox[\(b\), \(21\), \(2\)]\)) + ((Subscript[K,         1 R]*Subscript[a, 11])* Subscript[b, 13]      \!\(\*SubsuperscriptBox[\(b\), \(21\), \(2\)]\)) - (2 *(Subscript[K,         2 L]*Subscript[a, 11])*      \!\(\*SubsuperscriptBox[\(b\), \(11\), \(2\)]\)      \!\(\*SubsuperscriptBox[\(b\), \(21\), \(3\)]\)) + ((Subscript[K,         2 R]*Subscript[a, 11])* Subscript[b, 11]      \!\(\*SubsuperscriptBox[\(b\), \(21\), \(4\)]\)) - ((Subscript[K,         2 L]*Subscript[a, 11])*      \!\(\*SubsuperscriptBox[\(b\), \(21\), \(5\)]\)) - ((Subscript[K,         1 L]*Subscript[a, 21])*      \!\(\*SubsuperscriptBox[\(b\), \(11\), \(2\)]\) Subscript[b,       23]) - (2 *(Subscript[K, 1 R]*Subscript[a, 11])* Subscript[b, 11]       Subscript[b, 21] Subscript[b,       23]) + ((Subscript[K, 1 L]*Subscript[a, 21])*      \!\(\*SubsuperscriptBox[\(b\), \(21\), \(2\)]\) Subscript[b,       23]) - (Subscript[a, 21] Subscript[b, 25]);     y25 = ((Subscript[K, 2 L]*Subscript[a, 11])*      \!\(\*SubsuperscriptBox[\(b\), \(11\), \(5\)]\)) + (3* (Subscript[K,         1 L]*Subscript[a, 21])*      \!\(\*SubsuperscriptBox[\(b\), \(11\), \(2\)]\) Subscript[b,       13]) + (Subscript[a, 21] Subscript[b,       15]) + ((Subscript[K, 2 R]*Subscript[a, 11])*      \!\(\*SubsuperscriptBox[\(b\), \(11\), \(4\)]\) Subscript[b,       21]) + (2 * (Subscript[K, 1 R]*Subscript[a, 11])* Subscript[b,       11] Subscript[b, 13] Subscript[b,       21]) - (2*(Subscript[K, 2 L]*Subscript[a, 11])*      \!\(\*SubsuperscriptBox[\(b\), \(11\), \(3\)]\)      \!\(\*SubsuperscriptBox[\(b\), \(21\), \(2\)]\)) + ((Subscript[K,         1 L]*Subscript[a, 21])* Subscript[b, 13]      \!\(\*SubsuperscriptBox[\(b\), \(21\), \(2\)]\)) + (2  *(Subscript[K,         2 R]*Subscript[a, 11])*      \!\(\*SubsuperscriptBox[\(b\), \(11\), \(2\)]\)      \!\(\*SubsuperscriptBox[\(b\), \(21\), \(3\)]\)) + ((Subscript[K,         2 L]*Subscript[a, 11])* Subscript[b, 11]      \!\(\*SubsuperscriptBox[\(b\), \(21\), \(4\)]\)) + ((Subscript[K,         2 R]*Subscript[a, 11])*      \!\(\*SubsuperscriptBox[\(b\), \(21\), \(5\)]\)) - ((Subscript[K,         2 L]*Subscript[a, 11])*      \!\(\*SubsuperscriptBox[\(b\), \(21\), \(5\)]\)) + ((Subscript[K,         1 R]*Subscript[a, 11])*     \!\(\*SubsuperscriptBox[\(b\), \(11\), \(2\)]\) Subscript[b,       23]) - (2 * (Subscript[K, 1 L]*Subscript[a, 21])* Subscript[b,       11] Subscript[b, 21] Subscript[b,       23]) - ((Subscript[K, 1 R]*Subscript[a, 11])*      \!\(\*SubsuperscriptBox[\(b\), \(21\), \(2\)]\) Subscript[b,       23]) + (Subscript[a, 11] Subscript[b, 25]);          h11 = A1*y11 + ((3/4)*(A1)^3*y13) + ((5/8)*(A1)^5*y15) +      I*(A1*y21 + ((3/4)*(A1)^3*y23) + ((5/8)*(A1)^5*y25));          h31 = ((A1^3)/4)*y13 + ((5/16)*(A1)^5*y15) +      I*(((A1^3)/4)*y23 + ((5/16)*(A1)^5*y25));          h51 = ((A1^5)/16)*y15 + I*((A1^5/16)*y25);          h12 = A2*y11 + ((3/4)*(A2)^3*y13) + ((5/8)*(A2)^5*y15) +      I*(A2*y21 + ((3/4)*(A2)^3*y23) + ((5/8)*(A2)^5*y25));          h32 = ((A2^3)/4)*y13 + ((5/16)*(A2)^5*y15) +      I*(((A2^3)/4)*y23 + ((5/16)*(A2)^5*y25));          h52 = ((A2^5)/16)*y15 + I*((A2^5/16)*y25);               h11g = Expand[(A1*         y11 + ((3/4)*(A1)^3*y13) + ((5/8)*(A1)^5*y15))^2 + (A1*         y21 + ((3/4)*(A1)^3*y23) + ((5/8)*(A1)^5*y25))^2];     h12g = Expand[(A2*         y11 + ((3/4)*(A2)^3*y13) + ((5/8)*(A2)^5*y15))^2 + (A2*         y21 + ((3/4)*(A2)^3*y23) + ((5/8)*(A2)^5*y25))^2];     h31g = Expand[(((A1^3)/4)*         y13 + ((5/16)*(A1)^5*y15))^2 + (((A1^3)/4)*         y23 + ((5/16)*(A1)^5*y25))^2];     h32g = Expand[(((A2^3)/4)*         y13 + ((5/16)*(A2)^5*y15))^2 + (((A2^3)/4)*         y23 + ((5/16)*(A2)^5*y25))^2];     h51g = Expand[(((A1^5)/16)*y15)^2 + ((A1^5/16)*y25)^2];     h52g = Expand[(((A2^5)/16)*y15)^2 + ((A2^5/16)*y25)^2];               Solve[{h11g - (A1^2      \!\(\*SubsuperscriptBox[\(a\), \(11\), \(2\)]\)      \!\(\*SubsuperscriptBox[\(b\), \(11\), \(2\)]\) + A1^2      \!\(\*SubsuperscriptBox[\(a\), \(21\), \(2\)]\)      \!\(\*SubsuperscriptBox[\(b\), \(11\), \(2\)]\) + A1^2      \!\(\*SubsuperscriptBox[\(a\), \(11\), \(2\)]\)      \!\(\*SubsuperscriptBox[\(b\), \(21\), \(2\)]\) + A1^2      \!\(\*SubsuperscriptBox[\(a\), \(21\), \(2\)]\)      \!\(\*SubsuperscriptBox[\(b\), \(21\), \(2\)]\)) == 0,     h12g - (A1^2      \!\(\*SubsuperscriptBox[\(a\), \(11\), \(2\)]\)      \!\(\*SubsuperscriptBox[\(b\), \(11\), \(2\)]\) + A1^2      \!\(\*SubsuperscriptBox[\(a\), \(21\), \(2\)]\)      \!\(\*SubsuperscriptBox[\(b\), \(11\), \(2\)]\) + A1^2      \!\(\*SubsuperscriptBox[\(a\), \(11\), \(2\)]\)      \!\(\*SubsuperscriptBox[\(b\), \(21\), \(2\)]\) + A1^2      \!\(\*SubsuperscriptBox[\(a\), \(21\), \(2\)]\)      \!\(\*SubsuperscriptBox[\(b\), \(21\), \(2\)]\)) == 0,     h31g == 0, h32g == 0, h51g == 0, h52g == 0}, {Subscript[a,      11], Subscript[a, 21], Subscript[b, 13], Subscript[b, 23],      Subscript[b, 15], Subscript[b, 25]}]


What is the proper method to load a Mathematica package inside a DynamicModule

I have a `DynamicModule` that requires loading of Mathematica packages. The usual methods do not seem to apply (`Needs["MathematicaPackage`"]]`, etc) I've tried               Dynamic[Initialization :> (Needs["Package`"])];      with only partial success. I'm sure this is done regularly, but cannot find any MMA documentation to that effect.   What's the best way to load Mathematica packages in `Dynamic` or `DynamicModule` and `Manipulate`?


Issue with the NDSolve code

With this procedure, one may determine an eigen-value function $R(a)$ for any given $\Xi$ (say 0, 25, 50, 75, 100)               g[eta1_, eta3_, R_, a_, Xi_] := {f[1], h[1], q[1]} /.          NDSolve[{D[f[x], {x, 2}] - a^2 f[x] + a (h[x] + R q[x]) == 0,         D[h[x], { x, 2}] - a^2 h[x] + a Xi x f[x] == 0,         D[q[x], {x, 2}] - a^2 q[x] + a f[x] == 0,          f[0] == 0,     f'[0] == 1,     h[0] == eta1,     h'[0] == 0,      q[0] == 0,     q'[0] == eta3      }, {f, h, q}, {x, 0, 1}]     s[a_, Xi_] :=FindRoot[g[eta1, eta3, R, a, Xi], {{R, 0}, {eta1, 0}, {eta3, 0}},        MaxIterations -> 100000]      where the condition $f'(0) = 1$ is a normalisation condition. But the problem is that the code doesn't converge always. The output I am looking for is like this ![enter image description here](http://i.stack.imgur.com/wiBv8.png) Thanks


How to identify chemical substance from tattoo?

A friend of mine made a tattoo on his chest of some chemical substance formula. He challenged us to identify which substance is that. I thought that perhaps a combination of:   * Mathematica image processing capabilities   * Wolfram|Alpha chemical data   * Manual intervention could do the trick. Here is the picture: ![enter image description here](http://i.stack.imgur.com/SDZGa.png) I am looking for pointers on how to attack the problem (like keywords of Mathematica functions, etc). **EDIT 1** : I suppose the following need to be done:   * Extract the formula from the picture as basic (2D) structure diagram   * Define a distance metric for images or use existing one (e.g., `ImageDistance[]`)   * Calculate the distance of our element's diagram against all `ChemicalData[]` elements   * Pick the few first and do a visual verification At the moment 1st step seems like the most challenging. **EDIT 2** : As shown by Sjoerd it is much easier to search for a formula as string rather than as image!


Simplifying expressions involving Sum

I am trying to use _Mathematica_ to simplify a symbolic expression involving `Sum`. Particularly, I define a sum via               y = (x - x0)^α Sum[a[n] (x - x0)^n, {n, 0, Infinity}]      Then I take the derivative of `y` with respect to `x` and simplify via               FullSimplify[D[y, x]]      This yields $$(x-\text{x0})^{\alpha -1} \left(\alpha \sum _{n=0}^{\infty } a(n) (x-\text{x0})^n+(x-\text{x0}) \sum _{n=0}^{\infty } n a(n) (x-\text{x0})^{n-1}\right)$$ However, the expression above can be easily simplified further to $$(x-\text{x0})^{\alpha -1} \sum _{n=0}^{\infty } ( a(n) (x-\text{x0})^n(\alpha+n) ) $$ Is there a way to "make" _Mathematica_ recognise this simplification? I presume the problem has something to do with the fact that I use the unknown function `a[n]` in the expression, but I am not sure what can I do about it to get similar functionality. I am quite new to _Mathematica_. Apologies if this is a trivial question.


how to load everything when opening a saved notebook

generally, when I carry over work in a notebook from the previous day, I have to physically start from the top and re-evaluate every statement before I can begin from where i left off. Is there any setting I can enable so that the notebook will be in state when it becomes active? Thanks, Sid.


Format and TeXForm does not work as expected

Recently, we had a nice question which brought up an issue that I believe is a bug. In the tutorial Defining Output Formats is an example at the end which doesn't make sense > This specifies the `TeXForm` for the symbol `x`. >   >   >     Format[x, TeXForm] := "{\\bf x}" >   > > The output format for `x` that you specified is now used whenever the TeX > form is needed. >   >   >     TeXForm[1 + x^2] >     (* x^2+1 *) >   The given output is wrong and should instead be something like `{\bf x}^2+1`. Therefore, I tested this with my colleague on all versions available to us and the output below shows, that it only worked back in version 4.2. Is there a simple reason why `Format` does not work as advertised? ### Version 4.2               Format[x,TeXForm]:="{\\bf x}";     TeXForm[1+x^2]     (* 1 + {{\bf x}}^2 *)      ### Version 5.1               Format[x,TeXForm]:="{\\bf x}";     TeXForm[1+x^2]     (* x^2+1 *)      ### Version 6.0               Format[x, TeXForm] := "{\\bf x}";     TeXForm[1 + x^2]     (* x^2+1 *)      ### Version 7.0               Format[x, TeXForm] := "{\\bf x}";     TeXForm[1 + x^2]     (* x^2+1 *)      ### Version 8.0               Format[x, TeXForm] := "{\\bf x}";     TeXForm[1 + x^2]     (* x^2+1 *)      ### Version 9.0               Format[x, TeXForm] := "{\\bf x}";     TeXForm[1 + x^2]     (* x^2+1 *)


ListPlot with spherical coordinates with data from file

I have a file that is a table of values for r, $\theta$ and f(r,$\theta$) with r and $\theta$ being spherical coordinates, $\phi$ being 0 the whole time. The data thus looks like {{0.1,0.01,2},{0.1,0.02,2.1},{0.1,0.03,2.05},...} How do I plot this in a nice way? I do not want r- and $\theta$-axes but rather convert it to an xz-grid, I guess. Is there any neat way to do this? I just had the idea of converting the variables by myself typing this but also have no idea how to do that either. Any help is appreciated! So a little more thinking solved the problem: I read the data, create an empty array of the same size and transform coordinates by hand.               datalist = ReadList["file.dat", Number, RecordLists -> True];     data2 = Array[0, {Length[datalist], 3}];          For[i = 1, i < Length[datalist], i++,       For[j = 1, j <= 3, j++,        If[j == 1, data2[[i, j]] = datalist[[i, 1]]*Sin[datalist[[i, 2]]]];        If[j == 2, data2[[i, j]] = datalist[[i, 1]]*Cos[datalist[[i, 2]]]];        If[j == 3, data2[[i, j]] = datalist[[i, j]]]      ]     ]          ListPlot3D[data2]`      Not sure if this is the most elegant way but it worked. Thanks for the input and next time I will do my best to state the problem more clearly ;)


How to insert elements of a list into list of lists?

I have two lists. E.g.               l1 = {{{t1, d11}, {t2, d12}, {t3, d13}},            {{t1, d21}, {t2, d22}, {t3, d23}},            {{t1, d31}, {t2, d32}, {t3, d33}},            {{t1, d41}, {t2, d42}, {t3, d43}}};          l2 = {p1, p2, p3, p4};      I would like to generate a list like res.               l22 = Table[l2[[i]], {i, 1, Length[l2]}, {Length[l1]}];          res = Table[Riffle[l1[[i, j]], l22[[i]], 3], {i, 1, 4}, {j, 1, 3}]      > >     {{{t1, d11, p1}, {t2, d12, p1}, {t3, d13, p1}}, >     {{t1, d21, p2}, {t2, d22, p2}, {t3, d23, p2}}, >     {{t1, d31, p3}, {t2, d32, p3}, {t3, d33, p3}}, >     {{t1, d41, p4}, {t2, d42, p4}, {t3, d43, p4}}} >   It would be nice to have a code in one step and without counting the length of the list. I have seen similar manipulations with `Append` or `Join`, but I could not combined with mapping to get the right structure.


How to remove quotation marks from a generic InputField

I need to use an InputField with a generic dynamic variable (not restricted to be Number or String or whatsever) and I don't want to see the quotation marks in the case the input is a string. Here is an example               z="";     InputField[Dynamic[z]]      I know the Cell's option ShowStringCharacter but here doesn't work, for instance see               z = "";     Panel[Column[{Style[InputField[Dynamic[z]],          ShowStringCharacters -> False], Spacer[5],         Row[{"This is the value of variable z", Spacer[5], Dynamic[z]}]}]]      and this one               z = "";     ExpressionCell[      Panel[Column[{Style[InputField[Dynamic[z]],           ShowStringCharacters -> False], Spacer[5],          Row[{"This is the value of variable z", Spacer[5],            Dynamic[z]}]}]], ShowStringCharacters -> False]      Any suggestion? Thanks in advace, Roberto