title: How do I resolve the "Specified file is not a MathLink executable" in SerialIO package?

text: I've read and tried the previous StackExchange suggestions here about installing the SerialIO package (including placing SerialIO in the same folder as init.m and and editing the init.m file per Turkel. But when I use                <<SerialIO`      I still get the error               LinkOpen::linke: Specified file is not a MathLink executable..      (I installed SerialIO from the github repository on a Ubtuntu 12.04 64 bit machine). (Using **Terminal** ) when I change directory to the SerialIO folder and run the script               ./SerialIO      I see the "Create Link" and "Connect to Link" prompts. I have 2 related questions:   1. What should be entered at the Create Link / Connect to Link prompts to ensure SerialIO can 'connect' to a device on my system?   2. What else can I check/adjust to have _Mathematica_ correctly call the SerialIO package ?


title: How to determine Fixed Point of a function?

text: A function is defined as `f[x_]=Sqrt[1-x^2]`. How can I determine the fixed point of f? I've tried this: `FixedPoint[Sqrt[1-x^2],0]` But it only keeps running. So, help please.


title: How to convert Graphics3D object into an Image3D object?

text: How does one convert a `Graphics3D` object into an `Image3D` object? E.g., start with `Plot3D[x^2 - y^2, {x, -1, 1}, {y, -1, 1}]`.


title: Handling error in database connection (TimeConstrained)

text: I have a lot of scripts that use a database connection, and I have realized that my code should be protected against errors in my connection. For example, when my database is out for some technical reason. I tried to use this in a fake broke connection:               sqlConn:=OpenSQLConnection[JDBC["Microsoft SQL Server(jTDS)","187.111.111.111"],"Username"->"myUser","Password"->"myPass"];     (conn = TimeConstrained[sqlConn, 1]) // AbsoluteTiming      But without success as you can see. The 1 second argument is not respected. I get this:               "JDBC::error: Network error IOException: Operation timed out >>"     {76.518145, $Aborted}      Wolfram technical support asked me to try changing `$SQLTimeout`, but that did not work either. I tried before the last code:               `$SQLTimeout=1`      and the time restriction is also not respected. They then told me: > "Most of the timeout functions in Mathematica takes into account only the > CPU time spent inside the main Mathematica kernel process; it does not > include additional threads or processes. And the time OpenSQLConnection > spend is mostly on it's own thread." Some clue on how to deal with this?


title: DataEncoding and compression in HDF5 format

text: I would like to export data in HDF5 format with Mathematica 9. The Mathematica manual about Import and Export of this format can be read here. As I'm dealing with large arrays, export often lead to 100MB+ files. I'd like to use the HDF5 `"DataEncoding"` to compress the exported data, but I can't find a way to use it. For example, let's consider an array called               datapourrie = RandomInteger[99, {100000, 2, 5}]      First, I export it in simple ASCII format, for the purpose of comparison:               Export["expl.dat", datapourrie]      `expl.dat` is correctly written, with a size of 4.1 MB. Now, let's try in HDF5 format:               Export["expl.h5", datapourrie, {"Datasets", "mydata"}]      The file is correctly written in HDF5 format. It's 5.0 MB (the data + metadata). I tested it with a HDF5 viewer outside of Mathematica: everything's OK. Now, I'd like to compress it, because one of the main advantages of HDF5 format is that it can be used as a binary (compressed) file format. From the Mathematica 9 manual, I read: > `"DataEncoding"` can be none, `"GZIP"` or `"SZIP"` My problem is that I can't find a way to use this DataEncoding! I would expect the correct sentence to be:                Export["explgzip.h5", datapourrie, {"Datasets", "mydata"}, "DataEncoding" -> "GZIP"]      but it produces exactly the same file as without the `"DataEncoding"` tag. What am I doing wrong?


title: Distances of locations in the matrix form

