Is the CompiledFunctionCall WVM opcode efficient?

There is example in Mathematica documentation about `Compile`               cf = Compile[{{x}}, Sin[x]];     cf5 = Compile[ {{x}}, cf[x^2],         CompilationOptions -> {"InlineExternalDefinitions" -> True,           "InlineCompiledFunctions" -> False}];      The above code makes `"InlineCompiledFunctions"` `False`, thus prevents inlining. If we looks at the `CompilePrint` output,               <<CompiledFunctionTools`     CompilePrint[cf5]      will be                       1 argument             3 Real registers             Underflow checking off             Overflow checking off             Integer overflow checking on             RuntimeAttributes -> {}                  R0 = A1             Result = R2          1   R1 = Square[ R0]     2   R2 = CompiledFunctionCall[ Hold[CompiledFunction[{x}, Sin[x], -CompiledCode-]][ R1]]     3   Return      There is a `CompiledFunctionCall` opcode. **I don't know whether this call is as efficient as the "inline" version or not. The documentation didn't say.** I quote a paragraph here which I don't quite understand. > Here the external definition is used, but the compiled function is not > inlined. Instead it uses an efficient instruction to allow one compiled > function to call another. This type of call is important since it could > allow a compiled function to call itself, and when parallel execution is > carried out in the compiler the call can be done without any synchronization > locking. What does it mean? It says "it could allow a compiled function to call itself". But there is a example in the same documentation where the compiled function is a recursive call. For example,               cFact = Compile[{{x, _Integer}}, If[x == 1, 1, x*cFact[x - 1]],        {{_cFact, _Integer}},         CompilationOptions -> {"InlineExternalDefinitions" -> True}];     CompilePrint[cFact]      And what is **"synchronization locking"**?


Maximizing a function with assumptions

Using               f[s_] := Log[(s/r)^α ((α - 2) n0 r^α  + 2 π Pmax ρ r^2)                 /((α - 2) n0 s^α + 2 π Pmax ρ s^2)]/s      When I run the following line:               Assuming[ s > r && r > 1 && Pmax > n0 && n0 > 0 && ρ > 1 && α > 2,      Maximize[f[s],s]]      I get the following output:               Maximize[Log[((s/r)^α (n0 r^α (-2 + α) + 2 π Pmax r^2 ρ))                 /(n0 s^α (-2 + α) + 2 π Pmax s^2 ρ)]/s, s]      Actually, Mathematica ignores the assumptions and outputs the function only. That is, nothing is done by Mathematica. I know that `Assuming[.]` works with `Refine`, `Simplify`, and `Integrate`. But, is there any way to use `Maximize` with assumptions? What do you think about the given function? Is it analytically solvable at all? **EDIT:** Let `g[x]=n0 β + 2 π ρ Pmax x^(-β)`, where `β = α - 2`. We can rewrite `f[s]` as:               f[s_] := Log[g[r]/g[s]]/s      for `β>0`. Therefore, the optimal point is found by maximizing `Log[(g[r]/g[s])^(1/s)]` or equivalently maximizing `(g[r]/g[s])^(1/s)`. Mathematica cannot solve the latter optimization problem as well. Even with some more simplification, `r=1` and `n0=1`, which results in the following problem, it cannot be solved:               Maximize[{((β + 2 π Pmax ρ)/(β + 2 π Pmax s^-β ρ))^(1/s), β > 0, Pmax > 1, ρ > 1}, s]


How to protect pattern or subexpression when distributing / expanding expression?

I've got an expression like               expr = (1-x)(a+b)      that I would like to distribute / expand while keeping factors of `(1-x)` intact, i.e. the result should in the above example should look like               (1-x)a + (1-x)b      I know that for the explicit example given here, `Expand[expr,(a+b)]` would yield the desired result. However, I would need a solution where `(a+b)` can be any arbitrary algebraic expressions that is distributed with `(1-x)` being left untouched. Is there maybe a way to define a pattern that matches my `(1-x)` terms that I can than hold while distributing?


Delete a style type from stylesheet

I have created a new stylesheet but now I'd like to delete a style type, for example "program" from it. How can I do it ?


Efficient circular buffer?

I wish to create an efficient circular buffer. That is, I wish to keep a fixed length list while appending a new value and dropping the oldest, repeatedly. As we know lists in _Mathematica_ are implemented as arrays and `Append` etc. are slow on long lists. For example:               big = Range@1*^7;          Do[big = Append[Rest@big, RandomInteger@99], {100}] // AbsoluteTiming      > {2.2100031, Null} `Internal`Bag` and related functions are appropriate for a continually accumulating list but do not appear to be applicable to this situation. Is there an efficient means to have a large circular buffer in _Mathematica_?


Using a list of tuples in a pure function

