title: RGB numbers for pastel colordata

text: How can I get the rgb numbers for colors that show up in the colordata "pastel" so I can use them inside a regionplot? I am combining several regionplots and I would like each of the regionlots to be one color from the "Pastel" color scheme. This thread Sunset Colors tells me how to get some of the colors but it would be helpful to be able to get the codes for all possible blends on a continuum.               datt = DataPaclets`ColorDataDump`getColorSchemeData["Pastel"][[5]]          {RGBColor[0.761959, 0.470832, 0.940597],       RGBColor[0.809695, 0.585618, 0.953269],       RGBColor[0.866514, 0.647659, 0.771795],       RGBColor[0.909422, 0.699383, 0.647465],       RGBColor[0.937061, 0.764486, 0.598975],       RGBColor[0.954654, 0.842244, 0.587209],       RGBColor[0.962197, 0.913524, 0.594117],       RGBColor[0.948179, 0.953299, 0.634088],       RGBColor[0.891128, 0.944422, 0.72627],       RGBColor[0.771259, 0.887462, 0.856246],       RGBColor[0.594516, 0.801371, 0.955499],       RGBColor[0.431296, 0.709773, 0.927077]}               Table[RegionPlot[       x > 0, {x, series[5][[22, 2]]/10000,         series[5][[22, 2]]/10000 + series[14][[22, 2]]/10000}, {y, 0, -1},        PlotStyle -> k, AspectRatio -> Automatic], {k, datt}]      ![enter image description here](http://i.stack.imgur.com/47Wgx.jpg)


title: Mathematica .m file can not open in Ubuntu

text: My operating system is Ubuntu. I add some new .m file to /usr/local/Wolfram/Mathematica/9.0/AddOns/Packages/ and then call for it in Mathematica, but failed with the message Get::noopen: "Cannot open !(\"Qdensity.m\").". What should I do to make it work?


title: in search for mathematica function similar to imagesc in matlab

text: Simple question: Is there any built in function for images that acts similar to imagesc in matlab, i.e. take grayscale image scale it to use full [0,1] range and then use some kind of colorgradient to plot the image? The one thing I use right now is to first use `HistogramTransform` to scale to full [0,1] range then obtain image data via `ImageData` and then use `ArrayPlot` with appropriate `ColorFuntion`:               ArrayPlot[image // HistogramTransform // ImageData, ColorFunction -> "TemperatureMap"]      Of course this works just fine, but I am curious if I overlooked some procedure operating directly on images.


title: Inverse prediction function

text: I am trying to write a code which learns a data set. Now, I want to know the input value for a given output value. Consider, the following code               trainset = {{1,2}, {2,4}, {3,6}}     fn = Predict[trainset]      Now I want to solve for m               Solve[fn[m] == 5, m]      Is there any way to find value of `m`, other than plotting the function looking for the input value which gives `5`.


title: How to properly project a Graphics object consisting of line primitives

text: My problem starts from attempts at depicting overlapping lines of different thickness, i.e.               ClearAll[line1, line2, overlapping1, overlapping2, ov1Flat, ov2Flat]     line1 = Graphics[{Thickness[0.003], Blue, Line[{{0, 0}, {4, 1}}]}];     line2 = Graphics[{Thickness[0.03], Red, Line[{{0, 0}, {4, 1}}]}];     overlapping1 = Show[{line2, line1}];      ![overlapping lines 2d](http://i.stack.imgur.com/UaB8q.png) I am often annotating parts of a plot with lines of varying thickness and my preferred method of projecting 2D plots onto 3D is by, well, projecting:               ov1Flat = Show[{ContourPlot[Sin[y x], {x, -4, 4}, {y, -4, 4}], overlapping1}];     Graphics3D@(N@First@ov1Flat /. {x_?AtomQ, y_?AtomQ} -> {x, y, 2.})      ![enter image description here](http://i.stack.imgur.com/nDJt5.png) This works really well for projecting `Graphics` objects comprised of polygons onto a plane but I am not happy with the behaviour of `Line` as a 3D object: lines of various thicknesses get turned into ugly cylinders and their overlap doesn't show too well. I know I can use `Texture` to do the same thing but I would like to avoid it. I'd need to adjust the position of a rasterized image which I'd need to rasterize to an acceptable quality etc - in short, I find it dirtier. So I am looking for a failsafe rule that maps lines onto polygons that I can apply to a `Graphics` object before projecting it and turning it into a truly flat `Graphics3D` object. In trying making a rule for lines consisting of two points, I got the following:               overlapping2 =        overlapping1 /. {pre1___, Thickness[a_], mid___, Line[c_],           post___} :> {pre1, mid,           Polygon[           Transpose@(Transpose@c +                4 a (RotationMatrix[π/2].Normalize[                   Flatten@Differences@c]))~Join~            Transpose@(Transpose@Reverse@c -                4 a (RotationMatrix[π/2].Normalize[                   Flatten@Differences@c]))]          , post};     Show[overlapping2]      which probably has a million ways to break, is inefficient etc, but at least works for the toy example of a line consisting of a start and end point. ![overlap2](http://i.stack.imgur.com/CINfw.png) This replicates the line quite well and once projected is still "flat" with the overlaps showing much better:               Show[Graphics3D@(N@          First@Graphics@overlapping2 /. {x_?AtomQ, y_?AtomQ} -> {x, y,            2.}), Lighting -> "Neutral"]      ![line3D](http://i.stack.imgur.com/oORnI.png) but it doesn't like getting combined with other objects:               ov2Flat=Show[{ContourPlot[Sin[y x], {x, -4, 4}, {y, -4, 4}], overlapping2}];     Graphics3D@(N@First@ov2Flat /. {x_?AtomQ, y_?AtomQ} -> {x, y, 2.})      ![projected line](http://i.stack.imgur.com/Eoz36.png). So my question in its most general form would be: **Is there a transformation rule that one can apply to a`Graphics` object so that the said object can be projected to a truly flat `Graphics3D` object (and look good)?** I know that for `Text` this would probably be impossible so something that has the right behaviour for `Line` and `Point` primitives would be great. And a "no" answer that would mean I have to use `Texture` is also OK but as I said, I want this to be a last resort. **\----EDIT----** The reason I want to do the projection is so that I combine two and three dimensional plots. I am stuck with the toy example I made up (which isn't very well suited for this) but it should give an idea:               Show[{Plot3D[8 + Sin[y x], {x, -4, 4}, {y, -4, 4},         MeshFunctions -> {(0.25 #1 - #2) &}, Mesh -> {{0}},         MeshStyle -> {Blue, Thick}, PlotPoints -> 80],       Graphics3D@(N@           First@ov2Flat /. {x_?AtomQ, y_?AtomQ} -> {x, y, 2.})},       PlotRange -> All, BoxRatios -> {Automatic, Automatic, 6}]      ![projection3](http://i.stack.imgur.com/IzJ7r.png) **\----EDIT 2----** Ok, so the only way out seems to be offsetting each polygonised `Line` a little with respect to the overlapping line and all these lines with respect to the projected plane. I think @belisarius's rule based on the line colour is the simplest one to do that (especially if there's a lot of lines to go through) so I'm going with that.


title: Implementing a back button (in CDF)

text: I have a rather large notebook, which contains a lot of hyperlinks to different parts of the notebook. Is it possible to make a back button (maybe as a docked cell button?) so that when a reader clicks a link and is moved up or down in the document, then he can click the button and then return to the location of the link?


title: How can I make check boxes that put elements into a list?

text: Right now I have a blank list that I am putting in Manipulate[]. I want to be able to choose whether 1,2, or 3 are in this list by setting z1,z2, z3 as True or False:                z1 = True;      z2 = True;      z3 = False;      list = {};      For[i = 1, i <= 3, i++,        If[ToExpression["z" <> ToString@i], list = Insert[list, i, 1]]]      list      The problem comes when I put this code into Manipulate[], where I have a button called "Update list" that essentially does the process above:                Manipulate[{list, {z1, z2, z3}},        Row[{Control[{z1, {True, False}}], Control[{z2, {True, False}}],          Control[{z3, {True, False}}]}],        Button["Update list",list = {};        For[i = 1, i <= 3, i++,       If[ToExpression["z" <> ToString@i],        list = Insert[list, i, 1]]]]]      But as you shall see, the button does nothing. I want: if box "z1" is checked, 1 is added to the list. if box "z2" is checked, 2 is added to the list. ... if box "zi" is checked, i is added to the list. How do you do this?


title: How to extract metadata from an image of a business card?

text: I'm trying to digitize some documents, and I came across a very cool app called camscanner app which performs parallax transform and ocr very nicely, now I'm implementing it in mathematica... ![enter image description here](http://i.stack.imgur.com/Rhjjc.jpg) Given a picture of a business card (taken perhaps at an angle) I'd like to read off the information. I'm trying to solve it in two steps:   1. Calculate the parallax using locators and PerspectiveTransformation[]   2. Clean up the image and OCR with TextRecognize[] Here are sample images to work with: ![enter image description here](http://i.stack.imgur.com/H2Ksg.jpg) ![enter image description here](http://i.stack.imgur.com/Yj5YB.jpg) ![enter image description here](http://i.stack.imgur.com/8fhYT.jpg) ![enter image description here](http://i.stack.imgur.com/VXe2R.jpg) ![enter image description here](http://i.stack.imgur.com/OEcrB.jpg)


title: What are Controlling and Computing Processes?

text: My wolfram user portal claims that I have 2 controlling processes and 8 computing processes. ![Processes](http://i.stack.imgur.com/eltXw.png) Mousing over the question mark gives me some information, but I still don't fully understand what this means.   * Does 2 Controlling Processes mean I can install Mathematica on 2 different computers?   * If not, what are they and how do I make use of them?   * Are Computing Processes like the number of cores I can use simultaneously? (Does Mathematica even support multicore?)   * If so, how can I make use of this?


title: Problem with high parameter values in ParametricPlot

text: I tried to plot the following function as a Parametric Plot. When I include values for w up to 1 the plot looks fine, but I need this plot for values up to 100 or 1000.               z[w_, L_, re_, r1_, c1_, r2_, WoR_, WoT_, WoP_, c2_] =           I w L + 1/(1/(I w c1) + 1/r1) + re +            1/(1/(I w c2) + 1/r2 +               1/(WoR*Coth[(I*WoT* w)^WoP]/(I*WoT* w)^WoP))      I want to have a Nyquist-Plot, so I plotted Real and Imaginary-Part with the following command:               ParametricPlot[{        Re[z[w, 5.1867*10^(-7), 0.10549, 0.014394, 1.699,           0.0098142, 5.5173*10^(-7), 7.428*10^(-13), 0.19962, 0.085349]],         Im[z[w, 5.1867*10^(-7), 0.10549, 0.014394, 1.699,           0.0098142, 5.5173*10^(-7), 7.428*10^(-13), 0.19962,           0.085349]]}, {w, 0.000001, 1},       PlotRange -> {{0.098, 0.13}, {-0.004, 0.01}}]      This works fine. When I replace `{w,0.000001,1}` with `{w,0.000001,1000}` I get a weird plot. Unfortunately I have no idea where the problem could be, so I posted the whole example. I think that there might be some numerical problem that is responsible for the weird edges in the second plot. For small w like 0.00001 the graph is not correct either, it should become negative.


title: Boundary Value Problem

text: I have to solve this boundary value problem: $$\frac{\mathrm{d}e_{3x}}{\mathrm{d}l}=(M_0+F_{0z}x-F_{0x}z)e_{3z}$$ $$\frac{\mathrm{d}e_{3z}}{\mathrm{d}l}=-(M_0+F_{0z}x-F_{0x}z)e_{3x}$$ $$\frac{\mathrm{d}x}{\mathrm{d}l}=e_{3x}$$ $$\frac{\mathrm{d}z}{\mathrm{d}l}=e_{3z}$$ With conditions: $$x(0)=x(1)=z(0)=0$$ $$z(1)=1-d$$ $$e_{3x}(0)=0$$ $$e_{3z}(0)=e_{3z}(1)=1$$ $d$ is a parameter in range (0,2), everything else must be computed. Is this possible in Wolfram Mathematica? The indices confused Mathematica, so I replaced x-related indices with $i$ and z-related indices with $k$. Here is my attempt (I'm trying to find configuration $x(l),z(l)$): ![enter image description here](http://i.stack.imgur.com/U0krf.png) And here is the code:               eq1 = D[Subscript[e, i][l],         l] == (Subscript[M, 0] + Subscript[F, k] x[l] -           Subscript[F, i] z[l]) Subscript[e, k][l]     eq2 = D[Subscript[e, k][l],         l] == -(Subscript[M, 0] + Subscript[F, k] x[l] -            Subscript[F, i] z[l]) Subscript[e, i][l]     eq3 = D[x[l], l] == Subscript[e, i][l]     eq4 = D[z[l], l] == Subscript[e, k][l]          c1 = x[0] == x[1] == z[0] == 0     c2 = z[1] == 1 - d     c3 = Subscript[e, i][0] == 0     c4 = Subscript[e, k][0] == Subscript[e, k][1] == 1          d = 0.01          s = NDSolve[{eq1, eq2, eq3, eq4, c1, c2, c3, c4}, {x[l], z[l]}, {l, 0,         1}]      The physical problem to be solved is this: An elastic rod of length L is placed along $z$ axis. The tips are fixed so they cannot rotate and then the distance betwwen fixators is shortened (they are pushed together) by length D. The rod between becomes curved. Task is to find curvature. $(x(l),z(l))$ are the coords of the rod, $(e_x(l), e_z(l))$ is tangent of the curve and $d=D/L$. $\vec{F}$ and $M$ is the force and torque exerted on the tip of rod upon these deformations. Here is a MATLAB code that solves this problem of compressing rod and calculates all 7 unknowns for various values of $d$:               function elastigs_stienis              scrsz = get(0,'ScreenSize');         figure(1)             set(1,'OuterPosition',[0 scrsz(4)/2 scrsz(3)/2 scrsz(4)/2])         figure(2)             set(2,'OuterPosition',[scrsz(3)/2 scrsz(4)/2 scrsz(3)/2 scrsz(4)/2])         figure(3)             set(3,'OuterPosition',[0 0 scrsz(3)/2 scrsz(4)/2])         figure(4)             set(4,'OuterPosition',[scrsz(3)/2 0 scrsz(3)/2 scrsz(4)/2])              solis = 0.05;  %precizitate         d = solis;         parameters = [0 4*pi^2 4*pi*sqrt(d)];  %Fx, Fz, M - minejumi              sol = bvpinit(linspace(0,1,10),@yinit,parameters,d);              for i = 1:25             sol = bvp4c(@odefun,@bcfun,sol,[],d);                  figure(1)                         % stiena konfiguracija                 plot(sol.y(4,:),sol.y(3,:))                 axis([-1 1 0 .5])                  figure(2)                         % Fx                 plot(d,sol.parameters(1,:),'o','Markersize',3)                 axis([0 2 -0.2 0.2])                 ylabel('Fx')                 xlabel('d')                 hold on                    figure(3)                         % Fz                 plot(d,sol.parameters(2,:),'o','Markersize',3)                 axis([0 2 -400 0])                 ylabel('Fz')                 xlabel('d')                 hold on                    figure(4)                         % M                 plot(d,sol.parameters(3,:),'o','Markersize',3)                 axis([0 2 0 40])                 ylabel('M')                 xlabel('d')                 hold on                    d = d + solis;         end     %--------------------------------------------------------------------------     function y = yinit(l,d)         y = [0                              %ex              1                              %ez              sqrt(d)*(1-cos(2*pi*l))/pi     %x              l];                            %z     %--------------------------------------------------------------------------     function dydx = odefun(x,y,parameters,d)         dydx = [(parameters(3)+parameters(2)*y(3)-parameters(1)*y(4))*y(2)  %ex                 -(parameters(3)+parameters(2)*y(3)-parameters(1)*y(4))*y(1) %ez                 y(1)                                                        %x                 y(2)];                                                      %z     %--------------------------------------------------------------------------     function res = bcfun(ya,yb,parameters,d)         res=[ya(3)           %x(0)=0              ya(4)           %z(0)=0              yb(3)           %x(L)=0              yb(4)-1+d       %z(L)=1-D/L              ya(1)           %ex(0)=0              ya(2)-1         %ez(0)=1              yb(2)-1];       %ez(L)=1      The question remains - can Wolfram Mathematica do the same?


title: Dialog crashes Mathematica

text: I have some dialog windows in a GUI of which one regularly crashes the kernel. I managed to focus on this particular piece of code, though I don't really know what causes the crash:               CreateDialog[DialogNotebook[Button[TextCell["Go"], DialogReturn[]]]];      Whenever I push the button, _Mathematica_ crashes. Strangly, if I remove either the `TextCell` wrapper or the `DialogReturn[]` command, the button behaves correctly. Any idea what is the cause of the symptom? ( _Mathematica_ 8.0.4, Win7/64)


title: Why doesn't my script work when I redirect stdout?

text: I'm using Mathematica Home Edition 9.0.1 on Mac OS X 10.8.2. I have this script:               #!/Applications/Mathematica.app/Contents/MacOS/MathematicaScript -script          exportableDate[date_] := 10000 date[[1]] + 100 date[[2]] + date[[3]];          dividendTable = FinancialData[$ScriptCommandLine[[2]], "Dividend", All];          exportableDividendTable = { exportableDate[#[[1]]], #[[2]] }& /@ dividendTable;         Export[$Output, exportableDividendTable, "CSV"];      When I run it without redirecting `stdout`, it works:               $ ./dividendsForSymbol INTC     StringForm["Initializing `1` indices ....", "FinancialData"]     19921026,0.00313     19930126,0.00313     19930426,0.00313     19930726,0.00313     19931026,0.00313     19940126,0.00313     ...      When I redirect the output to a file, it just exits immediately without producing any output:               $ ./dividendsForSymbol INTC > out         $ echo $?         0         $ ls -l out     -rw-r--r--  1 mayoff  staff  0 Mar  9 17:18 out      Why is it failing when I redirect the output? Or, how can I diagnose the problem?


title: Solving an equation and finding a couple of results given that they are integer

text: My problem is to find all solutions to an equation with 2 variables between two values that define the range of my search. e.g., $(x+y-y²)/(1-y-x²)=0$ with solutions ${x,y} \in \mathbb{Z}$.


title: Mathematica Source-Code Control for CDF files in multi-user scenario

text: **Q:** I'm putting together a strategy on how its best to maintain cdf documents with multiple users in a source code repository. Ideally I wish for users to create (unit tested) cdf's with data and calculations specific to their role. Once the cdf's have been code reviewed, approved to be checked into source control (TFS or possibly SVN). _TFS would be a better solution over SVN since we require integration with the Office suit of applications: Sharepoint 2010, Excel 2010, Word and Outlook._ **Is there a preferred way to manage the cdf files in a source control system? or will any do?**


title: Gamma function computation efficiency?

text: I wonder what kind of algorithm is used to compute the values for the gamma function. Specifically, I am interested in how the computational load increases when the complexity of the input grows. So, for example, evaluating               Gamma[x + I y]      for integer `x` and `y` and gradually increasing their number of digits will make the computation time longer. What is the corresponding power law for the increase? EDIT: evaluating at `4 Pi + I 8 GoldenRatio`:               data = Monitor[     Table[{k,       N[Gamma[4 Pi + I 8 GoldenRatio], k 10^3]; // Timing //        First}, {k, 1, 10, 5/10}], k];      ListLinePlot[data, Mesh -> All,      MeshStyle -> Directive[Red, PointSize[Large]]]      Now shows ![enter image description here](http://i.stack.imgur.com/mqkHh.gif) and I get               line = Fit[Log@data, {1, x}, x]     -3.350 + 2.723 x      not sure if this is relevant or just an artifact.


title: Illogical failures of symbolic integration over Boole

text: Is there a way to work around integration over `Boole` being mysteriously flaky like examples show below? Is there a meaningful explanation for this behaviour? First, rather obvious integral stays unevaluated:               Integrate[Boole[u^2 + v^2 < 1], {u,-1,1}, {v,-1,x}, Assumptions -> -1 < x < 1]          (* Integrate[Boole[u^2 + v^2 < 1], {u,-1,1}, {v,-1,x}, Assumptions -> -1 < x < 1] *)      While the following succeeds to produce a meaningful result:               Integrate[Boole[u^2 + v^2 < 1], {u,-1,1}, {v,-1,x}, Assumptions -> -1 < x < 0]          (* Pi + x Sqrt[1 - x^2] - ArcCos[x] *)      Why this succeeds particularly puzzles me, when the first one fails:               Integrate[Boole[u^2 + v^2 < 1], {u,-1,1}, {v,-1,x},       Assumptions -> -1 < x < Infinity] // FullSimplify          (* Pi + x Sqrt[1 - x^2] - ArcCos[x]             x <= 0        Pi                                           x >= 1        x Sqrt[1 - x^2] + ArcCos[x] + 2 ArcSin[x]    True *)


title: How to change step size of ListPlot

text: The command `ListPlot` will plot lists with a unit step. Is there any way to change the step size of this?


title: Dynamic plot with Evaluate on expression

text: I'm trying to make a make a plot of a table of expressions, which should be pre-evaluated (since they are infinite series with analytic sums). I'm able to make the plot normally with `Evaluate @ Table`:               Plot[Evaluate@Table[Sum[t^k/k! Exp[-t], {k, 0, Infinity, n}], {n, 1, 5}], {t, 0, 5}]      But when I surround it with a Manipulate it no longer works (there are errors that indicate _Mathematica_ is evaluating the summation with a fixed value of t, which doesn't work at `t = 0, k = 0`).               Manipulate[       Plot[Evaluate @         Table[Sum[ ((a t)^k)/k! Exp[-a t], {k, 0, Infinity, n}], {n, 1, 5}], {t, 0, 5}],       {a, 0, 3}]      I know I can just evaluate the table and copy-paste, but I was hoping for a more elegant solution.


title: subscripts in plot axis labels

text: Superscripts can be included in axis labels by the use of the caret symbol (e.g., `Plot[x^2, {x, -1, 1}, AxesLabel -> {x, x^2}]`). How does one include subscripts in an axis label? The use of the underscore character does not seem to work (e.g., `Plot[f, {x, -1, 1}, AxesLabel -> {x, f_i(x)}]`).


title: Convert Integer to Real

text: Is there a preferred way of converting an `Integer` to a `Real`? What I'm using at the moment is `x + 0.0`.


title: How can I insert text into a relative position in a plot?

text: I use the following code to draw a parametric plot, with `Epilog` to add a point, and text using `Graphics`.               graf7 = ParametricPlot[  { delta18[t], delta2D[t]}, {t, 0, 800},        Epilog -> {Red, PointSize[Large],           Point[{ delta18[0] , delta2D[0]} ],           Line[{{20, 160}, {-50, -400}}] } ,        AspectRatio -> 1, PlotLabel -> "d18O vs dD (g/kgda)",        PlotStyle -> Thick, PlotRange -> All, ImageSize -> Medium        ];          Show[graf7,       Graphics[Text["Dot is at surface", {-10.6, -89.4}]],       Graphics[Text["Black line is MWL ", {-10.6, -89.6}]]  ]      For now, it works fine. I experimented with the equations that find the original arguments, `delta18[t]` and `delta2D[t]`, so their value ranges change drastically, and the inserted text is no longer in the plot region. How can I make the text appear at a _relative_ position within the plot, so it is never outside the plot region?


title: Constructing an Array from typed expression

text: I want to produce an array from expressions given by               test[one][1] = 3;     .      .     test[one][5] = 7;      etc. Normally would use `Table[test[one][i], {i,N}]`, but for this you need the value of `N` that may not be known (without keeping track of it via some other means). I would like to be able to read the maximum value of the integer inside `test[one][ ]` and use this to construct the array. For expression such as `test[1] = 5`, this is straight forward since `DownValues[test]` can be used, but when adding another level the head becomes "test" and `DownValues[]` will not work.


title: Unexpected behavior from GatherBy in version 7

text: I have come across what appears to be a bug in `GatherBy`. It appears similar to the problem of using `Table[Random[], {1000}]` in older versions in that the behavior changes depending on the size of the data.   * Has this problem been fixed in version 8?   * **Is there a system option that effects this, or another global work-around for version 7?** Examples:               SeedRandom[1];     set = RandomInteger[4, {500, 3}];          DeleteDuplicates[Sort /@ set] ~Partition~ 5 // Column      > >     {{2,4,4},{0,0,1},{0,0,2},{0,2,3},{0,3,4}} >     {{1,3,4},{1,2,4},{1,4,4},{0,3,3},{1,1,3}} >     {{1,2,3},{0,1,4},{0,2,4},{2,2,3},{1,1,2}} >     {{1,3,3},{2,3,4},{2,2,2},{0,1,3},{0,2,2}} >     {{3,3,4},{2,2,4},{3,4,4},{0,1,2},{2,3,3}} >     {{0,0,3},{0,0,4},{3,3,3},{0,4,4},{1,2,2}} >   But this does not agree:               GatherBy[set, Sort][[All, 1]]      > >     {{4, 2, 4}, {0, 1, 0}, {0, 3, 2}, {4, 1, 3}, {3, 1, 1}} >   If I change the gather function to something that apparently does not compile:               GatherBy[set, ("x"; Sort@#) &][[All, 1]] ~Partition~ 5 // Column      > >     {{4,2,4},{0,1,0},{0,2,0},{0,3,2},{0,3,4}} >     {{4,1,3},{4,2,1},{1,4,4},{0,3,3},{3,1,1}} >     {{3,2,1},{1,4,0},{0,2,4},{2,3,2},{1,2,1}} >     {{3,3,1},{2,4,3},{2,2,2},{0,3,1},{2,0,2}} >     {{4,3,3},{4,2,2},{3,4,4},{0,1,2},{2,3,3}} >     {{0,3,0},{0,4,0},{3,3,3},{4,0,4},{2,1,2}} >   This problem does not appear to affect smaller sets:               SeedRandom[1];     set = RandomInteger[4, {60, 3}];          GatherBy[set, Sort][[All, 1]]~Partition~5 // Column      > >     {{4,2,4},{0,1,0},{0,2,0},{0,3,2},{0,3,4}} >     {{4,1,3},{4,2,1},{1,4,4},{0,3,3},{3,1,1}} >     {{3,2,1},{1,4,0},{0,2,4},{2,3,2},{1,2,1}} >     {{3,3,1},{2,4,3},{2,2,2},{0,3,1},{2,0,2}} >     {{4,3,3},{4,2,2},{3,4,4},{0,1,2},{2,3,3}} >


title: Counting the number of operations performed during a calculation

text: I need to know how can I count the number of operations performed during a calculation of a `CompoundExpression`. In some of these expressions there are `Dot` products between matrices and I want to count how many additions a multiplications are performed in each of these calculations. In other words, I need a functions that does the same as the function `cost` of Maple (http://www.maplesoft.com/support/help/Maple/view.aspx?path=codegen/cost) Does anyone know how to do it?


title: Placement of pattern matching rules in functions

text: Is there any difference at all between               f[x_Integer /; x >= 0] := x + 1;     f[x_Integer] := x - 1;     f[x_] := Null;      and               f[x_Integer] := x + 1 /; x >= 0;     f[x_Integer] := x - 1;     f[x_] := Null;      The output is identical in both the cases. Even if there is no technical difference, is it common practice to adhere one and avoid the other?


title: Recognize simple shapes in an image and color them randomly?

text: I have an image of polygons built from a polar function (see below). I'd like to color each triangle or quadrilateral a random color. Firstly, I'm not sure how to separate the simple shapes. Secondly, I can't think of a simple way to color each a random color (only 3 different colors result with `Colorize`).               sunflower = 2 Pi (1 - 1/GoldenRatio);     PolarCoordinate[r_, theta_] := r {Cos[theta], Sin[theta]}     Graphics[Polygon[        Table[PolarCoordinate[i^10, i*sunflower], {i, 1, 1000}]],        AspectRatio -> 1] // Colorize      ![enter image description here](http://i.stack.imgur.com/YxLL0.jpg)


title: How to eliminate error message from a LocatorPane showing graphincs?

text: My code               q1 = {{1, 0.5}, {2, 0.5}}; q2 = 10; q3 = {3, 3};     Dynamic[       LocatorPane[Dynamic[q1],         Graphics[{},            PlotRange -> {{0, Dynamic[q2]}, {-1, 1}},           Axes -> True],          Appearance -> q3],        TrackedSymbols :> {q3}]      is wrong, because when I press this button               Button["Add", AppendTo[q1, {q1[[-1, 1]] + 1, 0.5}]; AppendTo[q3, 1]]      a bad output cell appears, and I get the mesage > The specified setting for the option GraphicsBoxOptions, PloRange cannot be > used." ![](http://i.stack.imgur.com/DVsOU.png) What is wrong here??


title: Manipulate for variable number of sliders

text: I'm trying to use Manipulate for plotting multidimensional data, where higher dimensions are defined as sliders. First, this simple example works:               myfun[v1_Real, v2_Real, v3_Real, v4_Real, v5_Real] :=       Sin[v1]*Cos[v2]*v3 + v4*v5          Manipulate[      Plot3D[myfun[v1, v2, v3, v4, v5], {v1, 0, 2}, {v3, 0, 2}], {{v5,         0.5}, 0., 1.}, {{v2, 0.5}, 0., 1.},(*{{v3,0.5},0.,1.},*){{v4, 0.5},        0., 1.}]      ![Mathematica graphics](http://i.stack.imgur.com/gAlXK.png) But when the dimensions for plotting and for controls are configured to change dynamically, then Mathematica gets stuck:               Manipulate[      With[{myaxis = Sequence @@ {{v[ax1], 0, 2}, {v[ax2], 0, 2}},         mycontrols =          Sequence @@ {{{v[sl1], 0.5}, 0., 1.}, {{v[sl2], 0.5}, 0.,             1.}, {{v[sl3], 0.5}, 0., 1.}}},        Manipulate[Plot3D[myfun[v[1], v[2], v[3], v[4], v[5]], myaxis],         mycontrols]], {ax1, Range[1, 4, 1], ControlType -> Setter}, {ax2,        Range[ax1 + 1, 5, 1], ControlType -> Setter}, {sl1,        Complement[Range@5, {ax1, ax2}], ControlType -> Setter}, {sl2,        Complement[Range@5, {ax1, ax2, sl1}], ControlType -> Setter}, {sl3,        Complement[Range@5, {ax1, ax2, sl1, sl2}], ControlType -> Setter}]      ![Mathematica graphics](http://i.stack.imgur.com/a3pyY.png) How can I make the last piece of code to evaluate correctly?


title: Error when compiling function containing InterpolationFunction

text: I'm trying to solve a coupled ODE system using `NDSolve`. The coupling can turn on and off in some regions, and when the coupling is off, the solution can be written down directly in terms of simple algebraic functions. So I only need to solve the regions when the coupling is on using NDSolve. Then the solutions in different regions are put together to form a `Piecewise` function as a whole solution. This `Piecewise` function now contains several `InterpolationFunction` objects and other simple algebraic functions. Since the `InterpolationFunction` only takes a small part of the whole solution region, I'm trying to compile this `Piecewise` function so that those simple algebraic functions would benefit from compiling. Here is the simplified version of the problem: suppose we have the solution in one region as an interpolation function               s = C1 /.        First@NDSolve[{I C1'[t] == C2[t] E^(-I t),           I C2'[t] == C1[t] E^(I t), C1[0.] == 1., C2[0.] == 0.}, {C1,           C2}, {t, 0., 10.}]     (*       InterpolatingFunction[{{0.,10.}},<>]     *)      and the solution in full region is constructed as               sol[t_] :=       Piecewise[{{s[t], t <= 10.}, {Sin[t], t <= 20.}, {Cos[t], t <= 30}}, 0.]      it can compile without problem, but when executed gives error               f2 = Compile[{{t, _Real}}, Evaluate@sol[t], {{_InterpolationFunction, _Complex}}];     f2[5.]      > CompiledFunction::cfex: Could not complete external evaluation at > instruction 3; proceeding with uncompiled evaluation. >>               (*       -0.787325-0.231525 I     *)      if we compile without `Evaluate`, then there is no error               f1=Compile[{{t,_Real}},sol[t],{{_sol,_Complex}}];     f1[5.]     (*       -0.787325-0.231525 I     *)      but this seems to send the whole `sol` function to the MainEvaluator and thus those simple algebraic functions can't benefit from the compiling. Indeed if we print out the content we can see this difference.               CompilePrint@f1          "             1 argument             1 Real register             1 Complex register             Underflow checking off             Overflow checking off             Integer overflow checking on             RuntimeAttributes -> {}                  R0 = A1             Result = C0          1   C0 = MainEvaluate[ Hold[sol][ R0]]     2   Return     "          CompilePrint@f2          "             1 argument             3 Boolean registers             1 Integer register             9 Real registers             Underflow checking off             Overflow checking off             Integer overflow checking on             RuntimeAttributes -> {}                  R0 = A1             R2 = 7.             R1 = 10.             R4 = 20.             I0 = 30             R7 = 0.             Result = R5          1   B0 = R0 <= R1 (tol R2)     2   if[ !B0] goto 6     3   R3 = MainEvaluate[ Hold[InterpolatingFunction[{{0., 10.}}, <>]][ R0]]     4   R5 = R3     5   goto 20     6   B1 = R0 <= R4 (tol R2)     7   if[ !B1] goto 11     8   R5 = Sin[ R0]     9   R6 = R5     10  goto 19     11  R6 = I0     12  B2 = R0 <= R6 (tol R2)     13  if[ !B2] goto 17     14  R6 = Cos[ R0]     15  R8 = R6     16  goto 18     17  R8 = R7     18  R6 = R8     19  R5 = R6     20  Return     "      So how can I solve this problem? Thanks.


title: Why do vertex labels disappear when I edit with drawing tools?

text: I'm trying to change the text and arrow style in GraphPlot using the drawing tool, but the the vertex labels disappear when I do that:               GraphPlot[{Subscript[δ, 1] -> Subscript[X, 1],        Subscript[δ, 2] -> Subscript[X, 2],        Subscript[δ, 3] -> Subscript[X, 3],        Subscript[δ, 4] -> Subscript[X, 4],        Subscript[ξ, 1] ->         Subscript[ξ, 2], {Subscript[ξ, 2] -> Subscript[ξ, 1],         "\!\(\*SubscriptBox[\(ϕ\), \(21\)]\)"}, {Subscript[ξ,           1] -> Subscript[X, 1],         "\!\(\*SubscriptBox[\(γ\), \(11\)]\)"}, {Subscript[ξ,           1] -> Subscript[X, 2],         "\!\(\*SubscriptBox[\(γ\), \(21\)]\)"}, {Subscript[ξ,           2] -> Subscript[X, 3],         "\!\(\*SubscriptBox[\(γ\), \(32\)]\)"}, {Subscript[ξ,           2] -> Subscript[X, 4],         "\!\(\*SubscriptBox[\(γ\), \(42\)]\)"}},       VertexLabeling -> True, DirectedEdges -> True,       VertexCoordinateRules -> {Subscript[ξ, 1] -> {0, 3},         Subscript[ξ, 2] -> {0, 0}, Subscript[X, 3] -> {Sqrt[3], 1},         Subscript[X, 4] -> {Sqrt[3], -1}, Subscript[X, 2] -> {Sqrt[3], 2},         Subscript[X, 1] -> {Sqrt[3], 4},         Subscript[δ, 1] -> {Sqrt[3] + 1, 4},         Subscript[δ, 2] -> {Sqrt[3] + 1, 2},         Subscript[δ, 3] -> {Sqrt[3] + 1, 1},         Subscript[δ, 4] -> {Sqrt[3] + 1, -1}}, ImageSize -> 320]      results something like ![enter image description here](http://i.stack.imgur.com/ca2w4.jpg) when I use the drawing tool to make the text and arrow head bigger, the vertex labels disappear ![enter image description here](http://i.stack.imgur.com/6ZfTm.png) Why that happens and how to get around that? I'm using version 8 on Mac. This also happens in version 8 on Windows 7.


title: Alignment in columns

text: I need to stack three objects on top of each other and align the first two to the center and the third one to the left. I've been trying to do this with `Column`, but it won't let me align the objects differently. The code below should make clear what I'm trying to do:               Column[{Style["Title", FontSize -> 20, "Title"],Graphics@Disk[],Style["Footnote text..."]},        {Center, Center, Left}]      I want the title and the disk to be centered, but the footnotes aligned to the left. Anyone know how to do this?


title: Extracting "records" from a matrix

text: From a rank 3 matrix like               M =       {        {{a, v, x01}, {a, w, x02}, {a, x, x03}, {a, y, x04}, {a, z, x05}},        {{b, v, x06}, {b, w, x07}, {b, x, x08}, {b, y, x09}, {b, z, x10}},        {{c, v, x11}, {c, w, x12}, {c, x, x13}, {c, y, x14}, {c, z, x15}},        {{d, v, x16}, {d, w, x17}, {d, x, x18}, {d, y, x19}, {d, z, x20}}        };      I want to extract information based , for instance, on the following keys :               Keys1 = {y, w};     Keys2 = {d, a, b};      Using               Map[Cases[Flatten[Map[Cases[Flatten[P, 1], {_, #, _}] &, Keys1], 1], {#, _, _}]&,Keys2]      gives the desired unsorted result:               {{{d, y, x19}, {d, w, x17}}, {{a, y, x04}, {a, w, x02}}, {{b, y,  x09}, {b, w, x07}}}      In reality, my matrices have up to 30000 rows, but always 3 columns: Key1 (String), Key2 (String), x01 ... x20 (Lists of real values) Because of many repetitive lookups, timing here is important, so my question is: Are there faster ways? Thanks in advance for your help


title: How to sum over a List

text: list = {11.5575, 11.397, 5.52734, 4.0878, 2.54815, 1.86652, 2.55028,     2.14952, 1.6242, 1.34117}      I have a list of numbers. How do I make a function that creates a new list, where the first entry is equal to               {list[[1]], list[[1]] + list[[2]], list[[1]] + list [[2]] + list[[3]]}       etc until the end of the list. I ask because my real list is quite a bit longer than just 10 entries, and writing this out would get far too long to handle.


title: Plot "number of triples at each v in V(G)"

text: For a uni assignment, I need to plot the "number of triples at each v in V(G)". I tried to find relevant information in the Mathematica documentation through Google, but I'm lost. How do I get the set of number of triples at each v in V(G)? I have graph WS:               WS = RandomGraph[WattsStrogatzGraphDistribution[500, 0.01, 10]]      I want this:               ListPlot[NumberOfTriples[WS]]      NumberOfTriples is an imaginary function, but the previous line illustrates what I want.


title: DistributionFitTest with WeightedData?

text: My problem is related to statistical testing with weighted data. I have a data sample and I assume that a part of the data follows a specific distribution (Pareto). So I fit my data to a distribution by using `EstimatedDistribution` and in turn I obtain a p-value related to this fit according to different statistical tests (Cramer-Von Mises, Kolmogorov-Smirnov and possibly others). Everything goes well as long as I do not include weights (I really know it works, since I have replicated my results in another software package...). When including weights by using the function `WeightedData` I run into problems. `EstimatedDistribution` still works well on `WeightedData` (again results are replicated in another package), but the `DistributionFitTest` does not work any longer. When trying to apply `DistributionFitTest` on `WeightedData` I get an error message of the following form: > "rctnln: The argument [my weighted data object] at position 1 should be a > rectangular array of real numbers with length greater than the dimension of > the array." I got the intuition behind these error message and intensely searched for an appropriate work-around or alternative Function, but could not find any suitable tools. Could anybody help me out on this?


title: How to implement the Observer design pattern?

text: As a programmer with a history with procedural languages, the Observer design pattern inmediately springs to my mind when attacking certain class of problems, mostly **UI/notifications** related. A two-pronged question:   * Is the **Observer** pattern well suited to _Mathematica_ style(s)? Or, more generally, can event-driven programming, being mostly about state and asynchronous notifications, be implemented efficiently/elegantly in _Mathematica_? `Dynamic` seems promising, but is a **FE** solution.   * In any case --for educational purposes, maybe,-- how would you implement a bare-bones **Observer** mechanism? I know that taming all `*Values` and assignments is hard or directly impossible without hooks. Let's settle with somewhat useful, instead of perfect: only `OwnValues`, simple `Protect[]`, very simple notification callbacks. Something along the lines of:               ClearAll[a];     a[b_] := b;     a = 2;     Observe[a, observer1 = Print["1.- ", ToString[Unevaluated[#1]], ": ", #2] &];     a = 3      > 1.- a: 3   >  3               Observe[a, Print["2.- ", ToString[Unevaluated[#1]], ": ", #2] &];     a = 4      > 1.- a: 4   >  2.- a: 4   >  4               DownValues[a] = DownValues[a]~Join~{HoldPattern[a[c_]] :> c};     a /: b[Unevaluated[a]] := b;          Set::write: "Tag a in DownValues[a] is Protected."     TagSetDelayed::write: "Tag a in b[a] is Protected."          RemoveObservations[a,observer1];     RemoveObservations[a];     a = 5      > 5 Related:   * Detecting changes of variables' values   * Is it possible to create an event handler for changes in values of variables? and possible starting points:   * Triggering actions when a variable is set   * ValueFunction


title: Export data as XLS file

text: data = WeatherData["WMO44207", "Temperature", {{1950}, {2013}}]      This list contains 11400 records ... date,temperature value .... I want to export all records as an XLS file. How can I do that?


title: Can I speed up the following plotting code?

text: I have the following _Mathematica_ code. I do get the output graphs, but it takes like 12 seconds, on my computer. Longer still if I increase the value of `n1`. Are there ways that can speed up the code?               Code1[A_, n1_] := Module[{E2},       h = 197.327053^2;       a = 0.65;       r0 = 1.285;       k0 = ((V02) 2 m/h)^0.5;       R0 = r0 A^0.333;       m = (A/(A + 1.00866 ))*931.49432;           V02 = 40.5 + 0.13 A;       z = a Sqrt[(2 m/h) (V02 - E2)];            b = a*Sqrt[(2 m/h) (E2)];       q1 = Sqrt[(V02 - E2)/E2];       phi444[E_] := (z R0/a  ) -          Sum[ ArcTan[2 z/n] - 2 ArcTan[z/(n + b)], {n, 1.0, n1}];       t1 = Plot[{Tan[phi444[E2]], -q1}, {E2, 0, 45.0}];       Print[t1]]


title: How to define a new stochastic process which is function of another process?

text: I need to define a new process from for example Wiener process like $U(t)=f(W(t))$, (for example $f(x)=1+x^2$ ) and then calculate the average like $\langle U(t)U(s)\rangle$. Is it possible?


title: Fast two dimensional version of Range[]

text: I have need of a two dimensional version of `Range[]`. I have a few ideas of varying speeds, and I was wondering if anyone knew a better way to do this.               rangeX=2000;evaluatedRangeX=Range[rangeX];     rangeY=2000;evaluatedRangeY=Range[rangeY];     speed1=First[AbsoluteTiming[test1=Table[{y,x},{y,rangeY},{x,rangeX}];]];     speed2=First[AbsoluteTiming[test2=Outer[{#1,#2}&,evaluatedRangeY,evaluatedRangeX];]];     speed3=First[AbsoluteTiming[test3=Array[{#1,#2}&,{rangeY,rangeX}];]];     speed4=First[AbsoluteTiming[      test4=Table[Transpose[{ConstantArray[y,rangeX],evaluatedRangeX}],{y,rangeY}];]];     speed5=First[AbsoluteTiming[Range[rangeX*rangeY];]];     test1==test2==test3==test4     {speed1,speed2,speed3,speed4,speed5}      With results:               True     {2.813062, 2.179700, 0.575586, 0.082393, 0.019547}      So my best effort is still four times slower than using `Range[]` to make a one dimensional range of the same size, which seems like a reasonable lower bound. Can anyone suggest a better way?


title: Solve inhomogeneous Poisson's equation, gives no result at all

text: I would like to solve the following two-dimensional inhomogeneous Poisson's equation in Mathematica including specific boundary conditions, and I know that an analytical solution exists, but Mathematica is not cooperating in this special case. I would like to analytically solve the following Poisson's equation: $$\frac{\partial^2 u(x,y)}{\partial x^2}+\frac{\partial^2 u(x,y)}{\partial y^2}=6 x (1-y) y-2 x^3$$ with the boundary conditions $$u(0, y)=0,\ u(1, y)=(1-y)y,\ u(x, 0)=0,\ u(x, 1)=0$$ From a textbook I know that the solution is $$u(x,y)=y(1-y)x^3$$ If I try to solve this equation system by using `DSolve`               DSolve[{D[u[x, y], {x, 2}] + D[u[x, y], {y, 2}] == -2 x^3 + 6 x (1 - y) y,      u[0, y] == 0,       u[1, y] == (1 - y) y,       u[x, 0] == 0,       u[x, 1] == 0}, u, {x, y}]      But _Mathematica_ refused to do anything and is not returning any error message at all. Am I overlooking something or is such an PDE not solvable analytically in _Mathematica_? Of course one could use `NDSolve`, but I would like to have the possibility to get more general solutions through `DSolve`.


title: Why Doesn't Mathematica Simplify Combinations of Quotients? (Integer Division)

text: I stumbled across this as part of a more complicated formula but it can be shown very simply:               In[1]:= f[x_] := Quotient[Quotient[x, 5], 7]; FullSimplify[f[x]]          Out[1]= Quotient[Quotient[x, 5], 7]          In[2]:= FullSimplify[f[x], Element[x, Integers] && x >= -1000 && x <= 1000]          Out[2]= Quotient[Quotient[x, 5], 7]          In[3]:= f[x] == Quotient[x, 35] /. x -> Range[-1000, 1000]          Out[3]= True      Why doesn't Mathematica make the simplification shown to be true in step 3? EDIT 2: The following works for me, using the identity pointed out by RiemannZeta:               In[1]:= f[x_] := Quotient[Quotient[x, 5], 7]             FullSimplify[f[x]]             FullSimplify[FunctionExpand[f[x]]]          Out[2]= Quotient[Quotient[x, 5], 7]          Out[3]= Floor[1/7 Floor[x/5]]          In[4]:= Unprotect[Floor];             Floor[Floor[x_ Rational[1, m_]] Rational[1, n_]] :=               Floor[x/(n m)] /; Element[{m, n}, Integers] && m > 0 && n > 0             FunctionExpand[f[x]]             FunctionExpand[f[x] == Quotient[x, 35]]          Out[6]= Floor[x/35]          Out[7]= True


title: How to fix MIDI playback on OS X?

text: Sometimes sounds specified using `SoundNote` (i.e. things played using MIDI) don't play properly on OS X. Some notes are missing and some are stuck. At least this is what happens on my system with Mathematica 9.0.1 on OS X 10.8.4 and Apple Java 1.6.0_51. How can I fix this and have Mathematica play MIDI properly? Note: this code is affected as well.


title: Getting variables out of Dynamic Modules after restoring the program

text: The scrap of code below [from _Mathematica's Help_ on `DynamicModules`] generates a `Pane` of `Locator`s, and a line showing the interpolation between the datapoints.               DynamicModule[{pts = {{0, 0}, {1, 1}, {2, 0}, {3, 2}}},       LocatorPane[Dynamic[pts],                   Dynamic[Plot[InterpolatingPolynomial[pts, x], {x, 0, 3},                                PlotRange -> 3]      ]]]      When the program is saved,and reloaded, the `Plot` persists with the then current values of the points. Suppose, after reloading the file (but not reinitializing the `DynamicModule`), I want to use the values of the points (which I moved in interacting with the program before saving it). In otherwords, I'd like to be able to access a list of the modified points with, perhaps, new functions. I realize I could just read out variables in the original function, store them, then load them as part of the initialization procedure when restarting a program a second time, but this in effect means running the original program history completely again. In complex programs, with lots of potential branches, this could be tedious and error prone. Any solution? `DynamicModule` would seem to attempt to address this problem by saving variables, but, for example, in the above code scrap, I want to get numerical values of the point positions for use in other parts of the program, how would I do it?


title: Manipulate Slider over discrete collection. Keyboard control.

text: I would like to create a `Manipulate` slider that iterates over a discrete set of items. Something like the following               Manipulate[u, CharacterRange["a","z"]]      produces a drop-down menu, which doesn't have a great interaction style. I must move the mouse back up to the top to get a new item, taking my eyes off the display back to the controls, rather than being able to just slide around without having to look at the controls too often. Even better would be some kind of keyboard control that would let me left-and- right arrow my way through a collection. Then I'd never have to take my eyes off the target display. But that would be too intuitive [sarcasm].


title: SiegelTheta fails to evaluate when given proper arguments

text: SiegelTheta often returns error messages when I give it arguments that should be of the correct form. For instance, I have a numerical matrix like               M = N[{{1 + π/2, -1, 1 - π/2}, {-1, 1 + π/2, -1}, {1 - π/2, -1, 1 + π/2}}];      and I want to evaluate `SiegelTheta[Ω[0.01], s]`, where               Ω[r_] := I*Inverse[M]/r          s = {0, 0, 0};      but I get the following error message:               SiegelTheta::invmat:     "{{0. + 56.831I,0. + 31.831I,0. + 25.I},{0. + 31.831I,0. + 63.662I,0. +31.831I},     {0. + 25.I,0. + 31.831I,0. + 56.831I}} must be a symmetric matrix with a positive definite      imaginary part."      However, `Ω[0.01]` does satisfy those conditions, even according to Mathematica:               PositiveDefiniteMatrixQ[Im[Ω[0.01]]]     (* True *)          SymmetricMatrixQ[Ω[0.01]]     (* True *)      I would appreciate any help resolving this issue. I am using Mathematica version 9.0.1.


title: Symbolic evaluation of the sum of KroneckerDelta

text: I want to evaluate this simple expression $$ \sum_n f(n)\delta_{mn} = f(m) $$ using this:               Sum[KroneckerDelta[m, n] f[n], {n, Infinity}]      However Mathematica didn't reduce this expression. Could someone tell me how to do this correctly?


title: Layout a second graph of the same nodes in the same way

text: I have a number of graphs with the same nodes. I would like to be able to somehow save the layout that results from the spring embedded results of one graph (the first image), and have the other graphs position the nodes in the same locations (which would otherwise get you the second image). Not sure if there is a property of the first graph that can be applied to the second. Or whether I need to create a manual set of coordinates using VertexCoordinates to apply to each. Ideas? ![enter image description here](http://i.stack.imgur.com/i7Krg.png) ![enter image description here](http://i.stack.imgur.com/RJC2K.png) The data for the two graphs is               {"Al-1" -> "Bru-2", "Bru-2" -> "Gra-7", "Chas-3" -> "Ned-14",       "Dave-4" -> "Bru-2", "Ed-5" -> "Ned-14", "Frank-6" -> "Unwin-21",       "Hal-8" -> "Unwin-21", "Ian-9" -> "Ned-14", "Jo-10" -> "Ron-18",       "Ken-11" -> "Ron-18", "Leo-12" -> "Unwin-21", "Mal-13" -> "Ned-14",       "Ned-14" -> "Gra-7", "Ollie-15" -> "Ned-14", "Pat-16" -> "Bru-2",       "Quinn-17" -> "Unwin-21", "Ron-18" -> "Gra-7", "Sam-19" -> "Ned-14",       "Tom-20" -> "Ned-14", "Unwin-21" -> "Gra-7"}      and               {"Al-1" -> "Bru-2", "Al-1" -> "Dave-4", "Al-1" -> "Hal-8",       "Al-1" -> "Leo-12", "Al-1" -> "Pat-16", "Bru-2" -> "Al-1",       "Bru-2" -> "Ron-18", "Bru-2" -> "Unwin-21", "Chas-3" -> "Ned-14",       "Chas-3" -> "Sam-19", "Dave-4" -> "Al-1", "Dave-4" -> "Bru-2",       "Dave-4" -> "Hal-8", "Dave-4" -> "Leo-12", "Dave-4" -> "Pat-16",       "Dave-4" -> "Quinn-17", "Ed-5" -> "Bru-2", "Ed-5" -> "Ian-9",       "Ed-5" -> "Ken-11", "Ed-5" -> "Ned-14", "Ed-5" -> "Quinn-17",       "Ed-5" -> "Sam-19", "Ed-5" -> "Unwin-21", "Frank-6" -> "Bru-2",       "Frank-6" -> "Gra-7", "Frank-6" -> "Ian-9", "Frank-6" -> "Leo-12",       "Frank-6" -> "Quinn-17", "Frank-6" -> "Unwin-21",       "Hal-8" -> "Dave-4", "Jo-10" -> "Chas-3", "Jo-10" -> "Ed-5",       "Jo-10" -> "Hal-8", "Jo-10" -> "Ian-9", "Jo-10" -> "Leo-12",       "Jo-10" -> "Pat-16", "Jo-10" -> "Tom-20", "Ken-11" -> "Al-1",       "Ken-11" -> "Bru-2", "Ken-11" -> "Chas-3", "Ken-11" -> "Dave-4",       "Ken-11" -> "Ed-5", "Ken-11" -> "Hal-8", "Ken-11" -> "Ian-9",       "Ken-11" -> "Leo-12", "Ken-11" -> "Mal-13", "Ken-11" -> "Ollie-15",       "Ken-11" -> "Quinn-17", "Ken-11" -> "Ron-18", "Ken-11" -> "Sam-19",       "Leo-12" -> "Al-1", "Leo-12" -> "Dave-4", "Leo-12" -> "Quinn-17",       "Leo-12" -> "Unwin-21", "Mal-13" -> "Ed-5", "Mal-13" -> "Ken-11",       "Ned-14" -> "Gra-7", "Ned-14" -> "Ollie-15", "Ollie-15" -> "Al-1",       "Ollie-15" -> "Chas-3", "Ollie-15" -> "Ed-5",       "Ollie-15" -> "Frank-6", "Ollie-15" -> "Ian-9",       "Ollie-15" -> "Ken-11", "Ollie-15" -> "Ned-14",       "Ollie-15" -> "Sam-19", "Pat-16" -> "Al-1", "Pat-16" -> "Bru-2",       "Quinn-17" -> "Al-1", "Quinn-17" -> "Bru-2", "Quinn-17" -> "Chas-3",       "Quinn-17" -> "Dave-4", "Quinn-17" -> "Ed-5",       "Quinn-17" -> "Frank-6", "Quinn-17" -> "Gra-7",       "Quinn-17" -> "Hal-8", "Quinn-17" -> "Ian-9", "Quinn-17" -> "Jo-10",       "Quinn-17" -> "Ken-11", "Quinn-17" -> "Leo-12",       "Quinn-17" -> "Ned-14", "Quinn-17" -> "Ollie-15",       "Quinn-17" -> "Pat-16", "Quinn-17" -> "Sam-19",       "Quinn-17" -> "Tom-20", "Quinn-17" -> "Unwin-21",       "Ron-18" -> "Bru-2", "Sam-19" -> "Al-1", "Sam-19" -> "Bru-2",       "Sam-19" -> "Chas-3", "Sam-19" -> "Ed-5", "Sam-19" -> "Ken-11",       "Sam-19" -> "Leo-12", "Sam-19" -> "Ned-14", "Sam-19" -> "Ollie-15",       "Sam-19" -> "Tom-20", "Tom-20" -> "Ken-11", "Tom-20" -> "Ron-18",       "Unwin-21" -> "Bru-2", "Unwin-21" -> "Leo-12",       "Unwin-21" -> "Quinn-17", "Unwin-21" -> "Ron-18"}      UPDATE It would also be ideal to be able to colour-code the vertexes according to the the final column in the list below (numbered from 0 to 4).               {{"Al-1", 33., 9.333, 3., 4.}, {"Bru-2", 42., 19.583, 2.,        4.}, {"Chas-3", 40., 12.75, 3., 2.}, {"Dave-4", 33., 7.5, 3.,        4.}, {"Ed-5", 32., 3.333, 3., 2.}, {"Frank-6", 59., 28., 3.,        1.}, {"Gra-7", 55., 30., 1., 0.}, {"Hal-8", 34., 11.333, 3.,        1.}, {"Ian-9", 62., 5.417, 3., 2.}, {"Jo-10", 37., 9.25, 3.,        3.}, {"Ken-11", 46., 27., 3., 3.}, {"Leo-12", 34., 8.917, 3.,        1.}, {"Mal-13", 48., 0.25, 3., 2.}, {"Ned-14", 43., 10.417, 2.,        2.}, {"Ollie-15", 40., 8.417, 3., 2.}, {"Pat-16", 27., 4.667, 3.,        4.}, {"Quinn-17", 30., 12.417, 3., 1.}, {"Ron-18", 33., 9.083, 2.,        3.}, {"Sam-19", 32., 4.833, 3., 2.}, {"Tom-20", 38., 11.667, 3.,        2.}, {"Unwin-21", 36., 12.5, 2., 1.}}      I can easily make up a labelling type of table               {{"Al-1" -> 3.}, {"Bru-2" -> 2.}, {"Chas-3" -> 3.}, {"Dave-4" ->         3.}, {"Ed-5" -> 3.}, {"Frank-6" -> 3.}, {"Gra-7" ->         1.}, {"Hal-8" -> 3.}, {"Ian-9" -> 3.}, {"Jo-10" ->         3.}, {"Ken-11" -> 3.}, {"Leo-12" -> 3.}, {"Mal-13" ->         3.}, {"Ned-14" -> 2.}, {"Ollie-15" -> 3.}, {"Pat-16" ->         3.}, {"Quinn-17" -> 3.}, {"Ron-18" -> 2.}, {"Sam-19" ->         3.}, {"Tom-20" -> 3.}, {"Unwin-21" -> 2.}}      But do I map the number to a colour? I was thinking some kind of rule or assignment to VertexStyle, eg. {0->Black,1->Blue,2->Green,3->Red,4->Yellow}, but exactly how to apply it I am not sure.


title: Particular solutions of a Differential Equation not evaluated in a given case

text: Below first case which gives particular solutions of an OED correctly:               ClearAll[soln];                            (* case 1 *)     soln[a_?NumericQ] :=      soln[a] =      DSolve[{y''[t] + y[t] == Sin[t], y[0] == a, y'[0] == 0}, y[t],       t];          res1  =  Grid[     Partition[      Table [soln[i][[1, 1, 2]], {i, 0, 2, 1}] // FullSimplify , 1],       Frame -> All]       As the OED is manipulated elsewhere in my notebook I need to rewrite the above code using an assignment for the equation:                ClearAll[solp];                                       (* case 2 *)      eqd := {y''[t] + y[t] == Sin[t], y[0] == a, y'[0] == 0};      solp[a_?NumericQ] := solp[a] = DSolve[eqd, y[t], t];           res2  =        Grid[Partition[       Table [solp[i][[1, 1, 2]], {i, 0, 2, 1}] // FullSimplify , 1],       Frame -> All]      However this time I only get the general solution with the particular solutions left unevaluated for the arbitray value "a". What's wrong here? I checked that it is possible to use an assignement for the equation given to DSolve but after rewriting the first case like that:               solq = DSolve[eqd, y[t], t] ;                 (* case 3 *)     res3  =  Grid[     Partition[      Table [solq[[1, 1, 2]] /. a -> i, {i, 0, 2, 1}] // FullSimplify ,      1], Frame -> All]        res3 == res1       Why is it OK here and not in case 2? Thanks


title: Copy As Latex automatically alphabetizes words

text: If you take the following line, right click on it and `Copy As Latex`:               Cell[BoxData[RowBox[{"what", " ", "are", " ", "you", "  ", "mode", " ",       Cell["f(x)", "Title"]}]], "Text",       CellChangeTimes->{{3.578697794669105*^9, 3.5786978134524927`*^9}}]      The result of pasting that is:               \text{are}\text{mode}\text{what}\text{you}\text{f(x)}      which is an alphabetization of the original set of words. How is it possible to copy the original text into $\LaTeX$ while preserving the ordering. Sometimes this kind of disorder occurs in converting to `TraditionalForm`.               ExportString[     Cell[BoxData[RowBox[{"what"," ","are"," ","you","  ","mode"," ",      Cell["f(x)","Title"]}]], "Text",        CellChangeTimes->{{3.578697794669105*^9,3.5786978134524927`*^9}}],"Tex"]      it's ok. how to add an item named `ExportLatexToString` below `Copy As Latex` in the menu comes via right click whose function is what `ExportString` done here, i.e. without the disorder of words? My system is Windows-8 X64, Mathematica 9.0.1 Updating1: I found `TextCell` and `TextData` should have not such disorders, maybe this is one of the right track, but the problem is how to convert default text- style-cell to `TextCell` like this one               CellPrint[TextCell[Row[{Style["bold", FontWeight->Bold], " are"}],"Text"]]


title: Is there a clean way to extract the subspaces invariant under a list of matrices?

text: Let's say I have some $n \times n$ square matrices $A_1, A_2, \ldots, A_m$ with exact numbers for entries, and I want to find the subspaces of $V = \mathbb{C}^n$ invariant under these matrices. Is there a clean way to do this? The way I'm doing it seems to require writing ridiculous amounts of code from scratch to do things like calculate intersections, get all the invariant subspaces belonging to a particular generalized eigenspace, etc.


title: Plotting a mixture CDF with a truncated distribution in version 7

text: I'd like to plot the CDF of the following pdf in _Mathematica_ 7: $$f(x)=0.1 g(x)+0.85 m(x)+0.05 h(x)$$ where $$ \begin{array}{ccl} g(x)&:&P(0)=1,\ P(x\neq 0)=0\\\ h(x)&:&P(1)=1,\ P(x\neq 1)=0 \end{array} $$ and $m(x)$ is a truncated normal distribution between `{0, 1}` of `NormalDistribution[0.85, 0.1]` My code for the moment is (I used the code from MixtureDistribution in Mathematica 7):               Clear@MixtureDistribution     MixtureDistribution /: CDF[MixtureDistribution[wts_List, dist_List]] :=         With[{normWts = Normalize[wts, Total], cdfs = CDF[#, \[FormalX]] & /@ dist},              Evaluate[Total[normWts cdfs] /. \[FormalX] -> #] &]     MixtureDistribution /:          CDF[m : MixtureDistribution[wts_List, dist_List], x_] := CDF[m]@x          truncf = PDF[NormalDistribution[0.85, .1], x] /          (CDF[NormalDistribution[0.85, .1], 1] - CDF[NormalDistribution[0.85, .1], 0]);          ℳ = MixtureDistribution[{0.1, 0.85, 0.05},              {DiscreteUniformDistribution[{0, 0}], truncf, DiscreteUniformDistribution[{1, 1}]}];          Plot[CDF[ℳ]@x, {x, 0, 1}, Filling -> Axis]      I get a blank plot without any distribution plotted... Any ideas how to fix this?


title: What kind of Mathematica license do i need to create cdf documents for my students and put them on my (academic) page at the university?

text: I'm an enthusiastic university teacher willing to exploit _Mathematica_ for teaching purposes. I would like to know what kind of _Mathematica_ license would let me:   1. create notebooks and cdf documents to distribute to students   2. and put those documents on my academic page at the university so that my students can interact with the cdfs online. My university does not hold a license, so I'm willing to buy one but I need to be sure it will cover my needs, that's why i'm asking. I would be very grateful for any answers or suggestions on this matter.


title: StreamColorFunction ignored when setting to the RGB color

text: Recently I needed to color streamlines with exact color (e.g. RGBColor[0.1,0.478,0.5]). The help (http://reference.wolfram.com/language/ref/StreamColorFunction.html) suggests, that this can be achieved by setting StreamColorFunction to some value ("The function specified by StreamColorFunction must return color directives such as RGBColor and Hue or named colors such as Red and Blue."), however in the examples the only option used is "hue", which produces rather fancy colored streams for me (?). I'd like to have all streams e.g. Red, or Yellow, but all of the following codes:               StreamPlot[{x, -y}, {x, -1, 1}, {y, -1, 1}, StreamColorFunction -> Yellow]          StreamPlot[{x, -y}, {x, -1, 1}, {y, -1, 1}, StreamColorFunction -> Red]          StreamPlot[{x, -y}, {x, -1, 1}, {y, -1, 1}, StreamColorFunction -> RGBColor[0,0,0]]      produces default blue streamlines, instead of yellow, red or black (there is a slight possibility that I'm color blinded since today, but I doubt it :)). Why is the StreamColorFunction behaving this way? Is there a possibility to color streams with any color I like? Any help'd be much appreciated.


title: Visualizing multi-state lattice from a data set

text: Is there any way to make Mathematica visualize a multistate square lattice? That is, I have a data set from a simulation that is _x_ coloumns wide and _y_ rows tall (just a simple .dat file), where each cell has a value *n_i = 0,1,2,3* - and I then want Mathematica to draw a _x_ by _y_ square lattice and color each square in the lattice corresponding to the state in the data set, e.g. 0 = red, 1 = green, 2 = blue, 3 = yellow.


title: Better code to solve number puzzle

text: **Question:** (34 O 5 O 6 O 8 O 9 O 1) O 2=2008 Replace the Symbol of "O" to "+" or "-" or "*",and make the expression is true. **My solution:**               info = {{"+"}, {"-"}, {"*"}};          For[a = 1, a < 4, a++,        For[b = 1, b < 4, b++,          For[c = 1, c < 4, c++,            For[d = 1, d < 4, d++,              For[e = 1, e < 4, e++,               For[f = 1, f < 4, f++,                    temp = StringJoin["(34", Part[info, a], "5", Part[info, b], "6",          Part[info, c], "8", Part[info, d], "9", Part[info, e], "1)",          Part[info, f], "2"];       If[ToExpression[temp] == 2008, Print[temp]]           ]          ]         ]        ]       ]     ]      **The results:** (34*5*6-8-9+1)*2==2008


title: Speed up series expansion

text: I have a rather complicated function that I need to expand it in series, which is quite straightforward but takes a long time. I was wondering if there is a way to speed up such a calculation:               Series[1/(1 + x)^2 y z/.{x->x1+x2+x3+x4,y->y1+y2+y3+y4,z->z1+z2+z3+z4},{x1,0,2},{x2,0,2},{x3,0,2},{x4,0,2},{y1,0,2},{y2,0,2},{y3,0,2},{y4,0,2},{z1,0,2},{z2,0,2},{z3,0,2},{z4,0,2}]      Now the one,sth seconds the above needs to be computed on my laptop is not dramatic but the function I consider is way more complicated and runtime is in the order of hours...Thanks for any advice!


title: Best way to power series expand in multiple variables?

text: A power series expansion of a multivariate function can be performed with the `Series` command, which performs each expansion consecutively. The results can be a bit clunky, however. Often "mixed" terms will show up. For instance, a function f(x,y) expanded to the first order about zero in x then y will often have terms `a*x*y` with `a` some constant. Since we've aske for a first-order expansion, terms like `a*x*y` are undesirable. It is easy-enough to fix this in the two-variable case with something like this.               ReplaceAll[#,{x*y :> 0}]&      But in n variables, an explosion in the number of possible combinations becomes prohibitive to use this "by-hand" type of fix. Is there an elegant solution to this? I could write a routine to generate all combinations and corresponding list of replacement rules, but this seems... excessive. Is there a better way to perform the expansion that avoids this? Or is there an elegant simplification method?


title: Placing some controls above and some below plot

text: The code below is something I wrote quickly to simulate the problem I'm having with more complex code. I use Row (or Grid) to get the first 2 manipulate variables (a and b) on one line above the plot and I want the other 2 variables (c and d) in one line below the plot. I can get the controls where I want them without Row (or Grid) but then they appear in a column. Whenever I add Row all controls appear to have the same placement. I wasn't able to find any other posts that could help me with this problem.               Manipulate[      f = a*x^3 + b*x^2 + c*x + d;      Plot[f, {x, -4, 4}],      Row[{        Control[{{a, 1, "a"}, 0, 3, ControlPlacement -> Top}],        Control[{{b, 2, "b"}, 0, 5, ControlPlacement -> Top}]        }],      Row[{        Control[{{c, 1, "c"}, 0, 4, ControlPlacement -> Bottom}],        Control[{{d, 0, "d"}, 0, 2, ControlPlacement -> Bottom}]        }]      ]      ![enter image description here](http://i.stack.imgur.com/NXE26.jpg)


title: Bring Vertices to the foreground

text: I'm having some issues with being able to trigger the Tooltip in an AdjacencyGraph, as the edges are "covering" the vertex labels. In the example provided, there are no issues to display the tooltip when you are hovering above GLD, but I can't make the tooltip be displayed when hovering above EWK. Here is the code                   graphsty = Sequence[ImageSize -> Large, VertexLabels -> {1 -> Tooltip[Style["DBC", LineColor -> GrayLevel[0.3], FrontFaceColor -> GrayLevel[0.3], BackFaceColor -> GrayLevel[0.3],             GraphicsColor -> GrayLevel[0.3], FontFamily -> "Verdana", FontSize -> 10, FontWeight -> Bold, FontColor -> GrayLevel[0.3]],            Column[{" PowerShares DB Commodity Index ", " Commodities"}, Alignment -> Left, ItemSize -> {Automatic, Automatic}]],          2 -> Tooltip[Style["GLD", LineColor -> GrayLevel[0.3], FrontFaceColor -> GrayLevel[0.3], BackFaceColor -> GrayLevel[0.3], GraphicsColor -> GrayLevel[0.3], FontFamily -> "Verdana",             FontSize -> 10, FontWeight -> Bold, FontColor -> GrayLevel[0.3]], Column[{" SPDR Gold Shares ", " Commodities"}, Alignment -> Left, ItemSize -> {Automatic, Automatic}]],          3 -> Tooltip[Style["CSJ", LineColor -> GrayLevel[0.3], FrontFaceColor -> GrayLevel[0.3], BackFaceColor -> GrayLevel[0.3], GraphicsColor -> GrayLevel[0.3], FontFamily -> "Verdana",             FontSize -> 10, FontWeight -> Bold, FontColor -> GrayLevel[0.3]], Column[{" iShares Barclays 1-3 Year Credit (2yr) ", " Corporate/Credit Bonds"}, Alignment -> Left,             ItemSize -> {Automatic, Automatic}]], 4 -> Tooltip[Style["LQD", LineColor -> GrayLevel[0.3], FrontFaceColor -> GrayLevel[0.3], BackFaceColor -> GrayLevel[0.3],             GraphicsColor -> GrayLevel[0.3], FontFamily -> "Verdana", FontSize -> 10, FontWeight -> Bold, FontColor -> GrayLevel[0.3]],            Column[{" iShares iBoxx Invest Grade Bond (7-8yr) ", " Corporate/Credit Bonds"}, Alignment -> Left, ItemSize -> {Automatic, Automatic}]],          5 -> Tooltip[Style["VCLT", LineColor -> GrayLevel[0.3], FrontFaceColor -> GrayLevel[0.3], BackFaceColor -> GrayLevel[0.3], GraphicsColor -> GrayLevel[0.3],             FontFamily -> "Verdana", FontSize -> 10, FontWeight -> Bold, FontColor -> GrayLevel[0.3]], Column[{" Vanguard Long-Term Corp Bond (12+yr) ", " Corporate/Credit Bonds"},             Alignment -> Left, ItemSize -> {Automatic, Automatic}]], 6 -> Tooltip[Style["SSO", LineColor -> GrayLevel[0.3], FrontFaceColor -> GrayLevel[0.3],             BackFaceColor -> GrayLevel[0.3], GraphicsColor -> GrayLevel[0.3], FontFamily -> "Verdana", FontSize -> 10, FontWeight -> Bold, FontColor -> GrayLevel[0.3]],            Column[{" +2x ProShares Leveraged Long S&P 500 ", " Derivatives - Leveraged and Volatility Products"}, Alignment -> Left, ItemSize -> {Automatic, Automatic}]],          7 -> Tooltip[Style["EWX", LineColor -> GrayLevel[0.3], FrontFaceColor -> GrayLevel[0.3], BackFaceColor -> GrayLevel[0.3], GraphicsColor -> GrayLevel[0.3], FontFamily -> "Verdana",             FontSize -> 10, FontWeight -> Bold, FontColor -> GrayLevel[0.3]], Column[{" SPDR S&P Emerging Markets Small Cap ", " Emerging Markets Equity"}, Alignment -> Left,             ItemSize -> {Automatic, Automatic}]], 8 -> Tooltip[Style["VWO", LineColor -> GrayLevel[0.3], FrontFaceColor -> GrayLevel[0.3], BackFaceColor -> GrayLevel[0.3],             GraphicsColor -> GrayLevel[0.3], FontFamily -> "Verdana", FontSize -> 10, FontWeight -> Bold, FontColor -> GrayLevel[0.3]],            Column[{" Vanguard MSCI Emerging Markets ", " Emerging Markets Equity"}, Alignment -> Left, ItemSize -> {Automatic, Automatic}]],          9 -> Tooltip[Style["ACWI", LineColor -> GrayLevel[0.3], FrontFaceColor -> GrayLevel[0.3], BackFaceColor -> GrayLevel[0.3], GraphicsColor -> GrayLevel[0.3],             FontFamily -> "Verdana", FontSize -> 10, FontWeight -> Bold, FontColor -> GrayLevel[0.3]], Column[{" iShares MSCI All-World ACWI Index ", " International Equity"},             Alignment -> Left, ItemSize -> {Automatic, Automatic}]], 10 -> Tooltip[Style["EFA", LineColor -> GrayLevel[0.3], FrontFaceColor -> GrayLevel[0.3],             BackFaceColor -> GrayLevel[0.3], GraphicsColor -> GrayLevel[0.3], FontFamily -> "Verdana", FontSize -> 10, FontWeight -> Bold, FontColor -> GrayLevel[0.3]],            Column[{" iShares MSCI EAFE Index ", " International Equity"}, Alignment -> Left, ItemSize -> {Automatic, Automatic}]],          11 -> Tooltip[Style["VEU", LineColor -> GrayLevel[0.3], FrontFaceColor -> GrayLevel[0.3], BackFaceColor -> GrayLevel[0.3], GraphicsColor -> GrayLevel[0.3],             FontFamily -> "Verdana", FontSize -> 10, FontWeight -> Bold, FontColor -> GrayLevel[0.3]], Column[{" Vanguard FTSE All-World ex-US ", " International Equity"},             Alignment -> Left, ItemSize -> {Automatic, Automatic}]], 12 -> Tooltip[Style["BWX", LineColor -> GrayLevel[0.3], FrontFaceColor -> GrayLevel[0.3],             BackFaceColor -> GrayLevel[0.3], GraphicsColor -> GrayLevel[0.3], FontFamily -> "Verdana", FontSize -> 10, FontWeight -> Bold, FontColor -> GrayLevel[0.3]],            Column[{" SPDR Barcap Global Ex-U.S. Bond (6-7yr) ", " Int'l Bonds / Currencies"}, Alignment -> Left, ItemSize -> {Automatic, Automatic}]],          13 -> Tooltip[Style["ELD", LineColor -> GrayLevel[0.3], FrontFaceColor -> GrayLevel[0.3], BackFaceColor -> GrayLevel[0.3], GraphicsColor -> GrayLevel[0.3],             FontFamily -> "Verdana", FontSize -> 10, FontWeight -> Bold, FontColor -> GrayLevel[0.3]], Column[{" WisdomTree Emerg Mkts Local Debt (4-5yr) ", " Int'l Bonds / Currencies"},             Alignment -> Left, ItemSize -> {Automatic, Automatic}]], 14 -> Tooltip[Style["UUP", LineColor -> GrayLevel[0.3], FrontFaceColor -> GrayLevel[0.3],             BackFaceColor -> GrayLevel[0.3], GraphicsColor -> GrayLevel[0.3], FontFamily -> "Verdana", FontSize -> 10, FontWeight -> Bold, FontColor -> GrayLevel[0.3]],            Column[{" PowerShares DB U.S. Dollar Index ", " Int'l Bonds / Currencies"}, Alignment -> Left, ItemSize -> {Automatic, Automatic}]],          15 -> Tooltip[Style["AMJ", LineColor -> GrayLevel[0.3], FrontFaceColor -> GrayLevel[0.3], BackFaceColor -> GrayLevel[0.3], GraphicsColor -> GrayLevel[0.3],             FontFamily -> "Verdana", FontSize -> 10, FontWeight -> Bold, FontColor -> GrayLevel[0.3]],            Column[{" J.P. Morgan Alerian MLP Index ", " Quasi-Equity: REITs, Preferreds, MLPs etc"}, Alignment -> Left, ItemSize -> {Automatic, Automatic}]],          16 -> Tooltip[Style["PFF", LineColor -> GrayLevel[0.3], FrontFaceColor -> GrayLevel[0.3], BackFaceColor -> GrayLevel[0.3], GraphicsColor -> GrayLevel[0.3],             FontFamily -> "Verdana", FontSize -> 10, FontWeight -> Bold, FontColor -> GrayLevel[0.3]],            Column[{" iShares S&P US Preferred Stock Index ", " Quasi-Equity: REITs, Preferreds, MLPs etc"}, Alignment -> Left, ItemSize -> {Automatic, Automatic}]],          17 -> Tooltip[Style["VNQ", LineColor -> GrayLevel[0.3], FrontFaceColor -> GrayLevel[0.3], BackFaceColor -> GrayLevel[0.3], GraphicsColor -> GrayLevel[0.3],             FontFamily -> "Verdana", FontSize -> 10, FontWeight -> Bold, FontColor -> GrayLevel[0.3]], Column[{" Vanguard MSCI U.S. REIT ", " Quasi-Equity: REITs, Preferreds, MLPs etc"},             Alignment -> Left, ItemSize -> {Automatic, Automatic}]], 18 -> Tooltip[Style["DIA", LineColor -> GrayLevel[0.3], FrontFaceColor -> GrayLevel[0.3],             BackFaceColor -> GrayLevel[0.3], GraphicsColor -> GrayLevel[0.3], FontFamily -> "Verdana", FontSize -> 10, FontWeight -> Bold, FontColor -> GrayLevel[0.3]],            Column[{" SPDR Dow Jones Industrial Average ", " U.S. Equity"}, Alignment -> Left, ItemSize -> {Automatic, Automatic}]],          19 -> Tooltip[Style["IWM", LineColor -> GrayLevel[0.3], FrontFaceColor -> GrayLevel[0.3], BackFaceColor -> GrayLevel[0.3], GraphicsColor -> GrayLevel[0.3],             FontFamily -> "Verdana", FontSize -> 10, FontWeight -> Bold, FontColor -> GrayLevel[0.3]], Column[{" iShares Russell 2000 Index Fund ", " U.S. Equity"}, Alignment -> Left,             ItemSize -> {Automatic, Automatic}]], 20 -> Tooltip[Style["QQQ", LineColor -> GrayLevel[0.3], FrontFaceColor -> GrayLevel[0.3], BackFaceColor -> GrayLevel[0.3],             GraphicsColor -> GrayLevel[0.3], FontFamily -> "Verdana", FontSize -> 10, FontWeight -> Bold, FontColor -> GrayLevel[0.3]],            Column[{" PowerShares Nasdaq-100 Index ", " U.S. Equity"}, Alignment -> Left, ItemSize -> {Automatic, Automatic}]],          21 -> Tooltip[Style["SPY", LineColor -> GrayLevel[0.3], FrontFaceColor -> GrayLevel[0.3], BackFaceColor -> GrayLevel[0.3], GraphicsColor -> GrayLevel[0.3],             FontFamily -> "Verdana", FontSize -> 10, FontWeight -> Bold, FontColor -> GrayLevel[0.3]], Column[{" SPDR S&P 500 Index ", " U.S. Equity"}, Alignment -> Left,             ItemSize -> {Automatic, Automatic}]], 22 -> Tooltip[Style["VTI", LineColor -> GrayLevel[0.3], FrontFaceColor -> GrayLevel[0.3], BackFaceColor -> GrayLevel[0.3],             GraphicsColor -> GrayLevel[0.3], FontFamily -> "Verdana", FontSize -> 10, FontWeight -> Bold, FontColor -> GrayLevel[0.3]],            Column[{" Vanguard MSCI Total U.S. Stock Market ", " U.S. Equity"}, Alignment -> Left, ItemSize -> {Automatic, Automatic}]],          23 -> Tooltip[Style["IEF", LineColor -> GrayLevel[0.3], FrontFaceColor -> GrayLevel[0.3], BackFaceColor -> GrayLevel[0.3], GraphicsColor -> GrayLevel[0.3],             FontFamily -> "Verdana", FontSize -> 10, FontWeight -> Bold, FontColor -> GrayLevel[0.3]], Column[{" iShares Barclays 7-10 Yr Treasury (7-8yr) ", " U.S. Treasury Bonds/TIPS"},             Alignment -> Left, ItemSize -> {Automatic, Automatic}]], 24 -> Tooltip[Style["TIP", LineColor -> GrayLevel[0.3], FrontFaceColor -> GrayLevel[0.3],             BackFaceColor -> GrayLevel[0.3], GraphicsColor -> GrayLevel[0.3], FontFamily -> "Verdana", FontSize -> 10, FontWeight -> Bold, FontColor -> GrayLevel[0.3]],            Column[{" iShares Barclays TIPS (4-8yr) ", " U.S. Treasury Bonds/TIPS"}, Alignment -> Left, ItemSize -> {Automatic, Automatic}]]}, VertexSize -> Large,        GraphLayout -> {"PackingLayout" -> "ClosestPacking"}, ImagePadding -> 20, VertexStyle -> {1 -> RGBColor[0.6980392156862745, 0.01568627450980392, 0.],          2 -> RGBColor[0.6980392156862745, 0.01568627450980392, 0.], 3 -> RGBColor[0.9372549019607843, 0.6274509803921569, 0.16862745098039217],          4 -> RGBColor[0.9372549019607843, 0.6274509803921569, 0.16862745098039217], 5 -> RGBColor[0.9372549019607843, 0.6274509803921569, 0.16862745098039217],          6 -> RGBColor[0.7254901960784313, 0.8, 0.07058823529411765], 7 -> RGBColor[0.17254901960784313, 0.3607843137254902, 0.07058823529411765],          8 -> RGBColor[0.17254901960784313, 0.3607843137254902, 0.07058823529411765], 9 -> RGBColor[0.22745098039215686, 0.23921568627450981, 0.45098039215686275],          10 -> RGBColor[0.22745098039215686, 0.23921568627450981, 0.45098039215686275], 11 -> RGBColor[0.22745098039215686, 0.23921568627450981, 0.45098039215686275],          12 -> RGBColor[0.5607843137254902, 0.5254901960784314, 0.5647058823529412], 13 -> RGBColor[0.5607843137254902, 0.5254901960784314, 0.5647058823529412],          14 -> RGBColor[0.5607843137254902, 0.5254901960784314, 0.5647058823529412], 15 -> RGBColor[0.9215686274509803, 0.49411764705882355, 0.43137254901960786],          16 -> RGBColor[0.9215686274509803, 0.49411764705882355, 0.43137254901960786], 17 -> RGBColor[0.9215686274509803, 0.49411764705882355, 0.43137254901960786],          18 -> RGBColor[0.9921568627450981, 0.8156862745098039, 0.49019607843137253], 19 -> RGBColor[0.9921568627450981, 0.8156862745098039, 0.49019607843137253],          20 -> RGBColor[0.9921568627450981, 0.8156862745098039, 0.49019607843137253], 21 -> RGBColor[0.9921568627450981, 0.8156862745098039, 0.49019607843137253],          22 -> RGBColor[0.9921568627450981, 0.8156862745098039, 0.49019607843137253], 23 -> RGBColor[0.3176470588235294, 0.49019607843137253, 0.0784313725490196],          24 -> RGBColor[0.3176470588235294, 0.49019607843137253, 0.0784313725490196]}];     m = {{0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,          1, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,          0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,          0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 1, 0, 0, 0, 0, 0,          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1}, {1, 0, 0, 0, 0, 0,          1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, {1, 0, 0,          0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0,          0}, {1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1,          1, 1, 0, 0}, {1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1,          1, 1, 1, 1, 1, 0, 0}, {1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0,          0, 0, 1, 1, 1, 1, 1, 1, 0, 0}, {1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0,          0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0,          0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {1, 0, 0, 0, 0,          1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0}, {0, 0,          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,          0}, {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,          1, 1, 0, 0}, {0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0,          0, 0, 0, 1, 1, 0, 0}, {0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0,          0, 0, 0, 1, 1, 1, 1, 1, 0, 0}, {1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,          0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0}, {1, 0, 0, 0, 0, 1, 1, 1,          1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0}, {1, 0, 0, 0, 0,          1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0}, {1, 0,          0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0,          0}, {1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1,          1, 0, 0, 0}, {0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,          0, 0, 0, 0, 0, 0, 1}, {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,          0, 0, 0, 0, 0, 0, 0, 0, 1, 0}};     g = AdjacencyGraph[m, graphsty]


title: Mathematica Basic Plotting Question

text: Is it possible to plot `y = x^2` and `x = y^2` on the some graph? For some reason, I can't get it to plot the `x = y^2` properly. Here is what I get:               Show[{ Plot[x == y^2, {y, -1, 1}], Plot[y = x^2, {x, -1, 1}]}]      ![enter image description here](http://i.stack.imgur.com/V03MN.png) Thank you for your time.


title: How to know form of plotted Bezier function

text: Simple scenario is to see the Bezier function, but how to know which polynomial approximate it?               pts = {{0, -1}, {1, 0}, {2, -1}};     Graphics[{BezierCurve[pts], Green, Line[pts], Red, Point[pts]}]


title: Speeding up solving a system of simultaneous equations

text: I am trying to solve the following system of equations. Solve takes a very long time to solve the following system of equations. Is there any way to speed it up? ![enter image description here](http://i.stack.imgur.com/jBZpb.png)               l = 4;     vars = Flatten[Table[{a[i], b[i], c[i], d[i]}, {i, l}]];          eq1 ={{x (x a[1] + x b[1] + d[1] (1 - 2 z[1]) +            c[1] (-1 + 2 z[1]))}, {x (x a[1] - x b[1] + 2 c[1] z[1] +            2 d[1] z[1])}} == {{1}, {0}};          eq2={{a[4]}, {c[4]}} == {{0}, {0}};          eq3=Table[     {{E^(x h[i]) x a[i]+E^(-x h[i]) x b[i]+E^(-x h[i]) d[i] (1+x h[i]-2 z[i])+E^(x h[i]) c[i] (-1+x h[i]+2 z[i])},{E^(x h[i]) x a[i]-E^(-x h[i]) x b[i]+E^(-x h[i]) d[i] (-x h[i]+2 z[i])+E^(x h[i]) c[i] (x h[i]+2 z[i])},{-((E^(x h[i]) x a[i] (1+z[i]))/y[i])+(E^(-x h[i]) x b[i] (1+z[i]))/y[i]+(E^(x h[i]) c[i] (2-x h[i]-4 z[i]) (1+z[i]))/y[i]+(E^(-x h[i]) d[i] (2+x h[i]-4 z[i]) (1+z[i]))/y[i]},{-((E^(x h[i]) x a[i] (1+z[i]))/y[i])-(E^(-x h[i]) x b[i] (1+z[i]))/y[i]+(E^(-x h[i]) d[i] (1-x h[i]) (1+z[i]))/y[i]-(E^(x h[i]) c[i] (1+x h[i]) (1+z[i]))/y[i]}}=={{x a[1+i]+x b[1+i]+d[1+i] (1-2 z[1+i])+c[1+i] (-1+2 z[1+i])},{x a[1+i]-x b[1+i]+2 c[1+i] z[1+i]+2 d[1+i] z[1+i]},{-((x a[1+i] (1+z[1+i]))/y[1+i])+(x b[1+i] (1+z[1+i]))/y[1+i]+(c[1+i] (2-4 z[1+i]) (1+z[1+i]))/y[1+i]+(d[1+i] (2-4 z[1+i]) (1+z[1+i]))/y[1+i]},{-((x a[1+i] (1+z[1+i]))/y[1+i])-(x b[1+i] (1+z[1+i]))/y[1+i]-(c[1+i] (1+z[1+i]))/y[1+i]+(d[1+i] (1+z[1+i]))/y[1+i]}}     ,{i, l - 1}];          Solve[Join[{eq1, eq2}, eq3], vars]      The notebook file containing equations in matrix form can be downloaded from the following link: Solve Problem.nb


title: How to get the coefficient list

text: polynomial=-x^4+2 b x^3+(b^2-c^2+2 c) x^2+(2 b c-2 c d) x+c^2-d^2      This is good               CoefficientList[polynomial, x]      But how to get coefficient list from the `PolynomialForm`? I've tried this, but it does not give the coefficient list.               CoefficientList[PolynomialForm@polynomial,x]


title: How to remove a line of a matrix if not all elements are numeric?

text: I have a matrix a `n` columns and `m` lines. I'd like to efficiently remove the lines that are not entirely composed of numeric values, lines like this:               {6.22926,6.23254,6.23128,,6.23453,6.22548,6.22938,6.23443,}      In this case the last element. The matrix is quite big, I have no clue what an efficient method would be.


title: Plot of a function which includes numerical integrals

text: I want to make a 3D plot of two variable i1 and b1. The dependent variable results from a pay-off function               payoff1 :=  q1*((1 + g1)*b1*10000 - i1*10000) - (1 - q1)*(1 - d)*i1*10000      The problem is that q1 is actually the result from an integral calculation:               q1 := NIntegrate[combo1, {x, 0, 2000000}]      where "combo1" is a function that is defined higher and that is also dependent on i1 and b1. I want to make this plot:               Plot3D[payoff1, {i1, 0, 20}, {b1, 0, 50}]      So for every value of i1 and b1, it should make the q1-calculation, but what _Mathematica_ does (because I think I have a bug in my code here) is to always take the initial q1 value. How could I solve this problem? Thank you! The entire code can be found here: First some parameters are introduced:               mue = 0.25     mui = 0.25     lambdae = 0.25     lambdai = 0.25     sigmap = 0.05     betae = 0.05     betai = 0.05     gammae = 0.10     gammai = 0.50     d = 0.8     experience1 = 7     experience2 = 6      Some functions are added:               g1 := betae*Exp[-mue*experience1] + betai*Exp[-mui*i1]     g2 := betae*Exp[-mue*experience2] + betai*Exp[-mui*i2]     sd1 := Sqrt[sigmap^2 + (gammae*Exp[-lambdae*experience1])^2 + (gammai*        Exp[-lambdai*i1])^2]*1000000     sd2 := Sqrt[sigmap^2 + (gammae*Exp[-lambdae*experience2])^2 + (gammai*        Exp[-lambdai*i2])^2]*1000000          bid1 := NormalDistribution[1000000*(1 + g1)*(1 + b1/100), sd1]     bid2 := NormalDistribution[1000000*(1 + b2/100) (1 + g2), sd2]          pbid1 := PDF[bid1, x]     pbid2 := PDF[bid2, x]     cbid1 := 1 - CDF[bid1, x]     cbid2 := 1 - CDF[bid2, x]     combo1 := pbid1*cbid2          q1 := NIntegrate[combo1, {x, 0, 2000000}]          combo2 := pbid2*cbid1          q2 := NIntegrate[combo2, {x, 0, 2000000}]               payoff1 := q1*((1 + g1)*b1*10000 - i1*10000) - (1 - q1)*(1 - d)*i1*10000     payoff2 := q2*((1 + g2)*b2*10000 - i2*10000) - (1 - q2)*(1 - d)*i2*10000      And now I want to make the plot for payoff1, given that (example):               i2 = 5     b2 = 10          Plot3D[payoff1, {i1, 0, 20}, {b1, 0, 50}]      If I make a plot for q1, I think I get the right one, but the one of the pay- off does not seem correct/logic. Afterwards I will need to solve the system of equations (given that now i1,i2,b1 and b2 are unknown) There is also still a problem, but that might be caused by the above stated problem.               eq1 := D[payoff1, i1]     eq2 := D[payoff1, b1]     eq3 := D[payoff2, i2]     eq4 := D[payoff2, b2]          FindRoot[{eq1 == 0, eq2 == 0, eq3 == 0, eq4 == 0}  , {{i1, 5}, {i2, 5}, {b1, 5}, {b2, 5}}]      I am very new to the world of Mathematica, so thank you for any help. Regards, ## Dennis New code: I implemented the new code now, but than a numerical integration error occurs and there is already a problem by making pbid1 (a normal probability distribution function). Here is the new code (so, i2 and b2 are given; i1 and b1 are unknown): The parameters that were introduced are still te same. The functions become:               g1[i1_] := betae*Exp[-mue*experience1] + betai*Exp[-mui*i1]     g2 := betae*Exp[-mue*experience2] + betai*Exp[-mui*i2]          sd1[i1_] := Sqrt[sigmap^2 + (gammae*Exp[-lambdae*experience1])^2 + (gammai*Exp[-lambdai*i1])^2]*1000000     sd2 := Sqrt[sigmap^2 + (gammae*Exp[-lambdae*experience2])^2 + (gammai*Exp[-lambdai*i2])^2]*1000000          bid1[b1_, g1_, sd1_] := NormalDistribution[1000000*(1 + g1[i1])*(1 + b1/100), sd1[i1]]     bid2 := NormalDistribution[1000000*(1 + b2/100) (1 + g2), sd2]      A problem occurs already in this statement:               pbid1[bid1_, x_] := PDF[bid1[b1, g1[i1], sd1[i1]], x]      The probability density function pbid2 causes no problems:               pbid2[x_] := PDF[bid2, x]      The remainder of the code:               cbid1[bid1_, x_] := 1 - CDF[bid1[b1, g1[i1], sd1[i1]], x]     cbid2[x_] := 1 - CDF[bid2, x]          combo1[pbid1_, cbid2_] := pbid1[bid1[b1, g1[i1], sd1[i1]], x]*cbid2[x]          q1[combo1_] := NIntegrate[combo1[pbid1[bid1[b1, g1[i1], sd1[i1]], x], cbid2[x]], {x, 0, 2000000}]      When Evaluating the integral, I get the non-numerical values error. And finally, for the pay-off, I was thinking of this formula:               payoff1[combo1_, g1_, b1_, i1_] := q1[combo1[pbid1[bid1[b1, g1[i1], sd1[i1]], x], cbid2[x]]]*((1 + g1[i1])*b1*10000 - i1*10000) - (1 - q1[combo1[pbid1[bid1[b1, g1[i1], sd1[i1]], x], cbid2[x]]])*(1 - d)*i1*10000      I have not really a clue where something is going wrong.


title: Print without linefeed

text: Is it possible to print with a carriage return but not a new line? I'd like to keep track of the progress of a long calculation without filling the screen with prints.


title: How to allow ContinuousAction on something that is not all

text: I have this code:               DynamicModule[{r = 1},     Grid[{{Slider[Dynamic[r]], SpanFromLeft},     {f[Dynamic[r]], g[Dynamic[r]]}}]]      While I move the slider, $f$ ang $g$ are evaluated continually, but only $f$ should be. I want $g$ to be evaluated only with the final value of $r$. (When I release left click) How to do this?


title: Passing down arguments

text: In R, one can use `...` to pass arguments down to another function. For example               fun <- function(arg1, ...){       print(arg1)       subfun(...)     }          subfun <- function(mex){       print(mex)     }          fun(1, "passed down")      Is there a similar construct in _Mathematica_? In particular I would like to pass down the attribute `WorkingPrecision`.


title: ConditionalExpression Limiting Domain

text: I came across a problem when evaluating the following integral: $\int_0^t \sqrt{9 x^4+1} \, dx$ Now, when I evaluate that, I get               ConditionalExpression[t Hypergeometric2F1[-(1/2), 1/4, 5/4, -9 t^4], t >= 0]      The issue is if t is negative. If I do this $\int_0^{-5} \sqrt{9 x^4+1} \, dx$ I get               -5 Hypergeometric2F1[-(1/2), 1/4, 5/4, -5625]      That seems okay, since it's a number. However, if I do this $\int_0^t \sqrt{9 x^4+1} \, dx\text{/.}t\to -5$ I get "Undefined". The issue is that I need to keep t symbolic, but still be able to use negative numbers later. I don't understand why t must be positive, especially since Mathematica seems to be able to compute it when it's negative. Does anyone know why this is happening, or what I can do to fix it? EDIT: I'm actually looking for a general solution for any function. This code is being used to calculate arc length of any function (in this case, x^3). This is just an example of it not working. Here is my actual code:               baseFunction = Function[x,x^3]     secondFunction = Sin     r[t_] = FullSimplify[p0[t] + norm[t]*a*secondFunction[b*Integrate[Sqrt[1 + Derivative[1][baseFunction][x]^2], {x, 0, t}]], Element[t, Reals]]      p0 and norm are 2D vector functions, and a and b are constants. I want to be able to use any function for baseFunction, though, which is why I need a general solution.


title: RSolve and "the given boundary conditions lead to an empty solution"

text: I am trying to solve the following recurrence relation:               c[1] = 0,          c[2] = a[1]*b[1],          c[n] = a[n]*b[n] + a[n]*c[n-1]+b[n]*c[n-1],          Modulus -> 2, a[n]*a[n]-a[n] = 0, b[n]*b[n]-b[n] = 0      `c[n]` is the recurrence that grows out of control that I am trying to solve/simplify Everything I try in `RSolve` is producing > "For some branches of the general solution, the given boundary conditions > lead to an empty solution" Can anyone help me understand the right way to approach this recurrence problem? Here is what I tried in the worksheet:               RSolve[ {c[1] == 0, c[2] == a[1]*b[1],               c[n] == a[n]*b[n] + a[n]*c[n - 1] + b[n]*c[n - 1]},               c[n], n     ]      > RSolve::bvnul: For some branches of the general solution, the given boundary > conditions lead to an empty solution. >> Now if I try to include the equations specifying that values for a and b must be 0 or 1 (a*a-a==0), I get a different error:               RSolve[ {c[1] == 0, c[2] == a[1]*b[1],              c[n] == a[n]*b[n] + a[n]*c[n - 1] + b[n]*c[n - 1],              a[n]*a[n] - a[n] == 0, b[n]*b[n] - b[n] == 0},              c[n], n     ]      > RSolve::deqx: Supplied equations are not difference equations of the given > functions. Lastly, I have no idea how to specify `Modulus -> 2` or if that matters for the purposes of recurrence relation solving.


title: Trouble outputting Plot

text: I am trying to solve a system of ODEs and plot them with Manipulate but I keep getting blank outputs. Below is my code:               f[u_, a_, b_] := 1/(1+Exp[-a*(u-b)]) - 1/(1+Exp[a*b])     InvMexHat[v_] := -(1 - Abs[v]) E^-Abs[v];     MexHat[w_] := (1 - Abs[w]) E^-Abs[w];     DecExp[x_] := E^-Abs[x];     NE0[y_] := 1/2 (Tanh[5 (y - (dx*n)/2 + 1)] - Tanh[5 (y - (dx*n)/2 - 1)]);      Manipulate[Module[{     L = n*dx,     eqs = Table[     dNE[i][t]/dt == -NE[i][t] + (1 - NE[i][t])*Sum[dx*(g[Abs[dx*i - dx*j]] + g[L - (Abs[dx*i - dx*j])]) f[NE[j][t], a, b], {j, n}],      {i, n}],     init = Table[NE[i][0] == NE0[i*dx], {i, n}],     u = Table[NE[i], {i, n}],     sol = NDSolve[       Join[eqs, init],       u,       {t, 0, T}][[1]]},     ListLinePlot[     Table[      {i*dx, NE[i][tt]}, {i, n}] /. sol,     PlotRange -> {{0, n*dx}, {-1, 1}}, ImageSize -> Scaled[0.8]]],     {tt, 0, T}, {{dx, .1}, .001, 1}, {{n, 150}, 10, 1000}, {{T, 10}, 1, 100}, {{a, 1}, 0, 10}, {{b, 5}, 1, 10}, {g, {InvMexHat, MexHat, DecExp}}]      Any comments on what I should do to modify the code to get the proper output would be helpful! Thanks!


title: Split a Unicode string maintaining uppercase characters

text: I want to split a string according to a predefined set of substrings (lowercase), though the actual text can contain uppercase characters anyplace. The task is to find the matches, longer preferred over shorter (like `"tt"` over `"t"` hence the order of `alt`) **and** to maintain upper/lowercase status. Since `StringCases` has a quirk not being able to correctly recognize some upper/lowercase characters (cf. here), the solution is not trivial. The following code matches every element in `alt` correctly, though it also converts everything to lowercase:               alt = "tt" | "t" | "a" | "á";     word = "TtattÁatT";     StringCases[ToLowerCase@word, alt]      > `{"tt", "a", "tt", "á", "a", "tt"}` The next one, while correctly maintains capital letters, fails to recognize `"Á"` as the uppercase version of `"á"` (or of `a`, see later).               StringCases[word, alt, IgnoreCase -> True]      > `{"Tt", "a", "tt", "a", "tT"}` The problem here is that `StringMatchQ` returns `False`:               StringMatchQ["A", "a", IgnoreCase -> True]       (* ==> True *)     StringMatchQ["Á", "á", IgnoreCase -> True]       (* ==> False *)     StringMatchQ["Á", "a", IgnoreCase -> True]       (* ==> False *)     StringMatchQ["Á", "á" | "a", IgnoreCase -> True] (* ==> True *)     (* for the record *)     ToLowerCase@"Á" === "á"       (* ==> True *)     ToUpperCase@"á" === "Á"       (* ==> True *)      I think it actually is a bug, as this behaviour is rather inconsistent. Nevertheless, the next code I came up with to match `"Á"` fails:               StringCases[word, __?(StringMatchQ[#, alt, IgnoreCase -> True] &), IgnoreCase -> True]      > `{"Ttatt", "atT"}` It cannot recognize `"Á"`, and it splits by the longest match instead of exact matches. Is it possible to overcome somehow this issue _without_ explicitly listing all combinations of upper/lowercase letters (like `"a"|"A"|"á"|"Á"|"tt"|"tT"|"Tt"|...`) or saving and restoring character states (upper/lowercase) manually? There are nice examples how the string patternmatcher can be used effectively, I hope this can be solved as well. **Question** Given a possibly large list of short elementary strings like `"tt" | "t" | "a" | "á"`, how can a larger string be split into elementary substrings with keeping all uppercase letters correctly. For example:               "TtattÁatT" == > {"Tt", "a", "tt", "Á", "a", "tT"}


title: Derivative of real functions including Re and Im

text: When deriving functions using `Re`, `Im` or `Arg` (and probably some other functions as well), Mathematica gives nonsensical results, e.g.               Assuming[Element[x, Reals], D[Re[Gamma[I x]], x]]     (*     ==> I Gamma[I x] PolyGamma[0, I x] Re'[Gamma[I x]]     *)      Of course the wanted result would be `-Im[Gamma[I x] PolyGamma[0, I x]]`. Now in this case, it is easy to resolve, but often those functions are deeply inside a complicated expression. Therefore my question is: Is there any way to get reasonable derivatives for real functions of real parameters which involve `Re`, `Im` etc. of complex expressions depending on those variables?


title: Determine the Number of Lines in a Text File

text: I have looked and looked but I do not see a simple efficient way to get MMA to return the number of lines in a text file? I thought about reading the file until it returned the EOF marker, but that could take a long time when working with very large files. Any suggestions are appreciated!


title: Difficulty catching thrown errors in asynchronous tasks

text: In this Question, Leonid explained that module variables can get garbage collected from a chain of asynchronous tasks unless their `Temporary` attribute is cleared either by calling `ClearAll` on them or by Holding them. This works for preserving a variable that refers to the function that creates asynchronous task. The next step is to create a variable that Catches a value Thrown inside an asynchronous task, but the same technique does not seem to work, as I illustrate below. First, a synchronous version that works as I need. This has an internal synchronous task wrapped in a `Catch.` By default, the `Catch` returns a symbolic value that is `Unique`; that is the default, "OK" case. Internally to the `Catch`, the task bumps a state variable, checks that the state value is ok, prints it if so, throws it if not, and schedules the next iteration of the task up to a maximum state value. "Ok" in this contrived example means that state's value is less than 2; in a real application, it would be based on some unpredictable outcome, hence the whole reason for `Catch`. The following code implements the scheme above and works fine, printing `1` and then `ERROR`:               Module[{       state = 0,       runNextTask,       catchResult,       defaultCatchResult = Unique[]},      runNextTask = Function[        catchResult = Catch[          If[state < 4,            state = state + 1;            If[state < 2, Print[state], Throw[state]];            runNextTask[],           {0.10}];          defaultCatchResult];        If[catchResult =!= defaultCatchResult, Print["ERROR"]]];      runNextTask[]]      Now, I want to do the same asynchronously, attempting the following code, wherein the only differences to the synchronous versions are marked with comments:               Module[{       state = 0,       runNextTask,       catchResult,       defaultCatchResult = Unique[]},      (* the following device removes the "Temporary"       attributes from "runNextTask" and "catchResult." *)      ClearAll[runNextTask, catchResult];      runNextTask = Function[        catchResult = Catch[          If[state < 4,           (* the following invocation techniques make the           body here asynchronous. *)           StartScheduledTask@            CreateScheduledTask[              state = state + 1;              If[state < 2, Print[state], Throw[state]];              runNextTask[],             (* This is the amount of time with which to             separate asynchronous invocations. *)             {0.10}]];          defaultCatchResult];        If[catchResult =!= defaultCatchResult, Print["ERROR"]]];      runNextTask[]]      The problem, now, is that the Thrown value is not caught, as revealed in the message box:               1     Throw::nocatch: Uncaught Throw[2] returned to top level.      This isn't the end of the world, since at least the repeating chain of asynchronous tasks is interrupted and I can wrap the entire thing in another catch and make it behave well inside other code. But it's another case where I am uncomfortable proceeding when I don't understand what's going on. I expected one result and got another! I will be grateful for advice, suggestions, solutions! I'll be grateful for any advice, clues, solutions.