title: Finding connected components in an array

text: I have an $w\times h$ array with non-negative integers. I wish to partition the set of coordinates $(c,r)$ with $1\leq c \leq w$ and $1\leq r \leq h$, in subsets, so that each subset corresponds to a cluster of the same value in the array. Two coordinates are neighbouring if they either are on top of another, or one is down-left of the other. This corresponds to finding clusters in a parallelogram. belisarius was nice to provide a picture: ![enter image description here](http://i.stack.imgur.com/kJEhK.png) I have some code to find one connected cluster in an array (I call it gt):               FloodFillExtractTile[gt_, {sr_, sc_}] :=       Module[{r, c, toExplore, visited = {}},       toExplore = {{sr, sc}};       While[Length@toExplore > 0,        (* Pop *)        {r, c} = Last@toExplore;        toExplore = Most[toExplore];        AppendTo[visited, {r, c}];        (* Down-left *)             If[c > 1 && r < h &&           gt[[r + 1, c - 1]] == gt[[r, c]] && !            MemberQ[visited, {r + 1, c - 1}],         AppendTo[toExplore, {r + 1, c - 1}];         ];        (* Down-right *)             If[ r < h &&           gt[[r + 1, c]] == gt[[r, c]] && ! MemberQ[visited, {r + 1, c}],         AppendTo[toExplore, {r + 1, c}];         ];        (* Up-right *)             If[r > 1 && c < w &&           gt[[r - 1, c + 1]] == gt[[r, c]] && !            MemberQ[visited, {r - 1, c + 1}],         AppendTo[toExplore, {r - 1, c + 1}];         ];        (* Up-left *)             If[ r > 1 &&           gt[[r - 1, c]] == gt[[r, c]] && ! MemberQ[visited, {r - 1, c}],         AppendTo[toExplore, {r - 1, c}];         ];        ];       Return@visited;     ];      Then `FloodFillExtractTile[gtp, {1, 1}]` gives the component connected to the upper left hand corner. However, this method feels ugly, and extending it to all components feels even uglier. I was looking at `Gather`, but the problem is that it wants _all_ points in a cluster to be _equal_ , see for example Gather dependency on list order? Edit: So this is the type of arrays I am looking at. The 6, the 3's, the 2's and the 0's are in one component respectively, but there are two components with 1's. Being neighbours means being adjacent down-left, down-right, up-left and up-right. Now, the rows is stored just like regular rows in a rectangular matrix, so that is why this translates to a bit strange criteria for being neighbours. ![GT-pattern](http://i.stack.imgur.com/LrdCQ.png) This is the best code I have so far, first extract points with the same value, then do connected-component analysis on those parts.               GetGTTiles[gtp_] :=        Module[{testSame, testEdge, h, w, pts, sameClusters, getEdges,          tiles},        {h, w} = Dimensions[gtp];        pts = Join @@ Table[{r, c}, {r, h}, {c, w}];        testSame[{r1_, c1_}, {r2_, c2_}] := (gtp[[r1, c1]] ==            gtp[[r2, c2]]);        testEdge[{r1_, c1_}, {r2_,            c2_}] := (gtp[[r1, c1]] ==             gtp[[r2, c2]]) &&          ((c1 == c2 &&               Abs[r1 - r2] <= 1) || (c1 == c2 - 1 &&               r1 == r2 + 1) || (c1 == c2 + 1 && r1 == r2 - 1));        sameClusters = Gather[pts, testSame];        getEdges[clust_] :=          Join @@ Outer[If[testEdge[#1, #2], #1 -> #2, Sequence @@ {}] &,            clust, clust, 1];        tiles =          Join @@ (ConnectedComponents[Graph@getEdges[#]] & /@ sameClusters);        Return@tiles;        ];      This is the output I expect for the example given (5 clusters found):               {{{1, 1}}, {{1, 2}, {2, 1}},      {{1, 3}, {2, 3}, {3, 2}, {4, 1}, {3, 1}, {2, 2}},      {{1, 4}},      {{2, 4}, {3, 4}, {4, 4}, {5, 4}, {5, 3}, {4,3}},      {{3, 3}, {4, 2}, {5, 2}, {5, 1}}}      EDIT: So this is the final code, based on belisarius solution:               GTTiles[gtp_List] := Module[{fromEuclidean, toEuclidean,         getOneTile, elements, elmPos, pts, tile, tiles},             (* This is used to changefrom different coordinate systems. *)             fromEuclidean[{r_, c_}] := {r, (c - r)/2 + 1};        toEuclidean[{r_, c_}] := {r, 2 c + r - 2};             getOneTile[pts_List, maxDist_?NumericQ] := Module[{f},          f = Nearest[pts];          FixedPoint[           Union@Flatten[f[#, {Infinity, maxDist}] & /@ #, 1] &, {First@             pts}]];             elements = Union @@ gtp;        elmPos = (toEuclidean /@ Position[gtp, #]) & /@ elements;        (* This is really strange code. *)        tiles = Flatten[Flatten[             Reap[NestWhile[Complement[#,                  Sow@getOneTile[#, N@Sqrt@2]] &, #, # != {} &]][[2]],              1] & /@ elmPos, 1];        tiles = Map[fromEuclidean, tiles, {2}];        Return@tiles;        ];


title: Variable scoping in Module

text: I don't understand why $a$ and $b$ are not local in the following code:               Clear[lint];     lint[f_, x_] := Module[{a, b}, f /. Replace[x, {a_, b_} -> a -> b]];          Clear[a];     lint[x, {x, t}] (* returns t, as I would expect *)          a = 3;     lint[x, {x, t}] (* returns x *)          Clear[a]; a=3;     lint1[f_, x_] := Module[{a, b}, f /. Replace[x, {a_, b_} :> a -> b]]; (* returns t *)      It appears that the occurrence of $a$ in the pattern inside the replace is being interpreted in the outer scope. Why is that? Update: Having read @szabolcs comment and the first answer, I still don't quite understand. First, the documentation for `Rule` says that "Symbols that occur as pattern names in lhs are treated as local to the rule.". Fine, that's what the comment said. But if they are local, then why is $3$ substituted for $a$ in the second example above? Second, why does using `:>` solve the problem? The only difference between `Rule` and `RuleDelayed`, as far as I can see, is when the _right-hand_ symbols are evaluated. So why does this change the behavior? (See the new fourth example above).


title: Is it possible to find a function from first few terms in the expansion

text: Is it possible to find a function if first few terms of the expansion is known. For example if I have this series $f(x)=\frac{k^3 x^2}{6}-\frac{k^5 x^4}{120}+\frac{k^7 x^6}{5040}-\frac{k^9 x^8}{362880}+\frac{k^{11} x^{10}}{39916800}+\cdots$, is it possible to find what would be the full function? (answer: $k- \sin(kx)/x$). One suggestion I find for a problem close to this is to use `GeneratingFunction`, but for that It is necessary to know the form the $n^\text{th}$ term in terms of the exponent of different variable which is often quite difficult. What I am looking for is an algorithm which can guess a possible form of the full function if first few terms are given.


title: NDSolve for PDE with discontinuous initial/terminal condition

text: I have an issue with NDSolve for the case of a PDE with discontinuous initial/terminal condition. Consider the PDE solution               Z=z/.First[NDSolve[{       D[z[t,x],t] == z[t,x] D[z[t,x],x]-1/2 (1-t)^2 D[z[t,x],{x,2}],       z[1,x]==UnitStep[x],       z[t,-5000]==0,       z[t,5000]==1},       {z},{t,0,1},{x,-5000,5000}]]      The terminal condition is the discontinuous UnitStep function. When I plot the solution for t=1 now,               Plot[Z[1, x], {x, -10, 10}]      ![plot](http://i.stack.imgur.com/5d344.png) Mathematica has obviously smoothened the terminal condition (which was explicitly given by the UnitStep function). Is it possible to disable this smoothing? Or at least, I want to have a smooth function that does not exceed 1 and does not go below 0. Note: What I am not searching for is a solution like "increase the MaxSteps" or something similar. I am interested in options on how Mathematica processes the initial/terminal condition. Thanks a lot for your help!!


title: Caesar's cipher

text: How can Caesar cipher be implemented? I want to use `StringReplace` but I don't know how to write the replacement rule to replace the characters with, say, the character two positions down in the alphabet.


title: Trying to access Twitter returns Cannot import data as JSON

text: I am trying to use the Social features of Mathematica 10. The Facebook interaction works, but with Twitter I am getting "Cannot import data as JSON". Example:               In[16]:= ServiceExecute["Twitter", "LastTweet", {"ScreenName" ->         "stephen_wolfram"}]          During evaluation of In[16]:= Import::fmterr: Cannot import data as JSON format. >>          Out[16]= ServiceExecute["Twitter", "LastTweet", {"ScreenName" ->         "stephen_wolfram"}]      I have tried `ClearSystemCache[]` but this has no impact. I am getting the valid token from Twitter and it is marked as an allowed App with read access. If I use `SocialMediaData[]` it fails but returns numbers. Example:               In[17]:= SocialMediaData["Twitter", "Followers"] // Short      Generates this: ![output showing numbers](http://i.stack.imgur.com/IplUx.png) Can anyone tell me what I am doing wrong, or how to diagnose/solve this? **[Edit]** Further testing. Restarting the client then `ServiceExecute[]` works. However `SocialMediaData[]` doesn't. Restarting the client and running `SocialMediaData[]` first fails but displays some names. Eg. ![enter image description here](http://i.stack.imgur.com/q5IZz.png) Also I've noticed that ServiceExecute allows you to save your Auth key, but SocialMediaData doesn't.


title: Cannot plot Quantity values with DateListPlot

text: Is there a way to use `DateListPlot` with `Quantity` values? I retrieved the following time series data from WolframAlpha:               gasPrices = WolframAlpha[     "us gas prices", {{"History:Price:GasPriceData", 1},      "TimeSeriesData"}];      Each data point is composed of a date and a `Quantity`:               {{{1993, 4, 5, 0, 0, 0.}, Quantity[1.068, ("USDollars")/("Gallons")]},      {{1993, 4, 19, 0, 0, 0.}, Quantity[1.079, ("USDollars")/("Gallons")]},     ...      {{2012, 12, 31, 0, 0, 0.}, Quantity[3.369, ("USDollars")/("Gallons")]} }      I can plot the values using `ListPlot`:                ListPlot[gasPrices[[All,2]]]      ![enter image description here](http://i.stack.imgur.com/uy8vH.png) Strangely however, `DateListPlot` produces an empty plot:                DateListPlot[gasPrices]      ![Empty plot from DateListPlot](http://i.stack.imgur.com/3Kstn.png) To get `DateListPlot` to produce a proper plot I have to do this instead:               DateListPlot[ Transpose[{gasPrices[[All, 1]], gasPrices[[All, 2, 1]]}] ]      ![OK plot from DateListPlot](http://i.stack.imgur.com/EXfGf.png) Am I missing something? I would have thought that `Quantity` values could be taken directly by `DateListPlot`, as they are by `ListPlot`.


title: Horizontal shift in fitting data by a sinusoidal nonlinear model

text: I have data that can apparently be fitted by a sinusoidal function in form $D+A\sin(B(x-\frac CB))$. I tried doing the best fit in _Mathematica_ using `NonlinearModelFit` function. I got a message saying it failed to converge with current accuracy and max iterations, so I tinkered a little bit with the function, but it made a model far from being the best fit for the data. I tried replacing parameters with constants and it turned out the problem was in finding $B$, or the horizontal shift, since I got a satisfactory fit when I specified the shift. So my question is: Is there a work-around for this problem, so I can find the best horizontal shift? **Note:** I tried it with the form $D+A\sin(Bx-C)$ with the same problem. **Edit:** This is the requested data, note that in the second `NonlinearModelFit`, I specified `b` and it worked like a charm:               data = {{10, 716}, {20, 727}, {30, 744}, {40, 762}, {50, 783},{60, 804},             {70, 826}, {80, 848}, {90, 872}, {100, 894}, {110, 915}, {120, 935},             {130, 954}, {140, 969}, {150, 982}, {160, 990}, {170, 993},              {180, 992}, {190, 986}, {200, 975}, {210, 961}, {220, 944},             {230, 926}, {240, 905}, {250, 883}, {260, 861}, {270, 839},             {280, 817}, {290, 795}, {300, 774}, {310, 755}, {320, 738},             {330, 723}, {340, 712}, {350, 706}, {360, 706}}          NonlinearModelFit[data, d + a Sin[b (x - c)], {a, b, c, d}, x]["BestFit"]      > During evaluation of NonlinearModelFit::cvmit: Failed to converge to the > requested accuracy or precision within 100 iterations. >   >   >     853.439 - 1717.86 Sin[0.94244 (10.0078 + x)] >                 NonlinearModelFit[data, d + a Sin[b (x - c)] /. b -> π/185, {a, c, d}, x]["BestFit"]      > >     849.276 + 141.098 Sin[π/185 (-1930.24 + x)] >


title: Programming a recursive FFT with Mathematica

text: I'm trying to program a FFT using a recursive function in _Mathematica_ , though my program is not getting me anywhere at the moment. Could you say what's wrong with it and what I can do to make it work? My program is the following: (We assume that a is a list of size $2^s$ for some integer $s$)                FFT[a_] :=            (n := Length[a];       If[n == 1, Return[a],       f := Exp[2 I Pi/n];       o := 1;       b := Drop[a, {1, Length[a], 2}];       c := Drop[a, {2, Length[a], 2}];       d := FFT[b];       e := FFT[c];       For[k = 0, k < n/2, k++,       y[k] := d[[{k}]] + o e[[{k}]];       y[k + n/2] := d[[{k}]] - o e[[{k}]];       o = o f]       Return[Table[y[i], {i, 1, n}]]])


title: Intersection of two splines

text: I have a collection of sets of points, each set defining the segment of a (nice) curve on the unit sphere $S^2 \subset \mathbb{R}^3$. The points are computed numerically. I now want to compute the intersection of the curve segments and I would like to get all solutions if two curve segments intersect more than once. The following Mathematica script works but only gives me one solution:               f1 = BSplineFunction[points[[1]]];     f2 = BSplineFunction[points[[2]]];     g[u_, v_] := Norm[f1[u] - f2[v]]     NMinimize[{g[x, y], 0 <= x <= 1, 0 <= y <= 1}, {x, y}]      Using               NSolve[g[x, y] == 0, {x, y}]      simply yields the function call as an output, and               FindRoot[g[x, y] == 0, {{x, 0.5, 0, 1}, {y, 0.5, 0, 1}}]      complains that the number of variables does not match the number of equations. Any suggestions on how to solve this? Edit2: This is a sample of the data I am using that I would like to yield two points of intersection               points =     {{{ 0.0563319, -0.0207277,  -0.998197}, { 0.0468164,  -0.020208,  -0.998699},        { 0.0361213, -0.0187319,  -0.999172}, { 0.0269836,  -0.0165999, -0.999498},        { 0.0191223, -0.0140227,  -0.999719}, { 0.0122367,  -0.0111131, -0.999863},        { 0.00603102,-0.00789628, -0.999951}, { 0.000232715,-0.00432551,-0.999991},        {-0.00539442,-0.000299408,-0.999985}, {-0.0110431,   0.00431947,-0.99993},        {-0.0168598,  0.00968684, -0.999811}, {-0.0229461,   0.0159607, -0.999609},        {-0.0293624,  0.0232877,  -0.999298}, {-0.036133,    0.031792,  -0.998841},        {-0.0432526,  0.0415674,  -0.998199}, {-0.0506922,   0.0526714, -0.997324}},       {{-0.0563319,  0.0207277,  -0.998197}, {-0.0468164,   0.020208,  -0.998699},        {-0.0361213,  0.0187319,  -0.999172}, {-0.0269836,   0.0165999, -0.999498},        {-0.0191223,  0.0140227,  -0.999719}, {-0.0122367,   0.0111131, -0.999863},        {-0.00603102, 0.00789628, -0.999951}, {-0.000232715, 0.00432551,-0.999991},        { 0.00539442, 0.000299408,-0.999985}, { 0.0110431,  -0.00431947,-0.99993},       { 0.0168598, -0.00968684, -0.999811}, { 0.0229461,  -0.0159607, -0.999609},        { 0.0293624, -0.0232877,  -0.999298}, { 0.036133,   -0.031792,  -0.998841},        { 0.0432526, -0.0415674,  -0.998199}, { 0.0506922,  -0.0526714, -0.997324}}};


title: Finding the intersection of a curve with an interpolation function

text: There are no issues trying to find the intersection points of two defined curves.                   f[x_] := 2 (x - 1) (x - 1.5) (x - .5) (x + .5) (x + 1) (x + 1.5);         g[x_] := 0.4 x - 0.4;         Solve[f[x] == g[x], x]         (*{{x -> -1.39849}, {x -> -1.20949}, {x -> -0.331841}, {x ->            0.426865}, {x -> 1.}, {x -> 1.51295}}*)         Manipulate[Plot[Evaluate[{f[x], g[x]}], {x, -1.5, 1.52},                     Epilog -> {Red, PointSize[Large],                     Point[{#, f[#]} & /@ (x /.                     Solve[f[x] == g[x], x])]}], {a, -0.8, .5, .2}]      ![enter image description here](http://i.stack.imgur.com/HUdTQ.png) When I try to perform the same but this time with an interpolation function I run into problems.               points = Table[{x, f[x]}, {x, -1.5, 1.5, .25}];     if = Interpolation[points];      I can obtain the first intersection by using the following. Neither NSolve nor Solve will work with interpolation function. With Solve this will happen               Solve[if[x] == g[x], x]      Solve::inex: Solve was unable to solve the system with inexact coefficients or the system obtained by direct rationalization of inexact numbers present in the system. Since many of the methods used by Solve require exact input, providing Solve with an exact version of the system may help. >> With NSolve, you get a similar error.               NSolve[if[x] == g[x], x, Reals]      ( _NSolve[InterpolatingFunction[{{-1.5,1.5}}, <>][x]==-0.4+0.4 x,x,Reals]_)               FindRoot[if[x] == g[x], {x, -1.5}]     (*{x -> -1.36794}*)      Which makes this question different from marking points of intersections between two curves as the problem is specific when using InterpolationFunction What is the best way to find all intersection points between the range (-1.5 and 1.5)?


title: How to Invert a Multivariate Interpolating Function?

text: I used NSolve on a partial differential equation with boundary conditions to get a numerical solution that Mathematica says is of the form InterpolatingFunction. I then defined a function f(x,y) which evaluates this solution for a given (x,y). I want to be able to retrieve all of the values of (x,y) such that f(x,y) = C for a given constant C, and then pick the (x,y) in this set that maximizes a different (non-interpolative) function g(x,y). Is this possible? If so, how?


title: How I can use Apply or Map with If?

text: I have list of objects:                list = {{1, 1, 0.05, 0.05}, {2, 2, 0.05, 0.05}, {13, 13, 0.05, 0.05}};           list = {{x,y,Vx,Vy},{x,y,Vx,Vy},...};      And               object = {10, 10};      I want when I change position of object the objects from the list to follow the first object. I try with this:               If[object[[1]] < #1 && #3 > 0, list = {#1,#2,-#3 ,#4}, list = {#1,#2,#3,#4}] &@@@list     If[object[[1]] > #1 && #3 < 0, list = {#1,#2,-#3 ,#4}, list = {#1,#2,#3,#4}] &@@@list     If[object[[2]] < #1 && #4 > 0, list = {#1,#2,#3 ,-#4}, list = {#1,#2,#3,#4}] &@@@list     If[object[[2]] < #1 && #4 < 0, list = {#1,#2,#3 ,-#4}, list = {#1,#2,#3,#4}] &@@@list      and works but only the first cycle. I know that I can do this with:               If[object[[1]] < list[[1, 1]] && list[[1, 3]] > 0, list[[1, 3]] *= -1]....      But is very slow and not look nice :). And doesn't work completely correct.


title: Plot electric potential and field

text: I am trying to plot an electric pottentional of a dielectric cylinder along with it's field. The pottentional is a piecewise function               F[r_, f_] :=       Piecewise[{{-2 e r Cos[f]/(1 + er),      0 <= r < a}, {-e r Cos[f] + (er - 1)*a^2 *e*r^(-1)*Cos[f],      r >= a}}](*electorstatic pottential*)     e = 500;(*outer electric field*)     a = 0.02;(*cylinder's radius*)     er = 2;(*relevant acceptance*)      What's the best way to plot this function(pottential), with it's derivative(electric field)? I tried to plot it using `ContourPLot` but it doesn't look nice(I am not a Mathematica expert apparently)               ContourPlot[-2 e r Cos[f]/(1 + er), {r, 0, a}, {f, 0, 2 Pi}]     ContourPlot[-e r Cos[f] + (er - 1)*a^2 *e*r^(-1)*Cos[f], {r, a,      2 a}, {f, 0, 2 Pi}]     Show[%, %%]      ![](http://i.imgur.com/FkJkt.png) What I am trying to achive is a sophisticated plot,with the cylinder at the origin, where the equipottential lines and the electric field lines will be plotted. I found something like that on the net (specifically the page "Gradient field plots in Mathematica"), but I don't know how to modify it...               gradientFieldPlot[f_, rx_, ry_, opts : OptionsPattern[]] :=       Module[{img, cont, densityOptions, contourOptions, frameOptions,         gradField, field, plotRangeRule, rangeCoords},        densityOptions =         Join[FilterRules[{opts},           FilterRules[Options[DensityPlot],            Except[{Prolog, Epilog, FrameTicks, PlotLabel, ImagePadding,              GridLines, Mesh, AspectRatio, PlotRangePadding, Frame,              Axes}]]], {PlotRangePadding -> None, Frame -> None,           Axes -> None, AspectRatio -> Automatic}];       contourOptions =         Join[FilterRules[{opts},           FilterRules[Options[ContourPlot],            Except[{Prolog, Epilog, FrameTicks, PlotLabel, Background,              ContourShading, PlotRangePadding, Frame, Axes,              ExclusionsStyle}]]], {PlotRangePadding -> None, Frame -> None,           Axes -> None, ContourShading -> False}];       gradField = ComplexExpand[{D[f, rx[[1]]], D[f, ry[[1]]]}];       field =         DensityPlot[Norm[gradField], rx, ry,          Evaluate@Apply[Sequence, densityOptions]];       img = Rasterize[field, "Image"];       plotRangeRule = FilterRules[Quiet@AbsoluteOptions[field], PlotRange];       cont = If[         MemberQ[{0,            None}, (Contours /. FilterRules[{opts}, Contours])], {},          ContourPlot[f, rx, ry, Evaluate@Apply[Sequence, contourOptions]]];       frameOptions =         Join[FilterRules[{opts},           FilterRules[Options[Graphics],            Except[{PlotRangeClipping, PlotRange}]]], {plotRangeRule,           Frame -> True, PlotRangeClipping -> True}];       rangeCoords = Transpose[PlotRange /. plotRangeRule];       Apply[Show[          Graphics[{Inset[             Show[SetAlphaChannel[img,                "ShadingOpacity" /. {opts} /. {"ShadingOpacity" -> 1}],               AspectRatio -> Full], rangeCoords[[1]], {0, 0},              rangeCoords[[2]] - rangeCoords[[1]]]}], cont,           StreamPlot[gradField, rx, ry,            Evaluate@FilterRules[{opts}, StreamStyle],            Evaluate@FilterRules[{opts}, StreamColorFunction],            Evaluate@FilterRules[{opts}, StreamColorFunctionScaling],            Evaluate@FilterRules[{opts}, StreamPoints],            Evaluate@FilterRules[{opts}, StreamScale]], ##] &,         frameOptions]]      This can be run like that               gradientFieldPlot[(y^2 + (x - 2)^2)^(-1/         2) - (y^2 + (x - 1/2)^2)^(-1/2)/2, {x, -1.5, 2.5}, {y, -1.5,        1.5}, PlotPoints -> 50, ColorFunction -> "BlueGreenYellow",       Contours -> 10, ContourStyle -> White, Frame -> True,       FrameLabel -> {"x", "y"}, ClippingStyle -> Automatic, Axes -> True,       StreamStyle -> Orange]      And the amazing output is ![](http://i.imgur.com/qlDMM.png) What I would like to do is ![](http://i.imgur.com/1JVe9.jpg)


title: Can you call a C function that takes function pointers as arguments?

text: I want to use MathLink to call a function I wrote in C. However, similar to an integrator, it takes a function pointer as an argument and applies it on numbers depending on the other arguments. I know how to pass lists of reals and so on, but can you also pass pointers to functions defined in Mathematica? In the end, it should look something like this:               f[x_,y_] := x*y; Install["mycprogram"]; MyCFunction[f,1,2]      `f` is a function that takes two doubles and returns a double. It's fairly simple and should always be some combination of polynomials, fractions, `Log` and `Exp`.


title: Visualize cluster distances in DendrogramPlot

text: I want to perform a cluster analysis using the `HierarchicalClustering` package. Is there a way to display the inter-cluster distances in a dendrogram plot? An example how the result should look like: ![here](http://i.stack.imgur.com/DsPJT.jpg).


title: Initializing Minimization

text: I am trying to implement a model predictive control scheme in _Mathematica_ , e.g. I optimize input sequences by predicting future outputs. So every time I call the cost function it will simulate the system and produce the desired function value. Since the cost function has to call `NDSolve`, there is no symbolic representation and trying to call the cost with symbolic variables will not produce any results. Now, whenever I try to minimize my cost function, _Mathematica_ tries to evaluate the cost function symbolically:               FindMinimum[J[As, bs, cs, x0s, predY, Table[u[i], {i, 10}], 49, g, .1], Table[{u[i], 0}, {i, 10}]]     (* NDSolve::ndnum: Encountered non-numerical value for a derivative at t == 0.`. >>        ReplaceAll::reps: {NDSolve[{(x[1]')[t]==0. +1. x[2][t],(x[2]')[t]==0. +1. x[3][t],(x[3]')[t]==0. +u[1]-7.90817 x[2][t]-7.5181 x[3][t],x[1][0]==6.29161,x[2][0]==7.04417,x[3][0]==6.94553},{x[1],x[2],x[3]},{t,0,0.1}]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >> *)      and a couple of more like that telling me that _Mathematica_ doesn't know what to do with nonnumerical values. How can I force _Mathematica_ to initialize the minimization numerically, without trying to find some gradient symbolically?


title: How do I get the critical value in statistical hypothesis testing?

text: What I am trying to do is to get the value of $\chi^2$ for given probability (let us say $\alpha$=0.01) and degrees of freedom (for example df=3). How do I get that? Inverse...Distribution functions return something quite different from expected. Thanks in advance.


title: Question about sum and list in a function

text: I have a list of this form: $ lst =\left\\{\left\\{q_1,x_1,y_1,z_1\right\\},\left\\{q_2,x_2,y_2,z_2\right\\},\text{...},\left\\{q_n,x_n,y_n,z_n\right\\}\right\\} $ I want to use this list in the function: $V(\\{x,y,z\\})=\sum _{i=1}^n \frac{q_i}{\sqrt{\left(x_i-x\right){}^2+\left(y_i-y\right){}^2+\left(z_i-z\right){}^2}}$ Where n is the lenght of the list n = Length[lst]. I am not sure how i get this into a inpute code. I have tried the following with the list lst and function v2 :               lst= {{1, 0, 0, 0}, {1, -1, 0, 0}, {1, 1, 0, 0}};       $ \text{V2}(\\{\text{x$\\_$},\text{y$\\_$},\text{z$\\_$}\\},\text{lst$\\_$})\text{:=}\sum _{i=1}^n \frac{\text{lst}[[\text{All},1]]}{\sqrt{\left(\text{lst}[[\text{All},2]]_i-x\right){}^2+\left(\text{lst}[[\text{All},3]]_i-y\right){}^2+\left(\text{lst}[[\text{All},4]]_i-z\right){}^2}}$                   V2[{x_, y_, z_}, lst_] :=             Sum[lst[[All,1]]/Sqrt[(Subscript[lst[[All,2]], i] - x)^2 + (Subscript[lst[[All,3]], i] - y)^2 +                 (Subscript[lst[[All,4]], i]- z)^2], {i, 1, n}];       * * *                   Apply[V2, {{x, y, z}, lst}]      Gives : $ \left.\frac{1}{\sqrt{\left(\\{0,-1,1\\}_2-x\right){}^2+\left(\\{0,0,0\\}_2-y\right){}^2+\left(\\{0,0,0\\}_2-z\right){}^2}}+\frac{1}{\sqrt{\left(\\{0,-1,1\\}_3-x\right){}^2+\left(\\{0,0,0\\}_3-y\right){}^2+\left(\\{0,0,0\\}_3-z\right){}^2}}+\frac{1}{\sqrt{\left(\\{0,-1,1\\}_1-x\right){}^2+\left(\\{0,0,0\\}_1-y\right){}^2+\left(\\{0,0,0\\}_1-z\right){}^2}},\frac{1}{\sqrt{\left(\\{0,-1,1\\}_2-x\right){}^2+\left(\\{0,0,0\\}_2-y\right){}^2+\left(\\{0,0,0\\}_2-z\right){}^2}}+\frac{1}{\sqrt{\left(\\{0,-1,1\\}_3-x\right){}^2+\left(\\{0,0,0\\}_3-y\right){}^2+\left(\\{0,0,0\\}_3-z\right){}^2}}+\frac{1}{\sqrt{\left(\\{0,-1,1\\}_1-x\right){}^2+\left(\\{0,0,0\\}_1-y\right){}^2+\left(\\{0,0,0\\}_1-z\right){}^2}},\frac{1}{\sqrt{\left(\\{0,-1,1\\}_2-x\right){}^2+\left(\\{0,0,0\\}_2-y\right){}^2+\left(\\{0,0,0\\}_2-z\right){}^2}}+\frac{1}{\sqrt{\left(\\{0,-1,1\\}_3-x\right){}^2+\left(\\{0,0,0\\}_3-y\right){}^2+\left(\\{0,0,0\\}_3-z\right){}^2}}+\frac{1}{\sqrt{\left(\\{0,-1,1\\}_1-x\right){}^2+\left(\\{0,0,0\\}_1-y\right){}^2+\left(\\{0,0,0\\}_1-z\right){}^2}}\right\\}$ But i am expecting to get $\frac{1}{\sqrt{x^2+y^2+z^2}}+\frac{1}{\sqrt{(x+1)^2+y^2+z^2}}+\frac{1}{\sqrt{(x-1)^2+y^2+z^2}} $ What am i doing wrong?


title: Why didn't Reduce give me the right result?

text: My code:               Clear[r1, r2];      par[r1_, r2_] := r1 r2 / (r1 + r2);      Reduce[{5 par[r2, 32000]/(r1 + par[r2, 32000]) == 1.8 && par[r1, r2] == 5000}, {r1, r2}]      with this result: ![enter image description here](http://i.stack.imgur.com/xGpr3.png) I checked it a dozen times, but I can't see why MMA doesn't give me a value for r1. So, like I always do when I'm desperate :-), I quit and restarted MMA. Copied and pasted my input. And ecco!: ![enter image description here](http://i.stack.imgur.com/g5go4.png) Any idea what could have caused the first result?


title: Probability of the sum of the largest n samples

text: 15 numbers are randomly chosen from U(0,1), what is the probability that the sum of largest four numbers is greater than 3.5?                   With[{f = OrderDistribution[{UniformDistribution[], 15}, #] &},           Probability[a + b + c + d > 3 + 1 / 2,           {a \[Distributed] f[15], b \[Distributed] f[14], c \[Distributed] f[13],           d\[Distributed] f[12]}]]      Trouble is, it is very, very slow. I shut it down after 30 minutes. When I used NProbability it converged on the wrong answer but it did warn me with numerous error messages. Another CAS could do the above code but it also returned the same wrong answer. The right answer is supposed to be (it at least agrees with a simulation): $\frac{224077804910008595}{584325558976905216} $ $\approx 0.383481094515780$ How do I do this using Mathematica?


title: First evaluation fails

text: I am fairly new to _Mathematica_ (version 7), so please bear with me... I have duplicated, in _Mathematica_ , a program that I originally wrote in C (it generates OEIS sequence A191837). The problem is that each time I make a change to the function `nCk` the first evaluation doesn't print. I have to stop the evaluation and then start it again to see the result of my change. What am I missing? Also, does anyone have any tips on how to make the code more compact?               For[smnds = 4; m = 6, smnds <= 60, m += 6,       s = {};       sum = smndct = pct = 0;       For[p = 5, p < m/2, p += 2,        If[PrimeQ[p] && PrimeQ[m - p],         If[sum + p > m, Break[]];         If[smndct++ < smnds - 1, sum += p];         AppendTo[s, p];         pct++]];       If[pct >= smnds, sdf = Range[smnds];        While[nCk[Length[s], smnds]]]       ];     (* Subsets[] uses too much memory, so process each         combination one at a time. *)      nCk[vy_, vz_] :=       Block[{indx = ns = vy, i = rs = vz, ct = tot = 0},        If[(sdf[[1]] - 1) == (ns - rs),         For[ct = 1, ct <= rs, ct++, tot += s[[sdf[[ct]]]]];         If[tot == m, Print["a(", smnds/2, ") = ", tot];          smnds += 2; m -= 6; Return[False], Return[False]]];        While[sdf[[i]] == indx && i > 1, --i; --indx];        sdf[[i]] += 1;        i++;        While[i <= rs, sdf[[i]] = sdf[[i - 1]] + 1; ++i;];        For[ct = 1, ct <= rs, ct++, tot += s[[sdf[[ct]]]];         If[tot > m, Break[]]];        If[tot == m, Print["a(", smnds/2, ") = ", tot];         smnds += 2; m -= 6; Return[False]];        Return[True]        ];


title: Undocumented Dynamic Function question

text: In the code below the value displayed next to the slider may be correct, and should be the result of The value of `x` for `cyL` and the value of `x` for change at the slider position. Slider position 0 should provide the first values for `x` in these lines. Now if I evaluate `x`outside of the function after moving the sliders, it only returns the slider position and not the value of `x` from the function. How can I get the variable to return the correct value for each slider? Thanks!               cyL[x_] :=        58.770000000000046` - 3.557000000000158` x -         3.525333333333144` x^2 + 4.987999999999908` x^3 -         1.3386666666666487` x^4;          cyA[y_] := -35.13365403304179` - 0.009572400388682331` y +         0.08989310009715228` y^2 - 0.01687074829931251` y^3;          change[x_] := -0.17006802721089645` + 62.92517006802724` x -         6.802721088435384` x^2;          Column[{{Slider[Dynamic[x, Automatic]],         Dynamic[cyL[change[x]]]}, {Slider[Dynamic[g, Automatic]],         Dynamic[cyA[change[g]]]}}]


title: Plot Indefinite integral

text: I'm having a hard time to find a solution to a numerical limitation on mathematica:               PwD = 0.005*Integrate[(Exp[-(0.25/\[Tau])]/\[Tau])*       Integrate[Exp[-((Tan[45*Degree]^2 - (z + 30)^2)/(4*\[Tau]))]*              (1 +            2*Sum[Exp[-((n^2*Pi^2*\[Tau])/10000)]*Cos[0.8*n*Pi]*              Cos[(n*Pi)/2 - (n*Pi*z)/100], {n, 1, 4}]), {z, -50,          50}], {\[Tau], 0, t}]      ![Mathematica graphics](http://i.stack.imgur.com/vKNct.png) After solving the integral in space `{z,-50,50}` I need to evaluate the indefinite integral in time `{tau,0,t}`, so I eventually generate a plot of `PwD` as function of `Log[t]`. But it seems that it does not converge. Can someone provide an alternative way? * * * Hi everybody thanks for the comments... They sound about right! In the past 2 months I dedicated my time to derive these solutions again - once I had no help from the author. Well, I finally get it! The published expression has a type mistake... The right equation should be:               PwD = (1/200)*Integrate[         (1/(E^(0.25/\[Tau])*\[Tau]))*Integrate[           (1 + 2*Sum[(Cos[0.8*n*Pi]*Cos[(n*Pi)/2 -                    (n*Pi*z)/100])/E^((n^2*Pi^2*\[Tau])/                  10000), {n, 1, 100}])/            E^((Tan[\[Psi]*Degree]^2*(z + 30)^2)/(4*\[Tau])),            {z, -50, 50}], {\[Tau], 0, t}]      Now I'm able to generate the graphics. For different angles `\[Psi]` this is what I did:               Pw1 = (Exp[-0.25/t]/t)*        Integrate[         Exp[-(((Tan[0 Degree]^2)*(z + 30)^2)/(4*t))]*(1 +             2*Sum[Exp[-((n^2)*(Pi^2)*t)/(100^2)]*Cos[0.8*n*Pi]*               Cos[(n*Pi/2) - (n*Pi*z/100)], {n, 1, 100}]), {z, -50, 50}];     Pw2 = (Exp[-0.25/t]/t)*        Integrate[         Exp[-(((Tan[30 Degree]^2)*(z + 30)^2)/(4*t))]*(1 +             2*Sum[Exp[-((n^2)*(Pi^2)*t)/(100^2)]*Cos[0.8*n*Pi]*               Cos[(n*Pi/2) - (n*Pi*z/100)], {n, 1, 100}]), {z, -50, 50}];     Pw3 = (Exp[-0.25/t]/t)*        Integrate[         Exp[-(((Tan[60 Degree]^2)*(z + 30)^2)/(4*t))]*(1 +             2*Sum[Exp[-((n^2)*(Pi^2)*t)/(100^2)]*Cos[0.8*n*Pi]*               Cos[(n*Pi/2) - (n*Pi*z/100)], {n, 1, 100}]), {z, -50, 50}];          PD1[y_] := 0.005*NIntegrate[Pw1, {t, 0, y}, MaxRecursion -> 20];     PD2[y_] := 0.005*NIntegrate[Pw2, {t, 0, y}, MaxRecursion -> 20];     PD3[y_] := 0.005*NIntegrate[Pw3, {t, 0, y}, MaxRecursion -> 20];          T1 = Table[{y,          PD1[y]}, {y, {0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 2,           2.2, 2.5, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,           18, 19, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85,           90, 100, 110, 120, 130, 140, 150, 200, 250, 300, 350, 400, 450,           500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000, 1100,           1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200,           2300, 2400, 2500, 2600, 2700, 2800, 2900, 3000, 3500, 4000,           4500, 5000, 5500, 6000, 6500, 7000, 7500, 8000, 8500, 9000, 9500,           10000, 11000, 13000, 15000, 17000, 19000, 20000, 22000, 24000,           26000, 28000, 30000, 35000, 40000, 45000, 50000, 55000, 60000,           65000, 70000, 75000, 80000, 90000, 95000, 100000, 150000, 200000,           250000, 300000, 350000, 400000, 450000, 500000, 550000, 600000,           700000, 800000, 900000, 1000000}}];     T2 = Table[{y,          PD2[y]}, {y, {0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 2,           2.2, 2.5, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,           18, 19, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85,           90, 100, 110, 120, 130, 140, 150, 200, 250, 300, 350, 400, 450,           500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000, 1100,           1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200,           2300, 2400, 2500, 2600, 2700, 2800, 2900, 3000, 3500, 4000,           4500, 5000, 5500, 6000, 6500, 7000, 7500, 8000, 8500, 9000, 9500,           10000, 11000, 13000, 15000, 17000, 19000, 20000, 22000, 24000,           26000, 28000, 30000, 35000, 40000, 45000, 50000, 55000, 60000,           65000, 70000, 75000, 80000, 90000, 95000, 100000, 150000, 200000,           250000, 300000, 350000, 400000, 450000, 500000, 550000, 600000,           700000, 800000, 900000, 1000000}}];     T3 = Table[{y,          PD3[y]}, {y, {0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 2,           2.2, 2.5, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,           18, 19, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85,           90, 100, 110, 120, 130, 140, 150, 200, 250, 300, 350, 400, 450,           500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000, 1100,           1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200,           2300, 2400, 2500, 2600, 2700, 2800, 2900, 3000, 3500, 4000,           4500, 5000, 5500, 6000, 6500, 7000, 7500, 8000, 8500, 9000, 9500,           10000, 11000, 13000, 15000, 17000, 19000, 20000, 22000, 24000,           26000, 28000, 30000, 35000, 40000, 45000, 50000, 55000, 60000,           65000, 70000, 75000, 80000, 90000, 95000, 100000, 150000, 200000,           250000, 300000, 350000, 400000, 450000, 500000, 550000, 600000,           700000, 800000, 900000, 1000000}}];          PwD1 = Interpolation[T1];     PwD2 = Interpolation[T2];     PwD3 = Interpolation[T3];          P1 = LogLogPlot[{PwD1[y], y*PwD1'[y]}, {y, 0.1, 1000000},         PlotRange -> {0.01, 10}, PlotStyle -> {{Black}, {Dashed, Black}},         Frame -> True, FrameLabel -> {tD, "PD e tD*PD'"},         BaseStyle -> {FontSize -> 12}];     P2 = LogLogPlot[{PwD2[y], y*PwD2'[y]}, {y, 0.1, 1000000},         PlotRange -> {0.01, 10}, PlotStyle -> {{Brown}, {Dashed, Brown}}];     P3 = LogLogPlot[{PwD3[y], y*PwD3'[y]}, {y, 0.1, 1000000},         PlotRange -> {0.01, 10}, PlotStyle -> {{Purple}, {Dashed, Purple}}];          Show[P1, P2, P3]      The problem is that it takes a very long time to compute these codes... Since I don't have good programming skills, could anyone propose an alternative way to computing this plot? thanks


title: Explanation on why Compile statement works only if input and output sizes work

text: I found the following code:               Compile[{{m, _Real, 2}}, Fourier[m]][Table[N[i - j], {i, 4}, {j, 4}]]      which doesn't work correctly. But the following was posted as a correction:               Compile[{{m, _Real, 2}}, Fourier[m],              {{_Fourier,_Complex,2}}][ Table[N[i-j],{i,4},{j,4}] ]      Firstly, why does Compile care about matching the size of the input and output? Secondly, could someone kindly explain to me why the above works?


title: VectorPlot: How can I evaluate the vector field by clicking on the plot?

text: This seems like a basic feature that is somehow missing. Ideally we'd get something like a tooltip which shows the x,y position where I click (or of where the mouse is currently hovering) and the evaluated vector (or scalar in the case of a scalar field) at that position. I think this would be a great way to "get a feel for" the values because by default the arrows are scaled automatically so they fit so I don't know anything about the relative magnitude of a particular arrow. I have found that this is a good way to get a tooltip which displays the current mouse coordinates really well, but it obviously won't evaluate my vector field for me.


title: Should Row be used in place of StringForm?

text: I've been using _Mathematica_ for a long time, so I have a habit of using some of the older functions even when newer, better ones have been added to replace them. `StringForm` is one such function. I have the habit of using it with `Print` as the _Mathematica_ analog of C's `printf` when I need debugging output. Today, when I found myself typing `Print[StringForm[ ...` once again, the thought "why am I not using `Row`?" occurred to me. Indeed, why not? `Row` has been in _Mathematica_ since ver. 6. It looks to me it can do anything that `StringForm` can do and a lot more. However, WRI has not deprecated `StringForm`, so I wonder: should `Row` always be used in place of `StringForm`? Or is there still some use cases where `StringForm` is better?


title: How can I visualize an array of very small vectors spaced on very large grid?

text: I have data in the form               points = {{1, 1, 1}, {1, 1, 2}, ...}          vectors = {{2, 2, 5}, {2, 1, 7}, ...}      Can somebody help to edit this data so I can ListVectorPlot a vector `point[[i]] + vector[[i]]` from a point `point[[i]]`? Nothing seems to work! :( The data I have to work with is:               points = {{-100, -100, 0}, {-100, -80, 0}, {-100, -60, 0}, {-100, -40,         0}, {-100, -20, 0}, {-100, 0, 0}, {-100, 20, 0}, {-100, 40,         0}, {-100, 60, 0}, {-100, 80, 0}, {-100, 100, 0}, {-80, -100,         0}, {-80, -80, 0}, {-80, -60, 0}, {-80, -40, 0}, {-80, -20,         0}, {-80, 0, 0}, {-80, 20, 0}, {-80, 40, 0}, {-80, 60, 0}, {-80,         80, 0}, {-80, 100, 0}, {-60, -100, 0}, {-60, -80, 0}, {-60, -60,         0}, {-60, -40, 0}, {-60, -20, 0}, {-60, 0, 0}, {-60, 20, 0}, {-60,         40, 0}, {-60, 60, 0}, {-60, 80, 0}, {-60, 100, 0}, {-40, -100,         0}, {-40, -80, 0}, {-40, -60, 0}, {-40, -40, 0}, {-40, -20,         0}, {-40, 0, 0}, {-40, 20, 0}, {-40, 40, 0}, {-40, 60, 0}, {-40,         80, 0}, {-40, 100, 0}, {-20, -100, 0}, {-20, -80, 0}, {-20, -60,         0}, {-20, -40, 0}, {-20, -20, 0}, {-20, 0, 0}, {-20, 20, 0}, {-20,         40, 0}, {-20, 60, 0}, {-20, 80, 0}, {-20, 100, 0}, {0, -100,         0}, {0, -80, 0}, {0, -60, 0}, {0, -40, 0}, {0, -20, 0}, {0, 0,         0}, {0, 20, 0}, {0, 40, 0}, {0, 60, 0}, {0, 80, 0}, {0, 100,         0}, {20, -100, 0}, {20, -80, 0}, {20, -60, 0}, {20, -40,         0}, {20, -20, 0}, {20, 0, 0}, {20, 20, 0}, {20, 40, 0}, {20, 60,         0}, {20, 80, 0}, {20, 100, 0}, {40, -100, 0}, {40, -80,         0}, {40, -60, 0}, {40, -40, 0}, {40, -20, 0}, {40, 0, 0}, {40, 20,         0}, {40, 40, 0}, {40, 60, 0}, {40, 80, 0}, {40, 100, 0}, {60, -100,         0}, {60, -80, 0}, {60, -60, 0}, {60, -40, 0}, {60, -20, 0}, {60,         0, 0}, {60, 20, 0}, {60, 40, 0}, {60, 60, 0}, {60, 80, 0}, {60,         100, 0}, {80, -100, 0}, {80, -80, 0}, {80, -60, 0}, {80, -40,         0}, {80, -20, 0}, {80, 0, 0}, {80, 20, 0}, {80, 40, 0}, {80, 60,         0}, {80, 80, 0}, {80, 100, 0}, {100, -100, 0}, {100, -80,         0}, {100, -60, 0}, {100, -40, 0}, {100, -20, 0}, {100, 0, 0}, {100,         20, 0}, {100, 40, 0}, {100, 60, 0}, {100, 80, 0}, {100, 100, 0}}      and               vectors = {{0., 0., -2.94877*10^-11}, {0., 0., -3.17712*10^-11}, {0.,         0., -3.15544*10^-11}, {0., 0., -2.67049*10^-11}, {0.,         0., -1.57288*10^-11}, {0., 0., 0.}, {0., 0., 1.57288*10^-11}, {0.,         0., 2.67049*10^-11}, {0., 0., 3.15544*10^-11}, {0., 0.,         3.17712*10^-11}, {0., 0., 2.94877*10^-11}, {0.,         0., -3.97097*10^-11}, {0., 0., -4.60745*10^-11}, {0.,         0., -5.00432*10^-11}, {0., 0., -4.66251*10^-11}, {0.,         0., -2.97483*10^-11}, {0., 0., 0.}, {0., 0., 2.97483*10^-11}, {0.,         0., 4.66251*10^-11}, {0., 0., 5.00432*10^-11}, {0., 0.,         4.60745*10^-11}, {0., 0., 3.97097*10^-11}, {0.,         0., -5.2583*10^-11}, {0., 0., -6.67217*10^-11}, {0.,         0., -8.19101*10^-11}, {0., 0., -8.89697*10^-11}, {0.,         0., -6.59367*10^-11}, {0., 0., 0.}, {0., 0., 6.59367*10^-11}, {0.,         0., 8.89697*10^-11}, {0., 0., 8.19101*10^-11}, {0., 0.,         6.67217*10^-11}, {0., 0., 5.2583*10^-11}, {0.,         0., -6.67523*10^-11}, {0., 0., -9.3246*10^-11}, {0.,         0., -1.33453*10^-10}, {0., 0., -1.84298*10^-10}, {0.,         0., -1.86496*10^-10}, {0., 0., 0.}, {0., 0., 1.86496*10^-10}, {0.,         0., 1.84298*10^-10}, {0., 0., 1.33453*10^-10}, {0., 0.,         9.3246*10^-11}, {0., 0., 6.67523*10^-11}, {0.,         0., -7.86329*10^-11}, {0., 0., -1.18988*10^-10}, {0.,         0., -1.97808*10^-10}, {0., 0., -3.72992*10^-10}, {0.,         0., -7.37191*10^-10}, {0., 0., 0.}, {0., 0., 7.37191*10^-10}, {0.,         0., 3.72992*10^-10}, {0., 0., 1.97808*10^-10}, {0., 0.,         1.18988*10^-10}, {0., 0., 7.86329*10^-11}, {0.,         0., -3.13741*10^-11}, {0., 0., -4.65701*10^-11}, {0.,         0., -7.45312*10^-11}, {0., 0., -1.2865*10^-10}, {0.,         0., -2.005*10^-10}, {0., 0., 0.}, {0., 0., 2.005*10^-10}, {0., 0.,         1.2865*10^-10}, {0., 0., 7.45312*10^-11}, {0., 0.,         4.65701*10^-11}, {0., 0., 3.13741*10^-11}, {0.,         0., -7.86329*10^-11}, {0., 0., -1.18988*10^-10}, {0.,         0., -1.97808*10^-10}, {0., 0., -3.72992*10^-10}, {0.,         0., -7.37191*10^-10}, {0., 0., 0.}, {0., 0., 7.37191*10^-10}, {0.,         0., 3.72992*10^-10}, {0., 0., 1.97808*10^-10}, {0., 0.,         1.18988*10^-10}, {0., 0., 7.86329*10^-11}, {0.,         0., -6.67523*10^-11}, {0., 0., -9.3246*10^-11}, {0.,         0., -1.33453*10^-10}, {0., 0., -1.84298*10^-10}, {0.,         0., -1.86496*10^-10}, {0., 0., 0.}, {0., 0., 1.86496*10^-10}, {0.,         0., 1.84298*10^-10}, {0., 0., 1.33453*10^-10}, {0., 0.,         9.3246*10^-11}, {0., 0., 6.67523*10^-11}, {0.,         0., -5.2583*10^-11}, {0., 0., -6.67217*10^-11}, {0.,         0., -8.19101*10^-11}, {0., 0., -8.89697*10^-11}, {0.,         0., -6.59367*10^-11}, {0., 0., 0.}, {0., 0., 6.59367*10^-11}, {0.,         0., 8.89697*10^-11}, {0., 0., 8.19101*10^-11}, {0., 0.,         6.67217*10^-11}, {0., 0., 5.2583*10^-11}, {0.,         0., -3.97097*10^-11}, {0., 0., -4.60745*10^-11}, {0.,         0., -5.00432*10^-11}, {0., 0., -4.66251*10^-11}, {0.,         0., -2.97483*10^-11}, {0., 0., 0.}, {0., 0., 2.97483*10^-11}, {0.,         0., 4.66251*10^-11}, {0., 0., 5.00432*10^-11}, {0., 0.,         4.60745*10^-11}, {0., 0., 3.97097*10^-11}, {0.,         0., -2.94877*10^-11}, {0., 0., -3.17712*10^-11}, {0.,         0., -3.15544*10^-11}, {0., 0., -2.67049*10^-11}, {0.,         0., -1.57288*10^-11}, {0., 0., 0.}, {0., 0., 1.57288*10^-11}, {0.,         0., 2.67049*10^-11}, {0., 0., 3.15544*10^-11}, {0., 0.,         3.17712*10^-11}, {0., 0., 2.94877*10^-11}}      This code works               Graphics3D[        Table[{Arrowheads[Small],           Arrow[{tocke[[i]], polje[[i]] + tocke[[i]]}]}, {i, 1, 121}],         Axes -> True, AxesLabel -> {x, y}]      but I don't like the ouput and hopefully `ListVectorPlot` does it better. * * * @m_goldberg Here is the data and it does not work:               poljez0 = {{0., 0., -2.94877*10^-11}, {0., 0., -3.08265*10^-11}, {0.,         0., -3.17712*10^-11}, {0., 0., -3.21021*10^-11}, {0.,         0., -3.15544*10^-11}, {0., 0., -2.98416*10^-11}, {0.,         0., -2.67049*10^-11}, {0., 0., -2.19887*10^-11}, {0.,         0., -1.57288*10^-11}, {0., 0., -8.21739*10^-12}, {0., 0., 0.}, {0.,         0., 8.21739*10^-12}, {0., 0., 1.57288*10^-11}, {0., 0.,         2.19887*10^-11}, {0., 0., 2.67049*10^-11}, {0., 0.,         2.98416*10^-11}, {0., 0., 3.15544*10^-11}, {0., 0.,         3.21021*10^-11}, {0., 0., 3.17712*10^-11}, {0., 0.,         3.08265*10^-11}, {0., 0., 2.94877*10^-11}, {0.,         0., -3.42494*10^-11}, {0., 0., -3.64045*10^-11}, {0.,         0., -3.82149*10^-11}, {0., 0., -3.93897*10^-11}, {0.,         0., -3.95435*10^-11}, {0., 0., -3.82133*10^-11}, {0.,         0., -3.49226*10^-11}, {0., 0., -2.93063*10^-11}, {0.,         0., -2.12865*10^-11}, {0., 0., -1.12326*10^-11}, {0., 0., 0.}, {0.,         0., 1.12326*10^-11}, {0., 0., 2.12865*10^-11}, {0., 0.,         2.93063*10^-11}, {0., 0., 3.49226*10^-11}, {0., 0.,         3.82133*10^-11}, {0., 0., 3.95435*10^-11}, {0., 0.,         3.93897*10^-11}, {0., 0., 3.82149*10^-11}, {0., 0.,         3.64045*10^-11}, {0., 0., 3.42494*10^-11}, {0.,         0., -3.97097*10^-11}, {0., 0., -4.29899*10^-11}, {0.,         0., -4.60745*10^-11}, {0., 0., -4.86039*10^-11}, {0.,         0., -5.00432*10^-11}, {0., 0., -4.96684*10^-11}, {0.,         0., -4.66251*10^-11}, {0., 0., -4.01173*10^-11}, {0.,         0., -2.97483*10^-11}, {0., 0., -1.59157*10^-11}, {0., 0., 0.}, {0.,         0., 1.59157*10^-11}, {0., 0., 2.97483*10^-11}, {0., 0.,         4.01173*10^-11}, {0., 0., 4.66251*10^-11}, {0., 0.,         4.96684*10^-11}, {0., 0., 5.00432*10^-11}, {0., 0.,         4.86039*10^-11}, {0., 0., 4.60745*10^-11}, {0., 0.,         4.29899*10^-11}, {0., 0., 3.97097*10^-11}, {0.,         0., -4.5854*10^-11}, {0., 0., -5.06406*10^-11}, {0.,         0., -5.55459*10^-11}, {0., 0., -6.01789*10^-11}, {0.,         0., -6.38574*10^-11}, {0., 0., -6.55107*10^-11}, {0.,         0., -6.3662*10^-11}, {0., 0., -5.6646*10^-11}, {0.,         0., -4.32321*10^-11}, {0., 0., -2.35904*10^-11}, {0., 0., 0.}, {0.,         0., 2.35904*10^-11}, {0., 0., 4.32321*10^-11}, {0., 0.,         5.6646*10^-11}, {0., 0., 6.3662*10^-11}, {0., 0.,         6.55107*10^-11}, {0., 0., 6.38574*10^-11}, {0., 0.,         6.01789*10^-11}, {0., 0., 5.55459*10^-11}, {0., 0.,         5.06406*10^-11}, {0., 0., 4.5854*10^-11}, {0.,         0., -5.2583*10^-11}, {0., 0., -5.93105*10^-11}, {0.,         0., -6.67217*10^-11}, {0., 0., -7.44992*10^-11}, {0.,         0., -8.19101*10^-11}, {0., 0., -8.7531*10^-11}, {0.,         0., -8.89697*10^-11}, {0., 0., -8.28876*10^-11}, {0.,         0., -6.59367*10^-11}, {0., 0., -3.70582*10^-11}, {0., 0., 0.}, {0.,         0., 3.70582*10^-11}, {0., 0., 6.59367*10^-11}, {0., 0.,         8.28876*10^-11}, {0., 0., 8.89697*10^-11}, {0., 0.,         8.7531*10^-11}, {0., 0., 8.19101*10^-11}, {0., 0.,         7.44992*10^-11}, {0., 0., 6.67217*10^-11}, {0., 0.,         5.93105*10^-11}, {0., 0., 5.2583*10^-11}, {0.,         0., -5.96744*10^-11}, {0., 0., -6.87782*10^-11}, {0.,         0., -7.94658*10^-11}, {0., 0., -9.17131*10^-11}, {0.,         0., -1.05036*10^-10}, {0., 0., -1.17951*10^-10}, {0.,         0., -1.27078*10^-10}, {0., 0., -1.26209*10^-10}, {0.,         0., -1.06812*10^-10}, {0., 0., -6.29109*10^-11}, {0., 0., 0.}, {0.,         0., 6.29109*10^-11}, {0., 0., 1.06812*10^-10}, {0., 0.,         1.26209*10^-10}, {0., 0., 1.27078*10^-10}, {0., 0.,         1.17951*10^-10}, {0., 0., 1.05036*10^-10}, {0., 0.,         9.17131*10^-11}, {0., 0., 7.94658*10^-11}, {0., 0.,         6.87782*10^-11}, {0., 0., 5.96744*10^-11}, {0.,         0., -6.67523*10^-11}, {0., 0., -7.85691*10^-11}, {0.,         0., -9.3246*10^-11}, {0., 0., -1.11406*10^-10}, {0.,         0., -1.33453*10^-10}, {0., 0., -1.58847*10^-10}, {0.,         0., -1.84298*10^-10}, {0., 0., -2.00169*10^-10}, {0.,         0., -1.86496*10^-10}, {0., 0., -1.1899*10^-10}, {0., 0., 0.}, {0.,         0., 1.1899*10^-10}, {0., 0., 1.86496*10^-10}, {0., 0.,         2.00169*10^-10}, {0., 0., 1.84298*10^-10}, {0., 0.,         1.58847*10^-10}, {0., 0., 1.33453*10^-10}, {0., 0.,         1.11406*10^-10}, {0., 0., 9.3246*10^-11}, {0., 0.,         7.85691*10^-11}, {0., 0., 6.67523*10^-11}, {0.,         0., -7.32848*10^-11}, {0., 0., -8.79115*10^-11}, {0.,         0., -1.06975*10^-10}, {0., 0., -1.32171*10^-10}, {0.,         0., -1.65774*10^-10}, {0., 0., -2.10347*10^-10}, {0.,         0., -2.66891*10^-10}, {0., 0., -3.2764*10^-10}, {0.,         0., -3.55877*10^-10}, {0., 0., -2.63745*10^-10}, {0., 0., 0.}, {0.,         0., 2.63745*10^-10}, {0., 0., 3.55877*10^-10}, {0., 0.,         3.2764*10^-10}, {0., 0., 2.66891*10^-10}, {0., 0.,         2.10347*10^-10}, {0., 0., 1.65774*10^-10}, {0., 0.,         1.32171*10^-10}, {0., 0., 1.06975*10^-10}, {0., 0.,         8.79115*10^-11}, {0., 0., 7.32848*10^-11}, {0.,         0., -7.86329*10^-11}, {0., 0., -9.57814*10^-11}, {0.,         0., -1.18988*10^-10}, {0., 0., -1.51309*10^-10}, {0.,         0., -1.97808*10^-10}, {0., 0., -2.67028*10^-10}, {0.,         0., -3.72992*10^-10}, {0., 0., -5.33815*10^-10}, {0.,         0., -7.37191*10^-10}, {0., 0., -7.45985*10^-10}, {0., 0., 0.}, {0.,         0., 7.45985*10^-10}, {0., 0., 7.37191*10^-10}, {0., 0.,         5.33815*10^-10}, {0., 0., 3.72992*10^-10}, {0., 0.,         2.67028*10^-10}, {0., 0., 1.97808*10^-10}, {0., 0.,         1.51309*10^-10}, {0., 0., 1.18988*10^-10}, {0., 0.,         9.57814*10^-11}, {0., 0., 7.86329*10^-11}, {0.,         0., -8.21623*10^-11}, {0., 0., -1.01086*10^-10}, {0.,         0., -1.2732*10^-10}, {0., 0., -1.65129*10^-10}, {0.,         0., -2.22347*10^-10}, {0., 0., -3.14553*10^-10}, {0.,         0., -4.75961*10^-10}, {0., 0., -7.91236*10^-10}, {0.,         0., -1.49197*10^-9}, {0., 0., -2.94876*10^-9}, {0., 0., 0.}, {0.,         0., 2.94876*10^-9}, {0., 0., 1.49197*10^-9}, {0., 0.,         7.91236*10^-10}, {0., 0., 4.75961*10^-10}, {0., 0.,         3.14553*10^-10}, {0., 0., 2.22347*10^-10}, {0., 0.,         1.65129*10^-10}, {0., 0., 1.2732*10^-10}, {0., 0.,         1.01086*10^-10}, {0., 0., 8.21623*10^-11}, {0.,         0., -3.13741*10^-11}, {0., 0., -3.79051*10^-11}, {0.,         0., -4.65701*10^-11}, {0., 0., -5.83094*10^-11}, {0.,         0., -7.45312*10^-11}, {0., 0., -9.72345*10^-11}, {0.,         0., -1.2865*10^-10}, {0., 0., -1.68328*10^-10}, {0.,         0., -2.005*10^-10}, {0., 0., -1.65281*10^-10}, {0., 0., 0.}, {0.,         0., 1.65281*10^-10}, {0., 0., 2.005*10^-10}, {0., 0.,         1.68328*10^-10}, {0., 0., 1.2865*10^-10}, {0., 0.,         9.72345*10^-11}, {0., 0., 7.45312*10^-11}, {0., 0.,         5.83094*10^-11}, {0., 0., 4.65701*10^-11}, {0., 0.,         3.79051*10^-11}, {0., 0., 3.13741*10^-11}, {0.,         0., -8.21623*10^-11}, {0., 0., -1.01086*10^-10}, {0.,         0., -1.2732*10^-10}, {0., 0., -1.65129*10^-10}, {0.,         0., -2.22347*10^-10}, {0., 0., -3.14553*10^-10}, {0.,         0., -4.75961*10^-10}, {0., 0., -7.91236*10^-10}, {0.,         0., -1.49197*10^-9}, {0., 0., -2.94876*10^-9}, {0., 0., 0.}, {0.,         0., 2.94876*10^-9}, {0., 0., 1.49197*10^-9}, {0., 0.,         7.91236*10^-10}, {0., 0., 4.75961*10^-10}, {0., 0.,         3.14553*10^-10}, {0., 0., 2.22347*10^-10}, {0., 0.,         1.65129*10^-10}, {0., 0., 1.2732*10^-10}, {0., 0.,         1.01086*10^-10}, {0., 0., 8.21623*10^-11}, {0.,         0., -7.86329*10^-11}, {0., 0., -9.57814*10^-11}, {0.,         0., -1.18988*10^-10}, {0., 0., -1.51309*10^-10}, {0.,         0., -1.97808*10^-10}, {0., 0., -2.67028*10^-10}, {0.,         0., -3.72992*10^-10}, {0., 0., -5.33815*10^-10}, {0.,         0., -7.37191*10^-10}, {0., 0., -7.45985*10^-10}, {0., 0., 0.}, {0.,         0., 7.45985*10^-10}, {0., 0., 7.37191*10^-10}, {0., 0.,         5.33815*10^-10}, {0., 0., 3.72992*10^-10}, {0., 0.,         2.67028*10^-10}, {0., 0., 1.97808*10^-10}, {0., 0.,         1.51309*10^-10}, {0., 0., 1.18988*10^-10}, {0., 0.,         9.57814*10^-11}, {0., 0., 7.86329*10^-11}, {0.,         0., -7.32848*10^-11}, {0., 0., -8.79115*10^-11}, {0.,         0., -1.06975*10^-10}, {0., 0., -1.32171*10^-10}, {0.,         0., -1.65774*10^-10}, {0., 0., -2.10347*10^-10}, {0.,         0., -2.66891*10^-10}, {0., 0., -3.2764*10^-10}, {0.,         0., -3.55877*10^-10}, {0., 0., -2.63745*10^-10}, {0., 0., 0.}, {0.,         0., 2.63745*10^-10}, {0., 0., 3.55877*10^-10}, {0., 0.,         3.2764*10^-10}, {0., 0., 2.66891*10^-10}, {0., 0.,         2.10347*10^-10}, {0., 0., 1.65774*10^-10}, {0., 0.,         1.32171*10^-10}, {0., 0., 1.06975*10^-10}, {0., 0.,         8.79115*10^-11}, {0., 0., 7.32848*10^-11}, {0.,         0., -6.67523*10^-11}, {0., 0., -7.85691*10^-11}, {0.,         0., -9.3246*10^-11}, {0., 0., -1.11406*10^-10}, {0.,         0., -1.33453*10^-10}, {0., 0., -1.58847*10^-10}, {0.,         0., -1.84298*10^-10}, {0., 0., -2.00169*10^-10}, {0.,         0., -1.86496*10^-10}, {0., 0., -1.1899*10^-10}, {0., 0., 0.}, {0.,         0., 1.1899*10^-10}, {0., 0., 1.86496*10^-10}, {0., 0.,         2.00169*10^-10}, {0., 0., 1.84298*10^-10}, {0., 0.,         1.58847*10^-10}, {0., 0., 1.33453*10^-10}, {0., 0.,         1.11406*10^-10}, {0., 0., 9.3246*10^-11}, {0., 0.,         7.85691*10^-11}, {0., 0., 6.67523*10^-11}, {0.,         0., -5.96744*10^-11}, {0., 0., -6.87782*10^-11}, {0.,         0., -7.94658*10^-11}, {0., 0., -9.17131*10^-11}, {0.,         0., -1.05036*10^-10}, {0., 0., -1.17951*10^-10}, {0.,         0., -1.27078*10^-10}, {0., 0., -1.26209*10^-10}, {0.,         0., -1.06812*10^-10}, {0., 0., -6.29109*10^-11}, {0., 0., 0.}, {0.,         0., 6.29109*10^-11}, {0., 0., 1.06812*10^-10}, {0., 0.,         1.26209*10^-10}, {0., 0., 1.27078*10^-10}, {0., 0.,         1.17951*10^-10}, {0., 0., 1.05036*10^-10}, {0., 0.,         9.17131*10^-11}, {0., 0., 7.94658*10^-11}, {0., 0.,         6.87782*10^-11}, {0., 0., 5.96744*10^-11}, {0.,         0., -5.2583*10^-11}, {0., 0., -5.93105*10^-11}, {0.,         0., -6.67217*10^-11}, {0., 0., -7.44992*10^-11}, {0.,         0., -8.19101*10^-11}, {0., 0., -8.7531*10^-11}, {0.,         0., -8.89697*10^-11}, {0., 0., -8.28876*10^-11}, {0.,         0., -6.59367*10^-11}, {0., 0., -3.70582*10^-11}, {0., 0., 0.}, {0.,         0., 3.70582*10^-11}, {0., 0., 6.59367*10^-11}, {0., 0.,         8.28876*10^-11}, {0., 0., 8.89697*10^-11}, {0., 0.,         8.7531*10^-11}, {0., 0., 8.19101*10^-11}, {0., 0.,         7.44992*10^-11}, {0., 0., 6.67217*10^-11}, {0., 0.,         5.93105*10^-11}, {0., 0., 5.2583*10^-11}, {0.,         0., -4.5854*10^-11}, {0., 0., -5.06406*10^-11}, {0.,         0., -5.55459*10^-11}, {0., 0., -6.01789*10^-11}, {0.,         0., -6.38574*10^-11}, {0., 0., -6.55107*10^-11}, {0.,         0., -6.3662*10^-11}, {0., 0., -5.6646*10^-11}, {0.,         0., -4.32321*10^-11}, {0., 0., -2.35904*10^-11}, {0., 0., 0.}, {0.,         0., 2.35904*10^-11}, {0., 0., 4.32321*10^-11}, {0., 0.,         5.6646*10^-11}, {0., 0., 6.3662*10^-11}, {0., 0.,         6.55107*10^-11}, {0., 0., 6.38574*10^-11}, {0., 0.,         6.01789*10^-11}, {0., 0., 5.55459*10^-11}, {0., 0.,         5.06406*10^-11}, {0., 0., 4.5854*10^-11}, {0.,         0., -3.97097*10^-11}, {0., 0., -4.29899*10^-11}, {0.,         0., -4.60745*10^-11}, {0., 0., -4.86039*10^-11}, {0.,         0., -5.00432*10^-11}, {0., 0., -4.96684*10^-11}, {0.,         0., -4.66251*10^-11}, {0., 0., -4.01173*10^-11}, {0.,         0., -2.97483*10^-11}, {0., 0., -1.59157*10^-11}, {0., 0., 0.}, {0.,         0., 1.59157*10^-11}, {0., 0., 2.97483*10^-11}, {0., 0.,         4.01173*10^-11}, {0., 0., 4.66251*10^-11}, {0., 0.,         4.96684*10^-11}, {0., 0., 5.00432*10^-11}, {0., 0.,         4.86039*10^-11}, {0., 0., 4.60745*10^-11}, {0., 0.,         4.29899*10^-11}, {0., 0., 3.97097*10^-11}, {0.,         0., -3.42494*10^-11}, {0., 0., -3.64045*10^-11}, {0.,         0., -3.82149*10^-11}, {0., 0., -3.93897*10^-11}, {0.,         0., -3.95435*10^-11}, {0., 0., -3.82133*10^-11}, {0.,         0., -3.49226*10^-11}, {0., 0., -2.93063*10^-11}, {0.,         0., -2.12865*10^-11}, {0., 0., -1.12326*10^-11}, {0., 0., 0.}, {0.,         0., 1.12326*10^-11}, {0., 0., 2.12865*10^-11}, {0., 0.,         2.93063*10^-11}, {0., 0., 3.49226*10^-11}, {0., 0.,         3.82133*10^-11}, {0., 0., 3.95435*10^-11}, {0., 0.,         3.93897*10^-11}, {0., 0., 3.82149*10^-11}, {0., 0.,         3.64045*10^-11}, {0., 0., 3.42494*10^-11}, {0.,         0., -2.94877*10^-11}, {0., 0., -3.08265*10^-11}, {0.,         0., -3.17712*10^-11}, {0., 0., -3.21021*10^-11}, {0.,         0., -3.15544*10^-11}, {0., 0., -2.98416*10^-11}, {0.,         0., -2.67049*10^-11}, {0., 0., -2.19887*10^-11}, {0.,         0., -1.57288*10^-11}, {0., 0., -8.21739*10^-12}, {0., 0., 0.}, {0.,         0., 8.21739*10^-12}, {0., 0., 1.57288*10^-11}, {0., 0.,         2.19887*10^-11}, {0., 0., 2.67049*10^-11}, {0., 0.,         2.98416*10^-11}, {0., 0., 3.15544*10^-11}, {0., 0.,         3.21021*10^-11}, {0., 0., 3.17712*10^-11}, {0., 0.,         3.08265*10^-11}, {0., 0., 2.94877*10^-11}}      and               tockez0 = {{-100, -100, 10}, {-90, -100, 10}, {-80, -100,         10}, {-70, -100, 10}, {-60, -100, 10}, {-50, -100, 10}, {-40, -100,         10}, {-30, -100, 10}, {-20, -100, 10}, {-10, -100, 10}, {0, -100,         10}, {10, -100, 10}, {20, -100, 10}, {30, -100, 10}, {40, -100,         10}, {50, -100, 10}, {60, -100, 10}, {70, -100, 10}, {80, -100,         10}, {90, -100, 10}, {100, -100, 10}, {-100, -90, 10}, {-90, -90,         10}, {-80, -90, 10}, {-70, -90, 10}, {-60, -90, 10}, {-50, -90,         10}, {-40, -90, 10}, {-30, -90, 10}, {-20, -90, 10}, {-10, -90,         10}, {0, -90, 10}, {10, -90, 10}, {20, -90, 10}, {30, -90,         10}, {40, -90, 10}, {50, -90, 10}, {60, -90, 10}, {70, -90,         10}, {80, -90, 10}, {90, -90, 10}, {100, -90, 10}, {-100, -80,         10}, {-90, -80, 10}, {-80, -80, 10}, {-70, -80, 10}, {-60, -80,         10}, {-50, -80, 10}, {-40, -80, 10}, {-30, -80, 10}, {-20, -80,         10}, {-10, -80, 10}, {0, -80, 10}, {10, -80, 10}, {20, -80,         10}, {30, -80, 10}, {40, -80, 10}, {50, -80, 10}, {60, -80,         10}, {70, -80, 10}, {80, -80, 10}, {90, -80, 10}, {100, -80,         10}, {-100, -70, 10}, {-90, -70, 10}, {-80, -70, 10}, {-70, -70,         10}, {-60, -70, 10}, {-50, -70, 10}, {-40, -70, 10}, {-30, -70,         10}, {-20, -70, 10}, {-10, -70, 10}, {0, -70, 10}, {10, -70,         10}, {20, -70, 10}, {30, -70, 10}, {40, -70, 10}, {50, -70,         10}, {60, -70, 10}, {70, -70, 10}, {80, -70, 10}, {90, -70,         10}, {100, -70, 10}, {-100, -60, 10}, {-90, -60, 10}, {-80, -60,         10}, {-70, -60, 10}, {-60, -60, 10}, {-50, -60, 10}, {-40, -60,         10}, {-30, -60, 10}, {-20, -60, 10}, {-10, -60, 10}, {0, -60,         10}, {10, -60, 10}, {20, -60, 10}, {30, -60, 10}, {40, -60,         10}, {50, -60, 10}, {60, -60, 10}, {70, -60, 10}, {80, -60,         10}, {90, -60, 10}, {100, -60, 10}, {-100, -50, 10}, {-90, -50,         10}, {-80, -50, 10}, {-70, -50, 10}, {-60, -50, 10}, {-50, -50,         10}, {-40, -50, 10}, {-30, -50, 10}, {-20, -50, 10}, {-10, -50,         10}, {0, -50, 10}, {10, -50, 10}, {20, -50, 10}, {30, -50,         10}, {40, -50, 10}, {50, -50, 10}, {60, -50, 10}, {70, -50,         10}, {80, -50, 10}, {90, -50, 10}, {100, -50, 10}, {-100, -40,         10}, {-90, -40, 10}, {-80, -40, 10}, {-70, -40, 10}, {-60, -40,         10}, {-50, -40, 10}, {-40, -40, 10}, {-30, -40, 10}, {-20, -40,         10}, {-10, -40, 10}, {0, -40, 10}, {10, -40, 10}, {20, -40,         10}, {30, -40, 10}, {40, -40, 10}, {50, -40, 10}, {60, -40,         10}, {70, -40, 10}, {80, -40, 10}, {90, -40, 10}, {100, -40,         10}, {-100, -30, 10}, {-90, -30, 10}, {-80, -30, 10}, {-70, -30,         10}, {-60, -30, 10}, {-50, -30, 10}, {-40, -30, 10}, {-30, -30,         10}, {-20, -30, 10}, {-10, -30, 10}, {0, -30, 10}, {10, -30,         10}, {20, -30, 10}, {30, -30, 10}, {40, -30, 10}, {50, -30,         10}, {60, -30, 10}, {70, -30, 10}, {80, -30, 10}, {90, -30,         10}, {100, -30, 10}, {-100, -20, 10}, {-90, -20, 10}, {-80, -20,         10}, {-70, -20, 10}, {-60, -20, 10}, {-50, -20, 10}, {-40, -20,         10}, {-30, -20, 10}, {-20, -20, 10}, {-10, -20, 10}, {0, -20,         10}, {10, -20, 10}, {20, -20, 10}, {30, -20, 10}, {40, -20,         10}, {50, -20, 10}, {60, -20, 10}, {70, -20, 10}, {80, -20,         10}, {90, -20, 10}, {100, -20, 10}, {-100, -10, 10}, {-90, -10,         10}, {-80, -10, 10}, {-70, -10, 10}, {-60, -10, 10}, {-50, -10,         10}, {-40, -10, 10}, {-30, -10, 10}, {-20, -10, 10}, {-10, -10,         10}, {0, -10, 10}, {10, -10, 10}, {20, -10, 10}, {30, -10,         10}, {40, -10, 10}, {50, -10, 10}, {60, -10, 10}, {70, -10,         10}, {80, -10, 10}, {90, -10, 10}, {100, -10, 10}, {-100, 0,         10}, {-90, 0, 10}, {-80, 0, 10}, {-70, 0, 10}, {-60, 0, 10}, {-50,         0, 10}, {-40, 0, 10}, {-30, 0, 10}, {-20, 0, 10}, {-10, 0, 10}, {0,         0, 10}, {10, 0, 10}, {20, 0, 10}, {30, 0, 10}, {40, 0, 10}, {50,         0, 10}, {60, 0, 10}, {70, 0, 10}, {80, 0, 10}, {90, 0, 10}, {100,         0, 10}, {-100, 10, 10}, {-90, 10, 10}, {-80, 10, 10}, {-70, 10,         10}, {-60, 10, 10}, {-50, 10, 10}, {-40, 10, 10}, {-30, 10,         10}, {-20, 10, 10}, {-10, 10, 10}, {0, 10, 10}, {10, 10, 10}, {20,         10, 10}, {30, 10, 10}, {40, 10, 10}, {50, 10, 10}, {60, 10,         10}, {70, 10, 10}, {80, 10, 10}, {90, 10, 10}, {100, 10,         10}, {-100, 20, 10}, {-90, 20, 10}, {-80, 20, 10}, {-70, 20,         10}, {-60, 20, 10}, {-50, 20, 10}, {-40, 20, 10}, {-30, 20,         10}, {-20, 20, 10}, {-10, 20, 10}, {0, 20, 10}, {10, 20, 10}, {20,         20, 10}, {30, 20, 10}, {40, 20, 10}, {50, 20, 10}, {60, 20,         10}, {70, 20, 10}, {80, 20, 10}, {90, 20, 10}, {100, 20,         10}, {-100, 30, 10}, {-90, 30, 10}, {-80, 30, 10}, {-70, 30,         10}, {-60, 30, 10}, {-50, 30, 10}, {-40, 30, 10}, {-30, 30,         10}, {-20, 30, 10}, {-10, 30, 10}, {0, 30, 10}, {10, 30, 10}, {20,         30, 10}, {30, 30, 10}, {40, 30, 10}, {50, 30, 10}, {60, 30,         10}, {70, 30, 10}, {80, 30, 10}, {90, 30, 10}, {100, 30,         10}, {-100, 40, 10}, {-90, 40, 10}, {-80, 40, 10}, {-70, 40,         10}, {-60, 40, 10}, {-50, 40, 10}, {-40, 40, 10}, {-30, 40,         10}, {-20, 40, 10}, {-10, 40, 10}, {0, 40, 10}, {10, 40, 10}, {20,         40, 10}, {30, 40, 10}, {40, 40, 10}, {50, 40, 10}, {60, 40,         10}, {70, 40, 10}, {80, 40, 10}, {90, 40, 10}, {100, 40,         10}, {-100, 50, 10}, {-90, 50, 10}, {-80, 50, 10}, {-70, 50,         10}, {-60, 50, 10}, {-50, 50, 10}, {-40, 50, 10}, {-30, 50,         10}, {-20, 50, 10}, {-10, 50, 10}, {0, 50, 10}, {10, 50, 10}, {20,         50, 10}, {30, 50, 10}, {40, 50, 10}, {50, 50, 10}, {60, 50,         10}, {70, 50, 10}, {80, 50, 10}, {90, 50, 10}, {100, 50,         10}, {-100, 60, 10}, {-90, 60, 10}, {-80, 60, 10}, {-70, 60,         10}, {-60, 60, 10}, {-50, 60, 10}, {-40, 60, 10}, {-30, 60,         10}, {-20, 60, 10}, {-10, 60, 10}, {0, 60, 10}, {10, 60, 10}, {20,         60, 10}, {30, 60, 10}, {40, 60, 10}, {50, 60, 10}, {60, 60,         10}, {70, 60, 10}, {80, 60, 10}, {90, 60, 10}, {100, 60,         10}, {-100, 70, 10}, {-90, 70, 10}, {-80, 70, 10}, {-70, 70,         10}, {-60, 70, 10}, {-50, 70, 10}, {-40, 70, 10}, {-30, 70,         10}, {-20, 70, 10}, {-10, 70, 10}, {0, 70, 10}, {10, 70, 10}, {20,         70, 10}, {30, 70, 10}, {40, 70, 10}, {50, 70, 10}, {60, 70,         10}, {70, 70, 10}, {80, 70, 10}, {90, 70, 10}, {100, 70,         10}, {-100, 80, 10}, {-90, 80, 10}, {-80, 80, 10}, {-70, 80,         10}, {-60, 80, 10}, {-50, 80, 10}, {-40, 80, 10}, {-30, 80,         10}, {-20, 80, 10}, {-10, 80, 10}, {0, 80, 10}, {10, 80, 10}, {20,         80, 10}, {30, 80, 10}, {40, 80, 10}, {50, 80, 10}, {60, 80,         10}, {70, 80, 10}, {80, 80, 10}, {90, 80, 10}, {100, 80,         10}, {-100, 90, 10}, {-90, 90, 10}, {-80, 90, 10}, {-70, 90,         10}, {-60, 90, 10}, {-50, 90, 10}, {-40, 90, 10}, {-30, 90,         10}, {-20, 90, 10}, {-10, 90, 10}, {0, 90, 10}, {10, 90, 10}, {20,         90, 10}, {30, 90, 10}, {40, 90, 10}, {50, 90, 10}, {60, 90,         10}, {70, 90, 10}, {80, 90, 10}, {90, 90, 10}, {100, 90,         10}, {-100, 100, 10}, {-90, 100, 10}, {-80, 100, 10}, {-70, 100,         10}, {-60, 100, 10}, {-50, 100, 10}, {-40, 100, 10}, {-30, 100,         10}, {-20, 100, 10}, {-10, 100, 10}, {0, 100, 10}, {10, 100,         10}, {20, 100, 10}, {30, 100, 10}, {40, 100, 10}, {50, 100,         10}, {60, 100, 10}, {70, 100, 10}, {80, 100, 10}, {90, 100,         10}, {100, 100, 10}}      What gives me a completely empty box is               Graphics3D[{Arrowheads[Small],        MapThread[Arrow[{#1, #2}] &, {tockez0, poljez0 + tockez0}]},       BoxRatios -> {1, 1, 1.5}, Axes -> True, AxesLabel -> {x, y, z}]


title: Running external pdflatex command and importing the generated PDF document

text: There have been a couple of questions about incorporating labels and equations that were typeset in $\LaTeX$ into a _Mathematica_ notebook. Ideally, this requires running `pdflatex` (or `latex`) from within _Mathematica_ and then importing the generated `PDF` document. Unfortunately, importing of `PDF` is known to be buggy, as discussed in these questions (among others, probably):   * Mathematica PDF import and fonts   * Difficulties with Importing PDFs in Mathematica   * Combine multiple PDF files into one document The last two also mention `ghostscript` as the way to solve some of the issues, in particular using the `pdfwrite` device to re-generate a new `PDF` from existing ones. This could be used in a $\LaTeX$ workflow like this (I am assuming **Mac OS X** here):               Export["words.tex", "\n\\nonstopmode       \\documentclass[12pt]{article}       \\begin{document}\n       here\\qquad we\\qquad go       \\end{document}\n       ", "Text"];          Run["pdflatex words"]          (* ==> 0 *)          Import["words.pdf"]      > `Import::general: Expected cross reference table >>` > > `Import::general: Expected cross reference table >>` > > `Import::general: Could not find document trailer >>` > > `General::stop:` As was to be expected, here we get error messages similar to what the second question referenced above saw. So now try the `ghostscript` workaround. Since this question aims at using $\LaTeX$, by assumption we have a working $\TeX$ installation which nowadays includes `ghostscript`, so the following will be able to execute:               Run["gs -sDEVICE=pdfwrite -dNOCACHE \     -sOutputFile=words-nofont.pdf -q -dBatch -dNOPAUSE words.pdf -c quit"]          (* ==> 0 *)          Import["words-nofont.pdf"]      ![wrong spacing](http://i.stack.imgur.com/88iT7.png) But the imported `PDF` has incorrect spacings between the words. It should (as you can tell from the `\\qquad` in the source) look more like > $\text{Here}\qquad \text{we}\qquad \text{go}$ This is just a somewhat artificial example illustrating the general problem of incorrect lengths and fonts upon import of a `PDF`. So the question is, how can one fix this, either by using $\TeX$ and its companion utilities differently, or by relying only on _Mathematica_ 's capabilities? If this can be done, then it will be possible to automate the generation of $\LaTeX$ labels etc. from within _Mathematica_. I'll post my answer based on `ghostscript` below, hoping that eventually someone will come up with a fix for `PDF` import that doesn't require external software.


title: Run entire notebook

text: I have created a notebook, with functions. The only thing that I want to change in the notebook later is the input file. I therefor want to have a button that runs every input step-by-step so that I do not have to go into every input and press enter for it to update. How could this be done.


title: user defined functions, how to save them for future use?

text: I need certain user defined functions over and over. I was wondering how can I define and where and how to save them such that each time I start a notebook, these functions are available and need not to be defined again.


title: Equation of the plane passing through the three points

text: > **Possible Duplicate:**   >  How to put terms in lexicographic order? I write the equation of the plane passing through the three points $A(-1, 5, -2)$, $B(2, 4, -3)$ and $F(4, -8, 6)$, and this is my code               A := {-1, 5, -2};     B := {2, 4, -3};     F := {4, -8, 6};     M := {x, y, z};     u := A - B;     v := A - F;     w := A - M;     n := u\[Cross]v;     Sort[Simplify[w.n] == 0]      I want the equation $ABF$ has the form $21 x + 29 y + 34 z-56=0$, but Mathematica out $0 == -56 + 21 x + 29 y + 34 z$ What must I do? Please help me.


title: Define Log so that negative reals evaluate on lower edge of branch

text: I need to get _Mathematica_ to evaluate the logarithm of a negative real number using the lower branch instead of the upper branch, so that while               In[1]:=   Log[3.2]     Out[1]:=  1.16315      I need               In[2]:=   Log[-3.2]     Out[2]:=  1.16315 - 3.14159 I      and not               Out[2]:=  1.16315 + 3.14159 I      I have already defined my own function `loopLog` that does this:               loopLog[x_: NumericQ] = If[Element[x,Reals], Conjugate[Log[x]]];      But I am not able to get it to perform any of the usual simplifications or manipulations using this function. For example, when I want to differentiate loopLog, I get               In[3]:=   D[loopLog[x],x]     Out[3]:=  If[x \[Element] Reals, Derivative[1][Conjugate][Log[x]]/x]      Instead of the much needed `1/x`. What is the cleanest way to define such a logarithm function in _Mathematica_?


title: Matrix multiplication in Block Form symbolic calculation by Mathematica

text: I have a problem which requires taking product of two $10\times10$ matrices. I would like to do it by considering both matrices as $5\times5$ matrices such that each entry of both matrices is actually a $2\times2$ matrix; moreover, there are variables so this is a symbolic calculation. (Side remark: matrix multiplication is not a commutative operation, i.e. $AB\neq BA$ in general.) Does anyone know how to perform this block form multiplication in _Mathematica_ , or using any other software?


title: Closing front end from within

text: Based on this I'd like to close the mathematica front end without the nagging dialog boxes that follow. Why am I trying to do this? I have a bash script which is such:               #!/bin/bash          mathematica bfile01.nb     pid1=$(pgrep mathematica)         kill -9 $pid1          ! [ -z `pidof mathematica` ] || mathematica bfile02.nb     pid2=$(pgrep mathematica)         kill -9 $pid2          ! [ -z `pidof mathematica` ] || mathematica bfile03.nb      So this is just a serial execution of several mathematica files, each of which has an initialization cell in it. I find that unless I close the front end, the next file doesn't launch and killing the process in the unix terminal didn't quite help (very strange as this only happens with mathematica) So any thoughts or ideas? # Edit 2: Using a mathematica script file Here is a mathematica file that I converted into a script: When I chmod it and run it, I get a bunch of error messages which don't allow my figures to be saved from the Plot3D or ContourPlot. If you try to run the file attached (test3.m), you would want to change the file save path, `Export` in the last line of the file. ## Error messages:               > General::stop: Further output of ReplaceAll::reps will be suppressed     > during this calculation.      # Edit 3: In the test3.m file, I made the following changes: Changed `hSol =` to `hSol[x_?NumericQ, y_?NumericQ, t_?NumericQ]` (file has been uploaded). This has changed the error messages that I get to:               > Part::partw: Part 3 of InterpolatingFunctionDomain[hSol] does not     > exist.     >      > Set::shape: Lists {TMin, TRup} and     > InterpolatingFunctionDomain[hSol][[3]] are not the same shape.     >      > Set::shape: Lists {nX, nY, nT} and {} are not the same shape.      Clearly, when run as a mathematica notebook, I never got these errors. # Edit 4: I seem to have corrected my errors after Ruebenko's last comment. the new file is attached here. Heres the issue that I had: Once the package was created (.m file), when opened in a text editor, all the lines were commented out with (**) which I don't know why. However, getting rid of the comments also uncommented some text that I had previously commented so as to not use. That resulted in error messages.


title: Spreading colors in ListContourPlot

text: I have a data file with triplets. The first two numbers indicate the x and y position, while the third one is the log10 value of a particular indicator. I want to create a 2D plot in which the positions are plotted and assigned colors according to the value of the third number. I think the best solution is to use `ListContourPlot` or `ListDensityPlot`. I tried the first one and I managed to create the plot I wanted. However, there is problem which I cannot solve. I provide the corresponding _Mathematica_ code. Unfortunately, I don't know how to upload the data file. The black dots correspond to the points. As you can see, there is a region with "bad" colors in which there are no points at all in the data file, but the algorithm is trying to spread the colors in that region. How could I fix this? I want to restrict colors to the data.               ListContourPlot[dataMLCN,         ContourShading -> Automatic,        ContourStyle -> None,        InterpolationOrder -> 5,         ColorFunction -> "Rainbow",         PlotLegends ->           Placed[            BarLegend[Automatic,                LegendMargins -> {{0, 0}, {10, 5}},                LegendLabel -> "\!\(\*SubscriptBox[\(log\), \(10\)]\)(MLCN)",                LabelStyle -> {FontSize -> 15, FontFamily -> "Helvetica"}],             Right],         PerformanceGoal -> "Quality",         FrameLabel -> {"R", OverDot["R"]},         RotateLabel -> False,         LabelStyle -> Directive[FontSize -> 17, FontFamily -> "Helvetica"],         Contours -> 200,        ImageSize -> 500]      * * * **Code and data files**   Apparently it's not possible at this moment to easily upload files to the StackMMA attachment repository (see this Meta question). Therfore I share the above mentioned files in the following way. The files will be automatically opened in a file system browser (at least on Windows) by executing the following single line of code in Mathematica (this method is describe here):               SystemOpen[Export[FileNameJoin[{$TemporaryDirectory, "StackMMATempFile.zip"}], Uncompress@FromCharacterCode@Flatten@ImageData[Import["http://i.stack.imgur.com/SiCSP.png"], "Byte"], "Byte"]]      [Sjoerd]


title: How to divide a notebook into sections?

text: I've seen some very nicely formatted Mathematica notebooks with sections, explanatory text, etc., but I can't figure out how to do something similar. The documentation is not especially helpful here so I'm asking here. I see you can group cells together, and then I've tried putting a line at the top to be a section header - say, "Preliminaries." In this cell I've done a few different things to try to make it text - Cell/Convert To/Text Display, Cell/Cell Properties/Uncheck Editable, Format/Style/Section - but still the cell saying Preliminaries is evaluatable. Doing practically anything - even right-clicking the text in that cell - will change its format/style back form Section to Input. How do I make a true section header, a cell that really contains text and not something that Mathematica can evaluate?


title: One more question about Assumptions and Integrate

text: There are many questions about assumptions here. Many of them are problem specific. That is why I want to ask a question in the most general way. Why does Mathematica solves this               Assuming[{x < 0}, Integrate[1/x, x]]      as               Log[x]      and not               -Log[-x]      ?


title: How do get an output table or a plot of individual variables from NDSolve output

text: I have the following equations and settings:               Clear[koff]; koff = 5.*10^-5;     Clear[kon]; kon = 1.*10^4;     Clear[koff2]; koff2 = 1.*10^-5;     Clear[kon2]; kon2 = 1.*10^4;     Clear[kcg]; kcg = 1.2*10^-5;     Clear[ndsolKRH];     ndsolKRH =       NDSolve[{           D[ag[t], t] == -kon2*ag[t]*b[t] + koff2*cg[t] - kcg ag[t],            D[a[t], t] == -kon*a[t]*b[t] + koff*c[t],            D[cg[t], t] == kon2*ag[t]*b[t] - koff2*cg[t],            D[c[t], t] == kon*a[t]*b[t] - koff*c[t],            D[b[t], t] == -kon2*ag[t]*b[t] - kon*a[t]*b[t] + koff2*cg[t] + koff*c[t],           ag[0] == 450. 10^-9, a[0] == 90.247 10^-9, cg[0] == 0,            c[0] == 473.75 10^-9, b[0] == 26.25 10^-9},         {ag, a, b, c, cg},         {t, 0, 1200000}][[1]];      I would like to get a table of individual numbers for cg and ag. I would also lime to be able to plot these variables vs time. At present I can do it one at a time but there must be a lot easier way. I am doing the following:               Clear[solKRHfix]; solKRHfix = ag /. ndsolKRH;      AND THEN:               solKRHfix[600000]


title: Retrieving duplicates from nested list

text: Consider the following: `data={{1,a},{10,a},{5,b},{4,c}};` In my case duplicates are defined when for `{x1,y1}` and `{x2,y2}`, `y2` is equal `y1`. Hence in the case of `data`, I would get via `MyFunction[data]` the following result: `{{1,a},{10,a}}`. Does anyone have an idea?


title: What's the difference between the following two codes?

text: I have two codes to find the integer numbers $m$, $x$, $y$, $z$ in the system of equations. First code               Solve[{( m  x +   y - 7 z)^2 ==         Cos[\[Pi]/3]^2*(x^2 + y^2 + z^2)*(m^2 + 1^2 + 7^2), -10 <= m <=         10, -10 <= x <= 10, -10 <= y <= 10, -10 <= z <= 10}, {m, x, y,        z}, Integers]      Second code               Clear[a, b];     a = {m, 1, -7};     b = {x, y, z};     Solve[{Abs[a . b]/(Norm[a] Norm[b]) == Cos[\[Pi]/6], 0 <= m <= 10,        0 <= x <= 10, 0 <= y <= 10, 0 <= z <= 10}, {m, x, y, z}, Integers]      The first code run faster the second code. I can not get the answer of the second code. How to edit the second code? How do I tell _Mathematica_ to do that?


title: Counting the number of a specific type of permutation

text: In the theory of cumulants of vector-valued random variables, the following types of formulas appear: \begin{equation} \theta^i \theta^{jk} [3] = \theta^i \theta^{jk} + \theta^j \theta^{ik} + \theta^k \theta^{ij} \end{equation} This is supposed to mean as follows: sum over all possible permutations (in this case 3) of the indices. The indices of a given theta are symmetric and need not be counted twice. Another example would be $\theta^i \theta^j \theta^{kl}$ [6]. In this case there is a total of 6 terms: $i\;|\;j\;|\;kl$ $i\;|\;k\;|\;jl$ $i\;|\;l\;|\;jk$ $j\;|\;k\;|\;il$ $j\;|\;l\;|\;ik$ $k\;|\;l\;|\;ij$ Going to even higher order, $\theta^{ij} \theta^{kl} \theta^{mn}$ [15] has 15 terms, and etc. I am unaware of any closed expressions for the number of terms. Thus, I was trying to use Mathematica to numerically compute all terms involved in a given permutation. However, so far I have been entirely unsuccessful. Any ideas? Here are some (failed) attempts, made with 4 indices and the combination $\theta^i \theta^j \theta^{kl}$. This lists all permutations of four terms.               perm = Permutations[{a, b, c, d}]      I can use Mr. Wizard's dynP to partition in the size I want. For instance,               dynP[{a,b,c,d},{1,1,2}]     {{a},{b},{c,d}}      So, an alternative, would be to do this for all members of perm, and then eliminate duplicates according to the above-specified criteria. This, however, I failed to do. I appreciate any help in advance. Best regards, Gabriel


title: How do I simplify a vector expression?

text: I am doing vector analysis. I have figured out that the following expression won't be simplified in _Mathematica_ :               Simplify[Dot[x, y] - Dot[y, x]]      I think the reason is that x and y could be matrices, so generally the operation does not commute. But for a vector, the commutation relation should hold. What I don't know is how to tell _Mathematica_ to consider x and y to be vectors. Also, how can I expand `Cross[x + y, z]` to be `Cross[x, y] + Cross[y, z]`? I tried to use `Expand` and `ExpandAll` but neither worked. BTW, in _Mathematica_ , is it possible to define a abstract row/column vector without explicitly specifying the number of entries?


title: Removing Linear drift from an oscillating data

text: I have an array of 800,000 data measured at 1.1s time gap. It is oscillating data but has clear linear drift. I want to remove this linear drift. But the estimates by `FindFit` and `Fit` has been very bad.   Here is my attempt with `FindFit`               model = e*x + noise[[1]];       fit = FindFit[noise, model, {e}, x]     {e -> -0.0430509}      The value of `e` is quite visibly wrong. It should be arround `-0.040`. Is there better ways to find and remove linear trends from datas? Thank you very much. The data can be found here: https://www.dropbox.com/s/xg2w6d4a6bpaejk/data.dat


title: Listing the functions defined in a package

text: Assume that I know a package's (Context?) name that is loaded. Now I want to list the functions defined in this package. How can I do it? I remember that I found a way once, but I cannot re-find it. I tried some combinations with `?` but for vain.


title: How to completely reinstall Wolfram Workbench on linux

text: I've messed up my Ubuntu install, I've changed some pathnames I shouldn't have (don't know which ones exactly though), and after that Wolfram Workbench was not launching anymore. I uninstalled it by erasing the folder /usr/local/Wolfram and the workspace, then reinstalled it at the same place. Workbench is now launching but the editor is still messed up, as you can see in this screenshot, this is all I get and I can't interact with: ![screenshot](http://i.stack.imgur.com/pinm2.png) When I launch Wolfram Workbench via command-line, I get the messages:               (Wolfram Workbench:5188): LIBDBUSMENU-GTK-CRITICAL **: watch_submenu: assertion `GTK_IS_MENU_SHELL(menu)' failed          (Wolfram Workbench:5188): LIBDBUSMENU-GTK-CRITICAL **: watch_submenu: assertion `GTK_IS_MENU_SHELL(menu)' failed          (Wolfram Workbench:5188): LIBDBUSMENU-GTK-CRITICAL **: watch_submenu: assertion `GTK_IS_MENU_SHELL(menu)' failed      Do you know what is causing this and what I can do to reinstall Workbench properly?


title: Controlling margin around PlotLegends

text: Here's my code:               k = 1;      L = 1;      λ[n_] = (((2*n - 1)*Pi)/(2*L))^2;      v[x_] = -50*x + 100;      f[x_] = (300*x*Cos[11*x] + 100)*(1 - x);      b[n_] = (2/L)*Integrate[(f[x] - v[x])*Sin[Sqrt[λ[n]]*x], {x, 0, L}];      w[x_, t_] = Sum[b[i]*Sin[Sqrt[λ[i]]*x]*Exp[(-λ[i])*k*t], {i, 1, 5}];      u[x_, t_] = v[x] + w[x, t];          Manipulate[Plot[{u[x, t], f[x], v[x]}, {x, 0, L},           PlotStyle -> {{Thick, Black}, {Thick, Blue}, {Thick, Red}},           AxesLabel -> {x, u}, PlotRange -> {-30, 120},           PlotLegends -> "Expressions"], {t, 0, .5}]      Note how the right edge of the box of the output jumps back and forth depending on how many decimal places is shown for a specific $t$ value. How can I anchor that right edge so it doesn't move back and forth?


title: How can I kill one evaluator from another?

text: I have a kernel named A in one notebook and other notebook with kernel B, how can I kill B from A?


title: How to sequentially select, from a large set of tuples (of matrices), those with a certain property

text: I'm interested in finding a computationally efficient way for selecting all tuples of matrices which have a certain property. The property I'm interested in is that I want the column sum, of f[the sum of matrices in the tuple], to contain only distinct elements.               f[x_] = Piecewise[{{1, x >= 2}}, 0]      The below code specifies this property               h[{{{x1_, x2_, x3_}, {x4_, x5_, x6_}, {x7_, x8_, x9_}}, {{y1_, y2_,       y3_}, {y4_, y5_, y6_}, {y7_, y8_, y9_}}, {{z1_, z2_, z3_}, {z4_,       z5_, z6_}, {z7_, z8_, z9_}}}] = Piecewise[{{1,      f[x1 + y1 + z1] + f[x4 + y4 + z4] + f[x7 + y7 + z7] !=        f[x2 + y2 + z2] + f[x5 + y5 + z5] + f[x8 + y8 + z8] &&       f[x2 + y2 + z2] + f[x5 + y5 + z5] + f[x8 + y8 + z8]  !=        f[x3 + y3 + z3] + f[x6 + y6 + z6] + f[x9 + y9 + z9] &&       f[x1 + y1 + z1] + f[x4 + y4 + z4] + f[x7 + y7 + z7] !=        f[x3 + y3 + z3] + f[x6 + y6 + z6] + f[x9 + y9 + z9]}}, 0]      However, there are certain restrictions on the sorts of matrices I want to collect into these triples. The below code specifies these restrictions:               g[{{x1_, x2_, x3_}, {x4_, x5_, x6_}, {x7_, x8_, x9_}}] = Piecewise[{{1,      x1 + x4 + x7 != x2 + x5 + x8 && x2 + x5 + x8 != x3 + x6 + x9 &&       x1 + x4 + x7 != x3 + x6 + x9 }}, 0]       Each individual matrix in the triple must itself have a column sum with only distinct elements. And moreover, contain only elements of {0,1}, their trace equal to 0, and the sum of any symmetrical elements w.r.t the main diagonal must be 1               W = Tuples[Select[Tuples[Tuples[{0, 1}, 3], 3], Tr[#] ==        0 && #[[1, 2]] != #[[2, 1]] && #[[1, 3]] != #[[3, 1]] && #[[2,         3]] != #[[3, 2]] && g[#] == 1 &], 3]      W creates triples of such matrices               Q = Select[W, h[#] == 0 &]      Q selects the triples which have the desired property. However, when I try to apply the same method to either larger matrices (5x5 rather than 3x3 for example), or larger tuples (5-tuples), or both, this code crashes mathematica. I suspect this is because W is too large for my computer's memory (for example if I create 5-tuples of 4x4 elements W should have a cardinality of (4!)^5, in general the set is (N!)^r, where N is the number of matrices and r the size of the tuples drawn from them) I suspect that there is a much more efficient way of generating Q (which is much smaller than W). Rather than generating the entirety of W, and then selecting from it, I would prefer to construct each element of W one by one, and check for the property. I only need to output the matrices with the property, those who fail to meet it can be discarded. Any help would be greatly appreciated.


title: How to make list plot when all information is in a single list

text: I want to make a plot , where the data is structured like so               { {"l1", "l2"}, n1, n2, n3} }      The values in the inner sub list are labels which are associated with each data point. Each distinct "l2" should be on the 'x' axis (like a histogram bin). Therefore I want to plot ("l2", n1) and ("l2", n2). The point generated by using ("l2", n1) should be labeled with "l1", and the point generated with ("l2", n2) should be labeled with "l2" any repeated values are ignored.               exampleData = {       {{"A", "B"}, -1, -2, 0.5},       {{"C", "B"}, -3, -2, 0.6},       {{"D", "A"}, -5, -6, 0.7}     };      For example from the above data we would plot   * (B, -1) label A   * (B, -2) label B   * (B, -3) label C    * (B, -2) label B (* ignore this one since we plotted the same point *)   * (A, -5) label D   * (A, -6) label A The xAxis Position can be obtained by using a replacement list like so:               rules = {"A" -> 1, "B" -> 2}      The plot should have 3 points above B and two points above A and each point should be labelled.


title: Using NMinimize Properly

text: I'd like to find the point on a Bezier curve that's closest to some other point. The tricky thing is that because Bezier curves can loop around, the distance function can have multiple local minima along the length of the curve. I figured the easiest way to find the point I'm after would be to use NMinimize. So I create a curve, create a BezierFunction, and then use NMinimize. Here I'm trying to find the Bezier point closest to {9,5}:               bezXY = {{3, -9}, {3., -4}, {14, -4}, {16, -12}};     bezF = BezierFunction[bezXY];     dist2D[p_, q_] := Sqrt[Apply[Plus, (p-q)^2]];     NMinimize[{dist2D[{9, 5}, bezF[t]], 0 <= t <= 1}, t]      This fails with multiple errors of the form:               Part::partw: Part 2 of BezierFunction[1,{{0.,1.}},{3},{{{3.,-9.},{3.,-4.},{14.,-4.},{16.,-12.}},{}},{0},MachinePrecision,Unevaluated][t] does not exist. >>      I believe the problem is that NMinimize is handing bezF values outside of [0,1], in which case bezF doesn't return a point. Restricting the domain of t to [0,1] unfortunately doesn't solve the problem - this line produces similar errors:               NMinimize[{dist2D[{9, 5}, bezF[t]], 0 <= t <= 1}, {{t, 0, 1}}]      I've tried wrapping bezF in various ways so that it always returns something valid. Here's a typical attempt:               bezF2[v_] := bezF[Max[0, Min[1, v]]];      If I use bezF2 instead of bezF in the call to NMinimize, it too fails with multiple errors. Writing bezF2 as a Module doesn't improve things. I'm not sure exactly what's going wrong here, so I'm not sure how to fix it. Any guidance would be appreciated; the more concrete and practical the better. Thank you!


title: How can I interrupt Speak?

text: I want to use an event handler to stop speaking:               Speak[ExampleData[{"Text", "DonQuixoteISpanish"}]]      The only way I can stop this is by restarting mathematica!


How to obtain a fixed number of solutions to $x+y=1$? For example, I want 4 solutions: $(1,0),(2,-1),(3,-2),(-2,3)$ I want to do this also on bigger equations such as $x+y+...=1$ and then I want to plot these values on a graph. I need help only on obtaining these solutions, I've tried to do it with `Solve` but I've been unable to do so. Notice that I can do it using Loops, I'm just checking if there's a viable way through the use of `Solve` or another built-in function.


title: Using ReplaceAll on SparseArray

text: I'm using `SparseArray` in a notebook in which I am doing complex conjugation manually, i.e. writing $\sqrt{-1}$ as `i` and applying `/.{i->-i}` to perform complex conjugation. I noticed that `ReplaceAll` or `/.` doesn't seem to work on `SparseArrays`, e.g.               m = SparseArray[{2, 2} -> i];     m /. {i -> -i}      just returns `m`. Any clues on how to get around this quickly?


title: Solving a system of equations in two variables

text: I have a system of two equations in two variables $x$ and $y$. $$\begin{align} F_1(a,b,c,d,e)x+F_2(a,b,c,d,e)y+F_3(a,b,c,d,e)&=0\\\ G_1(a,b,c,d,e)x+G_2(a,b,c,d,e)y+G_3(a,b,c,d,e)&=0 \end{align}$$ I am pretty sure that they have a unique solution but I don't have a proof. The thing is that the coefficients are gigantic and _Mathematica_ is taking forever to do a `Solve`. My guess is that it is checking to see if the system is not indeterminate or something. Is there any way I can stop _Mathematica_ from doing that and just solve it. I suppose I can suck it up and solve it by hand. I wanted to post the exact system but copy and paste is not working, I guess because it's too large. Each coefficient has maybe a hundred expressions in different combinations of about 10 variables. I need these expressions later when I will evaluate, plot, etc.


title: MATLAB To Mathematica: How to implement imshow()

text: I want to implement the MATLAB imshow function in _Mathematica_. This is a `DensityPlot[]` from _Mathematica_ > ![This pic was Densityplot by > Mathematica](http://i.stack.imgur.com/9Gakp.jpg) And this is `imshow()` image generated by _MATLAB_ > ![This pic was print by imshow\(\) from > Matlab](http://i.stack.imgur.com/v2RO2.jpg) As you can see there's a difference between the two plots. I want to obtain smooth transition in _Mathematica_ as I can in _MATLAB_.


title: How to define a fixed length vector in Mathematica?

text: I would like to define a 3-D vector as say v={x,y,z}, but I want it to have a fixed norm, say a unit norm |v|=1. How do I impose this condition on v.


title: Dynamically position labels on ListPlot

text: When it comes to labelling every single point on a `ListPlot` there might be some labels overlapping. Thus, I would like to manually position the labels with a `Line` linking them to their associated point. The following shows the idea:               coord={{0,0},{1,1}};     Manipulate[       Show[        Graphics[{Red,Line[{#2,1.02*#}]&@@@Thread[{pt,coord}]}],        ListPlot[{coord}],ImageSize->250],         {{pt,coord},Locator,Appearance->(#&/@{"a","b"})}]      ![Mathematica graphics](http://i.stack.imgur.com/omi8s.png) When it comes to more than one dataset I'm having an issue.               coord = {{0, 0}, {1, 1}};     coord1 = {{-1, 1}, {2, 0}};     Manipulate[       Show[         Graphics[{Red, Line[{#2, 1.02*#}] & @@@ Thread[{pt, coord}],                    Blue, Line[{#2, 1.02*#}] & @@@ Thread[{pt1, coord1}]}],          ListPlot[{coord, coord1}]],       {{pt, coord}, Locator, Appearance -> (# & /@ {"a", "b"})},       {{pt1, coord1}, Locator, Appearance -> (# & /@ {"c", "d"})}]


title: Plotting using IntegerListPlot

text: I can't seem to implement IntegerListPlot, or find anything about it in the documentation. I can only assume it a custom function. It comes from this link. I downloaded the _Mathematica_ notebook, but can't seem to replicate the plot. Here is the code used:               RiemannFSum[x_?NumericQ] := Total[PrimePi[x^(1/#)]/# & /@ Range[Floor[Log[2, x]]]]          Show[Block[{$DisplayFunction = Identity}, {IntegerListPlot[PrimePi[Range[50]],      PlotStyle -> Black], IntegerListPlot[RiemannFSum /@ Range[50]]}], AxesLabel ->     TraditionalForm /@ {x, {StyleForm[HoldForm[f[x]], FontColor -> Red],      StyleForm[PrimePi[x], FontColor -> Black]}}]      which _should_ generate this: ![enter image description here](http://i.stack.imgur.com/fVe9O.gif) For me though, it just generates an error message. Using ListPlot works, but is not the desired result: ![enter image description here](http://i.stack.imgur.com/581k8.gif) Am I missing something?


title: Interlacing a single number into a long list

text: This seems like it should be a simple question, but I am running into some difficulty in doing this with _Mathematica_. Right now, I have a list like this:               data1={0, 0, 0, 0, 0, 0, 3, 1, 10, 3, 11, 1, 0, 0, 32, 0, 1, 0, 5, 0, 2, 0, 25, 0, 1, 0, 1,             0, 0, 0, 0, 7, 0, 0, 0, 0, 13, 4, 0, 5, 0, 0, 2, 3, 4, 0, 0, 95, 4, 16, 11, 2, 0, 0,             81, 35, 0, 0, 0, 33, 0, 0, 0, 0, 0, 5, 42, 0, 0, 0};      I want to insert "1997" into the list after each element and transpose it, so that it will look like so: `{{1997,0},{1997,0},{1997,0}...}`. So far so good. Unfortunately, the only way I know how to do this is to manually create a list of equal length to `data1` (70 "1997"s in a row). I also do not know how to create a list that is just 70 "1997"s in a row. I've plumbed the documentation and tried every command I can think of, but the closest I can get are either functions or a list that resembles `{{1997,0,1997,0,1997,0...}` etc.


title: Threading a single abscissa through a list of ordinates

text: Suppose that I have the following list, called `list`. `list` contains elements `X`, `X1`, `X2`, and `X3`:               list = {X, {X1, X2, X3}}      I would like a function that operates on `list` and gives the following output list:               {{X, X1}, {X, X2}, {X, X3}}      Is there a simple way to accomplish this with `Thread`, `MapThread`, `Inner`, `Through`, or the like? I feel like this should be simple, but I am having a lot of trouble coming up with a simple solution. So far, I have only been able to come up with rather complicated solutions, such as               Transpose[{Table[#[[1]], {Length[#[[2]]]}], #[[2]]}] &@list      > {{X, X1}, {X, X2}, {X, X3}}


title: Slow Dynamic Button Does Not Print

text: > **Possible Duplicate:**   >  Why do buttons with ChoiceDialog freeze the front end?   >  Why is SystemDialogInput failing to return a save file path?   >  Evaluation inside Button stops after some seconds I am trying to use the code from: Make a button that evaluates a function over and over to make a button evaluate some code and plot the results, but when the code takes more than a few seconds it does not plot the results. Here is a simple example that illustrates the problem I am having For short time periods it works fine:                   func := (Pause[1]; Plot[Sin[x], {x, 0, 5}]);         DynamicModule[{result = Null},  Column[{Button["Press", result = func], Dynamic[result]}]]      But if I change the pause to be 10 seconds it doesn't show the plot                   func := (Pause[10]; Plot[Sin[x], {x, 0, 5}]);         DynamicModule[{result = Null},  Column[{Button["Press", result = func], Dynamic[result]}]]