How to input and output partitioned matrices that show partitions and compute as normal?

I want to demonstrate multiplication of partitioned matrices as in the example here. Using the Insert Menu, you can build a matrix and draw lines between rows and columns. However, I want to be able to select a subset of the column and row lines to add. Then I would like to be able to compute the product of two compatible matrices (so the column partition on the left matrix matches the row partition on the right matrix) and have the output show as a partitioned matrix where the row dividers come from the row dividers on the left matrix and the column dividers come from the column dividers on the right matrix. In the example, this matrix multiplication is defined since the column partition on A is, say, {2} and the same for the row partition on B. The resulting matrix C has a row divider after the 2nd row since A had a row divider after the second row (while B had no column dividers).


Slideshow export to PDF (landscape)

I am trying to export a slideshow presentation that I have created in Mathematica 8 to PDF in case I have trouble connecting my laptop to a projector for a talk I am giving. I have tried Save As, Save Selection As and Print to File after setting the print setting to landscape. The latter produces the enormous file even though I am rasterizing the plots, and the former save my file normally but in portrait and also lose the `Scaled` option of plots. Does anyone have a good workflow for this or know a good reference?


Import variables from excel

I have an excel file I am trying to import into _Mathematica_. It is in the format of variables names in the first row of each column and then the data underneath. One of the columns specifies hospitals, so each row has observations for each hospital. There are approximately 800 columns and 400 hospitals. Some of the variables are strings, such as hospital names. But I could delete those in Excel if I had to. I imported it and the text filled the screen. I saw there was a program called Link for Excel, but $250 is a lot of money for a student. I then tried ListView and the table was all wrong. The variable names were in the first column. It seems like it was displaying rows as columns. I want to make sure what is imported is a matrix so we can run some linear programming. Thanks so much for your help in advance!


Plotting vector field

I am trying to plot the gradient vector field of the function: $$sin\sqrt{x^2+y^2}$$ This is my code: `VectorPlot[{(x cos (sqrt (x^2 + y^2)))/ sqrt (x^2 + y^2), (y cos (sqrt (x^2 + y^2)))/ sqrt (x^2 + y^2)}, {x, -3, 3}, {y, -3, 3}]` I am getting a blank plot. Am I entering the code correctly?


Why does a variable become real when using the second argument of Dynamic?

