title: Plot3D Not Showing plot

text: I have a function that I'm trying to visualize and for some reason the plot only shows a small snippet of the graph of the function. The function, `d`, and relevant values are as follows:                   G = 6.67*10^(-11)         c = 3*10^8         M = 10^(30)         J = 10^(20)         \[Gamma] = 0.018         rmin = M  + Sqrt[M^2 - J^2/M^2]              d[r_, \[Theta]_] = 1 - (2 G M r)/(c^2 r^2 + J^2/M^2 Cos[\[Theta]]^2)                             - (Sin[\[Theta]]^2 \[Gamma]^2)/c^2 (r^2 + J^2/(M^2 c^2) + ( 2 G J^2 r Sin[\[Theta]]^2)/(c^4 M (r^2 + J^2/(M^2 c^2) Cos[\[Theta]]^2)))                             + (8 \[Gamma] G r J Sin[\[Theta]]^2)/(c^4 (r^2 + J^2/(M^2 c^2) Cos[\[Theta]]^2))      The exact values of `\[Gamma], M` and `J` aren't particularly significant, although `M` and `J` are meant to be large. I'm trying to plot the graph of this function using Plot3D                    Plot3D[                 d[Sqrt[x^2 + y^2], ArcCos[x/Sqrt[x^2 + y^2]]],                  {x, 0, 3 M},                  {y,0, 6 M},                  RegionFunction -> Function[{x, y, z}, rmin < Sqrt[x^2 + y^2] ]                ]      I'm really new when it comes to working with mathematica, but I've seen online that sometimes varying `PlotPoints` and `MaxRecursion` can help to fix a plot. I tried setting `PlotPoints -> {50, 100, 1000}`, as well as `MaxRecursion -> 10` (I don't if these values are high or low w.r.t Mathematica's default settings), changing these tended to make Mathematica really sluggish, moreover they didn't produce any more of the plot. I've also tried setting `ClippingStyle -> None` and `PlotRange -> All` and none of these had any effect. I'm thinking that maybe It could be the large values that might be throwing Mathematica off, but I was under the impression that Mathematica could deal with 'astronomical numbers' (literally). Anyway if anybody has any insight into what's going wrong or just helpful advice it would be very much appreciated. **EDIT** : In the comments it was mentioned that (0,0) is a potential problem, but I have an analogous function                   M = 10         J = 1         \[Gamma] = 0.018              g[r_, \[Theta]_] = 1 - 2 M r/(r^2 + J^2/M^2 Cos[\[Theta]]^2)                             - \[Gamma]^2 Sin[\[Theta]]^2 (r^2  + J^2/M^2 + 2 r J^2 Sin[\[Theta]]^2/(M (r^2 + J^2/M^2 Cos[\[Theta]]^2)))                             + \[Gamma] 8 r J Sin[\[Theta]]^2/(r^2 + J^2/M^2 Cos[\[Theta]]^2)      Which in principle is the same, and should encounter the same issue at (0,0), but Plot3D manages just fine.


title: How can you combine lines in LATEX, and lines Mathematica?

text: supose that You want to make a report about the golden section algorithm, and you want to explain the proccess with text in LATEX, and in every iteration you want to show in that report the values ande the correct option, and then, you want to continue explaining in LATEX. How can you do this? ## For exemplae in this code, How can you do it?               itmax = 10;     tolerancia = 0.2;     alfa = (-1 + Sqrt[5])/2;     ttheta[Lambda_] = Lambda^2 + 2*Lambda;     a = -3;     b = 5;     La = a + (1 - alfa)*(b - a) // N;     Mu = a + alfa*(b - a) // N;     tthetaLa = ttheta[La];     tLacalc = "*";     tthetaMu = ttheta[Mu];     tMucalc = "*";     Printf["With * we show you that this is an evaluate of theta(t)"]     Printf["With NO* we show you that this is an evaluate of theta(t)"]     Print["iteración_k   |   a_k    b_k   |   Lambda_k     Mu_k   |   \     theta(Lambda_k)  theta(Mu_k)"];     Do[       L = b - a;       Print[" In the iteration "i, " you have the values:",           "\n a= ",a,           "\n b= ",b,           "\n Lamda= ",La,           "\n Mu= ",Mu,           "\n ",           "\n Where the values of theeta are:",           "\n theta (Lambda)= ",tthetaLa,           "\n theta (Mu)=     ",tthetaMu,        "os a =  |   ", a, "     ", b, "   |  ", La, "     ", Mu,         "   |  ", tthetaLa, tLacalc "      ", tthetaMu, tMucalc ];       If[tthetaLa > tthetaMu,        If[b - a < tolerancia, Break[]];             a = La;        La = Mu;        Mu = a + alfa (b - a);        tthetaLa = tthetaMu;        tLacalc = " ";        tthetaMu = ttheta[Mu];        tMucalc = " ";,             b = Mu;        Mu = La;        La = a + (1 - alfa) (b - a);        tthetaMu = tthetaLa;        tMucalc = " ";        tthetaLa = ttheta[La];        tLacalc = "*";        ]       , {i, 1, itmax}       ];     solucionestimada = (Mu + La)/2;     valorestimado = ttheta[solucionestimada];     Print["La solución estimada es ", solucionestimada,        " donde la función toma valor ", valorestimado];


title: How could I find the singular solutions of an ODE?

