title: Rough mesh lines in partially opaque 3D plots

text: If I plot a surface with mesh lines, they show up fine (of course). However, if the surface is even just a little transparent, they get quite rough. Compare this to setting the Opacity to 1:                 ParametricPlot3D[{4 + (3 + Cos[v]) Sin[u], 4 + (3 + Cos[v]) Cos[u],         4 + Sin[v]}, {u, 0, 2 Pi}, {v, 0, 2 Pi},         PlotStyle -> Opacity[.99],        MeshStyle -> Thickness[.005],         ImageSize -> 800,        Axes -> False, Boxed -> False]      Here are the results: ![rough lines](http://i.stack.imgur.com/z9Fbo.jpg) ![smooth lines](http://i.stack.imgur.com/hfenx.jpg) How can I get proper smooth lines and use Opacity at the same time? UPDATE (Aug. 9, 2014): Wolfram tells me that "this is an issue with rendering transparent 3D objects on Linux systems using Intel graphics hardware." It has to do with "depth peeling".


title: Why setting PlotPoints make my 3d contour plot broken?

text: I'm trying to make a iso surface plot from some data using ContourPlot3d. My data is a 3 dimension data with form like `{{x,y,f[x,y]},...}`. I first make this data into 4d by rotating it along the x axis, so that `{x,y,f[x,y]}` becomes `{x,y,z,f[x,y,z]}`. Then interpolate them and plot the interpolated function. But sometimes I get a broken surface. Here is the detail:               Get["https://dl.dropboxusercontent.com/u/24667921/data.dat"];     f = Interpolation[data];     f3d[x_, y_, z_] := f[x, Sqrt[y^2 + z^2]];          ContourPlot3D[      Abs[f3d[x, y, z]]^2, {x, -15, 15}, {y, -15, 15}, {z, -15, 15},       Mesh -> None, PlotPoints -> 20, Contours -> {1*^-6},       ViewPoint -> {1.3, -1.3, 2.9}, ViewVertical -> {0.2, -1, 0.2},       Axes -> False, Boxed -> False, ImageSize -> 300]      ![enter image description here](http://i.stack.imgur.com/AwyGu.png) We can see two dark spot on the surface. If I remove the `PlotPoints->20`, the holes are gone. And this seems not caused by the same reason from this post, because I still see the broken surface as I exported to pov file and rendered in povray. For my problem I can't just remove the `PlotPoints->20` option, because I have to generate the same kind of plots from a serial of data. And I have to set a PlotPoints to a number to make sure the contour can be found. ![enter image description here](http://i.stack.imgur.com/0yG0r.png)


title: How to compute this triple integral?

text: In **Mathematica** how can I compute this integral:$$ \iiint_{D}\sqrt{(1-9z^2)(1-4y^2-9z^2)}\,dx\,dy\,dz$$ where D is the domain: $$D: x^2 +4y^2+9z^2\le1$$ Please I need help!!!


title: How do I get a list of allowed values for an option?

text: When using _Mathematica_ how can I get a list of the allowed values of an option? As an example I can use the `Options` command as follows -               Options[Manipulate]      which gives me a list of available options               (* {Alignment->Automatic,AppearanceElements->Automatic,AutoAction->\     False,AutorunSequencing->Automatic,BaselinePosition->Automatic,\     BaseStyle->{},Bookmarks->{},ContentSize->Automatic,ContinuousAction->\     Automatic,ControlAlignment->Automatic,ControllerLinking->Automatic,\     ControllerMethod->Automatic,ControllerPath->Automatic,\     ControlPlacement->Automatic,ControlType->Automatic,DefaultBaseStyle->\     "Manipulate",DefaultLabelStyle->"ManipulateLabel",Deinitialization:>\     None,Deployed->False,Evaluator->Automatic,Frame->False,FrameLabel->\     None,FrameMargins->Automatic,ImageMargins->0,Initialization:>None,\     InterpolationOrder->Automatic,LabelStyle->{},LocalizeVariables->True,\     Method->{},Paneled->True,PreserveImageOptions->True,RotateLabel->\     False,SaveDefinitions->False,ShrinkingDelay->0,\     SynchronousInitialization->True,SynchronousUpdating->Automatic,\     TouchscreenAutoZoom->False,TouchscreenControlPlacement->Automatic,\     TrackedSymbols->Full,UnsavedVariables:>None,UntrackedVariables:>None} \     *)      I can use `Options` for a specific parameter, i.e.,               Options[Manipulate,ControlType]     (* {ControlType->Automatic} *)      But this doesn't tell me what the possible allowed values are for this option. Checkbox, Setter etc. Is there a command I can use to find the allowed values of an option?


title: GraphPath: *all* shortest paths for 2 vertices, edge lengths negative

text: _Mathematica_ uses Bellman-Ford to find a shortest path between two vertices when the edge lengths are negative:               g = SparseArray[{{1,2} -> -1,{1,3} -> -1,{2,4} -> -1,{3,4} -> -1}]       GraphPath[g,1,4]      yields > {1,2,4} I want to find _all_ such shortest paths. In the example above, `{1,3,4}` is another shortest path. Goal: I'm testing a non- _Mathematica_ shortest path algorithm against _Mathematica_. My algorithm also lazily finds only one shortest path, but it's different from the path _Mathematica_ finds. I need to confirm my algorithm's shortest path really is a shortest path. I realize I could just compare the path lengths (if they're equal, my algorithm has found a shortest path), but that wouldn't catch other errors in the algorithm (eg, if it's inventing edges or nodes or something). I also realize I could have _Mathematica_ find all paths or something and filter for the shortest ones, but that seems inefficient for larger graphs. I've read Finding all shortest paths between two vertices, but   1. I couldn't get it to work with _Mathematica_ 9, and, more importantly   2. it appears to be for positive-length edges.  NOTE: I realize I'm using a SparseArray for a graph above, but _Mathematica_ seems to be OK with this.


title: calling CUDA library functions

text: Mathematica has some predefined CUDA functions, like CUDAMap, CUDAFourier, etc. My question is how can one call functions which are part of CUDA library but not part of predefined Mathematica functions? For example, CUDA 6.0 has a large Math library; so if I am to call cuFFT from that library instead of using CUDAFourier, how would I go about doing this? Do I have to write a C code which calls the cuda library function and then call the c function from Mathematica. That seems too round about way of doing something. I could not quite find it in the documentation. Thanks very much!


title: Compute (Co)Variance of Random Variable(s) Directly

text: Is there a direct command in Mathematica that computes the covariance between two random variables? Hence, instead of typing               Expectation[f(x)*g(y),{y~some distribution,x~some distribution}] -      Expectation[f(x),{y~some distribution,x~some distribution}]*     Expectation[g(y),{y~some distribution,x~some distribution}]      Is there a command that archieves the same by typing simply               Covariance[{f(x),g(y)},{y~some distribution,x~some distribution}]      I have tried to use the following function:               CoVar[RVfuncs_, dist_] :=      Expectation[RVfuncs[[1]]*RVfuncs[[2]],      dist] - (Expectation[RVfuncs[[1]], dist]*Expectation[RVfuncs[[2]], dist])      It works, but it is much slower than writing out the three "Expectation" parts.


title: Shading between polar graphs

text: Since `PolarPlot` doesn't support `Filling`, what is the best way to shade or fill the a region between two polar curves? For instance, how would I generate a version of the following graph with the region inside the first curve but outside the second curve filled?               PolarPlot[{{1, -1} Sqrt[2 Cos[t]], 2 (1 - Cos[t])}, {t, -\[Pi], \[Pi]}]      ![Mathematica graphics](http://i.stack.imgur.com/C7rJB.png)


title: EventHandler {"MouseDown", 1} with PassEventsDown -> True not working as expected

text: I want my `EventHandler` to respond only to left mouse clicks and pass the right mouse click to the built in event handler. I have tried               DynamicModule[{pt = {0, 0}},       EventHandler[       Graphics[{Disk[Dynamic[pt], .1]},         PlotRange -> 1], {"MouseDown", 1} :> (pt = MousePosition["Graphics"]), PassEventsDown -> True]]      But the problem is that the point moves even on right clicks. Is this a bug? **How can I make the point move only on left clicks and display the graphics pop up menu on right clicks (without moving)?**               DynamicModule[{pt = {0, 0}},       EventHandler[       Graphics[{Disk[Dynamic[pt], .1]},         PlotRange -> 1], {"MouseDown", 1} :> (pt = MousePosition["Graphics"]), PassEventsDown -> False]]      Responds only to left clicks as expected. So to clarify: I want to have this menu, but without the point going to the position of the right click. The point should respond to left clicks only. ![Mathematica graphics](http://i.stack.imgur.com/mBqGq.png) I'm running MMA 9.0.0 on Win 7 64 bit.


title: NDSolve much slower when using InterpolatingFunctions inside

text: I am solving an ODE system with _Mathematica_. Let's say the system is of the form (to simplify).               sol = NDSolve[{x'[t] == f[t] x[t] + g[t], x[0] == 0}, x, {t, 0, 1}]      The functions `f[t]` and `g[t]` are obtained from a different program. I either use a simple fit for `f[t]` and `g[t]` (say polynomial) or define them as `InterpolationFunctions` from data tables I have, i.e.               f = Interpolation[data]      In the latter case (which is more desirable as more accurate), the system takes 10 times longer to solve! In detail, I actually loop over `NDSolve` for several additional parameters, and my ODE is with complex coefficients and 6-dimensional. So the system is already kind of long to solve, and 10 times longer is killing me... Anyone has any advice on how to speed this up? Interpolating functions should be super fast, shouldn't they?


title: Integrating hat functions

text: I am trying to integrate a hat function for a project that I am doing and have found a method to do so but I find it sloppy. Currently I have the basis function               \[Psi][z_] := z - Subscript[Z, i]/ \[CapitalDelta]z + 1;      which I am trying to integrate from $z_{i-1}$ to $z_{i+1}$. I break the basis function up into two pieces and integrate the left side from $z_{i-1}$ to $z_{i}$ and then the right side from $z_i$ to $z_{i+1}$. My first question is, is there a way to integrate piecewise functions? The second question I have is, is there a way to set global assumptions like $z_{i-1} < z_i < z_{i+1}$, $z_i - z_{i-1} = \Delta z$ , etc? **Edit** : This is the piece wise function taken directly from my code I am trying to integrate               \[Psi][z_, c_] :=  Piecewise[{{(z - c)/\[CapitalDelta]z + 1,       z <= c}, {-(z - c)/\[CapitalDelta]z + 1, z > c}}];      where $c$ is the center of the hat function. Here is my attempt to integrate the piece wise function                FullSimplify[      Integrate[\[Psi][z, Subscript[Z, i]], {z, Subscript[Z, i - 1],         Subscript[Z, i + 1]}],       Assumptions -> {-(Subscript[Z, i + 1] - Subscript[Z,             i ]) == -\[CapitalDelta]z,         Subscript[Z, i + 1] - Subscript[Z,           i ] == \[CapitalDelta]z, -(Subscript[Z, i] - Subscript[Z,             i - 1 ]) == -\[CapitalDelta]z,         Subscript[Z, i] - Subscript[Z, i - 1 ] == \[CapitalDelta]z}]      I do not get a usable answer. Am I doing something wrong (ie can one integrate a piece wise function)?


title: How to play microtonal music using Mathematica?

text: I am trying to model microtonal music using `Play`. I have only partial success because it takes such a long time to make some sound. Could you please have a look at my stackoverflow.com question? The link is http://stackoverflow.com/questions/14849184/how-to-play-microtonal-music- using-mathematica-or-other-tools **=========== Original question linked above ===============** Do you have any suggestions how to write and play microtonal music? My solution: I tried to use `Play` and `Piecewise` but it takes a LONG time to take a sound! Please read the details. As you know there are many notes other than Do or Re or Mi of western music. So maybe I can not use `SoundNote` for ancient music. Each note is represented as a fraction. Using middle Do as a base (i.e., `base = 260.741 Hz`); the next notes are represented by `re = 9/8 base`, `mi = 5/4 base`, `fa = 4/3 base`, `di = 3/2 base`, etc. For example, to play fa for 2 seconds with `SoundVolume = 1/3`, evaluate               Play[1/3 Sin[ fa 2 Pi x], {x,0,2}].      I model each such instance with a list of the form `{time, note, soundvolume}`, for example `{2, fa, 1/3}`. Consider a very short example of such a sequence of notes               voice1= {{1, 9/8, 1}, {1, 5/4, 2/3}, {1/2, 4/3, 1/3}, {1/2, 9/8, 1/3}, {1, 4/3, 1},              {1, 3/2, 2/3}, {1, 4/3, 1/3}}      How can voice1 be easily played using `Play`? I tried using `Piecewise`, but with that I have to wait for a LONG TIME before I get any sound result. (Maybe the reason is the use `Piecewise` in `Play`, but I am not sure.) Please, try the following example to see how slow you get the sound result for voice1.               Play[       Piecewise[{         {1, 0. < x <= 1},         {2/3, 1 < x <= 2},         {1/3, 2 < x <= 5/2 || 5/2 < x <= 3},         {1, 3 < x <= 4},         {2/3, 4 < x <= 5},         {1/3, 5 < x <= 6},         {0, True}}]       Sin[ base 2 Pi          Piecewise[{           {9/8, 0. < x <= 1},           {5/4, 1 < x <= 2},           {4/3, 2 < x <= 5/2},           {9/8, 5/2 < x <= 3},           {4/3, 3 < x <= 4},           {3/2, 4 < x <= 5},           {4/3, 5 < x <= 6},           {0, True}           }]],       {x,0, 6}]


title: Write a table to a file

