title: Drawing dessins d'enfants (bipartite graphs subject to certain conditions)

text: I want to write a function which constructs all possible _dessins d'enfants_ (bipartite graphs fulfilling certain criteria, given below) from a collection of data presented in the following form: $\begin{Bmatrix}r_{0}\left(1\right),r_{0}\left(2\right),\ldots,r_{0}\left(W\right)\\\ r_{1}\left(1\right),r_{1}\left(2\right),\ldots,r_{1}\left(B\right)\\\ r_{\infty}\left(1\right),r_{\infty}\left(2\right),\ldots,r_{\infty}\left(I\right) \end{Bmatrix}$ The graphs produced should be such that:   1. For every $r_{0}\left(i\right)$ there is a white node with $r_{0}\left(i\right)$ edges emanating therefrom; there are $W$ white nodes in total.   2. For every $r_{1}\left(j\right)$ there is a black node with $r_{1}\left(j\right)$ edges emanating therefrom; there are $B$ black nodes in total.   3. White nodes only join black nodes and vice versa (the graph is bipartite).   4. The graph has $I$ faces; the $k$th face is a polygon with $2r_{\infty}\left(k\right)$ sides. (A useful simplification is that in most cases of interest, for all $i$ and $j$, $r_{0}\left(i\right)=3$ and $r_{1}\left(j\right)=2$ - I've been focusing on this specific case in my own attempted solutions). To illustrate, the graphs at the top of page 28 in this article correspond to the data given at the top of page 25 of the same article. Taking the specific example of Ia, we see that:   * The graph has 8 white nodes, all with three connecting edges (criterion (1) above satisfied).   * The graph has 12 black nodes, all with two connecting edges (criterion (2) satisfied).   * The graph is bipartite (criterion (3) satisfied).   * The graph has six faces (one for each of the individual boxes, and one around the outside), each with eight edges (criterion (4) satisfied). I would like to write a Mathematica function which reproduces these graphs, when the corresponding 3-vector of data is input. As a further complication, it is sometimes the case that for one set of data there are multiple _dessins_. For example, consider the following data: $\begin{Bmatrix}3^{8}\\\ 2^{12}\\\ 18,2,1,1,1,1 \end{Bmatrix}$ (The Mathematica input for this would be something like `{{3,3,3,3,3,3,3,3},{2,2,2,2,2,2,2,2,2,2,2,2},{18,2,1,1,1,1}}`.) This has three dessins associated with it, drawn here. (Here, each vertex corresponds to a white node, and the author has omitted all the black nodes - he's presumably only done this for the sake of clarity). (By the way, this example also illustrates something which confused me to start off with - the "polygon" with $18\times2=32$ edges is found by going round the _whole_ of the outside of the graph.) I appreciate that this is not exactly a trivial problem. My approach so far has been to create a graph with $B+W$ vertices and initially no edges, making the first $B$ vertices black and the next $W$ vertices white. Then, connect each of the black vertices to two of the white vertices, such that each white vetex is connected to three black vertices (at least two of which are distinct). Check that the resulting graph is connected. Then use a cycle algorithm (such as the one here) to identify all the cycles of the graph starting at white vertices which do _not_ backtrack, i.e. which do not go from a white vertex to a black vertex and back to a white vertex again, _unless_ the intermediate black vertex is _only_ connected to the initial white vertex. If those cycles have edge numbers given by the $2r_{\infty}\left(k\right)$, then draw the graph and move onto the next permutation of connections between the black vertices and white vertices. Else, just move onto the next permutation of connections between the black vertices and white vertices. I'll post the explicit code for this algorithm ASAP (i.e. after some reworking, which will hopefully get it to do _something_!), but I don't think it's likely to be the most efficient way of going about the problem, and I am sure a more elegant solution is possible.


title: Speeding up Integrate and the numerical solution

text: I want to compute the drag of a plate ![enter image description here](http://i.stack.imgur.com/kcEVv.jpg) Below is the code I am using to integrate the function               velcenter = {dotx, doty, 0};                           r = {Cos[θ[t]], Sin[θ[t]], 0};     veltanA = {-Sin[θ[t]], Cos[θ[t]], 0};      velxpoint = Part[Cross[velcenter, r], 3];      dragD = 1/2*ρ*cofD*h*Integrate[(Abs[velxpoint - s*dotθ])*(velcenter +                                             s*dotθ*veltanA), {s, a - l, a}];      The integration is so slow and I want to speed it up. Any suggestions are welcome !


title: How to define a button inside Manipulate that tells Mathematica to re-evaluate the whole Manipulate code?

text: I have written a `Manipulate` code carrying out some very complicated tasks. There is no problem for the first run, but if I click the reset button to reset all variables to their initial states (which is also ok) and click the run button a second time, then it is very likely that the Mathematica kernel will crash during the re-run progress, the frequency for such crash happening is about 9 out of 10 times. I have spent almost a month trying to track down the source of this problem, but failed. I also asked the Wolfram support team, they suggested to implement the `Quit` function in the reset button as a workaround, such that the reset button will make the kernel quit, since the first run is always ok. Now the problem is, I cannot directly put `Quit[]` inside the button, for by doing this the kernel loses all definiton about the enclosing `Manipulate`. So I need the reset button doing two tasks:   1. Quit the kernel.   2. Make Mathematica automatically re-run the enclosing `Manipulate` code. I wonder if this is possible?


title: How to calculate the residue of $1/f(z)$ at a numerical approximation to a root of $f(z)$?

text: The input               Residue[1/DirichletL[19,10,s],{s,s0}]      gives `0` even when `s0` is a root. For example, from LMFDB, I found `s0 = 0.5 + 1.51608375316006 I` is an approximate root of `DirichletL(19,10,s)`. (In LMFDB this character is actually indexed 18, though.) For the Riemann zeta function, we can get around this by using `ZetaZero[1]` to represent `s0`. What can be done for other $L$-functions?


title: How to build a funcion that returns a piecewise function

text: I dont know how to go ahead with this The problem statement is "Make a piecewise linear function maker that accepts lists of points as input and has a piecewise linear function as the output". Lets say for example I have a data sect {1,1,1,0,0,1,1}.


title: Image basics in mathematica

text: 1) How the pixel values are defined in mathematica or how it is different from matlab? 2) I am wondering how image properties are different in mathematica, and how they are calculated? ComponentMeasurement: properties: such as "Centroid", "IntensityCentroid", "Area". 3) I want to find basic image processing link for mathematica 8 or 9? I felt documentation is not informative enough, any link or help on this topic will be great.


title: Finding the roots of Hypergeometric1F1[]

text: I am trying to find the roots, `λ`, for this equation:               Hypergeometric1F1[1/4 (2 -  λ /β), n + 1, β]       for certain `β` and `n`. Here is my _Mathematica_ code.               eq[n_, β_, λ_] = Hypergeometric1F1[1/4 (2 - λ/β), n + 1, β]      Find the root near `λ = β`.               ED[n_, β_] := λ /.        FindRoot[eq[n, β, λ] == 0, {λ, β}]       List all `λ`-values for each value of `n` when `β = 0.00001`               {ED[0, 0.00001], ED[1, 0.00001], ED[2, 0.00001], ED[3, 0.00001], ED[4, 0.00001],      ED[5, 0.00001], ED[6, 0.00001], ED[7, 0.00001], ED[8, 0.00001], ED[9, 0.00001],      ED[10, 0.00001]}      Then, I got `{5.78319, 14.682, 26.3746, 40.7064, 57.5829, 76.9388, 98.7262, 122.907, 149.453, 178.337, 209.54}` However I'm supposed to get `{5.78306, 14.6819, 26.3744, 30.4715, 40.707, 49.2186, 57.5823, 70.8493, 74.8865, 76.9392, 95.2771}` I guess _Mathematica_ gives only one root. How can I also find the 2nd, 3rd, 4th roots, for each value of `n`?


title: How to understand shared passing of a MTensor in LibraryLink?

text: According to the documentation, there are four different type of memory managing when passing a MTensor with LibraryLink: Automatic, "Constant", "Manual" and "Shared". The Automatic and "Manual" is easy to understand, since in both of them, the MTensor get copied and passed into the library function. The difference between them is wether the tensor will be automatically clean or not. The "Constant" and "Shared" will pass a reference of the MTensor into the library function, and "Constant" promises the library function to not change the MTensor. I find "Shared" is difficult for me to understand. Does the "Shared" passing means that variable in Mathematica and my library function point to the same data buffer in the memory? And if I change on one side, the changes will be transparent on the other side ? Consider this example from the document:               loadFun =        LibraryFunctionLoad["demo_shared",         "loadArray", {{Real, _, "Shared"}}, Integer];     unloadFun =        LibraryFunctionLoad["demo_shared", "unloadArray", {}, Integer];     getFunVector =        LibraryFunctionLoad["demo_shared", "getElementVector", {Integer},         Real];      If we load the library function with an array               array = Range[1., 20];     loadFun[ array]      and change the array on the Mathematica side               array[[1]] = 2.;     getFunVector[ 1]     (* 1. *)      why the data on the library side not changed? Also, in the documentation, it says after call unload, which disowns the MTensor, array cannot be used anymore,               unloadFun[ ]     (* 0 *)          getFunVector[1]     (* 1. *)          array[[1]]     (* 2. *)      but why I can still use it? What does disown do?


title: How to print a message dialog window

text: I'm trying to figure out how to print a message dialog without printing the whole notebook. `FrontEndExecute[FrontEndToken["PrintDialog"]]` displays the print window (just like selecting file -> print but it prints the whole notebook. I have also tried using `FrontEndExecute[FrontEndToken["PrintSelectionDialog"]]` but when the code is run the selected area becomes unselected. I have solved part of the problem with the following               DialogInput[       DialogNotebook[{Column[{Plot[Sin[x], {x, 0, 6 Pi}],            Row[{Button["print",               DialogReturn[               FrontEndExecute[FrontEndToken["PrintDialog"]]]]}]}]}]];      This prints the entire window including the print button as shown.   ![print output](http://i.stack.imgur.com/GXp1E.png)   This is exactly what I am looking for but without the print button.   Any ideas much appreciated,   Christina


title: NDSolve with Table and Boundary Conditions

text: I am trying to implement a 1D model of coupled field equations where I split up space into pieces to get a system of coupled ODEs which I call Eeqns and Ieqns. The problem I can't figure out is how to put Dirichlet boundary conditions (NE=0, NI=0 at both edges) into the code. Everything I try results in an error. Below is what I've written (which works) without BCs. Pardon the text conversions problems. I don't know how to fix it. Also, f and g are functions defined in the code.               Eeqns = Table[             {10*D[NE[i][t], t] ==             -NE[i][t]+(1-NE[i][t])*             f[α*10*Sum[dx*g[dx*i-dx*j, bEE, σEE]*NE[j][t], {j, 1, n}]             - α*10*Sum[dx*g[dx*i-dx*j, bIE, σIE]*NI[j][t], {j, 1, n}]             + α*10*(P/2)*(Tanh[10*(i-Elefti)]-Tanh[10*(i-Erighti)])*(1/2)*(Tanh[10*(t-Einputstart)]-Tanh[10*(t-Einputstop)]), aE, θE]}, {i, 1, n}];          Ieqns = Table[             {10*D[NI[i][t], t] ==             -NI[i][t]+(1-NI[i][t])*             f[α*10*Sum[dx*g[dx*i-dx*j, bEI, σEI]*NE[j][t], {j, 1, n}]             - α*10*Sum[dx*g[dx*i-dx*j, bII, σII]*NI[j][t], {j, 1, n}]             + α*10*(Q/2)*(Tanh[10*(i-Ilefti)]-Tanh[10*(i-Irighti)])*(1/2)*(Tanh[10*(t-Iinputstart)]-Tanh[10*(t-Iinputstop)]), aI, θI]}, {i, 1, n}];          Einit = Table[NE[i][0] == 0, {i, 1, n}];     Iinit = Table[NI[i][0] == 0, {i, 1, n}];          u = Table[NE[i], {i, 1, n}];     v = Table[NI[i], {i, 1, n}];          sol = NDSolve[           Join[Eeqns, Ieqns, Einit, Iinit],           Join[u, v],           {t, 0, T},           MaxStepSize -> 0.01][[1]];


title: Preventing label crowding in PieChart RadialCallout and RadialCenter

text: Is it possible to avoid this unreadable situation with label crowding when using `PieChart`'s `RadialCallout` and `RadialCenter` methods?               PieChart[tabData109[[All, 2]],       SectorOrigin -> {{Pi/2, "Clockwise"}, 1},       ChartStyle -> tabData109[[All, 1]] /. PACE["TAB_COLOR_RULES"],      LabelingFunction -> (Placed[          Row[{NumberForm[             100 # /Plus @@ tabData109[[All, 2]] // N, {3, 1}], "%"}],           "RadialCenter"] &),      ChartLabels ->        Placed[tabData109[[All, 1]] /. PACE["TAB_DESCRIPTION_RULES"],         "RadialCallout"]]      Gives: ![enter image description here](http://i.stack.imgur.com/i0ey1.jpg)


