How to apply compiled function on list

Compile function output error: How to apply compiled function on list?                   mkCompileCode[vars_, code_, idx_] :=          With[{fVars = Flatten[vars]},          Compile[{{in, _Real, idx}}, Block[fVars, fVars = Flatten[in];         code], RuntimeAttributes -> Listable]]              vars = {x, y, z};         df = Function[{x, y, z}, Sqrt[x^2 + y^2 + z^2] - 1];      Compiling the above function                   cdfs = mkCompileCode[vars, df, 1]      Compiled function does nt work on following list:                   p = {{-1.`, -1.`, -1.`}, {-1.`, -1.`, -0.75`}, {-1.`, -1.`, -0.5`},               {-1.`, -1.`, -0.25`}};              cdfs[p]      out:                  During evaluation of In[236]:= CompiledFunction::cfse: Compiled expression                  Function[{x,y,z},Sqrt[x^2+y^2+z^2]-1] should be a machine-size real number. >>            {Function[{x, y, z}, Sqrt[x^2 + y^2 + z^2] - 1],        Function[{x, y, z}, Sqrt[x^2 + y^2 + z^2] - 1],        Function[{x, y, z}, Sqrt[x^2 + y^2 + z^2] - 1],        Function[{x, y, z}, Sqrt[x^2 + y^2 + z^2] - 1]}      What's missing?


Parsing output from FindHamiltonianCycle to recover an ordered list of vertex positions for a discovered path

After applying `FindHamiltonianCycle` to a graph, one generates output that looks like the following:               {{1<->2,2<->3,3<->4,4<->5,5<->6,6<->7,7<->8,8<->9,9<->10,10<->11,11<->12,12<->13,13<->14,14<->15,15<->16,16<->17,17<->18,18<->19,19<->20,20<->21,21<->22,<<3670>>,77<->75,75<->73,73<->71,71<->69,69<->67,67<->65,65<->63,63<->61,61<->59,59<->57,57<->55,55<->53,53<->51,51<->49,49<->47,47<->45,45<->43,43<->41,41<->39,39<->36,36<->1}}      I've replaced `\[UndirectedEdge]` with "<->" here to deal with formatting. How can I quickly return an ordered list of vertices in the path, and an ordered list of their (previously specified) coordinates?


What domain does Resolve assume by default?

Consider the statement: $\forall x\left(x<7\Rightarrow \exists a\exists b\exists c(a^2+b^2+c^2=x)\right)$ This is true provided the universe of discourse is $\mathbb{N}$ Now I use `Resolve` as follows to assess the validity of this statement:               Resolve[ForAll[x, Implies[x < 7, Exists[{a, b, c}, a^2 + b^2 + c^2 == x]]]]      and _Mathematica_ returns `True`. Why? If I did not specify $\mathbb{N}$ as the domain how does _Mathematica_ justify returning `True`? Is there a way to specify $\mathbb{N}$ as the domain?


Reverse-order Negative BarSpacing

