title: How to graph a series of coupled oscillators and watch the wave move along them

text: Here are the differential equations that set's up the 11 coupled oscillators.               new = Join[     Table[x[i]''[t] == - x[i][t] +       0.1*(x[i + 1][t] - 2*x[i][t] + x[i - 1][t]), {i, 1,      9}], {x[0]''[t] == -x[0][t], x[10]''[t] == x[9][t], x[0][0] == 1,      x[0]'[0] == 1, x[1]'[0] == 0, x[1][0] == 0},      Table[x[i][0] == 0, {i, 2, 10}], Table[x[i]'[0] == 0, {i, 2, 10}]]      Here are the solutions.               Solt = NDSolve[new, Table[x[i], {i, 0, 10}], {t, 25}]      Here are the individual plots.               Table[Plot[Evaluate[x[i][t] /. Solt], {t, 0, 25},      PlotRange -> All], {i, 0, 10}]      I am trying to figure out how to make a graph so along the x-axis are my i's from 0 to 10, and I can watch the wave move along each oscillator as time moves on. I keep getting errors in which it floods my notebook and doesn't stop unless I close the kernel. This is what I have so far, and I'm not sure how to incorporate time into this.               Plot[Evaluate[x[i][t] /. Solt], {i, 0, 10}]      EDIT Coupled in a circle               Stew = Join[      Table[x[i]''[t] == - x[i][t] +        0.1*(x[i + 1][t] - 2*x[i][t] + x[i - 1][t]), {i, 1,       9}], {x[10]''[t] == - x[10][t] +        0.1*(x[0][t] - 2*x[10][t] + x[9][t]),      x[0]''[t] == - x[0][t] +        0.1*(x[1][t] - 2*x[0][t] + x[10][t])}, {x[0][0] == 0,      x[0]'[0] == 0, x[1][0] == 1, x[1]'[0] == 0.5},      Table[x[i][0] == 0, {i, 2, 10}], Table[x[i]'[0] == 0, {i, 2, 10}]];      The Dsolve               Loin = NDSolve[Stew, Table[x[i], {i, 0, 10}], {t, 6.28}]      The individual graphs               Table[Plot[Evaluate[x[i][t] /. Loin], {t, 0, 6.28},      PlotRange -> All], {i, 0, 10}]      How would I go about putting the i=0 to 10 around in a circle?


title: Working with nested matrices

text: I have a matrix:               A = {{a, b}, {c, d}}      But each its element, itself, is another matrix too.               a={{0,1,1},{0,1,0}}     b={{0,0,1},{1,0,0}}          c={{0,0,0},{0,1,0}}     d={{0,0,1},{1,0,1}}      I want to comprise 'a' and 'b' with their elements; and respectively 'c' and 'd'. If just one element be similar in 'a' and 'b' and simultaneously equal to '1', (here:)               a13=b13=1      the 'b' element of 'A' must be replaced with zero. (here A12=0). Question1:   For the comparison I write bellow line, I Do not know which must be written in the A['indexes referring to location of b'] in this line:               Do[If[a[[i, j]] == b[[k, m]], A['indexes referring to location of b'] = 0], {i, 1, 2}, {j, 1,3}, {k, 1, 2}, {m, 1, 3}]      Question2: All of us know each element of a matrix has two indexes {i and j; for example Aij}. are there any possibility to devote four indexes to a one element of a Matrix(for example Aijkm? Actually, if we can devote four indexes to each A element in the above 'Do' loop, the line will be written more easily. Question3: if instead of 'a','b', 'c' and 'd' we have numerics:               A = {{1, 2}, {3, 4}}      Are the any possibility to devote a matrix to numeric!!!!!!? For example               1={{0,1,1},{0,1,0}}     2={{0,0,1},{1,0,0}}      !!


title: Function that prints a different value than it returns

text: I want to create a function something like this: `test[x_] := (Print[1]; Return[2];)` Except it prints `1` when executed as `test[a]` for any `a` on the notebook, but when used in computations uses the `2` value instead. Thus `test[2342]` will output just `1` but `test[43589] + 1` will output just `2` (because the value returned, 2, is used instead). I have looked into `Interpretation` but that returns a held object and does not allow you do perform operations like `test[1] + 123` without explicitly releasing the hold.


title: InverseFunction on an Interpolating Function is misbehaving

text: I am getting strange behavior when I try to calculate the inverse of an interpolating function for two similar data sets. My data sets are:               Array1 = {25, 425, 825, 1175, 1575, 1975, 2025, 2625, 3225, 3775, 4375, 4975, 5250, 9250,                13250, 16750, 20750, 24750, 27500, 47500, 67500, 82500, 102500}          Array2 = {13, 88, 188, 263, 338, 413, 513, 588, 613, 688, 788, 863, 938, 1013, 1113, 1188,               1250, 1950, 2650, 3350, 4050, 4750, 5450, 6150, 6700, 13700, 20700, 27700, 34700, 41700,               48700, 55700}      Let's define:               int1 = Interpolation[Array1];     int2 = Interpolation[Array2];          inv1 = InverseFunction[int1];     inv2 = InverseFunction[int2];      Now if these are behaving, then taking the inverse of the interpolating function's value for X should return X. Here's what happens when we try that for, say, 5:               N[inv1[int1[5]]]      > Out: 5.               N[inv2[int2[5]]      > Out: -1.73315 Err...this makes no sense. Is there any reason that the inverse of an interpolating function would behave as expected with one data set but not another? These data sets aren't very different so it isn't clear to me what about the second set could be causing the routine heartburn.


title: Using Nest inside NestList

text: I need results like this:               {Cos[Cos[x]], Sin[Cos[Cos[x]]],Cos[Cos[Sin[Cos[Cos[x]]]]],       Sin[Cos[Cos[Sin[Cos[Cos[x]]]]]], ... }      I've tried to use `Nest` inside `NestList`, but failed:               NestList[Sin, Nest[Cos, x, 2], 3]          (* {Cos[Cos[x]], Sin[Cos[Cos[x]]], Sin[Sin[Cos[Cos[x]]]],       Sin[Sin[Sin[Cos[Cos[x]]]]]}  *)      Any idea?


title: Fold Dynamic Function

text: I'm making on a demo working with differential equations as functions of two variables (x and y). The demo will have to Fold the differential equation with an initial y-value and a series of x-values. Here's a simple code for the demo. The output should be a list on new y-values.               DynamicModule[{dydx = Null},      Deploy@     Panel@     Grid@     Transpose@     {{"Differential equation: (dy/dx)=",         "List of Slopes:"},       {InputField[Dynamic[dydx]],         InputField[Dynamic[FoldList[dydx, 1, {0, 1, 2, 3}]]]}}]      The code doesn't work because dydx cannot be applied as a function in FoldList. "dydx" needs to be defined as a function f[y_,x_]. However, I'm not sure how to dynamically change a function using InputField.               f[y_,x_]= dydx     FoldList[f,1,{0,1,2,3}]      I'd like to have this as part of the Dynamic Module. Users would be able to input a function then receive a list of new y values.   Any advice?


title: Strip waste braces in nested list

text: I have nested lists wherein there are a lot of waste levels which looks like               l = {{{{{{2, 2}}, 3}, 2, {{2, 33}}, 4, 5}}};      I would like to reduce it to somthing like               l = {{{2, 2}, 3}, 2, {2, 33}, 4, 5};      I made the function which remove waste levels on the top level:               l = {{{{{{2, 2}}, 3}, 2, {{2, 33}}, 4, 5}}};          strip = Function[{list},                      If[(Head[list] === List) && (Length[list] > 0),                         If[Flatten[list, 1] === list[[1]],                             s = strip[list[[1]]],                             s = list],                         s = list];                      s];     strip[l]      To do it at any depth I tried to do `Map[strip[l]]` without success. How I can to apply my function to all levels? Also, I guess there more appropriate way to solve my problem.


title: How to control Boundary conditions after integrating over piecewise function?

text: The following code               Assuming[-1 < t < 1 && Element[a, Reals],       FullSimplify[       Integrate[        Piecewise[{{(1 + x)/(1 + t), -1 < x < t},                    {(1 - x)/(1 - t),  t < x < 1},                    {0,                True}}],         {x, -1, a}]]]      will result in $$ \begin{cases} 1 & a>1 \\ \frac{(a+1)^2}{2 (t+1)} & a>-1\land a<t \\ \frac{t+1}{2} & a=t \\ \frac{(a-1)^2}{2 (t-1)}+1 & a>t\land a\leq 1 \end{cases} $$ By the assumptions above, that's the same as: $$ \begin{cases} 1 & a\ge 1 \\ \frac{(a+1)^2}{2 (t+1)} & a>-1\land a\leq t \\ \frac{(a-1)^2}{2 (t-1)}+1 & a>t\land a< 1 \end{cases} $$ which is the form I'd prefer.   Is there a way to automatically tell mathematica to do that? The reason I want the second form is, that I'd need to integrate the output once again and in the first form, it would result in weird behavior, suddenly unnecessarily special-casing for $\frac{1}{\sqrt{2}}$ or things like that. (Note that there is no case for $a\leq -1$. That case gets auto-handled by Mathematica as $\{0,True\}$ and doesn't show up when you use the \TeXFormat command)


title: How to understand and use DSolve solution

text: This equation is simple to `DSolve` in _Mathematica_ , but I don't know how to use and understand solution.                DSolve[Y1''[x] - a2 Y1[x] - a1*X1[x] == 0, Y1[x], x]      $ \text{Y1}[x]\to e^{\sqrt{\text{a2}} x} C[1]+e^{-\sqrt{\text{a2}} x} C[2]+e^{-\sqrt{\text{a2}} x} \left(e^{2 \sqrt{\text{a2}} x} \int_1^x \frac{\text{a1} e^{-\sqrt{\text{a2}} K[1]} \text{X1}[K[1]]}{2 \sqrt{\text{a2}}} \, dK[1]+\int_1^x -\frac{\text{a1} e^{\sqrt{\text{a2}} K[2]} \text{X1}[K[2]]}{2 \sqrt{\text{a2}}} \, dK[2]\right) $ What is `dK1` and `dK2`, how to solve integrals [1,x], and how to use this solution `Y1[x]` to find `X1[x]` in another equation               Derivative[2][X1][x] == Y1[x]


title: How to set up the Fourier domain for a Fourier Transform?

text: I am having trouble understanding how to set up the grid in the Fourier domain, while performing Discrete Fourier Transforms. This might be a very trivial question, but I'd appreciate any help understanding this problem. I am trying use Fourier transforms to model the propagation of an electric field through space. The steps that I need to perform are:   * Take the Fourier transform of $f(x, z = 0)$ to obtain $f(k, z=0)$   * Multiply $f(k)$ by $\exp[i\,k_z\,d]$ for some propagation distance $d$ with $i = \sqrt{-1}$. Here k_z is defined as: $$ k_z = \sqrt{k^2 - k_x^2} $$ where $k$ is the known wavenumber.   * Inverse Fourier Transform back to obtain $f(x, z=d)$ I have set-up my grid for the x-dimension but I do not understand how I should go about setting up the grid for the k-dimension. My approach (as obtained from the section on FFT in Computational Methods in Physics by Joel Franklin): My $x$-grid is defined as $x_i = i\,\,dx$ for $i \in [0,N-1]$ for some number $N$. Now, I define the $k$ space with $k_j = j \times dk$ such that $dk=\frac{1}{dx \,\,N}$. This grid was created to obtain the max value of k allowed by Nyquist's theorem. Then, I execute the following:               (*fields is a list of the values of the field on the x-grid*)         klist = Table[n*dk, {n, -NN/2 , NN/2}];        four = Fourier[fields];     final= InverseFourier[        Table[four[[i]]*Exp[-I*d*Sqrt[k^2 - kxlist[[i]]^2]], {i, 1,           Length[four]}]];      The output of the above code does not give me expected results for the what the field looks like at various distances. I would appreciate any explanation about where the definitions of setting up the k-grid come from and also if someone can point out mistakes in my implementation. Thanks


title: Interactive 3D plot in web browser?

text: Are there any ways to show a mathematica plot in a web browser so that the user can rotate it and such? I am open to embedding it in a web page - or some other method such as porting it to a different language such as java or javascript.


title: How do I draw lines perpendicular to contour lines on ListPlot3D?