I want to use a list of tuples within a function to make assignments. Say I want to make assignments of the form               value[i,j] = val      What I have is a list of tuples that give the relevant indices (i,j):               tuples = {{i[1],j[1]},{i[1],j[2]}, ... , {i[imax],j[jmax]}}      What I have found is that this statement will work in Mathematica 8 :               Function[t, value[t[[1]], t[[2]]] = 0.] /@ tuples      But using slots does somehow not work:               value[#[[1]],#[[2]]] = 0. & /@ tuples      ... gives an error. Where is the mistake I am making or is there no way to do this using slots? (using `Part[#,1]` and `Part[#,2]` will not help either]? Kind regards, Guido


Make Entire Area of New Graphic Editable

Create a new graphic via the menu bar: `Graphics -> New Graphic`. The `FullForm` expression for this graphic is:               Graphics[{}, ContentSelectable -> True, ImageSize -> {480, 360}, PlotRange -> {{0, 4/3}, {0, 1}}]      Using the Drawing Tools palette, the entire area of the newly created graphic is editable: ![fullyeditable](http://i.stack.imgur.com/Nv1iC.png) Suppose now I want to make a new graphic but make it taller; that is, I want a new graphic but with dimension 480 x 800. I can do so with `Graphics[{}, ImageSize -> {480, 800}]` but only a small part of it is editable. ![noteditable](http://i.stack.imgur.com/GWpdf.png) If I add a `PlotRange`, for example, `Graphics[{}, ImageSize -> {480, 800}, PlotRange -> {{0, 1}, {0, 4/3}}]`, the editable area increases. ![noteditable2](http://i.stack.imgur.com/21Eip.png) To make the entire area editable, I can change `PlotRange` to `{{0, 1}, {0, 5/3}}`. ![noteidtable3](http://i.stack.imgur.com/sQmfY.png) If I change `ImageSize`, is there a systematic way to choose `PlotRange` to make the entire area editable? Other approaches are also welcome.


Converting XMLElement objects to plain text

**Short version:** How can I convert an `XMLElement` that represents part of a HTML document to plain text? **Long version:** The more general problem is extracting information from webpages. We can import the webpage as an `XMLObject` and extract the relevant part. But this may still be a complex expression of many nested `XMLElement`s (several paragraphs, links, emphasis, etc.), while I'm typically only interested in the text. Let's take a random example: extracting the text from this article. Using the developer tools of any modern browser it's easy to find out that the relevant part is in a `div` with `id="article-body-blocks"`. So we do               page = Import[        "http://www.guardian.co.uk/science/blog/2012/nov/13/science-enforced-humility",        "XMLObject"];          body = Cases[page,         XMLElement["div", {"id" -> "article-body-blocks"}, ___], Infinity];      The body is still a compound expression. Is there a built-in, direct way to extract the text? My workaround is               ImportString[ExportString[First@body, "XML"], "HTML"]      but this is a hack (i.e. fragile, likely to break in future versions or with an input I didn't anticipate). Is there anything specifically meant for this purpose?


Using free-form linguistic input in a dynamic input field

I've been playing around with dynamic input fields; here's a basic example, which just consists of an input field where the user can enter a function and then a button that can be clicked to graph the function. What I'm wondering is: is there a way to allow free-form linguistic input to be entered in the input field? Right now, I must enter regular Mathematica syntax like Cos[x] to get a graph, but I'd really like to be able to enter something like "cos x". (Ultimately, I'd like my dynamic module to do more than just graph the function, which is why I don't want to just use Wolfram Alpha directly.)               DynamicModule[{graph, f, button},      graph = Plot[1, {x, 0, 1}, PlotRange -> {0, 0.1}, Axes -> False,         ImageSize -> 480, Background -> White];      f = Cos[x];           button = Button["Graph!",        graph = Plot[f, {x, -3, 3}, ImageSize -> 480, Background -> White];        ];           Panel[       Grid[{         {InputField[Dynamic[f]], button},         {Dynamic[graph], SpanFromLeft}},        Spacings -> {2, 1}, Alignment -> {Left, Baseline}        ]       ]      ]      Thanks!


An elegant way to plot a numeric function that returns a list, and have each element in a different color

I have a function that takes a numeric argument and returns a list of numbers. I want to plot each element of the list in a different color. If I use this command,               Plot[f[x],{x,-1,1}]      all the elements are plotted in the same color. The function takes only a numeric argument (its definition is `f[x_?NumericQ]:=...`) so I can't use `Evaluate` like in this question. So far I've been using this command:               Plot[{f[x][[1]],f[x][[2]],f[x][[3]],f[x][[4]]},{x,-1,1}]      Which works fine (since the function evaluates very fast, I don't mind there are redundant evaluations here, see this question). However this is not very elegant, and considering I have 16 elements to plot, it gets downright ugly. **Is there a more elegant way to plot each element in a different color?**


How can I create a colour image using raw black and white data? (FITS data cube)

I have a data cube containing pictures of a galaxy across a thousand wavelengths. I want to take the data for the image slides in the red and blue parts of the spectrum, and have them represented in the appropriate colours. If I could then superimpose the images somehow to show the red and blue regions of the galaxy together that would be fantastic. Currently I have been working with the raw data for each slide and the pixel magnitudes. To plot the galaxy at any given wavelength I've just being using a list density plot. I don't know how to map the range of images with a gradual colour change or how to combine them?


Exporting lists with two extensions to files

Continuation of this question: How to export if I need to have two extensions instead of one. E.g., in the previous case one can generate lists labeled L[1], L[2],.....and so on using a loop. But if I have 2 loops and hence two variables and the lists are labeled L[1,1], L[1,2],… then L[2,1], L[2,2],… How do I export them in wdx format?


Plotting two vectors on the unit circle

I would like to plot a vector on the unit circle, depending on an angle `Pi/k`, and the same vector rotated by an angle `d`. I try the following:               k = 0.9; d = 0.3;     pt = {Sin[Pi/k], Cos[Pi/k]};     pt2 = {pt[[1]]*Cos[d] + pt[[2]]*Sin[d],      pt[[2]]*Cos[d] - pt[[1]]*Sin[d]};          Graphics[Arrow[{{0, 0}, pt, {0, 0}, pt2}], Axes -> True,      AxesLabel -> {x, z}, PlotRange -> {{-1.1, 1.1}, {-1.1, 1.1}}]      In some cases, like when `k=0.9` and `d=0.3` as above, this almost works, except that the first vector has no arrowhead, only a line (see figure). In other cases, as when `k=1`, Only the second vector is drawn. Can anyone see what the problem is? ![The plotted vectors](http://i.stack.imgur.com/qLPxE.png)


ParallelTable 70 times slower on 16 cores than Table on single core

Consider these code(sorry it's messy), why the `ParallelTable` version is 70 times slower than the `Table` version?               Quit[]     Clear["`*"]       $Version       (*     ==> "8.0 for Linux x86 (64-bit) (February 23, 2011)"     *)        Kernels[]       (*     ==> {}     *)        a = RandomReal[{0., 1.}, {401, 300000}];         b = RandomReal[{0., 1.}, {401, 300000}];       Developer`PackedArrayQ /@ {a, b}      (*     ==> {True, True}     *)          ht = 2*0.375*^-9;         DFT[A_, ht_] :=        RotateRight[        ht/Sqrt[2 \[Pi]]*         Fourier[RotateLeft[A, Length[A]/2 - 1],           FourierParameters -> {1, 1}], Length[A]/2 - 1];          SmoothDFT[A_, ht_, n_] :=        DFT[Table[0., {(n - 1)*Length[A]/2}]~Join~A~Join~         Table[0., {(n - 1)*Length[A]/2}], ht];          SelectbyWRange[A_, {WMin_, WMax_}, {TakeWMin_, TakeWMax_}] :=       Module[{lthA, nMax, nMin}, lthA = Length[A];       nMin = Round[-((-WMax + lthA WMin)/(           WMax - WMin)) - ((1 - lthA) TakeWMin)/(WMax - WMin)];       nMax = Round[-((-WMax + lthA WMin)/(           WMax - WMin)) - ((1 - lthA) TakeWMax)/(WMax - WMin)];       Transpose[{Table[          TakeWMin + n *(TakeWMax - TakeWMin)/(nMax - nMin), {n, 0,            nMax - nMin}], Take[A, {nMin, nMax}]}]       ]          Smtx1 =         Table[SelectbyWRange[-Im[            SmoothDFT[a[[n]], ht, 2]*             Conjugate[SmoothDFT[b[[n]], ht, 2]]], {-834., 834.}, {19.5,            20.5}], {n, 1, 2}]; // AbsoluteTiming          (*     ==> {0.404922, Null}     *)       Kernels[]       (*     ==> {}     *)     LaunchKernels[]         (*     ==> {KernelObject[1, "local"], KernelObject[2, "local"],       KernelObject[3, "local"], KernelObject[4, "local"],       KernelObject[5, "local"], KernelObject[6, "local"],       KernelObject[7, "local"], KernelObject[8, "local"],       KernelObject[9, "local"], KernelObject[10, "local"],       KernelObject[11, "local"], KernelObject[12, "local"],       KernelObject[13, "local"], KernelObject[14, "local"],       KernelObject[15, "local"], KernelObject[16, "local"]}     *)        Smtx2 =         ParallelTable[         SelectbyWRange[-Im[            SmoothDFT[a[[n]], ht, 2]*             Conjugate[SmoothDFT[b[[n]], ht, 2]]], {-834., 834.}, {19.5,            20.5}], {n, 1, 2}]; // AbsoluteTiming          (*     ==> {25.459674, Null}     *)      Note that I have 16 cores on the node and the table have only 2 elements, i.e. `{n,1,2}`, even if I change to `{n,1,16}`, the `ParallelTable` version is still 10 times slower than the Table version. If it is the overhead, why it has a such huge overhead? Thanks. These are the screenshots: ![enter image description here](http://i.stack.imgur.com/uuv3A.png) ![enter image description here](http://i.stack.imgur.com/AUNYk.png) **Update** 1.As OleksandrR point out that there is no `DistributeDefinitions`, but in the documentation of `ParallelTable` it promises to automatically distribute the calculations (version 9): > ParallelTable is a parallel version of Table which automatically distributes > different evaluations of expr among different kernels and processors. > > The default value is `DistributedContexts:>$DistributedContexts` with > `$DistributedContexts:=$Context`, which distributes definitions of all > symbols in the current context, but does not distribute definitions of > symbols from packages. 2.OleksandrR also gave an excellent analysis in this post, pointing out that the performance problem is the `MemberQ` function. Indeed if we turn on the unpack warning, we can see it unpacks the array in call to MemberQ               On["Packing"];     Smtx2 = AbsoluteTiming[ParallelTable[         SelectbyWRange[-Im[SmoothDFT[a[[n]], ht, 2]*             Conjugate[SmoothDFT[b[[n]], ht, 2]]], {-834., 834.}, {19.5, 20.5}], {n, 1, 2}];]      > Developer`FromPackedArray::unpack: Unpacking array in call to MemberQ. >>               (*{25.557433, Null}*)      However a second evaluation is much faster even the array still unpacks               ClearSystemCache[]     Smtx2 = AbsoluteTiming[ParallelTable[         SelectbyWRange[-Im[SmoothDFT[a[[n]], ht, 2]*             Conjugate[SmoothDFT[b[[n]], ht, 2]]], {-834., 834.}, {19.5, 20.5}], {n, 1, 2}];]      > Developer`FromPackedArray::unpack: Unpacking array in call to MemberQ. >>               (*{0.156995, Null}*)      If we use the temporary fix of `MemberQ` proposed by Szabolcs in the same post, then the unpack warning is gone, but the evaluation is still slow.               Quit[]     On["Packing"];          (*need to reevaluate all the definition code above*)          memberQ[list_, form_] := Or @@ (MatchQ[#, form] & /@ list)     ClearAll[fix]     SetAttributes[fix, HoldAll]     fix[expr_] := Block[{MemberQ = memberQ}, expr]          Smtx2 = fix@       AbsoluteTiming[ParallelTable[SelectbyWRange[-Im[             SmoothDFT[a[[n]], ht, 2]*              Conjugate[SmoothDFT[b[[n]], ht, 2]]], {-834., 834.}, {19.5,             20.5}], {n, 1, 2}];]     (*{25.192359,Null}*)      So how to fix this?


Dealing with errors and resuming the code after one

How can I write my _Mathematica_ code so that it resumes at a specific place if any `Message` is displayed during the execution of an expression? For example, in Visual Basic for Applications there's `on error resume next`, or `on error goto`. I'd like also to be able to log the issue in a list so I can reproduce and correct the problem later.


Basic Row Traversal Question

Right now I'm using this `For` loop to do an operation to each row of a $n \times n$ matrix, I was trying to figure out how to do this with `Map` or `Take` or something like that.               evecs = RandomReal[1, {5, 5}]     For[{i, 1, Length@evecs}, i++, evecs[[i, All]] = evecs[[i, All]]/Norm[evecs[[i, All]]]];


Evaluating derivatives for use in solve

I need to evaluate the derivative of a function. My function looks like               approx[vector_, x_] :=  Sum[vector[[n]]*Basis[n - 1, x], {n, 1, Length[vector]}]      and I'm defining my derivative like:               ddappx[vector_, x_] := D[approx[vector, x], {x, 2}]       However if I evaluate it at a specific x I get an error:               General::ivar: 1 is not a valid variable. >>      I searched enough to know that a solution when plotting this is to evaluate it first. Something about HoldAll and so on. What I need to do is use it in a set of simultaneous equations. So I should be able to have:               Solve[{ddappx[{a,b}, 1]==0,ddappx[{a,b}, -1]==0},{a,b}]      To solve for {a,b} by setting the 2nd derivative of approx ==0 at x=1 and x=-1. However I get the               General::ivar: 1 is not a valid variable. >>      Errors again. Evaluating like                Solve[{Evaluate[ddappx[{a,b}, 1]]==0,Evaluate[ddappx[{a,b}, -1]]==0},{a,b}]      isn't working. so, any ideas? cheers EDIT: Having made the suggested change, that error is solved. However although evaluating approx works perfectly well, evaluating ddappx gives 0, no matter what I do. there is no error, just 0. I've added the whole code which goes in front just in case you think its relevant               diffeq[y_, x_] := y''[x] + y[x]     f[x_] := Cos[2*x]     Basis[n_, x_] := ChebyshevT[n, x]     approx[vector_, x_] := Sum[vector[[n]]*Basis[n - 1, x], {n, 1, Length[vector]}]          ddappx[vector_, x_] := Derivative[0, 2][approx][vector, x]      ....               approx[{0, 0, 1, 1}, x]      returns correctly:               -1 - 3 x + 2 x^2 + 4 x^3                     ddappx[{0, 0, 1, 1, 1}, x]      returns incorrectly:               0


Differential Equation power spectra

ε = .1; A = 0; ω0 = 1; ωf = 0;      data =        NDSolve[         {x''[t] == ε (1 - x[t]^2) x'[t] - ω0^2*x[t] + A*Cos[ωf*t], x[0] == 1, x'[0] == 0},          {t, 0, 100}];     Periodogram[data, ScalingFunctions -> "Absolute", PlotRange -> All]      How would I create a suitable Power spectrum of the frequencies that this system has. For these set of values (at the top), there should ideally be only one unique frequency (ω0) since the other one is not in play. Mathematica's example of power spectra utilizes the periodogram funcition, although I don't really understand what it does mathematically, so there is room for using another type of graph.


Using transformation rules to manipulate expressions

I'm trying out Mathematica as a replacement for LaTeX for typesetting math. It works very well, but I would like to take advantage of Mathematica's computer algebra capabilities as well. Specifically, instead of manually figuring out and typing the result of a transformation to an expression, I would like Mathematica to do it. For example, suppose I am trying to prove that associativity of multiplication holds in the complex numbers. The first step might be the following:               (a+bi)((c+di)(e+fi)) = (a+bi)(ce + cfi + edi - df)      How can I automate this using transformation rules? I can do the following:               In:  (a+bi)((c+di)(e+fi)) /. x_*(y_*z_)->x+y+z     Out: a + bi + c + di + e + fi      which works as expected, so the pattern is matching properly (I've tried various other simple transformations as well). However, the following does not work as expected:               In:  (a+bi)((c+di)(e+fi)) /. x_*(y_*z_)->x*(Expand[y*z])     Out: (a+bi)(c+di)(e+fi)      What am I missing? Am I even on the right track, or is there a better way to accomplish this?


How to read data from IBM 32-bit floating point binary file ? (not the common IEEE !!!)

I am trying to read a binary file. This file records seismic data. Basically its first 3600 bytes are for the general file information, following are for seismic traces, each begins with 240 bytes for information about this trace. For the file I am reading, it has 3617 traces, each trace has 6240 bytes, with the first 240 bytes for trace headers. Following the trace headers are some velocity values for underground formation, it has 1500 data points. I can view this data using some commercial software, the values should be around 4999.99 feet/s(velocity of sea water) to 14800 feet/s. But what I read range from 590.125 to 743.25, which is obviously not correct. Later I found out that the binary file I am trying to read is IBM binary file. If I read it as IEEE binary file, for integer data, it is all right, but for floating point data, what I read is totally wrong. The trace head I read is about the geographic location of trace, and it is correctly read by mathematica, which is {0, 20, 40, 60, ..., 72320} feet. I don't need to read all the trace headers. What I care most is to read the correct velocity values. Could someone help me? Thanks a lot! (* The following code do not work right away, you need to download and unzip the file first and replace the file string path, the file name is timodel_vp.segy.gz, it is about 22 Megabytes after unzip and absolutely free to download. The address is: http://software.seg.org/datasets/2D/Hess_VTI/ Sorry for the inconvenience! *)               nByteFile =        FileByteCount[        "e:/SeismicDataset/HessVTI/VelocityModelFiles/timodel_c11.segy"];          nByteTrace = (nByteFile - 3600)/3617;          nTraceSample = (nByteTrace - 240)/4;               str = OpenRead[        "e:/SeismicDataset/HessVTI/VelocityModelFiles/timodel_vp.segy",         BinaryFormat -> True];     pos = Range[3600, nByteFile - 1, nByteTrace];          traces = {SetStreamPosition[str, # + 76];        BinaryRead[str, "Integer32", ByteOrdering -> +1],        SetStreamPosition[str, # + 240];        Table[BinaryRead[str, "Real32",          ByteOrdering -> +1], {nTraceSample}]} & /@ pos;


Exploiting a relation among constants

Say I have two arbitrary real constants $p,q$ that satisfy $p^2+q^2=1$. Is there any way to easily declare this relation in _Mathematica_? **Edit** More specifically I have this (among others) expression: $$\frac{\sqrt{\frac{p^4 q^4(p^2-q^2)^2}{p^4 + q^4}}}{\sqrt{p^{10}+p^2q^8+p^8(-2+q^2)+2p^4q^4(-2+q^2)+q^6(-1+q^2)^2+p^6(1+2q^4)}}$$               Divide[Sqrt[Divide[p^4 q^4 (p^2 - q^2)^2, p^4 + q^4]],       Sqrt[p^{10} + p^2 q^8 + p^8 (-2 + q^2) + 2 p^4 q^4 (-2 + q^2) +         q^6 (-1 + q^2)^2 + p^6 (1 + 2 q^4)]]      and am asking whether there is a way to have _Mathematica_ reduce it using the relation $\;q^2+p^2=1$.


Integrate function without specifying limits of integration

I've been having trouble to make mathematica evaluate an integral without specifying the values of the limits of integration. I mean, if I write               Integrate[x,{x,x1,x2}]      Mathematica returns the correct answer: $\frac{(x2)^2-(x1)^2}{2}$. But If I write something like               Integrate[x^2/(1-x),{x,x1,x2}]      Mathematica just keeps the evaluation forever... Is there something that I can do to avoid this behaviour?


Strange behavior of BinCounts

Just try this example:               lst = {0, 1, 1, Sqrt[2], Sqrt[5], 2 Sqrt[2], 2, Sqrt[13], Sqrt[5], Sqrt[6], Sqrt[11],             Sqrt[14], Sqrt[11], Sqrt[10], 3 Sqrt[2], Sqrt[17], Sqrt[13], 2 Sqrt[5], Sqrt[29],             2 Sqrt[2]};          ex1 = BinCounts[lst, {Range[0, 18]}]     ex2 = BinCounts[lst, {Range[0, 19]}]     ex3 = BinCounts[N@lst, {Range[0, 18]}]      > >     {1, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} >     {1, 3, 6, 6, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} >     {1, 3, 6, 6, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} >   Seems that `BinCounts` failed to notice the irrational numbers in `ex1`:               Select[lst, IntegerQ]      > >     (* This result is consistent with ex1. *) >     {0, 1, 1, 2} >   Is it a bug? I'm using _Mathematica 8.0.4, Windows Vista 32bit_.


What pattern will match accented letters in a regular expression?

How should I modify the following such that the accented letter `É` is matched and the expression returns `True`?               StringMatchQ["Éta", RegularExpression["[a-zA-Z]+"]]


The shortcut for Subsuperscript doesn't work?

The document for Subsuperscript says that: > To enter a subsuperscript in a notebook, use either `Ctrl`+`_` to begin a > regular subscript or `Ctrl`+`^` to begin a regular superscript. After typing > the first script, use `Ctrl`+`%` to move to the opposite script position. > `Ctrl`+`Space` moves out of the subscript or superscript position. This just create a expresion that **looks like** a symbol with subsuperscript! Specifically, I typed `Ctrl`+`-` / `Ctrl`+`6` and a regular subscript / superscript appeared, `Ctrl`+`5` and the opposite script appeared, and after I moved the cursor out of the symbol by pressing `→` and checked its `InputForm`, what I saw is **not** something like               Subsuperscript[a, x, y]      but               Subscript[a, x]^y      _Snapshot:_ ![Mathematica graphics](http://i.stack.imgur.com/O8Nyb.png) What's wrong with it, I misunderstood the document? I use _Mathematica 8.0.4_ and _Windows Vista Home Basic 32bit_.


Optimizing the fitting of Ordinary Differential Equation(NDsolve) involving interpolation functions

I am a newbie to this forum. I am trying to use NDsolve to solve some ODEs involving the interpolation function. Then, I will compare the fitted curve and data to determine the ODE coefficients. Basically, I measure the Voltage(V) and Current(I) for a circuit. Then I want to use these V and I to determine the value of electric components in the circuit. First, I make a interpolation function out of the waveform V data:               dataIndex = Range[2, 10001];     myVoltData = Transpose[{rawData[[dataIndex, 1]], rawData[[dataIndex, 4]]}];     myCurrData = Transpose[{rawData[[dataIndex, 1]], rawData[[dataIndex, 2]]}];     voltageFunc = Interpolation[myVoltData, InterpolationOrder -> 2];      Second, use `NDSolve` to solve the ODE, then use the solution to calculate the chi-sq. In the following code, the ODE parameters to be fit are `r0Fit, r1Fit, c1Fit, currOffset`, and the function `fitFunc` will eventually return the chi- sq:               fitFunc[r0Fit_?NumberQ, r1Fit_?NumberQ, c1Fit_?NumberQ, currOffsetFit_?NumberQ] :=       Block[ {sol, curr00, curr11},       sol = NDSolve[ {voltageFunc[t] == curr00[t]*r0Fit + curr11[t]*r1Fit ,               curr00[t] == (curr11[t] + r1Fit*c1Fit/10^6*curr11'[t]),               curr00[t0fit] == curr11[t0fit] == (voltageFunc[t0fit])/(r0Fit + r1Fit)},              {curr00, curr11}, {t, t0fit, t1fit}, AccuracyGoal -> 7][[1]];         Apply[Plus,      ((myCurrData[[fitDataRange, 2]] + 50*currOffsetFit/10^6      - 50*Flatten[curr00[t] /. sol /.t -> myCurrData[[fitDataRange, 1]]])     /myCurrDataErr[[fitDataRange, 2]])^2/dataPnts]          ]      Finally, use `NMinimize` find the fitting result with chi-sq minimum:               Timing[fitResult = NMinimize[ {fitFunc[r0f, r1f, c1f,  iOffset],      130 < r0f < 170, 3000 < r1f < 3200, 650 < c1f < 750, 60 < iOffset < 100},       {r0f, r1f, c1f,  iOffset},AccuracyGoal -> 0, Method -> "DifferentialEvolution"]]       My first problem is, since `voltageFunc[t]` is the interpolation function from data, it severely procrastinates the `NDSolve` command, as a result, the `NMinimize` is consuming vast amount of time(>20 mins). I wonder, why does interpolation function of ODE delay `NDSolve` so much? Is there any optimization method to make the `NMinimize` and `NDSolve` faster? Secondly, `NMinimize` occasionally fails to find the global minimum. Any suggestions to improve the fitting result's reliability. Any suggestion is appreciated. Thank you all.


How to color lines in Epilog

I often use Epilog to label lines within graphs, and I like to coordinate the color of the labels with the color of the lines they're labeling. This is no problem. However, I'm currently working on a project in which I need vertical connecting lines at selected places, and these should color match as well. For the life of me, I can't figure out how to do this.               Plot[{Sin[x], Sin[x + 0.5]}, {x, 0, 2*Pi}, PlotStyle -> {Blue, Red},       Epilog -> {        Line[{{2, 0}, {2, Sin[2]}}],        Line[{{3, 0}, {3, Sin[3.5]}}]}]      ![enter image description here](http://i.stack.imgur.com/U0XFe.png) Any help would be appreciated.


Exponential function Integral

I have tried to solve this integral:               Integrate[E^(-((a^2 b c^2)/(a^2 + b)))/(a^2 + b)^2,a]      Mathemathica is not able to solve it, I have tried the integration by parts and it did not work, as well as some substitutions. Any idea how to tackle this problem?


Getting message DSolve::conarg:

I want to solve a simple linear PDE about $p_0$ which is a function of ξ, ζ and τ. However, the boundary condition is defined at `ζ = h`, which is a function of ξ and τ. The other quantities are all constant. In fact, this PDE can be solved by hand. I want to find p0 as a function of `h` and ζ. I just want to verify it, then I will try another more complex one. ![enter image description here](http://i.stack.imgur.com/GYHRo.jpg) The solution I want is as follows which is obtained by hand. ![enter image description here](http://i.stack.imgur.com/Aw0ft.jpg) I tried the following code, but it does not work.               DSolve[      {D[Subscript[p, 0][          h[ξ, τ], ζ], ζ] == (R/            Pr)*(1 - ζ*(h[ξ, τ] + k)^-1) - G, (2/3)*         Subscript[p, 0][h[ξ, τ], h[ξ, τ]] ==         e^2* d^(-1)*((h[ξ, τ] + k)^-1)^2 -          2*s*D[h[ξ, τ], {ξ, 2}]       },      Subscript[p, 0][       h[ξ, τ], ζ], {h[ξ, τ], ζ}      ]      I get the message > DSolve::conarg: The arguments should be ordered consistently. >>


Minimize amount of evaluations with fold/table/thread or something else

I can't figure out how to use fold/table/map/distribute or whatever to get this:               {f[f[{},a],a],f[f[{},a],b],f[f[{},a],c],f[f[{},a],d],f[f[{},a],e],     f[f[{},b],a],f[f[{},b],b],f[f[{},b],c],f[f[{},b],d],f[f[{},b],e],     f[f[{},c],a],f[f[{},c],b],f[f[{},c],c],f[f[{},c],d],f[f[{},c],e],     f[f[{},d],a],f[f[{},d],b],f[f[{},d],c],f[f[{},d],d],f[f[{},d],e],     f[f[{},e],a],f[f[{},e],b],f[f[{},e],c],f[f[{},e],d],f[f[{},e],e]}      That is I need to evalute f[{},n] n=a,...,e. For each result I need do the same again and again. So total evaluations for i iterations should be:               Sum[Power[5,n],{n,i}]


Butterworthfilter data filter

I am currently doing a signal analysis and filtering using Matlab. The filter I am using is Butterworthfilter model to filter scattered data (vector data). I am using Matlab as follows:               function [y]=fButterworthfilter(input_data,f_cut)     rng default;     [b,a] = butter(8,f_cut/(200/2));     y=filtfilt(b,a,input_data); % zero-phase filtering      I want to see how can I do the Butterworthfilter filtering using Mathematica. I tried ButterworthFilterModel in the help but the input is a function not a vector data. Let us say I have the following noisy data:               data1 = Table[Exp[-i^2], {i, -5, 5, .01}];     noise = RandomReal /@ RandomReal[{-0.3, 1}, Length[data]];     data2 = data1+noise;      How can I do Butterworthfilter filtering for this data? Thanks


CUDALink ran out of available memory

I have a problem with automatic GPU memory management when using CUDA. The situation is the following: I create a simple CUDA function that operates on a 2D array (image), which does not take much memory space. This 2D array is passed as input then modified and output again. The function is loaded into mathematica using `CUDAFuncitonLoad` (pseudocode):               CUDATestFunction = CUDAFunctionLoad[...,{"Float", 2, "InputOutput"},{16,16}];      The function compiles fine and works. Then I create some sort of loop that involves calling the CUDA-function mentioned before, assigning the output to a new variable and then doing the whole thing again till some number of iterations is reached (again only pseudocode):               Array2Dold = imageData; (*assign raw image data*)     For[i=1,i<maxiter,i++,         Array2Dnew = CUDATestFunction[Array2Dold];         Array2Dold = Array2Dnew;        ]      The problem I have now is that when the number of iterations gets high I am running out of GPU memory and I get the error-message:"CUDAFunction::outmem: CUDALink ran out of available memory, possibly due to not freeing memory using the memory manager". **Does anybody know why that happens?** My guess is that mathematica for some reason keeps the `Array2Dold` or some modified version of it after calculation in CUDA in GPU memory and does not free the memory when the CUDA-funtion (CUDATestFunction) is finished. I know that there is a CUDALink Memory Manager, but from what I read in the mathematica documentation mathematica should at least be able to handle the above situation automatically in a way that does not lead to a memory overflow. Real Code for the actual problem with some modification to simplify the input (which does not change the occurring problem):               (*data initialization*)     imageData = Table[RandomReal[], {i, 200}, {j, 300}]; (*this would usually be some GrayScale ImageData*)     f = Table[RandomReal[], {i, 200}, {j, 300}]; (*this would be some function evaluated on the imageData*)     maxiter = 10000;     testImageData = Table[{RandomReal[], RandomReal[]}, {i, 200}, {j, 300}]; (*would be the gradient of the imageData*)          (*the for loop that leads to the memory overflow*)     For[i = 1, i < maxiter, i++,      test = First@CUDATestFunction[testImageData, 0.1, f, imageGradientNormalized, 1, Sequence @@ Dimensions[imageData]];      testImageData = test;      ]          (*CUDACode*)     CUDATestFunction = CUDAFunctionLoad["       __device__ float length(const float2& a)       {         return sqrtf(a.x*a.x+a.y*a.y);       }       __device__ float2 operator+(const float2& a, const float2& b)       {         return make_float2(a.x + b.x, a.y + b.y);       }       __device__ float2 operator-(const float2& a, const float2& b)       {         return make_float2(a.x - b.x, a.y - b.y);       }       __device__ float2 operator*(const float& a, const float2& b)       {         return make_float2(a * b.x, a * b.y);       }       __device__ float2 operator/(const float2& a, const float& b)       {         return make_float2(a.x / b, a.y / b);       }       __global__ void resolvFs(float* p, float sigma, float* f, float* imageGradientNormalized, float lambda1, mint width, mint height)       {         int xIndex = threadIdx.x + blockIdx.x * blockDim.x;           int yIndex = threadIdx.y + blockIdx.y * blockDim.y;           int index = 2*(xIndex + yIndex * width);         if(xIndex < width && yIndex < height)         {             float2 vecP = make_float2(p[index], p[index+1]);             float2 vecN = make_float2(imageGradientNormalized[index], imageGradientNormalized[index+1]);                  vecP = vecP + 2 * sqrtf(lambda1) * vecN;             vecP = vecP/fmaxf(1, length(vecP)/(2*sqrtf(f[index/2]+lambda1)));             vecP = vecP - 2 * sqrtf(lambda1) * vecN;                  p[index] = vecP.x;             p[index+1] = vecP.y;         }       }", "resolvFs", {{"Float", 3, "InputOutput"},         "Float", {"Float", 2, "Input"}, {"Float", 3, "Input"},         "Float", _Integer, _Integer}, {16, 16}]


How to visualise an iterative approximation to pi

I'm experimenting with different algorithms that approximate pi via iteration and comparing the result to pi. I want to both visualise and perhaps know the function (if any) that describes the increasing trend in accuracy as the number of iterations rises. For example, 1 iteration might give me 3.0, 10 iterations might give me 3.12, 50 iterations might give me 3.1409 etc. The more iterations, the better. Sometimes it might be a case of diminishing returns, running 1000 iterations to get an additional decimal point of correctness - is it worth it? Knowing the sweet spot at which to quit would be nice to know, for each pi approximation algorithm type. I'm a mature programmer who is rekindling an interest in math, and this project idea interests me. Trouble is, I don't know what the correct math and statistical terminology is to describe what I want to do. Could someone please locate my problem within the history of math and possibly illustrate with mathematica? **UPDATE** : To be more specific. My pi generation algorithm produces the following pairs of numbers, where the first number is the number of iterations it looped and the second number is the abs(result - pi) i.e. how much the result differs from pi. The more iterations, the smaller the second number.               data = {{10, 0.19809}, {50, 0.039984}, {100, 0.019998}, {500,      0.00399998}, {1000, 0.002}, {20000, 0.0001}, {100000,      0.00002}, {500000, 4.*10^-6}}      I want to visualize what is going on with the data and find a function that describes what is going on. I'd like to also know what is possible in this area with this sort of data. What I've tried:               ListPlot[data, Joined -> True]      gives me an an almost unreadable graph due to the small numbers involved.               GeneralizedLinearModelFit[data,{x},{x}]      gives me FittedModel[0.0405405 -<<22>> x] which when plotted Show[ListPlot[data,PlotStyle->Red],Plot[%36[x],{x,10,500000}]] gives me a straight line. Not helpful as it doesn't seem to tell me anything about the trend re gradually converging on pi. I think there would be a curve of some sort that would better fit the data, but functions like FindFit seem to require you supply an expression e.g. Log and various parameters a, b etc - but how do I know what expression and what parameters to supply? Should I be looking at Interpolation instead? **UPDATE 2** : Thanks for the answers so far. What's holding me back from accepting an answer is the fact that I'm expecting a curved graph - not a straight line. Because the whole point of more and more iterations is that it gets closer to pi and so the answer must be a curve. And that curve must have a formulae, which it would be nice to have defined. So I did some experimenting in mathematica and came up with a curve after all. Here's how I did it. My data came from a crude Wells / Gregory / Leibniz algorithm (see Gregory Series) where I get pi by alternately adding and subtracting 1/n where n is 3, 5, 7... for example               N[(1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + 1/13 - 1/15 + 1/17) * 4]      which gives me 3.25237 - not bad for 8 numbers in the series, or 8 iterations if its a program that's generating the result. So I went on to define a Mathematica function that takes the number of iterations you want and generates pi. The following function also happens to subtract from real pi and return the discrepancy difference. The higher the iterations _it__ passed to this function, the smaller the difference from pi and the smaller the result coming out of this function:               f[it_]:=Abs[N[Sum[(-1)^(n-1)/(2n-1),{n,it}]]*4-\[Pi]]      So my original data points were for 10, 50, 100, 1000, 20000 and 100000 iterations. I thought those would be representative. Thus I can now generate my original data in Mathematica with               data = {{10,f[10]},{50,f[50]},{100,f[100]},{500,f[500]},{1000,f[1000]},{20000,f[20000]},{100000,f[100000]}}     output: {{10,0.099753},{50,0.019998},{100,0.00999975},{500,0.002},{1000,0.001},{20000,0.00005},{100000,0.00001}}      then plot it using the recommended techniques offered as comments and answers on this page               ListLogLogPlot[data,Joined->True,GridLines->Automatic,PlotStyle->Thick]      and I of course get a straight line like everybody else. Hmmm - remember I am after a curve. My instinct tells me it should be a curve. So then I discover that if I generate a more gradual list of points like this:               data = Table[f[x],{x,20}]     ListPlot[data]      then I finally get my curve. ![curved graph](http://i.imgur.com/XkKxiHF.png) Yey! It looks exactly like I imagined it would - curving gradually towards perfection. And if I change the iterations from 20 to 1000 or any higher number, I get the same curve, only smoother. So this is the function I want a precise definition of. Interestingly, if I use the ListLogLogPlot everybody is recommending on my more gradually spaced data               ListLogLogPlot[data, Joined -> True, GridLines -> Automatic, PlotStyle -> Thick]      I get a straight line again! Grrr. ![straight line again](http://i.imgur.com/5tPbiig.png) What I suspect is going on here is that there _was_ probably a curve in the normal ListPlot of my original data but we couldn't see it due to the scaling, which is why we went for the ListLogLogPlot. But that probably turns curves into straight lines (hence the log in the name?) - which disappointed me because I was expecting a visual curve. And I don't think my original choice of x values (representing the number of iterations being fed into my pi calculation function) and how those x values are spaced makes a difference. My x values of 10, 50, 100, 1000, 20000 and 100000 certainly made it hard to see the curve in the graph, but the curve was still probably there. My second, gentler set of x data points (from the same pi generation function) of 1..20 makes the curve ridiculously easy to see. So what counts as an answer to this question?   * An exact definition of the curve being seen here.    * And perhaps some commentary on what functions describing curves typically arise when attempting to visualise pi using iterative techniques. I hope I haven't changed the goal posts in this question. I think I have always asked for an exact definition of the curve in my data plus some commentary of what might be typical / best practice in this sort of visualisation/graphing territory, where there is a known value we are iterating towards.


FindMaximum inconsistency

The code below seems to work for n<11\. But for n=11, and above, it outputs `newa` then just outputs "beep" sound. WhyTheBeep says "The kernel Local has quit (exited) during the course of an evaluation.". On two separate occasions, (after making trivial changes) it gave the correct output for n=11. I then increasing n and it failed again. After setting n=11 again, it it failed to output and gave the "beep" sound again. Nothing was altered other than n between success and failure in this instance. Why the inconsistency/problem with n>10? (I'm using Mathematica 8.0 on Windows7) Any help would be much appreciated.               n = 10     c = 1.     e = 5.          newa = Table[(2 - i) Subscript[p, m] + (i - 1)/n, {m, 2 n + 2}, {i, 2}]          FindMaximum[     {((Subscript[p, 2 n + 2] - c (1 - Subscript[p, 2 n + 1]))/(Subscript[p, 2 n + 1])),     Subscript[p, 2 n + 2] == Sum[((n + 1) - m) Subscript[p, m] Subscript[p, n + m], {m, 1, n}],     Subscript[p, 2 n + 1] == Sum[Subscript[p, m] Subscript[p, m + n], {m, 1, n}],     Table[Subscript[p,m] == (Subscript[p,2 n + 1] (1 - Subscript[p, m + n]))/(((e*n)/(1 +   e)) Subscript[p, n + m] - (1 - Subscript[p, n + m])^2), {m, n}],     Table[Subscript[p, m] >= 0, {m, 2 n}],     Table[Subscript[p, m] <= 1, {m, 2 n}],     Sum[Subscript[p, m], {m, 1, n}] == 1     }, newa, MaxIterations -> 10000]


Path construction using `Nearest` shows ill behavior?

I have a `dataSet` that I'm trying to sort choosing a starting point and going to its nearest neighbor, and then to its nearest neighbor and so on. To do so, I've written the following code (wich im sure is not optimal)               ordDataSet = NestList[With[{elem = Nearest[#[[1]], #[[2]]][[1]]},          {Select[#[[1]], (# != elem &)], elem}] &,          {Delete[dataSet, {startIdx}], dataSet[[startIdx]]}, 300][[All,2]];      What the code does is given the starting point `dataSet[[startIdx]]` and the list `Delete[dataSet,{startIdx}]`, uses `Nearest` to find the nearest neighbor `elem`, and return the pair `{newDataSet,elem}` where the new list is the original data set minus the starting point and the nearest neighbor. Then it nests. At first glance this works very well, but for some reason, it starts misbehaving at some point. For the actual `dataSet`               dataSet ={{0,107.212,-166.757},{0,104.104,-164.502},{0,112.403,-150.885},     {0,115.978,-158.598},{0,105.259,-163.986},{0.00417,107.759,-166.45},     {0.00417,104.471,-164.266},{0.00417,107.026,-151.875},{0.00417,105.777,-163.744},     {0.00417,116.652,-158.168},{0.00833,108.316,-166.138},{0.00833,104.845,-164.025},     {0.00833,113.825,-150.301},{0.00833,117.3,-157.713},{0.00833,106.307,-163.497},     {0.0125,114.546,-150.},{0.0125,117.949,-157.25},{0.0125,105.226,-163.78},     {0.0125,108.883,-165.822},{0.0125,106.855,-163.25},{0.0167,118.582,-156.766},     {0.0167,109.459,-165.5},{0.0167,101.6,-140.503},{0.0167,115.272,-149.69},     {0.0167,107.423,-163.003},{0.0167,105.617,-163.531},{0.0208,110.046,-165.175},     {0.0208,108.007,-162.753},{0.0208,119.185,-156.256},{0.0208,106.019,-163.277},     {0.0250,119.72,-155.695},{0.0250,110.631,-164.839},{0.0250,106.428,-163.019},     {0.0250,116.72,-149.036},{0.0250,108.607,-162.502},{0.0292,120.192,-155.087},     {0.0292,111.232,-164.501},{0.0292,109.223,-162.248},{0.0292,117.451,-148.698},     {0.0292,106.845,-162.755},{0.0333,107.27,-162.487},{0.0333,117.414,-152.444},     {0.0333,118.18,-148.348},{0.0333,120.441,-154.333},{0.0333,111.84,-164.158},     {0.0375,110.494,-161.728},{0.0375,107.703,-162.214},{0.0375,118.904,-147.984},     {0.0375,112.455,-163.807},{0.0417,111.158,-161.467},{0.0417,119.618,-147.603},     {0.0417,113.078,-163.451},{0.0417,108.146,-161.937},{0.0458,108.595,-161.654},     {0.0458,113.709,-163.089},{0.0458,111.838,-161.204},{0.0500,112.534,-160.938},     {0.0500,112.654,-141.388},{0.0500,114.345,-162.72},{0.0500,109.044,-161.363},     {0.0500,112.524,-160.933},{0.0500,120.969,-146.763},{0.0542,113.234,-160.665},     {0.0542,121.605,-146.304},{0.0542,109.504,-161.068},{0.0583,109.975,-160.769},     {0.0583,122.156,-145.782},{0.0583,115.631,-161.958},{0.0583,100.877,-151.789},     {0.0583,115.968,-141.83},{0.0625,122.61,-145.19},{0.0625,116.281,-161.565},     {0.0625,110.451,-160.464},{0.0625,101.965,-151.715},{0.0625,114.685,-160.109},     {0.0667,110.933,-160.153},{0.0667,116.931,-161.162},{0.0667,115.445,-159.836},     {0.0667,122.707,-144.366},{0.0708,111.42,-159.836},{0.0708,117.583,-160.748},     {0.0708,104.149,-151.56},{0.0708,116.223,-159.561},{0.0750,111.913,-159.512},     {0.0750,117.022,-159.288},{0.0750,118.22,-160.316},{0.0750,105.254,-151.482},     {0.0792,118.863,-159.875},{0.0792,112.41,-159.182},{0.0792,117.82,-159.},     {0.0792,106.37,-151.402},{0.0833,107.494,-151.318},{0.0833,100.785,-147.01},     {0.0833,112.91,-158.844},{0.0833,119.491,-159.413},{0.0833,118.672,-158.738},     {0.0875,113.414,-158.499},{0.0875,119.579,-158.508},{0.0917,113.919,-158.146},     {0.0917,103.978,-147.28},{0.0958,114.425,-157.784},{0.100,114.93,-157.413},     {0.100,107.059,-147.566},{0.104,113.234,-150.814},{0.104,115.433,-157.031},     {0.108,115.932,-156.638},{0.113,116.423,-156.232},{0.113,101.498,-145.35},     {0.117,116.906,-155.813},{0.117,102.399,-145.22},{0.121,117.374,-155.376},     {0.121,103.297,-145.086},{0.125,117.826,-154.921},{0.125,104.183,-144.944},     {0.129,118.252,-154.444},{0.133,118.644,-153.937},{0.133,105.938,-144.636},     {0.138,118.996,-153.401},{0.138,106.801,-144.466},{0.142,119.308,-152.835},     {0.142,107.658,-144.286},{0.146,119.57,-152.235},{0.146,108.498,-144.09},     {0.150,109.328,-143.88},{0.150,119.787,-151.607},{0.154,119.966,-150.958},     {0.154,110.138,-143.652},{0.158,110.927,-143.404},{0.158,120.106,-150.289},     {0.163,120.211,-149.605},{0.163,111.689,-143.134},{0.167,120.259,-148.896},     {0.167,112.415,-142.835},{0.171,113.099,-142.506},{0.171,119.977,-147.999},     {0.175,120.277,-147.493},{0.175,113.727,-142.137},{0.179,120.589,-146.993},     {0.179,114.291,-141.726},{0.183,114.772,-141.264},{0.183,120.91,-146.499},     {0.188,115.167,-140.749},{0.188,121.239,-146.01},{0.192,121.576,-145.524},     {0.192,115.485,-140.189},{0.196,121.922,-145.041},{0.196,115.723,-139.584},     {0.200,122.274,-144.561},{0.200,115.898,-138.947},{0.204,122.634,-144.083},     {0.204,116.027,-138.288},{0.208,116.109,-137.61},{0.213,123.371,-143.131},     {0.213,116.16,-136.921},{0.217,116.162,-136.215},{0.217,123.739,-142.65},     {0.221,124.081,-142.15},{0.221,116.199,-135.54},{0.225,124.382,-141.622},     {0.225,115.642,-134.569},{0.229,124.612,-141.048},{0.229,115.929,-134.06},     {0.233,124.705,-140.391},{0.233,116.244,-133.565},{0.238,124.403,-139.499},     {0.238,116.576,-133.078},{0.242,116.922,-132.599},{0.242,120.971,-137.197},     {0.246,120.605,-136.819},{0.246,117.284,-132.126},{0.250,117.66,-131.659},     {0.250,120.585,-136.614},{0.254,120.676,-136.469},{0.254,118.049,-131.197},     {0.258,120.824,-136.357},{0.258,118.452,-130.74},{0.263,121.006,-136.266},     {0.263,118.869,-130.287},{0.267,121.211,-136.19},{0.267,119.287,-129.833},     {0.271,121.431,-136.125},{0.271,119.665,-129.354},{0.275,119.977,-128.839},     {0.275,121.662,-136.069},{0.279,121.901,-136.021},{0.279,120.191,-128.271},     {0.283,122.148,-135.978},{0.283,120.266,-127.633},{0.288,122.4,-135.941},     {0.288,120.148,-126.902},{0.292,122.655,-135.908},{0.292,119.772,-126.057},     {0.296,122.915,-135.88},{0.296,119.114,-125.106},{0.300,123.178,-135.855},     {0.300,118.23,-124.103},{0.304,123.442,-135.833},{0.304,117.299,-123.157},     {0.308,123.71,-135.815},{0.308,116.465,-122.334},{0.313,123.978,-135.799},     {0.313,115.785,-121.644},{0.317,115.25,-121.066},{0.317,124.249,-135.786},     {0.321,124.521,-135.776},{0.321,114.834,-120.578},{0.325,124.794,-135.768},     {0.325,114.516,-120.159},{0.329,125.068,-135.763},{0.329,114.275,-119.795},     {0.333,114.099,-119.476},{0.333,125.343,-135.759},{0.338,125.619,-135.759},     {0.338,113.974,-119.193},{0.342,125.902,-135.762},{0.342,113.892,-118.939},     {0.346,113.848,-118.71},{0.346,126.18,-135.766},{0.350,113.834,-118.503},     {0.350,126.46,-135.772},{0.354,113.847,-118.313},{0.354,126.739,-135.78},     {0.358,113.886,-118.14},{0.358,127.018,-135.79},{0.363,127.298,-135.802},     {0.363,113.943,-117.98},{0.367,127.579,-135.816},{0.367,114.018,-117.833},     {0.371,114.109,-117.695},{0.371,127.86,-135.832},{0.375,128.142,-135.85},     {0.375,114.215,-117.568},{0.379,128.424,-135.871},{0.379,114.333,-117.449},     {0.383,114.462,-117.338},{0.383,128.706,-135.893},{0.388,114.602,-117.233},     {0.388,128.989,-135.918},{0.392,114.75,-117.135},{0.392,129.272,-135.945},     {0.396,129.556,-135.975},{0.396,114.907,-117.043},{0.400,129.84,-136.006},     {0.400,115.07,-116.956},{0.404,115.241,-116.874},{0.404,130.124,-136.04},     {0.408,115.417,-116.796},{0.408,130.409,-136.077},{0.413,115.599,-116.723},     {0.413,130.694,-136.116},{0.417,115.785,-116.653},{0.417,130.979,-136.158},     {0.421,115.976,-116.588},{0.421,131.265,-136.202},{0.425,131.551,-136.249},     {0.425,116.17,-116.525},{0.429,116.368,-116.466},{0.429,131.837,-136.3},     {0.433,116.568,-116.41},{0.433,132.123,-136.353},{0.438,116.772,-116.357},     {0.438,132.41,-136.409},{0.442,116.977,-116.307},{0.442,132.697,-136.468},     {0.446,132.985,-136.531},{0.446,117.186,-116.259},{0.450,133.273,-136.597},     {0.450,117.395,-116.214},{0.454,133.56,-136.668},{0.454,117.606,-116.171},     {0.458,133.849,-136.742},{0.458,117.819,-116.131},{0.463,118.033,-116.093},     {0.463,134.137,-136.82},{0.467,118.247,-116.057},{0.467,134.426,-136.903},     {0.471,134.715,-136.991},{0.471,118.462,-116.024},{0.475,135.004,-137.085},     {0.475,118.678,-115.992},{0.479,135.294,-137.184},{0.479,118.895,-115.963},     {0.483,135.584,-137.29},{0.483,119.112,-115.936},{0.488,135.874,-137.402},     {0.488,119.328,-115.911},{0.492,136.164,-137.523},{0.492,119.544,-115.888},     {0.496,136.455,-137.654},{0.496,119.761,-115.868},{0.500,119.977,-115.849},     {0.500,136.746,-137.795},{0.504,120.193,-115.833},{0.504,137.038,-137.95},     {0.508,120.411,-115.819},{0.508,137.331,-138.12},{0.513,120.627,-115.807},     {0.513,137.625,-138.31},{0.517,137.922,-138.525},{0.517,120.839,-115.797},     {0.521,121.052,-115.789},{0.521,138.222,-138.775},{0.525,121.263,-115.784},     {0.525,143.043,-147.527},{0.525,138.528,-139.074},{0.529,121.473,-115.78},     {0.529,143.1,-147.916},{0.529,138.847,-139.456},{0.533,121.682,-115.779},     {0.533,143.082,-148.164},{0.533,139.204,-140.01},{0.533,140.401,-143.007},     {0.538,121.89,-115.781},{0.538,143.053,-148.367},{0.542,122.095,-115.784},     {0.542,143.011,-148.517},{0.546,122.3,-115.79},{0.546,142.974,-148.641},     {0.550,142.948,-148.745},{0.550,122.502,-115.799},{0.554,142.94,-148.841},     {0.554,122.701,-115.81},{0.558,142.942,-148.914},{0.558,122.898,-115.823},     {0.563,142.963,-148.976},{0.563,123.092,-115.84},{0.567,123.282,-115.858},     {0.567,143.003,-149.027},{0.571,143.063,-149.07},{0.571,123.468,-115.88},     {0.575,143.145,-149.11},{0.575,123.651,-115.904},{0.579,123.829,-115.931},     {0.579,143.247,-149.136},{0.583,124.002,-115.961},{0.583,143.37,-149.154},     {0.588,124.169,-115.995},{0.588,143.515,-149.166},{0.592,124.329,-116.031},     {0.592,143.684,-149.17},{0.596,143.873,-149.168},{0.596,124.481,-116.07},     {0.600,144.087,-149.16},{0.600,124.625,-116.112},{0.604,124.759,-116.158},     {0.604,144.324,-149.146},{0.608,124.882,-116.206},{0.608,144.583,-149.125},     {0.613,124.991,-116.258},{0.613,144.858,-149.102},{0.617,125.086,-116.313},     {0.617,145.161,-149.069},{0.621,125.164,-116.371},{0.621,145.489,-149.03},     {0.625,125.223,-116.432},{0.625,145.841,-148.985},{0.629,146.216,-148.934},     {0.629,125.261,-116.497},{0.633,146.612,-148.877},{0.633,125.276,-116.563},     {0.638,125.264,-116.632},{0.638,147.033,-148.814},{0.642,125.224,-116.704},     {0.642,147.477,-148.745},{0.646,125.154,-116.776},{0.646,147.943,-148.67},     {0.650,148.431,-148.588},{0.650,125.052,-116.849},{0.654,148.943,-148.5},     {0.654,124.918,-116.923},{0.658,149.477,-148.407},{0.658,124.752,-116.997},     {0.663,150.034,-148.306},{0.663,124.555,-117.069},{0.667,150.611,-148.198},     {0.667,124.329,-117.14},{0.671,124.075,-117.209},{0.671,151.211,-148.084},     {0.675,123.798,-117.275},{0.675,151.833,-147.964},{0.679,152.472,-147.835},     {0.679,123.499,-117.338},{0.683,123.183,-117.398},{0.683,153.136,-147.7},     {0.688,153.821,-147.558},{0.688,122.852,-117.456},{0.692,122.509,-117.51},     {0.692,154.527,-147.409},{0.696,122.155,-117.562},{0.696,155.25,-147.251},     {0.700,121.794,-117.61},{0.700,155.98,-147.08},{0.704,121.425,-117.656},     {0.704,156.746,-146.908},{0.708,121.052,-117.699},{0.708,157.531,-146.729},     {0.713,120.674,-117.74},{0.713,158.338,-146.542},{0.717,120.293,-117.778},     {0.717,159.164,-146.347},{0.721,119.91,-117.814},{0.721,160.011,-146.144},     {0.725,160.876,-145.933},{0.725,119.524,-117.849},{0.729,119.137,-117.881},     {0.729,161.759,-145.713},{0.733,138.983,-129.306},{0.733,132.82,-128.392},     {0.733,118.75,-117.911},{0.733,162.66,-145.485},{0.738,163.577,-145.247},     {0.738,118.362,-117.94},{0.738,141.38,-129.709},{0.738,131.315,-128.279},     {0.742,117.972,-117.967},{0.742,164.514,-145.},{0.742,130.272,-128.245},     {0.742,130.258,-128.242},{0.742,143.342,-130.024},{0.746,129.413,-128.244},     {0.746,117.583,-117.992},{0.746,145.14,-130.295},{0.750,117.193,-118.016},     {0.750,128.681,-128.269},{0.750,166.436,-144.478},{0.750,146.841,-130.531},     {0.754,148.513,-130.75},{0.754,128.023,-128.307},{0.754,167.422,-144.203},     {0.754,116.803,-118.039},{0.758,116.413,-118.06},{0.758,168.401,-143.906},     {0.758,127.418,-128.356},{0.758,150.161,-130.951},{0.758,100.035,-93.1424},     {0.763,126.853,-128.413},{0.763,169.419,-143.611},{0.763,116.023,-118.081},     {0.763,151.804,-131.137},{0.763,101.189,-93.1484},{0.767,115.633,-118.1},     {0.767,153.443,-131.308},{0.767,170.453,-143.306},{0.767,126.319,-128.477},     {0.771,125.809,-128.545},{0.771,171.502,-142.99},{0.771,115.243,-118.118},     {0.775,125.32,-128.618},{0.775,172.565,-142.664},{0.775,114.854,-118.136},     {0.775,104.853,-93.1614},{0.779,124.847,-128.694},{0.779,158.429,-131.756},     {0.779,173.641,-142.326},{0.779,114.465,-118.152},{0.779,106.142,-93.1641},     {0.783,124.389,-128.773},{0.783,160.12,-131.884},{0.783,114.076,-118.168},     {0.783,174.729,-141.976},{0.783,107.439,-93.1533},{0.788,161.832,-132.005},     {0.788,175.829,-141.614},{0.788,113.687,-118.184},{0.788,123.943,-128.854},     {0.792,123.508,-128.938},{0.792,113.299,-118.199},{0.792,163.566,-132.118},     {0.792,176.939,-141.239},{0.792,110.183,-93.1532},{0.796,123.082,-129.023},     {0.796,111.604,-93.1513},{0.796,178.059,-140.849},{0.796,112.911,-118.213},     {0.796,165.333,-132.228},{0.800,122.664,-129.109},{0.800,179.152,-140.426},     {0.800,112.522,-118.228},{0.800,167.121,-132.328},{0.800,113.059,-93.1484},     {0.804,122.253,-129.197},{0.804,180.284,-140.006},{0.804,112.134,-118.242},     {0.804,168.949,-132.43},{0.804,114.547,-93.1443},{0.808,116.067,-93.1385},     {0.808,121.849,-129.286},{0.808,111.747,-118.257},{0.808,181.418,-139.568},     {0.808,170.806,-132.527},{0.813,182.55,-139.11},{0.813,121.45,-129.376},     {0.813,172.714,-132.631},{0.813,111.36,-118.272},{0.817,174.666,-132.739},     {0.817,110.973,-118.287},{0.817,183.673,-138.627},{0.817,121.056,-129.466},     {0.817,119.203,-93.1213},{0.821,120.667,-129.558},{0.821,184.733,-138.086},     {0.821,110.587,-118.302},{0.821,176.687,-132.865},{0.821,120.818,-93.1095},     {0.825,110.2,-118.318},{0.825,120.282,-129.65},{0.825,185.8,-137.531},     {0.825,122.463,-93.095},{0.829,109.814,-118.335},{0.829,186.812,-136.925},     {0.829,119.9,-129.743},{0.829,124.138,-93.0775},{0.833,187.63,-136.179},     {0.833,109.428,-118.353},{0.833,119.522,-129.836},{0.833,125.841,-93.0562},     {0.833,101.434,-76.7516},{0.833,183.346,-133.463},{0.838,109.043,-118.371},     {0.838,119.147,-129.929},{0.838,127.53,-93.0084},{0.838,188.095,-135.196},     {0.838,186.301,-134.068},{0.838,103.785,-77.2176},{0.842,118.774,-130.023},     {0.842,108.657,-118.391},{0.842,129.287,-92.978},{0.846,108.272,-118.412},     {0.846,108.625,-78.1698},{0.846,118.404,-130.118},{0.850,118.036,-130.212},     {0.850,107.886,-118.434},{0.850,132.878,-92.9027},{0.854,117.67,-130.308},     {0.854,134.71,-92.8557},{0.854,113.665,-79.1537},{0.854,107.502,-118.459},     {0.858,107.117,-118.485},{0.858,117.305,-130.403},{0.858,116.271,-79.6627},     {0.863,116.942,-130.499},{0.863,118.94,-80.1854},{0.863,106.733,-118.513},     {0.863,138.437,-92.7383},{0.867,116.581,-130.595},{0.867,106.35,-118.543},     {0.867,121.666,-80.7181},{0.871,116.22,-130.692},{0.871,105.966,-118.576},     {0.871,142.17,-92.5433},{0.875,105.583,-118.611},{0.875,144.07,-92.4357},     {0.875,115.861,-130.789},{0.875,127.349,-81.8495},{0.879,105.2,-118.649},     {0.879,115.502,-130.886},{0.879,145.973,-92.3099},{0.883,115.144,-130.984},     {0.883,104.818,-118.69},{0.883,133.39,-83.0948},{0.888,149.743,-91.9766},     {0.888,114.786,-131.082},{0.888,104.437,-118.735},{0.888,136.58,-83.7813},     {0.892,151.488,-91.6963},{0.892,104.056,-118.783},{0.892,114.429,-131.182},     {0.896,114.072,-131.281},{0.896,153.213,-91.3845},{0.896,103.676,-118.834},     {0.900,113.714,-131.382},{0.900,103.296,-118.889},{0.900,154.775,-90.9557},     {0.904,155.686,-90.1154},{0.904,102.917,-118.948},{0.904,113.357,-131.483},     {0.908,102.54,-119.011},{0.908,113.,-131.585},{0.913,112.642,-131.687},     {0.913,102.163,-119.078},{0.917,101.787,-119.149},{0.917,112.284,-131.791},     {0.921,111.926,-131.895},{0.921,101.412,-119.225},{0.925,111.566,-132.001},     {0.925,101.038,-119.305},{0.929,111.206,-132.108},{0.929,100.666,-119.39},     {0.933,110.845,-132.216},{0.933,100.294,-119.479},{0.938,110.483,-132.326},     {0.942,110.12,-132.437},{0.946,109.756,-132.55},{0.950,109.392,-132.665},     {0.954,109.025,-132.781},{0.958,108.657,-132.9},{0.963,108.288,-133.02},     {0.967,107.917,-133.143},{0.971,107.545,-133.268},{0.975,107.171,-133.396},     {0.979,106.797,-133.527},{0.983,106.42,-133.66},{0.988,106.043,-133.796},     {0.992,105.664,-133.936},{0.996,105.284,-134.078},{1.00,104.903,-134.225}};      Here is a 3d representation of the `dataSet` ![enter image description here](http://i.stack.imgur.com/gKHPg.png) Starting the code at the last point of `dataSet`               ordDataSet = NestList[With[{elem = Nearest[#[[1]], #[[2]]][[1]]},          {Select[#[[1]], (# != elem &)], elem}] &,          {Delete[dataSet, {-1}], dataSet[[-1]]}, 300][[All, 2]];      works very well, until step 243 where everithing goes bad (sorry for the huge gif) ![enter image description here](http://i.stack.imgur.com/jfJ8C.gif) Looking at the 3d plot, is clear that the nearest neighbor is `ordDataSet[[245]]`, but manually calculating the distance confirms that the nearest point is `ordDataSet[[244]]`. What is wrong then, my code, the displayed plot or the calculation of the Norm? * * * **EDIT** > Kuba wrote > > I hope I have not missed the point but the problem is you are probably using > `BoxRatios->1` which can affect the judgement. I tried to see this before posting, but using `AspectRatio` instead of `BoxRatio`. Lucky for me, the small dimension plays a crucial role in connectendness, and it should be rescaled to wiegth as much as the _yz_ coordinates. Rescaling the data:               rescDataSet = MapAt[100# &, dataSet, {All,1}];          rescOrdDataSet = NestList[With[{elem = Nearest[#[[1]], #[[2]]][[1]]},           {Select[#[[1]], (# != elem &)], elem}] &,           {Delete[scaledDataSet, {-1}], scaledDataSet[[-1]]}, 300][[All, 2]];      everithing goes as expected: ![enter image description here](http://i.stack.imgur.com/aq73t.gif) Thank you very much Kuba!


Specify a variable as an integer

I have a formula that always evaluates to a certain number for any variable `X` under one condition that `X` is an integer and greater than 0. So how can I evaluate `Func[X]` and specify that X is an integer greater than 0? is there a way to do that? I tried saying `Func[Round[X]]` but it didn't work, it just used `Round[X]` as a variable instead of understanding that it means `X` is an integer. Ok I will give exactly what I'm trying to do, it's fairly simple: $p= \begin{array}{cccccccccc} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\ 0.5 & 0 & 0.5 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\ 0.5 & 0 & 0 & 0 & 0.5 & 0 & 0 & 0 & 0 & 0 \\\ 0 & 0.5 & 0 & 0 & 0 & 0.5 & 0 & 0 & 0 & 0 \\\ 0 & 0 & 0 & 0.5 & 0 & 0.5 & 0 & 0 & 0 & 0 \\\ 0 & 0 & 0 & 0 & 0.5 & 0 & 0.5 & 0 & 0 & 0 \\\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\\ \end{array} ;$ $\text{mainWin}=\\{0,12.4461,24.8921,37.3382,49.7842,62.2303,74.6763,87.1224,99.5685,112.015\\};$ $u=\\{0,0,0,1,0,0,0,0,0,0\\};$ Now I'm evaluating: $(u.\text{MatrixPower}[p,x]).\text{money}$ where $x$ is a positive integer This will always evaluate to: **37.3382** which if you notice is the fourth entry in $money$ which is also the state that we started with. Now I want to know if mathematica can figure that out (that it always evaluates to this number) if I indicate that $x$ is a positive integer. If I just use $x$ normally:               (u.MatrixPower[p, x]).mainWin // Simplify      I get:               37.3382 + (2.77553*10^-24 - 1.91762*10^-31 I) (-0.5)^     x - (1.77636*10^-15 - 1.59872*10^-14 I) (-0.116393 - 0.396276 I)^     x + (3.55271*10^-15 - 1.95399*10^-14 I) (-0.116393 + 0.396276 I)^     x + (7.10543*10^-15 - 4.73403*10^-15 I) (-2.20245*10^-16)^     x - (5.68434*10^-14 + 2.27918*10^-16 I) 0.732786^x      As you can see I just want to get rid of that imaginary part The answers here are quite educational (I'm new to Mathematica) but unfortunately they don't give the required outcome. Just for the interested; this is modelling the outcome of a gamble where you have p as the probability matrix, your initial state is number 4. and what I'm doing here is guaranteeing that I get one outcome no matter how many times I gamble, and that outcome is equal to whatever I started with. This is Mathematica code:               p = \!\(\*     TagBox[     RowBox[{"(", "", GridBox[{     {"1", "0", "0", "0", "0", "0", "0", "0", "0", "0"},     {"0.5`", "0", "0.5`", "0", "0", "0", "0", "0", "0", "0"},     {"0.5`", "0", "0", "0", "0.5`", "0", "0", "0", "0", "0"},     {"0", "0.5`", "0", "0", "0", "0.5`", "0", "0", "0", "0"},     {"0", "0", "0", "0.5`", "0", "0.5`", "0", "0", "0", "0"},     {"0", "0", "0", "0", "0.5`", "0", "0.5`", "0", "0", "0"},     {"0", "0", "0", "0", "0", "0", "1", "0", "0", "0"},     {"0", "0", "0", "0", "0", "0", "0", "1", "0", "0"},     {"0", "0", "0", "0", "0", "0", "0", "0", "1", "0"},     {"0", "0", "0", "0", "0", "0", "0", "0", "0", "1"}     },     GridBoxAlignment->{             "Columns" -> {{Center}}, "ColumnsIndexed" -> {},               "Rows" -> {{Baseline}}, "RowsIndexed" -> {}, "Items" -> {},               "ItemsIndexed" -> {}},     GridBoxSpacings->{"Columns" -> {     Offset[0.27999999999999997`], {     Offset[0.7]},      Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {     Offset[0.2], {     Offset[0.4]},      Offset[0.2]}, "RowsIndexed" -> {}, "Items" -> {},               "ItemsIndexed" -> {}}], "", ")"}],     Function[BoxForm`e$,          MatrixForm[BoxForm`e$]]]\);     mainWin = {0, 12.4460563, 24.89211259, 37.33816889, 49.78422519,         62.23028148, 74.67633778, 87.12239407, 99.56845037, 112.0145067};     u = {0, 0, 0, 1, 0, 0, 0, 0, 0, 0};     (u.MatrixPower[p, x]).mainWin // Simplify


Graphics plot of point using unfilled circle

I'd like to be able to place points on a plot using `Graphics[{Point[{a,b}],....}]` but have the plot symbol be an unfilled circle. I've looked around but can't find any way of doing this. Is there one? Thanks. After reading the first response, perhaps I should add a bit more. I'd like to be able to do the following:               p1 = Plot[x^2,{x,-3,3}]     p2 = Graphics[Style[Point[{0,0}],PointSize[Large]]     Show[p1,p2]      but with an unfilled circle instead of a dot. The solution proposed in the first answer falls short in two ways: first, the unfilled circle does not properly hide graphics elements underneath it; second, the circle will appear as an ellipse, not a circle, in the (likely) event that the underlying graphic does not have aspect ratio 1. The application here is for plotting piecewise discontinuous functions and showing clearly which endpoint at a jump discontinuity holds the value at the point.


System of differential equations - solving for a constant

I will reformulate my question in the hopes it will be more intelligible. First, I defined the functions:               f1[r_] = b*SphericalBesselJ[l, α*r];     f2[r_] = c*SphericalHankelH1[l, I*β*r];          g1[r_] := D[f1[r], r]/(f1[r]);     g2[r_] := D[f2[r], r]/(f2[r]);      And I want to set:               f1[a]==f2[a]      g1[a]==g2[a]      Is it possible to use these two equations to find another equation that relates Alpha, Beta and a?


Mathematica 9.01 and CUDA under VB 2013 and modified CCompilerDriver

I tried to force CUDA using Visual Studio 2013 C compiler by manipulating the VisualStudioCOmpiler file found at C:\Program Files\Wolfram Research\Mathematica\9.0\AddOns\Applications\CCompilerDriver When run, CUDA will not run at all.Mathematica hangs at Needs["CUDALink`"] Anyone faced similar problem? HAs anyone tried to make the same modification?


Dynamically filling matrix with a[[n,m]] = 1/a[[m,n]]

I'm building a square matrix, with 1s on the diagonal and elements in U the inverse of elements in L, which are random integers drawn from the sequence 1, ..., 9. Given the nature of the problem I need to solve, conceptually this does the trick perfectly.               size = 5; (*size of matrix*)     range = {1, 9}; (*the range of integers, min to max*)     init = RandomInteger[range, size]; (*builds the initial vector*)     matrix = Transpose[Table[init/init[[i]], {i, size}]];       (*constructs the matrix from the initial vector the way the problem requires*)      `matrix` is an "ideal" matrix, because in a second step a hypothetical user should be able to perturb it by modifying the elements in L, with elements in U changing accordingly; i.e., becoming the inverse `matrix[[1,2]] = 1/matrix[[2,1]]`, and so on. This is the best I have done so far to implement the dynamic behavior I want.               onscreen = SparseArray[{       {i_, i_} -> 1,         (*1s on the diagonal*)       {i_, j_} /; i - j >= 1 :> InputField[Dynamic[matrix[[i, j]]]],         (*InputFields to edit L part of matrix*)       {i_, j_} /; i - j <= 1 :> Dynamic[1/matrix[[j, i]]]         (*the U part of matrix - comment below*)       }, {size, size}]      I use `onscreen` as the means for the user to enter the desired values. Now he/she can edit the L part of `matrix`, and the U part of `onscreen` should reflect what is expected in `matrix`. However values in U of `matrix` don't change. How can I make it happen? I should remark that `matrix` will be needed for further calculations, so I can't populate it with `Dynamic`.


how to nest parallelized computations on a cluster?

I am lucky to have access to a computational cluster and I could submit my job to many-many cores. As I need to evaluate a numerical integral within a numerical integral, I would like to know if I can set things up (e.g. during the compilation of the inner integral as compiled function) in a way that would run the inner function on 8 cores (on a single node) and distribute the outer one across nodes in the cluster?               tmp = Compile[      {{z,_Real},{zz,_Real}},      NIntegrate[1 - \[Xi]u[zzz]/\[Xi]c[zzz], {zzz, z, zz},Parallelization -> True]      ]     g[z_] := NSolve[       T'[z]/(1 - T'[z]) - (k SurvivalFunction[H,z]/(z PDF[Hstar, z]))       *NIntegrate[(1 - g) Exp[tmp[z, zz]] PDF[H, zz]/SurvivalFunction[H, z],        {zz, z, \[Infinity]}], g, Reals]     N[g[2000000], 10]      Simple `LaunchKernel` and `Parallelize` did not seem to give me this control. (If it made sense in the first place...) Separately, I would evaluate my function (`g`) for many points (a `List`), but as all for all points `g` uses the integrals over the right tail of the same distribution, actually it sounds like a waste of time to calculate them separately, even if I do it within a single call like `ParallelTable`. Would Mathematica notice that it could use some calculations across the evaluations? Or shall I explicitly separate the useful object first? Or can I call some clever `Fold`? Could any of this be parallelized? (Not trivial if I try to be cheap and ask Mathematica to solve for a function only implicitly defined in an expression.) **EDIT** : Actually the code as given does not run, but gives the error > CompiledFunction::cfsa: "Argument zz at position 2 should be a !(\"machine- > size real number\")." Probably because of the outer integral having upper limit of infinity?


How to guess initial complex value for FindRoot

I have to solve a transcendental equation for a parameter, say $\beta$. Now, the $\beta$ has a range from $ik$ to $k$ where $i$ is the usual imaginary root $\sqrt{-1}$ and $k$ is a real number. Problem is, the transcendental equation has multiple solutions, and so I cannot guess what will be the proper choice for the initial value of $\beta$ in `FindRoot`. I could do it if $\beta$ ranges from $p$ to $q$ where $p$ and $q$ are reals by plotting the transcendental equation's lhs and rhs. However, I don't know how to plot complex ranges. Is there any way to guess the initial values?


PaddedForm adds an additional padding character

I would like to get a sequence from `"01"` to `"10"`. I tried               ToString@PaddedForm[#, 1, NumberPadding -> "0"] & /@ Range@10          (*{"01", "02", "03", "04", "05", "06", "07", "08", "09", "010"}*)      But this returns `"010"` instead of `"10"`. What am I doing wrong? And yes, I know I can do               StringTake[ToString[PaddedForm[#, 1, NumberPadding -> "0"]], -2] & /@ Range@10          (*{"01", "02", "03", "04", "05", "06", "07", "08", "09", "10"}*)      But this feels like a hack.


Plot help with axes coordinates

Plot[{4 - 2 y, (5 + y)/3}, {y, 1, 10}]      ![graph](http://i.stack.imgur.com/o4Dve.png) How do I make Mathematica tell me the coordinates for cuts with the y-axis, other than just looking at it?


how to work with list as function parameter

I want to output an arrow based on input from user and I tried writing this small function to achieve this:               g[{matric}] :=       For[i = 1, i < Length[mat], i++,        Graphics[{Arrow[{{0, 0}, {matric[[1]], matric[[2]]}}]}, Axes -> True,         AspectRatio -> Automatic]]      To call it: `g[mat[[1]]]` which is not working !! I want to send array as list for example `{{1,2},{3,4}}` and create its output as arrow but I don't know how to break this list. The second problem is that I can generate plots using `Apply[f,arg,{1}]` but it gives different plots for different elements in the list,so how can I combine them together in one plot. I know about `Show` command but I just wanted to know if there is any other way too.


Plotting the discrete solution to a PDE

So I went through all the grunt work of solving a PDE in discrete form for a research project. Now I have a Temperature solution as a function of time and space: $$ T_{i}^{n+1}=\left( \dfrac {\lambda _{1}} {\rho_{1}c_{1}}\right)\left( \dfrac {\Delta t} {\Delta r^{2}}\right)\left( 1-\dfrac {\Delta r} {r}\right) T_{i-1}^{n}+\left( 1-2\left( \dfrac {\lambda _{1}} {\rho _{1}c_{1}}\right) \left( \dfrac {\Delta t} {\Delta r^{2}}\right) \right) T_{i}^{n}+\left( \dfrac {\lambda _{1}} {\rho_{1}c_{1}}\right)\left( \dfrac {\Delta t} {\Delta r^{2}}\right)\left( 1+\dfrac {\Delta r} {r}\right) T_{i+1}^{n}+\dfrac {\Delta t} {\rho_{1}c_{1}}\omega_{b1}c_{b}(\left( T_{b}-T_{i}^{n}\right)+\dfrac {\left( P\lambda _{1}\right) } {\omega_{b_{1}}c_{1}}) $$ But my problem now is I don't know how to plot this in mathematica. I'm looking to plot this Temperature as a function of time online (for fixed radius). As you can see, I have delta t and delta r increments and the variable n is my time variable while i is my space variable. I also have initial conditions for when t = 0 (n = 0). I also have another solution just for i = 0 but I didn't write it out here. Is this just a matter of creating a recursive function and then using plot? Because I tried that and it isn't working for me. Any ideas on how to go about plotting this in mathematica would be greatly appreciated. Thanks! Mathematica Code (with dummy numbers for coefficients):               T[n_, i_] := T[n + 1, i] = 3*T[n, i - 1] + 2*T[n, i] +                   3*T[n, i + 1] + 4 ((300 - T[n, i]) + 8)          T[n + 1, 0] = 5*T[n, 0] + 6*(3 + 2 (300 - T[n, 0])) + 10     T[0, i] = 300      Everytime I run this, I get a recursion depth of 256 exceeded.


Are there any videos that show how different Mathematica expressions are evaluated?

Are there any videos that show how different _Mathematica_ expressions are represented internally as object graphs and demonstrate how they are transformed during an evaluation? I am asking because I believe it can help to develop better intuition about the evaluation process, in particular, which parts of expressions are shared, and which are copied, what happens when different scoping constructs are evaluated, how parts of expressions are modifoed, how evaluation rules are selected from up- and downvalues and how pattern matching is performed etc. I found some interesing animations at http://reference.wolfram.com/flash, but they are mostly intended to give intuition about what are the _results_ of some built-in functions, rather than the _evaluation process_ itself.


Making a Stock Options Database in Mathematica

I am trying to use _Mathematica_ to create a stock options database of sorts. That is I wish to write a function that imports the option chain of a given stock. Unfortunately Wolfram has yet to put stock options on the data server associated with `FinancialData[]` so I decided to obtain the necessary data from _Yahoo Finance_. Here is the function I wrote to do this:               rules = {"Jan" -> "01", "Feb" -> "02", "Mar" -> "03", "Apr" -> "04",      "May" -> "05", "Jun" -> "06", "Jul" -> "07", "Aug" -> "08",      "Sep" -> "09", "Oct" -> "10", "Nov" -> "11", "Dec" -> "12"};          acquireOptions[stock_String] :=      Module[{z =      StringSplit[Import["http://finance.yahoo.com/q/op?s=" <> stock <>"+Options"]],index1, index2},     index1 = Position[z, "Expiration:"][[1, 1]] + 1;     index2 = Position[z, "Call"][[1, 1]] - 1;     ArrayFlatten[(Partition[(DeleteCases[z[[index1 ;; index2]], "|"] /.           rules), 2] /. {x_String,          y_String} :> {"20" <> y <> "-" <> x}) /. {x_String :>        Cases[Import[         "http://finance.yahoo.com/q/op?s=" <> stock <> "&m=" <> x,          "Data"], {_?NumberQ, _String, __?NumberQ}, \[Infinity]]}]]      I should note that I had to study the structure of the _Yahoo Finance_ website hard core to make this work. Although it is functional the problem I have is that it is simply too slow. Running this function for a single stock takes about 30 seconds. Lets assume there are 1000 stocks that have options that I would want to acquire (there are probably a lot more than 1000, I would literally want to be able to acquire every last option). This would take about 8 and a half hours which is just too long. So I'm interested in how I can do this more efficiently. If I used parallel table on my 8 core machine could I expect this to only take about 2 hours? Besides for the code I've written, I saw that _Yahoo_ has a query language YQL that can be used to pull data off their servers. I then saw that Mathematica has Database Link SQL operations. I don't know much about SQL/YQL but would this have been a better direction to go in? If so would anyone be able to show how to link Mathematica and YQL and provide an example where YQL is used in Mathematica to obtain options data? Oh and in case anyone was wondering why I am doing this, it is for an investment model I'm working on. Thanks


How does PolarPlot render a nested list of functions?

I am getting unexpected plots from `PolarPlot` when I provide a list of functions that I generate using `Table`. I suspect the issue is related to the presence of nested lists, but I want to understand how `PolarPlot` is rendering the nested list of functions. I expect the output to be a plot showing the curve of each function in my list. I do not know what functional form would generate the plot that I do observe. For example:               f[a_, b_, c_, t_] := 1 + (1/a)Sin[b + c*t]     t1 = Table[f[a, b, c, t], {a, 3}, {b, 0, Pi/2, Pi/2}, {c, 1}]     PolarPlot[t1, {t, 0, Pi}] (* Not expected result *)     PolarPlot[t1[[1, {1, 2}, {1}]], {t, 0, Pi}] (* Not expected result *)     PolarPlot[Flatten[t1], {t, 0, Pi}] (* Expected result *)     PolarPlot[t1[[1, {1, 2} ,1]],{t, 0, Pi}] (* Expected result *)


How do you adjust tick direction on a 3d plot?

I have a 3d plot with oddly angled tick marks. Whether it's due to the viewing angle being unexpected or some other reason, the tick marks on the bottom axes are angled up along the sides rather than in to the plane. In order to fix this, I'd like to manually change the tick angle back to what it should be, but I can't find the setting that controls tick direction. Any help? Edit: Here is a simple example that illustrates the problem: suppose I plot               Plot3D[x + y, {x, 0, 1}, {y, 0, 1}]      At first, the tick marks on the x and y axes are in the x-y plane. However, if I rotate the point of view, I fairly quickly (around `ViewPoint -> {2.22811, -2.31877, 1.05302}`) find that the ticks switch from being in the x-y plane to pointing up along the z axis. I want to stop it from doing that, so that the ticks stay in the x-y plane for other choices of ViewPoint. This really seems like the sort of thing there ought to be a setting for.


Make 2D vector norm graph

I have: List of points on 2D plane:               pointsz0 = ToExpression@Import@"http://pastebin.com/raw.php?i=VQfP0HgB";      And I have some values in those numbers:               table = ToExpression@Import@"http://pastebin.com/raw.php?i=7g4QNPPw";      Now since `pointsz0` are only 2D (notice `z = 0`), I would like to create a 2D graph. At a `point[[1]]` I want `table[[1]]`. To make things a bit more clear. My numbers are actually vector norms and I would like to make a nice graph showing how the norm of a vector changes in given points. Most likely using colors. That's the idea.


Evaluating $n$-th derivative of a function at a given point

I have a function defined as follows: \begin{array}{ccccc} g & : & [-1,1] & \to & \mathbb C \\\ & & x & \mapsto & \frac{1}{(x-z)^k} \\\ \end{array} where $k$ is a positive integer and $z$ a complex number outside $[-1,1]$ . I want to plot the sequence $\displaystyle \frac{|g^{(n+1)}(0)|}{2^n (n+1)!}$. I tried to do what follows:               g[x_, z_, k_] = 1/(x - z)^k          DiscretePlot[Abs[D[g[x, 5 + I*1/5, 3], {x, n + 1} /. x -> 0]]/(2^n (n + 1)!), {n, 1, 500}]      But the error               General::ivar: 0 is not a valid variable.       pops up. What have I done wrong ?


Why does Maximize return a wrong answer?

I want to find the maximum of the following function, but get a wrong result. What am I doing wrong?               Clear[x, y, xx, yy]     peaks[x_, y_] :=        3*(1 - x)^2.*Exp[-(x^2) - (y + 1)^2] -         10*(x/5 - x^3 - y^5) Exp[-x^2 - y^2] - 1/3 Exp[-(x + 1)^2 - y^2];     N[Maximize[peaks[xx, yy], {xx, yy}]]     NMaximize[{peaks[x, y], x >= -2, x <= 2, y >= -2, y <= 3}, {x, y}]     peaks[0, 2]     peaks[1.28568, -0.00484756]      When you look at these graphs, you realize that the results are strange:               peaks[x_, y_] := 3*(1 - x)^2*Exp[-(x^2) - (y + 1)^2] -                       10*(x/5 - x^3 - y^5) Exp[-x^2 - y^2] - 1/3 Exp[-(x + 1)^2 - y^2];     Plot3D[peaks[x, y], {x, -2, 2}, {y, -2, 3},          ColorFunction -> "DarkRainbow",          AxesLabel -> Automatic]     ContourPlot[peaks[x, y], {x, -2, 2}, {y, -2, 3},           ColorFunction -> "DarkRainbow",          ContourLines -> False,           Contours -> 25]      ![Mathematica graphics](http://i.stack.imgur.com/QcoGl.png)


Depth from Graphics3D

Consider this simple 3D rendering with some geometric primitives:               Graphics3D[{Cylinder[{{-1, -1, 0}, {-1, -1, 1}}, .42], Cuboid[],        Polygon[{{-2, -2, 0}, {2, -2, 0}, {2, 2, 0}, {-2, 2, 0}}],        Sphere[{.3, -.6, .5}, .5]}, Boxed -> False]      How can I get the depth of each _pixel_ of the rendering, i.e. the distance of the corresponding point to the camera? **Edit:** The required depth image would be something like the OpenGL z-buffer. Vertices alone are not enough - I need the depth of every pixel in the rendered image.


How do I draw a Circular Graph colored like this in Mathematica?

I must plot some data in radians and would like to use this image as a background to that graph. Although it looks good the lines are degraded in image form. thus the reason for this question. Can something like this be drawn in Mathematica? ![Colored Circular Graph](http://i.stack.imgur.com/uSM96.jpg)


How to apply Gaussian kernel to smooth density of points on 2D (algorithmically)

I have a set of points on a 2D surface and need to build a heatmap. However, I also need to smooth out the density/distribution by applying some sort of kernel (Gaussian kernel, for example). I Know what Gaussian distribution is, and I have no idea, how mathematically apply the Gaussian kernel to the points on 2D so I can get a smooth distribution or density of points. I know there are functions in Wolfram to do that, but this is more like a research problem, so I need to understand the THEORY of it. Let's say, I am a theory person, and I am NOT in needs of programming. I just need to understand the underlying math of it, why it is still Can someone, please, explain to me, possibly with an example? Or take me to a website that I can read about it? I'd much appreciate that. Thanks


Do/For loop for plots

I have a lot of points that I would like to get shown on a plot. The problem is that sometimes I only have 2 points while other times i have 10 points. I've tried to make a for loop to create a plot with the points but without any luck. This is my code I have for now:               Point1 = {x -> 2, y -> 4};     point1dot =        ListPlot[{{Point1[[1, 2]], Point1[[2, 2]]}},         PlotStyle -> {AbsolutePointSize[5]}];     Label1 = Graphics[        Text[StyleForm["Point 1", FontSize -> 9], {Point1[[1, 2]] + 0.25,           Point1[[2, 2]] + 0.25}]];     Show[point1dot, Label1]      In this example there is only one point, but sometimes it will look like this:               Point1= {x -> 2, y-> 4};     Point2= {x -> 4, y-> -1};     Point3= {x -> 6, y-> 2};     Point4= {x -> 11, y-> 4};     Point5= {x -> 4, y-> 5};     Point6= {x -> 3, y-> -1};      It will become a great shortcut for my work if it could generate it itself instead of editing it manually all the time. So here is my question: Is it possible to make some sort of for loop (it doesn't have to be for), that takes value from my points and create a listplot with the label based on the amount of different numbers?


How to apply tags to expression terms?

I often see on this site and at the mathgroup the repeated questions on how to rearrange expression that _Mathematica_ "likes" to keep in one form, but the user prefers in another. Consider this trivial example:               (x^2 - 1)/(x + 1) // Simplify      _Mathematica_ returns `-1 + x`, rather than the `x - 1` that the user might prefer. I have seen many answers to these questions and gave a few myself. The problem here is that the answers are non-universal; they strongly depend upon the expression in question. Besides, they require some additional programming for sorting terms, and the more complex the formula, the longer will be the code that does the sorting. It seems that the problem of sorting terms in analytic expressions into the desired order might be solved, if one could assign tags to the terms to be sorted. One would then sort the terms according to a specified list of such tags. Now comes my question, can you tell me how to apply tags to expression terms?


How can I speed up numerical integration of multidimensional integral?

I am numerically solving an integral equation that contains a double integral. I have managed to get a solution but it takes forever. I am wondering if there is a way to speed up numerical integration of multidimensional integrals. Here is the code: First a couple of functions that enter the calculation (if I don't include them, the integration will be faster)               g = Pi          cs[x_] := 2*ArcCos[x]/Sqrt[1 - x^2];          csh[x_] := 2*ArcCosh[x]/Sqrt[x^2 - 1];          pref[t_, v_, d_] :=        1/d^2*(1 + 10^(2*(v - t)) (1 - 1/d^2)) /          Sqrt[1 - 1/4*((10^(2*t) + 10^(2*v))/10^(t + v) - 10^(v - t)/d^2)^2]          piece[d_,v_] :=        If[d Astart[v] < 1, cs[d Astart[v]], If[d Astart[v] > 1, csh[d Astart[v]], 2]]      Here is the actual iteration               Clear[Astart, A, precision, values]          precision = 10^-1;          Astart[t_] = -g*t + 1;          values = ParallelTable[{t,        1 + g/(Pi^3*2)         (NIntegrate[Log[10]*10^(v - t)*pref[t, v, d]*((d^2*Astart[v] - 1)*(Pi - g*piece[d,v]) +              d*Astart[v]*g^2*csh[g])/(d^2*Astart[v]+ g^2 - 1),           {v, -Infinity, 0},           {d, 1/(10^(t - v) + 1), 1/Abs[10^(t - v) - 1]},           WorkingPrecision -> 12,           PrecisionGoal -> 3,           MaxRecursion -> 20,           AccuracyGoal -> 12,           Method -> {"SymbolicPreprocessing",  "OscillatorySelection"-> False, "SymbolicProcessing"->0}         ])},       {t, Union[Range[-5.6,-1.6, 0.5]~Join~Log10[Range[0.08, 0.98, 0.1]]]}];           A[t_] = Interpolation[Re@values, t, InterpolationOrder -> 2, Method-> "Spline"]      Perhaps I should also mention that this later on iterated into a while loop until convergence is achieved (just to give a better picture on the amount of total waiting time...) EDIT: I have added in the code also the method the 'fastest' method that I could find, however it still runs for ages... Given the particular form of the integration limits, is there any better trick to help mathematica? Also, by inspection I can see that the result explodes logarithmically which might be another reason why it is so slow.


Defining a rule with functions of arbitrary arguments

I have a set of "functions operators", say A1[u],A2[u],A3[u],and I would like to define a rule such that, for instance,               (x*A1[u1]).(y*A2[u2])      returns               x*y*A1[u1].A2[u2]      I have been trying something like:               operatorset = {A1[u1],A2[u1],A3[u1],A1[u2],A2[u2],A3[u2]};     distri = Dot -> Composition[Distribute, Dot];     rule1 = {Dot[Times[scalar1__, z1_ /; MemberQ[operatorset, z1]],          Times[scalar2__, z2_ /; MemberQ[operatorset, z2]]] ->         scalar1*scalar2 *z1.z2};      It works, however, I will need this kind of product when the operators have other arguments, like A1[u1^2], A2[u3], etc. Is there a way to define an "operatorset" where each operator has arbitrary arguments? Thanks in advance.


Loading Statistics`Library`

I need to use a number of functions from the`Statistics`Library`` namespace. Since that is a bit of a mouthful I would like to import it, but I get errors:               In[42]:= Needs["Statistics`Library`"]          During evaluation of In[42]:= Get::noopen: Cannot open Statistics`Library`. >>          During evaluation of In[42]:= Needs::nocont: Context Statistics`Library` was not created when Needs was evaluated. >>          Out[42]= $Failed          In[43]:= << Statistics`Library`          During evaluation of In[43]:= Get::noopen: Cannot open Statistics`Library`. >>          Out[43]= $Failed      I can use individual functions from the namespace               In[44]:= Statistics`Library`DistributionDimensionality[      NormalDistribution[]]               Out[44]= 1      so the problem is not in the name. What is the problem then? What is the correct way to do the import?


How to count number of {True,True} outputs?

Do[Print[{x + y + z == 3, x + y > z}], {x, 1, 2, 1}, {y, 1, 2, 1}, {z, 1, 2, 1}]      If I run this syntax I get a series of Outputs, I am trying to Count only the number of outputs which is `{True,True}`


Importing LTSpice data into mathematica

I am working with LTSpice (Discret electrical circuit ( Spice) simulator). I would like to import LTSpice ouput data into mathematica for processing and plots. An example of a file can be found here (https://www.dropbox.com/s/ixbp11p6876pz1o/Test_SCOneDiode.raw) Any comments, suggestions and helps are welcome! Thank you in advance


Linear Stability Analysis Routine. Normal Modes in NDSolve

I want to make the linear stability analyis of a nonlinear system of PDEs. So for example then I want to plot what happens to the amplitudes of the modes. To do that I need to solve my equations with different initial conditions, which can be parametrised by the wavelenght $k$. There's what I do, but doesn't seem to work. I write down the equations               eqn1[λ_, ω_, v_, α_, δ_, σ_, A_] := **Something**     eqn2[λ_, ω_, v_, α_, δ_, σ_, A_] := **Something**      I prepare the parametrisation (I would like to put my different solutions - functions of $x,t$ - in the arrays SolVec1,2; and my different maximums - functions only of $t$ - in the arrays MaxVec1,2) :               SolVec1 = Table[0, {i, Nk}]; SolVec2 = Table[0, {i, Nk}];     MaxVec1 = Table[0, {i, Nk}]; MaxVec2 = Table[0, {i, Nk}];          Initial[x_, kk_] := {0.01*Sin[2 Pi kk*x / L], 1 - 0.01 Cos[2 Pi kk*x / L]/L};          Max1[sol_, t_] := First[Maximize[sol[x, t], 0 <= x <= L, x]];      I call NDSolve inside a loop on $k$:               Nk=3;          For[kk = 1, kk <= Nk, kk + 1,            sol1 = {θ, ϕ} /. First[NDSolve[{       eqn1[0.1, 0.13, 0.1, 0.08, 0.3, 0, 0] == 0,       eqn2[0.1, 0.13, 0.1, 0.08, 0.3, 0, 0] == 0,         **HERE, BOUNDARY CONDITIONS, I DO NOT WRITE THEM FOR SIMPLICITY**      θ[x, 0] == First[Initial[x, kk]],       ϕ[x, 0] == Last[Initial[x, kk]]}, {θ, ϕ}, {x,        0, L}, {t, 0, T}, AccuracyGoal -> 5, PrecisionGoal -> 4,       MaxSteps -> 200000]];           SolVec1[[kk]] = sol1[[1]];      SolVec2[[kk]] = sol1[[2]];           MaxVec1[[kk]]=Max1[sol1[[1]],t];      MaxVec2[[kk]]=Max1[sol1[[2]],t];          ]      Where I filled the various arrays. First question >> This doesn't work, it gets stuck in the loop. Why? Second question >> I would like to plot the different solutions (which will be saved in SolVec1,2) on the same graph, with different colors. For example for the different initial conditions:               Plot[{SolVec1[[n]][x, 0]}, {n, 1, Nk}, {x, 0, L}, PlotRange -> All]      does this make any sense? How could I do otherwise?


Generating a matrix using sublists A and B n times

I want to write a function that generates a square matrix from sublists. My sublists are `a = Range[0, x, 0.5]; b = Range[0.25, x + 0.25, 0.5];` Suppose x=2, then I can manually evaluate {a,b,a,b,a} to generate an 5x5 matrix. I want to make the matrix automatically, of course, but without using a loop. I've tried different ways to do it, with Nest, Range and Table, but I can't make it work. Do I absolutely have to use a loop?


How to plot a 2D region when there are 3 free parameters?

How could I obtain the region of payments, with the parameters a,b,c,d between 0 and 1 and the sum of all equals 1? After the comment/recommendation of belisarius... I edit the original question and.... ask you a question in the last line of code.               P = {{a, b}, {c, d}}          A = {{2, -1}, {0, 1}}         B = {{-1, 1}, {2, -1}}          A[[1]].P[[1]] + A[[2]].P[[2]]          f1[a_, b_, c_, d_] = A[[1]].P[[1]] + A[[2]].P[[2]]     f2[a_, b_, c_, d_] = B[[1]].P[[1]] + B[[2]].P[[2]]          ParametricPlot[{f1[a, b, c, d], f2[a, b, c, d]}, {  a, 0, 1}, {b, 0,        1}, {c, 0, 1}, {d, 0, 1} ]      In the last line, How Can I code for consider only a,b,c,d in [0,1] with a+b+c+d=1 ? It´s similar to obatin all the convex combinations of the points (a(i,j),b(i,j))


Scaling the x-axis in ListLogLogPlot[] or ListLogPlot[] in lieu of DataRange

I will present my existing workaround but I am wondering if there is a better solution that takes less time (my solution seems to ~double the time it takes to produce the desired plot). Using DataRange would be ideal, but I'm either missing something or it doesn't work when a ListPlot has logarithmic axes. I have some data in a list (1D) that I'm plotting with ListLogLogPlot. I know that the x-values should range from 1 to 5000; with ListPlot I would just use DataRange to take care of this. However, DataRange seems to do nothing when using ListLogPlot or ListLogLogPlot. Let's do an example:                   fakedata = Table[1/x, {x, 1, 100, .1}];         ListLogLogPlot[fakedata, Frame -> True, ImageSize->500]      ![enter image description here](http://i.stack.imgur.com/rsmEb.png) Adding DataRange->{1,5000} does nothing to the plot. I can instead make a new list, composed of the x-values since I know they should vary linearly from 1 to 5000 over the length of the data:                   sol = Solve[1 == m + b && 5000 == m*Length@fakedata + b, {m, b}];         fakexvals =             Table[Evaluate[x*m + b] /. First@sol, {x, 1, Length@fakedata}];      Using this new list, I can get the desired plot:                   ListLogLogPlot[Transpose[{fakexvals, fakedata}], Frame -> True,          ImageSize -> 500]      ![enter image description here](http://i.stack.imgur.com/DaFaC.png) This is _ok_ for this example, but it becomes cumbersome with the data set is large. It appears to take Mathematica roughly twice as long to create the list plot from x-y pairs versus just y-values. I have some data sets with 200,000 points and for these generating a list plot from {x,y} pairs takes between 10-20 seconds.


Tell ParallelMap[] to use just specific kernels

Is there a way to tell `ParallelMap` to use just some specific kernels (as is possible for `ParallelEvaluate`)? **Background:** I have 6 local and 16 remote kernels. During some analysis I call `ParalleMap` twice. One `ParallelMap` is quicker using all the kernels, but one is actually slower (probably bandwidth limited). This is why I would like to run one `ParallelMap` on all the kernels and the other only on the local kernels. I don't want to close the kernels in between if possible. I also tried setting the parallelization method to `"CoarsestGrained"` or `"FinestGrained"`, but that didn't help much. **Edit:** Could somebody shed light on why the following does not work?               num = 10;     list = Range[num];     function = Labeled[Framed[#], $KernelID] &;     ParallelMap[function, list]     aKer = Kernels[];     Block[{Parallel`Protected`$kernels = aKer[[{2, 3}]]},        ParallelMap[function, list]     ]      ![Mathematica graphics](http://i.stack.imgur.com/M9OxY.png) The second map is still run on 4 of the Kernels instead of just two. I traced `ParallelMap` to               Parallel`Developer`ParallelDispatch[Parallel`Combine`Private`cmdl]      and               Parallel`Developer`ParallelDispatch[Parallel`Parallel`Private`cmds_] :=         Parallel`Developer`ParallelDispatch[Parallel`Parallel`Private`cmds,Kernels[]]     Kernels[]:=Parallel`Protected`$kernels      so overriding `Parallel`Protected`$kernels` should in theory work.