Making a multiple choice button

I've written the following code to create a multiple choice button that takes an arbitrary number of answer options and will assign a variable true/false depending on whether or not the correct choice is selected:               mchoice[question_, answers_, correct_, var_] :=      DynamicModule[{x},       Column[{Dynamic[var = (x == correct);], (*problem line *)         Dynamic@          ActionMenu[question,            MapThread[#1 :> (x = #2) &, {answers, Range@Length@answers}]],         PaneSelector[          MapThread[#1 -> #2 &, {Range@Length@answers, answers}],           Dynamic[x]]         }]       ]      The code is executed as below and gives the button:               Clear[avar]     mchoice["argon", {"solid", "liquid", "gas"}, 3, avar]      ![Mathematica graphics](http://i.stack.imgur.com/1PUmc.png) The correctness of the selection is stored in `avar` which I can evaluate at the end of the notebook to "grade" the quiz, if you will. The problem is the presence of `Null` above the button. With the code as written, I cannot seem to create a button that both updates the value of avar and doesn't print the answer. For example, if I substitute `Dynamic[var = (x == correct)]` for the problem line, then the student will know if the chosen answer is correct. If I use `Dynamic[var = (x == correct)];` then the result is visually correct but `avar` will not update when the student selects an answer. I _can_ get the desired result by using `Dynamic[var = (x == correct);] /. {Null ->""}` but that feels like I'm cheating (yes, I'm getting the desired result, but no, I'm not using `Dynamic` correctly). I'm interested in either of the following:   1. A better solution to my (* problem line *)   2. Alternative methods for creating a multiple choice button.


Non-canonical re-ordering of nested lists

