How to use DegreeGraphDistribution with directed graphs?

`DegreeGraphDistribution` supports directed graphs because it has a `DirectedEdges` option. How can I specify the in-degree sequence and the out-degree sequence separately when generating random _directed_ graphs? For example,               RandomGraph@DegreeGraphDistribution[{2, 2, 1, 1}, DirectedEdges -> True]      gives a graph where the vertices have the following {in, out} degree combinations: `{{2,2}, {2,2}, {1,1}, {1,1}}`. This syntax worked, but the in and out-degree sequences are identical for each vertex. How can I specify them separately? * * * I'd like to note that as a workaround it is possible to use igraph's `degree.sequence.game` function through the IGraphR package. However, now I am looking to do this in pure Mathematica though. If you do end up using igraph, be sure to read the documentation in detail, and be aware of the quirks of each method that is available (does it guarantee uniform sampling? does it produce simple graphs? does it support directed graphs? there are several options).


Construct a simple mesh or tetrahedral mesh from 3D image surface

I have a 3D Y-Shape hollow tube, not so good surface.                Import["http://dl.dropbox.com/u/68983831/tube02.vtk", "Graphics3D"]      ![enter image description here](http://i.stack.imgur.com/A2k9g.png) I tried to use following vertex data plot and generate mesh.               pts = Import["tube02.vtk", "VertexData"];     Graphics3D[Point@pts]      ![enter image description here](http://i.stack.imgur.com/5LztT.png) Question: How to plot a smooth surface from vertex data and then generate tetrahedral or simple mesh? I was trying to use following thread to solve my problem: How to calculate volume of convex hull and volume of a 3D object and My donut has holes in it!.


Combination of a Contourplot and a Graphics Object

I want to combine the following to graphs.               cartPoints = Table[With[{x = RandomReal[]}, {1/(2*Pi), ArcCos[x]}], {10}];     Graphics[Arrow[{{0, 0}, #}] & /@ CoordinateTransform["Polar" -> "Cartesian", cartPoints],      Frame -> True, FrameTicks -> None, AspectRatio -> 1,      PlotRange -> {{0, 1/(2*Pi)}, {0, 1/(2*Pi)}},      FrameLabel -> {{"z", ""}, {"y", ""}},      LabelStyle -> { FontFamily -> "Arial", FontSize -> 14},      BaseStyle -> {FontFamily -> "Arial", FontSize -> 14}]          ContourPlot[Cos[x^2 + y^2], {x, -Sqrt[Pi]/2, Sqrt[Pi]/2}, {y, -Sqrt[Pi]/2,      Sqrt[Pi]/2}, FrameLabel -> {{"x", ""}, {"y", ""}},      LabelStyle -> { FontFamily -> "Arial", FontSize -> 14},      BaseStyle -> {FontFamily -> "Arial", FontSize -> 14}]      How can I arrange both graphs in 3D? The Countourplot should be the bottom of the resultung graph and the arrows should point in z direction


Keeping vertexcoordinates after adding a new vertex

I want to add a new vertex to a graph, with fixed VertexCoordinates but when I use VertexAdd, the new graph does not have the VertexCoordinates of the previous one.               g = Graph[{1 -> 2}, VertexCoordinates -> {{0, 0.5}, {0.5, 0}},        PlotRange -> 1]      This is the initial graph               g = VertexAdd[g, 3]      Adding a new vertex makes a new graph with automatic coordinates. I tried to see if there is a way to define the coordinates when adding a new vertex but I could not find anything. Also I was looking if there is something like:               SetProperty[g, VectorCoordinates -> {list of coordinates}]      To set coordinates for all vertices in a graph, but I could not find anything.


How to combine elements of two matrices?

Given two matrices m1 and m2, e.g.:               m1 = {{a1, b1}, {c1, d1}}     m2 = {{a2, b2}, {c2, d2}}      How can one obtain the following?               {{f[a1, a2], f[b1, b2]}, {f[c1, c2], f[d1 ,d2]}}      I found this solution               MapThread[f, {m1, m2}, 2]      Is there a simpler way?


Question with ParametricNDSolveValue

When solving the following system:               g[a_,b_] := c /. FindRoot[a + b == c, {c, 0}]          pf =        ParametricNDSolveValue[{y''[x] == g[a,b] y[x] Cos[x + y[x]],          y[0] == a, y'[0] == 1}, Integrate[y[s]^2, {s, 0., b}], {x, 0, b}, {a, b}];      _Mathematica_ gives me two error messages, which say: > FindRoot::nlnum: The function value {0. +a+b}is not a list of numbers with > dimensions {1} at {c} = {0.}. >> > > ReplaceAll::reps: {FindRoot[a+b==c,{c,0}]} is neither a list of replacement > rules nor a valid dispatch table, and so cannot be used for replacing. >> How can I fix this issue?


Using the same frame ticks for two different histograms

Consider the following:               SetOptions[Histogram, BarOrigin -> Left,        Frame -> {{True, None}, {True, None}}, FrameTicks -> Automatic];          data1 = {Table[1, {i, 5}], Table[5, {i, 50}], Table[3, {i, 25}],         Table[4, {i, 20}]};     data2 = {Table[1, {i, 3}], Table[5, {i, 20}], Table[3, {i, 25}]};     data3 = {Table[1, {i, 3}], Table[5, {i, 20}], Table[4, {i, 15}]};          histo1 = Histogram[data1]     histo2a = Show[Histogram[data1, ChartElements -> None],Histogram[data2]]     histo3a = Show[Histogram[data1, ChartElements -> None],Histogram[data3]]          histo2b = Show[Histogram[data1], Histogram[data2, ChartStyle -> Red]]         histo3b = Show[Histogram[data1], Histogram[data3, ChartStyle -> Red]]      I would like to use the same frame/coordinate system for `histo2a` and `histo3a` as in `histo1`. `histo3b` shows how it should be (only without the grey part) and `histo2a` how it should not be. `histo2b`in addition shows the disadvantage of the `Show[]`-approach (one bar exceeds the frame). Due to the latter, I was trying to extract the FrameTicks-values from `histo1` and to use them for `Histogram[data2]` and `Histogram[data3] but neither`Options[histo1,FrameTicks]`,`AbsoluteOptions[histo1,FrameTicks]`nor`HistogramList[data1]` return help. Now I would like to use exactly the same frame ticks, which were calculated based on `data1` for `histo2`. Neither `Options[histo1,FrameTicks]`, `AbsoluteOptions[histo1,FrameTicks]` or `HistogramList[data1]` help. Has anyone an idea?


Generating a non-convex polyhedron from a list of vertex coordinates

I want to include a figure in a paper I am writing on Combinatorial Geometry which features a non-convex polyhedron given by the following vertices, EDIT: I was unaware that Mathematica could convert coordinates from spherical to Cartesian, so I will post the correct spherical coordinates as follows:               {{0, 0, 0}, {1, 0, 0}, {1, Pi/3, 0}, {1, Pi/3, ArcCos[1/3]},      {1, Pi/3, 2 ArcCos[1/3]}, {1, Pi/3, 3 ArcCos[1/3]},      {1, Pi/3, 4 ArcCos[1/3]}, {1, (2 Pi)/3, (ArcCos[1/3])/2},      {1, (2 Pi)/3, (3 ArcCos[1/3])/2}, {1, (2 Pi)/3, (5 ArcCos[1/3])/2},      {1, (2 Pi)/3, (7 ArcCos[1/3])/2}, {1, (2 Pi)/3, (9 ArcCos[1/3])/2}, {1, Pi, 0}}      Does anyone know how I can generate such a figure using Mathematica? I assume I will need to also somehow define which vertices are connected by an edge with a list, but I am unsure how I would do that as well. I have tried using the "Computational Geometry Package", and have been reading through the tutorial for about an hour, but I have no idea what a "vertex adjacency list" is or how I could make this work in 3-dimensions; the package tutorial seems to only comment on triangulations in the plane, etc. Any help is greatly appreciated! EDIT: I will attempt to describe this non-convex polyhedron and include pictures and a figure. ![Real image](http://i.stack.imgur.com/8d9hA.jpg) ![figure](http://i.stack.imgur.com/m4L7M.png) I will quote from my paper: > The inspiration for constructing a simplicial 3-complex $\mathcal{K}$ for > which 12 tetrahedra touch at a vertex comes from the configuration of 4 > tetrahedra sharing an edge; see Figure 3. Let $v_{0}=(0,0,0)$ be the origin > and connect the two vertices $v_{1}=(1,0,0)$ and $v_{12} = (-1,0,0)$ to > $v_{0}$ by an edge. Label these edges as $e(v_{0}v_{1})$ and > $e(v_{0}v_{12})$ and notice that their union forms a straight line of length > 2 in $\mathbb{E}^3$. Around each of these edges we arrange four tetrahedra > as in Figure 3, and we rotate the cluster of four tetrahedra sharing edge > $e(v_{0}v_{12})$ by $\pi/6$ in order to ensure that an extra four tetrahedra > will fit in between the two clusters of 4 tetrahedra (explained in more > detail later). Considering the vertices of these tetrahedra, we obtain a > point set $P$ (with $|P|=12$) where the minimum distance which can occur any > of the points is of unit length. Figure 3: in the context of my paper, this figure shows that at most 4 tetrahedra can share an edge with conditions I impose. If you imagine one of the tetrahedra removed so that there is a bigger space, these are the "clusters of 4 tetrahedra" I described above. ![figure 3](http://i.stack.imgur.com/GKAcn.png) * * * (The bonus question was solved, thank you Mr. Wizard.) BONUS: If anyone knows how to check with Mathematica if all of the points are at least a distance of 1 away from each other that would be very helpful.


Crash with subsetting TemporalData

The first line gets a single sample path for an M/M/1 queue for time between 0 and 100. No problem, I can plot it, etc.               td = RandomFunction[QueueingProcess[9, 10], {0, 100}, 1];      Next, I want to look at the sample path of the process between time 10 and 50, so I do               subset = td["Part", 1, {10, 50}];      and MMA crashes on me. Ver 9.0.1.0 on windows 7 64 bit. Any suggestions?


How to create animated snowfall?

Well, the title is self-explanatory. What sorts of snowfall can we generate using _Mathematica_? There are two options I suggest to consider: 1) Continuous GIF animations with smallest possible number of frames. 2) `Dynamic`-based animations.


Transparency rendering problems in Mathematica 10 (Mac)

For some weird reason, they apparently changed the styling of contours in ContourPlot for 10.0. Here is a comparison of the results for V9 and V10 (first 9, then 10):               ContourPlot[Sin[x y], {x, 0, 3}, {y, 0, 3},          ContourShading -> None,  ContourStyle -> {{Red, Thickness[0.008]}}]      ![Mathematica 9 output](http://i.stack.imgur.com/UUxhg.png) Version 9 ![Mathematica 10 output](http://i.stack.imgur.com/QxZ3N.png) Version 10 Firstly, can I override the coloring? I would like to keep the solid colors that were in V9. And secondly, where do those dark spots come from? Is this a bug? Edit: yes, this does look like a bug. The dark spots are only visible in the Mac version. Interestingly enough, for about half a second after the output appears, what I see on the screen is similar to what `Export` produces (shown below). The only difference is that the lines are thinner in the exported .png (another bug?). After those 0.5 seconds, another level of transparency kicks in and I see what is shown in the top picture below.               ContourPlot[Sin[x y], {x, 0, 3}, {y, 0, 3},          Contours -> {.9}, ContourShading -> None,          ContourStyle -> {{Red, Thickness[0.17]}}]      ![enter image description here](http://i.stack.imgur.com/3pz2e.png) <\- What I see. ![enter image description here](http://i.stack.imgur.com/9HQzI.png) <\- What `Export` produces.


How to incorporate a matrix in a For loop?

I would like the equivalent of:               For[x = 0, x less than Infinity, x++]             For[y = 0, y less than Infinity, y++]                 m = Table[(x, x-2 y, x-2 y, 0, 0, 0), (x-2 y, x, x-2 y, 0, 0, 0),                      (x-2 y, x-2 y, x, 0, 0, 0), (0, 0, 0, 2 y, 0, 0),(0, 0, 0, 0, 2 y, 0),                      (0, 0, 0, 0, 0, 2 y)]      I then would like to include an "if-else" statement where I print only the largest possible matrix. (i.e. If `m` is less than `m`, continue running through loop until it finds the largest `m`, then print it). I have another matrix, `l`, where I need to minimize the distance between `l` and `m`, hence requiring the largest possible matrix for `m`. Could you help me with this?


Using different random values at each recursion step

I have the following code:               ϕ[0] := π/4     ϕ[n_] := Exp[-n] ϕ[n - 1] + Sqrt[1 - Exp[-2 n]] M     M = RandomVariate[NormalDistribution[0, 1]]      For this recursion relation, is the normal deviate taking a random variable during each recursion or is it just taking one for the whole recursion process? Thanks,


Numerically integrating a list-valued function

I want to `NIntegrate` a `List` valued function `foo[x]` which is only defined for numerical arguments `x`. Here is a simple toy example:               foo[x_?NumericQ] := {x^2, x^3};     NIntegrate[foo[x], {x, 0, 1}]      It gives the following error > >     NIntegrate::inum: Integrand foo[x] is not numerical at {x} = > {0.00795732}. >> >     NIntegrate::inum: Integrand foo[x] is not numerical at {x} = > {0.00795732}. >>. >   Note that the symbolic definition `fooS` works fine:               fooS[x_] := {x^2, x^3};     NIntegrate[fooS[x], {x, 0, 1}]     (*{0.333333, 0.25}*)      What causes the error? It seems to be crucial that the function `foo` is `List` valued. When I `NIntegrate` each component separatly, the error does not occur:               foo1[x_?NumericQ] := foo[x][[1]];     foo2[x_?NumericQ] := foo[x][[2]];     {NIntegrate[foo1[x], {x, 0, 1}], NIntegrate[foo2[x], {x, 0, 1}]}     (*{0.333333, 0.25}*)      and even               NIntegrate[{#1, #2} & @@ {foo1[x], foo2[x]}, {x, 0, 1}]     (*{0.333333, 0.25}*)


How to find the domain and range of a function with Mathematica?

I'm studying calculus and in some exercises I am asked to find the domain and range of a function. Does _Mathematica_ have already a built-in function for this? I can imagine some ways of doing so, but at the moment I want to know if there's a built-in function or some easy way of doing it.


How to compute MIN$(A(x), B(x))$

I have two polynomials: $\;A(x) = \sum a_i\;x^i$, $\quad B(x) = \sum b_i\;x^i$.   Given $A(x)$, $B(x)$, I want to compute $\;C(x) = $MIN$(A(x), B(x)) = c_i\;x^i$ where $c_i = $MIN$(a_i, b_i)$. How can I do it automatically in _Mathematica_?


Creating custom functions with multiple arguments

I am hoping that this isn't a stupid question so feel free to vote it for closure. Google failed somehow. I want to define a custom function (more complicated than the usual `f[x_] := someExpression`) that performs several tasks (taking elements of a set, performing computations, etc.) before giving an output. I don't want to run the whole bunch of codes repeatedly. Is there a way of defining such a function? What I have in mind is, say a program in R, which goes like               function_name <- function(arg1, arg2, ..., argn){         routine 1         routine 2         routine 3         ...         Output to be returned     }      EDIT: In view of the comment that this question is somewhat vague, I am posting part of the code below:               Final = {{1}};     For[hn = 0, hn < 7, hn++;      rp = {0}; fn = hn;      For[fk = 0, fk < fn, fk++;        Clear[r, v, w, p, q, z, x, n, k, t, res, pt];        v[z_] := Sum[q^d, {d, 0, z - 1}];        n = fn; k = fk; t = {}; For[i = 0, i < (n - k), i++;          For[j = -1, j < k, j++; t = Join[t, {j}];]];        t = KSubsets[t, (n - k)];        For[i = 0, i < Length[t], i++;          t[[i]] = Sort[t[[i]]]];        t = Union[t];      The code is quite long (sloppy programming). I just want the whole thing to be given a name so that I can just type that name of that function and vary the arguments.


About minimizing calculations when using ComposeList

I have a lot of functions to use in a iterative way, and I need some of the calculation results. For example:                func = Function[{s}, s Sin[#] &] /@ Range[100];      ComposeList[func, x][[1 ;; ;; 10]]       Apparently, this code calculates much more than necessary. Especially, a lot of time is needed for the calculation when the length of `func` list is very long and when the `Function` is very complicated (e.g. `Length@func = 1024` and the function is `Fourier`); **Is there any elegant way to reduce the calculation?** _**Edit_** Perhaps I should say more about the fact that this code calculates than necessary. For example,                 func = Function[{s}, s Sin[#] &] /@ Range[10];        result=ComposeList[func, x][[1 ;; ;; 5]]      (* {x, 5 Sin[4 Sin[3 Sin[2 Sin[Sin[x]]]]], 10 Sin[9 Sin[ 8 Sin[7 Sin[6 Sin[5 Sin[4 Sin[3 Sin[2 Sin[Sin[x]]]]]]]]]]} *) Now we can see that result[[2]] (i.e., 5Sin[4 Sin[3 Sin[2 Sin[Sin[x]]]]]) is also appeared inside result[[3]] (i.e., 10Sin[...5Sin[4 Sin[3 Sin[2 Sin[Sin[x]]]]]], so the evaluation for 5Sin[4 Sin[3 Sin[2 Sin[Sin[x]]]]] is repeated twice here. The repetition will be very large with an increase of Length[func], which will be much more time-consuming than it is required. This is my point here (Up to now, Rojo has gotten the point and solved it ).


Assumptions with D

I want to give assumptions for the `D` function. Say I want to calculate $\frac{d|x|}{dx}$ for $x>0$, which is 1. I write `D[Abs[x], x, Assumptions -> x > 0]` which gives `D::optx: Unknown option Assumptions in D[Abs[x],x,Assumptions->x>0]. >>` Why doesn't D take assumptions?


Clickable Bounded Diagram

Suppose I make a `BoundedDiagram` via the following code               Needs["ComputationalGeometry`"];     data2D = RandomReal[{0, 10}, {10, 2}];     b1 = {{0, 0}, {11, 0}, {11, 11}, {0, 11}};     convexhull = ConvexHull[data2D];     delval = DelaunayTriangulation[data2D];     {vorvert, vorval} = VoronoiDiagram[data2D];     {dvert1, dval1} = BoundedDiagram[b1, data2D, delval, convexhull];     DiagramPlot[data2D, dvert1, dval1]      How would I go about making each region clickable, i.e. open some link that I associated with the data? \-- Edit: I should note, all I really want is a to be able to click on regions of a Voronoi-Like diagram, it doesn't have to be done via BoundedDiagram, this is just my first attempt at doing that ... (and is basically straight from the documentation.)


Calculating the volume under a surface with Riemann sum

I have a set of xyz data points. X and Y are coordinates of a regular grid of 10x10 units, Z is the independent variable. I am trying to calculate the volume under the set of points, using Riemann sum. I have used two approaches that I expected to produce the same result, and on the contrary, produce very different results. In the first approach I make a sum of the volumes of the prism formed by every point. In the second approach I make an interpolation function with an interpolation order of 0, and then integrate it. Here is a MWE of the code I'm using:               Data = {{{230, 310}, 0.4434}, {{230, 320}, 0.5078}, {{230, 330},      0.6000}, {{230, 340}, 0.6430}, {{230, 350}, 0.6724}, {{230, 360},      0.7204}, {{230, 370}, 0.7593}, {{230, 380}, 0.7987}, {{230, 390},      0.8908}, {{230, 400}, 1.0175}, {{230, 410}, 1.1136}, {{230, 420},      1.2342}, {{230, 430}, 1.3375}, {{230, 440}, 1.4055}, {{230, 450},      1.3979}, {{240, 310}, 0.4593}, {{240, 320}, 0.3963}, {{240, 330},      0.3985}, {{240, 340}, 0.3877}, {{240, 350}, 0.4262}, {{240, 360},      0.4763}, {{240, 370}, 0.5465}, {{240, 380}, 0.6163}, {{240, 390},      0.7376}, {{240, 400}, 0.8567}, {{240, 410}, 0.9769}, {{240, 420},      1.1350}, {{240, 430}, 1.2960}, {{240, 440}, 1.4032}, {{240, 450},      1.4310}, {{250, 310}, 0.5866}, {{250, 320}, 0.4513}, {{250, 330},      0.3789}, {{250, 340}, 0.3360}, {{250, 350}, 0.3273}, {{250, 360},      0.3526}, {{250, 370}, 0.4068}, {{250, 380}, 0.4520}, {{250, 390},      0.5269}, {{250, 400}, 0.6071}, {{250, 410}, 0.6807}, {{250, 420},      0.7808}, {{250, 430}, 0.8794}, {{250, 440}, 0.9572}, {{250, 450},      0.9682}};          Total[Data[[All, 2]]*100]          Integrate[Interpolation[Data, InterpolationOrder -> 0][x, y], {x, 230, 250}, {y, 310, 450}]      The first approach yields a volume of 3377.73, and the second one of 1918.94. Can someone explain the reason for this difference? Or which one is more appropriate for the purpose of estimating a volume? Any help will be very much appreciated.


How can I dynamically get a file whenever it is saved in Workbench?

I want to get a file once and only once at the start of a coding session. Then, whenever I save the file in the Wolfram Workbench, have it be gotten automatically. How can I construct such a utility?


Why doesn't Abs simplify further?

Why does this:               Simplify[Abs[x + I], Element[x, Reals]]      give me               Abs[x + i]      Is there a way to force Mathematica to give me the following answer? $\sqrt{x^2+1}$


X label in GraphicsColumn is cut off

I'm trying to use GraphicsColumn to plot two curves with very different ranges. for example,               GraphicsColumn[{Plot[Sin[x], {x, 0, 10}, PlotRange -> All,         AspectRatio -> 0.3, Frame -> True, Axes -> False,         ImageMargins -> 20],        Plot[Cos[x], {x, 0, 10}, PlotRange -> All, AspectRatio -> 0.3,         Frame -> True, Axes -> False, ImageMargins -> 20]},       Epilog -> {Text["Frequency", {Center, Bottom}],         Rotate[Text["Power", {0.5, Center}], 90 Degree]}]      But the x label is not displayed properly, i.e., it is cut by the edge of the graph. ![enter image description here](http://i.stack.imgur.com/yAVbL.jpg) How to improve it?


Integration strategies for oscillatory multidimensional function

I am seeking to integrate a highly oscillatory, multidimensional function. I am currently using NIntegrate's QuasiMonteCarlo approach. However, this is time-consuming and, given my current resources, not very accurate. How can I obtain more reliable estimates of the beasty integral given below? As the function itself will be integrated at a later stage, I am also interested in speeding up the function evaluation. The integral to be solved:               fun[r_?NumericQ, d_?NumericQ, c_, opts:OptionsPattern[]]:=        NIntegrate[           Cos[(c (d^2+r^2-2 d r Cos[ta] - 3 ((-r+d Cos[ta]) Cos[tb]+d Cos[a] Sin[ta] Sin[tb])^2)) / Abs[d^2+r^2-2 d r Cos[ta]]^(5/2)]            Cos[(c (d^2+r^2+2 d r Cos[ta] - 3 ((r+d Cos[ta]) Cos[tb]+d Cos[a] Sin[ta] Sin[tb])^2)) / Abs[d^2+r^2+2 d r Cos[ta]]^(5/2)]           * Sin[ta]*Sin[tb]/(2*Pi),        {ta,0,Pi},        {tb,0,Pi/2},        {a,0,Pi},        Evaluate@FilterRules[{opts},Options[NIntegrate]]     ]      Typically, $d$ = 2, $r$ is in the range from 0 to Infinity (with the small values and $r$=$d$ posing problems), and $c$ is in the range from 100 to 3000. A typical function call is:               AbsoluteTiming[fun[3, 2, 400, Method -> "QuasiMonteCarlo", PrecisionGoal -> 6,      MaxPoints -> 40000000]]     (* -> {102.3215798,-0.00442278} *)      This issues a NIntegrate::maxp warning and indicates an error estimate of 0.00011. Using the default strategy I obtain:               AbsoluteTiming[      fun[3, 2, 400, MaxRecursion -> 20, Method -> {GlobalAdaptive, MaxErrorIncreases -> 10000}]]     (* -> {9.3912165,-0.00439357} *)      and a NIntegrate::eincr warning. Estimated error: 0.0369. How to proceed from here? Thank you for your help.


Figuring out how AbsoluteOptions works with Graphs

I am puzzled by how `AbsoluteOptions` works with `Graph` objects. I would have expected that one could use it to obtain all the options used to draw a graph. There are several ways in which it behaves contrary to my expectations. First, let' s make a simple graph, g, and set some custom options:               g = RandomGraph[{6, 11}, VertexStyle -> {1 -> Red, 2 -> Green},          VertexSize -> {1 -> Large, 2 -> Large}, VertexLabels -> "Name",          ImagePadding -> 15, EdgeLabels -> "Name", Axes -> True]      ![g](http://i.stack.imgur.com/cfx2X.png) **1 - Why won' t all the options work again?** One expects that the options used for `g` could be obtained through `AbsoluteOptions[g]` and redeployed. However, this does not work. Either the code below locks up completely or the Out cell has a tooltip: "$Failed is not a Graphics primitive or directive".               allOptions = AbsoluteOptions[g];     g2 = Graph[EdgeList[g], allOptions]      **2 - Some options work as expected, others do not. Why?** Let's take a subset of the options of `g`; namely, `{VertexCoordinates, EdgeLabels, Axes, VertexLabels, VertexSize, AlignmentPoint, ImagePadding}`. Now let's compare g and the partial replication, g3, side by side:               someOptions =        Sort@AbsoluteOptions[         g, {VertexCoordinates, EdgeLabels, Axes, VertexLabels, VertexSize,          AlignmentPoint, ImagePadding}]     g;     g3 = Graph[EdgeList[g], someOptions]     someOptions3 =           Sort@AbsoluteOptions[          g3, {VertexCoordinates, EdgeLabels, Axes, VertexLabels, VertexSize,          AlignmentPoint, ImagePadding}]          (* Out someOptions3*)     {AlignmentPoint -> Center, Axes -> {True, True},         EdgeLabels -> {"Name"}, ImagePadding -> 15.,         VertexCoordinates -> {{0.518253, 0.817802}, {1.61587,         0.866512}, {2.05896, 0.336143}, {1.03973, 1.21024}, {1.04431, 0.}, {0., 0.377097}},           VertexLabels -> {"Name"},      VertexSize -> {1 -> Large, 2 -> Large}}      ![g and g3](http://i.stack.imgur.com/xfqQd.png) The vertex sizes are the same in each case, as expected. Also, the `VertexStyle` is different. That's fine: g3 has the default vertex style. But why are the vertices in different locations? After all, we passed the `VertexCoordinates` option to g3. And the vertex coordinates returned by `AbsoluteOptions[g3...` do not correspond to the coordinates used for the vertices. **3 - What are failed options?** If we inspect the options used by g, we will notice that two of them failed, even though `g` was drawn with no apparent issues.               AbsoluteOptions[g, {VertexShapeFunction, EdgeShapeFunction}]          (* Out *)     {VertexShapeFunction -> $Failed, EdgeShapeFunction -> $Failed}      If you look at the graph, g, you see that the default vertex shapes and edge shapes were correctly rendered? So, whence the fail? **4 - Why is it insufficient to remove failed options?** If we remove the failed options and try to implement all the other options, MMA does one of two things: (1) It returns the unparsed `Graph` command or (2) it produces only a small portion of the graph, g. Any help would be appreciated. I'm not trying to correct a particular program but rather understand the strengths and limitations of `AbsoluteOptions.`


Sharpening extrema using DensityPlot

I have a data set where I really care mainly about visualizing the highest and lowest areas. DensityPlot suits my needs well, but ideally the maxima and minima would pop more from the rest of the data. I know that DensityPlot scales the data from your function to between zero and one before coloring it accordingly. I'd like to use a scaling that has more meat in the middle than theirs. So I was thinking I could take their scaling, and use it as an input to for example                (x-0.5)^3/8,       which has the properties `f[0]=0` and `f[1]=1`, but is better distributed for my purpose. Then I'd pass these values to the colorizer. Can't really figure out how to do this though. Any thoughts?


Tips on giving a lecture course using Mathematica

I've had a look at this question on giving presentations with Mathematica which is very useful on the technical side of setting up slideshows. However, my question is more about the integration of Mathematica with good teaching style. I shall shortly be giving an undergraduate lecture course on Mathematical Methods to engineers and others from non pure maths disciplines (it'll be from integration onwards) and am planning on using Mathematica as a teaching tool. One has to be careful with not letting technology take the place of good teaching but I would like to be able to use Mathematica effectively for showing the structure of a problem and the parametric dependencies of functions etc. - the perfect place for plenty of `Manipulate` usage. I hope to give at least 90% of my lectures in Mathematica and the rest on a blackboard - this is a wild estimate but it's what I'm aiming for. I would be grateful if anyone has undertaken such an exercise to give me possible pitfalls and pointers as to the best methods they've found to make Mathematica bring the maths to life, rather than confuse the students with a mass of fast-paced buttons, dynamic displays and notation. P.S I saw also this question on lecture courses with Mathematica, however again, these are examples and not descriptions of what went well and what didn't.


How to Show the "TemperatureMap" using Manipulate?

How to show the "TemperatureMap" in Manipulate?. ONLY the image, without text "ColorData..."               Manipulate[ Column[{Style["This is a Test... " -> DateString[] -> "  -  " -> i^2,18, Bold], Style["How to show ONLY the image of TemperatureMap in the last row?", 18,Darker@Red, Bold], ColorData["TemperatureMap"]}], {i, 1, 5}]      ![Temperature in Manipulate](http://i.stack.imgur.com/YBEfj.jpg)


Easy button or hot key to switch between `Working` and `SlideShow` Screen Environments to avoid trip to menu

When I edit a slide show it easy to copy whole slides in `Working` Screen Environment but nice to preview slides in `SlideShow` Screen Environment. ![enter image description here](http://i.stack.imgur.com/xo8ZD.png) _Mathematica_ has convenient interactive buttons to go to Full Screen mode and change slides. ![enter image description here](http://i.stack.imgur.com/5lyQy.png) **Is it possible to set up an easy button or hot key to switch between`Working` and `SlideShow` Screen Environments to avoid trips to menu? Maybe using `DockedCells` ? Any similar ideas ?**


Graphical solution of a a two-variable system containing an equation and an inequality

I'm currently studying atmospheric-gravity waves and their dispersion relations. I want to have look at values of $(x,y)$ that solve the following system : \begin{equation}\label{}(1) \left\\{ \begin{array}{rcr} (x+\frac{1}{2}y^{2})\exp(u^2)-y[u+\exp(u^2)]+u\exp(u^2)& = &0\\\ 2u(x+\frac{1}{2}y^{2})\exp(u^2)-y[1+u\exp(u^2)]+u^2& < &0\\\ \end{array} \right. \end{equation} where $x\in [0,1]$, $y\in[0,1]$ and $u\in[0,1]$. My goal is to plot the region $(x,y)$ where this system has a solution. How can I plot S in the $(x,y)$-plane.? The code for the first funtion :               f1[u_, x_, y_] := ((y^2)/2 + x)*Exp[u^2] - y*(u + Exp[u^2]) + u*Exp[u^2]     f2[u_, x_, y_] := 2*u*((y^2)/2 + x)*Exp[u^2] - y*(1 + u*Exp[u^2]) +  u^2      The problem is how to used : ContourPlot or RegionFunction to construct the surface S.


NMinimize stops with no more memory?

I am using NMinimize function for simulation based optimization. So my objective function is a simulation that runs for every combination of variable values evaluated by NMinimize function. However, the problem I have is the Nminimize function ceases after the first run (I am printing the time stamp for every iteration) and eventually after a long time gives me out of memory error. I even tried with different methods such as "RandomSearch" and "SimulatedAnnealing" with custom method parameter values, but in vain. Can some one pinpoint where I am going wrong? edit: My code is long, but as requested is given below:               f[a1_, a2_, a3_] := Module[{b1 = a1, b2 = a2, b3 = a3, L = 3, Flen = 1, Rlen = 1,SimTime = 60, Kj = 150,w = 20,Theta = 5, dt = 6,delta = 1,DemandDuration = 10,RMstart = 1,RMLocation = 3, TT = 0},           Print[DateString[]]; Vf = Theta w; dx = Vf dt/3600; capacity = w*Vf*Kj/(Vf + w);n = Round[Flen/dx];m = Round[SimTime/dt];p = Round[Rlen/dx];Rdensity = Table[0*i, {i, p}, {i, m}, {i, n}];Rflow = Table[0*i, {i, p}, {i, m}, {i, n}];Fdensity = Table[0*i, {i, n}, {i, m}];Fflow = Table[0*i, {i, n}, {i, m}];demand[n_, k_] := Min[k*Vf, n*capacity];supply[n_, k_] := Min[(n*Kj - k)*w, n*capacity];flo[demand_, supply_] := Min[demand, supply];den[k_, qin_, qout_] := k + (qin - qout)/Vf;     merge[n_, Fu_, Fd_, Rd_] := Min[1, supply[n, Fd]/(demand[n, Fu] + 0.01)]*demand[1, Rd]/delta;Nsupply[n_, k_, qsum_] := Min[(n*Kj - k)*Vf - qsum, n*capacity];     RM[x_, t_] := N[b1 x^2 + b2 x + b3];alpha[a_] := 1500*a/Flen;beta[a_] := 0.1*a/Flen;          For[k = 1, k <= n, k++,      For[i = 1, i <= p, i++, Rdensity[[i, 1, k]] = 0;];     For[j = 1, j <= DemandDuration, j++, Rdensity[[p, j, k]] = alpha[n*dx]*delta/Vf;     TT = TT + Rdensity[[p, j, k]]];];          For[j = 1, j <= 4, j++,      For[k = 1, k <= n, k++,      If[k == 1,        Rflow[[1, j, k]] =         merge[L, Fdensity[[k, j]], Fdensity[[k, j]],          Rdensity[[1, j, k]]],        Rflow[[1, j, k]] =         merge[L, Fdensity[[k, j]], Fdensity[[k - 1, j]],          Rdensity[[1, j, k]]]];      If[k == 1,        Fflow[[k, j]] =         flo[demand[L, Fdensity[[k, j]]], supply[L, Fdensity[[k, j]]]],        Fflow[[k, j]] =         flo[demand[L, Fdensity[[k, j]]],          supply[L, Fdensity[[k - 1, j]]] - Rflow[[1, j, k - 1]]*dx]];      If[k > 1 && j < m,        Fdensity[[k - 1, j + 1]] =         den[Fdensity[[k - 1,           j]], (Rflow[[1, j, k - 1]] - beta[(n)*dx]*Fflow[[k, j]])*dx +           Fflow[[k, j]], Fflow[[k - 1, j]]];       TT = TT + Fdensity[[k - 1, j + 1]];];      If[k == n && j < m,        Fdensity[[k, j + 1]] =         den[Fdensity[[k, j]], Rflow[[1, j, k]]*dx, Fflow[[k, j]]];       TT = TT + Fdensity[[k, j + 1]];];      For[i = 2, i <= p, i++,        If[i == RMLocation && j >= RMstart,         Rflow[[i, j, k]] =          Min[RM[k dx, j dt],           flo[demand[1, Rdensity[[i, j, k]]],            supply[1, Rdensity[[i - 1, j, k]]]]],         Rflow[[i, j, k]] =          flo[demand[1, Rdensity[[i, j, k]]],           supply[1, Rdensity[[i - 1, j, k]]]]];       If[j < m,         Rdensity[[i - 1, j + 1, k]] =          den[Rdensity[[i - 1, j, k]], Rflow[[i, j, k]],           Rflow[[i - 1, j, k]]];        TT = TT + Rdensity[[i - 1, j + 1, k]];]];];];     For[j = 5, j <= m, j++,      For[k = 1, k <= n, k++,      If[k == 1,       Rflow[[1, j, k]] =        merge[L, Fdensity[[k, j]], Fdensity[[k, j]],         Rdensity[[1, j, k]]],       Rflow[[1, j, k]] =        merge[L, Fdensity[[k, j]], Fdensity[[k - 1, j]],         Rdensity[[1, j, k]]]];     FQsum = 0;     For[r = 1, r <= Theta - 1, r++, FQsum = FQsum + Fflow[[k, j - r]]];     If[k == 1,       Fflow[[k, j]] =        flo[demand[L, Fdensity[[k, j]]], supply[L, Fdensity[[k, j]]]],       Fflow[[k, j]] =        flo[demand[L, Fdensity[[k, j]]],         Nsupply[L, Fdensity[[k - 1, j - Theta + 1]], FQsum] -          Rflow[[1, j, k - 1]]*dx]];     If[k > 1 && j < m,       Fdensity[[k - 1, j + 1]] =        den[Fdensity[[k - 1,          j]], (Rflow[[1, j, k - 1]] - beta[(n)*dx]*Fflow[[k, j]])*dx +          Fflow[[k, j]], Fflow[[k - 1, j]]];      TT = TT + Fdensity[[k - 1, j + 1]];];     If[k == n && j < m,       Fdensity[[k, j + 1]] =        den[Fdensity[[k, j]], Rflow[[1, j, k]]*dx, Fflow[[k, j]]];      TT = TT + Fdensity[[k, j + 1]];];     For[i = 2, i <= p, i++, RQsum = 0;      For[r = 1, r <= Theta - 1, r++,        RQsum = RQsum + Rflow[[i, j - r, k]]];      If[i == RMLocation && j >= RMstart,        Rflow[[i, j, k]] =         Min[RM[k dx, j dt],          flo[demand[1, Rdensity[[i, j, k]]],           Nsupply[1, Rdensity[[i - 1, j - Theta + 1, k]], RQsum]]],        Rflow[[i, j, k]] =         flo[demand[1, Rdensity[[i, j, k]]],          Nsupply[1, Rdensity[[i - 1, j - Theta + 1, k]], RQsum]]];      If[j < m,        Rdensity[[i - 1, j + 1, k]] =         den[Rdensity[[i - 1, j, k]], Rflow[[i, j, k]],          Rflow[[i - 1, j, k]]];       TT = TT + Rdensity[[i - 1, j + 1, k]];]];];];          TT]          NMinimize[{f[x, y, z], {x, y,z} \[Element] Integers}, {{x , 27, 30}, {y, 797, 800}, {z, 2497, 2500}}];      Ps. Also any suggestions to improve the performance of this code will be greatly appreciated!!


Calling functions which take their arguments interactively

Lets say I have a file named `test.m` containing some functions.               test[arg1_, arg2_] := (       Print[arg1];       Print[arg2];     )     test3[arg1_, arg2_] := (       Print[arg1];       Print[arg2];     )      What would be a good way to generate a list of butons that would allow you to invoke the functions easily? For example. ![enter image description here](http://i.stack.imgur.com/3l0yK.png) The tricky part here (and is mainly why I am asking this question) is calling the functions, which will have several different argument types? I had thought about using an `InputField` with a `MessageDialog`, but I would bet there is better way to incorporate _Mathematica_ 's features.               ClearAll[loadFile];     loadFile[path_String?FileExistsQ] := DeleteCases[ToExpression[         FromCharacterCode[BinaryReadList[path]]         , InputForm, HoldComplete], Null];     x = ReleaseHold[        loadFile["test.m"] /.         HoldPattern[sym_[args__] := eval_] :>          Button[sym, eval]        ];     x[[0]] = List;     x


How to get list of duplicates when using DeleteDuplicates?

This might be easy, but can't find a way to use `DeleteDuplicates` to get also list of the actual duplicates. Example:               lstA = {1, 2, 4, 4, 6, 7, 8, 8};     r = DeleteDuplicates[lstA]     (* {1, 2, 4, 6, 7, 8} *)      I also wanted to get list of the actual duplicates, which are `{4,8}` in this example. It would have been nice if `DeleteDuplicates` would also return those, but there is no option there for that. I do not know what many Mathematica functions do not return back more useful information when called. Many seem to return one piece of information only, and one has to call another function to get another piece of information. For example, here `DeleteDuplicates` could had an API like this               {r,d}=DeleteDuplicates[lst]      and `r` will contain the list after duplicates are moved, but `d` would contain the actual list of duplicates. To make it even more useful, it can be               {r,d,p}=DeleteDuplicates[lst]      Where `p` will be the positions of the duplicates in the original list. Matlab seems to do it this way. Many functions there can return more than one piece of information at a time. This might be due to WL being functional programming language, and designed for cascading function calls, where each function only does one thing at a time. I am not sure now. DeleteDuplicates.html


How to efficiently process pasted content from PDF

I had selected a matrix in a PDF file, ![Mathematica graphics](http://i.stack.imgur.com/rg5tt.png) and paste it onto my MMA notebook. Below is the exact copy-pasted content:               0.9034 "NAN" 0.7163 0.8588     0.3031 0.5827 0.2699 0.8063     0.0418 0.8426 "NAN" 0.8634     "NAN" 0.8913 0.0662 0.8432      I want to display this content in the matrix form as shown in the original PDF. Thankfully there was no distortion when the content was transferred; however, the white spaces now became implied multiple signs in MMA. ![Mathematica graphics](http://i.stack.imgur.com/3I5dx.png) * * * **My solution** **1)** Convert content to string by simply wrapping it in `""` **2)** I then ran into the problem of the `"NAN"`'s becoming apart from the overall string due to its being wrapped by a pair of `""` previously. I couldn't find a quick way to assimilate them back into the larger string but to manually modify them (by adding a pair of `\`'s such that `"NAN"` became `\"NAN\"`: ref) ![Mathematica graphics](http://i.stack.imgur.com/LMHz5.png) ![Mathematica graphics](http://i.stack.imgur.com/1xn1T.png) ![Mathematica graphics](http://i.stack.imgur.com/VE1aQ.png) **3)** Use `StringSplit` twice, first to split the string at each line break `"\n"` to create 4 "lines"/sublists, and then map it the second time to each line at the `","` to create separate elements for each line.               StringSplit[#, {" "}] & /@ StringSplit[%, "\n"]     (* {{"0.9034", "\"NAN\"", "0.7163", "0.8588"}, {"0.3031", "0.5827",        "0.2699", "0.8063"}, {"0.0418", "0.8426", "\"NAN\"",        "0.8634"}, {"\"NAN\"", "0.8913", "0.0662", "0.8432"}} *)      **4)** Replace each `"\"NAN\""` with a simple `"NAN"`               % /. "\"NAN\"" :> "NAN"     (* {{"0.9034", "NAN", "0.7163", "0.8588"}, {"0.3031", "0.5827", "0.2699",        "0.8063"}, {"0.0418", "0.8426", "NAN", "0.8634"}, {"NAN", "0.8913",        "0.0662", "0.8432"}} *)      **_Sidestep_** : I tried to do this step more generally (since the string enclosed by `\"` might be more varied in future cases), by doing this:               % /. "\""~~x___~~"\"" :> x      This did not work, probably because `ReplaceAll` couldn't handle more complex string replacements (e.g. involving blanks). As a result, I tried `StringReplace`, and it worked as expected:               Map[StringReplace[#, "\"" ~~ x___ ~~ "\"" :> x] &, %, {2}]     (* {{"0.9034", "NAN", "0.7163", "0.8588"}, {"0.3031", "0.5827", "0.2699",        "0.8063"}, {"0.0418", "0.8426", "NAN", "0.8634"}, {"NAN", "0.8913",        "0.0662", "0.8432"}} *)      **One-step summary**               Map[StringReplace[#, "\"" ~~ x___ ~~ "\"" :> x] &,        StringSplit[#, {" "}] & /@ StringSplit["0.9034 \"NAN\" 0.7163 0.8588         0.3031 0.5827 0.2699 0.8063         0.0418 0.8426 \"NAN\" 0.8634         \"NAN\" 0.8913 0.0662 0.8432", "\n"], {2}] // MatrixForm      ![Mathematica graphics](http://i.stack.imgur.com/btfQe.png) * * * **My question is:** Could anyone help me think of a more elegant/efficient way to get the same result? The greatest bottleneck, I think, is the manual adding of `\`'s, so I'd love to hear how you can do that programmatically.


Is there a built-in procedure for simultaneous diagonalization of a set of commuting matrices?

Given a set $\\{A_1,...,A_m\\}$ of $m$ commuting $N\times N$ diagonalizable matrices, it is known that there exists a basis of eigenvectors $\Lambda$ that simultaneously diagonalizes all the $A_i$. Is there an automated way to compute $\Lambda$ in Mathematica? For a pair of matrices $\\{A_1,A_2\\}$ it can be done "by hand" using `Eigenvectors` to first compute the eigenvectors $\Lambda_1$ of $A_1$, finding similarity transforms $P_k$ that act on the degenerate subspaces of $\Lambda_1$ to make them also eigenvector of $A_2$, and then combining the transformed degenerate subspaces together to form $\Lambda$, but I don't know how to generalize this to more than 2 matrices.


Plotting implicitly-defined space curves

It is known that space curves can either be defined parametrically, $$\begin{align*}x&=f(t)\\\y&=g(t)\\\z&=h(t)\end{align*}$$ or as the intersection of two surfaces, $$\begin{align*}F(x,y,z)&=0\\\G(x,y,z)&=0\end{align*}$$ Curves represented parametrically can of course be plotted in _Mathematica_ using `ParametricPlot3D[]`. Though implicitly-defined plane curves can be plotted with `ContourPlot[]`, and implicitly-defined surfaces can be plotted with `ContourPlot3D[]`, no facilities exist for plotting space curves like the intersection of the torus $(x^2+y^2+z^2+8)^2=36(x^2+y^2)$ and the cylinder $y^2+(z-2)^2=4$: ![torus-cylinder intersection](http://i.stack.imgur.com/ODFj1.png) Sometimes, one might be lucky and manage to find a parametrization for the intersection of two algebraic surfaces, but these situations are few and far between, especially if the two surfaces are of sufficiently high degree. The situation is worse if at least one of the surfaces is transcendental. > How might one write a routine that plots space curves defined as the > intersection of two implicitly-defined surfaces? It would be preferable if the routine returns only `Line[]` objects representing the space curve. A routine that handles only algebraic surfaces would be an acceptable answer, but it would be nice if your routine can handle transcendental surfaces as well. A bonus feature for the routine might be the ability to determine if the two surfaces given do _not_ have a space curve intersection, or intersect only at a single point, or other such degeneracies.


Plotting a curve in 3D

Say I have two polynomials in $\mathbb{R}[X,Y,Z]$, whose intersection of zero loci correspond to a curve in the 3D space. What is the best way to plot the curve? ## Example: $$ f = X^2+Y^2-Z^2, \qquad g = 2X^3+Y^3-Z $$ I want to plot the curve given by $$ \begin{cases} &X^2+Y^2=Z^2 \\\\\\\ &2X^3+Y^3=Z \end{cases} $$


How can I commit files to Github by Mathematica?

# How can I publish Notebooks to Github via using Mathematica? * * * I'm on windows 8.1 x64, _Mathematica_ 9. How can I upload the current notebook to Github? My function expected is: `Notebook2Github[EvaluationNotebook[]]` Now I've installed Github on Windows, and have one test page The **annoying** thing is that each time I added/modified a new file in the destination folder(`E:\Users\HyperGroups\Documents\GitHub\hypergroups.github.com`), I should open GitHub, and add something into the `uncommitted changes` fields and click the `sync` button(shown in the picture) ![enter image description here](http://i.stack.imgur.com/10jQA.png) How can I avoid doing that and complete all such things by the function `Notebook2Github`. * * * ### My tries in Git Shell I can use the following commands in the GitShell. `git add [new file]` /`git commit` and `git push` and the new file will be updated to GitHub.


Deleting parts of a large list

At present I am running an analysis on economic data. Within the data I was able to identify countries which went through recession. I then calculated for example the average decline rate of GDP during recession. All my results are in the following list:               CompleteQuarterlyStatData      In this list I had to keep also all the countries which did not go through a recession. So if I ask for the decline rate of Australia during recession I get the following answer:               In[1328]:= CompleteQuarterlyStatData[[1]][[1]][[1]]          Out[1328]= {{"Australia", "AUS", "other countries", "GDP","quarterly data"}, {}}      Whereas position 1 (`CompleteQuarterlyStatData[[i]]`) indicates the key figure (in the above example "decline rate during recession"), position 2 (`CompleteQuarterlyStatData[[i]][[j]]`) the economic indicator (in the above example "GDP") and position 3 (`CompleteQuarterlyStatData[[i]][[j]][[k]]`) the country (in the above example "Australia"). (by the way: In total I have nine key figures (so `i` ranges from 1 to 9), 24 economic indicators (`j` ranges from 1 to 24) and 32 countries (`k` ranges from 1 to 32)) As Australia obviously did not got through a recession I want to get rid of all key figures for Australian GDP, which works with the following code:               If[      NumberQ[CompleteQuarterlyStatData[[1]][[1]][[2]][[2]]] == False,       Table[       Delete[CompleteQuarterlyStatData, i],       {i,        Map[        Part[#, 1 ;; 3] &,         Position[CompleteQuarterlyStatData,CompleteQuarterlyStatData[[1]][[1]][[2]][[1]]]]       }      ]     ];      (Note: Position 2 of `CompleteQuarterlyStatData[[1]][[1]][[2]]` is `{}` and `CompleteQuarterlyStatData[[1]][[1]][[2]]` `{"Australia", "AUS", "other countries", "GDP","quarterly data"}`. (see Out[1328])) So what all countries, which did not go through a recession or a longterm decline, have in common is, that `CompleteQuarterlyStatData[[1]][[EcoIndicator]][[Country]][[2]]` is always of the value `{}`. (Note: `CompleteQuarterlyStatData[[1]]` refers to the key figure "decline rate during recession".) To get rid of all countries which did not suffer from a longterm decline in a given economic indicator I could wrap `Table` around my if-procedure to go through all economic indicators and countries:               Table[     Table[        If[      NumberQ[CompleteQuarterlyStatData[[1]][[EcoIndicator]][[Country]][[2]]] == False,       Table[       Delete[CompleteQuarterlyStatData, i],       {i,        Map[        Part[#, 1 ;; 3] &,         Position[CompleteQuarterlyStatData,CompleteQuarterlyStatData[[1]][[EcoIndicator]][[Country]][[1]]]]       }      ]     ]     ,{Country,Length[CompleteQuarterlyStatData[[1]][[EcoIndicator]]]}]     ,{EcoIndicator,Length[CompleteQuarterlyStatData[[1]]]}];      But that does not work. Does anyone has a suggestion? In fact it would be nice to have something like `Delete[CompleteQuarterlyStatData,ArrayXXX]` whereas `ArrayXXX` represents the position of all countries (which did not go through a longterm decline) within `CompleteQuarterlyStatData`. * * * For better understanding I created an example:               list = {       {        {{{"Australia","GDP"},{}}, {{"Korea","GDP"},-2.45}, {{"USA","GDP"},-2.34}},        {{{"Australia","GDP"},2.34}, {{"Korea","GDP"},1.23}, {{"USA","GDP"},1.45}}       },       {        {{{"Greece", "Imports"},3.25}, {{"Turkey","Imports"}, {}}, {{"USA","Imports"},-2.64}},        {{{"Greece", "Imports"},-1.23}, {{"Turkey","Imports"},3.56}, {{"USA","Imports"},-1.56}}       }     };      The output of `list[[1]][[1]][[1]]` or `list[[2]][[1]][[2]]` matches the pattern `{_,{}}`. In that case I would like not only to delete those parts of list witch matches the pattern `{_,{}}` but also all other key figures which were calculated for the individual country and economic indicator. The result should then be:               {       {        {{{"Korea","GDP"},-2.45}, {{"USA","GDP"},-2.34}},        {{{"Korea","GDP"},1.23}, {{"USA","GDP"},1.45}}       },       {        {{{"Greece", "Imports"},3.25}, {{"USA","Imports"},-2.64}},        {{{"Greece", "Imports"},-1.23}, {{"USA","Imports"},-1.56}}       }     };      The reason: Australia did not go through a longterm decline in GDP, neither did Turkey in imports (if so, all other key figures concerning Australia & GDP or Turkey & imports would be irrelevant for further calculation).


How to implement Kemeny-Young method? (rank aggregation problem)

**Prehistory** I am trying to make some statistical analysis of some experimental data, arises from measurements made on an ordinal scale. I faced with the problem of _rank aggregation_ : to get from many "individuals" orderings (on the same set of objects) one "collective" ordering. The most "natural" approach to this problem is _Kemeny-Young method_ (better look primary source). Surprisingly I found out that there is no program application for this method!!! (There is one C++ code, but it does not allow weak orderings, i.e., does not allow cases when several objects share same position at ordering). Previously I asked some points (one, two) for constructing needed code, but now I have decide to tell all at once — because the problem is more complicated than I thought at first, and I can miss some points since I am null in _Mathematica_ and programming. **Description** Let $R_1, R_2, R_3, ..., R_N$ denote "individuals" weak orderings of $N$ given objects $a, b, c, ...$. Let consider $R$ as set of ordered pairs of objects. Then $(a, b)\in R$ has the usual interpretation: "$a$ is _ordered at least as good as b_ at $R$". In case $(b, a)$ is also in $R$ we say that " _both are ordered equally good_ ". Where in case $(b,a)$ is not in $R$ we say that "$a$ is _ordered above_ $b$" or "$b$ is _ordered below_ $a$". (After introducing metric we will see that it is possible to neglect — since they don't make further difference — such pairs as $(a, a), (b, b), (c, c)...$.) > To demonstrate orderings notation, here are all possible orderings for > $N=3$: > > $\ R_1=\\{(a, b), (a, c), (b, c)\\}$ > > $\ R_2=\\{(a, c), (a, b), (c, b)\\}$ > > $\ R_3=\\{(a, b), (a, c), (b, c), (c, b)\\}$ > > $\ R_4=\\{(b, a), (b, c), (a, c)\\}$ > > $\ R_5=\\{(b, c), (b, a), (c, a)\\}$ > > $\ R_6=\\{(b, a), (b, c), (a, c), (c, a)\\}$ > > $\ R_7=\\{(c, a), (c, b), (a, b)\\}$ > > $\ R_8=\\{(c, b), (c, a), (b, a)\\}$ > > $\ R_9=\\{(c, a), (c, b), (a, b), (b, a)\\}$ > > $R_{10}=\\{(a, b), (b, a), (a, c), (b, c)\\}$ > > $R_{11}=\\{(a, c), (c, a), (a, b), (c, b)\\}$ > > $R_{12}=\\{(b, c), (c, b), (b, a), (c, a)\\}$ > > $R_{13}=\\{(a, b), (b, a), (a, c), (c, a), (b, c), (c, b)\\}$ For such notation we may introduce metric $\delta$ (so-called _Kemeny distance_ ) between any two orderings $R_1$ and $R_2$ by next way: $$\delta(R_1,R_2)=|R_1\setminus R_2|+|R_2\setminus R_1|$$ where $\setminus$ means set-theoretic difference; and $||$ means cardinality of set (i.e., number of elements, because sets are finite). The required "collective" ordering $Ω$ (so-called _Kemeny mean_ ) is such ordering of given objects, that minimizes the sum of the squares of Kemeny distances to all "individuals" orderings, i.e.: $$Ω=\min \sum_{i=1}^{N } \delta(R_i,Ω)^2$$ In fact, $Ω$ may be not unique, there may be several $Ω_1, Ω_2, ...$ for which the appropriate sums of the squares of Kemeny distances are equal and minimal. So in general case $Ω$ is set of such $Ω_i$. **How to attack** So we have several of $R_i$ as input and the goal is to output $Ω$. It looks, like there should be brute-force with one-by-one generating of possible ordering, calculating the sum of the squares of Kemeny distances to all input orderings and verifiaction for minimum. Even for small $N$ number of possible orderings is huge (for my data case $N=10$, there are over $10^8$ possible orderings), so we should keep less data.


Generating an Ulam spiral

An Ulam Spiral is quite an interesting construction, revealing unexpected features in the distribution of primes. Here is a related topic with one answer by Pinguin Dirk, who has provided one approach. I've created a faster implementation, but I believe it can surely be speeded up:               ClearAll[spiral]     spiral[n_?OddQ] := Nest[        With[{d = Length@#, l = #[[-1, -1]]},          Composition[            Insert[#, l + 3 d + 2 + Range[d + 2], -1] &,            Insert[#\[Transpose], l + 2 d + 1 + Range[d + 1], 1]\[Transpose] &,            Insert[#, l + d + Range[d + 1, 1, -1], 1] &,            Insert[#\[Transpose], l + Range[d, 1, -1], -1]\[Transpose] &            ][#]] &,        {{1}},        (n - 1)/2];          spiral[5] // MatrixForm     spiral[201] // PrimeQ // Boole // ArrayPlot      > ![enter image description here](http://i.stack.imgur.com/9p8h8.png) > > ![enter image description here](http://i.stack.imgur.com/v65AV.png) This is good enough for my purposes, and I don't have time to focus on this now, However, it might be interesting for future visitors, so **the question** is how to make it faster by improving/rewriting. * * * **Note:** There may be confusion concerning whether I need a matrix populated with primes or one populated only with 0 and 1, 1 indicating the prime positions. Let's assume it doesn't matter. Maybe someone has a neat idea for the first representation that does not look good in the second one, so I'm leaving it open.


Creating a realtime MIDI Out

I have a live stream of notes and note velocities using `SoundNote` and `SoundVolume`. My problem is that I have no idea how to export the MIDI data in real time to an external synthesizer. Would I just use something like this, for example?               Dynamic[Export["file.mid", Sound[SoundNote[0]]] ]      I haven't tried this yet because even if I did have a dynamic MIDI file, how would I get the third party software, like GarageBand or Logic to recognize the MIDI input stream? Another way to phrase this question would be: how do I make _Mathematica_ into a live-playing software synth and not just produce a static MIDI composition?


Why is AllTrue much slower than VectorQ?

This seems to be a theme with V10, a new function dedicated to a specific task doesn't live up to expectation performance-wise. Mr. Wizard has already uncovered 2 such functions here and here. So how about `AllTrue` versus `VectorQ`? From the docs ![Mathematica graphics](http://i.stack.imgur.com/vQ9tw.png) ![Mathematica graphics](http://i.stack.imgur.com/iOfva.png) We're interested in the second usage of `VectorQ` here, which is the same as the purpose of `AllTrue`. A quick test shows that `VectorQ` annihilates `AllTrue` when it comes to performance e.g.               Needs["GeneralUtilities`"]          AccurateTiming[AllTrue[Range[10^6], IntegerQ]]      > 0.20069455 While for `VectorQ`:               AccurateTiming[VectorQ[Range[10^6], IntegerQ]]      > 0.00214923153 That is a two order of magnitude performance increase over `AllTrue`. Using `BenchMarkPlot` from the useful `GeneralUtilities` package we observe the following:               BenchmarkPlot[      {VectorQ[#, IntegerQ] &, AllTrue[#, IntegerQ] &},      Range[#] &,      PowerRange[10, 10^8],      "IncludeFits" -> True, PlotRange -> Full      ]      ![Mathematica graphics](http://i.stack.imgur.com/PEjLa.png) So, why is `AllTrue` slow compared to `VectorQ`?


How to make a function work on symbols in a specific context

Let us say we have two sets of symbols $(x, y, z)$ with the same names that live in two different contexts:               {context1`x,context1`y,context1`z} = {1, 10, 100}          {context2`x,context2`y,context2`z} = {2, 20, 200}      How can we define a function which takes as an argument a context name, adds $x$ and $y$ that live in the specified context and assigns the result to $z$ in the same context? **Example:**               f["context1`"]      would result in > >     {context1`x, context1`y, context1`z} = {1 ,10, 11} >   >     {context2`x, context2`y, context2`z} = {2, 20, 200} >


ParallelTable and Table do not give same result

I have a question regarding the use of `Parallelize`. In the help one can read that “`Parallelize[Table[expr,iter, …]]` (which is equivalent to `ParallelTable[expr,iter,…])` will give the same results as `Table`, except for side effects during the computation.” Ok, here I have an easy code where I use an `If`-conditional inside my Table:               arrayA=Table[RandomReal[{-1,1}],{i,1,1000}];     arrayToBeFilled=ConstantArray[0,1000];     Parallelize[Table[If[arrayA[[i]]<=0,arrayToBeFilled[[i]]=arrayA[[i]]+5,     arrayToBeFilled[[i]]=arrayA[[i]]-5],{i,1,1000}],Method->Automatic];//Timing      I do not get any useful result except my unaltered initialized array, but if I use the same code without `Parallelize`, it works fine (and even faster)! Since my real code (in principal the same as above but with more calculations) takes some time for evaluation, I hoped that I could increase the speed by using `Parallelize`. But it seems that either I am doing/understanding something wrong or that something is wrong with `Parallelize` by itself. Can somebody tell me what the case is? I also would be happy if somebody could tell me a better way how I could increase the speed of such code as in my example.


Updating List with Do works but not with ParallelDo

I am trying to find 5 minimas for some function. I can obtain the results if I implement a simple Do function. I tried to speed it up by using ParallelDo and then my code returns spurious results. Here is an example: **With Do Loop**               mytable = {{0, 0, 0, 0, 0, 0, 10^7}, {0, 0, 0, 0, 0, 0, 10^6}, {0, 0, 0, 0, 0, 0,          10^10}, {0, 0, 0, 0, 0, 0, 10^8}, {0, 0, 0, 0, 0, 0,10^9}};     ele[a_, b_, c_, d_, e_, f_] := (c/(a + b)) Exp[(d/e)^(-1/f)];          Do[mytable = SortBy[mytable, Last]; If[ele[a, b, c, d, e, f] < Last[Last[mytable]],         mytable[[-1, All]] = {a, b, c, d, e, f, ele[a, b, c, d, e, f]}],          {a,1, 2, 0.5}, {b, 2, 2.5, 0.05}, {c, 0.1, 1.1, 0.5}, {d, 1, 2, 0.5},         {e, 1, 2, 0.5}, {f, 1, 2, 0.5}]          SortBy[mytable, Last]      I get the desired output: > {{2., 2.5, 0.1, 2., 1., 1., 0.0366383}, {2., 2.45, 0.1, 2., 1., > 1.,0.0370499}, {2., 2.4, 0.1, 2., 1., 1., 0.0374709}, {2., 2.35, 0.1,2., 1., > 1., 0.0379016}, {2., 2.3, 0.1, 2., 1., 1., 0.0383424}} But when I simply change Do to **ParallelDo** , it gives me the original mytable values without any change. > {{0, 0, 0, 0, 0, 0, 1000000}, {0, 0, 0, 0, 0, 0, 10000000}, {0, 0, 0, 0, 0, > 0, 100000000}, {0, 0, 0, 0, 0, 0, 1000000000}, {0, 0, 0, 0, 0, 0, > 10000000000}} Can anyone tell me if this is due to independence problem or is there a better way to Parallelize my code?


Can I make a function which depends on several arguments which are not independent?

Here's a simple example Suppose have the permanent relation that z is proportional to xy^2, for real numbers s.               z = s x y^2      Now, we are interested in functions of x,y,z, say:               f[x_,y_,z_] = Sin[x z]-(1-y z Cos[z])^(-1)      Let's say for reasons of interpretation of the system, we do not want to simply replace z by sxy^2 and make a new function always                g[x_,y_,s_] = Sin[s x^2 y^2] - (1-s x y^3 Cos[s x y^2])^(-1)        This same thing could have been obtained from the first function by just calling:                f[x, y, s x y^2]        Instead, what I would like to be able to do, is retain the full f[x_,y_,z_], unless I have specifically asked for numerical values of x and y. What I would like is to get               f[x, y, z] = Sin[x z]-(1-y z Cos[z])^(-1)        and               f[2,1,(*something*)] =         to do something a little different. If the first two arguments are numerical, I would like the function to treat the third argument as the proportionality constant s, instead of as z itself. I suppose I could accomplish this with some kind of If statement? If those arguments are NumberQ false, take the 3rd argument to be z, and if they are both NumberQ True, take the third argument to be s, as in z=s x y^2? I suppose this question really reduces to can I make a conditional function which differs depending on the argument type?


Runge-Kutta 2nd Order ODE Solver

Suppose I have a 2nd order ODE of the form `y''(t) = 1/y` with `y(0) = 0` and `y'(0) = 10`, and want to solve it using a Runge-Kutta solver. I've read that we need to convert the 2nd order ODE into two 1st order ODEs, but I'm having trouble doing that at the moment and am hoping someone here might be able to help. This is my code thus far:               Remove["Global`*"]     (*dy/dt=*)f[t_, y_] := 1/y;     (*d^2y/dt^2=*)g[t_, y_, yd_] :=???;     t[0] = 0;     y[0] = 0;     yd[0] = 10;     tmax = 1000;     h = 0.01;          Do[      {t[n] = t[0] + h n,            k1 = h f[t[n], y[n], yd[n]];       l1 = h g[t[n], y[n], yd[n]];            k2 = h f[t[n] + h/2, y[n] +  k1/2, yd[n] + l1/2];       l2 = h g[t[n] + h/2, y[n] +  k1/2, yd[n] + l1/2];            k3 = h f[t[n] + h/2, y[n] + k2/2, yd[n] + l2/2];       l3 = h g[t[n] + h/2, y[n] + k2/2, yd[n] + l2/2];            k4 = h f[t[n] + h, y[n] + k3, yd[n] + l3];       l4 = h g[t[n] + h, y[n] + k3, yd[n] + l3];            y[n + 1] = y[n] + 1/6 (k1 + 2 k2 + 2 k3 + k4);       yd[n + 1] = yd[n] + 1/6 (l1 + 2 l2 + 2 l3 + l4);            }, {n, 0, tmax}]      As you can see by the question marks for the function `g[t_,y_,yd_]`, I don't know how I can set it in such a way that `y''(t) = 1/y`. Do I feed the results of `y[n+1]` into `g` when running the algorithm? Any help would be appreciated.


Speeding Up Replacing of Labels in Large Matrix?

I am Mathematica novice and am trying to find a fast way to replace labels in some rather large matrices (512x512 or 1024x1024) that have resulted from segmenting images with WatershedComponents or MorphologicalComponents. At present I have written the function below that takes a "label matrix" (matrix that results from segmentation) and a list of "keeper" labels (labels that I want to remain in place in the returned matrix) and returns a new matrix with only those labels remaining in place that are in the listOfKeepersIn. All other labels are replaced in the returned matrix with a single "background" label, here designated as 100. I suspect there are many more efficient ways to achieve this than what I have written here, so I welcome your suggestions. I have tried to convert this to a Compiled Function using Compile but haven't had any success (get an error message about "tensors of different ranks"). I also tried to use ParallelTable instead of Table but didn't notice much improvement. Thanks in advance for any help you can provide. -GR               ComponentKeeperFunction[matrixIn_, listOfKeepersIn_] :=          Block[{matrixToReturn},          matrixToReturn =           Table[           Which[                MemberQ[listOfKeepersIn, matrixIn[[r, c]]] == True,              (* If label value is on the keeper list then just keep that         label in its place, (i.e. make the value in the table the same as             matrixIn[[r,c]])*)              matrixIn[[r, c]],                    MemberQ[listOfKeepersIn, matrixIn[[r, c]]] == False,              (* If label value is not on the keeper list then replace that label with a                    designated background label  *)                      100  (*here I designate the background label as having a value of 100 *)           ] (* close Which *),               {r, 1, Dimensions[matrixIn][[1]]}, {c, 1, Dimensions[matrixIn][[2]]}           ] (*close Table *);            Return[matrixToReturn]           ](*close Block*)


Simulated Annealing Parameters and Results

I am using `SimulatedAnnealing` method for a simulation based optimization problem and was wondering if someone can enlighten me on the following features:   1. Is there some guidelines on optimal size of `"SearchPoints"` based on the size of the solution space knowing that the objective function is non-linear?   2. It is intuitive that the number of iterations will depend on the objective function, but I have noticed that the number of iterations seem to be a multiple of number of variables. is this true? Sample code is provided in Simulated Annealing Convergence   3. I think it is difficult to prove global optimization results, but was wondering if any one has ideas on alternative ways to do that.


How can I calculate the correlation dimension and/or the Lyapunov exponent of a time series using Mathematica

I have a pretty long time series (4000 data points). How can I calculate the Correlation dimension and/or Lyapunov exponent for such data? Please also advise on how to import the data as well.


How to run all command with same name into a notebook

I have a very big notebook with a command repeated a lot of times but with different parameters each time and I want to run all these commands at the same time without having to run separately all of them. Is there a way? **EDIT: more info** Between different calls of the 'command' there are other things (mainly plots) and I want to preserve the order of the notebook. Using the `Evaluate Notebook` form the menu `Evaluation` can be an option but when I am in a hurry this is bad because it evaluates also all the things in between while I am mainly interested in the output of my commands.


Use of Ito's lemma in ItoProcess

In the documentation for the `ItoProcess` it says: > Converting an `ItoProcess` to standard form automatically makes use of Ito's > lemma. It is unclear to me how this is done, also the example given for the standard form doesn't help. How can I, for example, apply Ito's lemma on the following stochastic differential equation (SDE) $dS=S(σdB+μdt)$, with $B$ being Brownian motion. Applying Itō's lemma with $f(S)=log(S)$ gives $$\begin{align} d\log(S) & = f^\prime(S)\,dS + \frac{1}{2}f^{\prime\prime} (S)S^2\sigma^2 \,dt \\\ & = \frac{1}{S} \left( \sigma S\,dB + \mu S\,dt\right) - \frac{1}{2}\sigma^2\,dt \\\ &= \sigma\,dB +\left (\mu-\tfrac{\sigma^2}{2} \right )\,dt. \end{align}$$ It follows that $$\log (S_t) = \log (S_0) + \sigma B_t + \left (\mu-\tfrac{\sigma^2}{2} \right )t,$$ exponentiating gives the expression for $S$, $$S_t=S_0\exp\left(\sigma B_t+ \left (\mu-\tfrac{\sigma^2}{2} \right )t\right).$$ How can I achieve that in Mathematica?


Expanding a Function in Series works, SeriesCoefficient Doesn't Work

Take the following definitions:               rho = Cos[(2 Pi)/7] + I Sin[(2 Pi)/7]          F[y, q] =       y^3*Product[(1 -            Conjugate[lambda] y^-2) Product[(1 -              Conjugate[lambda] y^-2*q^n) (1 - lambda*y^2*q^n), {n, 1,            Infinity}], {lambda, {rho, rho^2, rho^4}}]          G[y, q] =       y^2*Product[(1 -            Conjugate[mu] y^-1) Product[(1 - Conjugate[mu] y^-1*q^n) (1 -              mu*y*q^n), {n, 1, Infinity}], {mu, {1, rho^3, rho^5, rho^6}}]          Psi[y, q] = (F[y, q]/G[y, q]) * Product[(1 - q^n)^2, {n, 1, Infinity}]      For some reason, I can compute `Series[Psi[y, q], {y, 0, 3}]` quite quickly, but the command `SeriesCoefficient[Psi[y, q], {y, 0, i}]` will not finish for $i=1,2,3$. Why could this be? I've noticed the output of `Series[]` isn't exactly a power series in y, but rather has some powers of y buried into the functions `QPochHammer[]` but I don't know how to get them out. Any help is greatly appreciated. Thanks, Andy.


How to measure segment length and branch angle

I am trying to measure segment length and branch angle or bifurcation angle between each pair of segments. My image after thinning looks like this: ![enter image description here](http://i.stack.imgur.com/me0gY.jpg)                i = Import@"http://dl.dropbox.com/u/68983831/thinned.png";      dat = ImageData[i];       i1 = Image[dat[[34 ;; 242, 28 ;; 213]]]      g = MorphologicalGraph[i1, EdgeWeight -> Automatic]      thus output looks like: ![enter image description here](http://i.stack.imgur.com/tqIPZ.jpg)


Argmax in a List

I have a sequence of 100 lists. A sample list, list[1], looks like this:               list[1]=Table[{N[i/10], 25 - (i - 2)^2, 25 - (i - 8)^2}, {i, 1, 10}]          {{0.1, 24, -24},       {0.2, 25, -11},      {0.3, 24, 0},      {0.4, 21, 9},      {0.5, 16,16},      {0.6, 9, 21},      {0.7, 0, 24},      {0.8, -11, 25},      {0.9, -24,24},      {1., -39, 21}}      I would like to see where the 3rd column, $list[1][[*, 3]]$ is maximized. The 8th Row in this example. Then I want to note the value of the first column in the 8th row, namely $list[1][[8,1]]=0.8$. Then I would like to delete all records where the 1st column is > 0.8, i.e. where $list[1][[*,1]]>list[1][[8,1]]$ . In this example, since the numbers are monotonic, that means the last two rows get deleted. I'll be left with:                   {{0.1, 24, -24},       {0.2, 25, -11},      {0.3, 24, 0},      {0.4, 21, 9},      {0.5, 16,16},      {0.6, 9, 21},      {0.7, 0, 24},      {0.8, -11, 25}}      Then, I would like to see where the 2nd column, $list[1][[*, 2]]$ is maximized. The 2nd Row in this example. Then I want to note the value of the first column in the 2nd row, namely $list[1][[2,1]]=0.2$. Then I would like to delete all records where the 1st column is < 0.2, i.e. where $list[1][[*,1]]<list[1][[2,1]]$ . In this example, since the numbers are monotonic, that means the first row get deleted. I'll be left with:                   {       {0.2, 25, -11},      {0.3, 24, 0},      {0.4, 21, 9},      {0.5, 16,16},      {0.6, 9, 21},      {0.7, 0, 24},      {0.8, -11, 25}}      I guess both transformations are identical so if I know how to do one, I can do the other. I just mentioned both simply because it might be feasible to do both in one shot and that code might teach me more than learning the code for a single transformation. Also, I have a hundred different lists and I'd like to be able to do this transformation to all 100 of them in one shot, using Table or something. Thanks, PS: I have read advanced help but I can't seem to figure out how to get the shaded grey background on certain text so I have instead put $$ to get things like $ list[1][[*, 2]] $ as latex math above in my question to appear distinguished from the rest of the text.


Use Mathematica to do a network analysis of Mathematica.SE

Recently Wolfram|Alpha announced that you could use it to analyze your Facebook site. How could I do a network analysis of questioners and answers here on Mathematica.SE?


How to display docked cell (defined in stylesheet) in *.nb only (and not in *.cdf)?

I have a docked cell in a stylesheet (with shortcuts for editing the notebook). Is there an option I can set so that this cell is not displayed in CDF? **Edit** Based on answer by @MikeHoneychurch and the reference provided, here is the code I ended up using. Note this code deploys a notebook to a CDF removing any docked cells and cells tagged with "delete me". It will also ensure that styles embedded in the notebook are copied over to the CDF. Further changes may be required if the notebook inherits a stylesheet (refer to answer and link provided by @MikeHoneychurch).               Button["Save as CDF",      (*Get the directory/name of the current notebook and change the .nb to .cdf; use this as the default path for the deployed CDF*)      tmp = EvaluationNotebook[];      cdfDefaultName = NotebookFileName[EvaluationNotebook[]];      cdfDefaultName = StringReplace[cdfDefaultName, ".nb" -> ".cdf"];      cdfFileName =        SystemDialogInput["FileSave", {cdfDefaultName, {"CDF Files" -> {"*.cdf"}}}];      (*Get a copy of the private stylesheet a.k.a child and delete the docked cell*)      child = Options[tmp, StyleDefinitions];      childstyles = Cases[child, Cell[StyleData[_, ___], __], \[Infinity]];      modchildstyles = DeleteCases[childstyles, Rule[DockedCells, _], \[Infinity]];      (*Remove specified cells from the notebook *)      tmp1 = First@NotebookGet[EvaluationNotebook[]];      tmp1 = tmp1 /. CellGroupData[{Cell[_, "Input", ___, CellTags -> "delete me", ___], ___}, ___] :> Sequence[];      (*Deploy the CDF*)      CDFDeploy[cdfFileName, Notebook[tmp1, StyleDefinitions ->          Notebook[modchildstyles, StyleDefinitions -> "PrivateStylesheetFormatting.nb"]]],       ImageSize -> 100, Method -> "Queued"]


LevelScheme for ListPlot Joined->False exceeds the size of the Panel

In two side by side panels, using LevelScheme, I output the same data using ListPlot. In the first panel I use option Joined-> **False** , while in the second Joined-> **True**. The data in the second panel is properly limited by the size of the panel, while in the first panel it goes beyond the panel limits. So, my question is: how to make objects being displayed be cut exactly by the size of the panel, if even explicitly specifying the PlotRange in ListPlots doesn't make any difference?               << "LevelScheme"`     Figure[{       Multipanel[{{0, 1}, {0, 1}}, {1, 2}, XGapSizes -> {.5}],            FigurePanel[{1, 1}, PlotRange -> {{0, 10}, {0, 1}}],       RawGraphics[        ListPlot[Table[{.1 x, Sinc[.1 x]}, {x, Range@200}],          PlotRange -> {{0, 1}, {0, 1}},Joined->False]        ],            FigurePanel[{1, 2}, PlotRange -> {{0, 10}, {0, 1}}],       RawGraphics[        ListPlot[Table[{.1 x, Sinc[.1 x]}, {x, Range@200}],          PlotRange -> {{0, 1}, {0, 1}}, Joined -> True]        ]            },                PlotRange -> {{-0.1, 1.1}, {-0.1, 1.1}}]      results in ![result of the aforementioned code execution in Mathematica 9](http://i.stack.imgur.com/1Mvs4.png)


Strange response with dynamic texture and MousePosition

I built a cubic, then use `MousePosition` together with `GUIScreenShot` to take a floating region with fixed size (200*200) on the screen, and use it as dynamic texture on the cubic. My code is               Needs["GUIKit`"];     $HistoryLength = 1;          DynamicModule[{mpp},      Dynamic@{       Refresh[        ClearSystemCache[];        g = GUIScreenShot[With[{mp = MousePosition[]}, mpp = {mp - 100, mp + 100}]];        Graphics3D[{Texture[g], Polygon[coords, VertexTextureCoordinates -> Table[vtc, {6}]]}, Lighting -> "Neutral"],        UpdateInterval -> .5],       mpp, g},      Initialization :> (       vtc = {{0, 0}, {0, 1}, {1, 1}, {1, 0}};       coords = {{{0, 0, 0}, {0, 1, 0}, {1, 1, 0}, {1, 0, 0}}, {{0, 0, 0}, {1, 0, 0}, {1, 0, 1}, {0, 0, 1}}, {{1, 0, 0}, {1, 1, 0}, {1, 1, 1}, {1, 0, 1}}, {{1, 1, 0}, {0, 1, 0}, {0, 1, 1}, {1, 1, 1}}, {{0, 1, 0}, {0, 0, 0}, {0, 0, 1}, {0, 1, 1}}, {{0, 0, 1}, {1, 0, 1}, {1, 1, 1}, {0, 1, 1}}};)]      You can see the result by executing the code then moving your mouse around. Like this, ![enter image description here](http://i.stack.imgur.com/4rNof.png) But there are two strange problems, 1) the size of the floating area taken should be always 200*200, however it will actually change. 2) the memory usage will constantly grow as we move our mouse, but I have already used `$HistoryLength=1` and `ClearSystemCache[]`. Any suggestion?


Creating functions from output of other calculations

Apologies in advance if the title is vague, I'm not really sure what to call this. I have a function (call it 'foo') that generates a largeish polynomial, and it is natural to make the variables be               x[1],x[2],x[3]      and so on, so I get a polynomial, e.g.               x[1]^2 x[2]+x[3]      Now, I'd like to store this as a function               bar[x[1]_,x[2]_,x[3]_]:=foo[whatever]      This doesn't work, of course, but if the variables were e.g.               x1,x2,x3      etc. instead, I could do               bar[x1_,x2_,x3_]:=foo[whatever]      and that would work. I figured some replacement rule would work, e.g.               rule={x_[i_] :> ToExpression@(ToString[x] <> ToString[i])}      which looks like it should work:               x[1]^2 x[2]+x[3]/.rule      gives output               x1^2 x2 + x3      but if I define               bar[x1_,x2_,x3_]:=foo[whatever]/.rule      then               bar[1,2,3]      outputs               x1^2 x2 + x3      instead of 5, which it should. Obviously, there is something I don't really understand about the way Mathematica handles variable names, and what I'm trying to do to fix this is probably too naive. Is there some better way to get around this problem? Thanks in advance for any help.


Weighted Kirchhoff Matrix?

I have a weighted graph and I want its graph Laplacian matrix (what Mathematica calls the Kirchhoff matrix in the unweighted case). Is there an easy way to get this? For example, the command:               WeightedAdjacencyMatrix[Graph[{0 \[UndirectedEdge] 1},EdgeWeight -> {3}]]//MatrixForm      returns the matrix               0   3     3   0      and               KirchhoffMatrix[Graph[{0 \[UndirectedEdge] 1}, EdgeWeight -> {3}]] //MatrixForm      returns               1 -1     -1 1      whereas I would like               3 -3     -3 3      I can do it in an ugly way, but I am wondering if there is a beautiful way to do it. * * * ### Edit I wrote a small function to do this, and it works.                    WeightedKirchhoffMatrix[G_] :=          (M = WeightedAdjacencyMatrix[G];          n = Length[M];          e = Table[1, {i, n}];          DiagonalMatrix[e.M] - M)


How to calculate definite integral when boundary is a limit?

Integrate[Log[x]/(1-x)^2,{x,eta,Infinity}]      The conditions are `eta>0`, and `eta->1`, how to incorporate the conditions?


Using Part rather than Extract

In my work I found that I needed the `Extract` function. However I was wondering if there was a way to use `Part`. Assume that `mList` is a 4-dim array. I did the following, which worked.               x = {2, 10, 3, 4};     y = Extract[mList, x];      I found that I can't do this.               y = mList[[x]]      Is there a way to convert the list `x`, into a sequence of integers that I can use in `Part`? I tried enclosing it in `Sequence`, but that seemed to have no effect. As I said, I'm fine without this, I was just wondering.


Solving two-component two-dimensional differential Equation with NDSolve (Brusselator Model)

I'm trying to solve a two-component two-dimensional reaction-diffusion differential equation system with Mathematica. The background of the model is the so called "Brusselator Model" where one can find a nice outline online from the Institute of Theoretical Physics in Münster, Germany. The model is given by the differential equation system: $$u_t=D_u\Delta u+a-(b+1)u+u^2 v$$ $$v_t=D_v\Delta v+b u-u^2 v$$ with u,v as the solution variables depending on x,y and t, $\Delta$ as the Laplace operator $D_u$ and $D_v$ as the diffusion constants and a,b as positive reaction rate constants. This system exhibits a transition from small fluctuations around the uniform steady state solution of the model into a high-amplitude stripe pattern as shown in Fig. 8.6 of the online reference, when the parameterset $D_u$, $D_v$, a and b is in the instability region. Based on stability analysis (see reference) the system is unstable when e.g. using the parameter set $D_u=5$, $D_v=12$, a=3 and b=9. The steady state solution of the system is: $$u_0=a=3, v_0=\frac{b}{a}=1/3$$ In Mathematica we define a small fluctuation (e.g. $\pm2\%$) on the steady state solutions $u_0$ and $v_0$ as initial values (at t=0) of the differential equations               u0 = Interpolation[Flatten[Table[{{x, y}, 3 + If[x == 0 || y == 0 || x == 50 || y == 50,             0,             RandomReal[{-a/50, a/50} /. a -> 3]], {0, 0}}, {x, 0,50}, {y, 0, 50}], 1],             InterpolationOrder -> 2];     v0 = Interpolation[Flatten[Table[{{x, y}, 9/u0[x, y], {0, 0}}, {x, 0,50}, {y, 0, 50}], 1],             InterpolationOrder -> 2];      here I restricted the initial value boundaries to the steady state without random fluctuation and enforced that the first derivate of the interpolation function is zero at the boundaries too, to keep the boundary and initial conditions in the differential equation consistent. One can plot the initial condition $u_0$ with the following statements               GraphicsRow[{       ContourPlot[u0[x, y], {x, 0, 50}, {y, 0, 50},          PlotLegends -> Automatic,          ColorFunction -> "SolarColors",          FrameLabel -> {"x", "y"},          ImageSize -> Medium],        Plot3D[u0[x, y], {x, 0, 50}, {y, 0, 50}, PlotRange -> {2.9, 3.1}]}]      My approach to solve this system for a x-y space interval of 50x50 units and the mentioned parameters, I tried out the following statement               NDSolve[Evaluate[{       D[u[x, y, t], t] == Du (Derivative[2, 0, 0][u][x, y, t] + Derivative[0, 2, 0][u][x, y, t]) + a - (b + 1) u[x, y, t] + v[x, y, t] (u[x, y, t])^2,       D[v[x, y, t], t] == Dv (Derivative[2, 0, 0][v][x, y, t] + Derivative[0, 2, 0][v][x, y, t]) + b u[x, y, t] - v[x, y, t] (u[x, y, t])^2,       u[x, y, 0] == u0[x, y],       v[x, y, 0] == v0[x, y],       Derivative[1, 0, 0][u][0, y, t] == 0, Derivative[1, 0, 0][u][L, y, t] == 0,       Derivative[0, 1, 0][u][x, 0, t] == 0, Derivative[0, 1, 0][u][x, L, t] == 0,       Derivative[1, 0, 0][v][0, y, t] == 0, Derivative[1, 0, 0][v][L, y, t] == 0,       Derivative[0, 1, 0][v][x, 0, t] == 0, Derivative[0, 1, 0][v][x, L, t] == 0,     } /. {L -> 50, Du -> 5, Dv -> 12, a -> 3, b -> 9}],      {u, v}, {x, 0, 50}, {y, 0, 50}, {t, 0, 0.05 4000}, MaxSteps -> {15, 15, Infinity}]      but get the following error: NDSolve::ibcinc: Warning: boundary and initial conditions are inconsistent. which is strange since I enforced the Neumann boundary conditions through the interpolation function derivate. Finally NDSolve runs forever, yielding no result even with the rather low setting of 15 for MaxSteps in x and y direction. Any proposal for improvements?


RDPStruct.exe: what is it and why are there so many?

I have an old (v7) webMathematica system running and it seems to generate a lot of RDPStruct.exe processes. First, what does this "Converter" do? GIF.exe and JPEG.exe are obvious, but "RDPStruct" doesn't mean anything to me. Does it make sense for there to be more than one running at a time? Does it make sense for there to be like 20 running at a time? Are they being orphaned somehow? If so, how can I figure out which ones are no longer in use? They seem to be causing system problems. I also have some command-line Mathematica processes that stop functioning properly sometimes and I find that killing off the RDPStruct processes will make them start working again. I don't yet have a lot of detail around this yet.


Alternative ways to AppendTo and Delete in a While loop

Is there an alternative way to do `AppendTo` and `Delete` and also replace `k0` during every update? I want to avoid the 3- `CopyTensor`s in the following code which probably are the reason behind the memory and performance problems for large values of `n`.               f = Compile[{{n, _Integer}},        Module[{Fk = Table[RandomReal[{0, 1}], {5}, {n}], k0 = Table[RandomReal[{0, 1}], {n}], TT = 0.1, ksum, i = 0},         While[TT > 0 ,          ksum = Total@Fk;          k0 = MapThread[Min[#1, #2 RandomReal[{0, 1}]] &, {k0, ksum}];          TT = Round[Total@k0, 0.01]; i++;          Fk = Delete[Fk, {1}];          AppendTo[Fk, k0];         ]; i        ]       ]


Odd edge-case behavior of Block

In this example, `Block` is used to localize the variable cache as used in the function `g` when called from the function `f`. In `f`, the cache symbol to use is passed in as the second parameter `z`:               f[a_, z_] := Block[{cache = z}, g[a]];     g[a_] := (Print["hash" -> Hash[cache]]; cache[1] = a; cache[1]);      Everything works as expected:               Hash[z]      2065959314 (your number may be different)       Calling `f`:               f[1, z]      hash->2065959314 (same)      1       The symbol `z` now has a single downvalue:               DownValues[z]      {HoldPattern[z[1]] :> 1}       However, what if I use the **actual symbol cache** as the cache symbol (say. by accident; not knowing that is the symbol name used inside `Block`):               Hash[cache]      1028301578 (your number may be different)       Calling `f`:               f[1, cache]      hash->1028301578 (same)      1       But nothing stored in the cache this time?               DownValues[cache]      {}       My (partial) theory is that `Block[{cache = cache}, ...]` may have used a temporary variable `cache$xxx` after `cache=cache` collapses, but that doesn't explain why we still see the correct hash for the symbol inside `g`. This is an awkward, but OK situation **if** you know the name of the variable used inside `Block`, but could conceivably lead to some very puzzling bugs (as it did for me) if you chance upon the same symbol name.


Strange behavior on very large numbers

I want to test the value of a differential equation by replacing a solution and setting random values for r and z variables:               sol = ψ -> Function[{r, z}, Sinh[2 (r + z)^2] + Tan[4/3 + r] + 5 (-r + Tanh[1/r])];          de2 = 1/(4*r^2) - D[ψ[r, z], z]^2 + D[ψ[r, z], z, z] + D[ψ[r, z], r]/(2 r)+ D[ψ[r, z], r]^2 +  D[ψ[r, z], r, r];      If I set for example:               N[de2 /. sol /. r -> -9 /. z -> 4]==0      I get a false result. The value is a very large negative number (-3.16913*10^29). If I set:               N[de2 /. sol /. r -> -90 /. z -> 4]      I get 0.*10^12836 in red, and a message saying "No significant digits are available to display." If I compare this last command to zero:               N[de2 /. sol /. r -> -90 /. z -> 4]==0      I get True! What's happening? How could I prevent this from occurring? Not using PZQ because it is too slow for the number of tests I want to do.


How to Export the current graphic state of a dynamic module?

After manipulating the graphics in a dynamic module like this: Synchronizing manual rotations for multiple Graphics3D outputs? How do I get at the current graphic so that I can Export the image? The answer might be burried in here Using DynamicModule variables outside the DynamicModule someplace but i am unable to decipher it..


How can I program the RiemannR function using the LogIntegral command?

I would like to program the `RiemannR` function using the `LogIntegral` command because I would like to later experiment with a double integral instead of the `LogIntegral` function. I have tried to program the `RiemannR` function starting with the `LogIntegral` command as defined in the Stein-Mazur paper called "Primes": ![RiemannR function as in Stein Mazur paper on primes](http://i.stack.imgur.com/uHKVF.png) That agrees almost completely with the definition given in the _Mathematica_ help page about the `RiemannR` command: $$R(x)=\sum_n^\infty \mu(n)\mathrm{li}(x^{1/n})/n$$ The only differences I see are that the summation limit $n=1$ is given in the Stein-Mazur paper while in the _Mathematica_ help page it is not. Also the Stein-Mazur paper uses $\mathrm{Li}$ for the logarithmic integral while the _Mathematica_ help page uses $\mathrm{li}$. However in the _Mathematica_ help page for the `LogIntegral` command the lower case $\mathrm{li}$ is used. My problem is that when I enter the following lines:               N[RiemannR[1000]]     N[Sum[MoebiusMu[n]*LogIntegral[1000^(1/n)]/n, {n, 1, Infinity}]]      in _Mathematica_ , I get different numerical values:               168.359     168.341      What am I doing wrong?


How to create InterpolatingFunction from data?

If I have a function at a number of non-uniformly spaced data points:               youtReal[7.8]=2.0332;, youtReal[8.54]=6.24352354;..................      ......... and the imaginary parts:               youtImag[7.8]=2.54345345; youtImag[8.54]=-5.2434;.................      Is there an easy way to generate an InterpolatingFunction from this data consisting of complex values i.e. so I have yout[7.8]=2.0332+2.54345345I; and can also just get an interpolated value for say yout[8.12] and so on. To make this more concrete, the initial data is read in from a text file that looks like               youtReal[39.983881559265192985] =0.003175121157662356963;      youtImag[39.983881559265192985] =-0.025570345562818877981;      youtReal[39.945803445544929806] =0.0030816430773355882379;      youtImag[39.945803445544929806] =-0.025607948113924885628;      youtReal[39.907725331824666628] =0.0029879382430246325535;      youtImag[39.907725331824666628] =-0.025645261479980185081;      youtReal[39.869647218104403449] =0.0028940073645911109315;      youtImag[39.869647218104403449] =-0.025682284691974913792;       youtReal[39.831569104384140271] =0.0027998511548903118804;       youtImag[39.831569104384140271] =-0.025719016782491712295;       youtReal[39.793490990663877092] =0.0027054703297639490629;      youtImag[39.793490990663877092] =-0.025755456785713930289;      youtReal[39.755412876943613914] =0.0026108656080328711776;      youtImag[39.755412876943613914] =-0.025791603737433792661;     youtReal[39.717334763223350736] =0.00251603771148972405;      youtImag[39.717334763223350736] =-0.025827456675060525123;      .      .      .      and so on all the way down to around youtReal[~29]. So I read this in then have a function with quite arbitrarily defined value points, and lots and lots of them. I don't have a nice list of points I can just feed into `ListInterpolation` ab initio, I need to somehow generate this.


Plotting array of vectors with conditions

Given data in the form               list={{{1,2},{3,4},{5,6}},{{7,8},{9,10},{11,12}},...}      a matrix where elements are 2-element vectors, what is a efficient way to plot this as a spatial grid? As I understand               ArrayPlot[array,ColorFunction->(If[#>3,Red,White]&), ColorFunctionScaling->False]      can only be "fed" with normal array (no 2-vector like above), if you want to use Colorfunction If condition. I want that a cell of the ArrayPlot mesh gets Red, when in {x,y} vector `1<x<2 AND y>3`, otherwise White. I know I could recreate the list into a {{1,0,1},{0,1,0},...} like normal array so ArrayPlot could read it, by using Table and Take, 1 and 0 representing the Red and White Case:               If[1<First[Flatten[Take[list,i]]]<2,1,0]      Then rebuild that list with Table and Join. But as far as I know MM, there has to be easier way, simply reading list and replacing a 2-vector with 1 or 0 1-vector under above conditions. Or do I really have to build the list completely new, problem is it has some million elements. Thanks for any tips to improve this


How to visualize slope fields of differential equations without vectors?

I'm looking to visualize slope fields of differential equations for my differential equations course. Every example I see draws them as vectors, adding unnecessary "arrows" that, to me, are visually distracting. Is there a way to plot these slope fields without the "arrows" that get in the way?


Is it possible to treat starting values as variables?

I have a problem where I am using FindRoot a gazillion times over a grid of parameters. I need to allow the starting values to vary a bit with the parameters to get it to converge. Here is a simple example in the spirit of my much bigger problem:               f[a_] := x /. FindRoot[x^2 - 1 == a, {x, a - 1, a + 1}]     NIntegrate[f[z], {z, 0, 5}]      NIntegrate actually gives an answer (I think it's even right), but it also gives the following errors: > FindRoot::srect: Value -1.+z in search specification {x,z-1,z+1} is not a > number or array of numbers. >> > > ReplaceAll::reps: {FindRoot[x^2-1==z,{x,z-1,z+1}]} is neither a list of > replacement rules nor a valid dispatch table, and so cannot be used for > replacing. >> It looks like it doesn't like treating the starting values for x as variables. For some reason, the actual numbers between 0 and 5 in the integral are not being passed to the starting values in FindRoot. Any suggestions?


Symbol created in unevaluated second argument of If

Apologies for the long question title, but I couldn't come up with something shorter to describe the following. Starting with a clean session, there are no symbols in, let's say, `myContext`:               Names["myContext`*"]     (* {} *)      But if I now evaluated this If statement,               If[False, myContext`mySymbol = "value"]      all of the sudden `mySymbol` has been created in `myContext`:               Names["myContext`*"]     (* {"myContext`mySymbol"} *)      but, as expected, `mySymbol` doesn't have a value:               myContext`mySymbol     (* myContext`mySymbol *)      My question is twofold: why has `mySymbol` been created, and how can I prevent this from happening?


Error invoking Information on functions containing Legended

In adapting some plotting functions to utilize the `PlotLegends` option of version 9, I came across the following errors:               f[x_] := Legended[Plot[Sin[t], {t, 0, Pi}], x]     f[1];     Information[f]      > `TextForm[First::first: StandardForm[Short[Shallow[HoldForm[{}], {10, 50}], > 5]] has a length of zero and no first element. >>]` This is just a toy example for a more complex situation where I can't directly use the `PlotLegends` option but have to use `Legended` explicitly. What is the best way to catch this error when a user invokes the above or types `?f` to see the code for this function. It seems the output of `Definition` works as expected (it formats the `Legended` contents, and that happens for other constructs such as `Framed` too).


How to execute kernel command from Front End?

Documentation for Yuri E. Kandrashkin's OptionsExplorer package says to add the following menu commands in MenuSetup.tr:                  Item["Options &Explorer", KernelExecute[ToExpression["OptionsExplorer[]"]],        MenuKey["o", Modifiers->{Control,Command}], MenuEvaluator->Automatic]      And I want to accomplish the same thing by a corresponding `FrontEnd`AddMenuCommands...` expression in an `Autoload`PacletManager`Configuration`FrontEnd`init.m`. But I don't find any `KernelExecute` function. How to do it?


Formatting All Appropriate Output as Desired Automatically

I want to output in `MatrixForm` whenever I have a list/vector/matrix, but I do not want to have to type out the command each time. How can I write one command at the beginning of the notebook so that all output is so formatted? (Also: generalization to any formatting would be better, with additional specific detail included for this case.)


solving a cubic equation

I need to find the minimum $r$ and the maximum $k$ of the following cubic equation for which there does not exist three distinct real roots. $rx^3-rkx^2+(r+k)x-rk=0$. Is it possible to find such $r$ and $k$ analytically? Or if you can provide me help using mathematica, that would be fine too.Thanks.


Accessing the Options of the parent Cell

From within the Kernel, it is possible to access a `Cell`'s options using `CurrentValue`. For instance, in a `Cell` tagged `{"Bob", "Frank"}`, executing this               CurrentValue[CellTags]     (* {"Bob", "Frank"} *)      But, how would one go about accessing the options of the parent cell in the hierarchy? One difficulty is that the `Cell` knows nothing about the `CellGroup` it finds itself in, so attacking the problem from that direction seems difficult. However, the current executing `Notebook` can be accessed via `EvaluationNotebook`, so traversing the tree from that direction seems plausible, if not efficient.


generating pdf using UseFrontEnd

I run mathematica on a remote server and run it in batch mode using /math -noprompt -script 'scriptname.m' & Now, I use ssh -X to connect to the server. The server is linux based and my computer is a mac. I use x11 forwarding. I would like to generate PDFs in the above mentioned 'script.m'. In my code, how should I incorporate UseFrontEnd? should I invoke it first using ConnectToFrontEnd[] ? Should I use UseFrontEnd[Export["blah.pdf",fig]] or is it a one time thing? Also, when using the UseFrontEnd command, is it required that I do ssh -X/Y or is it sufficient if I do ssh? I greatly appreciate your help. Thanks. P.S - I am using mathematica 8


Plotting a path in a vector field

I am trying to make a visual representation of the curve $y=x^{2}$, with $x\in\left[0,1\right]$ in the vector field defined by $\vec{F}=\left[-y,x\right]$. However, as far as I can tell there does not seem to be any facility which allows me to do this in Mathematica (I've looked through as much of the documentation as I could find which seemed pertinent). I know how to do each of these separately, e.g.               Plot[x^2,{x,0,1}]     VectorPlot[{-y,x},{x,-3,3},{y,-3,3}]      However, I am unsure how I can combine these two plots (or plot them both at the same time). Thanks in advance!


Choose partition of a set with Manipulate

Suppose I have a set represented by an array of strings, like > set = { "A", "B", "C", "D", "E", "F" } I would like to create a Manipulate which allows the user to build repartitions of the set. To be clear, I'd like the user to be able to build, for instance, the following repartitions:               repa1 = { {"A", "B", "C"}, {"D", "E", "F"} }      and               repa2 = { { "A" }, { "B", "C" }, { "D", "E", "F" } }      $$ $$ Is this possible? * * * Even better, I would like to be able to use labels for the manipulate command. I mean, let's say the set is > set = { {"A", 26}, {"B", 33}, {"C", 69}, {"D", 2}, {"E", 16} } then the selector should look like part1 : [ A, B, C, D, E ] part2 : [ A, B, C, D, E ] part3 : [ A, B, C, D, E ] and, supposing I choose the following combination, part1 : [ **A** , B, **C** , D, E ] part2 : [ A, **B** , C, **D** , E ] part3 : [ A, B, C, D, **E** ] the result should be > repa = { { {"A", 26}, {"C", 69} }, {{"B", 33}, {"D", 2}}, {{"E", 16}} }


V10 interface problems

Has anyone noticed the following?   1. Sometimes when I bring up the Help->Wolfram Documentation there is no text field to type into.   2. When I bring up Find and Replace there are two text fields for Find: and Replace with: but no other controls or buttons (No buttons Find Next, Find Previous, Replace etc). In this case on my system - win7-64 - the dialog box is unnaturally tall (whole height of screen).   3. Syntax highlighting seems somewhat erratic - defined symbols stay the wrong color for a while. Symbols that are part of a function signature, say f[x_]:=... stay the wrong color for a while as well. Restarting Mathematica restores these.