text: I want to have the distances of the cities in the matrix form.How can I have it for example for the cities like followings that also includes the distance of the city from itself which is zero:               Union[#[[1]] -> #[[2]] & /@      Permutations[CityData[{Large, "Germany"}], {2}], # -> # & /@      CityData[{Large, "Germany"}]]


title: Efficiency problem with least square algorithm (Error in both variables)

text: I was informing myself about the least square algorithms with errors in `x` and `y`. I found this post and the top answer wasn't working for magnitudes around `10^-20`. Because I couldn't figure out why, I completed the code from belisarius to also produce errors on slope and intercept. But my code is really, really slow, if I take `10` or more `{x, y}` pairs with errors it takes way too long. I think it's the `Reduce` part that slows it down so much, but I don't know how to make it more efficient. Also the function output isn't really elegant yet.               LinFit[xi_List, yi_List, errx_List, erry_List]:=       Module[{n=Length@xi,wi,ui,vi,wmean,d,g,a,b,set,least,c,wxi,wyi},       wxi=errx^-2;       wyi=erry^-2;       wi[i_,m_]:=wxi[[i]] wyi[[i]]/(m^2 wyi[[i]]+wxi[[i]]);       ui[i_,m_]:=xi[[i]]-wmean[xi,m];       vi[i_,m_]:=yi[[i]]-wmean[yi,m];       wmean[q_List,m_]:=Sum[wi[i,m] q[[i]],{i,n}]/Sum[wi[i,m],{i,n}];       d[m_]:=Sum[wi[i,m]^2 ui[i,m]^2/wxi[[i]],{i,n}];       g[m_]:=-Sum[wi[i,m] ui[i,m] vi[i,m],{i,n}]/d[m];       a[m_]:=2 Sum[wi[i,m]^2 ui[i,m] vi[i,m]/wxi[[i]],{i,n}]/(3 d[m]);       b[m_]:=(Sum[wi[i,m]^2 vi[i,m]^2/wxi[[i]],{i,n}]-Sum[wi[i,m] ui[i,m]^2{i,n}])/(3d[m]);            set={ToRules@Reduce[\[FormalM]^3-3 a[\[FormalM]] \[FormalM] \[FormalM]+             3 b[\[FormalM]] \[FormalM]-g[\[FormalM]]==0&&\[FormalC]==wmean[yi,\[FormalM]]-             \[FormalM]wmean[xi,\[FormalM]]&&\[FormalA]==Sqrt[1/(n-2) Sum[wi[i,\[FormalM]]             ( \[FormalM] ui[i,\[FormalM]]-vi[i,\[FormalM]])^2,{i,n}]/             Sum[wi[i,\[FormalM]] ui[i,\[FormalM]]^2,{i,n}]]&&\[FormalB]==Sqrt[(             Sum[wi[i,\[FormalM]] xi[[i]]^2,{i,n}]/Sum[wi[i,\[FormalM]],{i,n}])*             \[FormalA]^2],{\[FormalM],\[FormalC],\[FormalA],\[FormalB]},              Backsubstitution->True]};       least=Sum[wxi[[i]] (xi[[i]]-(yi[[i]]-\[FormalC])/\[FormalM])^2+wyi[[i]] (yi[[i]]-                (\[FormalM] xi[[i]]+\[FormalC]))^2,{i,Length@xi}]/.set[[Flatten@Position[                \[FormalM]/.set,_Real]]];       c=Flatten@set[[Flatten@Position[\[FormalM]/.set,_Real]]][[Position[           least,Min@least][[1]]]];       {Function[(\[FormalM]/.c[[1]])#+\[FormalC]/.c[[2]]][x],           {\[FormalA]/.c[[3]],\[FormalB]/.c[[4]]}}     ]


title: Swapping elements of list

text: Say I have a directed graph inputted in the following format in _Mathematica_ :               g = {{1, "a", 2}, {2, "b", 1}}      I'd like to plot this graph using `GraphPlot` in _Mathematica_ , which is the following syntax:               GraphPlot[{{1 -> 2, "a"}, {2 -> 1, "b"}}, VertexLabeling -> True, DirectedEdges -> True,          VertexCoordinateRules -> Auto, VertexLabeling -> True]      How would I swap the middle elements and the last elements in any list like `g`, so that `g` would look closer to the argument of `GraphPlot`?               {{1 -> 2, "a"}, {2 -> 1, "b"}}       I have searched the _Mathematica_ documentation but was unable to find a good way of doing this.


title: Import numeric data into Mathematica

text: I have a C++ program that outputs a set of numbers at each time step. A blank line separates successive time steps. Here is an example of my data format:               0.2 42.8     0.4 12.3     0.6 32.1     0.8 37.3          0.2 44.2     0.4 17.8     0.6 39.0     0.8 30.1      I want to import this into _Mathematica_ with the following format:               data = {       {{0.2`, 42.8`}, {0.4`, 12.3`}, {0.6`, 32.1`}, {0.8`, 37.3`}},       {{0.2`, 44.2`}, {0.4`, 17.8`}, {0.6`, 39.`},  {0.8`, 30.1`}}       };      i.e., the data for each time step is in one list. How do I do this?


title: Trace of FullSimplify

text: I have a symbolic function and I used `FullSimplify` command to simplify the equation given below. I am calculating it by hand but I couldn't reach the same solution. I used `Trace` command to observe the intermediate steps but trace only gives the expression before `FullSimplify`. Are there any possible methods that I can observe the steps of simplification?                   Trace[FullSimplify[2 b (-(1/(1 - fd)) + 1/fd) +         (2 a (1 - (b (1 - 1/fd + 1/(fd t)))/(a + b)) t)/        (1 - (1 - fd) t - (b fd (1 - 1/fd + 1/(fd t)) t)/(a + b)) == 0]]


title: Non-commutative algebra

text: I'm constantly dealing with non-commutative algebras. `**` is inbuilt, non- commutative and associative. That's good :-) But it is not distributive. Rats.   * What is a simple way (I probably won't need much more) to have, say, `(a1 + a2 + a3)**(b1 + b2 + b3)` always expand to `a1**b1 + ... + a3**b3`, on the fly?   * And if I like to add (also executed on the fly) laws like `a1**b1 = c1 + d1`?   * And, last question, if I did and have `a2**a1**b1` (with, say, `a2**a1 = e1` forced), do `(a2**a1)**b1` and `a2**(a1**b1)` substitute to `e1**b1` and `a2**(c1+d1)`, respectively, or both to `e1**b1` due to flatness of `**`?


title: Export Graph to PDF

text: I know that I exported Graphs to PDFs before but it doesn't seem to work any more. I tried               K5 = GraphData[{"Complete", 5}]     Export["K5.PDF", K5]      And I get a PDF with a grey rectangle in it. Even exporting to TIFF doesn't seem to work. When I right click the `Graph` object I can do a "Convert to Graphics". Then exporting this converted Graph to PDF works. Why doesn't it work directly? If it's not possible ... How can I convert a `Graph` to `Graphics` programatically before calling a export to PDF? I'm using Mathematica 9.0.0 on Windows 7 x64 UPDATE: Problem solved by Szabolcs I checked if dynamic evaluation was checked and it was. However when I restarted Mathematica it did work as expected. I realize with hindsight that this morning going through some help files a warning was issued about dynamic evaluation. I didn't really pay attention to it but probably it got disabled automatically but did not show that change in the evaluation menu option. Also Show[] is nice to know that it effectively converts the Graph to a non dynamic graphics object!


title: Dynamic and Graphics3D crash in Ubuntu

text: Im running ubuntu 12.04 and sometimes mathematica 9.0 crashes when I have Dynamic Content or graphics 3d. I'm wondering if this has happened to anyone else? I wouldn't be surprised if this is a problem specific to the settings on my machine but i figured it is worth asking. I get the following error message:               X Error of failed request:  GLXBadContext       Major opcode of failed request:  154 (GLX)       Minor opcode of failed request:  6 (X_GLXIsDirect)       Serial number of failed request:  93197       Current serial number in output stream:  93196          X Error of failed request:  BadAlloc (insufficient resources for operation)       Major opcode of failed request:  154 (GLX)       Minor opcode of failed request:  3 (X_GLXCreateContext)       Serial number of failed request:  93192       Current serial number in output stream:  93197          X Error of failed request:  GLXBadContext       Major opcode of failed request:  154 (GLX)       Minor opcode of failed request:  5 (X_GLXMakeCurrent)       Serial number of failed request:  93198       Current serial number in output stream:  93198          Mathematica has received the signal: SIGSEGV and has exited.     If possible, please report this problem to support@wolfram.com     describing in as much detail as possible what you were doing     when the problem occurred.      Usually I can fix the problem by restarting the notebook between 1-10 times. Eventually, it works and stops crashing.


title: Randomly generated polymer with certain spatial density

text: For simplicity's sake, let the polymer's composing particle be integer 3-tuples (on 3D Cartesian grid), such that:   1. Polymer-ness -- for all particle there is an directly adjacent neighbor. i.e in directions of {{0,0,1}, {0,0,-1}, {0,1,0}, {0,-1,0}, {1,0,0}, {-1,0,0}}   2. Of loose spacial density -- there's no more than $d_n$ particles in a radius $n$ sphere around each particle The plot looks interesting. DLA-esque. In fact, if we let $ d_n = <3^n> $, it appears rather dimensionless i.e. factal looking However my code was slow and it's a pain to generate a set larger than 400 particles (~7mins) ![200 particles](http://i.stack.imgur.com/WW7Gt.png) Moreover, how can I spin the plot independently around 2 spatial axis? (like that asteroid in Armageddon IYNWIM) I tried ViewAngle and use 2 RotationTransform to rotate the vector. However, that's not how it seems to works.               Clear["Global`*"];     colorPalette = (#/3 + 0.2) & /@ {1, 2, 3};     radiusPlaette = {0.63, 0.53, 0.46};     adjLimit = {3, 9, 27, 81};     idx = Range[Length@adjLimit];     dir = {{1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0}, {0, 0, 1}, {0,       0, -1}};     pos = {{0, 0, 0}}; test = {};          adj[x_, d_] := Cases[pos, _?(EuclideanDistance[x, #] <= d &)];          Dynamic[Length[pos]]          (*Polymer, nice-looking spheres*)     Dynamic[     Graphics3D[{Hue[Take[colorPalette, {Mod[#2, 3] + 1}], 1, 0.1],       Sphere[#1 - {0.5, 0.5, 0.5} - Mean[pos],         Take[radiusPlaette, {Mod[#2, 3] + 1}]]} & @@@         MapThread[List, {pos, Range[Length@pos]}], Axes -> False,        Boxed -> False, Lighting -> Automatic, SphericalRegion -> True ]]          (*Alternative layout     (*Colored Boxes*)      Dynamic[Graphics3D[{Hue[1.*#2/3+0.15,0.7,1],Cuboid[#1-{0.5,0.5,0.5}-     Mean[pos]]}&@@@MapThread[List,{pos,Range[Length@pos]}],Axes->     False,Boxed->False,Lighting->{{"Ambient",White}}, SphericalRegion->True]]     *)          Timing[      Do[       out = Catch[While[True,          stem = RandomChoice[pos];            rnd = stem + RandomChoice[dir];          listadj1 = Length /@ (adj[rnd, #] & /@ idx);              adj1 = And @@ MapThread[(#1 <= #2) &, {listadj1, adjLimit}];          listadj2 = (Function[x, Max[Length /@ (adj[#, x] & /@ adj[rnd, x])]] /@ idx);              adj2 = And @@ MapThread[(#1 <= #2) &, {listadj2, adjLimit}];               If[! MemberQ[pos, rnd] && adj1 && adj2,(*Debug*)           AppendTo[test, listadj2]; Throw[rnd]];          ]];       AppendTo[pos, out];       , {399}]      ]     (*Debug*)     Last@Sort[test]     Tally[Length /@ (adj[#, 2] & /@ pos)]      .


title: Permanent minors

text: The function `Minors` yields the minors of a matrix. Is there a function that yields the permanent minors of a matrix?


title: Cut out circle out of circle

text: In the documentation of `FilledCurve`, one can create a circle "cut-out" of a bigger circle using `FilledCurve` and `Beziercurve`. Is it also possible using two `Circle` commands and some Boolean operator, as can be done with Adobe Illustrator using the Pathfinder commands? Does some counterpart exist in _Mathematica_? Edit: As asked in the comments: there exist a few Pathfinder operations, the most kwown are   * Add two graphics   * Substract one graphic from the oterh   * Union of two graphics   * "Exclusive" union of two graphics (without intersection)   * Intersection of two graphics Thanks for all inputs!


title: ContourPlot3D for a 3D vector contour plot

text: The procedure `ContourPlot3D` allows plotting the contour lines of the components of a 3D-vector. The problem is I don't know how to give the contour planes of each individual component its own colour. To be more specific: green for the X-component, yellow for the Y and red for the Z-component contour planes.               Clear["Global'*"];     B[x_, y_, z_, a_, b_, c_, Br_] :=       (e := {0, 0, 0};        Sum[s = x - a (-1)^i;          Sum[t = y - b (-1)^j;           Sum[u = z - c (-1)^k; r = Sqrt[s^2 + t^2 + u^2];            e = e + (-1)^(i + j + k) {Log[r - t], Log[r - s],                ArcTan[(s t)/(r u)]};           , {k, 0, 1}], {j, 0, 1}]  , {i, 0, 1}];        Return[e Br/(4 Pi)]);     a = 0.0456/2; b = a; c := 0.0175; Br := 1.4;          ContourPlot3D[      B[x, y, z, a, b, c, Br], {x, -2 a, 2 a}, {y, -2 a, 2 a}, {z, 0, 4 c},       Contours -> 21, PlotLabel -> "Field cuboidal magnet",       RegionFunction -> (! (#1 > 0 && #2 < 0 && #3 > 0) && ! (#1^2 <               a^2 && #2^2 < b^2 && #3^2 < c^2) &),       ContourStyle ->        Table[Directive[Opacity[0.3], ColorData["BrightBands"][f],          Specularity[White, 60]], {f, -0.5, 0.5, 0.05}], PlotPoints -> 16,       MaxRecursion -> 0, Mesh -> False]       ![Mathematica graphics](http://i.stack.imgur.com/jJEix.png)


title: Two quick Mathematica Questions about the dictionary

text: Question1: Get the list of pairs of the form {language,number of words in dictionary}. Call this list langlength What I did was this:               langlength =        {{Arabic, Length[DictionaryLookup[{"Arabic", All}]]},         {BrazilianPortuguese, Length[DictionaryLookup[{"BrazilianPortuguese", All}]]},         {Breton, Length[DictionaryLookup[{"Breton", All}]]},......}      And so on. What's a shorter way of doing this? * * * Question2: Look at all the words contained in all the dictionaries. What are the ones of maximum length? I had:               Max[StringLength[lang]]      But that's not working and not sure what's missing. Please help me with either or both questions. * * * I set lang = DictionaryLookup[All]


title: Symmetry-finding packages

text: Where can I find the most up-to-date or whatever you consider to be the most useful symmetry-finding package for differential equations? I do not intend to restrict to, but would like to include those, that are designed to work within Mathematica. I'm looking for something analogous to this for Mathematica (software and documentation) or this for Maple.


title: Finding the intersection of curves in a one-parameter family

text: I have a function               f[c_] := y^2 - 2 x^2 (x + 3) == c ((y + 1)^2 (y + 9) - x^2)      I need to find the points of intersection between the plots of f[0] and f[2]. How can I find these intersections? Also, how can I visualize the intersections of the five curves `f[-1]`, `f[0]`, `f[1]`, `f[e]`, and `f[-Pi]`?


title: How to use some other driving process than the WienerProcess?

text: According to the following reference page http://reference.wolfram.com/language/ref/ItoProcess.html > The driving process _dproc_ can be any process that can be converted to a > standard Ito process and > Processes _proc_ that can be converted to standard ItoProcess form include > OrnsteinUhlenbeckProcess, GeometricBrownianMotionProcess, > StratonovichProcess, and ItoProcess. However, it does not seem to work in my example:               proc = ItoProcess[\[DifferentialD]x[          t] == -x[t] \[DifferentialD]t + \[DifferentialD]w[t],        x[t], {x, 1}, t,        w \[Distributed] OrnsteinUhlenbeckProcess[0, 1, 1]]     RandomFunction[proc, {0., 5., 0.01}]     ListLinePlot[%, Filling -> Axis]      which resulted in the error: RandomFunction::unsproc: The specification ItoProcess[[DifferentialD]x[t]==[DifferentialD]w[t]-[DifferentialD]t x[t],x[t],{x,1},t,w[Distributed]OrnsteinUhlenbeckProcess[0,1,1]] is not a random process recognized by the system. Note that in defining the ItoProcess proc like above, `w \\[Distributed] WienerProcess[0,1]` would work, but `w \\[Distributed] OrnsteinUhlenbeckProcess[0, 1, 1]` does not.


title: I want to create an arrow so that my output of my program will indicate 2 Sin x is the plotted graph

text: Plot[2 Sin[x], {x, -2 Pi, Pi},             PlotStyle -> {Dashing[0.0155], Thickness[0.006]},             Ticks -> {{-2 Pi, -Pi, 0, Pi}, {1, 2}}, Filling -> Axis,             Epilog -> {Text[Style["2 Sin(x)", Black, 10], {-1, -1}, {3.5, -26}],                        Text[Style["(-1,-1.68)", Black, 10], {-1, -1}, {-1.3, 6}],                         PointSize[0.017], Point[{-1, -1.68}]},             FillingStyle -> Yellow,             Background -> LightGray]      ![Mathematica graphics](http://i.stack.imgur.com/W2R81.png)


title: Expand Graphics based on all elements

text: How might I force the following Graphics element to expand to contain the Inset text? ![enter image description here](http://i.stack.imgur.com/zcUSK.png)               Graphics[{White, Rectangle[{0., 0.0}, {1, 1}],       Yellow, Rectangle[{0., 0.0}, {.2, 1}],       Black,       Inset[        Style[ToString[Unevaluated@abcdefghijklmnopqr],         FontSize -> Scaled[.4]]        , ImageScaled[{0.2753623188405797,                0.48550724637681175}], {Left, Center}]       },  ImagePadding -> 0, PlotRangePadding -> 0,      PlotRangeClipping -> True]      The following gives the desired output although it doesn't solve the issue because ultimately I am trying to nest the text inside another Graphics element: `Row[{Graphics[{}, ImageSize -> {10, 23}, Background -> Yellow],Text["abcedefghijklmnopqr"]}]`. Ultimately I have several nested Insets but unfortunately I can't seem to force the Insets to nest inside of each other and therefore show entirely on the screen. These plot range questions seems to be related. The first question titled "How to determine PlotRange to include all Graphics" is likely a duplicate, although I believe you must ImageSize and PlotRange to get correct values.


title: Replacing character in position

text: I'm trying to use Mathematica to make some work on binary data, and I'm missing something. Consider the string `"111"`. I want to flip the last bit to become `"110"`. My guess would be to use `StringReplacePart`, but I'm struggling to achieve this:               StringReplacePart["111", "0", 3]  (* returns "0" *)      What is the function for replacing a single character at a given position?


title: How to label the coordinates of the plotted graph?

text: How can I label the coordinates of the plotted graph? I want to label the coordinate of $(-1,-1)$.               Plot[2 Sin[x], {x, -2 Pi, Pi},       PlotStyle -> {Dashing[0.0155], Thickness[0.006]},       Ticks -> {{-2 Pi, -Pi, 0, Pi}, {1, 2}}, Filling -> Axis,       Epilog -> {PointSize[0.017], Point[{-1, -1.68}]},       FillingStyle -> Yellow, Background -> LightGray]


title: Plot solution of equation with shift

text: For example I have an equation $F[x,y]==0$. Let $S$ is a set of solutions of equation. $(a,b) \in S \leftrightarrow F[a,b]=0$. I wanna draw a set $\{(a,b) + \operatorname{grad} F (a,b) : (a,b) \in S\}$, how can I do that? For example I have               F[x_, y_] := x^2 + y^2 - 1;      G[x,y]:={2x,2y}      y1[x]=Sqrt[1-x^2]      y2[x]=-Sqrt[1-x^2]      ParametricPlot[{{t, y1[t]} + G[t, y1[t]], {t, y2[t]} + G[t, y2[t]]}, {t, -1, 1}]      There are $G=\operatorname{grad} F(x,y)$, $y1,y2$ — solutions of $F(x,y)=0$. But in some cases I dont know how to solve $F(x,y)=0$ and find $y1,y2$. For example in case $F(x,y)=xlnx−y$


title: Module in numerical model for NonlinearModelFit is slow and leaks memory

text: I am trying to make a `NonlinearModelFit` where the model is the result of a numerical calculation. My code works, but it is very slow and also seems to have a memory leak. I'd appreciate advice about how to improve the code, make it faster, and stop leaking. A simplified version of my model is:               $HistoryLength=0;     model[gnIN_?NumberQ, gpIN_?NumberQ] :=        Module[{rep, eqs, sol, t},         rep = {gn -> gnIN, gp -> gpIN, n0 -> 10, p0 -> 0.01};         eqs = {          n'[t] == -gn (n0 + n[t]) f[t],          p'[t] == -gp ((p0 + p[t])) (1 - f[t]),          n[t] == p[t] +f[t],          n[0] == 10, p[0] == 10, f[0] == 0};         sol = NDSolve[eqs /. rep, {n, p, f}, {t, 0, 10}];         First[(n[#] + p[#])/(n[0] + p[0]) /. sol] &]      [ **Edit** : maximum time in `NDSolve` changed from 50 to 10. See comment below.] There are three coupled equations (one of them not a differential equation, so it could be removed easily). The output that I want for my model, however, is not `n`, `p`, or `f`, but rather `(n+p)/(n[0]+p[0])`. I have used a pure function to pass this out of the model, but I don't know if there's a better way. We can make some fake data by               tmp = model[1,.1];     data = Table[{i, tmp[i]}, {i, 0, 50}];      I then call               MemoryInUse[]/10^6.     nlm=NonlinearModelFit[data, {model[gn,gp][t], gn>=0 && gp>=0},{gn,gp},t];     MemoryInUse[]/10^6.      This runs successfully, giving best fit parameters `{gn -> 1.04935, gp -> 0.0998232}`, but it takes several minutes -- 376 seconds [ **Edit** : revised to 68 seconds], from `AbsoluteTiming` on my 3.2GHz i5 iMac running MMA 9. (In this case, I could clearly give it excellent initial guesses, but that's a bit harder in my real problem. As an aside, giving it initial guesses of `{2,0.2}` causes it to take 450 seconds and return `{1.48,0.098}` as best fits, badly missing on `gn`.) On this time that I'm running, the `MemoryInUse` commands return `92.9` and `101.1`. Running it again will cause steady increase in memory usage, which is why I believe there is a memory leak. Running `Names["*$*"]` returns a list with many variables like n$10849.               Names["n*$*"]//Length         Names["p*$*"]//Length      returns `289` and `336`. I assume that all these `n` and `p` variables are being kept for some reason related to the return of the `Module`. But if I run the `NonlinearModelFit` again, the total memory continues to rise, but the number of `n$*` and `p$*` variables does not continue to increase -- it seems to stay very close to 300, indicating that some garbage collection is occurring. Also, the total memory used by those `n$*` and `p$*` variables, using `symbolMemoryUsage` from here, does not explain the increase in memory usage of the kernel. That is,               Total[symbolMemoryUsage /@ Names["*n$*"]]         Total[symbolMemoryUsage /@ Names["*p$*"]]      returns `13872` and `16176`, which is much less than the 8 MB increase in memory use on running the `NonlinearModelFit`. In my actual case, the increased memory use can reach over 5 GB (and grind my computer to a halt) before `NonlinearModelFit` finishes. In this simple case, the leak is smaller, but it is still there. Running               MemoryInUse[]/10^6.     AbsoluteTiming[Do[model[1, .1], {i, 1, 1000}];]     MemoryInUse[]/10^6.      returns `104.161`, `4.34`, and `104.261`. So the memory increase is about 100 KB with each 1000 evaluations of `model`. When I add a simple counter into `model` to count the number of times it is evaluated during the `NonlinearModelFit`, the answer is about 85000, indicating that the 8 MB increase in memory use is mostly due to a leak from `model`. Similarly, the time to evaluate `model` 85k times should be about 370 seconds, which is close to the total evaluation time. The slowness of my code and the memory leak are all in my `model`. I understand that there's a limit to how fast a model with `NDSolve` could possibly be, but I suspect it can be better than this. Previous discussions of `Block` vs. `Module` have left me concerned that `Block` will do things I don't understand, but I haven't tried it. Any advice for coding practice (in particular, better ways to return the function from `model` so it's in the correct format to put into `NonlinearModelFit`), speed, or memory will be greatly appreciated. **EDIT** : In case people have been dissuaded from working on this problem by the running time of my example code, I have changed the maximum time of `NDSolve` in `model` from 50 to 10, which makes the `NonlinearModelFit` run in 68 seconds, rather than 376. The memory leak is still there and of the same magnitude as in the original question. Any comments or advice welcome!


title: Componentwise Addition of TemporalData

text: I'm a little confused with the `TemporalData` structure in Mathematica, in the sense that it doesn't seem to behave like a list. What I'd like to do is plot the sum and difference of a Brownian motion and an OU process, and so far, generating and plotting these individual processes is not a problem:               Z = RandomFunction[WienerProcess[0, 1], {0, 1, 0.01}];          L = RandomFunction[OrnsteinUhlenbeckProcess[0, 1, 1, 0], {0, 1, 0.01}];          ListLinePlot[{Z,L}]      However, plotting their sum with               ListLinePlot[Z+L]      yields an error: > >     ListLinePlot::lpn: > TemporalData[Automatic,{<<1>>}]+TemporalData[Automatic,{<<1>>}] >     is not a list of numbers or pairs of numbers. >   I've checked out this related post, but am unsure how to interpret it in the context of my particular problem. Is there a simple way to do what I'd like?


title: When to use Compile

text: I am new to Mathematica and have a general question: Working with matrices I have the impression that Compile can only be used if the elements of a matrix are ONLY Integers or ONLY Reals. No mixed types are allowed. But my matrices generally include some missing elements like               m = {{1., 2.}, {Null, 3.}}      Is there a way to compile m*m ?


title: How do I plot a proper streamline plot, including spacings and line endings?

text: Mathematica includes two nice built-in tools to visualize vector fields, `VectorPlot` and `StreamPlot`. The latter is a useful tool, and it plots the streamlines of the given 2D vector field. ![enter image description here](http://i.stack.imgur.com/MIF0J.gif) A streamline is an integral curve of the vector field: that is, a curve $\vec\alpha(s)$ whose derivative $\frac{d\vec\alpha}{ds}$ is proportional at every point to the vector field $\vec F(\vec\alpha(s)$ at that point. These are very useful tools for understanding the qualitative behaviour of many types of vector fields. However, in certain cases, these diagrams require a bit more structure. In situations where the divergence $\nabla\cdot\vec F$ of the field matters, and in particular for   * streamlines of a fluid flow, and   * field lines of an electric or magnetic field, there are two constraints which are followed, by convention, very strictly, and which make available quantitative information about the field from the diagram, by encoding the field strength in the local density of streamlines. (For more on how and why they work, see this physics.SE thread). Specifically:   * Streamlines should never end or begin in any region in which $\nabla\cdot\vec F$ is zero; they should start at point sources or regions where $\nabla\cdot\vec F>0$, and end at point sinks or regions where $\nabla\cdot\vec F<0$.   * The vector field flow between adjacent streamlines, i.e. the integral $$\int_L\vec F\cdot d\vec s^\perp$$ where $L$ joins the two streamlines, should be constant. (There is some interplay when the field is in 3D, where it's the flow across unit "cell" surfaces that join three or more streamlines, or when one is displaying a 2D cross-section of a 3D field, but the principle remains.) Unfortunately, the built-in `StreamPlot` function does nothing of the sort, at least out of the box, and I can find no built-in options that will enforce this type of behaviour. For an example, consider the vector fields $\hat{\mathbf{r}}/r^n$, for $n=1$ and $n=2$. These are the electric fields produced in 3D by a line of charge and a point charge, respectively. When seen as a 2D field, the former has no divergence, and the corresponding streamlines should start at the origin and end at infinity; the latter, on the other hand, has negative divergence as a 2D field and its intensity thins out faster than the first, so the local density of field lines should thin out as $1/r$ away from the origin. If you try to plot them with Mathematica, though, the opposite happens: ![enter image description here](http://i.stack.imgur.com/Vxk7k.png)               Table[       StreamPlot[{x, y}/(x^2 + y^2)^n, {x, -2, 2}, {y, -2, 2}        , ImageSize -> 400, PlotLabel -> "(x,y)/r^{n+1}, n="<>ToString[2 n - 1]        ]       , {n, {1, 3/2}}] // GraphicsRow      The field from the line charge, on the left, has approximately constant spacing after a while, but here are streamlines that are created almost at $r=1$. The field on the right is from a point charge, and it shows the opposite of what it should:   * streamlines are _created_ away from the origin, instead of destroyed,   * _more_ streamlines are created than for a line charge,    * and to top it off, the field is not even rotationally symmetric. ### Is there a way to overcome these shortcomings and make StreamPlot, with appropriate options, produce correct versions of these plots? Is there some other way to produce such a diagram properly?


title: How to demonstrate lack of stability with advection equation

text: I am trying to that using a coarse grid with an explicit method for, say, the advection equation leads to an unstable solution. The trouble is _Mathematica_ avoids unstable solutions with good `Method`s or I am unable to set a coarse spatial grid or temporal grid spacing. **My code is as follows:**               sol = NDSolve[{D[u[t, x], t] ==          0.5 D[u[t, x], x, x] + u[t, x] D[u[t, x], x],          u[t, -Pi] == u[t, Pi] == 0 , u[0, x] == Sin[x]},        u, {t, 0, 2}, {x, -Pi, Pi}, MaxStepFraction -> 1/10]      **And a plot of sol is:**               Plot3D[Evaluate[u[t, x] /. First[sol]], {t, 0, 2}, {x, -Pi, Pi},       PlotRange -> All      ![enter image description here](http://i.stack.imgur.com/SNI34.png) Should I not be using `MaxStepFraction` to demonstrate instability? What is the most coarse explicit `Method` I could use? I have tried `Method->{"ExplicitEuler"}` but this was good enough to resolve instabilities and I found a stable solution without kinks at larger times.


title: LabelStyle doesn't affect PlotLegends

text: > **Possible Duplicate:**   >  Setting the default font for PlotLegends Using version 9 The option setting for `LabelStyle` in plots (I've tried this in `Plot[]`, `DateListPlot[]`, and `ListLinePlot[]`) doesn't appear to affect `PlotLegends[]` at least the way I've tried it:               Plot[{Sin[x], Cos[x]}, {x, 0, 10},       LabelStyle -> (FontFamily -> "Helvetica Neue"),       PlotLegends -> {"Sin", "Cos"}]          Plot[{Sin[x], Cos[x]}, {x, 0, 10},       LabelStyle -> (FontFamily -> "Helvetica Neue"),       PlotLegends -> {"Sin", "Cos", LabelStyle -> (FontFamily -> "Helvetica Neue")}]      Both sets of code give the exact (to an eye) output: ![enter image description here](http://i.stack.imgur.com/UHyWk.png) Note the legend font remains in some default (TimesNewRoman) setting, where everything else in the plot properly goes to "Helvetica Neue". I've also tried wrapping `Style[]` around each of the legend names to no avail. Any thoughts on how to do this or work around it? * * * I stumbled upon a workaround, but it doesn't seem very elegant to me so I remain open to other solutions:               Plot[{Sin[x], Cos[x]}, {x, 0, 10},       LabelStyle -> (FontFamily -> "Helvetica Neue"),       PlotLegends ->        SwatchLegend[{"Sin",          "Cos"}, {LabelStyle -> (FontFamily -> "Helvetica Neue")}]]      ![enter image description here](http://i.stack.imgur.com/mU7Tf.png)


title: VoronoiMesh for 3D points

text: I believe that this is a doc error in V10 (this was programmed to be but not implemented). The new `VoronoiMesh` should work for 3D set of points. The `DelaunayMesh` function works. Here is a doc example:               pts = RandomReal[{-1, 1}, {25, 3}];     DelaunayMesh[RandomReal[{-1, 1}, {25, 3}]]      ![enter image description here](http://i.stack.imgur.com/qjDiH.png) But if you try:               pts = RandomReal[{-1, 1}, {25, 3}];     VoronoiMesh[pts]      You get the error: ![enter image description here](http://i.stack.imgur.com/g3UrU.png) Docs for Voronoi say: > The cells will be intervals in 1D, convex polygons in 2D, and convex > polyhedra in 3D. Tested in V10.0.0 for Mac and Win.


title: Curious behavior using SpanFromLeft in Grid[]

text: I need to set up a rather complicated `Grid[]` and I've run into a curious problem. I've reduced it to a simple example. See the following 2 sets of code and their output:                   plot = Plot[Sin[x], {x, 0, 6 Pi}, ImageSize -> 175];         Grid[          {           {1, 2, 3, 4, 5},           {2, "x", "x", "A long title... ", 70000},           {3, "xx", "xx", "", ""},           {4, "xxx", SpanFromLeft, plot, SpanFromLeft},           {5, "xxxx", SpanFromLeft, SpanFromAbove, SpanFromBoth},           {6, "xxxxx", SpanFromLeft, SpanFromAbove, SpanFromBoth},           {7, "xxxxxx",  SpanFromLeft, SpanFromAbove, SpanFromBoth},           {8, "xxxxxxx", SpanFromLeft, SpanFromAbove, SpanFromBoth},           {9, "xxxxxxxx", SpanFromLeft, SpanFromAbove, SpanFromBoth},           {10, "xxxxxxxxx", SpanFromLeft, SpanFromAbove, SpanFromBoth}          } ,          Alignment -> {Left, Top}          ]              "-----------------------------"              Grid[          {           {1, 2, 3, 4, 5},           {2, "x", "x", "A long title... ", 70000},           {3, "xx", "xx", "", ""},           {4, "xxx", "", plot, SpanFromLeft},           {5, "xxxx", SpanFromLeft, SpanFromAbove, SpanFromBoth},           {6, "xxxxx", SpanFromLeft, SpanFromAbove, SpanFromBoth},           {7, "xxxxxx",  SpanFromLeft, SpanFromAbove, SpanFromBoth},           {8, "xxxxxxx", SpanFromLeft, SpanFromAbove, SpanFromBoth},           {9, "xxxxxxxx", SpanFromLeft, SpanFromAbove, SpanFromBoth},           {10, "xxxxxxxxx", SpanFromLeft, SpanFromAbove, SpanFromBoth}          } ,          Alignment -> {Left, Top}          ]      Output: ![Grids](http://i.stack.imgur.com/PgnZu.png) Both grids have 10 rows x 5 columns. They have identical code excepting for the position at row 4 column 3:   * 1st grid has SpanFromLeft at that position.    * 2nd grid has "" at the same position. Immediately to the left of row 4 column 3 I have the plot. Can anyone explain why I get such different alignment in the two grids?


title: How to run mathematica scripts without initializing the kernel every time

text: I have written a Mathematica script that is to be run periodically on a Raspberry Pi. The code takes about 3 seconds to execute if I test it in a CLI Mathematica session. However, when I execute the script with               wolfram -script script.w > out.csv      it takes more than 10 seconds. The output of the script is a single `String` three ASCII characters long, so writing output to file does not take a significat part of the time. I thus assume most of the extra time comes from kernel initialization. I'd like to initialize Mathematica kernel once and then run my script periodically without needing to initialize the kernel every time. Is this possible? * * * **UPDATE** Following the answer from this related question I tried to make it work like this:               mkfifo mmpipe     tail -f mmpipe | wolfram -noprompt &      However, when I pipe a command that contains a file-importing function like ReadList, it stays in interactive mode and does not exit to shell:               echo 'ReadList["/home/pi2/data.csv","String"]'>mmpipe      > >     { ... , "2014/02/05 21:35:02,0.28", "2014/02/05 21:40:02,0.00", > "2014/02/05 21:50:02,0.00"} >     _ >   So I can't use it in an automated process.


title: How to align cells in a grid?

text: I would like to align the text in the gauge such as the label "AKs" is in the center of the gauge and the value (60) is in the upper right corner with a smaller font. How can I achieve this? I tried playing with the Alignment option and SpanFromLeft and related functions with no success. Thanks.               bar = VerticalGauge[#1, {0, 100}, GaugeMarkers -> "ScaleRange",          GaugeStyle -> {Green, GrayLevel[1]},          TicksStyle -> None, GaugeFrameSize -> None, ScalePadding -> None,          ImageSize -> 50, AspectRatio -> 1, LabelStyle -> None,          Epilog ->           Text[Grid[{{"", Style[#1, Italic, Small]}, {Style[#2, Bold],               ""}}], Scaled[{0.5, 0.5}]], ImagePadding -> 0,          PlotRangePadding -> 0, Frame -> True, FrameTicks -> False] &;     bar[60, "AKs"]


title: Iterate until condition is met

text: I want to find the first 5 prime numbers of the form $n^6 + 1091$. I have used this code:                Timing[Select[Table[n^6 + 1091, {n, 10000}], PrimeQ, 5]]      Which gives the desired answer, and takes 0.0156 seconds. What if I didn't have a rough idea of what values of $n$ to check?               Timing[Select[Table[n^6 + 1091, {n, 100000}], PrimeQ, 5]]      Takes 10 times as long. So, my question is: Is there a simple(ish) way to make _Mathematica_ stop when the desired number of solutions are found?


title: Ways to change an explicit function into a pure function

text: I'm trying to use `FixedPoint` to solve a transcendental equations, but the first argument of the `FixedPoint` should be a pure function, But the function I have to use is an explicit function from a lot of preceeding symbolic calculations and is very complicated, e.g.,               func=-HankelH1[1, 0.6 Sqrt[27.415568 - \[Beta]^2]] ((1/(       57.641231 - \[Beta]^2))       1.6666667 \[Beta] BesselJ[1,          0.6 Sqrt[57.641231 - \[Beta]^2]] ((          1.6666667 \[Beta] BesselJ[1,             0.6 Sqrt[57.641231 - \[Beta]^2]] HankelH1[1,             0.6 Sqrt[27.415568 - \[Beta]^2]])/(27.415568 - \[Beta]^2) - (          1.6666667 \[Beta] BesselJ[1,             0.6 Sqrt[57.641231 - \[Beta]^2]] HankelH1[1,             0.6 Sqrt[27.415568 - \[Beta]^2]])/(57.641231 - \[Beta]^2))      My failed effort is to use `Function[\\[Beta],func]&`, but it seems the value of func doesn't get into the Function, because of scoping problem I think. Is there any clever way to change functions like this to be a pure function??


title: Find root of a function defined as a Module

text: I have a simple module like               BCdet[x_, y_] := Module[       {AuxMat},       AuxMat = Mat /. {f -> x, A -> y};       Det[AuxMat]       ]      where `Mat` is a normal matrix 12x12 with parameters `f` and `A`. The above defined module returns a complex number and it works without any problems. Then I would like to find root of its real part for given `A=trailA` and for a complex `f`               FindRoot[      Re[BCdet[f, trialA]],      {f, 2.5 + 0. I},      StepMonitor :> Print["Step to f = ", f]      ]      Unfortunately, this does not work at all. I cannot get any result. I use `StepMonitor` to check it, however, it does not give any output. Any idea where might be the problem?


title: Why is SystemDialogInput failing to return a save file path?

text: I am encountering a problem using `SystemDialogInput` within a `Button`. The code below shows what I am doing. To test this create a couple of files "myfile.txt" and "myfile2.txt" etc.               DynamicModule[{path = $HomeDirectory},           Column[{       Button["Save",        path = SystemDialogInput["FileSave", "myfile.txt"];        Print[FullForm@path],        BaseStyle -> {"GenericButton", 11, Bold},        ImageSize -> 120],       Dynamic[path]       }]      ]      **1:** Press the "Save" button. **2a:** Find e.g. "myfile.txt" and click on it; or (next try) **2b:** Type "myfile.txt" in the input field. **3:** I then get the warning message asking me if I want to replace. I choose "Replace". The problem is that the pathway 1->2a->3 seems to work ok, however 1->2b->3 seems to abort (no path returned). In other words when you type the file name of an exisitng file into the input field and try to save nothing happens. I am using Mma 8.0.4 on OS X 10.6.8. WRI tech support say they cannot reproduce this. **Q1.** Can anyone else reproduce this? **Q2.** Can anyone suggest possible causes? For those who post that it works for them can you give your system and version details. Thanks **Edit** I must be in need of a break because it does seem that the evaluation timeout is the cause so `Method -> "Queued"` is needed. Rookie mistake! Not sure now whether this question even needs to be here. Probably not.


title: How to export a table of complex numbers?

text: I'm having problems exporting a table of complex numbers. I have:               tablevalues=Table[M[a,b],{b,1,101},{a,-500+5*(b-1),500+5*(b-1),5}];     Export["trial.dat",tablevalues,"Table"];      But then when I try to import the data using:               Data=Import["trial.dat","Table"];      I find that the `Table` has changed (later commands in my code no longer work, despite the fact that they do work if I use `tablevalues` directly). Any help would be really appreciated, thanks! More info: the code for M is:               M[a_, b_] := l1[a, b] + l2[a, b] -l3[a, b];      where `l1`, `l2` and `l3` are calculated for different a and b (the full expressions are quite long).


title: How to constrain the range of a plot o f a function to satisfy an inequality?

text: Given the function `f[x_] := x^2`, how can I plot `f[x]` over the region where `f[x] >= 10` and `x ∈ [-5 to 5]` without solving the inequality `f[x] >= 10`?


title: Clojuratica setup

text: I am trying to get Clojuratica set up (MMa v 9 free trial) (on a Mac running Mavericks) I am following the instructions in "Clojure Data Analysis Cookbook" but have also followed the instructions:   * http://drcabana.org/2012/10/23/installation-and-configuration-of-clojuratica/   * http://clojuratica.weebly.com/tutorial.html I get the error message:               user=> (MathLinkFactory/createKernelLink path)     Fatal error: cannot find the required native library named JLinkNativeLibrary.          UnsatisfiedLinkError com.wolfram.jlink.NativeLink.MLOpenString(Ljava/lang/String;  [Ljava/lang/String;)J  com.wolfram.jlink.NativeLink.MLOpenString (NativeLink.java:-2)


title: Problem with the DSolve function

text: OK guys, here's the thing, Mathematica **does not return a solution** for this system of differential equations:               DSolve[{p11'[t] == 2*p12[t] - (1/r)*p12[t]^2,      p12'[t] ==      p22[t] - (w^2)*p11[t] - 2*z*w*p12[t] - (1/r)*p12[t]*p22[t],      p22'[t] == -2*(w^2)*p12[t] -      4*z*w*p22[t] - (1/r)*p22[t]^2 + (w^4)*q, p11[0] == 0, p12[0] == 0,     p22[0] == 0}, {p11[t], p12[t], p22[t]}, t]      Where `z,w,r,q` are parameters. Can anyone please try it on your system and tell me if you have the same problem? I also tried with the `NDSolve` function               NDSolve[{p11'[t] == 2*p12[t] - (1/r)*p12[t]^2,      p12'[t] ==      p22[t] - (w^2)*p11[t] - 2*z*w*p12[t] - (1/r)*p12[t]*p22[t],      p22'[t] == -2*(w^2)*p12[t] -      4*z*w*p22[t] - (1/r)*p22[t]^2 + (w^4)*q, p11[0] == 0, p12[0] == 0,     p22[0] == 0}, {p11[t], p12[t], p22[t]}, {t, 0, 10}]      but I get the error `message:NDSolve::ndnum: Encountered non-numerical value for a derivative at t == 0.` I greatly appreciate your help (I use mathematica 8.0 and of course `VariationalMethods` is turned on)


title: .NET link - index of property

text: I have a property in .NET Type, which is actually a generic list of objects. When I try access the property using numeric index e.g. 10, this works. However when I iterate through indices using indexer such as i, then I get error "NET::nofield: No public field or property named i exists for the .NET type ..." How to resolve this?


title: StatusArea display of message with hyperlink

text: just trying to label a hyperlink, using an example right from the documentation....               StatusArea[      Hyperlink["Wolfram Research, Inc.", "http://www.wolfram.com"],      "Makers of Mathematica"]      This should display "Makers of Mathematica" in the status area, but displays the URL instead. Am I missing something here...? I'm using Mathematica 9 on a Mac. Tom


title: How can I shorten this code to rotate a line segment around its center?

text: I have a list of line segments stored in the form:               { {{x11,y11},{x12,y12}} , {{x21,y21},{x22,y22}} , ... , {{xn1,yn1},{xn2,yn2}} }      Now I want to rotate all of them by 90 degrees about their own centers. To do that I wrote a pure function like this               {{{0, -1}, {1, 0}}.(#[[1]] - (#[[1]] + #[[2]])/2) + (#[[1]] + #[[2]])/2,     {{0, -1}, {1, 0}}.(#[[2]] - (#[[1]] + #[[2]])/2) + (#[[1]] + #[[2]])/2} &      As you can see this is pretty lengthy compare to the simplicity of my request. But I do not have enough _Mathematica_ experience to shorten it. So can anyone help?


title: Converting numbers to integers

text: I've read the available documentation but I still haven't found an `NumberForm -> Integer` function yet. No result in this site's search, either. Does it exist? I should mention: _there are no decimals in my numbers_. They are all integers, which makes me wonder why MMA bothers to fiddle with them at all. Numbers like `84039` get transformed to `84039.0`, and `8048511` to `8.048511*10^6` * * * The problem is I'm importing an XLS file that _should_ contain only strings - the fields are set to `Text` in Excel - but Mathematica has its way when using `Import` and outputs a list containing multiple different number formats. Preferably, everything imported by Mathematica would be kept as string, and not converted to `Real` or `ScientificForm`. Exporting to CSV and reopening with `ReadList` also hasn't worked well.


title: How can I extract all the non-number symbols from an expression

text: If I have an expression, let us say something like this:               Cos[3 x] + π/cofe Exp[y^(c  z)]      how can I get all non-number symbols in the expression which are: > >     {x, cofe, y, c, z} >   I tried this:               Cases[Cos[3 x] + π/cofe Exp[y^(c  z)], _Symbol]      but it didn't work.


title: Converting a large floating-point number to a single-line string

text: When I feed a large (or small) enough floating-point number to `ToString`, it produces a two-line string, with the first line containing only the exponent of 10:               In := ToString[12345.^6]     Out :=           24            3.53954 10      This creates problems because it's very counterintuitive when written to a log file. For example `ToString[{51.5^7, 2, 3, 12345.^6}]` would be written out as                          11                  24\n{9.60839 10  , 2, 3, 3.53954 10  }      which is practically unrecognizable for what it is, especially when inserted in the middle of other output. I would like to see output like               {9.60839E+11, 2, 3, 3.53954E+24}      or, if not that, I'd be fine with something like               {9.60839*^11, 2, 3, 3.53954*^24}      What can I do to print out floating-point numbers in a format suitable for single-line output?


title: Evaluate function of two variables using nested Do loops

text: Is there a more efficient way of evaluating a function of two variables on a rectangular grid the the following nested Do loops?               fonGrid[x_, y_, f_] := Module[{n, m, fvals},       (* x is an n-by-1 vector *)        (* y is an n-by-1 vector *)        (* f is a scalar function of two variables *)       (* fvals is an m-by-       n matirx where fVals[[i,j]]=f[ x[[j]], y[[i]] ] *)       n = Length[x];       m = Length[y];       fvals = Table[0, {m}, {n}]; (* preallocate fvals *)       Do[         Do[           fvals[[i, j]] = f[x[[j]], y[[i]]];,          {i, 1, m}];,        {j, 1, n}];       fvals]


title: How to monitor the progress of Map?

text: I have a function `doSomethingComplicated[...]` that takes about 10s on average to evaluate. My list, `listOfArgs` has about 10000 elements. I'd like to monitor the progress of `Map[doSomethingComplicated, listOfArgs]` without having it ever occupying a big area of the screen. What's best way to do that?


title: DateList not using current year when a year is not specified

text: According to the documentation when using `DateList` but not giving it a year it should use the current year. It is not doing that for me. Instead it uses 1900. Evaluating the example in the documentation:               DateList[{"2/15", {"Month", "Day"}}]      results in               {1900, 2, 15, 0, 0, 0.}      when I would expect               {2012, 2, 15, 0, 0, 0.}      Am I reading the documentation wrong, or do I have some setting set wrong somewhere, or is this a bug if some kind?


title: How do I view initialization (or other invisible) cells in a notebook?

text: I am looking at someone else's notebook, and when I go to evaluate it, it asks whether I want to evaluate the initialization cells. I would like to look at them first, but "I do not see them here nor there, I do not see them anywhere". How do I reveal these cells, and, for that matter, any other invisible cells in the notebook? I searched (sought?) for "initialization cell/s" and for "invisible cell/s" in the Wolfram documentation, and only found info about cells that don't have visible cell brackets, no info about cells that are completely invisible. Not how to hide my own or reveal someone else's. I found only this: `howto/SelectCellsWithoutVisibleCellBrackets` I'd be grateful for guidance.


title: DateList's aggressive interpretation of TimeML duration codes

text: `DateList` "aggressively" interprets strings, such as "p72h": `DateList["p72h"]` gives `{1972, 1, 1, 0, 0, 0.}` Strings like "p72h" represent not DATE type but DURATION type values ("72 hours") in TimeML's TIMEX3 specification. In a perfect world this would not matter since Cases or similar pattern matching can be used to select TIMEX tags based on the type element. Unfortunately, coding is not perfect; some fraction of DURATION tags are misclassified as DATES. I don't see an `Option` to force `DateList` to be more literal (is there?). Since all TIMEX3 DATE values normalized as one of the following three forms, where Y, M, D are individual digit characters corresponding to year, month, day: > "YYYY-MM-DD" or "YYYY-MM" or "YYYY" What's the most succinct StringExpression to match only these cases and reject DURATION strings? I'm guessing it may involve `Alternatives` and `DigitCharacter` but I'm not overly familiar with the subtleties of string expressions. Any help appreciated.


title: Generating a range of numbers according to some rules

text: I'm pretty new to Mathematica, and I'm mainly a programmer so I don't have a lot of knowledge about maths.   I want to generate a set of UNIQUE incremental numbers (series) according to the following rules:     * From N1 to N2 INCLUSIVE   * The count is exactly N e.g. I want 5000 numbers   * Scales according to a function i.e. I want the distance between each number and the following number to increase sequentially for example I want it to scale such that the first 25% of the range contains 50% of the number (numbers close together) then next 25% contains 30% of the numbers, then 15% then 5%, that way as you move forward the numbers are stretched further apart.         Thanks,   SM      EDIT: The actual situation that makes me think I need this is:   I'm simulating a slot game where you can win an amount of money each spin, I get a long list of all the wins and their frequencies, now I want to **"redistribute"** or **"group up"** those range of wins into a smaller set, for example only 5000 numbers instead of having like 1M, I want to do that by basically generating a series as specified in my question and then "grouping" each of the real wins into the closest number in the generated set, so for example 0.9, 1 and 1.1 would be grouped into just 1 with frequency 3 (assuming that 1 is in the generated set of numbers)   EDIT: **Now that my question has been answered, my next step should be:**   1. My new set of numbers has a weights list all initialised to 0 {0,0,0,...}   2. Go through my original list and for each number I get its weight and add it to the weight of the nearest number in the new set.   For example:   Original: {1,2,3,4,5,...,10} (from 1 to 10)   Weights: {1,1,1,1,..} (all have equal weight)   New set: {1,10}   so the weights for the new set would be calculated:   {1 to 5} get "rounded" to 1 (closest number)   {6 to 10} get "rounded" to 10 (closest number)   New weights: {5,5}   I can do this in code easily but I'm sure there must be a way to do this in Mathematica? Should I post this as a new question? I don't want to spam


title: How to add a panel with definition about plots, accompanied by dot and dot-dash lines?

text: u = 2/(1 + Z1) Sech[T/Z1 + 1/(9 Z1) Log[1 + Z1]]^2;     w = 2/(1 + Z2) Sech[T/Z2 + 1/(9 Z2) Log[1 + Z2]]^2;     Z1 = 5;     Z2 = 10;               Plot[{u, w}, {T, -15, 15}, PlotRange -> {0, 0.45}, Frame -> True,       Axes -> {False, False},       Epilog -> {Inset[         Graphics[{DotDashed, Line[{{0, 0}, {0.19, 0}}]}], {10, 0.41}],         Inset["z=0.1", {13, 0.41}],         Inset[Graphics[{Dashed, Line[{{0, 0}, {0.19, 0}}]}], {10, 0.38}],         Inset["z=0.2", {13, 0.38}]}, PlotStyle -> {DotDashed, Dashed}]      ![Mathematica graphics](http://i.stack.imgur.com/ubVTa.png) When I want is to change the format of the plot into EPS, though some parts of the plot programed by using `Epilog` and `Inset` ( I mean `"_._. Z=0.1"` and `"_ _ _Z=0.2"`) change their forms and make the plot unreadable! How can I revise my program? I think I should use `Panel` but I dont know how!


title: Optimization with assumptions

text: I have the following problem, when I am trying to optimize function with pre- defined assumptions. I am using Mathematica 8 and I wrote the following simple code               $Assumptions = (m > 0)     Minimize[{x^m, x >= 1}, x]      It is clear, that the answer is 1, since $x^m\ge 1$ if $x\ge 1$ for all positive $m$. However, Mathematica fails to calculate this simple problem. What do I do wrong? Should I use another function for minimization?


title: Creating a variable from Reduce[] output in Mathematica

text: Say I have the following input:               Reduce[{t*c==50, t==5}]      the output: > >     t == 5. && c == 10. >   Is there a way to create a variable `x` that gets assigned the value of `c` from the output without actually having to type `x = 10`?


title: Solving a large equation set

text: ClearAll[Equations, Unknows]     Equations = {c1bXZ[6] - (Sqrt[3]*c1bYZ[1])/2 + c1sStr[1]/2 +       c1sStr[3] == (-1)*RX[1],      c1bXZ[4] + (Sqrt[3]*c1bYZ[1])/2 - (Sqrt[3]*c1bYZ[5])/2 +       0.00005061454828623123*c1bYZ[8] -       0.00005061454828613165*c1bYZ[9] - c1sStr[1]/2 + c1sStr[5]/2 -       0.9999999987190837*c1sStr[8] +       0.9999999987190837*c1sStr[9] == (-1)*0, -c1bXZ[4] + c1sStr[2] -       c1sStr[3] == (-1)*0, -c1bXZ[7] + (Sqrt[3]*c1bYZ[5])/2 -       c1sStr[2] - c1sStr[5]/2 == (-1)*RX[4], -c1bXZ[6] -       0.00005061454828623123*c1bYZ[8] +       0.9999999987190837*c1sStr[8] == (-1)*0,      c1bXZ[7] + 0.00005061454828613165*c1bYZ[9] -       0.9999999987190837*c1sStr[9] == (-1)*0,      c1bYZ[1]/2 + c1bYZ[3] + (Sqrt[3]*c1sStr[1])/2 + c1sStr[6] == (-1)*      RY[1], -c1bYZ[1]/2 - c1bYZ[5]/2 - 0.9999999987190837*c1bYZ[8] -       0.9999999987190837*c1bYZ[9] - (Sqrt[3]*c1sStr[1])/2 -       c1sStr[4] - (Sqrt[3]*c1sStr[5])/2 -       0.00005061454828623123*c1sStr[8] -       0.00005061454828623123*c1sStr[9] == (-1)*F,      c1bYZ[2] - c1bYZ[3] + c1sStr[4] == (-1)*0, -c1bYZ[2] +       c1bYZ[5]/2 + (Sqrt[3]*c1sStr[5])/2 + c1sStr[7] == (-1)*RY[4],      0.9999999987190837*c1bYZ[8] - c1sStr[6] +       0.00005061454828623123*c1sStr[8] == (-1)*0,      0.9999999987190837*c1bYZ[9] - c1sStr[7] +       0.00005061454828623123*c1sStr[9] == (-1)*0,      c1bXZ[1] + c1bXZ[3] - c1bYZ[6] == (-1)*RZ[1], -c1bXZ[1] +       c1bXZ[5] - c1bXZ[8] + c1bXZ[9] + c1bYZ[4] == (-1)*0,      c1bXZ[2] - c1bXZ[3] - c1bYZ[4] == (-1)*0, -c1bXZ[2] - c1bXZ[5] -       c1bYZ[7] == (-1)*RZ[4],      c1bXZ[8] + c1bYZ[6] == (-1)*0, -c1bXZ[9] +       c1bYZ[7] == (-1)*0, -c1tTor[1]/2 -       c1tTor[3] - (Sqrt[3]*(c1bXZ[1] + c2bXZ[1]))/2 - c2bYZ[6] ==      MX[1], c1tTor[1]/2 - c1tTor[5]/2 + 0.9999999987190837*c1tTor[8] -       0.9999999987190837*c1tTor[9] + (Sqrt[3]*c2bXZ[1])/       2 - (Sqrt[3]*c2bXZ[5])/2 + 0.00005061454828623123*c2bXZ[8] -       0.00005061454828613165*c2bXZ[9] - c2bYZ[4] ==      0, (433*c1bYZ[4])/500 - c1tTor[2] + c1tTor[3] + c2bYZ[4] ==      0, (433*c1bYZ[7])/500 + c1tTor[2] +       c1tTor[5]/2 + (Sqrt[3]*(c1bXZ[5] + c2bXZ[5]))/2 + c2bYZ[7] ==      MX[4], (433*c1bYZ[6])/500 - 0.9999999987190837*c1tTor[8] -       0.00005061454828623123*(c1bXZ[8]/2 + c2bXZ[8]) + c2bYZ[6] == 0,      0.9999999987190837*c1tTor[9] +       0.00005061454828613165*(c1bXZ[9]/2 + c2bXZ[9]) - c2bYZ[7] == 0,      c1bXZ[3]/2 - (Sqrt[3]*c1tTor[1])/2 -       c1tTor[6] + (c1bXZ[1] + c2bXZ[1])/2 + c2bXZ[3] ==      MY[1], (Sqrt[3]*c1tTor[1])/2 +       c1tTor[4] + (Sqrt[3]*c1tTor[5])/2 +       0.00005061454828623123*c1tTor[8] +       0.00005061454828623123*c1tTor[9] - c2bXZ[1]/2 - c2bXZ[5]/2 -       0.9999999987190837*c2bXZ[8] - 0.9999999987190837*c2bXZ[9] == 0,      c1bXZ[2]/2 - c1tTor[4] + c2bXZ[2] - c2bXZ[3] ==      0, -(Sqrt[3]*c1tTor[5])/2 - c1tTor[7] -       c2bXZ[2] + (c1bXZ[5] + c2bXZ[5])/2 == MY[4],      c1tTor[6] - 0.00005061454828623123*c1tTor[8] +       0.9999999987190837*(c1bXZ[8]/2 + c2bXZ[8]) == 0,      c1tTor[7] - 0.00005061454828623123*c1tTor[9] +       0.9999999987190837*(c1bXZ[9]/2 + c2bXZ[9]) ==      0, -c1bYZ[1] - c1bYZ[3]/2 - c2bXZ[6] - c2bYZ[1] - c2bYZ[3] == 0,      c2bXZ[4] + c2bYZ[1] - c2bYZ[5] + c2bYZ[8] - c2bYZ[9] ==      0, (-433*c1bXZ[4])/500 - c1bYZ[2]/2 - c2bXZ[4] - c2bYZ[2] +       c2bYZ[3] ==      0, (-433*c1bXZ[7])/500 + c1bYZ[5] - c2bXZ[7] + c2bYZ[2] +       c2bYZ[5] ==      0, (433*c1bXZ[6])/500 - c1bYZ[8]/2 + c2bXZ[6] - c2bYZ[8] == 0,      c1bYZ[9]/2 + c2bXZ[7] + c2bYZ[9] ==      0, -c1sStr[3]/4000000000 + (-c1sStr[1]/2000000000 - c2sStr[1])/2 -       c2sStr[3] -       c4bXZ[6] - (Sqrt[          3]*((c1bYZ[1] + 3*c2bYZ[1] + 2400000*c3bYZ[1])/2400000 +            c4bYZ[1]))/2 ==      0, -c2sStr[2] + (c1sStr[5]/2000000000 + c2sStr[5])/       2 - (433*((433*((433*c1bXZ[7])/500 + 3*c2bXZ[7]))/500 +            2400000*c3bXZ[7]))/1200000000 -       c4bXZ[7] + (Sqrt[          3]*((c1bYZ[5] + 3*c2bYZ[5] + 2400000*c3bYZ[5])/2400000 +            c4bYZ[5]))/2 ==      0, -(Sqrt[3]*(c1sStr[1]/2000000000 + c2sStr[1]))/2 +       c2sStr[6] + ((c1bYZ[3]/2 + 3*c2bYZ[3])/2 + 2400000*c3bYZ[3])/       4800000 + ((c1bYZ[1] + 3*c2bYZ[1] + 2400000*c3bYZ[1])/2400000 +          c4bYZ[1])/2 + c4bYZ[3] ==      0, (-433*c1sStr[7])/       1000000000000 - (Sqrt[3]*(c1sStr[5]/2000000000 + c2sStr[5]))/2 -       c2sStr[7] +       c4bYZ[2] + ((c1bYZ[5] + 3*c2bYZ[5] + 2400000*c3bYZ[5])/2400000 +          c4bYZ[5])/2 ==      0, (c1bXZ[1] + 3*c2bXZ[1] + 2400000*c3bXZ[1])/       2400000 + ((c1bXZ[3]/2 + 3*c2bXZ[3])/2 + 2400000*c3bXZ[3])/       4800000 + c4bXZ[1] + c4bXZ[3] + c4bYZ[6] ==      0, (-c1bXZ[5] - 3*c2bXZ[5] - 2400000*c3bXZ[5])/       2400000 - (433*((433*((433*c1bYZ[7])/500 + 3*c2bYZ[7]))/500 +            2400000*c3bYZ[7]))/1200000000 + c4bXZ[2] - c4bXZ[5] -       c4bYZ[7] ==      0, (-c1sStr[1]/2000000000 - c2sStr[1])/       2 - (Sqrt[          3]*((c1bYZ[1] + 3*c2bYZ[1] + 2400000*c3bYZ[1])/2400000 +            c4bYZ[1]))/2 == -c1sStr[3]/4000000000 -       c2sStr[3], -c1sStr[3]/4000000000 -       c2sStr[3] == -c4bXZ[6], -c2sStr[1]/2 - (Sqrt[3]*c4bYZ[1])/       2 == -c4bXZ[4], -c4bXZ[4] == c2sStr[5]/2 + (Sqrt[3]*c4bYZ[5])/2,     c2sStr[5]/2 + (Sqrt[3]*c4bYZ[5])/2 == -0.9999999987190837*       c2sStr[8] -       0.00005061454828623123*c4bYZ[8], -0.9999999987190837*c2sStr[8] -       0.00005061454828623123*c4bYZ[8] ==      0.9999999987190837*c2sStr[9] +       0.00005061454828613165*c4bYZ[9], -c1sStr[2]/4000000000 -       c2sStr[2] == -c2sStr[3], -c2sStr[       3] == (-433*((433*((433*c1bXZ[4])/500 + 3*c2bXZ[4]))/500 +            2400000*c3bXZ[4]))/1200000000 -       c4bXZ[4], -c2sStr[2] == (c1sStr[5]/2000000000 + c2sStr[5])/       2 + (Sqrt[          3]*((c1bYZ[5] + 3*c2bYZ[5] + 2400000*c3bYZ[5])/2400000 +            c4bYZ[5]))/2, (c1sStr[5]/2000000000 + c2sStr[5])/       2 + (Sqrt[          3]*((c1bYZ[5] + 3*c2bYZ[5] + 2400000*c3bYZ[5])/2400000 +            c4bYZ[5]))/       2 == (-433*((433*((433*c1bXZ[7])/500 + 3*c2bXZ[7]))/500 +            2400000*c3bXZ[7]))/1200000000 -       c4bXZ[7], (-433*((433*((433*c1bXZ[6])/500 + 3*c2bXZ[6]))/500 +            2400000*c3bXZ[6]))/1200000000 -       c4bXZ[6] == -0.9999999987190837*(c1sStr[8]/4000000000 +          c2sStr[8]) -       0.00005061454828623123*(((c1bYZ[8]/2 + 3*c2bYZ[8])/2 +             2400000*c3bYZ[8])/4800000 + c4bYZ[8]), -c4bXZ[7] ==      0.9999999987190837*(c1sStr[9]/4000000000 + c2sStr[9]) +       0.00005061454828613165*(((c1bYZ[9]/2 + 3*c2bYZ[9])/2 +             2400000*c3bYZ[9])/4800000 +          c4bYZ[9]), -(Sqrt[3]*(c1sStr[1]/2000000000 + c2sStr[1]))/       2 + ((c1bYZ[1] + 3*c2bYZ[1] + 2400000*c3bYZ[1])/2400000 +          c4bYZ[1])/       2 == ((c1bYZ[3]/2 + 3*c2bYZ[3])/2 + 2400000*c3bYZ[3])/4800000 +       c4bYZ[3], ((c1bYZ[3]/2 + 3*c2bYZ[3])/2 + 2400000*c3bYZ[3])/       4800000 + c4bYZ[3] ==      c2sStr[6], -(Sqrt[3]*c2sStr[1])/2 +       c4bYZ[1]/2 == -c2sStr[4], -c2sStr[4] == -(Sqrt[3]*c2sStr[5])/2 +       c4bYZ[5]/2, -(Sqrt[3]*c2sStr[5])/2 +       c4bYZ[5]/2 == -0.00005061454828623123*c2sStr[8] +       0.9999999987190837*c4bYZ[8], -0.00005061454828623123*c2sStr[8] +       0.9999999987190837*c4bYZ[8] == -0.00005061454828623123*       c2sStr[9] +       0.9999999987190837*       c4bYZ[9], ((c1bYZ[2]/2 + 3*c2bYZ[2])/2 + 2400000*c3bYZ[2])/       4800000 + c4bYZ[2] == c4bYZ[3],      c4bYZ[3] == (-433*c1sStr[4])/1000000000000 - c2sStr[4],      c4bYZ[2] == -(Sqrt[3]*(c1sStr[5]/2000000000 + c2sStr[5]))/       2 + ((c1bYZ[5] + 3*c2bYZ[5] + 2400000*c3bYZ[5])/2400000 +          c4bYZ[5])/2, -(Sqrt[3]*(c1sStr[5]/2000000000 + c2sStr[5]))/       2 + ((c1bYZ[5] + 3*c2bYZ[5] + 2400000*c3bYZ[5])/2400000 +          c4bYZ[5])/2 == (-433*c1sStr[7])/1000000000000 -       c2sStr[7], (433*c1sStr[6])/1000000000000 +       c2sStr[6] == -0.00005061454828623123*(c1sStr[8]/4000000000 +          c2sStr[8]) +       0.9999999987190837*(((c1bYZ[8]/2 + 3*c2bYZ[8])/2 +             2400000*c3bYZ[8])/4800000 + c4bYZ[8]), -c2sStr[       7] == -0.00005061454828623123*(c1sStr[9]/4000000000 +          c2sStr[9]) +       0.9999999987190837*(((c1bYZ[9]/2 + 3*c2bYZ[9])/2 +             2400000*c3bYZ[9])/4800000 + c4bYZ[9]), (c1bXZ[1] +          3*c2bXZ[1] + 2400000*c3bXZ[1])/2400000 +       c4bXZ[1] == ((c1bXZ[3]/2 + 3*c2bXZ[3])/2 + 2400000*c3bXZ[3])/       4800000 +       c4bXZ[3], ((c1bXZ[3]/2 + 3*c2bXZ[3])/2 + 2400000*c3bXZ[3])/       4800000 + c4bXZ[3] == c4bYZ[6],      c4bXZ[1] == -c4bYZ[4], -c4bYZ[4] == -c4bXZ[5], -c4bXZ[5] ==      c4bXZ[8],      c4bXZ[8] == -c4bXZ[       9], ((c1bXZ[2]/2 + 3*c2bXZ[2])/2 + 2400000*c3bXZ[2])/4800000 +       c4bXZ[2] == c4bXZ[3],      c4bXZ[3] == (-433*((433*((433*c1bYZ[4])/500 + 3*c2bYZ[4]))/500 +            2400000*c3bYZ[4]))/1200000000 - c4bYZ[4],      c4bXZ[2] == (-c1bXZ[5] - 3*c2bXZ[5] - 2400000*c3bXZ[5])/2400000 -       c4bXZ[5], (-c1bXZ[5] - 3*c2bXZ[5] - 2400000*c3bXZ[5])/2400000 -       c4bXZ[5] == (-433*((433*((433*c1bYZ[7])/500 + 3*c2bYZ[7]))/500 +            2400000*c3bYZ[7]))/1200000000 -       c4bYZ[7], (433*((433*((433*c1bYZ[6])/500 + 3*c2bYZ[6]))/500 +            2400000*c3bYZ[6]))/1200000000 +       c4bYZ[6] == ((c1bXZ[8]/2 + 3*c2bXZ[8])/2 + 2400000*c3bXZ[8])/       4800000 +       c4bXZ[8], -c4bYZ[       7] == ((-c1bXZ[9]/2 - 3*c2bXZ[9])/2 - 2400000*c3bXZ[9])/       4800000 -       c4bXZ[9], -c1tTor[3]/280000 + (-c1tTor[1]/140000 - c2tTor[1])/2 -       c2tTor[3] - (Sqrt[          3]*((c1bXZ[1] + 2*c2bXZ[1])/800000 + c3bXZ[1]))/2 +       c3bYZ[6] ==      0, (433*((433*c1bYZ[7])/500 + 2*c2bYZ[7]))/400000000 -       c2tTor[2] + (c1tTor[5]/140000 + c2tTor[5])/       2 + (Sqrt[3]*((c1bXZ[5] + 2*c2bXZ[5])/800000 + c3bXZ[5]))/2 +       c3bYZ[7] ==      0, (c1bXZ[3]/2 + 2*c2bXZ[3])/       1600000 - (Sqrt[3]*(c1tTor[1]/140000 + c2tTor[1]))/2 +       c2tTor[6] + ((c1bXZ[1] + 2*c2bXZ[1])/800000 + c3bXZ[1])/2 +       c3bXZ[3] ==      0, (-433*c1tTor[7])/       70000000 - (Sqrt[3]*(c1tTor[5]/140000 + c2tTor[5]))/2 -       c2tTor[7] +       c3bXZ[2] + ((c1bXZ[5] + 2*c2bXZ[5])/800000 + c3bXZ[5])/2 ==      0, (-c1tTor[1]/140000 - c2tTor[1])/       2 - (Sqrt[3]*((c1bXZ[1] + 2*c2bXZ[1])/800000 + c3bXZ[1]))/       2 == -c1tTor[3]/280000 - c2tTor[3], -c1tTor[3]/280000 -       c2tTor[3] == c3bYZ[6], -c2tTor[1]/2 - (Sqrt[3]*c3bXZ[1])/2 ==      c3bYZ[4], c3bYZ[4] == c2tTor[5]/2 + (Sqrt[3]*c3bXZ[5])/2,      c2tTor[5]/2 + (Sqrt[3]*c3bXZ[5])/2 == -0.9999999987190837*       c2tTor[8] -       0.00005061454828623123*c3bXZ[8], -0.9999999987190837*c2tTor[8] -       0.00005061454828623123*c3bXZ[8] ==      0.9999999987190837*c2tTor[9] +       0.00005061454828613165*c3bXZ[9], -c1tTor[2]/280000 -       c2tTor[2] == -c2tTor[3], -c2tTor[       3] == (433*((433*c1bYZ[4])/500 + 2*c2bYZ[4]))/400000000 +       c3bYZ[4], -c2tTor[2] == (c1tTor[5]/140000 + c2tTor[5])/       2 + (Sqrt[3]*((c1bXZ[5] + 2*c2bXZ[5])/800000 + c3bXZ[5]))/       2, (c1tTor[5]/140000 + c2tTor[5])/       2 + (Sqrt[3]*((c1bXZ[5] + 2*c2bXZ[5])/800000 + c3bXZ[5]))/       2 == (433*((433*c1bYZ[7])/500 + 2*c2bYZ[7]))/400000000 +       c3bYZ[7], (433*((433*c1bYZ[6])/500 + 2*c2bYZ[6]))/400000000 +       c3bYZ[6] == -0.9999999987190837*(c1tTor[8]/280000 + c2tTor[8]) -       0.00005061454828623123*((c1bXZ[8]/2 + 2*c2bXZ[8])/1600000 +          c3bXZ[8]),      c3bYZ[7] ==      0.9999999987190837*(c1tTor[9]/280000 + c2tTor[9]) +       0.00005061454828613165*((c1bXZ[9]/2 + 2*c2bXZ[9])/1600000 +          c3bXZ[9]), -(Sqrt[3]*(c1tTor[1]/140000 + c2tTor[1]))/       2 + ((c1bXZ[1] + 2*c2bXZ[1])/800000 + c3bXZ[1])/       2 == (c1bXZ[3]/2 + 2*c2bXZ[3])/1600000 +       c3bXZ[3], (c1bXZ[3]/2 + 2*c2bXZ[3])/1600000 + c3bXZ[3] ==       c2tTor[6], -(Sqrt[3]*c2tTor[1])/2 +       c3bXZ[1]/2 == -c2tTor[4], -c2tTor[4] == -(Sqrt[3]*c2tTor[5])/2 +       c3bXZ[5]/2, -(Sqrt[3]*c2tTor[5])/2 +       c3bXZ[5]/2 == -0.00005061454828623123*c2tTor[8] +       0.9999999987190837*c3bXZ[8], -0.00005061454828623123*c2tTor[8] +       0.9999999987190837*c3bXZ[8] == -0.00005061454828623123*       c2tTor[9] +       0.9999999987190837*c3bXZ[9], (c1bXZ[2]/2 + 2*c2bXZ[2])/1600000 +       c3bXZ[2] == c3bXZ[3],      c3bXZ[3] == (-433*c1tTor[4])/70000000 - c2tTor[4],      c3bXZ[2] == -(Sqrt[3]*(c1tTor[5]/140000 + c2tTor[5]))/       2 + ((c1bXZ[5] + 2*c2bXZ[5])/800000 + c3bXZ[5])/       2, -(Sqrt[3]*(c1tTor[5]/140000 + c2tTor[5]))/       2 + ((c1bXZ[5] + 2*c2bXZ[5])/800000 + c3bXZ[5])/       2 == (-433*c1tTor[7])/70000000 -       c2tTor[7], (433*c1tTor[6])/70000000 +       c2tTor[6] == -0.00005061454828623123*(c1tTor[8]/280000 +          c2tTor[8]) +       0.9999999987190837*((c1bXZ[8]/2 + 2*c2bXZ[8])/1600000 +          c3bXZ[8]), -c2tTor[       7] == -0.00005061454828623123*(c1tTor[9]/280000 + c2tTor[9]) +       0.9999999987190837*((c1bXZ[9]/2 + 2*c2bXZ[9])/1600000 +          c3bXZ[9]), (-c1bYZ[1] - 2*c2bYZ[1])/800000 -       c3bYZ[1] == (-c1bYZ[3]/2 - 2*c2bYZ[3])/1600000 -       c3bYZ[3], (-c1bYZ[3]/2 - 2*c2bYZ[3])/1600000 - c3bYZ[3] ==      c3bXZ[6], -c3bYZ[1] == -c3bXZ[4], -c3bXZ[4] == c3bYZ[5],      c3bYZ[5] == -c3bYZ[8], -c3bYZ[8] ==      c3bYZ[9], (-c1bYZ[2]/2 - 2*c2bYZ[2])/1600000 -       c3bYZ[2] == -c3bYZ[3], -c3bYZ[       3] == (-433*((433*c1bXZ[4])/500 + 2*c2bXZ[4]))/400000000 -       c3bXZ[4], -c3bYZ[2] == (c1bYZ[5] + 2*c2bYZ[5])/800000 +       c3bYZ[5], (c1bYZ[5] + 2*c2bYZ[5])/800000 +       c3bYZ[5] == (-433*((433*c1bXZ[7])/500 + 2*c2bXZ[7]))/400000000 -       c3bXZ[7], (433*((433*c1bXZ[6])/500 + 2*c2bXZ[6]))/400000000 +       c3bXZ[6] == (-c1bYZ[8]/2 - 2*c2bYZ[8])/1600000 -       c3bYZ[8], -c3bXZ[7] == (c1bYZ[9]/2 + 2*c2bYZ[9])/1600000 +       c3bYZ[9]};      And unknowns               Unknows = {c1bXZ[1], c1bXZ[2], c1bXZ[3], c1bXZ[4], c1bXZ[5], c1bXZ[6],     c1bXZ[7], c1bXZ[8], c1bXZ[9], c2bXZ[1], c2bXZ[2], c2bXZ[3],      c2bXZ[4], c2bXZ[5], c2bXZ[6], c2bXZ[7], c2bXZ[8], c2bXZ[9],      c3bXZ[1], c3bXZ[2], c3bXZ[3], c3bXZ[4], c3bXZ[5], c3bXZ[6],      c3bXZ[7], c3bXZ[8], c3bXZ[9], c4bXZ[1], c4bXZ[2], c4bXZ[3],      c4bXZ[4], c4bXZ[5], c4bXZ[6], c4bXZ[7], c4bXZ[8], c4bXZ[9],      c1bYZ[1], c1bYZ[2], c1bYZ[3], c1bYZ[4], c1bYZ[5], c1bYZ[6],      c1bYZ[7], c1bYZ[8], c1bYZ[9], c2bYZ[1], c2bYZ[2], c2bYZ[3],      c2bYZ[4], c2bYZ[5], c2bYZ[6], c2bYZ[7], c2bYZ[8], c2bYZ[9],      c3bYZ[1], c3bYZ[2], c3bYZ[3], c3bYZ[4], c3bYZ[5], c3bYZ[6],      c3bYZ[7], c3bYZ[8], c3bYZ[9], c4bYZ[1], c4bYZ[2], c4bYZ[3],      c4bYZ[4], c4bYZ[5], c4bYZ[6], c4bYZ[7], c4bYZ[8], c4bYZ[9],      c1sStr[1], c1sStr[2], c1sStr[3], c1sStr[4], c1sStr[5], c1sStr[6],      c1sStr[7], c1sStr[8], c1sStr[9], c2sStr[1], c2sStr[2], c2sStr[3],      c2sStr[4], c2sStr[5], c2sStr[6], c2sStr[7], c2sStr[8], c2sStr[9],      c1tTor[1], c1tTor[2], c1tTor[3], c1tTor[4], c1tTor[5], c1tTor[6],      c1tTor[7], c1tTor[8], c1tTor[9], c2tTor[1], c2tTor[2], c2tTor[3],      c2tTor[4], c2tTor[5], c2tTor[6], c2tTor[7], c2tTor[8], c2tTor[9],      RX[1], RY[1], RZ[1], RX[4], RY[4], RZ[4], MX[1], MY[1], MX[4],      MY[4]};      Explain please why I can not to solve this set?


title: What is the best way (lossless) to import .skp files into Mathematica?

text: I am using the free version of Google Sketchup and I've got a few designs in hand, which I need to be able to import into Mathematica. I saw the similar question asked by @Sjoerd C. de Vries in Stack Overflow, but I didn't find any answer that was simple and allows for complete communication of the information in the skp file to Mathematica. I am asking this question hoping that there has been some progress made in this regard as the previous question was asked in June, 2011.


title: Remove extra space between commas in subscripts generated by InputAlias

text: There are (unwanted) extra spaces between comma separators that are generated when I create an alias with subscript. Here is the code I am using:               SetOptions[EvaluationNotebook[], InputAliases -> {         "xx" -> "\!\(\*SubscriptBox[\(x\), \(\[SelectionPlaceholder], \         \[Placeholder], \[Placeholder]\)]\)"(*subscripts*)}]      ![enter image description here](http://i.stack.imgur.com/99FV1.png) This problem is independent of using `\\[Placeholder]`: For example,               SetOptions[EvaluationNotebook[], InputAliases -> {        "yy" -> "\!\(\*SubscriptBox[\(y\), \(x, y, z\)]\)"(*subscripts*)}]      ![enter image description here](http://i.stack.imgur.com/R5kCl.png) Any way to remove the unwanted space in the Alias?


title: How can I use the overhang argument to Partition to avoid using PadLeft and PadRight here?

text: Say I have a list of values `v = {v1, v2, v3, ... }`. I need to partition these values to perform operations with a sliding window (think `MovingAverage`). I define my window as `{r1, r2}` where `r1` indicates the number of objects to capture to the left and `r2` is the number to the right of each of the `vi`. Thus, my window width is `r1 + r2 + 1`. I have written a function which does this partitioning.               f[list_, {r1_, r2_}] := With[{r = r1 + r2 + 1, n = Length[list]},        Partition[PadRight[PadLeft[list, n + r1], n + r1 + r2], r, 1]       ]      For example.               f[Array[v, 6], {1, 3}]          (*{{0, v[1], v[2], v[3], v[4]}, {v[1], v[2], v[3], v[4], v[5]}, {v[2],        v[3], v[4], v[5], v[6]}, {v[3], v[4], v[5], v[6], 0}, {v[4], v[5],        v[6], 0, 0}, {v[5], v[6], 0, 0, 0}}*)      Is there a way to use the overhang argument to `Partition` so that I can avoid `PadLeft` and `PadRight`? The reason I don't just use this solution is because ultimately I don't want the zeros, I will be working with a ragged array. If I can get the overhang argument right I can just use `{}` for padding saving me from post processing the zeros.


title: Incorporating Built-In Function Options/Parameters into Shorthand

text: Shorthand syntax provides an alternate way to apply functions and, in many cases, improves readability. A simple example would be                In[1]:=  numList = {1, 0, 1, 1, 0, 1, 1};      In[2]:=  FromDigits@numList     Out[2]:=  1011011      instead of                In[3]:=  FromDigits[numList]     Out[3]:=  1011011      Here, the syntax is simply `<function> @ <argument>`. (There is also the weaker suffix `<argument> // <function>`.) For lists, more sophisticated methods of applying functions exist (`Map`, `Apply`, etc), some with their own shorthands (`/@`, `@@`). Many built-in functions accept parameters and options in addition to arguments. For example, one can specify which base to use for `FromDigits`:                In[4]:=  FromDigits[numList, 2]     Out[4]:=  91      How do you incorporate function parameters/options into shorthand syntax? EDIT: After more searching of _Mathematica Stack Exchange_ , I found this answer by Brett Champion to this question. I believe it answers my question.


title: Should 0 * 5ft be 0 or 0ft?

text: After playing with the new quantity system in Mathematica 9 for a while, I keep stumbling over this issue:               0 * Quantity[1, "Meters"]      is not the same as               1 * Quantity[0, "Meters"]      The first is dimensionless 0, the second is 0 meters, and a dimensionless quantity can't be added to or converted to a length like meters. Take e.g. this simplified example:               startPoint = Quantity[1, "Meters"];     endPoint = Quantity[5, "Meters"];         Manipulate[      UnitConvert[a*endPoint + (1 - a)*startPoint, "Inches"], {a, 0, 1}]      The manipulate converts a point along a line to inches. It works for any setting of `a`, except `0.` and `1.`, where I get `UnitConvert[0. + Quantity[1., "Meters"], "Inches"]` instead of a proper length. Generally speaking, it seems that any expression that contains a dimensionless subexpression that can be 0 might break somewhere in your `Manipulate`, `Table` or `Animate`. This seems extremely fragile to me. Is this a bug? Or am I using `Quantity` wrong? Should I avoid dimensionless expressions completely? Or avoid `Quantity` inside dynamic code?


title: How to improve the quality of the ListPlot output

text: I need to plot massive data stored in external ASCII files. Below is the _Mathematica_ code I use for this job:               Clear["Global`*"];          SetDirectory[" ... "];          dataRG = ReadList["dataRG.out", Number, RecordLists -> True];     dataCH = ReadList["dataCH.out", Number, RecordLists -> True];          Vd = -((Md*(1 + δ))/     Sqrt[(1 + δ)*(b^2 + y^2) +      x^2 + (a + Sqrt[h^2 + (1 + δ^2)*z^2])^2]);     Vn = -(Mn/Sqrt[x^2 + y^2 + z^2 + cn^2]);     Vh = -(Mh/Sqrt[x^2 + y^2 + z^2 + ch^2]);     V = Vd + Vn + Vh;          Md = 8200; b = 8; a = 3; h = 0.3; δ = 0.1;     Mn = 400; cn = 0.25;     Mh = 0; ch = 25;     E0 = -700;     z0 = 1;          f[x_, px_] := 1/2*px^2 + V /. {y -> 0, z -> z0};          xmax = 11;     pxmax = 41;     plrange = {{-xmax, xmax}, {-pxmax, pxmax}};          C0 = ContourPlot[Evaluate[f[x, px]], {x, -20, 20}, {px, -80, 80},      Contours -> {E0}, ContourStyle -> {Black, Thick}, AspectRatio -> 1,     ContourShading -> False, PlotPoints -> 200,      PerformanceGoal -> "Speed", PlotRange -> plrange];          S1 = ListPlot[Flatten[List /@ dataRG[[All, {1, 2}]], 1],      PlotStyle -> {GrayLevel[0.8], PointSize[0.003]}];     S2 = ListPlot[Flatten[List /@ dataCH[[All, {1, 2}]], 1],      PlotStyle -> {GrayLevel[0.05], PointSize[0.003]}];     P0 = Show[{S1, S2, C0}, Frame -> True, Axes -> False,      FrameLabel -> {"x", OverDot["x"]}, RotateLabel -> False,      FrameStyle -> Directive[FontSize -> 17, FontFamily -> "Helvetica"],      AspectRatio -> 1, PlotRange -> plrange, ImageSize -> 550]      which produces the following output ![my plot](http://i.stack.imgur.com/DcDtT.jpg) As you may see from the image two are the main issues: (1). How can I get rid off the vertical blank gaps?   (2). Why there are some "bold horizontal lines" in the plot and again how can I get rid off them? I observed, that both issues are influenced by the `ImageSize` option. In particular, if you play with this option between 400 and 600, it might eliminate the problems. However, I suspect that the cause must be something more profound. So, I would be very grateful, if you suggest me how can I solve these issues and also if you could provide me with a more correct way to plot my data files. Many many thanks in advance! Both data files can be found here: dataRG and dataCH.


title: Why does Mathematica not replace the derivative of $theta$1'[t]?

text: **I want to know the velocity of point $p$, given that I know the coordinate.** $p_x=L_1\cos(\theta1)+L_2\cos(\theta1+\theta2)$ I calculate $\frac{dp_x}{dt}$ to achieve the velocity of point $p$ about the $x$ coordinate. My trial as below:               px[t] = L1 Cos[θ1[t]] + L2 Cos[θ1[t] + θ2[t]];      Now I'd like to give the variable some value, $\theta_1=t^2,\theta_2=t^3,L_1=2,L_2=3$               D[px[t], t] /. {θ1[t] -> t^2, θ2[t] -> t^3, L1 -> 2, L2 -> 3}      However, _Mathematica_ gives the result: > >     -2 Sin[t^2] [θ1'[t] - 3 Sin[t^2 + t^3] ([θ1'[t] + [θ2'[t]) >   It doesn't evaluate `\\[Theta]1]'[t]` and `\\[Theta]1'[t]` to $2t ,3t^2$, respectively. So I use the command `FullForm`               θ1[t] // FullForm      > >     Derivative[1][θ1][t] >   **So my question is why is it that _Mathematica_ cannot do the full evaluation and how to fix it?** ![enter image description here](http://i.stack.imgur.com/zEBiQ.jpg)


title: Getting RGBA data from an image

text: What is going on with returned data in the following examples? It appears `ImageData` returns different types depending on the what data is passed into `Image`. How do I force `ImageData` to always return the RGBA `{{{0,0,0,0},{255,255,255,255}}}` version of the data?               ImageData[Image[{{{0, 0, 0,0}, {255, 255, 255,255}}}, "Byte"],"Byte"]        {{{0, 0, 0,0}, {255, 255, 255,255}}}      Now if I pass a compressed form of the same image I don't get back the RGBA representation of the image, but the same compressed form.               ImageData[Image[{{0, 255}}, "Byte"], "Byte"]        {{0, 255}}      Is there a way to construct an `Image` that insures _Mathematica_ always returns the RGBA form of the data? Basically I am looking for a function in the form of `ConvertToRGBA[i_Image] := ...`


title: How can I implement dynamic programming for a function with more than one argument?

text: > Dynamic programming is a technique for avoiding the repeated computation of > the same values in a recursive program. Each value computed is immediately > stored. If the value is needed again, it is not computed but simply looked > up in the table. (1) I use orthogonal polynomials a fair bit in my work. Since _Mathematica_ supports only the classical ones, I often have to write my own functions. For instance, the monic Charlier polynomials satisfy the three-term recurrence $$C_{n+1}^{(a)}(x)=(x-a-n)C_n^{(a)}(x)-an C_{n-1}^{(a)}(x)$$ with $C_0^{(a)}(x)=1$ and $C_1^{(a)}(x)=x-a$. If I want to be able to use monic Charlier polynomials in _Mathematica_ , I can do this:               CharlierC[0, a_, x_] := 1;     CharlierC[1, a_, x_] := x - a;     CharlierC[n_Integer, a_, x_] := (x - a - n + 1) CharlierC[n - 1, a, x] -                                      a (n - 1) CharlierC[n - 2, a, x]      The problem with this route, of course, is that the effort expended to generate, say, `CharlierC[20, a, x]` can't be used for evaluating `CharlierC[50, a, x]`. For a one-argument recursive function (e.g. Fibonacci), dynamic programming is fine and dandy for saving evaluation effort. For a multiple-argument function, imagine what would happen if one had used the definition `CharlierC[n_Integer, a_, x_] := CharlierC[n, a, x] = (* stuff *)` and then executed `Plot[{CharlierC[5, 1, x], CharlierC[6, x, 2]}, {x, -1, 1}]`. Is there a way to reap the benefits of dynamic programming on a multiple- argument function, while storing only results where the recursion variable (`n` in the Charlier example) changes?


title: How can I create an empty JSON object?

text: For creating non-empty object, I use following syntax               ExportString[{"key" -> "value"}, "JSON"]     (*{"key" : "value"}*)      But how can I create an empty object? When I run               ExportString[{}, "JSON"]     (*[]*)      it produces an empty array PS: the empty object in JSON is `{}`


title: Can a Symbol own OwnValues that don't evaluate when it's the head of an expression?

text: I believe this a question that most of us have encountered when we were beginners but forgot when we got more familiar with _Mathematica_. We know the notation $y=y(x)$ for functions, where $y$ here simultaneously represents the functional relation and the dependent variable, isn't rare. We also know it's trouble in _Mathematica_ because it'll cause infinite recursion:               y = y[x]      > $RecursionLimit::reclim: Recursion depth of 256 exceeded. >> >   >   > > Hold[y[x]][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x]... >   This behavior makes the language strict, of course. But recently, when I found myself in a situation with some justification for using a lot of $y=y(x)$ style notation, the question in the title came to my mind: what if this notation were well behaved in _Mathematica_? Needless to say, though quite similar, there're many differences between _Mathematica_ syntax and traditional math notation. For most cases we can easily see the advantages of such deviations. For example, the strict distinctions of `[]`,`()`,`{}`,`[[]]`. However, the advantage of the currently built-in behavior of `y = y[x]` seems not to be obvious. In other words, I can't see what kind of problems will arise if a symbol were allowed to have `OwnValues` and `DownValues` at the same time. In such case, `OwnValues` of a symbol would only be evaluated when the symbol is not the head of any expressions. Can I achieve this feature in _Mathematica_?


title: Piecewise function with user-input interval

text: I would like define a function `g[data,bins,x]` which is a piecewise constant function taking value `data[[i]]` in the range `bins[[i]][[1]] < x ≤ bins[[i]][[2]]`. The difficulty is that I'd like `data` and `bins` to be lists that are input by the user. _Mathematica_ seems to throw errors because the argument of `Piecewise` doesn't appear to be a list of pairs. Here's an example with explicit values that works:               f[x_] :=      Evaluate@Piecewise[        Map[         {#[[1]], #[[2]][[1]] < x <= #[[2]][[2]] } &,          Transpose[{{1, 2, 3}, {{0, 1}, {1, 2}, {2, 3}}}]         ]        ]      However, when I try to define a general function:               g[data_, bins_, x_] :=      Evaluate@Piecewise[        Map[         {#[[1]], #[[2]][[1]] < x <= #[[2]][[2]] } &,          Transpose[{data, bins}]         ]        ]      I get several errors because _Mathematica_ doesn't know if `{data,bins}` can be transposed. Any help would be appreciated!


title: How to replace multiple variables at once

text: I would like to make a replacement "c1 C1 -> F1, c2 C2-> F2...." such that the expression like this "c1 C1 c2 C2 c3 C3 c4 C4" becomes "F1 F2 F3 F4". I used the standard replacement method: `c1 C1 c2 C2 c3 C3 c4 C4 /. {c1 C1 ->F1, c2 C2 -> F2, c3 C3-> F3, c4 C4-> F4}`. But mathematica only gives "F1 c2 C2 c3 C3 c4 C4", it only replace the first product. What is the reason this replacement does not work? How could I make such a replacement at once? Thanks a lot.


title: Circular membrane vibration simulation

text: I'm new in Mathematica and I'm trying to simulate the vibration of a circular membrane for math project but I don't even know how to start. The wave equation describes the displacement of the membrane $(z)$ as a function of its position $(r,\theta)$ and time $(t)$. $$ \frac{\partial^2 z}{\partial t^2}=c^2 \nabla^2 z $$ For an ordinary circular drumhead the imposed boundary conditions are that $z$ is $2π$ periodic, finite within $0 ≤ r ≤ a$ and at $r = a$ (the edge of the drum) the displacement is zero: $z(a) = 0$. The wave equation is solved through a method of separation of variables and produces the solution: $$ ￼￼z=A_{nj}J_n\left(\frac{\omega r}{c}\right)sin(ωt+\phi)sin(nθ+φ) $$ How can I simulate/plot this solution in Mathematica? Thanks in advance!


title: Accessing variables outside DynamicModule

text: I have this `DynamicModule` which is basically a form of input fields that are parameters. My two final functions are `H1` and `H2` which I also define as disabled `InputFields`. Edit: I've only included one input field but this H1 and H2 variables depend on other variables that I've created input fields for in my code. In an effort to save space, I've removed those other variables. The new question is basically: WITHIN this dynamic module, after I've gotten this H1 and H2, I want to access them and plot them. But anytime I try to access them and manipulate them, nothing happens. Thoughts?               DynamicModule[{R = .005, a = .015, To = 310 , Tb = 310, wb = 0.0064,        cb = 4180, c2 = 3600, phi = .0002 , c = 670, k1 = .502, k2 = .502,        pb = 1000, P = 1.95*10^5, p1, p2 = 1060, c1, l1, l2, f1, f2, H1,        H2, r = .0001, C1, C2, No, N1, N2, N3, N4, N5, N0},           Panel[       Grid[         Transpose[{{            Style["H1", Green], Style["H2", Green]   }, {            {            InputField[             Dynamic[H1 =                C1*(Exp[Sqrt[l1]*r] - Exp[-Sqrt[l1]*r]) + (f1/l2)*r],              Enabled -> False],            InputField[Dynamic[H2 = C2*(Sqrt[l1]   )], Enabled -> False]            }}] , Alignment -> Left] , ImageMargins -> 50]      ]


title: Why does Mathematica not go to specified order in series?

text: For some reason Mathematica will not evaluate this asymptotic series to the requested order. Inputting:               1/x ( x ((1 - x)^2) + E^x);     Series[%, {x, \[Infinity], 0}]      Yields: $ \left( x^2 + \frac{1}{\mathcal{O} \left( \frac{1}{x} \right)} \right) + e^x \left( \frac{1}{x} + \mathcal{O} \left( \frac{1}{x} \right)^2 \right)$ The problem being that in the first term it doesn't give me the $\mathcal{O} (x^1)$ and $\mathcal{O} (x^0)$ that I requested. Mathematica does not make this error for simpler expressions, but I haven't been able to nail down what exactly about this expression is giving me problems. A couple things I have tried: (1) I could simply go to a higher order in x in order to get the 'missing' terms, but this is computationally expensive on more complicated expressions. (2) If I Expand[%] the expression prior to the series expansion that gives me the correct terms, the only thing is, I would never have guessed that I have to put that in there. Plus I often deal with expressions much more complicated than this and it is hard to visually inspect all the $\mathcal{O}(1/\Lambda)$'s all over the place Is there a simple reason I should have anticipated this being a problem for Mathematica? And is there a simple command to use that doesn't slow things down? - sometimes using Expand[%] prior to doing a computation can slow down when dealing with large expressions.


title: Using Dynamic with UpdateInterval and EventHandler Together

text: I've been having some difficulty with the aforementioned use of these three functions/options and would greatly appreciate some help. I know that they're is probably an easy way of making a disk move across a square, but, as you may be able to guess, this is an abstraction of my real problem and thus I have to work with an object-oriented system (i.e., currying). Let's say I wanted to make a disk move from the bottom left of a square to the top right, with enter as my play/pause control: My code:               makeobject[name_String] := object[name]          (* Default values for position and velocity *)       object[name_]["pos"] = {0, 0};       object[name_]["vel"] = {.05, .05};          (* Return a graphic method *)       (this : object[name_])["pic"] := {EdgeForm[Pink], Blue,       Disk[this["pos"], .2]}          (* update *)       tick[obj_] := ((obj["pos"] = obj["pos"] + obj["vel"] (.1)); obj)          (* Dynamic pictures *)     DynamicModule[{play = False, myobj = makeobject["myobj"]},         EventHandler[             Dynamic[                 EventHandler[                     If[play,                         myobj = tick[myobj];                         Graphics[{Black, Rectangle[{0, 0}, {50, 50}], myobj["pic"]},                              PlotRange -> {{0, 1}, {0, 1}}],                         Graphics[{Black, Rectangle[{0, 0}, {50, 50}], myobj["pic"]},                              PlotRange -> {{0, 1}, {0, 1}}]                       ],                     {"ReturnKeyDown" :> (play = False)}],                UpdateInterval -> .01],            {"ReturnKeyDown" :> (play = True)}        ],        Initialization :> ( myobj["pos"] = {0, 0})     ]        The site's not letting me put up any pictures of what's happening, but when I evaluate, you get an image of black rectangle with the quarter circle at the bottom. Pressing enter makes the disk move up and right. But, while it's updating, if I press enter, nothing happens, and the disk keeps moving. This means that it's still calling `tick[myobj]` and therefore the `"ReturnKeyDown":>(play=False)` never worked. Thanks in advance for any help. Sorry if I am missing any kind of information, this is my first question. Please let me know if so. MMA 8.0.1.0 for students   OS Windows 7 64-bit


title: Convert *.txt file

text: I would like to Import and Convert a *.txt file which looks like: https://docs.google.com/file/d/0Bw-308nJcF01Yl92RURCLUg4VzQ/edit?usp=sharing and turn it into a Matrix which I can use to make computations which looks like this one:                example = {{"DATE", "KEY", "C1", "C2", "C3"},                 {{2013, 04, 01, 00, 00, 1}, 1, Null, 12.23,  Null},                 {{2013, 04, 01, 00, 00, 2}, 2, Null, 2,      Null},                 {{2013, 04, 01, 00, 00, 3}, 3, Null, 10.2,   Null}}


title: logticks in a colorbar

text: I have a question on using logarithmic ticks in a colorbar in _Mathematica_ 8.0 . I use the package `ColorbarPlot` (`type->"Density"`) in order to show a legend. As well as the default ticks, I can set the ticks by myself. The problem is that my data range is from $-10^{16}$ to $10^{16}$, and I cannot see the intermediate values because the values with large exponents at the two ends to the range absorb all the colour. One solution would be to have logarithmic ticks, but I have also negative values. Do you have any ideas? If you have another solution without using `Colorbarplot`, it would also be welcome.


title: Implementing myMapThread with Thread, Apply

text: ## Problem: Exercise 5.2.1 from Wagner's Book: implement myMapThread in terms of Thread/Apply such that it works with the Power/Equal examples below. ## My Attempt:               In[3]:= myMapThread[func_, list_] :=        Thread[(Apply[func, #] &)[list]];     myMapThread[Power, {{a, b, c}, 3}]     myMapThread[Equal, {{1, 2, 3}, {1, 2, 4}}]          Out[4]= {a^3, b^3, c^3}          Out[5]= False          In[6]:= myMapThread[func_, list_] :=        Thread[Unevaluated[(Apply[func, #] &)[list]]];     myMapThread[Power, {{a, b, c}, 3}]     myMapThread[Equal, {{1, 2, 3}, {1, 2, 4}}]          Out[7]= {a^b^c, 3}          Out[8]= {False, False}      ## Question 1) I screwed up. What is the correct answer? 2) What am I doing wrong?


title: Extracting parts of nested lists of rules using a syntax similar to JsonPath or Xpath

text: Given an example data set:               data = {"region" -> "AA",              "systems" -> {{"name" -> 1,                              "sub" -> {{"name" -> "sub11"}, {"name" -> "sub12"}}},                           {"name" -> 2,                              "sub" -> {{"name" -> "sub21"}, {"name" -> "sub22"}}}}};      I would like to extract the various systems and subsystems attributes. I would prefer a sysntax similar to JsonPath ot XPath. So for example, I would like to be able to write something similar to:               data."region" (* AA *)     data."systems"[2]."name" (* 2 *)     data."systems"[2]."sub"[2]."name" (* sub22 *)      Filtering is a nice bonus                data."systems"[#."name" == 1 &]."sub"."name" (* {"sub11", "sub12"} *)       **How could I make this or a similar syntax work?** Using `ReplaceRepeated` almost works (just the substitutions have to be written in reverse ie `"name" /. "systems"[[2]]` instead of the more logical `"systems"[[2]] -> "name"`).               {"region", "name" /. "systems"[[2]], "sub"[[2]] /. "systems"[[2]]} //. data         (* ==> {"AA", 2, {"name" -> "sub22"}} *)      But this fails, as `"name"` appears on two levels               {"region", "name" /. "systems"[[2]],        "name" /. "sub"[[2]] /. "systems"[[2]]} //. data          (* ==> {"AA", 2, 2}  but I would like {"AA", 2, sub22}   *)


title: Extracing information from a table

text: I am new to Mathematica. I have created a table of real numbers. I want to create a new table that contains the set of values of $i$ such that, in my original table, the $i$th entry is greater than the $(i+1)$th entry. For example If I had the table {1,2,5,2,9} my new table would be {3}.


title: How to plot a function $\psi(r,\theta,\phi=0)$ in polar coordinates?

text: I have a function $\psi(r,\theta,\phi=\phi_0)$ with $\phi_0\in \Re$, $r\in[0,R]$ with $R\in \Re$, and $\theta \in [0,\pi]$ (spherical polar coordinates) and I want to plot it in Mathematica. I guess the proper way to do that is in polar coordinates, but how do I do that? The function is: $$\psi(r,\theta,\phi=0)=r^2e^{-r}\cos \theta $$


title: Why there is no name for #1@#2&?

text: Why does the pure function `#1@#2&` have no name? Is it due to the way _Mathematica_ works, or is it "just because"? I'm asking because I find inelegant to write expressions like               MapThread[#@#2 &, {{a, b, c}, {1, 2, 3}}]      > >     {a[1], b[2], c[3]} >   I would rather have a name form such as               MapThread[Work, {{a, b, c}, {1, 2, 3}}]       `Work` is not the best choice but I'm open on suggestions :)   * One may say that there is no name because `#1@#2&` is short enough. But `f/@{1,2,3}` is shorter than `Map[f,{1,2,3}]` and `Map` exists :)   * Then I've thought, maybe it is because `Map` gives other possibilities with 3rd argument and this is the difference. Well, it is a difference, but so what, why ther is no `Work`?


title: Why won't Mathematica Integrate my function?

text: My code:               r5 = 47000;     vcc = 3.3;     hfe = 420; (* BC337-40: 250 *)     vbe = 0.6;     r4 = vbe/2*^-6;     ctr = 1;     r1 = 1000000; r2 = r1;     vrms = 230;     vled = 1.5;     v0[t_] := Max[vcc - r5 ic[t], 0.2]     ic[t_] := Min[hfe ib[t] + 0.000005, vcc/r5]     ib[t_] := idar[t] - ir4[t]     ir4[t_] := Min[idar[t], vbe/r4]     idar[t_] := Abs[iled[t]] ctr     iled[t_] := Max[Sign[vi[t]] (Max[Abs[vi[t]] - vled, 0])/(r1 + r2), 0]     vi[t_] := vrms Sqrt[2]  Sin[2 Pi t/20]     pmains[t_] := vi[t] iled[t]     pvcc[t_] := vcc idar[t] + vcc ic[t]     power[t_] := pmains[t] + pvcc[t]     pvccavg = Integrate[pvcc[t], {t, 0, 20}]/20      MMA gives me this result: ![enter image description here](http://i.stack.imgur.com/Hz9l6.png) which is my list of nested function calls written as one single function. Why doesn't `Integrate` work here? Note that it does give me results if I split the [0,20] interval in [0,10] and [10,20].