Does an equivalent of marks in vim exist for navigating notebooks quickly?

Is it possible in the Mathematica front-end to associate a keyboard shortcut with a cursor location in the notebook (kind of like marks in vim) so that one can return to them quickly later? (Just wondering if this functionality exists in some easy-to-use form already or if it would be necessary to build something from scratch using presumably the front-end tokens.)


How can I deploy DLL files created by a Fortran function and call them from Mathematica

This is my Fortran function, established by Intel visual Fortran 11.1               FUNCTION MYADD(X,Y)      !DEC$ ATTRIBUTES DLLEXPORT::MYADD      REAL(8) X,Y,MYADD      MYADD=X+Y     end FUNCTION      A corresponding `.dll` file is created,`MDLL.dll` (64bit version) and I put this file in the `$Path` directory. In a Mathematica notebook, I input:               Needs["NETLink`"]     fun=DefineDLLFunction["MYADD", "MDLL.dll", "double", {"double", "double"}]     fun[1.0,2.0]      But it gives me an error:                NET::netexcptn: A .NET exception occurred: System.DllNotFoundException:           unable to load DLL"MDLL.dll": can not find corresponding module           (error form HRESULT:0x8007007E).          in Wolfram.NETLink.DynamicDLLNamespace.DLLWrapper1.MYADD(Double , Double).


How to record the stream of data (PixelPosition) dynamically?

I need to trace the moving of an object and get the coordinates of such movement. The set of coordinates will be used for the subsequent evaluation and analysis. I can easy get the current real-time coordinates by use of the following expression:               Dynamic[ImageKeypoints[EdgeDetect[CurrentImage[], 30], "PixelPosition"]]      But I need to record all these coordinates in the list in the separate cell or in separate file. I need that this list contains an cumulative set of all coordinates, frame by frame. Please, suggest how to resolve this issue.


Creating randomly oriented planes

I would like to create randomly oriented planes. This is how I'm attempting to do that:   1. I create a 2 random unit vectors, $\mathbf{v}_1$, and $\mathbf{v}_2$, in the $x$-$y$ plane   2. I assume that if I rotate these two vectors around a random vector (in $x$-$y$-$z$) called $\mathbf n$, the plane on which the two vectors lie is random and uniformly distributed over the sphere.    3. So I randomly pick $\mathbf n$, keeping in mind the issues of random point picking on spheres.   4. I then use `RotationMatrix[α, n].v1` (and same for `v2`) to get the new vectors on the rotated and supposedly random plane. There is some question on what to choose for the angle $\alpha$ which gives the angle of the rotation.      * If I choose $\alpha<\pi/2$, the vectors do not encompass the entire sphere.      * If I choose $\alpha=\pi/2$, I get a bunching of vectors at the poles.      * If I choose $\alpha>\pi/2$, there is bunching at various latitudes. I cannot get a uniformly random distribution over the sphere! Is there a fix to the current method I am implementing? Is there another way to do it? * * * My real goal here isn't creating random planes. My goal is to take two vectors with some arbitrary magnitude and direction in $x$-$y$ and then randomly orient them over the sphere while maintaining their relative positions with respect to one another. The steps I have taken above seem like the logical way to do that.


How to figure out whether a nonlinear inequality holds or not

I have an inequality consisted only of seven parameters as follows: $(1 + g)^{-(m+w)}\big[\big\{a+(1-a)(1 + g)^m\big\}(1 + p q)Q - (1 + g)^w \big\{(1 + g)^m (1 + q)-(1-p)q\big\} Q\big] < 0$ Parameters, $g$, $w$, and $m$, are subject to the following restrictions: $0<g$, $0<w$, $0<m$, $0<Q$ That is, these four parameters are all positive. Now, we can manually verify that this inequality holds under the above parameter restrictions. And I would like to confirm this with Mathematica. My codes for the assumptions:               $Assumptions = 0 < g && 0 < w && 0 < m && 0 < Q      And as for checking if the inequality holds, I used `Refine` and `If` as follows:               Refine[If[(1 + g)^(-m - w) ((a - (-1 + a) (1 + g)^m) (1 + p q) Q - (1 + g)^w ((-1 + p) q + (1 + g)^m (1 + q)) Q)<0, Print[True], Print[False]]]      Since the condition is true, the result I expect is `True`. But what I get is a simple repetition of the `If` bracket:               If[(1 + g)^(-m - w) ((a - (-1 + a) (1 + g)^m) (1 + p q) Q - (1 + g)^w ((-1 + p) q + (1 + g)^m (1 + q)) Q) < 0, Print[Yes], Print[No]]      When I use a little simpler, but similar, type of inequality, it gives me either `True` or `False` depending on the specific form of inequality I use. But it seems Mathematica is not able to figure out whether the above inequality, which is too complex (maybe?), is true or false. Or am I missing something? Can anyone help? Thank you so much.


Is there a change in V10 with Solve and exponents?

I've encountered a strange problem with V10. I can't quite nail it down, but the `Solve` seems to be unable to solve equations that it could in previous versions. Here is one I'm almost positive I've done before.               Solve[q == l^a ((l w b)/(r a))^b, l]      For those who are wondering this is one of the steps in solving for a cost function using a Cobb–Douglas production function. It can obviously be solved, all _Mathematica_ has to do is group the exponents. Is there a change in the solve assumptions, options? I've also tried being explicit about reals and allowing inverse functions.


Inverse function

What probably could be the inverse of following function?               y = (x^(1/t)-a^(1/t))*(x^(1/t)-c*b^(1/t))/(x^(1/t)-a^(1/t))*(x^(1/t)-c*b^(1/t))+           (x^(1/t)-   b^(1/t))*x^(1/t)-c*a^(1/t)      a,b,c & t are the parameters. Any help is going to be highly appreciated.


Q-Function representation in Mathematica

I observed that there is no Q-function representation in Mathematica. The definition of Q-Function is: \begin{align} Q(x) &= \frac{1}{\sqrt{2\pi}} \int_x^\infty e^{-\frac{u^2}{2}}du \\ &=\frac{1}{2} \mathrm{erfc}(\frac{x}{\sqrt{2}}) \end{align} a nother representation of Q-function is: \begin{align} Q(x) = \frac{1}{\pi} \int_0^{\frac{\pi}{2}} e^{\left(\frac{-x^2}{2\sin^2{\phi}} \right)}d\phi \end{align} there is only Complementary Error Function representation Erfc. $\mathrm{erfc}(x) = \frac{2}{\sqrt{\pi}} \int_{x}^{\infty} \exp(-t^2) dt$ Is there any possiblity that define a new function in _Mathematica_? so that it will be a permanent function. Note: In statistics, the Q-function is the tail probability of the standard normal distribution. In other words, Q(x) is the probability that a normal (Gaussian) random variable will obtain a value larger than x standard deviations above the mean.


More general pattern fails to match everything the more specific pattern does.

When I input this:               MatchQ[x*SF[a,b] + y*SF[c,d], Plus[Times[x,SF[a,b]],Times[y,SF[c,d]]]]       I get "True" as expected. But If I change it to:               MatchQ[x*SF[a,b] + y*SF[c,d], Plus[Times[_,SF[_,_]],Times[_,SF[_,_]]]]       Which ought to be more general, it returns false. Why does this happen? I think it's evaluate the Plus, and return a pattern like Times[2, _,SF[_ ,_]]. But how do I make it stop doing that? My goal is to Match the pattern for expressions like x*SF[a,b] + y*SF[c,d] + z*SF[e,f] ... So what do I have to do to fix this?


FindRoot Infinite expression 1/0 encountered error

I have 1 equation in 1 variable, which when I use `Plot`, looks like this:               i = 9     Plot[ A1[[i]]*(92)^(-1.7049946543060777) + B1[[i]]*(92)^(2.9716613209727445)-              c1[[i]]*80/0.057 + 65.89077138196083`, {H1S, 125, 135}, AxesOrigin -> {125, 0}]      ![enter image description here](http://i.stack.imgur.com/Fgo6x.jpg) Where,                A1[[9]]= -0.097752 H1S^2.70499-1.74292 H1S^4.67666 (-((0.213828 (-((1.70499                 (106.316-  0.166667 H1S))/H1S^2.70499)+0.166667/H1S^1.70499))/H1S^0.266667)               +(511.685 (-(0.0311244-80/H1S^1.70499) (685034./H1S^1.70499-0.000448489 H1S^2.97166)               +(0.0358792-71./H1S^1.70499) (877653./H1S^1.70499-0.000389055 H1S^2.97166)))/                (H1S^2.97166 (-(-0.662221+1702.13/H1S^1.70499)(685034./H1S^1.70499                                                             -0.000448489 H1S^2.97166)              +(-0.763386+1702.13/H1S^1.70499) (877653./H1S^1.70499-0.000389055 H1S^2.97166))));          B1[[9]]= (0.213828 (-((1.70499 (106.316-0.166667 H1S))/H1S^2.70499)               +0.166667/H1S^1.70499))/H1S^0.266667-(511.685 (-(0.0311244-80/H1S^1.70499)                (685034./H1S^1.70499-0.000448489 H1S^2.97166)+(0.0358792-71./H1S^1.70499)                (877653./H1S^1.70499-0.000389055 H1S^2.97166)))/(H1S^2.97166                (-(-0.662221+1702.13/H1S^1.70499) (685034./H1S^1.70499-0.000448489 H1S^2.97166)               +(-0.763386+1702.13/H1S^1.70499) (877653./H1S^1.70499-0.000389055 H1S^2.97166)));          c1[[9]]= -((-(0.0311244-80/H1S^1.70499) (685034./H1S^1.70499-0.000448489 H1S^2.97166)                 +(0.0358792-71./H1S^1.70499) (877653./H1S^1.70499-0.000389055 H1S^2.97166))/               (-(-0.662221+1702.13/H1S^1.70499) (685034./H1S^1.70499-0.000448489 H1S^2.97166)              +(-0.763386+1702.13/H1S^1.70499) (877653./H1S^1.70499-0.000389055 H1S^2.97166)));      But when I use `FindRoot` to get the same solution,               i = 9;     FindRoot[  A1[[i]]*(92)^(-1.7049946543060777) + B1[[i]]*(92)^(2.9716613209727445)              - c1[[i]]*80/0.057 + 65.89077138196083` == 0, {H1S, 125, 120, 135}]      I get two "things" and the messages :   * Infinite expression 1/0 encountered   * Further output of Power::Infy will be supressed during this this calculation and then it spits out what looks like the right solution if `Plot` is to be trusted               {H1S -> 128.907}      What am I doing wrong and how can solve this without the error messages? If the expressions was going to `Infinity` then it should show up on the `Plot` but the `Plot` looks well behaved. Perhaps some derivative is going to infinity during the `FindRoot` process. I have tried other methods specified in the "More Information" : `"Brent"` and `"Secant"` but am getting the same errors.


Finding a point from a set of contours such that it is nearest to a given point