text: I want to compute a multidimensional table in Mathematica and write it to an external file. Here is a simple example. I have three lists `x`, `y`, `z` and the output include all possible combinations of sums. In the output file, I want 27 = 3x3x3 rows. Each row should have four values: `x`, `y`, `z` and `x+y+z`. Here is my code.               x = {1, 2, 3};     y = {4, 5, 6};     z = {7, 8, 9};     output = Table[x[[i]] + y[[j]] + z[[k]], {i, 1, 3}, {j, 1, 3}, {k, 1, 3}]     sfile = OpenWrite["C:\\Temp\\test.txt"]     For[i = 1, i <= 3, i++,      {For[j = 1, j <= 3, j++,        {For[k = 1, k <= 3, k++,          Write[sfile, x[[i]], y[[j]], z[[k]], output[[i, j, k]]]]}]}]     Close[sfile]      The problem is there is no space in the output file. So I get something like               14712     14813     14914     15713     15814      but I actually want               1 4 7 12     1 4 8 13     1 4 9 14     1 5 7 13     1 5 8 14      I need help to get the format above. I am quite new to Mathematica and don't know much about other functions. I am OK with any functions as long as they can generate the output I want. Thank you.


title: Generating a Sierpinski carpet

text: I am trying to draw a Sierpinski_carpet. I have code that works, but I think there is a more elegant way to do than my way. Maybe I couls use `Tuples` or `Permutations` or some similar function to simplify my code. ![enter image description here](http://i.stack.imgur.com/x3FRh.png)               f[{{x1_, y1_}, {x2_, y2_}}] := Map[Mean, {         {{{x1, x1, x1}, {y1, y1, y1}}, {{x1, x1, x2}, {y1, y1, y2}}},         {{{x1, x1, x1}, {y1, y1, y2}}, {{x1, x1, x2}, {y1, y2, y2}}},         {{{x1, x1, x1}, {y1, y2, y2}}, {{x1, x1, x2}, {y2, y2, y2}}},         {{{x1, x1, x2}, {y1, y1, y1}}, {{x1, x2, x2}, {y1, y1, y2}}},         {{{x1, x1, x2}, {y1, y2, y2}}, {{x1, x2, x2}, {y2, y2, y2}}},         {{{x1, x2, x2}, {y1, y1, y1}}, {{x2, x2, x2}, {y1, y1, y2}}},         {{{x1, x2, x2}, {y1, y1, y2}}, {{x2, x2, x2}, {y1, y2, y2}}},         {{{x1, x2, x2}, {y1, y2, y2}}, {{x2, x2, x2}, {y2, y2, y2}}}         }, {3}];     d = Nest[Join @@ f /@ # &, {{{0., 0.}, {1, 1}}}, 3];     Graphics[Rectangle @@@ d]     Clear["`*"]


title: Identifying the color in Image

text: This has mad me Crazy for a while Can any one please Help me solving this this is the Image that I am working on . Basically this image is made up of 98 different color patches 7 patch on each level and there are 14 such level I want to get the colour of each patch on each level in something like an array   like this                 colorPatch={{#524,#521,#124,#897,#365,#489,#546},   -->Level 1                 {#124,#524,#897,#365,#546,#514,#687},   -->Level2                 .                 .}                                   -->nth Level this is what i did till now               s = Import["http://i.stack.imgur.com/ubuPp.jpg"];     p = ImagePartition[s, {50, 69}]      ![enter image description here](http://i.stack.imgur.com/ubuPp.jpg)


title: Finding the minimum of a function

text: I asked this question Mark Minimum Value in DensityPlot. Another question has come up, or better said, a task: Find the minimum of a function. I haven't been able to write the needed code for that, because I want to find the minimum of the function `ueislexpl[epsilon, h, n1, n2]` with respect to `n1` and `n2`. But `ueislexpl` calls the function `eislminx2[epsilon_?NumericQ, n2_?NumericQ]`, which needs a value for `n2`. For tests one may use `epsilon = 0.1`. Is there a way of finding the minimum of `ueislexpl[epsilon, h, n1, n2]` with respect to `n1` and `n2`?               eislexpl[gamma_,epsilon_, n2_, x_] :=         28 (epsilon)^2 - 1 + ((-2 Log[E^(1/2) x])/x^2 + (27/10(gamma - epsilon))/x +          (10 epsilon^2 n2^(3/2))/x^(3/2))          eislminx2[gamma_,epsilon_?NumericQ, n2_?NumericQ] :=      (       minx = FindArgMin[{eislexpl[gamma,epsilon, n2, x], 0 < x}, x];       eislexpl[gamma,epsilon, n2, minx]     )          ueislexpl[gamma_,epsilon_, h_, n1_, n2_] :=        n1 (40  epsilon^2 - 1) + (1 -127/100 ) (1 + (n1 - 1) HeavisideTheta[1 - n1] -        (-1 + Exp[-(n1 - 1)]) HeavisideTheta[n1 - 1]) + n2  eislminx2[gamma,epsilon, n2] +        (h - n1 - n2) (28  epsilon^2 - 1)      The function `ueislexpl[gamma,epsilon, h, n1, n2]` describes the energy of a specific type of crystal morphology. It is used to predict specific growth modes. `h` is the total amount of deposited material `h=n1 + n2 + n3`. There are 3 different types of structures that can appear. A so called wetting layer, 3d-structures of kind 1 (3ds1) and 3d-structures of kind 2 (3ds2). `n1`is the amount of material comprising the wetting layer, `n2`is the amount of material comprising 3ds1, and whats left of `h`, `h-n1-n2=n3` is the material comprising 3ds2. In my simulations i usually use values of h within [0,8], meaning that values for n1 and n2 are too within [0,8]. I saw, that i oversimplified my functions, so i edited them, now there is one variable more, `gamma`, the surface energy per unit area, epsilon is the strain. My goal is to plot 2 different phase diagrams, one that shows the energy as a function of `h` and `epsilon` and the second one showing the energy as a function of `h`and `gamma`. The function `eislminx2[gamma,epsilon, n2]` determines the energetic minimum for a given set of `gamma`,`epsilon` and `n2` \- so i can't give constant values for them, they need to be variables. And the function that determines the energetic minimum of the system (minimum of ueislexpl[gamma,epsilon, h, n1, n2]) needs to be able to deal with that, is that possible? Determining the formal minimum of ueislexpl[gamma,epsilon, h, n1, n2], leaving some variables blank for the moment, as if i took the derivative of `y=a x^2 + x`, `dy/dx=2 a x + 1=0` \- even though i dont know the value of a i can formally take the derivative and later on plug in values for a and determine the minimum. Or is there another way?


title: grid lines in Manipulate plots are not showing up when first rendered?

text: I have a `Manipulate` within which the plot does not render completely initially:               Manipulate[      tick;      If [ bRefreshPlot, (          plot = ParametricPlot3D[ {u, v, u^2 + av (-1)^fn v^2}, {u, -1, 1}, {v, -1, 1} ] ;        bRefreshPlot = False )       , ] ;      plot      , Grid[{        { Slider[ Dynamic[av, ( av = # ; bRefreshPlot = True ; tick = Not[tick]) &] , {0.05, 2} ], Dynamic@av },        { SetterBar[Dynamic[fn, ( fn = # ; bRefreshPlot = True ; tick = Not[tick]) &] , Range[2] ] }      }]      , {{tick, False}, None}      , {{av, 1}, None}      , {{bRefreshPlot, True}, None}      , {plot, None}      , {{fn, 2}, None}      , TrackedSymbols :> {tick}      , ControlPlacement -> Left      ]      Initially, the `Manipulate` output looks like: ![initially](http://i.stack.imgur.com/j6Brq.png) but after clicking each of the `SetterBar` buttons in sequence (toggling from paraboloid to saddle and back), the grid lines then show up as in: ![with grid lines](http://i.stack.imgur.com/W22p5.png) I appear to be able to use '`SaveDefinitions` -> True' to work around the initial display oddity. However, this lack of grid lines also occurs after adjusting the slider. After an adjustment of the slider, the plot is first rendered without grid lines, but after doing the same two-click toggle of the `SetterBar` buttons, the plot shows up properly with the grid lines?


title: Removing outermost braces

text: I want to calculate the Kronecker product of several matrices in different orders. the number of these matrices must be changeable.               sysdim = 5;(* number of matrices I want to multiply. this number must be changeable*)          id = IdentityMatrix[sysdim];          sp = (* it's a matrix. It can be anything. It's size is sysdim by sysdim*)          Do[Subscript[variable, i] = ReplacePart[KroneckerProduct[id, id, id, id, id], {i ->     sp}], {i, 1, sysdim}]      By this I can get all different Kronecker products corresponding to different orderings. However, I want to change the number of these matrices as I wish. So, I thought the solution could be something like this:               KroneckerProduct[Table[id,{i,1,sysdim}]]      The problem here is that the `Table`command returns:               {id, id, id, id, id}      which `KroneckerProduct`is not happy with. I need to get rid of the outermost braces to get the `KroneckerProduct`to work.


title: Removing sublists containing elements from another list's sublist

text: Let there be two lists that have sublists:               a[] = {{1, 2}, {1, 2, 3}, {2, 3, 4, 4}, {3, 4, 4, 5}}      and               b[] = { {1, 2}, {4, 5, 6}}      I want to remove all those sublists in a[] that has elements contained in a sublist of b[]. So after removal I am expecting               a[] = {{2, 3, 4, 4}, {3, 4, 4, 5}}.      I am not able to reach specific elements in a sublist. I can use a For loop for this, but it will slow down my program, so I want suggestions on a better _Mathematica_ way of manipulating lists. ### Edit Sorry I guess my example was less than clear about what I am asking for. I want that any sublist in `a[]` that has all elements of any sublist from `b[]` shall be removed.


title: How can I get precisely the subgraph corresponding to a set of edges?

text: Consider the complete graph on 3 vertices. ![enter image description here](http://i.stack.imgur.com/DB15Z.png) Then, a method gives me a list of interesting edges, say $\\{(1,2),(2,3)\\}$. I want to get a subgraph of $g$ that corresponds to precisely the given edgelist. How can I do this? If I use `Subgraph[g,e]` with `e = {1 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 3}`, I get back the original graph. This does preserve the colors, but includes an extra edge, namely $(3,1)$ that I don't want. However, `Subgraph` does have a pattern as an argument. That might do the trick, but perhaps there's an easier way.


title: Showing special characters in text containing unicode

text: How does one conveniently convert a string like: "Ya no me burlar\:00e9 de la diabetes de Nick Jonas. Me lo guardar\:00e9 para cuando le corten la pierna. S\:00ed es que a\:00fan alguien lo recuerda, claro." to "Ya no me burlaré de la diabetes de Nick Jonas. Me lo guardaré para cuando le corten la pierna. Sí es que aún alguien lo recuerda, claro."? Certainly if I directly input the former, Mathematica autoformats it to the latter. If that text, however, comes to me whole from an outside source it is not automatically reformatted to show the special character. There is the ShowSpecialCharacters option in TextCell, for example, but that doesn't preserve the object as a String. I intend to parse a lot of text and would ideally prefer to avoid applying a function that first finds all substrings "\:", then converts to CharacterCode, then StringReplace's, etc.


title: How can I preserve the properties of edges of the original graph $g$ in a subgraph that doesn't include every edge of $g$?

text: _The closest question to the following I could find wasPreserving labels when using graph functions, but it doesn't seem to cover this._ Consider a graph `g` where every edge is associated with an EdgeStyle.               g = CompleteGraph[3, VertexLabels -> "Name", ImagePadding -> 10];     PropertyValue[{g, 1 \[UndirectedEdge] 2}, EdgeStyle] = Red;     PropertyValue[{g, 1 \[UndirectedEdge] 3}, EdgeStyle] = Green;     PropertyValue[{g, 2 \[UndirectedEdge] 3}, EdgeStyle] = Blue;      ![enter image description here](http://i.stack.imgur.com/SkPTD.png) I have a method that returns interesting subgraphs of `g`. Suppose $\\{ (1,2),(2,3) \\}$ is one such subgraph. How can I create a subgraph that preserves the colors associated with the edges? I can do               Graph[EdgeList[g], Options[g]]      which gives me the original graph, with the colors preserved. I can also simply do               Graph[EdgeList[g], Options[g, {EdgeStyle}]]      which also works as expected. However, this seems to be so because there's an EdgeStyle for precisely every edge in the options. If there is even one edge in options that is not included in the graph, this won't work. (By _not working_ , I mean something like "the command is not recognized". I don't exactly know how to describe what happens since I'm new to Mathematica.) An example of this unwanted behaviour is ![enter image description here](http://i.stack.imgur.com/dRmLn.png) Is there a way I can tell Mathematica "give me the options of the original graph, but only include a setting for each edge that is present in the new graph"? I really only care about EdgeStyle.


title: ctags for Mathematica files?

text: I alway use vi to edit Fortran files. I can use ctags to know which variables and functions I have already defined. Now I use vi to edit Mathematica *.m files. I tried to use ctags for *.m files, but it does not work. I have searched for the solution in Google but no luck. Could you give me some suggestions?


title: Aborts and beeps without error warning

text: I have a piece of code that generates a figure, performing a calculation to generate each pixel. At a certain resolution it runs fine, but after a high enough resolution it fails. Mathematica beeps (sounds more line a 'dong') and just stops after a few seconds with no error warnings. How can I run some diagnostics on my code to try and figure out the problem? I assume it's a memory problem, but when I use the MaxMemoryUsed[] command it was only ~20Mb which doesn't seem that much. The code is shown below. I adjust the parameter 'res'. Up to res=12 it runs fine but thereafter it fails.               Clear["Global`*"];     startTime = AbsoluteTime[];     f[{rx_, ry_}] :=       Module[{e1, e2, e3, d1, d2, d3, a, b, c, sol1, sol2, data, round,         rArray},       {e1, e2, e3} = # & /@ {{0, -1}, {Sqrt[3]/2, 1/2}, {-Sqrt[3]/2, 1/2}};       If[        Norm[{rx, ry} - e1] <= 1/3 || Norm[{rx, ry} - e2] <= 1/3 ||          Norm[{rx, ry} - e3] <= 1/3,        Null,        {d1, d2, d3} = # - {rx, ry} & /@ {e1, e2, e3};        {a, b, c} = Norm[#]^-3 & /@ {d1, d2, d3};        round = 0.000001;        sol1 =         If[0 <= ((b + c)^2 - a^2)/(4 b c) <= 1, 0,          Re[{x, y} /. Solve[             Round[a b (d2 - d1), round] Sin[{x, y}.(d1 - d2)]               + Round[b c (d3 - d2), round] Sin[{x, y}.(d2 - d3)]               + Round[a c (d3 - d1), round] Sin[{x, y}.(d1 - d3)]              == 0, {x, y}]]];        sol2 =          Sqrt[a^2 + b^2 + c^2 + 2 a b Cos[#.(d1 - d2)] +              2 b c Cos[#.(d2 - d3)] + 2 a c Cos[#.(d1 - d3)]] & /@ sol1;        Min[sol2]        ]       ]     res = 20;     rArray = Table[{rx, ry}, {rx, -Sqrt[3]/2, Sqrt[3]/2,          Sqrt[3]/res}, {ry, 3/4, -3/4, -3/(2 res)}];     diagram = Map[f, rArray, {2}];     ArrayPlot[diagram, ColorFunction -> "Rainbow",       ColorRules -> {0 -> White, Null -> Gray}]     endTime = AbsoluteTime[] - startTime


title: Finding elements from a sparse matrix

text: I am dealing sparse matrices of very large dimensions. I need to locate the positive and negative elements of the matrices and make lists of their corresponding positions. Of course I can write a program which scans every element and gives the output. But is it possible to do it in a neater way? for instance, to make a list of `1`'s, I used `Position[S,1]`, but in future I need to get a list of positions of all entries which are `>0` for example. As suggested, I am giving an example of one of the smallest lists. For instance, I want to make a list of positions of elements which are `>0`.               S={{1,0,0,0,1,0,0,0,0,-1,0,0,0,-1,0,0,0,-1,0,0,0,0,-1,0,0,0,0},        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},              {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},        {1,0,0,0,2,0,0,0,0,-1,0,0,0,-1,0,0,0,-1,0,0,0,0,-1,0,0,0,0},        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},        {-1,0,0,0,-1,0,0,0,0,2,0,0,0,2,0,0,0,1,0,0,0,0,-1,0,0,0,0},               {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},               {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},        {-1,0,0,0,-1,0,0,0,0,2,0,0,0,2,0,0,0,1,0,0,0,0,-1,0,0,0,0},              {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},               {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},        {-1,0,0,0,-1,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,-1,0,0,0,0},        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1},        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},                 {-1,0,0,0,-1,0,0,0,0,-1,0,0,0,-1,0,0,0,-1,1,0,0,0,2,0,0,0,1},        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1}};


title: Why do Solve, NSolve, and FindRoot all fail on this simple, solvable actuarial equation?

text: If we express conditional mortality as a vector of annual probabilities of death, like so               qx1={0.04772, 0.05854, 0.07519, 0.09659, 0.11762, 0.13904, 0.16124,     0.18363, 0.2041, 0.22319, 0.24276, 0.262, 0.27897, 0.29458, 0.31044,     0.32691, 0.34597, 0.36573, 0.38348, 0.39799, 0.40855, 0.41447,     0.41774, 0.42266, 0.43064, 0.43913, 0.44417, 0.44802, 0.45, 0.45};      we can compute the associated survival vector with               lx1=Drop[FoldList[#1 (1 + #2) &, 1, -qx1], -1]      and we can find the median life expectancy of this population with               Length[Select[lx1, # >= .5 &]]      We can combine these two equations into a single function that translates the conditional mortality curve directly into a median life expectancy. It would look like               medianLEfromQx[qx_]:=Length[Select[Drop[FoldList[#1 (1 + #2) &, 1, -qx], -1], # >= .5 &]]      And using the sample data above, we see that the median life expectancy for the population is 7 years. If we want to see the implications of reducing annual mortality by 10%, we can ask               medianLEfromQx[.9*qx1]      And we get an answer of 8 years. Fine. Here lies the problem -- I can't get Mathematica to solve for that multiplier given a desired LE.               Solve[medianLEfromQx[x*qx1]==8,x]      doesn't work (returning an empty set)               NSolve[medianLEfromQx[x*qx1]==8,x]      doesn't work, also returning an empty set, and               FindRoot[medianLEfromQx[x*qx1]==8,{x,1}]      doesn't work either, with the error message that "The Function value {False} is not a list of numbers with dimensions {1} at {x} = {1.}" What am I doing wrong here?


title: A fast way to compute arrays avoiding If or Which

text: I found out that if I have to calculate huge arrays with most of the elements being zero( let's say each row has 10000 elements and only 8 are non zero) and the non zero elements' positions being given by an If or a Which, the most straight forward way to go is:               Table[...,{i,1,nn},{j,list[i]}]      instead of               Table[If[MemberQ[list[i],j]==True,...],{i,1,nn},{j,1,nn}]      But the problem is that, list[i] does not fix the position in the array, but only the value, the positions being [1,Length[list[i]]]. Let us ilustrate this with an easy example: Slow way:               A = Table[     Which[MemberQ[{1, 3, 5}, j] == True, 2*i + j, True, 0], {i, 1, 2}, {j,      5}] // MatrixForm     (*(3    0   5   0   7        5    0   7   0   9)*)      Fast way:               B=Table[2*i + j, {i, 1, 2}, {j, {1, 3, 5}}] // MatrixForm          (*(3    5   7        5    7   9)*)      So, I would like to get the matrix A but doing it B way somehow. (The condition for j, is an example, but in the real code is a rather complicated condition that varies with i.) Does anybody see how this could be done? Thanks


title: How can I convert a plot to pdf or eps without errors?

text: _Mathematica_ 9.0.1, Linux. I try to save a plot as a pdf. I tried four different options. In each case some errors appeared as blank space ![image 1](http://i.stack.imgur.com/DH4aL.jpg) ( http://yadi.sk/d/h1koyDci4z3rc ). I also tried to save as eps. Another problem appeared -- there is no half letter on the Labels: ![image 2](http://i.stack.imgur.com/1VaSg.jpg) (see here http://yadi.sk/d/OBRDmp3z4z42U ). The same figures are saved very well in _Mathematica_ 7 without an error. Is it possible to solve this problem?


title: Does Graphics`Mesh`SimplePolygonQ[] work for you?

text: `Graphics`Mesh`SimplePolygonQ` is an undocumented function. I'm using Mathematica 7, and when I try:               Graphics`Mesh`SimplePolygonQ[{{1, 0}, {0, Sqrt[3]}, {-1, 0}}]       I just get: > Graphics`Mesh`SimplePolygonQ[{{1, 0}, {0, $\sqrt{3}$, {-1, 0}}] I posted a question and a respondent successfully used this function in the code of her answer. Does anyone else have trouble using this function? Any ideas why it won't work for me?


title: How to paste multiple expression using PasteButton?

text: Is there a way to paste multiple expressions into notebook using `PasteButton`? For example, I want to do               PasteButton["Inputs", {Defer@(a=1;), Defer@(b=2;)}]      I want the expressions to be shown in multiple lines just as if we are typing them in, not as a list.


title: Poincaré section for 3BP

text: I try to plot the Poincaré section for the 3BP i use the following code that works very well:               Needs["DifferentialEquations`NDSolveProblems`"];     Needs["DifferentialEquations`NDSolveUtilities`"];     Clear["Global`*"]     \[Mu]=0.001;     SuperStar[\[Mu]]=1-\[Mu];     Subscript[r1, 1]=Sqrt[(Subscript[y1, 1][t]+\[Mu])^2+Subscript[y1, 2][t]^2];     Subscript[r1, 2]=Sqrt[(Subscript[y1, 1][t]-SuperStar[\[Mu]])^2+Subscript[y1, 2][t]^2];     a=0.298;     b=0.24;     c=0.10;     d=0.40;     tin=0.0;     tfin=60.;     eqns1={{Derivative[1][Subscript[y1, 1]][t]==Subscript[y1, 3][t],Subscript[y1, 1][0]==a},     {Derivative[1][Subscript[y1, 2]][t]==Subscript[y1, 4][t],Subscript[y1, 2][0]==b},     {Derivative[1][Subscript[y1, 3]][t]==2 Subscript[y1, 4][t]+Subscript[y1, 1][t]-(SuperStar[\[Mu]] (Subscript[y1, 1][t]+\[Mu]))/     \!\(\*SubsuperscriptBox[\(r1\), \(1\), \(3\)]\)-(\[Mu] (Subscript[y1, 1][t]-SuperStar[\[Mu]]))/     \!\(\*SubsuperscriptBox[\(r1\), \(2\), \(3\)]\),Subscript[y1, 3][0]==c},     {Derivative[1][Subscript[y1, 4]][t]==-2 Subscript[y1, 3][t]+Subscript[y1, 2][t]-(SuperStar[\[Mu]] Subscript[y1, 2][t])/     \!\(\*SubsuperscriptBox[\(r1\), \(1\), \(3\)]\)-(\[Mu] Subscript[y1, 2][t])/     \!\(\*SubsuperscriptBox[\(r1\), \(2\), \(3\)]\),Subscript[y1, 4][0]==d}};     Orbit=NDSolve[     eqns1,     {Subscript[y1, 1],Subscript[y1, 2],Subscript[y1, 3],Subscript[y1, 4]},{t,tin,tfin},     Method->{StiffnessSwitching,Method->{ExplicitRungeKutta,Automatic}},     AccuracyGoal->8,PrecisionGoal->8,MaxSteps->10000];          myx[t_]:=Evaluate[Subscript[y1, 1][t]/. Orbit];     myy[t_]:=Evaluate[Subscript[y1, 2][t]/. Orbit];          myxplot=Plot[myx[t],{t,0,tfin},AxesLabel->{"time","x"}]     myyplot=Plot[myy[t],{t,0,tfin},AxesLabel->{"time","y"}]          pp1=ParametricPlot[     Evaluate[{Subscript[y1, 1][t],Subscript[y1, 2][t]}/. Orbit],{t,0,tfin},     AxesLabel->{"x","y"},PlotPoints->150]          (*pp2=ParametricPlot3D[     Evaluate[{Subscript[y1, 1][t],Subscript[y1, 2][t],Subscript[y1, 4][t]}/.\[VeryThinSpace]Orbit],{t,0,tfin},     AxesLabel\[Rule]{"x","y","vy"},PlotPoints\[Rule]5000,     DisplayFunction\[Rule]Identity]*)          pp2=ParametricPlot3D[     Evaluate[{Subscript[y1, 1][t],Subscript[y1, 2][t],Subscript[y1, 4][t]}/.Orbit],{t,0,tfin},AxesLabel->{"x","y","vy"},     PlotPoints->4000,MeshFunctions->{#3&},Mesh->{{0}},     MeshStyle->{Directive[PointSize[Large],Red]},     BoxRatios->{1,1,1},DisplayFunction->Identity]          pl1=Graphics3D[     {Green,Opacity[0.9],Polygon[{{-3,-3,0},{-3,3,0},{3,3,0},{3,-3,0}}]},     DisplayFunction->Identity];          Show[pp2,pl1,DisplayFunction->$DisplayFunction,ImageSize->{500,500}]      If you have some problem with subscript You can convert it in standard form, anyway the problem is in the following part of the code (thanks a lot to Belisarius for his very good tips! intersection between function and plane ) that show a section that is different from the one plotted in the last `Show` command. In fact the following command make a section on the, for istance, y-axis (the `y1_2[t]` variable) but i want the section on the z-axis (the `y1_4[t]` variable):               getOneCluster[pts_List,maxDist_?NumericQ]:=(*Returns a cluster*)Module[{f},f=Nearest[pts];     FixedPoint[Union@Flatten[f[#,{Infinity,maxDist}]&/@#,1]&,{First@pts}]]     clusters[data_]:=Module[{f,dist},(*Some Characteristic Distance,assuming no isolated points*)f=Nearest[data];     dist=3 Max[EuclideanDistance[Last@f[#,2],#]&/@data];     Flatten[Reap[NestWhile[Complement[#,Sow@getOneCluster[#,dist]]&,data,#!={}&]][[2]],1]]          p1=ParametricPlot3D[Evaluate[{Subscript[y1, 1][t],Subscript[y1, 2][t],Subscript[y1, 4][t]}/.Orbit],{t,0,tfin},MeshFunctions->{#1&},Mesh->{{0}},PlotStyle->None,MeshStyle->Red];     gc=Cases[p1,GraphicsComplex[__],Infinity];     data=First[(Normal@gc)[[1,2,1,2;;]]/.Point->Sequence][[All,2;;]];     clusters[data];     Show[ListPlot@clusters@data]      Can someone help me to modify this last part of the program to find the correct intersection.


title: RandomSample Bug?

text: ![Screen Shot of my Mathematica Commands](http://i.stack.imgur.com/focjn.png) I was using RandomSample with very skewed weights. I am asking for a random sample of 6 numbers 1 through 100 without replacement. In the screen shown, the weights for 1 through 6 are 100 000, with all others less then 1; hence, the RandomSample should return numbers 1 through 6 is a random order very very often. But it does not. I have copied and pasted the commands shown. Am I missing something? Or am I misunderstanding the RandomSample function? Or is this actually a bug?


title: Fit data with linear combinations of Cos and Sin

text: Recall that if $f$ is a piecewise continuous function on the interval $[-\pi, \pi]$, then the Fourier series of $f$ is $$f(x) = \sum_{n=0}^{\infty} (a_n \cos(nx) + b_n \sin(nx)).$$ See for example, this page. Suppose that I have the following _discrete_ data stored in the List called `list`:               list = {{-6.28319,27.},     {-6.18319,29.9378},     {-6.08319,31.4545},     {-5.98319,31.4815},     {-5.88319,30.054},     {-5.78319,27.3079},     {-5.68319,23.4676},     {-5.58319,18.8269},     {-5.48319,13.7254},     {-5.38319,8.52035},     {-5.28319,3.5588},     {-5.18319,-0.849714},     {-5.08319,-4.45626},     {-4.98319,-7.09014},     {-4.88319,-8.66947},     {-4.78319,-9.20395},     {-4.68319,-8.78975},     {-4.58319,-7.59713},     {-4.48319,-5.85203},     {-4.38319,-3.81336},     {-4.28319,-1.7481},     {-4.18319,0.0934504},     {-4.08319,1.5002},     {-3.98319,2.31839},     {-3.88319,2.46391},     {-3.78319,1.92767},     {-3.68319,0.77379},     {-3.58319,-0.86928},     {-3.48319,-2.82358},     {-3.38319,-4.88107},     {-3.28319,-6.82563},     {-3.18319,-8.45569},     {-3.08319,-9.60509},     {-2.98319,-10.1604},     {-2.88319,-10.0728},     {-2.78319,-9.36378},     {-2.68319,-8.12337},     {-2.58319,-6.50193},     {-2.48319,-4.69555},     {-2.38319,-2.92666},     {-2.28319,-1.42171},     {-2.18319,-0.387886},     {-2.08319,0.00884309},     {-1.98319,-0.337699},     {-1.88319,-1.46055},     {-1.78319,-3.31281},     {-1.68319,-5.76826},     {-1.58319,-8.62934},     {-1.48319,-11.6421},     {-1.38319,-14.5166},     {-1.28319,-16.9518},     {-1.18319,-18.6617},     {-1.08319,-19.401},     {-0.983185,-18.9886},     {-0.883185,-17.3258},     {-0.783185,-14.4076},     {-0.683185,-10.327},     {-0.583185,-5.27092},     {-0.483185,0.492234},     {-0.383185,6.63133},     {-0.283185,12.7772},     {-0.183185,18.5507},     {-0.0831853,23.5918},     {0.0168147,27.5873},     {0.116815,30.2954},     {0.216815,31.5636},     {0.316815,31.3407},     {0.416815,29.6794},     {0.516815,26.7315},     {0.616815,22.7344},     {0.716815,17.9917},     {0.816815,12.8477},     {0.916815,7.66002},     {1.01681,2.7712},     {1.11681,-1.51793},     {1.21681,-4.97054},     {1.31681,-7.43032},     {1.41681,-8.83083},     {1.51681,-9.19685},     {1.61681,-8.63808},     {1.71681,-7.33557},     {1.81681,-5.52246},     {1.91681,-3.4608},     {2.01681,-1.41646},     {2.11681,0.365385},     {2.21681,1.68215},     {2.31681,2.3911},     {2.41681,2.42056},     {2.51681,1.77408},     {2.61681,0.527401},     {2.71681,-1.18153},     {2.81681,-3.16824},     {2.91681,-5.22173},     {3.01681,-7.12679},     {3.11681,-8.6864},     {3.21681,-9.74219},     {3.31681,-10.1909},     {3.41681,-9.99543},     {3.51681,-9.18896},     {3.61681,-7.87251},     {3.71681,-6.20529},     {3.81681,-4.38926},     {3.91681,-2.64914},     {4.01681,-1.20978},     {4.11681,-0.272896},     {4.21681,0.00442148},     {4.31681,-0.472474},     {4.41681,-1.72346},     {4.51681,-3.68806},     {4.61681,-6.22729},     {4.71681,-9.13288},     {4.81681,-12.1433},     {4.91681,-14.9649},     {5.01681,-17.2974},     {5.11681,-18.8597},     {5.21681,-19.416},     {5.31681,-18.7978},     {5.41681,-16.9216},     {5.51681,-13.7988},     {5.61681,-9.53872},     {5.71681,-4.34296},     {5.81681,1.50794},     {5.91681,7.67462},     {6.01681,13.7843},     {6.11681,19.4588},     {6.21681,24.3444}};      Plotting `list` using `ListPlot`, I see:               ListPlot[list, PlotRange -> {-25, 35}, Joined -> True,       PlotStyle -> Directive[Red, Thickness[0.015]]]      ![ListPlot](http://i.stack.imgur.com/wbtLG.png) I know that I can use the `Fit` function to "find a least-squares fit to a list of data as a linear combination of the functions _funs_ of variables _vars_." However, it seems that I can only have a **_single_** coefficient. For example, in the following code, I do three different types of fits:   1. In `cosfit`, I fit `list` to `Cos[n*x]` functions: `cosfit = Fit[list, Table[Cos[n*x], {n, 0, end}], x];`   2. In `sinfit`, I fit `list` to `Sin[n*x]` functions: `sinfit = Fit[list, Table[Sin[n*x], {n, 0, end}], x];`   3. In `cossinfit`, I fit `list` to `Cos[n*x] + Sin[n*x]` functions: `Fit[list, Table[Cos[n*x] + Sin[n*x], {n, 0, end}], x];` However, in the resulting fits, each function has only a single coefficient. For example, the fit of `list` to `Cos[n*x] + Sin[n*x]` (i.e., in `cossinfit`) becomes: $$c_0(\cos[0x] + \sin[0x]) + c_1(\cos[1x] + \sin[1x]) + c_2(\cos[2x] + \sin[2x]) + \ldots,$$ rather than $$a_0\cos[0x] + b_0\sin[0x] + a_1\cos[1x] + b_1\sin[1x] + a_2\cos[2x] + b_2\sin[2x] + \ldots.$$ **My question is,** in the following code, how do I fit to _both_ $\cos$ _and_ $\sin$ (with separate coefficients in front of each $\cos$ _or_ $\sin$ term)?               Grid[      Table[            cosfit = Fit[list, Table[Cos[n*x], {n, 0, end}], x];       sinfit = Fit[list, Table[Sin[n*x], {n, 0, end}], x];       cossinfit = Fit[list, Table[Cos[n*x] + Sin[n*x], {n, 0, end}], x];       {        Show[{          ListPlot[list, PlotRange -> All, Joined -> True,            PlotStyle -> Directive[Red, Thickness[0.015]]],          Plot[cosfit, {x, list[[1, 1]], list[[-1, 1]]}, PlotRange -> All,            PlotStyle -> Black]          }, PlotRange -> {-25, 35}, ImageSize -> 350,          PlotLabel -> "Cos Fit: n = " <> "0.." <> ToString[end]],             Show[{          ListPlot[list, PlotRange -> All, Joined -> True,            PlotStyle -> Directive[Red, Thickness[0.015]]],          Plot[sinfit, {x, list[[1, 1]], list[[-1, 1]]}, PlotRange -> All,            PlotStyle -> Black]          }, PlotRange -> {-25, 35}, ImageSize -> 350,          PlotLabel -> "Sin Fit: n = " <> "0.." <> ToString[end]],             Show[{          ListPlot[list, PlotRange -> All, Joined -> True,            PlotStyle -> Directive[Red, Thickness[0.015]]],          Plot[cossinfit, {x, list[[1, 1]], list[[-1, 1]]},            PlotRange -> All, PlotStyle -> Black]          }, PlotRange -> {-25, 35}, ImageSize -> 350,          PlotLabel -> "Cos/Sin Fit: n = " <> "0.." <> ToString[end]]        }            , {end, {1, 2, 5, 20, 25, 30}}]      ]      which gives this output: ![FitOutput](http://i.stack.imgur.com/gAlyw.png) Is using `Fit` the way to go, or should I use some other built-in Mathematica function? (In actuality, `list` was generated by taking discrete points from the function:               9 Cos[x] + 9 Cos[2 x] + 9 Cos[3 x] + 6 Sin[x] + 6 Sin[2 x] + 6 Sin[3 x]      which I chose as a minimal working example. But in general, I will not know the functional form of the data in `list`, since in general I will obtain `list` from (noisy) empirical measurements.)


title: Autocomplete from inside Module and SetDelayed

text: Autocomplete in Mathematica 9 offers suggestions from inside SetDelayed and Module. For example, after running:               func[thing1_, thing2_] := thing1 + thing2;     Module[{thing3},      thing3 = 10;      thing3 + 4     ]      autocomplete will offer `thing1`, `thing2`, and `thing3` as suggestions. Since they are intended to be local, this gets in the way. Is there a way around this?


title: How to plot a polygon and a line on the same graph?

text: I have to plot the line 1 + 4 t, 2 + 5 t, 1 + 12 t and the polygon with points {2, 3, 4}, {1, 4, 5}, {3, 3, 3} in the same graph to see if the line goes through the polygon. I was able to get them to plot separately but I cannot get them to plot together. This is what I typed in:               pic1 = ParametricPlot3D[{1 + 4 t, 2 + 5 t, 1 + 12 t}, {t, 0, 12}];     pic2 = p = Polygon[{{2, 3, 4}, {1, 4, 5}, {3, 3, 3}}]     {Graphics3D[{Pink, p}]}     Show[pic1, pic2, PlotRange -> Automatic]      But I get the error: > Coordinate {Skeleton[3]} should be a triple of numbers, or a Scaled form. How do I fix this?


title: DensityHistogram label/display values in Mathematica 8

text: I'm trying to make a `DensityHistogram` in _Mathematica 8_ that overlays the histogram values for each location. What I want is for the value of each square to be displayed over it always (i.e. not in the `StatusArea` or as a `Tooltip`). For instance, if you run this code in _Mathematica_ , one of the squares will have a value of 23, and I'd like that value overlaid on that square, and then the same for all the other non-zero values (I don't need a bunch of 0's).               a = {{1.6, 314.1592}, {0.8, 63.6172}, {0.4, 113.0973}, {1, 19.6349}, {1, 19.6349},           {1, 50.2654}, {1, 490.8738}, {1, 19.6349}, {0.045, 17.5}, {0.3, 80}, {0.06, 120},           {1, 100}, {1,78.5398}, {0.06, 120}, {1, 7.0685}, {0.33, 126.6768}, {1, 369.8361},           {0.0008, 0.09}, {1, 1134.1149}, {0.06, 64}, {0.08, 120}, {1, 113.0973}, {0.19, 600},          {1, 283.5287}, {0.00217,14}, {1, 201.0619}, {0.64, 283.5287}, {2, 1520.5308}, {60, 31.4159},          {0.3, 10}, {1, 201.0619}, {1, 283.5287}, {2, 12.5663}, {1, 506.7074}, {0.35, 176.7145},          {0.05, 1.1309}, {2, 1520.5308}, {0.7, 28.2743}, {1, 49}, {1, 100}, {1, 706.8583},          {1, 706.8583}, {8, 3848.451}, {1, 50.2654}, {1, 50.2654}, {1, 314.1592}, {1, 314.1592},          {1, 314.1592}, {1, 314.1592}, {1, 1140.0918}, {2, 314.1592}, {2, 314.1592},           {1.5, 314.1592}, {1, 23.7582}, {1, 15.2053}, {0.02, 0.415}, {1.5, 314.1592},           {1, 254.469}, {0.02, 0.415}, {1, 346.3605}, {0.5, 254.469}, {1, 95.0331}}          DensityHistogram[ a, {{{.0001, .001, .01, .1, 1, 10, 100}},                            {{.01, .1, 1, 10, 100, 1000, 10000}}}, ScalingFunctions -> {"Log", "Log"},                       ColorFunction -> (ColorData["SolarColors"][1 - #] &),                        ChartBaseStyle -> EdgeForm[Thin], BaseStyle -> {FontFamily -> "Arial"},                       Method -> {"DistributionAxes" -> "Histogram"},                       Ticks -> {                         Table[{10^k, Superscript[10, k]}, {k, -4, 4}],                          Table[{10^k, Superscript[10, k]}, {k, -2, 4}]},                        Frame -> {True, True, False, False}, Mesh -> True, ImageSize -> 600,                        LabelingFunction -> (Placed[#1, Above] &)]      I'm not sure if I'm using `LabelingFunction` correctly, probably not. I'd also like to see the relevant values on the axes histograms, if possible.


title: Equation values into list

text: Suppose I have a function say $f=x^2$. What I would like is a list (or even better, a list with a grid) which resembles `{{1,1},{2,4},{3,9}, ...}`. Ideally one should be able to specify the starting point, end point and step interval between values. This seem like such a simple idea I don't know why I am struggling with it...


title: Snapping two "Drawing Tools" objects together while decorating an image

text: I'm using "Drawing Tools" to decorate an imported image (a TIFF file). I need to create a set of regularly spaced parallel lines, and my solution for doing this is to create a pair of parallel lines (we have an LHS line and an RHS line), copy this pair, superimpose the copied LHS line on the previous RHS line, and then delete the previous RHS line. Doing this repeatedly gives me an array of parallel lines, which are all a fixed distance apart. My question is: while selecting multiple graphics primitives (lines here) how do I snap one primitive to a previously placed primitive decorating the image similar to how one can do this in Adobe Illustrator? Also, is there an easier way for me to automatically generate a set of parallel lines which can be translated / stretched apart using my mouse?


title: Calculating the Lyapunov Exponent/Spectrum for the Duffing Oscillator

text: Some fellow students and I are trying to calculate and plot the Lyapunov spectrum for the Duffing oscillator (currently a test approach). Each of us has _Mathematica_ knowledge based purely on past 'need to know' experiences and are having troubles with getting the following code to work.   Can anyone point out where we have gone wrong (probably in multiple places)?               solDuffingOscillator[A_, B_, C_, x0_, x1_, maxt_] :=         NDSolve[{D[x[t], {t, 2}] + 2 A D[x[t], {t, 1}] + B x[t] + x[t]^3 ==            C Cos[ t], x[0] == x0, x'[0] == x1},         {x[t], x'[t]},         {t, 0, maxt},          MaxSteps -> Infinity]        * * *               Manipulate[        Module[{sol1, sol2, X0, V0, X1, V1},         sol1 = solDuffingOscillator[A, B, C, x0, v0, tlim];         X0[t_] = First[x[t] /. sol];         V0[t_] = First[x'[t] /. sol1];              sol2[t_] =           solDuffingOscillator[A, B, C, (X0[t] + dx), (V0[t]), tlim];         X1[t_] = First[x[t] /. sol2[t]];         V1[t_] = First[x'[t] /. sol2[t]];              d = First[Evaluate[{X0}]] - First[Evaluate[{X1}]];         L = 1/dt*Log[d/dx];              Tbl1 = Table[{t, d}, {t, dt, tlim, dt}];         ListPlot[Tbl1, PlotRange -> {{0, tlim }, {-2 Pi, 2 Pi}},          ImageSize -> {1200, 800}]         ],        {{A, 0.5, "A"}, 0, 10, 0.001, Appearance -> "Labeled"},        {{B, -8.54, "B"}, -10, 0, 0.01, Appearance -> "Labeled"},       {{C, 14, "C"}, 0, 20, 0.05, Appearance -> "Labeled"},        {{dt, 1, "dt"}, 0.001, 1, 0.0001, Appearance -> "Labeled"},        {{x0, 1, "x0"}, -2, 2, 0.01, Appearance -> "Labeled"},        {{v0, 0, "v0"}, -1, 1, 0.0001, Appearance -> "Labeled"},        {{dx, 0.5, "dx"}, -0.5, 0.5, 0.001, Appearance -> "Labeled"},        {{tlim, 1000, "t Cutoff"}, 100, 4000, 5, Appearance -> "Labeled"}]


title: DSolve will not apply assumption `m ∈ Integers`

text: I am trying to solve a linear second order ODE using `DSolve` which involves an arbitrary integer `m`. `DSolve` gives me a solution when I set `m` to a particular integer (I have tried several, including negative/positive, even/odd, and `0`). When I try to use the assumption `m ∈ Integers` and ask `DSolve` to solve this ODE for an arbitrary integer `m`, it does not work. Here is the input:               $Assumptions = m ∈ Integers     testk =        0 == -16 c m^2 Cos[x] k[x] - c (-7 Sin[x] + Sin[3x]) k'[x]             + Cos[x] Sin[x]^2 (m^2 (3 + 4 m Cos[x] + Cos[2 x]) Tan[x/2]^(2 m) + 4 c k''[x])          DSolve[ testk, k[x], x]      > >     DSolve[ 0 == -16 c m^2 Cos[x] k[x] - c (-7 Sin[x] + Sin[3 x]) k'[x] >                   + Cos[x] Sin[x]^2 (m^2 (3 + 4 m Cos[x] + Cos[2 x]) > Tan[x/2]^(2 m) >                   + 4 c k''[x], k[x], x] >   Update: I have realized that the problem is that `DSolve` does not apply any of the global assumptions. Does anyone know how I can make `DSolve` apply the assumption that `m ∈ Integers`? I have tried using `Assuming[,]` to set the assumptions locally but that did not work either.


title: How do I get the length of held list without evaluating the list?

text: I used `Extract` with `Hold` to retrieve a sublist containing expressions I didn't want evaluating, _e.g._               foo = Extract[OwnValues[test], {1, 2}, Hold]     (* Hold[{expr1, expr2, expr3}] *)      I'm sorry to ask such a trivial question, but, how do I get the length of that list? Obviously `Length@foo` returns `1` because the top-level head is `Hold`. But attempting to access the lower levels seems to cause evaluation one way or another. What technique am I missing?


title: How can I find a root of my transcendental equation near a certain point?

text: What function could I use to solve this equation for x:               E^(-x^2) = 1 - Cos[x]      I tried `Solve`, `Reduce`, `Root`... None of them worked. `FindInstance` gave me an imaginary answer. Adding `Reals`, gave me:               {{x -> Root[{-1 + E^-#1^2 + Cos[#1] &, -6.28318531096301494721675292506}]}}      but this is not the answer I wanted, which would be between 0 and 1. How would I solve this? As a side note, WolframAlpha got it.


title: If doesn't compile if its output is the output of Compile?

text: The smallest sample I can find to reproduce this problem is:               test = Compile[{}, If[True, 1]];     << CompiledFunctionTools`     CompilePrint@test      > >     ………… >      1    R0 = MainEvaluate[ Function[{}, If[True, 1]][ ]] >      2    Return >   The problem disappears when the `If[]` is followed by a semicolon:               test = Compile[{}, If[True, 1];];     CompilePrint@test      > >     ………… >     1     if[ !B0] goto 3 >     2     goto 3 >     3     Return >   or enclosed by a redundant `Do[]`:               test = Compile[{}, Do[If[True, 1], {1}]];     CompilePrint@test      > >     ………… >     1   I1 = I0 >     2   I3 = I2 >     3   goto 6 >     4   if[ !B0] goto 6 >     5   goto 6 >     6   if[ ++ I3 < I1] goto 4 >     7   Return >   while a redundant `Table[]` won't help:               test = Compile[{}, Table[If[True, 1], {1}]];     CompilePrint@test      > >     ………… >   >     1   I1 = I0 >     2   I4 = I3 >     3   T(R1)0 = Table[ I1] >     4   I2 = I3 >     5   goto 8 >     6   R1 = MainEvaluate[ Function[{}, If[True, 1]][ ]] >     7   Element[ T(R1)0, I4] = R1 >     8   if[ ++ I2 < I1] goto 6 >     9   Return >   This phenomenon may lead to a total failure of compilation when codes become more complicated:               ie = 200;     ez = ConstantArray[0., {ie + 1}];     hy = ConstantArray[0., {ie}];          f1 = Compile[{{steps}},         Module[{ie = ie, ez = ez, hy = hy},          Do[ez[[2 ;; ie]] = ez[[2 ;; ie]] + (hy[[2 ;; ie]] - hy[[1 ;; ie - 1]]);          ez[[1]] = Sin[n/10];          hy[[1 ;; ie]] = hy[[1 ;; ie]] + (ez[[2 ;; ie + 1]] - ez[[1 ;; ie]]), {n, steps}];         ez]];          f2 = Compile[{{steps, _Integer}, {test, True | False}},         Module[{ie = ie, ez = ez, hy = hy},          Do[ez[[2 ;; ie]] = ez[[2 ;; ie]] + (hy[[2 ;; ie]] - hy[[1 ;; ie - 1]]);          ez[[1]] = Sin[n/10];          hy[[1 ;; ie]] = hy[[1 ;; ie]] + (ez[[2 ;; ie + 1]] - ez[[1 ;; ie]]), {n, steps}];         If[test, ez]]];          f1[1500]; // AbsoluteTiming      > >     {0.0250000, Null} >                 f2[1500, True]; // AbsoluteTiming      > _Warnings……_ >   >   >     {0.5730000, Null} >   So, as the title said, `If` won't compile when its output is the output of `Compile`? Of course it can be easily circumvented, but I wonder if there's a universal rule behind this, or it's just another unreasonable behavior of `Compile`?


title: Manipulate (Linux version of Mathematica)

text: I'm runnning _Mathematica_ 9 on Ubuntu 11.10. After installing CDF player I still have problem (most of time) with `Manipulate`. Only way I'm able to change value of a parameter is by manually entering a value into into an edit field (dragging the slider or pushing buttons doesn't work). Can anyone suggest what I'm doing wrong? (Even simple `Manipulate[x, {x, 1, 5}]` doesn't work properly.)


title: Measuring curve length on a binarized image

text: With the help of almighty Mathematica 9, I got from this ![enter image description here](http://i.stack.imgur.com/79l19.jpg) To this: ![enter image description here](http://i.stack.imgur.com/rwDwl.png) with this code:               MorphologicalBinarize[       Import["http://i.stack.imgur.com/79l19.jpg"]~        ColorConvert~"Grayscale"];     Binarize[LaplacianGaussianFilter[%, 10]];     CommonestFilter[MaxFilter[DeleteSmallComponents[%], 2.3], 10];     SelectComponents[MorphologicalComponents[%], "Length", -1] // Image;     Pruning[Thinning[%, Padding -> 1], Padding -> 1]      I'm sure the code could be shorter and is perhaps in places redundant, but that's not why I'm posting here, as because now, I'm interested in measuring the length of the curve that I got. I wanted to create a tool to test this theory whenever would I want so. I couldn't find a way - I thought I was close when I transposed `ImageData` position on ListPlot, alas, I swiftly got lost there. I am very new to this wonderful tool and am learning it by trial and error. I'd appreciate any form of help.


title: StringReplace, ReplaceAll and Rule interact in a bizarre way

text: I have the following pair of things:               ClearAll[foo, labeledFoo];          labeledFoo = {"FooBarBazQuux", foo};      This works like you'd expect:               labeledFoo /. hdr_String :>        StringReplace[hdr, l_?LowerCaseQ ~~ U_?UpperCaseQ :> l <> " " <> U]          (* {"Foo Bar Baz Quux", foo} *)        So does this:               labeledFoo /. hdr_String :>        StringReplace[hdr, l_?LowerCaseQ ~~ U_?UpperCaseQ :> l <> " " <> U] /.         {hdr_String, x_} :> (hdr -> x)          (* "Foo Bar Baz Quux" -> foo *)      Heck, even this works:               labeledFoo /. {hdr_String, x_} :> (Rule @@ {StringReplace[hdr,        l_?LowerCaseQ ~~ U_?UpperCaseQ :> l <> " " <> U], x})          (* "Foo Bar Baz Quux" -> foo *)       This, though, doesn't work at all:               labeledFoo /. {hdr_String, x_} :> (StringReplace[hdr,       l_?LowerCaseQ ~~ U_?UpperCaseQ :> l <> " " <> U] -> x)          (* "Fo" ~~ l <> " " <> U ~~ "a" ~~ l <> " " <> U ~~ "a" ~~         l <> " " <> U ~~ "uux" -> foo *)      I really have no idea what's going on. This is so weird that I feel like I must be missing a simple syntax error, but all the other things that **do** work make me doubt that.


title: I want change gamma function form into beta function form

text: I want to integrate below form               x5^b*(1 - x5)^c*(e + d*x5^0.5 + f*x5)          1./Integrate[x5^b*(1 - x5)^c*(e + d*x5^0.5 + f*x5), {x5, 0, 1},        Assumptions -> {{b, c, e, d, f} \[Element] Reals, c > -1, b > -1}]      and the _Mathematica_ answer is               1./(Gamma[       1 + c] ((e Gamma[1 + b])/Gamma[2 + b + c] + (1. d Gamma[1.5 + b])/        Gamma[2.5 + b + c] + (f Gamma[2 + b])/Gamma[3 + b + c]))      but I want see this answer in form of Beta function what should I do?


title: Working with large data, pass-by-reference, compiled functions

text: I think I know the answer to this, but after two days of Googling, this is my last effort before going down an unwanted path... I have a function that takes lots of large data as arguments as well as assigns new values to one of the arguments in place. Here is what it looks like:                   LinearIsotropicElastic[youngMod_,poisson_,node_,dilitation_,devElongState_,families_,volumes_,refMagState_,volState_,internalForce_] :=     Module[{ti,td,forceState,bulkMod=youngMod/3.0/(1.0 - 2.0*poisson),shearMod=youngMod/2.0/(1.0 + poisson)},              ti = 3.0*bulkMod*dilitation[[node]]/volState[[node]]*refMagState[[node]];              td = 15.0*shearMod/volState[[node]]*devElongState[[node]];              forceState = ti + td;              internalForce[[node]] += Total[forceState*volumes[[families[[node]]]]];              internalForce[[families[[node]]]] -= forceState*volumes[[node]];     ]      In pure Mathematica, I used `SetAttributes[]=HoldAll` and everything works fine. The issue is I need to map this function over many thousand "node" and this takes forever, therefore I'd really like to compile this function. I have not been able to successfully get the tricks that have been offered to compile a function while changing one of its arguments. This is standard pass-by- reference stuff in C of course. Are there any suggestions before I resort to writing this function in C and LibraryLink'ing it in? I really don't want to go down this path, because I actually already have a working similar application in C++ and was building this in Mathematica to be a prototyping code and not deal with all the complexity of C/C++. Any help will be appreciated.


title: What are the differences between the “Home Edition” and the regular Mathematica?

text: The product page for _Mathematica Home Edition_ says: > Mathematica Home Edition is intended for hobbyists and enthusiasts alike, > for non-professional use. If you wish to integrate Mathematica in your work, > teaching, or research, other licensing options are available. but I cannot find there nor here any technical description of the differences. Are those two different products? Or is it the same software sold under two names corresponding to two different licensing restrictions?


title: How to solve the warning problem and obtain real roots without imaginary part?

text: I am trying to solve a equation with _Newton_ 's method via `FindRoot`, and the codes are: Define the functions:               τs[Ωs_,t_]:=2*Ωs*Coth[Ωs/(2*t)]     τb[Ωb_,t_]:=2*Ωb*Coth[Ωb/(2*t)]     Xs[Js_,Jb_,Ωs_,t_,δ_]:=(τs[Ωs,t]-4*Js-4*Js/(Sqrt[2])^δ)/(Jb+4*Js/(Sqrt[2])^δ+4*Js/(Sqrt[3])^δ)     Xb[Jb_,Ωb_,t_,δ_]:=(τb[Ωb,t]-4*Jb-4*Jb/(Sqrt[2])^δ)/(Jb+4*Jb/(Sqrt[2])^δ+4*Jb/(Sqrt[3])^δ)     ϕ[Jb_,Ωb_,t_,δ_]:=ArcCosh[Xb[Jb,Ωb,t,δ]/2]     BN[Jb_,Ωb_,t_,δ_,n_]:=Sinh[(n+1)*ϕ[Jb,Ωb,t,δ]]/Sinh[ϕ[Jb,Ωb,t,δ]]     fumfa[Js_,Jb_,Ωs_,Ωb_,t_,δ_,n_]:=(Xs[Js,Jb,Ωs,t,δ])^2*BN[Jb,Ωb,t,δ,n-2]-2*Xs[Js,Jb,Ωs,t,δ]*BN[Jb,Ωb,t,δ,n-3]+BN[Jb,Ωb,t,δ,n-4]      Solve a series of solutions:               Table[FindRoot[fumfa[2.0,1.0,Ωs,2.0,3.5,t,4]==0.0,{Ωs,4.0}],{t,0.1,4.0,0.2}]      However, I got the following warning message: > The line search decreased the step size to within tolerance specified by > `AccuracyGoal` and `PrecisionGoal` but was unable to find a sufficient > decrease in the merit function. You may need more than `MachinePrecision` > digits of working precision to meet these tolerances. And some of the solutions have imaginary parts though the coefficients are actually zeros:               {{Ωs->11.6453 +0. I},{Ωs->10.5823 +0. I},{Ωs->9.58167 +0. I},{Ωs->8.63181 +0. I},{Ωs->7.72096 +0. I},{Ωs->6.83656 +0. I},{Ωs->5.96386 +0. I},{Ωs->5.08324 +0. I},{Ωs->4.16381 +0. I},{Ωs->3.14345 +0. I},{Ωs->1.82232},{Ωs->5.70687*10^-6},{Ωs->4.74748},{Ωs->3.29661},{Ωs->1.28711},{Ωs->-1.26412*10^-6},{Ωs->-3.05724*10^-6},{Ωs->-0.0000392875},{Ωs->0.0000453593},{Ωs->0.0000543535}}      My questions are:   1. How to remove the warning message?   2. why there are imaginary parts in the solutions and how to assure `Reals` only computation?


title: How to smoothly change the radius of a circle by dragging its circumference?

text: I am attempting to set an `EventHandler` to change the radius of a circle by dragging on its circumference. But the response to the dragging is terribly slow. What is wrong with the code?               cnt[p_] := Return[Round /@ p];     grids[min_, max_] :=        Join[Range[Ceiling[min], Floor[max]],         Table[{j + 1, Lighter@Lighter@Lighter@Lighter@Blue}, {j,           Round[min], Round[max - 1], 1}]];          DynamicModule[{pnt = {1, 1}, VPOS = {1, 1}, rad = 1},       Dynamic@Graphics[        {Thick,         EventHandler[          Circle[ cnt[pnt] , rad],          {           "MouseDragged" :> (             VPOS = MousePosition["Graphics"];               rad = EuclideanDistance[pnt, VPOS];             )           },          PassEventsDown -> True          ],         Locator[Dynamic[pnt], None]          },        Axes -> True,        GridLines -> grids,        PlotRange -> {{-10, 10}, {-10, 10}}]       ]      ![enter image description here](http://i.stack.imgur.com/Xfrw4.gif)


title: How to color the surface of the Box of 3D graphics

text: Is there any possibility to color the surface of the Box of a `Graphic3D[]`?               Show[Graphics3D[Sphere[]], ViewPoint -> Above,      BoxStyle -> Directive[Large, Orange, Thick]]      I need to color the surface of the Box. (Like a wall).


title: How to find best MLE using `FindDistributionParameters`

text: This question is an extension of this question, if we change the initial values `FindDistributionParameters[data1, dist, {{a, 0.1}, {b, 0.1}, {c, 0.1}, {al, 0.1}, {be, 0.1}, {ph, 0.1}}] ` to `FindDistributionParameters[data1, dist, {{a, 0.2}, {b, 0.1}, {c, 0.1}, {al, 0.1}, {be, 0.1}, {ph, 0.1}}]` parameter estimates also change. So my question is if we have no idea about initial values then how we search best initial values or best MLE estimates which close to empirical distribution of `data1`. The empirical distribution with two parameters which are estimated with initial value's given above are plotted as ![enter image description here](http://i.stack.imgur.com/8be82.gif) Not a best fit. The code of above plot is: > data1 = {275, 13, 147, 23, 181, 30, 65, 10, 300, 173, 106, 300, 300, 212, > 300, 300, 300, 2, 261, 293, 88, 247, 28, 143, 300, 23, 300, 80, 245, 266}; > g1 = NIntegrate[(2.51339*2.51952*3.21532)/Beta[2.87484, 0.0825351]* > y^-(3.21532 + 1)*(1 + > 0.0609138*2.51952*y^-3.21532)^-((2.87484*2.51339)/0.0609138 + 1)*(1 - (1 + > 0.0609138*2.51952*y^-3.21532)^-(2.51339/ 0.0609138))^(0.0825351 - 1), {y, 0, > x}]; > > g2 = NIntegrate[(1.98156*1.98026*3.2635)/Beta[2.64639, 0.090212]* y^-(3.2635 > + 1)*(1 + 0.0328252*1.98026*y^-3.2635)^-((2.64639*1.98156)/0.0328252 + 1)*(1 > - (1 + 0.0328252*1.98026*y^-3.2635)^-(1.98026/ 0.0328252))^(0.090212 - 1), > {y, 0, x}]; > > Plot[{g1, g2, CDF[EmpiricalDistribution[data1], x]}, {x, 2, 400},   >  Exclusions -> None]


title: List of Parallelize[]-able functions

text: The question is clear and is inspired by this question and the first comment on this question. Although there are many tricks for parallelizing things that are not `Parallelize[]`-able it would be handy to know beforehand whether the function you need is boostable with `Parallelize`. From the official documentation we have the following list:   * All listable functions with one argument.   * Structure-preserving functions: `Map`, `MapThread`, `MapIndexed`, `Scan`, `Apply`.   * Reductions: `Count`, `MemberQ`, `FreeQ`.    * Products: `Inner`, `Outer`, `Dot`.   * Iterators: `Table`, `Array`, `Product`, `Sum`. Does the complete list exist?


title: Rectangle with rounded edges

text: Inspired from : Fit an image within a Rectangle [] in Graphics I would like now to fit an image within a Rectangle[] with **rounded edges** as shown in the example below : ![enter image description here](http://i.stack.imgur.com/tqIrf.png) Is it possible ?


title: Plot Matlab icon

text: I started to explore this on a whim and hasn't succeeded yet… Some introduction for the icon is found here but I can't understand it very well. (I admit that, though playing with `NDSolve` a lot, I suffered my unstable foundation of knowledge for PDE. ) A matlab code sample for the icon is found at the end of the document here and I have no doubt that it can be translated to _Mathematica_ code mechanically, but it'll be so boring! Can we plot it in a _Mathematica_ style? Has anyone tried it before?


title: Root finding in Mathematica

text: I am new to Mathematica. I have used the WolframAlpha online calculator to find roots of equations (listed under the heading `Root` in the output generated in response to a submission). When I try to find the roots of the same equation in Mathematica, I receive various errors. I have tried `FindRoot` and `Reduce`. Is there a function in Mathematica that corresponds to whatever is generating the `Root` output in the online WolframAlpha calculator? Thank you.


title: Export Animate command to MOV video

text: I'm trying to export a rather complex `Animate` command into a full-HD resolution video, but having no success so far. The animation has around 520 frames (the number of elements in the `trajectory` array). What I should be seeing is a tube object moving with a sphere object, and whilst I can see the animation is working with the `Animate` command, I cannot see the same results when I export the animation. I have tried different things but this just doesn't seem to work, I'm probably not using the export command in the right way. Instead of the 500~ frames trajectory of the tube and the sphere, I just see the animator moving from one side to other. I'm using the `Export` function, in the following way:               Export["my_output.mov",animationObject,"QuickTime",ImageSize->{1920,1080}]      My animation object follows this pattern:               (*theta and phi work as a function of s (the only animated variable) to change the view point*)     theta = N[Table[q, {q, 0.1, 2 \[Pi], (2 \[Pi] - 0.1)/Length[trajectory]}]];     phi = N[Table[q, {q, 0.5 \[Pi], 2.5 \[Pi], 2 \[Pi]/Length[trajectory]}]];          Animate[      Show[       (*data is a static array of around 5000 points*)       ListPointPlot3D[(*my list plot options and data*)],            (*A tube *)       Graphics3D[{White, Thickness [0.01], Opacity[0.4],Tube[trajectory[[1 ;; s]]]}],            (*A sphere*)       Graphics3D[{Yellow, Sphere[{trajectory[[s]]}, {0.02, 0.02}]}],            (*Just showing some grids with 10 grid lines*)       FaceGrids -> {(*Specific options for the face grids to show more lines, etc*)},            (*ViewPoint changed according to the corresponding value of s in the theta and phi arrays*)       ViewPoint -> Dynamic[{Sin[theta[[s]]] Cos[phi[[s]]],Sin[theta[[s]]] Sin[phi[[s]]], Cos[theta[[s]]]}],       ViewAngle -> 50 Degree],           (*Animate Parameters*)      {s, 1, Length[trajectory], 1}, DisplayAllSteps -> True,AnimationRepetitions -> 1, AnimationRunning -> False]      I'm using Mathematica 8 student version.


title: How to mix Unevaluated property of function arguments with expression assignments?

text: This is a follow-up to my (solved) question How to distribute a generic function of two arguments (without evaluating the arguments) Say, I have a binary function               f[x : a_List, y : b_List] := g[a, b]      Now if               u={u1,u2};     v={v1,v2};     w={w1,w2};      I want do distribute `f[u,v+w]` prior to evaluating `v+w` which works fine with the solution proposed by Mr. Wizard to my previous question               Distribute[Unevaluated@f[u,v+w]]     (** g({u1,u2},{v1,v2})+g({u1,u2},{w1,w2}) **)      But now what if I do               expr = v + w;      and try to distribute f[u,expr]? I would like to get the same result as before, however this yields               f[u,expr]        (** g({u1,u2},{v1+w1,v2+w2}) **       as of course `v+w` is evaluated when assigning to `expr`. Now a SetDelayed approach `expr := v+w` also doesn't help. I then thought of doing               expr = Hold[v+w];     Distribute[Unevaluated@ftest[u, ReleaseHold[expr]]]     (** g({u1,u2},{v1+w1,v2+w2}) **)      but this also gives the wrong (i.e. not the desired) result. So, how do I do this?


title: Cannot Plot Function

text: I cannot plot this function as I am getting errors. I am not sure what I am doing wrong. Seems to work when $$n \rightarrow 1,$$ but when $$n \rightarrow 2,$$ I get a whole bunch of errors and nothing is plotted. Here is the code: $$ \text{Plot}\left[\frac{n e^{-t (\lambda +\mu )} I_1\left(2 t \sqrt{\lambda \mu }\right) \left(\int_0^t \frac{e^{t (-\lambda -\mu )} I_1\left(2 t \sqrt{\lambda \mu }\right)}{\sqrt{\rho } t} \, dt\right){}^{n-1}}{\sqrt{\rho } t}\text{/.}\, \left\\{\lambda \to 0.99,\mu \to 1,\rho \to \frac{1}{2},n\to \\{2\\}\right\\},\\{t,0,10\\},\text{PlotRange}\to \text{All}\right]$$ Here is copyable code:               Plot[(n*BesselI[1, 2*t*Sqrt[λ*μ]]*                       Integrate[(E^(t*(-λ - μ))*                BesselI[1, 2*t*Sqrt[λ*μ]])/(t*Sqrt[ρ]),                      {t, 0, t}]^(-1 + n))/         E^(t*(λ + μ))/(t*Sqrt[ρ]) /.           {λ -> 0.99, μ -> 1, ρ -> 1/2, n -> {2}}, {t, 0., 10}, PlotRange -> All]


title: Interpolation steeply drops to 0 beyond data

text: I use Interpolation on unstructured 3-D-Data to visualize different regions via RegionPlot. A problem I run into is that the interpolating function steeply drops to zero beyond my set of data. This is unfortunate, as I with to show the region up to their theoretical boundary (which lies only a little bit beyond the data region). Is there a way to get Interpolation to perform a proper extrapolation for just a little margin beyond my data? This image shows the problem pretty well I think. ![Example for the problem](http://i.stack.imgur.com/bfzTz.png) The data that produced the image can be found here


title: Numbers in alternate bases transcend the evaluator?

text: It looks to me like a number in a base other than base 10 gets evaluated before the evaluator ever gets a chance to be tweaked. For example, `FullForm[16^^abcdef]` or even `FullForm[HoldAll[16^^abcdef]]` both produce `11259375`. Am I missing a trick that would get me some sort of less evaluated form? I guess I can use `BaseForm[]` when I need to record what base the number originally was in.


title: Safely generating multiple controls from a list of variables

text: Suppose I need to create sliders associated with variables from a given list:               ClearAll[a, b, c, d];     vars = {a, b, c, d};     Slider[Dynamic@#, {0, 1}] & /@ vars     Dynamic@vars      Unfortunately it works only for variables which don't have values:               ClearAll[a, b, c, d];     vars = {a, b, c, d};     a = 1;     Slider[Dynamic@#, {0, 1}] & /@ vars     Dynamic@vars      As you can see now the first slider is not working because Mma attempts to assign values to raw object `1` instead of `a`. Nevertheless simple               Slider[Dynamic@a, {0, 1}]     Dynamic@a      produces the desired result. So, what is the right way to do such things?


title: Given a Boolean representation of a system, how can the Reliability Function be displayed as symbolic algebra?

text: Can Mathematica 9 convert a Boolean representation of an RBD to its symbolic algebraic form? If I have a simple series Reliability Block Diagram made up of 2 components, c1 and c2 bexpr1=And[c1,c2] and the corresponding symbolic representation for the system would be RS1 = R1*R2 The system I am interested in is more complex and contains 7 components in a 4 path architecture: path1=And[c1,c2,c5,c7] path2=And[c1,c3,c5,c7] path3=And[c1,c3,c6,c7] path4=And[c1,c4,c6,c7] bexpr2=Or[path1,path2,path3,path4] How can the algebraic form of the reliability function be obtained for bexpr2 using Mathematica? The solution can be seen on page 5 of the PDF file at the following link http://www.reliasoft.com/newsletter/2Q2000/index.htm Thank you. Daniel, Thank you for your reply but I think it too is not correct and I' m not sure why. See below for a comparision of the two solution methods. Am I mis- interpreting something here ? Also, I agree that Eq.(3) is undersimplified. Perhaps the author intentionally left it in that form to help show how this problem can be solved manually (pencil & paper).               equation3 = (r1*r4*r6*r7) + (r1*r3*r6*r7) - (r1*r3*r4*r6*r7) + (r1*r2*r3*r4*     r5*r6*r7) + (r1*r3*r4*r5*r6*r7) - (r1*r2*r3*r4*r5*r6*r7) - (r1*r2*r3*r5*     r6*r7) - (r1*r3*r5*r6*r7) + (r1*r2*r3*r5*r6*r7) - (r1*r2*r4*r5*r6*     r7) - (r1*r3*r4*r5*r6*r7) + (r1*r2*r3*r4*r5*r6*r7) + (r1*r2*r5*r7) + (r1*     r3*r5*r7) - (r1*r2*r3*r5*r7) (* Eq.(3) ReliabilityEdge volume 1, Issue 1 *)      r1 r2 r5 r7 + r1 r3 r5 r7 - r1 r2 r3 r5 r7 + r1 r3 r6 r7 + r1 r4 r6 r7 - r1 r3 r4 r6 r7 - r1 r3 r5 r6 r7 - r1 r2 r4 r5 r6 r7 + r1 r2 r3 r4 r5 r6 r7 Original Problem               path1 = And[c1, c2, c5, c7];     path2 = And[c1, c3, c5, c7];     path3 = And[c1, c3, c6, c7];     path4 = And[c1, c4, c6, c7];     bexpr = Or[path1, path2, path3, path4]      (c1 && c2 && c5 && c7) || (c1 && c3 && c5 && c7) || (c1 && c3 && c6 && c7) || (c1 && c4 && c6 && c7) Ilian' s Solution (1)               dists = Table[{ToExpression["c" ~~ ToString[i]],         BernoulliDistribution[ToExpression["r" ~~ ToString[i]]]}, {i, 7}]       {{c1, BernoulliDistribution[r1]}, {c2, BernoulliDistribution[r2]}, {c3, BernoulliDistribution[r3]}, {c4, BernoulliDistribution[r4]}, {c5, BernoulliDistribution[r5]}, {c6, BernoulliDistribution[r6]}, {c7, BernoulliDistribution[r7]}}               survivalfunction1 = Expand[PDF[ReliabilityDistribution[bexpr, dists], 1]]      r1 r2 r5 r7 + r1 r3 r5 r7 - r1 r2 r3 r5 r7 + r1 r3 r6 r7 + r1 r4 r6 r7 - r1 r3 r4 r6 r7 - r1 r3 r5 r6 r7 - r1 r2 r4 r5 r6 r7 + r1 r2 r3 r4 r5 r6 r7               Simplify[survivalfunction1/       equation3] (* This show that the results are equivalent *)      1 Daniel' s Solution (2)               bexpr2 = BooleanConvert[bexpr, "ANF"]      (c1 && c2 && c5 && c7) [Xor] (c1 && c3 && c5 && c7) [Xor] (c1 && c3 && c6 && c7) [Xor] (c1 && c4 && c6 && c7) [Xor] (c1 && c2 && c3 && c5 && c7) [Xor] (c1 && c3 && c4 && c6 && c7) [Xor] (c1 && c3 && c5 && c6 && c7) [Xor] (c1 && c2 && c4 && c5 && c6 && c7) [Xor] (c1 && c2 && c3 && c4 && c5 && c6 && c7)               survivalfunction2temp = bexpr2 /. {And -> Times, Xor -> Plus}      c1 c2 c5 c7 + c1 c3 c5 c7 + c1 c2 c3 c5 c7 + c1 c3 c6 c7 + c1 c4 c6 c7 + c1 c3 c4 c6 c7 + c1 c3 c5 c6 c7 + c1 c2 c4 c5 c6 c7 + c1 c2 c3 c4 c5 c6 c7               survivalfunction2stringtemp = ToString[survivalfunction2temp]      "c1 c2 c5 c7 + c1 c3 c5 c7 + c1 c2 c3 c5 c7 + c1 c3 c6 c7 + c1 c4 c6 c7 + c1 \ c3 c4 c6 c7 + c1 c3 c5 c6 c7 + c1 c2 c4 c5 c6 c7 + c1 c2 c3 c4 c5 c6 c7"               survivalfunction2string =       StringReplace[survivalfunction2stringtemp, "c" -> "r"]      "r1 r2 r5 r7 + r1 r3 r5 r7 + r1 r2 r3 r5 r7 + r1 r3 r6 r7 + r1 r4 r6 r7 + r1 \ r3 r4 r6 r7 + r1 r3 r5 r6 r7 + r1 r2 r4 r5 r6 r7 + r1 r2 r3 r4 r5 r6 r7" survivalfunction2 = ToExpression[survivalfunction2string] r1 r2 r5 r7 + r1 r3 r5 r7 + r1 r2 r3 r5 r7 + r1 r3 r6 r7 + r1 r4 r6 r7 + r1 r3 r4 r6 r7 + r1 r3 r5 r6 r7 + r1 r2 r4 r5 r6 r7 + r1 r2 r3 r4 r5 r6 r7               Simplify[survivalfunction2/       equation3](* This show that the results are not equivalent *)      (r4 r6 + r2 (1 + r3) r5 (1 + r4 r6) + r3 (r5 + r6 + r4 r6 + r5 r6))/( r4 r6 + r2 (-1 + r3) r5 (-1 + r4 r6) + r3 (r5 + r6 - r4 r6 - r5 r6)) Let' s do a quick numerical sanity check.               r1 = r2 = r3 = r4 = r5 = r6 = r7 = 1;          survivalfunction1  (* This is the correct numerical value *)      1               survivalfunction2  (* This is numerically not possible, must be less than or      equal to one *)      9 Upon examination of survivalfunction2 I notice there are no negative signs in the algebra . . . not sure why. Also, I apologize here if everything is not formatted with all proper formatting, I'm still unfamiliar with much at StackExchange. * * * Clay, Thank you for the reply. I believe there may be a problem with your code as it produces a result that differs from Eq.(3) in the referenced PDF file. I tested the following code on the system architecture that I posted (associated with Eq.(3) ) and other simpler systems and it appears to accurately produce the algebra for the reliability function. dists = Table[{ToExpression["c" ~~ ToString[i]], BernoulliDistribution[ToExpression["r" ~~ ToString[i]]]}, {i, 7}]; Expand[PDF[ReliabilityDistribution[bexpr2, dists], 1]] The above code was produced by Ilian Gachevski in his posting at Wolfram Community. Thanks again for your inputs.


title: Mathematica as a report generator

text: I would like to use Mathematica as a kind of report generator. I'm working in a Mathematica notebook and I want to handle Mathematica like this: 1) I want to define one cell as a text cell. In this cell I want to integrate an expression (maybe as an inline cell) lets say a*b (a and b have been defined in an input cell before). 2) After evaluating this cell a*b should be replaced by (assume a=10 and b=5) 50, so that the resulting cell would look like this. > some text ....... 50.. some other text...... More general: I want to have the possibility to call a function or an expression (which has been defined before) in a text cell. The displayed result of the call should be updated, whenever I change the input values.


title: New list generated from the sum of elements taken from two lists

text: I have been using mathematica for a while, but I have problem wrapping my head around list manipulation functions. I would appreciate any suggestions. Here is what I want to do. ListV is a list of vectors:               ListV= {{x1,y1,z1},{x2,y2,z2},...}= {V1,V2,...}      ListU is also a list of vectors :               ListU={{a1,b1,c1},{a2,b2,c2},...}= {U1,U2,...}      ListU and ListV may have unequal lengths. I want to make a new list (ListUV) which would contain all the new positions generated by the sum of all vectors in ListU and ListV. Mathematically, that would be > ListUV= {V1+U1, V2+U1, ..., V2+U1, V2+U2, ... }. Thanks for any suggestions.


title: Asymptotic Rate of Growth

text: How can I calculate the Asymptotic Rate of growth of a function, for instance like: $X^3 - X^2 - X -1$ EDIT: For instance, as you can see in this graph, after the 1200 the function approximates to the limit. I want to if there is a easy way to calculate the rate of grow, after 1200 for instance. ![enter image description here](http://i.stack.imgur.com/FejWE.png) **Edit** I'm trying to find a generalized way in order to graphically find it for Fibonacci, Tribonacci, Tetranacci sequences


title: How to define logical expressions for platonic solids?

text: A more general question would be: How to find logical expressions for 3D-objects described by closed polygon sets? Finally a simple question is more prolific, therefore: ## How to define logical expressions for platonic solids ? I study this question for two days now, and I thought, I found an answer already:               PolyhedronData["Tetrahedron", "RegionFunction"]          (* out *)      Sqrt[2] + 4 Sqrt[3] #3 >= 0 &&        4 Sqrt[3] #3 <= 3 Sqrt[2] + 8 Sqrt[6] #1 &&        4 Sqrt[3] (Sqrt[2] #1 + #3) <= 3 Sqrt[2] (1 + 4 #2) &&        4 (Sqrt[6] #1 + 3 Sqrt[2] #2 + Sqrt[3] #3) <= 3 Sqrt[2] &      So far, so good. But then I discovered ...               PolyhedronData["Octahedron", "RegionFunction"]          Missing["NotAvailable"]      ok, this is not dramatic, I can define this myself. But doing so, I found out, it is better to give up those incomplete and specific `RegionFunction` definitions of Mathematica. This led me back to my question: How to define region functions for the 5 platonic solids in a better way? What are your ideas, your suggestions? At the moment I just want to concentrate on the platonics.               c = constant = Abs@1; (* -1 <= c <=  +1 *)      plotPoints = 100/2; (* half value while testing *)          RegionPlot3D[      And[x + y + z <= c, -x - y + z <= c,        x - y - z <= c, -x + y - z <= c, -x - y - z <= c, x + y - z <= c,        x - y + z <= c, -x + y + z <= c], {x, -c, c}, {y, -c, c}, {z, -c,        c}, PlotPoints -> plotPoints]      ![octahedronRegionFunction](http://i.stack.imgur.com/4MvgF.gif) The octahedron region function could be simplified to: (not sure, if it's really a good idea )               RegionPlot3D[      Abs@x + Abs@y + Abs@z <= c, {x, -c, +c}, {y, -c, +c}, {z, -c, +c},       PlotPoints -> plotPoints]      two region functions for tetrahedrons of interest               RegionPlot3D[      And[x + y - z <= c, +x - y + z <= c, -x + y + z <= c, -x - y - z <=         c], {x, -c, +c}, {y, -c, +c}, {z, -c, +c}, PlotPoints -> plotPoints]          RegionPlot3D[      And[x - y - z <= c, -x - y + z <= c, -x + y - z <= c, +x + y + z <=         c], {x, -c, +c}, {y, -c, +c}, {z, -c, +c}, PlotPoints -> plotPoints]      # What would be `nice` regionFunctions for `Dodecahedron` or `Icosahedron`, to complete the 5 platonics ? You may checkout yourself the definitions for `RegionFunction` done by Mathematica. Especially non-convex polyhedrons have no region functions defined. (code from Mathematica, modfied):               Manipulate[      Column[{PolyhedronData[g], PolyhedronData[g, p]}], {{g, "Octahedron",         "polyhedron" // Style[#, GrayLevel@.4, "Menu"] &},        PolyhedronData[All]}, {{p, "RegionFunction" (* init *),         "property" // Style[#, GrayLevel@.4, "Menu"] &},        Complement @@ PolyhedronData /@ {"Properties", "Classes"}}]


title: Why is AstronomicalData so slow?

text: I'm having trouble getting some pretty simple functions using `AstronomicalData` to perform at anywhere near the speed I need them to. For example, I have many places where I need to compute something like               ParametricPlot[      {AstronomicalData[        "Mercury", {"RightAscension",          DatePlus[Date[], d], {$GeoLocation[[1]] , $GeoLocation[[2]]}}], d},      {d, 0, 365}, AspectRatio -> 1/1.6]      but find that it takes far to long for even this simple fragment to run. I want to put several such fragments (e.g. one for each of several astronomical objects) into a single figure, and even to dynamically change the parameters for the figure (such as location and date) inside a `Manipulate`, which would be prohibitively slow given the times I'm seeing with even the simple fragment above. Why is `AstronomicalData` so slow? Is there something I can do to speed it up so I can use it as I hope to?


title: How do I get rid of a "jump" in my plot?

text: How can I prevent plotting functions from "connecting" _inside_ a plot points that should "wrap around" _outside_ the plot? For example, how do I eliminate the horizontal lines running across the following `ParametricPlot`? ![enter image description here](http://i.stack.imgur.com/Wn2tr.png) In this figure, the paths that reach the right hand end of the graph at 24 should continue at 0 (these are hours, so 24=0) without passing backwards across the figure. * * *               Show[      ParametricPlot[       {AstronomicalData[         "Mars", {"RightAscension",           DatePlus[Date[], d], {$GeoLocation[[1]] , $GeoLocation[[2]]}}], d},       {d, 0, 365}, AspectRatio -> 1/1.6, PlotStyle -> Blue],      ParametricPlot[       {AstronomicalData[         "Mercury", {"RightAscension",           DatePlus[Date[], d], {$GeoLocation[[1]] , $GeoLocation[[2]]}}], d},       {d, 0, 365}, AspectRatio -> 1/1.6, PlotStyle -> Red],      ParametricPlot[       {AstronomicalData[         "Jupiter", {"RightAscension",           DatePlus[Date[], d], {$GeoLocation[[1]] , $GeoLocation[[2]]}}], d},       {d, 0, 365}, AspectRatio -> 1/1.6, PlotStyle -> Green]      ]      * * * FWIW, the (almost) final result, with help from SE: ![enter image description here](http://i.stack.imgur.com/5jAcd.png)


title: Nested Derivative

text: These two expressions are mathematically the same, but when substituting with the same rule, yield different results. What is happening?               Derivative[1][Derivative[1][x][t]][t] == 5 t + 3 x[t] /.        {x -> Function[{t}, 1/3 (-5 t + Derivative[1][Derivative[1][x][t]][t])]}          D[x[t], t, t] == 5 t + 3 x[t] /.        {x -> Function[{t}, 1/3 (-5 t + Derivative[1][Derivative[1][x][t]][t])]}


title: How can I get Mathematica to recognize equality of symbolic matrix expressions?

text: I have two matrix expressions:               X.Transpose[T].Transpose[X]       and               X.T.Transpose[X]       I want _Mathematica_ to recognize that these expressions are equal. Is it possible to do that?


title: Importing Text file and removing columns

text: I have a file that has 7 column but i only want to import two column from it, that is 1st and 3rd column from the file. How can i do that and this is the list for example:               {1.1033,6.1371,46471,0,1,,0}     {1.1064,6.2101,46504,0,1,,0}     {1.1371,0,46537,0,1,Z,0}     {1.1598,0.0731,46571,0,1,,0}     {1.1946,0.1461,46604,0,1,,0}     {1.1871,0.2192,46638,0,1,,0}     {1.217,0.2922,46671,0,1,,0}     {1.234,0.3653,46704,0,1,,0}     {1.2541,0.4384,46738,0,1,,0}     {1.2509,0.5114,46771,0,1,,0}     {1.2244,0.5845,46805,0,1,,0}     {1.2009,0.6575,46838,0,1,,0}     {1.1916,0.7306,46871,0,1,,0}     {1.2287,0.8037,46905,0,1,,0}     {1.2406,0.8767,46938,0,1,,0}     {1.2517,0.9498,46971,0,1,,0}     {1.2385,1.0228,47005,0,1,,0}     {1.2545,1.0959,47038,0,1,,0}


title: Savitzky-golay filter

text: How to use Savitzky-golay filter on csv file? I have file.csv in this format:               0.1,1.6,2.8,0     0.2,1.2,2.3,1     0.7,1.5,2.4,2     0.6,1.2,2.7,3     0.4,1.4,2.9,4     0.3,1.3,2.5,5      description               number1,number2,number3,id      I need to load CSV, use savitzky-golay filter on numbers1, numbers2 and numbers3 seperatly. And then save it into csv again. Can you help? EDIT: I've already tried to parse csv, try filter from example and plot it:               table = Take[Import["file.csv"]];     first = table[[All,1]];     c = SavitzkyGolayCoefficients[20, 20, 4];     c = N[c];     filterOutput = SavitzkyGolayFilter[test, c];     ListLinePlot[{filterOutput, first}]      How to save it to CSV again in same format. What does `SavitzkyGolayCoefficient` menas?


title: Searching for roots of complex function

text: I'm searching for roots of complex function $$ 2\imath q \ln(-2\imath k)+\imath\pi-2\imath \Im(\ln(\Gamma(1+2\imath q)))+\ln(\frac{\Gamma(1+\imath q-\imath q x/k)}{\Gamma(1-\imath q-\imath q x/k)})+\ln(\frac{\sqrt{-x+1}-\sqrt{-x-1}}{\sqrt{-x+1}+\sqrt{-x-1}}) $$ where $k=\sqrt{(-x+1)(-x-1)}$; $x$ is complex number with $\Re(x)<-1$ and $\Im(x)>0$ and $q$ is real and positive parameter. If a change a little bit starting values of $x$ in `FindRoot` function, result changes extremely. Please, can you tell me how to fix the result and what is the better way to find complex roots of such equations. Code:               2 I*q*Log[-2*I*Sqrt[(-x + 1) (-x - 1)]] + I*\[Pi] -  2*I*Arg[     Gamma[1 + 2*I*q]] + Log[Gamma[1 + I*q - I*q*x/Sqrt[(-x + 1) (-x - 1)]]] -      Log[Gamma[1 - I*q - I*q*x/Sqrt[(-x + 1) (-x - 1)]]] + Log[Sqrt[-x + 1] -      Sqrt[-x - 1]] - Log[Sqrt[-x + 1] + Sqrt[-x - 1]]


title: Getting long complex-valued integrals when simpler real-valued expressions exist

text: I have a long list of real-valued functions I'd like to integrate symbolically. For many of them, Mathematica gives me results with long complex-valued expressions involving weird functions such as `EllipticF`, even though I know that if I first manually apply a simple substitution such as $u=\sin\theta$ or $u=\cos\theta$, I will get a simple elementary real-valued expression. As an example, I want to integrate $\arcsin(a/\sin\theta)\cdot\cos\theta$ for some constant $a$ which satisfies $0<a<\sin\theta$ throughout the integration domain. Now, `Integrate[ArcSin[a/ Sin[theta]] Cos[theta], theta, Assumptions -> 0<a<Sin[theta]]` gives the result $$\sin (\theta ) \sin ^{-1}(a \csc (\theta ))+\frac{i a \cot \left(\frac{\theta }{2}\right) \sqrt{1-\frac{a^2 \tan ^2\left(\frac{\theta }{2}\right)}{-a^2+2 \sqrt{1-a^2}+2}} \sqrt{\frac{a^2 \tan ^2\left(\frac{\theta }{2}\right)}{a^2+2 \sqrt{1-a^2}-2}+1} \left(F\left(i \sinh ^{-1}\left(\sqrt{\frac{a^2}{a^2+2 \sqrt{1-a^2}-2}} \tan \left(\frac{\theta }{2}\right)\right)|-\frac{a^2+2 \sqrt{1-a^2}-2}{-a^2+2 \sqrt{1-a^2}+2}\right)-2 \Pi \left(\frac{a^2+2 \sqrt{1-a^2}-2}{a^2};i \sinh ^{-1}\left(\sqrt{\frac{a^2}{a^2+2 \sqrt{1-a^2}-2}} \tan \left(\frac{\theta }{2}\right)\right)|-\frac{a^2+2 \sqrt{1-a^2}-2}{-a^2+2 \sqrt{1-a^2}+2}\right)\right)}{\sqrt{\frac{a^2}{a^2+2 \sqrt{1-a^2}-2}} \sqrt{\frac{2 a^2+\cos (2 \theta )-1}{\cos (2 \theta )-1}}},$$ where $F=$ `EllipticF` and $\Pi=$ `EllipticPi`, but if I first perform the subsitution $u=\sin\theta$ and then evalute `Integrate[ArcSin[a/u] , u] /. u -> Sin[theta]`, I get the much simpler $$\frac{a \csc (\theta ) \sqrt{\sin ^2(\theta )-a^2} \log \left(\sqrt{\sin ^2(\theta )-a^2}+\sin (\theta )\right)}{\sqrt{1-a^2 \csc ^2(\theta )}}+\sin (\theta ) \sin ^{-1}(a \csc (\theta )).$$ How do I make Mathematica give me the second result without explicitly performing the variable substitution? In my case, all my functions are of the form $\cos\theta\cdot f(\sin\theta)$ or of the form $\sin\theta \cdot f(\sin^2(\theta))$ or of a form which does not need any special substitution (but my list of functions is too long for me to group them according to this). Can I encourage Mathematica to try the substitutions $u=\cos\theta$ and $u=\sin\theta$ first, or can I convince Mathematica that everything is real- valued and not to worry about subtleties concerning complex-valued functions?


title: How to code a simple audio equalizer?

text: I would like to code a simple Manipulate-based equalizer to make bass and treble adjustments in wav-file, but I haven't found any clues in documentation. Wiki says that I have to deal with linear filters, but I have no idea what is it. Is it a very advanced stuff?


title: Finding the position of a specific value in a list

text: Is it possible to easily find the position of a specific value in a list? For example, if the list is `{{x1,y1},{x2,y2},...,{xn,yn}}` I would like to know the position of `y = 123456.78`. I would prefer to not use `If`.


title: Creating a graph with variable size of vertices and variable thickness of edges

text: I'm trying to create a graph to represent transitions between different states of a system. I would like to represent the time the systems spent in a state with the size of the vertex and the frequency of transition between two states with the thickness of the edge connecting the two vertices. In short I need to control the size of vertices and the thickness of edges. Now that I grasp the difference between Graph and GraphPlot a bit better, I wanted to implement this using the newer `Graph` functunality, specifically `VertexSize` and `EdgeStyle`. Here is my clumsy attempt:               trans = Uncompress@        "1:eJyVV01vwjAMRfu47U/sv3RKKc2KGsahxw2YOE0aXPff17RJSZD8/HIBga3Efn5+\     dl4/f/rT32q1ujyNH+35cj09+F8v40d1/j1+XY+\     Ht8P30T2Pf9ihbyvn7Y0T3GbjzZtyM5LbYmcP9Els++FdTWJy7EwrOEYzTjbeRkHyODnvB\     adgnb7d8KHi4e3OgBudmb5sB3xsV1CBOTLpymCdv1sp/\     mBlzhq9tJrfqolRC9aSDNSzGPwxFv5f05GAldDVoJKbrgBWJsnCIuFMB/\     28JVXNMR7IQsfVvZSTCD07V79Z78Clo1VLIS+YVn5/2H67Q3h4M83wZr2B4W/\     oCmhaFDXSWysUWcVpH4sElyUTFYsEGxnPRl7nlRgTFoFBu0xGjuDToRLAs5GeeDWqes22H\     ORPLDl/FENXLXCmuVWQanrkBwmT88uGjhh8JgIyYRI91EW4aBoqtOIbg60RxD+IAGjuZC+\     QRSeXfC2qkhGor6gqD60WfdoZTOy8SGu9iONKFEJeVO7eELQGMvOD0UDYaXHN5a6DT5Zlv\     GuYlu2TmhIyD726bP5gSnswmEttWR9puG1wH6WE1VuSBI2sVNA6cfxlK6JIx7utFDE7vI5\     lyAL+Kv09FopgpA9t+\     cIcCcjZMXgYV4YWrHd86DFyR2xpTh012aCEY8sSoy3sX3A0OHUHTjWYWgR8fv/wd/kB";     l = VertexList[Graph[trans]];     (*Weigths for vertices*)     r = RandomReal[{0.5, 1}, Length[l]];     vs = Transpose@{l, r} /. List[a_, b_] -> Rule[a, b];     (*Adjust font size*)     vls = Transpose@{l, r} /.         List[a_, b_] -> Rule[a, Directive[Black, Bold, 20*b]];     (*Weigths for line thicknes*)     rr = RandomReal[{0.1, 1}, Length[DeleteDuplicates@trans]]/100;     es = (First@# -> Directive[Thickness[Last@#], Opacity[.5]]) & /@         Transpose@{DeleteDuplicates@trans, rr};     g = Graph[DeleteDuplicates@trans,        VertexLabels -> Placed["Name", Center],        VertexShapeFunction -> "Capsule", VertexSize -> vs,        VertexLabelStyle -> vls, EdgeStyle -> es,        EdgeShapeFunction ->         GraphElementData["ShortUnfilledArrow", "ArrowSize" -> 0.03]]      But the result is useless (the text is not readable and it's not clear from where to where the arrows are going): ![Resulting graph](http://i.stack.imgur.com/TdN55.png) **How can I either fix this graph so that it's readable or implement variable vertex sizes and variable edge thickens using`GraphLayout`?** **EDIT** @kguler's comment helps. so using:               esf = Function[         a, (First@            a -> ({Arrowheads[{{.03, 1}}],               Arrow[#1, {.10 + 6 Last@a, .15}]} &))] /@         Transpose@{DeleteDuplicates@trans, rr};     g = Graph[DeleteDuplicates@trans,        VertexLabels -> Placed["Name", Center], VertexSize -> vs,        VertexLabelStyle -> vls, EdgeStyle -> es, EdgeShapeFunction -> esf(*,       EdgeShapeFunction->GraphElementData["ShortUnfilledArrow",       "ArrowSize"->0.03]*)]      I get ![Mathematica graphics](http://i.stack.imgur.com/HQyLd.png), which is almost usable. Is there perhaps a way to draw vertices on top of the edges?