Version 9, on Windows 7. Please compare these 2 very simple examples               Manipulate[      x,      Row[{Manipulator[Dynamic[x], {0, 10, 1/100}]}],      {{x, 1}, None}     ]      and               Manipulate[      x,      Row[{Manipulator[Dynamic[x, (x = #) &], {0, 10, 1/100}]}],      {{x, 1}, None}     ]      Would you not expect them to work the same way? But in the second case, `x` becomes real, while in the first case it remains rational as expected. ![enter image description here](http://i.stack.imgur.com/90wtw.png) Any one knows the reasoning for this? I read about the second argument of `Dynamic`, but do not see something obvious. I did not read everything about it. But the above behaviour is surprising. The fix is easy:               Manipulate[      x,      Row[{Manipulator[         Dynamic[x, (x = Rationalize[#]) &], {0, 10, 1/100}]}],      {{x, 1}, None}      ]      I am only asking why it happens, so I can learn more.


Obtaining the Fourier transform of an operator

We know that if we have a function $f(x)$, and we call $g(\omega)$ its Fourier transform, then the Fourier transform of $x f(x)$ is $$\imath \frac{\mathrm{d} g(\omega))}{\mathrm{d}\omega} $$ and viceversa, ${\mathrm{d}f(x)}/{\mathrm{d}x}$ becomes $\imath \omega g(\omega)$ How can I transform an operator, for example $$L(u):= u+x^2 u+\frac{\mathrm{d}u}{\mathrm{d}x}$$ so that it automatically transforms the variable $x$ in a derivative, and $x^n$ in a derivative of order $n$, and viceversa? * * * The specific problem I'm solving is the following:               ds[u_]:= A.{D[u,s],D[u,a]}.{1,0}      da[u_]:= A.{D[u,s],D[u,a]}.{0,1}   (*where A is a constant matrix*)     G1[t_,x_,y_]:= G0[t,x,y] Integrate[K[tt,x,y],{tt,t,T}]      where `G0[t,s,a]` is a function already defined and `K[tt,x,y]` is a polinomial in the variable $x$ and $y$ (so its integral is still a polinomial in $x$ and $y$. I know the inverse Fourier transform of `G0`, that is `F0[t,s,a]`. What I need is to do is to substitute all the the $x^n$ terms in the polinomial with the operator `ds[u]` applied $n$ times and similarly, $y^m$ with the the operator `da[u]` applied $m$ times. thanks


Sorting function for non commuting bosons

I am trying to write a sorting function which will sort expressions involving products of bosonic objects which do not commute. For example, I can have objects like $a,\ a^\dagger,\ b,\ b^\dagger$ where $[a,a^\dagger] = 1$, $[b,b^\dagger] = 1$ and all other commutators vanish. So the sorting function should for example sort a term like $a a^\dagger b a b^\dagger$ to $a + a^\dagger a^2 + ab^\dagger b+a^\dagger a^2 b^\dagger b$. So I want to sort them first lexicographically and then such that dagger objects will be to the left. I have been using a function from the notebook provided by Simon Tyler at arXiv. So I have created a bosonic object using               Clear[Boson, BosonC, BosonA]     Boson /: MakeBoxes[      Boson[cr : (True | False), sym_], fmt_] :=        With[{sbox = If[StringQ[sym], sym, ToBoxes[sym]]},         With[{abox = If[cr, SuperscriptBox[#, FormBox["\[Dagger]", Bold]], #] &@sbox},         InterpretationBox[abox, Boson[cr, sym]]        ]       ]     BosonA[sym_:"a"] := Boson[False, sym]     BosonC[sym_:"a"] := Boson[True, sym]      Next following the code, I want to turn the atomic expressions into lists and use Mathematica's ordering after that. So I have functions like               NCOrder[Boson[cr : True | False, sym_]] :=      NCOrder[Boson[cr, sym]] = {{sym, Boole[cr]}}          NCSort[expr_] := Module[{temp, NCM},      temp = expr /. NonCommutativeMultiply -> NCM;         temp = temp /. (NCM[a : _Boson ..] :> (NCM[a][[Ordering[#]]] &[NCOrder /@ {a}]));      temp = temp /. NCM[singleArg_] :> singleArg;         temp = temp /. NCM -> NonCommutativeMultiply     ]      This NCSort function right now is just ordering it lexicographically. I want to modify it so that it would sort and order the expressions as I explained above.


Export Voronoi Data?

I have a Voronoi Diagram (VoronoiDiagram/DiagramPlot) in Mathematica - and I need to export it to something I can import into ArcGIS. I'll settle for any sort of data/vector-based (non-raster) format. Obviously a BMP isn't going to work - I need the actual vector data.


How to make a recursive code from this iterative code? (drawing tree graph)

I have a question about drawing tree graph. I use my iterative code to build a tree graph. Here it is.               ClearAll["Global`*"];     (*der={1,3,4,2};*)     der = Input["Add a lot of points in each level, enclosed in curly braces.     (contoh = {1,3,4,2}) : "]     awal = 1;     agab = {};     tekan = 1;     For[k = 1, k <= Count[der, _Integer] - 1, k++,       If[k == 1, mbiyen = 0, tekan = der[[k - 1]]];       For[l = 1, l <= tekan, l++,        For[j = 1, j <= der[[k]], j++,          a[j + mbiyen] =            Table[j + mbiyen \[UndirectedEdge] i, {i, awal + 1,              awal + der[[k + 1]]}];          agab = agab \[Union] a[j + mbiyen];          awal = awal + der[[k + 1]];          If[j == der[[k]], mbiyen = j + mbiyen];          ];        ];       ];     agab     Graph[agab, VertexLabels -> "Name", ImagePadding -> 10]      Now, I use`{1,3,4,2}` into input form. Then the graph looks like this ![1,3,4,2 tree graph](http://i.stack.imgur.com/hHLpX.png) But I have a problem when the levels are more than 4. It still left the vertex. Can anyone fix this code? Or maybe change into recursive mode? Thanks in advance.


Problem in exporting a plot with background to pdf

Just wondering if someone could help me for this problem. I have utilised `prolog` to use a jpg image as the background of my plot in order to compare my results with a reference plot. Although the outcome looks very good in the Mathematica working environment, when I try to export the outcome to pdf the scaling of the background image will be changed and the exported pdf graph is not like what I can see in the Mathematica working environment. This is what I used to draw the plot:               Needs["PlotLegends`"];     backimage = Import["backimage.jpg"];     ListLinePlot[{Data1}, Mesh -> Full, InterpolationOrder -> 3, PlotStyle -> {{Thick, Darker[Blue, 0.5]}}, Joined -> {True}, PlotMarkers -> {{"*",18}}, PlotRange -> {{320, 480}, {-80/1000, 80/1000}}, AxesOrigin -> {0, 0}, FrameTicks -> Automatic, Frame -> True, FrameStyle -> Directive[Thickness[0.0035], Bold, FontFamily -> "Helvetica", 16],  GridLines -> None, AxesStyle -> Directive[Thickness[0.0035], Bold, FontFamily -> "Helvetica"], Prolog -> {Texture[backimage], Polygon[{Scaled[{0, 0}], Scaled[{1, 0}], Scaled[{1, 1}], Scaled[{0, 1}]}, VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]}]      where data points are:               Data1={{320.`, 0.00171`}, {320.625`, 0.00802`}, {321.25`,  0.01382`}, {321.875`, 0.0194`}, {322.5`, 0.02464`}, {323.125`, 0.02974`}, {323.75`, 0.03426`}, {324.375`, 0.03881`}, {325.`, 0.04315`}, {325.625`, 0.04729`}, {326.25`, 0.051`}, {326.875`, 0.05469`}, {327.5`, 0.05792`}, {328.125`, 0.06066`}, {328.75`,0.06287`}, {329.375`, 0.06448`}, {330.`, 0.06512`}, {330.625`,0.065`}, {331.25`, 0.06418`}, {331.875`, 0.06236`}, {332.5`, 0.05963`}, {333.125`, 0.0562`}, {333.75`, 0.05219`}, {334.375`, 0.0474`}, {335.`, 0.04238`}, {335.625`, 0.037`}, {336.25`, 0.03139`}, {336.875`, 0.02559`}, {337.5`, 0.02011`}, {338.125`,  0.01444`}, {338.75`, 0.0088`}, {339.375`, 0.00313`}, {340.`, -0.00233`}, {340.625`, -0.00813`}, {341.25`, -0.01374`}, {341.875`, -0.01949`}, {342.5`, -0.02523`}, {343.125`, -0.03118`}, {343.75`, -0.03665`}, {344.375`, -0.04212`}, {345.`,-0.04726`}, {345.625`, -0.05204`}, {346.25`, -0.05601`}, {346.875`,-0.05954`}, {347.5`, -0.06211`}, {348.125`, -0.0638`}, {348.75`,-0.06465`}, {349.375`, -0.06484`}, {350.`, -0.06399`}, {350.625`,-0.06246`}, {351.25`, -0.06044`}, {351.875`, -0.05791`}, {352.5`,-0.05485`}, {353.125`, -0.05157`}, {353.75`, -0.048`}, {354.375`,-0.044`}, {355.`, -0.03988`}, {355.625`, -0.03559`}, {356.25`,-0.03091`}, {356.875`, -0.02575`}, {357.5`, -0.02044`}, {358.125`,-0.01462`}, {358.75`, -0.00845`}, {359.375`, -0.00192`}, {360.`,   0.00468`}, {360.625`, 0.01172`}, {361.25`, 0.01853`}, {361.875`, 0.02515`}, {362.5`, 0.03135`}, {363.125`, 0.03737`}, {363.75`, 0.04252`}, {364.375`, 0.04719`}, {365.`, 0.05109`}, {365.625`, 0.05436`}, {366.25`, 0.05672`}, {366.875`, 0.0588`}, {367.5`,  0.06019`}, {368.125`, 0.06105`}, {368.75`, 0.06141`}, {369.375`,   0.06165`}, {370.`, 0.06134`}, {370.625`, 0.06071`}, {371.25`, 0.05967`}, {371.875`, 0.0581`}, {372.5`, 0.05576`}, {373.125`, 0.05296`}, {373.75`, 0.04948`}, {374.375`, 0.04515`}, {375.`, 0.04011`}, {375.625`, 0.03457`}, {376.25`, 0.02845`}, {376.875`, 0.02188`}, {377.5`, 0.01525`}, {378.125`, 0.00844`}, {378.75`, 0.0016`}, {379.375`, -0.005`}, {380.`, -0.01107`}, {380.625`,-0.01703`}, {381.25`, -0.02254`}, {381.875`, -0.02772`}, {382.5`, -0.03252`}, {383.125`, -0.03728`}, {383.75`, -0.04152`}, {384.375`, -0.04573`}, {385.`, -0.04976`}, {385.625`, -0.05364`}, {386.25`, -0.05688`}, {386.875`, -0.05991`}, {387.5`, -0.06228`}, {388.125`, -0.06402`}, {388.75`, -0.06492`}, {389.375`, -0.0652`}, {390.`, -0.06431`}, {390.625`, -0.06257`}, {391.25`, -0.06007`}, {391.875`, -0.05694`}, {392.5`, -0.05296`}, {393.125`, -0.04866`}, {393.75`, -0.044`}, {394.375`, -0.03906`}, {395.`, -0.03399`}, {395.625`, -0.02904`}, {396.25`, -0.02384`}, {396.875`, -0.01843`}, {397.5`, -0.01298`}, {398.125`, -0.0074`}, {398.75`, -0.0015`}, {399.375`, 0.00386`}, {400.`, 0.0065`}, {400.625`, 0.0055`}, {401.25`, 0.00137`}, {401.875`, -0.00405`}, {402.5`, -0.00755`}, {403.125`, -0.00696`}, {403.75`, -0.00269`}, {404.375`, 0.00328`}, {405.`, 0.00844`}, {405.625`, 0.01005`}, {406.25`, 0.00696`}, {406.875`, 0.00101`}, {407.5`, -0.00515`}, {408.125`, -0.009`}, {408.75`, -0.00883`}, {409.375`, -0.00442`}, {410.`, 0.0014`}, {410.625`, 0.00588`}, {411.25`, 0.00702`}, {411.875`, 0.00442`}, {412.5`, -0.00088`}, {413.125`, -0.00558`}, {413.75`, -0.00705`}, {414.375`, -0.00475`}, {415.`, 0.00035`}, {415.625`, 0.00605`}, {416.25`, 0.00927`}, {416.875`, 0.00802`}, {417.5`, 0.00325`}, {418.125`, -0.00313`}, {418.75`, -0.0084`}, {419.375`, -0.01003`}, {420.`, -0.00693`}, {420.625`, -0.00113`}, {421.25`, 0.00464`}, {421.875`, 0.00795`}, {422.5`, 0.00717`}, {423.125`, 0.00266`}, {423.75`, -0.00277`}, {424.375`, -0.00618`}, {425.`, -0.00623`}, {425.625`, -0.0027`}, {426.25`, 0.00281`}, {426.875`, 0.00718`}, {427.5`, 0.00794`}, {428.125`, 0.00486`}, {428.75`, -0.00081`}, {429.375`, -0.00686`}, {430.`, -0.00993`}, {430.625`, -0.00844`}, {431.25`, -0.00325`}, {431.875`, 0.0031`}, {432.5`, 0.00818`}, {433.125`, 0.00924`}, {433.75`, 0.00591`}, {434.375`, 0.00024`}, {435.`, -0.00482`}, {435.625`, -0.00729`}, {436.25`, -0.00583`}, {436.875`, -0.00106`}, {437.5`, 0.00402`}, {438.125`, 0.00682`}, {438.75`, 0.00602`}, {439.375`, 0.00186`}, {440.`, -0.00407`}, {440.625`, -0.00823`}, {441.25`, -0.00847`}, {441.875`, -0.00469`}, {442.5`, 0.0014`}, {443.125`, 0.00738`}, {443.75`, 0.01001`}, {444.375`, 0.00797`}, {445.`, 0.00265`}, {445.625`, -0.00353`}, {446.25`, -0.00801`}, {446.875`, -0.00859`}, {447.5`, -0.00489`}, {448.125`, 0.00065`}, {448.75`, 0.00535`}, {449.375`, 0.00717`}, {450.`, 0.00505`}, {450.625`, -0.00006`}, {451.25`, -0.00509`}, {451.875`, -0.00724`}, {452.5`, -0.00574`}, {453.125`, -0.00091`}, {453.75`, 0.00496`}, {454.375`, 0.00873`}, {455.`, 0.00819`}, {455.625`, 0.00402`}, {456.25`, -0.0022`}, {456.875`, -0.00781`}, {457.5`, -0.0099`}, {458.125`, -0.00737`}, {458.75`, -0.00177`}, {459.375`, 0.00427`}, {460.`, 0.00841`}, {460.625`, 0.00826`}, {461.25`, 0.00411`}, {461.875`, -0.00167`}, {462.5`, -0.00596`}, {463.125`, -0.0072`}, {463.75`, -0.00441`}, {464.375`, 0.00087`}, {465.`, 0.00559`}, {465.625`, 0.00716`}, {466.25`, 0.0051`}, {466.875`, 0.00016`}, {467.5`, -0.00553`}, {468.125`, -0.00866`}, {468.75`, -0.00763`}, {469.375`, -0.00299`}, {470.`, 0.00321`}, {470.625`, 0.00848`}, {471.25`, 0.00981`}, {471.875`, 0.00651`}, {472.5`, 0.00048`}, {473.125`, -0.00553`}, {473.75`, -0.00898`}, {474.375`, -0.00809`}, {475.`, -0.00323`}, {475.625`, 0.00254`}, {476.25`, 0.00662`}, {476.875`, 0.00725`}, {477.5`, 0.00418`}, {478.125`, -0.00122`}, {478.75`, -0.00567`}, {479.375`, -0.00692`}};      And the image I used in the background (backimage.jpg) is ![enter image description here](http://i.stack.imgur.com/pOorm.jpg) After running this command in the Mathematica notebook, this is how it looks in the working environment: ![enter image description here](http://i.stack.imgur.com/CIkQC.jpg) Which is very nice and it is exactly what I need. But when I try to export this graph (including the background) to pdf, this is what I get: ![enter image description here](http://i.stack.imgur.com/E3vrc.jpg) which is not the same as what I expected. I tried to use `PrintingStyleEnvironment` to sort this issue out, but it was not successful.


Matrix Operation

I have a $3\times3$ matrix `A`, and a function `sTrans` that outputs two $3\times3$ matrices in a list when given a $3\times3$ matrix. So the input               A = {{1,2,3} , {4,5,6} , {7,8,9}}      And the output > sTrans[A] > > { {{3, 1, 2}, {4, 5, 6}, {7, 8, 9}} , {{1, 2, 3}, {6, 4, 5}, {7, 8, 9} }} And now I want to append the two matrices in a queue. The enQueue operation               enQueue[q_, elem_] := If[FreeQ[q,elem],qt++; q[[qt]]= elem]      How should I write the code without using loop? (P.S. I've heard multiple times that the whole concept of MMA is against `For` and `While` loops)


How to put the legends above the figure and make them vertical?

The following way will put the legends on the right of the figure, and the three legends are vertically aligned.               Plot[{x, x^2, x^3}, {x, 0, 3}, Frame -> True,        PlotLegends -> {"long text 1", "long text 2", "long text 3"}]      ![enter image description here](http://i.stack.imgur.com/BtTiT.jpg) The following way will put the legends above the figure, but the three legends are in one line, instead of three lines.               Plot[{x, x^2, x^3}, {x, 0, 3}, Frame -> True,        PlotLegends -> Placed[{"long text 1", "long text 2", "long text 3"}, Above]]      ![enter image description here](http://i.stack.imgur.com/bkO4v.jpg) How to get a figure such that the legends are above the figure (like the second figure), and they are vertically aligned in multiple lines (like the first figure)?


Finding values w.r.t. one parameter out of many and making a plot

μ = 0.15;     λ = 0.4;     ρ = 1;     r = 0.04;     i = 3;     θ = 1;     κ = 0.1;     σ = 0.15;     γ[κ_, μ_, λ_, ρ_, σ_, r_] =        (2 κ - 2 μ + 2 λ ρ σ + σ^2 + Sqrt[8 r σ^2 + (-2 κ + 2 μ - 2 λ ρ σ - σ^2)^2])/(2 σ^2);     b[κ_, μ_, λ_, ρ_, σ_, r_] =        2 - 2 γ[κ, μ, λ, ρ, σ, r] + 2 (κ - μ + λ ρ σ)/σ^2;     B[κ_, μ_, λ_, ρ_, σ_, r_] =        -Gamma[1 - γ[κ, μ, λ, ρ, σ, r] - b[κ, μ, λ, ρ, σ, r]]*        Gamma[b[κ, μ, λ, ρ, σ, r]]/        Gamma[-γ[κ, μ, λ, ρ, σ, r]]/        Gamma[2 - b[κ, μ, λ, ρ, σ, r]];     h[V] = Hypergeometric1F1[-γ[κ, μ, λ, ρ, σ, r], b[κ, μ, λ, ρ, σ, r], (2 κ θ)/(σ^2 V)];     g[V] =        Hypergeometric1F1[         1 - γ[κ, μ, λ, ρ, σ, r] - b[κ, μ, λ, ρ, σ, r], 2 - b[κ, μ, λ, ρ, σ, r],          (2 κ θ)/(σ^2 V)];     F[A, V] =        A*(h[V] + B[κ, μ, λ, ρ, σ, r]*((2 κ θ)/(σ^2 V))^(1 - b[κ, μ, λ, ρ, σ, r])*g[V])*       V^γ[κ, μ, λ, ρ, σ, r];     x = V /. FindRoot[{F[A, V] == V - i, D[F[A, V], V] == 1}, {A, 0.01}, {V, 1.01}]      I think this should be an easy question, but I am new to _Mathematica_ and can not figure it out. Variable `x` is what I would like to obtain, and given the parameters values at the beginning of the code, the value of `x` can be found. It should be 6.3632. Here is the question: how can I change the code and establish a loop to evaluate the values of `x` with σ taking different values, like ranging from 0.1 to 0.2 in step of 0.01. Thus, σ is no longer a constant input as presented in my code but a iterating variable. Also, if it is convenient, how can I plot `x` against the values of σ?


ColorFuntion input

Is there any input for `ColorFunction`, which ranges from Black for smallest values, goes through red-orange-yellow and ends in very bright yellow almost white for the highest values of the `ListDensityPlot`?


Code for sum of exponential divisors function

Consider $n = p_{1}^{a_1}\cdots p_{r}^{a_{r}}$. An integer $d = p_{i}^{b_{i}} \cdots p_{r}^{b^{r}}$ is called an _exponential divisor_ of $n$ if $b_{i}$ divides $a_{i}$ for every $1\leq i \leq r.$ I am trying to encode two functions: $\tau'(n)$, the number of exponential divisors of $n$, and $\sigma'(n)$, the sum of the exponential divisors of $n$. Both $\tau'$ and $\sigma'$ are multiplicative, hence we only need to look at them on prime powers. For example $\sigma'(p^6) = p + p^2 + p^3 + p^6$, and $\tau'(p^6) = 4$. I have been having difficulty in using Mathematica to encode an expression for $\tau'$ and $\sigma'$. I do not really understand what 'heads' and 'levels' mean. Does anyone have any suggestions?


Resampling when using image as Texture

How to get sharp pixel boundaries with Texture? I'd like to have only black/white in the example below, no gray.               a := Image[Table[If[EvenQ[x + y], 1, 0], {x, 50}, {y, 50}]];     Graphics[{Texture[a],       Polygon[{{1, 0}, {0, Sqrt[3]}, {-1, 0}},         VertexTextureCoordinates -> {{1, 0}, {0.5, 1}, {0, 0}}]}, ImageSize -> 200]      ![enter image description here](http://i.stack.imgur.com/Wvnui.png)


2D Visualization of links and knots

I am trying to draw a picture using Mathematica of three loops linking together in 3D as follows. ![3D visualization](http://i.stack.imgur.com/V6spd.png)               Module[{r = 0.03, col1, col2, col3}, {col1, col2, col3} =      ColorData["HTML"] /@ {"Firebrick", "ForestGreen", "RoyalBlue"};     Graphics3D[{{{{col2,          Rotate[#, π/12, {0, 0, 1}, {0, 0, 0}]}, {col3,          Rotate[#, -π/12, {0, 0, 1}, {0, 0, 0}]}} &@      Translate[       Tube[Table[         0.5 {Cos[θ], 0, Sin[θ]}, {θ, 0,           2 π, π/24}], r], {1, 0, 0}]}, {col1,      Tube[Table[{Cos[θ], Sin[θ], 0}, {θ, 0,         2 π, π/24}], r]}},     ViewPoint -> {5, 0, 2}, Boxed -> False, Lighting -> "Neutral"]]      I used Graphics3D and Tube to draw the above picture. But I found that it is not easy to see which line is in front of which. So then I use Graphics and Circle to draw the following 2D picture, in which the overlapping relation is represented by a small gap of the underlying line at the intersection. ![2D visualization](http://i.stack.imgur.com/XbhOE.png)               Module[{col1, col2, col3},     {col1, col2, col3} =      ColorData["HTML"] /@ {"Firebrick", "ForestGreen", "RoyalBlue"};      Graphics[{{col1, Circle[{0, 0}, {2, 1}]},      Translate[{{White, Disk[{-0.47, -0.08}, 0.15]}, col2,       Circle[{0, 0}, {0.5, 1}, {0.07 π, 1.97 π}]}, {0.6, -0.9}],     Translate[{{White, Disk[{-0.47, 0.12}, 0.15]}, col3,       Circle[{0, 0}, {0.5, 1}, {0.02 π,         1.92 π}]}, {-0.8, -0.9}]}]]      I think the 2D picture is nicer and can be saved as the vectorized image with a much smaller size compared to the 3D version. However I need to explicitly tell Mathematica where and how to break the lines. My question is: is there a method to have Mathematica automatically draw links or knots in the 2D style with the underlying lines broken at the intersections.


Cannot solve system of linear equation sums?

I cannot get mathematica to solve: ![enter image description here](http://i.stack.imgur.com/a6u6s.png) The problematic code:               With[{n = 7},       Solve[((2*            Sum[((Subscript[y,                   k] - (a*Subscript[x, k]^3 + b*Subscript[x, k]^2 +                    c*Subscript[x, k] + d)))*(-Subscript[x, k]^3), {k, 1,               n}]) == 0) && ((2*            Sum[(Subscript[y,                  k] - (a*Subscript[x, k]^3 + b*Subscript[x, k]^2 +                   c*Subscript[x, k] + d))*(-Subscript[x, k]^2), {k, 1,               n}]) == 0) && ((2*            Sum[(Subscript[y,                  k] - (a*Subscript[x, k]^3 + b*Subscript[x, k]^2 +                   c*Subscript[x, k] + d))*(-Subscript[x, k]), {k, 1,               n}]) == 0) && ((2*            Sum[(Subscript[y,                  k] - (a*Subscript[x, k]^3 + b*Subscript[x, k]^2 +                   c*Subscript[x, k] + d))*(-1), {k, 1, n}]) == 0), {a, b,         c, d}]      ]      I tried for a variable `n`, but that gave me 'could not solve with methods available to Solve', so then via a recommendation here I used n=6, but this still doesn't seem to work :/ If I put $x_{k}$ and $y_{k}$ instead as $x[[k]]$ and $y[[k]]$ and give a list however, then it is able to solve in under a second, as shown in this example:               x = RandomReal[{-10, 10}, 6];     y = RandomReal[{-10, 10}, 6];     With[{n = 6},       Solve[And @@         Table[Sum[(y[[k]] - (a x[[k]]^3 + b x[[k]]^2 + c x[[k]] +                 d)) (-x[[k]]^j), {k, 1, n}] == 0, {j, 0, 3}], {a, b, c, d}]]          (*     ==> {{a -> -0.0970828, b -> 0.771442, c -> 0.895965,        d -> -3.73369}}     *)      Here is a version of this code that doesn't work:               Clear[x, y]          With[{n = 6},       Solve[And @@         Table[Sum[(Subscript[y,                k] - (a Subscript[x, k]^3 + b Subscript[x, k]^2 +                 c Subscript[x, k] + d)) (-Subscript[x, k]^j), {k, 1, n}] ==           0, {j, 0, 3}], {a, b, c, d}]]


Shortening the syntax {var1, var2} /. # & /@ list

I noticed that I often turn out to have a list of substitutions in the form               list =      {       {var1 -> value1, var2 -> value2, ..., varn -> valuen},        {var1 -> value1, var2 -> value2, ..., varn ->  valuen}     }      and need to extract some of the values (for instance for plotting). I use the syntax               {var1, var2} /. # & /@ list      Is there a shorter one?


BC for transport equation using NDSolve

First I can solve a transport equation with a source (Is it still called transport equation?) using `DSolve`. The form of the source serves only as an example. It can be anything.               sol1 = DSolve[               { D[y[x, t], t] - 2 D[y[x, t], x] == Exp[-(t - 1)^2 - (x - 5)^2],                 y[x, 0] == 0               },               y[x, t],               {x, t}               ];          Plot3D[Evaluate[y[x, t] /. sol1], {x, -10, 10}, {t, 0, 15}, PlotRange -> All]      It will give me the following results. This is what I expected. ![Results using DSolve](http://i.stack.imgur.com/KFbUK.png) **My question is, if I want to use`NDSolve` instead, what should I use as boundary conditions?** The BC should allow the bulk to follow out of the domain and never return. I have no idea how to write down the BC. For example,               sol3 = NDSolve[               { D[y[x, t], t] - 2 D[y[x, t], x] == Exp[-(t - 1)^2 - (x - 5)^2],                 y[x, 0] == 0,                 y[-10, t] == 0,                 y[10, t] == 0},               y[x, t],               {x, -10, 10},               {t, 0, 15}];          Plot3D[Evaluate[y[x, t] /. sol3], {x, -10, 10}, {t, 0, 15}, PlotRange -> All]      will give me an error and the following results which is obviously wrong:               NDSolve::eerr: Warning: scaled local spatial error estimate of 89.96891825336817` at t = 15.` in the direction of independent variable x is much greater than the prescribed error tolerance. Grid spacing with 25 points may be too large to achieve the desired accuracy or precision. A singularity may have formed or a smaller grid spacing can be specified using the MaxStepSize or MinPoints method options. >>      ![enter image description here](http://i.stack.imgur.com/COTfw.png) I think the error might involve something besides BC.


How to get a solution set of a nonlinear system of equations?

I'm trying to find the solution set of `{x, y}` variables for the following system of equations:               Solve[{0 == -1/2*Tan[Pi*x/2] + y, 0 == -1/2*Tan[Pi*y/2] + x}, {x, y}]      But when I try this, I can't get a result. Is there another function I should use? I can get the "basic" solutions by hand noting that if $x = 0$, then $y = 2n$ where $n$ is an integer (and vice-versa for when $y = 0$). But I think there are other solutions... Any help would be appreciated, thanks! I'm using Mathematica 8, BTW.


Explicit use of Evaluate not behaving the way I expect it to

I discovered a strange behavior of the `Evaluate` function. Case 1:               Clear[f]     f[x_] := x^2     g[x_] := Evaluate[D[f[x], x]]     Clear[f]     g[x]      > >     2 x >   Case 2:               Clear[f]     f[x_] := x^2     g[x_] := Evaluate[D[f[x], x]] + f[x]     Clear[f]     g[x]      > >     f[x] + Derivative[1][f][x] >   I think the Case 2 behavior is strange, because the derivative of `f` isn't evaluated properly when `g` defined. Why do I see this difference?


Licence and number of controlling kernels

I'm trying to understand the differences between controlling kernels and subkernels. I created 3 local kernels (kernel configuration options > add), each using a maximum of 8 local subkernels. However on the Wolfram User Portal my license reads               Controlling 2      Computing 8      So what are these "controlling kernels" ? Is there a limit on local kernels that can be started ? Cf. This question on the same topic, but the answers appear contradictory. Following one of these answers, I don't understood how I am allowed to run 3 local kernels. Additionally, what is the difference between launching 1 front-end and having many local kernels and launching many front-ends each with only one local kernel ?


How to construct a new list made from a function that operates on two lists

I need to take two lists (each list contains the number of moles of a chemical). I have a function calledFraction that takes the each entry of the list and then calculates the mole fraction of Chloroform. Each entry in the new list should be the mole fraction calculated by taking   molesChloroform[[1]]/(molesChloroform[[1]] + molesAcetone[[1]] Here is what I have tried:               molesChloroform = {0.125, 0.100, 0.0625, 0.0375}     molesAcetone = {0.027, 0.068, 0.0952, 0.136}     moleFraction[molesA_, molesB_] = molesA/(molesA + molesB)     {moleFraction[#1, #2]} & @@@ {molesChloroform[[1 ;;]],        molesAcetone[[1 ;;]]}     Out[23]= {{0.555556}, {0.284211}}      This is not the correct output.


Merge StyleSheet into a notebook

I have a custom style called _style1.nb_ and I want to install it into a notebook _Class01.nb_ so I can send only the notebook file to my students with the style of _style1.nb_. Is that possible?


Deleting quasi-duplicates from large list efficiently

I have the need to remove "duplicates" from large (>10K members) lists, where a "duplicate" is either a verbatim duplication, _or_ the element's second entry exists as a first entry for some "earlier" member in the list. E.G., given               testcase = {{1, 2}, {2, 1}, {1, 3}, {3, 4}, {4, 9}, {1, 3}, {6, 4}, {9, 4}, {7, 5}, {6, 7}, {5, 7}}      the desired result would be `{{1, 2}, {1, 3}, {3, 4}, {4, 9}, {7, 5}}`. Of course the trivial method is `DeleteDuplicates[testcase, #2[[2]] == #1[[1]] &]`, but this goes exponential, as hinted to in the MMA documentation. I've been pondering for a bit, shooting blanks so far, looking for any ideas toward an _efficient_ solution.


Creating a number station

This is a question about manipulating sound (wav files). The goal is to produce something that sounds like a number station broadcast, see e.g., 4:00 in http://www.youtube.com/watch?v=EdnoAJ7KoFE It is easy to generate a random string of numbers, and send it to the linux program `espeak` (with `-v de` for German and `-w out.wav` for saving the sound as a wav file.) Now, the resulting voice is too clean to sound like a radio recording, so the challenge is to distort the sound a bit and make it sound more like a strange radio recording. Adding a little echo and some white noise maybe?


Plot range of a 2-dimensional function as a function depending on one variable

I want to plot a function of 2 variables x and y, for discrete values of y, like:               myFunc[x_, y_] := Sin[x y]     yvalues={0.1,0.5,1.0,2.0}     Plot[Evaluate@Map[myFunc[x, #] &, yvalues], {x, 0, 5}]      What I want is that the maximum x range (in this case 5) is a function of yvalues, for example, for each value i of yvalues, stop the corresponding plot curve at `Cos[yvalues[[i]]]`. I need this because in my real case, the function to plot is a 2D interpolation which behaves badly outside some specific intervals depending on y. Thanks.


Testing the Erdos square free conjecture

Can someone please answer these two parts of my homework assignment? Adding an explanation would be appreciated! > a. Test the Erdos square free conjecture for $n <= 30000$. You should use > `SquareFreeQ`. Give the time it takes to perform this test. For this part, I said,               {#, SquareFreeQ[#]} & /@ {Binomial[5, 30000]}      > b. Now test using your `squareFreeQ` and give the time it takes to perform > this test. For this part, my `squareFreeQ` is:               squareFreeQ[n_Integer] := Select[FactorInteger[n][[All, 2]], # > 1 &] == {}      For part b, my answer is:               {#, squareFreeQ[#]} & /@ {Binomial[5, 30000]}      But none of the answers seem to be correct.


How can I type "aprox symbol in Mathematica?

I want to obtain a value of the Normal Distribution, but I can´t type "approx symbol" before Normal Distribution" to tell Mathematica that x FOLLOWS N[0,1] How can I do it? Probability[z >= 8.49, z **"HOW TO TYPE THE SYMBOL I MUST TYPE HERE"** NormalDistribution[0, 1]]


StepMonitor not working inside ParametricNDSolveValue

Here is a toy example:               currentTimeStep = 0;     Dynamic[currentTimeStep]     pfun = ParametricNDSolveValue[               {y'[t] == a y[t], y[0] == 1}, y, {t, 0, 10000}, {a},               StepMonitor :> (currentTimeStep = t;), MaxSteps -> 100000            ];     pfun[1]      As you can see from the value of `currentTimeStep`, the variable is most of the time left without a numerical value. Is there a way to look at the current status of computation when using `ParameticNDSolveValue`?


Mathematica Implementation of Householder’s Method

I typed the Householder code in _this paper_, which starts on page 7. The code is:                A = {{4., 1., -2., 2.}, {1., 2., 0, 1.}, {-2., 0, 3., -2.}, {2.,             1., -2., -1.}}; (* Made A numeric for speed-up purposes *)      n = Length[A[[1]]];      zeroVector = {};      For[i = 1, i <= n,           zeroVector = Append[zeroVector, {0}];          i++         ];      Alist = {A};      Hlist = {};           For[j = 1, j <= n - 2,           If[A[[j + 1, j]] >= 0, c = 1, c = 2];           alpha = (-1)^c (Sum[A[[k, j]]^2, {k = j + 1, n}])^(1/2);           r = ((1/2) alpha^2 - (1/2) alpha A[[j + 1, j]])^(1/2);           x = zeroVector;           x[[j + 1, 1]] = (A[[j + 1, j]] - alpha)/(2 r);           For[k = j + 2, k <= n,               x[[k, 1]] = A[[k, j]]/(2 r);               k++];           H = IdentityMatrix[n] - 2 x.Transpose[x];           A = H.A.H;          Hlist = Append[Hlist, H]; Print[Hlist];          Alist = Append[Alist, A]; Print[Hlist];          j++];      Of course, the program is complaining with such things as "Sum::write: Tag Set in k=j+1 is Protected." I am just not seeing what is wrong. I added the prints as I want to see intermediate results. Can anyone spot the issue? Is there a better solution or code for this? **Aside:** I wish I could find a nice implementation of this somewhere, but unfortunately I have not been able to find in MMA or the web. I found the following snippet on _Wolfram_, but I cannot make use of it (maybe I am missing something).                HouseholderMatrix[v_?VectorQ] :=     IdentityMatrix[Length[v]]       - 2 Transpose[{v}] . {v} / (v.v)      **End Aside**


What is the formula's are used to convert to meters/second?

Using mathematica, what are the formula's/methods available to convert the following per hour intervals into meters per second (using meters/s from light speed):   * Kilometer   * Mile (US)   * Mile (Nautical)   * Feet The result should be decimal form of each interval with no E+/- in the float section.


Is it Possible to change dashes into circles with Plot command?

Is it possible to change the Dashed Style of a curve into circles with Plot command ?               Plot[Cos[x], {x, 0, 2*Pi}, PlotStyle -> Directive[Dashed, Thickness[0.005]]]      ![enter image description here](http://i.stack.imgur.com/Q1554.jpg)


Is it possible to calculate a Lebesgue integral in Mathematica?

As the title says, I wonder if it is possible to calculate a Lebesgue integral in _Mathematica_ , especially when the domain of integration is $\mathbb{R}^N$, or in other words multivatiate Lebesgue integration is of interest. As an example, one could take $f_0$ and $f_1$ as two different (possibly correlated) bi-variate Gaussian density functions and consider $$\int_{\frac{f_1}{f_0}>\tau}f_0\mbox{d}\mu=\int_{\Large\{x,y:\frac{f_1(x,y)}{f_0(x,y)}>\tau\Large\}}f_0(x,y)\mbox{d}x\mbox{d}y$$ for some known number $\tau$. If it is not possible can one manipulate the existent functions of _Mathematica_ to get a method which can calcuate the Lebesgue integral. I am only interested in very fast numerical methods, no analytical results are needed. **Note** : Why am I asking such a question here?   * I checked google about it and found no answer   * I checked the _Mathematica_ help and found no result   * I searched the keyword "Lebesgue" among the questions in `mathematica.stackexchange.com` but couldnt see any related answer   * I have no idea how I can do it in _Mathematica_


Automatically tracing and keeping ViewPoints in a list while manually rotating 3D graphics

I will need to make a video from the manual rotation of a 3D graphics. In order to do this, I will need to record the set of all view points that I made during rotation. There is method that we can use to get a single viewpoint, like discussed here, but can we find a way to use AppendTo or Sow and Reap to automatically store all the view points in a list?


Is there a better way to add elements to a Graphics expression repeatedly?

Consider simple example where a set of points is generated and some are displayed.               k = 10^5;     p = RandomReal[{-1, 1}, {k, 2}];     n = 2     Graphics[Dynamic@Point@p[[;; n]], Frame -> True, PlotRange -> 1]      > ![enter image description here](http://i.stack.imgur.com/qCbVd.png) Let's plot more and more points from the set:               Dynamic@n     While[n += 100; FinishDynamic[]; n < k - 100]      > ![enter image description here](http://i.stack.imgur.com/iQZJg.png) I find the loop will start to slow down as `n` gets near to 10^5. This should be expected because the code is replotting all the points at each update of the graphics. (Depending on your system, the rate of slowdown my vary.) But each time only 100 points are added while the rest of the displayed image remains the same. Naive thinking tells me that there must be a way to do this better. I have tried many things but with no avail; still, I have a feeling I'm missing something basic.


3d plot for function defined for integer values

I would like to make a plot of a function defined just for integer values, like               f[n_, m_] := 2 - (1/IntegerPart[n]) - (1/IntegerPart[m])      If I try to plot               Plot3D[f[n, m], {n, 1, 6}, {m, 1, 6}, PlotRange -> All,      PlotPoints -> 100, Exclusions -> None,      ColorFunction -> "BlueGreenYellow"]      I need this 100 points to get a "decent" result. This takes a long time, and the result is not very similar as the histogram one. Do you know if there is anyway to do this? Thanks in advance!


Export to PDF - scaling grids of plots and text size

Sometimes I have occasion to make big grids of plots. As a toy example:               lots = GraphicsGrid[     Table[With[{a = RandomInteger[{1, 17}], b = RandomInteger[{1, 17}]},       ParametricPlot[Sin[t^2] { Cos[a t], Sin[b t]}, {t, 0, 2 \[Pi]},           PlotRange->{{-1, 1}, {-1, 1}}, Frame->True]], {15}, {7}]]      Which is a 7 by 15 grid of plots. For ease of viewing, printing and wider distribution; I will often export this to a pdf.               Export["lots.pdf", lots]      This results in a completely rubbish view. You get giant text labels and a graph too small to even see. This can be rectified by fiddling with the scaling:               Export["lots.pdf", lots, ImageSize->2000]      Now the text labels are more in proportion with the graph size. But how do I know what `ImageSize` should be? It depends on how big your graphic grid is, but I know not the voodoo required to get a good result. Alternatively, how can I get the text size to be proportional to the graph size?


Problem with parentheses and ScriptBaselineShifts

Style[      DisplayForm@RowBox[{"(", SubsuperscriptBox[2, 6, 7], ")"}],      18, Bold, ScriptSizeMultipliers -> 1, ScriptBaselineShifts -> {1, 3}]      > ![enter image description here](http://i.stack.imgur.com/sr5tg.png) or for `ScriptBaselineShifts -> {4, 1}` > ![enter image description here](http://i.stack.imgur.com/vKTSM.png) This is at least undesired effect. I'd like to cut those parentheses just below `6`. Why `ScriptBaselineShifts` affects both limits equally? Is there a walkaround?


Getting the complete Cell expression some input would generate as output

I can think of calling `Print` and then `SelectionMove` to copy the expression and then delete it. Is there any more transparent way?


Matlab-style Find in Mathematica? Value list and Boolean List, how to select values according to the boolean list?

I want to select elements with the true value (Indices list) in the corresponding point to the value list (MCS). Is there anything like Matlab- style Find to get the indices of true values in the boolean list and then use it like `MCS[[indicesNumbers]]`? ![enter image description here](http://i.stack.imgur.com/7cWna.png)


Abstract algebra: define constants in a finite field

How can I to define a constant in $Z_{2}$? For example, I want to create a constant `b` that inherits the properties of an element from $Z_{2}$. For example               b + b = 0     b^n = b


Is it possible to convert expressions containing Root objects to Excel formulas?

I am still a beginner and do not fully understand pure functions and root objects. When I tried to calculate the inverse of a function, _Mathematica_ gave me:               f[B_] :=       -744.790486 +        559.361126 Root[-247818634 - 2500 B + 796044875 #1 - 1032864500 #1^2 +          675444825 #1^3 - 222213025 #1^4 + 29396850 #1^5 &, 1] -       0.468197 Root[-247818634 - 2500 B + 796044875 #1 - 1032864500 #1^2 +          675444825 #1^3 - 222213025 #1^4 + 29396850 #1^5 &, 1]^2      _Mathematica_ has no problems evaluating f[B] once B is defined. Simple equations can be easily converted into an Excel-friendly format, but this isn't exactly a simple equation. My question: Is it possible to format this in a way that Excel can generate the same result as _Mathematica_ , or is this simply beyond the scope of what is achievable with Excel?


Disable and Enable Hyperlinks Graphics

![enter image description here](http://i.stack.imgur.com/DKgUA.png) I have a `Graphics` element which I edit with Drawing Tools. I have determined a technique using `NotebookWrite` to add hyperlinks to the selected shape. My question is, how might I disable and enable the hyperlinks so that I can edit the current shape and surround shapes without invoking the links. **Other usability ideas are welcome**


Defining a ForEach function

Consider the following function definition: `ForEach[iterators__] := Table[#, iterators] &;` Two questions about it: I. It works perfectly if you call it like `ForEach[{m,3},{n,3}]@{m,n}` and outputs: $$ \left( \begin{array}{ccc} \{1,1\} & \{1,2\} & \{1,3\} \\ \{2,1\} & \{2,2\} & \{2,3\} \\ \{3,1\} & \{3,2\} & \{3,3\} \end{array} \right) $$ However, the result of `ForEach[{m, 3}, {n, 3}]@ToString[m n]` is: $$ \left( \begin{array}{ccc} \text{m n} & \text{m n} & \text{m n} \\ \text{m n} & \text{m n} & \text{m n} \\ \text{m n} & \text{m n} & \text{m n} \end{array} \right) $$ Why it doesn't treat `m` and `n` as known variables? II. How can I pass a piece of code to the function to be run before each iteration? For instance, I want to call the function with an option like `k=0; ForEach[{m, 3}, {n, 3},Pre->k++]@{k,m,n}` which is the same as `k = 0; Table[k++; {k, m, n}, {m, 3}, {n, 3}]`?


Replace a sum of squared variables by a new variable squared

Is there any way to tell Mathematica to replace $\kappa^2 + k_z^2 \rightarrow k^2$ in an expression? I want to make a result more readable, e.g. something like this: $$\frac{2 k_z^3 \sqrt{k_z^2 + \kappa^2} + 2 k_z \kappa^2 \sqrt{k_z^2 + \kappa^2} + k_z \sqrt{k_z^2 + \kappa^2} \mu^2}{2 (k_z^4 + 2 k_z^2 \kappa^2 + \kappa^4)}$$ * * *               (2 kz^3 Sqrt[kz^2 + κ^2] + 2 kz κ^2 Sqrt[kz^2 + κ^2] + kz Sqrt[kz^2 + κ^2] μ^2)/      (2 (kz^4 + 2 kz^2 κ^2 + κ^4))      * * * Which can be simplified to: $$k_z \frac{ (2k^2 + \mu^2) }{2k^3}$$ But I can't get Mathematica to perform this substitution. I have made sure to use the proper assumptions for this to work:               $Assumptions={k>0};      Yet it seems to not see the (arguably trivial) patterns. Does anyone know how to trick Mathematica into doing what I want :-)?


Dot when used in a pattern becomes Times... Why?

In[1] := Hold[a.b] // FullForm     Out[1] := Hold[Dot[a,b]]      So far so good.                In[2] := Hold[a_.b_] // FullForm     Out[2] := Hold[Times[Optional[Pattern[a,Blank[]]],Pattern[b,Blank[]]]]      Why does the Dot become Times? I have a feeling it has something to do with the Optional that also appears, but I can't find anything that explains what's going on in the documentation.


Pattern matching a multivariate derivative

I can extract the parameters of a single variable derivative with the rule               D[f[x], x] /. Derivative[order_][fcn_][variable_] ->       {order, fcn, variable}      produces               {1, f, x}      How do I generalize this to the multivariate case? For example,               D[f[x, y], x, y] /. Derivative[order_][fcn_][variable_] ->       {order, fcn, variable}      produces ![Mathematica graphics](http://i.stack.imgur.com/0ZhEw.png) The match didn't work -- but I can't seem to reproduce the actual Mathematica display. I'm sure there's some magic syntax that will accomplish the match. I tried a few variations to no avail. Can anyone help? Thanks much.


Speed up replace all

I have large list of rules, I would like to use `list/.rule`, but assume that rule is a set of rules `rule 1, rule2 rule...`I want the Replace All to find first match of rule 1 then apply rule,and so go over to look for match of rule two. This would speed up the process in a very large dataset. I want the first rule on only the first match found, then continue with the next rule from start of the list, if there are any cases of no match go to to next rule. Result would be the list but with applied rules where matches of patterns have been found.If a rule changes a value, and that new value is matched by a later rule, then leave it untouched.(Do not apply rule on al ready changed value) Example:               list={{"02jan2001", "A", 47.98, ""}, {"03jan2001", "A", 52.9312,         ""}, {"04jan2001", "A", 54.9353, ""}, {"05jan2001", "A", 51.9292,         ""}, {"08jan2001", "A", 50.2198, ""}, {"09jan2001", "A", 49.9841,         ""}}          Rules= {{"02jan2001", "A", q$___} -> 0.815473`, {"03jan2001", "A", q$___} ->       0.840296`, {"04jan2001", "A", q$___} -> 0.833659`}      Wanted output `{0.815473, 0.840296, 0.833659, {"05jan2001", "A", 51.9292, ""}, {"08jan2001", "A", 50.2198, ""}, {"09jan2001", "A", 49.9841, ""}}`


Scroll bar glitch when entering full screen mode at magnifications higher than 100%

I noticed that when I enter full-screen mode in Mathematica 9 (F12 for Windows) using a magnification of 125% (or any other number higher than 100%) there is a horizontal scroll bar at the bottom of the screen taking up space, provided that the original windowed notebook had lines long enough to warrant a horizontal scrollbar. This wouldn't be particularly annoying if it weren't for the fact that it's doesn't actually seem to do anything at all; clicking on it moves the scroll bar around, but nothing actually happens onscreen because fullscreen mode automatically wraps everything to the page. For some reason, it still thinks it needs a scrollbar, however, but it doesn't actually work. I suspect this is some kind of glitch/oversight for the frontend? Here's a screenshot (small preview below): ![enter image description here](http://i.stack.imgur.com/zFyfl.png) A simple workaround is to collapse all code into their corresponding orange code blocks onscreen at the time, change magnification to the preferred value, enter fullscreen, and then expand all orange code blocks (at which point the horizontal scrollbar will not load). However, I feel like this kind of editing gymnastics shouldn't be necessary in the first place. If anyone can confirm or deny that this is a frontend visual bug, I'd be glad to hear about it.


Using FindGraphCommunities, write community membership for each vertex to CSV

I have a network that I've loaded into Mathematica, and I've used `FindGraphCommunitites[network,Method->"Hierarchical"]` to identify the communities in the network. I know that I can use `CommunityGraphPlot[network]` to visually plot the graph, however, **I would like to export to CSV a list of each vertex in the graph and the community they belong to.**               ## Import .gml data     network=Import["file.gml"]          ## Run community detection     FindGraphCommunitites[network,Method->"Hierarchial"]          ## Number of communities     Length[FindGraphCommunitites[network,Method->"Hierarchial"]]          ## Number of vertices in each community     Length/@FindGraphCommunitites[network,Method->"Hierarchial"]          ## Plot network with community structure     CommunityGraphPlot[network,Method->"Hierarchial"]


Determing two Nonlinear model fits with 95% confidence bands from one data set

I have the following data which is postulated to have contributions from two different sources .....as can be seen from the confidence band, many points are out of the band. Question: How can I separate the data into two groups such that I can have 2 fitting curves with less data out of confidence band for each cluster?               data = {{17.63, 3794.90}, {19.88, 2410.30}, {21.67, 3282.10}, {23.92,          3153.80}, {24.37, 2846.20}, {24.82, 2487.20}, {25.27,          1692.30}, {26.16, 1564.10}, {27.06, 3205.10}, {27.06,          3692.30}, {27.51, 3384.60}, {29.76, 1307.70}, {30.20,          3615.40}, {31.10, 3282.10}, {33.80, 1179.50}, {40.53,          1051.30}, {47.27, 1871.80}, {47.71, 2589.70}, {49.51,          410.26}, {49.51, 3435.90}, {49.96, 1538.50}, {52.20,          410.26}, {52.65, 948.72}, {52.65, 1179.50}, {54.90,          717.95}, {55.35, 1384.60}, {55.35, 615.38}, {55.80,          846.15}, {56.69, 1897.40}, {57.14, 589.74}, {57.59,          2384.60}, {59.84, 2025.60}, {60.29, 538.46}, {60.29,          358.97}, {62.08, 538.46}, {62.98, 384.62}, {63.43,          1128.20}, {63.43, 615.38}, {63.88, 871.79}, {63.88,          717.95}, {64.78, 461.54}, {64.78, 1615.40}, {65.22,          3743.60}, {67.02, 794.87}, {68.82, 1538.50}, {70.16,          487.18}, {70.16, 897.44}, {72.86, 538.46}, {72.86,          641.03}, {73.76, 435.90}, {74.65, 1538.50}, {74.65,          1205.10}, {75.55, 769.23}, {76.00, 307.69}, {76.45,          410.26}, {76.90, 794.87}, {76.90, 641.03}, {76.90,          538.46}, {80.49, 820.51}, {81.84, 743.59}, {83.18,          512.82}, {86.33, 487.18}, {87.67, 384.62}, {88.12,          1102.60}, {89.02, 871.79}, {94.86, 461.54}, {95.31,          205.13}, {95.76, 333.33}, {96.65, 538.46}, {98.45,          256.41}, {98.45, 461.54}, {98.90, 128.21}, {99.80,          282.05}, {100.24, 666.67}, {100.69, 487.18}, {100.69,          384.62}, {100.69, 153.85}, {102.04, 564.10}, {102.04,          230.77}, {102.94, 974.36}, {102.94, 692.31}, {105.18,          512.82}, {105.18, 282.05}, {105.18, 974.36}, {106.08,          179.49}, {106.53, 1102.60}, {106.98, 615.38}, {107.43,          410.26}, {107.43, 333.33}, {111.92, 384.62}};          nlm = NonlinearModelFit[data, a Exp[-b (x - c)], {a, b, c}, x]          {bands95[x_], bands99[x_], bands999[x_]} =        Table[nlm["MeanPredictionBands",          ConfidenceLevel -> cl], {cl, {.85, .95, .999}}];          Show[ListPlot[data],       Plot[{nlm[x], bands95[x], bands95[x], bands99[x], bands999[x]}, {x,         1, 105}, Filling -> {2 -> {1}, 3 -> {2}, 4 -> {3}, 5 -> {4}}]]      ![Mathematica graphics](http://i.stack.imgur.com/FTzjf.png)


Export/Copy + Paste a plot from Mathematica Trial Version to TeX editor

I wish to get a view plots from Mathematica trial version into a TeX editor, but cannot seem to do it (unless I print the screen and crop the image which leads to bad quality). Is there a way in which I can? I have tried saving the plot as an image file and copying the LaTeX code across but neither will allow me to do so. I should also note that I have a legend for the graph, which seems to be slightly separated... I'd ideally like both to be copied across. Thanks.


Can't compute definite integral

Consider a scalar field (in polar co-ordinates), $f(r) = l-r$. Now I want to evaluate the field integral over a circular region of radius $b$, centered at a distance of $x$ from the origin. According the law of cosines, The arc of radius $r$ from the origin subtends an angle of $\theta = 2 \arccos(\frac{r^2+x^2-b^2}{2 r x}) $ in the circular region. ![enter image description here](http://i.stack.imgur.com/Uf7RR.png) Assuming $x>b$, the integral over the region should be: $$\int_{x-b}^{x+b} r f(r) 2\cos^{-1}[\frac{r^2+x^2-b^2}{2 r x} ] dr$$ Or, $$\int_{x-b}^{x+b} r (l-r) 2\cos^{-1}[\frac{r^2+x^2-b^2}{2 r x} ] dr$$ Since this is a real valued integral with real limits, we should be able to compute the integral. In Mathematica, I have:               Integrate[      2 ArcCos[(r^2 + x^2 - b^2)/(2 r x)] r (l - r), {r, x - b, x + b},       Assumptions -> l > 0 &&  x > b && b > 0 ]      which never evaluates! If, however, I try to do the indefinite integral:               expr = Integrate[2 ArcCos[(r^2 + x^2 - b^2)/(2 r x)] r (l - r), r,        Assumptions -> l > 0 &&  x > b && b > 0 && x - b <= r <= x + b ]      I get the answer               1/18 r ((-9 l + 4 r) x Sqrt[-((           b^4 + (r^2 - x^2)^2 - 2 b^2 (r^2 + x^2))/(r^2 x^2))] -          6 r (-3 l + 2 r) ArcCos[(-b^2 + r^2 + x^2)/(           2 r x)]) - (2 I (b - x)^2 (7 b^2 + x^2) Sqrt[(          b^2 - r^2 - 2 b x + x^2)/(b - x)^2] Sqrt[(          b^2 - r^2 + 2 b x + x^2)/(b + x)^2]           EllipticE[           I ArcSinh[r Sqrt[-(1/(b + x)^2)]], (b + x)^2/(b - x)^2] +          b (9 b l Sqrt[-(1/(b + x)^2)]              Sqrt[-b^4 - (r^2 - x^2)^2 + 2 b^2 (r^2 + x^2)]              ArcTan[(b^2 - r^2 + x^2)/              Sqrt[-b^4 - (r^2 - x^2)^2 + 2 b^2 (r^2 + x^2)]] -             4 I (b - x)^2 (3 b - x) Sqrt[(             b^2 - r^2 - 2 b x + x^2)/(b - x)^2] Sqrt[(             b^2 - r^2 + 2 b x + x^2)/(b + x)^2]              EllipticF[              I ArcSinh[r Sqrt[-(1/(b + x)^2)]], (b + x)^2/(b -                 x)^2]))/(9 r x Sqrt[-(1/(b + x)^2)]          Sqrt[-((b^4 + (r^2 - x^2)^2 - 2 b^2 (r^2 + x^2))/(r^2 x^2))])      which looks ugly, but since there should be no discontinuities, I should be able to evaluate the definite integral as               (expr /. {r -> x + b}) - (expr /. {r -> x - b})      Which gives another ugly answer. Now, if I try to evaluate for some numerical values:               N[((expr /. {r -> x + b}) - (expr /. {r -> x - b})) /. {x -> 5,         b -> 1, l -> 10}]      I get errors such as               Power::infy: Infinite expression 1/Sqrt[0] encountered.      Questions:   1. Why can't we evaluate the definite integral directly?   2. Since the integrand is real and finite, why does the integral give infinity expressions?


FindMinimum gets confused by If[...]

I'm confused by why the following doesn't work. I'm trying to numerically minimize a function that has an If statement in its definition, as follows:               means = {3.0, 1.5, 2.1};         sigmashi = {0.5, 0.4, 0.3};     sigmaslo = {0.4, 0.6, 0.25};     coeffA = {1.2, 3.2, 2.0};     coeffB = {0.3, -0.4, 0.5};     chisq[x_] :=       Sum[If[coeffA[[i]] x + coeffB[[i]] >          means[[i]], (coeffA[[i]] x + coeffB[[i]] - means[[i]])^2/         sigmashi[[i]]^2, (coeffA[[i]] x + coeffB[[i]] - means[[i]])^2/         sigmaslo[[i]]^2], {i, 1, Length[means]}]         FindMinimum[chisq[x], {x, 1.0}]      This returns a long string of error messages: _Part::pspec: Part specification i is neither a machine-sized integer nor a list of machine-sized integers. >> Part::pspec: Part specification i is neither a machine-sized integer nor a list of machine-sized integers. >> Part::pspec: Part specification i is neither a machine-sized integer nor a list of machine-sized integers. >> General::stop: Further output of Part::pspec will be suppressed during this calculation. >> FindMinimum::nrnum: The function value ({0.3,-0.4,0.5}[[i]]+1. <<1>>-{3.,1.5,2.1}[[i]])^2/{0.4,0.6,0.25}[[i]]^2+(2 ({0.3,-0.4,0.5}[[i]]+<<1>>-{3.,1.5,2.1}[[i]])^2)/{0.5,0.4,0.3}[[i]]^2 is not a real number at {x} = {1.}. >>_ Why doesn't FindMinimum like my function? Why does it even care about the "i"? Is there a way to force Mathematica to do the minimization purely numerically, and not care about how the function computes its result? (NMinimize returns the same errors.) I can kluge my way around this with the following alternative:               myif[z_, x_, y_] := ((Tanh[100 z] + 1)/2) x + ((Tanh[-100 z] + 1)/2) y     chisqA[x_] :=       Sum[myif[coeffA[[i]] x + coeffB[[i]] -          means[[i]], (coeffA[[i]] x + coeffB[[i]] - means[[i]])^2/         sigmashi[[i]]^2, (coeffA[[i]] x + coeffB[[i]] - means[[i]])^2/         sigmaslo[[i]]^2], {i, 1, Length[means]}]      But it isn't pretty.


Solving a system with three equations and two variables

I am trying to solve some equations with two variables. This is the last step in the process of determining a `x` tilt angle of a molecule, as well its depolarization ratio `r` . To do so, I've defined the three equations:               Xsps[x_,r_]:=0.659*0.696*0.716*Sin[61°]*0.5*(1-r)*(Cos[x]-Cos^3[x])          Xssp[x_,r_]:=(0.659*0.65*0.702*Sin[54°])*0.5*(Cos[x]*(1+r)-(1-r)*Cos^3[x])          Xppp[x_,r_]:=-(1.006*1.077*0.702*Cos[60°]*Cos[61°]*Sin[54°]*0.5*(Cos[x]*(1+r)-(1-r)*       (Cos^3[x])))-(1.006*0.696*1.022*Cos[60°]*Sin[61°]*Cos[54°]*0.5*(1-r)*       (Cos[x]-(Cos^3[x])))+(0.704*1.077*1.022*Sin[60°]*Cos[61°]*Cos[54°]*0.5*(1-r)*       (Cos[x]-(Cos^3[x])))+ (0.704*0.696*0.702*Sin[60°]*Sin[61°]*Sin[54°]*       (r*Cos[x]+(Cos^3[x])*(1-r)))       To find the solutions for `r` and `x` (two variables on the above equations), I’ve build a system with two equation, where:               (Xssp/Xpp)^2=(0.120/0.076)^2, (Xsps/Xpp)^2=(0.102/0.076)^2      To solve such system for `x` and `r` using _Mathematica_ , I’ve faced some difficulties since I am a beginner with the software. I’ve tried to solve it using the following code, but unsuccessfully:               Nsolve[{(Xsps/Xppp)^2 = (0.076/0.120)^2, (Xssp/Xppp)^2 = (0.076/0.102)^2}, x, r]      Please, I would love to have some help with this issue. Looking forward for any piece of advice. Following bellow the work code;               Xsps[x_, r_] =       0.659*0.696*0.716*       Sin[61 °]*0.5*(1 - r)*(Cos[x] - (Cos[x]*Cos[x]*Cos[x]))          Xppp[x_, r_] = -(1.006 *1.077*0.702*Cos[60 °]*          Cos[61 °]*          Sin[54 °]*{0.5*(Cos[                x]*(1 + r) - (1 - r)*(Cos[x]*Cos[x]*                 Cos[x]))}) - (1.006*0.696*1.022*Cos[60 °]*         Sin[61 °]*         Cos[54 °]*{0.5*(1 -              r)*(Cos[x] - (Cos[x]*Cos[x]*Cos[x]))}) + (0.704*1.077*1.022*         Sin[60 °]*Cos[61 °]*         Cos[54 °]*{0.5*(1 -              r)*(Cos[x] - (Cos[x]*Cos[x]*Cos[x]))}) + (0.704*0.696*0.702*         Sin[60 °]*Sin[61 °]*         Sin[54 °]*{(r*Cos[x] + (Cos[x]*Cos[x]*Cos[x])*(1 - r))})          Xssp[x_, r_] = (0.659*0.650*0.702*         Sin[54 °])*{0.5*(({Cos[x]}*(1 + r)) - ((1 - r)*{Cos[x]*               Cos[x]*Cos[x]}))}          NSolveolve[{(Xsps/Xppp)^2 == (0.076/0.120)^2, (Xssp/Xppp)^2 == (0.076/          0.102)^2}, x,  r]


Parallel evaluation of Image and Rasterize problem

The following command:               ParallelTable[Image[Graphics[{{Red, Disk[{5, 5}, 4]}}]], {i, 10}]      shows a very strange behaviour. It starts a new _Mathematica_ process on every Parallel Kernel, so that using 6 Kernels I end up with 7 _Mathematica_ Processes and 14 MathKernels running. With `Rasterize` it is the same. Can anyone explain/help?


How do I make an EventHandler non-responsive to MouseMoved after a mouse click?

Consider the following code. After evaluating it, when I move the mouse over the output `text`, it prints 1, and when I click the mouse on `text`, it prints 2.               EventHandler["text", {"MouseMoved" :> (Print[1]), "MouseDown" :> (Print[2])}]      I want to modify this so when I move the mouse over the output `text`, it prints 1, and when I click on `text`, it prints 2 and stops printing 1. How do I do this?


Smooth Max and Abs

I'm trying to implement smooth approximations of Max and Abs functions. Moreover I want the functions to map element-wise on tensors. Here's my code.               $Assumptions = {        Element[A, Arrays[{i, j, k}, Reals]],        Element[Nlarge, Reals] (* Nlarge tends to infinity *)        };     Hyper[x_] := Map[Exp[Nlarge #1] &, x, -1]     Hypo[x_] := Map[Log[#1]/Nlarge &, x, -1]     SMax[x__] := Hypo[Plus @@ (Map[Hyper, {x}])]     SAbs[x_] := SMax[x, -x]     SAbs[A] // TensorDimensions      I'm expecting it to return {i, j, k}, but instead I get {}. What's wrong with it?


What is causing a type error when trying to modify Mathematica state from a function linked with LibraryLink

I've managed to reduce my problem to a very simple C program:               #include "mathlink.h"     #include "WolframLibrary.h"          int SetX( WolframLibraryData libData )     {         int errorCode;         int nextPacket;         MLINK link = libData->getMathLink( libData );         MLPutFunction( link, "EvaluatePacket", 1 );         MLPutFunction( link, "Set", 2 );         MLPutSymbol( link, "x" );         MLPutDouble( link, 3.14159 );         errorCode = libData->processMathLink( link );         if ( errorCode != 0 )             return errorCode;         nextPacket = MLNextPacket( link );         if ( nextPacket == RETURNPKT )             MLNewPacket( link );         return 0;     }          DLLEXPORT int WolframLibrary_getVersion()     {         return WolframLibraryVersion;     }          DLLEXPORT int WolframLibrary_initialize(WolframLibraryData libData)     {         return 0;     }          DLLEXPORT int testIt(WolframLibraryData libData, mint argc, MArgument*                          margs, MArgument result)     {         int error = SetX( libData );         if ( error != 0 ) {             libData->Message( "error setting x" );         }         return error;     }      I use `AppendTo` to add the directory containing the compiled shared object/Dll to `$LibraryPath`, then do:               In[4]:= LibraryFunctionLoad[ "CB", "testIt", {}, Void ]     Out[4]= LibraryFunction[ <>, testIt, {}, {}]          In[5]:= %[]     During evaluation of In[5]:= LibraryFunction::error setting x: -- Message text not found -- >>     During evaluation of In[5]:= LibraryFunction::typerr: An error caused by inconsistent types was encountered evaluating the function testIt. >>     Out[5]= LibraryFunctionError[LIBRARY_TYPE_ERROR,1]      Regretfully, the error message doesn't tell me what type is wrong, and what type I should be using instead. (I've tried using `MLPutString`, insteamd of `MLPutSymbol`, in the above, with the same results.) I've tried this with the same results under Windows and Linux, so I don't think it's a problem with the build procedure I'm using; but FWIW, here is the command line used to build the shared object under Linux:               Gabi (41): echo $MATHINCL         -I /usr/local/Wolfram/Mathematica/8.0/SystemFiles/IncludeFiles/C -I /usr/local/Wolfram/Mathematica/8.0/SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions         Gabi (42): echo $MATHLIB     /usr/local/Wolfram/Mathematica/8.0/SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/libML64i3.so     Gabi (43): gcc -shared -fPIC $MATHINCL CB.c $MATHLIB -o CB.so      (I use something similar from CygWin bash under Windows, with options /MDd and /Tc.)


how to associate a metric for tensor contraction operations?

I see that Version 9 now has some built in tensor support (which was missing back when previously asked How to represent and manipulate abstract indexed vector (or tensor) expressions?). The docs appear to describe the following as tensor operations               Clear[a, b, x , y]     a = Array[x, 2]     b = Array[y, 2]     m = { {1, 0}, {0, 1}}     n = { {1, 0}, {0, -1}}     a . m . b     a . n . b      Here I am "contracting" two rank 1 tensors, using a Euclidean and Minkowski metric tensor respectively. Is there a way to associate a desired metric tensor for a set of operations so that I can contract my vectors in a more natural way? I suspect that the new builtin tensor support is supposed to be used differently than this (i.e. this doesn't seem like anything new, other than calling the array a tensor). Also, is there a way to have this Array "tensors" display in an indexed fashion? How would you specify if the tensor variable is upper or lower indexed? EDIT: It was pointed out in the comments that Assumptions can be used to declare a symbolic tensor, but it's not obvious to me how to make this do something useful. For example, if declare               $Assumptions = c \[Element] Matrices[{2, 1}, Reals] ;          $Assumptions = d \[Element] Matrices[{2, 1}, Reals] ;     $Assumptions = e \[Element] Matrices[{1, 2}, Reals] ;         $Assumptions = f \[Element] Matrices[{1, 2}, Reals] ;      I'd assume one of these pairs of declarations (I'm not sure which), to be a rank 1 tensor with two elements, but if I try to contract this as I did above with the array declaration               c . n . d     e . n . f      I get:               c.{{1, 0}, {0, -1}}.d     e.{{1, 0}, {0, -1}}.f      respectively. I can also manually "declare" a subscript notation "tensor"               w = {Subscript[u, 1], Subscript[u, 2]}      q = {Subscript[v, 1], Subscript[v, 2]}       While I'm not sure how to declare this with Array, or some other less manual way, this at least solves the notation issue. I can then contract that with `w. n . q` yielding $u_1 v_1-u_2 v_2$ Again, none of this looks like it is anything what I'd expect from the advertised new "native" version 9 support for tensors (something like what the Ricci package appears to support).


Solve this equation symbolically

I am trying to solve the equation for the quantity r = y/x symbolically:               3/y^4 == 3/x^4 + a/(x + 2 y)^4        with the requirement that we need to perform the substitution y -> r x and use **Thread** to factor both sides of the equation at the same time. Here is my attempt:               In: {3/y^4 == 3/x^4 + a/(x + 2 y)^4} /. y-> r x        > Out: {3/(r^4 x^4) == 3/x^4 + a/(x + 2 r x)^4} But the above method of course is not completely correct. If I used thread, the output does not change:               In: Thread[{3/y^4 == 3/x^4 + a/(x + 2 y)^4} /. y-> r x]        > Out: {3/(r^4 x^4) == 3/x^4 + a/(x + 2 r x)^4} Then I think I have to factor them first by using Thread to both sides:               In: Solve[Thread[Factor[{3/y^4 == 3/x^4 + a/(x + 2 y)^4} /. y -> r x], Equal], r]      > Out: {{r -> Root[-3 - 24 #1 - 72 #1^2 - 96 #1^3 + (-45 + a) #1^4 + 24 #1^5 + > 72 #1^6 + 96 #1^7 + 48 #1^8 &, 1]},   >  {r -> Root[-3 - 24 #1 - 72 #1^2 - 96 #1^3 + (-45 + a) #1^4 + 24 #1^5 + 72 > #1^6 + 96 #1^7 + 48 #1^8 &, 2]},   >  {r -> Root[-3 - 24 #1 - 72 #1^2 - 96 #1^3 + (-45 + a) #1^4 + 24 #1^5 + 72 > #1^6 + 96 #1^7 + 48 #1^8 &, 3]},   >  {r -> Root[-3 - 24 #1 - 72 #1^2 - 96 #1^3 + (-45 + a) #1^4 + 24 #1^5 + 72 > #1^6 + 96 #1^7 + 48 #1^8 &, 4]},   >  {r -> Root[-3 - 24 #1 - 72 #1^2 - 96 #1^3 + (-45 + a) #1^4 + 24 #1^5 + 72 > #1^6 + 96 #1^7 + 48 #1^8 &, 5]},   >  {r -> Root[-3 - 24 #1 - 72 #1^2 - 96 #1^3 + (-45 + a) #1^4 + 24 #1^5 + 72 > #1^6 + 96 #1^7 + 48 #1^8 &, 6]},   >  {r -> Root[-3 - 24 #1 - 72 #1^2 - 96 #1^3 + (-45 + a) #1^4 + 24 #1^5 + 72 > #1^6 + 96 #1^7 + 48 #1^8 &, 7]},   >  {r -> Root[-3 - 24 #1 - 72 #1^2 - 96 #1^3 + (-45 + a) #1^4 + 24 #1^5 + 72 > #1^6 + 96 #1^7 + 48 #1^8 &, 8]}} I am not sure whether my approach is correct. Then if I want to plot the solution for a$\in${-1,1} which is to examine the number of solutions which are real-valued. Here is what I did:               Plot[Table[Solve[Thread[Factor[{3/y^4 == 3/x^4 + a/(x + 2 y)^4} /. y -> r x], Equal], r], {a, -1, 1, 0.02}], {r, -100, 100}]      The output showed error and said ivar is not a valid variable. I am not sure what went wrong and how to fix it. Any helps and comments are greatly welcomed. Many thanks.


I need to move all the variables(x,y,z) to one side of an equality for the equation of a plane

I have `5(x-1)-(y+1)-(z+1)==0`. If I use `FullSimplify` on it it returns `5x==7+x+y`. This is not what I want: I want it to return `5x-y-z==7`.


Deleting elements on a list by the first element of another list

I was trying to make this               L1 = {{2, 1}, {6, 4}, {8, 7}, {9, 5}};     L2 = {{2, 9}, {9, 6}};     L = Union[L2 , L1]      And I used this:               Cases[L, {{a_, _}, {b_, _}} /; a == b]     Complement[L,L2]      And this:               DeleteCases[L, MemberQ[L1, {#[[1]], _}] & /@ L2]      But, both fail. The answer must take from L1 only the elements where the first element appear in L2. For L1 and L2 above, must return               {{2,1},{9,5}}       And {6, 4} and {8, 7} must be dropped from L2! Thanks,


Handing a list of constraint expressions to a C++ function with MathLink

I need to solve an optimization problem, which is defined in a Mathematica notebook. Using Mathematica's `FindMinimum` is not an option, because it is too slow. So, the idea is to use an external solver for quadratically constraint quadratic problems and use MathLink to get the constraints of the problem from Mathematica, calculate the solution, and return the solution to Mathematica. And here is my problem: The constraints (quadratic and linear) are given to me as a list of expressions, e.g.               { -1+(-0.363263+x)^2+(-0.329466+y)^2<=0,     -1+(-0.248721+x)^2+(0.451803 +y)^2<=0,      -1+(0.33444 +x)^2+(-0.41341+y)^2<=0,      -1+(0.414249 +x)^2+(0.384528 +y)^2<=0,      -1+(-0.65488+x)^2+(0.242478 +y)^2<=0,      -1+(-0.176244+x)^2+(0.30843 +y)^2<=0,      -1.4+x<=t, -0.5+y<=t, 0.4 -x<=t, -0.5-y<=t }      How do I deal with such a list in my C++ function? Do I need to change its template signature so that it takes a SymbolList instead of a RealList (as in my current version)? Or is there a way to extract all the numbers in my constraint list and put them in a list in Mathematica?


Converting a string containing whitespace-delimited numbers to a list of numbers

Suppose I have a string `str` that contains only whitespace-delimited real numbers:               str = " 0\t1.46604\t1.44829\t12.0546\t1.57075\t1.64044\t12.0489\t1.58142";      I would like to convert `str` to a list of real numbers. One way to accomplish this is to split the string using `StringSplit` and then `Map` the function `ToExpression` across the resulting list:               Map[ToExpression, StringSplit[str]]      which gives the correct output: > {0, 1.46604, 1.44829, 12.0546, 1.57075, 1.64044, 12.0489, 1.58142} But, is there a cleaner or more efficient way to do this? I will be converting about 100,000 strings `str` -- each of which are approximately the same length as the example `str` above -- which will be read as records from a text file (i.e., using `OpenRead` and `Read`), so it would be nice if the method is relatively efficient. Thank you for your time!


Formatting and printing lists with Mathematica scripts

I'm just starting out with _Mathematica_ and I'm using `MathematicaScript` rather than the GUI. However, I'm having trouble formatting a list when printing it. Suppose I have a list and I want to print it using `Column`:               list = {a, b, c};     Print[Column[list]];      Calling this outputs `Column[{a, b, c}]` rather than               a     b     c      I suspect that this is because I'm running _Mathematica_ in script mode. Is there anything I can do to display a list like this? How can I verify what the cause of my problem is from the documentation (I'm having trouble running the GUI)? The documentation doesn't say anything about `Column` only working in GUI mode. I assume that the answer to getting a list (if there is one) to display as a column will explain how to do the same for a grid with 2D lists.


Error solving third order ODE in version 10. No error in V9. DSolve`DSolveKovacicDump`

This is an ode which is solved with no error in V9, but gives a very strange error in V10. Is this a regression bug? On version 9, the ode is solved with no error                 $Version       (* 9.0 for Microsoft Windows (64-bit) (January 25, 2013) *)       ClearAll[x, y]       ode = ((30 + 4 x)y[x]+5(-6 + x)x y'[x] +x^2(3 + x) y''[x]+ x^3 y'''[x] == 0);       DSolve[ode, y[x], x]      ![Mathematica graphics](http://i.stack.imgur.com/4pj6Z.png) Now on version 10                $Version      (*10.0 for Microsoft Windows (64-bit) (June 29, 2014)*)      ClearAll[x, y];      ode = ((30 + 4 x) y[x] +5(-6 + x) x y'[x] +x^2 (3 + x)y''[x]+x^3 y'''[x] == 0);      DSolve[ode, y[x], x]      I get screen full of errors ![Mathematica graphics](http://i.stack.imgur.com/1Q0DU.png) At the bottom I see the same solution as given by Version 9 ! This happens after I restart the kernel, on fresh session. The computation takes few minutes (on my PC it took 5 minutes, old PC). Reproducible. I am on windows 7, 64 bit. Can other reproduce this? Any idea what might be causing it?


How to define UpValues in a different context from within a package

I'm trying to create a function (in a package) to import a lot of data and create a symbol with UpValues to return specific results about the data. I've got it working fine in a regular notebook, but when I define the function within a package I can't get it to work properly. A simple example of my problem: TestPackage.m:               BeginPackage["TestPackage`"];          testFunction::usage= "testFunction[] does all kind of interesting things.";          Begin["`Private`"]          testFunction[name_Symbol]:=      Module[{},(       ClearAll[name];       UpValues[name]=        {         test[name]->"hello!"        };       Protect[name];      )]          End[]          EndPackage[]      I then call the function in a regular notebook:               Needs["TestPackage`", "/path/to/TestPackage.m"]          testFunction[a]        * `test[a]` returns `test[a]`   * and `TestPackage`Private`test[a]` returns the expected `"hello!"` How do I change `testFunction` so that `test[a]` also returns `"hello!"`?


How to make use of NumericQ[x] = True (and use it safely)?

* * * ## Basic Issue: I'm trying to understand the proper use of `NumericQ`'s "magical" capabilities. Please consider the examples below. Actual question and some links are at the very end. * * * ## Example 1: Many of you are aware that `NumericQ` can be used as follows, without unprotecting:               In[1]:=              Remove[x, y];             NumericQ[x] = True;             (*and apparently using TagSet instead of Set makes no difference because \             you can't direct, let alone see, where this type of info is stored \              anyways.*)      The following output is as expected:               In[3]:=              NumericQ[x]             NumericQ[y]          Out[3]= True     Out[4]= False      Go ahead and make the following assignment:               In[5]:= x = y          Out[5]= y      The following behavior is interesting, but quite reasonable. It seems logical that setting `x` to `y` would somehow globally overwrite the "magical" numeric property:               In[6]:=              NumericQ[x]             NumericQ[y]          Out[6]= False     Out[7]= False      ### _Hmmm... #1_ ...Well, at least I thought it would have 'overwritten' the behavior!!               In[8]:=              (*Note: Could also use Clear[x] or ClearAll[x] *)             x =.             NumericQ[x]          Out[9]= True      * * * ## Example 2: Now suppose we had made the assignment `x = y` _first_ (before evaluating `NumericQ[x] = True`):               In[12]:=               Remove[x, y];              x = y          Out[13]= y      ### _Hmmm... #2_ Now _Mathematica_ has pushed the numerical property onto `y` as well.               In[14]:=               NumericQ[x] = True              NumericQ[y]          Out[14]= True     Out[15]= True      * * * * * * ## Question: How can one put `NumericQ[x] = True` to good/powerful use---and just as importanltly, in light of the above examples, how can it be used safely? (i.e., Can this behavior be localized somehow? Used safely within a package? ---intuition makes me wonder if the only way to isolate the behavior would be to store impacted symbols in a junk context or something.) **Links of Interest:** @Szabolcs 'Mathematica Tricks' page; scroll down about half way or search for `NumericQ`: http://web.ift.uib.no/~szhorvat/mmatricks.php MathGroup Discussion: https://groups.google.com/forum/?fromgroups=#!topic/comp.soft- sys.math.mathematica/buxdxzwV4bY


ComplexInfinity/Indeterminate error when evaluating derivative

**Motivation:** I want to find the coefficients for the polynomial that is obtained when one adds together the first $n$ natural numbers to the power of $a$; that is, when you consider $1^{a} + 2^{a} + \cdots + n^{a}$. The way I wanted to do this was: find the polynomial, then take the $j$-th derivative, evaluate at 0, and divide by $j!$. My code to _just_ obtain the polynomials and to take the derivatives are:               f[n_, a_] = Sum[i^(a), {i, 1, n}]     g[d_, a_, n_] = Derivative[d, 0][f][n, a]      So, for example, $g[1,2,n]$ is the first derivative (with respect to $n$) of the polynomial corresponding to $1^2 + 2^2 + \cdots + n^2$. **The Problem:** If I try $g[1,2,r]$ or $g[2,2,r]$, everything is fine. If I attempt to try $g[3,2,r]$ (the third derivative, which should just be 2) I get the error:               Infinity::indet: Indeterminate expression 0 ComplexInfinity encountered. >>      I'm not sure what I'm doing wrong; this is true for $g[d,a,n]$ in general, if $d = a+1$. I'm using Mathematica 8.


How to ensure that command line variables are secure for MathKernel scripts?

Suppose I write a Mathematica script, called test.m, like the following:               Print["Hello, World!"];     test = ToExpression[$CommandLine[[-1]]];     Print["I'm alive!"];      and then I try to call that script from the command line like so:               math -script test.m a";Print[LOLOL];Quit[]"      I get the following output:               "Hello, World!"     LOLOL      Naturally, this scares me. I'm hoping to have a way to interpret command line arguments in a secure way. Can anyone help?


Initialization Cells in CDF

I am wanting to run about 15 pages of initialization cells in a CDF, but can't seem to do so. I have set the InitializationCellEvaluation to True and InitializationCellWarning to False, but it doesn't work in the CDF. (works just fine in the .nb) I saw something about the NotebookDynamicExpression, but I wasn't sure how to run a ton of code through it. Are there any alternatives? I use no Manipulate or Dynamic functions in my code either. For example...               GenerateDisplayShotsFor :=        Quiet[Button[         Style["GENERATE", Bold, FontFamily -> "Terminal", 20,           Background -> LightBlue],          CreateWindow[          DocumentNotebook[DisplayShotsFor, WindowTitle -> "Shots For",            WindowFrame -> "ModelessDialog",            Background -> RGBColor[48/240, 164/240, 220/240],            Editable -> False, TextAlignment -> Center ,            WindowFloating -> False,            WindowMargins -> {{0, Automatic}, {Automatic, 0}}]]]];


Keep Mathematica from simplifying functions with a specified Head

I want to run `Simplify` and/or `Refine` on various expressions, but keep it from touching anything that contains a specific `Head`. For example, I would like to `Refine` the following expression under the assumption `x>0` but not do anything with any part of the expression whose `Head` is `Log`:               expr = Sqrt[x^4] Log[x^2] + Log[x^4];     Refine[expr, x>0]      Instead of               (* 4 Log[x] + 2 x^2 Log[x] *)      I would like to see               (* x^2 Log[x^2] + Log[x^4] *)      Where the Logarithms remain unsimplified


Building a list recursive with one or more arguments

Consider the following:               data={a,b,c,d};     res={{a,b,c,d},{b,c,d,e},{c,d,e,f},{d,e,f,g}};      The idea is to define a function `MyFunction` which will return `res` when applied on `data`. Please note that for every recursive step the function will delete the first element of a 4-tuple and append one element to this tuple. I had the following idea which worked but maybe somebody has a much shorter version:               ListBuilder[data_] := Module[       {data1 = data, data2, data3, data30},            data2 =         Join[{data1}, {data1 /. {a_, b_, c_, d_, e_, f_, g_, h_} :>             Flatten@{b, c, d, e, f, g, h,               Round@RandomVariate[NormalDistribution[1000, 0.1*1000], 1]}}];            data3 =         Join[data2, {data2[[-1]] /. {a_, b_, c_, d_, e_, f_, g_, h_} :>             Flatten@{b, c, d, e, f, g, h,               Round@RandomVariate[NormalDistribution[1000, 0.1*1000], 1]}}];            While[Length@data3 < 8,         data3 = Join[          data3, {data3[[-1]] /. {a_, b_, c_, d_, e_, f_, g_, h_} :>              Flatten@{b, c, d, e, f, g, h,                Round@RandomVariate[NormalDistribution[1000, 0.1*1000],                  1]}}];        data3];       data3            ]          SeedRandom[32452345]     NumData = Round@RandomVariate[NormalDistribution[1000, 0.1*1000], 8]     NumRes=ListBuilder@NumData      **EDIT** It would also be interesting to allow list building with more than one argument (e.g. answer by YvesKlett.) Does anyone have an idea?


Package relative file path specification

I have some packages inside a folder (named Packs) that is in the same file level of some executed package.               executedPack.m     Packs/subPack01.m     Packs/subPack02.m     Packs/subPack03.m      Today I use this structure do load the sub packages inside the executedPack.m:               (*Execution without Front-End*)      Needs["MyPack`",FileNameJoin[{DirectoryName@$InputFileName,"Packs","subPack01.m"}]]          (*Execution with Front-End*)         Needs["MyPack`",FileNameJoin[{NotebookDirectory[],"Packs","subPack01.m"}]]      The first I use when running the package without front-end, and the last when I evaluate in the front-end. There is some simpler way to do that, more symmetric? I read some kernel folder structure, but I didn't find more details on that. ## Update Now what I want, but better. This works both in Fron-End and no Front-End execution.               Quiet[Check[SetDirectory@DirectoryName@$InputFileName,SetDirectory@NotebookDirectory[]],SetDirectory::fstr];     Needs["Packs`subPack01`"];


Can code optimize code?

Are there functions, programs or packages that deal with optimizing mathematica code i.e. re-writing ineffecive or convoluted code. -This question has haunted me since I joined SE. The background for my question being the following: I have noticed that a considerable amount of answers and comments deal with trying to improve a given code sample. It is fascinating to see in how many ways a particular problem can be solved and often there is an unspoken and cheerful competition as who can write the fastest and or shortest code that does the job. - This creates an extremely creative and positive atmosphere here. Given the above, the answer to my question could be **no**. However: Since Mathematica must be considered extremely powerful with, patterns, rules and an extensive set of built-in functions and advanced algorithms, it seems quite reasonable to expect that someone has tried to write a code optimizing program, at least on a very basic level. So the answer could be **yes**. So to recap: Does there exist any program/function/package that give the user feedback in better or alternative code?


Getting consistent Ticks lengths and TickLabels positioning

From the Documentation, > Tick mark lengths are given as a fraction of the distance across the whole > plot. I wish to have identical _tick mark lengths_ for both horizontal and vertical ticks and I wish them to look outside of the plot area. For this I multiply the horizontal tick lengths by `GoldenRatio` that is the default for `Plot`-like functions:               Plot[Cos[x], {x, 0, 10}, Frame -> True, Axes -> False,      FrameTicks -> {{{0, 0, {0, .2 GoldenRatio}}, {Pi,           180, {0, .2 GoldenRatio}}, {2 Pi,           360, {0, .2 GoldenRatio}}, {3 Pi,           540, {0, .2 GoldenRatio}}}, {{0, 0, {0, .2}}}}]      ![plot](http://i.stack.imgur.com/N6pL3.png) As you see, the horizontal `TickLabels` are positioned correctly but at the bottom and at the top the real length of ticks are ignored and `TickLabels` are positioned as it is by default (if I remove the `GoldenRatio` multiplication). Is it possible to position `TickLabels` correctly?


URLFetch functionality for a Persian website

I want to fetch the content of a Persian website. I tried                URLFetch["http://www.tsetmc.com/"]      Why is _Mathematica_ unable to recode the characters in the results retuned? Why do they look strange? The problem is not a matter of the language because, for some Persian websites, the function works. But what goes wrong when I access this particular website? Here is an extract from the data `URLFetch` retuned               :\.18ìî?'û \.0fÎ®øoí]Ùim/*¯^ï\é\[CenterDot]º îô \     \.16û\[CenterDot]ÂÞ¥?Þhî\.04í \[RawEscape]kíîfûB¿»ÓÜ£Í¸ÿy?¾\     \[Paragraph]Ø¸q©ñ\.b3þ¥3Ø©¦u5X®këívðoÿ \.06¯ýd-ýD/7køfðó_ü \     \.02¦û+nÜë/.éþ&ênÇÅ zq!     \.16ú½ø \.06[Ù{+íns# Þ½í/ÿ[m~çg\.0b?½\.b4ð\.b3Þðj\.b3ÝÝ»½¸\.b3\     \[PlusMinus]¿\[CenterDot]t¦¿\.06/ðâv\[CenterDot]Ó/Æ_âx\.16û¿íGí¸\.b3\


an NIntegrate inside a manipulate in mathematica was working and suddenly won't work now. it says indeterminent and it doesn't make any sense why

my title says pretty much everything heres what I'm entering. `NumericQ` returns a false value but it was true before. Im loosing my patience because this is so infuriating and makes no sense.               Manipulate[      1.054*10^-34/(2 .063*9.11*10^-31) (NIntegrate[          kz^2 kp (kz^2 (Vz) + kp^2 (Vp))^(-1/              2)*(1/(kz^2 +                kp^2))*((Exp[-1/                   8 ((1.054*10^-34 (kp^2 + kz^2)/(2 .063*9.11*10^-31) -                        kz Vd + 1.88*10^11)^2/(kz^2 + kp^2))] +                 Exp[-1/8 ((1.054*10^-34 (kp^2 + kz^2)/(2 .063*9.11*10^-31) +                        kz Vd + 1.88*10^11)^2/(kz^2 + kp^2))]) (Coth[                 1/2] + 1) + (Exp[-1/                   8 ((1.054*10^-34 (kp^2 + kz^2)/(2 .063*9.11*10^-31) -                        kz Vd - 1.88*10^11)^2/(kz^2 + kp^2))] +                 Exp[-1/8 ((1.054*10^-34 (kp^2 + kz^2)/(2 .063*9.11*10^-31) +                        kz Vd - 1.88*10^11)^2/(kz^2 + kp^2))]) (Coth[                 1/2] - 1)), {kp, 0, 2792.530}, {kz, 0,            2792.530}])/(NIntegrate[          kz^2 kp (kz^2 (Vz) + kp^2 (Vp))^(-3/              2)*(1/(kz^2 +                kp^2))*(((1.054*10^-34 (kp^2 + kz^2)/(2 .063*9.11*10^-31) -                    kz Vd +                    1.88*10^11) Exp[-1/                    8 ((1.054*10^-34 (kp^2 + kz^2)/(2 .063*9.11*10^-31) -                         kz Vd + 1.88*10^11)^2/(kz^2 +                        kp^2))] + (1.054*10^-34 (kp^2 +                        kz^2)/(2 .063*9.11*10^-31) + kz Vd +                    1.88*10^11) Exp[-1/                          8 ((1.054*10^-34 (kp^2 + kz^2)/(2 .063*9.11*10^-31) +                         kz Vd + 1.88*10^11)^2/(kz^2 + kp^2))]) (Coth[                 1/2] + 1) + ((1.054*10^-34 (kp^2 +                        kz^2)/(2 .063*9.11*10^-31) - kz Vd -                    1.88*10^11) Exp[-1/                    8 ((1.054*10^-34 (kp^2 + kz^2)/(2 .063*9.11*10^-31) -                         kz Vd - 1.88*10^11)^2/(kz^2 +                        kp^2))] + (1.054*10^-34 (kp^2 +                        kz^2)/(2 .063*9.11*10^-31) + kz Vd -                    1.88*10^11) Exp[-1/                    8 ((1.054*10^-34 (kp^2 + kz^2)/(2 .063*9.11*10^-31) +                         kz Vd - 1.88*10^11)^2/(kz^2 + kp^2))]) (Coth[                 1/2] - 1)), {kp, 0, 2792.530}, {kz, 0,            2792.530}]), {Vz, .00360, .0750}, {Vp, .00360, .0750}, {Vd, 0,        4}]      Also I should add my computer died before it stopped working but I did save. This really makes no sense I cannot understand why it was working fine and now it isn't. I saved it also after I knew it was working well.


How to make a tight crop of a 3d plot?

I like Mathematica, but it's syntax baffles me. I am trying to figure out how to minimize the whitespace around a graphic. For example,               ParametricPlot3D[{r Cos[t], r Sin[t], r^2}, {r, 0, 1}, {t, 0, 2 \[Pi]},       Boxed -> True, Axes -> False]      ![3d bounding box on](http://i.stack.imgur.com/jGpvA.png) Puts the 3d bounding box at the limits of the view. But if I don't show the 3d bounding box, ![3d bounding box on](http://i.stack.imgur.com/jGpvA.png)               ParametricPlot3D[{r Cos[t], r Sin[t], r^2}, {r, 0, 1}, {t, 0, 2 \[Pi]},       Boxed -> False, Axes -> False]      ![3d bounding box off](http://i.stack.imgur.com/E8skr.png) there is all this white space around the actual object. Is there some way (syntax) that can put the view just around the visible objects? # Edit in response to answers Ok, from the below answers, I have two solutions; 1) use ImageCrop, or 2) use `Method->{"ShrinkWrap" -> True}`. However both of these options do a little something strange to the plot I want (maybe it is just a problem with the plot itself). So the actual plot I am after is,               Module[{r = 1, \[Theta] = \[Pi]/2, \[CurlyPhi] = \[Pi]/6, \[Psi] = \[Pi]/12},     Framed@Show[      Graphics3D[       {        {Arrowheads[.025],         Arrow[{{0, 0, 0}, {1.1, 0, 0}}], Text["x", {1.2, 0, 0}],         Arrow[{{0, 0, 0}, {0, 1.1, 0}}], Text["y", {0, 1.2, 0}],         Arrow[{{0, 0, 0}, {0, 0, 1.1}}], Text["z", {0, 0, 1.2}],         Arrow[{{0, 0, 0}, r {Cos[\[Theta]] Sin[\[CurlyPhi]],            Sin[\[Theta]] Sin[\[CurlyPhi]], Cos[\[CurlyPhi]]}}]},        {Specularity[White, 50], Opacity[.1], Sphere[{0, 0, 0}, r]}        },       Boxed -> False,       ImageSize -> 600,       PlotRange -> 1.1 {{-r, r}, {-r, r}, {0, r}}       ]]      ]      ![enter image description here](http://i.stack.imgur.com/emm3z.png) Which has too much whitespace. If I replace `Framed@Show[` with `Framed@ImageCrop@Show[` I get, ![enter image description here](http://i.stack.imgur.com/AUCNY.png) which actually crops some of the (hemi)sphere. If just use `Method -> {"ShrinkWrap" -> True},` in the `Show` options, I get, ![Mathematica graphics](http://i.stack.imgur.com/WhX2Y.png) which looks almost correct, but the `x` and `z` textboxes have now not included. Seems like I can't win!


export data points from differential equation system?

I am solving a dynamical three equation system. Besides plotting the individual effects for each of the state variables in an array and in a tridimensional graph, I would like to export the data points to a .csv file. However, when I try to export the table to a .txt file via the "Export" command, the output is not suitable (as it exports the output in a very disorganized way). I was wondering if there could be a way to do this. The code I am using is below:               f = {L, \[Psi], d} /. NDSolve[{       d'[t] == (1/z) (\[Alpha] -             X \[Beta] (d[t]/Y[t]) - \[Gamma] L[t] - \[Delta] \[Psi][              t] - \[Tau] Y[t]) + \[Beta] (d[t]/Y[t]) d[t],       L'[t] == j (Y[t]/K) - e,       \[Psi]'[t] == p L[t] + 0.035 \[Psi][t],       Y[t] == (I + E + \[Alpha] -            X \[Beta] ( d[t]/Y[t]) - \[Gamma] L[t] - \[Delta] \[Psi][             t])/(1 - (1 - \[Tau]) (\[Psi][               t] + (1 - s) (1 - \[Psi][t]) - m z)),       L[0] == 0, \[Psi][0] == 0,        d[0] == 0} /. { \[Alpha] -> 1, \[Gamma] -> 10, \[Delta] -> 10,        X -> 1, \[Beta] -> 0.5, j -> 0.8, \[Tau] -> 0.01, I -> 1,        s -> 0.85, p -> 0.8, E -> 1, m -> 1.3, e -> 0.035, w -> 0.5,        z -> 1.2, K -> 1}, {L, \[Psi], d, Y}, {t, 0, 200}, MaxSteps -> 1000000 ][[1]]     l = {L[t], \[Psi][t], d[t]};     Show[GraphicsArray[Table[Plot[f[[i]][t], {t, 0, 200}, PlotRange -> All,     PlotStyle -> Blue,     AxesLabel -> TraditionalForm /@ {t, l[[i]]},      DisplayFunction -> Identity], {i, 3}]]]     Export["table.txt", f[t] /. sol, "Table"]     ParametricPlot3D[Evaluate[Append[#[t] & /@ f, Red]], {t, 0, 200}, BoxRatios -> {1, 1,0.5}, PlotRange -> All, PlotPoints -> 1500, AxesLabel -> TraditionalForm /@ l]


Benchmarking Mathematica performance on the Raspberry Pi

It is not surprising that Mathematica on the Raspberry Pi is slow and clunky. In Stephen Wolfram's words, the command line is "quite zippy" but the notebook interface is "a trifle sluggish by modern standards". I believe the performance issues are due primarily to two reasons:   * The Raspberry Pi performs at about the level of a 300 MHz Pentium II.   * Mathematica isn't optimized for the ARM processor (yet?) and is currently in pilot release There are in my mind two good reasons for dealing with the sluggish performance of M/RPi:   * Running Mathematica for free on a \$35 credit-card sized computer is just awesome   * The RPi platform allows for hardware interfacing that is not readily available on a PC (or put another way, I'd rather brick a \$35 credit-card sized computer than a \$1000+ PC) How can end users improve the performance of their M/RPi systems while we wait for Wolfram to roll out optimizations for the RPi?


PiecewiseExpand doesn't take all kind of assumptions

Running PiecewiseExpand[expr, assum] does not work with all kind of assumptions. For example, the following line will not split the expression with absolute values in the chambers, considering m1=m2. Why is it so? How can I allow arbitrary asumptions, in particular setting some of the entries equal to others, and some greater than others?               PiecewiseExpand[-Abs[m1 - m2] - Abs[m2 - m3] - Abs[m1 - m3] +         n/2*(Abs[m1] + Abs[m2] + Abs[m3]), {m1 \[Element] Reals,         m2 \[Element] Reals, m3 \[Element] Reals,         m1 == m2 >= m3}] // FullSimplify      Thank you.


ReadList and multiple access of the same file

I have a file containing a large amount of data which can be processed independently. In order to process all data in a reasonable amount of time I distribute the jobs on three different machines. Each job accesses the data file via the command `ReadList`. My question is, if there may be a problem accessing the data file from three programs at once. Thanks in advance, I very much appreciate any help.


Speed up Numerical Integration

**EDIT:** I need to evaluate a very complicated multi-dimensional Integral. The dimension of the Integral depends on a variable `j`. Let's make my point clear with the following example:               Clear["Global`*"];     j = 1;     b = 5;     xvars = Table[Symbol["x" <> ToString[i]], {i, 1, j + 1}];     xrange = Table[{xvars[[i]], 0, b}, {i, 1, j + 1}];     yvars = Table[Symbol["y" <> ToString[i]], {i, 1, j}];     yrange = Table[{yvars[[i]], -1, 1}, {i, 1, j}];     kvars = Table[Symbol["k" <> ToString[i]], {i, 1, j + 1}];     krange = Table[{kvars[[i]], 0, 1}, {i, 1, j + 1}];          f := 9.706509465469745` E^(-1.3507509720280906` k1^2 -         0.6753754860140453` k2^2 - 0.05555555555555558` x1 - y1^2/2)        Sin[1.7289432000093294` k2] Sin[7.748120838924868` k1 x1] Sin[        7.748120838924868` k2 x2] Sin[        7.748120838924868` k1 (x2 + (0.` + 0.15` I) y1)]          expression0 = Sum[f, Evaluate[Sequence @@ krange]]     expression1 = Integrate[expression0, Sequence @@ xrange]     Integrate[expression1, Sequence @@ yrange]      This integral is evaluated rather fast but my function f get's more and more complicated as the index j grows. So do you have any tipps to speed up the calculation of the Integral, or which method should I use. Im not that familiar with numerical integration rules, especially multidimensional. I used in the example `Integrate` which I think is not as fast as `NIntegrate` but I can't make `NIntegrate` work. How can I use `NIntegrate`in this example? And which method would you recommend? Any tipps greatly appreciated.


DensityPlot with one log axis

Is there any way of generating a density plot (or something similar) with one of its axes on a log scale? Essentially I'm trying to combine a `LogLinearPlot` and a normal `Plot` on two different variables to create the associated density plot. If this can't be done directly, what would be the best work-around?


ProbabilityDistribution PDF on boundary points

I would like to evaluate the PDF of a custom `ProbabilityDistribution` at the min and max values. However, `PDF[...]` returns 0 at the boundary conditions. Is there an elegant way to prevent this? Example:               dst = ProbabilityDistribution[2 x, {x, 0, 1}];     PDF[dst, 0.99999] (* = 1.99998 *)     PDF[dst, 1] (* = 0 *) (* I would like this to return 2 *)      The docs say that > the pdf is taken to be zero for $x < x_{min}$ and $x > x_{max}$ It seems inconsistent that the PDF is forced to zero at $x = x_{max}$.


Incrementing a nested list element

I've been wanting to increment a nested list element of which I know the "coordinates". I thought of the following procedure, using Apply with Part.               test = Table[10 h + 5 i + j, {h, 0, 3}, {i, 0, 1}, {j, 0, 4}];     pos = {4, 2, 3};     Increment[test[[##]] & @@ pos];      Yet it seems that `test[[##]] & @@ pos` is treated like a different variable. When I print               test[[##]] & @@ pos     test      I can see that `test[[##]] & @@ pos` gives an incremented result, but `test` itself is not changed. What would be a nice and efficient way of incrementing a nested list element, saving the new value of the whole list ? ## Edit So in the light of the first comments, let me say more about what I would like to achieve : I have a nested list `test` which can be of any depth. I have a list `pos` whose length is equal to               Depth[test]-1      The goal is to increment the element at the position `pos` in `test` (I guess by using `Apply`) and return the incremented nested list. My method below increments well but then does not store the new value in the list.