I have several contour lines and one point. How can I find a point in one of those contour lines which is nearest to the given point?               (*Create the implicit curves*)     Data={{10,20,1},{10,40,2},{10,60,3},{10,80,4},{20,25,2},{20,45,3},{20,65,4},{30,30,3},{30,50,4},{40,35,4},{40,55,5},{50,20,4},{50,40,5},{60,25,5}};     U=NonlinearModelFit[Data,a x^b (y^(1-b))+c,{a,b,c},{x,y}];     L={ContourPlot[U[x,y]=={1},{x,0,100},{y,0,100},ContourStyle->Red],ContourPlot[U[x,y]=={2},{x,0,100},{y,0,100},ContourStyle->Magenta],ContourPlot[U[x,y]=={3},{x,0,100},{y,0,100},ContourStyle->Brown],ContourPlot[U[x,y]=={4},{x,0,100},{y,0,100},ContourStyle->Blue],ContourPlot[U[x,y]=={5},{x,0,100},{y,0,100},ContourStyle->Green]};     (*Point nearest to which we need to find the points on the curves*)     pt={30,50};     (*Graphic*)     Show[L,Graphics[{PointSize[Large],Blue,Point[pt]}],FrameLabel->{"X","Y"}]      ![enter image description here](http://i.stack.imgur.com/kElkt.jpg)


Using data from multiple cameras

`ImageCapture[]` has an option `Device->` for specifying which camera to use, but `CurrentImage[]` takes no options and no relevant arguments. Changing `$DefaultImagingDevice` might or might not work, but it would be a pretty awkward solution for a program that needs to frequently take frames from different cameras quickly. Is there a way to use `CurrentImage[]` with more than one camera? If not, is there a better workaround?


the way to save multidimensional array in text file

I have an array which is defined as a table, e.g.               g = Table[ cos[l1*3.]*sqrt[l2*1.]*l3 + l1*1 , {l1, 0, 3}, {l2, 0, 3}, {l3, 0, 3}];      then, I need to save it in the following format               1 1 1 g[1,1,1]          ...          i1 i2 i3 g[i1,i2,i3]      If I do something like               Do[ Export[ file, {i, g[[i, 2, 3]]}], {i, 1, 4}];      then it saves only the last line for `i == 4`: > >     4 >     3 + 2*cos[9.]*sqrt[1.] >   Another "subquestion" - is there a way to convert the `Table` to float? `N` doesn't help.


How to divide a graph into connected components?

Suppose I have some edges:               edges = {1 -> 2, 2 -> 3, 3 -> 1, 4 -> 5, 3 -> 6, 7 -> 8, 8 -> 9, 8 -> 10};      And I make a graph:               g = Graph[edges, VertexLabels -> "Name", ImagePadding -> 10]      ![graph with 3 connected groups](http://i.stack.imgur.com/mdiqd.png) After seeing the graph, you realize that there are three separate sub-graphs or families in it, and I want to see them separately. This is what I have done:               families = {Subgraph[g, {1, 2, 3, 6}], Subgraph[g, {4, 5}], Subgraph[g, {7, 8, 9, 10}]};     nMax = 3;     Manipulate[families[[n]], {n, 1, nMax, 1}]      ![manipulate generated graph viewer](http://i.stack.imgur.com/ZA36q.png) I would like to know how to calculate `nMax` and `families` automatically. My real problem has thousands of edges and it is not viable to do it visually.


Invert Colors Stylesheet White on Black

There have been a couple studies done that showed that white text on a black background increase recall of data. Although this is certainly debatable how might I invert the colors of Notebook font and background in Mathematica. There are likely more then a couple ways to do this(external software vs stylesheet). Currently I think the best solution likely involves using the built in Mathematica stylesheets, but currently(as mentioned in the comments) there doesn't appear to be a great way to do such.


What kind of check does DirectoryQ exactly perform?

I'm using _Mathematica_ 9.0.1 on Windows XP and my drive letters are assigned as follows: `C:` and `D:` are hard local disks, while `E:` is assigned to some removable media. Now, the situation is as follows               DirectoryQ[# <> ":\\"] & /@ {"c", "d", "e"}      returns `{True,True,True}`, even when an optical disk isn't in the drive. To outflank the problem I use a `directoryQ` function, defined in the code below. However, it obviously fails against a full hard disk or when I don't have write access. Therefore, I' m wondering about the kind of check `DirectoryQ` basically performs. Is there a better solution to fix the problem?                  directoryQ[unit_]:=Module[            {root,file,ret},            ret=False;            root=unit<>":\\";            file = FileNameJoin[{root, "testFile.txt"}];            If[              DirectoryQ[root],              Quiet[Export[file,"test","Text"]];              If[                FileExistsQ[file],                DeleteFile[file];                ret=True              ];            ];            Return[ret];     ];          directoryQ["c"]     directoryQ["e"]


How to plot population growth model?

How would I draw the graph of a function `dy/dt=((Ry^2)/T)-Ry` in _Mathematica_? I have tried a few times but the constants are confusing me.


Implementing an algorithm for finding the largest circle that contains a single point in a set (and no other point)

This question concerns the implementation of an algorithm proposed by Rahul Narain on a former question of mine that was migrated to math.stackexchange: http://math.stackexchange.com/questions/483845/finding-the-largest-circle- that-contains-a-single-point-in-a-set-and-no- other-p/484600?noredirect=1#484600 Here are the details for the algorithm I'd like to implement - Let $r(\mathbf q) = \min_{i=1}^n\|\mathbf q-\mathbf p_i\|$ be the largest radius of a circle centered at the coordinate $q$ containing some point $p_0$ (thus satisfying the requirement that $\|\mathbf q-\mathbf p_0\|\le r(\mathbf q)$) and containing no other point in the set $(p_0, p_1, ...) \in P$. We wish to find $q$ and $r(\mathbf q)$ for every point $p_i \in P$. To do so, Rahul Narain proposed the following steps:   1. Construct the Voronoi diagram $\mathcal V$ of $\{\mathbf p_0,\mathbf p_1,\ldots,\mathbf p_n\}$.   2. Let $C$ be the cell of $\mathcal V$ corresponding to $p_0$.   3. Evaluate $r(\mathbf q)$ for all vertices of $C$.   4. Construct the Voronoi diagram $\mathcal V'$ of $\{\mathbf p_1,\ldots,\mathbf p_n\}$. (There should exist efficient algorithms for removing a single point $p_0$ from a previously computed Voronoi diagram $\mathcal V$.)   5. Evaluate $r(\mathbf q)$ at all vertices of $\mathcal V'$ that lie inside $C$.   6. Choose the point from steps 3 and 5 with the largest $r(\mathbf q)$. The desired circle has center $q$ and radius $r(\mathbf q)$. The idea is that, by the definition of $r(\mathbf q)$ the center of the circle containing some $p_0 \in P$ is going to be closer to $p_0$ than any other point in the set $P$. Thus, we know that $q$ is going to fall in the Voronoi cell (which is a convex polygon) of $p_0$ since, by definition, this cell $C$ contains the set of points closer to $p_0$ than any other point in $P$. Rahul Narain then argues: "There are two possibilities: either the maximum lies in the interior of $C$, or it lies on its boundary. In the former case, it must be an unconstrained local maximum of $\min_{i=1}^n\|\mathbf q-\mathbf p_i\|$; any such maximum is a vertex of the Voronoi diagram of $\{\mathbf p_1,\ldots,\mathbf p_n\}$. In the latter case, if $q$ lies on an edge, you can always increase $r(\mathbf q)$ by moving along the edge, so the maximum must occur at a vertex of $C$." In other words, if $q$ for some point $p_0$ is inside $C$, then it's going to be a point that is as far away as possible from all other points in $P$ excluding $p_0$ (i.e. a vertex of the Voronoi diagram for $P-p_0$ falling inside the convex polygon $C$). Move away from this vertex, and you're strictly moving closer to at least one point in $P-p_0$. If $q$ lies on an edge of $C$, since $C$ is a polygon, any step along an edge will strictly move us closer to $p_0$ or further away, so $q$ must lie on a vertex of $C$. From this argument, which makes sense to me, we know that $q$ must lie on a vertex $C$, or a vertex inside $C$ in the Voronoi diagram $\mathcal V'$ of the points $\{\mathbf p_1,\ldots,\mathbf p_n\}$ missing the point $p_0$. * * * Here's where I am thus far with an implementation --- Let's first generate some random 2D coordinates:                numPoints = 10;      lowerboundPointRange = 0;      upperboundPointRange = 10;      randPoints = RandomReal[{lowerboundPointRange, upperboundPointRange}, {numPoints, 2}];      To plot the Voronoi diagram can write:               Get["ComputationalGeometry`"]     DiagramPlot[randPoints]      To return a set of vertices `vdVertices` for the Voronoi diagram $\mathcal V$, we can write:               VoronoiDiagram[randPoints]      Which returns something like this (if we set `numPoints = 4`):               {{{-5.08005, 20.1012}, {4.94272, 2.06684}, {10.0376, 2.1414}, Ray[{4.94272, 2.06684}, {2.70604, -2.84145}], Ray[{-5.08005, 20.1012}, {-9.26944, 26.3737}], Ray[{10.0376, 2.1414}, {15.9904, -0.261357}]}, {{1, {2, 1, 5, 4}}, {2, {3, 2, 4, 6}}, {3, {2, 3, 1}}, {4, {1, 3, 6, 5}}}}      We can understand this as, first, a set of vertices for the Voronoi cell $\mathcal V$, a list of rays defining edges for each Voronoi cell, and finally as a vertex adjacency list. If we just want the vertices, we can select for them with the command:               vdVertices = Select[VoronoiDiagram[randPoints][[1]], Head[#] == List &]      In terms of solving the problem of determining which vertices in $\mathcal V'$ fall in the Voronoi cell $C$ for some point $p_0$, we can use (rm -rf♦)'s answer to the question (How to check if a 2D point is in a polygon?), where he points out that one can use an internal function Graphics`Mesh`PointWindingNumber to check if a point is in a 2D polygon:               inPolyQ[poly_, pt_] := Graphics`Mesh`PointWindingNumber[poly, pt] =!= 0          (* Examples *)     inPolyQ[{{-1, 0}, {0, 1}, {1, 0}}, {1/3, 1/3}]     (* True *)     inPolyQ[{{-1, 0}, {0, 1}, {1, 0}}, {1, 1}]     (* False *)      For the moment I am stuck at not knowing how to do things like efficiently compute a Voronoi diagram $\mathcal V'$ missing a point from the Voronoi diagram $\mathcal V$, as Rahul Narain suggests, and also how to efficiently find the polytope vertices for $C$ given some $p_0$, and in general how to restrict the search for vertices in $\mathcal V'$ that fall in $C$. Also, there ought to be a better way to compute $r(\mathbf q) = \min_{i=1}^n\|\mathbf q-\mathbf p_i\|$ than scanning through each $p_i \in P-p_0$? Help on completing the implementation would be much appreciated.


FunctionInterpolation Errors / Question re Evaluation Order and Options

I have using Mathematica functions that takes a Cartesian coordinate relative to the Earth (xyz) and converts it to a latitude, longitude, and altitude (lla). And here it is:               xyz2lla = First@GeoPosition@GeoPositionXYZ[#, "WGS84"] &      I'm using it to convert a satellite viewing line (line of sight or los) from xyz to lla. For instance, if I have a satellite at the following observation point (obs, meters) looking in the direction of look:               obs = {2.560453600382259, 5.245110323032143, -3.819772142191310} 1*^6;     look = {-0.233218833096895, -0.814561997858160, -0.531128729720249};      It has the line of sight:               obs+d look      The transformation xyz2lla is smooth, so I was hoping to use function interpolation:               f = FunctionInterpolation[{xyz2lla[obs + # look]} &[d],                                {d, 2000000, 3700000}         ]      And while this works, and I get the following lat, lon, alt functions from it: ![enter image description here](http://i.stack.imgur.com/ualb4.png): ![enter image description here](http://i.stack.imgur.com/EQJ7u.png) ![enter image description here](http://i.stack.imgur.com/95dPs.png) I also get the following errors that I'm wondering why I get:               GeoPositionXYZ::invcoord: "\!\(\"{2.560453600382259*^6 - 0.233218833096895*d, 5.245110323032143*^6 - 0.81456199785816*d, -3.81977214219131*^6 - 0.531128729720249*d}\"\) is not a valid coordinate specification."          Thread::tdlen: Objects of unequal length in {-212500.,-70833.3,70833.3,212500.}^{} cannot be combined. >>          Thread::tdlen: "Objects of unequal length in {12.2667 +3.14159\ I,11.1681 +3.14159\ I,11.1681,12.2667}\ {}\\n cannot be combined."          FunctionInterpolation::nreal: Near d = 2.2125`*^6, the function did not evaluate to a real number.      Does anyone have any insight into these errors? Also, how can I adjust the quality of the interpolation / how many points are investigated?


Median marker style in BoxWhiskerChart

I was trying to adapt the `BoxWhiskerChart` to obtain a minimalistic quartile plot, like this: ![Quartile plot](http://i.stack.imgur.com/F1mF4.png) What I obtained is the plot below that is, however, unsatisfying; the median markers should be circles, but they are instead slightly squared. ![Quartile plot with wrong median markers](http://i.stack.imgur.com/G7n4K.png) The code:               data = Table[        RandomVariate[NormalDistribution[μ, 1], 100], {μ,          RandomInteger[{-2, 2}, 10]}];     filledCircle[size_] := Graphics[{Black, Disk[]}, ImageSize -> size];     BoxWhiskerChart[data,       {{"Whiskers", Black},        {"MedianMarker", filledCircle[10], Black},        {"Fences", None}},       ChartBaseStyle -> White,       Frame -> False,       Method -> {"BoxRange" -> (Quantile[#,              Range[0, 1, 1/4], {{1/2, 0}, {0, 1}}] &)}       ]      As an alternative, I've tried to rasterize the circles; the shape is now correct, but we get a lateral shift of the median marker.               filledCircle[size_] := Rasterize[Graphics[{Black, Disk[]}, ImageSize -> size]];      ![Quartile plot with shift](http://i.stack.imgur.com/T8F1p.png) Does anyone have a better approach or solution? Or should I just build my own function?


Map a function conditional on elements at multiple relative positions in a list

I figure this question has many solutions, and if an answer already exists it would be nice just to be referred to it. I need a function that 'maps' over my list and produces a list of equal length of either 1 or 0 with particular conditions that switch the the result from 1 to 0. The result starts as `0` and is carried into the next step unless one of these conditions is met:   1. That when both the first and element is `1` we set our result to `1`; this can happen on the first element of the list.   2. When the last element is `0` we set our result to `0`.   3. However if we don't find a `1` at position two in any even numbered list counting from the switch to `1` before the next switch back to `0`, then leave the result as 0 for the entire period. Essentially step 3 requires that if for the period that the result could be 1 (according to steps 1. and 2.) that at least once the even numbered elements in that period have [[2]]=1. For example if the data is `{{0, 0, 1}, {1, 0, 1}, {0, 0, 1}, {1, 0, 1}, {0, 0, 1}, {1, 0, 1}, {0, 0, 0}}` then the result of this algorithm is `{0, 0, 0, 0, 0, 0}`. Without the third condition it would yield `{0, 1, 1, 1, 1, 1, 0}`. However if the data is `{{0, 0, 1}, {1, 0, 1}, {0, 1, 1}, {1, 0, 1}, {0, 0, 1}, {1, 0, 1}, {0, 0, 0}}` (note the third element has a 1 at position 2 which meets the criteria that is in the element that is in a odd position after the switch, in this case 1 element after), then the result should be `{0, 1, 1, 1, 1, 0}`. So far I have tried a Which function in a Table. This is fine for steps 1. and 2., but not so good for 3.               Table[      Which[       i == 1 && data[[i, 1]] == 1 && data[[i, -1]] == 1, 1,       i == 1, 0,       i > 1 && (data[[i, 1]] == 1 || data[[i, 2]] == 1) &&         data[[i, -1]] == 1, 1,       i > 1 && (data[[i - 1, 1]] == 1 || newALtest[[i - 1, 2]] == 1) &&         data[[i - 1, -1]] == 1 && data[[i, -1]] == 1, 1,       i > 1, 0], {i, 1, Length[data]}]      Some example data is here               data={{0, 0, 0}, {0, 0, 0}, {0, 0, 1}, {1, 0, 1}, {0, 0, 1}, {1, 0, 1}, {0, 0, 1}, {1, 0, 1}, {0, 0, 0}, {0, 0, 0}, {1, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {1, 0, 0}, {1, 0, 1}, {0, 1, 1}, {1, 0, 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}, {1, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 1}, {1, 0, 1}, {0, 1, 1}, {0, 0, 0}, {0, 0, 1}, {0, 0, 1}, {1, 0, 1}, {0, 1, 1}, {0, 1, 1}, {0, 1, 1}, {0, 1, 1}, {0, 1, 1}}      Any tips about the approach to take would probably get me heading in the right direction (I'm trying steps 1. and 2. first, then using that result for another test, but I'm still mighty confused). For the above table, the result will be               result= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1}


NSolve gives additional solutions that don't satisfy the equations!

I am trying to solve the following polynomial equations in Mathematica:               e= {-1 + c[1]^2 + s[1]^2, -1 + c[2]^2 + s[2]^2, -1 + c[3]^2 + s[3]^2, -1 +            (-0.70873 c[1] + c[2] - 0.70548 s[1]) y1[ 1], -1 + (-0.916596 c[2] + c[3] +           0.399814 s[2]) y1[ 2], -1 + (c[1] + 0.808085 c[3] + 0.589066 s[3]) y1[ 3],          -1 + (c[1] + 0.808085 c[3] + 0.589066 s[3]) y2[ 1], (-0.70548 c[1] +          0.70873 s[1] + s[2]) y1[ 1] - (-0.589066 c[3] + s[1] + 0.808085 s[3])         y2[1], -1 + (-0.70873 c[1] + c[2] - 0.70548 s[1]) y2[ 2], (0.399814 c[2] +        0.916596 s[2] + s[3]) y1[ 2] - (-0.70548 c[1] + 0.70873 s[1] + s[2]) y2[ 2],         -1 + (-0.916596 c[2] + c[3] + 0.399814 s[2]) y2[ 3], (0.589066 c[3] - s[1] -       0.808085 s[3]) y1[ 3] - (0.399814 c[2] + 0.916596 s[2] + s[3]) y2[3]}      using `NSolve` command. i.e.,               sol = NSolve[e==0, Variables[e]]      I am only interested in real solutions, so in principle I could also use               NSolve[e==0, Variables[e], Reals].      The command indeed solves this system and gives me 8 solutions, all real. However, when I insert them back to the equations to check if the solutions satisfy the equations, they don't!               Do[ Print[eatsol[i] = e /. Thread[var -> sol[[i]]]], {i, lrealsol}]      gives > >     {-1.,-1.,-1.,-1.,-1.,-1.,-1.,0.,-1.,0.,-1.,0.} >     {-1.,-1.,-1.,-1.,-1.,-1.,-1.,0.,-1.,0.,-1.,0.} >     {-1.,-1.,-1.,-1.,-1.,-1.,-1.,0.,-1.,0.,-1.,0.} >     {-1.,-1.,-1.,-1.,-1.,-1.,-1.,0.,-1.,0.,-1.,0.} >     {-1.,-1.,-1.,-1.,-1.,-1.,-1.,0.,-1.,0.,-1.,0.} >     {-1.,-1.,-1.,-1.,-1.,-1.,-1.,0.,-1.,0.,-1.,0.} > > {0.,6.93889*10^-17,7.97973*10^-17,0.,-1.11022*10^-16,-1.11022*10^-16,-1.11022*10^-16,-4.47201*10^-17,0.,1.4905*10^-17,-1.11022*10^-16,-1.82678*10^-18} > > {0.,6.93889*10^-17,7.97973*10^-17,0.,-1.11022*10^-16,-1.11022*10^-16,-1.11022*10^-16,-4.47201*10^-17,0.,1.4905*10^-17,-1.11022*10^-16,-1.82678*10^-18} >   Thus, the first 6 solutions don't even remotely satisfy the equations! I would be fine with some numerical errors etc. but it seems that the infinite solutions also appear here. Do you know what is going on here? Is there any problem with `NSolve`? Update: Please run the below code in Mathematica:               Clear["Global`*"];     e = {-1 + c[1]^2 + s[1]^2, -1 + c[2]^2 + s[2]^2, -1 + c[3]^2 +          s[3]^2, -1 + (-0.5646917067485537` c[1] + c[2] -             0.8253019304045068` s[1]) y1[1], -1 + (0.5033628291371058` c[2] + c[3] -             0.8640751484929357` s[2]) y1[2], -1 + (c[1] - 0.47880555467239877` c[3] +             0.877920976406679` s[3]) y1[3], (-0.8253019304045068` c[1] +             0.5646917067485537` s[1] + s[2]) y1[1] - (-0.877920976406679` c[3] + s[1] -             0.47880555467239877` s[3]) y2[1], -1 + (c[1] - 0.47880555467239877` c[3] +             0.877920976406679` s[3]) y2[1], -1 + (-0.5646917067485537` c[1] + c[2] -             0.8253019304045068` s[1]) y2[2], (-0.8640751484929357` c[2] -             0.5033628291371058` s[2] + s[3]) y1[2] - (-0.8253019304045068` c[1] +             0.5646917067485537` s[1] + s[2]) y2[2], -1 + (0.5033628291371058` c[2] + c[3] -             0.8640751484929357` s[2]) y2[3], (0.877920976406679` c[3] - s[1] +             0.47880555467239877` s[3]) y1[3] - (-0.8640751484929357` c[2] -             0.5033628291371058` s[2] + s[3]) y2[3]};     var = Variables[e];     sol = NSolve[e == 0, var];     lsol = Length[sol];     Do[      Print[Chop[e /. sol[[i]]]],      {i, lsol}]      > >     {-1.,-1.,-1.,-1.,-1.,-1.,0,-1.,-1.,0,-1.,0} >     {-1.,-1.,-1.,-1.,-1.,-1.,0,-1.,-1.,0,-1.,0} >     {-1.,-1.,-1.,-1.,-1.,-1.,0,-1.,-1.,0,-1.,0} >     {-1.,-1.,-1.,-1.,-1.,-1.,0,-1.,-1.,0,-1.,0} >     {-1.,-1.,-1.,-1.,-1.,-1.,0,-1.,-1.,0,-1.,0} >     {-1.,-1.,-1.,-1.,-1.,-1.,0,-1.,-1.,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} >   Basically, the problem is that the solutions given by the `NSolve` command are not actually the solutions of the equations!


expression in an string

I want to create several directories `"dir_i"` in a mother directory `"home"`. and put an specific file in each directory `"file_j"`. so that I will have `home/dir_1/file_a`, `home/dir_2/file_b`,...               Table[CreateDirectory["home/dir_i"],{i,1,10}]      obviously doesn't work because `"home/dir_i"` is a string not an expression.


Populating and storing a very large array in Mathematica

I am using Mathematica 8 to generate a very large multidimensional array of floating-point numbers and then store it in a file. Typical array sizes are 10000 x 50 x 15 x 40, resulting in a 3-4 GB file. The entries of the array are generated recursively, after computing a few starting values. After computations finish (about 12 hours), **Mathematica appears to hang while writing the array, for 8 or more hours.** Sometimes the program doesn't finish within a 24 hour time limit (imposed by the systems I'm using), and no file is produced (not even a partial one). I am wondering: what are some strategies for dealing with these large arrays in Mathematica, and ensuring writing to a file happens successfully? Some background: the array is allocated in memory, and then populated using some initial values and a recursion relation               prec = 50;     GenerateMyArray[iMax_,jMax_,kMax_,lMax_] := Module[{myArray},       myArray = ConstantArray[SetPrecision[0.0, prec], {iMax, jMax, kMax, lMax}];            (* do something to populate initial entries *)       ...            (* populate the rest with a recursion relation *)       Do[         myArray[[i,j,k,l]] = Evaluate[myRecursionRelation],         {i,1,iMax},         {j,1,jMax},         {k,1,kMax},         {l,1,lMax}       ];       myArray     ];      (The calculations must be done at high precision, although the array is eventually stored at lower precision). Finally, I write the entries to a file               mp[x_] := NumberForm[SetPrecision[x, 16], 16, ExponentFunction -> (Null &)];              myArray = GenerateMyArray[10000, 50, 15, 40];     w = OpenWrite[myFileName];     writeHeader[w];     Do[WriteString[w, mp[x], "\n"],         {irow,myArray},         {jrow,irow},         {krow,jrow},         {x,krow}];     Close[w];      My understanding of when things are being passed by value and when they're being passed by reference in Mathematica is pretty poor. Perhaps large amounts of data are being copied unnecessarily? I would appreciate help making this process more efficient and robust. Additional note: The output will be read by a non-Mathematica program, so using .mx files is not an option.


Using the keyboard to interactively and dynamically specify coordinates in a grid (a la Battleship board game)

In Mathematica, it is possible to create a `Table` or `Grid` of `\\[Placeholder]` boxes. For example, I can make a 3-by-3 `Grid` of `\\[Placeholder]` boxes:               Grid[      Table[\[Placeholder], {3}, {3}],      Frame -> All, ItemSize -> Full]      > ![Grid](http://i.stack.imgur.com/638FP.png) Then, I can click on one of the placeholders (for example, the top left-hand placeholder) to change focus to it: > ![GridFocus](http://i.stack.imgur.com/HgSKc.png) Once focus is on one of the placeholders, I can use the arrow keys on the keyboard or the `Tab` key to change the focus to one of the other placeholders (at least in Windows XP; I have not tested this on later versions of Windows or Mac or Linux). Using the `Tab` key is particularly handy, because it cycles through the placeholders in the "canonical" order (i.e., cells **{1,1}, {1,2}, {1,3}, {2,1}, {2,2}, {2,3}, {3,1}, {3,2}, {3,3}** where the elements are **{row index, column index}** ): ![GridTab](http://i.stack.imgur.com/3ImAE.png) But, it can somewhat of a chore to cycle through the placeholders using `Tab`, especially for large _n_ -by- _n_ grids. My question is, **is it possible to interactively change focus in a grid _using the keyboard_?** For example, suppose that I label the rows with letters and the columns with numbers:               TableForm[      Table[\[Placeholder], {3}, {3}],      TableHeadings -> {{"a", "b", "c"}, {"1", "2", "3"}}]      > ![GridLabeled](http://i.stack.imgur.com/2HmwP.png) Is there any way to write a function in which I could type **"b2"** , for example, using the keyboard and have Mathematica automatically change focus to the placeholder at **coordinate b2** , like the following? > ![GridLabeledFocus](http://i.stack.imgur.com/1ZWzx.png) With the focus now at **"b2"** , I can mark this coordinate it in some way, perhaps by typing an **"x"** : > ![GridLabeledFocusMarked](http://i.stack.imgur.com/5NhrG.png) Remember the board game _Battleship_? It is basically a game of placing **"x"** at "hit" coordinates (and placing nothing at "miss" coordinates): ![BoardGame](http://i.stack.imgur.com/iNYgL.png) I would like to use Mathematica to specify and mark coordinates in a grid _interactively, using the keyboard._ It doesn't matter _how_ the coordinates are marked. In other words, I don't necessarily need the script to change `\\[Placeholder]` focus in a `Grid`; I just need to be able to specify coordinates such as **"b2"** interactively (i.e., in real time, not from a list of predefined coordinates) and be able to mark those coordinates in some way. So, in this sense, it doesn't necessarily need to be a `Grid` of `\\[Placeholder]`s. It could be a `Grid` of `Checkbox`es. It could be a `Grid` of `Rectangle`s that change color when specified using the keyboard. In other words, **the important feature I am looking for is to use the keyboard to specify coordinates** , not mouse clicks. Do you have any initial thoughts of how I can accomplish this? Do I need to use `Input` or `InputField`, or are there other ways to get keyboard input from the user? Thanks so much for your time and help.


Check does not interrupt evaluation of the expression when a Message is emitted

On the surface, `Check` looks like a good method to use when you need to abort the evaluation of an expression whenever a `Message` is emitted. Unfortunately, as the following code demonstrates, the evaluation of the expression is completed after a `Message` has occurred.               (* the test message *)     Test::wrpt = "Negative point at `1`";          dat = RandomReal[1, 500];          (* without Check *)     woCheck = MapIndexed[        If[# < 0,           Message[Test::wrpt, #2[[1]]]; Unevaluated[Sequence[]],           #] &,        {-1}~Join~dat];          (* with Check *)     res = {};     Check[      MapIndexed[       If[# < 0,          Message[Test::wrpt, #2[[1]]]; Unevaluated[Sequence[]],          res = {res, #}; #] &,       {-1}~Join~dat],      $Failed      ]      (* Test::wrpt: Negative point at 1       $Failed      *)      But, when comparing the two               woCheck == Flatten@res     (* True *)      This implies, that for long running computations `Check` is not a good solution to abort a computation if an error `Message` is emitted. Can this be fixed?


How can I make my code simpler?

I want to find similar letters               charList = CharacterRange["a", "l"];     ls = ImageData@Binarize@Rasterize@# & /@ charList;     Table[{i}~Join~Nearest[Complement[ls, {i}], i, 1], {i, ls}];     % /. Rule @@@ Table[{ImageData@Binarize@Rasterize@ii, ii}, {ii, charList}]     GraphPlot[Rule @@@ %, DirectedEdges -> True, VertexLabeling -> True]     Clear["`*"]      I think my code could be better. How can I refactor it?


Question about MapThread and Dynamic

I don't understand the following:                 f[a_, b_] := a + b       ls = {1, 2, 3};       MapThread[f, {ls, {10, 20, 30}}]      This yields ( as expected ) {11,22,33} If I change the code to                 f[a_, b_] := a + b       ls = {1, 2, 3};       MapThread[f, {Dynamic[ls], {10, 20, 30}}]      mma returns the following message:                 MapThread::mptd: Object {1,2,3} at position {2, 1} in MapThread[f,{{1,2,3},{10,20,30}}] has only 0 of required 1 dimensions. >>      **Question: Why does this happen? How can it be fixed?**


Reuse a dynamic list

Consider this `Dynamic` list               Slider[Dynamic@i, {Range[2, 10]}]     MapThread[DirectedEdge, Gather[##] & /@ (Range[#] & /@ Dynamic@i)]      The error is > List expected at position 2 in `MapThread[...]` . Although the output given by the function is correct:               MapThread[DirectedEdge, {{1}, {2}}]     (* {1 -> 2} *)      **Edit:** The purpose of the list creating above is to create a list being exploited by `Graph`:               DynamicModule[{p = {{0, 0}, {2, 2}}, i = 2},          Grid[{         {Dynamic[DirectedEdge @@ Range@i],          Dynamic@N@Round[MousePosition["Graphics"], 0.5]},         {(Dynamic@Thread[{{DirectedEdge @@ Range@i}, {p}}]),           EventHandler[Dynamic@Graph[{DirectedEdge @@ Range@i},             VertexCoordinates -> p, PlotRange -> 5, GridLines -> Automatic,             Frame -> True,              FrameTicks -> All], "MouseDown" :>         {(AppendTo[p, N@Round[MousePosition["Graphics"], 0.5]];),++i}]}           }, Frame -> All]]      ![enter image description here](http://i.stack.imgur.com/AUK8F.png) With at the top the construction of the `DirectedEdge` and the location of the mouse, at the bottom my attempt to see what should the list look like in order to be replaced in               Graph[{#1},VertexCoordinates -> #2]      Once again I assume that it's a `Dynamic` issue.


Trying to access element of a matrix

> **Possible Duplicate:**   >  Question about MapThread and Dynamic I'm trying to extract element of a matrix. Let's suppose that the matrix is               ACC = {{1, 0, 0, 1}, {0, 0, 0, 2}, {0, 0, 0, 3}, {0, 0, 0, 1}}      then               ACC[[1,4]]      will return 3. I don't understand why Mathematica is giving me the error Part::partw when trying to get the value [[1,x]] with x>1 of the following matrix Rbar: (sorry for the code but it wont work otherwise)               Avz[\[Theta]z_,         dz_] := {{Cos[\[Theta]z], -Sin[\[Theta]z], 0, 0}, {Sin[\[Theta]z],          Cos[\[Theta]z], 0, 0}, {0, 0, 1, dz}, {0, 0, 0, 1}};          Avx[\[Theta]x_,         dx_] := {{1, 0, 0, dx}, {0, Cos[\[Theta]x], -Sin[\[Theta]x],          0}, {0, Sin[\[Theta]x], Cos[\[Theta]x], 0}, {0, 0, 0, 1}};          Linea[tz_, dz_, tx_, dx_] := Avz[tz, dz].Avx[tx, dx];          Grid[{{"", "Theta", "d", "Alpha", "a"}, {"Link1",         InputField[Dynamic[t1], FieldSize -> 3],         InputField[Dynamic[d1], FieldSize -> 2],         InputField[Dynamic[alpha1], FieldSize -> 4],         InputField[Dynamic[x1], FieldSize -> 1]}},       Frame -> Darker[Gray, .6], Alignment -> {{Left, {Center}}}]               Rt = {{1, 0, 0, -L1/2}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}};          Rbar = Dynamic[Linea[t1, d1, alpha1, x1].Rt]      here Rbar[[1,4]] for example returns error, but why?


I'm definitely giving an integer, but I get Nest::intnm

I am attempting to make a small interactive plot that displays the plot of `Cos` iterated `its` times. Whenever I try to evaluate my cell, however, I get a `Nest:intnm` error, something like:               Nest::intnm: Non-negative machine-sized integer expected at position 3 in Nest[Cos,0.000128356,100].      As you can see, the 3rd argument for `Nest` is an integer, but Mathematica is not happy with it. Here is my code:               DynamicModule[{its=100},Column[{Plot[Nest[Cos,x,Dynamic[its]],{x,0,2\[Pi]}],Slider[Dynamic[its],{1,500,1}]}]]      I've tried changing `Nest[Cos,x,Dynamic[its]]` to `Nest[Cos,x,IntegerPart[Dynamic[its]]]` (so as to catch any sort of glitch where `100` was not seen as an integer) with no avail. This is my first time dealing with anything dynamic, or even sliders, so any help is appreciated.


Why does ; suppress Dynamic output?

`Dynamic[x=7];` does not make `x` dynamic! But `Dynamic[x=7;]` makes `x` dynamic with initial value 7. The problem with the later is the presence of `Null` in the output. My question is: how can I assign a (big) value (or a huge list, etc.) to a dynamic variable AND suppress any possible output (including `Null`)?


Using Hold correctly with Simplify and ComplexityFunction

It seems like Mathematica immediately evaluates the expression `Sqrt@I` to `(-1)^(1/4)`. I'm trying to use `Simplify` with my own `ComplexityFunction f` in such a way, that `Simplify[Sqrt@I]` returns `Sqrt@I`, which (in my opinion) is the simpler expression. Hence, I've defined the following `f`:               Attributes[f]=HoldAll;     f[expr_]:=StringLength@ToString@HoldForm@expr      Testing it yields the expected results:               f[Sqrt@I]     f[(-1)^(1/4)]      > 7 > > 12 Now, when I call `Simplify[Sqrt@I, ComplexityFunction->f]` it still returns `(-1)^(1/4)`. I believe this is due to the fact that after the simplification (which should return `Sqrt@I`), the expression is in turn evaluated to `(-1)^(1/4)`. Can I define `f` in such a way that this last evaluation is not performed? Can I use `HoldForm` to achieve this?


Error about limit MaxExtraPrecision

After my evaluations I have an error: `N::meprec: Internal precision limit $MaxExtraPrecision=50. reached while evaluating ...` `General::stop: Futher output of N::mecprec will be supressed during this calculation.` As as I might guess, the problem is that I am evaluating very big numbers, and the precision limit is ended. But what that means for my number: how big will be the suppression? Can I do something to reduce this error? If the suppression is not very big (for example only from the 50th decimal number), how can I store this value, to have possibility to use them in `Reduce` function, because when I want to use this value I have an error: `Unable to decide whether numeric quantity ... is equal to zero. Assuming it is.` How can I make to NOT assuming it is zero?


LibraryLink: is WolframLibraryData libData persistent?

I am writing some C++ code that I want to call both through LibraryLink and independently from Mathematica. Thus it must be compatible with LibraryLink but not depend on it. When calling it from Mathematica, I want to make it abortable. All LibraryLink functions take an argument `WolframLibraryData libData` (this is really a pointer). `AbortQ` is called through it. **Question:** Is it safe to cache the value of `libData` in a global variable, never change it after `WolframLibrary_initialize`, and use this global variable for calling all LibraryLink functions? To make the question clearer, this is the layout of my code:               WolframLibraryData libData; // global variable          EXTERN_C DLLEXPORT int WolframLibrary_initialize(WolframLibraryData iLibData) {         libData = iLibData;         return LIBRARY_NO_ERROR;     }          class MyClass      {     public:         void simulate() {             for (...) { // long loop                 ...     #ifdef WolframLibraryVersion  // use the global libData here:                 if (libData->AbortQ) { /* abort computation */ }     #endif             }         }     }      Cross posted to Wolfram Community.


Help with Computation-heavy triple integration

I'm Trying to use Mathematica to symbolically integrate a function with respect to x, y, and z. For some reason, this computation either takes about, 60s and returns the input, or takes many hours and doesn't seem to finish. here is a screenshot of the problem. This is an attempt to integrate the gravitational potential equation over x, y, and z. The constants have been pulled out of the integration in order to try and reduce computation error or time. ![integration of gravitational force](http://i.stack.imgur.com/eJ9ll.png) as you can see, at this moment in time, mathematica has been working for over 20,000 seconds (running about 30% on i7 @ 2.8ghz. I feel like perhaps there is an error in my formatting, because i've run into many problems attempting to perform similar integration. I've used assumptions in past attempts, but they've haven't proved useful. any suggestions?


Confused by (apparent) inconsistent precision

$$ e^{\pi \sqrt{163}} \approx 262537412640768743.99999999999925 $$               E^(Pi Sqrt[163.0])     N[E^(Pi Sqrt[163.0]), 35]     NumberForm[E^(Pi Sqrt[163.]), 35]      returns               2.6253741*10^17     2.6253741*10^17     2.625374126407682*10^17      That's not the 35 digits I expected. OTOH,               N[Pi* E, 35]      returns 35 digits,               8.5397342226735670654635508695465745      but then               NumberForm[Pi*E*1., 35]      again doesn't:               8.53973422267357      So I'm confused. Why doesn't one `N[]` what the other one does? In the documentation: > **NumberForm** [ _expr_ , _n_ ]   >  prints with approximate real numbers in _expr_ given to _n_ -digit > precision. I read this three times, slowly, went for a cup of tea, and read it again. But 15 isn't 35, or is it?


Improving working precision of LegendreP[n,x]?

I was trying to evaluate               N[LegendreP[5,0.1]]      The cell gives me:               N[LegendreP[5,0.1]]=0.178829      However I wanted more precision digits. I tried to use:               N[LegendreP[5,0.1],20]      But the result is the same. Interestingly, if I try with                N[LegendreP[5,1],20]      The result showed significantly increased digits               1.0000000000000000000      Is there a way that we can evaluate LegendreP more accurately?


Does InterpolationOrder cause conflicts with PlotMarkers in ListPlot?

My code:               data = {MapIndexed[{First[#2], #1} &,          Accumulate[RandomInteger[{-1, 1}, {54}]]],         MapIndexed[{First[#2], #1} &,          Accumulate[RandomInteger[{-1, 1}, {34}]]]};          ListPlot[data,      Axes -> False,      AspectRatio -> 0.75,      Frame -> True,      InterpolationOrder -> {0, 0},      ImageSize -> {400, 300},      ImageMargins -> 0,      Joined -> True,      PlotMarkers -> {{"\[FilledCircle]", 11}, {"", 11}}      ]      On OS X 10.6.8 V8.0.4 I get this output: ![enter image description here](http://i.stack.imgur.com/wY9QM.png) You will note that the filled circle plot markers have been "distributed" across both sets of data. However if I change the `InterpolationOrder` setting to say:               InterpolationOrder -> {0, None}      ...then no markers appear for the second set of data (due to the markers being an empty string). ![enter image description here](http://i.stack.imgur.com/nMOMP.png) Could someone please advise me if the cause of this behaviour is due to me setting these options incorrectly? Any ideas?


Simplifying Fourier transform of a complicated function

I would like to evaluate the following expression but takes too much time. I would be greatly appreciate for any comments to make it fast.               Clear[a, b];          FullSimplify[      FourierTransform[       Exp[-1/2 (1 - s) (a^2 + b^2)]*(α4 1/2 Sqrt[            6] (1/Sqrt[2] (a + I b))^4 - α1 α4 1/(2 Sqrt[               6]) (1/Sqrt[2] (a + I b))^3 (-(a^2 + b^2)/2 +              4) + α2 α4 1/(2 Sqrt[3]) (1/               Sqrt[2] (a + I b))^2 ((a^2 + b^2)^2/8 - 2(a^2 + b^2) +              6) + α4^2 1/            24 ((a^2 + b^2)^6/16 - 2 (a^2 + b^2)^3 + 18 (a^2 + b^2)^2 -              48 (a^2 + b^2) + 24) + α2 1/            Sqrt[2] (1/Sqrt[2] (a + I b))^2 - α1 α2 1/            Sqrt[2] (1/Sqrt[2] (a + I b)) (-(a^2 + b^2)/2 +              2) + α2^2 ((a^2 + b^2)^2/8 - (a^2 + b^2) +              1) + α2 α4 1/(2 Sqrt[3]) Conjugate[             1/Sqrt[2] (a + I b)]^2 ((a^2 + b^2)^2/8 - 2 (a^2 + b^2) +              6) + α1 (1/              Sqrt[2] (a + I b)) - α1^2 (-(a^2 + b^2)/2 +              1) - α1 α2 1/Sqrt[2] Conjugate[            1/Sqrt[2] (a + I b)] (-(a^2 + b^2)/2 +              2) - α1 α4 1/(2 Sqrt[6]) Conjugate[             1/Sqrt[2] (a + I b)]^3 (-(a^2 + b^2)/2 + 4) +           1 + α1 Conjugate[1/Sqrt[2] (a + I b)] + α2 1/            Sqrt[2] Conjugate[             1/Sqrt[2] (a + I b)]^2 + α4 1/(2 Sqrt[6]) Conjugate[             1/Sqrt[2] (a + I b)]^4), {a, b}, {x, y}], {-1 < s < 1}]


Circular Plot and Circular Histogram

The spherical or circular data arises when we measure data in degree e.g wind direction, clock and compass etc. Then representation of such data we need to plot circular plot, circular histogram and rose diagram. How to plot this data? for example we have data               data={8,9,13,13,14,18,22,27,30,34,38,38,40,44,45,47,48,48,48,48,50,53,56,57,58,58,61,63,     64,64,64,65,65,68,70,73,78,78,78,83,83,88,88,88,90,92,92,93,95,96,98,100,103,106,113,118,138,     153,153,155,204,215,223,226,237,238,243,244,250,251,257,268,285,319,343,350}      These are the 76 directions measured in degree clockwise from north. The specimen of circular plot, circular histogram and rose diagram are given below ![Circular Plot data given above](http://i.stack.imgur.com/7tUxQ.png) Circular Plot (data given above) ![Circular Histogram](http://i.stack.imgur.com/dBCNK.png) Circular Histogram (not above data) ![Rose Diagram](http://i.stack.imgur.com/THvea.png) Rose Diagram (not above data) Note: Any appropriate interval is to be taken for circular histogram from the given data.


"Reset" Button for Manipulate

I want to distribute a .cdf to my students wherein they manipulate 5 locators on a graph to define various shapes. The .cdf opens with the locators in a "nice" position, but of course it is very hard to return the locators, by hand, to these positions once they have been moved. Is there a way to utilize a "Reset" button that returns all settings to the original state? The only method I can see right now is to reopen the file in the CDFPlayer.


Time varying Poisson rate using ParameterMixtureDistribution

I have a system in which there is a Poisson arrival process with rate $\lambda$. I need to split this process into two independent poisson processes $\lambda_i$ and $\lambda_u$. Where $\lambda_i=p(t)\lambda$ and $\lambda_u=(1-p(t))\lambda$. $p(t)$ is a deterministic function which is defined as the CDF of the Lognormal Distribution. I am using `ParameterMixtureDistribution`, but cannot get it to recognise the CDF of the log-normal distribution.               PDF[ParameterMixtureDistribution[ExponentialDistribution[t/600],            t \[Distributed] CDF[LogNormalDistribution[1, 2], t],       t]]      Does anyone know how I can achieve my goal of modelling a time varying rate of the Poisson process?


Is Mathematica 8 compatible with Mac OS X 10.9?

Does anyone know if _Mathematica 8_ works with _OS X 10.9_?


adding a 1 to all second elements

I want to add 1 to all second elements but I am running into a "level" problem I believe here is my code:               list2 = {{{5, 1}}, {{2, 1}, {3, 1}}, {{7, 1}}, {{2, 3}}}          r1pow = Map[(# + {{0, 1}}) &, list2]      the result I got is:               {{{5, 2}}, {{0, 1}} + {{2, 1}, {3, 1}}, {{7, 2}}, {{2, 4}}}      my desired result is:               {{{5, 2}}, {{2, 2}, {3, 2}}, {{7, 2}}, {{2, 4}}}      as you can see it is giving a problem for my second element {{2, 1}, {3, 1}}, how can i fix this problem?


I cannot get tables names and columns names from database

I am working with database using OpenSQLConnection-JDBC. I am able to fetch the data perfectly from the tables but I cannot get nor the names of the tables (using SQLTableNames) neither the column names (using SQLColumnNames). I tried also to work with the help examples; but I got same problem. what could be the reason?               conn = OpenSQLConnection[        JDBC["MySQL(Connector/J)",         "IP/databasename"],        "Username" -> "username", "Password" -> "password"]          eventsdata = SQLSelect[       conn, "tablename",       SQLColumn["columnname"] == somevalue]      where: IP= Ip address of the database, databasename=database name that I am connecting to, tablename=table name which I have it before, columnname=columns names of the table that I have it before, somevalue=value so that I can fetch some of the data.


Interactively Manipulate Code

Bear with me, I'm a noob; I simply want to create a radio button bar that selects whether I want to add or subtract two numbers:               {RadioButtonBar[Dynamic[stringvar], {"*" -> "Multiply Numbers", "+" -> "Add Numbers"}]}      And my equation might simply be:               2 + 2      And I just want to change the + to a * interactively. Not sure if this is the right way to do it. Thanks.


How can I specify the exact colors two Polygons in plots combined with Show?

I made two `Polygons` with different colors. Their names are `p1` and `p2`.               p1Color = Red;     p2Color = Green;     w = 30;     h = 40;     l = 50;     p1 = Graphics3D[{p1Color,      Polygon[{{0, 0, 0}, {0, h, 0}, {w, h, 0}, {w, 0, 0}},        VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]},        Boxed -> False,       Lighting -> {{"Ambient", p1Color}},        RotationAction -> "Clip"];     p2 = Graphics3D[{p2Color,      Polygon[{{0, 0, l}, {0, h, l}, {w, h, l}, {w, 0, l}},        VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]},        Boxed -> False,       Lighting -> {{"Ambient", p2Color}},        RotationAction -> "Clip"];     {p1, p2, Show[{p1, p2}]}      The output is a list of three elements, p1, p2, and the output of `Show[{p1,p2}]`. The third element instead of lighting p1 an p2 with their indivdual colors mixes p2's colors with p1's colors. Any particular reason why is this is so? How do I overcome the mixing here? How can I specify the exact colors in the output of `Show`?


ExportString and HTML: where are saved images?

I want to use ExportString to generate HTML expression. Here is an easy example:               ExportString[x^3, "HTML", "FullDocument" -> False]      gives

      I cannot find the folder HTMLFiles and related file gif. I tried setting the working directory, or looking in any folder of the computer, without having success. My guess is that files are not actually generated. But the point is: ExportString is not useful at all for HTML format. Please, help, any comment is welcome.


Problem with function as an argument

I want to write a function like the following:               s[u_, v_, x_, val_] := u[val]/NIntegrate[u'[x] v[x] + u'[x] v'[x], {x, 0, 1}]      So I can evaluate something like               s[Cos[x], Sin[3 x], x, 5]      I have a strong feeling that my approach is incorrect, however, I couldn't find the right one. **Update:** Thanks to b.gatessucks, who wrote the correct version of what I was trying to achieve. However, after that I tried to use that approach on lists:               r = {1, 2, 3, 4, 5};     u[x_, i_] := Sin[r[[i]] x];     A = Table[s[u[#, i] &, u[#, j] &, 5], {i, 5}, {j, 5}]      After this, I get a matrix, but I also get a bunch of errors, so I don't know if I can trust the output. The errors are:               Part::pspec: Part specification #2 is neither an integer nor a list of integers.     Part::pspec: Part specification #2 is neither an integer nor a list of integers.     Part::pspec: Part specification #2 is neither an integer nor a list of integers.     General::stop: "Further output of Part::pspec: will be suppressed during this calculation."


Drawing a quadrilateral inscribed within a circle

I would like to draw a quadrilateral inscribed within a circle. How can I construct this figure, taking into account arbitrary (specified) side lengths, while still ensuring that the vertices of the quadrilateral lie on the circle?


Compact Rational Function Fitting

I have some data from a study that I am trying to fit with a rational function of arbitrary form: $y(x) = \frac{\sum_{i=n}^m A_ix^{i/q}}{\sum_{j=o}^p B_jx^{j/r}}$ where $i$, $j$, $k$, $l$, $m$, $n$, $o$, $p$, and $q$ are all integers. The goal is to produce a function of this form with as few terms as possible that still provides a reasonable match to the data. For instance, I have some data that looks like this: ![enter image description here](http://i.stack.imgur.com/SATsb.png) where the black line is a fit to the data, and the fit is a function of the following form: $y(x) = \frac{-0.31+1.2 \sqrt{x}-1.2 x }{1.0+1.3 \sqrt{x}-4.2 x}$ My current method of generating these functions is to produce a rational function of a high order, and then to successively eliminate terms if their coefficients are small compared to other terms in the expression. My algorithm is pretty ad-hoc, and the cutoffs, maximum order to use, and fractional powers to include are all parameters that one can pass as inputs to the function. I was curious if anyone had a better way to produce a compact rational fit to an arbitrary set of data that perhaps didn't rely on such an ad-hoc approach. Here is the code I currently use to generate these fits:               compactRationalFit[data_, x_, coeffthresh_: 0.1, minorder_: 0,         maxorder_: 4, powerfrac_: 1] :=        Module[{lcoeffthresh, bestfit, cld, cln, csc, i, dd, nn, norderlist,          dorderlist, ndelpos, ddelpos, result, totdel, norigdelems,          norignelems},        dorderlist = norderlist = Range[minorder, maxorder, 1/powerfrac];        norignelems = Length[dorderlist];        norigdelems = Length[dorderlist];        totdel = 1;        cld = ConstantArray[1, Length[dorderlist]];        cln = ConstantArray[1, Length[norderlist]];        While[totdel !=            0 && ! (Length[dorderlist] == 1 && Length[norderlist] == 1),     lminorder = Min[norderlist~Join~dorderlist];     norderlist -= lminorder;     dorderlist -= lminorder;     lncoeffthresh = coeffthresh*Length[norderlist]/norignelems;     ldcoeffthresh = coeffthresh*Length[dorderlist]/norigdelems;     lncoeffthresh = coeffthresh;     ldcoeffthresh = coeffthresh;     cld[[Flatten[Position[cld, x_ /; x < 0]]]] = 1;          bestfit =       Normal[NonlinearModelFit[SetPrecision[data, 20],(*{*)        Total[Table[            ToExpression[             "nn" <>               ToString[PaddedForm[i, 2, NumberPadding -> "0"]]], {i,              Length[norderlist]}] Table[x^i, {i, norderlist}]]/         Total[Table[            ToExpression[             "dd" <>               ToString[PaddedForm[i, 2, NumberPadding -> "0"]]], {i,              Length[dorderlist]}] Table[x^i, {i, dorderlist}]](*,        Apply[And,Table[ToExpression["dd"<>ToString[PaddedForm[i,2,        NumberPadding->"0"]]]>0,{i,Length[dorderlist]}]]}*),         Table[{ToExpression[            "dd" <> ToString[PaddedForm[i, 2, NumberPadding -> "0"]]],            cld[[i]]}, {i, Length[dorderlist]}]~Join~         Table[{ToExpression[            "nn" <> ToString[PaddedForm[i, 2, NumberPadding -> "0"]]],            cln[[i]]}, {i, Length[norderlist]}], x,         AccuracyGoal -> 3, PrecisionGoal -> 3, MaxIterations -> 1000,         ConfidenceLevel -> .95,         VarianceEstimatorFunction -> (Mean[#^2] &)]];         cld =           Table[Coefficient[Expand[Denominator[bestfit]], x, i], {i,             dorderlist}];          cln = Table[           Coefficient[Expand[Numerator[bestfit]], x, i], {i,             norderlist}];         cln = Delete[cln, Position[cln, x_ /; x == 0]];          cld = Delete[cld, Position[cld, x_ /; x == 0]];         ndelpos =           If[Length[cln] == 1, {},            Position[cln, x_ /; Abs[x] < lncoeffthresh Max[Abs[cln]]]];         ddelpos =           If[Length[cld] == 1, {},            Position[cld, x_ /; Abs[x] < ldcoeffthresh Max[Abs[cld]]]];         totdel = Length[Flatten[ndelpos]] + Length[Flatten[ddelpos]];         norderlist = Delete[norderlist, ndelpos];          dorderlist = Delete[dorderlist, ddelpos];         cln = Delete[cln, ndelpos]; cld = Delete[cld, ddelpos];         csc = First[cld];         result =           SetPrecision[Total[cln/csc*Table[x^i, {i, norderlist}]]/           Total[cld/csc*Table[x^i, {i, dorderlist}]], 2];         ];        Return[result];        ];      Here, I have made the simplifying assumption that the numerator and the denominator have the same limits/fractional order, i.e. $n=o$, $p=m$, and $q=r$. A call to this function (using the default parameters) looks like this:               compactRationalFit[myData, x]      with the restriction that the number of data points + 1 should not exceed the total number of terms in the numerator and denominator combined. Some of the other ideas I have been thinking of involve trying all possible combinations simultaneously, and selecting the one with the least amount of terms that satisfies an error threshold, but this involves finding fits to potentially thousands of possible combinations of power series. My current method is relatively fast, as it only requires at most $q^2(m-n)(m-n-1)/2$ iterations, but often times the fits it finds are not perfect, as rational functions are prone to zeroes in the denominator that can produce sharp discontinuities in-between data points: ![enter image description here](http://i.stack.imgur.com/xShre.png) If anyone could come up with a more robust solution that results in better, more compact fitting formulae, I would be grateful.


Machine precision infinity

Is it possible to obtain the machine precision (double) version of `Infinity`? This is useful when using `LibraryLink` and C functions that accept doubles: passing `Infinity` raises a type error, because `Infinity` is a symbol.


Listing all celltags in a notebook

Is there a command to obtain all the `CellTags` and the style of the cell they are in? This question is derived from this question which was answered by jVincent. Based on his answer I want to be able to create a function which takes in a string. Looks for the text "\ ref{String_}" (There should be no space between \ and ref, I'm not sure how to avoid mathjax here, if you know how to please make the proper edits) and uses that information to insert a `CounterBox`. The problem is that the type of counterboxes I want to insert require two arguments, the first is the style of a cell and the second is the `CellTag`. So really, this is a two part question: 1) How do you find out all the `CellTags` available? The obvious answer is by going to `Cell > Add/Remove Cell Tags`. This only works if you have a cell selected. If you give a cell a cellTag it will appear under "All cellTags in the notebook". So obviously Mathematica keeps a list of all the CellTags available in the notebook. The question is, how do we get this list? 2) Once we found out if this celltag is available, is there a way to obtain the style of the cell in which it is in? For instace, I might create a "DisplayFormulaNumbered" cell, and tag it as "eq1". So why all of this? The idea is to have some cell with text like this: > From equation ref{eq1} we then ... Note that I did not include the backlash before ref because I don't know how to avoid mathjax from transforming it at this point. Back to the idea, now using jVincent's code we could create a button that when the cell is selected, it looks for all instances of ref, grabs the input (in this case eq1), looks to see if it is a valid tag, if it isn't then it just issues a warning telling you that there's no valid tag, otherwise it replaces the ref section for the counterbox which as inputs the Cell style in which the tag is contained and the tag.


Optimization with Matrix value constraint

I am trying to find the orientation and position of a polygon resting on a curved surface under gravity.The polygon **MUST** not be penetrated by any part of the surface below. Here is an example for a square shape.![enter image description here](http://i.stack.imgur.com/mgQp6.jpg) The curved surface is defined by a 2D Matrix: Tdata. The problem can be formulated to a constrained Optimization problem. The initial square can be approximated by five points(four vertices and one center point):               ConVer = {{l/2, w/2, 0}, {l/2, -w/2,0}, {-l/2, -w/2, 0}, {-l/2, w/2,0}, {0, 0, 0}};      Where l is the length and w is the width of the Square. The square's orientation is parameterized by three angles:               Rθ = RotationMatrix[θ, {0, 0, 1}];     Rψ = RotationMatrix[ψ, {0, 1, 0}];     Rϕ = RotationMatrix[ϕ, {1, 0, 0}];      Then the parameterized square is               For[i = 1, i < 6, i++, ConVer[[i]] =Rθ.Rψ.Rϕ.ConVer[[i]] + {x, y,z}];      Where {x ,y ,z} is the coordinates of the center point of the square. The optimization uses NMinimize function:               x = 1; y = 1; θ = 0;     NMinimize[{z,                  Tdata[(ConVer[[1]])[[1 ;; 2]]] <= (ConVer[[1]])[[3]] &&                  Tdata[(ConVer[[2]])[[1 ;; 2]]] <= (ConVer[[2]])[[3]] &&                          Tdata[(ConVer[[3]])[[1 ;; 2]]] <= (ConVer[[3]])[[3]] &&                  Tdata[(ConVer[[4]])[[1 ;; 2]]] <= (ConVer[[4]])[[3]] &&                  Tdata[(ConVer[[5]])[[1 ;; 2]]] <= (ConVer[[5]])[[3]]},                  {{ψ, -Pi/4, Pi/4}, {ϕ, -Pi/4, Pi/4}, {z, 0, 1}}];      When Tdata is a 2d function this works well, but as to 2d Matrix error occurs! Why is that? I also tried to solve this problem in Matlab using 'fmincon', and Matlab can return desired result.


How do I draw a credible velocity vs. time graph using Locators?

This is partly a math question, partly a _Mathematica_ question. For educational purposes, I'm making a simple demonstration to create a velocity over time graph from six locators. On the basis of input from the user in the velocity graph (he moves the graph control points), a distance over time graph and an acceleration over time graph will be automatically produced through integration and differentiation. Trouble is, a piecewise linear function leaves corners for which the derivative is undefined. There is also a real-world issue: an object cannot instantaneously jump from an acceleration of 2 to 3. I would like the velocity function to "round" the corners. I don't want to use `Bezier` or `BSpline` because the control points do not lie on the graph of the function. I suspect that `Fit` will be of use, but I'm unsure what model to use that will have the function intersect with the points where the locators are positioned. Suggetions about the math (which model) and/or the _Mathematica_ code are appreciated. Here's a simplified version of the code: ![velocity over time graph](http://i.stack.imgur.com/m8YFv.png)               Manipulate[      LocatorPane[       Dynamic[pts, (pts = #;           pts = Function[             pnt, {.25 Round[4 pnt[[1]]], .1 Round[10 pnt[[2]]]}] /@             pts) &],       data = (Sort@pts);       Dynamic@Show[{ListPlot[{data},           ImageSize -> 550,           Joined -> True,           AspectRatio -> 1/2,           Epilog ->             Dynamic@MapIndexed[Text[#2[[1]], Offset[{5, 10}, #1]] &,               data],           BaseStyle -> 12,           AxesLabel -> {"time (min)", "velocity \n(m/s)("},           PlotRange -> {{0, 30}, {-20, 20}}, Axes -> True,            ImageSize -> 450]}]],           {{pts, {{0, 0}, {4, 12}, {7, 12}, {23, -12}, {25, -12}, {27, -6}}},        ControlType -> None}]


Audio sample data from a Sound object

When generating a Sound object by using Sound primitives, like:               Needs["Audio`"]     sound = Sound[ListWaveform[{{1, 1}, {1.496, .7}, {2.501, .3}}, 265, 1]];      how can I get the sample ("amplitude") data which is produced by the Sound primitive at a given sample rate? Obviously one could export `sound` to a wav file and re-import it, but how to do it directly? Or let's say: what is the `Rasterize` function for Sounds, the inverse of `ListPlay`? Sorry for this rather simple question, but I have been looking for some time and could not find anything.


List has a date and amount, I need to create a cumulative amount by date

I have a list which has a date and a amount, I need to create a list that has the cummulative total with the date. I have the following result:               {{{2009, 8, 3}, 1829.}, {{2009, 8, 4}, 1113.}, {{2009, 8, 5}, 730.}, {{2009, 8, 6}, -243.}}      What I need:                {{{2009, 8, 3}, 1829.}, {{2009, 8, 4}, 2942.}, {{2009, 8, 5}, 3672.}, {{2009, 8, 6}, 3429.}}      I have just spent over an hour trying to figure this out, any help is most appreciated.


Matrix/tensor addition behaving funny under replacement?

I have two matrices I want to add, and one of the matrices is a tensor product of two vectors. I've used a SetDelayed to define the summed matrix, because I want to evaluate it for different values of these vectors. However, when I try to evaluate it using a replacement, I get a new array with the wrong dimensionality. Here's a minimal(ish?) example:               mat := DiagonalMatrix[{1, 1, 1, 1}] + TensorProduct[vec, vec]      Then using a replace gives me something horrible:               mat /. vec -> {2, 2, 2, 2}          {{{{5, 5, 5, 5}, {5, 5, 5, 5}, {5, 5, 5, 5}, {5, 5, 5, 5}}, {{4, 4, 4,      4}, {4, 4, 4, 4}, {4, 4, 4, 4}, {4, 4, 4, 4}}, {{4, 4, 4, 4}, {4,      4, 4, 4}, {4, 4, 4, 4}, {4, 4, 4, 4}}, {{4, 4, 4, 4}, {4, 4, 4,      4}, {4, 4, 4, 4}, {4, 4, 4, 4}}}, {{{4, 4, 4, 4}, {4, 4, 4,      4}, {4, 4, 4, 4}, {4, 4, 4, 4}}, {{5, 5, 5, 5}, {5, 5, 5, 5}, {5,      5, 5, 5}, {5, 5, 5, 5}}, {{4, 4, 4, 4}, {4, 4, 4, 4}, {4, 4, 4,      4}, {4, 4, 4, 4}}, {{4, 4, 4, 4}, {4, 4, 4, 4}, {4, 4, 4, 4}, {4,      4, 4, 4}}}, {{{4, 4, 4, 4}, {4, 4, 4, 4}, {4, 4, 4, 4}, {4, 4, 4,      4}}, {{4, 4, 4, 4}, {4, 4, 4, 4}, {4, 4, 4, 4}, {4, 4, 4,      4}}, {{5, 5, 5, 5}, {5, 5, 5, 5}, {5, 5, 5, 5}, {5, 5, 5,      5}}, {{4, 4, 4, 4}, {4, 4, 4, 4}, {4, 4, 4, 4}, {4, 4, 4,      4}}}, {{{4, 4, 4, 4}, {4, 4, 4, 4}, {4, 4, 4, 4}, {4, 4, 4,      4}}, {{4, 4, 4, 4}, {4, 4, 4, 4}, {4, 4, 4, 4}, {4, 4, 4,      4}}, {{4, 4, 4, 4}, {4, 4, 4, 4}, {4, 4, 4, 4}, {4, 4, 4,      4}}, {{5, 5, 5, 5}, {5, 5, 5, 5}, {5, 5, 5, 5}, {5, 5, 5, 5}}}}      But a block (or setting vec={2,2,2,2}) gives the correct behavior:               Block[{vec = {2, 2, 2, 2}}, mat]          {{5, 4, 4, 4}, {4, 5, 4, 4}, {4, 4, 5, 4}, {4, 4, 4, 5}}      (Sorry, not sure if I typed in the output correctly here.) What's going on?


X-axis offset for LogLinearPlot

I want to set a zero-offset not only for the y-axis like i did with PlotRangepadding, but also for the x-axis. That means i dont want the white offset left of 1E-4 and right of 1E-1, and the y-axis/frame at my o-range. When i use the normal plot i dont get a x-axis-offset there, at least not in the positive direction. I thought that How to set a zero offset for the frame origin? would solve it but it only did it for the y-axis ![enter image description here](http://i.stack.imgur.com/TS0pr.png)               i[r_, o_] := (r*0.87)/(0.00022 + o)     LogLinearPlot[Evaluate@Table[i[r, o], {r, {100, 200, 400, 600}}], {o, 1*10^-4,0.1},PlotRangePadding -> None, PlotRange -> {0, 2500000},       Filling -> Axis,Frame -> True]


Series expansion for small ratio of variables

I have a messy expression of variables that I would like to simplify under the assumption that certain ratios of the variables are small. For example, consider $\sqrt{x+y}\;$ expanded for small $\frac{y}{x}$. That is, $x >> y$. This is simple enough to do by hand (pull out a $\sqrt{x}$ and then define a new variable to be $\frac{y}{x}$, then expand this variable about $0$). But, I cannot figure out how to do it in _Mathematica_. **EDIT 1** I've since realized that what I actually want to do is more complicated than the example above. Consider the following expression $\sqrt{a+d} + \sqrt{b+d}\;$ expanded for small $\frac{d}{a}$ and small $\frac{d}{b}$ (that is $a>>d$ and $b>>d$). Following Artes' answer below, the solution is               Series[ (a + d)^(1/2) + (b + d)^(1/2) /. {d -> z1 a, d -> z2}, {z1, 0, 2},{z2, 0, 2}] /.      {z1 -> d/a, z2 -> d/b}      But this solution doesn't work as intended due to the order operations _Mathematica_ performs upon this command. What needs to be done is to replace `d` with `z1 a`, then expand `z1` about `0`, replace `z1` with `d/a`, then replace `d` with `z2 b`, expand `z2` about `0`, and finally replace `z2` with `d/b`. How can one do this in _Mathematica_?   (Obviously the example I gave can be separated into two expressions when can be expanded separately, but this cannot be done for the more complicated expression I am actually trying to expand).


ScalingFunctions option works for ListPlot but only if there's no Frame: how to work around this?

Mathematica has quite a nice `ScalingFunctions` option to `BarChart`, `BubbleChart` and the various financial charting functions, which simplifies log scaling, reverse scales and so on. Consider:               test = FoldList[0.85 #1 + #2 &, 0.,        Abs@RandomVariate[NormalDistribution[0, 3], 25]]          {0., 1.40961, 4.59418, 9.49233, 11.4004, 9.93797, 11.0347, 11.0437,      9.39412, 8.46501, 10.5416, 10.3413, 9.60696, 8.47968, 9.45521,      9.44406, 12.3554, 15.3821, 17.8863, 15.5349, 17.2376, 18.3164,       18.5506, 16.459, 14.6381, 13.7955}          BarChart[test, Frame -> True]      ![enter image description here](http://i.stack.imgur.com/m9fU8.png)               BarChart[test, ScalingFunctions -> "Log", Frame -> True]      ![enter image description here](http://i.stack.imgur.com/nHmaK.png) As has been previously noted on the site, the option actually works for `ListPlot` and `ListLinePlot` (but not `DateListPlot`) as well, even though this fact is not documented.               ListLinePlot[test, ScalingFunctions -> {"Log10", "Reverse"}]      ![enter image description here](http://i.stack.imgur.com/ZFC2Z.png) However that breaks down where there is a frame. The tick labels (`FrameTicks`) are now the _rescaled_ values, not the original values. The data are correctly rescaled.               ListLinePlot[test, ScalingFunctions -> {"Log10", "Reverse"}, Frame -> True]      ![enter image description here](http://i.stack.imgur.com/07Uqd.png) Obviously the undocumented insertion of this functionality into `ListPlot` and `ListLinePlot` only affected `Ticks` and not `FrameTicks`. Is there any way to get the correct tick labels back?   Even better, is there a reasonably straightforward way to use `OptionValue[ScalingFunctions]` to ensure that _custom_ tick mark placement is correct when the data have been rescaled like this?


Is the Wolfram | Alpha output in Mathematica not Alpha Pro?

Mathematica 8 includes " _Wolfram | Alpha_ integration", but the features of Alpha available in Mathematica seem not to include many of those available in the "Pro" version of Alpha. Does Mathematica 8 include Alpha's Plus features? If not, has Wolfram announced plans to include them?


How can I build a GraphicsGrid of arbitrary size?

This is actually a very simple scenario, in order to make simpler this question Part I. Consider the following piece of _Mathematica_ code               data1 = {{-1, 2}, {3, 1}};     data2 = {{1, -5}, {2, -1}};     data3 = {{0, 1}, {-3, 4}};     data4 = {{-4, 9}, {8, 10}};     data5 = {{-2, 5}, {-2, -5}};     data6 = {{-5, -3}, {0, 1}};     data7 = {{-1, -2}, {-1, 1}};     data8 = {{2, 9}, {7, 1}};          L1 = ListPlot[data1];     L2 = ListPlot[data2];     L3 = ListPlot[data3];     L4 = ListPlot[data4];     L5 = ListPlot[data5];     L6 = ListPlot[data6];     L7 = ListPlot[data7];     L8 = ListPlot[data8];          P0 = GraphicsGrid[{{L1, L2, L3}, {L4, L5, L6}, {L7, L8}}, ImageSize -> 550]      The simple two elements lists could be massive external data files. So, my question is: If I don't know the exact number of data files beforehand (in my case for example, it could be anything between 0 and 8), how can I define the `GraphicsGrid`? If a list (file) is missing then I will get an empty slot in the grid. Is it possible to fit the empty slot with the next available item, but maintaining the grids's original structure (3 rows, the first 2 with 3 plots per row and the last one with only 2 plots)? **EDIT** I see that the use of lists is not helpful because it does not match to the actual case. So, let me explain the situation: I run a FORTRAN program which produces 8 data files. However, there are cases in which the number of produced files is smaller than 8, even zero but never larger than 8. So in order to plot these files I constructed this code. However, many complained about this and for this reason let's suppose the following:               SetDirectory[];          data1 = Import["data1.ab","Table"];     data2 = Import["data2.cd","Table"];     data3 = Import["data3.ef","Table"];     data4 = Import["data4.gh","Table"];     data5 = Import["data5.ij","Table"];     data6 = Import["data6.kl","Table"];     data7 = Import["data7.mn","Table"];     data8 = Import["data8.op","Table"];          L1 = ListPlot[data1];     L2 = ListPlot[data2];     L3 = ListPlot[data3];     L4 = ListPlot[data4];     L5 = ListPlot[data5];     L6 = ListPlot[data6];     L7 = ListPlot[data7];     L8 = ListPlot[data8];          P0 = GraphicsGrid[{{L1, L2, L3}, {L4, L5, L6}, {L7, L8}}, ImageSize -> 550]      The structure of the grid corresponds to the case where all 8 files are present. What I want is an automatic procedure reading every available data file, determine which of them are present (not empty) and then plot them in a grid.


Test whether date is in a certain period

I have one table which contains time periods (`"start"` and `"end"`) and a `"type"` for every period:               table1 = {{"start", "end", "type"},                {{2013, 8, 10, 8, 5, 0.`}, {2013, 8, 10, 10, 6, 0.`}, "a"},                {{2013, 8, 10, 10, 6, 0.`}, {2013, 8, 10, 10, 50, 0.`}, "b"},                {{2013, 8, 10, 10, 50, 0.`}, {2013, 8, 10, 12, 10, 10.`}, "c"}}       Now, I have a second table which contains dates:               table2 = {"date",                {2013, 8, 10, 11, 5, 0.`},                {2013, 8, 10, 10, 15, 0.`},                {2013, 8, 10, 10, 35, 0.`},               {2013, 8, 10, 11, 10, 0.`},                {2013, 8, 10, 12, 5, 0.`}}       What I want to do now, is to test whether a date is within one of the periods and if yes in which period. The result should be a table which shows in which period the date is. For my small example, the table should look like this:               result = {{"date", "coresp. type"},                {{2013, 8, 10, 11, 5, 0.`}, "c"},                {{2013, 8, 10, 10, 15, 0.`}, "b"},                {{2013, 8, 10, 8, 5, 0.`}, "a"},                {{2013, 8, 10, 11, 10, 0.`}, "c"},                {{2013, 8, 10, 12, 5, 0.`}, "c"},                {{2013, 9, 10, 10, 10, 0.`}, "none"}}      Is there an way to create the result table automatically?


Growth of functions

Does somebody know if Mathematica can be used to calculate the growth of functions, that is in Big O, Theta, and Omega and find proper $n_{0}$ and $c_{1}$, $c_{2}$ respectively?


I want to change the outer background color of a manipulated plot

I downloaded some demonstrations' sources (for example) and I want to change their colors. I am only stuck with the white outer background that is around the plot's yellow background. I would like to see a part of the code where I should put in something like Background->Color.


NSolve cannot find the solution

I have some data which looks like:               Tdata = {{0., 0.05}, {0.78125, 0.05}, {1.5625, 0.15}, {2.34375, 0.}, {3.125,      0.}, {3.90625, 0.1}, {4.6875, 0.15}, {5.46875, 0.05}, {6.25,      0.}, {7.03125, 0.1}, {7.8125, 0.05}, {8.59375, 0.1}, {9.375,      0.1}, {10.1563, 0.2}, {10.9375, 0.25}, {11.7188, 0.4}, {12.5,      0.55}, {13.2813, 0.45}, {14.0625, 0.7}, {14.8438, 0.95}, {15.625,      1.}, {16.4063, 1.8}, {17.1875, 2.}, {17.9688, 2.3}, {18.75,      2.05}, {19.5313, 2.6}, {20.3125, 3.4}, {21.0938, 4.1}, {21.875,      4.8}, {22.6563, 4.8}, {23.4375, 5.75}, {24.2188, 6.3}, {25.,      6.45}, {25.7813, 7.15}, {26.5625, 8.8}, {27.3438, 8.6}, {28.125,      9.25}, {28.9063, 10.35}, {29.6875, 12.1}, {30.4688, 10.6}, {31.25,      11.6}, {32.0313, 12.7}, {32.8125, 12.6}, {33.5938, 12.75}, {34.375,      15.3}, {35.1563, 13.25}, {35.9375, 12.35}, {36.7188, 12.65}, {37.5,      14.1}, {38.2813, 13.5}, {39.0625, 12.5}, {39.8438, 13.6}, {40.625,      12.4}, {41.4063, 11.15}, {42.1875, 10.65}, {42.9688, 11.3}, {43.75,      11.45}, {44.5313, 9.95}, {45.3125, 10.4}, {46.0938, 10.45}, {46.875,     8.85}, {47.6563, 9.6}, {48.4375, 8.4}, {49.2188, 8.5}, {50.,      8.05}, {50.7813, 7.9}, {51.5625, 6.95}, {52.3438, 6.85}, {53.125,      6.2}, {53.9063, 6.6}, {54.6875, 6.6}, {55.4688, 5.25}, {56.25,      5.45}, {57.0313, 5.35}, {57.8125, 4.5}, {58.5938, 4.1}, {59.375,      3.6}, {60.1563, 3.5}, {60.9375, 2.95}, {61.7188, 3.05}, {62.5,      3.1}, {63.2813, 3.15}, {64.0625, 2.85}, {64.8438, 2.35}, {65.625,      2.15}, {66.4063, 3.1}, {67.1875, 2.5}, {67.9688, 1.95}, {68.75,      2.45}, {69.5313, 2.}, {70.3125, 1.95}, {71.0938, 1.9}, {71.875,      1.35}, {72.6563, 1.2}, {73.4375, 1.}, {74.2188, 1.05}, {75.,      1.5}, {75.7813, 1.05}, {76.5625, 1.2}, {77.3438, 1.05}, {78.125,      0.95}, {78.9063, 0.85}, {79.6875, 0.7}, {80.4688, 1.05}, {81.25,      0.9}, {82.0313, 0.65}, {82.8125, 0.85}, {83.5938, 0.65}, {84.375,      0.8}, {85.1563, 0.6}, {85.9375, 0.65}, {86.7188, 0.4}, {87.5,      0.55}, {88.2813, 0.7}, {89.0625, 0.45}, {89.8438, 0.55}, {90.625,      0.35}, {91.4063, 0.5}, {92.1875, 0.45}, {92.9688, 0.3}, {93.75,      0.15}, {94.5313, 0.3}, {95.3125, 0.3}, {96.0938, 0.35}, {96.875,      0.15}, {97.6563, 0.2}, {98.4375, 0.3}, {99.2188, 0.15}, {100.,      0.3}, {100.781, 0.2}, {101.563, 0.25}, {102.344, 0.45}, {103.125,      0.1}, {103.906, 0.1}, {104.688, 0.05}, {105.469, 0.3}, {106.25,      0.1}, {107.031, 0.25}, {107.813, 0.05}, {108.594, 0.15}, {109.375,      0.05}, {110.156, 0.1}, {110.938, 0.1}, {111.719, 0.05}, {112.5,      0.}, {113.281, 0.2}, {114.063, 0.05}, {114.844, 0.1}, {115.625,      0.05}, {116.406, 0.05}, {117.188, 0.1}, {117.969, 0.25}, {118.75,      0.1}, {119.531, 0.1}, {120.313, 0.}, {121.094, 0.05}, {121.875,      0.05}, {122.656, 0.05}, {123.438, 0.}, {124.219, 0.05}, {125.,      0.05}, {125.781, 0.}, {126.563, 0.}, {127.344, 0.1}}      ![enter image description here](http://i.stack.imgur.com/F1MjW.jpg) I tried to fit this data to a series of polynomials:               sol = Fit[Tdata, Table[x^i, {i, 0, 14}], x]     plot1 = Plot[sol, {x, 1, 120}, PlotStyle -> {Red, Thickness[0.005]},      PlotRange -> All];     Show[{plot1, plot}]          0.180145 - 0.202127 x + 0.0517504 x^2 - 0.000786656 x^3 -      0.000942415 x^4 + 0.000123705 x^5 - 7.22477*10^-6 x^6 +      2.44885*10^-7 x^7 - 5.32789*10^-9 x^8 + 7.78619*10^-11 x^9 -      7.75517*10^-13 x^10 + 5.20728*10^-15 x^11 - 2.25919*10^-17 x^12 +      5.72595*10^-20 x^13 - 6.4449*10^-23 x^14      ![enter image description here](http://i.stack.imgur.com/FuOmm.jpg) I know that this data, which obtained experimentally, is the convolution of a Gaussian function and an exponential.               numberOFexp = 1;          model[z_] := Sum[Subscript[a, i]*Exp[-z/Subscript[\[Tau], i]], {i, 1, numberOFexp}] ;          irf[z_] := (2.0*Sqrt[2*Log[2]])/(\[CapitalDelta]*Sqrt[2.0*Pi])*Exp[-4.0*Log[2]*     ((z -\[Mu])/\[CapitalDelta])^2];          model2 = Integrate[irf[z]*model[t - z], {z, 0, t}](*This is what generates the exprimentall data*)      Now, I expand `model2` up to the powers by which I fitted the data with polynomials. The point is that in the `model2` there are some parameters which I want to know. I had fitted the data with a polynomial with 15 terms. I want to expand `model2` up to 15 terms and equate the coefficient of each polynomial of my fit to this expansion and get those unknown parameters. Because I have just 4 unknown I decided to expand `model2` up to 4 term. I tried:               model3 = Normal[Series[model2, {t, 36, 3}]];          unknowns= CoefficientList[model3, t];     co2 = CoefficientList[sol, x];     co3 = co2[[1 ;; 4]]     NSolve[unknowns==co3 , {\[CapitalDelta], \[Mu], Subscript[\[Tau], 1], Subscript[a, 1]}, Reals]       However, this can't find the solution.


Extracting text from nested HTML lists <ul> <li>

We wish to analyze the tree structure of HTML documents that consist of nested lists, ie, using the HTML tags `<ul>` and `<li>`. The documents are generated by Workflowy, a note taking web app that can manage arbitrarily deep nesting (and dynamically re-arrange them by zooming and searching). For example, here's a portion of one document:

Subjective

XX yr old man here for fu on med problems

feels absolutely positively wonderful

Active problems

htn

started on hctz in 8/10, in early 11 given lasix as his gfr was low

limits salt caffeine, home readings140/80  or less when he runs

not been exercising now

      After applying the main parse function in Leonid Shifrin's HTML parser (Thanks for that), the above portion is transcoded to:               ulContainer[attribContainer[ class="ul1"],       ,liContainer[attribContainer[ class="li2"],Subjective],       ,ulContainer[attribContainer[ class="ul1"],         ,liContainer[attribContainer[ class="li2"],XX yr old man here for fu on med problems],         ,liContainer[attribContainer[ class="li2"],feels absolutely positively wonderful],       ],       ,liContainer[attribContainer[ class="li2"],Active problems],       ,ulContainer[attribContainer[ class="ul1"],         ,liContainer[attribContainer[ class="li2"],htn],         ,ulContainer[attribContainer[ class="ul1"],           ,liContainer[attribContainer[ class="li2"],started on hctz in 8/10, in early 11 given lasix as his gfr was low],           ,liContainer[attribContainer[ class="li2"],limits salt caffeine, home readings140/80  or less when he runs],           ,liContainer[attribContainer[ class="li2"],not been exercising now],         ],      Shifrin writes: > What it gives you is a symbolic tree representation of the parsed html > document, with different tags transformed into ...Container[content], for > example divContainer[aContainer["Some text"]]. The container names mirror > the html tag names, except for attribContainer which is for tag attributes. > Also, without post-processing, no information is lost What is required is a method to strip the markup and extract the text data as strings into a nested list expression preserving the (tree) structure. Thus for the above portion, the desired output is:                {"Subjective",         {"XX yr old man here for fu on med problems",          "feels absolutely positively wonderful"},       "Active problems",         {"htn",              {"started on hctz in 8/10, in early 11 given lasix as his gfr was low",               "limits salt caffeine, home readings140/80  or less when he runs",               "not been exercising now"}}}      I made the entire HTML document available online:               parsed = postProcess@        parseText[         Import["http://statigrafix.com/projects/pace/datasets/20130527/\     NOTES.001-01.0.WORKFLOWY.20130527.html", "TEXT"]];      From manually analyzing the example () and following the tree structure, it's easy to extract at the top level, eg:               Column@Cases[parsed[[1, 5, 5]],        liContainer[attribContainer[_], txt_] :> txt]          (*     Subjective     Active problems     General health     Past medical and surgical history     DA     Medications     8/08  Family History     8/08  Personal and social history     Habits     Exam     Labs     Clinical Reminder Activity     *)      I would appreciate help with the method to automate extraction at all levels.


Importing a large Excel file

I'm trying to import a simple Excel file containing 94,000 rows and 52 columns of various types, mostly `Real`s. It's a 38-MB file. I get this _super helpful_ error message:               Import::fmterr: Cannot import data as XLS format. >>      A little googling reveals that for large files, Wolfram recommends this magic snippet:               << JLink`;     InstallJava[];     ReinstallJava[JVMArguments -> "-Xmx512m"]      But I get the same error no matter how big I make the number in `"-Xmx512m"`, which I assume is the Java heap size. Can anyone recommend a way to import this file _without_ using Excel to convert it to a different format? **Addendum:** I appreciate the effective ideas that have been proposed as workarounds. But I'm looking for a way of directly importing Excel files. It will be difficult to explain that my favorite software cannot import Excel files without prior conversion using some external program. If this is the case, I'm truly surprised.


Finding a Specific Line in a Package

In a package I am developing, I accidentally left this line               Protect[      uncompleted prior to running the package. Mathematica produced this error message               Syntax::sntup: Unexpected end of file (probably unclosed parenthesis)                   (line 102 of "DataListPlot`").      which includes the line number of the error. Since the code was short and it was the only thing in that cell, it was straightforward to find. But, in general, how would one find a specific line in a package? Also, is it possible in the standard package interface to add line numbers, like in WorkBench?


How can I extract data points from a black and white image?

Consider the following graph (source): ![Mathematica graphics](http://i.stack.imgur.com/hhPr9.png) Is there any way to extract the data points from this image in a semi- automatic way? I have seen, and tried the methods suggested in this question, but they did not work, as most of the approaches there utilize color contrast to extract the data; I couldn't get `barChartDigitizer` to work, either.


Font sizes in graphics

I'm trying to find an explanation for the different sizes I'm seeing for fonts added to graphics in different ways, and haven't yet located an easy to understand explanation. Here's a minimal example:               Graphics[      {LightGray,       Rectangle[{0, 0}, {72, 72}],       Red,       Style[        Text["Hig", {0, 0}, {-1, -1}], 72,        FontFamily -> "Times New Roman"],       Black,       First[        First[         ImportString[          ExportString[           Style["Hig",             FontFamily -> "Times New Roman",             FontSize -> 72], "PDF"],          "TextMode" -> "Outlines"]]]       },      PlotRange -> {{0, 100}, {0, 100}},       Axes -> True,       Ticks -> {Table[x, {x, 0, 100, 10}], Table[x, {x, 0, 100, 10}]},      Epilog -> {Text["72", {200, 75}], Line[{{0, 72}, {200, 72}}]}]      ![fonts](http://i.stack.imgur.com/l2wT7.png) The red text doesn't change size when you resize the graphic, although everything else changes. The black text resizes along with everything else. But neither text seems to be the result of specifying 72. ## Update After changing the screen resolution to Automatic following @Sjoerd's suggestion, I can see how the red text is basically displaying at a fixed size that's independent of _Mathematica_. In this picture, the left image shows 72 dpi, the red font is using 70ish pixels of vertical space. The right image is at 'Automatic' (so presumably 133.51 for my machine, according to this site, and similarly uses up 70ish pixels. ![resolutions](http://i.stack.imgur.com/Qjbuv.png) I'm still puzzled by the size of the black font, which doesn't seem to be related to the specified font size or to the screen resolution. Perhaps the PDF translation introduces another scaling factor.


How to load a package without naming conflicts?

This question applies to any package, but I encountered this problem while working with graphs. There are symbols in the `Combinatorica` package (such as `Graph`, `IncidenceMatrix`, `EdgeStyle`, and others) that have the same name as analogous symbols in `System`. If I execute `Needs[Combinatorica`]`, then I can access `Combinatorica`Graph` by the name `Graph`, but if I want to access `System`Graph`, I have to write `System`Graph`. I want to use the `Combinatorica`` prefix to access all the symbols in `Combinatorica``, and I want to access `System`` symbols without using a prefix. And I don't want to have the symbols `Graph`, `IncidenceMatrix`, and so on, in red in Mathematica because of the naming conflict. Is there a way to use the `Combinatorica`` package without introducing naming conflicts?


Compose two special power series expansions

I have two functions $A(x), B(x)$, given in a special power series form: $A(x)=1-x^{2}\left(\frac{a}{10}-\sum_{k=1}^{9}b_{k}\left(\frac{(x^{2}-1)}{r}\right)^{k}\right)$ $B(x)=1-x^{2}\left(\frac{c}{10}-\sum_{k=1}^{9}d_{k}\left(\frac{(x^{2}-1)}{r}\right)^{k}\right)$ where $a,b_{k},c,d_{k}$ are real numbers, and $r\in\mathbb{R}^{+}$. What I want to do, is to find the composition of these series $A(B(x))$ in a similar form, i.e. find such $u=u(a,b_{k},c,d_{k},r)$ and $v_{k}=v_{k}(a,b_{k},c,d_{k},r)$ so that $A(B(x))=1-x^{2}\left(\frac{u}{10}-\sum_{k}v_{k}\left(\frac{(x^{2}-1)}{r}\right)^{k}\right)$ I tried defining these series by brute force:               A[x_] := 1 - x^2*((a/10) + Sum[b[k]*((x^2 - 1)/r)^k, {k, 1, 9}]);                B[x_] := 1 - x^2*((c/10) + Sum[d[k]*((x^2 - 1)/r)^k, {k, 1, 9}]);      And then calling `A[B[x]]//Expand` but it took forever long to run. Is there an efficient way to get an explicit power series expansion for `A[B[x]]`? Then I can just get the desired form by simple equating coefficients, but what my question is: how to get an output for `A[B[x]]` in the standard power series form? Thanks! (this is not homework)


Enter exact rational numbers easily with decimal notation

Is there a simple way to enter decimal numbers such as 0.123 so that Mathematica interprets it as an exact rational number 123/1000?


Verify factorization of RSA numbers

How would I verify the factorizations here with Mathematica? (read: multiply the two 100+ bit factors and check equality with the intended product).


Drawing tool with Overlay

I combined two plots using `Overlay`. In the output plot I want to add few modifications. Usually I right click on the plot (for `Plot` or `ListPlot`) and use the drawing tool option. But there is no such option for the output of the `Overlay`. Is there any alternative to drawing tool to modify (like adding text or arrow) a plot created by `Overlay`.


Confusing font information from CurrentValue

I'm trying to programmatically get the width of a character in Mathematica's default fixed-width font, Courier. I believe `CurrentValue` holds the answer but I'm having trouble understanding correct usage. Four examples:               In[1]:= CurrentValue[$FrontEnd, FontFamily]     Out[1]= "Times"      Example 1: Expected Courier, since input is typed in Courier.               In[2]:= s = Style["Confusion", FontFamily -> "Times"]; CurrentValue[s, FontFamily]     Out[2]= "Courier"      Example 2: Expected Times, since I specifically chose that font family for `s`.               In[3]:= CurrentValue[s, "FontMWidth"] / CurrentValue[s, "FontNWidth"]     Out[3]= 2.      Example 3: Expected exactly 1, since since all letters should be equally wide in Courier.               In[4]:= CurrentValue[$FrontEnd, "FontMWidth"] / CurrentValue[$FrontEnd, "FontNWidth"]     Out[4]= 2.      Example 4: Expected about 1.2, based on a quick measurement of the width ratio of Times' M to N. A prior question about fonts and CurrentValue has an example of using `DynamicWrapper` to get information out of dynamic objects, but I'm still curious how to use `CurrentValue` correctly in non-dynamic settings, and why the ratio of `FontMWidth/FontNWidth` is always 2. I'm on Mac OS X 10.8.5 and Mathematica 9.0.1.0.