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

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.


Polynomial GCD over a ring (with composite characteristic)

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.


Efficient submatrix swaps for large sparse matrix

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


3D Plotting with PieceWise function

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.


How to optimize my code?

**_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. >>


How to completely delete the head of a function expression

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.


What was added to the LibraryLink API in version 9?

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.


Complex integrals and residues

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.


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

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


Extracting lists from list based on length

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.


how draw root locus in mathematica 9 for a special case

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.


Checking if two trigonometric expressions are equal

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])


Write an expression as a full derivative

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).


Interpolating a plot with missing values

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)


Accessing methods and properties of C++ objects?

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 ?


Tell Mathematica to factor something specific

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.


How to make lines in Plot Legends wider?

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}}]


Plot Legends and Frame Ticks in Array Plots

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!


How do I sum up p items in a sequence?

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 ?


Delete elements from a list really fast

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?


How do you deal with very large datasets in Mathematica?

This question is in two related parts. The first is about dataset size, the second data wrangling. Part 1: I've built a naive Bayesian classifier on Mathematica. It uses `KernelMixtureDistribution` to train on a large (2mm row) dataset. About 200 fields, of which 30 are used. Two separate classes are trained. Unfortunately, when I try to load 2mm rows into _Mathematica_ I get a Java out of heap space error. This is not the end of the world, I can load each column individually, compute the distribution and save it. Then load up all the distributions separately without the training data later. The problem comes in, with the prediction part of the process. I have a 300Mb (400K rows) CSV file, and can't load it. In more traditional environments, I'd either read a row at at time (slow), do a prediction and write it out to a separate file. Or read in some block of rows at a time. I can't see a way to do this in Mathematica. Import seems to only import whole files, and runs out of memory. (4Gig) How are people working with large datasets that won't fit into memory? Part2: I'm dealing with data that mostly has the same columns, but can be shifted about a bit, sometimes have extra columns added. Mathematica, doesn't seem to have a record or structure type, only lists and matrices. How are people dealing with this? I've taken to loading my data into an SQL database, but even this is suboptimal - for my classifier I have to make sure I select the same fields, in the same order, in the same offset in a list. Edit: It looks like Mathematica supports a sort of cursor called result sets. This looks to be slow (400K records, one at a time), but computer time is cheap, person time isn't. I'm going to attempt to train my classifier per normal, then use result sets to individually classify each sample row. If this works out, I'll post an answer to this question detail how I did it. I am making one huge presumption here, that MMA/Java database link will free up memory after each row is no longer needed. As long as that's the case, this approach might stand a chance of working. http://reference.wolfram.com/mathematica/DatabaseLink/ref/SQLResultSetRead.html Edit2: After some playing around, I found Mathematica's result sets acts the same as a standard select would - it loads the entire dataset into JDBC and Mathematica's memory. So that approach runs out of memory just like a standard Import or Select would. I hit on another approach relying on my database (PostgresQL) to do the lifting for me using cursors. This approach only works if you can process your data sequentially. For me, that's an acceptable limitation. First I declared a cursor predRows, and made sure it would persist outside of a transaction (The hold part): SQLExecute[dbconn, "declare predRows cursor with hold for select * from myTable;"] Next, I fetch a row from the cursor - this will iterate over all my ~400K rows one at a time for each request. I can also ask for more rows say 1000 at a time if I'd like. (* Fetch one row at a time *) SQLExecute[dbconn, "fetch 1 from predRows;"] (* Fetch 1000 rows at a ttime *) SQLExecute[dbconn, "fetch 1000 from predRows;"] This does mean I have to program in a imperative manner, but I'll learn to live with myself. Postgres documentation on cursors: http://www.postgresql.org/docs/current/interactive/sql-declare.html


Implementing Position