text: I am plotting the voltage in a pool of water with two electrodes. I have contour lines on my graph at every volt, but I would like to show the electric field lines which are going to be perpendicular to the contour lines. How can I do that? ![enter image description here](http://i.stack.imgur.com/1oSP8.png)


title: Can this Part shortcut key be made to work with version 9?

text: In version 8 I was a frequent user of the "Use shortcut keys to easily type〚 and 〛" trick. In version 9, when I try to make the necessary change to `KeyEventTranslations.tr`, the `\\[LeftDoubleBracket]` and `\\[RightDoubleBracket]` get immediately changed to doubled single-brackets (`[[` and `]]`). And indeed the shortcuts work, but they insert the doubled single-brackets instead of the single double-brackets. How can the brackets' doubleness be preserved in `KeyEventTranslations.tr`?


title: Using NDSolve for three variables as function of time

text: I want to be able to plot z, and r. Should I be using DSolve, NDSolve or something else? I've tried to clear it up a bit Thanks, Will               ClearAll["Global`*"];          (*Constants*)     rho = 1000;     g = 9.81;     Patm = 100000;     gma = 0.0728;     mu = 0.0001;     rs = 287;     T = 293.15;     Psat = 2399;          (*Variables*)     r0 = 25*(10^-6)          (*equations*)     Pl = rho*g*z[t] + Patm;          eqn1 = Pb[t] == rho*g*z[t] + Patm + (2*gma)/r[t]          eqn2 = r[t] == (((1 + (Psat/Pb[t]))*(rho*g*z[t] + Patm)*r0^3)/Pb[t])^(1/3)          eqn3 = z'[t] == -(2/9)*(1/mu)*(r[t]^2)*(Pl - Pb[t]/(rs*T))               eqn = {eqn1 && eqn2 &&  eqn3 , r[0] == 0.000025 && z[0] == 1 }               sol = NDSolve[eqn, {r[t], Pb[t], z[t]}, t, {Z[t], 1, 0}]


title: How do I find the number of countries that have a type of industry?

text: I am trying to find the number of countries that have a certain type of industry. Currently, I have this code:               countries = Flatten[CountryData[]];          listofCountries = Table[countries[[i]], {i, 1, 240}];          industries = Map[{CountryData[#, "MajorIndustries"]} &, CountryData[All]];          data = Table[industries[[i]] -> listofCountries[[i]], {i, 1, 240}];      I am not sure on how to find the number of countries that have an industry (i.e. `Coal`), or if I am headed in the correct direction. Could somebody show me the correct way to find the number of countries with an industry? EDIT: If I were trying to shade in the countries found on the world map with a color, how would I do so? (This is using the CountryData function.) I'm curious to see how much of the world has this industry, and so forth. (EDIT: How could I do it with the world map showing the boundaries of every country?) EDIT 2: How could I do the edit above with two industries? (i.e. Coal and Copper)


title: Coding contour integration

text: I am struggling to understand contour integration. How would it be applied in _Mathematica_? I am hoping that if I see it written in _Mathematica_ code, it will help me understand it. eg how would $$\int_\gamma \text{}(z) = \int_a^b \text{f}(z(t)) z'(t) \, \text{d}t$$ be coded? (Example taken form Wikipedia.)


title: Write list of polynomials as a matrix of coefficients times a list of monomials

text: I have the following problem: given a list of polynomials `P = {p1, ..., pn}` on the variables `x[1], ..., x[n]`, find a list of monic monomials `M = q1, ..., qm` on `x[1], ..., x[n]` and a matrix `A` that does not depend on `x[1], ..., x[n]` such that `A.M = P`. For example, taking `P = {x[1] x[2] + x[1]^2 x[2], a x[1]^2 + b x[2], c x[1]^2 x[2] + d x[2]^2}` a possible solution is: `M = {x[1] x[2], x[1]^2, x[2], x[2]^2, x[1]^2 x[2]}`, `A = {{1, 0, 0, 0, 1}, {0, a, b, 0, 0}, {0, 0, 0, c, d}}` I managed to find a long and clumsy solution by using a lot of replacement rules, but I want to know if there is an easy way of doing something like this. Many thanks in advance.


title: Stop use of Scientific Notation in Tooltips

text: I have a list of pairs of values that I am plotting in a ListLinePlot. I can use the tooltip functionality fine but I want to stop them from displaying in scientific notation. I have tried the following                 DisplayData20Yr = {{2010, 1.49952026`*^6}, {2011,         1.82272254`*^6}, {2012, 2.01921445`*^6}, {2013,         2.28115586`*^6}, {2014, 2.77986072`*^6}, {2015,         3.18915846`*^6}, {2016, 3.1505870500000003`*^6}, {2017,         3.44300142`*^6}, {2018, 3.58399037`*^6}, {2019,         3.67522613`*^6}, {2020, 3.88522079`*^6}, {2021,         3.90061335`*^6}, {2022, 3.9293277800000003`*^6}, {2023,         3.90820965`*^6}, {2024, 3.9495397`*^6}, {2025,         3.6954160300000003`*^6}, {2026, 3.76539612`*^6}, {2027,         3.77579118`*^6}, {2028, 3.29648289`*^6}, {2029,         1.6678326400000001`*^6}}          DisplayData20YrNoScientific =        Map[NumberForm[N[#], ExponentFunction -> (Null &)] &,         DisplayData20Yr];          ListLinePlot[Tooltip[Table[DisplayData20Yr[[i]], {i, 20}]],        Joined -> True, PlotMarkers -> {Automatic, 12}];          ListLinePlot[Tooltip[DisplayData20Yr], Joined -> True,        PlotMarkers -> {Automatic, 12}];          ListLinePlot[       Tooltip[DisplayData20Yr, Table[DisplayData20Yr[[i]], {i, 20}]],        Joined -> True, PlotMarkers -> {Automatic, 12}];      The first plot works normally with the tooltips showing in scientific notation. The second plot works in the same way as the first plot. The third plot doesn't disply tooltips at all. When I then use the DisplayData20YrNoScientific data set all three plot do not display anything at all. No lines/points or tooltips. They are blank. In my understanding the third plot should work because tooltip can be used as Tooltip[expression,label].


title: Manipulate changing controls

text: Is it possible to use `Manipulate` and `Switch` to change the `Manipulate` controls?               Manipulate[Module[{...variables...},       Switch[type,         1,         controls = ...,         2,         controls = ...]],       controls]      Where `Manipulate` controls would be different for each `type`.


title: ListPolarPlot not showing full plot range even with PlotRange -> All

text: I have a list of data `dpdOt` (given below) with associated angular coordinates `thetaplot`, which when plotted using                   thetaplot = Table[tt,{tt,0,2*Pi,2*Pi/300}]         ListPlot[Transpose[{thetaplot/Pi 180, dpdOt}], Joined -> True, PlotRange -> All]      looks like this: ![ListPlot](http://i.stack.imgur.com/dZMZB.png) However, I'd rather see this plotted as a `ListPolarPlot`, but I am having trouble with `PlotRange`. For example, when I use the command                   ListPolarPlot[Transpose[{thetaplot, dpdOt}],            Joined -> True, PolarAxes -> True,            PolarTicks -> {"Degrees", Automatic},            PolarGridLines -> True, PlotRange -> All]      I get the following plot: ![ListPolarPlot](http://i.stack.imgur.com/y5rYi.png) which is obviously not plotting the full data range. If I try and manually set `PlotRange -> 1.5`, _Mathematica_ merely gives me a zoomed out version of the same polar plot: ![enter image description here](http://i.stack.imgur.com/NwnFz.png) Does anybody have any idea how I can get _Mathematica_ to show the full dataset on my polar plot? The dataset is:                   dpdOt = {0.`, 0.009554081538201524`, 0.03657921246993372`,  0.07645719594918586`, 0.1224134613324866`, 0.16671965853831489`,  0.2020509236272155`, 0.22274769290832974`, 0.22575257105691635`,  0.21105662334588893`, 0.18158393497377667`, 0.14254991938921568`,   0.10042704400882534`, 0.06172261938230206`, 0.03180381202988293`,   0.013989865520678359`, 0.009074375607003422`, 0.015353199348562318`,   0.029133703291304467`, 0.045608259290746044`,  0.059907143344449666`, 0.06811602801815318`, 0.06805619079404875`,   0.05967798355792369`, 0.044998917623994925`, 0.027610426330823622`,   0.011863439428043385`, 0.001905442213411619`,  0.0007687312281260307`, 0.009696350336090554`,   0.027841942524898654`, 0.05240297090682485`, 0.07915899837109333`,   0.10330545634013048`, 0.12041455169350666`, 0.1273300195707255`,   0.12281593359315725`, 0.10782877955797118`, 0.08535664034364425`,   0.0598548826381265`, 0.0363874297112553`, 0.01964103546890816`,   0.013005632519217386`, 0.017901837073488084`, 0.03348933529492066`,   0.05681622331866217`, 0.08338356368455244`, 0.10801797869739073`,   0.1258838157458027`, 0.13343735028386552`, 0.12913464839968958`,   0.11375083606637912`, 0.09024321729842082`, 0.0631798709645865`,   0.03784184580594409`, 0.01917378839552386`, 0.010791123900980252`,   0.014244303123378875`, 0.028692550180028028`, 0.051059513247240756`,   0.07664648824951373`, 0.10008465443777814`, 0.11643545518106532`,   0.12221354284042615`, 0.11611806246510771`, 0.09931464269298441`,   0.07520186774030126`, 0.048703952993848255`, 0.025233271631061455`,   0.009540102126567822`, 0.004695564232203329`, 0.011429494446618007`,   0.027971655343629113`, 0.050436902199565224`, 0.07367569127391489`,   0.0924069287274574`, 0.10238447666431386`, 0.1013374846275298`,   0.08947198471813812`, 0.06941749674225801`, 0.04562682130072883`,   0.02336179577963223`, 0.007493854962987605`, 0.00139302722259097`,   0.006161200150237524`, 0.020388179378757983`, 0.04048931173627752`,   0.06154859929889949`, 0.078472675688499`, 0.08718681535608698`,   0.08559234035384577`, 0.07405894111973076`, 0.05533354561614883`,   0.03388451541925968`, 0.014833968423679648`, 0.0027301058954676103`,   0.00045163413523262254`, 0.008507481364097463`,   0.024903075095984252`, 0.0456105809967408`, 0.06553606471258362`,   0.0797558049558498`, 0.08472607856766433`, 0.0791726455592892`,   0.06443855291626575`, 0.04419570077716716`, 0.023577636442966548`,   0.007932512944609768`, 0.001492113602352463`, 0.006281152280129452`,   0.021542228899509474`, 0.04383535778027103`, 0.06781257671823812`,   0.08750405559279266`, 0.0978210472734063`, 0.09591516988165438`,   0.08205096374581881`, 0.05974878090823095`, 0.03511799119091121`,   0.015491056611719418`, 0.007644208098589879`, 0.016008842898051462`,   0.041308975498834125`, 0.0799920698716276`, 0.12466309845912157`,   0.16551502191459355`, 0.19251813998620537`, 0.1979365219231554`,   0.1786272840234142`, 0.1375777607510681`, 0.08425397825386047`,   0.0335534665496219`, 0.0034359646772461074`, 0.011591552251972725`,  0.07173765420231708`, 0.19026282194703806`, 0.3639239411625669`,   0.5791488923696507`, 0.813221884473814`, 1.037282176743776`,   1.2207136698253551`, 1.3362119128823164`, 1.3646459208863824`,   1.2988226517976427`, 1.1454201179472137`, 0.9246567650991964`,   0.6676574849266789`, 0.4118891574170705`, 0.19539424083596366`,   0.050782165477450084`, 0.`, 0.050782165477450084`,   0.19539424083596366`, 0.4118891574170705`, 0.6676574849266789`,   0.9246567650992072`, 1.1454201179472137`, 1.2988226517976427`,   1.3646459208863868`, 1.33621191288231`, 1.2207136698253502`,   1.0372821767437717`, 0.813221884473814`, 0.5791488923696507`,   0.36392394116255933`, 0.19026282194703142`, 0.07173765420231298`,   0.011591552251971629`, 0.0034359646772465858`,   0.033553466549622345`, 0.08425397825386129`, 0.13757776075106873`,   0.17862728402341452`, 0.1979365219231553`, 0.19251813998620523`,   0.16551502191459352`, 0.12466309845912063`, 0.07999206987162717`,   0.04130897549883387`, 0.016008842898051108`, 0.00764420809858988`,   0.015491056611719966`, 0.0351179911909119`, 0.05974878090823171`,   0.08205096374581904`, 0.0959151698816545`, 0.0978210472734063`,   0.08750405559279249`, 0.06781257671823812`, 0.04383535778027089`,   0.02154222889950937`, 0.006281152280129231`, 0.001492113602352463`,   0.0079325129446096`, 0.023577636442966645`, 0.044195700777166905`,   0.06443855291626631`, 0.0791726455592894`, 0.08472607856766434`,   0.07975580495584968`, 0.06553606471258311`, 0.045610580996740674`,   0.0249030750959836`, 0.008507481364097328`, 0.00045163413523252865`,   0.0027301058954676857`, 0.014833968423680205`,   0.033884515419259915`, 0.05533354561614951`, 0.07405894111973105`,  0.08559234035384577`, 0.08718681535608702`, 0.078472675688499`,   0.061548599298899026`, 0.04048931173627754`, 0.020388179378757657`,   0.006161200150237425`, 0.0013930272225909912`,   0.007493854962987713`, 0.023361795779632825`, 0.04562682130072909`,   0.06941749674225874`, 0.08947198471813836`, 0.10133748462752992`,   0.10238447666431386`, 0.0924069287274574`, 0.07367569127391442`,   0.05043690219956524`, 0.027971655343628703`, 0.011429494446618017`,   0.0046955642322033106`, 0.009540102126567813`,   0.025233271631062083`, .04870395299384845`, 0.07520186774030205`,   0.09931464269298464`, 0.11611806246510807`, 0.12221354284042608`,   0.11643545518106499`, 0.10008465443777788`, 0.07664648824951395`,   0.05105951324724025`, 0.028692550180028028`, 0.014244303123378665`,   0.010791123900980252`, 0.01917378839552417`, 0.03784184580594409`,   0.06317987096458702`, 0.09024321729842102`, 0.11375083606637972`,   0.1291346483996897`, 0.13343735028386566`, 0.1258838157458027`,   0.1080179786973901`, 0.08338356368455223`, 0.05681622331866127`,   0.03348933529492036`, 0.017901837073488223`, 0.013005632519217408`,   0.01964103546890816`, 0.03638742971125556`, 0.059854882638126314`,   0.0853566403436447`, 0.10782877955797118`, 0.12281593359315748`,   0.1273300195707255`, 0.12041455169350626`, 0.10330545634013014`,   0.07915899837109269`, 0.052402970906824456`, 0.027841942524897894`,   0.009696350336090289`, 0.0007687312281258732`,   0.0019054422134117427`, 0.011863439428043385`, 0.02761042633082383`,   0.044998917623994925`, 0.0596779835579238`, 0.06805619079404875`,   0.06811602801815296`, 0.05990714334444941`, 0.04560825929074557`,   0.029133703291304193`, 0.015353199348562014`, 0.009074375607003374`,   0.013989865520678902`, 0.031803812029883506`, 0.06172261938230317`,   0.10042704400882617`, 0.14254991938921568`, 0.18158393497377667`,   0.21105662334588893`, 0.22575257105691635`, 0.22274769290832974`,   0.2020509236272155`, 0.16671965853831489`, 0.1224134613324866`,   0.07645719594918586`, 0.03657921246993372`, 0.009554081538201524`,   0.`}


title: Using header files

text: I have a piece of code I keep using in new notebooks over and over again and I have to copy and paste it in each new notebook. Problem arises: if I update the code in one file I have to manually do it in all the other files. So I was wondering, is it possible to create one file, let's call it InitCode-7 July.nb, and use a command as an initialization cell in _Mathematica_ to load it? This way I would only have one file to change and it would apply to all the files where I use the same code. I am familiar with the concept of headers file in other programming languages but I have no idea how to do it in Mathematica. Thank you.


title: Solve a system of M equations without specifying M

text: **This post has been edited heavily in response to the comments: my initial question was very confusing.** I am trying to write my game-theoretic model in _Wolfram Language_. There is only one remaining step and I am not sure if it is within reach of _Wolfram Language_ (or _Mathematica_ ). I describe a simplified version of my problem below. # Cournot game There are $M$ firms. Each firm $i$ can produce some output $q_i\geq0$ at a cost of $c_i$ per unit. Once the firms have (simultaneously) decided on their outputs, the price is set in the market according to an inverse demand function $P(Q)=\alpha-Q$, where $Q=q_1+\ldots+q_M$ is the aggregate output and $\alpha>0$ is market size parameter. Firm $i$'s profits are $q_iP(Q)-q_ic_i=q_i(\alpha-q_1-\ldots-q_M-c_i)$. Each firm maximizes its profits taking outputs of the opponents as given. By differentiating the profit function with respect to $q_i$ and imposing the necessary condition for maximizing a function, I obtain the equilibrium outputs: $$q_i^*=\frac{1}{2}\left(\alpha-\sum_{k\neq i}q_k^*-c_k\right) \text{ for } i=\{1,\ldots,M\}.$$ A quick derivation on the piece of paper gives me the explicit solution: $$q_i^*=\frac{1}{M+1}\left(\alpha-Mc_i+\sum_{k\neq i}c_k\right)$$ **Here's the thing: I would like to obtain exactly this result (the above equation) in _Mathematica_. Is it possible?** Note: I don't want to substitute any numbers for $M, c_1, \ldots, c_M$ or $\alpha$. They are general, exogenous parameters. In other words, the above problem boils down to inverting a $M\times M$ matrix of the form: $$\left[\begin{array}{cccc} 2 & 1 & \ldots & 1\\ 1 & 2 & \ldots & 1\\ \vdots & \vdots & \ddots & \vdots \\ 1 & 1 & \ldots & 2 \end{array}\right].$$ Can one do this without specifying $M$? I hope I expressed myself clearer this time.


title: Defining a Unique Domain for Solving Diophantine Equations

text: I am working on a research problem in discrete geometry to do with sphere packings, and believe it or not, I have been able to reduce it to finding the solutions to the Diophantine equation, $$n = \frac{x + 2y + 3z}{2}, \text{ where $n,x,y,z \in \{1,2,3,4,5,6,7,8,9\}$}$$ In _Mathematica 8_ I have attempted to use the "FindInstance" command in order to find these solutions (there are a finite number of them), but I have no way to define the domain $\{1,2,3,4,5,6,7,8,9\}$, it only accepts "Reals", "Integers", etc. as a domain. Is there any way around this?               FindInstance[(x + 2 y + 3 z)/2 == 4, {x, y, z}, {1, 2, 3, 4, 5, 6, 7, 8, 9}, 10]      My idea would be to use that to find 10 instances of the solution, but the domain is undefined.


title: Profiler calls function without providing true arguments

text: I found Profile[] in the Mathematica workbench does not run on my function. To investigate, I provided a simple function,               In[]:= test[arg_] := (Print[arg]);          In[]:= Profile[test[1]]     Out[]=      1     1      This is as expected, only that the profiler called the function twice. However, after running my code, if I run the same test function again, I get               In[]:= test[arg_] := (Print[arg]);          In[]:= Profile[test[1]]     Out[]=      1     1     1     arg_     arg      Very strange that the profiler tries to call the function with arg_, instead of the given argument 1. And this is exactly the first error message I got when I use Profile to run my code. EDIT: I created an empty project and the above simple example does not make a mistake. Thus the problem should be some part of my code is incompatible with the Profiler... PS: my code is too long to be provided here. Just in case of an interest, it is at https://github.com/tririver/MathGR/tree/experimental               << MathGR/gr.m     Profile[Simp[t[DN@"a", DN@"a"]]]


title: Computing Slater determinants

text: I need to compute Slater determinants. I'm wondering if I would benefit from assigning each of my functions to a variable prior to computation. I'm working with Slater determinants, but my question goes beyond them and applies to the computation of any determinant. Say I have functions $f_n[x]$ which are sums of complex exponentials. If I want to compute the determinant of an $N\times N$ matrix, should I use the expanded form of $f_n[x]$ or variables ($a_1,a_2,b_1,b_2$, etc.), or else? Does _Mathematica_ benefit from prior "simplification" of the matrix or not? At the moment, I'm not concerned with speed because the systems I work with contain few electrons, but that will change.


title: How to calculate mix of 4 colors defined in CIELAB L*a*b* model?

text: I have 4 colors that I converted from RGB to CIELAB **L*a*b*** model.   1. How can I calculate mix of these 4 colors when I have `(L,a,b)` for each such color?   2. How can I calculate same mix, if I want to put weights `(w1, w2, w3, w4)` on such 4 colors, having 1 maximum and 0 minimum (none) weight?


title: How can I speed up SQL queries in Mathematica?

text: I have an application that queries a MySQL database many times for data. At the moment, Mathematica and MySQL are running on the same box and yet it takes over 1.6 seconds for the query to run and return a value. This feels very slow, and I was hoping somebody might give me counsel on how this might be sped up.               AbsoluteTiming[      SQLSelect[commodDB, "tbcommodprices", "price",          SQLColumn["ticker"] == "LAV05 Comdty" &&          SQLColumn["whichprice"] == "last" &&          SQLColumn["date"] == "2005-09-01"];]          {1.6093750, Null}


title: Is this function convex?

text: How can I determine convexity of the function `f = Log[ x, 1 + (x^a - 1) (x^b - 1)/(x - 1)]` with the parameters $a,\,b$ belonging to the interval $(0,1)$ in _Mathematica_?


title: Set gives an unexpected error message (Set::partw)

text: Here is a minimal example:               s = 1 /(a + b[3]) + 1 /(2 a + b[3]);     s[[1]] = Sum[s[[1]] /. b[3] -> k, {k, 3}]     s[[4]]     s[[4]] = Sum[s[[4]] /. b[3] -> k, {k, 3}]      Output:               Out[143]= 1/(1 + a) + 1/(2 + a) + 1/(3 + a)     Out[144]= 1/(2 a + b[3])      > Set::partw: Part 4 of (1/(1+a)+1/(2+a)+1/(3+a))+1/(2 a+b[3]) does not exist. > >>               Out[145]= 1/(1 + 2 a) + 1/(2 + 2 a) + 1/(3 + 2 a)      I could only make the error occur when using `Set`. As the above code shows, both `s[[4]]` and `Sum[s[[4]] /. b[3] -> k, {k, 3}]` are well defined. I have been struggling with similar errors for days, can someone please explain exactly what is happening behind the scenes?


title: Coefficient of determination (R squared) of EstimatedDistribution

text: I have estimated the distribution for a set of data as `LogisticDistribution[3.5, 1.037]`. How can I calculate and plot the coefficient of determination (R squared) with the PDF of the distribution? Here is the quantile-quantile plot: ![q-q plot](http://i.stack.imgur.com/esF2V.jpg)


title: How to draw a line (1D) with labeled subdivisions

text: I want to draw a simple line with some symbols, but so far have had no luck finding an easy way to do it in _Mathematica_. Does anyone know if _Mathematica_ can easily implement e.g. the example below? ![example](http://i.stack.imgur.com/lwbQp.jpg)


title: Update only one element in a dynamic grid?

text: I've got a grid of buttons that each display an image from an array. When a button is clicked, its image changes.               DynamicModule[{g = Table[Image[RandomReal[{0.5, 1}, {16, 16, 3}]], {19}, {19}]},       Grid[Table[With[{i = i, j = j},         Button[Dynamic[g[[i, j]]], g[[i, j]] = Image[RandomReal[1, {16, 16}]],           ImageSize -> Full, Appearance -> None]],         {i, 19}, {j, 19}], Spacings -> {0, 0}]]      The problem is that it is very slow. I presume this is because all the buttons get updated when only one is changed. This raises the general question as to how can you dynamically change only the control corresponding to the changed element in the list? I've already come up with a workaround for my particular problem:               DynamicModule[{g = Table[Image[RandomReal[{0.5, 1}, {16, 16, 3}]], {19}, {19}]},       Pane[ClickPane[Dynamic[ImageAssemble[g]],         (g[[19 - Floor[#[[2]]/16], Floor[#[[1]]/16] + 1]] =           Image[RandomReal[1, {16, 16}]])&],         ImageSize -> Full]]      This splices together a single image, works out where you clicked on it, then changes the appropriate element in the list. It doesn't answer the original question, but it's lots faster. ### Additional note: I'd quite like `g` to be available outside the grid. Then you could have multiple grids doing different things. Or some other view of the data.


title: Challenge: Speeding up MaxDetect for application in 3D blob detection

text: In image segmentation it is a common problem that objects appear clustered and are therefore undistinguishable from each other when using simple algorithms. Based on this post I obtained efficient ways to tackle the problem based on fast 3D distance transformation (`DistanceTransform3D`) and the usage of the _Mathematica_ built-in function `MaxDetect`. For details please have a look at the answer of UDB in the post. Consider two simple functions to generate a test `Image3D` containing sphere-like objects:               generateRandomObject3D[dim_, min_, max_] := Block[        {rdDim, rd, v, s1, s2},        rdDim = {RandomInteger[{min, max}], RandomInteger[{min, max}],           RandomInteger[{min, max}]};        rd = DiskMatrix[rdDim];        v = dim - 2 # - 1 & /@ rdDim;        s1 = # - RandomInteger[{1, #}] & /@ v; s2 = v - s1;        ArrayPad[rd, MapThread[List, {s1, s2}]]        ];          generateRandomImage3D[dim_, min_, max_, objNum_] := Block[        {},        Image3D[         Plus @@ Table[generateRandomObject3D[dim, min, max], {objNum}]]        ];          objects=generateRandomImage3D[64, 5, 5, 15];     colComps=Colorize@MorphologicalComponents@objects;      > ![bin](http://i.stack.imgur.com/C4bGM.png) > ![comps](http://i.stack.imgur.com/DWmvZ.png) Now we can identify the locations of the potentially clustered objects using a 3D distance transformation followed by `MaxDetect`.               AbsoluteTiming[MaxDetect[ImageAdjust@DistanceTransform3D[rand], 0.1]]      > {1.339987, ![enter image description > here](http://i.stack.imgur.com/7lJ1Q.png)} As you can see this operation already takes more than one second. If I check for the runtime of the individual steps, `DistanceTransform3D` needs about 1/4 of the time. Is there a faster way of doing this? The images I need to apply the algorithm to are much larger. Therefore, efficiency and runtime plays an important role in this case.


title: How to find regions that satisfy this inequality?

text: 1. I am new to _Mathematica_ and would like to find the set $$\{ (x,y) \in \mathbb{R}^2: (3x+y\exp(xy))(x-a) + (6y + x \exp(xy))(y-b) < 0 \}$$ for some constants $a$ and $b$. How can I do this? **Added** : Is the set empty when a=-1.0643 and b=0.150?    2. My actual question may be more difficult. For this function $f:\mathbb{R}^2 \to \mathbb{R}$, defined as $$ f(x,y) := (3x+y\exp(xy))(x-a) + (6y + x \exp(xy))(y-b) $$ I would like to know its range $f(\mathbb{R}^2)$, or better yet $f(\mathbb{R}^2 - \{(a,b)\})$, or as close as possible. Can it be done in _Mathematica_ as well?


title: Add content to an existing .zip file

text: I have been looking over the .zip documentation from Mathematica (http://reference.wolfram.com/mathematica/ref/format/ZIP.html). It seems pretty straighforward to export and import from/to a .zip file, but how can i add content to an existing .zip file?


title: Parallel optimization of Markov Chain Monte Carlo

text: I'm trying to reduce the computation time of a MCMC simulation. Essentially I have a set of particles performing a random walk in a periodic random potential. The particles are independent and every 100 timesteps I perform some checks and modify the state of some of the particles. This seemed to me a perfect case to be optimized by parallelizing the simulation, but whatever I try I always make things just a little bit worse. Here is in short detail what I'm doing. First I define my random potential function U[x] as an interpolation over a simple discrete time random walk               rw[L_] := Accumulate[RandomVariate[NormalDistribution[0, 1], L]]     myrw = rw[100];     myrw = Rescale[myrw];     ifun = Interpolation[        Transpose[{Range[1, 200], Join[Reverse@myrw, myrw]}],         PeriodicInterpolation -> True];     U[x_] := ifun[x];      Here are the two functions needed to perform a single time step evolution of a particle on my potential (Metropolis-Hastings algorithm):               p[x_, prop_, T_] := Exp[-(U[prop] - U[x])/T];     MCMCEvo[x_, T_] :=      Module[{prop},       prop = RandomVariate[NormalDistribution[x, 0.1]];       Return[If[RandomReal[] < p[x, prop, T], prop, x]]       ]      Then I have a function that checks the state of the particles and with some probability modifies it and then performs 100 time steps of evolution for the whole population. It then returns the state of the particles as a function of this 100-time steps evolution.               PopulationEvolve[pop_, pdiv_, plife_] := Module[{newpop},       (*I leave this SomeFunctionOfTheStates here for the sake of completeness, but commenting it and setting newpop=pop doesn't change anything in the timings*)       newpop = SomeFunctionOfTheStates[#,pdiv,plife]&/@pop;       Return[(Join[{#[[1]], #[[2]]}, {Mean[U /@ #], Last[#]} &[NestList[MCMCEvo[#, 0.1] &, If[#[[2]] == 0, RandomReal[{0, 100}], #[[4]]],100]]])& /@ newpop]     ]      Then I generate 2 populations, one with 100 elements and one with 400 to perform some tests:               pop100 = Table[{1, 0, 0, RandomReal[{1, 100}]}, {i, 100}];     pop400 = Table[{1, 0, 0, RandomReal[{1, 100}]}, {i, 400}];      and try parallelized and unparallelized calculations (4-Cores i5-2.6GHz):               AbsoluteTiming[PopulationEvolve[pop400, 0.8, 1]][[1]]     AbsoluteTiming[Table[PopulationEvolve[pop100, 0.8, 1], {i, 4}]][[1]]     AbsoluteTiming[ParallelTable[PopulationEvolve[pop100, 0.8, 1], {i, 4}]][[1]]     0.952207     0.960080     1.088009      and these proportions doesn't change even if I make PopulationEvolve perform 1000 time steps instead of 100: in principle I would expect the ratios to change in favor of the parallelized version, since the ratio between data exchanged between the kernels and length of the computation changes.               (*With 1000 time steps*)     AbsoluteTiming[PopulationEvolve[pop400, 0.8, 1]][[1]]     AbsoluteTiming[Table[PopulationEvolve[pop100, 0.8, 1], {i, 4}]][[1]]     AbsoluteTiming[ParallelTable[PopulationEvolve[pop100, 0.8, 1], {i, 4}]][[1]]     9.723611     9.816607     10.676737      I'm not very experienced with parallel calculations but, since now, once I was sure that there was no interactions among the parallel calculations the only bottlenecks I've ever found were about passing too much data back and forth to the kernels, which doesn't seem to be the case in this example. What am I missing here and what would be a good way to parallelize this?


title: CCodeGenerate and calling external functions

text: Is it possible to use `CCodeGenerate` to generate code which calls functions from other C libraries? For example, I would like to do something like this:               CCodeGenerate[Compile[{{x}}, f[x]+1], "f1"]      where `f` is a function defined in some other library (which I would then link to the generated code). I tried to first make `f` available in _Mathematica_ via LibraryLink, but then `CCodeGenerate` issues a warning (`CCodeGenerate::wmreq`) and returns `$Failed`.


title: How to set focus of a dialog window?

text: I have a dialog, which, when pops up, requests input from the user. How can I set the window up that the focus is on the `InputField` of the new window (i.e. the caret stands in the `InputField`), so that when the user starts typing, it is immediately registered by the field? At the moment, I have to click inside the field first to make it the active control on screen.               DialogInput[{InputField["", String], Button["Ok", DialogReturn[]]}]


title: Composing an image with a plot

text: I'm trying to illustrate the solutions to a textbook problem dealing with quadratic functions. This will involve plotting a quadratic and overlaying the plot and the image. Here is the textbook scan.....![enter image description here](http://i.stack.imgur.com/La8Zs.jpg) The idea of the problem is to find several possible quadratic models that would go through the hoop. I imported this image into a variable, call it img1 I wanted to establish a "baseline" so I started with a simple plot, x intercepts of 0 and 18, and vertex at (9,14). I know, NOT a solution to the problem but I wanted to see how the plot and image would match up. I created the plot               g2 = Plot[-14/81 x (x - 18), {x, -1, 19}, PlotStyle -> Thick]      Then I put them together and tweaked the placement of the plot based on the image size.               ImageCompose[img1, g2, {983/2, 811/2}]      Which gives me this... ![enter image description here](http://i.stack.imgur.com/gvgpf.jpg) The vertex is in the right place, but the axes don't line up. Sorry if this is a dumb question, I'm not at all sure how I could get my plot to match the background image so the axes in the image would be the same as the axes in my plot.... Do I need to scale my plot, or scale my image.. or something obvious that I am missing. Any help is appreciated


title: How do you draw the plane on which two vectors lie?

text: Given two arbitrary vectors $\textbf{v}_1$ and $\textbf{v}_2$, how can I draw the plane which they span?


title: Interface C# STAThread

text: How do I convert a .NET STAThread into .NET/Link Mathematica code? Alternatively what would be the easiest way to compile and run the program below from within mathemaitca?               using System;     using Wolfram.NETLink;     using System.IO;     using System.Drawing;     using System.Windows.Forms;          public class File{      [STAThread]      public static void Main(String[] args) {         MathKernel k = new MathKernel();         k.Compute("ExportString[Graphics[Circle[]],{\"Base64\",\"PNG\"}, Background -> None]");         string input = k.Result.ToString();              byte[] bytes = Convert.FromBase64String(input);          Stream stream = new MemoryStream(bytes);         IDataObject dataObject = new DataObject();         dataObject.SetData("PNG", stream);         Clipboard.SetDataObject(dataObject, true);       }     }      I am compiling it using the following code, in case anyone wants to try it out.               csc /target:winexe /reference:Wolfram.NETLink.dll File.cs


title: Customizing & finding intersection points in polar plot

text: I want to verify a theory stating that a golden mean spiral plotted on a polar graph will have intersection points at specific values. ![golden mean spiral plotted on polar graph](http://i.stack.imgur.com/ljuGi.png) There should be 8 concentric circles, each **at the same distance** as the previous one. The radial lines should be in 10-degree increments, and the spiral should start from `0` on the first circle in the middle and end on circle #8 at `360`. The golden mean spiral should progress independently of the grid lines. If all these requirements are met, `NSolve` should reveal where the intersection points are (the theory claims - 0deg at circle #1 - 120deg at circle #2 - 190deg at circle #3 - 240deg at circle #4 - 280deg at circle #5 - 360deg at circle #8). If the initial stretch of the spiral proves the theory wrong, trying to stretch the spiral between any 2 intersection points might do it. ![enter image description here](http://i.stack.imgur.com/Ii22f.png)


title: Stealth daylight saving shift in SQL data

text: I'm querying a SQL database with `DatabaseLink` and resulting `SQLDateTime` objects are shifted by an hour during daylight saving time. The dates are stored in the database without a DST shift, so it seems like Mathematica is applying the change. How can I eliminate the spurious shift? A workaround, such as getting `AbsoluteTime`-style integers instead of `SQLDateTime` expressions would be fine.


title: Multiplying expressions within a list of pure functions

text: Let's say I have a list of pure functions that are nice algebraic expressions: say               l = {(#1 - 1)&, (#1^2 + #1)&, (#1^3 - 1)&}      What's an easy way to get a pure function that will give the product of these expressions? For example, in the above I'd like to get a function f with               f = (#1 - 1)(#1^2 + #1)(#1^3 - 1)&      I've tried `(Times @@ Identity @@@ l)&`, but this just gives `(#1 - 1)(#1^2 + #1)(#1^3 - 1)`. Essentially, it seems my difficulty is converting a `List` of `Function` expressions to a `Function[Times[...]]` expression, and I can't see how to "strip off" the functions without messing up the referencing of the `Slot[1]` expressions inside. Thanks for any help.


title: Mathematica program for PLUR decomposition of a symbolic matrix using full pivoting

text: I wanted to ask if there is a Mathematica program for PLUR decomposition of a symbolic matrix M, such that M = P*L*U*R, using FULL (row and column) pivoting, and where R = reduced row echelon form of M. The entries of the matrix M are rational numbers, floating point numbers and symbolic expressions.


title: What is the definition of FitResiduals

text: What is the definition of `FitResiduals` in Mathematica? I could not find its definition in the Mathematica help. Is it the same as chi squared?


title: NMinimize usage

text: I would like to minimize functions including the following.               NMinimize[{1 - (1 - 1/n)^x - x/n, n > x, x > 1}, {n, x}]      However _Mathematica_ complains about values not being real. How should I do this?


title: Comparison Operation for Nested Matrices

text: I have a nested matrix `n` as bellow               n = {{a, b}, {c, d}}     a = {{0, t, q, dh}, {0, 1, 0, th}, {1, 0, 0, sh}}     b = {{0, t, q, dh}, {0, 0, 0, th}, {0, 0, 1, sh}}     c = {{0, t, q, dh}, {1, 0, 1, th}, {0, 0, 0, sh}}     d = {{0, t, q, dh}, {0, 1, 0, th}, {1, 0, 0, sh}}      ![enter image description here](http://i.stack.imgur.com/4TsWq.png) containing letters and numbers. I am going to do a particular operation in each row yielding the result shown bellow: ![enter image description here](http://i.stack.imgur.com/zQT7u.png) > >      {{{{0, t, q, dh}, {0, 1, 0, th}, {1, 0, 1, sh}}}, >       {{{0, t, q, dh}, {1, 1, 1, th}, {1, 0, 0, sh}}}}M >


title: Delay of events detection dependent of "MouseDown" position

text: Let's say we have a `Rectangle` with color which depends of `CurrentValue["MouseOver"]`:               Deploy@Framed@Graphics[            Dynamic @ {If[CurrentValue["MouseOver"], Red, Green], Rectangle[]}            , ImagePadding -> 10]      ![enter image description here](http://i.stack.imgur.com/nLw4h.png)   * With cursor over the `Rectangle[]` the color switches to `Red` as expected,   * also if one put the `"MouseDown"` and drag it around it is still `Red`,   * however if you put the `"MouseDown"` outside the rectangle, on the padded area, and drag it to the rectangle **it will not switch the color till`"MouseUp"`**. **Is there any way to avoid such behaviour in general?** I can create some workarounds for particular situations but I'm looking for a general solution. I was thinking about `EventHandler`'s `PassEvents` options but it seems it is a deeper problem ( _I've failed with this approach :)_ ). * * * It looks like the problem is the `"MouseDown"` event is blocking some functions, for example:   * `Dynamic@CurrentValue["ControlKey"]` is not working while the mouse button is down.   * I've faced it before with `MouseAppearance`: Problem MouseAppearance updating while “MouseDown”


title: How to copy text from InputField

text: The problem when you copy text from one InputFiled to another. Inserts in unnecessary places gap. For example copy the text "#bbb" (without the quotes) from one field to another get "# bbb" (without the quotes).


title: Importing multiple files using a for-loop

text: once again I am stuck solving a seemingly easy problem :( I would like to make a List of tables by importing data from several txt- Files. Importing the data into a table works so far and I am able to do ListPlots etc. The txt-file-names follow a simple pattern: `txtFile_1.txt, txtFile_2.txt, ...` **My take on the problem is the following:**                   testList = List[1, 2, 3, 4]         For[i = 1, i < 4, i++             testList[[i]] =             Import["C:\\txtFiles\\txtFile_" <> ToString[i] <> ".txt" <>               ToString[i] <> ".txt", "Data"];          ]      _Background:_ I would like to have the tables in the list to be able to access them via `testList[[i]]` and in order to do consecutive ListPlots via a `for`-loop etc...


title: Label points in plot with a text

text: I'm a newbie at Mathematica and I couldn't find how to label the maximum and the zero of a simple function in `Plot` with their names:               rho[r_] = 1 - r^2;     Plot[rho[r], {r, -1, 1}, AxesLabel -> {r, \[Rho]}]       and i want to show the maximum on the plot with               Subscript[\[Rho], c]      and the point rho[1] with               Subscript[R, TF]


title: Plot a 3D vector field from a file

text: I have a data file with six columns {x,y,z} and {ux,uy,uz} respectively, and I would like to plot the 3D vector field. http://www.mediafire.com/download/udoa61hu0m6itrc/campo.txt I'm trying to do this,               te = Import["C:\\Users\\oliver\\Documents\\campo.txt",                  "Table", "IgnoreEmptyLines" -> True];     x = te[[All, 1]];     y = te[[All, 2]];     z = te[[All, 3]];     ux = te[[All, 4]];     vy = te[[All, 5]];     wz = te[[All, 6]];     point = Transpose[{x, y, z}];     vel = Transpose[{ux, vy, wz}];          ListVectorPlot3D[Transpose[{point, vel}], PlotRange -> Full,VectorPoints -> All]       The vector field must be as this picture, http://www.mediafire.com/download/9ddgux4ralx712k/1.jpg ![enter image description here](http://i.stack.imgur.com/2Ltcp.jpg)


title: Can I improve the importing speed of Excel data?

text: I have data in an Excel spreadsheet that has 4 rows and 1,000 columns. I am using `Import` as follows:               fittedMatrix  = Table[          Import["sheet.xlsx", {"Sheets", "MC", #, i}] & /@ Range[2, 5],           {i, 2, 1001}     ]; // AbsoluteTiming      which is importing on a column by column basis -- a thousand imports per spreadsheet. Is there a way to import row by row basis? Hopefully, this would improve the speed of import. Or would it be better to transpose my data within Excel first? EDIT: I tried transposing within Excel first to get dimensions of 1,000 x 4 and tried again using:               fittedMatrix=Table[          Import["sheet.xlsx",{"Sheets","mcTransposed", #,i}] &/Range[2,1001],             {i,2,5}     ];//AbsoluteTiming        but now it is giving:               {{1/2 (Import[sheet.xlsx,{Sheets,mcTransposed,#1,i}]&),       1/3 (Import[sheet.xlsx,{Sheets,mcTransposed,#1,i}]&),       1/4 (Import[sheet.xlsx,{Sheets,mcTransposed,#1,i}]&),       1/5 (Import[sheet.xlsx,{Sheets,mcTransposed,#1,i}]&),       1/6 (Import[sheet.xlsx,{Sheets,mcTransposed,#1,i}]&),       1/7 (Import[sheet.xlsx,{Sheets,mcTransposed,#1,i}]&),       1/8 (Import[sheet.xlsx,{Sheets,mcTransposed,#1,i}]&),       1/9 (Import[sheet.xlsx,{Sheets,mcTransposed,#1,i}]&),       1/10 (Import[sheet.xlsx,{Sheets,mcTransposed,#1,i}]&),       1/11 (Import[sheet.xlsx,{Sheets,mcTransposed,#1,i}]&),        instead of my actual Excel data?


title: NonLinearModelFit with Two Dimensional List of Weights

text: I'm currently trying to fit Planck's law (`B[λ, T]`) to measurements, thereby determining Planck's constant. I have a list of triplets containing wavelength, temperature and measured intensity and a list of triplets with their errors, like:               datalist  = {{λ1, T1, B1}, {λ2, T2, B2}, ...}         errorlist = {{σλ1, σT1, σB1}, {σλ2, σT2, σB2}, ...}      Although `NonlinearModelFit` can fit functions of the type `R2 → R`, it seems to only accept a one dimensional list as `Weights`. This is what I tried:               NonlinearModelFit[datalist, B[λ, T], {{h, hlit}}, {λ,T}, Weights -> (errorlist)^-2]      I could of course propagate the partial uncertainties to create one uncertainty for each triplet, thereby have a one dimensional `Weights` list instead, but it seems a bit unethic. Would it be possible to fit Planck's curve to my measurements without having to combine the errors first? **Edit** : Here's the exact error message that I get: > NonlinearModelFit::wts: The value of option Weights -> > {{100.,100.,2500.},{11.1111,25.,25.},{11.1111,2.77778,11.1111}} should be a > list of real numbers or a pure function. >> (I used this data and function as an example: http://pastebin.com/pqxDfe4u)


title: What is the fastest way to get a list of subexpressions and their positions?

text: I have spent quite some time trying to figure out what the fastest way is to get a list lists of all subexpressions and their positions. I have tried things with MapIndexed, which seems ideal in cases where we have an expression in which no functions with Hold-Attributes are present that we can let evaluate freely. For Held expressions, however, I found using MapIndexed complicated and I was unable to get a practical solution using this. Furthermore, I have tried things with Extract and Position. All these things were hinted at in the comments of/answers to the positionFunction question by Mr.Wizard, which caused me to be interested in this. Because I have spent time on this and because I feel this is quite a fundamental question, I would like to get some feedback. To be fair, I am also quite glad with my own answer, as it is considerably faster than the alternatives I found (although it took me a long time), but if there are better alternatives I would be even gladder to know. Lastly, it may be nice for me to refer to this Q&A later, if I ever write a good answer to Mr.Wizards question. **The question is** : What is the fastest way to get a list of lists of subexpressions and their positions, that works with held expressions?    **Test expressions** Let's make a big expression to do tests with. Let               body[i_][n_] := If[n < i, head[body[i][n + 1], body[i][n + 1]], 1];     tree12 = head[body[12][1]];     tree3 = head[body[3][1]];      We have               LeafCount[tree12] == 2^12 && LeafCount[tree3] == 2^3      > (True)


title: Problem with interpolation

text: I have a problem with the function interpolation. when I use it my points are all very shifted. Do you have an idea of the solution?               data = Import["EQE.txt", "Table", "HeaderLines" -> 3];     eqelambda = Table[{data[[n, 1]], data[[n, 5]]}, {n, Length[data[[All, 1]]]}];          h[x_] := hplanck*c/(x*10^-9)     f[x_] := Log[-Log[1 - x]]          data11 = h /@ eqelambda[[All, 1]];     data12 = f /@ eqelambda[[All, 2]];     data1 = Table[{data11[[n]], data12[[n]]}, {n, Length[data11]}];     intdata1 = Interpolation[data1];     ListPlot[data1]     Plot[intdata1[x], {x, 0, 1.8}]      Data files here: https://www.dropbox.com/sh/4ztzyv4zjwwlh1y/u1P_ELgBVA


title: Highlight the same symbol throughout notebook

text: Once I saw people using Matlab use a keystroke shortcut that made all the same symbols as a selected symbol become blue. I am wondering is there is a function in _Mathematica_ that is similar. If so, what's the keyboard convenient shortcut. (Of course, `Ctrl`+`F` can be made to do something a little similar, but that is not what I'm looking for.)


title: Mathematica won't solve equation I know is solvable

text: I'm just trying to solve the Schrodinger equation for hydrogen. We went through the solution by hand in class but Mathematica doesn't do anything when I try to solve it (it just re-displays what I typed in):               DSolve[-h^2/(2*mu)*(1/r^2*D[r^2*D[y[r,theta,phi],r],r] +          1/(r^2*Sin[theta])*D[Sin[theta]*D[y[r,theta,phi],theta],theta] +          1/(r^2*Sin[theta]^2)*D[D[y[r,theta,phi],phi],phi]) -          k*q^2/r*y[r,theta,phi] == energy*y[r,theta,phi],y,{r,theta,phi}]


title: find the real root

text: I have the following equation: \begin{equation} (y-1)^{b1} - C~~ y~~ \exp(a x)=0 \end{equation} where $a, b$ are real constants, $C$ may be a complex number. I need to find the real solution of the above equation for each choice of $x$, with $x \in [-100, 100]$.   I tried with $\mathbf{fzero, fsolve}$ in _Matlab_. But it does not work. I also tried to solve with the Newton - Raphson method. The outcome is negative. Is it possible to solve it in any other way. Any help/suggestion/advice, will be very useful. I tried with the below given mathematica code, but it almost give up as I increase the range of $x$. Here is my mathematica code:               k  = 0.5;   (*k is positive*)     b  = 0.01;  (*b is a positive number not greater than 1*)     a1 = bk;     b1 = 1 + b;     a2 = b1 + k;     a  = a1 / a2;     y0 = 0.5;     z  = ConstantArray[0, 11];     For[x = −5; i = 1,         x < 6,         x = x++; i++,      t = Solve[y0 (1 − y)^b1 − y (1 − y0)^b1 Exp[a x] == 0, y];      z[[i]] = y /. t]      I need the real solution, not the real part of the solution. Secondly my constants are dependent on parameters $k, b$ as stated in the code. And $C = \frac{(1-y0)^{b1}}{y0}$. Hope my question make sense in the mathematica category. Any further query / suggestions/ feedback, please let me know. Thank you all who show concern; I require your help.


title: Unexpected result when reading Cell with comment-lines by NotebookRead

text: When considering this question about re-formatting `Cell` (also this one), I encountered an issue which confuses me. I'll let the code itself speak: Consider the following simple `Cell` expression, which contains a comment line:               cellexpr =        Cell[BoxData[{RowBox[{RowBox[{"a", ";"}], "\[IndentingNewLine]",             RowBox[{"(*", RowBox[{"b", ";"}], "*)"}]}],           "\[IndentingNewLine]", "c"}], "Input"];      Write it to a `Notebook`:               testnb = NotebookCreate[];     NotebookWrite[testnb, cellexpr];      It looks like the following, which is what one would expect: ![enter image description here](http://i.stack.imgur.com/9ozU1.jpg) Now read the `Cell` expression back from `testnb`:               SelectionMove[testnb, Before, Notebook];     SelectionMove[testnb, Next, Cell];     NotebookRead[testnb]      ![Mathematica graphics](http://i.stack.imgur.com/DDMrU.png) Note the first `RowBox`, it has a structure as `RowBox[ item1, item2, ...]`, which is ill-posed since _the first argument to RowBox must be a list_. And the obtained `Cell` expression is therefor ill-posed, which can be seen by `CellPrint`-ing it: ![enter image description here](http://i.stack.imgur.com/PY050.jpg) I noticed that if the comment-line part is removed (e.g. by deleting `"(*"` and `"*)"` in `cellexpr`), everything works fine. And for the example in this question, the second comment is correctly obtained: ![Mathematica graphics](http://i.stack.imgur.com/rwS6u.png) # My question: Did I miss something? Or is this a bug? My system: **Mathematica 9.0.0.0** on **Windows 7 32-bit**


title: How to numerically integrate this integral?

text: I want to integrate the function funcin (spherical coordinates).               ϵ=78.36     λ=0.548881         funcin =        1/(ϵ*π)*Exp[-(2*r + λ*Sqrt[r^2 + ρ^2 -          2*r*ρ*Cos[θ]])]*r^2*Sin[θ]*1/Sqrt[ρ^2 + r^2 - 2*r*ρ*Cos[θ]]     intfuncing = Integrate[funcin, {r, 0, Infinity}, {θ, 0, π}, {ϕ, 0,2 π}]      If I use analytic calculation (`Integrate`), an integral over r is left, which must be numerically evaluated, e.g., by using `N[intfuncing]` for specific ρ. For example I can write:                Do[ρ = 0.1 + (i - 1)*0.05; int[[i]] = N[intfuncing], {i, 60}]      to calculate the integral at 60 points. But I get an error by that: > NIntegrate::slwcon: Numerical integration converging too slowly; suspect one > of the following: singularity, value of the integration is 0, highly > oscillatory integrand, or WorkingPrecision too small. If I try to evaluate the integral numerically with `NIntegrate`, I get: > the integral ... evaluated to non-numerical values for all sampling points > in the region with boundaries {{∞, 0.}, {0, 3.14159}, {0, 6.28319}}. Does anyone have an idea how to solve this problem?


title: Where can I find the Distributions Palette?

text: I was watching the "Statistics: Modeling with Statistical Distribution" Training Course http://www.wolfram.com/training/videos/DAT016/ and in one of the slides, the following image showed up. Does anybody know if this palette is available and where can it be found? ![enter image description here](http://i.stack.imgur.com/OohYD.png)


How to return matching sublists or empty list               m1 = {{1, 0.5}, {2, 0.4}, {3, 0.1}};     m2 = {{1, 0.5}, {0, 0.4}, {0, 0.1}};     Commonest[Join[m1, m2]]       out:               {{1, 0.5}}      But it fails to return 0 or empty list as the lists do not match               m1 = {{1, 0.5}, {2, 0.4}, {3, 0.1}};     m2 = {{0, 0.5}, {0, 0.4}, {0, 0.1}};     Commonest[Join[m1, m2]]       out:               {{1, 0.5}, {2, 0.4}, {3, 0.1}, {0, 0.5}, {0, 0.4}, {0, 0.1}}      how to return empty list?


title: Calculate expected value of custom pdf

text: I've a custom pdf in the sense that it's the convolution of several other PDFs               p[t_] := Convolve[p1[x],p2[x],x,t];      Now I want to calculate the expected value of this 'new' pdf w.r.t $t$ $\mu = \mathbb{E}_t [ p(t) ]$ How can I do this with mathematica?


title: How to get rid of the perspective effect in a 3D graphics

text: I have plotted a figure of MoS2 crytal structure. But the actual output looks like the spheres are not in the correct position due to the perspective effect. I obtained the correct position figure by setting the `ViewPoint` to `Infinity`. But when I rotate the figure, the infinity effect fails and the perspective effect takes place again. ![before and after rotation](http://i.stack.imgur.com/PI6Hk.png) I was wondering if there is a way to get rid of the perspective effect when you draw a graphic? Thank you. Here is my code               a0 = 1; ceng = 1; znn =3*ceng; ynn = 5; xnn = 5; a1 = 2; cznn = 3; hh = 2;     p1[θ_] := RotationTransform[θ, {0, 0, 1}];     posx1 = (nx1 - 1) a0 + ((ny1 - 1) a0)/2 + (Mod[nz1 - 1, 3] a0)/2;     posy1 = Sqrt[3]/2 (ny1 - 1) a0 + (Sqrt[3] Mod[nz1 - 1, 3] a0)/6;     posz1 = Sqrt[3]/2 (nz1 - 1) a0 + Floor[(nz1 - 1)/3] a0;     sinpq2 = Transpose[Table[{posx1, posy1, posz1}, {ny1, ynn}, {nz1, znn}, {nx1, -xnn, 0}]];     rr = 0.3 a0;     tom2 =        Table[         Graphics3D[{If[Mod[cc, 3] == 2, Pink, Yellow], Sphere[sinpq2[[cc, bb, aa]], rr]}],          {aa, xnn}, {bb, ynn}, {cc,znn}];     Show[tom2,        Axes -> False,        BoxStyle -> Directive[Orange, Opacity[0]],         BoxRatios -> Automatic,        PlotRange -> All,        Background -> Black,         ViewPoint -> {0, 0, ∞}]


title: two histograms ratio

text: I have two histograms and using listplot to draw both. Now, I want to draw a second plot, below the first, with the ratio of each bin. Does anyone know how to do this? Many thanks. This is the code I'm using to draw the histograms:               Needs["PlotLegends`"]          dadosGtop = Import["Gtop_PR.dat", "table"];          costhbGtop = Table[dadosGtop[[i]][[1]], {i, 1, Length[dadosGtop]}];          costhleGtop = Table[dadosGtop[[i]][[2]], {i, 1, Length[dadosGtop]}];               histPlot[data_, bins_, origin_, color_, label_, title_, nome_] :=        Module[{countBorder1 =           Partition[Riffle[Riffle[#1, #1[[2 ;;]]], Riffle[#2, #2]], 2] & @@            HistogramList[data[[1]], bins],          countBorder2 =           Partition[Riffle[Riffle[#1, #1[[2 ;;]]], Riffle[#2, #2]], 2] & @@            HistogramList[data[[2]], bins],         },        ListLinePlot[{countBorder1, countBorder2}, PlotRange -> All,          PlotStyle -> {{color[[1]]}, {color[[2]], Dashed}},          AxesLabel -> {Style[label[[1]], 14, Bold],            Style[label[[2]], 14, Bold]}, AxesOrigin -> origin,          LegendPosition -> {0.65, 0.1}, LegendSize -> 1,          LegendShadow -> None,          PlotLegend -> {Style[nome[[1]], 12, Bold],            Style[nome[[2]], 12, Bold]},          PlotLabel -> Style[title, Black, 14, Bold],          TicksStyle -> {16, Bold}, ImageSize -> Scaled[0.6]]];          histPlot[{costhbGtop, costhneGtop}, {-1, 1, 0.1}, {-1, 0}, {Green, Blue}, {"\[Eta]",        "\!\(\*FractionBox[\(dN\), \(d\[Eta]\)]\)"}, "Pseudorapidity of b", \     {"b", "ne"}]      Here is a data sample:               dadosGtop={        {-0.68, 0.536, 0.316}, {-0.394, 0.187, 0.287}, {-0.874, 0.753, 0.474},        {-0.202, 0.18, 0.066}, {-0.267,  0.894, -0.077}, {0.126, -0.144, -0.063},        {0.952,  0.63, -0.953}, {0.671, 0.073, -0.84}, {-0.344,  0.72, -0.024},        {0.824, -0.205, -0.741}, {0.718, -0.793, -0.268}, {-0.423, 0.568, -0.204},        {-0.192, -0.096, 0.357}, {-0.03,   0.865, -0.629}, {-0.784, 0.39, 0.588},        {0.98, 0.59, -0.953},   {-0.97,  0.682, 0.653}, {-0.654, 0.907, -0.201},        {-0.35,   0.712, -0.176}, {-0.929, 0.654, 0.48}, {-0.479, 0.826, 0.099},        {-0.54, 0.785,-0.724}, {-0.812, 0.818,-0.069}, {-0.988, -0.083, 0.89},        {-0.559, 0.976,-0.188}, {0.748, 0.211,-0.994}, {0.507, -0.527,-0.266},        {0.776, -0.025,-0.964}        }


title: How to introduce custom hot keys for the styles of cells?

text: In the JournalArticle StyleSheet there are useful hot keys Alt+6 for a DisplayFormulaNumbered and Alt+5 for the DisplayFormula. Such hot keys, however, are not present in the Default StyleSheet. Even more, there Alt+5 is reserved for the Section, and Alt+6 - for the subsection styles. Is it possible to introduce custom hot keys for (generally) any cell style for which there is no built-in one?


title: How to tell Mathematica not to simplify an expression

text: While there is this question with a very similar title, it does not answer my question, which is: I have part of an input, in my case               Re[Exp[I*x]]      which _Mathematica_ "simplifies" to > >     Cos[Re[x]]/E^Im[x] >   So I am wondering how to tell _Mathematica_ to leave this expression, whether it's alone or part of a longer formula, in its previous form rather than to change it as shown here. ### Update I should probably add I am still running version 6, hoping this is not causing the issue.


title: Gather list elements by index

text: The following list has some elements that are labeled. For example `{1, 2} -> 1, {-1, 3} -> 3`, etc:               list = {{1, 2}, {-1, 3}, {5, 6}, {-3, 4}, {7, 8}, {-9, 1}, {0, 1}};     labels = {1, 3, 2, 1, 2, 1, 3};      What is a good way to gather `list`'s elements clustered according to their labels?               clusters = {{{1 ,2}, {-3, 4}, {-9, 1}}, {{5, 6}, {7, 8}}, {{-1, 3}, {0, 1}}}


title: keyboard sequence for Magnify in version 8?

text: It used to be that you could find a Magnify item in the Format menu of the Mathematica front-end, at the very bottom if I remember correctly. You could get at the item in Windows by a keyboard sequence like `Alt-R`, `M`, then a number. Mac probably had something similar. This was really useful for mouse avoiders like me. That little tiny drop menu in the extreme lower right of a notebook is annoying to catch with a mouse on highest-speed setting, which you need on a high-def screen with 1920 or 2560 pixels width. My mouse movements end up looking like a plot of a strange attractor swirling around the target! I haven't been able to find the Magnify menu item in Mathematica 8 nor any other keyboard shortcut for notebook-magnify in the Mathematica documentation center. Would be grateful for anyone pointing out any means for accessing notebook magnify from the keyboard.


title: How to force the compilation language to be C++ (not C) in CreateExecutable or CreateLibrary

text: I'm trying to speed up a section of a Mathematica 9.0.1 notebook by performing some calculations in C++ with the Cilk Plus and Threading Building Blocks tools available for the Intel C++ 14.0 compiler [in Intel Parallel Studio XE 2013 SP1, installed with VS 2012 Professional, running under Windows 8.1 Pro]. I would like to avoid using MathLink to access the C++ code, if possible, and "get away with" using the CreateExecutable and CreateLibrary functions of Mathematica. I've had no success with CreateLibrary, as yet, but I have had one "success" and one failure with CreateExecutable. I'm trying to understand my one success as a way of possibly fixing the failures. The simple Cilk-enhanced C++ code below adds the number 7 to itself one trillion times in about 8 seconds on a 4-core, 3.5 GHz clock, laptop. This code is not useful from the standpoint of the result it computes, but it quickly makes the fan run and serves to test whether or not Cilk-enhanced C++ code can be incorporated within a Mathematica notebook. So, apparently, it is possible to run Cilk-enhanced C++ code from Mathematica. The code works if I first write the Cilk-enhanced C++ code string, CilkMain, to a file with the extension .cpp, and then use that .cpp file as the first (list) argument of CreateExecutable. When I use the ShellCommandFunction and ShellOutputFunction options of CreateExecutable to look at what happened, it seems that Mathematica looked at the .cpp extension, forwarded a .cpp file to the Intel compiler, and everything worked.               In[1]:= nbdir = NotebookDirectory[];         Needs["CCompilerDriver`"]         CCompilers[Full];         $CCompiler = {"Compiler" -> CCompilerDriver`IntelCompiler`IntelCompiler,         "CompilerInstallation" -> "C:\\Program Files (x86)\\Intel\\Composer XE 2013          SP1"};          In[5]:= cilkMain = "         #include<cilk/cilk.h>         #include<cilk/reducer_opadd.h>         #include<stdio.h>              int main()         {         cilk::reducer_opadd<long long>j(0);         long long size=(long long)(1000)*(long long)(1000*1000*1000);                       cilk_for(long long i=0;i<size;i++) j+=7;              printf(\"The value of j is %14lld\\n\",j.get_value());         return 0;         }";          In[6]:= Export[nbdir <> "cilkMain.cpp", cilkMain, "Text"];          In[7]:= cilkExe = CreateExecutable[{nbdir <> "cilkMain.cpp"}, "cilkExeFile"];          In[8]:= AbsoluteTiming[Import["!" <> QuoteFile[cilkExe], "Text"]]          Out[8]= {8.165778, "The value of j is  7000000000000"}          In[9]:= cilkExe = CreateExecutable[cilkMain, "cilkExeFile"]             cilkExe = CreateExecutable[cilkMain, "cilkExeFile", "Language" -> "C++"]          Out[9]= $Failed          Out[10]= $Failed      But if I give the Cilk-enhanced code string directly to CreateExecutable as its first (non-list form is required for a string) argument, with or without the "Language" option set to "C++", the code fails. The printed results from the ShellCommandFunction and ShellOutputFunction options show that for a string argument, a file with extension .c is forwarded to the Intel compiler, which leads to failure because the Cilk functions require C++ compilation. Is there a direct way to tell CreateExecutable and CreateLibrary to forward code for C++ (not C) compilation? There is little documentation of the "Language" option in the Mathematica help, and no examples. What you see in the notebook above is merely my best guess as to how to force C++ compilation. Clearly, it is an incorrect guess, likely based on incorrect understanding. I don't like resorting to tricks, such as writing a string to a file with a special extension, in order to fool a Mathematica function. What is the right way to do this? Learning the right way may well set me on the road to fixing the failures. P.S. Thanks for the quick replies. Will look at CCompilerDriver` code, then move on to trying to trick CreateLibrary in a similar way.


title: Bad fonts in Mathematica 10

text: In _Mathematica_ V10, the glyphs for mathematical and/or other special symbols are wrong. I see this in input cells and also in the Basic Math Assistant palette. How do I solve this problem?


title: Is pure pattern matching without PatternTest and Condition Turing-complete?

text: Note that this question is _not_ a duplicate of that one. It is specifically about the pattern-matching engine, and explicitly excluding those patterns which call back into the full evaluation (i.e. `PatternTest` and `Condition`; if there are others like those, consider them excluded as well). To state the problem more specifically: Given a problem with a yes/no answer which can be decided in finite time by an appropriate Turing machine, does there always exist a Mathematica pattern involving neither `PatternTest` nor `Condition` together with an appropriate encoding for the input data which matches iff the Turing machine would give "yes" for the input data? To make more clear what I mean, I give an example of a problem solvable both with a Turing machine and with the pattern matcher: Given a natural number, determine whether that number is even or odd. It is obvious that a Turing machine can solve this problem in finite time. Here's how pattern matching can solve that problem: Encode the natural number into a list of as many `1`, so that 0 is `{}`, 1 is `{1}`, 2 is `{1,1}` etc. Then the pattern implementing the test is simply `{PatternSequence[1,1]...}`.


title: Software for effectively modeling gears

text: Are then any applications for effectively modeling gears in mathematica?


title: What is the story with Removed symbols?

text: The system function `Remove` evidently exists primarily to turn a fatal problem into an annoying one, by giving the user a (rather blunt) instrument with which to resolve symbol clashes. Presumably, it works by removing the entry for a given symbol from whatever internal table Mathematica uses to look them up by name. However, there can be some interesting consequences when you have a reference to a symbol that you later `Remove`. First, we need to set up a symbol that we will remove, and give another symbol a reference to it:               In[1]:= y = 3     Out[1]= 3          In[2]:= x := y          In[3]:= x     Out[3]= 3          In[4]:= OwnValues[x]     Out[4]= {HoldPattern[x] :> y}      And then we can remove it:               In[5]:= Remove[y]          In[6]:= x     Out[6]= Removed["y"]      Now, we have `Removed["y"]`, which is the ghost of the symbol we just bludgeoned to death. However, contrary to appearances, `Removed` is not the head of the expression:               In[7]:= x // Head     Out[7]= Symbol       It's still a symbol. It appears to just have had all its values cleared when it was `Remove`'d. However, you need an elaborate incantation to contact a symbol that's moved on into the spirit world in order to verify this:               In[8]:= OwnValues[x]     Out[8]= {HoldPattern[x] :> Removed["y"]}          In[9]:= ReleaseHold[Hold[OwnValues[x]] /. OwnValues[x]]     Out[9]= {}      That's OK, though, because I can still give new values to the removed symbol!               In[10]:= With[{yy = x},               yy = 17]     Out[10]= 17          In[11]:= ReleaseHold[Hold[OwnValues[x]] /. OwnValues[x]]     Out[11]= {HoldPattern[Removed[y]] :> 17}      So, what _can't_ you do with a removed symbol that you can do with an ordinary symbol? And is there any reliable programmatic way to check whether a symbol really has been removed, seeing that it has a perfectly ordinary `Symbol` head? I suppose you can hack something together with `StringMatchQ`, but that just feels wrong and it's tough to get the evaluation order right if the removed symbol might have `OwnValues`.


title: Count Elements in Image

text: I have the following image: img1 ![enter image description here](http://i.stack.imgur.com/wOJps.png) I'm trying to count al these colored cells and draw a circle around them. I really don't now how I can use `SelectComponents` for this image. And `EdgeDetect` has the following result: img2 ![enter image description here](http://i.stack.imgur.com/hit12.png) Maybe some tips or examples. Greetings


title: How can I get even steps on x and y axes in a plot?

text: I'm plotting the shortest distance from a point to a line using the following code               Show[Plot[1/2 x + 1/2, {x, -6, 7}],           ListPlot[{{4, -2.5}, {2, 1.5}}, Joined -> True, PlotMarkers -> Automatic]]      As this is the shortest line from the point to the line, the angle between the two lines should be 90 degrees. It doesn't show up like that in _Mathematica_ , however, since the y-axis is incrementing in visually smaller steps than the x-axis. How can I get _Mathematica_ to automatically to use even steps on the two axes?


title: Extracting function calls from an expression

text: I have an expression like this:               expr = F[0, 1] + 2 F[0, 0] - 17*F[2, 0]      and I want to transform it to a list consisting of all function calls with its arguments:               MyList = {F[0, 1], F[0, 0], F[2, 0]}      Does anyone know a clever way to do this in _Mathematica_? My currently best solution is using ToString and do string-manipulations, but it is defintivly very slow and ugly.


title: NotebookWrite Cell with Grid

text: I'd like to `NotebookWrite` a `Cell` in `StandardForm` with a `Grid` to a new document. What I'd like to copy is               toCopy = TraditionalForm@Grid[{{a^2, b^2, c^2}, {d^2, e^2, f^2}}]      If I now use the following code               NotebookWrite[      CreateDocument[]      , toCopy]      I get a red rectangle in the new Notebookbook. I've tried to change all letters a to f to "a" ... "f", but nothing changed. I am somewhat puzzled... What I missing here? Thanks for all help, as always! Edit: With the answer of Alexey, it works good to copy the `Grid` to the new Notebook. But the TraditionalForm is lost: I get InputForm. Even using               NotebookWrite[      CreateDocument[],       ToBoxes[toCopy, TraditionalForm]]      doesn't seem to work. Any more help, as always, very much appreciated!


title: Drawing a series of circles with `MapThread` & `Graphics`

text: I'm attempted to use `MapThread` to draw a series of circles at coordinates correspond to some list, like so:               pointList = {{1, 0}, {1, 2}, {1, 3}};     Graphics[MapThread[{Circle[#1, 0.1]} &, pointList]];      However, this fails. Looking at the output for:               MapThread[{Circle[#1, 0.1]} &, pointList]      I see the following:               out -> {{Circle[1, 0.1]}, {Circle[0, 0.1]}}      MapThread is obviously not doing what I'd like it to do. Where's my error?


title: How to control variables of outer and inner Manipulates?

text: Consider the following ( working ) snippet:                 Manipulate[        Column[{         Manipulate[          vote,          {vote, {"Yes", "No"}},          Initialization :> {votes = 0}         ],         k,         Button["TEST", Print[votes]]        }],        {k, 1, 5, .5}       ]      My question concerns programming style and Outer/Inner Manipulate structures. What is the best way to handle code that is executed conditionally based on values in the inner Manipulate, but needs to be processed further in the outer Manipulate? I.e. checking thresholds, maintaining sub-totals, balancing, etc. To make my question 'answerable' I have translated it in terms of a simplified example: **how / where would you maintain a Yes vote counter that is used in the outer manipulate?** UPDATE: The requested pattern would also apply to synchronizing views in data on Tabs on a TabView.


title: Vertical alignment of FrameTicks Text

text: The text box of a FrameTick/Tick is, by default, vertically centered on the tick mark. ![Illustrating alignment of FrameTicks textbox](http://i.stack.imgur.com/uZgGg.png) Is there a way to adjust the vertical alignment of FrameTick text? Specifically, along the lines of Baseline, Top, etc. FrameTicksStyle in combination with TextAlignment/Alignment does nothing.


title: ArrayRules for a ragged list

text: Let there be a sample list as ,               l = {a, {{b, c}}, {d, e}, {f}, {{g, {y}, u, h}, {{{{k, j}}}}},k, {{{{q}, {w}, {r}, {x}}}}};     ArrayRules[l]      **ArrayRules::rect: Nonrectangular array encountered. >>** is the error thrown. So, I was just wondering that if someone needs to preserve list structure using a similar kind of functionality, than what might be the steps needed. My intention is to pass data to replace later rather than as rule in ArrayRules. I could parse list to find positions information like ArrayRules using following code,                ListRules[l_List] :=      Module[{l1 = l, l11, s1, pos, M, tpos, trpos, sp, ntrpos, temntrpos,         fin, fin2},        {l11 = {#} & /@ l1,         s1 = Map[{#, Position[l11, #]} &, l11,Infinity] /. {a_, {{s___}}} -> {s} //. {d___, {}, e___} -> {d,e},         pos = Table[s1[[i]] //. {___, {a___List}, ___} -> a, {i, 1,Length[s1]}],         M = Last[SortBy[pos, Length]] // Length,         tpos = Table[If[Length[pos[[i]]] < M, PadRight[pos[[i]], M, 1], pos[[i]]], {i, 1, Length[pos]}],         }; tpos]      listrules= ListRules[l]      > {{1, 1, 1, 1, 1, 1, 1}, {2, 1, 1, 1, 1, 1, 1}, {2, 1, 1, 2, 1, 1, 1}, {3, 1, > 1, 1, 1, 1, 1}, {3, 1, 2, 1, 1, 1, 1}, {4, 1, 1, 1, 1, 1, 1}, {5, 1, 1, 1, > 1, 1, 1}, {5, 1, 1, 2, 1, 1, 1}, {5, 1, 1, 3, 1, 1, 1}, {5, 1, 1, 4, 1, 1, > 1}, {5, 1, 2, 1, 1, 1, 1}, {6, 1, 1, 1, 1, 1, 1}, {5, 1, 2, 1, 1, 1, 2}, {5, > 1, 2, 1, 1, 1, 1}, {6, 1, 1, 1, 1, 1, 1}, {7, 1, 1, 1, 1, 1, 1}, {7, 1, 1, > 1, 2, 1, 1}, {7, 1, 1, 1, 3, 1, 1}, {7, 1, 1, 1, 4, 1, 1}} Than I tried to create it back to a list using following method,               CreateList[s_List] :=      Module[{tpos = s, trpos, sp, ntrpos, temntrpos, t, x, y,         h}, {trpos =Table[tpos[[i]] -> RandomInteger[100], {i, 1,Length[tpos]}],         sp = SparseArray[trpos],         ntrpos = Normal[sp],         temntrpos = ntrpos //. {a___, {h___, 0 ..}, b___} -> {a, h, b} //. {a___, {}, b___} -> {a, b}         }; temntrpos        ]     CreateList[listrules]      gives, > {{{{{{76}}}}}, {{{{{82}}, {{83}}}}}, {{{{{67}}}, {{{19}}}}}, {{{{{32}}}}}, > {{{{{51}}, {{22}}, {{60}}, {{1}}}, {{{{26,59}}}}}}, {{{{{12}}}}}, {{{{{6}, > {78}, {34}, {72}}}}}} It shows that it has been able to retain nesting structure but there are extra braces associated. I tried to use Dimension, Depth etc. I can get rid of nesting for single elements by associating dimension from original list with them and flattening all those with maximum dimension as 1 for Rest[sublist]. But in case of multiple nesting, I am failing. I have to keep number of braces same in both source and destination.


title: Plotting vectors originating from the origin in 3D

text: I have an array of data with 3D elements. Ex: `x = {{1,2,3}, {3,4,5}, {5,6,7}}`. I want to show this data in 3 dimensions, such that each point in the space is shown as a vector originating from the origin. There should be an arrow/line whose one end is at the origin $(0,0,0)$ and the other end at the point $(1,2,3)$. Which function should I use?


title: Efficient setting of properties of multiple vertices in Graph

text: The functions `SetProperty` and `PropertyValue` can only set a single property of a single vertex, as far as I know. How do I set a property for multiple vertices simultaneously? In the documentation, they recommend using `Do` to set multiple properties, but I've heard that `Do` is not the most efficient way to do things in _Mathematica_. Are there any alternatives? **EDIT :** The only approach seems to make several calls to `SetProperty` or `PropertyValue` (which is faster), one call for each distinct vertex property I want to set. From the answers so far it seems that there is no Mathematica equivalent to `SetProperty` or `PropertyValue` that sets several properties of distinct vertices at once. But I'd still hope that something could be done directly on the `Graph` object, bypassing `SetProperty` and `PropertyValue`.


title: Missing titles in palettes with Win 8

text: I just noticed that MMA (8 and 10) in Windows 8 on my machine does not display the title of any palette. For ex. Basic Math Assistant palette appears without title. Same with user-defined palettes Can you confirm this or it is just my Win 8? If it is just me, as I suspect, can anybody suggest any setting change to Win 8 that I may perform in order to show titles in palettes? Titles in notebooks are ok.


title: Numerical rule evaluation -> {True, False} to deviation of target equation

text: I solve some equations numerically with **FindRoot[]** returning a quadruple {1,2,3,4}. Because the solver sometimes do not find any roots depending on parameterization of these equations I select only those replacement rules "full filling" the equations:               Select[rules, ! MemberQ[eqns /. #1, False] &];      My question is the following: How can I easily calculate **the deviation of an application of a replacement rule** quadruples containing a False so i can check how "badly" some of my equations are not met. My problem is that as soon as I apply an rule to an equation the result is of type boolean and not numeric - which is needed for calculating the deviation. To note: I do back substitution of my previous solution into the solver as I'am variating some parameters. (see here) Thank you for your suggestions!


How to use summation to get the value of a binary number? I want to do this: $(x_{n}x_{n-1}...x_{0})=\sum_{i=0}^{n}x_{i}\cdot b^{i} $ But it seems that I can only do something like this: $\sum_{i=1}^{10}i^{2}$ I imagine that there is some indexation function which will help to do so, I also know how to do in another way, but is it possible to do this using summation?


title: Solve ODE $d^2u/dx^2 + u/A = 0$

text: How can I solve following ODE with Mathematical: $$d^2u/dx^2 + u/A = 0 \quad (\text{or } \ C),$$ with the conditions: $$ \left.\frac{d^2u}{dx^2}\right|_{x=0} = 0, $$ $$u(x=0) = B$$ and $$\left.\frac{du}{dx}\right|_{x=W} = 0, $$ $A$, $B$, and $C$ are constants.


title: Transform sequential cell operations to programmatic workflow

text: Let's say I have a workflow that involves importing images and turning them into an animated gif. Here's how I currently have it setup: Import Images:               imports = {};     importimages[] := Module[{a},        a = SystemDialogInput["FileOpen"];        If[ListQ[a], Table[Import[a[[i]]], {i, 1, Length[a]}], Import[a]]]     imports = Flatten[Append[imports, importimages[]]]      Allow for selection and rearranging:               sels = Range[Length[imports]];     CheckboxBar[Dynamic[sels], Table[i -> imports[[i]], {i, 1, Length[imports]}]]     imgs = Dynamic[imports[[sels]]]      Set animation rate and preview:               Manipulate[       displayrate = 1/rate;       ListAnimate[Setting[imgs], AnimationRate -> rate, AnimationRunning -> False],       {{rate, 1}, 0, 10, 0.1, LocalizeVariables -> False}]      Export to gif:               Export["~//Desktop//test.gif", Setting[imgs], "DisplayDurations" -> displayrate]      (By the way, feel free to improve code.) My question is, what is the best way I can smoothly and dynamically wrap this entire workflow into a graphical program where if I were to put a non- _Mathematica_ user in front of it, he/she can easily work it? This question mainly stems from my poor understanding of the dynamic constructs and roots in action-based programming. The gif routine is just an example for future implementations that involve concise sequential steps.


title: 1D quasicrystal: points on a line nearest to points on a lattice

text: I have a simple lattice / line manipulation:               Manipulate[r = 10; b = {{0, r}, {r, 0}};     l1 = Flatten[Table[i b[[1]] + j b[[2]], {i, 0, r}, {j, 0, r}], 1]/r;     Clear[a, b]; b = a /. Solve[a + y == 90, a][[1]]; x = y Pi/180;     g = Graphics[Line[{{0, 0}, {If[y <= 45, r/Cos[x], r/Cos[b Pi/180]], 0}}]];     rot = l : Line[pts_] :> Rotate[l, x, {0, 0}];     Show[Graphics[Point[l1], Frame -> True, AspectRatio -> 1], g /. rot], {{y, 45}, 0, 90}]      and would like to add points (that move with the manipulation) on the line that are perpendicular to the nearest points of the lattice, as shown below: ![enter image description here](http://i.stack.imgur.com/79O89.png) It would be a bonus if the perpendicular joining lines appeared also. The only way I can think of pursuing this is to use something like `Nearest`, `FrobeniusSolve`, etc. (have been looking at the answers to this question with little success so far) to generate data for something along the lines of:               f = Graphics[Point[{{0, 0}, data, {If[y <= 45, r/Cos[x], 12], 0}}]];     rot1 = l : Point[pts_] :> Rotate[l, x, {0, 0}];     Show[Graphics[Point[l1], Frame -> True, AspectRatio -> 1], g /. rot, f /. rot1]      # Note: As noted by Vitaliy Kaurov below, the defining 'band' (dashed in the diagram) would not (necessarily) be symmetric about the main line. In this instance, the ratio of smaller to larger is the golden ratio. This is more obvious when looking at central red line in the above image - compare with: ![enter image description here](http://i.stack.imgur.com/NG1d7.png) I would ideally like this band width to be adjustable within the manipulation, but this is a minor concern. # Update A minor modification of george2079's code               a = N[1/2 (Sqrt[(2/(5 + Sqrt[5]))] + Sqrt[10/(5 + Sqrt[5])])];     b = N[Sqrt[2/(5 + Sqrt[5])]];     Manipulate[Module[{grid, f, lndat, near, lnpts, lines1, lines2}, band = 1;     grid = Flatten[Outer[List, Range[-4, 4], Range[-4, 4]], 1];     f[x_] := m x;     lines1 = Select[pointlinedis[{{{0, 0}, {4, f[4]}}, grid}],      Norm[Subtract @@ #] < a band &];     lines2 = Select[pointlinedis[{{{0, 0}, {4, f[4]}}, grid}],      Norm[Subtract @@ #] < b band &];     Show[Plot[f[x], {x, -4, 4}, PlotRange -> 4],      Plot[f[x] - b band/Cos[ArcTan[m]], {x, -4, 4}, PlotRange -> 4],      Plot[f[x] + a band/Cos[ArcTan[m]], {x, -4, 4}, PlotRange -> 4],      Graphics[{{Opacity[.5], PointSize[.015], Point[grid]},     {Orange, Thickness[.005], Line /@ lines1}, {Red, Opacity[.5],      PointSize[.03], Point[#[[1]] & /@ lines1]}, {PointSize[.015],      Blue, Point[#[[2]]] & /@ lines1}}], AspectRatio -> 1]], {{m, N[Pi/5]}, -10, 10}]      gives ![enter image description here](http://i.stack.imgur.com/TYEXg.gif) which is nearly what I was after, but I would really like to exclude the points outside the lower line. If I swap `lines1` for `lines2` in bottom 3 lines of code, they are excluded, but so are some of points in top band. I have tried playing around with various `If` combinations, but can't seem to select points in upper band separately to points in lower band. Also, point near $\{3,3\}$ shouldn't be included (though george2079 does note that this may happen in his answer).


title: Why is this list not a valid vector field dataset or a valid list of datasets?

text: a = 0.1     x = Pi/2     data = Table[With[{y = -1 + 0.5*i, z = -1 +0.5*j},        {{NIntegrate[-(z/(t^2 - 2 t x + x^2 + y^2 + z^2)^(3/2))          - (3 (y z Sin[t]) a)/(t^2 - 2 t x + x^2 + y^2 + z^2)^(         5/2) + (3 z (t^2 - 2 t x + x^2 - 4 y^2 + z^2) Sin[t]^2 a^2)/           (2 (t^2 - 2 t x + x^2 + y^2 + z^2)^(7/2)), {t, -∞, ∞},         Method -> {"GlobalAdaptive", "MaxErrorIncreases" -> 200,           Method -> "GaussKronrodRule"}, AccuracyGoal -> 20,         MaxRecursion -> 20],        NIntegrate[y/(t^2 - 2 t x + x^2 + y^2 + z^2)^(3/2)         + ((t Cos[t] - x Cos[t] - Sin[t])/(t^2 - 2 t x + x^2 + y^2 + z^2)^(3/2)           + (3 y^2 Sin[t])/(t^2 - 2 t x + x^2 + y^2 + z^2)^(5/2)) a +             ((3 y (t Cos[t] - x Cos[t] - Sin[t]) Sin[t])/(t^2 - 2 t x +               x^2 + y^2 + z^2)^(5/2) + (3 y (-t^2 + 2 t x - x^2 + 4 y^2 - z^2) Sin[t]^2)/         (2 (t^2 - 2 t x + x^2 + y^2 + z^2)^( 7/2))) a^2, {t, -∞, ∞},         Method -> {"GlobalAdaptive", "MaxErrorIncreases" -> 700,           Method -> "GaussKronrodRule"}, AccuracyGoal -> 20,         MaxRecursion -> 60] },        0.}], {i, 0, 4}, {j, 0, 4}];      a)               data5 = data /. {_Complex -> 0.}     data1 = Flatten[data /. {_Complex -> 0.}, 1]          By = data1[[All, 1, 1]]          Bz = data1[[All, 1, 2]]          B = Sqrt[By^2 + Bz^2]          data2 = Transpose[{By, Bz}]          data3 = Transpose[{data2, B}]          data4 = {data3}      /a)                ListStreamDensityPlot[data4, VectorScale -> Automatic,       Evaluated -> True, DataRange -> {{-1, 1}, {-1, 1}},       ColorFunction -> ColorData["Rainbow"]          ListStreamDensityPlot::vfldata: {{{1.00103,-0.998971},1.41421},     {{0.80244,-1.60145},1.79124},{{0.,-2.00492},2.00492},{{-0.80244,-1.60145},1.79124},      {{-1.00103,-0.998971},1.41421},<<15>>,{{1.00103,0.998971},1.41421},     {{0.80244,1.60145},1.79124},{{0.,2.00492},2.00492},{{-0.80244,1.60145},1.79124},     {{-1.00103,0.998971},1.41421}} is not a valid vector field dataset or a valid list of      datasets. >>      I plot with the function Edit: illustrating additional options but I didn't want to include the whole code here so the upper one is snipped. The post is already long enough but if you want I could add it. These additional errors appears when plotting with the whole function.               FindDivisions::fdargs: "The arguments in Developer`FindDivisions[{∞,-     ∞,0.5}, 10, 10] are not supported."     ∞::indet: "Indeterminate expression 0\ (-∞) encountered."     ∞::indet: "Indeterminate expression -∞+∞ encountered."       I don't understand where I get ∞. I put the complex element to 0. If you check the output there is no ∞ value. That could happen because of the error "is not a valid vector field dataset or a valid list of datasets." When I compare data5 and data4 I see no differences in format output. It works with data5 and not with data4. The code between a) was done that way so I could plot {{By,Bz}, Norm[By,Bz]}. I couldn't find a better way. Thanks in advance.


title: region plot in a 2-simplex

text: I want to plot a 2-dimensional region with constraint $x+y\le N$, i.e., I want to plot a sub-region inside a 2-simplex. As an example:               Module[{n = 300, p = 0.5},     RegionPlot[{y > (1/2)*(n - x) && y + x <= n && y > p/(1 - p)*x},      {x, 0, n}, {y, 0, n}, FrameLabel -> {"x", "y"},      PlotStyle -> {Yellow, Opacity[0.5]}]]      What should I do to transform the region to a 2-simplex? **Edit 1 & 2 & 3** The command above will give you the following plot: ![enter image description here](http://i.stack.imgur.com/LhfN1.png) which clearly satisfies the $x+y\le N$ constraint. So I want a coordinate transform that changes the shape of the yellow area into the shape of the red area in the plot below (it is from Matlab): ![enter image description here](http://i.stack.imgur.com/pMGxD.png)


title: Discrete 3D plots of median ratios of two 2D matrices of lists of values

text: Lets say I have 2 2D arrays where each cell contains a list of values: Example:               data_1[[1]][[1]] = {1,2,3}      data_1[[1]][[2]] = {1,2,3}      data_1[[2]][[1]] = {1,2,3}      data_1[[1]][[2]] = {1,2,3}           data_2[[1]][[1]] = {2,4,6}      data_2[[1]][[2]] = {3,6,9}      data_2[[2]][[1]] = {4,8,12}      data_2[[2]][[2]] = {5,10,15}       What's a neat way to make a discrete 3D plot of the ratio between medians of these data sets (assuming that the indices always mach, but can represent any value, not only consecutive natural numbers).For the following data I would expect a plot of:               x,y,z     1,1,2     1,2,3     2,1,4     2,2,5


title: Filling Fill incomplete in ListLinePlot

text: data = {{0., 0., 0}, {0.12, 0.04, 2}, {0.24, 0.08, 4}, {0.36, 0.11,          6}, {0.47, 0.15, 8}, {0.59, 0.19, 10}, {0.71, 0.23, 12}, {0.83,          0.26, 14}, {0.95, 0.3, 16}, {1.07, 0.34, 18}, {1.21, 0.38,          20}, {1.38, 0.41, 22}, {1.78, 0.45, 24}, {2.84, 0.49, 26}, {3.45,          0.52, 28}, {3.88, 0.56, 30}, {4.33, 0.6, 32}, {4.79, 0.64,          34}, {5.25, 0.64, 36}, {5.89, 0.3, 38}, {6.16, 0.68, 40}, {6.51,          0.84, 42}, {6.89, 0.98, 44}, {7.27, 1.14, 46}, {7.67, 1.39,          48}, {8.07, 1.95, 50}, {8.47, 5.3, 52}, {8.89, 5.82, 54}, {9.3,          6.14, 56}, {9.71, 6.48, 58}, {10.11, 6.9, 60}, {10.52, 7.56,          62}, {10.92, 8.18, 64}, {11.32, 8.55, 66}, {11.72, 8.86,          68}, {12.13, 9.16, 70}, {12.53, 9.46, 72}, {12.93, 9.77,          74}, {13.33, 10.07, 76}, {13.73, 10.38, 78}};          ListLinePlot[data[[;; , {#, 3}]] & /@ {1, 2}, Filling -> {1 -> {2}}, Frame -> 1]      My code gives this ![enter image description here](http://i.stack.imgur.com/K9cr7.png) but I want it look like this ![enter image description here](http://i.stack.imgur.com/sFHq3.png)