title: Mathematica - Dynamic - ListPlot - baseline

text: I am performing baseline fitting to a raw dataset on a two-state equilibrium process. The process involves fitting the sigmoidal curve to an upper and lower linear baseline, and subtracting so that you get a curve going from y=(0) (state 1) to y=(1) (state 2) over your x-value range instead y=(experimental observable values). I'd like to expedite the baseline selection process through an interactive dynamic approach rather than manually typing in lhs/rhs x-values for each curve. However, I'm noticing that the dynamic values behind the dynamic plots need to be on the screen for the plot to update. Meaning, if I'm dynamic listplotting 4 points, and only three of these dynamic values (the output) are on screen then only three show up. I have to scroll up or down through the notebook to "update" various values and then the plots correct themselves. I have many calculations downstream after baseline selection, and I'd like to have all these subsequent calculations print up in a neat little grid near the sliders, without have to scroll. I'm new to Dynamic, and also having trouble combining multiple plots (similar to Show) when held under the Dynamic functions. I'd like to dynamically in one graphic plot the ListPlot of my rawData, the four baseline points, and then the fitted linear function through the selected rawData in the baseline area. Next to this, I'll plot the two-state equilibrium plot (y=0 to 1) and then a single point representing the transition point of 50/50 state1/state2 (y=0.5). All of these downstream processes are highly dependent on baseline selection, so I'd like to have the slider there and final plots to immediately see the results of various choices for baselines. In summary, two questions: 1) screen refresh needed of output from dynamic values for updating dynamic plots not in the same input section 2) multiple plot types within a single graphic, dynamically               ramp1FCelsiusXRFUSmooth[        1] = {{5.2, 171.5576923076923}, {5.4, 171.4583916083916}, {5.6,          171.36804195804197}, {5.8, 171.31552447552448}, {6,          171.31125874125877}, {6.2, 171.35321678321677}, {6.4,          171.41783216783216}, {6.6, 171.5072027972028}, {6.8,          171.61223776223778}, {7, 171.74020979020978}, {7.2,          171.8802097902098}, {7.4, 172.01412587412588}, {7.6,          172.1367832167832}, {7.8, 172.25818181818184}, {8,          172.37916083916082}, {8.2, 172.52223776223775}, {8.4,          172.65797202797202}, {8.6, 172.81475524475525}, {8.8,          172.97706293706293}, {9, 173.16314685314686}, {9.2,          173.35531468531468}, {9.4, 173.56958041958043}, {9.6,          173.7951048951049}, {9.8, 174.03153846153847}, {10,          174.2748951048951}, {10.2, 174.51762237762236}, {10.4,          174.7634265734266}, {10.6, 174.9851048951049}, {10.8,          175.1865034965035}, {11, 175.3864335664336}, {11.2,          175.59503496503498}, {11.4, 175.81916083916082}, {11.6,          176.02797202797203}, {11.8, 176.2442657342657}, {12,          176.45391608391608}, {12.2, 176.6886013986014}, {12.4,          176.9281118881119}, {12.6, 177.19}, {12.8, 177.47}, {13,          177.7390909090909}, {13.2, 178.01503496503494}, {13.4,          178.2923076923077}, {13.6, 178.60461538461539}, {13.8,          178.92685314685315}, {14, 179.24713286713288}, {14.2,          179.5781818181818}, {14.4, 179.93076923076922}, {14.6,          180.32083916083917}, {14.8, 180.71741258741258}, {15,          181.124965034965}, {15.2, 181.55125874125875}, {15.4,          181.97825174825175}, {15.6, 182.41020979020982}, {15.8,          182.8441258741259}, {16, 183.3011188811189}, {16.2,          183.77636363636367}, {16.4, 184.26951048951048}, {16.6,          184.80447552447555}, {16.8, 185.37951048951047}, {17,          185.97846153846154}, {17.2, 186.58356643356643}, {17.4,          187.19545454545454}, {17.6, 187.81587412587407}, {17.8,          188.44538461538463}, {18, 189.08426573426573}, {18.2,          189.73111888111887}, {18.4, 190.38111888111888}, {18.6,          191.04258741258744}, {18.8, 191.7199300699301}, {19,          192.43076923076922}, {19.2, 193.16111888111888}, {19.4,          193.91048951048953}, {19.6, 194.68713286713282}, {19.8,          195.4913286713287}, {20, 196.32006993006993}, {20.2,          197.17510489510488}, {20.4, 198.05881118881118}, {20.6,          198.95755244755247}, {20.8, 199.8584615384615}, {21,          200.76384615384615}, {21.2, 201.68461538461537}, {21.4,          202.62685314685316}, {21.6, 203.66496503496504}, {21.8,          204.81300699300698}, {22, 205.96062937062936}, {22.2,          206.8897902097902}, {22.4, 207.50202797202797}, {22.6,          207.81699300699304}, {22.8, 207.95888111888112}, {23,          208.02839160839162}, {23.2, 208.14692307692306}, {23.4,          208.4265734265734}, {23.6, 208.94608391608392}, {23.8,          209.81937062937064}, {24, 211.1255244755245}, {24.2,          212.82013986013985}, {24.4, 214.7145454545455}, {24.6,          216.61958041958042}, {24.8, 218.50860139860137}, {25,          220.42069930069928}, {25.2, 222.4111888111888}, {25.4,          224.48314685314682}, {25.6, 226.616013986014}, {25.8,          228.8025874125874}, {26, 231.0102097902098}, {26.2,          233.26111888111888}, {26.4, 235.54636363636362}, {26.6,          237.8906293706294}, {26.8, 240.30881118881118}, {27,          242.80363636363634}, {27.2, 245.37720279720278}, {27.4,          248.0467132867133}, {27.6, 250.82118881118885}, {27.8,          253.69622377622377}, {28, 256.65937062937064}, {28.2,          259.7168531468531}, {28.4, 262.8809090909091}, {28.6,          266.136083916084}, {28.8, 269.48853146853145}, {29,          272.9494405594406}, {29.2, 276.5634265734266}, {29.4,          280.31496503496504}, {29.6, 284.1983916083916}, {29.8,          288.2063636363637}, {30, 292.3523076923077}, {30.2,          296.6392307692308}, {30.4, 301.0708391608391}, {30.6,          305.62391608391613}, {30.8, 310.3113286713287}, {31,          315.11034965034963}, {31.2, 320.04965034965034}, {31.4,          325.1569230769231}, {31.6, 330.4420979020979}, {31.8,          335.90902097902097}, {32, 341.55034965034963}, {32.2,          347.37482517482516}, {32.4, 353.38538461538457}, {32.6,          359.5694405594406}, {32.8, 365.93888111888117}, {33,          372.4761538461538}, {33.2, 379.2182517482518}, {33.4,          386.1609790209791}, {33.6, 393.32629370629365}, {33.8,          400.7041958041958}, {34, 408.26265734265735}, {34.2,          416.02657342657346}, {34.4, 423.96489510489516}, {34.6,          432.1181818181819}, {34.8, 440.4820979020979}, {35,          448.6806293706294}, {35.2, 456.86342657342664}, {35.4,          465.53755244755246}, {35.6, 475.66034965034964}, {35.8,          487.5865734265734}, {36, 501.1653146853147}, {36.2,          516.0813286713288}, {36.4, 531.9086013986014}, {36.6,          548.2587412587412}, {36.8, 564.6713986013987}, {37,          580.6118881118881}, {37.2, 595.7270629370629}, {37.4,          609.4006293706293}, {37.6, 622.2286013986014}, {37.8,          634.5355944055943}, {38, 647.2777622377623}, {38.2,          660.156153846154}, {38.4, 673.3221678321679}, {38.6,          686.4862237762237}, {38.8, 699.9664335664336}, {39,          713.5155244755244}, {39.2, 727.4389510489511}, {39.4,          741.0336363636363}, {39.6, 755.0702097902098}, {39.8,          769.5217482517482}, {40, 785.5246153846156}, {40.2,          802.3835664335664}, {40.4, 820.4558741258742}, {40.6,          838.8953146853147}, {40.8, 858.1897202797202}, {41,          877.5658741258741}, {41.2, 897.573986013986}, {41.4,          917.3868531468532}, {41.6, 937.4052447552448}, {41.8,          956.7482517482517}, {42, 976.6904895104893}, {42.2,          997.0346153846153}, {42.4, 1018.8477622377623}, {42.6,          1041.1142657342657}, {42.8, 1064.3213286713287}, {43,          1088.1560139860142}, {43.2, 1112.473986013986}, {43.4,          1137.4900699300697}, {43.6, 1164.0341958041959}, {43.8,          1192.6026573426573}, {44, 1223.4609090909091}, {44.2,          1255.9941258741258}, {44.4, 1290.8709790209791}, {44.6,          1327.0130769230768}, {44.8, 1364.6239860139858}, {45,          1402.7880419580417}, {45.2, 1442.381118881119}, {45.4,          1482.7290909090907}, {45.6, 1523.66013986014}, {45.8,          1565.570979020979}, {46, 1609.5718881118883}, {46.2,          1656.1732867132866}, {46.4, 1705.5791608391607}, {46.6,          1757.082797202797}, {46.8, 1811.405664335664}, {47,          1867.7601398601398}, {47.2, 1927.0214685314686}, {47.4,          1988.903566433566}, {47.6, 2053.9727272727273}, {47.8,          2121.3558741258735}, {48, 2191.253076923077}, {48.2,          2263.4567132867137}, {48.4, 2338.992097902097}, {48.6,          2417.6206293706296}, {48.8, 2499.507062937063}, {49,          2584.0679020979014}, {49.2, 2672.40048951049}, {49.4,          2764.2509090909093}, {49.6, 2860.08972027972}, {49.8,          2958.8880419580414}, {50, 3061.5296503496506}, {50.2,          3167.954475524476}, {50.4, 3279.3267132867136}, {50.6,          3394.996363636363}, {50.8, 3514.5386013986017}, {51,          3637.8941958041955}, {51.2, 3767.8172727272727}, {51.4,          3907.369160839161}, {51.6, 4057.940839160839}, {51.8,          4218.387692307691}, {52, 4387.486363636363}, {52.2,          4559.219090909091}, {52.4, 4737.994405594407}, {52.6,          4926.850629370629}, {52.8, 5133.069790209789}, {53,          5351.979300699301}, {53.2, 5580.233216783217}, {53.4,          5815.771258741259}, {53.6, 6059.474335664335}, {53.8,          6310.2300699300695}, {54, 6566.168951048951}, {54.2,          6824.079510489511}, {54.4, 7080.809090909091}, {54.6,          7333.146293706293}, {54.8, 7587.8459440559445}, {55,          7850.626853146852}, {55.2, 8125.57027972028}, {55.4,          8409.073496503495}, {55.6, 8698.83132867133}, {55.8,          8996.236433566435}, {56, 9300.716293706295}, {56.2,          9614.424195804197}, {56.4, 9936.465874125875}, {56.6,          10267.16895104895}, {56.8, 10604.112797202795}, {57,          10948.749580419582}, {57.2, 11300.41020979021}, {57.4,          11659.683006993006}, {57.6, 12023.626783216785}, {57.8,          12392.80202797203}, {58, 12766.768741258744}, {58.2,          13147.152517482516}, {58.4, 13533.405594405594}, {58.6,          13929.522447552448}, {58.8, 14331.496503496504}, {59,          14735.11027972028}, {59.2, 15134.907552447552}, {59.4,          15531.639090909091}, {59.6, 15926.898251748251}, {59.8,          16319.009370629366}, {60, 16708.945804195802}, {60.2,          17100.06636363636}, {60.4, 17496.746923076924}, {60.6,          17899.96601398601}, {60.8, 18310.962377622378}, {61,          18733.114335664337}, {61.2, 19158.742027972025}, {61.4,          19578.491538461538}, {61.6, 19983.563636363637}, {61.8,          20383.41286713287}, {62, 20771.78615384616}, {62.2,          21143.815874125874}, {62.4, 21493.19979020979}, {62.6,          21831.533146853144}, {62.8, 22165.208671328666}, {63,          22497.004265734264}, {63.2, 22829.18895104895}, {63.4,          23165.61839160839}, {63.6, 23505.106223776227}, {63.8,          23845.65895104895}, {64, 24185.918321678324}, {64.2,          24530.909580419582}, {64.4, 24870.472797202798}, {64.6,          25198.522797202797}, {64.8, 25507.47804195804}, {65,          25802.223846153847}, {65.2, 26082.483426573428}, {65.4,          26348.033426573424}, {65.6, 26600.166853146857}, {65.8,          26840.285384615385}, {66, 27072.183286713287}, {66.2,          27294.89937062937}, {66.4, 27510.708951048953}, {66.6,          27720.160139860138}, {66.8, 27922.566853146855}, {67,          28118.26083916084}, {67.2, 28307.706083916084}, {67.4,          28494.77258741259}, {67.6, 28679.58657342657}, {67.8,          28860.11972027972}, {68, 29039.42153846154}, {68.2,          29210.7306993007}, {68.4, 29366.41545454545}, {68.6,          29502.546223776226}, {68.8, 29629.67433566434}, {69,          29744.836363636365}, {69.2, 29836.08020979021}, {69.4,          29898.33790209791}, {69.6, 29933.56769230769}, {69.8,          29959.04762237762}, {70, 29975.020909090912}, {70.2,          29991.388531468532}, {70.4, 30006.784055944052}, {70.6,          30018.964685314684}, {70.8, 30026.687132867133}, {71,          30047.393426573428}, {71.2, 30084.82174825175}, {71.4,          30135.9965034965}, {71.6, 30182.328111888113}, {71.8,          30225.142167832168}, {72, 30268.663566433566}, {72.2,          30319.640629370628}, {72.4, 30372.744545454545}, {72.6,          30427.39160839161}, {72.8, 30477.89188811188}, {73,          30521.84727272727}, {73.2, 30553.777762237765}, {73.4,          30573.294825174824}, {73.6, 30571.749790209793}, {73.8,          30562.458741258743}, {74, 30552.884825174824}, {74.2,          30553.355174825174}, {74.4, 30564.295454545452}, {74.6,          30576.382587412594}, {74.8, 30594.90377622378}, {75,          30610.827692307692}, {75.2, 30633.06699300699}, {75.4,          30653.350000000002}, {75.6, 30666.33594405594}, {75.8,          30668.923426573427}, {76, 30668.75461538462}, {76.2,          30670.575314685306}, {76.4, 30670.93328671329}, {76.6,          30667.266083916085}, {76.8, 30663.819300699302}, {77,          30647.977062937065}, {77.2, 30618.72202797203}, {77.4,          30565.47013986014}, {77.6, 30508.620349650355}, {77.8,          30455.27230769231}, {78, 30410.724055944054}, {78.2,          30383.247272727276}, {78.4, 30363.072377622375}, {78.6,          30355.305034965033}, {78.8, 30342.20923076923}, {79,          30340.65146853147}, {79.2, 30337.188811188807}, {79.4,          30331.158181818184}, {79.6, 30315.162097902103}, {79.8,          30295.13181818182}, {80, 30271.48195804196}, {80.2,          30250.13118881119}, {80.4, 30224.207062937065}, {80.6,          30201.98300699301}, {80.8, 30170.62013986014}, {81,          30157.62923076923}, {81.2, 30143.96188811189}, {81.4,          30141.00909090909}, {81.6, 30117.328741258738}, {81.8,          30092.859790209794}, {82, 30056.212097902095}, {82.2,          30011.19230769231}, {82.4, 29951.637552447555}, {82.6,          29881.86965034965}, {82.8, 29809.408811188812}, {83,          29743.92013986014}, {83.2, 29687.225244755246}, {83.4,          29650.274545454547}, {83.6, 29609.51027972028}, {83.8,          29570.36111888112}, {84, 29528.284685314688}, {84.2,          29495.74104895105}, {84.4, 29464.83104895105}, {84.6,          29432.034545454546}, {84.8, 29397.90867132867}, {85,          29359.92979020979}, {85.2, 29328.5486013986}, {85.4,          29309.78937062937}, {85.6, 29295.625034965036}, {85.8,          29279.513916083917}, {86, 29255.218671328672}, {86.2,          29234.38566433567}, {86.4, 29227.73384615385}, {86.6,          29216.327202797198}, {86.8, 29201.22685314685}, {87,          29162.052937062937}, {87.2, 29113.863776223774}, {87.4,          29051.34391608391}, {87.6, 28988.94237762238}, {87.8,          28926.36160839161}, {88, 28856.33132867133}, {88.2,          28782.890699300704}, {88.4, 28712.760769230772}, {88.6,          28660.5920979021}, {88.8, 28620.868461538463}, {89,          28583.4386013986}, {89.2, 28546.60818181818}, {89.4,          28502.005384615386}, {89.6, 28462.87916083916}, {89.8,          28422.843076923076}, {90, 28389.142517482516}, {90.2,          28339.938461538462}, {90.4, 28275.94958041958}, {90.6,          28203.151538461538}, {90.8, 28132.62300699301}, {91,          28069.04839160839}, {91.2, 27992.026083916087}, {91.4,          27914.222797202798}, {91.6, 27834.239160839163}, {91.8,          27766.07118881119}, {92, 27716.52062937063}, {92.2,          27679.7613986014}, {92.4, 27652.8013986014}, {92.6,          27618.464055944052}, {92.8, 27588.78923076923}, {93,          27574.388531468536}, {93.2, 27566.27888111888}, {93.4,          27547.25811188811}, {93.6, 27502.117692307693}, {93.8,          27444.676573426572}};          ramp1FSmoothFunc[1] = Interpolation[ramp1FCelsiusXRFUSmooth[1]]               ClearAll[helixMidPoint, helixLineLength, helixLowPoint, \     helixLowPointRFU, helixHighPoint, helixHighPointRFU]     ClearAll[coilMidPoint, coilLineLength, coilLowPoint, coilLowPointRFU, \     coilHighPoint, coilHighPointRFU]     ramp1FCelsiusXRFUSmooth[1];     helixLowBarrier = 10;     helixHighBarrier = 40;     coilLowBarrier = 60;     coilHighBarrier = 90;          {Slider[Dynamic[helixMidPoint], {helixLowBarrier, helixHighBarrier}],       Dynamic[helixMidPoint],       Dynamic[helixMidPointRFU = ramp1FSmoothFunc[1][helixMidPoint]],       Slider[Dynamic[helixLineLength], {5, 25}], Dynamic[helixLineLength]}          {Slider[Dynamic[coilMidPoint], {coilLowBarrier, coilHighBarrier}],       Dynamic[coilMidPoint],       Dynamic[coilMidPointRFU = ramp1FSmoothFunc[1][coilMidPoint]],       Slider[Dynamic[coilLineLength], {5, 25}], Dynamic[coilLineLength]}          Dynamic[{ListPlot[{ramp1FCelsiusXRFUSmooth[          1], {{helixLowPoint, helixLowPointRFU}}, {{helixHighPoint,            helixHighPointRFU}}, {{coilLowPoint,            coilLowPointRFU}}, {{coilHighPoint, coilHighPointRFU}}},         ImageSize -> Medium,         PlotStyle -> {PointSize[Small], PointSize[Large], PointSize[Large],           PointSize[Large], PointSize[Large]}],            Grid[{{, "temperature (C)", "Interpolated RFU"}, {"helix low point",           Dynamic[helixLowPoint = helixMidPoint - helixLineLength/2],           Dynamic[helixLowPointRFU =             ramp1FSmoothFunc[1][helixLowPoint]]}, {"helix high point",           Dynamic[helixHighPoint = helixMidPoint + helixLineLength/2],           Dynamic[helixHighPointRFU =             ramp1FSmoothFunc[1][             helixHighPoint]]}, {, ,}, {"coil low point",           Dynamic[coilLowPoint = coilMidPoint - coilLineLength/2],           Dynamic[coilLowPointRFU =             ramp1FSmoothFunc[1][coilLowPoint]]}, {"coil high point",           Dynamic[coilHighPoint = coilMidPoint + coilLineLength/2],           Dynamic[coilHighPointRFU = ramp1FSmoothFunc[1][coilHighPoint]]}},         Frame -> All]}]          Dynamic[ramp1FBaseLinesTEST =        Plot[{ramp1FHelixLinFitEqTEST[temp],          ramp1FCoilLinFitEqTEST[temp]}, {temp, 1, 100}]]                         Dynamic[ramp1FHelixTEST =        Select[ramp1FCelsiusXRFUSmooth[1],         helixLowPoint <= #[[1]] <= helixHighPoint &]]          Dynamic[ramp1FHCoilTEST =        Select[ramp1FCelsiusXRFUSmooth[1],         coilLowPoint <= #[[1]] <= coilHighPoint &]]          Dynamic[ramp1FHelixLinFitTEST =        Fit[ramp1FHelixTEST, {1, temp}, temp]]     Dynamic[ramp1FHelixLinFitEqTEST[temp_] = ramp1FHelixLinFitTEST]     Dynamic[ramp1FCoilLinFitTEST = Fit[ramp1FHCoilTEST, {1, temp}, temp]]     Dynamic[ramp1FCoilLinFitEqTEST[temp_] = ramp1FCoilLinFitTEST]


title: Removing numerically vanishing complex part within NDSolve

text: I am using functions that are only well-defined for real values (e.g. `HeavisideTheta`) within `NDSolve`. Internally `NDSolve` works, of course, with complex numbers and sometimes returns a numerically vansihing complex value (e.g. 0.` i) that breaks these functions. Is it possible to get rid of the complex part (like applying `Chop` at each step)?


title: How to set row height in Grid?

text: I always thought that `Grid` (and the underlying `GridBox`) and the general handling of tabular objects is a bit weird in _Mathematica_. One particularly annoying fact is that while one can set column widths explictly, the same cannot be done to row heights, because each row is set to the height of its largest content by default. I don't really understand this asymmetry between the two dimensions. Does anyone have any insight on this matter? As a more specific question: How to set the row height to be exactly 1, by clipping the content if necessary (i.e. some part of it should not be visible)?               Grid[{       {"000000000\n111111111\n222222222", "000000000"},       {"000000000", "000000000"}       },      ItemSize -> {{10, 5}, {1, 1}}, Frame -> All]      ![Mathematica graphics](http://i.stack.imgur.com/h10dj.png) Can this be done with only `Grid` or do I have to map a `Pane` with explicit height value to each element (converting from pixels to ems, as `Pane` uses the latter)?


title: ParametricPlot3D doesn't appear

text: Here I have one simple system solvable with NDSolve. I don't know why ParametricPlot3D doesn't present trajectory in space. I have solutions for x[t], y[t] and z[t]                 ss = NDSolve[{x''[t] == -1^2*((1 + 1) x[t])/       Abs[(x[t]^2 + y[t]^2 + z[t]^2)]^(3/2),       y''[t] == -1^2*((1 + 1) y[t])/Abs[(x[t]^2 + y[t]^2 + z[t]^2)]^(3/       2), z''[t] == -1^2*((1 + 1) z[t])/       Abs[(x[t]^2 + y[t]^2 + z[t]^2)]^(3/2), x'[0] == 0, y'[0] == 0,      z'[0] == 0, x[0] == 1, y[0] == 10, z[0] == 1}, {x, y, z}, {t, 0,      1.2}];           ParametricPlot3D[{Evaluate[x[t] /. ss], Evaluate[y[t] /. ss],       Evaluate[z[t] /. ss]}, {t, 0, 1.2}]          Plot[Evaluate[x[t] /. ss], {t, 0, 1.2}, PlotRange -> All]     Plot[Evaluate[y[t] /. ss], {t, 0, 1.2}, PlotRange -> All]     Plot[Evaluate[z[t] /. ss], {t, 0, 1.2}, PlotRange -> All]


title: TrueQ - Test of inequality

text: I want to look if a term is `<0`,`>0` or `==0`. What is wrong when I write               a < 2 b;     b > 0;     a > 0;     TrueQ[Re[(3 a + 6 b +          Sqrt[9 (-36 + 7 a^2) + 4 a (-27 + 8 a^2)*b +            4 (-45 + 16 a^2) b^2 + 32 ab^3])/4 (a + b)] < 0]       It gives me `FALSE` every time regardless of whether I say `<0`,`>0` or `==0`. But I took the real part, hence it one case has to be `TRUE`! For a=2b               Simplify[Re[(-3 a - 6 b +         Sqrt[9 (-36 + 7 a^2) + 4 a (-27 + 8 a^2)*b +           4 (-45 + 16 a^2) b^2 + 32 a b^3])/4 (a + b)] < 0,      Assumptions -> {a > 0, b > 0, a = 2 b}]      I get               Re[Sqrt[-9 - 4 b^2 + 16 b^4]] < True      What does this means? **EDIT*** _EDIT_ * For               Simplify[Re[(-3 a - 6 b +         Sqrt[9 (-36 + 7 a^2) + 4 a (-27 + 8 a^2)*b +           4 (-45 + 16 a^2) b^2 + 32 a b^3])/4 (a + b)] < 0,      Assumptions -> {a > 0, b > 0, a == 2 b}]      I get Re[Sqrt[-9 - 4 b^2 + 16 b^4]] < 2 b Does this means that this is only true if Re[Sqrt[-9 - 4 b^2 + 16 b^4]] < 2 b ?


title: How to get 'exact' expression for result

text: I have a result from _Mathematica_ for which want to have the exact expression, i.e. all of the arguments of type `#` replaced. It is given by:               { a > 0,        Inequality[ 0, Less, r, LessEqual, Root[a^3 #1^2 + a^2 #1^4 - 22 a #1^6 + #1^8 & , 5]]}      where `a` and `r` are the only two variables. What exactly does the `#1` mean here? To which variables does it refer? How do I make _Mathematica_ replace all these place holders with its corresponding variable?


title: Drawing a quadrangular surface

text: Is there a way to draw a quadrangular surface in _Mathematica_ so that it shows the bilinear term (not two triangles)? The quadrangular polygon is given by the expression $$\phi = \sum_i^4 N_i U_i$$ where the $N_i$ are the Lagrangian shape functions (from finite element analysis), and the $U_i$ are the degrees of freedom. The shape functions are given by               N1[xi_, eta_] := (1 - eta) (1 - xi)/4;     N2[xi_, eta_] := (1 + eta) (1 - xi)/4;     N3[xi_, eta_] := (1 + eta) (1 + xi)/4;     N4[xi_, eta_] := (1 - eta) (1 + xi)/4;      So there is a bilinear term `xi*eta` that gives the curvature to the element.


title: Iteration problem

text: I am trying to write a simple program - perform `f1` as long as `t` is smaller than 800. `t` is declared in `a` list. The problem is easy, but difficult to explain, so I'll give You my code:               a = {t -> 120};     f1[{x_, y_}] := {x + t, y + t} /. a;     NestWhile[f1[#] &; a = a /. Rule[t, _] :> Rule[t, f1[#][[1]] &], {100, 100}, (t /. a) <= 800]      > ReplaceAll::reps: {{t->(f1[Slot[<<1>>]][[1]]&)}>=800} is neither a list of > replacement rules nor a valid dispatch table, and so cannot be used for > replacing. >> After each calculation step I want to change replacement rule in `a` list. Desired output should be `{880, 880}`. Any idea how to make it work? I know it sounds like a stupid example, but if can fix that, I can also fix problem with my original functions.


title: Minimum value with two factors

text: Approximate the minimum value of $2e^{x-2}-6x+xe^{x-2}$. Is my input correct? If not can you please correct it?                               In: MinValue[2 E^(x-2)-6 x+x E^(x-2), x]      I also read that you can find this answer by writing a program to to take the derivative to find this answer. Is this how you do it?                                   In[1]: f[x]= MinValue[2 E^[x-2]-6 x+x E^[x-2]      then it would give you the out[1]. Then you would do this:                                 In[2]:f'[x]      then it would give you out[2]. This is what I know. Can you please help me with the rest? I am trying to learn this by myself and it would be nice if you could help. I also did some research and this is what I came up with.


title: How to load thumbnail, not image?

text: Is there any way to import only the thumbnail of an image instead of the full image? I frequently work with lots of images and it would be nice if the contents of a directory could be quickly displayed as small images, without loading the full image. On my machine (2 x 2.4Ghz, 2GB ram, Win7, _Mathematica_ 8), loading 12 images (PNG, 1200x900, 45KB each) takes ~1.4 sec, which is a bit too much for delay.


title: How to save ChemicalData queries so that they are available immediately on notebook load?

text: If I put some viscosity (or density, ...) lookups in my notebook, such as:               muMercury = ChemicalData["Mercury", "Viscosity"] ;     muWater = ChemicalData["Water", "Viscosity"] ;      Then these are fetched each time the notebook is loaded, which is kind of slow (a little window pops up showing "Initializing Chemical Data Indices" while it does this lookup). Is there a way to cache these, without doing a kludge like manually copying the numeric values obtained from an initial call? I've got two reasons for asking. The first is just the slowness aspect, and the second is functional. I've got a `Manipulate` control that depends indirectly on these values, and when I start up the notebook for the very first time, it appears that my `Manipulate` executes before the preceding `ChemicalData` functions are evaluated. The `"Initializing ChemicalData indices"` doesn't occur until after an explicit evaluation.


title: Constraining function found by NDSolve to stay positive

text: I am trying to constrain my variables in `NDSolve` so that they stay positive for the integration interval. Is is possible to do that? Using Assumptions as in Simplify does not work. WhenEvent also does not help, as it just finds the event once. Here is a code snippet of a minimal example:               a = 10;     sol = NDSolve[{x'[t] == -10, x[0] == 10}, x, {t, 0, 10}];     Plot[Evaluate[x[t] /. sol], {t, 0, 10}, PlotRange -> All]      What I would like to get out is a function, that linearly decreases from 10 to 0 and stays on 0 -- instead of turning negative. ### Edit To clarify the question: I am using _Mathematica_ for fast prototyping. In a C environment I can modify the time integration with an additional step, like `if(x<0){ x=1e-10; }` to ensure my variable does not turn negative. So I am looking for a way to introduce a lower bound into my system. My full system consists of a system of 1st order nonlinear ODEs, which represent positive real quantities. I am aware that this modification will change the resulting solutions. The above just provides a minimal example of what I am looking for. Changing the rhs as suggested below will unfortunately not do the trick, as it only adjusts the rate of change but does not introduce a lower bound for the solution. (Although, strictly speaking this procedure will result in a solution I was describing above ;)


title: Exporting data from different notebooks to a common file

text: I am doing some calculations from different notebooks. I need to export the results from all those notebooks in columns of the same file, like > a1 b1 c1   >  a2 b2 c2   >  a3 b3 c3   >  . . . where a, b and c are the different notebooks.


title: FactorInteger over UFDs

text: How can I factor 'integers' over other quadratic number fields (not just gaussian integers). For instance, how could I factor $7 = (3 + ω)(2 − ω)$ over Eisenstein integers ($ω = \frac{-1+ I \sqrt{3}}{2}$) What I want to achieve is something like `Factor[n, Extension->Sqrt[n]]` Apologies for any misused terminology :)


title: Select rows from table by keys

text: I am looking for a way to iteratively select all sublists with the same ID (my 1st column, residual columns are `AbsoluteTime` entries). First, I obtained the list of unique IDs with `Union`. Then I want to use this list for the selection task. I assume that it must work with `Sequence` and `ReplaceAll`, but could not make it work. Here's what I have so far:               ticketList = Union[dataList[[1 ;;, 1]]];     tempList = Select[dataList, #1[[1]] == x &] /. x ->  Sequence[ticketList];      My ultimate goal is to build up a `TemporalData` array with all items which each belong to the same ID. My data is has dimensions `n x m`. The ticket list has dimension `t`. The resulting table should have dimensions `t x i x m`, where `i` is the cardinality of items with the same ID, and the `i`'s sum to `n`. I assumed, that I can then map `TemporalData` on every `t`-th item in order to build the temporal list. I searched the site but didn't find a previous question that seem to address my problem. Maybe I misunderstood the use cases of similiar questions.


title: Transparent Cylinder with Dashed Edges only

text: I would like to have that kind of cylinder with `Dashed` edges (including the bellow inner ring): ![Edged Cylinder](http://i.stack.imgur.com/D7u61.png) I've been trying that:               opt = {Mesh -> None, PlotStyle -> {Lighter@Black, Opacity[0.3]}};      Show[{     ParametricPlot3D[{r Cos@th,r Sin@th,#},{th, 0, 2 Pi},{r, 0.3, 0.31},Evaluate@opt] &/@ {0,2},      ParametricPlot3D[{# Cos@th,# Sin@th,z},{th, 0, 2 Pi},{z, 0, 2},Evaluate@opt] & /@ {.3, .31}}      ,PlotRange -> All, Axes -> False, Boxed -> False, ViewVertical -> {1, 0, 0}]      But I can't find out how to dash the edges. According to that answer I've been trying that:               tube = ParametricPlot3D[2 {Cos[t], Sin[t], u}, {t, 0, 2 Pi}, {u, -5, 5},                               Mesh -> None, PlotStyle -> {Opacity[0]}];     tube /. Polygon[a__] :> {EdgeForm[{Dashed}], Mesh -> All, Polygon[a]}      But it only dashes the mesh: ![Mathematica graphics](http://i.stack.imgur.com/GTF9U.png) And belisarius has been trying that:               RegionPlot3D[1 < x x + y y < 2 && -2 < z < 2, {x, -2, 2}, {y, -2, 2}, {z, -1/2, 1/2},                  Mesh -> False, BoundaryStyle -> Directive[Red, Thick, Dashed],                  BoxRatios -> {1, 1, 1/5}, Boxed -> False, Axes -> False]       Which doesn't give the transparency: ![Mathematica graphics](http://i.stack.imgur.com/tY6v7.png) Thus, **my question is** : is it possible to construct the first picture cylinder with `Dashed` Edges?


title: Interpolating a Bivariate Polynomial over a Finite Field

text: Let $F=GF(p)$ be a finite field, $p$ prime and write $F^\times=\\{x_1,\ldots,x_n\\}$. I'm trying to implement an earlier version of Sudan's list-decoding algorithm for Reed Solomon Codes $$RS(d+1,n+1)=\\{(f(x_1),\ldots,f(x_n))|f\in F[x], \deg f \leq d\\}$$ I would like to find a way to do the following in Mathematica: Let $(y_1,\ldots,y_n)\in F^n$. (1) Is there a way in Mathematica to solve a homogeneous linear system where the number of variables is greater than the number of constraints? Sudan's algorithm involves finding a polynomial $Q(x,y)$ (not identical to 0) with coefficients in $F$ such that $Q(x_i,y_i)=0$ for all $i$. The algorithm specifies that every monomial $cx^jy^k$ in $Q$ satisfy $j+kd\leq m+ld$, where $m=\left\lceil \frac{d}{2} \right\rceil-1$, $l=\left\lceil\sqrt{\frac{2(n+1)}{2}}\right\rceil-1$ and has $(m+1)(l+1)+d_f\binom{l+1}{2}$ unknowns. This entails solving the linear system $Q(x_1,y_1)=0,\ldots,Q(x_n,\ldots,y_n)$. I tried using `Solve[Q(x_1,y_1)==0 && ... && Q(x_n,y_n)==0, <list of the unknowns>, Modulus->n+1]` however, this methods doesn't work if the number of unknowns is greater than the number of constraints ($n$), which is the case here. (2) Factor $Q(x,y)$ into irreducible factors. Is there a way of doing this given that $Q$ has coefficients over a finite field. Here's a link to Sudan's paper. EDITS: As suggested, here is the actual code I used: The elements of the field are in the vector $x=$ `fieldx`. The input is the codeword $y=$ `rw`, and my desired output is a polynomial $Q(x,y)$ such that $Q(x_i,y_i)=0$ for all $i$.               q = 5;     k = 3;     n = q - 1;     d = k - 1;     m = Ceiling[d/2] - 1;     l = Ceiling[Sqrt[2(n + 1)/2]] - 1;     t = d*Ceiling[Sqrt[2(n + 1)/2]] - Floor[d/2];     Var = Array[f, (m + 1)(l + 1) + d*Binomial[l + 1, 2]];     Eqn = Array[b, Num];     Num = Length[Var];     Cons = Array[h, n];     Poly = Array[g, n];     fieldx = {1, 2, 3, 4};     rw = {1, 2, 2, 3};     For[i = 0, i < n, i++; h[i] = {}];     For[i = 0, i < n, i++;     For[j = -1, j < l, j++;       For[k = -1, k < m + (l - j)*d, k++;         Cons[[i]] = Join[Cons[[i]], {(fieldx[[i]]^k)*(rw[[i]]^j)}]]       ]];     Hom = {}; For[i = 0, i < n, i++; Hom = Join[Hom, {{0}}]];     For[i = 0, i < n, i++; Poly[[i]] = 0; Poly[[i]] = Total[Cons[[i]].Eqn]];     Eqn = Array[b, Num];     LinearSolve[Cons, Hom]     Solve[Poly[[1]] == 0 && Poly[[1]] == 2 && Poly[[2]] == 0 && Poly[[     3]] == 0 && Poly[[4]] == 0, Eqn]      This produces the matrix `Cons`               {{1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 2, 4, 8, 16, 2, 4, 8, 4}, {1, 3, 9, 27, 81,      2, 6, 18, 4}, {1, 4, 16, 64, 256, 3, 12, 48, 9}}      MORE EDITS: While the algorithm itself has several other details, I am mainly interested in FIRST QUESTION: How can I solve a linear system with more unknowns than constraints (which was addressed by Michael E2's answer below). Details on the algorithm are in Sudan's paper. I don't think I should discuss those details here as they would make my post extremely long (for instance, why I took the values of m and l as above). As to my SECOND QUESTION: How can I factor a bivariate polynomial over F - it turns out that the latest version of Mathematica can do this. Unfortunately, my current copy of Mathematica can only factor polynomials in one variable. When I try to evaluate, say, `Factor[6*x*y^2 + 2, Modulus -> q]`, I get the following error: `Factor::facmm: Factoring multivariate polynomials with respect to a modulus is not yet implemented.`


title: Image processing, masking

text: My question is about finding a object in a specific part of a image. For example, I use this image: As you can see, you will se two persons walking on the field. I only want to find the second person on the right site of center line ![enter image description here](http://i.stack.imgur.com/yF0XY.gif) If I use the following script, Mathematica find both.               Show[Image[picture1, ImageSize -> 600],       Graphics[{Red,         Table[Inset[ToString[i],           PixelValuePositions[foto17, {0.07, 0.09, 0.1}, .05][[i]]], {i, 1,           Length [           PixelValuePositions[foto17, {0.07, 0.09, 0.1}, .05]]}]}]];      Is there a way to select a specific part of a image? Fore example, something like this: ![enter image description here](http://i.stack.imgur.com/uI59o.gif)


title: Reduce the output from tuples by including symmetry?

text: I need all the possible 3x3 binary tensors, but I'd like to have this account for symmetries. I've started by using the Tuples command.               Tuples[{1, 0}, {3, 3}]      This tuples command produces 512 binary tensors. If I consider tensors that are symmetric by any permutation to be redundant, how can I remove the extraneous ones from the output? Here are a few examples of tensors that I'd like to consider as the same:               {{0, 1, 0}, {0, 1, 0}, {1, 1, 0}} // MatrixForm     {{1, 1, 0}, {0, 1, 0}, {0, 1, 0}} // MatrixForm     {{0, 1, 0}, {0, 1, 0}, {0, 1, 1}} // MatrixForm     {{0, 0, 1}, {1, 1, 1}, {0, 0, 0}} // MatrixForm      Additionally, I'd like to remove tensors that are equal if you replace the 1's with 0's, and vice versa, such that these two tensors are equivalent:               {{1, 0, 1}, {1, 0, 1}, {0, 1, 0}} // MatrixForm     {{0, 1, 0}, {0, 1, 0}, {1, 0, 1}} // MatrixForm      By my estimation, this should reduce the output from 512 to ~50 tensors. Any help would be greatly appreciated. **Clarification of "permutations" for the original question:** I'm not sure the most accurate way to describe it. Imagine taking a 3x3 array of 1's and iteratively changing each 1 to a 0 until you have an array of 0's. I consider a duplicate being an array that is identical under any rotation or mirror around any row or diagonal. For example, if you start with:               {{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}       There are only three distinct 1's that can be removed:               {{0, 1, 1}, {1, 1, 1}, {1, 1, 1}}     {{1, 0, 1}, {1, 1, 1}, {1, 1, 1}}      {{1, 1, 1}, {1, 0, 1}, {1, 1, 1}}


title: Experiment with TagSetDelayed involving Part

text: Reading Associating Definitions With Different Symbols, I was intrigued by this: > You can think of upvalues as a way to implement certain aspects of object- > oriented programming. A symbol like `quat` represents a particular type of > object. Then the various upvalues for `quat` specify "methods" that define > how `quat` objects should behave under certain operations, or on receipt of > certain "messages". To play with this idea, I attempted to implement a variation on `List` called `ContiguousOrderedIntegerMap`: like `List`, but any attempts to _get_ an index beyond its length return `Null`; and any attempts to _set_ an index beyond its length automatically fill intermediate indices with `Null`. I started,               ClearAll[ContiguousOrderedIntegerMap, foo, bar];     SetAttributes[ContiguousOrderedIntegerMap, HoldAll];     ContiguousOrderedIntegerMap /:        Part[ContiguousOrderedIntegerMap[expr_], i_] := (        If[Length@expr < i, expr = PadRight[expr, i, Null]];        return = expr[[i]];        expr = ContiguousOrderedIntegerMap@expr;        return        );     foo = {100, 200, 300};     bar = ContiguousOrderedIntegerMap@foo;     Print@bar;     Print@bar[[2]];     Print@bar[[5]];          (* ContiguousOrderedIntegerMap[foo] *)     (* 200 *)     (* Null *)      This is however, of course, wrong, because I'm mistakenly modifying `foo` instead of `bar` and creating nonsense recursion, _i.e._               foo = ContiguousOrderedIntegerMap[foo];      So, the first thing I'm stuck on is, **How can I access the _symbol_ passed into `Part`?** Scanning through all Mathematica's available operators, I came across Pattern (:), which seemed like exactly what I needed, and applied it like so:               ContiguousOrderedIntegerMap /:        Part[symbol : ContiguousOrderedIntegerMap[expr_], i_] := (        Print@symbol;          (* ContiguousOrderedIntegerMap[foo] *)      But wait, instead of `bar`, I got back `bar`'s OwnValue. Why? Ah, because `Part` evaluates its first argument:               Attributes[Part]          (* {NHoldRest, Protected, ReadProtected} *)      So, what's next? Do I find some way to set `HoldFirst` on `Part` only when applying to a `ContiguousOrderedIntegerMap`? (If that's even possible.) Instead, is there a more obvious, idiomatic way to go about this all? I have other questions in mind, _e.g. "How do I set a separate UpValue for`Set` given that attempting to `TagSet` `Part[Set[...]]` would push `ContiguousOrderedIntegerMap` a level too deep?"_. However, I end my question here for now, since it's where I'm stuck, and I'll probably need to edit this question a few times as I receive help and make progress.


title: ParallelTable and DistributeDefinitions

text: I have a function in the following form:               function[...] := With[       {...},       Table[         anotherfunction[i, j, ...],         {i, ...},         {j, ...},         ...       ]     ]      If I'd like to replace `Table` with `ParallelTable`, do I need to put `DistributeDefinitions["Global`"]` somewhere? If yes, where? (Before `With`, before `ParallelTable`, or before calling `function`?) `anotherfunction` is defined globally, and uses other global variables.


title: How to improve the solution of a double pendulum system

text: First, the code:               (* numerical solution of the double pendulum system in polar coordinates *)     sol = Flatten[{v1, v2, θ1, θ2} /.         NDSolve[{v1'[t] == -l^2/         2 (3 g/l Sin[θ1[t]] + θ1'[t] θ2'[             t] Sin[θ1[t] - θ2[t]]),       v2'[t] == -l^2/         2 (g/l Sin[θ2[t]] + θ1'[t] θ2'[             t] Sin[θ1[t] - θ2[t]]),       θ1'[t] ==         6/(m l^2) (         2 m v1[t] - 3 Cos[θ1[t] - θ2[t]] m v2[t])/(         16 - 9 Cos[θ1[t] - θ2[t]]^2),       θ2'[t] ==         6/(m l^2) (         8 m v2[t] - 3 Cos[θ1[t] - θ2[t]] m v1[t])/(         16 - 9 Cos[θ1[t] - θ2[t]]^2),            θ1[0] == π/2, θ2[0] == π/2,        v1[0] == v2[0] == 0       } /. {g -> 9.81, l -> 1, m -> 1}, {v1,       v2, θ1, θ2}, {t, 0, 20}     ]]          (* cartesian coordinates of pendulum ends *)     x1k[t_, l_] := l Sin[sol[[3]][t]]     y1k[t_, l_] := -l Cos[sol[[3]][t]]     x2k[t_, l_] := l (Sin[sol[[3]][t]] + Sin[sol[[4]][t]])     y2k[t_, l_] := -l (Cos[sol[[3]][t]] + Cos[sol[[4]][t]])          (* corresponding plot *)     ParametricPlot[     Evaluate[{{x1k[t, l], y1k[t, l]}, {x2k[t, l], y2k[t, l]}} /. {l -> 1}], {t, 0, 20}]      > ![double pendulum plot](http://i.stack.imgur.com/0SCk6.png) As you can see, the function for the position of the second pendulum's end is very inaccurate, so the red curve is jagged instead of smooth. I have tried with specifying various options to `NDSolve`: `AccuracyGoal`, `InterpolationOrder`, `MaxStepFraction`, `PrecisionGoal`, but neither seemed to help.


title: A question about two ways to use Default

text: Usually we define a function with default values by the syntax `x_:default`, but there is another technique to do this by registering a global default value with `Default`. In the Document, there are three ways to use `Default`, two of which have confused me. The document tells that > `Default[f,i]` gives the default value to use when _. appears as the i-th > argument of f , while > `Default[f,i,n]` gives the default value for the i-th argument out of a > total of n arguments . Therefore, I have tried the following comparison:               Default[f, 1] = a1;     Default[f, 2] = a2;     Default[f, 3] = a3;     f[x_., y_., z_.] := {x, y, z}     {f[], f[1], f[1, 2], f[1, 2, 3]}      The result is `{{a1, a2, a3}, {1, a2, a3}, {1, 2, a3}, {1, 2, 3}}`.               ClearAll[f];     Default[f, 1, 3] = a1;     Default[f, 2, 3] = a2;     Default[f, 3, 3] = a3;     f[x_., y_., z_.] := {x, y, z}     {f[], f[1], f[1, 2], f[1, 2, 3]}      This give the same result. It seems that there is no difference between these two ways to use `Default`. If there were no difference, why would the document list the two ways? I'd appreciate it if someone could provide some information.


title: Plot3D list elements

text: I've been having some trouble with `Plot3D`. I have a quite complex function of two variables (actually three but the first one doesn't matter) that returns a list with two elements. Then I wrote the following code to see the behaviour of the first element:               Module[{R = 1},      Plot3D[       g[R, θ, z][[1]],       {θ, 0, Pi}, {z, 0, 4},        AxesLabel -> {θ, z, Subscript[F, θ]}       ]      ]      Well the thing is: when the coordinate $\theta=0$, the first element is zero and the plot doesn't show that: ![enter image description here](http://i.stack.imgur.com/zg9vA.jpg) I know that the problem isn't from the function because if I plot the first element keeping $\theta=0$:               Module[{R = 1},      Plot3D[       g[R, 0, z][[1]],       {θ, 0, Pi}, {z, 0, 4},        AxesLabel -> {θ, z, Subscript[F, θ]}       ]      ]      (in the code I only changed that $\theta \to 0$) it outputs correctly: ![enter image description here](http://i.stack.imgur.com/gGTSn.jpg) Moreover, If I use `Manipulate` it behaves as expected; so I must be doing something wrong with `Plot3D`... can anyone help me? **PS:** Here is the horrible definition of the function $g$:               g[R_, \[Theta]_,         z_] := (Module[{For1 = 0, For2 = 0, d1 = 0, d2 = 0, Forca = {0, 0},           nmax = 10},              If[\[Theta] == 0,          For[n = 0, n < nmax,            d1 = Sqrt[R^2*(2 Pi*n)^2 + z^2];            If[n == 0,             If[d1 + 0.0 < R*Pi,               For1 = -1/(2 Pi*d1^2);               Vec1 = {0, z};               ,               For1 = -1/(4*d1^2*ArcSin[R*Pi/d1]);               Vec1 = {0, z};                ];             ,             For1 = -1/(4*d1^2*ArcSin[R*Pi/d1]);             Vec1 = {0, z};             For2 = -1/(4*d1^2*ArcSin[R*Pi/d1]);             Vec2 = {0, z};              ];            Forca += For1*Vec1 + For2*Vec2;            ++n;             ];            (*Here works iff \[Theta]=0*)            ,            For[n = 0, n < nmax,              d1 = Sqrt[R^2*(\[Theta] + 2 Pi*n)^2 + z^2];              d2 = Sqrt[R^2*(-2 Pi*(n + 1) + \[Theta])^2 + z^2];                   If[d1 + 0.0 < R*Pi,                  For1 = -1/(2 Pi*d1^2);                  Vec1 = {\[Theta], z};                  ,                   For1 = -1/(4*d1^2*ArcSin[R*Pi/d1]);                   Vec1 = {\[Theta] + 2 Pi*n, z};                   ];                    If[d2 + 0.0 < R*Pi,                   For2 = -1/(2 Pi*d2^2);                   Vec2 = {-2 Pi*(n + 1) + \[Theta], z};                   ,                   For2 = -1/(4*d2^2*ArcSin[R*Pi/d2]);                   Vec2 = {-2 Pi*(n + 1) + \[Theta], z};                    ];                Forca += For1*Vec1 + For2*Vec2;                ++n;                ]          (*Here works for all points except \[Theta]=0*)            ];              N[Forca]         ]        );


title: Exporting large numbers in WDX format

text: I have a list of 10 000 3×3 matrices in Mathematica. The entries are rational numbers. I would like to write this to a file so I can load it again in the future. After some fussing with file formats, it looks like the one I'd like to use is "WDX". However, some of my numbers are quite large, and don't seem to want to export. Does anyone know a good way around this issue? I can reproduce the sort of problem I'm having just by running:               Export[NotebookDirectory[] <> "junk.wdx", {42838805520130}, "WDX"]      which returns               BinaryWrite::nocoerce: 42838805520130 cannot be coerced to the specified format. >>      I've used the "MX" file format, which works well, but I want to be able to import the file on another computer. Other file types don't seem to work so well. (For example, the "Table" format bizarrely introduces extraneous commas.)


title: How to work around Column cutting off a pixel row from images?

text: I have a problem where `Column` will occasionally cut off a single pixel from the top of images. To reproduce the problem, evaluate this:               image = Import["http://i.stack.imgur.com/2dEty.png"]     Column[{"text", Image[image, Magnification -> 1], "text"}]      The output I get looks like this in the front end: ![Mathematica graphics](http://i.stack.imgur.com/VJqZh.png) Note that in `Out[2]` a single pixel wide row is cut off from the top of the image. It does not occur with all images, but it does with this particular one. **How can I work around this problem?** This is on Win7. Can you reproduce on other platforms? I need this for the image uploader palette (`SOUploader`uploadWithPreview[]` function to be specific). * * * It is interesting to note that if I wrap the image in a `Pane`, and set a pane-size explicitly (as in the original code of the palette), whether the row is cut off depends on whether the size is even or odd (I suspect a rounding issue): Try this and notice that the cropping happens for even `k` only:               Table[      Column[{"text",         Pane[Image[image, Magnification -> 1],          ImageDimensions[image] + {0, k}], "text"}],      {k, 0, 5}      ]


title: FullDefinition and Module local variable

text: I have a question about `FullDefinition` and how it interacts with the local variables of `Module`. I've created a few functions (with `Module`) and I wanted to save their definitions, so I can use them later. These functions call other functions and so I wanted to use `Save` to have their `FullDefinition` saved. The problem I have is that when I do this, it also saves whatever variable which happened to have the same name of that one of the local `Module[]` variable. A simple example would be :               g[t_] := 5*t;     f[t_] := Module[{c},       c = g[t];       Return[c]       ]      I use another variable :               c = 2;      and now if I call `FullDefinition[]` :               FullDefinition[f]     (*         f[t_] := Module[{c}, c = g[t]; Return[c]]         c = 2         g[t_] := 5 t   *)      I don't really understand why `FullDefinition` contains the global assignment of c, and it's really a problem if I don't want global variables to pollute my saved file. I don't want them to be loaded every time I load the functions.


title: Why doesn't ParallelMap improve the performance of FoldList?

text: This question arose during my analysis of the following problem: filling gaps. (The code used here is Simon Woods's work.) `FoldList` seems to not cooperate with `ParallelMap` and I do not understand it:               f[_, y_] := y     f[x_, "."] := x          fill[data_] :=       Transpose[FoldList[f, First[#], Rest[#]] & /@ Transpose[data]]          fillP[data_] := Transpose[       ParallelMap[        FoldList[f, First[#], Rest[#]] &,        Transpose[data]]       ]          data = Table[RandomChoice[{1, "."}], {10^6}, {4}]~Prepend~(Range@4);      Timings are as follows:               fill@data; // Timing // First (* -> 3.868825 *)     fillP@data; // Timing // First (* -> 4.056026 *)


title: Hue-like Legend spectrum with bright colors for a plot

text: I use `Hue` to color `ArrayPlot`:               Needs["PlotLegends`"]     GraphicsRow[{      ArrayPlot[gridmatrixpair, Mesh -> False,         ColorFunction -> (         Which[2.0 < #[[1]] < 4.9 && 3*10^8 > #[[2]] > 1*10^6,                Hue[(#[[2]] - 1*10^6)*3.344*10^-9],               True, White              ] &),         ColorFunctionScaling -> False, AspectRatio -> 2/7,         FrameLabel -> {y, x}      ],       Graphics[        Legend[ColorData["Rainbow"][1 - #1] &, 10, "10^6", "10^8",          LegendShadow -> None, LegendLabel -> "Power (a.u.)"]]     }]      ![enter image description here](http://i.stack.imgur.com/UzsUE.png) But as you see the colors in `ArrayPlot` are brighter than the rainbow colors for the legend. I did not find another `ColorData` object with brighter colors. What can I do, the scale is changing on and on for different notebooks, so the scale spectrum should be part of the `Legend` object.


title: What is the fastest way to obtain the eigenvalues of a Wishart matrix?

text: I would like a fast method of creating a sample of random numbers which corresponds to the eigenvalues of a Wishart matrix: ![definition of Wishart matrix](http://i.stack.imgur.com/6xYr3.png) For M>N the eigenvalues \lambda_i are given by the jpd ![eigenvalue distribution](http://i.stack.imgur.com/WA02Y.png) Where $K_N$ is a normalisation constant and $\beta = 1,2$ depends on whether $X$ is real or complex. Does anyone have any suggestions for a fast way of implementing this? My goal is to play with multiple realisations of eigenvalues representing 100x100 matrices. Many thanks in advance! EDIT: Ok, here is a very basic example:               n = 1000;     m = 1001;     μ = 0;     σ = 1/Sqrt[n];     AbsoluteTiming[     a = RandomVariate[NormalDistribution[μ, σ], {n, m}];     wish = a.a\[ConjugateTranspose];     ewish = Eigenvalues@wish;     ]     ewishPlot = Histogram[ewish, {0.1}, "PDF"];          ηp = n σ^2 (1 + Sqrt[η])^2;     ηm = n σ^2 (1 - Sqrt[η])^2;     η = m/n;     ρmp[λ_] := 1/(2 π n σ^2 λ)Sqrt[(ηp - λ) (λ - ηm)];     ρmpPlot = Plot[ρmp[λ], {λ, 0, 4}];     Show[ρmpPlot, ewishPlot]      I guess speed won't be a problem but I would still very much like to know the best way of doing this.


title: Manipulate Controller - Simplex

text: Imagine you have three numbers `a`, `b` and `c`, and using `Manipulate` you wish to combine them in the following way: `x a + x2 b + (1-x-x2) c`. Here, `x`, `x2` and `x3 = 1-x-x2` must all be between `0` and `1`.This means `x`, `x2` and `x3` form a two-dimensional simplex within a three-dimensional space. Does anyone have a nice idea of how to create a simplex (triangular) controller which allows me to move `x` and `x2`, such that `x3` is always between `0` and `1`. I hope this is clear, at least to the people who know what a simplex is. The solution might be a `Slider2D` with some constraint. Thanks!


title: Generating a list of pure variables

text: I want to pass a list of pure variables to a function, in which the ordering of the variables matters. For instance, if I want a palindrome, my function might be:               func[{#1,#2,#2,#1}&]      I want to be able to generalise this to an arbitrary number of variables:               func[{#1,...,#n,...,#1}&]      So what I want is a simple way to write a function g[n] that calls func with n variables. How to achieve this? I've tried generating the list {#1,...,#n,...,#1}& with a Table, but it seems Mathematica is not interpreting the ampersand correctly.


title: Matrix consisting of the matrices

text: I need Dirac Matrix in my work. They consists of PauliMatrix and ZeroMatrix, which is:               ZeroMatrix:=IdentityMatrix[2]-IdentityMatrix[2]      I define Dirac Matrix as:               gamma = ({{PauliMatrix[0], ZeroMatrix}, {ZeroMatrix, -PauliMatrix[0]}}) // MatrixForm;      I got such result: ![enter image description here](http://i.stack.imgur.com/Wvc1i.gif) But I need something else: I need a monolithic table, does not consist of individual blocks. How can I get it? (I need something universal, because I need to use it to construct 4 gamma matrices and spinors).


title: How to construct matrix by using already-defined matrix?

text: I'm trying to construct the matrix by using matrices which are already defined. For example, I would like to construct the following matrix 1 0 0 1 And each elements are 2-by-2 matrix like 1 is for 2-by-2 identity matrix and 0 is for 2-by-2 zero matrix. If I already defined the identity matrix and zero matrix, is there any way to construct the above matrix in terms of these matrices? I really don't want to type like 1 0 0 0 0 1 0 0 .... to build my matrix.


title: How to Flatten Array of Arrays of the highest order in a simple way?

text: I have a matrix of matrices, given in the following code. I want to flatten the array...               e1[l_] = Table[{KroneckerDelta[l, m]}, {m, 1, 2}];          σ[l_, m_, k_] = e1[l].Transpose[e1[m]];      na = 4;     Sigma[l_, m_] := TensorProduct @@ Table[ σ[l, m, k], {k, 1, na}]     Sigma[1, 1] // MatrixForm      ![enter image description here](http://i.stack.imgur.com/fLKG2.gif) I can do this, but if `na` is very large then this method:               ArrayFlatten[ArrayFlatten[ArrayFlatten[ArrayFlatten[Sigma[1, 1]]]]] // MatrixForm      is not convenient.


title: Styling ticks in a plot

text: I managed to turn the ticks inside-out but the ticks go now through the numbers. In fact I would like to have it like in the picture attached (ticks pointing outside the plot and no additional ticks between the numbers). Has anyone a suggestion?               data={-1.2056,-(7288960271654/4985881289361),-1.30053,-(33199059446612625/13128459048331036),-(5130109517723890585/5148852459134416857),-1.73904,-1.164,-1.83398,-0.97505,-(152151059187768664247/302333262014074402254),-(33596749386427335752225/52657796909983176600514),-0.785963,-0.398132,-(2414923435622638997136189344226575/3392598745831412249336953513454508),-0.820439};     a=First[HistogramList[data]]     b=Range[Max[Last[HistogramList[data]]]]     Histogram[       data,       BarOrigin->Left,       Axes->False,       Frame->{{True,None},{True,None}},       FrameTicks->{                   {Transpose[{a,a,Table[{-0.02,0},{i,Length[a]}]}],None},                   {Transpose[{b,b,Table[{-0.02,0},{i,b}]}],None}                   }     ]      ![Example](http://i.stack.imgur.com/Rmrkp.png)


title: Zero order term in an exprerssion

text: I have a very long expression like `a + b x/y + f + c y/x + d (x z)/y + ...` where `a , b, c, f ...` are coefficients and `x,y,z,...` are variables. I need to pick up the terms without variables which are `a , f` here how can I do this? Or even collection of the zero order terms will be helpful.


title: Typography messed up in prints

text: For a long time now I've had trouble printing Mathematica files. While the .nb itself displays just fine on my screen, the kerning is awful when printed. **Screen:** > ![enter image description here](http://i.stack.imgur.com/hh2Es.png) **Print:** > ![enter image description here](http://i.stack.imgur.com/VMOGY.png) And in case you thought that's not _too_ bad, here's a picture of a longer passage: > ![enter image description here](http://i.stack.imgur.com/QnBW0.png)   * The stylesheet I use is just a slightly modified version of the default stylesheet (which experiences the same problems)   * If it's any help, I'm on Mathematica 8.0.4.0, Ubuntu 11.04.   * Code sections are printed correctly! The error occurs for pretty much everything else, including plot labels, ...   * If you want to see the horror for yourself, I've uploaded a nb (using the default stylesheet) and a few prints: [tgz] [zip]


title: Plotting function with Dynamic parameter

text: I'm trying to get this code working:               a = 2;     func[t_] := Dynamic[t + a];     Plot[func[t], {t, -5, 5}]      The idea is: I'd like to have the dynamic parameter a change the graph, without the need of actually re-evaluate the `Plot` command after each change of the parameter `a`. But this code delivers no plot printed on the screen. I've tried adding an `Evaluate` command as well, without luck. What am I missing of the `Dynamic` command? Or where did I do something wrong? Thank you all for your answers and your help!


How do you export the result of a RevolutionPlot3D to STL for printing? I am a tyro when it comes to 3D rendering and printing. Thanks for any help. Jeff Thomson


title: How can I change VertexWeights in a Graph?

text: I evaluate               gt = Graph[{"A" <-> "B", "B" <-> "C", "A" <-> "C", "C" <-> "D"}, VertexLabels -> "Name"]     gt = SetProperty[{gt, "B"}, VertexWeight -> 3];        I check that the property is set.               PropertyValue[{gt, "B"}, VertexWeight]      > >     3 >   Next I evaluate               gt = SetProperty[{gt, "A"}, VertexWeight -> 4];        and check               PropertyValue[{gt, "A"}, VertexWeight]      > >     4 >   Then I check to confirm the `B` vertex still has the weight I set               PropertyValue[{gt, "B"}, VertexWeight]      > >     1 (* should be 3 *) >   Any ideas what I'm doing wrong?


title: Graphics always rendered twice with SimpleFrontEnd example?

text: I am looking at the Java `SimpleFrontEnd` example provided by _Mathematica_. Everything goes well except it always renders graphics twice. ![enter image description here](http://i.stack.imgur.com/ya33f.png) Can anyone help me with this? BTW: I am using version 9 under ubuntu 14.04 (32 bit).


title: SetPrecision with indexed variables

text: I have an expression as below:               Equations = 2.0799361919940695` x[1] + 3.3534325557330327` x[1]^2 -         4.335179297091139` x[1] x[2] + 1.1989715511881491` x[2]^2 -         3.766597877399148` x[1] x[3] - 0.33254815073371535` x[2] x[3] +         1.9050048836042945` x[3]^2 + 1.1386715715291826` x[1] x[4] +         2.802846492104668` x[2] x[4] - 0.6210244597295915` x[3] x[4] +         4.943369095158792` x[4]^2      I want to write it in an output file. So I use the below code:               removebracketvar[x_] :=        StringReplace[        StringReplace[         ToString[x], {"[" -> "", "]" -> "", "," -> "", "*^" -> "e",           ".*" -> ".0*"}], Whitespace -> ""];     SetDirectory["C:\\folder"];     WriteString["eqfile.txt",        removebracketvar[        ToString[Equations , InputForm, NumberMarks -> False]] ];     Close["eqfile.txt"]      The slight problem with the code for me is that it inserts the floating point numbers up to 16 digits of precision. I just want them to around up to 10 digits of precision. When I use `SetPrecision[Equations,10]`, it weirdly changes `x[1]` etc. to `x[1.0000000]`, etc.! I want to leave the variables as they are but want to change the floating points to less number of digits after the decimal point. What would be the best way of doing this?


title: Issue with PieChart3D in Version10. Is it Mac specific?

text: I was testing version 10 to see if the `ImagePadding` bug described here had been fixed and came across a significant issue. The chart (code from linked question) took "forever" to render. `AbsoluteTiming` wrapped around the code kept telling me the timing was ~0.3sec. However the cell bracket remained "active" for ages -- a little after a minute the cell bracket went "inactive" and the chart was rendered in output (I used a stopwatch since the built in timing functions were not capturing the real world delay): ![enter image description here](http://i.stack.imgur.com/cFf6s.png) After experimenting it seems that the problem was arising from `ChartElementFunction -> ChartElementDataFunction["ProfileSector3D", "Profile" -> 4]`               PieChart3D[{data[[All, 2]]},       ChartElementFunction ->        ChartElementDataFunction["ProfileSector3D", "Profile" -> 4],       ChartStyle -> 54, ImageSize -> 400, ImagePadding -> All,       LabelingFunction -> labeler[data[[All, 1]]],       PerformanceGoal -> "Speed", PlotRange -> All,       SectorOrigin -> {Pi, 0}, SectorSpacing -> 0.2]      Further testing showed this problem to occur **only** when both `ChartElementFunction` and `SectorOrigin` where present as options as you can see in the grab below: ![enter image description here](http://i.stack.imgur.com/xAex9.png) However the examples in the docs for `ChartElementFunction` rendered ok -- but these have `SectorOrigin -> {Automatic, 1}`. So it seems that it is the first position in the `SectorOrigin` list that is the culprit (but only when combined with this `ChartElementFunction` ...I haven't tested other types of `ChartElementFunction` ...yet). I am running V10.0.0.5098698 on OS X 10.9.4 ![enter image description here](http://i.stack.imgur.com/IPLvh.png) It appears others are having no problems on both Mac and Windows. Further monitoring shows the CPU load rising quite dramatically as the front end begins to crap itself: ![enter image description here](http://i.stack.imgur.com/agJoO.png) ![enter image description here](http://i.stack.imgur.com/nkhkf.png) ![enter image description here](http://i.stack.imgur.com/oSwl2.png) The above was after a restart. The CPU time elapsed (~ 1 minute) is indicative of how long it took for the output to be rendered. When I close V10 and run the same code in V9 output is "instantaneous." **Also even when the chart is rendered this is not the end of the problem. As soon as the cursor is over the rendered chart the front end freezes again -- CPU usage goes to 100%.** There is nothing in the underlying box code to indicate what the problem may be. Comparing V9 to V10 I notice that `EdgeForm[GrayLevel[0.5]]` in V9 output has been replaced by `EdgeForm[{GrayLevel[0],Opacity[0.1]}]` in V10 output, however this replacement occurs in both the working version in 10 (the first example below) and the freezing version. So that doesn't appear to be the issue. Some test input: This should work ok:               PieChart3D[{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14},       ChartElementFunction ->        ChartElementDataFunction["ProfileSector3D", "Profile" -> 4],       SectorOrigin -> {Automatic, 0}]      This next example should take a minute (literally) to render (WARNING. save your work. If you evaluate this >2 times the front end might soil its pants and crash):               PieChart3D[{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14},       ChartElementFunction ->        ChartElementDataFunction["ProfileSector3D", "Profile" -> 4],       SectorOrigin -> {Pi, 0}]      **Update** Szabolcs sent me a notebook in which he'd rendered the pie chart. The notebook opened instanteously but as soon as I placed the mouse over the pie chart the front end crapped itself.


title: Infinite Expression Error from NDSolve

text: I am trying to solve a differential equation numerically. So I have               zSolutionRule = NDSolve[        {         z''[x]*z[x] - z'[x]^2 - z[x]^2 - p0[x]*z[x]^3 == 0,         p0'[x] == 0,         z'[0]*E == z'[1],         z[0] == 1,         z[1] == E        },        {z, p0}, {x, 0, 1}       ];      When I run this, though, I get an "infinite expression $\frac{1}{0}$ encountered" error, but I want to get the solution to the differential equation. How do I get NDSolve to give me the solution like it does with other differential equations? (I am using Mathematica 9.0.0.0.) ## Background At first I solved a related differential equation               ySolutionRule = NDSolve[        {y''[x] - 1 - p0[x]*Exp[y[x]] == 0,         p0'[x] == 0,         y'[0] == y'[1],         y[0] == 0,         y[1] == 1         },        {y, p0}, {x, 0, 1}        ];     ySolution = y /. ySolutionRule[[1, 1]];     chargeNormalization = (p0 /. ySolutionRule[[1, 2]])[.5];      and this worked just fine, but I figured I could try to change variables to see if eliminating the exponential would change how good the solution is if I change boundary conditions when y[1] is big. So I rewrote the equation in terms of $z=e^y$. I can check that the exponential of ySolution satisfies the transformed differential equation and boundary conditions:               zSol[x_] := Exp[ySolution[x]];     zSol[1]/zSol[0] - E     zSol[0] - 1     zSol[1] - E      and               Plot[zSol''[x]*zSol[x] - zSol'[x]^2 - zSol[x]^2 -chargeNormalization*zSol[x]^3, {x, 0, 1}]      It does, up to some accuracy. So then I tell it to find my solution but instead, it gives me an infinite expression error.


title: Mathematica giving infinity as a random number!

text: I am trying to generate several random numbers from normal distribution using _Mathematica_. The following is the relevant code:               Clear["Global`*"];     SeedRandom[8396]     Sigma = 1;     Dim = 4;          A = RandomReal[NormalDistribution[0, Sigma], Dim,         WorkingPrecision -> 6];     B = RandomReal[NormalDistribution[0, Sigma], {Dim, Dim, Dim},         WorkingPrecision -> 6];      F = RandomReal[NormalDistribution[0, Sigma], {Dim, Dim, Dim, Dim},         WorkingPrecision -> 6];       Now, when I print out `B`, there are several infinities! `B` looks as follows:               {{{-1.92981, -1.21226, -0.244472, -0.00362004},        {0.700307, 1.49892, 0.874067, -0.539336},        {-0.643797, 0.356028, \[Infinity], -\[Infinity]},        {-0.130875, -0.379856, 2.20859, 1.65716}},       {{-1.87016, 0.478610, 0.261428, -1.15096},        {-0.0967131, 1.75239, -0.130795, -0.488940},        {-0.771886, 1.04727, -0.499386, 0.180890},        {-0.844033, 0.439520, -0.153382, 0.0686604}},       {{1.75313, -0.917641, -0.222227, 0.746214},        {1.40456, -0.249076, 1.90326, 0.436745},        {1.14792, 0.369685, 0.00756157, 0.407814},        {1.47316, 1.60401, 0.923612, -0.776877}},       {{0.764598, -1.58140, 1.66268, -1.93439},        {-0.520680, 0.227234, 0.908374, -1.11542},        {-2.28119, -1.58329, -0.536070, 0.209272},        {-0.157313, -0.0102335, -0.225685, -0.198312}}}      How is it possible? It shouldn't be because of the `WorkingPrecision->6`, is it?! This happens to specific `RandomSeed`, e.g., in this case, 6893. For other `RandomSeed`, I don't get this problem! I want to leave `WorkingPrecision->6` as it is to avoid larger floating numbers in the computation, unless it is this specific option that's the problem. Any idea?! Thanks.


title: Documentation for user-defined functions; undocumented documentation feature?

text: I stumbled on some strange behaviour when trying out the new function template and documentation features, now purportedly working in v 9.0.1. I defined a function `f` and `f::usage="f[x] does something to x"`. Typing `f` and then `Cmd+Shift+K` pulls up a tab and, as with built-in functions, there is an area marked `Documentation` underneath the completion section. Clicking on that (I always wanted an easy way to extend the built-in documentation; the approach described in this question is rather too much of a meal for me) I was given what looks like a notebook view on a directory (the directory shown is the working directory for my notebook): ![Opening a directory](http://i.stack.imgur.com/6XqgA.png) Feeling foolhardy, I thought I'd try to save it (well, I do have a recent bootable backup, TM snapshots and my files are under git/Dropbox control): ![Undocumented feature\(?\) -> error message](http://i.stack.imgur.com/baoOL.png) I was relieved to find that the file could not be written, as it seems to correspond to a directory, which I don't think you can open via the front end and I hope can't be directly written in that way either? It can be "saved as", default being `Consultancy.txt` So, to my question: bug or (undocumented?) feature? Can I use this to do something useful for documentation of my own functions?


title: Drawing an arrow pointing at the "Enable Dynamics" button

text: Sometimes my students are given Mathematica notebooks as part of an assignment, and asked to go through some demonstrations contained in the .nb file. A lot of times I get complaints that the "graphs aren't showing up" or "all I see is lines of code". The problem usually is that they haven't enabled dynamics on that particular notebook. What I'd like to do is have an arrow contained in the notebook that points directly at the "Enable Dynamics" button which shows when a notebook is opened. Then, once the button is clicked, _the arrow disappears_. I know how to draw an arrow, but what I don't know how to do is:   1. Have that arrow point to the corner of the notebook window, where the button is;   2. have that arrow disappear once the button is clicked. Any help or pointers on this would be sincerely appreciated!


title: Better way to get Fisher Exact?

text: I want to perform a Pearson's $\chi^2$ test to analyse contingency tables; but because I have small numbers, it is recommended to perform instead what is called a Fisher's Exact Test. This requires generating all integer matrices with the same column and row totals as the one given, and compute and sum all p-values from the corresponding distribution which are lower than the one from the data. See Wikipedia and MathWorld for relevant context. Apparently _R_ offers that, but couldn't find it in _Mathematica_ , and after extensive research couldn't find an implementation around, so I did my own. The examples in the links are with 2x2 matrices, but I did a n x m implementation and, at least for the _MathWorld_ example, numbers match. I have one question: The code I wrote uses `Reduce`; although it seemed to me generating all matrices was more a combinatorial problem. I pondered using `FrobeniusSolve`, but still seemed far from what's needed. Am I missing something or is `Reduce` the way to go? The essential part of the code, which I made available in github here, is that for a matrix like $$ \left( \begin{array}{ccc} 1 & 0 & 2 \\\ 0 & 1 & 2 \\\ \end{array} \right)$$ with row sums 3, 3 and column sums 1, 1, 4, it creates a system of linear equations like: $$ \begin{array}{c} x_{1,1}+x_{1,2}+x_{1,3}=3 \\\ x_{2,1}+x_{2,2}+x_{2,3}=3 \\\ \end{array} $$ $$ \begin{array}{c} x_{1,1}+x_{2,1}=1 \\\ x_{1,2}+x_{2,2}=1 \\\ x_{1,3}+x_{2,3}=4 \\\ \end{array} $$ subject to the constrains $ x_{1,1}\geq 0$, $x_{1,2}\geq 0$, $x_{1,3}\geq 0$, $x_{2,1}\geq 0$, $x_{2,2}\geq 0$, $ x_{2,3}\geq 0 $ and feeds this into `Reduce` to solve this system over the `Integers`. `Reduce` returns all the solutions, which is what we need to compute Fisher's exact p-value. _Note:_ I just found this advice on how to use github better for Mathematica projects. For the time being, I leave it as-is. Hope easy to use and test. You can test the above mentioned code like               FisherExact[{{1, 0, 2}, {0, 0, 2}, {2, 1, 0}, {0, 2, 1}}]      It has some _debugging_ via `Print` which shows all the _generated_ matrices and their p-value. The last part (use of `Select`) to process all found matrices didn't seem very _Mathematica_ to me, but it was late and I was tired - feedback is welcome. I would give my tick to the answer with more votes after a couple of days if anyone bothers to write me two lines :) Thanks in advance!


title: Viewpoint options for a 3D plot

text: Let's say I created a 3D plot in _Mathematica_. It's not oriented the way I want it, so I manually rotate it (in the output cell) to a desired view. (I tried playing with some view options in the code, but I gave up -- I admit my spatial imagination is really bad.) Here's the question: how can I find the options in the manually adjusted graph, so that I can reproduce it with _Mathematica_ code?


title: Extract values for ViewMatrix from a Graphics3D

text: Under _More Information_ in the help page of `ViewMatrix` the following entry can be found > With the setting `ViewMatrix->Automatic`, explicit forms for the matrix `m` > can be found using `AbsoluteOptions[g,ViewMatrix]`. Trying this with a basic example               gr = Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}];     AbsoluteOptions[gr, ViewMatrix]          (* Out[11]= {ViewMatrix -> Automatic} *)      shows, that this does not work as I would have expected it. Even setting `ViewMatrix` explicitely to `Automatic` does not help. I tried this on Linux and MacOSX. Can someone tell me how this is supposed to be used and how I can extract explicit values for the viewing matrix which is used for the projection?


title: How to apply by default the style to the Cell instead of the selection?

text: It's a bit tiresome repeating ctrl-., or UpArrow, Shift-DownArrow (in Mac), or grabbing the mouse to select the bracket every time one want to change the cell style. As style commands on empty selections aren't even registered unless you type something following, do you Front End experts know if is there some hook, trick, option, shortcut, or configuration to effect the style application? Like this: if there's a non-empty selection, do as always; if the selection is empty, change the cell style.


title: Converting HeavisideTheta[]s and Sign[]s functions to a single Piecewise[]

text: I have the product of some Heaviside functions or sign functions, a simple example could be:               HeavisideTheta[q^2 - 4]*Sign[q - 3]      Another slightly more complicated example, involving a quartic function could be:               HeavisideTheta[Sqrt[((q - 3)^2 - 10)^2 + 15] - 8]      Clearly the resulting function will be composed of many steps, so I would like to convert it to a piecewise function. For the example before, the result would be:               Piecewise[{{-1, q <= -2}, {0, -2 < q <= 2}, {-1, 2 <= q < 3}}, 1]      Except for (maybe) a zero measure set, for which I don't care. Many times the variable appears quadratically or quartically inside the functions, so solving to find the zero may be non trivial, but it can always be done exactly by Solve[] or Reduce[]. I need to repeat this procedure a lot of times, so I would like to automate the procedure... Is there a way to teach Mathematica how to do it?


title: Memoization of Rounded inputs

text: Memoization is a technique for improving performance by having a function remember its previous arguments. For example,               f[x_]:=f[x]=mySlowFunction[x]      will be slow on its first evaluation for a given `x`, but will be vastly faster on subsequent calls for that `x`, whereas repeated calls to `mySlowFunction[x]` will always be slow. My case is that I would like to discretize the parameter space to increase performance at the expense of accuracy. Any `Real` value of `x` should be evaluated only at the rounded value, which itself should be memoized. Compare these toy examples:               Clear[f];     f[x_] := f[x] = Total[Table[x, {100000}]]          Clear[g];     g[x_Real] := g[Round[x]];     g[x_Integer] := g[x] = Total[Table[x, {100000}]]          Timing[f[0]][[1]]       (* 0.002007 *)          Timing[f[0.1]][[1]]       (* 0.001523 *)          Timing[g[0]][[1]]       (* 0.002059 *)          Timing[g[0.1]][[1]]       (* 0.000013 *)      The 2nd call to `g[x]` is much faster than the first call, even though the actual input (`0.1`) has not been memoized itself. The second call is less accurate, and I can live with that. But I would like to `Round[]` to arbitrary precision. For example, I could try               g[x_Real] := g[Round[x,0.01]];      The `g[x_Integer]` pattern of the 2nd definition would fail in this case. I tried the naive               h[x_Real] := h[Round[x,0.01]] = Total[Table[x, {100000}]]      which does not produce the desired effect. How could one memoize a function's inputs, such that subsequent calls to the function at values near the (rounded) memoized inputs are replaced by calls at those memoized inputs? For the curious, I am tracing particles under the influence of a force. That force can be calculated to high precision at arbitrary locations, but this is slow. I'd like to cache the force at discrete locations, so that particles within some distance of a previously-calculated value use the cached value.


title: Fourier series for rectangular wave incorrect, why?

text: I'm trying to get the fourier series function(s) to work for a square wave with duty cycles other than 50% ie rectangular wave.               squareWave[t_, period_, duty_] := UnitBox[Mod[t/period, 1.]/(2. duty)]         xx[t_] := squareWave[t, 10, 0.8]         Plot[xx[t], {t, -10, 10}, Background -> Gray]     curvexx = FourierTrigSeries[xx[t], t, 10];       Plot[curvexx, {t, -10, 10}, Background -> Gray]      that's my code, set up squarewave, check by plotting (alright so far), take fourier series, check by plotting and it's wrong but why where did I go wrong?


title: How to find a recurrence relation for a sequence?

text: I have a sequence given by an explicit formula for n-th term:               seq[n_] := FullSimplify[LerchPhi[1/2, 2, -n] - 2^(-2-n) (π^2 - 6 Log[2]^2)/3];     Array[seq, 10]     (* {1, 3/4, 35/72, 11/36, 347/1800, 149/1200, 9701/117600, 209/3675, 8093/198450, 6031/198450} *)      I am trying to find a recurrence relation for this sequence (e.g. in a form of `DifferenceRoot` object). An invocation of `DifferenceRootReduce` does not produce a desired result:               DifferenceRootReduce[LerchPhi[1/2, 2, -n] - 2^(-2-n) (π^2 - 6 Log[2]^2)/3, n]     (* LerchPhi[1/2, 2, -n] - 2^(-2-n) (π^2 - 6 Log[2]^2)/3 *)      Are there any other ways to find a recurrence relation for a sequence?


title: Assigning an equation as a variable

text: I am compiling a calculator where many slider parameters are used to define a value, where the defined value may then be reused to define another value. I am unable able to, or at least been unsuccessful in assigning these values as variables. I want my coding to be able to refer to a variable (where the variable is an equation) in the sense, however the equation is defined by slider parameters and doesn't initially contain values. An example of this is a three-step formulation, where the first equation requires parameters defined through sliders, a second equation requires the value from the first equation and another slider parameter, then a third equation requires the value from the second equation and another slider; variables **A** , **C** and **F** are defined from individual sliders like this:               Row[{"Magnification: ", F/C}],     Row[{"Exit Pupil: ", A/(F/C)}],     Row[{"Longest Useful FOV: ", F/(A/(F/C))}],          {{A, 130, "Aperature: "}, 60, 508, 1, Appearance -> "Labeled"},     {{F, 650, "Focal Length: "}, 480, 4064, 1, Appearance -> "Labeled"},     {{C, 32, "Occular Focal Length: "}, 1, 110, 1, Appearance -> "Labeled"},      An easier way to express this would be and how I would like it to display is like this:               Row[{"Magnification: ", F/C = M}],     Row[{"Exit Pupil: ", A/M = E}],     Row[{"Longest Useful FOV: ", F/E}],      I am unable to find a way where this is achieved, the calculator hosts several instances like this however some require the value from another equation without a parameter set from a slider. Some equations are reused multiple times, due to the equations being used there are inconsistencies with formulation until some sliders have changed their values. I have a working example with complete code if required to see the depth of the formulation, however none of the equations require more than a three-step formulation. # Edit - Full Code               $S1 = Bold;         $S2 = Orange;          Manipulate[      N@Grid[{       {Style["Focal Ratio: ", $S1], Style[FL/AD, $S2]},       {Style["Dawes Limit: ", $S1], Style[115.824/AD, $S2]},       {Style["Rayleigh Limit: ", $S1], Style[139.7/AD, $S2]},       {Style["Gathering Power: ", $S1], Style[(AD/OP)^2, $S2]},       {Style["Magnification: ", $S1], Style[N[FL/OL, 4], $S2]},       {Style["Min Magnification: ", $S1], Style[N[AD/OP, 4], $S2]},       {Style["Exit Pupil: ", $S1], Style[N[AD/(FL/OL), 3], $S2]},       {Style["True FOV (No F/Stop): ", $S1], Style[N[OF/(FL/OL), 3], $S2]},       {Style["True FOV (F/Stop): ", $S1], Style[N[(.0957*OL*OF*N[Pi]/180)/FL 57.3, 3], $S2]},       {Style["Max FOV: ", $S1], Style[N[31.7 180/N[Pi]/FL, 3], $S2]},       {Style["Longest Useful FOV: ", $S1], Style[N[FL/(AD/(FL/OL)), 5], $S2]},       {Style["Magnitude Limit: ", $S1], Style[NumberForm[7.5 + 5 Log10[AD/10], 4], $S2]},       {Style["Ocular Field Stop: ", $S1], Style[N[.0957*OL*OF*N[Pi]/180, 4], $S2]}      }],     {{AD, 130, "Aperature: "}, 60, 508, 1, Appearance -> "Labeled"},     {{FL, 650, "Focal Length: "}, 480, 4064, 1, Appearance -> "Labeled"},     {{OL, 32, "Occular Focal Length: "}, 1, 110, 1, Appearance -> "Labeled"},     {{OF, 52, "Occular FOV: "}, 40, 72, 1, Appearance -> "Labeled"},     {{OP, 7, "Observer's Pupil: "}, 4, 9, 1, Appearance -> "Labeled"}     ]      ![Example Image](http://i.stack.imgur.com/THYSv.jpg) I reworked the layout to a `Grid`, I will have to adjust the decimals still. There are no more compiling errors, however the instance I want to adjust is being able to refer to a variable say with the **Exit Pupil** rather than reusing the **Mag** formula, there are many instances where I have reused the same formulas multiple times, if I can set some of the equations to a variable it will significantly reduce the size and unnecessary complexities. Is there a way I can do this?


title: Increasing number of decimal places in Manipulate input

text: I've made a Manipulate app. in Mathematica where I vary the value of a function f(a) by varying the parameter a. However, I seem to only be able to edit my input for a for a value up to 5 decimal places (if I enter in a number with more than 5 decimal places, it rounds the figure). Is it possible to increase the number of decimal places with which I can enter in my value of a into the manipulate input?


title: Speeding up construction of simple tridiagonal matrix

text: I have the following code to construct a tridiagonal matrix:               ClearAll[th];     th[nwells_ /; EvenQ@nwells] := Module[       {size = nwells, bdiag},       bdiag = RandomReal[{0, 99}, size - 1];       SparseArray[        {         Band[{1, 1}] -> bdiag,         Band[{1, 2}] -> -0.5,         Band[{2, 1}] -> -0.5},        {size - 1, size - 1}        ]       ]         This will be executed millions of times (`bdiag` is actually something that will change each time, so this is unavoidable). I'd like to speed it up as much as possible. Any ideas? I am interested in values of `nwells` of the order of 100 to 1000. EDIT: Let us compare the time taken by the `Band` version, by MrW's version and Rojo's version for varying sizes:               {       Table[{i, Do[th[i], {100}] // AbsoluteTiming // First}, {i, 100,          5000, 200}],       Table[{i, Do[banded[i], {100}] // AbsoluteTiming // First}, {i, 100,          5000, 200}],     Table[{i, Do[banded2[i], {100}] // AbsoluteTiming // First}, {i, 100,              5000, 200}]       } // ListLogPlot[#, AxesLabel -> {"size", "t"}] &      ![Mathematica graphics](http://i.stack.imgur.com/ZWwUg.png) (the slowest one is mine). Note the logarithmic axis. Evidently, the `Band` method falls behind more and more with larger system sizes. Also, using `Band` unpacks:               On["Packing"]     th[3000]; // AbsoluteTiming     banded[3000]; // AbsoluteTiming      ![Mathematica graphics](http://i.stack.imgur.com/fpEFv.png) This occurs when `Band` is used to insert the (packed) `bdiag` list into the diagonal.


title: Automatic Text Adjustment

text: Continuing the theme of minor interface annoyances, one of the unique features of Mathematica as a text editor is the automatic adjustment of text location as you type. This could be a bit disorienting...Any way to make it stop?