title: Solving partial differential equation with DSolve does not give a result

text: I am trying to solve the equation: $-(d^2/dx^2+d^2/dy^2)\psi+(x^2+y^2-2)\psi=0$ Here, is my code:               Eq = -(D[ψ[x, y], {x,2}] + D[ψ[x, y], {y,2}]) + (x^2 + y^2 - 2) ψ[x, y] == 0;          DSolve[Eq, ψ, {x, y}]      The output returns an unevaluated expression. Why do I receive such a thing? The solution to the PDE is: $\psi=\exp(-1/2(x^2+y^2))$


title: Which ColorFunction should I use to get such a gradient of blue-cyan-green-yellow-orange-red?

text: ![enter image description here](http://i.stack.imgur.com/fe3Fd.jpg) ## I want to get the effect in the above Figure. Here is my code:               Plot3D[Log[        4*((1 + x)^2)*(0.0065^2)*Log[y]/(3*((1 - 2 x))^2*(0.0267^2)) + 1]/       Log[y], {x, 0.315, 0.45}, {y, 0, 1}, Mesh -> 50, ImageSize -> 600,       AspectRatio -> 0.8, PlotRange -> {0, 20},       PerformanceGoal -> "Quality",       LabelStyle -> Directive[Bold, FontFamily -> "Times New Roman", 24],       AxesStyle -> {Thick, Thick, Thick}, AxesOrigin -> {0.315, 0, 0},       AxesLabel -> {\[Nu], n, l}, MaxRecursion -> 6, ClippingStyle -> None,       ColorFunction -> "Rainbow",       PlotLegends -> BarLegend[Automatic, LegendMarkerSize -> {20, 300}]]


title: Plotting a contour on a torus

text: There are two ways to consider a two-dimensional torus. One way is to take a parallelogram (let's say the square $[0, 1]^2$) and topologically glue the opposite edges. Another way is to look at the surface of a doughnut with one hole. I would like to draw the zero set of a doubly-periodic function as a contour on a torus. Here is how I do it when viewing the torus as a square: ![Contour on torus](http://i.stack.imgur.com/NDBZZ.png) However, I'd really like to see a contour on the surface of a doughnut. How can this be done? (Generally, I'd like to transplant the square $[0, 1]^2$ of any graphic onto the surface of a doughnut.)


title: new kernel for notebook

text: I know I can create a new kernel for my notebook from the evaluation menu but is there a command for this? I'd really like some of my notebooks to startup their own kernel as the first line of code.


title: Distance between two functions satisfying a constraint

text: My problem is that I have two functions that are described as follows:               x1 =        x[t] /. DSolve[{55 x''[t] + 100*n x'[t] + (5/22)*n x[t] == 5, x'[0] == 1/8, x[0] == 0},          x[t], t][[1]]     x2 =        x[t] /. DSolve[{x''[t] + 1 == 0, x'[0] == 1/8, x[0] == 0}, x[t], t][[1]]      Variable `n` in function `x1` ranges from 1 to 8. I want to find which `n` enables `x1` to come as close to `x2` as possible without falling below `x2`. Or stated otherwise, what is the highest `n` that ensures `x1 > x2` at all times. A plot of the functions reveals that most of the action takes place between `t = 0` and `t = 0.15`. However, the curves are too close to each other to read the right `n` from my screen. I have been trying ways to calculate the difference with integration, solving and all types of manners for hours now, but I'm certain there must be an easier way to achieve this within _Mathematica_.


title: Line Breaks in AxesLabel or PlotLabel?

text: Searching got me peripherally related threads, but not exactly what I was looking for. I'm making some graphs which I want to use on exams. Sometimes, labels (specifically in AxesLabel and PlotLabel) that are longish can be a hassle. Is there a way to introduce a line break in these labels to make them fit better in the space that I have? Thanks in advance.


title: Resizing palettes

text: My eyes are weary and my sight grows dim, so I used the zoom control bottom- right in the palette. Unfortunately, having zoomed in the palette window cannot be resized - so I can't see the rhs - _and_ there is no horizontal scrollbar. I'm also bemused by the fact that I can expand and collapse sections within palettes, but the overall palette size still doesn't change. What's the point of a "palette" in which everything you choose to be visible isn't? (screen limitations aside? Is there a way to resize palettes? (Mma 9 BTW) **Update & followup question to my own answer** Palettes can be made to respond as desired, but the Options dialog settings don't persist. How might I ensure that the options are reset each time I start Mma? **Update 2** I intended place copies of the relevant palette files in $USerBaseDirectory\SystemFiles\FrontEnd\Palettes and edit them in the hope that they would override the installed palettes. To check that the override works, I restarted without any mnodifications and found that lo-and-behold the zoom control works as it should do - and no editing seems to be required. The failure of the zoom control previously therefore _seems_ linked to the palette files' location. Hmmmmmm. **Eh?** And then it _doesn't_ work as I just described and I've edited all the relevant palette notebooks in $UserBaseDirector to make them editable, saveable, etc. Clearly I am missing something or this is very strange... probably the former, but palettes now come back where I left them (Screen 2) with the previous zoom (mostly, apart form Special Characters (?)


title: Drag & drop path info into front end?

text: On OSX at least, it's possible to quickly retrieve a folder/file path by dragging & dropping the folder/file into the terminal, eg: ![enter image description here](http://i.stack.imgur.com/1txfU.jpg) Is it possible to program _Mathematica_ 's front end enable similar drag & drop operation? I'm primarily interested in passing path info to `Import` and `Export`.


title: Text formatting with different wrappers

text: Formatting text in _Mathematica_ should be a punishment for serious crimes. I've face another frustrating feature, and I don't know how to get rid of it.               tekst = StringJoin @@ Array["tekst " &, 15];           Composition[        Grid[{{#, Graphics[Inset@#]}}, Frame -> All] &,          Panel[#, ImageSize -> {150, 100}] &,        Style[#, LineIndent -> 0] &                ][tekst]      ![enter image description here](http://i.stack.imgur.com/4BVds.png) Those texts should look the same imo. The only difference is that the one in `Graphics` is not formatted as it should be. * * * `Boxes` look well and I don't know what causes that:               ...     PanelBox[      StyleBox["\<\"tekst tekst ... tekst \"\>", StripOnInput->False, LineIndent->0],       ImageSize->{150, 100}],      GraphicsBox[InsetBox[     PanelBox[       StyleBox["\<\"tekst ... tekst \"\>", StripOnInput->False, LineIndent->0],     ...      I was trying to set `FormatType` for `Inset`or `BaseStyle` for `Graphics` or `ParagraphIndent -> 0`. But with no avail :/. Help me please :P


title: Mathlink works strangely

text: I have problem when using mathlink, the source code is quite simple:               void MAXF(char* ex1, char* ex2, char** result){        MLINK lp;        int pkt;        MLEnvironment env;        env = MLInitialize(NULL);        if (env == NULL) return;        int argcs = 4;        char *argvs[5] = {"-linkmode", "launch", "-linkname", "math -mathlink", NULL};        lp = MLOpen(argcs, argvs);        if (lp == NULL) return;             *result = malloc(100);        sprintf(*result, "0");             MLPutFunction(lp, "Exit", 0L);        MLClose(lp);        MLDeinitialize(env);     }      and in main, i call it by:               char* test;     MAXF("0", "0", &test);      However, after running, the terminal always shows this line:               In[2]:=       I believe that there is a problem, but I can't figure it out. Please help.


title: The third argument of the Root function

text: Consider the roots of an arbitrary indecomposable polynomial:               sol = Solve[x^5 + 2 x + 1 == 0, x]      The returned expression is               {{x -> Root[1 + 2 #1 + #1^5 &, 1]},      {x -> Root[1 + 2 #1 + #1^5 &, 2]},      {x -> Root[1 + 2 #1 + #1^5 &, 3]},      {x -> Root[1 + 2 #1 + #1^5 &, 4]},      {x -> Root[1 + 2 #1 + #1^5 &, 5]}}      Everything seems OK. But now let us evaluate the expression               InputForm[sol]      Now the returned expression is               {{x -> Root[1 + 2*#1 + #1^5 & , 1, 0]},      {x -> Root[1 + 2*#1 + #1^5 & , 2, 0]},       {x -> Root[1 + 2*#1 + #1^5 & , 3, 0]},      {x -> Root[1 + 2*#1 + #1^5 & , 4, 0]},       {x -> Root[1 + 2*#1 + #1^5 & , 5, 0]}}      Why has the extra argument `0` appeared ?   Is it a bug, mystery or some extremely smart property ? I use _Mathematica 9.0.1.0_ ( _64-bit Windows 7_ ).


title: Why does Manipulate execute the expression twice?

text: When I execute `Foobar[]` in the code below and move a slider, the variable `grad` is printed twice. Why is this? How can I make the `Manipulate` body only execute once on each update?               Foobar[] := Module[{f, vars, grad},        f = a x^3 - b x^2 + c y^2;        vars = {a, b, c};        With[{fman = f, controls = Apply[Sequence, {{#, 0}, -5, 5} & /@ vars]},         Manipulate[          g = fman/(x^2 + y^2 + 1);          grad = D[g, {{x, y}}];          Print[grad];          , controls]         ]        ];      **Edit:** As noticed below, this function is creating a `Manipulate`. My concern is why the `Manipulate` appears to be executing twice for every one update. This is a minimal working example and hence there is significant amount of code (that takes a while to run) excluded from inside the `Manipulate` body. I included `Print` to emphasize that the code appears to be executing twice.


title: Find parameters of ODEs to fit solution data

text: # Problem How to find the initial conditions `x[0]`,`y[0]` and the optimal value of parameters `a`,`b`,`c`,`d` to fit the following system of ODEs?                x'[t] ==  a*x[t] - b*x[t]*y[t]      y'[t] == -c*y[t] + d*x[t] y[t]      Solution data is:                   (* The first column is time 't', the second column is coordinate 'x', and the last         column is coordinate 'y'. *)     data = {{11, 45.79, 41.4},    {12, 53.03, 38.9},    {13, 64.05, 36.78},              {14, 75.4, 36.04},    {15, 90.36, 33.78},   {16, 107.14, 35.4},             {17, 127.79, 34.68},  {18, 150.77, 36.61},  {19, 179.65, 37.71},             {20, 211.82, 41.98},  {21, 249.91, 45.72},  {22, 291.31, 53.1},             {23, 334.95, 65.44},  {24, 380.67, 83.},    {25, 420.28, 108.74},             {26, 445.56, 150.01}, {27, 447.63, 205.61}, {28, 414.04, 281.6},             {29, 347.04, 364.56}, {30, 265.33, 440.3},  {31, 187.57, 489.68},             {32, 128., 512.95},   {33, 85.25, 510.01},  {34, 57.17, 491.06},             {35, 39.96, 462.22},  {36, 29.22, 430.15},  {37, 22.3, 396.95},             {38, 16.52, 364.87},  {39, 14.41, 333.16},  {40, 11.58, 304.97},             {41, 10.41, 277.73},  {42, 10.17, 253.16},  {43, 7.86, 229.66},             {44, 9.23, 209.53},   {45, 8.22, 190.07},   {46, 8.76, 173.58},             {47, 7.9, 156.4},     {48, 8.38, 143.05},   {49, 9.53, 130.75},             {50, 9.33, 117.49},   {51, 9.72, 108.16},   {52, 10.55, 98.08},             {53, 13.05, 88.91},   {54, 13.58, 82.28},   {55, 16.31, 75.42},             {56, 17.75, 69.58},   {57, 20.11, 62.58},   {58, 23.98, 59.22},             {59, 28.51, 54.91},   {60, 31.61, 49.79},   {61, 37.13, 45.94},             {62, 45.06, 43.41},   {63, 53.4, 41.3},     {64, 62.39, 40.28},             {65, 72.89, 37.71},   {66, 86.92, 36.58},   {67, 103.32, 36.98},             {68, 121.7, 36.65},   {69, 144.86, 37.87},  {70, 171.92, 39.63},             {71, 202.51, 42.97},  {72, 237.69, 46.95},  {73, 276.77, 54.93},             {74, 319.76, 64.61},  {75, 362.05, 81.28},  {76, 400.11, 105.5},             {77, 427.79, 143.03}, {78, 434.56, 192.45}, {79, 410.31, 260.84},             {80, 354.18, 339.39}, {81, 278.49, 413.79}, {82, 203.72, 466.94},             {83, 141.06, 494.72}, {84, 95.08, 499.37},  {85, 66.76, 484.58},             {86, 45.41, 460.63},  {87, 33.13, 429.79},  {88, 25.89, 398.77},             {89, 20.51, 366.49},  {90, 17.11, 336.56},  {91, 12.69, 306.39},             {92, 11.76, 279.53},  {93, 11.22, 254.95},  {94, 10.29, 233.5},             {95, 8.82, 212.74},   {96, 9.51, 193.61},   {97, 8.69, 175.01},             {98, 9.53, 160.59},   {99, 8.68, 146.12},   {100, 10.82, 131.85}};      I have tried `ParametricNDSolveValue` but get a lot error message. Can you help me? ## Solution(up to now) We now have a **direct method** to solve this problem. The main idea is interpolating many points from `t=11` to `t=100`, then get the value of `dx/dt` and `dy/dt` by Finite Difference method(with minor time step, this can decrease the loss of accuracy). Finally, just use `FindFit` twice to get parameters `a`, `b` and `c`, `d`. So that system of ODEs can be determined, but how can we find `x[0]` and `y[0]`? Just solve the system backward using `NDSolve` or `NDSolveValue`.               {t, x, y} = Transpose[data]; (* extract data *)     {xdata, ydata} = (Transpose[{t, #}]) & /@ {x, y}; (* get {t,x} and {t,y} pairs *)     fx = Interpolation[xdata, Method -> "Spline"];  (* spline interpolation *)     fy = Interpolation[ydata, Method -> "Spline"];     dx=fx'[t];     dy=fy'[t];     ab=FindFit[Transpose[{fx[t], fy[t], dx}], a*X - b*X Y, {a, b}, {X, Y}]     cd=FindFit[Transpose[{fx[t], fy[t], dy}], -c*Y + d*X Y, {c, d}, {X, Y}]      Here we get `{a -> 0.213493, b -> 0.00119763}` and `{c -> 0.104194, d -> 0.000950553}`. As I put above, use `NDSolve` to find `x[0]` and `y[0]`.               (* search backward *)     NDSolve[{X'[u] == a*X[u] - b*X [u] Y[u] /. ab,  Y'[u] == -c*Y[u] + d*X[u] Y[u] /. cd,                  X[11] == 45.79, Y[11] == 41.4}, {X[0], Y[0]}, {u, 0, 12}]      It returns `{{X[0] -> 10.415, Y[0] -> 102.984}}`. Let's see the plot:               (* find solution of x[t], y[t] with NDSolveValue *)     sol = NDSolveValue[{X'[u] == a*X[u] - b*X [u]Y[u] /. ab,Y'[u] == -c*Y[u] + d*X[u]Y[u] /. cd,     X[11] == 45.79, Y[11] == 41.4}, {{u, X[u]}, {u, Y[u]}}, {u, 11, 100}]     (* plot the results *)     Show[{ListPlot[{xdata, ydata}, AxesLabel -> {"time", "value"},           PlotLegends -> {"xdata", "ydata"}, PlotStyle -> {Red, Green}],     ListLinePlot[{Table[sol[[1]], {u, 11, 100, 0.01}], Table[sol[[2]], {u, 11, 100, 0.01}]},           PlotStyle -> {Orange, Blue}, PlotLegends -> {"solution.x", "solution.y"}]}]      ![see the results](http://i.stack.imgur.com/WGMq9.png) It is obvious that scaters at the peaks and valleys are off the curves a little. This implies us that the result is not good enough and there exists improved space of the _direct method_. Can you image how difficult it would be using FDM when the system of ODEs is of much higher order? We must find out an universal way to solve this kind of problem. * * * Here we show another way:               {tval, xval, yval} = Transpose[data]; (*extract data*)     {xdata, ydata} = (Transpose[{t, #}]) & /@ {xval, yval }; (*get {t,x} and {t,y} pairs*)     (* define the embeded function with arguments a,b,c,d *)     px[a_?NumberQ, b_?NumberQ, c_?NumberQ, d_?NumberQ] := (modle[a, b, c, d] =          First[x /. NDSolve[{x'[t] == a x[t] - b x[t] y[t], y'[t] == -c y[t] + d x [t] y[t],                     x[11] == 45.79, y[11] == 41.70}, x, {t, 10, 100}]]);     FindFit[xdata, px[a, b, c, d][t], {{a, .1}, {b, .1}, {c, .1}, {d, .1}}, t]     py[a_?NumberQ, b_?NumberQ, c_?NumberQ, d_?NumberQ] := (model[a, b, c, d] =          First[x /. NDSolve[{x'[t] == a x[t] - b x[t] y[t], y'[t] == -c y[t] + d x [t] y[t],                     x[11] == 45.79, y[11] == 41.70}, y, {t, 10, 100}]]);     FindFit[ydata, py[a, b, c, d][t], {{a, .1}, {b, .1}, {c, .1}, {d, .1}}, t]      Unfortulately, it doesn't work. We need a _good initial value_ for `a`, `b`, `c`, `d`, or will fail to do the fitting work. Maybe we could take a chance to get _good value_ with the help of `NSolve` or `FindInstance`.


title: Plotting values above a threshold in ListPlot3D

text: I'm able to plot a 3D plot of a grayscale image using `ListPlot3D`, where it plots a 3D surface of the image pixel intensity. But I would like not to plot the pixel value below a certain value. In the specific case I'm working on, I want to remove all the pixels with value zero but still plot the pixels that are above zero at there original position. Does anyone knows of how to do this?


title: How to rotate TickMarks in DateListPlot?

text: Is there a way to rotate TickMarks in DateListPlot to avoid overlap, eg: ![enter image description here](http://i.stack.imgur.com/hnblp.jpg) Part of the code used to generate this is:               TimelineGr[file_] :=       DateListPlot[{{First[#], 1}, {Last[#], Length@#}} &@        Sort@Flatten[ Last /@ I2B2[file, dateIntervals], 1],        Epilog -> ({Text[First@#, {First@Last@#, First@#2}, {1, 0}], Blue,             Rectangle[{First@Last@#, First@#2}, {Last@Last@#,               First@#2 + 0.1}]} &~MapIndexed ~ I2B2[file, dateIntervals]),       PlotRange -> All, AspectRatio -> 1/4, ImageSize -> 800,        DateTicksFormat -> {"Year", "/", "Month", "/", "Day"},        FrameTicks -> {{Automatic, Automatic}, {           First[Last[#]] & /@ I2B2[file, dateIntervals], Automatic}},        PlotLabel -> file <> ".xml"       ]      (Note, this includes custom functions) If not, this is just another example of why it's almost always better to write visualization from the bottom-up


title: Export to CDF fails

text: The code below generates the error when I attempt to export to CDF Preview: > Coordinate {xde[4.69588928222656], yde[4.69588928222656]} should be a pair > of numbers, or a Scaled or Offset form. Here is my code:               system = {x'[t] == 2 x[t] - 0.08 x[t] y[t], x[0] == 400,        y'[t] == -y[t] + 0.01 x[t] y[t], y[0] == 25};          sol = NDSolve[system, {x[t], y[t]}, {t, 6}];          {xde[t_], yde[t_]} = {x[t], y[t]} /. Flatten[sol];          Animate[Show[       ParametricPlot[{xde[t], yde[t]}, {t, 0, 5.4},         AxesLabel -> {"Prey", "Predator"}, AspectRatio -> 1,         PlotRange -> {{0, 400}, {0, 80}}],        Graphics[{Red, PointSize[Large], Point[{xde[t], yde[t]}]}]], {t, 0,        5.4, AppearanceElements -> "PlayPauseButton"}, AnimationRate -> 0.5]      How can this be fixed? Thx.


title: Are there ways to create local variables analogous to a local variable in C++ and other languages?

text: There has been a great deal of discussion on local variables in Modules and Manipulate. If I am reading this correctly, local variables in a language such as C++ or C# are not exactly analogous to local variables in a Mathematica Module or Manipulate. Developers such as myself who come from a C++, C# background find the ability to restrict the scope of variables to a function very useful. These are often used because they minimize the risk of unintended changes to variable values. This is especially true if writing Modules or Custom Controls that other Mathematica developers may use. I don't want to run the risk of stepping on someone else's variable when they use my code. Is there a way to implement local variables in Modules or DynamicModules so they are not accessible and visible to the notebooks or code calling the Mathematica code? I have noticed that if I use the option LocalizeVariables->True in a Manipulate, the variables used by Manipulate as parameters that set the range and step value of the variable that as soon as the Needs[] is executed on the .m file containing my Module that all variables are visible and settable. I don't have to call the Module[] - just execute the Needs[] for the package or nb that contains the Module. This is a popular topic and with good reason. Below is an example:               BeginPackage["MyPackage`"]            LocalTestModule[]=Module[{localX, localY},                 localX=1; localY=2;]          EndPackage[]      I open a Mathematica notebook and issue the following command:               Needs["MyPackage`"]      My expectation is that I should not be able to set the value of the `localX` variable from the notebook because it is local to `LocalTestModule`. If it is truly local to LocalTestModule[], it should not be visible outside of `LocalTestModule[]`. However:               Information[localX]      returns `MyPackage`localX` And:               MyPackage`localX = 10      returns `10` In C or C++, a calling function would not have access to localX.


title: Does the VerticalCallout algorithm in PieChart work correctly?

text: This manufactured example is typical of many real world cases where we have thin slices of the pie:               Clear[labeler];     labeler[datax_][v_, {1, c_}, ___] := Placed[Column[{datax[[c]], v}, Alignment -> Center,      BaseStyle -> Directive[FontFamily -> "Arial", 11]],"VerticalCallout"];     data = Transpose[{"This is label " <> ToString[#] & /@ Range[14],Range[14]}];          PieChart[data[[All, 2]],      ChartStyle -> 54,      ImageSize -> {All, 300},      ImagePadding -> Automatic,      LabelingFunction -> labeler[data[[All, 1]]],      PerformanceGoal -> "Performance",      PlotRange -> All,      SectorOrigin -> {Automatic, 0},      SectorSpacing -> 0.15]      ![enter image description here](http://i.stack.imgur.com/vLO4h.png) It seems inevitable that when thin pie slices are adjacent you will have overlap problems with `RadialCallout` labels but it seems to me that `VerticalCallout` should have labels evenly spaced on the left and right side of the pie chart. Is the (non evenly spaced) distribution of labels as per the image a bug or intended? Does anyone know how to create evenly spaced vertical labels with built in options? (I can probably do this with my own code given enough time and patience but am looking for built in solutions)


title: How to generate a random matrix with specific parameters?

text: I want to use Mathematica to generate a random matrix with given dimensions, entries coming from a finite set, and with a determinant also coming from a finite set. (It's very important that the generation of this matrix is random. Ideally this process would give the same results as making a list of all matrices of the given size and possible entries with one of the acceptable determinants, and picking one at random.) Some implementations of this are easy. To solve the 2x2 case with determinant == 1, and integral entries from -10 to 10, I can enter               Solve[{a d - b c == 1, -10 <= a <= 10, -10 <= b <= 10, -10 <= c <= 10, -10 <= d <= 10}, {a, b, c, d}, Integers]      But this doesn't easily extend to the problem of having broader sets of possible entries, e.g. a, b, c, and d being from -20 to 15, and being fractions with denominator between 1 and 10. That isn't essential, but the following condition is: I only need one random matrix, and I need it quickly -- but Mathematica takes forever via the above trick to generate all possible 3x3s. I thought of trying to use FindRoot together with seeding the process with random values, but I couldn't find control over If there isn't a single function that will do the trick, I don't mind writing a function in Mathematica to do what I'm looking for -- but I'm very much a newbie to MM, so as much advice as you can give me would be greatly appreciated! EDIT: As per gpap's excellent answer, here's the code that I've ended up with, modified from his answer to work with fractions.               det = Module[{i}, Sequence @@ (i /. Solve[Det[{{#1, #2, #3}, {#4, #5, #6}, {#7, #8, i}}] == 1, i]) &];          candidates = Apply[{##, det@##} &, RandomChoice[{0, 1/2, 1, 3/2, 2}, {10000, 8}], 2] // Quiet;          RandomChoice[Select[candidates, MemberQ[{0, 1/2, 1, 3/2, 2}, Last@# ] &]];


title: A bug in Commonest in version 10

text: **Bug introduced in 10.0.0** * * * m_goldberg demonstrated that in _Mathematica_ 10 `Commonest` does not behave as the documentation indicates that it will. Concisely: ![enter image description here](http://i.stack.imgur.com/YdXqX.png)               Commonest[{1, 2, 3, 1, 2, 3}, 1]  (* should return {1} *)      > >     {3} >   The function did behave as it was supposed to in earlier versions.


title: Locate Blow-up in NDSolve with Whenevent

text: At some point I get this error:               Warning: scaled local spatial error estimate of 32773.0090044258` at      t = 987.7919550194803` in the direction of independent variable x is much greater than the          prescribed error tolerance. Grid spacing with 1001 points may be too large to achieve the       desired accuracy or precision.         (etc.) How do I track this time with `WhenEvent`? How is this _scaled local spatial error_ kept in NDSolve?


title: Export date with specified format

text: My problem is that I want use _PGFplot_ in $\LaTeX$ to draw my graphs, which x axis is a date. Therefore the output file has to have one column _"UTC time" (YYYY-MM-DD hh:mm:ss)_ and the second one is the corresponding data list. Would it be possible to specify the date format of `Export[]` ?


title: Problem with integral equations

text: I have solved an integral equation with the following methods:               Options[FredholmKind2]={Method->Automatic};     FredholmKind2[{a_,b_,lambda_,k_,g_},n_?IntegerQ,OptionsPattern[]]:=          Block[{step,SI,GI,KMatrix,W,DMatrix,f,deltaX,delta},step=(b-a)/n;       SI=Range[a,b,step];       GI=g/@SI;       KMatrix=Outer[k,SI,SI];       W={step/2}~Join~ConstantArray[step,n-1]~Join~{step/2};       DMatrix=DiagonalMatrix[W];       f=If[OptionValue[Method]===NIntegrate,deltaX[x_?NumericQ]:=          W.(k[x,#]&/@SI)-NIntegrate[k[x,y],{y,a,b}];       (*If the integral is expensive ParallelMap is an option here*)delta=deltaX/@SI;          Interpolation[            Transpose@{SI,LinearSolve[IdentityMatrix[n+1]+                  lambda*(DiagonalMatrix[delta]-KMatrix.DMatrix),GI]}],         Interpolation[           Transpose@{SI,LinearSolve[IdentityMatrix[n+1]-                  lambda*(KMatrix.DMatrix),GI]}]];     f]          n=50;(*number of discretization*)a=0.;     b=1.;     lambda=-1.;     Kpart[x_,y_]:=With[{A=2},(A/2)*         (BesselJ[1,A*(x+y)]-BesselJ[1,A*Abs[x-y]]-I*StruveH[1,A*(x+y)]+I*StruveH[1,A*Abs[x-y]])]     Gpart[x_]:=x;     f1=FredholmKind2[{a,b,lambda,Kpart,Gpart},n,Method->Automatic];     f2=FredholmKind2[{a,b,lambda,Kpart,Gpart},n,Method->NIntegrate];     (Plot[Evaluate@(#/@{f1[x],f2[x]}),{x,a,b},Frame->True,Axes->False,         PlotStyle->{{Thick,Opacity@.45},{Dashed,Red}},         PlotLegends->{"Automatic","NIntegrate"},ImageSize->400]&/@{Re,Im})      I now want to evaluate and then plot Ktt(A):               Ktt[A]=A^3*NIntegrate[x f2[x],{x,0,1}]      for A ranging from 0 to 10 with 0.01 step. This means that for all these values of A I must find the corresponding f2(x) and then the corresponding Ktt(A) and then put all the Ktt points into a plot. Is there a way to do this with matrices or maybe with a loop?


title: Social Network Analysis - Get the End Points of an Edge

text: I want to get the end points of an Edge of a Graph. For example see the following source,               In[1]:=gFriendShip = ExampleData[{"NetworkGraph", "Friendship"}];     In[2]:= EdgeList[gFriendShip, "Rose" \[UndirectedEdge] _]     Out[2]:={"Anna" \[UndirectedEdge] "Rose", "Ben" \[UndirectedEdge] "Rose",       "Rose" \[UndirectedEdge] "Nora"}      Now I want to write something like `EndPoints["Rose" \\[UndirectedEdge] "Nora"]` (actually, `EndPoints[%2]` in the above example) and want to get `{"Rose", "Nora"}` as output. It might be a basic thing, but I am new to _Mathematica_. I am using _Mathematica 9.0_.


title: Find points on the surface of a Graphics3D object

text: If I have a Graphics3D object that was generated from manipulations to PolyhedronData rather than via an explicit equation, for example the Spikey ![Spikey 6!](http://i.stack.imgur.com/N2Kqn.png) (for which the entire code can be found here _The Cover Image: Making the Mathematica 6 Surface-Textured Hyperbolic Dodecahedron_, but which culminates with the following command,               Graphics3D[{EdgeForm[],        addHatToL /@ Take[Flatten[Take[LsOnDodecahedron, All]], All]},       PlotRange -> All, Boxed -> False, ImageSize -> Full,       Lighting -> {{"Ambient", RGBColor[0.2, 0, 0]}, {"Point",          RGBColor[0.4, 0.4, 0.4], {2, 0, 2}}, {"Point",          RGBColor[0.4, 0.4, 0.4], {2, 2, 2}}, {"Point",          RGBColor[0.4, 0.4, 0.4], {0, 2, 2}}, {"Point",          RGBColor[0.2, 0, 0], {-2, -2, -2}}}]      Is there a way for me to extract/generate a table of 3D points along the surface of (or within, I don't actually care) the object? I saw _Efficiently determining if 3D points are within a surface composed of polygons_, which went a bit over my head, but many of the answers given seemed to either require a 'nice' shape (i.e., no concave surfaces, no cusps, no self-intersections, etc.) or be based on the fact that he had generated the object with generated data sent to ListContourPlot3D, which is not the case here.


title: Finding the common areas of two contourplots

text: I used ListContourPlot to specify an area for which the function value is less than a number. For example consider the following areas:                plot1 = ListContourPlot[       Table[Sin[i + j^2], {i, 0, 3, 0.1}, {j, 0, 3, 0.1}],        RegionFunction -> Function[{x, y, z}, z < 1], PlotRange -> {0, 1},        DataRange -> {{0, 3}, {0, 3}}]          plot2 = ListContourPlot[       Table[Cos[i + j^2], {i, 0, 3, 0.1}, {j, 0, 3, 0.1}],        RegionFunction -> Function[{x, y, z}, z < 0.7]       , PlotRange -> {0, .7}, DataRange -> {{0, 3}, {0, 3}},        ColorFunction -> ColorData["BlackBodySpectrum"]]      ![enter image description here](http://i.stack.imgur.com/sKiVP.jpg) ![enter image description here](http://i.stack.imgur.com/6Kxyx.jpg) How can I specify the common areas of these two parameter spaces in a plot? RegionPlot doesn't give the common area:               RegionPlot[      Sin[i + j^2] < 1 && Cos[i + j^2] < 0.7, {i, 0, 3}, {j, 0, 3},       PlotPoints -> 80, Mesh -> 2,       ColorFunction ->        Function[{x, y}, ColorData["SolarColors"][Sin[x^2 + y]]],       PlotRange -> {0, 2},       MeshFunctions -> {Sin[#1^2 + #2] &, Abs@Cos[#1^2 + #2] &}]      ![enter image description here](http://i.stack.imgur.com/435jW.jpg) Because RegionPlot uses i and j which change continuously but ListContourPlot uses only certain number of data:               {i, 0, 3, 0.1}, {j, 0, 3, 0.1}


title: How can I access Mathematica kernel for WebMathematica in Linux(Ubuntu 12.04)

text: I have been working in `webMathematica` with Application server(Geronimo 3.0.1) in windows, It was working fine. Recently I have changed to Linux(ubuntu 12.04). I have installed mathematica in Linux and made it work then I have installed Application server(Geronimo 3.0.1) and it is working with with sample JSP applicaiton and try to deploy webMathematica 3.2.0 in Application server. I need to change MSPConiguration file to access `mathekernel` like               <KernelExecutable>/home/niren/Wolfram/Mathematica/9.0/Executabales/MathKernel.sh</KernelExecutable>      But it is not working. For windows I used like               <KernelExecutable>C:\Program Files\Wolfram Research\Mathematica\9.0\MathKernel.exe</KernelExecutable>      It was working for windows. Suggest me how should I refer `MathKernel` in `MSPConfiguration` file of `webMathematica` in Linux. Note: I can deploy sample `jsp` application in application server and made it work. But can't make `webMathematica` work.


title: integrating a Green's function for a damped harmonic oscillator

text: I have the following integrand:               int = Sin[Sqrt[-g^2 + omega^2]*(t - tp)]*Exp[-g*(t - tp)]*A*Exp[-(tp - t0)^2/sigma^2]*Cos[Omega*tp]/Sqrt[-g^2 + omega^2]      and am trying to integrate it with:               Integrate[int, {tp, 0, t}, Assumptions -> {g > 0, omega > 0, Omega > 0, A > 0, sigma > 0, t > 0, t0>0}]      but _Mathematica_ is not able to do it (I have tried to do this with no assumptions as well). Maple does the integration in under a second and returns a solution (which can be expressed in terms of the Erf functions). Is there a way to help _Mathematica_ calculate this integral? ... and just to note, the result of the integration is a solution of damped harmonic oscillator, driven by a force:               A*Exp[-(t - t0)^2/sigma^2]*Cos[Omega*t]


title: Speed up Eliminate

text: I have a set of trig equations, c1,c2,c3 are constants, I excepted the result is `c1 c2 c3 r^2 + (c1^2 + c2^2 + c3^2 - 1) r + c1 c2 c3 == 0` but following code worked so slow, is there a faster method do this?               Eliminate[{       c1 == Cos[a] Sin[b],       c2 == Cos[b] Sin[c],       c3 == Cos[c] Sin[a],       r== Tan[a] Tan[b] Tan[c]}, {a, b, c}]


title: How to make endpoints flush with fill in ListLinePlot?

text: If one plots a filled line plot such as, for example, the one produced by               ListLinePlot[{{{0, 0.6}, {0.5, 0.6}}, {{0.5, 0.3}, {1, 0.3}}},          Filling -> Axis, PlotStyle -> AbsoluteThickness[10],         AspectRatio -> Automatic, PlotRange -> {Automatic, {0, 0.8}},         PlotRangePadding -> None]      ![](http://i.stack.imgur.com/bUxRT.png) the ends of the plot's lines have a rather noticeable "overhangs" beyond the fill regions below. How can I make this line be flush with the fill?


title: Automatically generated summation region

text: In a multiple `Sum` I need to put an automatically generated summation region. But when I generate the summation region automatically I get a list whose elements are lists. Then the summation does not work. For example:               Sum[1,{i,1,2},{j,1,2}]      works;               Sum[1,{{i,1,2},{j,1,2}}]      or               A = Table[{i[j],j+1},{j,2}];     Sum[1,A]      doesn't work.


title: Why my if statement does not work

text: Thanks for your attention. I'm new to mathematica. I have the codes as below. But the If statement does not work. Anything wrong with my code? Thanks for help! Ben               ClearAll;     (*Define of hill function*)          Hillinh[x_, nx_, x0_] = 1./(1. + (x/x0)^nx) ;     Hillexc[x_, nx_, x0_] = 1. - Hillinh[x, nx, x0];     Hillshift[x_, nx_, x0_, lamda_] = lamda + (1. - lamda)*Hillinh[x, nx, x0];     (*Parameters*)     aa =  2(*gx/(k*xT)*);     (*bb= 10 gy/(k*yT)*)     py = 4;     px = 4;     yT = 1;     xT = 1;     data = {};          For[i = 1, i <= 20, i++,           bb = i*0.5;           (*Equations for system*)      eqs1 = aa*Hillinh[y, py, yT] - x;      eqs2 = bb*Hillexc[x, px, xT] - y;      eqscomb = {eqs1, eqs2};           (*calculate the fixpoint and eigenvalues*)      r = {x, y};       fp = NSolve[Rationalize[Thread[eqscomb == 0 && x > 0 && y > 0]], r, Reals];           (*Calculate tau*)      xs = x /. fp;      ys = y /. fp;           alpha = (py/aa)*xs^2*ys^(py - 1);      beta = (px)*(ys/xs)*(1 - ys/bb);      test = alpha*beta - 1;                If[test <= 0, Continue[], Print[-2*ArcTan[Sqrt[test]]/Sqrt[test]+Pi/Sqrt[test]]];           ]


title: NDSolve PDE, not enough boundary condition?

text: The PDE that I want to solve is: $$ \frac{\partial f}{\partial t} + \frac{1}{m} \left( p_x \frac{\partial f}{\partial x} + p_y \frac{\partial f}{\partial y} + p_z \frac{\partial f}{\partial z} \right) - \frac{\partial V}{\partial x} \frac{\partial f}{\partial p_x} - \frac{\partial V}{\partial y} \frac{\partial f}{\partial p_y} - \frac{\partial V}{\partial z} \frac{\partial f}{\partial p_z} = 0 $$ where $$ V(x,y,z) = c \sqrt{\frac{x^2 + y^2}{4 a^2} + \frac{z^2}{a^2}} $$ the boundary/initial condition I have is: $$ f(x,y,z,p_x,p_y,p_z,t=0) = exp \left(- \frac{p_x^2 + p_y^2 + p_z^2}{2 m} - (x^2 + y^2 + z^2) \right) $$               potentialCartesian[x_, y_, z_, a_, c_] := c Sqrt[(x^2 + y^2)/(4 a^2) + z^2/a^2]          eqn = D[f[x, y, z, px, py, pz, t], t] + 1/m (px D[f[x, y, z, px, py, pz, t], x] + py D[f[x, y, z, px, py, pz, t], y] + pz D[f[x, y, z, px, py, pz, t], z]) - D[potentialCartesian[x, y, z, a, c], x] D[f[x, y, z, px, py, pz, t], px] -D[potentialCartesian[x, y, z, a, c], y] D[f[x, y, z, px, py, pz, t], py] - D[potentialCartesian[x, y, z, a, c], z] D[f[x, y, z, px, py, pz, t], pz] == 0;          ic = f[x, y, z, px, py, pz, 0] ==  Exp[-((px^2 + py^2 + pz^2)/(2 m)) - (x^2 + y^2 + z^2)];          sol = NDSolve[        {         eqn /. {m -> 1, a -> 1, c -> 1},         ic /. {m -> 1, a -> 1, c -> 1}        },        f,        {x, -5, 5},        {y, -5, 5},        {z, -5, 5},        {px, -5, 5},        {py, -5, 5},        {pz, -5, 5},        {t, 0, 5}     ]      When I run the NDSolve command, I get the following warnings:               NDSolve::nerres: The maximum number of spatial points (10) for independent variable x allowed by MaxPoints -> Automatic or MinStepSize -> Automatic is too few to compute a spatial error estimate. >>     NDSolve::nerres: The maximum number of spatial points (10) for independent variable y allowed by MaxPoints -> Automatic or MinStepSize -> Automatic is too few to compute a spatial error estimate. >>     NDSolve::nerres: The maximum number of spatial points (10) for independent variable z allowed by MaxPoints -> Automatic or MinStepSize -> Automatic is too few to compute a spatial error estimate. >>     General::stop: Further output of NDSolve::nerres will be suppressed during this calculation. >>     NDSolve::bcart: Warning: an insufficient number of boundary conditions have been specified for the direction of independent variable x. Artificial boundary effects may be present in the solution. >>     NDSolve::bcart: Warning: an insufficient number of boundary conditions have been specified for the direction of independent variable y. Artificial boundary effects may be present in the solution. >>     NDSolve::bcart: Warning: an insufficient number of boundary conditions have been specified for the direction of independent variable z. Artificial boundary effects may be present in the solution. >>     General::stop: Further output of NDSolve::bcart will be suppressed during this calculation.       Is this because I don't have enough boundary/initial conditions? The problem I am trying to solve only has a single initial condition, do I need to use other methods to solve it?


title: Is there a more idiomatic way to solve this implicit differentiation problem?

text: Here's an exercise from a calculus text by _Larson_ and _Edwards_ : > Find the rate of change of the distance between the origin and a moving > point on the graph of $y = x^2 + 1$ if $dx/dt = 2$ centimeters per second. Here's one way to solve it:               eq1 = d[t]^2 == x[t]^2 + y[t]^2;     eq2 = y[t] == x[t]^2 + 1;     {eq1, D[eq1, t], eq2, D[eq2, t], x'[t] == 2};     Reduce[%, {d'[t], d[t], y'[t], y[t]}]      Is there another way to solve it that might be considered more idiomatic?


title: Split list of states by run lengths and discontinuous changes in state

text: I was asked to look into writing some simulation code for a user, where the simulation output (`x`) would oscillate between three possible states:               states[x_, γ_] := Which[     x < -γ,  1 (*top*),     x < γ , -1 (*bottom*),     True  ,  0   (*middle*)]      The simulation essentially boiled down to the following, and what they were interested in is computing the lengths runs in each state - which could be easily computed with `SplitBy`:               γ = 0.9;     sampleSimulation = RandomChoice[{-1, 0, 1}, 1000000];     runLengths = Switch[Sign[#[[1]]],           1, {"top", Length[#]},         -1, {"bottom", Length[#]},           0, {"middle", Length[#]}      ] & /@ SplitBy[sampleSimulation, states[#, γ] &]      However, if the simulation output moved between the `"top"` and `"bottom"` states (in either direction) without occupying the `"middle"` state they needed this information in `runLengths` via the string `"unoccupied middle"`. The following code achieves that and is surprisingly performant and the experimenter was happy. However it feels unnecessary to `SplitBy` and then `Reap` and `Sow` with a `Do` loop to find where the simulation moves seemlessly between `"top"` and `"bottom"`. What would be a more natural, and less wasteful method to solve such a problem?               runLengthsFunc[list_, γ_] :=      Block[{splitting},       splitting =         Switch[Sign[#[[1]]],            1, {"top", Length[#]}, -1, {"bottom", Length[#]},            0, {"middle", Length[#]}] & /@          SplitBy[list, states[#, γ] &];       Append[Flatten[         Reap[Do[If[(splitting[[k, 1]] == "top" &&                 splitting[[k + 1, 1]] == "bottom") || (splitting[[k, 1]] ==                  "bottom" && splitting[[k + 1, 1]] == "top"),              Sow[{splitting[[k]], "unoccupied middle"}],             Sow[{splitting[[k]]}]],            {k, Length[splitting] - 1}            ]][[2]], 2], splitting[[-1]]]]      Timing:               In[10]:=AbsoluteTiming[runLengthsFunc[sampleSimulation, γ];]     Out[10]:={7.526282, Null}      **Solution Choosing** Thanks for the three very different solutions, as requested the focus was on different methodologies rather than sheer blistering speed. I'm going to accept Mr Wizard's answer as it provided the most different approach (and best learning experience for me) as well as exceptional speed - under a second for an initial set of 1,000,000 states. However, there was an apparently superfluous process; Unitize where a list already contained only 0,1. Kguler's method falls apart for more than ~3000 elements, but is a great example of pattern matching. And it's great to see in both this and Mr Wizard's solutions the convergent evolution of SE toward Composition. Leonid's answer introduced me to linked lists which will be a useful tool for similar problems I have. Unfortunately, I can't benchmark Leonid's as he elected to focus on methodology rather than speed so did not include an implementation of runLengths - but the linking of lists is much more performant than my `Reap[Do[Sow]` approach.


title: Finding elementary cycles of (directed) graphs

text: I need to enumerate all the simple cycles (i.e. elementary cycles where no vertex is repeated other than the starting) of a graph which has both directed and undirected edges, where we can treat the undirected edges as doubly directed. (Specifically, I am looking at the Cayley graphs of S3 and S4, which can be produced using `CayleyGraph[SymmetricGroup[3]]` and `CayleyGraph[SymmetricGroup[4]]` respectively.) I have tried two ways of doing this so far. First, I have tried using `ExtractCycles` in the _Combinatorica_ package, as detailed in this answer by TomD. For example, entering the ordered pairs for S3 (as "el"):               el = {{1, 2}, {1, 4}, {2, 3}, {2, 5}, {3, 1}, {3, 6}, {4, 1}, {4, 6}, {5, 4}, {5, 2},      {6, 5}, {6, 3}}      And then using:               Needs["Combinatorica`"]     ExtractCycles@FromOrderedPairs@el      returns:               {{5, 4, 6, 5}, {6, 3, 6}, {5, 2, 5}, {4, 1, 4}, {3, 1, 2, 3}}      However, that set is incomplete - what about e.g. `{{5, 4, 1, 2, 5}, {5, 4, 1, 2, 3, 6, 5}}`? These are simple cycles, so why are they not included in the list? The output for S4 is also much truncated (obviously we would expect a _lot_ of cycles there, but the output gives only eighteen). The second thing I tried was this answer by kguler. Taking the example of S3, using `CycleGraph[3, DirectedEdges -> True]` gave the right results, but `CycleGraph[4, DirectedEdges -> True]` did not - i.e. the cycles `{5, 4, 1, 2, 5}` etc. were not picked up again. Presumably this is something to do with the doubly directed edges? Any help with this would be much appreciated! **Edit:** As requested, the ordered pairs for the Cayley graph of S4 are:               el2 = {{1, 2}, {1, 9}, {2, 3}, {2, 17}, {3, 4}, {3, 13}, {4, 1}, {4, 5}, {5, 4}, {5, 6},     {6, 16}, {6, 7}, {7, 8}, {7, 22}, {8, 5}, {8, 10}, {9, 1}, {9, 10}, {10, 8}, {10, 11},     {11, 12}, {11, 21}, {12, 9}, {12, 18}, {13, 14}, {13, 3}, {14, 15}, {14, 20}, {15, 16},     {15, 23}, {16, 13}, {16, 6}, {17, 2}, {17, 18}, {18, 19}, {18, 12}, {19, 24}, {19, 20},     {20, 17}, {20, 14}, {21, 11}, {21, 22}, {22, 7}, {22, 23}, {23, 15}, {23, 24}, {24, 19},     {24, 21}}


title: Trying to use NDSolve to solve Blasius equation

text: s = NDSolve[{f'''[eta] + 0.5*f[eta]*f''[eta] == 0.0, f[0] == 0.0,      f'[0] == 0.0, f'[Infinity] = 1.0}, f, {eta, 0, 1}];     Plot[Evaluate[f[eta] /. s], {eta, 0, 1}, PlotRange -> All]      I don't understand why this doesn't work. I followed exactly the instructions from the site. I get the following error (among others)               NDSolve::deqn: Equation or list of equations expected instead of 1.` in the first argument


title: Scaling of ChartElements

text: In attempting to answer this question from @Cam on `BubbleCharts` with elliptical bubbles, I suggested using separate `ChartElements` which themselves could be ellipses. My idea was to define them as regular graphics objects and use them like this:               datatoplot = {{1, 2, 0.5, 0.7}, {10, 5, 10, 0.2}};     ellipse[v_] := Disk[{v[[1]], v[[2]]}, {v[[3]]/10, v[[4]]/10}];     ce = Graphics[Style[ellipse[#], Blue]] & /@ datatoplot;     Show[BubbleChart[{datatoplot[[;; , ;; 3]][[#]]},ChartElements->ce[[#]]]&/@{1,2}, PlotRange -> All]      However, while the objects I've called `ce` above are indeed ellipses, they get rescaled when they are used as ChartElements and their ellipsicity is undone (or at least altered). It seems in the help section for `ChartElements` that the format to define the width and height is to give               ChartElements->{g,{w,h}}      but this gives an error message when I try and implement it naively (with an arbitrary scaling of `{0.3,0.6}`). Trying it by hand:               Show[BubbleChart[{datatoplot[[;; , ;; 3]][[#]]},ChartElements -> {ce[[#]], {0.3, 0.6}}]&/@{1,2}, PlotRange -> All]      gives me the error shown here: ![error message](http://i.stack.imgur.com/3KZ7N.png) Does anyone know how to correctly implement the scaling for `ChartElements`? Is it that the elements should somehow be different from regular Graphics objects?


title: Histogram scale error when using DistributionChart

text: I'm a novice Mathematica user that is having some problems using the HistogramDensity function in a DistributionChart. My observations are heavily skewed to one category and the height of the other categories are larger than the number of observations should imply. Any ideas? Here's a stylized example of my problem:               data = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4}     DistributionChart[data, ChartElementFunction -> ChartElementDataFunction["HistogramDensity", "Bins" -> 4]]      ![enter image description here](http://i.stack.imgur.com/cksjk.png)


title: What are good/best practices to take the Fourier transform of an InterpolatingFunction?

text: I have a function which I have obtained from numerical integration of a differential equation, and I would like to take its Fourier transform. What are good practices for doing this? To make things more precise, suppose I have a function like the following:               solution =  u /. First@NDSolve[{              u'[t] == -E^(-(t^2/2)) t Cos[5 t] - 5 E^(-(t^2/2)) Sin[5 t] t,              u[0] == 1           }, u, {t, 0, 50}]      (Note that, while this example has an analytical solution, my full problem does not.) I am using `NDSolve` since it appears to be the best way to obtain functions $F$ of the form $F(t)=\int_{t_0}^t f(\tau) \,\text d\tau$ where $f$ is known. I am interested in the Fourier transform of this solution. I know of course that I can sample this function over a discrete set of points and then use the discrete Fourier transform `Fourier` to obtain a fair approximation:               ListPlot[      Abs[       Fourier[solution /@ Range[0, 50, 0.01]]       ]      , PlotRange -> {{0, 150}, {0, 1}}]      ![enter image description here](http://i.stack.imgur.com/6xKbc.png) However, this completely ignores the fact that the `InterpolatingFunction` itself is already a discrete representation of the desired function. As it stands, the code above includes interpolation from a discrete data set into a new discrete data set, and this can only   * lose information, in the case that the sample grid is too sparse, or alternatively   * give the impression that it contains more information than was already in the original data, if the sample grid is too closely spaced. Either way, this extra sampling step has no communication with the internals of the `InterpolatingFunction` and as such it cannot know how much information it contains or how good it is. **I am looking for a method which uses this information as optimally as possible.** The accuracy of the ODE solution, and therefore of its transform, are best controlled from the options of `NDSolve`, and the subsequent transformations of the data should take heed of this. I am aware of `NFourierTransform`, which, as I understand, uses `NIntegrate` internally; I'm also aware that `NIntegrate` natively supports `InterpolatingFunction` objects, which is presumably still the case if they are multiplied by a further factor of $e^{i\omega t}$. (On the other hand, the behaviour of this factor can rather radically change the overall behaviour of the whole integrand from 'slow' into highly oscillatory, so that some attention to `Method` would be warranted.) It could be, though, that the Fast nature of `Fourier` might be enough to outstrip such advantages, and still be faster than `NFourierTransform` even when over-blasted on the accuracy. Speed is definitely an issue, as I will be performing automated scans over many such spectra, so I want them to be accurate enough but not waste time overcalculating. So: what are good ways of performing this transform?


title: Plotting the solutions to a transcendental equation

text: I am trying, to no avail, to use _Mathematica_ to produce a plot in (x, y)-space of the solutions to the equation               Cos[Sqrt[y]] + Sin[Sqrt[y]]/Sqrt[y] == Cos[x]      Neither `NSolve` nor `InverseFunction` seem to work for inverting the equation (probably because there are multiple solutions for y for each x). Does anyone know a way to make such a plot?


title: Automatically shrink stretched images back to their original dimensions

text: We all sometimes find images on the web that are carelessly stretched to larger dimensions than original, which results in nothing but a reduction of the detail / dimensions ratio. See **Original** vs **Stretched** below: * * * Source: Kaley Cuoco (Model), Esquire (Latin America) # Original ![original](http://i.imgur.com/WsXXsnL.jpg) # Stretched ![stretched](http://i.imgur.com/RMEuvh3.jpg) * * * Questions:   1. Given only **Stretched** , is there a way to automatically find the best dimensions to shrink _Stretched_ down to which maximizes the `detail / dimensions` ratio?   2. Is there a generic way to define `detail` for all images (photos, line-art, text, etc.)?   3. Is 'stretched' the correct term or is there a more technically correct applicable?


title: Dynamic boundaries for FindRoot

text: As documented               FindRoot[f[x], {x, xs, min, max}]       searches for a solution, stopping the search if `x` ever gets outside the range `min` to `max` and returning the error `FindRoot::reged`. Now I have               FindRoot[{f[x, y], g[x, y]}, {{x, xs}, {y, ys}}]      and I want to obtain the same behavior but for the constrain `x > y`. Is this possible? In particular, I'm interested in the case in which there are many solutions that satisfy the constrain, and I want to get as many as possible of them by giving several starting points.


title: Is there a summary of answers Head[] can give?

text: Sometimes you need to check for the type of an expression. You use Head[data] to get answers. Some data:               data = {7, 1.4, Red, "hp", hps};     Head /@ data     (*{Integer, Real, RGBColor, String, Symbol}*)      Is there summary of what kind of answers `Head[]` can give?


title: Extract attribute data from an XMLElement

text: I'm trying to come to grips with parsing an XML file but I'm having difficulty working out how to extract specific attribute data from an XMLElement. Sample XML file below:               <!DOCTYPE DEXXMLDoc SYSTEM "DEXXMLDoc.DTD">     <DEXXMLDoc name="RSM-a.xml" creator="DX8" version="8.0.6">     <designInfo studyType="ResponseSurface" designType="CCD" noOfRuns="20" noOfFactors="3" noOfResponses="2">     <designNotes>This data file created by Design-Expert 6</designNotes>     </designInfo>     <blockInfo>     <block code="0" name="Block 1"/>     <block code="1" name="Block 2"/>     </blockInfo>     <factorInfo>     <factor id="A" name="time" unit="min." type="Numeric">     <numeric low="40" high="50" stdDev="0"/>     </factor>     <factor id="B" name="temperature" unit="deg C" type="Numeric">     <numeric low="80" high="90" stdDev="0"/>     </factor>     <factor id="C" name="catalyst" unit="%" type="Numeric">     <numeric low="2" high="3" stdDev="0"/>     </factor>     </factorInfo>      As you can see, this particular XML file relies on attributes to hold much of the data. I have no trouble selecting entire XMLElement(s) by name using `Cases` but I can't seem to work out how to extract specific attribute data by name. For example, I'd like to be able to extract the `studyType` attribute from the `designInfo` element. This is what the XMLElement that I'm working with looks like:                   XMLObject[       "Document"][{XMLObject["Doctype"]["DEXXMLDoc",         "System" -> "DEXXMLDoc.DTD"]},       XMLElement[       "DEXXMLDoc", {"name" -> "RSM-a.xml", "creator" -> "DX8",         "version" -> "8.0.6"}, {XMLElement[         "designInfo", {"studyType" -> "ResponseSurface",           "designType" -> "CCD", "noOfRuns" -> "20", "noOfFactors" -> "3",           "noOfResponses" -> "2"}, {XMLElement[           "designNotes", {}, {"This data file created by Design-Expert \     6"}]}], XMLElement[         "blockInfo", {}, {XMLElement[           "block", {"code" -> "0", "name" -> "Block 1"}, {}],           XMLElement["block", {"code" -> "1", "name" -> "Block 2"}, {}]}],      Does anyone have experience in extracting named attribute data from XMLElements?


title: Prevent Mathematica to automatically evaluate Manipulate at start

text: I'm using an initialization cell to import a lot of data:               data = Import[myFiles];      and then I use a custom function to display this data with Manipulate:               Manipulate[customFunction[data,variable],{variable,{0,1}}]      I have to keep these two commands in two seperate cells, because importing the data in `customFunction` each time I manipulate `variable` would take a lot of time. The problem is, when I start my notebook, `Manipulate` is evaluated automatically and sends a lot of error messages, because `data` is not defined. I know it might go against what Manipulate is made for, but is there a way to prevent Manipulate from being evaluated until I import my data for the first time?


title: 3D bubble textures in Bread (and other solids)

text: Bread has a bubbly texture that I would like to be able to recreate using Mathematica. Here are some examples of bubble textures:   * Bread ![enter image description here](http://i.stack.imgur.com/MdNcU.jpg)   * Swiss cheese ![enter image description here](http://i.stack.imgur.com/jURI2.jpg)   * Foam ![enter image description here](http://i.stack.imgur.com/wIj9K.jpg) Note that most of the bubbles are ellipsoids or more complex 3D forms (only 'isolated' bubbles in the second case are approximately spherical). Bubbles generally do not intersect but are deformable by each other (and by the original 'pre-cut' boundary of the object - e.g. in the case of bread). Closely spaced bubbles approach polyhedrons with a minimum curvature at the 'vertices' (like 3d voronoi texture). I can generate a bunch of spheres intersecting a cube easily using something like:               Graphics3D[{Cuboid[{-2, -2, -5}, {8, 10, 10}],      Sphere[RandomReal[10, {500, 3}], RandomReal[{0.1, 1}]]}]      ![enter image description here](http://i.stack.imgur.com/Y6gDb.png) But I can't see how to variably change their shape or allow them to deform without intersecting. Ultimately I'm looking to make bubbles that are deformed by each other and the 'pre-cut' boundary of the solid. I am thinking that one way to visualise this would be generate the bubbles (for example, within a 'pre-cut loaf' shape) and combing this with a surface slice using `ParamtericPlot3D` to end up with something like this: ![enter image description here](http://i.stack.imgur.com/f9kw9.png) (but with nice bubbles inside!) I realise that it may be non-trivial to work out how the bubbles deform... Also, it would be nice to be able to add colours and 2D textures to the different surfaces to, for example, brown the crust, add wholemeal flakes etc. How would one go about creating a semi-realistic bubble texture _intersecting_ a 3D surface and/or volume? (P.S - Not entirely relevant but there are some inspiring forms here and here)


title: How can I make a 2D line plot with a drop shadow under the line?

text: You often see plots styled like this (ignore the bar chart component): ![enter image description here](http://i.stack.imgur.com/Slmeh.jpg) i.e. with a small drop shadow under the line. (I'm assuming Excel is being used to produce these plots). How could you make something similar in Mathematica?


title: How to specify optional arguments that take functional values

text: I am trying to make a function with an optional argument that may change but mathematica caches the value when the function is defined. Here is an example where the optional time variable is set when the function is defined.               Remove[CurrentTime]     CurrentTime[time_: DateList[]] := {time, DateList[]};     Pause[1]     CurrentTime[]      The output is split by 1 second               {{2013, 6, 4, 13, 57, 46.149504}, {2013, 6, 4, 13, 57, 47.150726}}      Is there a way to tell it its a delayed set, or to just read the function each time?


title: How do I find the coordinates of points in this image?

text: I have never used image processing with Mathematica. I need to get the coordinates of the red points from this image I made in Illustrator. Is there a way to get Mathematica to read or detect the x-y coordinates? ![enter image description here](http://i.stack.imgur.com/R0Dqo.png)


title: How to solve this exponential inequality?

text: I want to solve the exponential inequality $$8^x +18^x -2\cdot 27^x>0.$$ I tried               Solve[8^x + 18^x - 2*27^x > 0, x]      and               Reduce[8^x + 18^x - 2*27^x > 0, x]      How do I tell _Mathematica_ to do that?


title: Is it possible to impose "Assumptions" in DSolve or equivalent? (differential equation solving)

text: When `DSolve` tries to solve differential equations, it is sometimes not smart enough to generate conditions according to different possible value of parameters. Consider the following minimal example, $x'=x^2-a$:               DSolve[x'[t] == x[t]^2 - a, x[t], t]      The result is               {{x[t] -> -Sqrt[a] Tanh[Sqrt[a] t - Sqrt[a] C[1]]}}      This would be wrong if $a \leq 0$. (When $a<0$ one may argue that the above result is correct in the sense of complex $\tanh$ function; I did not bother to think about this, but this is definitely not we normally want.) If the problem at hand is `Integrate`, we can use `Assumptions` to explicitly state the range of parameter; but `DSolve` does not provide such an option. So, is there any way to achieve a similar effect? I tried to use `Boole` etc. but failed.


title: Shooting method for solving 3rd Oder ODE with RK method

text: This is my 3rd Order IVP. `D[y[x], {x, 3}] == (m/2)*((D[y[x], x])^2 - 1) - ((m + 1)/2)* y*(D[y[x], {x, 2}])^2`. Initial conditions given are as follows `y[0] = 0; y'[0] = 0; y''[0] = 1; (* This is the First assumed value of y''[0] for initializing shooting method using RK 4rth order method *) ` For this problem y'[infinity] is equal to 1, I want to loop the shooting method using Runge Kutta 4 th order method in such a way that after calculations, it will check the y'[] value at sufficiently large value of x and from experimental results, for x ~ 7-8, f'[] is 1. To Use RK method I redefined the equation like               D[l[x], {x, 2}] ==  z; D[y[x], x] ==  l; D[z[x], x] == (m/2)*(l^2 - 1) - ((m + 1)/2)*z*y;      Now I could write one loop for RK method but this is proving out a bit tough for me because I have to generate a list for different values of f[0] { 0,1} and m is also a variable with range (0-1) step size 0.01 & then I have to deal with 3 equations simultaneously. I am solving this over C programming but its not that efficient. I dont know how to go ahead. If anyone could throw some light.....


title: plotting a trig functions along with its envelope

text: **Note** : This questions is quite different from the ones referred to in the comments. Those deal with numerical questions, while this one is algebraic. I have plots of the following type:               Plot[Cos[50 t] + Cos[51 t], {t, 0, 10}]      ![enter image description here](http://i.stack.imgur.com/LyJHJ.png) I would like to plot a envelope over this plot, i.e. another plot that joins all of maxima and minima of this plot respectively. Here is my attempt, but it's not exactly what I'd like:               Plot[{Cos[50 t] + Cos[51 t], Cos[t] + 1.5, -Cos[t] - 1.5}, {t, 0, 10}]      ![enter image description here](http://i.stack.imgur.com/XFAQj.png) How can I generate the actual envelope?


title: Minimization in single component of BSpline to extract points

text: I smoothed some data with a BSpline $B[t] = (x[t],y[t])$. I would like to extract certain points from this spline by their x-Values, $x_0$. The easiest way I came up with was to minimize $B[t][[1]]-x_0$ for $t \in [0,1]$. So for finding the parameter t at which the x value is 13.46 if have the following code:               data = {{9.93114`, 379022.8`}, {11.71875`, 321705.7`}, {13.46983`,      280830.8`}, {15.625`, 243949.8`}, {18.60119`, 206915}, {21.70139`,      179663.2`}, {24.93351`, 158942.4`}, {29.29688`,      138396.2`}, {33.48214`, 123873.8`}};          spline = BSplineFunction[data, SplineDegree -> 3];     tstfc[t_] := spline[t][[1]]          FindMinimum[Abs[tstfc[x] - 13.46] , {x, 0}]      It seems like the Spline is not getting evaluated. How can I solve this? And is there a standard way to extract points from a spline? Thanks!


title: Why is my solution to PE #5 so slow

text: I'm new to _Mathematica_ and it was suggested to me to go through the Project Euler problems in order to learn it. However, I can't quite figure out why my solution to #5 is so slow. The problem: > What is the smallest positive number that is evenly divisible by all of the > numbers from 1 to 20? My _Mathematica_ solution:               n = 1;      max = Fold[Times, 1, Range[20]];      While[Fold[Plus, 0, Table[Mod[n, x], {x, 20} ]] != 0 And n < max,          Null;          n++     ];      Print[n]      This works but takes a _long_ time to finish (to give you an idea I had time to eat supper and it still wasn't done). For comparison I wrote a close analogue of the above code in C++:               #include <algorithm>     #include <array>     #include <iostream>     #include <numeric>          int main(int argc, char* argv[])     {         std::array<int, 20> divisors;         std::iota(std::begin(divisors), std::end(divisors), 1);         auto isMultipleOf = [&](unsigned long long x)         {             return std::all_of(std::begin(divisors), std::end(divisors), [=](int i) { return (x % i) == 0; });         };              unsigned long long n = 1;         while (!isMultipleOf(n)) { n++; }              std::cout << n << std::endl;              std::cin.get();         return 0;     }      It follows the same structure, a while loop that stops when Modulo returns 0 for each divisor from 1 to 20. To give you an idea of how much faster this is, I've benchmarked it using nonius with the following setup:               #define NONIUS_RUNNER     #include "Nonius.h++"          #include <algorithm>     #include <array>     #include <iostream>     #include <numeric>          NONIUS_BENCHMARK("Project Euler #5", [](nonius::chronometer meter)     {         std::vector<unsigned long long> results(meter.runs());         std::array<int, 20> divisors;         std::iota(std::begin(divisors), std::end(divisors), 1);              auto isMultipleOf = [&](unsigned long long x)         {             return std::all_of(std::begin(divisors), std::end(divisors), [=](int i) { return (x % i) == 0; });         };              std::vector<int> storage(meter.runs());         meter.measure([&](int i)         {             unsigned long long n = 1;             while (!isMultipleOf(n)) { n++; }             results[i] = n;         });     })      And these are the results (and in HTML for here): ![enter image description here](http://i.stack.imgur.com/yK8LY.png) As you can see, the average is about 5.2s seconds per run. In fact the whole benchmark took less time than one run in _Mathematica_ and I'm really curious as to why.


title: FindFit (Jacobian Error)

text: I, like others before me, am struggling with `FindFit`. So, I tried a simple example.               data2 = Table[{x, x^2}, {x, -2, 2, 0.1}]          ListPlot[data2]          FindFit[data2, a x^d, {a, d}, x]      Which then produces the error: > >     "FindFit::nrjnum: The Jacobian is not a matrix of real numbers at {a,d} > = {1.,1.}" >   The plot looks good, but the error message doesn't mean anything to me. Where the bottom of the range of `x` is greater than zero, FindFit `enter code here`works okay, and gives the right result. When the bottom of the range is zero or less, the error message comes back. Two questions please. What does the error message mean, and how can I avoid running into it?


title: How to scale the size of Pane to make it fit a Grid element?

text: I am wanting to make a `Pane` scale to fit (if `Spacings` are zero) a `Grid` element.               Grid[{{x, x,        Framed[         Pane[x,          ImageSize -> {Scaled[1], Scaled[1]},          ImageMargins -> 0,          Alignment -> Center],         FrameMargins -> 0,         ImageMargins -> 0], x, x}, {x, x, x, x, x}, {x, x, x, x, x}},       Background -> {None, None, {{1, 3} -> Red}}, ItemSize -> {5, 5},      Frame -> All,      Spacings -> {0, 0}]      Note that I added the `Frame` solely to outline the `Pane` so that the dimensions could be seen. On my system, OS X 10.6.8, Mma V8.0.4, the scaling works in the x direction but not in the y direction. Can anyone offer an explanation and solution (or could this be a bug)? ![enter image description here](http://i.stack.imgur.com/BjnqH.png)


title: Implementation of Balaban's Line intersection algorithm in Mathematica

text: I'm trying to implement a Brillouin Zone algorithm within _Mathematica_ , including the generation of Brillouin zones of higher order in 2D and 3D. There is a nice implementation of generating these zones in the _Mathematica Guidebook for Graphics_. However, this implementation uses the brute force approach in calculating line segment intersections of order $\mathcal O(n^2)$ with $n$ number of lines:               intersectionPoint[{{p1x_, p1y_}, {r1x_, r1y_}}, {{p2x_, p2y_}, {r2x_, r2y_}}, maxDist_] :=     Module[{aux},     If[PossibleZeroQ[r1y r2x - r2y r1x], Sequence @@ {},      aux = {p1x + (r1x (p1y r2x - p2y r2x -                      p1x r2y + p2x r2y))/(r1x r2y - r1y r2x),                p1y + (r1y (p1y r2x - p2y r2x -                      p1x r2y + p2x r2y))/(r1x r2y - r1y r2x)} // N;      If[Simplify[aux.aux] <= maxDist &&       IntervalMemberQ[       IntervalIntersection[Interval[{p1x, p1x + r1x}],         Interval[{p2x, p2x + r2x}]], aux[[1]]] &&       IntervalMemberQ[       IntervalIntersection[Interval[{p1y, p1y + r1y}],         Interval[{p2y, p2y + r2y}]], aux[[2]]], aux, Sequence @@ {}]]]      I'm sure there are a lot of improvements to above code, but the fact persists that the order will be of $\mathcal O(n^2)$. Since the line intersection for the Brillouin zone algorithm for high order zones in 3D is by far the most costly step, I'm looking into smarter approaches to find intersecting line segments. The very smart algorithm by Balaban entitled _An optimal algorithm for finding segments intersections_ achieves an order of at least $\mathcal O(n\log\,n)$. However, the algorithm involves a rather complex binary search tree implementation. Since _Mathematica_ has very efficient search implementations within lists already natively supported, I wonder if someone has implemented the Balaban or equivalent sweep line and sweep plane algorithms within _Mathematica_ that takes advantage of the built-in _Mathematica_ search functions? I'm especially interested in a 2D **and** a 3D implementation of a line segment intersection within _Mathematica_. Many thanks in advance for any help!


title: How to thread a list

text: I have data in format               data = {{a1, a2}, {b1, b2}, {c1, c2}, {d1, d2}}       Tableform: ![enter image description here](http://i.stack.imgur.com/4fzOI.png) I want to thread it to :               tdata = {{{a1, b1}, {a2, b2}}, {{a1, c1}, {a2, c2}}, {{a1, d1}, {a2, d2}}}       Tableform: ![enter image description here](http://i.stack.imgur.com/HTptq.png) * * * And I would like to do better then               pseudofunction[n_] := Transpose[{data2[[1]], data2[[n]]}];     SetAttributes[pseudofunction, Listable];     Range[2, 4] // pseudofunction      * * * Here is my benchmark data, where data3 is normal sample of real data.               data3 = Drop[ExcelWorkBook[[Column1 ;; Column4]], None, 1];     data2 = {a #, b #, c #, d #} & /@ Range[1, 10^5];     data = RandomReal[{0, 1}, {10^6, 4}];      Here is my benchmark code               kptnw[list_] := Transpose[{Table[First@#, {Length@# - 1}], Rest@#}, {3, 1, 2}] &@list     kptnw2[list_] := Transpose[{ConstantArray[First@#, Length@# - 1], Rest@#}, {3, 1, 2}] &@list     OleksandrR[list_] := Flatten[Outer[List, List@First[list], Rest[list], 1], {{2}, {1, 4}}]     paradox2[list_] := Partition[Riffle[list[[1]], #], 2] & /@ Drop[list, 1]     RM[list_] := FoldList[Transpose[{First@list, #2}] &, Null, Rest[list]] // Rest     rcollyer[list_] := With[{fst = First@#, rst = Rest@#}, Thread[{fst, #}] & /@ rst] &@list          Drop[Timing[paradox2[#];] & /@ {data, data2, data3}, None, -1]     Drop[Timing[OleksandrR[#];] & /@ {data, data2, data3}, None, -1]     Drop[Timing[kptnw[#];] & /@ {data, data2, data3}, None, -1]     Drop[Timing[kptnw2[#];] & /@ {data, data2, data3}, None, -1]     Drop[Timing[RM[#];] & /@ {data, data2, data3}, None, -1]     Drop[Timing[rcollyer[#];] & /@ {data, data2, data3}, None, -1]      Results               {{7.503}, {0.968}, {0.031}}     {{0.983}, {0.296}, {0.031}}     {{0.312}, {1.67}, {0.031}}     {{0.094}, {0.218}, {0.031}}     {{3.759}, {0.546}, {0.032}}     {{3.073}, {0.733}, {0.031}}


title: BlockRandom and NestList: how get random maps with the same noise?

text: I need to compare solutions in random systems with the same noise and different initial conditions. Here I run twice a random map with the same initial condition, inside a `BlockRandom`. The output expected should be exactly the same orbit but they are different. What have I done wrong?               map[x_, α_] := α/2 ArcTan[x] + 1/2 x          ClearAll[α]     noisymap[x_, α_, σ_] := map[x, α] + σ RandomReal[{-1, 1}]          ClearAll[noisy1, noisy2]     BlockRandom[         noisy1 = NestList[With [{α = 2, σ = 0.1}, noisymap[#, α, σ] &], -0.32, 1000];         noisy2 = NestList[With [{α = 2, σ = 0.1}, noisymap[#, α, σ] &], -0.32, 1000];     ]          ListLinePlot[{noisy1, noisy2}]          ListLinePlot[Abs[noisy1 - noisy2]]


title: How to efficiently take complement of two big lists?

text: I have a giant list `l1` and some smaller lists `l21`, `l21`, ..., `l2n`. The `l1` is the superset and has $\tilde{}10^7$ elements. `l2?` is subset of `l1` (if my other code does correct job). All lists only contain numbers (again, if my code does correct job). I need to take complement of `l1` and each of the `l2?`. The number of subsets (i.e. `n`) is several hundreds. What's the most memory/time efficient way of doing this? I run this on 4GB machine and usually have 1.* GB of free memory when the program reaches that stage. I'd probably save numbers in file and use some command-line tool like `grep` to do this. But the original lists are all prepared in a Mathematica program. If there is a good solution in Mathematica then i'd like to avoid going out.


title: How do we solve N-Rooks variation using primes?

text: Using a $p_n $x $p_n$ matrix, how can we solve the N-Rooks problem to find a prime in every row and column?               Table[MatrixForm[Table[If[PrimeQ[n], "P", "."], {m, 0, Prime[o]^2 - Prime[o],      Prime[o]}, {n, m + 1, m + Prime[o]}]], {o, 1, 8}]        Here is the $11 $x$11$ matrix with the possible prime positions for the queens: ![N-RooksPrimeVariation](http://i.stack.imgur.com/OYfi0.jpg) Note: single primes are always in the $p$-th column. This is one possible solution (done by hand): ![N-RooksPrimeSolution](http://i.stack.imgur.com/V7Ojp.jpg) **Edit** Changed the title and link as Paxinum suggested.   OEIS A215637 has these counts of multiple solutions through $10th$ prime:   $$ 1, 1, 1, 2, 7, 72, 2144, 2641, 1345721, 2191254096$$


title: Replacement variable in list plot

text: I would like the replacement:               /. {ComplexInfinity -> 0}       to be treated as a variable. I am trying to overlay the following list plots:               g1 = (d = (q = 20;      f = (lop =          Transpose[{Flatten[            Reverse[              Table[Zeta[y], {y, 0, q}]] /. {ComplexInfinity -> 0}],           Flatten[Table[x^n, {n, 0, q}]]}];        {#1*#2} & @@@ lop);      Flatten[f];      Total[f]);     sol = Solve[d == 0];     r = ListPlot[{{Re@x, Im@x} /. sol}, AspectRatio -> Automatic, PlotStyle -> Black];     Show[r, PlotRange -> {{-q/10, q/3}, {-q/10, q/10}}, Axes -> False, ImageSize -> 800]);          g2 = (d = (q = 20;      f = (lop =          Transpose[{Flatten[            Reverse[              Table[Zeta[y], {y, 0, q}]] /. {ComplexInfinity -> 1}],           Flatten[Table[x^n, {n, 0, q}]]}];        {#1*#2} & @@@ lop);      Flatten[f];      Total[f]);     sol = Solve[d == 0];     r = ListPlot[{{Re@x, Im@x} /. sol}, AspectRatio -> Automatic, PlotStyle -> Black];     Show[r, PlotRange -> {{-q/10, q/3}, {-q/10, q/10}}, Axes -> False, ImageSize -> 800]);          ...      For:               Show[{g1, g2, g3.....}]      Is there an easier way to do this - ie, in a single command?


title: Using list elements in TrackedSymbols for Dynamic

text: During the execution of the following code a column of three lists and two sliders are displaying in output. The first list updates if either a or b changes. The second list updates only if the value of a is changed. Similarly, the third list updates only if the value of b is changed.               a = 0;     b = 0;     Column[     {       Dynamic[{a, b}, TrackedSymbols :> {a,b}],       Dynamic[{a, b}, TrackedSymbols :> {a}],       Dynamic[{a, b}, TrackedSymbols :> {b}],       Slider[Dynamic[a], {0, 1}],       Slider[Dynamic[b], {0, 1}]     }     ]      Next I would like to replace {a,b} by a list x with two elements:               x = {0, 0};     Column[     {       Dynamic[{x[[1]], x[[2]]}, TrackedSymbols :> {x}],       Dynamic[{x[[1]], x[[2]]}, TrackedSymbols :> {x[[1]]}],       Dynamic[{x[[1]], x[[2]]}, TrackedSymbols :> {x[[2]]}],       Slider[Dynamic[x[[1]]], {0, 1}],       Slider[Dynamic[x[[2]]], {0, 1}]     }     ]      It is easy to check that now only the first list updates. Please help me to solve this problem.


title: how can I solve integrals including recursion of some sequences of functions

text: I would like to solve the equations as given below in mathematica. I have written some codes before but I have no idea when there is sub indexing to indicate the series of functions. I will be very happy and grateful if you could help me. Here are the equations: $$P[n]=\int_{(-\infty,B)\cup (A,\infty)} q_n (x) \mathrm{d}x$$ and $$q_n(x)=\int_{B}^A q_{n-1} (\omega)f(x-\omega)\mathrm{d} \omega,\quad q_1=f,\quad n\geq 1.$$ and $f$ is some density function, say standard Gaussian density. Eventually, I want to obtain the probability mass $P[n]$. Thank you very much! * * * I wrote this (from Hector's post):               f0[x_] := 1/Sqrt[2*Pi*1^2]*E^(-(x + 1)^2/(2*1^2))     q[n_ /; n > 1, B_, A_, f_][x_] := NIntegrate[q[n - 1, B, A, f][ω] f[x - ω], {ω, B, A}]     q[1, B_, A_, f_][x_] :=f[x]     p[n_, B_, A_, f_] := NIntegrate[q[n, B, A, f][x], {x, -∞, B}] +                                        NIntegrate[q[n, B, A, f][x], {x, A, ∞}]          N[p[1, -2, 2, f0[x]]] --> 0.160005     N[p[2, -2, 2, f0[x]]] --> 0.35594     N[p[3, -2, 2, f0[x]]] --> 0.237045     N[p[4, -2, 2, f0[x]]] --> 0.229432     N[p[5, -2, 2, f0[x]]] --> 0.222063      ##  ... these results seem incorrect because $p$ is the probability mass function and should add up to $1$. Correct results for $f_0$ Gaussian with mean $-1$ and variance $1$ and $A=2$ and $B=-2$:               n=1-->0.1600     n=2-->0.3559     n=3-->0.2323     n=4-->0.1238     n=5-->0.0633     n=6-->0.0320     n=7-->0.0162


title: How to get complement of a pattern

text: I have a list. I want to get all the elements in that list which do not match a given pattern. That is, I want the strings which do not match any of the following patterns:   1. First and last characters are the same: $123aw1$    2. Does not have two consecutive similar characters: $1era22we, awe33rt, 123aa123$ I wrote following code               inputset = ToString /@ {       11223434, 12123434, 11234342, 11234243, 11234234, 11232434, 12132434,        12134234, 11234324, 11232443, 11234423, 12134243, 12314234, 12314324,        12341234, 11223344, 11223443, 11234432     };     outputset = Complement[inputset,        Select[inputset,          StringMatchQ[#, StringExpression[x_, ___, x_]] ||            StringMatchQ[#, StringExpression[___, x_, x_, ___]] &]];      and I got > >     outputset = {12123434, 12132434, 12134234, 12134243, 12314234, 12314324, > 12341234} >   Is there an easy simple and efficient way to do this?


title: Recognizing special cases of a defined function for permuted arguments

text: I have a number of ugly ways to implement the following **pattern recognition** task, but I'm looking for something elegant to keep my notebook tidy. I need to define a function of six variables $f(a,b,c;A,B,C)$ which is known to be unchanged under the simultaneous interchange of any two of $a,b,c$ and of the corresponding $A,B,C$: $$\begin{align}&f(a,b,c;A,B,C) = f(a,c,b;A,C,B) = f(b,a,c;B,A,C) \\ =&f(b,c,a;B,C,A) = f(c,a,b;C,A,B) = f(c,b,a;C,B,A)\end{align}$$ **EDIT for clarity: Given one definition, how do I get** **_Mathematica_** **to try all possibilities within the** **_restricted_** **set of permutations shown above for pattern matching? I need to mimic the effect of** `SetAttributes[f,Orderless]`. More concretely, if I define the special case:               f[a_, 0, b_, A_, 0, C_] := (a+b)/(A-C)      a function call `f[x, y, 0, m, n, 0]` should match, and return `(x+y)/(m-n)`. But `f[x, y, 0, m, 0, n]` should _not_ match, and thus return it must be returned unevaluated. **Added question:** Instead of finding a way to get _Mathematica_ to try all the possibilities when pattern matching, would it be easier to write code such that when a representative definition for `f` is made, the kernel automatically adds further definitions of `f` for the remaining permutations of the arguments?


title: Read and filter a text file without importing

text: I have a large text file of a million sections. Each section contains A lines of header and B lines of numeric data. I want to read the first and last line of B from each section (to have a list of 2 x million lines at the end). `Import` doesn't work since my file is too big to be read into memory. Is there a command like scan and filter for this?


title: Series command no longer expands arbitrary functions after aborting previous evaluation

text: I asked Mathematica 9 to execute the `SeriesCoefficient` command on a rather horrendously complicated expression. After some time I decided to abort the evaluation and try something different. Somehow, this has caused the `Series` and `SeriesCoefficient` commands to stop working properly. They can still correctly expand known functions, for example things like `Series[x^2*BesselJ[Sin[x],x],{x,0,5}]` do work as expected, but for arbitrary, not-yet-defined functions they no longer work, so `Series[f[x],{x,0,2}]` now returns just `f[x]` rather than the expected `f[0]+f'[0]x+f''[0]x^2/2+O[x]^3`. Does anyone know what exactly might have caused this and how I could fix it without having to restart the kernel? (Presumably the previous call to `SeriesCoefficient` changed some obscure internal parameter in the kernel which may be reversible...) I have a bunch of long, precalculated expressions in the kernel's memory and it would be quite annoying to have to export all of them and reimport into a new kernel.


title: Expanding derivatives of hypergeometric functions

text: Sometimes _Mathematica_ expresses results of integration or summation in terms of symbolic derivatives of `Hypergeometric2F1` function, and cannot further simplify these derivatives using `FunctionExpand` or `FullSimplify`. In some cases I was able to express those derivatives in terms of elementary functions and well-known mathematical constants, but it required some manual work and was on case-by-case basis. Now I have a table of about a hundred of derivatives I already dealt with and a function that can automatically replace them by their values. For example, it contains cases like               Derivative[0, 1, 0, 0][Hypergeometric2F1][-1/2, 3/2, 1/2, 1/Sqrt[2]] ==          (Sqrt[1 + Sqrt[2]] (Sqrt[2] Log[3/2 - Sqrt[2]] + 2 (Sqrt[2] + Log[2 + Sqrt[2]]))              - 4 Sqrt[2] ArcTan[Sqrt[1 + Sqrt[2]]])/2^(3/4)      and               Derivative[2, 0, 0, 0][Hypergeometric2F1][0, -3/4, 1, 1] ==          4 π/3 + 13 π^2/12 - 8 Log[2] - 3 π Log[2] + 9 Log[2]^2 - 8 Catalan      I wonder if anybody else tried to solve this problem and found a more general or automated approach to this? Or if anybody has a more comprehensive table of derivatives and is willing to share it? I can publish my table if anybody is interested (but I haven't kept all calculations that yielded those results).


title: Fraction of fibers that have failed

text: I have the following to set into mathematica. Assume a stress(sigma) applied on a specimen which has a number of fibers within it. All fibers that have a strength less than the applied stress should fail. I set a cumulative distribution of the fiber strengths with a mean and standard deviation. I want to use this cumulative distribution to tell me how many fibers are less than the applied stress which have failed and store this number somewhere. This procedure should be repeated until all fibers have failed. so there is a convergence in the two variables. I am new in mathematica so sorry for a vague question. thanks, Nick


title: Select words from different rows of column headings

text: I have a 2-dim array. The first 3 rows have column headings. The heading can be a single word, or 2 words (which take 2 rows) or 3 words (which take 3 rows). For each column I know which row has the most meaningful name for that column. I can't figure out how to map this and get what I want. For example:               a1 = {{"", "", "Class"}, {"Year", "Full", "of"}, {"Sold", "Amount",      "business"}};     a2 = {2, 3, 1};      I want my three headings to be "Year", "Amount", "Class", this is based on a2. I assume I can use Part to do this, and use Map with a LevelSpec. But I can't figure out how to make this work. Maybe I'm thinking in the wrong direction.


title: How to find a scaling parameter in matrix inversion process by MMA?

text: I simply would like to find the inverse of a given matrix $A$ by the iterative method $X_{k+1}=X_k(2I-AX_k)$ using $X_0=\frac{1}{\sigma_{max}^2}A^*$. An example is as follows               SeedRandom[123]; m = n = 500;     A = RandomReal[10, {m, n}]; Id = SparseArray[{{i_, i_} -> 1.}, {m, m}];     tolerance = 10^-6; max = 50; k = 0; R[0] = 1;     X[0] = (1./SingularValueList[A, 1][[1]]^2)*Transpose[A];     While[k < max && R[k] >= tolerance,       XX = A.X[k]; X[k + 1] = X[k].(2 Id - XX);       R[k + 1] = Norm[Id - X[k + 1].A, Infinity];       k++];     k     Table[R[l], {l, 1, k}]      As can be obsereved the number iterations is too high for a $500\times500$ matrix. What I want to do now is to scale this method by introducing the parameter $\alpha_k$ per cycle, i.e. $X_k<=\alpha_kX_k$. In fact, $\alpha_k$ must be computed adaptively so as to solve the following optimization problem $\|I-\alpha_kAX_k\|_2<\|I-AX_k\|_2$. In this way, we might be able to reduce the number of iterations. Note that $\alpha_k$ must rapidly tend to 1 in order not to cause instability. I will be thankful if anyone lend me a hand in caluculating the scaling parameter per cycle.


title: Loading and processing five files at a time from a directory containing many, many files

text: I have 3000 files (for example: aa101.csv, aa108.csv, aa120.csv, ...) and I need to process them. I need to load five files from a folder, process them, and export them to new list in Excel. Then I need to take another five files from the same folder and process them, and so on. I tried               printer[n_] :=        Module[{file = n},              calculation...         ...              Export[name <> ".xlsx", {data}, "Data"];       ]          printer[Import["E:\\mathematica\\a\\*", "text"]];      But `printer` loads all files from the specified folder. Could you please help me with this problem?


title: Getting FTSE indices in Mathematica

text: I'm not sure if this is the best StackExchange to post this question, but I figured it had more to do with the specifics of Mathematica than Quantitative Analysis so I've posted it here. Basically, I am trying to make a notebook in Wolfram Mathematica 9 which allows me to easily monitor and analyse share prices on the British FTSE 100,200 etc. stock exchanges; I know that Mathematica has the `FinancialData[]` function, and I was hoping to be able to use it for the FTSE markets. I have tried the following without success:               FinancialData["^FTAS","Members"]     FinancialData["^FTSE","Members"]      So I tried to look at the entire list of entities contained within `FinancialData` using:               FinancialData[]      However, this yielded a large list of indices and I was not able to find anything useful. The only reference I have managed to find on this was here, but as shown above I have tried this and only got the following output:               Missing["NotAvailable"]      Do I need to preload the british financial data in Mathematica at the beginning of my notebook, or is the data already there I just need to access it in a different way?


title: Implicitly differentiate an equation, then solve the resulting equation

text: Suppose I have an extremely tedious equation to differentiate and want mathematica to help do the differentiation and solve. Consider a less tedious equation: $$y (x,z) = sin \left(\frac{1}{x} \right) - \frac{1}{x} - z $$ Can mathematica find $\frac{\partial y}{\partial x} $ at $x=0.3$ by performing implicit differentiation on both sides and solving for $\frac{\partial y}{\partial x} $? Now suppose we try implicit differentiation: $$ sin (y) + y = sin \left(\frac{1}{x} \right) + xz$$ I want to find $\frac{\partial y}{\partial x} $ at $x=0.3$, $y=0.4$ and $z=0.5$ It should give a value of $5.94$. Tried this, but didn't work:               sin [y] + y == sin [1/x] + x z     D[y[x_, y_, z_], x] /. {x -> 0.3,  y -> 0.2, z -> 0.5}


title: How to make the MMA document has the background--color effect when the dounment is printed?

text: **_Description:_** Recently,I use the Mathematica to do my undergraduate paper,I would like to use the Mathematica to compose my paper. So I hope the Input and Output results have the `background--color effect` **_Question:_** How to do to achieve this effect?


title: Export Code to Pseudocode?

text: I'm writing a paper and all my code is in _Mathematica_. The snippets are mostly simple, and consist of loops, maps, variables, and conditionals. I'd like add it to my paper, however, not many academic journals accept verbatim code in a specific language, and I'm short on time, so here is my question: **Does anyone know of a package that translates _Mathematica_ functions and code to pseudo-code?** Of course there is no universal syntax pseudo-code, but I'll accept anything that is adequately general (bonus points for robust exportability to $\LaTeX$). Here are some examples of this utility in other languages:   * http://www.rapidqualitysystems.com/Products/CodeRocketEclipse   * http://www.bigresource.com/VB-Pseudocode-Generator-sjETRTxkP2.html When writing papers I always do the translation by hand, but enough is enough, _Mathematica_ should excel at a high-level translation problem like this and at least get the bulk of the work done for me! I use the pseudocode environment from the `fancybox` package to typeset pseudocode into $\LaTeX$. Please note that I fully intend on trying to write an answer to this myself, so don't down vote for the lack of code just yet! `:)`


title: Solving the Helmholtz equation in polar coordinates

text: I'm trying to (as a simple starter) find the solution to Helmholtz equation in polar coordinates -- I already know what it is and can derive it by hand, but just want to start here before asking _Mathematica_ to do it in more complex coordinates. Sample derivation from Wikipedia. My code:               pde2 = D[A[r, θ], {r, 2}] + D[A[r, θ], r]/r  + D[A[r, θ], {θ, 2}] / r^2 + k^2 A[r, θ] == 0          soln = DSolve[{pde2, A[a, θ] == 0}, A[r, θ], {r, θ}]      which I believe corresponds to: $$ A_{rr} + \frac{A_{r}}{r} + \frac{A_{\theta\theta}}{r^2} + k^2 A = 0 $$ with boundary condition $$ A(a, \theta) = 0 $$ One thing I'm wondering is that I'm not specifying $r \leq a$, but I can't work out how to do that. Any help, including links to documentation I've missed or misread will be greatly appreciated.


title: Convert operator to string

text: How to programmatically convert an operator such as `Equilibrium` into its displayed form as a string? The conversion should work like this:               FullForm[convert /@ {Equilibrium, LongRightArrow, LeftVector, Equal}]      ![Mathematica graphics](http://i.stack.imgur.com/sY9L8.png) I've tried various methods with no avail:   * converting to strings and wrapping in `"\\[...]"`   * using different form wrappers (`DisplayForm`, `TraditionalForm`, etc.)   * using low level boxes, but since that is really not my alley, I was a bit clueless   * since operators with built-in meaning are used too, argument usage does not seem viable (e.g. `ToString[Equal["", ""]]` which returns `True`)


title: updating code from 5.0 to 9.0

text: I am updating a code from a 5.0 version to a 9.0 version. I am speaking about "Advanced visual quantum mechanics". There is a package with this code: * * * `               VQMmsgon  = Head[General::"spell"]  =!= $Off;         VQMmsgon1 = Head[General::"spell1"] =!= $Off;          Off[General::spell1, General::spell];               (*-----------------------------------*)     BeginPackage["VQM`ArgColorPlot`"];     (*-----------------------------------*)         ClearAll[QArgColorPlot,QListArgColorPlot];          (*-----------------------------------*)     Begin["`Private`"];     (*-----------------------------------*)        If[!ValueQ[$UseListLinePlot],             $UseListLinePlot=True;     ];          Options[QArgColorPlot] := Sort @ {JoinOptions[             {             PlotStyle -> None             },             Options[ If[$UseListLinePlot, ListLinePlot, Plot] ],             {             Opacity -> 1,                      Compiled->True,              QSaturation->1, QBrightness->1, QBottomLine->0, QShiftPlot->0, QPlotDown->False,              QSquared->False             } ] };          Options[QListArgColorPlot] =  Sort @  Join[Options[QArgColorPlot],{QHorizontalRange->All}];          SetAttributes[QArgColorPlot,HoldAll];          QArgColorPlot[func_,{x_Symbol,xmin_,xmax_},opts___?OptionQ] :=         Module[{comp,plot1,opts1,xvars,yvals},             comp = Compiled/.Join[{opts}, Options[QArgColorPlot]];             If[comp === True,               abf = Compile[{x},Abs[func],{{func,_Complex}}];               fnc = Compile[{x},func,{{func,_Complex}}], (*else*)               abf = Abs[func];               fnc = Function[{x},func];             ];             opts1   = FilterRules[{opts},Options@Plot];             plot1   = Plot @@ { abf, {x,xmin,xmax},                                  {opts1} /. ( PlotStyle -> _ ) :> Sequence[]};             xvars   = First /@ Level[plot1[[1]], {5}];             yvals   = fnc /@ xvars;                 QListArgColorPlot[{xvars,yvals}//Transpose, opts]         ]/;NumericQ[xmin] && NumericQ[xmax]     EndPackage[]      ## `


title: Changing equations to be solved by NDSolve when an event is triggered

text: I am using NDSolve to solve a set of coupled differential equations. When a certain event occurs, I want two equations in the set to be changed radically, for example from `x'[t] == a*y[t] + b*y'[t], y[t] == c*x[t] + d*x'[t]` to `x'[t] == 0, y[t] == -f*y'[t]` For this purpose, I have first tried to use the trick shown in the Mathematica featured example for the ACDC Full Wave Rectifier. So I just wrote the equations like `x'[t] == go[t]*(a*y[t] + b*y'[t]), y[t] == go[t]*(c*x[t] + d*x'[t]) + (1-go[t])*(-f*y'[t])` and set events like `WhenEvent[{y[t] > y0 && go[t]==1}, go[t] -> 0]` `WhenEvent[{y[t] < y0 && go[t]==0}, go[t] -> 1]` to jump back and forth between the two pairs of equations I want to use each time the event is triggered. However, two 'division by zero' errors occur (I assume it's because NDSolve is still trying to solve the parts multiplied by zero). So apparently this method does not work for this type of problem. Anybody knows the 'right' way to do this?


title: Random variates in Recurrence Function

text: I'm completely new to Mathematica and can't seem to find an answer elsewhere so hopefully I can get some help here. I'm trying to plot a recurrence relation, where a random variate is generated at each iteration of the recurrence. From looking at the output, it appears as though the RandomVariate evaluates to a constant at each iteration. I have this inside a 'manipulate' block:               ListLinePlot[        RecurrenceTable[{S[i] ==         S[i - 1]*        Exp[(r - (vol^2/2.0))*T/N +           vol*RandomVariate[NormalDistribution[μ, σ]]*           Sqrt[T/N]], S[1] == S0}, S, {i, 2, N}]]}]      Any help with what I'm trying to accomplish would be appreciated. Edit: here's the full version                Manipulate[      Column[{      Plot[{PDF[ NormalDistribution[μ, σ], x],                    PDF[ JohnsonDistribution["SU", γ, δ, μ, σ], x]}, {x, -6, 6}, Filling -> Axis],     ListLinePlot[     RecurrenceTable[{S[i] ==         S[i - 1]*         Exp[(r - (vol^2/2.0))*T/N +            vol*RandomVariate[NormalDistribution[μ, σ]]*            Sqrt[T/N]], S[1] == S0}, S, {i, 2, N}]]}],     Style["Distribution Parameters", 12, Bold],      {{μ, 0}, -5,   5},      {{σ, 1}, 0.1,  5},      {{γ, 1},    1, 10},      {{δ, 1},    1, 10} ,      Delimiter,      Style["Option Parameters", 12 , Bold],      {{N, 10}, 10, 1000},      {{T, 1/12}, 1/12, 1},      {{vol, 0.2}, 0, 1.0},      {{r, 0}, 0, 0.3},      {{q, 0}, 0, 0.3},      {{S0, 100}, 0, 1000},      ControlPlacement -> Left]


title: Is there a notebook autosave frequency configuration?

text: I've had Mathematica crash on me a number of times, and have had to recreate notebook contents from the last save point. I was looking for something in the preferences like an autosave frequency configuration parameter that I could use to automatically save all my notebook content at some regular frequency to minimize losses due to crashes. I found `NotebookSave[]`, and a `NotebookAutoSave -> True` attribute for `CreateDocument`, but both these appear to be for manipulating external notebooks. Is there a way to do this systematically and by default?


title: Error bar plot - no bars but rather point size determined by errors

text: Looking for a way to create an `ErrorListPlot` `(x,y,error)` with the radius of the `PlotMarker` determined by the magnitude of the error (which in my case is symmetrical), no actual error bars desired. I want the size of the points to reflect the standard deviation of the datum, rather than `Small,`Large`or any`AbsolutePointSize` values. I can probably approach this a variety of ways (`BubbleChart`, `ListPlot` with custom `PlotMarkers`, or `ErrorListPlot` with custom `ErrorBarFunction`) but I can't make progress. All of my efforts are being foiled by the relative scaling of `PlotMarkers` to the width of the plot, rather than the magnitude of the data values.


title: How to reverse the gradient and ticks in BarLegend

text: I created a plot with a horizontal BarLegend for TemperatureColors (see1). Code:               PlotLegends ->           Placed[BarLegend[{"TemperatureMap", {15, 30}},Ticks -> Table[i, {i, 15, 31, 1}], LegendMarkerSize -> 300,             LegendLabel -> "T(\[Degree]C)",             LabelStyle -> {Bold, Black, 11}], {Bottom, Center}]       Now I just want to have the BarLegend having the temperatures on it decreasing from left to right, means values and colors reversed with high temperatures on the left. ![enter image description here](http://i.stack.imgur.com/0d9Jk.jpg)


title: plot data differences

text: I have the following data:               data12 = {        {1, 981.946, 978.783, 978.783},        {2, 813.948, 810.783, 810.667},        {3, 743.422, 743.447, 744.062},        {4, 715.382, 715.478, 715.326},        {5, 690.345, 696.075, 691.664},        {6, 862.126, 870.902, 860.371}     };      I want to make a `ListLinePlot` using the first row element (the index) as the X coordinate, and for the Y coordinate, the difference between the second and third value in row (generally speaking, the difference between two generic columns). How can I do it? Thanks in advance for your reply. === EDIT === I've found this solution:               ListLinePlot[{#[[1]], #[[2]] - #[[3]]} & /@ data12]      Is it a good solution, or is there a better way to accomplish this?


title: Hyperlinks not preserved when saving in PDF format in MMA V10

text: I usually create my course contracts in Mathematica and then save them in PDF format. The notebooks include hyperlinks and these have transferred to PDF without problem over the last several versions of Mathematica (at lease 7, 8 an 9). Is there something different that I need to do in version 10 in order to preserve hyperlinks? I tried `SetOptions[$FrontEndSession, PrintingStyleEnvironment -> "Working"]`. But this only changed font sizes.