As an assignment I need to re-implement `Position`. I've managed to do this except for one small thing, the resulting list is not in the current format. The following piece of code is what I have so far.               findPosition[lst_, x_] :=       Module[{output = {}, index = 1},         For[index = 1, index <= Length[lst], index++,           If[lst[[index]] == x,             AppendTo[output, {index}],             False,             If[MemberQ[lst[[index]], x],               AppendTo[output, Map[{index, #} &, findPosition[lst[[index]], x]]];               False             ]; (* If *)           ] (* If *)         ]; (* For *)         Return[output]       ] (* Module *)      This gives the following output:               findPosition[{1, 2, {3, 2, 1}, {1, {4, 2, 1}, 2, {2, 6}}, {2, 6}}, 2]     {{2}, {{3, {2}}}, {{4, {{2, {2}}}}, {4, {3}}, {4, {{4, {1}}}}}, {{5, {1}}}}      While the original gives:               Position[{1, 2, {3, 2, 1}, {1, {4, 2, 1}, 2, {2, 6}}, {2, 6}}, 2]     {{2}, {3, 2}, {4, 2, 2}, {4, 3}, {4, 4, 1}, {5, 1}}      **Am I doing something wrong or is there a way to make my result match the one from the original?** I've tried things using `Flatten`, but it's hard to control what is flattened and what is not. The closest I've come to is `{{2}, {{3, 2}}, {{4, 2, 2}, {4, 3}, {4, 4, 1}}, {{5, 1}}}` using               AppendTo[output, Map[Flatten[{index, #}] &, FindPosition[lst[[index]], x]]];


How to set font color for display formula to be same as the cell in which the display formula resides?

I have a stylesheet that works as expected in _Mathematica_ 8\. It does not work as expected in _Mathematica_ 9\. In the stylesheet I have set FontColor to `RGBColor[0.501961, 0, 0]` for ItemParagraph. DisplayFormula and InlineFormula have FontColor set to `Automatic` (I've also tried `Inherited`). When I press `Ctrl`+`(` to start a formula from within an ItemParagraph the color is the same as for my Text cell (black). The FontColor option for Text is Automatic. Interesting behavior. When I type `Esc``intt``Esc` the font color is `RGBColor[0.501961, 0, 0]` and it creates an inline formula region (or is it displayformula?). When I type `Ctrl`+`/` it creates an inline formula region but the color is black. I have both _Mathematica_ 8 and _Mathematica_ 9 installed and the behavior does not exist on _Mathematica_ 8.


Setting boundary values of a second order differential equation

Not sure what is wrong with the boundary conditions for this problem:               NDSolve[{D[u[x, y], x, x] + D[u[x, y], y, y] -          u[x, y] == -DiracDelta[x, y], u[10, y] == 0, u[x, 10] == 0,        u[-10, y] == 0}, u, {x, 0, 10}, {y, 0, 10}].      The error message is: > NDSolve::ivone: Boundary values may only be specified for one independent > variable. Initial values may only be specified at one value of the other > independent variable.


How to make a simple tree yourself with defined distances for each generation?

I'm trying to make a function that generates a tree for spin spin analysis in spectroscopy. I though it would be pretty easy, but I'm totally stocked. The tree should look something like this: ![Spin Spin analysis](http://i.stack.imgur.com/62ZXp.jpg) where the listed frequencies are the distance between the "generations". I have tried with this: `FoldList[{#1 + #2, #1 - #2} &, 0, {jad,jab,jac}]` where I get the right x-values, but rearranging these values to give me the right lines is where is where it all stops for me. What should I do?


How can I improve this trial division procedure?

My background is procedural programming, so I find this construction quite natural. Is there a way to get rid of the `While`?               gd[n_, k_] := Block[{d = k + 1}, While[0 != Mod[n, --d]]; d]     gd[n_, d_List] :=            Block[{j = Length[d] + 1}, While[0 != Mod[n, d[[--j]]]]; d[[j]]]            k = 4; n = 25;     gd[n, k]     gd[n, Range[1, k]]     d = Join[{1}, Table[Prime[j], {j, 1, PrimePi[k]}]];     gd[n, d]        My trial division requires the greatest divisor $\leq$ the square root. The $n$ mod $1$ is the terminating step. Whatever the final format, I will need to describe it for a math paper. **Edit** The revised functions as recursions:               gd[n_, k_] := If[Mod[n, k] == 0, k, gd[n, k - 1]]     fd[n_, d_List] := If[Mod[n, d[[1]]] == 0, d[[1]], fd[n, Delete[d, 1]]]        **Edit** The second function as it will be described in my paper: $$f(n,D)\text{:=} \begin{array}{ll} \lbrace & \begin{array}{ll} n \bmod d_{1}=0 & d_{1} \\\ n \bmod d_{1}\neq 0 & f(n,\text{Delete}(D,1)) \\\ \end{array} \\\ \end{array} $$


Functional programming and Do loops

I'm writing a Monte Carlo simulation. I'm using a `Do` loop to create the different simulations, iterating over different `SeedRandom[]` parameters in my pseudorandom number generator. I'm trying to formulate it as a function that returns a list of correlations that I can then manipulate. I expect there is a very simple solution, but I have to admit that I'm pretty new to _Mathematica_ so I'm having problems. The _Mathematica_ documentation seems to conveniently dodge this issue whenever it comes up! This might be a little complicated, so I'll explain what my code does first, then I'll describe the problem precisely. _First I make a list with the parameters of each of my random variables (I want them to have different means):_               varparams = Table[i, {i, 0.1, 0.9, 0.1}];      _Then I define my random variables:_               var[i_]:=RandomChoice[{varparams[[i]],1-varparams[[i]]}->{1,0},10]      _(I'm generating [for argument's sake] a set of 10 values for each run of the simulation)._ _Now, I define the function that iterates over different SeedRandom[] values, so as to generate different data sets. I want to calculate a list of correlations:_               corrlist = {};     corrcheck[i_, j_, n_] := Do[       SeedRandom[k];       AppendTo[corrlist, Correlation[var[i], var[j]]];       , {k, n}]      _(`n` is the number of different runs of the simulation)._ Now this sort of works, in the sense that I can run `corrcheck[i,j,n]` and then work with the `corrlist` that is produced, but what I want is for `corrcheck[i,j,n]` **itself** to be a list, so that I can make tables and other manipulations of `corrcheck` for different values of `i` and `j`. I hope this makes sense. To reiterate: I want the function `corrcheck`, which consists of a `Do` loop, to produce a unique list for each set of `i,j,n`, so that I can do things like:               Table[corrcheck[i,j,100],{i,10},{j,10}]      and manipulations thereof. The answer has to be obvious. I just can't see it! Thank you very much in advance.


How to prevent the loss of Tooltip when using ListLinePlot?

Version 9, windows 7: When I use `ListLinePlot` Tooltip does not work any more. It seems to have been lost somewhere. With same data, Tooltip works ok using `ListPlot`.               data = Table[Tooltip[{x, x^2}], {x, 0, 10, .1}];     ListPlot[data]     (* Tooltip shows ok *)          ListLinePlot[data]     (* Tooltip does not show up *)      ![enter image description here](http://i.stack.imgur.com/6BFH7.png) Looked at possible issues for `ListLinePlot` and do not seen mention of this. question: How to make Tooltip work with `ListLinePlot` thanks


Solving set of non-linear simultaneous equations gives PolynomialGCD::lgrexp error - what next?

I'm trying to solve a set of six simultaneous non-linear equations to get a numerical answer using `NSolve`:               NSolve[{-0.5547005383792517 +          0.8082903768654761/E^(0.08452994616207483*(0.10136907301545368 +                         beta1/0.3^alpha)) ==         a, -0.3147005383792517 + 0.669726312259966/               E^(0.08452994616207483*(0.10136907301545368 +                beta1/0.45^alpha)) == a,           -0.13470053837925167 +          0.5658032638058333/          E^(0.08452994616207483*(0.10136907301545368 +                beta1/0.55^alpha)) ==             a, -0.540774588761456 +          0.805711228582561/          E^(0.0779225411238544*(0.10136907301545368 + beta2/0.3^alpha)) ==             a, -0.420774588761456 +          0.7324647532568737/          E^(0.0779225411238544*(0.10136907301545368 + beta2/0.45^alpha)) ==             a, -0.160774588761456 +          0.5737640567178843/          E^(0.0779225411238544*(0.10136907301545368 + beta2/0.55^alpha)) ==             a}, {alpha, beta1, beta2, a}, Reals]      (I'm not very experienced with Mathematica - so I hope that is the correct way to paste code in here so that others can copy into Mathematica and try running it) I get the following errors:               PolynomialGCD::lrgexp: Exponent is out of bounds for function PolynomialGCD.      This seems to suggest that Mathematica can't deal with the large values used as the exponents in the equations given - but as far as I can see the values aren't particularly large. I do know roughly what sort of ranges the results for each of the variables should have (eg. `a` should be between 0 and 1) but I can't seem to find a way to specify this extra knowledge as an option to `NSolve`. I'm not sure where to progress from here, now that I've got these errors. Does anyone have any ideas? I am taking the equations from a paper that I am trying to reimplement, but I'm pretty sure the equations are how they're meant to be. I may be doing something silly in Mathematica though.


Use Results from Manipulate Plot NDSolve to create another plot versus variable used in DE

I created my plot using using this input:               Manipulate[solution[t_] = NDSolve[{          Derivative[1][w][t] == - k1  S w[t] + k2   x[t] -                    k7 H  w[t] + k8  y[t],           Derivative[1][x][t] == - k2  x[t] + k1 S w[t] - k3 H x[t] +                    k4  z[t],           Derivative[1][y][t] == -k8  y[t] + k7 H w[t] - k5  S y[t] +                    k6 z[t],           Derivative[1][z][t] == - k4  z[t] + k3 H  x[t] - k6  z[t] +                    k5 S y[t], w[0] == 1, x[0] == 0, y[0] == 0,           z[0] == 0}, {w [t],                x [t], y [t], z [t]}, {t, 0, 10}][[1, All, 2]];        Plot[solution[t], {t, 0, 10}], {{k1, 1}, 0.01, 5,          Appearance -> "Labeled"}        , {{k2, 1}, 0.01, 5, Appearance -> "Labeled"}        , {{k3, 1}, 0.01, 5, Appearance -> "Labeled"}        , {{k4, 1}, 0.01, 5, Appearance -> "Labeled"} , {{k5, 1}, 0.01, 5,          Appearance -> "Labeled"} , {{k6, 1}, 0.01, 5,          Appearance -> "Labeled"} , {{k7, 1}, 0.01, 5,          Appearance -> "Labeled"} , {{k8, 1}, 0.01, 5,          Appearance -> "Labeled"} , {{H, 1}, 0.1, 5,          Appearance -> "Labeled"}, {{S, 1}, 0.01, 5,          Appearance -> "Labeled"} ,        TrackedSymbols :> {k1, k2, k3, k4, k5, k6,  k7, k8, H, S}]      I now want to plot the solutions function versus S. Any suggestions?


Graphics and panel size

Consider the following snippet:                 DynamicModule[{},        Manipulate[         Graphics[          Translate[           GeometricTransformation[            {Blue, Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}]},            {{scx, 0}, {0, scy}}],           Tuples[{Range[wi], Range[he]}] - 1]],         {{scx, 1, "x scale"}, 0, 1},         {{scy, 1, "y scale"}, 0, 1},         {{wi, 1, "width"}, 1, 5, 1},         {{he, 1, "heigth"}, 1, 5, 1}]]      ![Mathematica graphics](http://i.stack.imgur.com/VPcuI.png) I want a stable, fixed, panel in which the polygons are displayed, thus independent from the slider values. Applying the `PlotRange-> option` to the `Graphics` function in the example above doesn't work as expected. **Question: How should I set and fix the panel size?**


Functions that creates symbol in a specific context

I'm trying to make a function `f` that takes a symbol, a value, and a context, and creates the symbol in the requested context and assigns it the passed value. The obvious doesn't work. I.e.:               Attributes[f]={HoldAllComplete};     f[symbol_,value_,context_]:=(Begin[context];Set[symbol,value];End[])      Creates the symbol in the current context, as opposed to the one that is passed as an argument. This seems to happen because the FrontEnd, as soon as it sees `f` getting evaluated, creates the symbol in the current context despite `HoldAllComplete`. I tried adding `Remove[symbol]` to the function but that doesn't work. Any thoughts?


Custom functions by delegating options in a specific way and using core functions

I'd like to create a custom function that does essentially the same as a core function of mathematica but uses different default settings. Example: I want a Plot function that uses Mathematica's core `Plot` function but uses different default settings. I don't want to use `SetOptions[Plot, ...]` because I don't want to override anything for the core Plot function. Instead of this I want to build a custom function `PlotFramed[x^2,{x,-5,5}]` that points to `Plot[x^2, {x,-5,5}, Frame->True, GridLines->Automatic]`. I also want the function to be able to override my default settings. So `PlotFramed[x^2, {x,-5,5}, GridLines->None]` should return the results from `Plot[x^2, {x,-5,5}, Frame->True, GridLines->None]`. And I want to use additional options that are not set by default as in the normal Plot function. So `PlotFramed[x^2, {x,-5,5}, PlotStyle->Dashed]` should point to `Plot[x^2, {x,-5,5}, Frame->True, GridLines->Automatic, PlotStyle->Dashed]`. The reason for this is that when writing reports (in LaTeX) I have to add several options to the plot function to make the font-size bigger, add a grid, etc pp. Using the idea above I could write a custom Plot function that I can use when generating output for the report and otherwise use Mathematica's core function since everything is fine with it when working inside Mathematica. Can anyone tell me how to do this? This would be awesome. Thanks in advance!


Mathematica Parellelization on HPC

I'm currently using _Mathematica_ on a High Performance Cluster (HPC) which consists of many compute nodes each with around 16 cores. I currently run my _Mathematica_ script on 20 of the nodes that invokes 10 cores and 10 of the subkernels licenses in Parallel, meaning I use 20 Mathkernel licenses and 200 subkernel licenses. The problem is we have limited Mathkernel licenses (36, and for me to be using 20 of them is unfair on everyone else!) although ample subkernel licenses (288). Is there a way I can just use a single (or at least fewer) Mathkernel licenses to invoke the 200 subkernels I need? Currently in each of the 20 scripts I just have               LaunchKernels[10];     ParellelTable[....];      which launches the 10 local subkernels on each node, but could I specify different nodes to launch subkernels on perhaps? Thereby I would only need to launch one Mathkernel which could invoke the 200 subkernels spread across the compute nodes.


Integral with HeavisideTheta takes too long to evaluate

I tried to compute $$\int_{-1}^1 d x_1 \int_{-1}^1 d x_2 \int_{-1}^1 d y_1 \int_{-1}^1 d y_2 \theta(x_1 x_2 + y_1 y_2)\,$$ where $\theta$ is Heaviside's step function, by using               Integrate[HeavisideTheta[x1 x2+y1 y2],{x1,-1,1},{x2,-1,1},{y1,-1,1},{y2,-1,1}]      but it took forever to evaluate. I didn't have the patience to wait until the end. However,               Integrate[Boole[x1 x2+y1 y2 >= 0],{x1,-1,1},{x2,-1,1},{y1,-1,1},{y2,-1,1}]      was very quick. Can anybody explain this strange behavior?


Check homework integration in Mathematica

Given in my homework I have to compute (by hand) $$\iint\limits_{x^2+y^2\leq 1}(x^2+y^2)\,\mathrm dx\,\,\mathrm dy.$$ My solution so far: Let $f(x,y)=x^2+y^2$ and $K=\\{(x,y)\in\mathbb{R}^2:x^2+y^2\leq 1\\}$. With the transformation of polar coordinates $\varphi:(r,\phi)\mapsto(r\cdot\cos\phi,r\cdot\sin\phi)=(x,y)$ and the determinant of the Jacobian matrix $|\det D_\varphi|=r$ we can rewrite the set as $K=\\{(r\cdot\cos\phi,r\cdot\sin\phi):r\in[0,1],\phi\in[0,2\pi]\\}$ and our integrand too as $f(x,y)=x^2+y^2=r^2$. $$\iint\limits_K f(x,y)\,\mathrm dx\,\mathrm dy=\int\limits_0^1\int\limits_0^{2\pi}r^2\cdot |\det D_\varphi|\,\mathrm d\phi\,\mathrm dr=2\pi\int\limits_0^1r^3\,\mathrm dr=\left.2\pi\cdot\frac{1}{4}r^4\right|_0^1=\frac{\pi}{2}.$$ I now want to check the result with a CAS. I am pretty new to Mathematica so I just didn't found any clue on how to enter such an integral for computation. Any help out there?


More elegant/efficient solution to browse through an array

I have an array of lists and want to correlate every list with each other like this:               Table[Table[Correlation[list[[y]], list[[x]]], {x, 1, Length[list]}], {y,1, Length[list]}];      I take the first list and correlate it with all others asf. I pretty much assume, this is not a very elegant and efficient code, so I wanted to ask for some alternatives. How would you guys do it?


How to convert from base 2 to base n?

I'm trying to use baseform to convert numbers in base 10 to base n, how can I make the convertion between, say base 2 to base n? Baseform seems to always think that the base in expr `BaseForm[Expr, n]` is always 10.


Selecting a specific complex number from a list

I have a formula which is producing a large (hundreds of elements) list of complex numbers of the simple form $x+iy$. However I'm only interested in the one value which satisfies the conditions:   1. The imaginary part is the _least negative_ value in the list   2. The real part is positive.  What can write that will pick out this value and display it for me?


Will aliasing the Quantity and UnitConvert functions to "in" and "to" create problems?

It seems that there is a lot of interest in enhancing the use of units in Mathematica; various solutions in the name of brevity, correctness, and general utility have been demonstrated. I've begun treating unit conversions in a very simple manner as listed below. My question: what problems might I run into making conversions in this manner? (It saves a little typing and seems somewhat easier to read to me, at the expense of defining "in" and "to" aliases.) (Mathematica v.9.0.1.0)               in = Quantity; to = UnitConvert;          Express x "in" feet:            x = 100.0~in~"Feet"          100. ft          Convert "to" yards:          x~to~"Yards"          33.3333 yd          Convert to SI units:          x // to          30.48 m          "One stop shop" conversion:          x = 1.0~in~"kg"~to~"lb"          2.20462 lb


Optimizing Monte Carlo simulation of a Pred-Prey model

**My assignment and code** As part of an assignment for one of my classes, I'm trying to run a "massive" Monte Carlo simulation in Parallel on the follow model:               {H'[t] == r (1 - H[t]/k) - d H[t] P[t],       P'[t] == -s P[t] + e H[t] P[t],       H[0] == H0, P[0] == P0}      I've been given values for d, s and e but am required to use distributions for r, k, H0 and P0. I've implemented this as follows:               If[Kernels[] == {}, LaunchKernels[]];          kdis = RandomVariate[NormalDistribution[150, 20], 10];      rdis = RandomVariate[NormalDistribution[0.4, 0.003], 10];     H0dis = RandomVariate[UniformDistribution[{50, 200}], 10];     P0dis = RandomVariate[UniformDistribution[{20, 70}], 10];     d = 0.01;     s = 0.3;     e = 0.02;     SetSharedVariable[d, s, e];          distr = Tuples[{kdis, rdis, H0dis, P0dis}];          Eqs[{k_, r_, H0_, P0_}] :=       NDSolve[{H'[t] == r (1 - H[t]/k) - d H[t] P[t],                P'[t] == -s P[t] + e H[t] P[t],                H[0] == H0, P[0] == P0}, {H, P}, {t, 0, 600}]     DistributeDefinitions[Eqs];          AbsoluteTiming[solset = ParallelMap[Eqs, distr];]      To display the results I create an envelope enclosing all runs for both predator and prey populations:               Envelope[n_] =       Map[{Min@#, Max@#} &,         Transpose[Map[Flatten[{H[n], P[n]} /. #] &, solset]]];     DistributeDefinitions[Envelope];          AbsoluteTiming[plotset = ParallelMap[Envelope, Range[0, 600, 1]];]          plotsetH = plotset[[All, 1]];     plotsetP = plotset[[All, 2]];     Show[ListPlot[{plotsetH[[All, 1]], plotsetH[[All, 2]]},                     Joined -> True, PlotRange -> {{0, 600}, {0, 25}}],          ListPlot[{plotsetP[[All, 1]], plotsetP[[All, 2]]},                     Joined -> True, PlotRange -> {{0, 600}, {0, 25}}]]      The result looks decent: ![The result](http://i.imgur.com/DPZIt6y.jpg) **The problem** Now my issue is that I'm currently hardly using proper distributions, but only 10 values per variable, which I doubt is what my instructor meant when he asked for a massive Monte Carlo simulation. The notebook takes about 2 minutes to evaluate and eats up almost all of the memory 8gb memory I have available in that time. Using 11 instead of 10 values per variable results in an error about kernels appearing dead, which I assume is caused by my memory running out. Are there any ways to optimize this kind of code, or to decrease memory usage? Thanks in advance!


Partitioning a list by recursion (Programming Paradigms via Mathematica (A First Course))

I am working through the course _Programming Paradigms via Mathematica_. One of the homework exercises for the section _Recursion I: Passing the Buck_ is as follows: > Use recursion to partition a list: "recurPartition[L_List,k_Integer]" should > return the same thing as "Partition[L,k]". Of course, don't use > "Partition[]". The following additional limitations are also applied: > First, use of a repetition function ("Map[]", "MapThread[]", "Nest[]", > "NestList[]", "Fold[]", "FoldList[]", "Table[]", "Apply[]", and so on, being > our "adverbs") will generally disqualify a method as purely recursive, for > the repetition is accomplished externally from the nested function calls. > Also, repetition accomplished with a loop structure, such as a "While[]", a > "Do[]", or some other repetition command, is explicitly forbidden. Here was my code, following many edits:               Clear[recurPartition]     recurPartition[{}, k_] := {}     recurPartition[L_List, k_Integer] :=       If[Length[L] >= k, {Take[L, k], recurPartition[Drop[L, k], k]}]     recurPartition[{1, 2, 3, 4, 5, 6}, 2]      Which produced the following output: > {{1, 2}, {{3, 4}, {{5, 6}, {}}}} By contrast `Partition[{1, 2, 3, 4, 5, 6}, 2]` would produce: > {{1, 2}, {3, 4}, {5, 6}} I can't figure out what I should have done differently and would appreciate some guidance.


Disk is displayed distorted in plot

What is the problem with my plot? I want to get a disk shape.               Plot[Table[-x + k, {k, -2, 2, .1}], {x, -5 ,5},        RegionFunction -> Function[{x, y}, (x^2 + y^2) < 1]]      ![enter image description here](http://i.stack.imgur.com/Wx0h9.jpg)


Extract Graphics properties using EventHandler

One can find primitives' properties such as the radius, the center or the color of a `Disk` using `Cases` by using:               g = Graphics[{Red, Disk[{0, 0}, 1], Black, Disk[{10, 0}, 5], Blue, Disk[{30, 0}, 3]}]     Cases[g, Disk[_, y_] :> y, Infinity]     Cases[g, Disk[x_, _] :> x, Infinity]     Cases[g, _RGBColor | _Hue | _GrayLevel, Infinity]      yielding the right values. How can the same functions be applied to an `EventHandler`? Consider for instance the following code:               DynamicModule[{list = {{0, 0}, {2, 0}}},      Graphics[       EventHandler[        {Red, Dynamic@Disk[#, 1] & /@ list},       {"MouseClicked" :> {(* the appropriate function *)}}]]]      The aim would be the extract the radius/center/color of the clicked primitive.


space lost when converting inline cell to tex

> Sample Cell 1 words with spaces in one inline cell               Cell[TextData[Cell[BoxData[\(TraditionalForm\`\(Y\ =\ \(\({\(x\ \[Element]\ \([\(a,\ b\)]\)\)\ :\ \(there\ is\ a\ finite\ subcover\ in\ \(\[Sum]\ \(of\ the\ \(interval\ [\(a,\ x\)]\)\)\)\)}\) .\ \)\)\)], "InlineFormula", FormatType -> "TraditionalForm"]], "Text"]      * * * When saving it as Tex, or `Copy As Latex`, the spaces between words will lost, What's the right and good method to deal with such thing? The worst is each time this happen, I modify it in Tex Editor. * * * As Silva's answer suggested, creating text cell for inline words block. What occurred in my mind is to develop some palletes like this post(my prevous quesion) to do the similar thing. How to make AutoAction take effect only one time? * * * As you see in the picture, I'm handling the `InlineFormula` with blue color. In the biggest blue block, there are two words block`there is a finite subcover in` and `of the interval`. Consider one possible situation, there are five or more words block in the inline cell with depth 2. ![enter image description here](http://i.stack.imgur.com/Twaft.png)


How to define a function or procedure that includes multiple steps?

I would like to define a procedure or function that takes as input an integer, s, and gives as output two nested lists. I have written code (shown below) that does this for one particular value of s, but I don't know how to generalize it. I would like to be able to get the nested lists for different input values without having to define and re-define s. Any help or suggestions would be much appreciated!                   s = 4;         popIndicies = Range[s^2];         list = Table[Table[Partition[popIndicies, s], {3}], {3}];         test = list;         output = {};         Do[temp2 = {};           Do[            temp1 = {};            Do[             temp0 = {};     Do[AppendTo[temp0, test[[l, i, k, j]]], {j, s}];     AppendTo[temp1, temp0], {i, 3}];            row = Flatten[temp1];            AppendTo[temp2, row], {k, s}];           AppendTo[output, temp2], {l, 3}];         output = Flatten[output, 1];         Partition[output, s*3];         latticeWthPadding = {};         Do[AppendTo[latticeWthPadding, output[[s + i, s ;; 2*s + 1]]], {i, 0,             s + 1}];         neighborhoods = {};         Do[          Do[AppendTo[            neighborhoods, {latticeWthPadding[[i, j]],              latticeWthPadding[[i, j - 1]], latticeWthPadding[[i, j + 1]],              latticeWthPadding[[i - 1, j]],              latticeWthPadding[[i + 1, j]]}], {j, 2, s + 1}], {i, 2, s + 1}]         latticeWthPadding // TableForm         neighborhoods // TableForm


How to get a list of days from July 4th to Oct 4th over a range of years

I'd like to create a list with days from the 4th of July to the 4th of October starting in July 1970 to the current date. I tried to use `DateRange`, but I'm a bit confused cause the documentation is't very clear on this point. What should I do? Have you ever tried to do such a thing?


How to extract only real solutions from the result of Solve

For Example, I have the following polynomial equations: $$ \left\\{ \begin{array}{ll} \dfrac{2025 (208 x+5 (y-3446))}{52 (y+90)^2}+\dfrac{300 (8 x-21 y+1920) (y-80)}{7 (x+30)^3}+\frac{300 (80 x-21 z+4500) (z-100)}{7 (x+30)^3}-\dfrac{1521 (-539 x+50 z+15425)}{539 (z+39)^2} =0\\\\[30pt] \frac{2025 (445 y-208 z+49410) (z-45)}{52 (y+90)^3}-\dfrac{2025 (x-85) (208 x+5 (y-3446))}{52 (y+90)^3}-\frac{300 (8 x-21 y+1920)}{7 (x+30)^2}-\frac{1521 (-539 y+90 z+19680)}{539 (z+39)^2} =0\\\\[30pt] \frac{2025 (445 y-208 z+49410)}{52 (y+90)^2}+\frac{300 (80 x-21 z+4500)}{7 (x+30)^2}+\frac{1521 (x-25) (539 x-25 (2 z+617))}{539 (z+39)^3}+\frac{1521 (y-30) (539 y-30 (3 z+656))}{539 (z+39)^3}=0 \\\ \end{array} \right.$$ The mathematica expression:               {{(300 (1920 + 8 x - 21 y) (-80 + y))/(7 (30 + x)^3) + (        2025 (208 x + 5 (-3446 + y)))/(52 (90 + y)^2) + (        300 (4500 + 80 x - 21 z) (-100 + z))/(7 (30 + x)^3) - (        1521 (15425 - 539 x + 50 z))/(        539 (39 + z)^2)}, {-((300 (1920 + 8 x - 21 y))/(7 (30 + x)^2)) - (        2025 (-85 + x) (208 x + 5 (-3446 + y)))/(52 (90 + y)^3) + (        2025 (49410 + 445 y - 208 z) (-45 + z))/(52 (90 + y)^3) - (        1521 (19680 - 539 y + 90 z))/(        539 (39 + z)^2)}, {-((2025 (49410 + 445 y - 208 z))/(         52 (90 + y)^2)) - (300 (4500 + 80 x - 21 z))/(7 (30 + x)^2) - (        1521 (-25 + x) (539 x - 25 (617 + 2 z)))/(539 (39 + z)^3) - (        1521 (-30 + y) (539 y - 30 (656 + 3 z)))/(539 (39 + z)^3)}}      How to extract only those real solutions as new Rule? I mean a general approach to such solutions with mixed real and complex solutions in a rule.


A problem with parallelize

I am experimenting with `Parallelize` and `ParallelTable` This is the code I am using:               K[a_, b_, r_] = a*Exp[-r/b]/r;          T = D[K[10^5, 10^9, s], s]/299792^2 /. s -> 7.6          R = Range[0, 7, 0.01];     \[Theta] = Range[0, 2*Pi, 0.05];          RcG[d_, t_] = Sqrt[7.6^2 + d^2 - 2*7.6*d*Cos[t]];     f[a_?NumberQ, b_?NumberQ] :=        1/299792^2*NIntegrate[K[10^5, 10^9, x], {x, 7.6 - a, b}];          tab = Parallelize[        Table[1/299792^2*           d*(K[10^5, 10^9, RcG[d, t]] - K[10^5, 10^9, 7.6] - d*T) +           f[d, RcG[d, t]], {d, R}, {t, \[Theta]}]];     p1 = ListPlot3D[tab, InterpolationOrder -> 4]      I want make a 3d plot using the complicated function defined in the table. When computing, Mathem. gives this error a lot of times:               NIntegrate::inumr: The integrand K[100000,1000000000,x] has evaluated to non-numerical values for all sampling points in the region with boundaries {{7.3,7.30039}}.      It doesn't happen without the `Parallelize`, so this means that I am using it wrongly, but I don't get where. I also used `ParallelTable`, with the same result.


Convert an expression's symbols of form a$x to a[x]

I want a function that takes expressions of the following form: `a$x` and converts them to `a[x]`. In particular, consider the following test cases               exp = a$x + b$x$y + a$x[d] + a$x[d$y]      Should become, with some `ToFunctionNotation`:               ToFunctionNotation[exp] == a[x] + b[x][y] + a[x][d] + a[x][d[y]]      Note: I want to keep this as an expression for further processing. I tried using matches with `SymbolName` and string patterns, but couldn't figure it out.


Clearing arguments passed to a Module

Is there a possible way to clear the arguments passed to a module to release some memory. I believe that arguments passed to modules are passed by value rather than pass by reference. e.g. I have the following module               DoSomething[arglist_,arglist2_]:=Module[{localvar},     Some long computations...     (*Clear arglist here*)     Some further long computations...     (*Is it possible to reassign some other value to arglist here? e.g. arglist={1,2}*)     ];      I've tried to use Clear[arglist] but i've got the following Clear::ssym error, however Clear[localvar] was fine. All I wan't is to release some memory because my arglist_ is a list of million sublists and tens of elements in each sublist. Secondly Is it possible to reassign some other value to arglist here? e.g. arglist={1,2} within a module. Thanks in advance for the help.


How can I change the size of the plot markers

I use `ListPlot` in order to plot four sets of data and also insert legends in my plot. Here is the Mathematica code               data1 = {{0, 48}, {50, 59}, {100, 69}, {150, 78}, {200, 86}, {250,      87}, {300, 88}, {350, 88.5}, {400, 89}, {450, 89.5}, {500, 90}};     data2 = {{0, 50}, {21, 57}, {45, 65}, {69, 73}, {100, 82}, {150,      86}, {200, 90}, {250, 90.5}, {300, 91}, {350, 92}, {400,      93}, {450, 93.5}, {500, 94}};     data3 = {{0, 55}, {50, 60}, {100, 65}, {150, 72}, {200, 80}, {250,      84}, {300, 87}, {350, 89}, {400, 91}, {450, 91.5}, {500, 92}};     data4 = {{0, 63}, {50, 66}, {100, 69}, {150, 72}, {200, 74.5}, {250,      77}, {300, 79}, {350, 81}, {400, 83}, {450, 85}, {500, 87}};          col = {Blue, Darker[Green], Red, Magenta};     leg = {"\!\(\*SubscriptBox[\(L\), \(z\)]\) = 5",      "\!\(\*SubscriptBox[\(L\), \(z\)]\) = 20",      "\!\(\*SubscriptBox[\(L\), \(z\)]\) = 40",      "\!\(\*SubscriptBox[\(L\), \(z\)]\) = 60"};     plrange = {45, 100};          P0 = ListPlot[{data1, data2, data3, data4}, Frame -> True,      PlotStyle -> Table[{Thickness[0.003], col[[i]]}, {i, 1, 4}],      Joined -> True, PlotMarkers -> {Automatic, 12},      FrameLabel -> {Subscript["M", "n"],      "Percentage of chaotic orbits (%)"},      FrameStyle -> Directive[FontSize -> 17, FontFamily -> "Helvetica"],      PlotRange -> plrange, Axes -> False, ImageSize -> 600,      PlotLegends ->      LineLegend[leg, LegendMarkers -> Automatic,      LegendMarkerSize -> {{20, 25}},      LabelStyle ->       Directive[FontSize -> 15, FontFamily -> "Helvetica"]]]      which produces the following output using version 9 ![enter image description here](http://i.stack.imgur.com/MkdPR.jpg) My main issue is how to increase the size of the plot markers in the legend. Inside the main plot, I can control the size of the markers by `PlotMarkers -> {Automatic, 12}`. On the other hand, even though I tried a lot, I cannot do the same regarding the markers in the legend. Any ideas? Many thanks in advance.


Command to get License Management Monitor info

Using Netlink, when we have more users than _Mathematica_ licenses (used in a pool), we get messages such as: > Error code: 11. Connected MathLink program has closed the link, but there > might still be data underway, that I translate into a more user friendly message. There's a Wolfram License Management Monitor on a server and it generates these reports: Ref: http://uczelnia.mazovia.edu.pl/info/mathematica.html ![enter image description here](http://i.stack.imgur.com/j7zf2.png) Unfortunately the License Server is locked down (its still in the network unlike this: How to access Mathematica license server (being outside of the local network)) and I can't install IIS or a Windows Service to retrieve the License Report on demand. Is there a command that can be used in _Mathematica_ (via Netlink or Front- End) to get this information? ### Update As per http://reference.wolfram.com/mathematica/ref/program/monitorlm.html, I can't get this command to work:               monitorlm  "servername"


How to manipulate a Fourier sine series?

I would like to plot the Fourier sine series for $f(x) = x$. I would like to manipulate the parameter `n` from $0$ to $10$ and plot the sine waves over $(0,1)$. My code below does not work; what is wrong?               Manipulate[Plot[FourierSinSeries[x, x, n], {x, 0, 1}], {n, 0, 10}]


Create a Figure with a sequence of Balanced Binary Trees

I would like make the attached image by Mathematica. someone who could help me? Thank!![enter image description here](http://i.stack.imgur.com/j7A1g.jpg)


Code for solving numerically an integro-differential equation

First of all, I want to greet the community. This is my first question, but I hope I will be able to help answering others members questions, although I am quite new working with Mathematica. I would like to work out the numerical solution of this integro-differential equation: $$\partial_t P(t)=-\frac{1}{\hbar^2}\int_0^tg(t,\tau)P(\tau) e^{\frac{i}{\hbar}k(t-\tau)}d\tau$$ where $k$ is a constant. The function is defined as $$g(t,\tau)=\frac{\hbar^4}{4}\sum_{n=1}^N|\alpha_n|^2\exp[-i \omega_n\cdot(t-\tau)]=F_1(t-\tau)+iF_2(t-\tau)$$ Before deciding to solve numerically, I applied the Laplace transform to my equation (having in mind that I have a convolution product) and got $P(s)$ but I can't go any further because to restore $P(t)=\mathcal{L}^{-1}[P(s)]$ I need to solve the Bromwich integral and finding the poles of my function has no analytical solution. Again, at certain point I should use numerical methods so I prefer to start solving the equation numerically from the beginning and learn how to do that. To be honest, this is my first try in Mathematica and I would appreciate any help, comments focused on code writing. Thank you very much.


2d heat conduction equation: Boundary and initial conditions are inconsistent

I have the following code for a 2d heat c equation:                soln = NDSolve[{        D[y[r, f, t], r, r] +                         (1/r)*D[y[r, f, t], r] +                      (1/r^2)*D[y[r, f, t], f, f] ==                                      (1/1.27*10^-4)*D[y[r, f, t], t],                y[r, f, 0] == 0,                y[10^-2, f, t] == 0,               (D[y[r, f, t], r] /.                     r -> 2*10^-6) == -(1/(3.14*10^-8))*(1 + Sin[2*2*3.14*t/2]),                (D[y[r, f, t], f] /. f -> 0) == -(10/238)*y[r, 0, t],                (D[y[r, f, t], f] /. f -> 3.14/2) == 0},                          y, {r, 2*10^-6, 10^-2}, {f, 0, 3.14/2}, {t, 0, 1}]      and I'm getting the two following error messages: NDSolve::ibcinc:   Warning: Boundary and initial conditions are inconsistent NDSolve::mxst:Maximim number of 10000 steps reached at the point t==1.629*10^-10 NDSolve::eerr:Scaled local spatial error estimate of 4203.0461 at t=1.840*10^-8 in the direction of independent variable r is much greater than prescribed error tolerance. Grid spacing with 51 points may be too large to achieve the desired accuracy or precision. A singularity may have formed or you may want to specify a smaller grid spacing using the MaxStepSize or MinPoints method options I saw an answer for the first one so i'm pretty ok with that but the second one is giving me trouble limitting the useful time domain.I cannot figure out why I'm getting this. Any help will be greatly appreciated! Claudiu


Save open Mathematica Notebook from command line or second Notebook to avoid data loss

I was executing a long Mathematica Notebook over night. The Mathematica instance is running on a Linux workstation (in a vnc server session to be precise). Now I cannot access this session anymore, which means that I likely loose the output data which was produced during the run. I can still login on the workstation as the same user and run Mathematica there. I know from the process list that Mathematica is still running, but I cannot access the GUI anymore. So, if there would be a remote control for Mathematica from command line or a second worksheet, which allows me to save the worksheet, I could prevent the data loss. I already tried to run a second instance of Mathematica but it seems that I cannot even see the Kernels there. Any ideas? It would save my day.


Manipulate slider unresponsive after suspend in Linux

I've tested Linux Mathematica versions 7-9 on various Linux distributions, with identical problem: after suspend/resume cycle my Manipulate controls (i.e. sliders&buttons) appear unresponsive, though I can enter the values manually. This looks much like this question, but before suspend I can use the controls normally, and if they stop working, restarting Mathematica also helps (killing and restarting math kernel doesn't help). Easy way to test this would be using this code:                 Manipulate[Plot[a x, {x, -3, 3}, PlotRange -> {-1, 1}], {a, -1, 1}]      Then making the machine suspend to RAM, waiting 5 seconds and resuming it. If the controls still work (I rarely encounter such situation), second suspend does kill them. Does anyone reproduce this problem? Are there any better workarounds than restarting Mathematica UI?


Working with a database

I just started to work with a database through _Mathematica_. I have a large data set. I use an `.mx` file to store my data. Now I have to store the data in a database, I have installed Microsoft SQL server 2012 in my system. My problem is I don't know how I should store my big list of data in the database. My options seem to be   1. store the mx file in database and retrieve it using SQL command in _Mathematica_   2. create a column in a database table and insert an element from my data list into each row. I tried the SQL route to insert the `.mx` file into the database, since I thought that would be better than inserting the list element-by-element.               insert into test select * from openrowset(bulk 'I:\MsSql\test.mx', single_blob) as test1       I executed the above line in Microsoft SQL server 2012. It appeared to work, but when I tried to retrieve my data set from the database table through _Mathematica_ , I got results that look like a big sublist containing some random numbers and characters. > {{282A546869732069732061......}} I have googled it, but I couldn't find a useful answer. Please explain what I did wrong or refer to me to good material I can learn from.


Find all permutations with a condition

How can I find all the permutations of `{a, b, c}` where `a + b + c = n`? For instance: if `n = 3` the permutations I seel are:   * `Permutations[{3, 0, 0}]`   * `Permutations[{2, 1, 0}]`   * `{1, 1, 1}`


CoordinateTransform from Cartesian to Spherical

I have a set of coordinates on the sphere in terms of cartesian coordinates. I would like to convert them to spherical data points. However, when I try to convert the point {0, 0, 1} it tells me that the solution is indeterminate. Why is this?               CoordinateTransform[ "Cartesian" -> "Spherical", {0, 0, 1}]      > ArcTan::indet: Indeterminate expression ArcTan[0,0] encountered. >> Best, Andy


How to test if all the elements in a list are Integers?

Consider a list such as `s={1,2,3,3,5,6,3}` With `IntegerQ[number]` , you know if `number` is an `Integer`, the result is `True`, and if not, the result is `False`. But... How to do this without visiting each element with a `Do[...,{i,1,Length[.]}]`?


How to show error messages in current notebook?

I would like Mathematica to print error messages in current notebook together with output. This is default option in Mathematica, but recently I turned it off somehow. Now, I am getting output in the notebook, and all cells with style Message go to this other window called Messages. How to set this option back?


Timing enclosed by Manipulate not working

**Manipulate[Timing[Show** [somegraphs[[1 ;; i]]]], {i, 1, 500, 1}] (in Mathematica 8) This is the last line of my function **f[x_]:= Module[....]**. I am trying to combine a list of graphs into a single graph. I want to test its performance so I add an Timing function within the Manipulate function. I want to find out the time it takes when I change the value of _i_. However, the output doesn't change as I change _i_ while clearly the time taken is increased.


Cumulative frequency plot

I have the following data:               data = {{0, 0}, {20, 1.4}, {25, 9.8}, {30, 32.2}, {35, 38.2}, {40, 15.6}, {45, 2.7}, {50, 0.1}};      where the second coordinates are frequencies measured as percent of total (adding, therefore, to $100$). I would like to produce a cumulative frequency plot. What would be the neatest way to do so?


Compare C++ Standard Library's Mersenne Twister with Mathematica's Mersenne Twister

The C++ standard library does contain a set of random distribution classes, among other things a Mersenne Twister engine. What I'd like to do is to generate the same random number distribution, using the same seed for C++ and Mathematica. For instance, generate 10 random numbers using the mersenne twister engine (C++):               std::vector<size_t> a1( 10 );     std::mt19937 gen(42);     std::generate(a1.begin(), a1.end(), gen);          /* {1608637542, 3421126067, 4083286876, 787846414, 3143890026, 3348747335,          2571218620, 2563451924, 670094950, 1914837113} */      and now I generate 10 random integers in _Mathematica_ using the MersenneTwister engine:               BlockRandom[SeedRandom[42, Method -> "MersenneTwister"]     RandomInteger[{0, 2^32 - 1}, 10]]          (* {3012359023, 1649004928, 188383571, 1935467488, 3494372723, 668236121,          1292572136, 98984411, 2487091843, 3121826951} *)      Apparently not the same. The mersenne twister in the C++ standard library uses the following default settings to generate the distribution: ![enter image description here](http://i.stack.imgur.com/cC5iN.png) The question is now: **How much influence do I have on _Mathematica's_ random number generator, so that I can overwrite some specific settings to generate the same set of numbers for a given seed**? EDIT: MathLink implementation MT19937Range: The .tm file:               :Begin:     :Function:      mersenneRange     :Pattern:       MT19937Range[seed_, len_]     :Arguments:     { seed, len }     :ArgumentTypes: { Integer, LongInteger }     :ReturnType:    Manual     :End:          :Evaluate:      MT19937Range::usage = ""      The .cpp file:               #include <random>          using namespace std;          void mersenneRange( int seed, long length )     {         mt19937 gen(seed);              MLNewPacket(stdlink);         MLPutFunction(stdlink, "List", length);             for(long x = 1; x <= length; x++)             MLPutLongInteger(stdlink, gen());     }      MLPutFunction expects as a third argument a int. So implicit conversion here with loss of precision. Is there a better alternative? The Mathematica side:               link = Install["wherever the binary is...",  LinkMode -> Launch]          MT19937Range[42, 10]          (* {1608637542, 3421126067, 4083286876, 787846414, 3143890026, 3348747335, 2571218620,        2563451924, 670094950, 1914837113} *)          Uninstall[link]


Image processing: Floor plan - detecting rooms' borders (area) and room names' texts

![here is a simple building floor plan](http://i.stack.imgur.com/qDhl7.jpg) Here is a simple building floor plan. I would like to derive the _rooms as (rectangular) components and the names of the rooms_. This is very common representation of building floor plans. **The problem** So far I could clean up the floor plan. However, only the walls are left as one component but I would like to derive the _rooms as rectangular components_. In the solution - The rooms may have polygonal shapes as well as rectangles with small rectangular components called circulation areas, corridors or an other function name... alternatively they could added to living room or any other near function. My Question is how to proceed from here? **Code to start with**               img = Import["http://i.stack.imgur.com/qDhl7.jpg"]     nsc = DeleteSmallComponents[Binarize[img, {0, .2}]];     m = MorphologicalTransform[nsc, {"Min", "Max"}]      **Cleaned up floor plan** ![Cleaned up floor plan](http://i.stack.imgur.com/9ywgs.png) **EDIT 1** Some further information about the image. The image contains 2 types of information.   1. The geometric   2. The Spatial The Spatial information; it is important to abstract the room names for defining adjacency of spaces. The door and windows helps to define the adjacency matrix. The adjacency matrix with the geometric information can be used to calculate areas or boundaries. For example : ![Layout](http://i.stack.imgur.com/S6j4F.png)


How to simplify a complicated Sum in terms of power Sums?

For example, I have: $a=\sum _{r=1}^n x_r \left(\left(\sum _{i=1}^n x_i-x_r\right){}^2-\sum _{i=1}^n x_i^2\right)$               a =        Sum[Subscript[x, r]*          ((Sum[Subscript[x, i], {i, 1, n}] - Subscript[x, r])^2 -             Sum[Subscript[x, i]^2,  {i, 1, n}]),         {r, 1, n}]      and $\sum _{i=1}^n x_i=s_1, \sum _{i=1}^n x_i^2=s_2, \sum _{i=1}^n x_i^3=s_3$                c2 = Sum[Subscript[x, i]^2, {i, 1, n}] == s2      I would like to represent $a$ by $s_1, s_2, s_3$, e.g. $a=s_1^3+s_3-3s_1s_2$ . How should I do it? I tried `Solve` or `Eliminate`, but couldn't find a way.


Compiler stack overflow

I tried to compile a huge function. I used these options:               "RuntimeOptions" -> {"EvaluateSymbolically" ->         False}, CompilationOptions -> {"InlineCompiledFunctions" ->         True}, CompilationTarget -> "C", Parallelization -> True      After 700 seconds it returned this error: > CreateLibrary::cmperr: Compile error: > C:\Users\myusername\AppData\Roaming\Mathematica\ApplicationData\CCompilerDriver\BuildFolder\mypcname-6828\Working- > mypcname-6828-4884-1\compiledFunction0.c(1703108) : fatal error C1063: > compiler limit : compiler stack overflow >> > > Compile::nogen: A library could not be generated from the compiled function. > >> How can I diagnose the problem? I feel this is because of the C compiler limitation.


How to randomly erode a 3D distribution of points with Mma 7.0?

Suppose we have a 3D distribution of points, like the spherical ball example below :               Ball[num_]:=Table[     {         #1 Sqrt[1-#2^2]Cos[#3],         #1 Sqrt[1-#2^2]Sin[#3],         #1 #2     }          &[         Random[NormalDistribution[1, 0.5]],         Random[Real,{-1,1}],         Random[Real,{0,2Pi}]     ],{num}]          Graphics3D[{AbsolutePointSize[2],Point[Ball[10000]]},Boxed->True,BoxRatios->{1,1,1},ImageSize->800,SphericalRegion->True]      This code produces the ball shown here : ![A spherical distribution of points in 3D space](http://i.stack.imgur.com/ONB8Q.jpg) Obviously, this ball has a spherical symmetry and could be considered as a "smooth" distribution (under the limit of an infinite set of points). Now, I would like to randomly "erode" the distribution, to get something that look a bit like a fractal shape (think about how an eroded mountain could be obtain from a smooth hill). How can I do that ? What Mathematica procedures could modify the Ball distribution that act like a random eroding process ? To me, "eroding" mean _removing a randomly selected point, and several of its neighbors, then repeat the process several times_. Please, the suggestions should be compatible with **_Mathematica 7.0_**.


Empirical Cumulative Distribution Function

I have a data set of the form $d=\\{(y_1,x_1),(y_2,x_2)...(y_n,x_n)\\}$ for a large $n$. A non-parametric plot of this data (a scatter plot where all observations are sorted along $x$ and joined with a line in the $y-x$ plane) looks like this: ![enter image description here](http://i.stack.imgur.com/WdMXQ.jpg) I want to know how to construct (or define) an empirical distribution, for which the CDF corresponds to this plot. I know that the function `EmpiricalDistribution` could create a distribution function from $d$. The question, however, is how to generate in Mathematica a function from an empirical CDF.


Why does simplification in Mathematica depend on variable names

_Mathematica_ fails to put the following into an obvious simplest form:                  numerator = C2p D2 (C1y N1x - C1x N1y - C1y N2x + N1y N2x + C1x N2y - N1x N2y) +      C1p D1 (-(C2y N1x) + C2x N1y + C2y N2x - N1y N2x - C2x N2y + N1x N2y)          numerator = Simplify[numerator]        produces               C2p D2 (-(C1x N1y) + C1y (N1x - N2x) + N1y N2x + C1x N2y - N1x N2y) +      C1p D1 (C2x N1y - N1y N2x + C2y (-N1x + N2x) - C2x N2y + N1x N2y)        which has obvious simplification failures If I change the name of a variable it succeeds.               numerator = ReplaceAll[numerator,{N2y -> aN2y}]     numerator = Simplify[numerator]          C2p D2 (aN2y (C1x - N1x) + C1y (N1x - N2x) + N1y (-C1x + N2x)) +      C1p D1 (aN2y (-C2x + N1x) + N1y (C2x - N2x) + C2y (-N1x + N2x))          numerator = ReplaceAll[numerator,{aN2y -> N2y}]              C2p D2 (C1y (N1x - N2x) + N1y (-C1x + N2x) + (C1x - N1x) N2y) +      C1p D1 (N1y (C2x - N2x) + C2y (-N1x + N2x) + (-C2x + N1x) N2y)      Once one knows that success depends on the variable names, possibly an alphabetic sort order in the sum somewhere, one knows what to do in order to simplify, but I am concerned about much bigger expressions where you don't know that you need to trick it. Is there any way to get _Mathematica_ to get past this variable name dependence? `FullSimplify` does not help here.


Fortran kind of matrix creation

I want to create the matrix H of dimensions nxn and matrix elements H(i,j). Because of the physical problem I am dealing with, it is necessary to build it in the following not trivial way. I know how to do it in Fortran, but this time I have not been able to figure out how to do it in Wolfram Mathematica. FORTRAN WAY:                 do iy=1,n               do ix=1,n                  do jy=1,n                     do jx=1,n                      i = ix+(iy-1)*n                      j = jx+(jy-1)*n               (Now I give a list of "If" about i and j, and give values to my matrix elemnts H(i,j))                      enddo             enddo         enddo     enddo      Does anybody know how to do this in Wolfram Mathematica?


How to apply a permutation to a symmetric square matrix?

Given a symmetric square matrix, how can I apply a permutation to the rows and columns (i.e. the same permutation to both the rows and the columns) such a way that the new structure of the matrix should follow the new row and column order? Consider an order of rows/columns, according to which the elements of a set are arranged in a matrix:               order = Range[5];     matrix = Table[Subscript[a, i, j], {i, 5}, {j, 5}];     TableForm[matrix, TableHeadings -> {order, order}]      ![Mathematica graphics](http://i.stack.imgur.com/l9T57.png) Now take a permutation of the row/column order:               newOrder = RandomSample[order]     (*        ==> {1, 4, 5, 2, 3}     *)      `FindPermutation` finds the appropriate permutation cycle for the new order:               permutation = FindPermutation[order, newOrder]     Permute[order, permutation]     (*        ==> Cycles[{{2, 4}, {3, 5}}]        ==> {1, 4, 5, 2, 3}     *)      Now the question is: **How to easily and elegantly apply the above permutation (preferably in its`Cycles` form) to the matrix to yield the following one**: ![Mathematica graphics](http://i.stack.imgur.com/1wQrV.png) Some notes:   * The `matrix` is always square and symmetric.   * Column and head orders are always identical.   * Bear in mind that `order`, and consequently `matrix`, can be big (e.g. `4^8` for `order`)   * Since `matrix` can be big, I'm looking for a method, that applies the permutation 'locally', that is without reconstructing the whole table every time, or without applying replacements/functions enumerating each element, thus no dispatch table should be used. This is rather important, as it could be that the new order only swaps two columns/rows, and nothing else.


About high dimensional integrals

I want to be able to do high dimensional integrals like, (..naively I wrote it as this..)               Nc = 12; Nn = 12;      f [x_] := (Sin[x])^2;     g[n_, x_] := Cos[n*(x)];     Integrate[ (Times @@          Flatten@Table[           f[(a[i] - a[j])/2], {i, 1, Nc - 1}, {j, i + 1, Nc}])*       SeriesCoefficient [         Series [          Exp[ Plus @@            Flatten@Table [   ((4)/(n (x^(-n/2) + x^(n/2))))*(Plus @@                 Flatten@                 Table[g[n, a[i] - a[j]], {i, 1, Nc}, {j, 1, Nc}]), {n, 1,               Nn}] ], {x, 0, 1}], 1/2], {a[1], -\[Pi], \[Pi]} , {a[        2], -\[Pi], \[Pi]}  , {a[3], -\[Pi], \[Pi]} , {a[        4], -\[Pi], \[Pi]}, {a[5], -\[Pi], \[Pi]}, {a[        6], -\[Pi], \[Pi]}, {a[7], -\[Pi], \[Pi]}, {a[        8], -\[Pi], \[Pi]}, {a[9], -\[Pi], \[Pi]} , {a[        10], -\[Pi], \[Pi]}, {a[11], -\[Pi], \[Pi]}, {a[12], -\[Pi], \[Pi]}]      But the above has been like running for ages without an output. I would like to know how I can optimize this work so that I can push this to higher levels. For instance I would like to extract higher powers of $x$ rather than $1/2$ as in the above example and also to more variables than $12$ as above.


What's fastest way of defining 10^5 down values?

I want to define               isGood[___] = False;          isGood[#] = True & /@ list      where `list` is a list of several million integers. What's the fastest way of doing this?


LogPlot of the calculated data in For Loop in Mathematica

I have the following loop, for calculating a data for different values of inputs. How I can plot the result at the end of For loop? Its not matter if the plot is inside or outside the loop, I just want to plot the results.               Clear["Global`*"];     b = 10^4;     s = b/2;     tx = ((2*RandomInteger[1, s])-1) + (I*((2*RandomInteger[1, s]) - 1));     For[i = 0, i <= 20, i++, snrdb = i;      snr = 10^(0.1*snrdb);      sd = 1/Sqrt[snr/2];      noise = 1/Sqrt[2]*(RandomReal[NormalDistribution[], {s, 1}] + I*RandomReal[NormalDistribution[], {s, 1}]);      y = tx + (sd*noise);      rx = Flatten[Sign[Re[y]]+I*Sign[Im[y]]];      error = Unitize[tx-rx];      ber = Total[error]/b;      Print["Total number of errors: ",Total[error]];      Print["Error rate: ",N[ber]];      ]     LogPlot[{ber, 10^-4, 10^0}, {snrdb, 0, 20}]      * * * Thanks All, Both techniques was useful. Sorry b is the same as bits, I made a mistake I corrected later. I need the continous line not discrete. how to change the y axis to be from 10^-4 to 10^1? Note: for the purpose of accuracy I increased b to 10^6.               Clear["Global`*"];     b = 10^6;     sym = b/2; tx = ((2*RandomInteger[1, sym]) -          1) + (I*((2*RandomInteger[1, sym]) - 1));     bervals = Reap[         For[i = 0, i < 21, i++, snrdb = i;          snr = 10^(0.1*snrdb);          sd = 1/Sqrt[snr/2];           noise = 1/             Sqrt[2]*(RandomReal[NormalDistribution[], {sym, 1}] +               I*RandomReal[NormalDistribution[], {sym, 1}]);           y = tx + (sd*noise); rx = Flatten[Sign[Re[y]] + I*Sign[Im[y]]];           error = Unitize[tx - rx];          Sow[ber = Total[error]/b];          ]][[2, 1]];     ListLogPlot[bervals, Joined -> True]


CurveGraphics for 3D System of DEQs

I am using the _CurveGraphics6_ NB to try and do some 3D related phase portraits and graphics. The following works and produces an animation.               pic = NDSolve[( {        {x'[t] == 2 y[t] (z[t] + 1)},        {y'[t] == -x[t] (z[t] + 1)},        {z'[t] == -(z[t])^3},        {x[0] == z[0] == 0},        {y[0] == 1}} ),         {x, y, z}, {t, -9, 9}, Animate -> True, PlotPoints -> 600,       ImageSize -> 300, HeadLength3D -> 1/30, DefaultDuration -> 40] // Last      I then attempt:                 Export["temp.gif", pic]      It exports the gif, but not the animation. What am I doing wrong? I also welcome if anyone has ideas on how to better show this in 3D. I do not see how to use the nice 3D Phase Portrait on the system above and maybe someone will be kind enough to provide guidance (as that is what I was really after).