Suppose I have some data for a bar chart:               testdata = Map[{1, #} &, RandomReal[{-0.5, 4}, {3, 2}], {2}]     (* {{{1, 3.30023}, {1, 3.814}}, {{1, -0.353959}, {1, -0.364447}}, {{1,           1.82514}, {1, 2.56824}}} *)          RectangleChart[testdata, BarOrigin -> Left, Frame -> True,        ChartStyle -> {Red, Blue}, BarSpacing -> {-0.2, 0.6}]      ![enter image description here](http://i.stack.imgur.com/05mW9.png) But what I really want is for the shorter, red bars to overlap _on top_ of the blue bars, not underneath.               RectangleChart[Reverse /@ testdata, BarOrigin -> Left, Frame -> True,        ChartStyle -> {Blue, Red}, BarSpacing -> {-0.2, 0.6}]      ![enter image description here](http://i.stack.imgur.com/jRbXf.png) That works, but the red bars only overlap if they are _above_ the blue bars. If I had set `BarOrigin->Bottom`, the red bars would then be on the right.               RectangleChart[Reverse /@ testdata, Frame -> True,        ChartStyle -> {Blue, Red}, BarSpacing -> {-0.2, 0.6}]      ![enter image description here](http://i.stack.imgur.com/yMs9p.png) Conceptually this is because later data prints after earlier data, so groups of bars on the right or at the top are "later" and print on top of the "earlier" bars on the left or below. This makes sense to me, but not to the person I am drawing the graph for. Is there any way to reverse the bar ordering such that the bars at the bottom of the group overlap on top of the upper bars when one has negative `BarSpacing`?


What is the Missing code in this Wolfram Blog article?

Here's a very cool Wolfram Blog Article with incomplete code, that can apply the Droste Effect to an image is various interesting ways. Copying this code, in the journal doesn't provide a working solution. What's missing here to get this code to work?               InitializeSources[source_, p1_, p2_] :=       Quiet[Block[{imgbytes = Import[source, "Byte"],     sourcebytestream},     If[imgbytes === $Failed, $Failed,       sourcebytestream = FromCharacterCode[imgbytes];       LaunchKernels[];       DistributeDefinitions[OriginalValueFns,        DrostifyRegion, ReplicateRegion, TransformCoordinates,        CropData];       ParallelEvaluate[$ImageInterpolationFn =          OriginalValueFns[CropData[           Reverse@Developer`ToPackedArray[             N[ImportString[#, {"JPG", "Data"}]]], p1, p2]/255.];] &[     sourcebytestream]]]     ]          OriginalValueFns[data_] :=      ($AspectRatio = 1/Apply[Divide, Most[Dimensions[data]]];       Apply[Function, {{x, y},          If[Abs[x] > 1 || Abs[y] > $AspectRatio, {1., 1., 1.}, #] &[          Table[ListInterpolation[             data[[All, All, channel]], {{-1, 1}, $AspectRatio {-1, 1}},         InterpolationOrder -> 1][x, y], {channel, 1, 3}]      ]}]);          DrostifyRegion[start_, end_, res_, opts : OptionsPattern[]] :=           Image[Table[      Apply[$ImageInterpolationFn,          TransformCoordinates[{x, y}, opts]], {x, end,          start, -2/(res - 1)}, {y, -$AspectRatio/$AspectRatio, 2/res}]     ];          DrosteImage[resolution_, opts : OptionsPattern[]] :=     ImageAssemble[     ParallelTable[      {DrostifyRegion[-1 + 2 (slice - 1)/#, -1. + 2 slice/#,        resolution, opts]},      {slice, #, 1, -1}]] &[Max[Length[Kernels[]], 1]     ];          (*Find the center of the selected rectangle*)     $DrosteScale = Max[Flatten[{Abs[r2 - center]/(center - {1, 1}), Abs[r1 - center]/      Abs[Reverse@Take[Dimensions[data], 2] - center]}]];     CropData[data_, r1_, r2_] := Block[{center, xlo, xhi, ylo, yhi, innerdims},     center = Mean[{r1, r2}];          (*Find the scaling of the cropped image to the rectangle*)          innerdims = Abs[r1 - r2]/$DrosteScale;     {{ylo, xlo}, {yhi, xhi}} = Round[{center - innerdims/2, center + innerdims/2}];     Return[data[[xlo ;; xhi, ylo ;; yhi, All]]]];          TransformCoordinates[{x_, y_}, opts : OptionsPattern[]] := FixedPoint[     ReplicateRegion, {Re[#],        Im[#]} &@((OptionValue[          Zoom] E^(I OptionValue[Rotation])) (OptionValue[XShift] +           I OptionValue[YShift] + x +           I y)^(OptionValue[CopiesPerRotation] +           OptionValue[Spirals] I  Log[$DrosteScale]/(2 \[DoubledPi]))),     OptionValue[MaxRecursion]];     Options[TransformCoordinates] =     {Zoom -> 1, XShift -> 0, YShift -> 0, Rotation -> 0,     CopiesPerRotation -> 1, MaxRecursion -> 10, Spirals -> 1};          ReplicateRegion[{x_, y_}] := Which[     (*If outside the image area, move closer*)          Abs[x] > 1 || Abs[y] > $AspectRatio,         {x, y} $DrosteScale,     (*If inside the frame move out to the main image*)          Abs[x] < $DrosteScale &&         Abs[y] < $DrosteScale $AspectRatio,         {x, y}/$DrosteScale,     (*otherwise use the calculated coordinates*)     True, {x, y}     ];


How to transform this matrix & swap its columns in a simple way?

I would like to transform matrix $\mathbf A = \begin{pmatrix} a&b&i&j\\\ c&d&k&l \\\ e&f&m&n \\\ g&h&o&p \end{pmatrix}$ into matrix $\mathbf B = \begin{pmatrix} -p&o&-h&g\\\ -n&m&-f&e \\\ -l&k&-d&c \\\ -j&i&-b&a \end{pmatrix}$. If possible I would like to generalize this to $\\{n\times n,\ n>4\\}$ size matrices. Is there a simple way to do this in Mathematica? Thanks in advance.


Is there a faster way to Map an Association?

Consider mapping an existing `Association` in a manner such as this:               asc = AssociationThread[Range @ 26, CharacterRange["a", "z"]];          Map[asc, {{11, 13, 2}, {19, 23, 16}}, {2}]      > >     {{"k", "m", "b"}, {"s", "w", "p"}} >   Is there a more efficient way perform this generic operation?


Duplicated output from chemical curated data

I just discovered something rather odd while using chemical curated data in _Mathematica_. I tried to extract `EdgeRules` for some molecules and some molecules gave me several copies of said `EdgeRules` as a list. Is this a bug? Have any of you found similar things happening with other curated data? Example:               ChemicalData[#, "EdgeRules"] & /@ {"Glutamine", "Alanine", "Serine"}      This input gives me 1, 3 and 2 copies of the `EdgeRules` of the given molecules.


Map 2 list to a function

Im playing around with `CountryData` and I want to pass it 2 lists as argument, `listCountries = {...}` and `data = {"GDP","ExternalDebt"}` If I do `CountryData[#, "GDP"]& /@ listCountries` it works well, but I want something like               CountryData[#1, #2]& /@ {listCountries,data}      I read something about `MapThread` but can make it.


Memory management and speed for Fast GCD

Let's say that we have some $300\,\text{K}$ digits (arbitrary function) and want to trial factor with $100{,}000{,}000$ first prime numbers.               PRP = {};           Func[Q_] := 77^Q + 2;          Do[If[TimeConstrained[PrimeQ[Func[i]], 1, True], AppendTo[PRP, i]], {i, 160000, 161000}]      PRP: ($64$ numbers out of $1000$ test samples)               {160001,160025,160037,160041,160045,160053,160065,160097,160101,160133,160137,160141,160161,160177,160181,160201,160241,160253,160257,160261,160285,160297,160305,160317,160321,160361,160393,160397,160405,160413,160421,160425,160441,160485,160541,160557,160577,160581,160601,160621,160633,160637,160645,160657,160685,160693,160713,160721,160725,160753,160761,160801,160821,160833,160845,160853,160857,160861,160881,160897,160921,160933,160945,160965}      Then I use the following to compute product of primes in $5$ part ($20{,}000{,}000$ range)               Pro = Product[i, {i, Prime[Range[1, 20000000]]}]; // about 170 million digits      And for each product I run:               Output ={};          Do[If[GCD[Func[i], Pr] == 1, AppendTo[Output, i]], {i, PRP}]      Currently each product (of $20{,}000{,}000$ primes) take $1\,\text{GB}$ of RAM and nearly $30$ seconds for each GCD               In[86]:= Timing[GCD[Func[160001], Pr]]          Out[86]= {28.562500, 117414067}      Is my configuration and setup the best possible one in memory management and speed? **Update** I modified the @tchronis answer a little to remove composite as early as possible. Not the best code (can be much better using `Reap` and `Sow`), but it works:               ClearAll[gcd2];     gcd2[list_, noprimes_: 20000000, noclusters_: 1] :=       Module[{clusters, n, pro},        clusters =         Table[{(i - 1)*noprimes/noclusters + 1, i*noprimes/noclusters}, {i,           noclusters}];       innerList = list;       Do[        pro = Product[i, {i, Prime[Range @@ clusters[[j]]]}];        newList = {};        Do[         If[GCD[func[m], pro] == 1, AppendTo[newList, m]],         {m, innerList}         ]; innerList = newList,        {j, 1, noclusters}        ]; newList       ]      **Result**               Timing[gcd[list, 5000000, 4]]          {327.9706, { .... 54 out of 64 ... } }          Timing[gcd2[list, 5000000, 4]]          {290.328125, { .... 54 out of 64 ... } }      The higher the number of primes and the larger the list, the speedup by stopping computation upon first non-one GCD gains more.


Why does Mathematica return a Fourier transform for a function for which it is not defined?

The following function $$g(x) = (1 + x^{1/a} )^a $$ should NOT have a Fourier transform, as far as I am aware, for any real values of $a$ since $g(x)$ is not nice in the sense of decays quickly enough to $0$ at infinity. However, doing:               g[x_, a_] := (1 + x^(1/a))^(a);     Plot[g[x, 2], {x, 0, 1000}]     FourierTransform[g[x, 2], x, ω]       _Mathematica_ somehow comes up with the result: $$\frac{\left(\frac{1}{2}+\frac{i}{2}\right) (\left| \omega \right| -\omega )}{\omega \left| \omega \right| ^{3/2}}$$ What is going on here?


How to implement nested With as a single construct using functional programming (Fold)?

It is possible to define my own `With` construct where each _local constant_ can depend on the previous defined _local constants_? I wish to replace something like this               With[{m=10},       With[{h=1/m},         Table[{i h}, {i, 0, m}]       ]     ]      with something like this               WithMany[{m=10, h=1/m},         Table[{i h}, {i, 0, m}]     ]      The very basic idea is to use `Fold`:               Attributes[WithMany] := {HoldAll};     WithMany[{vars___}, body_] := Fold[With[{#2}, #1] &, body, {vars}]      but we need to properly evaluate the argumens in a non-standard way, possibly using `Hold` and related constructs. I'm not so fluent with this. An improvement would be to use the minimum number of With constructs depending on the dependencies between variables. Any help will be appreciated. **EDIT** As several people pointed out the original question has already been answered. This solve my immediate needs but I'm still interested to other implementation. @Leonid Shifrin think the referred answer already use the best approach, the simplest, the most elegant, the most efficient and so, but, even if true, I consider an interesting programming exercise to try different approach, like the one in my original question, using functional programming and `Fold` The sketch of a possible implementation is the following:               Attributes[WithMany] := {HoldAll};     WithMany[vars : {__}, body_] :=      Block[{With},       Attributes[With] = {HoldAll};       ReleaseHold@Fold[         With[{#2}, #1] &,         Hold[body],         Reverse@Thread@Hold@vars         ]       ]      I don't understand if there is some limit or issue with this implementation, or if it is fully equivalent to the one in the referred answer and to nested `With` costruct (after adding Syntax coloring and handling `SetDelayed`)? At a first sight I like more my approach (if it works properly of course) and I think is cleaner. It also appears slightly faster, according to some very basic tests. But I recognize that some people might prefer a different approach.


Bug in PositiveDefiniteMatrixQ?

This seems like a bug in `PositiveDefiniteMatrixQ` to me:               m = {      { 2, -1},       {-3,  2}     };          PositiveDefiniteMatrixQ[m]     (* => False *)          PositiveDefiniteMatrixQ @ SparseArray[m]     (* => True *)      This is for version 9 and above; older versions (6-8) don't seem to be affected.


Is it possible to use Compile on a function with optional arguments?

My _Mathematica_ is a little rusty, so apologies in advance. I think my problem is quite simple, but I can't seem to find the answer on my own! Simple example : `j[x_, y_: 1] := x + y` where x and y are integer numbers. How would you go about implementing Compile using this function?


How can I get rid of extra commas in Export/Import?

Consider the following example of trying to export the following table:               Export["test.dat", {{{1, 1}, {2, 2}}, {{3, 3}, {4, 4}}}, "Table"];      Now I import to see what I get:               Import["test.dat", "Table"]     {{{1,,1}, {2,,2}}, {{3,, 3}, {4,,4}}}      which contains extra undesirable commas. I've trying making the data type a "List" but that possessing an issue in which elements are not separated by commas. How can I fix this problem so the the imported table is the same as I exported?


Problems with NIntegrate

I'm having trouble to do the following numerical integrations:               iEAs[Q_?NumericQ, m1_?NumericQ, m2_?NumericQ, mh_?NumericQ, V_?NumericQ, Vc_?NumericQ, A_?NumericQ, Ac_?NumericQ] := m1 Q NIntegrate[ x (A Ac (m2 + m1 (-1 + x)) + V Vc (m1 + m2 -          m1 x))/(8 \[Pi]^2 (-mh^2 (-1 + x) + (m2^2 + m1^2 (-1 + x)) x)), {x, 0, 1}, MaxRecursion -> 100, WorkingPrecision -> 13];          iEAf[Q_?NumericQ, m1_?NumericQ, m2_?NumericQ, mh_?NumericQ, V_?NumericQ, Vc_?NumericQ, A_?NumericQ, Ac_?NumericQ] := m1 Q NIntegrate[-(  (A Ac (12 m2 (1 + x) + m1 (1 - 9 x - 12 x^2)) + V Vc (12 m2 (1 + x) + m1 (-1 + 9 x + 12 x^2))))/(96 \[Pi]^2 (-m2^2 (-1 +x) + (mh^2 + m1^2 (-1 + x)) x)), {x, 0, 1}, MaxRecursion -> 100, WorkingPrecision -> 13];          iVAv[G_?NumericQ, m1_?NumericQ, m2_?NumericQ, M_?NumericQ, V_?NumericQ, Vc_?NumericQ, A_?NumericQ, Ac_?NumericQ] := G m1 NIntegrate[- (A Ac (-3 m2 (1 + x) + m1 (-3 + x + 2 x^2)) +      V Vc (3 m2 (1 + x) + m1 (-3 + x + 2 x^2)))/(8 \[Pi]^2 (M^2 (-1 + x) - (m2^2 + m1^2 (-1 + x)) x)), {x, 0, 1}, MaxRecursion -> 100, WorkingPrecision -> 13];          iVAf[Q_?NumericQ, m1_?NumericQ, m2_?NumericQ, M_?NumericQ, V_?NumericQ, Vc_?NumericQ, A_?NumericQ, Ac_?NumericQ] := m1 Q NIntegrate[ -( (V Vc (m1 - 2 m2 + m1 x) + A Ac (m1 + 2 m2 +      m1 x))/(4 \[Pi]^2 (M^2 + (m1^2 + m2^2) (-1 + x)))), {x, 0, 1}, MaxRecursion -> 100, WorkingPrecision -> 13];      Then when I try to calculate my other function, that is just a sum of several of those integrals taken with diferent arguments, I get the following errror: > During evaluation of In[1]:= NIntegrate::zeroregion: Integration region > {{1.000000000000,0.999999999999999999999999999972752437499605743914855469900697130}} > cannot be further subdivided at the specified working precision. NIntegrate > assumes zero integral there and on any further indivisible regions. >> > > During evaluation of In[1]:= NIntegrate::inumri: The integrand > -((3.94734084367020280294200477311377373096717807463275517933069283*10^-10 > (1.2679004580000000000 (1+x)+0.10565837150000000000 (1-9 x-12 > x^2)))/(-0.0111636914680320122499999999999999999999999999999999999999121163 > (-1+x)+0.011163691468032012250 (-1+x) x)) has evaluated to Overflow, > Indeterminate, or Infinity for all sampling points in the region with > boundaries > {{0.999999999999999999999999999972752437499605743914855469900697130,0.999999999999999999999990130457402984116116415865423076016809530}}. > >> > > > During evaluation of In[1]:= NIntegrate::zeroregion: Integration region > {{1.000000000000,0.999999999999999999999999999972752437499605743914855469900697130}} > cannot be further subdivided at the specified working precision. NIntegrate > assumes zero integral there and on any further indivisible regions. >> > > During evaluation of In[1]:= NIntegrate::inumri: The integrand > -((3.94734084367020280294200477311377373096717807463275517933069283*10^-10 > (1.2679004580000000000 (1+x)+0.10565837150000000000 (1-9 x-12 > x^2)))/(-0.0111636914680320122499999999999999999999999999999999999999121163 > (-1+x)+0.011163691468032012250 (-1+x) x)) has evaluated to Overflow, > Indeterminate, or Infinity for all sampling points in the region with > boundaries > {{0.999999999999999999999999999972752437499605743914855469900697130,0.999999999999999999999990130457402984116116415865423076016809530}}. > >> > > > During evaluation of In[1]:= 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. >> > > During evaluation of In[1]:= NIntegrate::eincr: The global error of the > strategy GlobalAdaptive has increased more than 400 times. The global error > is expected to decrease monotonically after a number of integrand > evaluations. Suspect one of the following: the working precision is > insufficient for the specified precision goal; the integrand is highly > oscillatory or it is not a (piecewise) smooth function; or the true value of > the integral is 0. Increasing the value of the GlobalAdaptive option > MaxErrorIncreases might lead to a convergent numerical integration. > NIntegrate obtained -1.102332818474*10^-28 and 1.773650837526`13.*^-29 for > the integral and error estimates. >> > > During evaluation of In[1]:= 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. >> > > During evaluation of In[1]:= NIntegrate::eincr: The global error of the > strategy GlobalAdaptive has increased more than 400 times. The global error > is expected to decrease monotonically after a number of integrand > evaluations. Suspect one of the following: the working precision is > insufficient for the specified precision goal; the integrand is highly > oscillatory or it is not a (piecewise) smooth function; or the true value of > the integral is 0. Increasing the value of the GlobalAdaptive option > MaxErrorIncreases might lead to a convergent numerical integration. > NIntegrate obtained > 1.68427508260603075850603189688997779553482730498560866417565317`63.*^-25 > and > 6.25652496229563136928773273149849536309587019886986176252873178`63.*^-26 > for the integral and error estimates. >> > > During evaluation of In[1]:= 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. >> > > During evaluation of In[1]:= General::stop: Further output of > NIntegrate::slwcon will be suppressed during this calculation. >> > > During evaluation of In[1]:= NIntegrate::eincr: The global error of the > strategy GlobalAdaptive has increased more than 400 times. The global error > is expected to decrease monotonically after a number of integrand > evaluations. Suspect one of the following: the working precision is > insufficient for the specified precision goal; the integrand is highly > oscillatory or it is not a (piecewise) smooth function; or the true value of > the integral is 0. Increasing the value of the GlobalAdaptive option > MaxErrorIncreases might lead to a convergent numerical integration. > NIntegrate obtained -1.343930509261*10^-26 and 7.504336838898`13.*^-27 for > the integral and error estimates. >> > > During evaluation of In[1]:= General::stop: Further output of > NIntegrate::eincr will be suppressed during this calculation. >> > > During evaluation of In[1]:= NIntegrate::zeroregion: Integration region > {{1.000000000000,0.999999999999999999999999999972752437499605743914855469900697130}} > cannot be further subdivided at the specified working precision. NIntegrate > assumes zero integral there and on any further indivisible regions. >> > > During evaluation of In[1]:= General::stop: Further output of > NIntegrate::zeroregion will be suppressed during this calculation. >> > > During evaluation of In[1]:= NIntegrate::inumri: The integrand > -((3.94734084367020280294200477311377373096717807463275517933069283*10^-10 > (1.2679004580000000000 (1+x)+0.10565837150000000000 (1-9 x-12 > x^2)))/(-0.0111636914680320122499999999999999999999999999999999999999121163 > (-1+x)+0.011163691468032012250 (-1+x) x)) has evaluated to Overflow, > Indeterminate, or Infinity for all sampling points in the region with > boundaries > {{0.999999999999999999999999999972752437499605743914855469900697130,0.999999999999999999999990130457402984116116415865423076016809530}}. > >> > > > During evaluation of In[1]:= General::stop: Further output of > NIntegrate::inumri will be suppressed during this calculation. >> > > Out[56]= -0.1054127670153 - 0.10565837150000000000 > NIntegrate[-(0.0006115582135884999042 \ 0.0006115582135884999042 (12 > 0.10565837150000000000 (1 + x) + 0.10565837150000000000 (1 - 9 x - 12 x^2)) > + 0 0 (12 0.10565837150000000000 (1 + x) + 0.10565837150000000000 (-1 + 9 x > + 12 x^2)))/(96 [Pi]^2 (-0.10565837150000000000^2 (-1 + x) + (0^2 + > 0.10565837150000000000^2 (-1 + x)) x)), {x, 0, 1}, MaxRecursion -> 100, > WorkingPrecision -> 13] I have tried many methods of integration. For most of them I get the kind of error above, for local adaptive methods I don't get any error, but I left Mathematica running for a whole afternoon and it didn't finish the calculation (it just kept running). I need the WorkingPrecision->13 because I'm going to compare this result with the electron anomalous magnetic moment (which has got 12 significant digits for it's experimental value). My final goal is to use thse integrals for several values of it's parameters, and then make RegionPlots comparing my calculations with the experimental value. EDIT: If I get divergences it is fine for me to discard the parameter values (m2, mh and M) where they happen. So, if anyone can find a way to solve my problem, I would be very grateful.


Why don't some functions work in trial versions of Mathematica?

I currently use the trial version before I decide to upgrade. However, a number of expressions don't work, i.e. it results in some errors that I don't know how to interpret. For example, if I use the simple `GeoGraphics[]` expression from the help menu, it results in the error message               General::unavail: ExportString is not available in this version of the Wolfram Language.      This error pops up in multiple contexts (e.g. other Geo-expressions, `CloudDeploy`, etc.) and I have no clue why.


Plot data as TradingChart

Does anyone know how to make a two data plot such that one of the data samples is showed as the volume transactions in `TradingChart` function? Thanks. EDIT: Sorry the english. So, I have two data samples. I want to plot one of them in a ordinary plot using, for example, `ListLinePlot`, but the second data sample to be showed bellow in the same way the volume is ploted in `TradingChart`. ![enter image description here](http://i.stack.imgur.com/qRV9h.gif) EDIT2: In resume I have 2 data samples. I want the first to be ploted in the main graph, and the second bellow. EDIT3:               Data1 = {{0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}, {6, 0}, {7, 1}, {8, 4}, {9, 6}, {10, 4}, {11, 5}, {12, 4}, {13, 6}, {14, 11}, {15, 6}, {16, 9}, {17, 15}, {18, 18}, {19, 24}, {20, 5},{21, 9}, {22, 8}, {23, 15}, {24, 12}, {25, 12}, {26, 8}, {27, 6}, {28, 0}, {29, 0}, {30, 1}, {31, 0}, {32, 0}, {33, 8}, {34, 3}, {35, 6}, {36, 1}, {37, 1}, {38, 1}, {39, 0}, {40, 0},{41, 0}, {42, 0}, {43, 0}, {44, 0}, {45, 0}, {46, 0}, {47, 0}, {48, 0}, {49, 0}, {50, 0}, {51, 0}};               Data2 = {{0, 2.509410662937836}, {1, 2.4808803466341955}, {2, 2.540569347654955}, {3, 2.547132749506656}, {4, 2.5608766053468215}, {5, 2.581673613536808}, {6, 2.604984165739864},{7, 2.6278553420965545}, {8, 2.6503872000749418}, {9, 2.6752177853363124}, {10, 2.7057947186702784}, {11, 2.745031662921106}, {12, 2.7943757324055767}, {13, 2.853013933116065},{14, 2.917745974429515}, {15, 2.983839933241766}, {16, 3.0465660811621076}, {17, 3.102516932682284}, {18, 3.1500203982948363}, {19, 3.188703244889767}, {20, 3.218713885646367},{21, 3.240043336569459}, {22, 3.252119187906068}, {23, 3.2536542495812055}, {24, 3.242674122710854}, {25, 3.2167232385868556}, {26, 3.17342632177792}, {27, 3.1117145450146624},{28, 3.0337272881633637}, {29, 2.9463165559593465}, {30, 2.860119427488097}, {31, 2.7856903736887726}, {32, 2.72960093847454}, {33, 2.693619848357109}, {34, 2.676505085841342},{35, 2.675912875804714}, {36, 2.688928643855797}, {37, 2.711270365853601}, {38, 2.7362623567711375}, {39, 2.7552236175724216}, {40, 2.760135480832154}, {41, 2.7472510017985674},{42, 2.7188819751432343}, {43, 2.6851673012886823}, {44, 2.6583557887909524}, {45, 2.640803683563485}, {46, 2.632087208191991}, {47, 2.6237017095679587}, {48, 2.59890527467275};


Mesh for points in 3D

I've got a set of Eisenstein integers (triangle lattice points in the complex plane), and I've selected them to be above a line, so that they form a triangle: ![eisenstein triangle above line](http://i.stack.imgur.com/wR8il.png) I then took these 2D points and embedded them in 3D space, with the z-axis chosen randomly:               points3d = Map[{#[[1]], #[[2]], RandomReal[]} &, eisensteinIntegers]     Graphics3D[Point /@ points3d, Boxed -> False]      ![3d points](http://i.stack.imgur.com/BOLJi.png) I would like to have those points form a triangular mesh, similiar to the Delaunay mesh for the eisenstein integers: ![Delaunay mesh](http://i.stack.imgur.com/NhJUf.png) Except that the Delaunay mesh on the 3D points forms a solid, not a surface. How can I form a mesh surface from these points?


Why does Mathematica appear to change the head of certain expressions?

I don't know if the question trivial or not (if so I will delete it), but here is what I have: I know that               x x     (*  x^2  *)      Looking at the full form gives               FullForm[Times[x, x]]     (* Power[x, 2] *)      It is clear that the `Times` head has been changed to `Power` head. I just wonder how does this happen. Can I control this behavior to stop this conversion between heads?


How to programmatically replace an expression in a .m file

I'm trying to write some code to programmatically replace a particular expression in my `init.m` file with a different expression. (It'll probably be some multi-line construct wrapped in a `Module[{someTag}, ...]` (where `someTag` is chosen to be unique and descriptive).) I was naively thinking `Import["init.m", "HeldExpressions"]` was going to be just what I needed, and would roundtrip nicely with an `Export[]`, but `Import[]` doesn't seem to help me preserve white space or comments. So I think I'm going to have to do this as text, and not as a list of expressions. I'm prepared to write my own (simple) expression splitter, but I'd be thrilled if there's some way for me to avoid going down that path. This might be crazy talk, but is there any good way to enlist the help of Mathematica's parser to spot where an expression begins and ends?


How to copy code out of notebook to an external text editor without extra line feeds being added?

I am simply trying to copy code from a cell (input cell) in a notebook, to paste the code into a plain text editor, and not have some lines wrap in the middle. I need to copy the code, as is, to a text editor, so I show it verbatim in there. I copy the code by selecting the cell, and then do COPY AS, and select INPUT TEXT. Then paste it into the other text editor. (if I try COPY AS PLAIN TEXT, then things are worst, I lose all formatting, so that is not an option) For some reason, some lines that are longer than some length, will end up wrapping in the text editor when pasted. The LF are inserted in different places depending on the length of the line. I see a CRLF added where this was not in the notebook. Here is a screen shot, where I have 2 cells, and the result of copying each cell to the text editor. You can see that the first cell, which is the same as the second cell, except one line in there is a little tiny bit longer than what is in the second cell (I added `+ x` to that line to make it little longer). Now that line was wrapped in the copy in 2 places. When the second cell, the line wrapping was in one place. ![enter image description here](http://i.stack.imgur.com/KIuGL.png) Here are the 2 cells shown in the image above, so you can try that yourself:               foo {z_} := Module[{x, y},       If[z < 1,        x + y/2 + Sin[3 x] - 43453488362 Cos[x]/Pi - (343^4 - Sin[34 - x]) + 34 Sin[x y]/(x y) + x,        x - y        ]       ]      second cell               foo {z_} := Module[{x, y},       If[z < 1,        x + y/2 + Sin[3 x] - 43453488362 Cos[x]/Pi - (343^4 - Sin[34 - x]) + 34 Sin[x y]/(x y),        x - y        ]       ]      Here is a screen shot showing the locations of the CRLF characters that are added during the copy of both cells to the text editor. ![enter image description here](http://i.stack.imgur.com/I84Qq.png) I would like to be able to copy the code from the cell to a text editor, without any extra LF being inserted during the copy. I think this problem is due to the notebook itself, but not sure. I tried different text editors, and they are show the same problem. So the LF is added during the copy, and not during the paste. I am on windows 7, using version 9. **Update** I have just found a work around !! But this can be done for the whole notebook, and not individual cells. But that is ok. I could always copy the cell to its own notebook. ## Here are the steps to copy code out of a notebook without extra CRLF   1. select File->SAVE AS ->Rich Text format (.rtf)   2. Using MS WORD (or any other program that can read .RTF), open the .rtf file   3. Select and Copy the text from word using the mouse.   4. Paste, using the mouse, into the other text editor (notepad, etc...) Now no line wrapping appear! No extra CRLF are seen. ![enter image description here](http://i.stack.imgur.com/ORbqH.png) So, I am happy now. This works for me, as a work around. It would be nice to know though if it is possible why this happens. **Update** Well, the excitement did not last for long. Even though the above solution fixes the extra CRLF problem, it introduces new problems. Many of Mathematica symbols in the code do not show up correctly in .rtf (all the 2D math symbols for examples. So this solution does not work. So I still need to find a way around this. More research is needed.


Why does Evaluate[a[[1]]]=0 assign a value to a variable while a[[1]]=0 doesn't?

I'm trying to do a small page counter with Mathematica, for leting me know about my reading progress on some books. I'm stuck on a problem:               Clear["Global`*"]     a = {v1, v2, v3, v4, v5, v6}     a[[1]] = 0     v1      With this, I'm trying to give 0 as a value to v1, but it seems that it swaps the v1 for 0 instead. I was expecting the evaluation of v1 to give me 0 as a value, but it still gives me v1, I've managed to partialy solve this with the following addition:               Clear["Global`*"]     a = {v1, v2, v3, v4, v5, v6}     Evaluate[a[[1]]] = 0     v1      When the v1 is evaluated, it gives me 0 as output, but it's not working in my program and I have no idea why this is happening. I've also managed to perform a separate test by evaluation both:               Clear["Global`*"]     a = {v1, v2, v3, v4, v5, v6}     Evaluate[a[[1]]] = 0     v1          Clear["Global`*"]     a = {v1, v2, v3, v4, v5, v6}     a[[1]] = 0     v1      In this case, it the outputs for both v1's are v1. Why is this happening? > My program(If needed): >   >   >     Clear["Global`*"] >     g = 1; i = 1; l = {}; ln = {}; pi = {}; m = 1; >     r1 := AppendTo[l, ToExpression["p" <> ToString[i++]]] >     r2 := AppendTo[ln, n] >     r3 := Clear[n] >     r4 := AppendTo[pi, np] >     r5 := Clear[np] >     r6 := Evaluate[l[[m]]] = 0 >     r7 := m++ >   >     o1 = Button["+1", r1; r2; r3; r4; r5; r6; r7, ImageSize -> {30, 19}]; >     o2 = InputField[Dynamic[n], String, FieldSize -> {15, 1}]; >     o3 = InputField[Dynamic[np], Number, FieldSize -> {4, 1}]; >     o4 = {o1, o2, o3}; >     o5 = Style["Book", 12]; >     o6 = Style["Book Title", 12]; >     o7 = Style["# Pages", 12]; >     o8 = {o5, o6, o7}; >   >     Grid[{o8, o4}, Frame -> True] >   >     t = Table[Button[ToString[x], Delete[l, {x}]], {x, 1, Length[l]}] // >       Dynamic >     l // Dynamic >     ln // Dynamic >     pi // Dynamic >


how can I generate a sequence of assignments?

I want to make a sequence like follows               r[1]=     r[2]=     r[3]=     r[4]=     ....     r[n]=      The above `r[i]` represents coordinates which I have to type in manually one by one. So I make such a sequence to make the typing easier and more confortable. (even without having to type the `=`, I am so lazy, I admit). If the problem involve n coordinate, I just generate a sequence of length n. So I naively write as follows               Table[r[i]= ,{i,1,n}]//TableForm      But with `=` there, I can't make such a list. So how could I generate a sequence of such incomplete expressions (like the above expressions, the `=` has no right side, this makes _Mathematica_ can't table it)?


Show does not combine the plots

i've the following problem: because it's not possible to plot complex numbers (or is it?) i created my own "function":                   complexPlot[cn_] :=            Plot[0, {x, -100, 100},                 PlotRange -> {-500, 500},                AspectRatio -> 1,                  AxesLabel -> {Re, I },                Epilog -> {Background -> None, PointSize[0.03],                 Point[{{Re[cn[[1]]], Im[cn[[1]]]}, {Re[cn[[2]]],                       Im[cn[[2]]]}, {Re[cn[[3]]], Im[cn[[3]]]}}]}       ]      with complexPlot, I can plot my complex Numbers, but i want to have one graphic for all my number pairs.                   myPlots = Table[                         complexPlot[linPolesAll[[n]]],                         {n, 1, 16}]              Show[myPlots]      Does not work, it overlays all Plots with the last one (tried it with Show[myPlots[[1]],myPlots[[10]]]) any ideas? Thanks!


Display function value on hover?

I have used Manipulate in conjunction with Plot to draw a function's graph and I would like to show the current x-axis value and function value while hovering over the function's plot. How can I achieve this? Thanks.


Include Headers on first page

I know it is possible to check the box "Include headers on first page" in the "Headers and Footers" dialog box of the Print Settings menu item, but is it also possible to check this using commands in the Notebook itself? It would be for the current notebook. Thanks for all help, as always!


Problem setting up edge rendering function

I have a graph, and I want my `EdgeRenderingFunction` to colour the edges based on the vertex they originate from. In this toy example, I'm trying to get the edge originating from vertex 1 to be red:               GraphPlot[{1 -> 2, 2 -> 3, 3 -> 4, 5 -> 1, 5 -> 2, 5 -> 3, 5 -> 4,        1 -> 4, 3 -> 5, 3 -> 3},       EdgeRenderingFunction -> (If[First[#1] === 1, {Red, Line[#1]},           Line[#1]] &), VertexLabeling -> True]      ![bad](http://i.stack.imgur.com/04rky.jpg) What am I doing wrong? I was following the (slightly more complicated) model given in the _Mathematica_ documentation:               GraphPlot[{1 -> 2, 2 -> 3, 3 -> 4, 5 -> 1, 5 -> 2, 5 -> 3, 5 -> 4,        1 -> 4, 3 -> 5, 3 -> 3},       EdgeRenderingFunction -> (If[          Length[#1] > 2, {Red, Line[#1],            Text[If[First[#1] === Last[#1], "loop", "multiedge"],             LineScaledCoordinate[#1, .7], Background -> White]},           Line[#1]] &), VertexLabeling -> True]      ![good](http://i.stack.imgur.com/caVav.jpg)


How can I define a function that takes a list of reals?

I'm trying to define a function `f` which takes a list of reals. My purpose is to build a function which I can give a list of reals, integers or strings and have it build an appropriate probability distribution for. So I'd like to do something like               f[{samples_Real}]:=makeRealDist[samples];     f[{samples_Integer}]:=makeInteger[samples];     f[{samples_String}]:=makeCategoricalDist[samples];      I can easily match on `Real`/`Integer`/`Strings`. The part I can't figure out is how to match on a list of `Real`/`Integer`/`String`.


What is the most convenient way to change options for Graph[] objects?

What is the most convenient way to change options such as `VertexLabels` in existing `Graph` objects? (Version 7 users note: `Graph` is new in Mathematica 8.) * * * With graphics, we can use `Show` for this, not matter what function was originally used to produce the graphic:               g = Plot[Sin[x], {x, 0, 10}]     Show[g, Axes -> False, Frame -> True]      Is there an analogous function for `Graph`s? Suppose we already have a graph, and now we need to show vertex labels in a different way. Here's a workaround using `HighlightGraph`:               g = Graph[{1 -> 2}]     HighlightGraph[g, {}, VertexLabels -> "Name"]      While it works, this is not really what `HighlightGraph` is meant for. * * * Please note that `Graph` objects are atomic before trying to take them apart. Also, I'm looking for the safest and most robust solution. I'm hoping there's a function I overlooked.


Integral of integral — it takes too much time

When I evaluate the following expression in _Mathematica_ , it takes so much time that I don't want to wait for the evaluation to complete. So I think that there must be a better approach.               wewint[lx_?NumericQ, ly_?NumericQ] := NIntegrate[         Cos[lx]*Cos[qx] + Sin[lx]*Sin[qx], {qx, -Pi, Pi}, {qy, -Pi, Pi},          Method -> Automatic];     NIntegrate[wewint[lx, ly], {lx, -Pi, Pi}, {ly, -Pi, Pi}, Method -> Automatic]      If I use `Cos[lx-qx]` instead of `(Cos[lx]*Cos[qx] + Sin[lx]*Sin[qx])`, the effect is the same. In reality, the expression I am working with is much more complicated and it couldn't be calculated analytically.


How to speed up the function DelaunayTriangulation?

First define a function `meshGrid` to generate some points:               meshGrid[{x1_, x2_, y1_, y2_}, h0_] :=        With[{yh0 = h0*Sqrt[3.]/2},          Array[{(#1 - 1)*h0 + x1 + (1 + (-1)^#2) h0/4, (#2 - 1)*yh0 +              y1} &, Ceiling@{(x2 - x1)/h0, (y2 - y1)/yh0}]]~Flatten~1;          p = meshGrid[{-1, 1, -1, 1}, 0.05];      The computing time of `DelaunayTriangulation`:               Needs["ComputationalGeometry`"];     DelaunayTriangulation[p] // Timing // First      In my computer it gives `18.533s` Matlab saves much time if does the same thing: ![enter image description here](http://i.stack.imgur.com/5s0vV.png) **====================================Update=====================================** @halirutan really made a great attempt to point the way, but I failed to compile and didn't get the right answer, maybe I should learn something before. Here I find another way in this blogpost, which also relates to Qhull but easier to implement. You can get more infomation from here. Before changing anything, two files need to be downloaded, one is mPower, from which we need is mPower.m, another one is Qhull. You can get the rest steps from that blog, only step two is worthy of note: step 2: download qhull for windows, you may need to change the name, and put it into the folder C:\qhull. **Then Copy all the *.exe files in bin folder and paste them in folder qhull, errors will occur without this step.**


Make a scatter plot

Considering I have weather data for last 10 years for London, how can I make a scatter plot that will show the previous day's temperature as a function from today's temperature?


Custom ticks in distribution chart

I am trying to just get simple logarithmic ticks to the distribution chart, and failing... It is unhappy with any `FrameTicks` format I try (sparing `-> Automatic`). What am I doing wrong?               DistributionChart[       Log[RandomReal[ExponentialDistribution[100], 50]],        Frame -> True, ChartStyle -> LightBlue,        FrameTicks -> {{{{Log[0.001], "0.001"}, {Log[0.01],"0.01"}}, None}, {None, None}},       ChartElementFunction -> "HistogramDensity",       ChartLabels -> {"s "}, BaseStyle -> {FontSize -> 14, FontFamily -> "Helvetica"}]


How to implement hive plot for graphs in Mathematica?

I'm trying to implement a version of the _hive plot_ advocated in [Kryzywinski, _et al._ , 2012]. There are many examples of such graphs on the author's webpage. It would be good enough for me to have three axes. I'm now able to project the coordinates onto three axes and style my graph like this via `VertexCoordinates`: ![basic hive](http://i.stack.imgur.com/TbdEK.png) First of all, is there any way to make edges be arcs and not straight lines?   1. Krzywinski M, Birol I, Jones S, Marra M (2012). _Hive Plots — Rational Approach to Visualizing Networks_. Briefings in Bioinformatics 13(5), 627-644.


Alternating Axis Labeling between Left and Right Axis

I'm using the following to label a MatrixPlot: `FrameTicks -> {{yticks, None}, {None, xticks}},` I'm labeling these ticks with text. It is impossible to get the graph to a reasonable size while maintaining legibility of the text all on a single axis. So what I'm attempting to do is sub-divide my label list, alternating the label that goes to one of two tick expressions: `FrameTicks -> {{leftyticks, rightyticks}, {None, xticks}},` But I have no idea how to do that. As of right now I am sorting the labels alternatively by hand and pasting them in to 'leftyticks' and 'rightyticks'. There has got to be a faster way to drag a list from a file, split it in alternating sequence, and dump the products in to the two tick-label groups, right?


Loading custom notation on startup without showing the Notation palette

I was creating some custom notations using the Notation package and it works fine. I put it in my default personal package, and it loads fine on _Mathematica_ 's startup. To make it complete I need just one more thing. How can I suppress the Notation palette from appearing every time I launch _Mathematica_? Is there some command that I can put into my package?


Correctly set up FindMinimum

I am trying to setup the following minimization to align two astronomical images.               scfac =        FindMinimum[         Log[AlignCriterion3[imTargetFM*SC, imRefFiltFM*SC, alpha]], {alpha, 1},          PrecisionGoal -> 6, AccuracyGoal -> 10];      where,               AlignCriterion3[im_, imRef_, scfac_] :=        Plus @@ Plus @@ ((im - ImRescale[imRef, scfac])^2)      and               ImRescale[Im_, ScFac_] :=        Module[{n, res},          n = Dimensions[Im][[1]];         Print[ScFac];         res = Resize[ImageData[ImageResize[Image[Im], {n*ScFac, n*ScFac}]], n]       ]      Clearly, I do not know how to setup the `FindMinimum` since I keep getting the following error: > ImageResize::imgrssz: The size {120 alpha,120 alpha} is not a valid image > size specification. How do I set it up so that the value of alpha is actually passed to the Rescaling code I've written. ![example of an image that I am trying to align. I have the x & y shifts pegged down pretty accurately - the idea is to scale the image size to try and fix what I think is some kind of scale based alignment issue.](http://i.stack.imgur.com/awjfW.png) Example of an image that I am trying to align. I have the x & y shifts pegged down pretty accurately - the idea is to scale the image size to try and fix what I think is some kind of scale based alignment issue.


How do I convert from NAD 83 State Plane Coordinates to Latitude and Longitude?

I am trying to convert NAD 83 State Plane New York Long Island coordinates to Latitude/longitude. Below is my code - what am I doing wrong?               LatitudeLongitude[GeoPosition[{172248, 1002321, 0}, "SPCS83NY04"]]


RSolve Lotka-Volterra: A Closed Form Solution to this Difference Equation?

I would like to solve a difference equation, a Lotka-Volterra difference equation. I tried a model from http://www.stolaf.edu/people/mckelvey/envision.dir/nonDE.lotka-volt.html Using their parameters:               a = 0.04; b = 0.0005; c = 0.2; d = 0.1;      I obtain the following:               eqs = {r[n + 1] == r[n] + a*r[n] - b*r[n]*f[n], f[n + 1] == f[n] + b*d*r[n]*f[n] - c*f[n]}     RSolve[eqs, {r[n], f[n]}, n]          (* RSolve[{r[1 + n] == 1.04 r[n] - 0.0005 f[n] r[n],                f[1 + n] == 0.8 f[n] + 0.00005 f[n] r[n]}, {r[n], f[n]}, n] *)      Mathematica does not give any clue, what is wrong. Can anyone help me find out where the problem is?


Fast integration of 2D distribution across lines parallel to y-axis

I'm struggling with a small data set and a slow calculation. I have _hundreds_ of small 2D data arrays and need to integrate across several lines parallel to the y-axis. Let me start with the data array:               data={{51.6,10},{16.52,18},{48.835,12},{72.975,7},{61.085,19},{78.362,11},{24.312,25},           {26.818,5},{37.336,5},{70.647,18},{48.783,35},{40.379,35},{75.926,8},{23.226,8},           {54.727,18},{116.046,12},{20.597,20},{21.973,28},{74.821,7},{56.408,51}};      After rescaling and truncating the distribution, it looks like this:               dnorm=Transpose[Rescale/@Transpose[data]];     pdf[x_,y_]=PDF[TruncatedDistribution[{{0,∞},{0,∞}},                    SmoothKernelDistribution[dnorm,Automatic,{"Radial","Gaussian"}]],{x,y}];     ContourPlot[pdf[x,y],{x,0,1},{y,0,1}]      ![plot of distribution](http://i.stack.imgur.com/V4vOR.png) I am interested in the profile across a line parallel to the y-axis (say e.g. $x=0.5$) and do handle this profile as a distribution for this specific x-value. I need the 95% quantile for this specific distribution at the specific x-value. Finally, I am interested in all the quantile-values for all x-values between 0 and 1 (in the rescaled domain) and do rescale them back afterwards. I have written the following function, which works but need approx. 10 seconds (even without the line plot and sampling at 20 data points between 0 and 1). I have to evaluate _hundreds_ of data sets with this function, so I **need to speed it up**.               myquantile[d_List,q_]:=Block[{dnorm,pdf,x,y,func,int,ξ,ψ,sol,invx,invy,lp},       dnorm=Transpose[Rescale/@Transpose[d]];       pdf[x_,y_]=PDF[TruncatedDistribution[{{0,∞},{0,∞}},                      SmoothKernelDistribution[dnorm,Automatic,{"Radial","Gaussian"}]],{x,y}];       func[ξ_]:=Block[{},         int=NIntegrate[pdf[ξ,y],{y,0,1}];         ψ/.FindRoot[NIntegrate[pdf[ξ,y],{y,0,ψ}]/int==q,{ψ,0.8,0.9},Evaluated->False]];         {invx[x_],invy[x_]}=Rescale[x,{0,1},#]&/@({Min[#],Max[#]}&/@Transpose[d]);         sol=Interpolation[Table[{invx[x],invy[func[x]]},{x,0,1,0.05}]       ];       lp=Plot[sol[x],{x,invx[0],invx[1]},AxesOrigin->{invx[0],invy[0]}];       {sol,lp}     ];     myquantile[data, 0.95] // Timing      The final `InterpolatingFunction` looks like this (in the regular domain): ![plot of interpolant](http://i.stack.imgur.com/Yrkl1.png) Can anybody point me in the right direction? Is it possible to get the line distribution in a different and faster way? A `MarginalDistribution` is pretty much what I want, but it is the distribution for all x-values and it gives me no information on individual x-values. Thanks!


Eigenvectors for a large symbolic matrix

I'm trying to compute the eigenvectors for a 42x42 symbolic matrix (with one variable) in Mathematica. I get the following error: Eigenvectors::eivec0: Unable to find all eigenvectors. >> and the answer is:zero What could be a possible way to proceed? Thanks. my matrix is in this form: Matrix= {{-2.74685 + (11 j)/2, 0, -0.390857, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, -1.72219 + (11 j)/2, 0, -1.32891, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {-0.390857, 0, -1.01642 + (11 j)/2, 0, -2.79771, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, -1.32891, 0, -0.528246 + (11 j)/2, 0, -4.66286, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, -2.79771, 0, -0.204268 + (11 j)/2, 0, -6.72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, -4.66286, 0, -0.00765149 + (11 j)/2, 0, -8.736, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, -6.72, 0, 0.0906785 + (11 j)/2, 0, -10.4832, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, -8.736, 0, 0.115571 + (11 j)/2, 0, -11.7669, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, -10.4832, 0, 0.0894089 + (11 j)/2, 0, -12.4457, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, -11.7669, 0, 0.0331231 + (11 j)/2, 0, -12.4457, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, -12.4457, 0, -0.0331231 + (11 j)/2, 0, -11.7669, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, -12.4457, 0, -0.0894089 + (11 j)/2, 0, -10.4832, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -11.7669, 0, -0.115571 + (11 j)/2, 0, -8.736, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -10.4832, 0, -0.0906785 + (11 j)/2, 0, -6.72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -8.736, 0, 0.00765149 + (11 j)/2, 0, -4.66286, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -6.72, 0, 0.204268 + (11 j)/2, 0, -2.79771, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -4.66286, 0, 0.528246 + (11 j)/2, 0, -1.32891, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2.79771, 0, 1.01642 + (11 j)/2, 0, -0.390857, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1.32891, 0, 1.72219 + (11 j)/2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0.390857, 0, 2.74685 + (11 j)/2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -6.3581 - 5 j, 0, 0., 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -4.84175 - 5 j, 0, -0.390857, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0., 0, -4.12192 - 5 j, 0, -1.32891, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0.390857, 0, -3.33864 - 5 j, 0, -2.79771, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1.32891, 0, -2.71762 - 5 j, 0, -4.66286, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2.79771, 0, -1.89062 - 5 j, 0, -6.72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -4.66286, 0, -1.29051 - 5 j, 0, -8.736, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -6.72, 0, -0.796132 - 5 j, 0, -10.4832, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -8.736, 0, -0.417701 - 5 j, 0, -11.7669, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -10.4832, 0, -0.161978 - 5 j, 0, -12.4457, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -11.7669, 0, -0.0331231 - 5 j, 0, -12.4457, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -12.4457, 0, -0.0331231 - 5 j, 0, -11.7669, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -12.4457, 0, -0.161978 - 5 j, 0, -10.4832, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -11.7669, 0, -0.417701 - 5 j, 0, -8.736, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -10.4832, 0, -0.796132 - 5 j, 0, -6.72, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -8.736, 0, -1.29051 - 5 j, 0, -4.66286, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -6.72, 0, -1.89062 - 5 j, 0, -2.79771, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -4.66286, 0, -2.58124 - 5 j, 0, -1.32891, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2.79771, 0, -3.33864 - 5 j, 0, -0.390857, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1.32891, 0, -4.12192 - 5 j, 0, 0.}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0.390857, 0, -4.84175 - 5 j, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0., 0, -5.808 - 5 j}} //MatrixForm


Integrate does not accept my integrand expression

I want to calculate the symbolic integral, but I could not obtain the final results from Mathematica.               $Assumptions = R > 0 && f > 0 && m ∈ Integers;     a1[a_] := Log[R Sqrt[2 (1 - Cos[a])]];     b[a_] := R (1 - Cos[a]);     c[a_] := R Sin[a];     d2[a_] := 2 R R (1 - Cos[a]);     d4[a_] := d2[a]^2;     Ebb[a_] := -a1[a] + b[a]^2/d2[a];     Ebc[a_] := b[a] c[a]/d2[a];     Ecc[a_] := -a1[a] + c[a]^2/d2[a];     fb[a_] := f Cos[m a];     fc[a_] := f Sin[m a];      when I calcualted wb ingetral as follows:               wb = Integrate[Ebb[a] fb[a] + Ebc[a] fc[a], {a, 0, 2  π}]      I found the result was not calculated -- I got the output: ![output](http://i.stack.imgur.com/Jf4Ff.png) Where did I make a mistake? Could you tell me how to do one bit more complicated integral by your method, please? I used the same method as you provided, but failed this time. Here I just introduced another angle u besides the angle a, and made fb and fc a little more complicated. But I guess that these minor changes should not affect your method to be applied.               a1[a_, u_] := Log[R Sqrt[2 (1 - Cos[u - a])]];     b[a_, u_] := R (1 - Cos[u - a]);     c[a_, u_] := R Sin[u - a];     d2[a_, u_] := 2 R R (1 - Cos[u - a]);     d4[a_, u_] := d2[a, u]^2;     Ebb[a_, u_] := -a1[a, u] + b[a, u]^2/d2[a, u];     Ebc[a_, u_] := b[a, u] c[a, u]/d2[a, u];     Ecc[a_, u_] := -a1[a, u] + c[a, u]^2/d2[a, u];     fb[a_] := Refb Cos[m a] - Infb Sin[m a];     fc[a_] := Refc Cos[m a] - Infc Sin[m a];               $Assumptions = True;     wb = Integrate[Ebb[a, u] fb[a] + Ebc[a, u] fc[a], {a, 0, 2 \[Pi]},      Assumptions -> R > 0 && Refb > 0 && Infb > 0 && Refc > 0 && Infc > 0 && m \[Element] Integers && {u, 0, 2 \[Pi]}]      > >     1/2 (-((2 Infb Sin[m \[Pi]]^2)/m) + (Refb Sin[2 m \[Pi]])/m + > (1/(m^2))Infb (-Hypergeometric2F1[1, -m, 1 - m, E^(-I u)] + >       Hypergeometric2F1[1, m, 1 + m, E^(-I u)] - >       Cos[2 m \[Pi]] Hypergeometric2F1[1, m, 1 + m, >         Cos[u] - I Sin[u]] + 2 m Log[R] - 2 m Cos[2 m \[Pi]] Log[R] + >       m Log[2 - 2 Cos[u]] - m Cos[2 m \[Pi]] Log[2 - 2 Cos[u]] + >       Hypergeometric2F1[1, -m, 1 - m, >         Cos[u] - I Sin[u]] (Cos[2 m \[Pi]] - I Sin[2 m \[Pi]]) + >       I Sin[2 m \[Pi]] - >       I Hypergeometric2F1[1, m, 1 + m, Cos[u] - I Sin[u]] Sin[ >         2 m \[Pi]]) + (1/(m^2)) I Refb (1 - Cos[2 m \[Pi]] - >       Hypergeometric2F1[1, -m, 1 - m, E^(-I u)] - >       Hypergeometric2F1[1, m, 1 + m, E^(-I u)] + >       Cos[2 m \[Pi]] Hypergeometric2F1[1, m, 1 + m, >         Cos[u] - I Sin[u]] + >       Hypergeometric2F1[1, -m, 1 - m, >         Cos[u] - I Sin[u]] (Cos[2 m \[Pi]] - I Sin[2 m \[Pi]]) + >       I Hypergeometric2F1[1, m, 1 + m, Cos[u] - I Sin[u]] Sin[ >         2 m \[Pi]] + 2 I m Log[R] Sin[2 m \[Pi]] + >       I m Log[2 - 2 Cos[u]] Sin[2 m \[Pi]]) - (Refb (m Cos[u] Sin[2 m \[Pi]] > - 2 Sin[m \[Pi]]^2 Sin[u]))/(-1 + >     m^2) + (Infb (2 m Cos[u] Sin[m \[Pi]]^2 + >       Sin[2 m \[Pi]] Sin[u]))/(-1 + m^2) + (1/(-1 + m^2)) 2 Sin[m \[Pi]] > (Sin[m \[Pi]] (Refc Cos[u] - Infc m Sin[u]) + >       Cos[m \[Pi]] (Infc Cos[u] + m Refc Sin[u]))) >   The help of `Limit` failed this time:               Limit[wb, m -> #] & /@ Range[-2, 2]      The final result is too long, so I do not copy it here. I am not sure where I made a mistake.


Remove linear trend from data

I have a large data set with 150k lines and two data columns. I noticed that there is a linear trend, which I want to remove. So, I do the following: first fit with a linear model               model = LinearModelFit[data, x, x]      then, I substract the fit from the data               data1 = data;     data1[[All, 2]] = data[[All, 2]] - model[data[[All, 1]]] + model[0];      This, however, takes unacceptable amount of time. Is there any way I can speed things up.


How do I visualize the result of EdgeColoring[g]?

Combinatorica has a heuristic edge-coloring function `EdgeColoring`. When I execute it on a graph, the result is a list of integers. My guess is that an integer $i$ at position $j$ in the list corresponds to coloring the edge $e$ at position $j$ with the color $i$. The Combinatorica documentation is helplessly scarce, and it's hard for a beginner to understand how to visualize the colored graph. Am I supposed to use `ShowGraph`, or `Highlight`, or something else? For example, consider the following.               << Combinatorica`     g = CompleteGraph[4];     c = EdgeColoring[g];      The output is now `{1, 2, 3, 3, 2, 1}`. How do I print out the graph with the colors on the edges showing?


Fitting a function

I defined and evaluated a function               Max2[t_?NumericQ] := Log[Abs[-1 + First[Maximize[sol1[[2]][x, t], 0 <= x <= L, x]]]];      Now, I expect this to be close to a straight line as a function of $t$, so I would like to get the best slope from a fit. Looking at the reference website, I don't understand how to linearly fit a function.


Finding all instances of length $N$ common subwords in two strings

Given a pair of strings, I'd like to return a list of all common subwords of a fixed length of "n" characters (i.e. contiguous subwords of length "n" that occur in both strings), allowing for overlaps. Is there a built-in or close- to-built-in way to do this in Mathematica?


Linear regression in a chosen range of points

Hi I'm absolutely newbie in Mathematica and have following problem: My list looks like `{{50, 0.75}, {51, 0.76}, ...`, and I want to choose a range out of my x-values (I don't want so say: _from point 150 to ..._ , I want to choose with values like _from x value 50 to 60_ ), with only these points a linear regression has to be done. I tried with `LinearModelFit[data, x, x]`, and Mathematica made a linear regression with all values, now I want to choose a range but I can't find a solution =( Has somebody an idea?


How can I get better control over StreamPlot?

I'm having some difficulties with the command `StreamPlot` in _Mathematica 7.0_. Here's the basic plots I'm doing :               StreamPlot[{x, -y}, {x, -2, 2}, {y, -2, 2}, Axes -> True,     AxesOrigin -> {0, 0}, FrameTicks -> None,      StreamPoints -> 12, StreamScale -> 0.15, PerformanceGoal -> "Quality"]          StreamPlot[{y, x}, {x, -2, 2}, {y, -2, 2}, Axes -> True,      AxesOrigin -> {0, 0}, FrameTicks -> None, StreamPoints -> 12,      StreamScale -> 0.15, PerformanceGoal -> "Quality"]      Here's the output, which I find ugly : ![Ugly output](http://i.stack.imgur.com/IvJw2.jpg)   * How can I define the number of arrows heads to be drawn on each curve? Currently, there are too many arrows on the curves. I would prefer a maximum of two (or maybe three) arrows per stream curve.   * How can I make the output perfectly symetric? Look for example at the second picture, which is terrible.   * How can I remove the straight stream lines?


Efficient way to generate random points with a predefined lower bound on their pairwise Euclidean distance

Using Mathematica what is an efficient way to generate a list of $n$ **random** two dimensional points $\\{x_i,y_i\\}$ where $i=1,...,n$ so that **no** two points $p_1$ and $p_2$ in the list has an Euclidean distance lower than say $d$ meaning $\|p_1-p_2\|\leq d$. I came up with the following solution. Though it works I wanted to know if some better method exists. **Code**               NodeGenetrator[LowerBound_, UpperBound_, DistanceBound_,SampleLength_] :=      Block[{list},           list = RandomReal[{LowerBound, UpperBound}, {1, 2}];           For[i = 0, Length@list <= SampleLength - 1, i++,               list = Module[{NewVal, dist},                             NewVal = RandomReal[{LowerBound, UpperBound}, 2];                             (*NewVal=RandomVariate[NormalDistribution[                             Mean@{LowerBound,UpperBound},DistanceBound],2];*)                             dist = Map[EuclideanDistance[NewVal, #] &, list];                             If[Min[dist] >= DistanceBound,                                 AppendTo[list, NewVal],                                 list                               ]                            ];              ];           list          ];     (* Define function parameters *)     LowerBound = 0;     UpperBound = 100;     DistanceBound = 5;     SampleLength = 60;     sample = NodeGenetrator[LowerBound, UpperBound, DistanceBound,SampleLength];     (ListPlot[#, Frame -> True, Axes -> False,PlotStyle -> PointSize[Large],     AspectRatio -> 1] &)@sample      **Output** ![enter image description here](http://i.stack.imgur.com/gLa0e.png)   1. As one can see this code uses `For` loop and also keeps on iterating until number of points requested is not met. This somehow makes the _execution time_ for this function unpredictable!    2. As expected the parameter `DistanceBound` has a important effect on the function behavior. If we try `DistanceBound=12.5` function evaluation becomes very _time consuming_.   3. Here we check only one mutual distance condition but is it possible to use a more _general test function_ that checks for more than one mutual characteristics involving those requested number of points that are to be generated. BR


Defining an integer-valued function on an integer domain

This should be an easy question! I want to define a function with domain = the 12 integers `{1,12}`, with the values `f[1]=31`, `f[2]=28`, `f[3]=31`, etc. (number of days in the month). This will be a part of nested `Do[]` loops running through the days of a non-leap year for a particular data set I am working with.


How can one define a custom data object?

In _Mathematica_ there are different objects like `InterpolatingFunction` or `SparseArray`? How can I define a custom data object with special data structure? **Example:**               f = Interpolation[{1, 2, 3, 5, 8, 5}];     f // InputForm      returns us               InterpolatingFunction[{{1, 6}}, {4, 3, 0, {6}, {4}, 0, 0, 0, 0, Automatic},      {{1, 2, 3, 4, 5, 6}}, {{1}, {2}, {3}, {5}, {8}, {5}}, {Automatic}]      But if one evaluates the above output one gets back               InterpolatingFunction[{{1, 6}}, <>]      I could not find any documentation how to do it for any custom data object that I want to define for my program.


Count number of sublists with a total not greater than a given max

Suppose I have a list of positive integers:               data={1, 1, 2, 3, 3, 3, 5, 5, 5, 7, 7, 8, 8, 9, 10, 10, 12, 16, 23}      I want to count the number of subsets up to length _t_ (including an empty set) whose total doesn't exceed the value _t_. The naive approach would be:               sumZaehl[t_, data_] :=       Length@Select[Total /@ Subsets[data, t], # <= t &]      But this would not work for larger list, because of the rapidly increasing number of subsets. I have an iterative method which works for larger list too:               sumZaehlIter[t_, data_] :=     Module[{n = Length[data], v, d, i, j},       For[i = 0, i <= t, i++, v[i] = 1];       For[i = 1, i <= n, i++,         d = data[[i]];         For[j = t, j >= d, j--,             v[j] = v[j] + v[j - d];       ]];     v[t]]      Is there a functional way to realize this?


Advanced Tupling

I had asked this question before but I guess I did not make the question clear enough and I apologize for that. Here is the problem: `Tuples` gives me more data than I want. A very bright user gave me a solution to restrict the output using a mechanism of filtering results as they are selected by his algorithm. The problem was even though it was efficient, it could not render data very well even on a machine with a lot of memory. Memory was the bottleneck and nothing else. It also tuples from all the lists and puts them in any of the positions. So let me present the problem hopefully more clearly, with some actual data I am trying to analyze. Suppose the following, I have the following lists:               a = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 18, 21, 22, 23, 25, 26, 28}          b = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 28, 30, 31, 33, 37, 41}          c = {6, 10, 13, 14, 15, 16, 18, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 32, 35, 37, 39}          d = {17, 19, 25, 30, 31, 33, 34, 35, 36, 38, 44}          e = {31, 41, 45, 47}          f = {23, 26, 31, 32, 33, 34, 35, 36, 38, 39, 40, 41, 42, 43, 45, 46, 47, 48, 49, 50, 51, 52, 53}      What I am trying to achieve: A tuple of length of 6 integer digits The first digit can only be a tuple of list a, second digit can only be tupled from list b, and so on. No number in any of the tupled outputs should be the same from any list, for example, `{2,2,25,25,31,31}` is not a desired combination and should be excluded. Order does not matter in this problem and should be excluded, for example, `{2, 1, 10, 9, 42, 41}` would be considered the same as `{1, 2, 9, 10, 41, 42}` and would be uneeded. Obviously we have a large set of possible combinations, and as previously mentioned, M! loves to use memory and is not at all processor dependent, so limiting the memory footprint would be a priority. Notice that the lists are of different lengths. For large numbers of combinations, M! has difficulty rendering such a potentially large dataset on even a highend consumer grade computer, it would probably be advantageous to write these out to a text file as they are generated so the data can be viewed with an external text editor like Ultraedit. Hope this is a detailed enough explaination and someone can share their thoughts! Thanks in advance!


Determining sample size with no replacement for a given confidence and reliability when there are x failures observed during sampling?

I am trying to follow the procedure of a Sandia Labs report found here to determine the required sample size, for various population sizes, with no replacement for a given confidence and reliability. The authors provide Mathematica code but I chose to write my own based on their procedure. The procedure described on page 13 is “The second SNL technique can be extended for any number of defective units in the sample by using the CDF for the hypergeometric distribution. This extension is referred to as the third technique. To find the minimum n given a specific x required for given N, γ, and R, the following technique can be used. Note that D is (1 - R) N rounded to the nearest integer. For the hypergeometric distribution HyperDist(n, D, N), find the minimum n for which CDF(HyperDist(n, D, N), x) does not exceed γ”. I believe I’m able to reproduce the corrected results in Tables 1 & 2 of the above report with my code below. There are columns labeled “INCORRECT” which I don’t plan to confirm. These tables however are based on observing _zero_ failures in the sample taken while I would like to be able to specify an arbitrary number of x failures. But when I use an x value (number of failures) other than zero I get an error message. Can someone shed any insight into this ? Thanks. My code is :               c=0.9;         (* Confidence *)     r=0.9;       (* Reliability *)     x=0;           (* Number of failures in the sample *)     pop=10;   (* Population size *)     n=0;            (* Sample size, iterated *)          d=Round[(1-r)*pop]     gamma=1-c     Do[{        Label[iterate];        n=n+1;        dist=HypergeometricDistribution[n,d,pop];        cdf[z_]:=CDF[dist,z];        cdfvalue=N[cdf[x]];        If[cdfvalue>gamma,Goto[iterate],Print["Solution:"]];        Print["n = ",n];        Print["CDF[x] = ",cdfvalue];        Break[]},      {pop+2}]


Variable location for intial value in ParametericNDSolve

I am trying to figure out if _Mathematica_ allows a variable location for a known initial value for `ParametricNDSolve`. I haven't been able to find an example where this is done. In the following I set `w[5.7] == 0` as an initial condition, but I would rather set `w[p] == 0`, or in some other way find the largest `p` for which the solution of interest exists. The solution of interest requires `w[y] >= 0` in the range `{ y, 1, p}`, so I plot `Sqrt[w]` there. Sorry about all the initial variables etc. The adjustable parameter `c` is to be anything in the range `{ 0, 1}` but here `0.2` is used.               {la, ra, ta, sa} = {0.06, 0.00002, 298., 5.6705*10^-8};      {roa, rex} = {5.6*10^(-8), 1.209} ; ro[y_] = roa*y^rex;      {ka, kc, kex} = {179., 0.9624, -0.2792}; k[y_] = ka*kc*y^kex;     {ga, g0, g1, g2, g3, g4} = {   0.0237,    1.09104, -0.751912,                                   0.792915, -0.0862438,  0.0029868};          g[y_] = ga*(g0 + g1*y + g2*y^2 + g3*y^3 + g4*y^4);     {fa, f1, f2} = {1.001, -0.001076, -0.0000635};      f[y_] = fa + f1*y + f2*y^2;     r[y_] = ra/f[y];     a[y_] = kex/y - 2.*(f1 + 2.*f2*y)/f[y];     b[y_, c_] = ((c^2)*ro[y]/Pi^2/r[y]^3 - 2.*sa*(ta^4)*g[y]*(y^4 - 1.))* la^2/ta/r[y]/k[y];          wsol = ParametricNDSolveValue[{ w'[y] + 2*a[y]*w[y]^2 + 2*b[y, c] == 0,                                     w[5.7] == 0}, w, {y, 1, 12}, {c}];     Plot[ Sqrt[wsol[0.2][y]], {y, 1, 12}, PlotRange -> {{1, 12}, {-1, 10}},           AxesOrigin -> {0, 0}, Frame -> True]      I get a nice graph with a $2$-branch solution, and it varies with parameter `c`, but I'd like to include the parameter `p` to be used in the initial condition `w[p] == 0`. At the largest `p = pmax`, the solution approaches a double root, somewhere between $5$ and $6$ in this example. That number is needed for further work - basically, what is `pmax[c]`?


2D Plotting of triplet data set with third axis as variation of thickness of curve

I have similar question like mentioned at representing triplet data set with color on 2d plot but this time instead of color I need to represent variation of third axis with the thickness of the curve


Solve trigonometric equation

I'm looking for a solution (graphic, numeric or analytic) for a function of the form: $$a^2\tanh(x)=\tan(ax),\quad a ≥ 1,\ x > 0$$ preferably using _Mathematica_. Any advice?


Image of first quadrant under $f(z)=(z+i)/(z-i)$

I'm able to plot the region where `Im[z] > 0` and `Re[z] > 0`:               RegionPlot[Re[x + I y] > 0 && Im[x + I y] > 0, {x, -2, 2}, {y, -2, 2}]      But now I'd like to apply the function $f(z)=(z+i)/(z-i)$ to this region and view the result. Can you give me suggestions?


Integrate[x^(1/3) AiryAi[x], {x, 0, ∞}]     (* Integrate[x^(1/3) AiryAi[x], {x, 0, ∞}] *)          Integrate[x^a AiryAi[x], {x, 0, ∞}] /. a -> 1/3     (* Gamma[1/3]/(3^(1/9) Gamma[1/9]) *)        * Why do I need to generalize/parameterize an integral sometimes to get a closed form result? Should cases like this be considered as bugs?   * How can I tell what kinds of generalization may help in a particular case? Do you know any other tricks besides replacing a constant with a parameter?


SolveAlways rejects inequality

I have two functions of `x`, `f` and `g`. `f[x] = g[x] + 2`, but the exact form of `g[x]` is unknown. It is known that `g[x]` is well-formed, positive, continuous, differentiable, etc., but an exact representation is unknown. What I would like to find are the conditions under which `f[x]` is positive. This is clearly whenever `g[x] > -2`, however, when I use `SolveAlways`:               f[x_] = g[x] + 2     SolveAlways[f[x] >= 0, x]      I get: > SolveAlways::eqf: 2 + g[x] < 0 is not a well-formed equation. >>


Use Initialization Cells to open a CellGroup

I would like to use "Evaluate Initialization Cells" to open a CellGroup in a notebook. However, the following code doesn't work if placed in an initialization cell:               SelectionMove[SelectedNotebook[], Previous, CellGroup];     FrontEndTokenExecute["SelectionOpenAllGroups"]      When I manually press shift-enter (on the closed CellGroup), then it works as expected by opening the CellGroup. Unfortunately, if I place this code in an initialization cell (in the appropriate location before or after the CellGroup I wish to have opened), the CellGroup doesn't open. Alternatively, is there an option I can set for CellGroups as there is for a single cell such as using `SetOptions` with `CellOpen -> True`?


DeleteCases that match partially

Say I have a list of strings L , L2= "some_text-to-delete" and I want to delete all the Li that match with "text" or "delete" DeleteCase only gives the ones that match exactly...


Reducing exponential inequalities fails

I am quite stumped by this problem :               Reduce[ N^(x-y) <1 && N > 0 , x, Reals]      gives the expected result               (N>1 && x<y) || (N<1 && x>y)      but               Reduce[ N^(x-y) <1 && N > 1 , x, Reals]     Reduce::nsmet This system cannot be solved by the methods available to Reduce      and more importantly               Reduce[ N^x < N^y && N > 0 , x, Reals]     Reduce::nsmet This system cannot be solved by the methods available to Reduce      Now this would not be a problem but I am trying to apply `Reduce` automatically to large quantities of inequalities, and I would rather avoid having to rewrite each and every one by hand. Especially considering that some will be multiple inequalities like               N^x < N^y < N^z      Do you have any idea why `Reduce` fails and how to go around this ? Thanks in advance.


Symbolic integral with distributions

Why is               Integrate[ HeavisideTheta[1 - x^2] DiracDelta[1 - x^2] , {x, 0, 1} ]     (*0*)      It should be `HeavisideTheta[0]`?


eigenvalues and eigenvectors without Root answers

I'd like to find eigen values and vectors of parametric 21*21 Matrix and i cant solve the root problem.please help me to find the answers without Root. My Matrix is:                {{-100 d, 0, 2 Sqrt[190] e, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,                0, 0, 0, 0}, {0, -81 d, 0, 6 Sqrt[57] e, 0, 0, 0, 0, 0, 0, 0, 0, 0,        0, 0, 0, 0, 0, 0, 0, 0}, {2 Sqrt[190] e, 0, -64 d, 0, 6 Sqrt[102] e,        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 6 Sqrt[57] e,        0, -49 d, 0, 8 Sqrt[85] e, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,        0}, {0, 0, 6 Sqrt[102] e, 0, -36 d, 0, 60 Sqrt[2] e, 0, 0, 0, 0, 0,        0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 8 Sqrt[85] e, 0, -25 d, 0,        42 Sqrt[5] e, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0,        60 Sqrt[2] e, 0, -16 d, 0, 28 Sqrt[13] e, 0, 0, 0, 0, 0, 0, 0, 0, 0,        0, 0, 0}, {0, 0, 0, 0, 0, 42 Sqrt[5] e, 0, -9 d, 0, 104 e, 0, 0, 0,        0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 28 Sqrt[13] e, 0, -4 d,        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0,        12 Sqrt[78] e, 0, -d, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0,        0, 0, 0, 0, 6 Sqrt[330] e, 0, 0, 0, 6 Sqrt[330] e, 0, 0, 0, 0, 0,        0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -d, 0, 12 Sqrt[78] e, 0,        0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -4 d, 0,        28 Sqrt[13] e, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,        12 Sqrt[78] e, 0, -9 d, 0, 42 Sqrt[5] e, 0, 0, 0, 0, 0}, {0, 0, 0,        0, 0, 0, 0, 0, 0, 0, 0, 0, 28 Sqrt[13] e, 0, -16 d, 0, 60 Sqrt[2] e,        0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42 Sqrt[5] e,        0, -25 d, 0, 8 Sqrt[85] e, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0,        0, 0, 0, 0, 60 Sqrt[2] e, 0, -36 d, 0, 6 Sqrt[102] e, 0, 0}, {0, 0,        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8 Sqrt[85] e, 0, -49 d, 0,        6 Sqrt[57] e, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,        6 Sqrt[102] e, 0, -64 d, 0, 2 Sqrt[190] e}, {0, 0, 0, 0, 0, 0, 0, 0,        0, 0, 0, 0, 0, 0, 0, 0, 0, 6 Sqrt[57] e, 0, -81 d, 0}, {0, 0, 0, 0,        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2 Sqrt[190] e,        0, -100 d}}


Partition data and plot each set as a different color

data = { {2, 60}, {4.5, 62}, {6.5, 64}, {8, 65}, {9, 65}, {10,        65}, {11, 65}, {12, 67}, {13, 67}, {14, 67}, {16, 67}, {17,        67}, {18, 67}, {19, 65}, {20, 64}, {21, 70}, {22, 75}, {23,        80}, {24, 80}, {25, 82}, {26, 82}, {27, 79}, {30, 80}}          ListPlot[data, Joined -> True,      AxesLabel -> {"T(Celcius)", "Volume Collected"}]      I want to partition the data into three pieces, and the plot produced should have the points joined with a line that corresponds to the color of the point.


Palette to set Cell Options such as Background Editable and Initialization property?

Hello I have found examples of codes that generate palettes to format the text of a cell (or a portion of it). I have also found codes for palettes that change the style of a cell. The latter is described in the Help for instance and gives a nice palette               CreatePalette[      Column[Button[Style[#, 12, FontFamily -> "Times"],           FrontEndTokenExecute[InputNotebook[], "Style", #],           Appearance -> "Palette", ImageSize -> 120] & /@ {"Title",          "Subtitle", "Subsubtitle", "Section", "Subsection",          "Subsubsection", "Text", "Code", "Input"}, Spacings -> 0],       WindowTitle -> "Format"]       Other questions here on MSE such as this do similar things, but still change the text style only. So I am stuck as I do not find how to modify this function to affect the `Background` of the Cell. I would also like to change properties such as the Cell being `Editable` or `Initialization`. Again I cannot find the proper command to put in the button to do this. Eventually I would like to have a button that takes a cell and makes several changes at once, for instance makes the cell initialization, non-editable, and LightGreen background. Is there a way to edit these properties with a palette? Thanks for helping, Roberto


Gaps in plots of equation solution from parameter

I'm trying to plot solution of system of equations as a function of parameter               Manipulate[{       Quiet[sol = Solve[{Ka*P*L*L == PLL, P0 == P + PLL, r*P0 == L + 2*PLL}, {P, L, PLL}]][[3]];       complex[x_] := PLL /. sol[[3]] /. r -> x;       Plot[{          Hold[Evaluate@D[complex[r], r]],          Hold[Evaluate@D[-complex[r], {r, 2}]]          } // Release,        {r, 0.1, 4},        PlotStyle -> {Red, Blue}        ]},      {Ka, 10000, 10000},      {P0, 0.5, 1}      ]      My plot has gaps! Why and how I can eliminate them? ![enter image description here](http://i.stack.imgur.com/3Frhi.png)


How can I create a table of sliders?

I'm trying to do the following: I have a table:               w = Table[ToExpression[ToString[h] <> ToString[i]], {i, 1, Length[c]}]      This table is suposed to generate variables, like the following list:               {h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11}      I'm trying to create a table of vertical sliders with this by adding this to the code:               w = Table[VerticalSlider[Dynamic[ToExpression[ToString[h] <> ToString[i]]]], {i, 1, Length[c]}]      It create a it gives me an error:               Set::write: "Tag ToExpression in \!\(ToExpression[\"hi\"]\) is Protected.      I'm aware that this may not be the best way todo this but it's all I can imagine, I guess the other feasible way would be with loops, I don't know. Can you help me?


How to make the coordinate indicator in a plot bigger?

I want the little vertical line which indicate the coordinate of the system in plot bigger. For example, in the picture below I marked those lines I am talking about with a blue rectangle. How can I make all such a indicators bigger? ![enter image description here](http://i.stack.imgur.com/zxPta.jpg)


Exporting numbered equations to HTML/TeX using conversion rules

This question is a follow up from this one. It may also be considered a duplicate since I have already asked this question in stackoverflow almost a year ago. For a background on using numbered equations see my post from SO. Since then I had not messed with the question till today. Consider the following:               ExportString[         Cell[             BoxData[                 FormBox[RowBox[{RowBox[{"f", "(", "x", ")"}], " ", "=", " ", "x"}],             TraditionalForm]         ],         "NumberedEquation",         CellTags -> "eq:myEq"         ]         , "HTML",         "FullDocument" -> False,         "ConversionRules" -> {             "NumberedEquation" -> {                 "\\begin{equation}\n", Convert`TeX`BoxesToTeX[#] &,  "\n\\end{equation}"             }         }      ]      The output is:               \begin{equation}          f(x) = x     \end{equation}      Notice how it was able to detect the cell tag using html. But if you were to export it using latex, it just doesn't. What we want is this output when using latex:               \begin{equation}\label{eq:myEq}     f(x) = x     \end{equation}      The question is, how we can use the conversion rules to take advantange of the cell tag.


What are the default TransformationFunctions used in Simplify and FullSimplify?

If I do               Simplify[(c^3 - s^3)^2 - (s^3 + c^3)^2,       TransformationFunctions -> Automatic]      (i.e. a verbose version of default behaviour), what transformation functions actually get applied? Similarly for FullSimplify. The documentation says `By default FullSimplify does not use Reduce:`. Well how would I know? What else doesn't it use? What does it use?


Helio chart for canonical correlation

I'm trying to create a chart usually called "Helio chart". It's a chart type very suited for canonical correlation analysis involving several dependent and independent variables. However, it is a little bit difficult to find good examples of for this chart on the web and the best example I have can be found on the 6th page of this paper on the NASA website: http://ti.arc.nasa.gov/m/profile/adegani/Canonical%20Correlation.pdf It is possible to create such a chart in Mathematica? ![enter image description here](http://i.stack.imgur.com/1fPk3.png)


How to apply a function of several arguments to a list?

I have a list of triplets:               list = {{1, 3, 5}, {4, 5, 1}, {4, 9, 2}}      How can I apply a function f to the last element of each triplet when f the last and second-to-last elements of each triplet as arguments? The result should look like: > >     {{1, 3, f[3, 5]}, {4, 5, f[5, 1]}, {4, 9, f[9, 2]}} >   I tried:               list /. {a_, b_, c_} :> {a, b, f[b, c]}      But the result comes out as > >     {{1, 3, 5}, {4, 5, 1}, {f[4], f[9], f[2]}} >


How to set up new types for pattern matching strings?

Consider the following toy example: I have a set of language sounds, which I partition into two exclusive subsets, consonants and vowels. I want to set up string patterns for e.g. `StringMatchQ` that may contain restrictions based on the sound specification. For sake of simplicity, I used letters instead of sounds, as for now it does not matter.               (* Define domains *)     vowels = {"a", "e", "i", "o", "u"};     consonants = {"b", "c", "d", "f", "g"};          (* Define predicates *)     VowelQ[x_] := MemberQ[vowels, x];     ConsonantQ[x_] := MemberQ[consonants, x];          (* Use predicates in pattern matcher *)     StringReplace["badge",       Shortest[pre__] ~~ c : __?ConsonantQ ~~ v_?VowelQ ~~ EndOfString :>        pre <> "-[" <> c <> "]-[" <> v <> "]"]      > `"ba-[dg]-[e]"` My question is: **How to set up domains that can be used like e.g.`DigitCharacter` in the pattern matcher**, that is, how to define `Consonant` and `Vowel` in the following (putative) application to yield the same result as the above code?               StringReplace["badge",       Shortest[pre__] ~~ c : Consonant .. ~~ v : Vowel ~~ EndOfString :>        pre <> "-[" <> c <> "]-[" <> v <> "]"]      I can define new data structures, like `Consonant["c"]`, that is displayed as `"c"`, but is nevertheless interpreted as `Consonant["c"]`, though I have the feeling that this is not the way to do it.


Differential geometry add-ons for Mathematica

I need a differential geometry tool for Mathematica. Is there any add-on? Unfortunately, Mathematica does not include such functionality or I can not find it.


How to make an arbitrary number of plots have different labels/colors/etc?

I'm sorry but I'm not sure how to phrase this question well. Frequently I have a function that produces and returns a Plot[] or array of Plot[]'s, which I can then display with Show[], or combine with Plot[]'s from another function and then use Show[]. Normally to tell which curve is which on a graph with many curves, you have a legend. Except here, the function produced an arbitrary number of plots, and also I maybe later want to combine them with other Plot[]'s in Show[], so they all have the same color in the legend. Is there a way to make Show[] give them different colors so I can tell them apart? I can think of some very contrived ways to do this (make some sort of global variable that keeps track of how many plots have been created, and uses this as a counter to change the color to be used for the next plot), but they're very ugly and I imagine there must be a better way in elegant MM. Does anyone know of one? Thank you! Edit: An example of the code:               (*Creates and returns a plot.*)     PlotSomething[freq0_] := (     Plot[Sin[freq0*x], {x,0,3.14}])          (*Call the above plotting function several times, create and return an array of Plots.*)     MakePlotArray[numplots_] := (     plottable = {};For[i = 1, i <= numplots, i++,     AppendTo[plottable, PlotSomething[i]];     ];     Return[plottable];)          (*How can I make these plots have different colors and labels?*)     Show[MakePlotArray[5]]


ParametricNDSolve and ProcessEquations

I have a question regarding NDSolve`ProcessEquations and ParametricNDSolve. When using the regular NDSolve we have the option to divide the integration into the three steps ProcessEquations, Iterate and ProcessSolutions. My question is: When using ParametricNDSolve, is the ProcessEquation stage only done one time (when we create the ParametricFunction) or is it done every time we call the object with new parameter values? /Jacob


Constraining some rows from LeastSquares to lines

For two matrices, `A` and `B`, with dimensions `{n,p}` and `{n,2}` respectively, `LeastSquares[A,B]` returns an matrix, `R`, with dimensions `{p,2}`. But any row of `R` could be anywhere in the real plane. I want to constrain `R[[1]]` and `R[[-1]]` to two different lines. How should this be done? The system is overdetermined, `n>p`


Compile for deployment

Is there any way (other than the manual one) to grab all the functions a notebook uses from the different user-defined packages and putting everything into one file to deploy the code for e.g. CDF? I understand that this involves a recursive search through a possibly large number of package files, and the discovery of heavy interrelations between functions, but it is definitely not impossible to be done (I've done it myself many times by hand), and thus _Mathematica_ should be able to do it. Perhaps Wolfram Workbench?


Avoiding the re-evaluation of a RegionPlot3D

Is there a simple way to save the output from `RegionPlot3D` so as to avoid re-evaluating when the notebook is re-opened and `Show` is used to re-display the plot? The re-evaluation takes in excess of 30 mins of run time.


Convert logical relational expression to / from disjunctive and conjunctive forms?

I would like to convert logical relational expressions in disjunctive form, e.g., $$(x \lt -1) \lor (-1 \lt x \lt +1) \lor (x \gt +1)$$ into conjunctive form, e.g., $$(x \ne -1) \land (x \ne +1)$$ I have some machinery in place that converts a logical relational expressions in disjunctive form into a union of intervals:               ClearAll[mxInterval];                                                                                mxInterval::unrecognized = "The expression `` is not an Inequality, Less, LessEqual, GreaterEqual\      or Greater operator or the logical Or of one or more of the operators.";                                   mxInterval[HoldPattern[Inequality[valueLeft_, ropLeft_, var_, ropRight_, valueRight_]]] :=                 mxInterval[ropLeft, valueLeft, valueRight, ropRight];                                                   mxInterval[(rop:(Less|LessEqual))[var_, value_]] :=                                                        mxInterval[LessEqual, "-\[Infinity]", value, rop];                                                      mxInterval[(rop:(Greater|GreaterEqual))[var_, value_]] :=                                                  mxInterval[rop, value, "\[Infinity]", GreaterEqual];                                                    mxInterval[HoldPattern[Or[x__]]] :=                                                                        Or @@ Replace[HoldComplete[x], elem_ :> mxInterval[elem], {1}];                                         mxInterval[expr_] := (Message[mxInterval::unrecognized, expr]; Return $fail;)                               mxIntervalSymbol[op_, side_] := Switch[                                                                    op,                                                                                Less|Greater, Switch[side, l, "[", r, "]"],                                                            LessEqual|GreaterEqual, Switch[side, l, "(", r, ")"]];                                                  mxInterval /: MakeBoxes[mxInterval[ropLeft : (Less|LessEqual|Greater|GreaterEqual),                                                   valueLeft_, valueRight_,                                                                           ropRight : (Less|LessEqual|Greater|GreaterEqual)], form_] :=            RowBox[{mxIntervalSymbol[ropLeft, l], MakeBoxes[valueLeft, form], ",",                                         MakeBoxes[valueRight, form], mxIntervalSymbol[ropRight, r]}];         Using `mxInterval` on the sample expression produces a disjunction of intervals,               In[]: mxInterval[x < -1 || -1 < x < +1 || x > +1]          Out[]: Or[mxInterval[-\[Infinity],LessEqual,Less,-1],               mxInterval[-1,Less,Less,+1],               mxInterval[+1,Greater,GreaterEqual,\[Infinity]]      which display as: $$(-\infty, -1] \cup [-1,+1] \cup [+1,+\infty)$$ or, as the number line: oops, which is actually of $(-\infty,-1] \cup [+1,+1\infty)$: ![NumberLine](http://imgur.com/QlUqb51.png) ( _Note_ : Maybe I should produce Union instead of Or here. Would that eliminate the needs for a `MakeBoxes` definition for `Or[mxInterval ..]`? The only use for that function is to get the $\cup$ operator instead of $\lor$ in the display). What I would really like is the function `mxInterval[Or[mxInterval ..], And]` which would take the disjunctive form of intervals and produce the conjunctive form. And, of course, `mxInterval[And[mxInterval ..], Or]` that would do the reverse. If I were using a more procedural language, I would sort and then iterate over the intervals constructing the result along the way. However, I feel like the best way to implement the function in Mathematica is to rely heavily on pattern matching, but I'm having trouble formulating a solution using that paradigm. Or, maybe there is a Mathematica incantation that will do the conversion on the original logical relational expression? That would be sweet.


getting Mathematica messages in .NET

For example, equation Sin[10*x]-Log[x]==0 can't be solved by NSolve. Mathematica returns message "NSolve::nsmet". How can I get messages in my c# program?               IKernelLink kl = MathLinkFactory.CreateKernelLink();     kl.WaitAndDiscardAnswer();     kl.ComplexType = typeof(Complex);     kl.Evaluate("x/.NSolve[" + equation + ",x]");     kl.WaitForAnswer();     Complex[] res = (Complex [])kl.GetComplexArray();     //some code     kl.Close();


What does "EquationalLogic`FindCounterexample[]" do?

I found the undocumented `EquationalLogic`FindCounterexample[]` by browsing the lists of available symbols, but I have no clue about its purpose. The name is intriguing! So far I found the following:   * Accepts 2 or 3 arguments    * Returns an `Integer` (1, 10, 15, 31, 100 ...)   * For the first two arguments it seems to need equalities and boolean expressions (I didn't try quantifiers yet). Like in               EquationalLogic`FindCounterexample[r == r + 1  && r == 2, b == 1]        * For the third argument, almost anything is allowed   * The numeric result seems to be connected to some feature of the equation system, but not sure to which one.  For example:               EquationalLogic`FindCounterexample[r == a + 1  , a == 1]     (*     -> 31     *)          EquationalLogic`FindCounterexample[r == a + 1  , r == a]     (*     -> 100     *)      Any suggestions or ideas about how to use this? **Edit** Some additional info, mostly provided by @Rojo:               Names["EquationalLogic`*"] // Column     (*      "EquationalLogic`FindCounterexample"      "EquationalLogic`FindProof"      "EquationalLogic`Prove"      "EquationalLogic`$MaxCounterexampleSearchSize"          "EquationalLogic`$ProverOptions"     *)      All interesting names! Now, look at this:               EquationalLogic`FindProof[y == x, y == 2 && x == 2]     (*     {ProofObject[       InitialLemma[1, 2 == x],       InitialLemma[2, 2 == y],       InitialHypothesis[3, y == x],       OrientRule[4, 2 -> x, Reason[1, Identity, 1]],       ApplyLemma[5, 2 -> x, 2 == y, 0, 1, DeducedLemma[5, x == y, SupportingReason[2, x, x, 4, 0]]],       OrientRule[6, x -> y, Reason[5, Identity, 2]],       ApplyLemma[8, y -> x, y == x, 0, 1, SufficesToShow[8, True, SupportingReason[3, x, x, 6, 1]]],       FinalGoal[9, True, EndReason[8]]       ], True}      However, hold your expectations:               EquationalLogic`FindProof[2 y == 2 x, y == 2 && x == 2]     (*     {ProofObject[], False}     *)      If you run               Trace[EquationalLogic`FindProof[x == 0, x == 0], TraceInternal -> True]      among a lot of non human gibberish, you will find a lot of references to               EquationalLogicDump`skolem____$      And just for your reference, there is the **Skolem normal form**


How to create this four-dimensional cube animation?

This is a tesseract, a four-dimensional cube, which contains two cubes. Here, each side length of the smaller one is 1, while the side length of the bigger one is 2. How do make I it? I am still working on it, and I wish to see different approaches. ![rotating tesseract](http://i.stack.imgur.com/NIxpn.gif)