I have some data in the form:                data = {{{d, 0.68}, {g, 0.88}, {h, 0.23}, {e, 0.15}, {b, 0.46}, {a, 0.07}},               {{d, 0.86}, {c, 0.99}, {b, 0.21}},               {{c,0.83}, {h, 0.63}, {f, 0.11}},               {{d, 0.31}, {g, 0.65}, {e, 0.88}, {a, 0.70}},               {{d, 0.58}, {g, 0.09}, {c, 0.66}, {b, 0.18}, {a, 0.15}}}      These data are essentially related to each other in the following way:               {{{d, d1}, {g, g1}, {h, h1}, {e, e1}, {b, b1}, {a, a1}},       {{d, d2}, {c, c2}, {b, b2}},       {{c, c3}, {h, h3}, {f, f3}},       {{d, d4}, {g, g4}, {e, e4}, {a, a4}},       {{d, d5}, {g, g5}, {c, c5}, {b, b5}, {a, a5}}}      The ordering of elements within each second level list is:               order1 = {d, g, c, h, e, f, b, a}      I want to collect the second term of each third level pair and rearrange the elements according to a different order:               order2 = {b, h, d, a, e, f, c, g}      so that I end up with something like:               {{b1, h1, d1, a1, e1, f1, c1, g1},      {b2, h2, d2, a2, e2, f2, c2, g2},      {b3, h3, d3, a3, e3, f3, c3, g3},      {b4, h4, d4, a4, e4, f4, c4, g4},      {b5, h5, d5, a5, e5, f5, c5, g5}}      Where an element is missing I want to replace it with a zero to obtain rows of equal length. Using numbers it would look like:                 {{0.46, 0.23, 0.68, 0.07, 0.15, 0, 0, 0.88},         {0.21, 0, 0.86, 0, 0, 0, 0.99, 0},         {0, 0.63, 0, 0, 0, 0.11, 0.83, 0},         {0, 0, 0.31, 0.7, 0.88, 0, 0, 0.65},         {0.18, 0, 0.58, 0.15, 0, 0, 0.66, 0.09}}      I am currently using                (row = #;         Map[(ordi = #; k = Flatten[Position[row, _?((ordi == #) &)]];                  If[Length[k] == 0, 0, row[[k[[1]], 2]]]) & , order2]) &/@ data      **Edit** The code in the original question is now working... (thanks @partial81 for trying it - and sorry for the confusion). However, I am still interested in discovering different ways to get the result. Any alternative suggestions would be appreciated.


BSplineFunction derivatives wrong if using weights?

In my work, I make heavy use of non-uniform rational B-spline (NURBS) functions, defined using the function `BSplineFunction` with the option defining `weights`. I never before questioned the results given by Mathematica, but it seem that I discovered something that seems like a bug. Let's use a simple example : a quarter of circle. The degree, knot vector, control point vector and weights used for this are :               d = 2;     kV = {0, 0, 0, 1, 1, 1};     P = {{0, 0}, {0, 1}, {1, 1}};     W = {1, 1/Sqrt[2], 1};      I defined the two parametric functions `x` and `y` this way :               x[t_] := BSplineFunction[P[[All, 1]], SplineWeights -> W, SplineDegree -> d, SplineKnots -> kV]][t];     y[t_] := BSplineFunction[P[[All, 2]], SplineWeights -> W, SplineDegree -> d, SplineKnots -> kV]][t];      The results obtained are perfect, `{x[t], y[t]}` is an exact quarter of circle. The problem is when I want to have the derivatives of `x` and `y`. Here is the graph I have when I plot `x'[t]` (blue) and the function I should have (computed by redefining all the NURBS functions from the beginning) ![enter image description here](http://i.stack.imgur.com/JFi0o.png) We can see that _Mathematica_ derivative is in fact `x'[t] = t b2`, which is in reality the derivative of the Spline function defined with the same degree, knot vector and control points, but uniform weights.(which is wrong) I would like to know if I made a mistake somewhere, or if it is really a bug of `BSplineFunction`.


How to raise the LegendLayout "Row" size

When using `LegendLayout->"Row"`, with a lengthy row, I get line breaks. This would seemed logic if it was confined by another structure. But if happens even when there's no "confinement":               LineLegend[{Blue, Orange, Green}, {"this is a big test",        "this is a big test", "this is a big test"}, LegendLayout -> "Row"]      ![enter image description here](http://i.stack.imgur.com/iurGp.gif) How can I change the `ItemSize`/`ImageSize` of the Legend? (should this behavior be reported?)


How can the evaluation queue be aborted?

While developing, I would sometimes like to stop evaluation of selected cells at a certain point. The following example nearly seems to work, but repeated runs of `Ctrl+A, Enter` reveal something sticking in memory. Is there a good way break out of the evaluation queue?               Print["1"]          Print["2"]          FrontEndExecute@FrontEndToken["EvaluatorAbort"]          Print["3"]          Print["4"]      _Example of the problem:_ On the fourth repetition (on this occasion) of `Ctrl+A, Enter` the first cell does not evaluate. ![enter image description here](http://i.stack.imgur.com/S5mdH.png)


Linear Integer Programming with absolute values in objective function

I'm trying to solve a problem of the form $$ \left|a_{1,0}+a_{1,1} x_1 + a_{1,2}x_2\right| + \left|a_{2,0}+a_{2,1} x_1 + a_{2,2}x_2\right|\to\min, $$ where $a_{i,j}$ are real-valued coefficients and the $x_i$ are integers. In fact, in my real problem, their are more variables and the problem looks like this: $$ \sum_{i=1}^n\left|a_{i,0}+\sum_{j=1}^ma_{i,j}x_j\right|\to\min, $$ Is there an easy way to transform this into an linear integer programming probably suitable for Mathematica? I'm not sure how to deal with the absolute values in the objective functions, and how to convert the problem into matrix form. Thanks. **Edit:** As a concrete example, consider the function               f = (x (-9 + 6 x - 8 x^2 + 3 x^3))/(4 (-3 + 3 x - 3 x^2 + x^3)) + 0.0002 Sin[50 x] + 0.0002 Sin[100 x]      which is known on the grid $0,.01,\ldots,1$. Defining               data=Table[{x,f},{x,0,1,.01}]      the problem is to recover the coefficients of $f$ from $data$, knowing that $f$ is a perturbed rational function with integer coefficients of bounded magnitude. If $f$ was not perturbed then               << FunctionApproximations`     RationalInterpolation[f, {x, 4, 3}, {x, 0, 1}]      could be used recover the coefficients (or a variant that specifies the $x_i$) Does the a priori information that the coefficients are integers allow exact reconstruction of $f$ despite the perturbation?


Why doesn't Compile work on Permutations function with second args?

Here is a narrowed-down example, the first case works, but the second one refuses to use the compiled version:                Compile[{}, Permutations[{1, 2, 3}]][]           Compile[{}, Permutations[{1, 2, 3}, {2}]][]      Full code:               Compile[{},       Module[{c, d, e, g, l, m, o, t, w, A = 10^Range[5, 0, -1]},         Do[{c, d, e, g, l, m, o, t, w} = x;         If[{w, w, w, d, o, t}.A - {g, o, o, g, l, e}.A == {d, o, t, c, o,              m}.A, Print@x], {x, Permutations[Range[0, 9], {9}]}]]       ][]


How to solve equations self-consistently

I want to solve the following equation self-consistently. So,               H.u = e.u          {{1, d}, {d, 1}}.{u1, u2} = e.{u1, u2}        1. I guess an initial value for `d`   2. Diagonalize `H` and get eigenvectors and eigenfunction `u` and `e->Eigenvector[H] Eigenvalue[H]`   3. Define `d -> d = u1 + u2`   4. Plug `d` in the matrix again   5. Diagonalize `H...` once and again until I get certain convergence, i.e., until the value I get for `d` does not change within a certain convergence range `dmin`. Of course, this a really simplified kind of problem of my actual problem I have to solve with a huge matrix. This is really easy to do in Fortran90, but I wonder how do you do this kind of things in _Mathematica_.


Using Control Objects with TabView

I have a number of different tabs on my 'dashboard'. Each tab has a few different Controls (drop down boxes) that the user makes selections with. These selections determine what is displayed on the tab in question. The controls, data, graphs etc are all known by seperate names so no control on one tab drives changes on another. My problem is that when I use these drop down controls the entire display jumps back to the default page for the TabView. I think this has something to do with := set delay or Dynamic but I can't work it out. The data comes from -               MOYGraphData := Select[Part[MonthlyFuel, 2 ;;, ;;], #[[4]] == DropDownGeneratorSelection && #[[1]] == DropDownYearSelection && #[[3]] == 0 &];           MOYGraphData1a := Partition[Riffle[Part[MOYGraphData, ;; , 2], Part[MOYGraphData, ;; , ColInDataM]], 2];          MOYGraphData2a := Partition[ Riffle[Part[MOYGraphData, ;; , 2], Part[MOYGraphData, ;; , ColInDataBaselineM]], 2];      Below is how I display it-               MOYGraph := ListLinePlot[Sort[{MOYGraphData1, MOYGraphData2}], PlotMarkers -> Automatic, PlotRange -> {{1, 12}, Automatic}, AxesOrigin -> {1, Automatic}, Ticks -> {Range[1, 12], Automatic}, PlotLabel -> "Monthly View", AxesLabel -> {"Month", YaxisTab2}, AspectRatio -> 1/11, ImageSize -> {1200, 150}]          Tab2 := Column[{Grid[{{YearHead, GenHead, MetricHead(, ChartHead)}, {DropDownYear, DropDownGenerator, DropDownMetric(, DropDownChartType)}}], Column[{HeadingTab2, MOYGraph, Column[{WeekHead, DropDownWeek, WOYGraph}], DOMGraph, Row[{GeneratorTotalWOYFuelVar, GeneratorWOYTotalFuelCons}, Alignment -> Left]}, Alignment -> Center]}, Alignment -> Left];          Dashboard := TabView[{"Introduction" -> IntroPage, "Fuel & Energy" -> Tab2, "Generator Loading" -> Tab3, "Generator Comparison" -> " ", "Data Exclusions" -> " "}, 2];          Dynamic[Dashboard]


Is there a better way to approximate some graphs of integrals than interpolation?

I'm still pretty new to Mathematica so my apologies if this is a dumb question. I wanted to plot some integrals of functions for no particularly good reason, but the only decent way I could come up with to do that in Mathematica is by getting an interpolation function from a table of points generated from my original function, and then NIntegrating that interpolation function. This seems awfully fiddly. Is there a better way that I've been too dumb to notice? Also, I wrote the "procedure" (very heavy quotes) in a block of text so I could use it later, is there a better way to write a simple program like this so that it can be called later without having to copy paste the text and run it again like I'm doing?               domainend = Input["Enter the maximum domain to calculate"]     iterator = Input["Enter the number of steps for each value of x in the domain."]     function = Input["Enter the function whose integral will be approximated."]     grdom1 = Input["Enter leftmost value to graph"]     grdom2 = Input["Enter rightmost value to graph"]     domainstart = (-domainend)          functionvar[x_] =        Interpolation[         N[Transpose[{           (Table[x, {x, domainstart, domainend, iterator}]),            (Table[function, {x, domainstart, domainend, iterator}] /. ComplexInfinity ->0)                }],          30],         x]     diff = NIntegrate[functionvar[x], {x, domainstart, 0}]     antiderivative[x_] = Integrate[functionvar[x], x]     f = Function[x, functionvar[x]]     i = Function[x, antiderivative[x]]     g = Function[x, antiderivative[x] - diff]          Plot[       {f[x], g[x]}, {x, grdom1, grdom2},          PlotStyle -> Thickness[0.0025], PlotLegends -> {function, \!\(         \*SubsuperscriptBox[\(\[Integral]\), \(0\), \(x\)]\(function \         \[DifferentialD]x\)\)}, Filling -> {1 -> {Axis, LightBlue}}     ]


How to draw Graphics3D items with straight border lines?

I want to make a `Polygon` with straight border lines. For that purpose I wrote the following code, but it doesn't show straight borders.               Graphics3D[{Style[Polygon[{{20, 0, 10}, {50, 0, 10}, {50, 0, 25}, {20, 0, 25}}],       Lighting -> {{"Ambient", LightBlue}}]}, Boxed -> False, RotationAction -> "Clip"]      How can I make a polygon with straight lines? ![enter image description here](http://i.stack.imgur.com/GrXgX.png)


Problem with plot of discontinuous function of 2 variables and adding legend to a contourplot

I have 2 problems with which I would need help: -first one is that I would like to plot a discontinuous function of 2 variables but can't succeed (see attachment) -then I also would like to display a legend with a contour plot on which there are several ellipses but can't figure out (also see attachment). I don't want the usual contourplot legend with color graduation but one like : blue->ellipse one red->ellipse two                   s1t = 90         s2t = 40         s1c = -130         s2c = -60         f[x_, y_] := (x/s1t)^2 + (y/s2t)^2 - x*y/(s1t)^2 /; x > 0 && y > 0          f[x_, y_] := (x/s1t)^2 + (y/Abs[s2c])^2 - x*y/(Abs[s1c])^2 /;      x > 0 && y < 0         f[x_, y_] := (x/Abs[s1c])^2 + (y/s2t)^2 - x*y/(s1t)^2 /;      x < 0 && y > 0         f[x_, y_] := (x/Abs[s1c])^2 + (y/Abs[s2c])^2 - x*y/(Abs[s1c])^2 /;      x < 0 && y < 0         ContourPlot[f == 1, {x, -30 Pi, 30 Pi}, {y, -45 Pi, 20 Pi},      Axes -> {True, True}]         ContourPlot[{(x/s1t)^2 - x*y/(s1t*s2t) + (y/s2t)^2 ==      1, (x/s1t)^2 + (y/s2t)^2 + x*y*(1/(s1t^2) - 1/(s2t^2)) == 1,      x^2/(s1t^2) + y^2/(s2t^2) - x*y/(s1t^2) == 1,      x^2/(s1t*Abs[s1c]) +      y^2/(s2t*Abs[s2c]) + (1/s1t - 1/Abs[s1c])*      x + (1/s2t - 1/Abs[s2c])*y +      2*x*y*1/(2*s45^2)*(1 - (1/s1t - 1/Abs[s1c] + 1/s2t - 1/Abs[s2c])*         s45 - (1/(s1t*Abs[s1c]) + 1/(s2t*Abs[s2c]))*s45^2) == 1,      x^2/Abs[(s1t*s1c)] +  y^2/Abs[(s2t*s2c)] + (1/s1t - 1/Abs[s1c])*      x + (1/s2t - 1/Abs[s2c])*y - 1/(2*Sqrt[s1t*s1c*s2t*s2c]) == 1,      x^2/Abs[(s1t*s1c)] +      y^2/Abs[(s2t*s2c)] + (1/s1t - 1/Abs[s1c])*      x + (1/s2t - 1/Abs[s2c])*y + 1/Sqrt[s1t*s1c*s2t*s2c] -      1/(2*S^2) == 1, (x/s1t)^2 + (y/s2t)^2 ==      1, (x/s1t)^2 + (y/s2t)^2 - x*y/(s1t*s2t) ==      1, (x*y - x^2)/(s1t*s1c) - (y^2/(s2t*s2c)) +      x*(s1t + s1c)/(s1t*s1c) + y*(s2c + s2t)/(s2t*s2c) ==      1, (1.95*x*y - x^2)/(s1t*s1c) - (y^2/(s2t*s2c)) +      x*(s1c + s1t)/(s1t*s1c) + y*(s2c + s2t)/(s2t*s2c) ==      1}, {x, -165 Pi, 70 Pi}, {y, -75 Pi, 30 Pi}, Axes -> {True, True},      FrameLabel -> {sigma1, sigma2}, PlotLabel -> failure surface,      AspectRatio -> Automatic]


Select rows of matrix that are higher than a given row

Imagine I have the following matrix: `X={{0,0,0},{1,0,1},{1,1,1},{1,2,1},{3,3,3}}`. I want to select the sublists that are greater or equal than this list `T={0,1,1}`. Greater in the sense that `X[[]]-T` has no negative entries. The output should look like `R={{1,1,1},{1,2,1},{3,3,3}}`, since all elements of the sublists are equal of greater than the elements of the list T compared element by element. Thanks for help! Thanks for the quick answers. I have searched myself meanwhile and found this one:               Higher[C_] := Select[B, NonNegative[Min[#[[]] - C[[]]]] &];      Does it seem right?


Solve equation with inequalities for parameters

I want to solve following equation:               Solve[{g^2 - gamma*alpha + alpha^2 -          omega*(omega*alpha)/(gamma - 2*alpha) - (omega^2*            alpha^2)/(gamma - 2*alpha)^2 == 0, gamma > 0, omega > 0,        g > 0}, alpha]      I want to become an analytic, explicit expression for alpha, but _Mathematica_ gives me only a solution with `Root`; for example, (there are more solutions):               {alpha ->        ConditionalExpression[        I Root[g^2 gamma^2 -              4 g^2 gamma Root[               g^2 gamma^2 + (-4 g^2 gamma - gamma^3 -                     gamma omega^2) #1 + (4 g^2 + 5 gamma^2 +                     omega^2) #1^2 - 8 gamma #1^3 + 4 #1^4 &, 1] -              gamma^3 Root[               g^2 gamma^2 + (-4 g^2 gamma - gamma^3 -                     gamma omega^2) #1 + (4 g^2 + 5 gamma^2 +                     omega^2) #1^2 - 8 gamma #1^3 + 4 #1^4 &, 1] -              gamma omega^2 Root[               g^2 gamma^2 + (-4 g^2 gamma - gamma^3 -                     gamma omega^2) #1 + (4 g^2 + 5 gamma^2 +                     omega^2) #1^2 - 8 gamma #1^3 + 4 #1^4 &, 1] +              4 g^2 Root[               g^2 gamma^2 + (-4 g^2 gamma - gamma^3 -                     gamma omega^2) #1 + (4 g^2 + 5 gamma^2 +                     omega^2) #1^2 - 8 gamma #1^3 + 4 #1^4 &, 1]^2 +              5 gamma^2 Root[               g^2 gamma^2 + (-4 g^2 gamma - gamma^3 -                     gamma omega^2) #1 + (4 g^2 + 5 gamma^2 +                     omega^2) #1^2 - 8 gamma #1^3 + 4 #1^4 &, 1]^2 +              omega^2 Root[               g^2 gamma^2 + (-4 g^2 gamma - gamma^3 -                     gamma omega^2) #1 + (4 g^2 + 5 gamma^2 +                     omega^2) #1^2 - 8 gamma #1^3 + 4 #1^4 &, 1]^2 -              8 gamma Root[               g^2 gamma^2 + (-4 g^2 gamma - gamma^3 -                     gamma omega^2) #1 + (4 g^2 + 5 gamma^2 +                     omega^2) #1^2 - 8 gamma #1^3 + 4 #1^4 &, 1]^3 +              4 Root[g^2 gamma^2 + (-4 g^2 gamma - gamma^3 -                     gamma omega^2) #1 + (4 g^2 + 5 gamma^2 +                     omega^2) #1^2 - 8 gamma #1^3 + 4 #1^4 &,                1]^4 + (-4 g^2 - 5 gamma^2 - omega^2 +                 24 gamma Root[                  g^2 gamma^2 + (-4 g^2 gamma - gamma^3 -                        gamma omega^2) #1 + (4 g^2 + 5 gamma^2 +                        omega^2) #1^2 - 8 gamma #1^3 + 4 #1^4 &, 1] -                 24 Root[                  g^2 gamma^2 + (-4 g^2 gamma - gamma^3 -                        gamma omega^2) #1 + (4 g^2 + 5 gamma^2 +                        omega^2) #1^2 - 8 gamma #1^3 + 4 #1^4 &,                   1]^2) #1^2 + 4 #1^4 &, 2] +          Root[g^2 gamma^2 + (-4 g^2 gamma - gamma^3 -                gamma omega^2) #1 + (4 g^2 + 5 gamma^2 + omega^2) #1^2 -             8 gamma #1^3 + 4 #1^4 &, 1], g > 0 && gamma > 0 && omega > 0]}      This is not an explicit solution. I have also tried `Reduce` without success. What can I do?


Calculate probability function

I would like to calculate the following with _Mathematica_ : > Let $X$ be a random variable with probability function $$p(x)= \left\\{ > \begin{matrix} \frac{x}{6} & \text{for }x \in \\{1,2,3\\}\\\ 0 & > \text{Otherwise} \end{matrix}\right. $$ Calculate $P(X \leq 2)$, $E(X)$ and > $var(x)$ My major problem is to create the probability function with the correct distribution since there haven't been any specific distribution informed in the task. So how do I solve this? If it is any help, then the results are respectively:               {0.5, 2.333, 0.5556}


Riemann-Spherical Projection of Network onto the $\mathbb{R}^2$-Plane

I'm trying to find a way to plot the graph               g := Graph[{a\[UndirectedEdge]b, b\[UndirectedEdge]c, c\[UndirectedEdge]a,         a\[UndirectedEdge]d, d\[UndirectedEdge]b, d\[UndirectedEdge]e, e\[UndirectedEdge]b},d\[UndirectedEdge]c]      onto a sphere, so that it can be shown that although there isn't a crossing on the sphere there is when projected on the $\mathbb{R}^2$-plane. Here is something much like what I'd like to see: $\hspace{6cm}$![enter image description here](http://i.stack.imgur.com/5Ou0v.jpg) Further, how does one manipulate a graph? I mean, move the points around as you would in reality if the vertices were connected with rubber bands. This is what I'm doing as an alternative to not knowing how to manipulate graphs in Mathematica 8: ![Image](http://i.stack.imgur.com/pK53U.jpg)


Why Min cannot be used as constrains of NMinimize?

I met a strange problem when trying to do an optimization. Initialization code,               goal = 2.;     vector = {1.0, 1.1, 1.2, 1.3, 1.4, 1.5};          f[m1_Real, m2_Real] := Block[{v},        v = Map[# + m1*Sin[Norm[{m1, m2}]] &, vector];        Clip[v, {0, goal}]];          g[m1_Real, m2_Real] := Max[(goal - f[m1, m2])/goal] + Norm[{m1, m2}];      where `f` is a vector function and `g` is a scaler function. I want to minimize `g[m1,m2]` with constrains `0.8 <= Min[f[m1,m2]] <= 1.0` and `0 <= m1 <= 2 && 0 <= m2 <=2`. Despite this seems straightforward, a direct implementation is problematic,               counter = 0;     NMinimize[{       g[m1, m2],       And[0.8 <= Min[f[m1, m2]]/goal <= 1.0, 0 <= m1 <= 2, 0 <= m2 <= 2]       }, {m1, m2},       Method -> {"NelderMead", "Tolerance" -> .001},       StepMonitor :> (Print[++counter, ":\t", {m1, m2}])]      If we execute the code, an error message NMinimize::bcons will be shown, which tells us that the constrains are not in the valid format. After a few tests I found out that the the problem is related to the command `Min` used in the first constrain `0.8 <= Min[f[m1, m2]]/goal <= 1.0`. If we do not use `Min` then there will be no problem, i.e., `0.8 <= Evaluate[Norm[f[m1, m2]/goal]] <= 1.0` can be evaluated without any problem. So it seems that `Min` is not valid for using as constrains with `NMizimize` (yet we can use `Norm`, `Plus`, etc.). But this is really inconvenient because I do need to use `Min` as part of the constrains. I wonder if we can fix this problem?


How to change the color of specified digits in a number?

I've been playing with numerical approximations for irrational numbers, and would find it convenient to be able to highlight where these approximations deviate from the known correct answers. For example, it would be nice to be able to output a number that looks like ![not quite Pi](http://i.stack.imgur.com/dBto7.png) where most of the digits have the default Output format, but after a specified number of digits, a different format (bold and red in this example) applies. What would be the most elegant way to accomplish this?


PlotRangeClipping not working correctly with small ImageSize and PDF-export

Although Mathematica has some nice plotting capabilities, there are some things which are annoying me: I like to export a Graphics oder Plot to PDF for use in $\LaTeX$. I like to a have an ImageSize of the PDF file, which corresponds to the image size in my document (e.g. 6 cm). I don't like to scale my image in $\LaTeX$. When exporting to PDF the `PlotRangeClipping` does not work as expected (especially when having a small `ImageSize`):               cm=72/2.54;     p1 = Graphics[{EdgeForm[{Red, Thickness[.1]}], FaceForm[], Disk[]},       Frame -> True,       PlotRange -> {{0, 1}, {0, 1}},       PlotRangeClipping -> True,       ImageSize -> 6 cm]     Export["p1.pdf", p1]          p2 = Graphics[{EdgeForm[{Red, Thickness[.1]}], FaceForm[], Disk[]},       Frame -> True,       PlotRange -> {{0, 1}, {0, 1}},       PlotRangeClipping -> True,       ImageSize -> 26 cm]     Export["p2.pdf", p2]      While the PlotRangeClipping for in the second generated file (p2.pdf) is more or less okay (not perfect), ![p2.pdf magnified](http://i.stack.imgur.com/kvJKA.png) there are serious problems in p1.pdf: ![p1.pdf magnified](http://i.stack.imgur.com/tvn1q.png) Is this a bug? Is there a way to have an acceptable PlotRangePadding with a small ImageSize?


While loop doing cell evaluation not completing

I am trying to get a loop structure using `While` to repeatedly evaluate another cell referred to in its body (using a cell tag).               "this is the while construct";     x = 2;     y = 5;     While[x < y,       NotebookLocate["code"];       FrontEndTokenExecute["EvaluateCells"];       x       y     ]      and this is the cell called "code"               "this cell contains the code i want to run";     x = x + 0.1;     y = y - 0.1;      My code seems to enter an endless loop. What I expected was when the two numbers, x and y, became equal, the loop would stop. What am I doing wrong?


how to make a pie chart using custom image

Can we make a pie chart using a costumed picture? For example, in representing the 0.1 cent, I would like to use this image and cut a piece out, and make a clickable pie chart. Any suggestions are appreciated. ![enter image description here](http://i.stack.imgur.com/8I3B1.jpg)


Finding parameters making real part of eigenvalues vanish

I have the following $\;3\times3$ matrix: $\left( \begin{array}{ccc} 0.04 -0.4 b & 0 & 0.04 -0.4 b \\\ 0 & -0.08-1.2 b & -0.06-0.9 b \\\ 1.04 -0.4 b & 2.08 -0.8 b & 0 \end{array} \right)$ I want to find the $b$ values that make any of the eigenvalues of this matrix is $0$. When I calculate the eigenvalues I get the following: > >     {Root[- 0.00832 - 0.0384 b + 1.264 b^2 - 0.48 b^3 + (0.08 + 2.24 b - 0.4 > b^2) #1 >           + (0.04 + 1.6 b) 2 + 1. #1^3&, 1], >      Root[- 0.00832 - 0.0384 b + 1.264 b^2 - 0.48 b^3 + (0.08 + 2.24 b - 0.4 > b^2) #1 >           + (0.04 + 1.6 b) #1^2 + 1. #1^3&, 2], >      Root[- 0.00832 - 0.0384 b + 1.264 b^2 - 0.48 b^3 + (0.08 + 2.24 b - 0.4 > b^2) #1 >           + (0.04 + 1.6 b) #1^2+1. #1^3&, 3]} >   Now I want to get the $b$ value that makes the real part of any of the eigenvalues $0$ with the following command:               Map[ NSolve[ Re[#] == 0 && b ∈ Reals, b] &, eigs]      _Mathematica_ finds that the real part of the first eigenvalue will never be $0$, hence produces an empty set. However, for the roots $2$ and $3$, it does not evaluate the command. Also, first root is 0 when $b=0.1$ as I can see it in the plot below (red dots). ![Eigenvalues with respect to $b$](http://i.stack.imgur.com/mR71F.png) Is there any way to find $b$ more effectively?


Images as labels of barChart

I'm trying to create a BarChart on which images are the labels of each bar. A Minimal example of what I'm trying to do:               image1 = Import["test1.png"];     image2 = Import["test2.png"];     image3 = Import["test3.png"];     BarChart[{0.4, 0.2, 0.8}, ChartLabels -> {image1, image2, image3}]      The problem is the position of the image on the label. The image is not resized to fit within the Bar width, and so it fills a great part of the plot. Another problem is that the image is not centered: the bottom left corner of it is on the label's expected position, and not the center of it. Any ideas how I can solve this? EDIT: as example of an image, wikipedia's picture of the day:               image1=image2=image3=Import["http://upload.wikimedia.org/wikipedia/commons/thumb/a/a5/Cabiria_1914_poster_restored.jpg/401px-Cabiria_1914_poster_restored.jpg"]      works for the problem in hands. (Thanks J.M. for pointing out)


Conditional T distribution

Suppose $(X,Y)$ has a bivariate t distribution. I want to plot the density of the conditional density of $Y$ given $X$, i.e. $Y|X$. I wonder why the following does not work:               bivT = MultivariateTDistribution[{{1, \[Rho]}, { \[Rho], 1}}, \[Nu]]     bivTCond[x_, y_, \[Nu]_, \[Rho]_]:=          Evaluate@PDF[bivT, {x, y, \[Nu], \[Rho]}] /           Evaluate@PDF[StudentTDistribution[0, 1, \[Nu]], {x, \[Nu]}]     Plot[bivTCond[1, y, 3, 0.5], {y, -3, 3}]      The last command does not produce any plot.


Silence debug output from Parallelize?

I have this script, which does a bunch of image aligning in parallel: https://gist.github.com/8848a25a15da013ed1ad However, on EVERY print, Mathematica also prints from what Kernel the message came and what the kernel's status is, etc. Is there a way to supress these debug messages? Edit: The messages in question are these: https://gist.github.com/e8ae961dc46c66ed809f And example images are available here: http://dl.dropbox.com/u/10190786/done.zip


MySQL Connection Problem

I have a problem with the configuration of the J-Connector plug-in with a MySQL database. Most of the time all works well, but sometimes the connection remains blocked for 2 hours and then it gives this error:               JDBC::error: "Communications link failure\n\nThe last packet successfully      received from the server was 7,200,110 milliseconds ago.  The last packet      sent successfully to the server was 7,200,047 milliseconds ago."      Note: I'm executing the query right after the connection is set, without waiting. It seems that the query is fetching results (with Mathematica running), but instead it remains blocked for 2 hours and then it fails. Edit: I have noticed that the connection is correctly estabilished, then during the execution of the query it magically disappears (I have seen this checking the `SHOW PROCESSLIST` with another connection to database), but the JDBC driver didn't know anything about this and then after 2 hours it gives the error. It looks like it has a 2 hours timeout (7,200,000 milliseconds) which I didn't set, my question is: how can I set it to a more reasonable time (like 1 minute)? So I can catch the error and re-execute the query without waiting for a long time. Or, anyway, do you have any other solution to handle MySQL connection problems?


Alternative to overloading Set

In the ideas shared in my answer to this post Struct equivalent in Mathematica? at the end I propose a solution that changes the way Set works in a particular case that can be expressed in plain words If I see something like x[u][key]=value where u is a symbol then assign value to u[key] (DownValues of u) instead of assigning value as a SubValues of x. The corresponding code               ObjectSet[(_[symbol_Symbol]|symbol_),key_,value_]:=symbol[key]=value;          Unprotect[Set];     Set[symbol_[key_],value_]:=        Block[{$inObjectSet=True},           ObjectSet[symbol,key,value]        ]/;!TrueQ[$inObjectSet];     Protect[Set];      This is needed for what I want to do as Set has a HoldFirst attribute, so I pass the left hand side to a function that will evaluate it. An example after having executed the code above               x[u]["key"]=3     DownValues[u]      Leonid expressed his concerns to this solution of modifying Set in case it becomes widespread. What could be alternatives to this way of doing ?


Does Mathematica implement the fast Fourier transform?

Is there a fast Fourier transform in _Mathematica_? Although looking in the help I could not find one. I am looking to implement the equivalent of `fft` in MATLAB.


Isolating a prefactor in an analytical expression

I have a large mathematica expression that looks roughly like               f = A1 Exp[a1 x] + A2 Exp[a2 x] + b1/x + b2/x^2 + c0 + c1 x + c2 x^2         where all the $A_n,a_n,b_n,c_n$ are symbolic constants.   how can I isolate the prefactor of x ? i.e some function that checks the pattern of $f$ and returns $c_1$ ?


How can I add a logo to a presentation?

I am trying to make a presentation with Mathematica and would like to know if there is a way to add a logo that will show in every slide. I have not found any settings that would allow me to do that automatically and would like to know if there is a straightforward way of implementing this. I tried using a custom template with the logo but this also seemed impossible since custom templates are not possible, to my knowledge, with Mathematica presentations. Any help is appreciated


Suppress negative y-axis in ListLinePlot even if all values are zero?

I have some lists that will always contain non-negative values, sometimes all zeros. Whatever non-negative values appear in the list, I would like the plots to appear without a negative y-axis. I'll use constant arrays instead of real data for the purpose of this message:               ListLinePlot[ConstantArray[0, 640], PlotRange -> {Full, {0, Full}}]      ![zero case](http://i.stack.imgur.com/Xco0U.jpg)               ListLinePlot[ConstantArray[1, 640], PlotRange -> {Full, {0, Full}}]      ![one case](http://i.stack.imgur.com/dS6VW.jpg) Ignore the aspect ratios... Doesn't the `{0, Full}` portion of `PlotRange -> {Full, {0, Full}}]` specify that I don't want to see anything under y == 0? If so, why does the first plot (zeros) produce a negative y-axis and is there any way to suppress it?


How can autocomplete entries be added for DownValues and Properties?

I'd like to assign `DownValues` to a symbol like this               x["firstvalue"] = 1;     x["secondvalue"] = 2;      And then have the `DownValue` keys `"firstvalue"` and `"secondvalue"` offered in an autocomplete list once I have entered `x[`. Another useful application for this kind of modification is to have the `"Properties"` of an object like a `FittedModel` added to the autocomplete list. It is not always easy to remember `"SinglePredictionConfidenceIntervalTableEntries"`, which is one of the 64 properties of `FittedModel`. Can this be done? What controls the entries in the autocomplete "engine"? ### Addendum This amazing answer shows a way of altering the behavior of autocomplete. I do not yet understand how it works.


Vary the thickness of a plotted function

I know, that I can change the color of a function with the help of PlotStyle:               Plot[Sin[x], {x, 0, 3 Pi}, PlotStyle -> {Green, Thickness[0.01]}]      I also know, that I can vary the color in relation to the function value:               Plot[Sin[x], {x, 0, 3 Pi}, PlotStyle -> {Thickness[0.01]},       ColorFunction -> "BlueGreenYellow"]      I wonder if it is possible to change the thickness of a plotted function dependent on the function value, for example the absolute value of the function. For the example above a nice thing would be to have, that the line is e.g. **twice as thick** at the minima and the maxima as it is at the roots.


Replace rule with function? Derivatives don't evaluate

Say I have an expression (call it expr) involving a function, f[x]. I'd like to be able to evaluate that for a particular choice of f[x] without setting that choice for the whole session. I thought to do this using a replacement,               expr /. f[x_]->x^2      (where expr is some expression involving f[x] and I want to set f to x^2), but this doesn't work on derivatives, e.g., if expr contains f'[x] then it will stay as f'[x] rather than become 2x. What's the best solution to this problem?


Import multiple files from folder in order of date added

I have a folder that contains certain files I want to import. In my case those are .png files. As all the files I want to import contain the phrase "accum" in their filenames, I can use               SetDirectory[directory]; (*directory is string of the directory that contains the files*)     importString = "./*" <> "accum" <> "*";     files = Import[importString];      to obtain a list consisting of all the images I wanted to import. Of course this list is sorted by filename. What can I do to tell `Import` that the files should not be sorted by "name" but by other options like "date added" (which is what I want)?


SpaceFillingMolecularPlot using CAS number of a compound

When I tried to get 3D graphics for molecule CAS52364-73-5 using _Mathematica_ 10 it produced following result               ChemicalData["CAS52364-73-5", "SpaceFillingMoleculePlot"]      > >     Missing["NotAvailable"] >   but it makes a plot for caffeine. How can I get for my compound?               ChemicalData["Caffeine", "SpaceFillingMoleculePlot"]      How can I get a plot for my compound?


How to remove repeated permutations?

I want to get the Permutations on the elements of a list. Then I'm doing this:               a = Drop[Permutations[Range[1, 16], 2], {1, 17}]     i = 15;     While[i <= (240 - 16), a = Drop[a, {i, i}]; i = (i + (16 - 1))]      The first line of the code gives me all the permutations, but I do not want repetitions, like: I already have `{1,2}`, I do not want the `{2,1}`. I'm trying to do this way but there's no result yet. Any help?


Minimization by Nelder-Mead

Finding a global minimum for this problem (non-linear optimization by the Nelder-Mead downhill simplex method) may not be possible, but by finding local minimum, I am expecting the value of the function at the minimum is around 1 or (far) less than 1 (the lower the value, the better is the answer). `"Nelder-Mead"` method is available for `NMinimize` in _Mathematica_. The problem I am facing is, even though I am changing the method options for Nelder-Mead (for example, `"ShrinkRatio"`, `"ContractRatio"`, `"ReflectRatio"`, and so on) and also initializing the calculation for different initial values (which is chosen by the `"RandomSeed"`), I am getting minima which are way greater than 1. I found people deal these kind of problems by writing codes either in C++ or Fortran and the results are good, but I know neither of them so I am trying to do it with _Mathematica_ using the built-in functions. Here is the what I am trying (a simplified version of the original problem that I have to deal with which has even more number of parameters):               A = ({{a11, 0},{0, a22}});     B = ({{b11, b13},{b13, b22}});     M1 = A + Exp[I phi] B;     M2 = a A + b Exp[I theta] B;     M3 = a A - 3 b Exp[I theta] B;     m1 = Abs[Eigenvalues[M1]];     m2 = Abs[Eigenvalues[M2]];     m3 = Abs[Eigenvalues[M3]];               t1 = T1[a11_?NumberQ, a22_?NumberQ, b11_?NumberQ, b22_?NumberQ,      b13_?NumberQ, phi_?NumberQ] = m1[[1]];     t2 = T2[a11_?NumberQ, a22_?NumberQ, b11_?NumberQ, b22_?NumberQ,      b13_?NumberQ, phi_?NumberQ] = m1[[2]];          t3 = T3[a11_?NumberQ, a22_?NumberQ, b11_?NumberQ, b22_?NumberQ,      b13_?NumberQ, theta_?NumberQ, a_?NumberQ, b_?NumberQ] = m2[[1]];     t4 = T4[a11_?NumberQ, a22_?NumberQ, b11_?NumberQ, b22_?NumberQ,      b13_?NumberQ, theta_?NumberQ, a_?NumberQ, b_?NumberQ] = m2[[2]];          t5 = T5[a11_?NumberQ, a22_?NumberQ, b11_?NumberQ, b22_?NumberQ,      b13_?NumberQ, theta_?NumberQ, a_?NumberQ, b_?NumberQ] = m3[[1]];     t6 = T6[a11_?NumberQ, a22_?NumberQ, b11_?NumberQ, b22_?NumberQ,      b13_?NumberQ, theta_?NumberQ, a_?NumberQ, b_?NumberQ] = m3[[2]];          O2 = 0.235; O1 = 72;     E2 = 0.031; E1 = 0.87;          O4 = 0.0222196; O3 = 0.958157;     E4 = 0.006198; E3 = 0.018862;          O6 = 0.0941698; O5 = 1.60087;     E6 = 3.6079*^-7; E5 = 0.00026;          function[a11, a22, b11, b22, b13, a, b, phi,theta] =      ((t1 - O1)/E1)^2 + ((t2 - O2)/E2)^2 + ((t3 - O3)/E3)^2 + ((t4 - O4)/E4)^2 +     ((t5 - O5)/E5)^2 + ((t6 - O6)/E6)^2;          Do[Print[NMinimize[     function[a11, a22, b11, b22, b13, a, b, phi, theta],      {a11, a22,b11, b22, b13, a, b, phi, theta},     Method -> {"NelderMead", "ShrinkRatio" -> 0.5,"ContractRatio" -> 0.7,     "ReflectRatio" -> 1, "ExpandRatio" -> 2,"RandomSeed" -> j}]], {j, 5}]      Five random iterations (with different initial conditions chosen randomly) find different minima but all are much greater than the expected result. Here they are:               (* {9081.63     {a11->0.0585825,a22->1.22145,b11->-0.26137,b22->0.327416,b13->-0.158818,     a->-1.2025,b->0.168387,phi->-1.01436,theta->0.698082}}          {32448.8     {a11->-0.542868,a22->0.845826,b11->1.10494,b22->0.739838,b13->-0.16513,     a->0.795721,b->0.346771,phi->-0.369352,theta->-0.077746}}          {7122.85     {a11->0.0846693,a22->-0.643122,b11->-0.0834931,b22->-1.14742,b13->-0.37268,     a->1.36398,b->-0.208855,phi->-0.367912,theta->-0.359771}}          {14919     {a11->-0.14745,a22->-0.0507363,b11->0.414601,b22->0.306933,b13->0.420321,     a->0.364225,b->0.663577,phi->-0.625049,theta->-0.33245}}          {13582.6     {a11->-0.182997,a22->0.431253,b11->0.201061,b22->0.507661,b13->0.258584,     a->-0.471931,b->0.741867,phi->-0.5953,theta->-0.0911202}} *)      I tried with different combinations of the Nelder-Mead options with no improvements. The default value of the `MaxIterations` is 100, and I also tried by increasing the number of iterations by using the package of Nelder- Mead from the excellent post Shaving the last 50 ms off NMinimize by Oleksandr R., but again did not get any improvement. Can anyone help me with what I am missing?


rule-based implementation of an algorithm

When I first started learning about rule-based programming with _Mathematica_ , I tried to translate this algorithm for computing the convex hull of a set of 2-D points in $O(n \log(n))$ time, to use rule-based replacement. For convenience, I'll paste the pseudocode of the algorithm below: > Input: a list P of points in the plane. > >   * Sort the points of P by x-coordinate (in case of a tie, sort by > y-coordinate). > >   * Initialize U and L as empty lists. The lists will hold the vertices of > upper and lower hulls respectively. > >   * for i = 1, 2, ..., n: > > while L contains at least two points and the sequence of last two points of > L and the point P[i] does not make a counter-clockwise turn:   >  remove the last point from L   >  append P[i] to L > >   * for i = n, n-1, ..., 1: > > while U contains at least two points and the sequence of last two points of > U and the point P[i] does not make a counter-clockwise turn:   >  remove the last point from U   >  append P[i] to U > >   * Remove the last point of each list (it's the same as the first point of > the other list). > >   * Concatenate L and U to obtain the convex hull of P. Points in the result > will be listed in counter-clockwise order. > (Actually, I used a version of this algorithm from the book "Computational Geometry" by de Berg & others, but it's pretty much the same thing except for the "counter-clockwise turn condition" that uses determinant instead of cross- product, which isn't really relevant to this question.) This was my implementation, which has the same end result as the stated algorithm, but as you can see doesn't operate quite the same way:               convexHullPM[pts_] := Module[{li, isRightTurn},        isRightTurn[p1_, p2_, p3_] :=           Sign[Det@MapThread[Prepend, {{p1, p2, p3}, {1, 1, 1}}]] == -1;       li = Sort[pts];       li = Join[li, Reverse@Most@li];       li //. {pre___, a_List, b_List, c_List, post___} :>              {pre, a, c, post} /; Not[isRightTurn[a, b, c]]]      It works, giving the same sequence of points as _Mathematica's_ own `ConvexHull` function from the Computational Geometry Package. However it's slow (referring to its time complexity, as the input size increases); timings with increasingly larger sets of input points seem to indicate $O(n^2)$ complexity, which seems about right - because the way I constructed the rule in _Mathematica_ , it starts matching from the start every time a replacement is made. Whereas the listed algorithm has the notion of a current point, and points are removed from the set (if need be) from the most recent points. So what would be a better rule-based implementation?


using array elements in minimization

I have switched from mupad to _Mathematica_ , however the syntax is completely different here. I want to               Minimize [{Sum[(y[[i]]-3)^2,{i,1,c}], Sum[y[[i]],{i,1,c}]==10},y[[i]]]      for parameter `c`. _Mathematica_ shows me > Part::pspec: Part specification i is neither a machine-sized integer nor a > list of machine-sized integers. Would you please help me


Solve and plot an equation that is dependent on a transcendental equation

I am trying to plot a function that uses the values of a transcendental equation as its input values:               y = Tanh[(2 y + x)/2.5]     z = 2.5 * Log[2*Cosh[(2 y + x)/2.5]]      for $x = [-1.5, 1.5]$. I am a relative newbie to _Mathematica_ , so I am at a complete loss as to how to go about this. I have successfully plotted the transcendental equation itself using `ContourPlot`, and mathematically I know what to do - but I can't for the life of it figure out how to make _Mathematica_ solve these two equations and plot the result. I find the _Mathematica_ notation to be somewhat cryptic, but I really love the results, so I want to get good at it. Can somebody help?


Welcome screen (V9): selecting notebook from Open Recent ... results in initialization cells not evaluating

The following represents an abbreviated example of more complicated code, but it replicates a problem the more complicated code encounters.               f[x_, y_] := Module[{o1, o2},       o1 = 2 x;       o2 = 3 y;       Column[{o1, Button["Save data to file", w = Print[o2], Method -> "Queued"]}, Frame -> True]]          z = "";     Grid[{{"input1", InputField[Dynamic[x]]},{"input2", InputField[Dynamic[y]]},{"A button", Button["Evaluate", z = f[x, y], Method -> "Queued"]}},Frame -> True]          Dynamic[z]      I put this code in an `InitializationCell`. When I launch the notebook containing this initialized cell either directly by clicking on the notebook's icon or by selecting it from Mathematica's `File >> Open`... menu, the notebook runs the code on startup as one would expect: ![enter image description here](http://i.stack.imgur.com/CavZG.png) BUT.... When using OS X, Mathematica 9, by default launches a "Welcome to Wolfram Mathematica 9" display. ![enter image description here](http://i.stack.imgur.com/jL2d9.png) If I select the same notebook from the above (by clicking on the correct "Open recent ...." selections) the `InitializationCell` fails to run when the notebook opens. What gives? I can certainly choose not to launch anything from this apparently problematic Welcome screen, but this presents a larger problem if one needs to deploy a Mathematica application to some end user over whom's environment one doesn't have complete control. This kind of inconsistency does not help an end user's confidence in the platform. Can anyone explain why this happens? Does this Welcome screen point to a cached version of the notebook for which it thinks the initialization cells have already run? But remember that this only happens when launching Mma. Can one set anything in a notebook or in the Options Inspector to stop this from happening?


How to use Assuming and If together?

I would like to compare variables `t` and `u` and print either `Yes` or `No` depending one which is larger. My code is simply the following:               Assuming[t < u, If[t - u < 0, Print[Yes], Print[No]]]      Since `t < u` is assumed, `t - u < 0` holds. So I should get `Yes`. But what I get is a repetition of `If` term. That is,               If[t - u < 0, Print[Yes], Print[No]]      Am I missing something?


Plotting a large number of data points

I would like to know how to plot when I have a large number of points (arround 600) in a specific format:               X          Y     1.000E-03 1.251E+01      1.500E-03 1.201E+01      2.000E-03 1.144E+01      2.484E-03 1.088E+01      2.484E-03 1.088E+01      2.534E-03 1.082E+01      2.586E-03 1.076E+01      2.586E-03 1.076E+01      3.000E-03 1.027E+01      3.066E-03 1.019E+01      3.066E-03 1.019E+01       All I need is to draw a line trought those points, but it would be anoying to write points in format `(x1,y1), (x2,y2), ...`. It would be tedious if I had to insert the commas and braces by hand for every pair of points coordinates. I'm totaly new in _Mathematica_ and I would appreciate help.


How to output local variables when error message is generated without interrupting evaluation?

I am running a calculation to generate a dataset. I use several iterations to sweep over a parameter space. A few times an error message is generated (which is not the problem per se). Is it possible to output the value of the iterative variables (or other local variables) for each generation of an error message, without interrupting the evaluation, in order for me to check what is going wrong? I tried (without success)something like this:               messageHandler = If[Last[#], Print[i]] &;     Internal`AddHandler["Message", messageHandler];      for a code that could be something like:               For[i=1,i<=imax,i++,      (*code*)        ]      My code is of course much more complex so that I do not want to use Trace, that outputs a huge amount of data that I cannot read. I tried the debugger in the WorkBench but it seemed like I could not access the local variables after a message interruption. Anyone has a simple Idea?


How do I plot a histogram with hatched shading?

I can plot an ordinary histogram with blue shading and black borders like this:               T = RandomVariate[NormalDistribution[0, 1], 10000];     Histogram[T, 30]      And I can simulate hatching like this:               T = RandomVariate[NormalDistribution[0, 1], 10000];     Histogram[T, 30, ChartElements -> Graphics[{Black, Line[{{0, 0}, {1, 1}}]}]]      How can I get the hatching and the black borders at the same time?


How can I run MUnit tests outside of Workbench under Linux?

I would like to run MUnit tests from the command line. On Mac OS, I can do this:               AppendTo[$Path, "/Applications/Wolfram Workbench.app/configuration/org.eclipse.osgi/bundles/13/1/.cp/MathematicaSourceVersioned/Head"];          << MUnit`      and then use the MUnit functions such as TestRun to run the tests. However, on Linux, the MUnit package is stored within a jar file (com.wolfram.eclipse.testing_2.0.126.jar), rather than being "bare" in the filesystem. Workbench must be able to load the package; is it possible to load MUnit from the jar file? One solution would be to extract MUnit into a temporary directory each time you wanted to load it, but this is quite ugly.


List manipulation - End loop

Given are two matrices (a & b). I want to end the For-loop if **all** values in the matrix (a minus b) are smaller than 7, in contrast to **any** value in the matrix (a minus b) is smaller than 7. Can anybody help me with this problem?               For[Q = 0, Q <= 20, Q += 1,       Print[Q];       Print[a = {{40, 40, 40}, {40, 40, 40}, {40, 40, 40}}];       Print[b = Q {{4, 4, 4}, {4, 3, 4}, {4, 4, 4}}];             compare[matrix_, length_, width_, value_] :=         Module[{state}, state = False; For[i = 1, i <= length, i++,           For[j = 1, j <= width, j++,            If[matrix[[i, j]] < value, state = True]]]; Return[state]];            If[compare[a - b, 3, 3, 7], Break[],]];


Implementation of a recurrence relation for the polynomials appearing in the large order asymptotics of the Bessel functions

I would like to implement the recurrence relation for the polynomials $U_n(x)$ appearing in the large order asymptotics of the Bessel functions. The recurrence in question is $$U_{n+1}(x)=\frac{1}{2}x^2(1-x^2)U_n^{\prime}(x)+\frac{1}{8}\int_{0} ^x(1-5t^2)U_n(t)dt,$$ with $U_0(x)=1$. I saw implementations for recursions for polynomials, but this one involves integration and differentiation. Any idea? Thank you very much in advance!


`Slot` (#) interfering with evaluation

In the following I am using one function `makeFunc` to assemble two functions `a[t]` and `b[t]` to pass to use in the formation of a `Table`. `makeFunc` appears to be doing its job appropriately because the error messages and `Trace` show that it has assembled `a[t]` and that the `Table` construct has evaluated the `t` portion of the function. However, `a[t]` is not evaluating itself and so the `Table` appears as `a[0]`, `a[30]`, etc.               tempMakeTableAn[{analEqs_, concs_, initConcs_, rateConstants_,          timeDom_, timeInc_}] :=       Module[{a, b},        a[t_] :=          aZero Exp[-k1 t] /. Evaluate[Join[initConcs, rateConstants]];        b[t_] :=          bZero + 1 - aZero a[t] /. Evaluate[Join[initConcs, rateConstants]];             makeFunc[conc_, time_] := Evaluate[conc[time]];             Column[{Table[{a[t], b[t]}, {t, 0, 300, 30}],          Table[makeFunc[#, timeDom[[1]]] & /@ concs, {t, 0, 300, 30}]}]         ];          tempMakeTableAn[{{Hold[a[t_] := aZero Exp[-k1 t],          b[t_] := bZero + 1 - aZero a[t]]}, {a, b}, {aZero -> 1,         bZero -> 0}, {k1 -> .01}, {t, 0, 300}, {30}}]      > { {{{1, 0}, {0.740818, 0.259182}, {0.548812, 0.451188}, {0.40657, 0.59343}, > {0.301194, 0.698806}, {0.22313, 0.77687}, {0.165299, 0.834701}, {0.122456, > 0.877544}, {0.090718, 0.909282}, {0.0672055, 0.932794}, {0.0497871, > 0.950213}}}, > > {{{a[0], b[0]}, {a[30], b[30]}, {a[60], b[60]}, {a[90], b[90]}, {a[120], > b[120]}, {a[150], b[150]}, {a[180], b[180]}, {a[210], b[210]}, {a[240], > b[240]}, {a[270], b[270]}, {a[300], b[300]}}} } This appears to have something to do with the way that I am utilizing the `Slot` (#) as you can see that when I entered in `a[t]` and `b[t]` directly, the `Table` works. I _think_ that this may have to do with scoping of the variables, because if I remove `a` and `b` as declared variables in the `Module`, everything works as expected. I.e. `a` and `b` get defined globally and the expected `Table` appears. I have also tried some judiciously placed `Evaluate` statements to see if that is what was needed, but that didn't make any changes. I have found a couple of questions that I thought might be applicable (Using pure functions in Table,Evaluate[] seems to not work inside Button[]), but since the construct works when the variables are declared globally, I don't understand why it doesn't work when they are declared within the module. Any help would be appreciated. [If somebody can come up with a better Title, have at it. This was the best that I could figure out].


Hardware Performance Metrics for Mathematica

Dear Mathematica users I am looking into buying a new computer and Mathematica is one of the main applications I run. To help me assess the overwhelming welter of choice out there:   1. I'd like to know whether there are any system performance metrics, along the lines of those measured by Geekbench http://browser.primatelabs.com/processor-benchmarks, defined specifically for working with Mathematica, and whether there are any tables on the web comparing currently sold machines.    2. It would also be very helpful if these metrics came with detailed descriptions of what they mean. I haven't been able to find a clear definition of what Geekbench numbers mean - e.g. does a measurement of 2000 mean a machine that runs roughly twice as fast as one measuring 1000 and what exactly was it doing when it was running. Many thanks in advance


How secure is J/Link?

Are there security concerns with using J/Link? If so, is there any way to encrypt the data passed between Mathematica and Java? If Mathematica and the JVM are running on the same machine, is there any reason to worry about this?


Bincounting a list

I'm a Mathematica novice here. I'm trying to execute the following code to add random 1's into a zero matrix, repeat this many times, and then bin/histogram the number of nearest neighbor 1s. Can anyone help me out with what I need to do to transform my list so that bincounts will play nicely?               ClearAll["Global`*"];      (*clear global variables*)     n = 10;       (*set number of diluent elements*)     Do[         b = SparseArray[{1, 1} -> 0, {100, 1},0];          (*generate zero matrix*)         a = RandomSample[Range[100],  n];          (*select random sites to add elements *)         Do[b[[a[[i]]]] = 1, {i, n}];          (*insert elements*)         e[i] = b;      ,         (*generate iterated variable to record each run*)          {i,50}     ];      (*loop i times*)     f = Table[e[i], {i,1,50}];     (*generate list from iterated variable*)     Do[g[j, i] = f[[j, i]] + f[[j, i + 1]], {j, 50}, {i, 99}];     (*sum nearest neighbors and loop over data set*)     h = Table[g[j, i], {i, 1, 99}, {j, 1, 50}] ;      (*create an indexed list variable*)     BinCounts[h, {0, 3, 1}]      Where Bincounts returns the error: "BinCounts::vectmat: The first argument is expected to be a vector or matrix"


ArrayPlot: space between displayed data and frame

When I execute the lines               data1 = Table[i + j, {i, 10}, {j, 1}];     data10 = Table[i + j, {i, 10}, {j, 10}];     opts = {ImageSize -> {Automatic, 300}, BaseStyle -> {FontSize -> 14}, ImagePadding -> 25};     bothPlots = Row[{ArrayPlot[data1, opts], ArrayPlot[data10, opts]}]      I get the following picture: ![enter image description here](http://i.stack.imgur.com/xq2At.png) The space between plot data and frame of the 1x10 array is much smaller than the space between the plot data and frame of the 10x10 matrix. Is there a possibility to avoide that or to set that space manually?


Retrieving PlotRange form BarChart

Consider the following data:               data1={73.9377, 54.4122, 53.0826, 24.1936};     data2={76.828, 49.1673, 45.7883, 18.9015};      I defined my own BarChart as follows:               MyBarCharts[list_]:=       BarChart[        list,        Frame -> {{True, None}, {True, None}}      ]      When applying MyBarCharts to `data1` and `data2` I get (not really surprising) two different (with regard to the coordinate system) plots. Now I would like to have for both plots the exact same coordinate system. I know that with `Histogram` it works as follows:               Histogram[     data2,     PlotRange -> Part[PlotRange /. Options[Histogram[                                            data1,                                            PlotRange -> Automatic                                            ],PlotRange], 2],     Frame -> {{True, None}, {True, None}}]      But the implementation of that approach in MyBarChart does not give the desired result. Has anyone an idea?


Symbolic solution of irrational equation

Is there any a nice looking solution to the following equation?               eq[x_] := 2 x q1 - 2 q2/x^3 - (4 x^3 q3 - 4 q5/x^5)/(4 Sqrt[x^4 q3 + q4 + q5/x^4])      Better than the one _Mathematica_ gives as output?                Solve[ eq[x] == 0, x]


Issue in ParallelTable after evaluating another function using NDSolve and FindRoot. What is wrong with this inverse?

I am trying to find the inverse of a function which is defined through `NDSolve` and `NIntegrate`. The question is pretty similar to How to invert an integral equation. Just that in my case $g_1(x)=1$ and $g_2(x)$ is the solution of an NDSolve. Following the first answer http://mathematica.stackexchange.com/a/4604/6138, I tried to implement this using `NDSolve` and `FindRoot`, but I get an error message and I don't understand where it comes from. The bug appears in the fact that if I don't evaluate the inverse function, there is no problem with ParallelTable or Table. After evaluating the inverse function, ParallelTable (but not Table) shows me the same error message. I would also like to know why FindRoot doesn't work in this case. Below is my minimal working code and some comments:               Needs["NumericalCalculus`"]     kvalues = {0.01,0.1,0.5,1.0,2.0};     tini = -Log[100];      tfin = 0;     timeGrid = Range[tini,tfin,(tfin-tini)/10];     fSpace[min_, max_, steps_, f_: Log] :=       InverseFunction[f] /@ Range[f @ min, f @ max, (f @ max - f @ min)/(steps -1)]     kin = 0.00072427;     kfin = 2.159;     klogGrid = fSpace[kin, kfin, 10];          funcA =        NDSolveValue[{         D[f[t, k], t] + f[t, k]^2 + (1 - t)*f[t, k] == 3/2*(1 + k^2),          f[tini, k] == 1},          f, {t, tini, tfin}, {k, kin, kfin}]          funcB[t_?NumericQ, k_] :=        funcB[t, k] = Exp[NIntegrate[funcA[et,k], {et, tini,t}]]          funcD[td_, kd_] := ND[Log[funcB[tt, kd]], tt, td]      Now a simple evaluation with `ParallelTable`:               BTable = ParallelTable[{{tt, kk}, funcB[tt, kk]}, {tt, timeGrid}, {kk,     klogGrid}]      The output is (shortened): > {{{-Log[100], 0.00072427}, 1.}, {{-Log[100], 0.00176173}, 1.}, {{-Log[100], > 0.00428528}, 1.}, {{-Log[100], 0.0104236}, 1.}, {{-Log[100], 0.0253546}, > 1.}, {{-Log[100], 0.0616732}, 1.}, {{-Log[100], 0.150015}, 1.}, {{-Log[100], > 0.3649}, 1.}, {{-Log[100], 0.887592}, 1.}, {{-Log[100], 2.159}, 1.}... Now if I try:               inverseN = FindRoot[funcD[tt, kk] == funcA[tt, kk], {tt, -1}]      I get: > NIntegrate::inumr: The integrand > InterpolatingFunction[{{-4.60517,0.},{0.00072427,2.159}},{4,5,1,{54,25},{4,5},0,0,0,0,Automatic,{},{},False},{<<1>>},{Developer`PackedArrayForm,{<<1>>},{1.,-5.10517,1.,-5.09284,1.,-5.05626,1.,-4.99541,1.,-4.9103,1.,-4.80093,1.,-4.6673,1.,-4.5094,1.,-4.32725,1.,-4.12083,1.,-3.89015,1.,<<5>>,1.,-2.72483,1.,-2.37285,1.,-1.99661,1.,-1.5961,1.,-1.17133,1.,-0.722307,1.,-0.249018,1.,0.248533,1.,0.770344,1.,1.31642,1.,1.88675,<<2650>>}},{Automatic,Automatic}][<<1>>] > has evaluated to non-numerical values for all sampling points in the region > with boundaries {{-Log[100],-4.60186}}. >> The same thing happens if I use the inverse function method suggested in the _Mathematica_ documentation of `FindRoot`:               inv[f_, s_] := Function[{t}, s /. FindRoot[f - t, {s, -2}]]     fInverse = inv[funcB[tt, kk], tt]      Now the bug: If I know evaluate again ParallelTable, I get the same above error message:               BTable = ParallelTable[{{tt, kk}, funcB[tt, kk]}, {tt, timeGrid}, {kk,     klogGrid}]      ... > NIntegrate::inumr: The integrand > InterpolatingFunction[{{-4.60517,0.},{0.00072427,2.159}},....Automatic}][<<1>>] > has evaluated to non-numerical values for all sampling points in the region > with boundaries {{-Log[100],-4.60186}}. >> But after the error messages I get the correct output from above. Nevertheless, with `Table` nothing bad happens:               Table[{{tt, kk}, funcB[tt, kk]}, {tt, timeGrid}, {kk, klogGrid}]      > {{{{-Log[100], 0.00072427}, 1.}, {{-Log[100], 0.00176173}, 1.}, {{-Log[100], > 0.00428528}, 1.}, {{-Log[100], 0.0104236}, 1.}, {{-Log[100], 0.0253546}, > 1.}, {{-Log[100], 0.0616732}, 1.},.... I hope you can reproduce this bug and by the way help me with finding the inverse function. I tried this in _Mathematica_ 10.0 and 9.0


Travel time sweet spot using: Mathematica and Google Maps API

I want to use _Mathematica_ to do some time minimisation calculations calling on Google Maps API for travel time data. I'm concerned with travel time, e.g. along roads (by car or walk) and **not** linear distances. I have a list of points (lets call them `Pf0, ..., Pfn`), (It could be either post codes, lat long, British National Grid, etc., however the data comes in). I want to take these points and, with some kind of iterative computation, workout where the 'optimum' point (lets call it `Px`) is at to get to minimise travel time to all these points. I'm assuming that I am equally likely to go to any of the points, so I cannot know in advance. But from a point (to be determined) I could go to any of these other fixed points (`Pf0, ..., Pfn`). I imagine I could chose a random seed, somewhere in the polygon described by the fixed points, calculate the total travel time from that point to each fixed point, then vary the point around and see if the time goes up or down. Then iterate until the I have found a minimum. Question 1: How do I ensure that the point is not a local minimum? A more intelligent method might be to vary the seed point along various linear features, this would reduce the total number of possible points, and reflect more realistic tests, since in real life I would probably be on a road. Again the local minima haunts me!   1. Can anyone thing of a better scheme?   2. Can anyone give me a start about how the code would have to work? I'm quite happy with querying the google maps api, as described in previous excellent q/a I need help with making that process iterative. My test data is a load of Mtb trail parks in South Scotland -- the result of the analysis would be the best place to stay if I was thinking of being there a while ;)               trailCentersCodes =        {"DG11QB", "DG54QU", "DG34AQ", "PH336SW", "EH458NB", "DG87BE", "TD90QD", "IV108", "DG28HB"}


How to extract structured array data from DefineDLLFunction in Mathematica

I want to use my Bluechip PCI-ADC acquisition card in Mathematica via his dynamic link library “Bcdll32.dll”; (used to access functions on my PCI data acquisition cards). My problem is the function “BCTGetBoardId” that will open a Board by providing a board type (integer 19 to my card) and a board number (integer 0 to my card). By considering VB.Net programming language, the BCTGetBoardId function is defined as:               Public Declare Function BCTGetBoardId Lib "BCDLL32.DLL"            (ByRef pBoardID As BCT_BOARD_ID, ByVal nDevType As Short, ByVal nBoard As Short) As Integer      where the variable pBoardID is a BCT_BOARD_ID type; in VB.Net this type is defined as:               <StructLayout(LayoutKind.Sequential)> _         Public Structure BCT_BOARD_ID                  Dim Handle As Integer             Dim SerialNo As Integer             <MarshalAs(UnmanagedType.ByValArray, SizeConst:=30, ArraySubType:=UnmanagedType.AsAny)> _             Dim DevName() As Byte             <MarshalAs(UnmanagedType.ByValArray, SizeConst:=30, ArraySubType:=UnmanagedType.AsAny)> _             Dim Clock0Name() As Byte             <MarshalAs(UnmanagedType.ByValArray, SizeConst:=30, ArraySubType:=UnmanagedType.AsAny)> _             Dim Clock1Name() As Byte             <MarshalAs(UnmanagedType.ByValArray, SizeConst:=30, ArraySubType:=UnmanagedType.AsAny)> _             Dim Clock2Name() As Byte             Dim hClock0 As BCT_HANDLE             Dim hClock1 As BCT_HANDLE             Dim hClock2 As BCT_HANDLE             Dim Index As Integer             Dim DeviceType As Integer         End Structure      According the “BLUECHIP.vb” file that allows access to DLL library functions IN VB.Net programs, in the case of the BCT_BOARD_ID structure described above, ” In VB.NET, we cannot declare a dimensioned array from within the structure. Instead, we use the 'MarshalAs Attribute' class to handle each array data.” To obtain the data contained in pBoardID variable and by using the help offered by (How can multiple null terminated strings be handled in a DLL-function result?) I used a Mathematica program as follows:               Needs["NETLink`"]     path="c:\\WINDOWS\\system32\\Bcdll32.dll"; (*my Bcdll32.dll  path*)     codgbi=DefineDLLFunction["BCTGetBoardId",path,"short",{"IntPtr","System.Int16","System.Byte"}];     $maxBufLen=1000;          LoadNETType["System.Runtime.InteropServices.Marshal"];          buf=Marshal`AllocHGlobal[$maxBufLen];           codergbi=codgbi[buf,19,0]          managedArray=NETNew["System.Byte[]",$maxBufLen];          Marshal`Copy[buf,managedArray,0,$maxBufLen];          bytes=NETObjectToExpression[managedArray];          FromCharacterCode[DeleteCases[SplitBy[bytes, # != 0 &], {0 ..}]]      I obtained the following confuse answer: > Out[18] 0 (*the value codergbi=0 indicate a correct function syntax *) > > Out[22] {"à.02", "D0.10", "\\\\.\PCIADC0_0000", > \"4B-B1DA-6F7CA\\\\.\PCIADC0_5400", "\\\\.\PCIADC0_5401", > \"\\\\.\PCIADC0_5402", "+", "Realtek PCIe GBE Family Controller - \Packet > Scheduler Miniport", ".06", ".08`no.b4", ".02", ".06", \"", "192.168.1.120", > "255.255.255.0", ".02", "192.168.1.1", \"0.0.0.0", "192.168.1.1", "0.0.0.0", > "0.0.0.0", "0.0.0.0", "0.0.0.0", \"ÞÂR^ÝÃR"} It is clear that I am not mastered the subtleties of programming in NET. Framework. Please, any help to extract in Mathematica all the correct form of the data contained in the structure “buf” from the function codgbi[buf,19,0]! * * * First of all, many thanks Alexey Popkov for your sugestion “calling a dll- function that returns a structure and many, many thanks Todd Gayley, for the superb examples presented in the same MathGroups thread above. Please ignore the last line of my first code, which splits up the bytes of the structure; this was a stupid trial inspired by “How can multiple null terminated strings be handled in a DLL-function result?” and bad adapted by me. To understand how to solve my problem I rebuilt and corrected some small errors (sign == bad placed due to the publisher of the site), the didactic examples offered by Todd Gayley . My second problem is that I deal with a nested structure: the BCT_BOARD_ID structure presented above use the BCT_HANDLE structure and the last use OVERLAPPED structure as follows:                  Structure OVERLAPPED         Dim Internal As Integer         Dim InternalHigh As Integer         Dim Offset As Integer         Dim OffsetHigh As Integer         Dim hEvent As Integer     End Structure                Public Structure BCT_HANDLE         Dim Handle As Integer         Dim Overlap As OVERLAPPED         Dim DeviceType As Integer         Dim BoardType As Integer         Dim nPort As Short         Dim LastError As Integer         Dim NextTime As Integer     End Structure      After analyzing the material on nested structures (pinvoke.net and others) I suggested the following DefineDLLFunction:               path = "c:\\WINDOWS\\system32\\Bcdll32.dll";          bctboardid = DefineDLLFunction[     "           public struct OVERLAPPED        {                public System.Int16 Internal;           public System.Int16 InternalHigh;             public System.Int16 Offset;             public System.Int16 OffsetHigh;             public System.Int16 hEvent;       }                 Public struct BCT_HANDLE            {            public System.Int16 Handle;            public OVERLAPPED Overlap;             public System.Int16 DeviceType;            public System.Int16 BoardType;            public System.Byte nPort;            public System.Int16 LastError;            public System.Int16 NextTime;       }                      [StructLayout(LayoutKind.Sequential)]                 public struct BCT_BOARD_ID            {                    public System.Int16 Handle;                    public System.Int16 SerialNo;                 [MarshalAs(UnmanagedType.ByValArray, SizeConst=30, ArraySubType=UnmanagedType.AsAny)]                    public System.Byte DevName();                 [MarshalAs(UnmanagedType.ByValArray, SizeConst=30, ArraySubType=UnmanagedType.AsAny)]                    public System.Byte Clock0Name();                  [MarshalAs(UnmanagedType.ByValArray, SizeConst=30, ArraySubType=UnmanagedType.AsAny)]                    public System.Byte Clock1Name();                  [MarshalAs(UnmanagedType.ByValArray, SizeConst=30, ArraySubType=UnmanagedType.AsAny)]                    public System.Byte Clock2Name();                    public BCT_HANDLE hClock0;                    public BCT_HANDLE hClock1;                    public BCT_HANDLE hClock2;                    public System.Int16 Index;                    public System.Int16 DeviceType;       }            [return: MarshalAs(UnmanagedType.Byte)]            [DllImport(path, CallingConvention = CallingConvention.StdCall,CharSet = CharSet.Auto, SetLastError = true)]                     public static extern short        BCTGetBoardId([In, Out] BCT_BOARD_ID pBoardId,System.Int16 nDevType,System.Int16 nBoard );"]      Unfortunately I received the message: > DefineDLLFunction::compileerr: "The compiler reported errors in your DLL > function declaration: "Invalid token 'struct' in class, struct, or interface > member declaration ". Please, help me identify the error!


Can I evaluated a cell in a notebook in a background process?

I currently run my _Mathematica_ on a linux computer through Putty and Xming. Xming provides a graphical display for _Mathematica_ windows running on a remote linux computer. But recently, the network has become quite unstable. A disadvantage of using Xming is the graphical display will disappear immediately as soon as the network goes down. When the graphical display disappears, all the evaluation that is running stops and is lost. **So I wonder if there is a way to control to make notebook cell evaluations run in the background when I use the graphical display to run _Mathematica_ remotely.** I expect that code running in the background will not be affected by the shutdown of the graphical display.


Zooming into animated plot

Let's say I have the following animation:               Animate[ParametricPlot[{Cos[a t], Sin[a t]}, {t, 0, 1}], {a, 0,        2Pi}, AnimationRate -> 0.1]      Is there a way to somehow zoom into the moving point of the animated plot at a preselected xy-coordinate or time; such as being able to zoom into the animated moving point after 3 seconds or when the moving point reaches {x,y}={-1,0}? Any help would be appreciated.


DSolve cannot solve for certain branches of the solution

Could somebody please tell me, why I am always getting an error message when trying to run the following code:               DSolve[y'[x] == c*(d - y[x]) - b*(d - y[x])*y[x] && y[0] == y0, y, x]      The error message:               DSolve::bvfail: For some branches of the general solution, unable to solve the     conditions.


Symbolically solve a system of coupled second order differential equations

I have posted a similar question in another forum where the general consensus seems to suggest that it is not possible to symbolic solve a system of coupled second order differential equations with damping (dissipation) and driving forces. However, I have found in many papers and books writing out analytical formula of the solutions to such coupled equations. So, it must be possible. I just do not know how. Attached is the system I am trying to solve. Although solving this sort of equation with two masses, no damping (dissipation) and with only one driving force is simple enough, even by hand, it is impossible to do the same for a system with two different damping constants and two driving forces. I have been trying for two weeks now, but could not figure out the solution. Of course, I could get the numeric solution, but I could not get the same result obtained from Eq. 5. So, I was wondering if someone could help me how to solve this analytically. Any solution to this problem would be of interest. I am completely new to _Mathematica_ , so any example worksheets on this sort of equation would be gratefully appreciated! ![Coupled second order diff eqn](http://i.stack.imgur.com/y91t6.jpg)


Pass Options to Export[]

I'm working with Options to change the look and feel of some generated Graphics by passing Options to several functions, one of them being `Export[]`. For example:               Options[myPlot] := {Resolution -> 325, Size -> 12, FileName -> "A",        PlotStyle -> Automatic};          myPlot[f_, opts : OptionsPattern[myPlot]] := Block[{fig},     (* ... some calculations here *)     fig = Plot[f[x], {x, -\[Pi], \[Pi]},          Evaluate[FilterRules[{opts}, Options[Plot]]]];     fig = Show[fig, ImageSize -> OptionValue[Size]*72/2.54];+     Export[OptionValue[FileName] <> ".png", fig,  FilterRules[{opts}, Options[Export]]];     Print[fig];     ]      And using `f[x_] := x^2` use the function as                myPlot[f, Resolution -> 120, PlotStyle -> Red]      The Option to plot the function in `Red` is passed correctly to `Plot` but `Resolution` is not passed to `Export`. This is of course due to the fact that `Options[Export] = {}`. My question is: _How can I still pass Options to`Export` (i.e. how to determine, which are available, if they are not written in `Options[Export]`?_ And closely related: _How to do that on your own, i.e. now I defined`PlotStyle` to be an Option of `myPlot`, though it's only passed on, how can I pass Options, that I haven't given myself, without getting the message_ > OptionValue::nodef: "Unknown option PlotStyle for ...


Two questions about drawing tool

In _Mathematica_ , Ctrl+1 inserts a new picture. Using the drawing tool, we can draw many things. It seems to me that there is no way to control the drawing angle. So here are my questions:   1. How to draw a regular polygon quickly and accurately? (e.g. a hexagon)   2. How to draw a straight line with an accurate angle relative to the horizontal line? Or rotate an existing horizontal line for an angle (e.g. 60 degrees)?


Plotting a complicated vector field

If we consider the vector $\left ( A \cdot \nabla \right) \: B$, we have in Cartesian coordinates $$\left ( A \cdot \nabla \right) \: B = \left ( A \cdot \nabla B_x \right ) e_x + \left ( A \cdot \nabla B_y \right ) e_y + \left ( A \cdot \nabla B_z \right ) e_z,$$ which gives in full writing: $$\left ( A \cdot \nabla \right) \: B = \left (A_x \frac{\partial \: B_x}{\partial \: x} + A_y \frac{\partial \: B_x}{\partial \: y} + A_z \frac{\partial \: B_x}{\partial \: z} \right )e_x + \left (A_x \frac{\partial \: B_y}{\partial \: x} + A_y \frac{\partial \: B_y}{\partial \: y} + A_z \frac{\partial \: B_y}{\partial \: z} \right )e_y + \left (A_x \frac{\partial \: B_z}{\partial \: x} + A_y \frac{\partial \: B_z}{\partial \: y} + A_z \frac{\partial \: B_z}{\partial \: z} \right )e_z$$ Now, say $B=A$ and $A=\left (10 \: x, \: 20 \, y^3, \: 30 \:z \right )$. I would like to plot the field of $A$ and of $\left ( A \cdot \nabla \right) \: A$ in Mathematica. How to go about? (My objective in this exercise is to know which direction the vector $\left ( A \cdot \nabla \right) \: A$ lies with respect to $A$ and also test for different vectors $A$ when the lines of $\left ( A \cdot \nabla \right) \: A$ are straight or are curved.) Thanks a lot...


How Do I Plot A Binomial to the Right of the Origin?

I'm having a seven element binomial distribution: BinomialDistribution[7, 0.5], x],{x, 0, 8}] I would like to locate to any arbitrary point on the X axis. Mathematica will let me have eight columns on the X axis ranging from -0.5 on up to 7.5. How do I shift the binomial on up to say, from 5.5 to 13.5?


How can I hold UpValues but evaluate other expressions?

Consider these definitions:               own = "OwnValue";     down[_] = "DownValue";     sub[_][_] = "SubValue";     N[n] = 3.14;     _[___, up, ___] ^= "UpValue";      The attribute `HoldAllComplete` holds an UpValue but it also holds the other Values as well. Without advance knowledge of the symbol `up` how can I evaluate everything but the UpValue? `Set` and related functions appear to have this evaluation property internally:               f[own, down[1], sub[1][2], N[n], up] = 1;          Definition[f]      > >     f["OwnValue", "DownValue", "SubValue", 3.14, up] = 1 >   * * * The first idea that comes to mind is to test if a symbol has an UpValue and skip evaluation if it does, but this proves problematic. First, a symbol can have both an OwnValue and an UpValue, and the OwnValue should be used if possible:               x[up3] ^= 2;     up3 = 1;          f[up3]      > >     f[1] (* desired output *) >   Second, testing for an UpValue can be difficult:               _[___, up4, ___] ^= {};          UpValues[up4] === UpValues[Plus]      > True * * * To clarify, it is not my intent to return `f[. . ., up]` as output, which would require `Defer` or similar. Rather I would like to handle the expression `f[. . ., up]` as an argument like `Set` does, or define a function `f[args___] := . . .` (with attribute `HoldAllComplete`) that returns e.g. `{"OwnValue", "DownValue", "SubValue", 3.14, HoldComplete[up]}` How can this be achieved?


RecurrenceTable with a recurrence function of two variables

I have to calculate the cool down process of a regenerative heat exchanger. I solved the problem in Excel before, but now I want to do it with _Mathematica_. I want to create a table with the variables t and z. For `t = 0`, there is a function which gives the temperature for each layer z. For `z = 0`, there is another function which gives the temperature for the first layer for each t. the rest of the table should be calculated layer by layer, so that z is constant while t goes form `t0` to `tend`, then z should increase 1 step and so on. I tried out some simple code, but it didn't work. What's worng? Are there any other ways to solve my problem?               RecurrenceTable[{       T[t + 1, z + 1] == T[t, z + 1] + T[t + 1, z],        T[t + 1, 0] == T[t, 0]/2,        T[0, z] == z + 2       },        T, {t, 0, 6}, {z, 0, 4}] // Grid


Plotting a dynamical NonlinearModelFit Function

Currently I'm playing around with dynamics and the `NonlinearModelFit` function. To be precise, I want to fit a function the data, which range I want to specify dynamically. This is not a problem and works fine. But when it comes to plotting, Mathematica refuses to show me anything. Here's an example code (the testdata consists of 100 values. The variable min gives the lower bound for the fit to begin. ) * * *               min = 50;          testdata = Table[{x*RandomReal[{0.95, 1.05}], 3 x^2 + 4 x}, {x, 0, 10, 0.1}];          fit = Dynamic[NonlinearModelFit[testdata[[min ;;]], a x^2 + b x, {a, b}, x]];          Dynamic[Plot[fit[x], {x, 0, 4}]];      * * * Do you have an idea, how to overcome this problem? Thanks in advance, Juergen


How to detect if a sequence of integers is consecutive

I'm not a math-guy really (a programmer actually) and this is my first question. And excuse me if I can not explain my problem good. The problem is I have a sequence of integers and I want to detect if they are consecutive or not. e.g.               a1 = {1, 2, 3, 4} (* consecutive *)          a2 = {0, 1} (* consecutive *)          a3 = {0, 1, 2, 4} (* non-consecutive *)          a4 = {3, 4, 5, 6} (* consecutive *)          a5 = {3, 5, 6, 7} (* non-consecutive *)          a6 = {2, 3, 4} (* consecutive *)      The numbers come from a list's indexes that a user selected in UI. Actually I want to see if he selects a consecutive rows or not. Is there any way (sure there is :)) to check this without walking through all items in the list? I mean for example by using the first and last number in the list etc? Update: **Note:** The numbers:   1. they are integers,    2. they are ascending,    3. no repeats


Plotting boundary value expression against a parameter

I am very new to _Mathematica_ and have a question regarding plotting a ODE boundary value problem. Let say I have an ODE               alpha = 1/2;     beta = -5;     eq = beta*f'''[x] + alpha*f[x]*f'[x] == 0     bc = {f[0] == 0, f'[0] == 0, f'[10] == 1};      NDSolve[{eq, bc}, f[x], {x, 0, 10}]      I want to plot `alpha*f''[0] + (f''[0])^3` vs `beta`. In the plot, `beta` should take the range [-5, 5]. `NDSolve` should use shooting method for the numerical solution. Also, how I can extract data from that plot as a .txt file.


MapThread over large graph

I am trying to build a very large graph with approximately $16\,000\,000$ edges, each being a two-dimensional integer vector. I have a list of edges in the form $\\{\\{e_{11}, e_{12}\\}, \\{e_{21}, e_{22}\\}, \dotsc\\}$, where $e_{11} = \\{n, m\\}$, etc. To convert it into a usable edge-list I need to turn every element of this list into a rule:               edgeList = MapThread[Rule, Transpose[edgelist]];      This works fast enough when there are $3\,000\,000$ edges but is too slow for $16\,000\,000$. What is the best way to speed up the threading?


Using Mathematica to find Derivatives

I am given a system first order differential equations: $x'=y$ and $y'=6x^2-a/2$, where $a$ is a constant and $'$ denotes $t$-derivatives. I then make the substitution $(x,y)=(x_1y_1,y_1)$. This implies that $x_1=\frac{x}{y}$ and $y_1=y$. The $t$-derivatives are $$x_{1}'=\left(\frac{x}{y}\right)'=\frac{yx'-xy'}{y^2}=1-x_{1}y_{1}^{-1}(6x_{1}^2y_{1}^2-a/2)$$ and $$y_{1}'=6x_{1}^2y_{1}^2-a/2.$$ I need to continue in this fashion, that is, in the next step, for example, we let $(x_{1},y_{1})=(x_{2}y_{2},y_{2})$ and then find $x_{2}'$, $y_{2}'$, etc. Is there a way I can compute the derivatives in Mathematica? For instance, how would I find $x_{1}'$ in Mathematica. Thanks, Radz.


Numerically solving an ODE for a parameter

My equation is as follows:               sol =        ParametricNDSolve[{(f'[r]^2 - 1) f'[r] r == 6.2 (f'[1])^2/1000, f[1] == a},          {f}, {r, 1, 3}, {a}]      where the function `f[r]` needs to satisfies a constraint `6.2 (f'[1])^2/1000 = 6 (f'[3])^2/1000` Then I plot `f[r]`               Plot[Evaluate[{(f'[a])^2[1],6(f'[a])^2[3]/6.2} /. sol], {a, 0, 2}]      I am getting the message > ParametricNDSolve::litarg: To avoid possible ambiguity, the arguments of the > dependent variable in {r (NDSolve`f$1$1^\[Prime])[r] > (-1+(NDSolve`f$1$1^[Prime])[r]^2)==0.0062 NDSolve`f$1$1[1]^2,2 r > (NDSolve`f$1$1^[Prime])[r]^2 (NDSolve`f$1$2^\[Prime])[r]+r (-1+ > (NDSolve`f$1$1^[Prime])[r]^2) (NDSolve`f$1$2^\[Prime])[r]==0.0124 > NDSolve`f$1$1[1] NDSolve`f$1$2[1]} should literally match the independent > variables. >> I do not know how to avoid the error message and solve the function `f[r]`


Generation of Sliders via Tables/For loops

I have a list named data that contains lists of arbitrary size,               data={{0.5, 0.5}, {}, {0.5, 0.5, 0.5}, {}, {}, {}, {}, {}, {}, {}}      I now want to generate for each sub-list the appropriate number of sliders (for the empty sets none, ~~though I believe they are easy to skip~~ ). However, I am not sure if this is even possible. In my quest I stumbled upon this thread, Manipulate with a variable number of sliders, which allows me to generate sliders for one sub-list,               Dynamic[Grid[     Table[With[{i = i}, {Slider[Dynamic[data[[1]][[i]]]],       Dynamic[data[[1]][[i]]]}], {i, Length[data[[1]]]}]]]       This works perfectly fine if I use a constant as an index for `data`, in this case 1. However, if I want to extend this by using a for loop or a table to make that index variable, say               Table[Dynamic[Grid[     Table[With[{i = i}, {Slider[Dynamic[data[[k]][[i]]]],       Dynamic[data[[k]][[i]]]}], {i, Length[data[[k]]]}]]],{k,1,1}]      the `k` gets marked red and the code fails. Is it even possible to generate sliders this way? I imagine the reason that the code fails is that Dynamic requires the object under consideration to remain constant, but is there a way around this?


Transition matrix of order n

I am doing a work about Markov Chains and I have as task to determine, either by induction or by spectral methods, the form of the higher order transition matrix of the model. My transition matrix (P) is:               transitionmatrix = {{17/72, 3/72, 5/72, 0, 0}, {5/72, 5/72, 7/72, 1/72, 0}, {4/72,9/72,     4/72, 0, 4/72}, {0, 0, 3/72, 1/72, 0}, {3/72, 1/72, 0, 0, 0}}            By spectral method P=MDM^-1 :               In[6]:= eigenvalues = Eigenvalues[transitionmatrix] // N     Out[6]= {0.297046, 0.113193, -0.0215001 + 0.0136874 I, -0.0215001 - 0.0136874 I,         0.00776109}          In[7]:= eigenvectors = Eigenvectors[transitionmatrix] // N     Out[7]= {{6.03283, 3.28881, 3.32027, 0.48858, 1.}, {4.22247, -4.51749, -4.76335,      -1.99863, 1.}, {-0.171634 + 0.124637 I, -1.0331 + 0.61158 I, 1.23199 - 0.86313 I,          -1.60369  + 0.395985 I, 1.}, {-0.171634 - 0.124637 I, -1.0331 - 0.61158 I, 1.23199 +      0.86313 I, -1.60369 - 0.395985 I, 1.}, {0.280052, -0.281356, -0.752063, 5.11374, 1.}}          In[18]:= M = Transpose[eigenvectors]     Out[18]= {{6.03283,      4.22247, -0.171634 + 0.124637 I, -0.171634 - 0.124637 I,      0.280052}, {3.28881, -4.51749, -1.0331 + 0.61158 I, -1.0331 -      0.61158 I, -0.281356}, {3.32027, -4.76335, 1.23199 - 0.86313 I,      1.23199 + 0.86313 I, -0.752063}, {0.48858, -1.99863, -1.60369 +      0.395985 I, -1.60369 - 0.395985 I, 5.11374}, {1., 1., 1., 1., 1.}}          In[16]:= Diag = DiagonalMatrix[eigenvalues]     Out[16]= {{0.297046 + 0. I, 0. + 0. I, 0. + 0. I, 0. + 0. I,      0. + 0. I}, {0. + 0. I, 0.113193 + 0. I, 0. + 0. I, 0. + 0. I,      0. + 0. I}, {0. + 0. I, 0. + 0. I, -0.0215001 + 0.0136874 I,      0. + 0. I, 0. + 0. I}, {0. + 0. I, 0. + 0. I,      0. + 0. I, -0.0215001 - 0.0136874 I, 0. + 0. I}, {0. + 0. I,      0. + 0. I, 0. + 0. I, 0. + 0. I, 0.00776109 + 0. I}}          In[17]:= Minver = Inverse[M]     Out[17]= {{0.109069 + 7.70366*10^-19 I, 0.0487956 + 6.50521*10^-19 I,      0.0514224 - 9.72945*10^-19 I, 0.00239343 + 5.5971*10^-19 I,      0.00961738 - 3.82994*10^-18 I}, {0.0828826 -      4.20783*10^-18 I, -0.0865795 + 1.0842*10^-17 I, -0.0549339 -      8.27329*10^-18 I, -0.0121092 - 4.07692*10^-18 I, -0.0269617 +      1.91893*10^-17 I}, {-0.0897774 + 0.141661 I,      0.0551552 - 0.443078 I, -0.00936235 + 0.351851 I, -0.0773342 +      0.143982 I, 0.429087 - 0.636007 I}, {-0.0897774 - 0.141661 I,      0.0551552 + 0.443078 I, -0.00936235 - 0.351851 I, -0.0773342 -      0.143982 I,      0.429087 + 0.636007 I}, {-0.0123972 -      4.92909*10^-18 I, -0.0725264 + 1.38778*10^-17 I,      0.0222361 - 1.0567*10^-17 I, 0.164384 - 5.62511*10^-18 I,      0.159171 + 2.19287*10^-17 I}}      But when i do               M.Diag.Minver      i dont get my transition matrix i get:               In[14]:= M.Diag.Minver          Out[14]= {{0.236111 - 7.80878*10^-19 I, 0.0416667 + 6.58726*10^-18 I,      0.0694444 - 5.94759*10^-18 I, -3.43324*10^-18 - 8.88005*10^-19 I,      4.15626*10^-17 + 2.63492*10^-18 I}, {0.0694444 + 2.15757*10^-18 I,      0.0694444 - 3.80299*10^-18 I, 0.0972222 + 2.07205*10^-18 I,      0.0138889 + 3.02264*10^-18 I,      1.88651*10^-17 - 1.20859*10^-17 I}, {0.0555556 + 4.03989*10^-18 I,      0.125 - 6.75901*10^-18 I,      0.0555556 + 5.16039*10^-18 I, -1.15614*10^-17 + 2.29187*10^-18 I,      0.0555556 - 1.62182*10^-17 I}, {-2.1617*10^-15 +      2.2484*10^-20 I, -9.09499*10^-16 - 5.39346*10^-19 I,      0.0416667 - 6.27859*10^-20 I,      0.0138889 + 1.20315*10^-18 I, -2.11264*10^-16 -      2.33486*10^-18 I}, {0.0416667 + 9.43055*10^-20 I,      0.0138889 + 9.58975*10^-19 I, -1.44261*10^-17 -      6.90605*10^-19 I, -2.78314*10^-18 - 5.28583*10^-19 I,      1.27434*10^-17 + 4.46324*10^-19 I}}      Please could u help me, i dont know what i am doing wrong. And could u help me finding the higher transition matriz by induction? My teacher gave this code, but i dont understand it, so i wouldnt like to use.               POTtrMx[0] = IdentityMatrix[Length[StSp]];      POTtrMx[n_Integer] := POTtrMx[n] = Dot[POTtrMx[n - 1], trMx]


Change number from real to integer

> **Possible Duplicate:**   >  Is this the most efficient way to round approximate integers to integers > while leaving other Reals untouched? Please consider the following:               data={123.,56.,45.};     Head/@data     (*result: {Real,Real,Real}*)      How do I change the numbers in `data` into integers, so:               dataConv=MyFunction/@data;     Head/@dataConv     (*result: {Integer,Integer,Integer}*)      **EDIT** Also interesting could be to change "real" reals like `{12.3,10.555}` into integers by returning only the numbers before the decimal separator `(*result: {12,10}*)`.


A dot appearing after a zero, and making the entries of a matrix into fractions

> For more info about the difference between 0. and 0 I am a self-taught Mathematica user and I have some elementary questions-- perhaps too elementary for this site, but here they are. ![Matrix](http://i.stack.imgur.com/XFQkd.jpg)   1. If you look at the identity matrix, you'll see a "dot" in each entry in the upper triangular portion of the matrix. Why are they there? Is it because those entries are not really zeros?    2. How do I get the entries in MatrixForm[Inverse[M]] to appear as fractions?  Thanks everyone! So I just found this link: Expressing a decimal as a fraction in lowest terms and tried the following: ![Matrix2](http://i.stack.imgur.com/cJfBZ.jpg) Isn't there a way to tell Mathematica to not show entries like -9.71445146547012`*^-17 (up to 17th decimal place)?


Returning Replacement Rules in a function and using it later on

I would like a function which returns replacement rules as some internal mathematica functions are doing and use the results in other functions. I could not find any information on that and I'm wondering if it is a good idea after all. I'm not sure how this is done in a good way. Here is an example:               Clear[f, f2, H, imax, res]     f[imax_] :=       Block[{H}, H = Table[Random[], {i, 1, imax}];        Return[{H -> H, imax -> imax}]]     f[5]      with the result               {{0.855859, 0.656278, 0.793888, 0.275233, 0.751709} -> {0.855859,       0.656278, 0.793888, 0.275233, 0.751709}, 5 -> 5}      Yes this is obvious but I would like to use the name H internally and also in the returned replacement rule. So I do this instead:               f2[imax_] :=       Block[{H}, H = Table[Random[], {i, 1, imax}];        Return[{"H" -> H, "imax" -> imax}]]     res = Table[f2[imax], {imax, 5, 7}]     (*now i want to invesgate the result with imax=6*)     p = First @Flatten[Position[res, "imax" -> 6]]     res[[p]]     Head["H"] /. res[[p]]      with the result:               {{"H" -> {0.486493, 0.60306, 0.666644, 0.148913, 0.598069},      "imax" ->       5}, {"H" -> {0.873354, 0.98408, 0.0392209, 0.428918, 0.485521,      0.710918},      "imax" ->      6}, {"H" -> {0.198376, 0.385448, 0.438549, 0.818111, 0.314781,      0.533971, 0.955322}, "imax" -> 7}}          2          {"H" -> {0.873354, 0.98408, 0.0392209, 0.428918, 0.485521, 0.710918},       "imax" -> 6}          String      So the Problem is that Head["H"] /. res[[p]] results in a string and ListPlot["H"] /. res[[p]] would complain but plot the result. A good thing tough is that it is possible to search in the results and it is more flexible and readable than returning a List. So what is the best way to do this? So that I can use H and imax internally in the function and in the Return?


Rearrangement of the list

I have the following list:                m = {{x == 0, y == 0.29264681456942615},            {x == 30, y == 0.2419119568894183},            {x == 50, y == 0.1485164898707659},            {x == 70, y == 0.05437093382683481},            {x == 90 , y == 1.}}      I would like to convert it to the form `{{0,0.29264681456942615},{30, 0.2419119568894183}, ... }` (extracting only the numbers form the list). How can I do this?


How to resolve Start up error 502?

My Mathematica is not launching properly (I run it on Ubuntu 12.04 LTS). Here is the screenshot of the error message. ![enter image description here](http://i.stack.imgur.com/XZmIy.png) I've tried the following suggestions :               i) -cleanstart     ii) ~/.mathematica and even      iii) reinstalled it.      But none of the above is woking. Can anyone please help me?


How to extract a possible closed form from WolframAlpha[] output

To find a possible closed form of a number, I can use the function               WolframAlpha["6.38905609893065", IncludePods -> "PossibleClosedForm"]      It returns a result in the following form: ![Possible closed forms](http://i.stack.imgur.com/DkQw8.png) The `InputForm` of this result displays quite a large expression containing pods and cells represented as `XMLElement`s. > Is there an easy way to extract the first suggested closed form as a normal > expression (in this case, `E^2 - 1`)?


Showing "updating..." message while Manipulate is re-evaluating

Is it possible to show a fixed text such as _"updating..."_ instead of the last result shown, when `Manipulate` is re-evaluating an expression (in a slow evaluation context)? How to do it? More precisely, I have a `Button` element in the set of controls, and it is the action triggered by the button the one that slows down the process, and _not_ the results shown in the `Manipulate` sentence themselves. This could be a MWE for what I mean:               Manipulate[result,      {{x, 5}, 0, 10, 1, Appearance -> {"Labeled"}, AppearanceElements -> None},      {{y, 5}, 0, 10, 1, Appearance -> {"Labeled"}, AppearanceElements -> None},      Button["Calculate", Pause[2]; result = x + y],      TrackedSymbols :> {result},      Initialization -> Clear[result, x, y]]      In this example, the values for two integer numbers `x` and `y` are selected using their respective slider controls, and then a button is used to perform some calculations based on them. Finally, results based on those calculations are shown using `Manipulate`. So, regarding this example, my question is: how can I show the text _"updating..."_ while the button is _thinking_? If you think there would be an easier solution in case it was not the button but the expression to be shown by `Manipulate` the one that takes some long time to be executed, I think I could also modify my real problem to be like that. The MWE could be like this:               Manipulate[Pause[2]; parameters[[1]] + parameters[[2]],      {{a, 5}, 0, 10, 1, Appearance -> {"Labeled"}, AppearanceElements -> None},      {{b, 5}, 0, 10, 1, Appearance -> {"Labeled"}, AppearanceElements -> None},      Button["Calculate", parameters = {a, b}],       TrackedSymbols :> {parameters},       Initialization -> (Clear[a, b, parameters]; parameters = {5, 5})]      It would be also OK if the text _"updating..."_ appeared _in the button_ , temporarily replacing the _"Calculate"_ text. It would be a little bit strange, but also valid. I look forward to your solutions.


How to declare a function of variable?

In my program, there are many functions relying on spatial coordinates: x, y, and z, which are also functions of time t, i.e., composite function. I need to differentiate some functions for example f:                   D[f[x[t], y[t], z[t]], t]      But because those coordinates appear so frequently, when I write x[t] instead of x my program becomes lengthy and lacks readability. So, how can I declare those coordinates as functions of time t at the start to tell _Mathematica_ that the differentiation is relative to t, so I can use x, y , and z, afterwards as an abbreviation.


Creation of name.m Package

I have a structure of folders.   1. Main Directory( has init.m, and name.m files)   2. Subfolders under Main directory      1. library ( has the packages, pacakge1.m, package2.m)     2. Data (some xcel sheets and other data files) The init.m has the following commands `Get[FileNameJoin[{NotebookDirectory[],"library", "Package1.m"}]]; Get[FileNameJoin[{NotebookDirectory[],"library", "Package2.m"}]];` Package1 has `function1` and `function2` definitions. Package2 has `function3` and `function4` definitions. The Names.m file has the following the commands               Get[FileNameJoin[{NotebookDirectory[],"init.m"}]];     DeclarePackage["Package1`",{"function1", "function2"}];     DeclarePackage["Package2`",{"function3", "function4"}]      After evaluating the name.m file, I was expecting that calling `function1` should execute the `Package1`function1`. However it is not happening. This is what I understand of _Mathematica_ so far. I don't want to touch the init.m file in the Autoload folder of the userbase directory as I don't want to modify the contents. I just want my init.m in the local folder to run. Workarounds anyone?