title: Generating a polynomial that's accurate to within an error of no more than 1/10^5

text: I'm currently stuck on a question for class that asks... "Find a polynomial `p[x]` that you can use to calculate `6 ArcTan[x]` to within an error of no more than `10^(-5)` for all the x's with `-(1/Sqrt[3]) <= x <= 1/Sqrt[3]`." I used a series expansion below.               Clear[x];        approx6arctan[x_] = Normal[Series[6Tan[x], {x, 0, 200}]]      However, this can only generate a function that's accurate only to the fourth decimal, no matter how much I expand the series (200 is already huge). Any hints on how to generate a polynomial that's accurate to the fifth decimal? Thanks in advance.


title: How could I improve this Central Limit Theorem demonstration speed- and content-wise?

text: My purpose is to demonstrate the _Central Limit theorem_ by assuming two custom distributions, taking some random samples, calculating their means and ploting the results. Ideally, the histograms should tend to a normal distribution. The code I am using is the following:               \[ScriptCapitalD]1 = ProbabilityDistribution[        1/5 Exp[-(1/5) Abs[2 x - 3]],        {x, -∞, +∞}];          \[ScriptCapitalD]2 = ProbabilityDistribution[         If[x >= -1/2 && x <= +1/2, 1, 0],         {x, -∞, +∞}];          f[n_] := ParallelTable[         Histogram[            Mean /@ Table[RandomVariate[n, 10], {k}], PlotLabel -> "n=" <> ToString@k],         {k, 10, 170, 40}]          cltHistPlots = GraphicsGrid[         {f[\[ScriptCapitalD]1], f[\[ScriptCapitalD]2]},         Spacings -> 0]      And the graph that is generated is this: ![enter image description here](http://i.stack.imgur.com/nZPL9.png) My questions are:   1. How could I speed the process up ? The code is very slow! I think the bottleneck is in the part where `RandomVariate[]` calculates the samples.   2. A bit offtopic, but, could you think of any other addition I could make so that the audience would better understand the theorem ?


title: Importing numerical data from RTF file

text: This might be a very simple question but I have been struggling with it for a couple of hours, so thought maybe someone here can show me a quick way of solving it. I have a file in rtf format (Triangles.rtf) https://drive.google.com/file/d/0B_DoKsn6afPMRTNHUW93NEEwc1U/edit?usp=sharing Now I am trying to load the file by typing `a = Import["PATH_TO_FILE/Triangles.rtf","Table"]` which seems to return a list of lists. So far it seems fine, for example `a[[1]]` returns {3 0 2 1}. `Head[a[[1]]]` returns list and `Head[a[[1,1]]]` returns String. Then I try to convert string into number by `ToExpression[a]` but here we get a list of Null! can anyone please tell me how to convert my imported data into a 2d array (list of list that is) so that I can use the numerics?


title: Implementation of Incomplete Fermi-Dirac Integral in Mathematica

text: I'm working on a special algorithm to implement a more accurate effective mass calculation for hole carriers in silicon in _Mathematica_. This rather involved algorithm uses incomplete Fermi-Dirac Integrals of the form: $$\mathscr F_j(x,b)=\frac1{\Gamma(j+1)}\int_b^\infty \frac{t^j}{e^{t-x}+1}\mathrm dt$$               Fincomplete[j_, x_, b_] :=1/Gamma[j + 1] Integrate[t^j/(E^(t - x) + 1), {t, b, ∞},                                                        Assumptions -> j > 0]      A call to this function with $b=0$ yields the complete Fermi-Dirac integral representation by the nicely implemented `PolyLog` function within _Mathematica_ :               In[1]:=  Fincomplete[j, x, 0]     Out[1]:= -PolyLog[1 + j, -E^x]      However, if one wants to evaluate the incomplete Fermi-Dirac integral, the expression stays unevaluated, indicating that there is no straightforward solution available.               In[2]:=  Fincomplete[j,x,b]     Out[2]:= Integrate[t^j/(1 + E^(t - x)), {t, b, ∞}, Assumptions -> j > 0]/Gamma[1 + j]      Now, my question(s):   1. Any idea which of the multitude of mathematical functions within _Mathematica_ could be leveraged to implement the incomplete Fermi-Dirac integral? Could the Nielsen generalized polylogarithm function mentioned within the _Mathematica_ help system be of any service?   2. Does anybody have this integral already implemented? There are some series expansions quoted on the web, e.g. Computation of the complete and incomplete Fermi-Dirac integral. However, the reference quotes that the series expansions converge rather slowly, and I would like to leave the implementation of the reference above as last resort, since this would take some time and maybe there is an easier way in _Mathematica_? Thanks in advance for all of your help!


title: Doing computations in a modulo ring

text: I need to perform some computations in a modulo ring, like               Mod[Subfactorial[n], m]     Mod[Binomial[n, k], m]      However, this is obviously much too slow for large `n` and `k`. Does Mathematica offer a possibility to perform those computations faster by using more efficient algorithms to compute the modulo? For example, there's Andrew Granville's generalization of Lucas' theorem, which would compute the binomial coefficient much faster. I don't like to implement these by myself, because I want to use Mathematica to cross-check the results of another program of mine.


title: How to refuse close de Dialog when press Enter Key

text: As you can see in the documentation of `CreateDialog` > In dialogs created with CreateDialog, pressing Return is effectively > equivalent to clicking the DefaultButton, and Esc to clicking the > CancelButton. > > If the dialog contains no DefaultButton or CancelButton, pressing Return or > Esc will close the dialog without taking any other action. I have a input field, for example, and I often press Enter key after I wrote my inputs. That what happened is that my window close immediately after that. How can change this behavior in Dialog?


title: Converting expressions to InputForm strings without spaces after commas

text: One of the little utility packages I use needs to convert Mathematica expressions to `InputForm` text that is interpolated into a custom file format which is then parsed by another tool. That other tool, for various reasons, has to actually parse the `InputForm` expressions, but uses its own parser to do so, and that parser doesn't deal very will with commas in _Mathematica_ expressions. It will choke on something like this:               {{1, 2, 3}, {4, 5, 6}}      but works fine with this:               {{1,2,3},{4,5,6}}      By default, `ToString`, with the `InputForm` format, will stick spaces in after the commas. Currently, I use `StringReplace` to work around the problem:               stringifyForExport[form_] :=          StringReplace[             ToString[form, InputString, PageWidth -> Infinity,                  CharacterEncoding -> "ASCII"],             " " -> ""];      I'm not very satisfied with this solution because it won't work if we have any strings in `form` that contain spaces. So far this hasn't caused serious problems, but I know it's just a matter of time. Is there a better way to get rid of those spaces?


title: How to use a self-defined function in the Manipulate function

text: This is what I want               Manipulate[ Plot[ Which[h < a, 1 - 1.5 h/a + 0.5 (h/a)^3, h >= a, 0], {h, 0, 8}],                 {a, 5, 10}]      Is it possible to rewrite it as something like the following?               f[h_] := Which[ h < a, 1 - 1.5 h/a + 0.5 (h/a)^3, h >= a, 0];     Manipulate[ Plot[ f[h], {h, 0, 8}], {a, 5, 10}]      Seems it doesn't work for me. Any suggestion is appreciated.


title: Parallelization of the stochastic Euler scheme

text: I wrote a simulation to approximate the law of a stochastic differential equation via a Monte Carlo method using the stochastic Euler scheme. Then I thought, it would be a good idea to speed up things by means of parallelization, but although I think it is an easy example (and similar problems were discussed here lots of times), none of my attempts was successful. First the code (you can find some explanations below):               (* Parameters of the SDE and radius of the Ball *)     T = 10; sigma = 3.0; z = 1; R = 5*10^6;          (* w denotes the noise and h the step size *)     Euler[x_, w_, h_] := x - x^3*h + sigma*w;          (* Noise is a List of Lists of random numbers *)     MCEuler[h_, StepsMC_, Noise_] := Quiet[Check[       Total[Table[        Fold[ Euler[#1, #2, h] &, z, Noise[[i]]]        , {i, 1, StepsMC}]       ]/StepsMC,     Indeterminate     ]];          MCEulerMT[h_, StepsMC_, Noise_] :=       Total[Table[Catch[Fold[If[Abs[Euler[#1, #2, h]] >= R, Throw[0],          Euler[#1, #2, h]] &, z, Noise[[i]]]], {i, 1, StepsMC}]]/StepsMC;          Comparison[h_, StepsMC_] := Module[{Noise},       Noise = Table[RandomReal[NormalDistribution[0, Sqrt[h]], T/h], {StepsMC}];       Return[{StepsMC, h, MCEuler[h, StepsMC, Noise], MCEulerMT[h, StepsMC, Noise]}];     ];          Result =       Table[Table[Comparison[h, StepsMC], {h, {2^0, 2^-2, 2^-4, 2^-6}}], {StepsMC, {10^3}}]      MCEuler implements the Monte Carlo Simulation using the standard stochastic Euler scheme. Since the coefficients of the stochastic differential equations doesn't fulfill standard assumptions like Lipschitz-continuity, it is possible, that some "discrete trajectories" explode. Therefore, I added the `Quiet` and `Check` commands. MCEulerMT uses again the Euler scheme, but if some "discrete trajectory" leaves a ball of radius R, we set the value to zero. The Comparison-method should test both procedures on the same noise. Then I replaced the Table-Commands in MCEuler, MCEulerMT and the last line of the code (I didn't use it creating the noise, but I think there are no side- effects!?) by "ParallelTable" and the runtime was awful. It was much slower than the code above, and I tried other implementations and commands (e.g. Parallelize) but I didn't make any progress. Perhaps here are some guys, who could explain me, what's wrong about my idea, and how I could fix it.


title: Limit not evaluating

text: Why is the input `Limit[IntegerPart[Sin[x]/x], x -> 0]` not being evaluated? ![Mathematica session](http://i.stack.imgur.com/H9dz6.png)


title: How to Solve this ODE with Mixed Boundary condition

text: I have an ODE equation which is sort of               y''[x] + 2 y'[x]/x + .0001 (y[x])^3 ==0       subject to the boundary conditions               y'[0]==0  and y[Infinity]==0      Can anyone please suggest what would be a reliable process for solving this numerically in Mathematica? `y[Infinity]` can obviously be truncated down to , say, `y[20]`.


title: Normalize equation in NDSolve?

text: I have numerically solved and plotted the solution to the Mathieu equation using NDSolve successfully, as below:               ClearAll["Global`*"]     a = 0.5;     b = 0.1;     w0 = 2.0;     T = 2 Pi/w0;          f[t_] := f[t] = y''[t] + (a + b  Cos[t]) y[t] == 0          s = NDSolve[{f[t], y[0] == 1, y'[0] == 0}, y, {t, 0, 1}]          Plot[Evaluate[y[t] /. s], {t, 0, 1}, PlotRange -> All]      But now I wish the normalize the period so I can plot from `t=0 -> t=1` and get 1 full period. I can do this by hand, but how do I do this inside of the `NDSolve` function?


title: Shortcut to insert plaintext?

text: Oftentimes I would find it useful to insert plaintext, to not be evaluated as input, right next to my input code. Is there a shortcut key to insert such a plaintext input box? I have relied on comments (shortcut key `Alt`+`/`), but as I use a touchscreen display and a small Bluetooth keyboard, it is a real hassle to select a line of text and hit `Alt`+`/`. So I was looking for something easier.


title: Problem with ParametricPlot

text: I'm ploting gear curves (http://mathworld.wolfram.com/GearCurve.html), and I observe that for some parameter values `ParametricPlot[]` does not plot all the teeth:               gearCurve[a_, b_, n_] := ParametricPlot[       {         (a + 1/b Tanh[b Sin[n t]]) Cos[t],          (a + 1/b Tanh[b Sin[n t]]) Sin[t]       },        {t, 0, 2 Pi},        Axes -> False];       gearCurve[10, 5, 38]      produces the following image: ![problematic gear](http://i.stack.imgur.com/bB595.gif) What is going on?


title: How do I place a texture on an irregular 3D model?

text: I'm trying to reproduce a textured head in Mathematica, and I'm using a kind of 'net' of a head which contains all the features on the face. The texture looks like this: ![enter image description here](http://i.stack.imgur.com/LmTQl.jpg) which is supposed to look something like this:![enter image description here](http://i.stack.imgur.com/8RuWq.png) Here's the code I'm using.               ListSurfacePlot3D[Import["inputImage.obj", "VertexData"],      PlotStyle -> Texture[texture], Mesh -> None, MaxPlotPoints -> 80,      TextureCoordinateFunction -> ({#1, -#2, #3} &)]      which gives me![enter image description here](http://i.stack.imgur.com/PCxHA.jpg) Another problem is that the texture is reflected about the origin (ie the face is plastered on the back of the head as well). It should instead be black on the back of the head mesh. I suppose this is suppose to do with the head being centered at the origin. I also need to have the texture to 'follow' the head when I change the coordinates of the mesh later on. I have attempted using               Graphics3D[      {EdgeForm[],       Texture[texture],       GraphicsComplex[mesh,        Polygon[polygon, VertexTextureCoordinates -> mesh]]}]      but it gives me this instead ![enter image description here](http://i.stack.imgur.com/lpK2R.jpg) I need to be able to reproduce this in Mathematica as I have some coordinate transformations which I need to apply, and thereafter, 'wrap' the mesh with the texture. Are these possible? EDIT: The link to the model is located https://www.dropbox.com/s/3elv96e8mfodzou/fit_9D0F8093-5566-4EE4-88A7-00070C1D6305.zip EDIT 2: I've tried converting the OBJ to PLY and I did this               Import["inputImage.ply", "UserExtensions"][[2]]     Import["inputImage.ply", "UserExtensions"][[3]]      which gave an output of               "texture_u" -> {..}     "texture_v" -> {..}      where .. was a bunch of numbers which had a `Length` of 3066 for both. My guess was that these are texture coordinates (where u is horizontal and v is vertical) as per the links provided by Rahul Narain. I attempted to create a list of coordinates from these two list in the following manner               texturecoord = {Import["inputImage.ply", "UserExtensions"][[2]][[2]],         Import["inputImage.ply", "UserExtensions"][[3]][[2]]} // Transpose      Then, I tried doing               Graphics3D[      {EdgeForm[],       Texture[texture],       GraphicsComplex[mesh,        Polygon[polygon, VertexTextureCoordinates -> mesh]]}]      But that gives me this ![enter image description here](http://i.stack.imgur.com/D20xM.jpg)


title: Parallelizing an associative binary operation

text: I have an associative binary operation '`.`', which I often use in this sort of way:               result = expr1 . expr2 . expr3 . expr4      The '`.`' operation is very fast, but the individual subexpressions are often _hard_ to compute. So I would like my '`.`' operation to automatically parallelize itself, evaluating each of the separate subexpressions in separate kernels before finally taking the results and actually performing the operation. How can I achieve this in Mathematica? It seems there are several challenges. One is to prevent the subexpressions evaluating before the '`.`' operation is evaluated.


title: Finding maximal sublist of linearly independent vectors

text: Given a list of vectors `v = {v1, ..., vn}`, which is the fastest way to find a maximal sublist of linearly independent vectors? I could add the vectors one by one to a list and check for the rank of the resulting matrix, but I would like to know if there's a better solution. Thanks in advance.


title: 10bits per rgb / 1024 shades of gray?

text: Can we display 10 bits per rgb in Mathematica? I'm using a quadro card and 30 bit monitor and can get a smooth gradient using Psychtoolbox in matlab. The following Mathematica should produce a bar with 8 shades of gray with 10 bits per color but I only see two, implying 8bits per color. (Stretch the bar across the full width of the screen and you'll see 8 steps if it is using 10 bits per color and 2 steps if it is only using 8).               n = 1024;     start = 512;     end = 519;     Graphics[Table[{GrayLevel[g], Rectangle[{g, 0}, {g + 1/n, .001}]}, {g,         start 1/1024, end 1/1024, 1/n}]]      I'm interested as I have 16 bit greyscale image data and the staircase effect at low bit depth reduces the ability to interpret the images efficiently without adjusting the window of 256 greys over which the 65535 greys present can be viewed. 1024 greys would be a useful improvement. This has been possible in medical imaging for several years but very expensive (tens of thousands of dollars, i.e. Dome 10MP). Now relatively "cheap" setups (like a \$1k quadro card and \$1k dell u3011 display) are able to do similar so it would be great to be able to achieve the same in Mathematica. I think it is to do with enabling opengl but thats as far as I've got.


title: Constraint minimization with NMinimize

text: I am using the following code in order to minimize the function `chi`               R = {5.68, 6.81, 7.95, 9.08, 10.22, 11.35, 12.49, 13.62, 14.76, 15.89,         17.03, 18.16, 19.30, 20.43, 21.45, 22.47, 23.50, 24.52, 25.54,         26.56, 27.58, 28.6, 29.62, 30.65, 31.67, 32.69, 33.71, 34.73};     V = {235.5, 242.9, 251.1, 262, 258.9, 255.1, 251.8, 252.1, 251, 245.5,         232.8, 232, 235.7, 229.3, 227.6, 226, 225.7, 227.5, 227.4, 225.6,         224.4, 222.3, 222.1, 224.9, 228.1, 231.1, 230.4, 226.8};     dV = {17.8, 0.8, 0.7, 2.1, 6.9, 5.7, 17.1, 7.4, 18.6, 28.8, 1, 14.2,         4.6, 13.8, 28.8, 28.8, 28.8, 28.8, 28.8, 28.8, 28.8, 28.8, 28.8,         28.8, 28.8, 28.8, 28.8, 28.8};     ICov = Inverse[DiagonalMatrix[dV]*DiagonalMatrix[dV]];     G = 6.67*10^(-20);     Msol = 2*10^30;     kk = 3*10^16;     sl = 299792;     incl = 90*Pi/180;               Vth[a_, b_, c_, d_] =        Sqrt[(G*a*Msol)/(R*kk)*(1 - Exp[-(R/d)]*(1 + R/d))]*(1 -           b*Exp[-R/c]/R);               chi = (Vth[M, \[Delta], L, Ld] - V).ICov.(Vth[M, \[Delta], L, Ld] -           V);     NMinimize[{chi, M > 0 && L > 0 && Ld > 0}, {M, \[Delta], L, Ld}]      Since `M` is a mass, and both `L` and `Ld` are lengths, and I know nothing about `[\Delta]`, the constraint should be: `M>0 && L>0 && Ld>0`: When I use it, I find:               {5848.86, {M -> 1.58505*10^6, \[Delta] -> -1.18329*10^6,        L -> 1.15986*10^6, Ld -> 3118.75}}      Since I know that the mass should be `M>2*10^11`, I tried to use this a constraint, and I find:               {40.8086, {M -> 2.41901*10^11, \[Delta] -> 8.90217, L -> 2.12644,        Ld -> 4.78551}}      Much better! Why doesn't Mathematica find it by itself? How can I improve my constraints?


title: Problem with Eventlocator Method for NDSolve

text: I want to solve the ode and plot the solution `v[x]` for different values of parameter `a` where `x=2000` (for just any fixed position x or event at x). By looking at examples of `EventLocator` available online i tried to write the code as:               data = Table[Reap[         soln =           NDSolve[{I D[v[x], x] == (0.4 + a)*v[x], v[0] == 1}, {v[x]}, {x, 0, 2000},           Method -> {"EventLocator",              "Event"          -> Abs[v[x]]^2,              "EventCondition" -> x == 1000,             "EventAction"    :> Sow[{a, Evaluate[Abs[v[x]]]^2 /. soln}]}]][[2, 1]],       {a, -1, 0, 0.3}]      But it does not give data file i wanted to grab as`{a,[Abs[v[x]]^2}`. instead it shows: > Part::partw: Part 1 of {} does not exist. >>   >  Part::partw: Part 1 of {} does not exist. >>   >  Part::partw: Part 1 of {} does not exist. >>   >  General::stop: Further output of Part::partw will be suppressed during this > calculation. >> > > {{{{v[x]->InterpolatingFunction[{{0.,2000.}},<>][x]}},{}}[[2,1]],   >  {{{v[x]->InterpolatingFunction[{{0.,2000.}},<>][x]}},{}}[[2,1]],   >  {{{v[x]->InterpolatingFunction[{{0.,2000.}},<>][x]}},{}}[[2,1]],   >  {{{v[x]->InterpolatingFunction[{{0.,2000.}},<>][x]}},{}}[[2,1]]} Any kind of help or suggestion will great .Even if you can help using other method like using for loop and logical condition that will be great too.


title: How to type binomial coefficient $\binom{n}{k}$

text: I know how to type a fraction as you would write a fraction in Mathematica (9). How do you type `Binomial[n,k]` as $\binom{n}{k}$ in Mathematica? Is there a single reference page that contains all the Mathematica operations like this, that you can type in math notation?


title: MapThread Alternatives

text: I want to add two matrices, the first one containing a 2D vector at each position the other one a list of 2D vectors. The 2D vector from the first matrix should be added to each of the 2D vectors at the same position in the other matrix. The way I know of is using MapThread, but is there a faster way? So basically I have two matrices defined like this:               MA = Table[RandomReal[], {i, 10}, {j, 10}, {k, 2}];     MB = Table[RandomReal[], {i, 10}, {j, 10}, {k, 3}, {l, 2}];      The output of `MA+MB` should be `Mout[[i,j]] = {MA[[i,j]]+MB[[i,j,1]],MA[[i,j]]+MB[[i,j,1]],MA[[i,j]]+MB[[i,j,1]]}` for each pair of indices `i,j`. The one method I am using right now is a combination of `MapThread` and `Map`:               Mout = MapThread[Function[{x,y},x+#&/@y],{MA,MB},2]      This works but is rather slow. Is there a faster and maybe more elegant way to do this?