text: Starting with the equation $$y^{\prime\prime}x^2={y^\prime}^2$$ I could only get the general solution using `DSolve`:               DSolve[{y''[x] x^2 == y'[x]^2}, y[x], x]     (* {{y[x] -> -(x/C[1]) + C[2] - Log[1 - x C[1]]/C[1]^2}} *)      However, I failed to get the singular solutions `y[x] -> x^2/2 + C[1]` and `y[x] -> C[1]`. So, how can I get them?


title: Problems with CircleTimes and infix notation

text: I am trying to create a function called `TensorBasis` that takes as input a list (thought of as a list of names of basis vectors of a vector space) and an integer `d` and output the lexicographically ordered basis of the `d`-fold tensor product of the vector space with itself. For instance, the output of `TensorBasis[{v1,v2},2]` should be               { v1 [\CircleTimes] v1, v1 [\CircleTimes] v2, v2 [\CircleTimes] v1, v2 [\CircleTimes] v2 },      and so on. I have written the following code:               TensorBasis[labels_, d_] := Module[        {dim = Length[labels], basis, j, k, indexlist, tmp},             basis = ConstantArray[0, dim^d];        tmp = ConstantArray[0, d];             For[j = 1, j <= dim^d, j++,        (* Indexlist stores the indices of the jth element of the basis for the d-fold tensor product  *)             indexlist = InverseLex[dim, d, j];             (* tmp holds the list of individual factors that will make up the jth element of the basis *)         For[k = 1, k <= d, k++,           tmp[[k]] = labels[[indexlist[[k]] ]]         ];             (* jth element of the basis is created by tensoring together all elements of tmp *)         basis[[j]] = Infix[tmp, "\[CircleTimes]"]       ];     Return[basis]     ];      The function InverseLex just gives me the appropriate list of indices for the basis element I am trying to construct. I am sure that that function is working properly. But the output is all weird. The problem is that in the output, the [CircleTimes] (i.e. tensor product) symbol is replaced by some junk: in Plain Text form it is               {Subscript[v, 1]â Subscript[v, 1],Subscript[v, 1]â Subscript[v, 2],Subscript[v, 2]â Subscript[v, 1],Subscript[v, 2]â Subscript[v, 2]}      When I use the Infix notation with "[CircleTimes]" otherwise it works fine. Why won't it work inside this function?


title: Find time since last 0 in list

text: When I have a list of data (measured per day), is it possible to define a function that gives the nr of days since the data has been 0? I tried working with`Position`to find the 0's but that did not really help me to create a function. **Simplified example:**               data = {{1, 0}, {2, 1}, {3, 3}, {4, 0}, {5, 1}, {6, 0}};     ListPlot[data, InterpolationOrder -> 0, AxesLabel -> {"time(day)", "data(mm)"}, Joined -> True]      ![enter image description here](http://i.stack.imgur.com/LtkUV.jpg) **Result I want:** ( I now entered it myself, but I want to do this for large amounts of data, which makes typing it very time consuming ;))               result = {{1, 0}, {2, 0}, {3, 1}, {4, 2}, {4,0}, {5, 0}, {6, 1}};     ListPlot[result, AxesLabel -> {"time(day)", "days since last 0"},         Joined -> True]      ![enter image description here](http://i.stack.imgur.com/fbuTb.jpg)


title: Extracting polygon color parameter from another variable

text: I'm a beginner with Mathematica, so this may seem like a simple question, though it's got me totally stumped. I'm trying to display several polygons and have the color of each polygon depend on the value in some other variable (`stscds`). My thinking is that I should do something like this: `Show[Graphics[Table[{RGBColor[stscds[[i]],0,0,0.2],EdgeForm[Black],poly[[i]]}, {i,1,300,1}]]]` `poly` contains all of the polygons. Or possibly this: `megapol = Table[{RGBColor[stscds[[i]],0,0,0.2],EdgeForm[Black],poly[[i]]}, {i,1,300,1}] Graphics[megapol]` It doesn't like that I'm trying to pull the color parameter out of `stscds` (this variable is full of values between 1 and zero). It says 'Ignoring invalid graphics directive RGBColor[0,01 1,0,0]. Any idea how I might approach this problem? Edit: Output of `stscds`: `{("1")/100, ("1")/100, ("1")/100, ("1")/100, ("1")/100, ("1")/100, \ ("1")/100, ("1")/100, ("1")/100, ("2")/100, ("2")/100, ("2")/100, \ ("2")/100, ("2")/100, ("2")/100, ("3")/100, ("4")/100, ("4")/100, \ ("4")/100, ("4")/100, ("4")/100, ("4")/100,....`


title: Custom highlighting in definitions

text: Suppose we defined a pattern with custom pattern name provided by user, like               Quiet[myCustomPattern@terms_ := f[terms : (_[_, _])..]]      for use in further definitions:               myTransform@myCustomPattern@localNameForTerms := Reverse /@ {localNameForTerms}      However, in definitions like this one, `localNameForTerms` is not by default highlighted the way it would be in case of appearing in explicit Pattern expression. Is it possible to Style it as a properly localized symbol, by putting               myCustomPattern -> Composition[myCustomPattern, Style[#, Darker@Darker@Green, Italic] &]      somewhere in the low-level notebook representation rules, for example?


title: What is an efficient way of selecting multiple colors via Manipulate?

text: Background: The following snippet is what I (intend to) use in a `Manipulate` form where up to 12 different colors can be selected:                Manipulate[{sliderCol1},       Row[{"Kleur 1: ", ColorSlider[          Dynamic[sliderCol1] ,          AppearanceElements -> {"SwatchSpectrum"},          ImageSize -> {200, 40},          BaselinePosition -> Scaled[.25]]}        ]      ]      To make this work with fields `sliderCol1` to `sliderColn` (where $n$ = 2, …, 12), I see no other option than copying the code in `Row` so many times. **Question: Is there a less verbose way of implenting a multiple (here 12) color selector using color sliders?**


title: Simple derivative not working

text: I'm a complete newbie to Mathematica. I've been using Wolfram Alpha Pro as well as MS Mathematics for a few months but wanted to dive into using a more powerful tool. I'm having a problem with calculating a simple derivative and I can't figure out what I'm doing wrong. I tried using free-form input after unsuccessfully trying to use Mathematica syntax but I get the same results. The same query works fine in Wolfram Alpha Pro. I'm getting pages of repetitive output. Here are a couple of screenshots. The second one is a continuation from further down showing "MaxFormatDepthExceeded" errors. Any help is greatly appreciated. I apologize for such a basic question. P.S. I've added a 3rd screenshot to illustrate the successful results for the same query in Wolfram Alpha Pro. As an aside, can anyone suggest any resources to quickly jump-start my usage of Mathematica? I started to go through the documentation but some of it was quite dense and assumed a level of knowledge that I don't yet have as a first semester calculus student who hasn't done math in some time. ![screenshot 1](http://i.stack.imgur.com/8Gpuu.png) ![screenshot 2](http://i.stack.imgur.com/r4p1z.png) ![same query in Wolfram Alpha Pro](http://i.stack.imgur.com/3SC25.png)


title: DSolve expression doesn't evaluate

text: Can _Mathematica_ solve $\; d^2/dx^2{}+ (1/x) d/dx\;$ form of equations?   For example, I am trying to solve the system of equations given below:               eqn1 = D[w[x], {x, 2}] + (1/x) (D[w[x], x]) - w[x];     eqn2 = D[v[x], {x, 2}] + (1/x) (D[v[x], x]) - (v[x] - u[x]);     eqn3 = D[u[x], {x, 2}] + (1/x) (D[u[x], x]) + v[x] - u[x] - w[x];     eqnSet = {eqn1 == 0, eqn2 == 0, eqn3 == 0, w[1] == 0, v[1] == 0,            u[1] == 0, w'[0] == 0, v'[0] == 0, u'[0] == 0};     DSolve[eqnSet, {w[x], v[x], u[x]}, x]      I am getting `DSolve` returning the input statement unevaluated.


title: How to create a 2D array (matrix)

text: I am pretty new to _Mathematica_. I need to create 2d array dynamicly. I got some code in C++(Qt) and it looks like this:               void Wave::getMatrix(int M, int N)     {         int k = -N;         while(k < N+1){             QVector<tsk_type> temp_vec;                  for(int i = -N; i < N+1; i++){                 temp_vec.push_back(getY(i));                 tsk_type temp_sum0;                      for(int ii = -M; ii < M+1; ii++ ){                     temp_sum0 += (getI(i-ii, b)/getY(ii)) * getJ(ii-k,b1,b2);                             }                 temp_vec[temp_vec.size()-1] = temp_sum0;                      if (k == i)                     temp_vec[temp_vec.size()-1] -= l;                          }                  temp_vec.push_back(getD(S)*getI(S-k, b));             main_array.push_back(temp_vec);             k++;         }          }      In _Mathematica_ , I have already written all the functions that I need to make some linear equation system matrix which I can solve. I even got a formula for this and I also implemented the functions I need.               getI[k_ , a_, b_];     getJ[k_ , a1_, b1_, a2_, b2_];      getGamma[n_]     getD[s_]      So `C_k` and `C_n` are unknown parameters which I need to find. Here is the formula ![enter image description here](http://i.stack.imgur.com/D9PEo.png) And the question is: How should I properly prepare and create matrix for which I could apply some lineral equation solving method like Gaussian or Gaussian- Jordan? P.S. I know that there are some C++ stuff like `librarylink`, but I need to use _Mathematica_ ;s built-in functions. **UPD:** Here's my attempt to create matrix. I run it but it's not working. Also there are no error messages. Whats wrong?               (*all globlas definiton is somewhere here*)                  k = -N;                  mainmatrix = List[[]];             While[k < N + 1,                         rowvalues = List[];                         For[i = -N, i < N + 1, i++,                             tempsum;                                 AppendTo[rowvalues, getGamma[i]];                             For[j = -M, j < M + 1, j++,                                                tempsum = tempsum +  (getI[i - j, a, b]/getGamma[j]) *                                            getJ[j - k, a1, b1, a2, b]                                 ]                                AppendTo[rowvalues, tempsum];                                    If[k == i, AppendTo[rowvalues, -l], 0]];                                AppendTo[rowvalues, getD[S]*getI[S - k, a, b]];                                AppendTo[mainmatrix, rowvalues];                   k++]


title: Returning a bounding disk or box centered on a coordinate in a 2D image

text: Provided a coordinate $c_k$ in a two-dimensional image, how can I return all of the pixels in a bounding disk or rectangle centered on $c_k$ of some specified dimension $d$? **Update:** Hat tip to Kuba for recommending `PixelValue` and Sjoerd C. de Vries for recommending `ImageData`. However, considering the case of the bounding box, is it possible to return the pixels using:               PixelValue[image,                {Subscript[x, min];;Subscript[x, max],Subscript[y, min];;Subscript[y, max]}]       In the form of a matrix rather than a 1-dimensional array?


title: Defining a pure function involving a function argument

text: I've got an expression involving `x` and `y` that I want to use as a `MeshFunction`:               mymesh = x + y     Plot3D[x^2 + y^2, {x, -1, 1}, {y, -1, 1}, MeshFunctions -> {Function[{x, y, z}, mymesh]}]      This works just fine. But now I want to create a plotting function that takes the mesh function as an argument, like so:               myplot[mesh_] := Plot3D[x^2 + y^2, {x, -1, 1}, {y, -1, 1},                             MeshFunctions -> {Function[{x, y, z}, mesh]}]     myplot[mymesh]      This produces the following error:               MeshFunctions::invmeshf:       "MeshFunctions->Function[{x$,y$,z$},x+y] must be a pure function or a list of pure functions"      It seems like it's making local variables `x$, y$, z$` and then keeping them distinct from the `x,y` in `mymesh`. Any suggestions how to make this work? I'd like to keep `mymesh` in the symbolic form, because the plot I'm actually interested in doing is much more complicated, and uses the `mymesh` function a second time as part of the function to plot. I'm going to add some more to this question, because I have a few answers, all of which suggested not passing `mymesh` in it's current form to the function. But I explicitly want to pass `mymesh` as it is. Here's the actual code I'm using it for. It plots the solutions to `c==0` on the unit sphere, where `c` is a homogeneous polynomial in `x,y,z`.               elliptic = z y^2 - x^3 + z^2 x     curveSpherePlot[c_] := ContourPlot3D[       {x^2 + y^2 + z^2 == 1, c == 0},       {x, -1, 1}, {y, -1, 1}, {z, -1, 1},       MeshFunctions -> {Function[{x, y, z}, x^2 + y^2 + z^2 - 1 - c]},       MeshStyle -> {{Thick, Black}},       Mesh -> {{0}},       ContourStyle -> {Opacity[0.9], None},       BoundaryStyle -> None     ]     curveSpherePlot[elliptic]      Notice that the argument `c` appears in the equation as well as in the mesh function. Not only that, but I manipulate the curve symbolically with other functions in the package, so I really don't want to switch it to a different type of object if I can help it.


title: NIntegrate Issue: Changing integration limits makes calculation time extremely long

text: After a long time developing some code in mathematica and finally getting it to work, I have unfortunately encountered an odd problem: When I change the limits of integration (and shift the function that I am integrating) NIntegrate takes extremely long (on the order of hours) to complete. Now, this would be understandable if I increased the limits of integration but in my case, its the opposite I am decreasing the limits of integration. Given the following constants and functions:               sL[phi_] := (r*phi^3)/24     lambdaB[z_] := 1/(sigmaSbeg*Sqrt[2 Pi]) Exp[-(z^2/(2*sigmaSbeg^2))]     lambdaE[z_] := 1/(sigmaSend*Sqrt[2 Pi]) Exp[-(z^2/(2*sigmaSend^2))]     lambdaC[z_, phi_] :=       1/(((sigmaSend - sigmaSbeg)/theta *phi + sigmaSbeg)*Sqrt[2 Pi])Exp[-(z^2/(         2*((sigmaSend - sigmaSbeg)/theta *phi + sigmaSbeg)^2))]         deEntrance[s_, phi_?NumericQ] :=       With[{sL = sL[phi]},         ((lambdaC[s - sL, phi] - lambdaB[s - 4 sL])/sL^(1/3) +           NIntegrate[(1/(s - sprime)^(1/3)*             D[lambdaC[sprime, phi], sprime]), {sprime, s - sL,             s}])]     deEntranceRMS[phi_?NumericQ] :=       Sqrt[NIntegrate[         lambdaE[s]*(deEntrance[s, phi])^2, {s, -5 sigmaSend,           5 sigmaSend}] - (NIntegrate[          lambdaE[s]*(deEntrance[s, phi]), {s, -5 sigmaSend,            5 sigmaSend}])^2]          NIntegrate[(eta1[r*phi])*deEntranceRMS[phi], {phi, 0.0,theta}]     NIntegrate[(eta2[r*phi])*deEntranceRMS[phi], {phi, 0.0, theta}]      The following works well and outputs an answer within a reasonable amount of time:               sigmaSbeg = 2.759153*10^-004;     sigmaSend = 2.774392*10^-004;     theta=0.06;     r=9.15445;     eta1[s_]:=-0.05461846 s^2     eta2[s_]:=-0.10923649 s      But, for the following, Mathematica takes extraordinarily long.               sigmaSbeg = 8.280940*10^-006;     sigmaSend = 8.308940*10^-006;     theta=0.014;     r=17.857143;     eta1[s_]:=0.00059452375 + 0.028 (-0.25 + s)^2     eta2[s_]:=-0.014 + 0.056 s      I cannot figure out why. I assume my eta1 and eta2 functions are a little more complex, but they're only shifted quadratics and linear functions. Any help would be great


title: How to calculate solution for each variable automatically

text: Here I have one problem how to calculate x for each y. In this form code doesn't work                    y = {0.1, 0.2, 0.3, 0.4, 0.5, 0.6,0.7};             NSolve[-y*16 x^3 - y^2*25 x^2 + 5 == 0, x]


title: Why doesn't FindClusters find any clusters in this case?

text: I am trying to use FindClusters to segment data points into similar numbers but so far I couldn't get it work for this example:               l = {110, 111, 115, 117, 251, 254, 254, 259, 399, 400, 401,           402, 542, 546, 549, 554, 660, 660, 660, 660};     FindClusters[l]     (*     -> {{110, 111, 115, 117, 251, 254, 254, 259, 399, 400, 401, 402, 542,         546, 549, 554, 660, 660, 660, 660}}     *)      If I set the N parameter (to specify: Exactly N clusters), it works:               FindClusters[l, 5]     (*     -> {{110, 111, 115, 117}, {251, 254, 254, 259},          {399, 400, 401, 402}, {542, 546, 549, 554}, {660, 660, 660, 660}}     *)      However, my intent was to use FindClusters to figure out N.


title: Module and Local variable

text: Hello,               GetIntersectionPoint[p1_, p2_] :=                   Module[{pts, vecs, n, vars, distance, sol, x, y, z, t}, (                         pts = p2;                    vecs = p1 - pts;                    n = Length[pts];                    vars = Array[t, n];                    {distance, sol} =                      Minimize[                      Total[({x, y, z} - Transpose[pts + vecs vars])^2, 2], {x, y, z}~                       Join~vars]                              )]      I call this function with p1 and p2 where                   p1={{100, 100, 100},{100, 0, 100},{0, 100, 100}};         p2={{500/3, 500/3, 0},{500/3, 0, 0},{0, 500/3, 0}};      I obtain like this:               {0, {x$17013 -> 0, y$17013 -> 0, z$17013 -> 250, t$17013[1] -> 5/2,        t$17013[2] -> 5/2, t$17013[3] -> 5/2}}      How Can I fix the rename of the local variables ?


title: Plot "OilReserves" using CountryData from 1985 until 2014

text: I am newer using Mathematica to plot with the Function: CountryData, I am trying to plot "OilReserves" in "UnitedKingdom" from 1985 until 2014. I don't know how to do it, please help me!


title: Filling the empty space in RevolutionPlot3D

text: I'm wanting plot the solid of revolution from the area between two functions such as: $1\leq x \leq e$ and $1 \leq y \leq 2 + ln(x)$, doing something like:               f[x_]:=2+Log[x]     g[x_]:=1     RevolutionPlot3D[{{f[x]}, {g[x]}}, {x, 1, E},      RevolutionAxis -> x, AxesOrigin -> {0, 0, 0},      Boxed -> False, Mesh -> {5, 0}, PlotRange -> {{0, 3}, All},      PlotStyle -> Opacity[0.5]]      ![plot](http://i.stack.imgur.com/mVCDJ.png) There is a way to fill this empty space between $f(x)$ and $g(x)$?   Thanks in advance.


title: How to create symbol whose name has subscript?

text: I can do               Symbol["foobar"]      to create a symbol `foobar`. How to create a symbol $\theta_1$?               Symbol[Subscript[\[Theta], 1]]      doesn't work.


title: How to minimize a certain function

text: What can be wrong with this?               Clear[a, b, c, x, AX, BX];     a > 0;     b > 0;     c > 0;     AX[x_] := Sqrt[a^2 + x^2];     BX[x_] := Sqrt[b^2 + (c - x)^2];     roadCost[x_] := 10000 AX[x] + 20000 BX[x];     Minimize[{roadCost[x], c - (b c)/(a + b) <= x <= c}, x]


title: Combining lists in a matrix

text: So I have a list of data `A={1.1,1.2,1.3,1.4,6.1}` etc and `B={2.5,2.6,2.7,2.8,2.9}` I need to combine the lists into a matrix C               {{1.1,2.5},{1.2,2.6},{1.3,2.7},{1.4,2.8},{6.1,2.9}}      How would I go about doing that?


title: Why does a translation in the horizontal direction affect PointSize?

text: I'm running _Mathematica_ 9.0.1 under Mac OSX. Not sure if this is a bug or whether I'm not supposed to apply a `GeometricTransformation` to a list containing graphic primitives and directives:               verts = {{0, 0}, {1, 0}, {Cos[60 Degree], Sin[60 Degree]}};     tri = {{PointSize[0.2], Point[verts]}, {Line[verts~Append~First@verts]}};      Translating purely in the vertical direction works how I expect it to:               Graphics[GeometricTransformation[tri, TranslationTransform[{0, #}] & /@ Range[0, 2]]]      ![vertical translation](http://i.stack.imgur.com/og8cq.png)               Graphics[GeometricTransformation[tri, TranslationTransform[{#, 0}] & /@ Range[0, 2]]]      However, if the translation has a horizontal component, then the point size gets messed up, in the sense that it's not compensating the size of the points with respect to the size of the graphic in the notebook: ![horizontal translation](http://i.stack.imgur.com/zWoAw.png) Is this a bug?


title: A problem about option "Plotlegends"

text: **_Today,I use the Mathematica to deal with data.My code as below:_**                Needs["PlotLegends`"]      **_Function Definition:_**                TargetList[dData_List, massData_List] := Block[      {TargetListResult, dAverageData, miData},      dAverageData = Mean /@ Partition[dData, 2, 1];      miData = Table[Total@massData[[1 ;; i]], {i, 1, Length@dAverageData}];           TargetListResult =       MapThread[List,                  N@Log[10, #] & /@ {dAverageData/Max@dAverageData, miData/         Total@massData}]      ]      **_Data Input:_**               DryData={{8.28, 17.57, 10.15, 4.85, 2.41, 11.74}, {7.82, 12.19, 6.65, 3.57, 1.8, 20.97},             {23.58, 19.44, 18.08, 11.1, 8.72, 19.08}, {25.18,16.51, 17.5, 8.01, 4.54, 28.26},            {10.67, 28, 14.49, 17.86, 8.97, 20.01},{14.29, 19.28, 16.14, 15.54, 10.36,24.39},               {25.94, 21.1,20.02, 11.37, 6.11, 15.46},{24.51, 23.99, 13.75, 11.95, 4.32,21.48},             {33.51, 22.69, 19.26, 8.23, 4.88, 11.43},{22.15, 25.54, 23.5, 8.34, 4.69,15.78},              {20, 19.06, 18.65, 12.19, 11.68,18.42}, {18.84, 20.09, 9.75, 15.3, 12.48,23.54}};           DryNameData={"Space0-20,Dry", "Space20-40,Dry", "Tao0-20,Dry", "Tao20-40,Dry",                    "Yang0-20,Dry", "Yang20-40,Dry", "Pu0-20,Dry", "Pu20-40,Dry",                   "Yangshu0-20,Dry", "Yangshu20-40,Dry",                   "MoxigeBai0-20,Dry", "MoxigeBai20-40,Dry"};           dData = {0, 0.25, 0.5, 1, 2, 5, 10};           solvingDryData = Reverse /@ DryData;           fitLineDryFunction =       Fit[#, {1, x}, x] & /@ (TargetList[dData, List[##]] & @@@solvingDryData);      **_Without PlotLegends:_**                Show[Plot[fitLineDryFunction, {x, -2, 0}, AxesOrigin -> {-2, -1},ImageSize -> 600],          ListPlot[TargetList[dData, List[##]] & @@@ solvingDryData,          AxesOrigin -> {-2, -1}, PlotMarkers -> Automatic, ImageSize -> 600]]      **_It give the normal graphics_** ![enter image description here](http://i.stack.imgur.com/XWtAN.jpg) **_However,when I use the`PlotLegends`option,it gives the wrong result:_**                Show[ListPlot[TargetList[dData, List[##]] & @@@ solvingDryData,            AxesOrigin -> {-2, -1}, PlotLegend -> DryNameData,            PlotMarkers -> Automatic, LegendPosition -> {1.1, -0.5},            LegendSize -> 1.25, LegendShadow -> None,            LegendTextOffset -> {-.6, 0}, LegendTextDirection -> {3, 1},            ImageSize -> 800], Plot[fitLineDryFunction, {x, -2, 0}]]      ![enter image description here](http://i.stack.imgur.com/prrh1.jpg) **_So my question is how to revise it?_**


title: Setting non-standard ImageResolution for EMF export as default

text: Mathematica has a bug in that `BarChart`s and `ListPlot`s with `Filling` will export as a pixelated bitmap, not a vector graphic when exporting as EMF format. There is a workaround, which is to set `ImageResolution` to be 1300 or higher in the `Export` command, like this:               testdata = RandomReal[{5, 10}, 20];     bg1 = BarChart[{testdata}]     Export["bg1400.emf", bg1, ImageResolution -> 1400]      (No, you don't get a huge file if you set `ImageResolution` this high. It somehow tricks it into using vector graphics. However the workaround is a bit unreliable, depending on the graph in question.) How can I make this option the default? `SetOptions[Export]={ImageResolution -> 1400}` produces an error message that it's not a recognised option to `Export`. I also tried:               SetOptions[$FrontEndSession, ConversionOptions -> {"ExportOptions" -> {"EMF" ->        {"IncludeSpecialFonts" -> True, ImageResolution -> 1400}}}]      But that doesn't seem to do anything. How do I set these export options as the default, e.g. in a package? Alternatively, how do I force this hidden vector capability?


title: Simple rule appears not to work

text: I have the following simple code               Clear["Global`*"];          V = v0^2/2*Log[x^2 + (y/q)^2 + rc^2];     sub = {(v0^2/(x^2 + (y/q)^2 + rc^2)) -> (arg)};          Vx = D[V, x];     Vy = D[V, y];          Vxx = Simplify[D[V, {x, 2}]];     Vxy = Simplify[D[Vx, y]];     Vyy = Simplify[D[V, {y, 2}]];     Vyx = Simplify[D[Vy, x]];          Print["******************************"]     Print["Vx = ", Vx //. sub]     Print["Vy = ", Vy //. sub]     Print["Vxx = ", Vxx //. sub]     Print["Vxy = ", Vxy //. sub]     Print["Vyx = ", Vyx //. sub]     Print["Vyy = ", Vyy //. sub]     Print["*****************************"]      which calculates the first and second derivatives the function $V$. The printed results I added a rule `sub` in order to make the output much simpler. However, for a strange reason, the rule applies correctly to the first derivatives $Vx$ and $Vy$ but it has no effect to the second ones $(Vxx, Vxy, Vyx, Vyy)$. Any ideas why?


title: How to create a wind rose with Mathematica?

text: I am trying to plot **wind rose** in _Mathematica_ , but have no idea how to do this. ![Plot](http://i.stack.imgur.com/wlLbu.jpg) Any suggestions ?


title: How to make Joined skip missing data points

text: I have a set of data taken on sequential days, but some points are missing. I'd like to make a joined date list plot, where the points are not joined across the missing point.The following example illustrates the desired result.               data1 = {     {{2013, 7, 1}, 1},     {{2013, 7, 2}, 5},     {{2013, 7, 3}, 2},     {{2013, 7, 4}, 4},     {{2013, 7, 6}, 2},     {{2013, 7, 7}, 6}     };     data2 = {     {{2013, 7, 1}, 6},     {{2013, 7, 2}, 2},     {{2013, 7, 3}, 4},     {{2013, 7, 4}, 1},     {{2013, 7, 5}, 7},     {{2013, 7, 6}, 1},     {{2013, 7, 7}, 4}     };     DateListPlot[{     data1[[1 ;; 4]],     data1[[5 ;; 6]],     data2[[ ;; ]]     }, PlotStyle -> {Blue, Blue, Red}, Joined -> True]      Note that `data1` is missing a point on July 5. In practice I'm doing this with multiple data sets, with hundreds of points, so breaking it apart and manually assiging plotstyle like I have here is not viable. How can I make `Joined` skip missing points?


title: Pure function with attributes of arbitrary number of arguments: Is it possible?

text: _Mathematica_ allows to define pure function, like               Function[{a, b},Length[Unevaluated@a]{b}][1+2,2+3]     (*     ==> {0}     *)      Pure functions in _Mathematica_ can take an arbitrary number of arguments, but only if not naming them, for example:               Function[Length[Unevaluated@#1]{##2}][1+2,2+3,3+1]     (*     ==> {0,0}     *)      Also, pure functions can optionally have attributes, for example:               Function[{a,b},Length[Unevaluated@a]{b},{HoldFirst}][1+2,2+3]     (*     ==> {10}     *)      However what I haven't found is a way to have both arbitrary many arguments and attributes:               Function[(* what, if anything, to put here? *)][1+2,2+3,3+1]     (*     ==> {10, 8}     *)      Therefore my question: **Is it possible to define pure functions which take an arbitrary number of arguments and at the same time have attributes? And if so, how would one define them?** The obvious solution doesn't work:               Function[Length[Unevaluated@#1]{##2},{HoldFirst}][1+2,2+3,3+1]     (*     Function::flpar: Parameter specification Length[Unevaluated[#1]] {##2} in      Function[Length[Unevaluated[#1]] {##2},{HoldFirst}] should be a symbol or      a list of symbols. >>     *)      Adding an empty parameter list disables parameter substitution for `##`;               Function[{},Length[Unevaluated@#1]{##2},{HoldFirst}][1+2,2+3,3+1]     (*     ==> {##2}     *)      Of course, a workaround is easy; for example, have the pure function take a list (which in the example above would actually have been the better alternative anyway), or simply using a named function. So it's more of a curiosity. It just seems odd to have two completely orthogonal features of pure functions, and yet not being able to combine them.


title: How to make a scatter plot from 2 images

text: How can two images be used to create a scatter plot, image 1 being the x axis, image 2 being the y axis, and the color of each plot point being the bin count?


title: Is there a better way to create my rotational-symmetric (180 degrees) rectangles?

text: I have created a simple way to create rotational-symmetric (180 degrees) rectangles, but my `stuffit` function bothers me. No matter what I tried, I couldn't get it to work within the recursive function. Can someone show me the way?               stuffit[n_List, k_] :=      Block[{j = n}, For[m = k, m <= Length[j], m += k, j[[m]] = k];      Return[j]]            f[1] := 1     f[k_] := stuffit[Flatten[Table[f[k - 1], {n, (Cyclotomic[k, 1])}]], k]     f[k_, p_] := Partition[f[k], p]          f[6, 6] // MatrixForm        **Edit** Replaced `stuffit` with `MapAt` from kguler's answer below. I used it within the recursive routine. Also, added parameter to the partitioning function to subtract the 3rd parameter from p to take the smaller rectangle: f[6,6,1] skips the rightmost column.               f[1] := 1       f[k_] := MapAt[k &, Flatten[Table[f[k - 1],       {n, (Cyclotomic[k, 1])}]], {k ;;  ;; k}]     f[k_, p_, x_] := Partition[f[k], p][[All, 1 ;; p - x]]          f[6, 6, 0] // MatrixForm (*below*)      $$\left( \begin{array}{cccccc} 1 & 2 & 3 & 4 & 5 & 6 \\\ 1 & 4 & 3 & 5 & 1 & 6 \\\ 1 & 2 & 5 & 4 & 1 & 6 \\\ 1 & 5 & 3 & 2 & 1 & 6 \\\ 5 & 2 & 3 & 4 & 1 & 6 \\\ 1 & 4 & 3 & 2 & 5 & 6 \\\ 1 & 2 & 3 & 5 & 1 & 6 \\\ 1 & 4 & 5 & 2 & 1 & 6 \\\ 1 & 5 & 3 & 4 & 1 & 6 \\\ 5 & 4 & 3 & 2 & 1 & 6 \\\ \end{array} \right)$$ The rotational symmetry is 180 degrees using the $k-1$ rectangle (omitting the rightmost column, including the ends of the rows.) I think this is the coolest thing I have ever created because it partitions down and keeps the symmetry. _Try 6,4,0 and 6,5,0 and 6,4,1 and 6,5,1_


title: puzzled with ColorData

text: At first let me thank, from this point as well, those that they replied to my previous queries. From a reply I got, I obtained finally the desired graph.               lst = {10*Cos[u]*Sin[v], 3*Sin[u]*Sin[v], 2*Cos[v]};     dam = Sqrt[(1296*Cos[u]^4*            Sin[v]^4)/(900*Cos[v]^2 + 36*Cos[u]^2*Sin[v]^2 +              400*Sin[u]^2*Sin[v]^2)^2 + (3600*Cos[u]^2*            Sin[v]^2*(9*Cos[v]^2 + 4*Sin[u]^2*Sin[v]^2))/(900*Cos[v]^2 +              4*(9*Cos[u]^2 + 100*Sin[u]^2)*Sin[v]^2)^2];     colFun = Function[{u, v}, Evaluate@Hue[Rescale[dam, {0, 1}]]];     {min, max} = {0, 1};     ParametricPlot3D[lst, {u, 0, 2*Pi}, {v, 0, Pi}, Mesh -> False,       ColorFunction -> (colFun[#4, #5] &), ColorFunctionScaling -> False,       PlotRange -> All, ImageSize -> 800,       PlotLegends ->        BarLegend[{Hue, {min, max}}, ColorFunctionScaling -> True]]      Now, what I want is to check the outputs of other available color schemes. I did the following:               coldata = ColorData["Gradients"];     col = Table[{i, coldata[[i]], ColorData[coldata[[i]]]}, {i, 51}];      So, for instance (for ColorData["BrightBands"])               {min, max} = {0, 1};     lst = {10*Cos[u]*Sin[v], 3*Sin[u]*Sin[v], 2*Cos[v]};     colFun = Function[{u, v}, Evaluate@col[[10, 3]][Rescale[dam, {0, 1}]]];     h = ParametricPlot3D[lst, {u, 0, 2*Pi}, {v, 0, Pi}, Mesh -> False,        ColorFunction -> (colFun[#4, #5] &), ColorFunctionScaling -> False,        ImageSize -> 800,        PlotLegends ->         BarLegend[{colFun, {min, max}}, ColorFunctionScaling -> True]]      The coloring of the ellipsoid is as desired, but this does not hold true for the color bar. Obviously, something I made wrong. I really appreciate any help! Dimitris


title: How to calculate a double indefinite integral

text: I need to calculate double integral as shown below. I used the Classroom Assistant palette to write the integral. How can I enter it as ordinary text, i.e., `Integrate[....],` so _Mathematica_ would treat it exactly the same as the form entered by means of the palette? How would I formulate it for submission to Wolfram Alpha? ![enter image description here](http://i.stack.imgur.com/rFOf8.png)


title: A timed switch with Dynamic

text: I'm trying to make a binary switch that switches after a fixed given interval. Why doesn't the following work:               step = .1;     t = Dynamic[Clock[{0, 5, step}, 5, 1] ];      Dynamic[t >=  2]


title: plot totally fragmented, WorkingPrecision,matlab comparison

text: I am trying to plot               F2q0overLambdaSimpler3[m_] :=      1/(Sqrt[2] (4*Pi)^2)*1/(2 (m^4) )*(1/Sqrt[1 - 4 m^2]*(2 - 10 m^2 + 8 m^4)*      ArcTanh[Sqrt[1 - 4 m^2]/(1 - 2 m^2)] +      2*(2 m^2 - 3 m^4 + (2 - 6 m^2) Log[m]))$      Just using               Plot[F2q0overLambdaSimpler3[m], {m, 1/(200*10^3), 1/(100*10^3)}]      But the result looks like this: ![enter image description here](http://i.stack.imgur.com/anmaP.jpg) Then I plotted this function using matlab: ![enter image description here](http://i.stack.imgur.com/blCyz.jpg) How do I get mathematica plotting it equally nice? I already tried things like               WorkingPrecision -> 100      or even 1000 what yields a very weird behaviour.... Any suggestions?


title: Prove (or check) an expression is positive given constraints on variables?

text: I'm trying to figure out whether an expression is always positive given positive parameters. When the expression is complicated, I can't do this by eye. Is there any way to make _Mathematica_ prove (that is, check) if `j` is positive for positive `c, d, k, ton, toff, V`?               j=-2 c d k toff ton - d^2 k toff ton - 2 c k toff^2 ton -       2 d k toff^2 ton - k toff^3 ton - 2 c d k ton^2 - d^2 k ton^2 -       4 c k toff ton^2 - 4 d k toff ton^2 - 3 k toff^2 ton^2 -       2 c k ton^3 - 2 d k ton^3 - 3 k toff ton^3 -       k ton^4 + (Sqrt[k] Sqrt[ton] (toff + ton) Sqrt[         d + toff +           ton] (2 c + d + toff +            ton) \[Sqrt]((c + d) k ton (c + toff + ton) (d + toff + ton) +             4 c d ((d + toff + ton) (k toff + (toff + ton)^2) +                c (k toff +                   d (toff + ton) + (toff + ton)^2)) V))/(2 Sqrt[(c +             d) (c + toff + ton)]) + (Sqrt[k] Sqrt[         ton] (toff + ton) Sqrt[(c + d) (c + toff + ton)] Sqrt[         d + toff +           ton] (k ton (d + toff + ton) (2 c + d + toff + ton) +            4 d ((d + toff + ton) (k toff + (toff + ton)^2) +               2 c (k toff +                  d (toff + ton) + (toff + ton)^2)) V))/(2 \[Sqrt]((c +                d) k ton (c + toff + ton) (d + toff + ton) +             4 c d ((d + toff + ton) (k toff + (toff + ton)^2) +                c (k toff + d (toff + ton) + (toff + ton)^2)) V))      I have many more expressions like this. I have tried putting in random values of the parameters and I do (so far) always get positive values. But I'd prefer something more convincing than a Monte Carlo argument for this (and other) complicated expressions being positive for any positive inputs. Thoughts?


title: Parallel computation of NDSolve and a problem

text: I used this code to solve a system of differential equations:                   ro[t_] :=          Table[Subscript[ρ, i, j][t], {i, 1, sysdim}, {j, 1, sysdim}];              RHS = A matrix;         RHS2 = RHS              ParallelTable[Flatten[NDSolve[{ro'[t] == RHS, ro[0] == initial}, Flatten[ro[t]],                                {t, 0, 10}]], {γ, 1, 2}]      Whenever I use `RHS`inside the `NDSolve`, I get this error: > >        NDSolve::ndnum: Encountered non-numerical value for a derivative at t > == 0.`. >   But, when I use `RHS2` which is basically `RHS`, I don't get any error message. Does anybody know the problem? * * * ### Edit. Here I put the whole code:                   δ[i_, j_] := KroneckerDelta[i, j]         sysdim = 7;              Hsystem[dimension_] := Module[{sysdim = dimension},         V[ii_, jj_] := Module[{i = ii, j = jj},              If[i > j, Return[Subscript[V, j, i]], Return[Subscript[V, i, j]]]];              hsys[i_, j_] := δ[i, j]*Subscript[ϵ, i] + V[i, j] (1 - δ[i, j]);              MHsys = Table[hsys[i, j], {i, 1, sysdim}, {j, 1, sysdim}]         ]              Hsys = Hsystem[sysdim];              A[m_] := Table[δ[i, m]*δ[j, m], {i, 1, sysdim}, {j, 1,          sysdim}]         ro[t_] :=          Table[Subscript[ρ, i, j][t], {i, 1, sysdim}, {j, 1, sysdim}];         (*LL=Table[(-1+δ[i,j])*ro[t][[i,j]],{i,1,sysdim},{j,1,sysdim}]*)                   L = γ*         Sum[A[m].ro[t].A[m]\[ConjugateTranspose] -           1/2 (A[m].A[m]\[ConjugateTranspose].ro[t] +              ro[t].A[m].A[m]\[ConjugateTranspose]), {m, 1, sysdim}];              Hrecom = Table[-I*ℏ*Γ*δ[i, j], {i, 1,          sysdim}, {j, 1, sysdim}];              Htrap = Table[-I*ℏ*κ*δ[i, 3]*δ[j, 3], {i,          1, sysdim}, {j, 1, sysdim}];              Hdiss = Hrecom + Htrap;              RHS = -I/ℏ (Hsys.ro[t] - ro[t].Hsys) + -I/ℏ (Hdiss.ro[t] +            ro[t].Hdiss) + L ;              hcp = 6.62606957*10^-34*3*10^10*10^-12; Subscript[ϵ, 1] =          280*hcp; Subscript[ϵ, 2] =          420*hcp; Subscript[ϵ, 3] = 0; Subscript[ϵ, 4] =          175*hcp; Subscript[ϵ, 5] =          320*hcp; Subscript[ϵ, 6] =          360*hcp; Subscript[ϵ, 7] = 260*hcp;              Subscript[V, 1, 2] = -106*hcp; Subscript[V, 1, 3] =           8*hcp; Subscript[V, 1, 4] = -5*hcp; Subscript[V, 1, 5] =           6*hcp; Subscript[V, 1, 6] = -8*hcp; Subscript[V, 1, 7] = -4*          hcp;  Subscript[V, 2, 3] = 28*hcp; Subscript[V, 2, 4] =           6*hcp; Subscript[V, 2, 5] = 2*hcp; Subscript[V, 2, 6] =           13*hcp; Subscript[V, 2, 7] =           1*hcp; Subscript[V, 3, 4] = -62*hcp; Subscript[V, 3, 5] = -1*          hcp; Subscript[V, 3, 6] = -9*hcp; Subscript[V, 3, 7] =           17*hcp; Subscript[V, 4, 5] = -70*hcp; Subscript[V, 4, 6] = -19*          hcp; Subscript[V, 4, 7] = -57*hcp; Subscript[V, 5, 6] =          40*hcp; Subscript[V, 5, 7] = -2*hcp; Subscript[V, 6, 7] = 32*hcp;                   κ = 1;         Γ = 10^-3;         ℏ = (6.62606957*10^-34)/(2*Pi);         initial = Table[δ[i, 6]*δ[j, 6] + δ[i, 1]*δ[j,            1], {i, 1, sysdim}, {j, 1, sysdim}];              RHS2 = RHS;              num = 20;         upper\[TripleDot]limit = 10;         sol = ParallelTable[NDSolve[{ro'[t] == RHS, ro[0] == initial}, Flatten[ro[t]],          {t, 0,upper\[TripleDot]limit}, MaxSteps -> 10^5], {γ, 1, num, 1}];//AbsoluteTiming              dens = Flatten[Table[ro[t] /. sol[[i, All, All]], {i, 1, num}],1];


title: Bar legend does not display values

text: My `BarLegend` shows only zeros instead of right values and I cannot find the reason. I set following minimum and maximum:               MinC=-1.66423*10^-13;      MaxC=9.39154*10^-13;     legend = BarLegend[{"TemperatureMap", {MinC, MaxC}}, LegendLayout -> "Column"]


title: How to pad Background size in Style calls

text: When highlighting text using `Style` and `Background`, as in `Style["Test ", White, Background -> Lighter@Blue]` is there a way to pad (ie, enlarge) the bounding box? The bottom of the background seems coincident with the base of the text: ![here](http://i.stack.imgur.com/SLimA.jpg)


title: How Can I superpose an image and a graphics?

text: I want to superpose an image with a graphics in order to evaluate their alignment. I am writting this exemple of code.               s1 = Graphics[{RGBColor[{1,0,0}],Circle[{0, 1}]}];     model = ContourPlot[x^2 + y^2 - 1 == 0, {x, -2, 2}, {y, -2, 2}]     imref = Rasterize[s1, ImageSize -> {200, 150}](*suppose that is given by camera*)     Show[imref,model];      (*second method*)     immodel=Rasterize[model, ImageSize -> {200, 150}];     ImageCompose[imref,immodel]      I have an other idea, I can binarize the two images and Multiply them or do ImageDifference to get the result alignement but I need also to show graphically the results! Is there any idea to add the opacity or transparency parameters in order to see both images superposed images? thanks


title: Changing default ImageSize in the frontend?

text: I would like graphs to appear somewhat larger in my notebooks (running v8.0.4 on OSX 10.8.2). Naturally I can specify `ImageSize` in each individual plot, or drag each plot to the size I want. But how can I just make it happen all the time? This legacy documentation indicates `ImageSize` typically defaults to 288px but shows no way to change that default. Checking the frontend preferences also comes up empty. How can I get bigger plots by default?


title: Refreshing the Palettes menu

text: How can the contents of the Palettes menu be refreshed (preferably programmatically) without restarting the Front End? When droppping a new palette notebook into `$UserBaseDirectory/SystemFiles/FrontEnd/Palettes`, it will appear in the Palettes menu after restarting the Front End. How can I make it appear there without restarting the front end? When using the `Palettes -> Install Palette...` feature, this refresh happens automatically, so I assume it must be possible. The source of the installation dialog notebook is available in `$InstallationDirectory/SystemFiles/FrontEnd/SystemResources`, but I did not manage to figure out how it works yet.


title: How do I plot the derivative of a set of experimental points?

text: I have a set of points like this: P = {{$x_1$,$y_1$},{$x_2$,$y_2$},...,{$x_n$,$y_n$}}. I want to plot them and also plot the derivative of that graph. How can I do this with Mathematica? Is there a simple way in Mathematica?


title: Writing data to a common file during parallel processing

text: I am executing a loop, and in each loop I have to store a parameter in a file. It is like               file = FileNameJoin[{NotebookDirectory[], "info.txt"}];     OpenWrite[file];     Do[out = Prime[i]; WriteString[file, i, "\t", out, "\n"], {i, 1, 10}]     Close[file]      It stores the values perfectly. But when I use Parallelize[], it produce only partial output.               file = FileNameJoin[{NotebookDirectory[], "infop.txt"}];     OpenWrite[file];     Do[out = Prime[i]; WriteString[file, i, "\t", out, "\n"], {i, 1, 10}]     Close[file]      It produces only 4-5 sets out of 10 (They are in random ordering, but that is not a problem). Although when I use Print[], it shows all the sets.               Parallelize[Do[out = Prime[i]; Print[i , "\t", out], {i, 1, 10}]]      The loop I am using for work is pretty big and I may have to check the info.txt file several times to know the status while the code is running. Is there any way to write the data (as the code is running) in a common file while using parallel processing.


title: Looking for ideas for handling a complicated fitting problem

text: I have the following data:               test={{{15.8257, -0.0769379}, {16.1561, -0.0974535}, {16.4865,      -0.0896821}, {16.5195, -0.065402}, {16.6847, -0.0581635}, {16.8499,      -0.0702727}, {17.0151, -0.0836196}, {17.1803, -0.0888208}, {17.3455,      -0.0929545}, {17.5107, -0.105148}, {17.6759, -0.103528}, {17.8411,      -0.0836455}, {18.0063, -0.0715808}, {18.1715, -0.0650529}, {18.3366,      -0.0582498}, {18.5018, -0.0588228}, {18.667, -0.0599082}, {18.8322,      -0.0605835}, {18.9974, -0.0664554}, {19.1626, -0.0695087}, {19.3278,      -0.0696179}, {19.493, -0.0734236}, {19.6582, -0.0709082}, {19.8234,      -0.0622981}, {19.9886, -0.0673829}, {20.1538, -0.0802961}, {20.319,      -0.0798284}, {20.4842, -0.0687257}, {20.6494, -0.0717655}, {20.8146,      -0.0806611}, {20.9798, -0.085287}, {21.145, -0.0922109}, {21.3102,      -0.0944269}, {21.4754, -0.0878644}, {21.6405, -0.0880898}, {21.8057,      -0.0899869}, {21.9709, -0.078788}, {22.1361, -0.0591576}, {22.3013,      -0.044466}, {22.4665, -0.0600192}, {22.6317, -0.0748474}, {22.7969,      -0.0704493}, {22.9621, -0.0572922}, {23.1273, -0.0562575}, {23.2925,      -0.0623347}, {23.4577, -0.0634224}, {23.6229, -0.068166}, {23.7881,      -0.0829702}, {23.9533, -0.0888241}, {24.1185, -0.0735696}, {24.2837,      -0.0593534}, {24.4489, -0.0637424}, {24.6141, -0.0650974}, {24.7793,      -0.0519863}, {24.9444, -0.0404489}, {25.1096, -0.0633278}, {25.2748,      -0.0747063}, {25.44, -0.0698835}, {25.6052, -0.0770221}, {25.7704,      -0.0828237}, {25.9356, -0.0727494}, {26.1008, -0.0432394}, {26.266,      -0.0423326}, {26.4312, -0.06231}, {26.5964, -0.0736631}, {26.7616,     -0.0655702}, {26.9268, -0.0632276}, {27.092, -0.0749202}, {27.2572,      -0.0780181}, {27.4224, -0.0727166}, {27.5876, -0.0615335}, {27.7528,      -0.056091}, {27.918, -0.063779}, {28.0832, -0.0615237}, {28.2483,      -0.0506654}, {28.4135, -0.0563894}, {28.5787, -0.0836379}, {28.7439,      -0.0994342}, {28.9091, -0.0896401}, {29.0743, -0.0615194}, {29.2395,      -0.0517822}, {29.4047, -0.062227}, {29.5699, -0.0769844}, {29.7351,      -0.0813083}, {29.9003, -0.0899082}, {30.0655, -0.0893884}, {30.2307,      -0.0725808}, {30.3959, -0.050268}, {30.5611, -0.0426449}, {30.7263,      -0.0480701}, {30.8915, -0.0559944}, {31.0567, -0.0608699}, {31.2219,      -0.06694}, {31.3871, -0.0797316}, {31.5522, -0.0904721}, {31.7174,      -0.0867335}, {31.8826, -0.0808754}, {32.0478, -0.0764141}, {32.213,      -0.0672197}, {32.3782, -0.0500709}, {32.5434, -0.0431931}, {32.7086,      -0.0477298}, {32.8738, -0.0606955}, {33.039, -0.072429}, {33.2042,      -0.0820698}, {33.3694, -0.100112}, {33.5346, -0.0911248}, {33.6998,      -0.0722954}, {33.865, -0.0553945}, {34.0302, -0.0577424}, {34.1954,         0.267945}, {34.3606, 0.580552}, {34.5258, 0.665223}, {34.6579,         0.755472}, {34.8231, 0.759053}, {34.9883, 0.76307}, {35.1535,         0.776505}, {35.3187,         0.779363}, {35.4839, -1.12199}, {35.6491, -2.55552}, {35.8143,      -2.94135}, {35.9795, -3.09798}, {36.1447, -3.19286}, {36.3099,      -3.20814}, {36.4751, -3.20919}, {36.6403, -3.21143}, {36.8054,      -3.22794}, {36.9706, -3.23869}, {37.1358, -3.22691}, {37.301,      -3.22079}, {37.4662, -3.23454}, {37.6314, -3.23401}, {37.7966,      -3.21475}, {37.9618, -3.20351}, {38.127, -3.19776}, {38.2922,      -3.20082}, {38.4574, -3.20999}, {38.6226, -3.20835}, {38.7878,      -3.22132}, {38.953, -3.24514}, {39.1182, -3.23904}, {39.2834,      -3.22584}, {39.4486, -3.22737}, {39.6138, -3.21398}, {39.779,      -3.19581}, {39.9442, -3.18892}, {40.1093, -3.18855}, {40.2745,      -3.20021}, {40.4397, -3.21298}, {40.6049, -3.21224}, {40.7701,      -3.20945}, {40.9353, -3.21391}, {41.1005, -3.20505}, {41.2657,      -3.195}, {41.4309, -3.19082}, {41.5961, -3.19234}, {41.7613,      -3.19255}, {41.9265, -3.18381}, {42.0917, -3.20026}, {42.2569,      -3.2267}, {42.4221, -3.24796}, {42.5873, -3.24242}, {42.7525,      -3.23463}, {42.9177, -3.229}, {43.0829, -3.21687}, {43.2481,      -3.19914}, {43.4132, -3.17638}, {43.5784, -3.17475}, {43.7436,      -3.1944}, {43.9088, -3.22259}, {44.074, -3.23448}, {44.2392,      -3.23701}, {44.4044, -3.25577}, {44.5696, -3.25209}, {44.7348,      -3.2347}, {44.9, -3.20355}, {45.0652, -3.18403}, {45.2304, -3.1984},      {45.3956, -3.2077}, {45.5608, -3.20139}, {45.726, -3.18804},      {45.8912, -3.19259}, {46.0564, -3.22305}, {46.2216, -3.23381},      {46.3868, -3.21896}, {46.552, -3.19782}, {46.7171, -3.19925},      {46.8823, -3.21254}, {47.0475, -3.20822}, {47.2127, -3.20076},      {47.3779, -3.21503}, {47.5431, -3.23415}, {47.7083, -3.23585},      {47.8735, -3.21257}, {48.0387, -3.19277}, {48.2039, -3.21066},      {48.3691, -3.23566}, {48.5343, -3.23804}, {48.6995, -3.22519},      {48.8647, -3.22}, {49.0299, -3.22857}, {49.1951, -3.22214}, {49.3603,      -3.18748}, {49.5255, -3.17048}, {49.6907, -3.18617}, {49.8559,      -3.20105}, {50.021, -3.19556}, {50.1862, -3.19728}, {50.3514,      -3.22789}, {50.5166, -3.25828}, {50.6818, -3.252}, {50.847,      -3.22992}, {51.0122, -3.23513}, {51.1774, -3.23703}, {51.3426,      -3.19712}, {51.5078, -3.1469}, {51.673, -3.15768}, {51.8382,      -3.19598}, {52.0034, -3.22341}, {52.1686, -3.22205}, {52.3338,      -3.21716}, {52.499, -3.24412}, {52.6642, -3.25222}, {52.8294,      -3.22671}, {52.9946, -3.2061}, {53.1598, -3.21205}, {53.3249,      -3.20663}, {53.4901, -3.1892}, {53.6553, -3.18521}, {53.8205,      -3.21223}, {53.9857, -3.22453}, {54.1509, -3.21086}, {54.3161,      -3.20821}, {54.4813, -1.83753}, {54.6465, -0.497467}, {54.8117,      -0.172629}, {54.9769, -0.118185}, {55.1421, -0.0401817}, {55.3073,      -0.0390328}, {55.4725, -0.0519028}, {55.6377, -0.0341139}, {55.8029,      -0.0159919}, {55.9681, -0.0322755}, {56.1333, -0.0560436}, {56.2985,      -0.055005}, {56.4637, -0.0382538}, {56.6288, -0.0461829}, {56.794,      -0.0519669}, {56.9592, -0.0478512}, {57.1244, -0.0485063}, {57.2896,      -0.0450605}, {57.4548, -0.0328684}, {57.62, -0.0012728}, {57.7852,         0.000699344}, {57.9504, -0.0282098}, {58.1156, -0.0528248},      {58.2808, -0.0660222}, {58.446, -0.0670143}, {58.6112, -0.0803909},      {58.7764, -0.0722626}, {58.9416, -0.056143}, {59.1068, -0.052108},      {59.272, -0.041373}, {59.4372, -0.0346966}, {59.6024, -0.0253502},      {59.7676, -0.0264026}, {59.9327, -0.0481955}, {60.0979, -0.0662766},      {60.2631, -0.068389}, {60.4283, -0.0613654}, {60.5935, -0.0516283},      {60.7587, -0.0460859}, {60.9239, -0.026215}, {61.0891, -0.0075962},      {61.2543, -0.0158598}, {61.4195, -0.0383789}, {61.5847, -0.052961},      {61.7499, -0.0406836}, {61.9151, -0.0423972}, {62.0803, -0.0769325},      {62.2455, -0.0948179}, {62.4107, -0.0665865}, {62.5759, -0.0433503},      {62.7411, -0.0465402}, {62.9063, -0.064464}, {63.0715, -0.0543498},      {63.2366, -0.0287138}, {63.4018, -0.0410531}, {63.567, -0.0596464},      {63.7322, -0.0323676}, {63.8974, -0.00447797}, {64.0626, -0.0176177},      {64.2278, -0.0278519}, {64.393, -0.0175132}, {64.5582, -0.0343388},      {64.7234, -0.0728937}, {64.8886, -0.0859438}, {65.0538, -0.0851371},      {65.219, -0.0734951}, {65.3842, -0.0496842}, {65.5494, -0.00584685},      {65.7146,         0.0095625}, {65.8798, -0.00930119}, {66.045, -0.0250789},      {66.2102, -0.0359847}, {66.3754, -0.0667467}, {66.5405, -0.09646},      {66.7057, -0.0840331}, {66.8709, -0.0524984}, {67.0361, -0.0383522},      {67.2013, -0.0540666}, {67.3665, -0.0645649}, {67.5317, -0.0412653},      {67.6969, -0.0161336}, {67.8621, -0.037667}, {68.0273, -0.0628333},      {68.1925, -0.0356986}, {68.3577, -0.0229571}, {68.5229, -0.0403972},      {68.6881, -0.0403037}, {68.8533, -0.0353493}, {69.0185, -0.0300052},      {69.1837, -0.0497527}, {69.3489, -0.0725242}, {69.5141, -0.0655332},      {69.6793, -0.0600311}, {69.8444, -0.0536261}, {70.0096, -0.051527},      {70.1748, -0.045936}, {70.34, -0.0338074}, {70.5052, -0.0315814},      {70.6704, -0.0265081}, {70.8356, -0.0228345}, {71.0008, -0.0348291},      {71.166, -0.0534865}, {71.3312, -0.0559775}, {71.4964, -0.0523304},      {71.6616, -0.0514005}, {71.8268, -0.0403854}, {71.992, -0.0236734},      {72.1572, -0.0114473}, {72.3224, -0.0182658}, {72.4876, -0.0314441},      {72.6528, -0.0284464}, {72.818, -0.0324639}, {72.9832, -0.0492846},      {73.1483, -0.0854126}, {73.3135, -0.0898038}, {73.4787, -0.0559581},      {73.6439, -0.0413622}, {73.8091, -0.051359}, {73.9743, -0.058296},      {74.1395, -0.0417273}, {74.3047, -0.0255182}, {74.4699, -0.0485516},      {74.6351, -0.0663423}, {74.8003, -0.0699121}, {74.9655, -0.0530811},      {75.1307, -0.0473759}, {75.2959, -0.0496924}, {75.4611, -0.0424499},      {75.6263, -0.0241374}, {75.7915, -0.0436916}, {75.9567, -0.089127},      {76.1219, -0.0761635}, {76.2871, -0.0538311}, {76.4522, -0.0522625},      {76.6174, -0.0747319}, {76.7826, -0.0739987}, {76.9478, -0.0333077},      {77.113, -0.00486031}, {77.2782, -0.0153005}, {77.4434, -0.0266643},      {77.6086, -0.0274922}, {77.7738, -0.0620418}, {77.939, -0.0877488},      {78.1042, -0.0803497}, {78.2694, -0.0537084}, {78.4346, -0.0425878},      {78.5998, -0.0402573}, {78.765, -0.0197596}, {78.9302, -0.0105323},      {79.0954, -0.0277539}, {79.2606, -0.0459642}, {79.4258, -0.0416842},      {79.591, -0.0456379}, {79.7561, -0.0775024}, {79.9213, -0.0816734},      {80.0865, -0.0372224}, {80.2517, -0.0110671}, {80.4169, -0.0447514},      {80.5821, -0.073486}, {80.7473, -0.0684747}, {80.9125, -0.0510865},      {81.0777, -0.0564664}, {81.2429, -0.05117}, {81.4081, -0.0249809},      {81.5733, -0.00204501}, {81.7385, -0.0035259}, {81.9037,      -0.00623434}, {82.0689, -0.0128054}}}      When I plot these data with _Mathematica_ , I get the following figure: > ![Overview](http://i.stack.imgur.com/9voBl.jpg) By the way, this is a physical, non-local, spin valve signal at a given temperature. What I need is a method to find the two switching fields (actually 4 if negative values are also considered). At present, I doing the following: By hand, I make two linear fits, one for the area where the signal is constant at about $-3$ mOhm, one for the area where the signal is decreasing from $0$ mOhm to $-3$ mOhm. For all temperatures, the first area is nearly the same. In the second area, where is this strong decrease of the signal, I have to fit the line by hand. For this example it would be: > >     {{35.3187, 0.779363}, {35.4839, -1.12199}, {35.6491, -2.55552}, >      {35.8143, -2.94135}, {35.9795, -3.09798}} >   From these two lines, I get the intersection point which is what I am interessted in. This method takes me about 10 min for each intersection point because I have to do it by hand, which is OK for one data set. For the 240 data sets that I have this would take a relativly long time, so I'm looking for a way to automate it. The final result looks like this : > ![final result](http://i.stack.imgur.com/fJ9rw.jpg) What I find especially difficult is getting _Mathematica_ to find the correct values for the second line, because I usually have just 3 or 4 measured points for such lines. I hope someone will respond with some nice ideas how this can be done automatically.


title: Transition between graphs

text: I want to visually demonstrate the manipulations made to a graph. For instance, I have a graph `g` where using the command `LayeredGraphPlot[g, Bottom, VertexLabeling -> True]` I get this figure as the output: ![g1](http://i.stack.imgur.com/TDjyd.png) After adding an edge and using the same command I get this one: ![g2](http://i.stack.imgur.com/hmqdH.png) I want to show a smooth transition between the two figures so that the user can track the addition of the edge. Is there any easy/general way to do such an effect in Mathematica.


title: Remote access to notebook is very slow

text: I am using _Mathematica_ at work remotely from a computer in my building and I can edit notebooks by opening them from terminal via ssh without problem (a little slow if there is a figure with many points, but that's all). Now I need to work from home, but editing a notebook that I open from terminal is just impossible because it is too slow and freezes each time I click on it. I am still using ssh on Ubuntu 12.04. Any idea how I can make it faster?


title: Custom TransformationFunction in Graphics? GeometricTransformation::nonaffine error

text: There are many functions in Mathematica, which return expressions with `TransformationFunction` head, for example RotationTransform. Unfortunately, there is no PerspectiveTransform amongst them. How to create custom transformation functions in general? There is no explanation in docs. It is only said that "TransformationFunction works like Function." what does it mean? That writing `TransformationFunction` is just writing a `Function`? Also it is said that when possible "matrix forms for transformations can be obtained from TransformationFunction objects using TransformationMatrix." Can I have some samples of custom TransformationFunction with and without matrix? **UPDATE** If I provide my transformation (homogenous) matrix it produces "nonaffine" error: ![enter image description here](http://i.stack.imgur.com/TJho5.jpg) ![enter image description here](http://i.stack.imgur.com/ffbB0.jpg) ![enter image description here](http://i.stack.imgur.com/w0X0h.jpg) **UPDATE 2** Now trying to form transformation via `LinearFractionalTransform` and effect ios the same ![enter image description here](http://i.stack.imgur.com/R94mK.jpg)


title: Function[] argument nesting for operations like Select[]

text: The following code selects a special element from a list               thelist = {"this", "notthis"};          Select[thelist, (# == "this") &]      What I want is a function which does just that and which takes lists (like _thelist_ ) and a string (like _"this"_ ) as argument. However I have a problem, because _Select_ already uses an abstract function and so the naive idea               sel:=Select[#1, (# == #2) &]          sel[thelist,"this"]      doesn't work. This is really about the Function command and the problem might not just appear with _Select_ but any abstract function nesting. How to construct the object I need?


title: ListDensityPlot: How to only retain regions with data without using interpolation?

text: I'm working with `ListDensityPlot` on a set of triples, $\\{\\{x_1, y_1, z_1\\}, \dots\\}$. The data is on a semi-regular grid and looks just as it should through most of the plot. However, at the boundary of the dataset, the function continues on with the bordering hue. ![Mathematica graphics](http://i.stack.imgur.com/1sMXt.png) Is there a simple way to fix this? I think it should work to append 'above' the data set a 'dummy' region with zero's or the like, but I feel that there must be something more elegant. Anyone have any thoughts? The top of the function is not neatly described by an analytic function, or this would be rather simple.


title: Decomposing a diagonal positive real matrix

text: I would like to 'decompose' a _diagonal positive real_ matrix $E$ of rank $D$ onto $\sum_{i=1}^{D}c(i)N^i$: $$E = \left( \begin{array}{ccc} 0 & & & \\\ & a & & \\\ & & b & \\\ & & & \ldots \\\ \end{array} \right) \Rightarrow \sum_{i=1}^{D}c(i)N^i$$ where $$ N = \left( \begin{array}{ccc} 0 & & & \\\ & 1 & & \\\ & & 2 & \\\ & & & \ldots \\\ \end{array} \right) $$ and $\bigl\\{c(0), c(1), c(2), \ldots \bigr\\}$ is the coeffients we want to find given $E$. Just a note about $E$: it is well behaved and $0<a<b<\ldots$. We can also assume $E$ is such that $c(i) < c(i+1)$. First I just re-express the problem as a set of linear equations, where $E[i]$ is the $i$th eigenvalue of the rank $D$ matrix and $D_{max}$ is the truncation of the expansion (I assume I have truncate because of numerical difficulty in solving the equations). $D$ should be of $\mathcal{O}(10^3)$: $$ E[p] = \sum_{i=1}^{D_\max}c(i)p^i : p\in(1,\ldots,D)$$ This sounds more complicated than the rather simple problem I think it should be. Now in terms of _Mathematica_ my toy attempt is as follows:                d = 10;       Dmax = 5;       (* Generate matrix E *)      evals = Table[1.25* x - 1.21*10^-5 x^2 + 10^-6 x^3 + 0*10^-8 x^7, {x, 1, d}]      (* Decompose *)      eqns = Table[ evals[[p]] == Sum[c[i] p^i, {i, 1, Dmax}], {p, 1, d}];      solns = NSolve[eqns, Table[c[i], {i, 0, Dmax}], Reals]  ;      Chop@solns       So as long as this is soluble, this works and gives:                (* {{c[1] -> 1.25, c[2] -> -0.0000121, c[3] -> 1.*10^-6, c[4] -> 0, c[5] -> 0}} *)      That is as long as 0 multiples $10^{-8} x^7$. Otherwise this is not a problem to solve but to minimize (which is the case of interest). (The `NSolve` here is just to demonstrate the idea). Using `NMinimize` with the constrains: $c[1] > c[2] > c[3] > c[4] > c[5]$:                eqns = Table[Abs[evals[[p]] - Sum[c[i] p^i, {i, 1, Dmax}] ],          {p, 1, d}];      solns = NMinimize[{Total[eqns],  Greater @@ Table[c[i], {i, 1, Dmax}]}, Table[c[i], {i, 1, Dmax}]]        Which gives the bad result:                (* {995.29, {c[1] -> 0.91, c[2] -> 0.468, c[3] -> 0.247, c[4] -> 0.245, c[5] -> -0.030}} *)      This is quite far from the result above, and it is much worse if the $10^{-8}x^7$ term is included. Does anyone have any ideas on how to do this more correctly or efficiently?


title: Is there a difference between Divide[a,b] and a/b?

text: In this comment it was asserted that `Divide[a,b]` and `a/b` are different, though the documentation indicates that they are the same. In particular, it was asserted that `a/b` is evaluated as `a * 1/b`, whereas `Divide[a,b]` performs the division directly. It was further asserted that this could result in an observable difference in behavior for machine-precision numbers. The question is: is there a difference? If so, what is it exactly? How does it manifest itself? Is there an example where `Divide` gives a different result than `/`? I tried a few edge cases with `$MaxMachineNumber` and `$MinMachineNumber`, but didn't find any differences in behavior between the two.


title: Polynomial GCD over a ring (with composite characteristic)

text: I'd like to implement the "Franklin-Reiter Related Message Attack" (see section 4.3 of Boneh's paper). As part of the implementation, I require to compute the GCD of two polynomials over $\mathbb{Z}_N[x]$, where $N$ is a composite integer (whose factorization is unknown). However, Mathematica's built-in `PolynomialGCD` allows the GCD to be taken over $\mathbb{Z}_p[x]$, where $p$ is a prime. > How can I compute polynomial GCDs over a ring (with composite > characteristic)? I think this question has similarities with one of my earlier questions (regarding the computation of the inverse of a polynomial in a polynomial ring). Unfortunately, I don't have enough math background to solve this question using the answers in the previous one. **Edit:** Example, as per @DanielLichtblau's request: Let $N = 91$ ($=7\times 13$), and consider the following polynomials:               f[x_] := PolynomialMod[(x + 1) (30 x + 40), 91]     g[x_] := PolynomialMod[(x + 1) (50 x + 60), 91]      Since $(x+1)$ divides both polynomials, I expect it to divide their GCD as well. Simply executing:               PolynomialGCD[f[x], g[x]]      will return 1, as it does not compute the GCD over the ring $\mathbb{Z}_{91}[x]$. Furthermore, running:               PolynomialGCD[f[x], g[x], Modulus -> 91]      returns error `PolynomialGCD::modp: Value of option Modulus -> 91 should be a prime number or zero`, as the ring's characteristic ($ = 91$) is a composite number, not a prime. So, the question is, how can I actually compute the GCD of `f[x]` and `g[x]` over $\mathbb{Z}_{91}[x]$ using Mathematica? * * * **Edit2:** As pointed out above, the factorization of $N$ is unknown. Therefore, the algorithm cannot use the factors of $N$. (However, we know that $N$ is an RSA modulus, meaning that it is of the form $p\times q$, where $p$ and $q$ are primes.) A general strategy is to use the extended Euclidean algorithm. Example:               r0 = g[x]     (* = 60 + 19 x + 50 x^2 *)     r1 = f[x]     (* = 40 + 70 x + 30 x^2 *)      We now find the inverse of the leading coefficient of `r1` over $\mathbb{Z}_N$:               PowerMod[30, -1, 91]      which is 88. Using extended Euclidean algorithm:               r2 = PolynomialMod[r0 - 50*88*r1, 91]     (* = 54 + 54 x *)      Next, the inverse of the leading coefficient of `r2` over $\mathbb{Z}_N$ is obtained:               PowerMod[54, -1, 91]      which is 59. Using extended Euclidean algorithm:               r3 = PolynomialMod[r1 - 30*59x*r2, 91]     (* = 40 + 40 x *)      The inverse of the leading coefficient of `r3` over $\mathbb{Z}_N$ is 66:               PowerMod[40, -1, 91]      Using extended Euclidean algorithm:               r4 = PolynomialMod[r2 - 54*66*r3, 91]     (* = 0 *)      Therefore, the GCD of `f[x]` and `g[x]` equals `r3 = 40 + 40 x = 40 (1+x)`. Notice that if `h[x]` is the GCD of `f[x]` and `g[x]` over $\mathbb{Z}_N$, and if $a \not\mid N$, then `a*h[x]` is also a GCD of `f[x]` and `g[x]` over $\mathbb{Z}_N$. (That is, the GCD is not uniquely defined.) Consequently, `1+x` is a valid GCD as well. * * * **Note:** If in any step above, the leading coefficient was not coprime to $N$, its inverse would not exist. In such cases, it seems reasonable to say that the GCD does not exist over the ring.


title: Efficient submatrix swaps for large sparse matrix

text: I am implementing the 'swap' algorithm for a binary matrix to generate matrix permutations that maintain row and column totals. My problem is that my matrices are large and sparse (e.g., 19774 x 942, 0.14% fill). The standard algorithm is this: Pick two rows and two columns at random, and examine the 2x2 sub matrix they define. If it is either {{1,0},{0,1}} or {{0,1},{1,0}}, then flip the entries. Otherwise do nothing and try another combination of rows and columns. Here is my version, which is not at all optimized:                swap[matrix_] :=       Module[{r, c, subMatrix, rowsChoice, colsChoice, outout},       {r, c} = Dimensions[matrix];       subMatrix = {0, 0, 0, 0};       While[(subMatrix =!= {1, 0, 0, 1}) && (subMatrix =!= {0, 1, 1, 0}),        rowsChoice = RandomInteger[{1, r}, 2];        colsChoice = RandomInteger[{1, c}, 2];        subMatrix =          Extract[matrix,           i = Flatten[Outer[List, rowsChoice, colChoice], 1]];               ];       output =         ReplacePart[matrix,          MapThread[#1 -> #2 &, {i,            If[subMatrix == {1, 0, 0, 1}, {0, 1, 1, 0}, {1, 0, 0, 1}]}]]       ]      Optimizations aside, obviously, for a large sparse matrix, the overwhelming majority of the random submatrices do not satisfy the swap criterion (most are {{0,0},{0,0}}), and so the process is quite slow. So, I'm trying to come up with an efficient algorithm that does not just shoot in the dark. Some simple possibilities are to constrain the row/column choice, for example by making sure that there are at least SOME ones in the submatrix. Another idea I'm working on is to first make a list of all the submatrices that satisfy the 'swappable' condition. Then one simply chooses one of these. Making the first list is fairly easy, and not too slow given that the matrix is sparse               allSubMatrices[matrix_] :=       Module[{ones, fill, oneCorner, otherOneCorners, oneCorners,         otherCorners, cornerFill},       ones = Position[matrix, 1];       fill = Length[ones];       Cases[Flatten[Table[          oneCorner = ones[[i]];          otherOneCorners =            Select[Drop[ones,              i], #[[1]] =!= oneCorner[[1]] && #[[2]] =!=                oneCorner[[2]] &];          Table[           oneCorners = {oneCorner, otherOneCorners[[j]]};           otherCorners = {{oneCorners[[1, 1]],               oneCorners[[2, 2]]}, {oneCorners[[2, 1]],               oneCorners[[1, 2]]}};           cornerFill = Extract[matrix, otherCorners];           If[cornerFill == {0, 0}, {{oneCorners[[1, 1]],               oneCorners[[2, 1]]}, {oneCorners[[1, 2]],               oneCorners[[2, 2]]}}, {}], {j, 1,             Length[otherOneCorners]}], {i, 1, 1}], 1], {{_, _}, {_, _}}]       ]      The output is a list pairs of rows and columns that define 'swappable' submatrices. The harder trick is, after doing a swap, to modify this list to reflect the new set of submatrices. A swap changes four matrix entries, and removes all valid submatrices that depended on these entries. Those are relatively easy to find in the existing list. But a swap potentially adds a number of newly valid submatrices, which need to found as well, and I haven't yet figured out how to find those quickly. Before I go further down this rabbit hole, I'm wondering if the stackexchange geniuses have any suggestions about the best way to speed up the swap algorithm. Should I stick with the basic algorithm and just work on optimizing/compile it? Is there a known (or obvious) more efficient algorithm for the sparse case that I'm missing? Thanks, Gareth


title: 3D Plotting with PieceWise function

text: Im trying to plot the following function: $f(x,y)$ = $\left\\{\begin{matrix} (x+y) & (x,y) \in T \\\ (x+y)^2 & (x,y) \notin T \end{matrix}\right.$ where $T= \\{ y\leq -x+1, x\geq 0, y\geq 0 \\}$ Im trying without success something like:               Plot3D[Piecewise[{{x + y, {y <= -x + 1, x>=0, y>=0}}, {(x + y)^2, y > -x + 1}},        0], {x, -4, 4}, {y, -4, 4}, Boxed -> False, AxesOrigin -> {0, 0, 0}]      I dont know if the PieceWise function supports multiple conditions like ${y <= -x + 1, x>=0, y>=0}$ for some piece.


title: How to optimize my code?

text: **_I use Mathematica to handle data.My trial as below:_** **_Interpolation function：_**               coordinateList[coordinateB_, coordinateF_, n_Integer] := Block[      {coordinateListResult, \[CapitalDelta]},(*B-Begin,F-Final*)       \[CapitalDelta] = (coordinateF - coordinateB)/n;       coordinateListResult =       Range[coordinateB, coordinateF, \[CapitalDelta]]      ]      **_Solving the center of a circle:_**               circleHeart[xyB_List, xyF_List, radius_] := Block[       {circleHeartResult},        circleHeartResult =        First@Simplify@        Solve[             {(xP - xyB[[1]])^2 + (yP - xyF[[1]])^2 == radius^2,               (xP - xyB[[2]])^2 + (yP - xyF[[2]])^2 == radius^2},              {xP, yP}]     ]      **_Solving the angle:_**               angleSolve[xyO_List, xyP_List] := Block[      {angleSolveResult},       angleSolveResult =       N@ArcTan @@ (xyP - xyO)     ]      **_Solving Data:_**               CircleJointsVaribles[L1_, L2_, xyB_List, xyF_List, radius_, tb_, tf_, n_Integer]     :=Block[           {LineJointsVariblesResult, xyO, xP, yP, px, py, A, c1, s1,        c2, s2, θ1, θ2, \[CapitalDelta]tList},       xyO = ({xP, yP} /. circleHeart[xyB, xyF, radius]);       A[t_] := InterpolatingPolynomial[                      {{tb, angleSolve[xyO, xyB]},{tf,angleSolve[xyO, xyF]}}, t];       px[t_] := First@xyO + Cos[A[t]];       py[t_] := Last@xyO + Sin[A[t]];       c2[t_] := (-L1^2 - L2^2 + px[t]^2 + py[t]^2)/(2 L1 L2);        s2[t_] := -Sqrt[1 - (c2[t]^2) ];       c1[t_] := -((-L1 px[t] - c2[t] L2 px[t] - s2[t] L2 py[t])/(              px[t]^2 + py[t]^2));        s1[t_] := -((s2[t] L2 px[t] - L1 py[t] - c2[t] L2 py[t])/(              px[t]^2 + py[t]^2));       θ2[t_] := Simplify@ArcTan[c2[t], s2[t]];       θ1[t_] := Simplify@ArcTan[c1[t], s1[t]];       \[CapitalDelta]tList = coordinateList[tb, tf, n];       Column[         ListPlot[#1, ImageSize -> 350, AxesStyle -> Arrowheads[.03], AxesLabel -> #2] &@@@                    MapThread[List, {(MapThread[List, {\[CapitalDelta]tList, #}] & /@          {θ1/@\[CapitalDelta]tList, θ2/@ \[CapitalDelta]tList}),                                   Map[Style[#, 15, Red] &,           {{"t", "θ1(t)"},{"t", "θ2(t)"}},{2}]}],              Center]     ]      **_However,when I use the function,it takes so much time._** > CircleJointsVaribles[35, 20, {10, 30}, {30, 6}, 20, 0, 10, 20] **_So my question is how to optimize it?_** **_Edit：_** > CircleJointsVaribles[35., 20., {10., 30.}, {30., 6.}, 20., 0., 10, 20] It gives the result immediately,However,gives the warning information: > Solve::ratnz: Solve was unable to solve the system with inexact > coefficients. The answer was obtained by solving a corresponding exact > system and numericizing the result. >>


title: How to completely delete the head of a function expression

text: Is there any way to completely remove the head of an expression function? For example, how would I remove the head `Cos` from `Cos[a]` to give only `a` as an output.


title: What was added to the LibraryLink API in version 9?

text: Looking at the LibraryLink examples, there are several new functions and objects, as well as example programs, that appeared in version 9. Are these documented? If yes, where? If would be nice to have a summary of the new features available, and a summary of how and when to use them, so people can more easily decide whether there is something that's useful for their project. Some things I noticed and would like to learn more about:   * `MInputStream` and `MOutputStream` types, `WolframStreamLibrary.h` header   * `DataStore` type   * `WolframIOLibrary_Functions` (comparable to `WolframLibraryData`, contains function pointers)   * all the `async-*.c` examples which use these features It should be possible to figure much of this out using the (uncommented) example programs, but I'm hoping that someone has already done this and can contribute and answer.


title: Complex integrals and residues

text: I have a question. I try to integrate this function:               Integrate[Exp[I k z]*Exp[-Sqrt[k^2 - A^2]x]*Exp[-k^2*L^2/4]/Sqrt[k^2 - A^2],          {k, -Infinity, -A}]      But Mathematica doesn't want to give an answer. It just prints me my integral. The same story I have when I try to calculate the residue of this function at the infinity point, for example. What's wrong? Thanks.


title: Need Help with Output/Code Optimization Conparative Statics with System of Equations and Matrices

text: I have a system of equations (equilibrium conditions) and would like to evaluate how changes of exogenous variables affect the endogenous values. In step 1, I state the equilibrium equations and some assumptions about the properties of the functions. The optimal solution may not be unique and therefore there are assumptions listed to ensure uniqueness (first assumption in first assumptions list and $y<0$). Unfortunately, the output involves complex numbers and the equations are quite long. I would be more than happy to just receive +/-/0 as ouput or any hints how to optimize my code and output. Thank you!               (*** Equilibrium Conditions ***)     (* Endogenous variables: c, L, n, k, m, u, d, q, f, e, Vl, Vc, a, \     δ , (y)*)     (* Exogenous variables: T, P, Π, A, r, ρ, s, \     α, ψ, ϕ, x, *)     ClearAll[c, L, n, k, m, u, d, q, f, e, Vl, Vc, a, δ, T,        P, Π, A, r, ρ, s, α, ψ, ϕ, x, y];     $Assumptions =           D[fm, {m, 2}]/D[fm, m] > (D[w, q]*ϕ)/(w*a) && D[fm, m] > 0 &&            D[fm, {m, 2}] > 0 &&  D[fm, {m, 3}] >= 0  &&  D[gn, n] > 0 &&             D[gn, {n, 2}] > 0          (* Assumptions for Properties of Cost Functions *)          $Assumptions =       r > 0 && A > 0 && P > 0  && ρ > 0 && ψ > 0 &&        s > 0 && α > 0 &&        T > 0 && Π > 0 && ϕ > 0 && σ > 0     (* Assumptions for Exogenous Parameters *)     fm = F[m];     (* Cost Type 1 *)     gn = G[n];     (* Cost Type 2 *)     (* δ = \!\(     \*SubsuperscriptBox[\(∫\), \(-∞\), \(y\)]\(w\     \[DifferentialD]x\)\) *)     (* Probability Function with Density Function w(.) of x *)      $Assumptions = y < 0     (* Optimal Solution is on the lefthand-side of normal distribution - \     i.e., y<0 *)     w = PDF[NormalDistribution[ρ, σ], y]     (* Density Function *)     y = q - (ϕ*m)/a     (* Error Term y - Normally Distributed with mean and variance Sigma^2 \     *)     g1 =    (P*A*Π)/(L*n) - n/(1 + n)*D[G[n], n]     g2 = k -   D[G[n], n]     g3 = L - (T - P)/(1 + n)     g4 = c - n*L     g5 = a - (P*A)/L     g6 = (w/(r + δ)) - (ϕ/a)*(-y/σ^2)     g7 = D[fm, m] +        D[fm, {m, 2}]*((r + δ)/w) - (ρ*s)/(α*         T)*ψ *ϕ/a     g8 = δ - \!\(     \*SubsuperscriptBox[\(∫\), \(-∞\), \(y\)]\(w \     \[DifferentialD]x\)\)     (* Probability Function with Density Function w(.) of x *)     g9 = u - a + ρ*m     g10 = d - n + m + u     g11 = e - δ/(n + δ)     g12 = f - n*k + gn +        fm +  ( D[fm, m]/(ϕ/a*w))*((r + e + δ*(1 - e))/(1 - e))     g13 = Vl - ((1 + r)/r)*((r + e)/(1 - e))*(D[fm, m]/(ϕ/a*w))     g14 = Vc - ((1 + r)^2/r)*(e/(1 - e))*(D[fm, m]/(ϕ/a*w))          (* First Step: Jacobian *)     J = {{D[g1, L], D[g1, c], D[g1, n], D[g1, k], D[g1, m], D[g1, u],          D[g1, d], D[g1, f], D[g1, q], D[g1, a] , D[g1, Vc], D[g1, Vl],          D[g1, e], D[g1, δ]},        {D[g2, L], D[g2, c], D[g2, n], D[g2, k], D[g2, m], D[g2, u],          D[g2, d], D[g2, f], D[g2, q], D[g2, a] , D[g2, Vc], D[g2, Vl],          D[g2, e], D[g2, δ]},        {D[g3, L], D[g3, c], D[g3, n], D[g3, k], D[g3, m], D[g3, u],          D[g3, d], D[g3, f], D[g3, q], D[g3, a] , D[g3, Vc], D[g3, Vl],          D[g3, e], D[g3, δ]},         {D[g4, L], D[g4, c], D[g4, n], D[g4, k], D[g4, m], D[g4, u],          D[g4, d], D[g4, f], D[g4, q], D[g4, a] , D[g4, Vc], D[g4, Vl],          D[g4, e], D[g4, δ]},        {D[g5, L], D[g5, c], D[g5, n], D[g5, k], D[g5, m], D[g5, u],          D[g5, d], D[g5, f], D[g5, q], D[g5, a] , D[g5, Vc], D[g5, Vl],          D[g5, e], D[g5, δ]},         {D[g6, L], D[g6, c], D[g6, n], D[g6, k], D[g6, m], D[g6, u],          D[g6, d], D[g6, f], D[g6, q], D[g6, a] , D[g6, Vc], D[g6, Vl],          D[g6, e], D[g6, δ]},         {D[g7, L], D[g7, c], D[g7, n], D[g7, k], D[g7, m], D[g7, u],          D[g7, d], D[g7, f], D[g7, q], D[g7, a] , D[g7, Vc], D[g7, Vl],          D[g7, e], D[g7, δ]},         {D[g8, L], D[g8, c], D[g8, n], D[g8, k], D[g8, m], D[g8, u],          D[g8, d], D[g8, f], D[g8, q], D[g8, a] , D[g8, Vc], D[g8, Vl],          D[g8, e], D[g8, δ]},        {D[g9, L], D[g9, c], D[g9, n], D[g9, k], D[g9, m], D[g9, u],          D[g9, d], D[g9, f], D[g9, q], D[g9, a] , D[g9, Vc], D[g9, Vl],          D[g9, e], D[g9, δ]},        {D[g10, L], D[g10, c], D[g10, n], D[g10, k], D[g10, m], D[g10, u],          D[g10, d], D[g10, f], D[g10, q], D[g10, a] , D[g10, Vc],          D[g10, Vl], D[g10, e], D[g10, δ]},        {D[g11, L], D[g11, c], D[g11, n], D[g11, k], D[g11, m], D[g11, u],          D[g11, d], D[g11, f], D[g11, q], D[g11, a] , D[g11, Vc],          D[g11, Vl], D[g11, e], D[g11, δ]},        {D[g12, L], D[g12, c], D[g12, n], D[g12, k], D[g12, m], D[g12, u],          D[g12, d], D[g12, f], D[g12, q], D[g12, a] , D[g12, Vc],          D[g12, Vl], D[g12, e], D[g12, δ]},        {D[g13, L], D[g13, c], D[g13, n], D[g13, k], D[g13, m], D[g13, u],          D[g13, d], D[g13, f], D[g13, q], D[g13, a] , D[g13, Vc],          D[g13, Vl], D[g13, e], D[g13, δ]},        {D[g14, L], D[g14, c], D[g14, n], D[g14, k], D[g14, m], D[g14, u],          D[g14, d], D[g14, f], D[g14, q], D[g14, a] , D[g14, Vc],          D[g14, Vl], D[g14, e], D[g14, δ]}};          MatrixForm[J]          (* Second Step: Determinant of Jacobian *)      (* Implicit function theorem requires Det J unequal to zero and all \     equations differentiable. *)     Det[J]      Simplify[%]          (* Third Step: Comparative statics with Cramer's Rule *)     (* dY/dx = det(J_Y)/det(J) *)          (* A) Effectiveness *)     (* A.1) Comparative Static: effectiveness, α, on information, \     m *)     Jma = {{D[g1, L], D[g1, c], D[g1, n], D[g1, k], -D[g1, α],          D[g1, u], D[g1, d], D[g1, f], D[g1, q], D[g1, a] , D[g1, Vc],          D[g1, Vl], D[g1, e], D[g1, δ]},        {D[g2, L], D[g2, c], D[g2, n], D[g2, k], -D[g2, α],          D[g2, u], D[g2, d], D[g2, f], D[g2, q], D[g2, a] , D[g2, Vc],          D[g2, Vl], D[g2, e], D[g2, δ]},        {D[g3, L], D[g3, c], D[g3, n], D[g3, k], -D[g3, α],          D[g3, u], D[g3, d], D[g3, f], D[g3, q], D[g3, a] , D[g3, Vc],          D[g3, Vl], D[g3, e], D[g3, δ]},         {D[g4, L], D[g4, c], D[g4, n], D[g4, k], -D[g4, α],          D[g4, u], D[g4, d], D[g4, f], D[g4, q], D[g4, a] , D[g4, Vc],          D[g4, Vl], D[g4, e], D[g4, δ]},        {D[g5, L], D[g5, c], D[g5, n], D[g5, k], -D[g5, α],          D[g5, u], D[g5, d], D[g5, f], D[g5, q], D[g5, a] , D[g5, Vc],          D[g5, Vl], D[g5, e], D[g5, δ]},         {D[g6, L], D[g6, c], D[g6, n], D[g6, k], -D[g6, α],          D[g6, u], D[g6, d], D[g6, f], D[g6, q], D[g6, a] , D[g6, Vc],          D[g6, Vl], D[g6, e], D[g6, δ]},         {D[g7, L], D[g7, c], D[g7, n], D[g7, k], -D[g7, α],          D[g7, u], D[g7, d], D[g7, f], D[g7, q], D[g7, a] , D[g7, Vc],          D[g7, Vl], D[g7, e], D[g7, δ]},         {D[g8, L], D[g8, c], D[g8, n], D[g8, k], -D[g8, α],          D[g8, u], D[g8, d], D[g8, f], D[g8, q], D[g8, a] , D[g8, Vc],          D[g8, Vl], D[g8, e], D[g8, δ]},        {D[g9, L], D[g9, c], D[g9, n], D[g9, k], -D[g9, α],          D[g9, u], D[g9, d], D[g9, f], D[g9, q], D[g9, a] , D[g9, Vc],          D[g9, Vl], D[g9, e], D[g9, δ]},        {D[g10, L], D[g10, c], D[g10, n], D[g10, k], -D[g10, α],          D[g10, u], D[g10, d], D[g10, f], D[g10, q], D[g10, a] ,          D[g10, Vc], D[g10, Vl], D[g10, e], D[g10, δ]},        {D[g11, L], D[g11, c], D[g11, n], D[g11, k], -D[g11, α],          D[g11, u], D[g11, d], D[g11, f], D[g11, q], D[g11, a] ,          D[g11, Vc], D[g11, Vl], D[g11, e], D[g11, δ]},        {D[g12, L], D[g12, c], D[g12, n], D[g12, k], -D[g12, α],          D[g12, u], D[g12, d], D[g12, f], D[g12, q], D[g12, a] ,          D[g12, Vc], D[g12, Vl], D[g12, e], D[g12, δ]},        {D[g13, L], D[g13, c], D[g13, n], D[g13, k], -D[g13, α],          D[g13, u], D[g13, d], D[g13, f], D[g13, q], D[g13, a] ,          D[g13, Vc], D[g13, Vl], D[g13, e], D[g13, δ]},        {D[g14, L], D[g14, c], D[g14, n], D[g14, k], -D[g14, α],          D[g14, u], D[g14, d], D[g14, f], D[g14, q], D[g14, a] ,          D[g14, Vc], D[g14, Vl], D[g14, e], D[g14, δ]}};          MatrixForm[Jma]     Det[Jma]     Cma = Det[Jma]/Det[J]     Simplify[Cma]     Sign[Cma] // Simplify


title: Extracting lists from list based on length

text: I have a list looking like this;               {{"ADS GY Equity", "", "", "ALV GY Equity", "", "", "BAS GY Equity",      "", "", "BAYN GY Equity", "", "", "BEI GY Equity", "", "",      "BMW GY Equity", ""}, {"Date", "PX_LAST", "", "Date", "PX_LAST", "",     "Date", "PX_LAST", "", "Date", "PX_LAST", "", "Date", "PX_LAST",      "", "Date", "PX_LAST"}, {"addidas", 17.925, "", "alvac", 287.292,      "", "basse", 24.875, "", "bayern", 42.34, "", "begge", 23.667, "",      "BMW", 29.49}, {{2000, 1, 4, 0, 0, 0.}, 17.5,      "", {2000, 1, 4, 0, 0, 0.}, 285.934, "", {2000, 1, 4, 0, 0, 0.},      23.925, "", {2000, 1, 4, 0, 0, 0.}, 41.216,      "", {2000, 1, 4, 0, 0, 0.}, 21.333, "", {2000, 1, 4, 0, 0, 0.},      28.3}, {{2000, 1, 5, 0, 0, 0.}, 17.5, "", {2000, 1, 5, 0, 0, 0.},      294.078, "", {2000, 1, 5, 0, 0, 0.}, 23.375,      "", {2000, 1, 5, 0, 0, 0.}, 40.176, "", {2000, 1, 5, 0, 0, 0.}, 21.,      "", {2000, 1, 5, 0, 0, 0.}, 27.74}, {{2000, 1, 6, 0, 0, 0.}, 18.25,      "", {2000, 1, 6, 0, 0, 0.}, 297.698, "", {2000, 1, 6, 0, 0, 0.},      24.015, "", {2000, 1, 6, 0, 0, 0.}, 41.356,      "", {2000, 1, 6, 0, 0, 0.}, 21.867, "", {2000, 1, 6, 0, 0, 0.},      27.65}, {{2000, 1, 7, 0, 0, 0.}, 18., "", {2000, 1, 7, 0, 0, 0.},      305.977, "", {2000, 1, 7, 0, 0, 0.}, 25.,      "", {2000, 1, 7, 0, 0, 0.}, 43.08, "", {2000, 1, 7, 0, 0, 0.},      22.33, "", {2000, 1, 7, 0, 0, 0.}, 27.6}, {{2000, 1, 10, 0, 0, 0.},      18.272, "", {2000, 1, 10, 0, 0, 0.}, 307.742,      "", {2000, 1, 10, 0, 0, 0.}, 25.11, "", {2000, 1, 10, 0, 0, 0.},      44.644, "", {2000, 1, 10, 0, 0, 0.}, 22.667,      "", {2000, 1, 10, 0, 0, 0.}, 28.7}, {{2000, 1, 11, 0, 0, 0.},      18.103, "", "", "", "", {2000, 1, 11, 0, 0, 0.}, 23.995,      "", {2000, 1, 11, 0, 0, 0.}, 43.323, "", {2000, 1, 11, 0, 0, 0.},      21.883, "", {2000, 1, 11, 0, 0, 0.},      28.6}, {{2000, 1, 12, 0, 0, 0.}, 18., "", "", "",      "", {2000, 1, 12, 0, 0, 0.}, 24., "", {2000, 1, 12, 0, 0, 0.},      41.45, "", {2000, 1, 12, 0, 0, 0.}, 21.717,      "", {2000, 1, 12, 0, 0, 0.}, 28.19}, {{2000, 1, 13, 0, 0, 0.},      17.462, "", "", "", "", {2000, 1, 13, 0, 0, 0.}, 23.75,      "", {2000, 1, 13, 0, 0, 0.}, 41.169, "", {2000, 1, 13, 0, 0, 0.},      22.163, "", {2000, 1, 13, 0, 0, 0.},      27.4}, {{2000, 1, 14, 0, 0, 0.}, 16.837, "", "", "",      "", {2000, 1, 14, 0, 0, 0.}, 23.75, "", {2000, 1, 14, 0, 0, 0.},      42.152, "", {2000, 1, 14, 0, 0, 0.}, 22.583,      "", {2000, 1, 14, 0, 0, 0.}, 27.2}, {{2000, 1, 17, 0, 0, 0.}, 17.,      "", "", "", "", {2000, 1, 17, 0, 0, 0.}, 23.935, "", "", "",      "", {2000, 1, 17, 0, 0, 0.}, 23.33, "", {2000, 1, 17, 0, 0, 0.},      27.28}, {{2000, 1, 18, 0, 0, 0.}, 17., "", "", "",      "", {2000, 1, 18, 0, 0, 0.}, 23.975, "", "", "",      "", {2000, 1, 18, 0, 0, 0.}, 22.667, "", {2000, 1, 18, 0, 0, 0.},      27.}, {{2000, 1, 19, 0, 0, 0.}, 16.65, "", "", "",      "", {2000, 1, 19, 0, 0, 0.}, 24.92, "", "", "",      "", {2000, 1, 19, 0, 0, 0.}, 23.3, "", {2000, 1, 19, 0, 0, 0.},      27.59}}      I want to extract every list which has length 14 or 15. This should leave me with eight lists, because I also want to drop the lists/columns with no values in it. This is how the output should look like after extraction                 {{{"ADS GY Equity", "", "BAS GY Equity", "", "BEI GY Equity", "",       "BMW GY Equity", ""}, {"Date", "PX_LAST", "Date", "PX_LAST",       "Date", "PX_LAST", "Date", "PX_LAST"}, {"addidas", 17.925, "basse",       24.875, "begge", 23.667, "BMW", 29.49}, {{2000, 1, 4, 0, 0, 0.},       17.5, {2000, 1, 4, 0, 0, 0.}, 23.925, {2000, 1, 4, 0, 0, 0.},       21.333, {2000, 1, 4, 0, 0, 0.}, 28.3}, {{2000, 1, 5, 0, 0, 0.},       17.5, {2000, 1, 5, 0, 0, 0.}, 23.375, {2000, 1, 5, 0, 0, 0.},       21., {2000, 1, 5, 0, 0, 0.}, 27.74}, {{2000, 1, 6, 0, 0, 0.},       18.25, {2000, 1, 6, 0, 0, 0.}, 24.015, {2000, 1, 6, 0, 0, 0.},       21.867, {2000, 1, 6, 0, 0, 0.}, 27.65}, {{2000, 1, 7, 0, 0, 0.},        18., {2000, 1, 7, 0, 0, 0.}, 25., {2000, 1, 7, 0, 0, 0.},       22.33, {2000, 1, 7, 0, 0, 0.}, 27.6}, {{2000, 1, 10, 0, 0, 0.},       18.272, {2000, 1, 10, 0, 0, 0.}, 25.11, {2000, 1, 10, 0, 0, 0.},       22.667, {2000, 1, 10, 0, 0, 0.}, 28.7}, {{2000, 1, 11, 0, 0, 0.},       18.103, {2000, 1, 11, 0, 0, 0.}, 23.995, {2000, 1, 11, 0, 0, 0.},       21.883, {2000, 1, 11, 0, 0, 0.}, 28.6}, {{2000, 1, 12, 0, 0, 0.},       18., {2000, 1, 12, 0, 0, 0.}, 24., {2000, 1, 12, 0, 0, 0.},       21.717, {2000, 1, 12, 0, 0, 0.}, 28.19}, {{2000, 1, 13, 0, 0, 0.},       17.462, {2000, 1, 13, 0, 0, 0.}, 23.75, {2000, 1, 13, 0, 0, 0.},       22.163, {2000, 1, 13, 0, 0, 0.}, 27.4}, {{2000, 1, 14, 0, 0, 0.},       16.837, {2000, 1, 14, 0, 0, 0.}, 23.75, {2000, 1, 14, 0, 0, 0.},       22.583, {2000, 1, 14, 0, 0, 0.}, 27.2}, {{2000, 1, 17, 0, 0, 0.},       17., {2000, 1, 17, 0, 0, 0.}, 23.935, {2000, 1, 17, 0, 0, 0.},       23.33, {2000, 1, 17, 0, 0, 0.}, 27.28}, {{2000, 1, 18, 0, 0, 0.},       17., {2000, 1, 18, 0, 0, 0.}, 23.975, {2000, 1, 18, 0, 0, 0.},       22.667, {2000, 1, 18, 0, 0, 0.}, 27.}, {{2000, 1, 19, 0, 0, 0.},       16.65, {2000, 1, 19, 0, 0, 0.}, 24.92, {2000, 1, 19, 0, 0, 0.},       23.3, {2000, 1, 19, 0, 0, 0.}, 27.59}}}      If I where to explain simply what has been done, It only extracted the companies date and closing price where the number of closing prices was equal to the number of longest number of closing prices for any of the companies.


title: how draw root locus in mathematica 9 for a special case

text: my closed loop transfer function is:               H(s)=2exp(-q)/(1+exp(-2q))           q=sqrt((a+k*sqrt(s)+s)*s) ,  s=sigma+jw      how can i draw root locus of H(s) as 'a' changes for different values of k? in other words, how can i solve below equation and plot real(s) versus imaginary(s)?               1+exp(-2q)==0      i need a code for mathematica 9,i have examined some codes, but they didn't work.Tnx All.


title: Checking if two trigonometric expressions are equal

text: Say I have two trigonometric expressions which are a bit complicated. Is there a quick way to check if they reduce to the same thing (that they are equal) using Mathematica? I was solving this: $y'' + y = \cos 4x,$ $y(0) = 6, y'(0) = 11$ using Laplace transformation technique, and I get this: $y = \frac{-1}{15}\cos(4x) + \left(\frac{1}{15} + 6\right) \cos(x) + 11 \sin(x)$.   I wanted to check if my answer is correct and Mathematica gave me this:               1/30 (182 Cos[x] - 5 Cos[x] Cos[3 x] + 3 Cos[x] Cos[5 x]           + 330 Sin[x] + 5 Sin[x] Sin[3 x] + 3 Sin[x] Sin[5 x])


title: Write an expression as a full derivative

text: Is there a command that tells Mathematica to try to write the terms (if possible) of an expression as total derivates? Example: I want to tell mathematica to write               -Sin[t]+g[t]       as               D[Cos[t],t]+g[t]       instead. Is this possible? Mathematically, this is basically (up to some constants) equivalent of Mathematica testing if the terms are analytically integrable (i.e. if they have closed form expressions).


title: Interpolating a plot with missing values

text: With               data = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {7, 5}, {8,         4}, {10, 3}, {10, 2}, {11, 1}}      and               ListLinePlot[data, Filling -> Axis, GridLines -> Automatic,       Joined -> True, Mesh -> Full, PlotMarkers -> Automatic,       InterpolationOrder -> 2]      we get: ![enter image description here](http://i.stack.imgur.com/Oizjk.jpg) In reality, my datasets oftentimes have missing values. Setting f.e.               data[[3]] = {3, Missing[]}      I obtain with `Off[ListLinePlot::ioproc]` this picture, ![enter image description here](http://i.stack.imgur.com/LKvjv.jpg) nicely not-showing the missing point. Unfortunately though, the smoothing vanished. Could you propose a general way (plots may vary in size and may have multiple sets) to interpolate over missing values? Thanks **EDIT** Based on the ideas presented here I have written this little function:               Smoother[v_] := If[smooth != 2, v, Select[#, #[[2]] != "na" &] & /@ v]      Turning `Smoother` on or off (via a button) I now get what I hoped for: ![enter image description here](http://i.stack.imgur.com/YAEHz.jpg) ![enter image description here](http://i.stack.imgur.com/ILTZL.jpg)


title: Accessing methods and properties of C++ objects?

text: Is it possible to access the properties or methods of C++ objects created with LibraryLink or MathLink like with J/Link ? Such capability doesn't seem built- in yet and I'm not sure it ever will as Java has introspection capabilities (the ability to retrieve information about classes' members) that I'm not sure C++ has. But maybe I'm wrong ?


title: Tell Mathematica to factor something specific

text: Is there a way to tell mathematica to factor 1/(1-x^2) from a large expression? For instance if the expression is A_1+A_2+A_3 and I want to factor 1/(1-x^2) from A_1+A_2 but leave A_3 alone.


title: How to make lines in Plot Legends wider?

text: 1.- How to put DASHED lines in the Legend? 2.- How to give Style to {20,Bold} to all "Expressions in Legend? ![enter image description here](http://i.stack.imgur.com/Z1NwP.png) (I use LegendMarkSize for make lines wider than default fine style )               Plot[{{E^(x/(1/4)), E^(x/(1/3)), E^(x/(1/2))}, {E^(x/1), E^(x/2),         E^(x/3), E^(x/4)}}, {x, -5, 0.2},       PlotStyle -> {{Dashing[0.024], Thickness[0.01]}, {Dashing[0.024],          Thickness[0.01]}, {Dashing[0.024], Thickness[0.01]},         Thickness[0.01], Thickness[0.01], Thickness[0.01],         Thickness[0.01]},       PlotLegends ->        SwatchLegend[ "Expressions", LegendMarkerSize -> {39, 6}],       PlotRange -> {{-5, 0.15}, {0, 1.15}}]


title: Plot Legends and Frame Ticks in Array Plots

text: Why do the frame ticks go away when PlotLegends->Automatic is inserted in an Array Plot? For instance, the following code produces an Array Plot with Frame Ticks.               ArrayPlot[Table[Random[], {i, 10}, {j, 10}], MaxPlotPoints -> 1000,      ColorFunction -> "ThermometerColors",      PlotLabel -> Style["Array Plot of Raw Data", 11, Bold, Black],     PlotRangePadding -> 0., ImageSize -> Full,      AspectRatio -> 1/2, Frame -> True,      FrameStyle -> Directive[Thick, Black],      FrameLabel -> {Style["Y", 11, Bold, Black],      Style["X", 11, Bold, Black]},      FrameTicks -> {{All, None}, {All, None}},      FrameTicksStyle -> Directive[Thick, Black, 11, Bold]]      Then when I add PlotLegends->Automatic, they go away!               ArrayPlot[Table[Random[], {i, 10}, {j, 10}], MaxPlotPoints -> 1000,      ColorFunction -> "ThermometerColors",      PlotLabel -> Style["Array Plot of Raw Data", 11, Bold, Black],      PlotRangePadding -> 0., ImageSize -> Full, AspectRatio -> 1/2,      Frame -> True, FrameStyle -> Directive[Thick, Black],      FrameLabel -> {Style["Y", 11, Bold, Black],      Style["X", 11, Bold, Black]},      FrameTicks -> {{All, None}, {All, None}},      FrameTicksStyle -> Directive[Thick, Black, 11, Bold],      PlotLegends -> Automatic]      Here is the really strange thing about this. When I go to "drag" the array plot graphic as if I were going to move it somewhere or manipulate it, the Frame Ticks suddenly appear!


title: How do I sum up p items in a sequence?

text: I have the following sequence list = {p1, p2, p3, p4 ....} I am summing up the p items as follows: p1 + p2 + 2*sqrt (p21*p2) = p12 p12 + p3 + 2*sqrt (p12*p3) = p123 p123 + p4 + 2*sqrt (p123*p4) = p1234 How do I get the end result to be an addition of p12 + p123 + p1234 ?


title: Delete elements from a list really fast

text: I have this bit of code that works, but it's very slow when there are 600k elements in the list:               mytbl = {};     ParallelDo{        If[Flatten[left][[i]] == 1 || Flatten[left[[i]]==0,          mytbl = AppendTo[mytbl, Flatten[left][[i]]];        ];,        {i, Length[Flatten[left]]}     ];      Is there a significantly faster way to do this?