title: Solving for equilibrium distribution (symbolic) by matrix multiplication

text: I have a huge transition matrix (81x81). The matrix is too huge to paste here, so I store it in this notebook. (There are constraints on the symbols: $0<p_b<1$ and $0<p_g<1$. If further constraints are needed, $0<p_b<0.5<p_g<1$) The terms are either in symbols or rational numbers, or the mixture of both. I tried to solve for its equilibrium distribution using `LinearSolve`, but the execution lasted for one day and ended up using up all work PC's physical RAM and swap space (16G in total) but no results could be obtained. Now I'm thinking about getting the equilibrium distribution by matrix multiplications, since for a transition matrix $\mathbb{M}$: $$ \lim_{n\rightarrow\infty}\mathbb{M}^n=\mathbb{A}. $$ The rows of $\mathbb{A}$ is the equilibrium distribution, provided the equilibrium exists. Operationally, I will repeatedly multiply the transition matrix and do `Simplify`. **I need the symbolic expressions rather than the numerical results for particular $p_b$ and $p_g$.** I would like to know if this method will work and if anyone has done the same before.


title: Units: Custom-defined units possible?

text: Converting between revolutions per minute (RPM) and revolutions per second (RPS) is not straightforward for me in Mathematica. I know that $1\; \text{RPM} = \frac{2\; \times\; \Pi\; \text{Radian}}{\text{Second}\; \times\; 60}$. To get RPS then, it is just a matter to remove the factor of $60$ in the denominator. Taking a numerical example, I can convert say $500$ RPM to Hertz as follows: $[\text{Convert}[\frac{500\; \times\; 2\; \times\; \Pi\; \text{Radian}}{\text{Second}\; \times\; 60}, \text{Hertz}],9]$ which gives me $52.3597776\; \text{Hertz}$ But now if I want to convert $500$ RPM to RPS, the following does not work as in the `Convert` command, the second argument has also **numerical values** in it: $[\text{Convert}[\frac{500\; \times\; 2\; \times\; \Pi\; \text{Radian}}{\text{Second}\; \times\; 60}, \frac{2\; \times\; \Pi\; \text{Radian}}{\text{Second}}],9]$ which gives me as output: $\frac{52.3598776\; \text{Radian}}{\text{Second}}$ instead of the desired answer of about $8.33\:$ . The factor of $2\; \Pi$ is the troublemaker. So how to do an appropriate conversion from RPM to RPS? **update** : I am using version `9`. Thank you.


title: Show the arrows in a plot

text: I have two plots:               pt1=ParametricPlot3D[{Sin[θ], y, Cos[θ]}, {θ, 0, 2 Pi}, {y, 0, 2 Pi},       PlotRange -> {{-2, 2}, {0, 2 Pi}, {-2, 2}},       BoxRatios -> {1, 3/2, 1}, Boxed -> False, AxesOrigin -> {0, 0, 0},       AxesLabel -> {x, y, z}, Mesh -> None,       AxesStyle -> Arrowheads[{0.1, 0.1, 0.2}],       ColorFunction -> Function[{x, y, z}, Lighter[LightGray]],       BoundaryStyle -> Gray];      ![Mathematica graphics](http://i.stack.imgur.com/ey0A8.png)               pt2=Show[Table[       Graphics3D[{{Arrowheads[Small],           Arrow[{{0, i1  (Pi/50), 0}, {Sin[ (2 Pi/50) i1], i1 (Pi/50),              Cos[ (2 Pi/50) i1]}}]}}, Boxed -> False], {i1, 1, 100}]];      ![Mathematica graphics](http://i.stack.imgur.com/U4bcY.png) I would like to see "apparently" all the arrows by combing them together. However, when I use               Show[pt1,pt2]      ![Mathematica graphics](http://i.stack.imgur.com/BTRQj.png) I can not see any "arrows" from the output. Can anyone help me to fix this? Thanks!


title: Automatically lining up two images that have some common elements

text: Over on genealogy.SE, I proposed a method of manipulating images to make "bleed through" less visible and the handwriting on the correct side of the page more legible. Here are the original images: ![enter image description here](http://i.stack.imgur.com/2hf7N.jpg) ![enter image description here](http://i.stack.imgur.com/WnVtF.jpg) The idea is to make a mirror image of the other page, and then remove things that are dark on the flipped page and lighter on the target page, and similarly keep things that are darker on the target page than the flipped page. Here's the flipped page:               page17cropflip = ImageReflect[page17crop, Left]      ![enter image description here](http://i.stack.imgur.com/W9BeF.jpg) Here was the set of commands that worked tolerably well in this case (it looks better at full size):               With[{brightness = -0.3`, contrast = 0, final = 0.903`,        highbleed = 0.159`, lowbleed = 0.221`, method = "Cluster"},       Binarize[ImageAdjust[        ImageClip[         ImageAdd[Blur[page18crop, 3],           ImageClip[page17cropflip, {lowbleed, lowbleed + highbleed}]], {0,           final}], {contrast, brightness}], Method -> method]]      ![enter image description here](http://i.stack.imgur.com/Makel.png) But I needed to crop the images by hand (I used `ImageDifference` to help line it up) so that the bleeding through text lined up with the actual text on the image of the facing page. Is there a way to automate this?


title: How to create effect like Van Gogh's stroke brush?

text: I need to apply Van Gogh's stroke brush effect to a random image ![Van Gogh's painting](http://i.stack.imgur.com/kN0cD.jpg) Take the following image as an example:![Example Image](http://i.stack.imgur.com/XwYg7.jpg) Thank you so much if you could help!


title: Can Mathematica solve this sort of functional/differential equation?

text: I am looking for differentiable functions $f$ from the unit interval to itself that satisfy the following equation $\forall\:p \in \left( 0,1 \right)$: $$1-p-f(f(p))-f(p)f'(f(p))=0$$ Is there a way to use _Mathematica_ to solve such equations?   `DSolve` is of course unable to handle this -- unless there are tricks I don't know about.


title: How to get grid lines at all (log) tick marks in Version 10?

text: In Version 7 using `GridLines -> Automatic` (or `All`) would put a grid line at every log-spaced tick mark:               LogPlot[x^x, {x, 1, 5},      GridLinesStyle -> LightGray,      GridLines -> Automatic,       Frame -> True]      ![enter image description here](http://i.stack.imgur.com/ZBtGK.png) In Version 10 this is no longer the case: ![enter image description here](http://i.stack.imgur.com/c6M9C.png) What is the simplest way to recover the old behavior?


title: How to input a 3-vector in spherical coordinates?

text: I would like to input a 3-vectors in spherical coordinates $(r, \theta, \phi)$ and be able to operate on such vectors (dot and cross product) with the results being given in the same spherical coordinate system. Is there an easy way to achieve this in _Mathematica_?


title: Writing a simple application: interactive quiz for multiplication table practice

text: I am trying to write a very simple application in Mathematica: a quiz that tests a multiplication table(let's use the 9x9 for this example). The app will display a question(e.g. 7x5), and the user has a textbox to type the answer(35 for the example). The user can simply press the enter or return key on a keyboard to proceed to another question (randomly selected). I have been using Mathematica for years, but I have no experience with constructing an application with interactive user interface since I use it for data analysis and complex mathematical tasks (I have no experience in constructing user interface in Mathematica except some simple usages of the Manipulate function). I would appreciate some guidance/help. Thanks!


title: sudden increase in timing when summing over 250 entries

text: Using math 9.0.1 on a MacBook Air, I see a sudden increase of `Timing` by a factor of thousands when I sum over 250 elements of a matrix rather than over 249. So for instance, this table contains sums from 1 to 249 and it takes 0.0002s               Clear[vec, time];     vec = Table[i, {i, 100}, {j, 100}, {k, 300}];     time = Timing[     Table[Sum[vec[[i, j, k]], {k, 1, 249}], {i, 1}, {j, 1}]][[1]]; time      while if I go from 1 to 250               Clear[vec, time];     vec = Table[i, {i, 100}, {j, 100}, {k, 300}];     time = Timing[     Table[Sum[vec[[i, j, k]], {k, 1, 250}], {i, 1}, {j, 1}]][[1]]; time      it takes 1.4s. The huge increase occurs regardless of the content of `vec`, regardless of the upper limits of i,j, and it does not depend on whether I go from 1 to 250 or from 2 to 251, provided it's at least 250 entries. So if I sum from 2 to 250, it's back to 0.0002s. It depends instead on the size of `vec` (that is why I create a much larger matrix `vec` than actually needed in the sum). Can anybody reproduce this behavior? Any suggestion?


title: Can a Mathematica Application be inside another Application?

text: The file structure of a simple MMA Application can have the form:                 MyApplication         MyApplication.m         SomeAuxiliarPack.m         Kernel           init.m      Where `init.m` file have the form:               Get["MyApplication`MyApplication`"]     Get["MyApplication`SomeAuxiliarPack`"]      Ok.. all nice until here. The question is. How can I have a SubApplication inside Application, in some way that the SubApplication is independent from the first one, and is initialized together with MyApplication? Using this structure:                 MyApplication         MyApplication.m         Kernel           init.m         MySubApplication            MySubApplication.m            Kernel              init.m      with `init.m` Application as:               Get["MyApplication`MyApplication`"]     Get["MyApplication`MySubApplication`"]     Get["MyApplication`SomeAuxiliarPack`"]      and `init.m` SubApplication 2 as:               Get["MyApplication`MySubApplication`MySubApplication`"]      It works, but as you can see, SubApplication init.m has a unnecessary reference for `MyApplication`.


title: Expanding lists with split strings

text: I've got data of the type:               list = {"Class","MW","10 - 11"}      which I would like to split into a number of lists based on the number of characters in the second list element. In the above case, the desired output would be:               newlists = {{"Class","M","10-11"},{"Class","W","10-11"}}      `StringSplit[list[[2]],""]` gets me in the right direction (the string I want to split will always be in the same position in the list); however, I don't know how to thread this new sublist through the original list.


title: Are there any functions that can determine the disorder between two lists?

text: dj11 = {1, 2, 3, 6, 5, 10, 15, 30, 7, 14, 21, 42, 35, 70, 105, 210,      11, 22, 33, 66, 55, 110, 165, 330, 77, 154, 231, 462, 385, 770,      1155, 2310};          dj12=Sort[dj11]            (* {1, 2, 3, 5, 6, 7, 10, 11, 14, 15, 21, 22, 30, 33, 35, 42, 55, 66,     70, 77, 105, 110, 154, 165, 210, 231, 330, 385, 462, 770, 1155, 2310} *)        I need to see if there is any way to determine the amount of disorder between the two lists dj11 and dj12 (i.e., how much complexity has been removed). **Motivation** I am exploring the changes in complexity for the square-free numbers as we step through the integers. _Square-free numbers_ are just the divisors of a primorial. Example _(top view)_ : $dj11 = \text{Join}(dj7, dj7 * p_{11})$.


title: Error with "Newton's method" in Wellin's Mathematica book

text: In Wellin's Programming with Mathematica book, here's one of his implementations of the Newton method, where the iteration runs until the error tolerance is reached. ![Mathematica graphics](http://i.stack.imgur.com/EnGoj.png) ![Mathematica graphics](http://i.stack.imgur.com/i4rj2.png)               Clear[findRoot]     findRoot[expr_, {var_, init_}, ϵ_] :=      Module[{xi = init, fun = Function[fvar, expr]},       While[Abs[fun[xi]] > ϵ,        xi = N[xi - fun[xi]/fun'[xi]]];       {var -> xi}]          findRoot[x^3 - 2, {x, 2.0}, 0.0001]     (* {x -> 2.} *)      As you could see the result is clearly wrong. I think it's because of the presence of `fvar` in the body of `Function`, which was never defined. I think he meant to use `var`. I tried that, and it works, but there was a warning that `"The variable name has been used twice in a nested scoping construct, in a way that is likely to be an error"`, with `var` highlighted in red. ![Mathematica graphics](http://i.stack.imgur.com/pU2zC.png) Should I be concerned about this warning? In what circumstances would that be an issue? Please feel free to come up with examples of your own. **Edit** : Here's a way that I found that avoid the scoping warning: ![Mathematica graphics](http://i.stack.imgur.com/RpuBw.png) Is this a better way? I think the main reason of using `Function` in Wellin's case and defining a function within the `Module` here is to make a regular expression (which can't take in variable directly) become a function that could take in a value (`xi` in this function). What's the best way to do it? This is closely related to this question here.


title: how to solve ODE with boundary at infinity

text: y''[x]-x y[x]==0     y[0]==AiryAi[0], y[infinity]==0      the analytic solution to this ODE is the Airy function               y[x]=AiryAi[x]      if I use `NDSolve` to solve this ODE, I do not know how to express the boundary condition at infinity. I first tried to set `y[100]=0`, the error message from `mathematica` is: > NDSolve::bvluc: The equations derived from the boundary conditions are > numerically ill-conditioned. The boundary conditions may not be sufficient > to uniquely define a solution. The computed solution may match the boundary > conditions poorly. >> > > NDSolve::berr: There are significant errors {0.,5.04843*10^273} in the > boundary value residuals. Returning the best solution found. >> then I tried to replace `x` by `x=tan[u]`, with `0<u<Pi/2`, now my boundary condition is at finite location, however I still receive error message when I use `NDSolve` > NDSolve::bvluc: The equations derived from the boundary conditions are > numerically ill-conditioned. The boundary conditions may not be sufficient > to uniquely define a solution. The computed solution may match the boundary > conditions poorly. >> > > NDSolve::mxst: Maximum number of 10000 steps reached at the point u == > 1.5651256862447316`. >> > > NDSolve::berr: There are significant errors {0.,1.331263934430340*10^660} in > the boundary value residuals. Returning the best solution found. >> > > NDSolve::mxst: Maximum number of 10000 steps reached at the point u == > 1.5651764393985212`. >> the equation I am posing here can be analytically solved, however my really equations can only be solved by NDSolve with boundary condition at Infinity. so I am asking for the possibility to solve this equation numerically. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% According to different kindly advice, numerically solve an ODE with unbounded region is impossible. A more practical way is by shooting method. By replacing `y[Infinity]==0` to `y[100]==10^{-10}`, the numerical result agrees very well with the exact solution `y[x]=AiryAi[x]`


title: Using J/Link with Wolfram Programming Cloud

text: Is it possible to use J/Link in a Wolfram Programming Cloud notebook? I need it to load and use 3rd-party .jars.


title: Assumptions about list elements

text: I am trying to simplify some expressions using assumptions and got an inconsistent behavior of _Mathematica_ 9 when working with indexed variables. Consider               Assuming[Subscript[x,_] ∈ Reals, Refine[Im[Subscript[x, 10]]]]      > 0               Assuming[Subscript[x,_] ∈ Reals && Subscript[x,_] > 0, Refine[Sign[Subscript[x,10]]]]      > >     Sign[Subscript[x, 10]] >                 Assuming[Subscript[x,10] > 0, Refine[Sign[Subscript[x,10]]]]      > 1 It appears that assumptions about an indexed variable being real work, but assumptions about the positivity of an indexed variable seem not to work.


title: Tile image on specific location without space between them

text: > **Possible Duplicate:**   >  How to combine images with the same dimensions in a grid? I would like to arrange images without any space between their edges as each piece is made to connect with others. The images should not necessarily be merged but simply tiled. My ultimate purpose is to use a Manipulate to generate different arrangements. So, how can I place those images in a coordinate system so I can define 9 positions and assign those locations to the images without any space between them ? Below my attempt using Grid and 2 example of the desired Output once I figure this out. Those composition were generated using Java Scripts. **EDIT** : The problem with `Grid` or `ImageAssemble` is they would not allow for "empty slots", which is an option I would like to have as shown in the last image for example. ![enter image description here](http://i.stack.imgur.com/2V1DA.png) ![enter image description here](http://i.stack.imgur.com/MZExV.png) ![enter image description here](http://i.stack.imgur.com/MW6h8.png)


title: some Graphics output do not fully render on the screen until an extra click is made into the notebook

text: Sometimes when using a command such as `Grid` and looking at the output, some of the actual lines (frame, gridlines) that make up the display will be missing on the screen (not finished rendering) After shaking the notebook by holding it with the mouse at the corner and just slightly pulling it to make it little bigger or smaller, the display will now finish rendering and any missing parts of the Graphics will show up. Forcing full rendering can also be achieved by making one extra click of the mouse once anywhere in the notebook. The Graphics can also be made to fully render by moving another application window over the Mathematica notebook and then removing that application window again, all the time without touching the notebook. This might make one think it can be a windows/graphics card/monitor issue? Since it looks like a repaint event is needed by the OS. Using V9, windows 7 64 bit. Intel hardware. ATI Radeon HD 5570 graphics card. (note: On version 8, the same issue is present hence it is not a version 9 specific) Using Default_8.nb with version 9. Here is a small example               Grid[{       {        Plot[Sin[x], {x, 0, 2 Pi},          AxesLabel -> {"x", "very very loooooooong"},          ImageSize -> {200, 150}, ImagePadding -> {{50, 20}, {40, 30}}]        },       {        Plot[Sin[x], {x, 0, 2 Pi}, AspectRatio -> 1/3,          AxesLabel -> {"x", "short"}, ImageSize -> {200, 140},          ImagePadding -> {{50, 20}, {40, 30}}]        }       }, Spacings -> {0, 0}, Frame -> All      ]      Notice the middle line and the bottom line are missing from the grid. Now Clicking in the code cell once caused it to fully draw. Here is screen shot showing before the click and after the click ![enter image description here](http://i.stack.imgur.com/C3lJi.png)


title: Cyclic Noncommutative Multiplication

text: I work with traces of long matrix products and I want mathematica to employ the cyclicity when simplifying. I use this redefinition of the non-commutative multiplication:               Unprotect[NonCommutativeMultiply];     Clear[NonCommutativeMultiply]          (*Factor out numerics-- could generalize to some ScalarQ*)     nc : NonCommutativeMultiply[a__] /; MemberQ[{a}, _?NumericQ] :=       NCMFactorNumericQ[NCM[a]] /. NCM -> NonCommutativeMultiply          (*Simplify Powers*)         b___ ** a_^n_. ** a_^m_. ** c___ :=       NCM[b, a^(n + m), c] /. NCM -> NonCommutativeMultiply          (*Minus*)     NonCommutativeMultiply[a___, b_Times, c___] :=       NCMFactorNumericQ[NCM[a, Sequence @@ b, c]] /.        NCM -> NonCommutativeMultiply     Protect[NonCommutativeMultiply];          Unprotect[NCM];     Clear[NCM]     NCMFactorNumericQ[nc_NCM] :=       With[{pos = Position[nc, _?NumericQ, 1]},        Times @@ Extract[nc, pos] Delete[nc, pos]]     NCM[a_] := a     NCM[] := 1     Protect[NCM];      which was given as an answer to this question and is very helpful, but I want it to be able to cancel `A**B**C` with `-B**C**A` (but only if these matrices stand alone, i.e. I don't want it to cancel `A**B**C**D` with `-B**C**A**D`). Any help would be greatly appreciated.


title: Confidence and prediction bands for custom nonlineal for CDF from ProbabilityDistribution

text: I have a CDF obtained with the code:               dist = ProbabilityDistribution[{"CDF",         Exp[-a Exp[-x b] - c Exp[-x d]]}, {x, 0, Infinity},        Assumptions -> {{0 < a < 10}, {0 < b < 1}, {0 < c < 10}, {0 < d <            1}}]     res = FindDistributionParameters[data,        dist, {{a, 3.8}, {b, 0.006}, {c, 0.08}, {d, 0.0002}}]      I can plot the confidence and prediction intervals following this demo for nonlinear pairs of data adjustment: http://demonstrations.wolfram.com/MeanAndSinglePredictionBandsForANonlinearModel/ But for the custom CDF obtained with ProbabilityDistritution, I tryed this:               Plot[{Func[x], bands90[x]}, {x, 0, 3000}, Filling -> {2 -> {1}}]      Without results. Someone knows how to get the confidence and prediction bands in the case of CDF obtained with that function, as well as the ANOVA or the table that one can shows with ParamterTable (when fitting with NonlinearModelFit)? Thanks you very much.


title: Very different results from evaluating same expression with different precisions

text: When I evalute the following expression,               N[95881665812878 - 120000000000000 (121576521638975 - (321097753837557 Log[1/3 (1 + (19 - 3 Sqrt[33])^(1/3) + (19 + 3 Sqrt[33])^(1/3))])/ Log[5]) + ( 321097753837557 Log[(-1 + 1/3 (1 + (19 - 3 Sqrt[33])^(1/3) + (19 + 3 Sqrt[33])^(1/3)))/(-6 + 4/3 (1 + (19 - 3 Sqrt[33])^(1/3) + (19 + 3 Sqrt[33])^(1/3)))])/ Log[5]]      I obtain > -1.875*10^12 But, when I evalute it asking for 3-digits, I get > 0.487 What is the reason for the different results?


title: Angular Range in Polar Plot

text: I am trying to make a polar plot using the following code               PolarPlot[1, {θ, 0, Pi/3}, PolarAxes -> True,       PolarTicks -> {"Degrees", Automatic}, PolarGridLines -> True,       PlotRange -> 1.5]      ![](http://i.imgur.com/nqG2HGm.png) What I would like to do is to set the angle range of the polar axis, from 0 to 60 degrees. I've tried using `PlotRange` but this changes the radial component of the function... How is it possible to define an anglular range of a polar plot?


title: The locations of (row-wise) minimum elements in a list

text: I have a list representing a 2D matrix, such as this 3 ⨉ 2 one:               {{2.1, 1.01}, {0.01, 7.2}, {7.8, 2.0}}      Does anyone know how to find the minimum of each row, ideally outputting a new list of 1's where the row minimums are in the original matrix and 0's for all other elements? i.e.               {{0, 1}, {1, 0}, {0, 1}}      The answer should work for any m ⨉ n list.


title: Quadratic programming problem

text: I am trying to solve a (Sequence) Quadratic Programming (SQP) problem in _Mathematica_. Here’s the problem setup:               size = 9; (* for illustrative purposes, can be larger *)     (* known coefficients *)     m1 = {{a, b, c, d}, {e, f, g, h}, {i, j, k, l}};     m2 = {{m, 0, 0, 0}, {0, n, 0, 0}, {0, 0, o, 0}};     (* unknowns *)     θ = Table[{Subscript[x, i], Subscript[y, i], Subscript[z, i], 1}, {i, size}];          (* My system of quadratic equations *)     data == Transpose [m1.Transpose[θ] + m2.Transpose[θ^2]];          (*Subject to the following constraints *)     constraints =        Table[{Subscript[x, i]^2 + Subscript[y, i]^2 + Subscript[z, i]^2 == 1}, {i, size}];      Sample data:               data =         {{0.0326857, -0.23977, -0.980886}, {-0.00491715, 0.160488, -0.980237},        {-0.0189063, 0.137756, 0.969873}, {-0.0165821, -0.256267, 0.967219},         {-0.00898421, -1.00759, -0.258025}, {-0.0131764, 0.918642, 0.192466},         {-0.00673595, 0.0658302, -0.996648}, {0.00647973, -0.147268, -0.997363},         {-0.0200075, -0.164866, 0.981011}, {-0.0242359,0.0523168, 0.981269},         {-0.0132569, -1.03757, -0.0196142}, {-0.0164502, 0.94126, -0.0110496},         {-1.01661, -0.0493139, -0.0169287}, {-0.0250339, -0.0569752, 0.988069},         {0.981252, -0.048789, -0.00833748}, {-0.00965323,-0.0403172, -1.00421}};          m1 =        {{0.851943, 0, 0, 0.0154734}, {0.500424, 1.01131, 0, 0.0564313},         {-0.164399, 0.00390119, 1.00309, 0.00583693}};          m2 = {{0.00912, 0, 0, 0}, {0, -0.00320, 0, 0}, {0, 0, 0.00175, 0}};


title: More structure in Source Code/Notebooks

text: _Mathematica_ is great for small and quick projects and has a great syntax. However as soon as a project grows I run into trouble. How do you scale and maintain projects in _Mathematica_? What is beyond the interactive notebook style? So far I   1. get something going in different cells   2. copy and paste it into one cell   3. define a function around it If I want change something I usually mess something up and then have to break up the code again to find the error. In C++ you obtain the structure by thinking object oriented...


title: "Thickness" doesn't work in Parametric3D

text: I have Mathematica 8 and for some reason, the parameter "thickness" doesn't work in Parametric3D, it works in 2D very fine > ParametricPlot3D[{{t, 0, -t}, {0, t, 2 t}}, {t, 0, 100}, PlotStyle -> {Blue, > Orange, Thickness[100]}] Anyone know a remedy for this?


title: Saving graphics in Adobe Illustrator .ai format

text: How do I save a `ListLinePlot` graphic as an _Adobe Illustrator_ file (with extension `.ai`)?


title: Does Mathematica solve transfer functions differently to Matlab?

text: Please note this is an edit to the same question posed a few weeks back: I'm using Mathematica to derive the transfer functions for a three phase AC/DC inverter. Given below is the code for the derivation of the transfer function for a third order filter (LCL) connected system:               Clear[Asys, Bsys, Csys, Dsys]          numericalvalues = {     R1 -> 0.,     R2 -> 0.,     Rd -> 0.,     Lff ->  2.3*10^-3,     Lgf -> 0.93*10^-3,     Cf -> 10*10^-6,     Vbatt ->  400,     Vdc -> 800,     d -> 1};          Asys = {{(Rd - R1)/Lff, -(Rd/Lff), 1/Lff}, {-(Rd/Lgf), (R2 + Rd)/Lgf,      1/Lgf}, {1/Cf, -(1/Cf), 0}};          Bsys = {{d/Lff}, {0}, {0}};     Csys = {{0, 1, 0}};          systf4 = TransferFunctionModel[Csys .Inverse[(( {         {s, 0, 0},         {0, s, 0},         {0, 0, s}        } ) - Asys)].Bsys, s]          Convertertf4 = Simplify[systf4 /. numericalvalues // N]      This results in the following transfer function:               (4.67508*10^10/(s^3+6.40486*10^7 s))      The transfer function calculated by this code differs from the same system solved in Matlab given below:                4.675*10^10/ (s^3 + 1.527*10^-12 s^2 + 6.405*10^7 s + 9.78*10^-5)      Does Mathematica have a tolerance limit that it is assuming the small numbers are insignificant and can be ignored? Has anyone had any experience with this before?


title: How I get random keys from keyboard for game controls?

text: I'm trying to make moving object using controls. I'm trying to do this using Buttons. The code is               diskPosition = {50, 50}; left = False; right = False; up = False; down = False;          Manipulate[      Graphics[Dynamic[        If[left, diskPosition[[1]] += -.01];         If[right, diskPosition[[1]] += .01];        If[up, diskPosition[[2]] += .01];         If[down, diskPosition[[2]] += -.01];        {Yellow, Disk[diskPosition, 3]}],       PlotRange -> {{0, 100}, {0, 140}}, Background -> Black       ],      Row[{Button["\[LongLeftArrow]", left = True;          right = up = down = False],         Column[{Button["\[UpArrow]", up = True;            right = left = down = False],          Button["\[DownArrow]", down = True; right = up = left = False]}],         Button["\[LongRightArrow]", right = True;          left = up = down = False]}]      ]      I wonder if I can use random keys on the keyboard? I know how to get "Shift", "Ctrl" and "Alt" with CurrentValue[] but not how to get random keys from keyboard. Some suggestions?


title: Making ColorSetter work like a PasteButton

text: I might be missing something obvious here. I am building a palette for constructing code to make certain graphics. The idea is that my colleagues can click buttons instead of having to know the right commands. So `PasteButton[]` is an obvious help. Where I have gotten stuck is in color definition. What I want is for the user to be able to select a color on a `ColorSlider`, and then click a button to paste the `RGBColor[]` value selected in that `ColorSlider` at the notebook insertion point. I do _not_ want the code pasted in this way to update subsequently when the user chooses a different color in the `ColorSlider` This is what I have so far, but the resulting pasted code does not pick up when the user has selected a different color in the slider. Pasting `Dynamic[col]` instead of `Setting[col]` results in a piece of code that changes when a different color is selected in the slider, which as I mentioned is not the desired behaviour.               Grid[{{PasteButton[         Graphics[{Dynamic[col], Rectangle[]}, ImageSize -> 26],          Setting@col, ImageSize -> 26, ImageMargins -> 0, FrameMargins -> 0],         ColorSlider[Dynamic[col], ImageSize -> {75, 25},         AppearanceElements -> "Spectrum"]}}, Spacings -> 0, Alignment -> Bottom]      ![enter image description here](http://i.stack.imgur.com/9ARi3.png) The idea is that the user clicks on a color in the spectrum zone, and then clicks the button on the left that looks like a swatch. How do I modify / rewrite this code to achieve the desired behaviour?


title: Transpose a ragged triangular matrix and display as columns rather than rows

text: I have a triangular list of lists as follows:               In[54]:= Tally[IntegerPartitions[#][[All,1]]][[All,2]]&/@Range[20]     Out[54]= {{1},{1,1},{1,1,1},{1,1,2,1},{1,1,2,2,1},{1,1,2,3,3,1},{1,1,2,3,4,3,1},{1,1,2,3,5,5,4,1},{1,1,2,3,5,6,7,4,1},{1,1,2,3,5,7,9,8,5,1},{1,1,2,3,5,7,10,11,10,5,1},{1,1,2,3,5,7,11,13,15,12,6,1},{1,1,2,3,5,7,11,14,18,18,14,6,1},{1,1,2,3,5,7,11,15,20,23,23,16,7,1},{1,1,2,3,5,7,11,15,21,26,30,27,19,7,1},{1,1,2,3,5,7,11,15,22,28,35,37,34,21,8,1},{1,1,2,3,5,7,11,15,22,29,38,44,47,39,24,8,1},{1,1,2,3,5,7,11,15,22,30,40,49,58,57,47,27,9,1},{1,1,2,3,5,7,11,15,22,30,41,52,65,71,70,54,30,9,1},{1,1,2,3,5,7,11,15,22,30,42,54,70,82,90,84,64,33,10,1}}      I want to display each member of the list in a column (ideally with # as the column heading). I tried using _Column_ , _Transpose_ and _Inverse_ to no avail.


title: Simple question about startup options

text: This is probably fairly straightforward, but I wasn't able to find it right away. I'd like for Mathematica to display on startup the latest notebook I was working on, and nothing else. No additional old notebooks and no new blank notebook. There is probably an option hiding somewhere to do that, but I wasn't able to find it. Apologies if this is too simple.


title: Integral with the derivative of Dirac delta does not evaluate correctly?

text: Integrate[DiracDelta'[y - z] DiracDelta[x - z], {z, -Infinity, Infinity},       Assumptions -> x \[Element] Reals && x \[Element] Reals]


title: How to export a plot into a file?

text: I am trying to save some graphics into a file, and it seems impossible.               x1 = Round[RandomVariate[NormalDistribution[325, 5], 25], 0.1];     x2 = Round[RandomVariate[NormalDistribution[325.5, 2], 25], 0.1];     x3 = Round[RandomVariate[NormalDistribution[327.5, 7], 25], 0.1];          h1 = Histogram[x1, 6, "Probability",         ChartLegends -> {"\!\(\*SubscriptBox[\(x\), \(1\)]\)"},         ChartStyle -> {Directive[Red]},         PlotRange -> {{308, 342}, {0, 0.5}}];     h2 = Histogram[x2, 6, "Probability",         ChartLegends -> {"\!\(\*SubscriptBox[\(x\), \(2\)]\)"},         ChartStyle -> {Directive[Blue]},         PlotRange -> {{308, 342}, {0, 0.5}}];     h3 = Histogram[x3, 6, "Probability",         ChartLegends -> {"\!\(\*SubscriptBox[\(x\), \(3\)]\)"},         ChartStyle -> {Directive[Green]},         PlotRange -> {{308, 342}, {0, 0.5}}];        Export["C:\CompareHist.png", GraphicsColumn[{h1, h2, h3}]]      Of course I cannot use save graphics into file option as there is no such option. And by the way: why Export functions always fails? Even when trying to follow tutorial. Is it some known bug?


title: Large Number times Tiny Number

text: A (maybe noob) question: Let               a = 1234567891234567889998.5     b = 1234567891234567889999.5      Mathematica (v8) yields for               a*0.5 - b*0.5      \--> `0.` (wrong answer) and               (a - b)*0.5      \--> `-0.5` (correct answer) although both expressions `a*0.5 - b*0.5` and `(a - b)*0.5` are mathematically identical. I set `$MinPrecision = 200`, to no avail. Is there a way to get for both analytically identical expressions the same numerical result? In my original mathematical problem I want to compare two representations of the same problem, with one yielding a vast sum over products of binomial coefficients (yielding numerically results of order `10^2^n`, for `n > 10`) with tiny numbers (order `0.1^2^n`). Analytically I cannot simplify the expressions. Thanks a bunch. Michelle


title: Restarting an Animate animation after variable in Manipulate changes

text: I've been trying to restart an animation after variables change from `Manipulate` `PopUpMenus`. My animation takes the form:               Animate[expr, {u, umin, umax, du}].       I can change `u`, after variations to `Manipulate`, back to an initial value momentarily, but from there `u` jumps back to its previous position (or farther forward) as if its continued running. I would be content with simply restarting the entire animation after changing the `Manipulate` variables. My code for `Animate[]` is in the following simplified form (I hope to make the `i` slider bar return back to the left and the red dot to begin being plotted at `x=-10` each time the function is changed):               gPrev[x_] := Sin[x];     Manipulate[      Switch[functionNumb,         0, g[x_] := Sin[x],         1, g[x_] := Cos[x],         2, g[x_] := ArcTan[x]],       {functionNumb, 0, 2, 1}]          Animate[      Plot[{g[x]}, {x, -10, 10},         Epilog -> {Red, PointSize[0.015], Point@{i, g[i]}}], {i, -10, 10, 1},         DisplayAllSteps -> True, AnimationRunning -> False]


title: Introduction of straight Line into Manipulate function

text: I just want to implement a line within my chart that starts from time point 0 to time point T and whose y-coordinates can be manipulated, which in my case is represented by D. I tried to implement a function called `Threshold` but I am still struggling with it. Can anybody of you help me out? My code so far:                Manipulate[        SeedRandom[seed]; Column[{test2[μ_, σ_, S_, P_, T_] := Table[RandomFunction[          GeometricBrownianMotionProcess[μ, σ, S], {0, T, 0.05}]["Path"], {P}];             meanPaths = Mean[test2[μ, σ, S, P, T][[All]]];        threshold[t_, T_] := Line[{{0, t}, {T, t}}];             ListLogPlot[{meanPaths,Flatten[test2[μ, σ, S, P, T], 1], threshold},          Joined -> True, AxesLabel -> {"Time", "St"},           PlotLabel -> Style["Forecasted Stock Price\n (Brownian Motion)", Bold],           PlotRange -> {{0, T}, {0, 700}},           PlotStyle -> {Directive[{Thick, Red}], Directive[{Thin, Gray}]},           GridLines -> {{}, {t}},           ImageSize -> 500]}],             {{S, 100, "Initial Stock Value"}, 100, 500, 0.05, Appearance -> "Labeled"},         {{μ, 0.01, "Drift μ"}, 0.01, 1, 0.05, Appearance -> "Labeled"},         {{σ, 0.01, "Standard Deviation σ"}, 0.01, 1, 0.05, Appearance -> "Labeled"},          {{P, 1, "Paths"}, 1, 100, 1, Appearance -> "Labeled"},           {{T, 1, "Time"}, 1, 250, 1, Appearance -> "Labeled"},          {{t, 100, "thresh"}, 95, 105, Appearance -> "Labeled"},         {{seed, 77777, "New Random Case"}, 10000, 999999, 1},       Button["Set Initial Values",         {S = 100, μ = 0.01, σ = 0.01, T = 1, P = 1, t = 100},         ImageSize -> 150],       ControlPlacement -> Left]


title: NIntegrate converging too slowly when increasing size of array

text: I have a problem with a numerical integration. I have a 4x4x4x4 array that has for each entry an integral and I want to use `NIntegrate` to evaluate it. It gives me no problem, it's actually pretty fast. But if I increase the size of the array to 9x9x9x9 I get this message: > NIntegrate::slwcon: Numerical integration converging too slowly; suspect one > of the following: singularity, value of the integration is 0, highly > oscillatory integrand, or WorkingPrecision too small. I increased the working precision already but it didn't help. **EDITED:** I put here a simplified version of my code:               B9b = Array[Nspher[#2, #4] &, {9, 9, 9, 9}, {1, 0, 1, 0}]      where               Nspher[l_, k_] :=       NIntegrate[       SphericalHarmonicY[l, 0, θ, φ] SphericalHarmonicY[k, 0, θ, φ]*Sin[θ],       {θ, 0, π}, {φ, 0, 2 π},       WorkingPrecision -> 50, AccuracyGoal -> 10, MaxRecursion -> 30]


title: Why TensorReduce not working here?

text: I would like to use `TensorReduce` to work on the tensor contraction $y_{ib}y_{ia}$ (where index $i$ is summed). However, `TensorReduce` does not bring the following `t1` and `t2` into a unique form:               $Assumptions = y ∈ Arrays[{d, d}];     t1 = TensorContract[TensorProduct[y, y], {{1, 3}}];     t2 = TensorTranspose[TensorContract[TensorProduct[y, y], {{1, 3}}], {2, 1}];     TensorReduce[t1]     TensorReduce[t2]          (* Output: *)     (* t1 -> TensorContract[y ⊗ y, {{1, 3}}] *)     (* t2 -> TensorTranspose[TensorContract[y ⊗ y, {{1, 3}}], {2, 1}] *)      Shouldn't they be brought into the same form? Thank you!


title: Graph stories, 3-d volumes

text: I saw a lesson plan that had students filling different shaped bottles at a constant rate. The idea was to graph height vs. time to show the students how different shapes would produce different graphs, and especially the idea that most bottles would not produce a linear height vs. time function. Would it be possible to "design" a bottle as a 3-d shape in Mathematica, and then use integration to animate filling it...?


title: How to solve a complicated equation system

text: I am trying to solve the equation system `eq1==eq2` for $\sigma1$ and $\sigma2$ where `eq1` and `eq2` are functions of 5 positive real variables as defined below:               eq1=(2 Sqrt[5 + 4 x1 + x1^2 + 2 y1 + y1^2])/(Sqrt[5] (2 + x1) (1 +y1))          eq2= (2 (1 + s) Sqrt[5 + 5 s^2 + 4 x1 \[Sigma]1 + x1^2 \[Sigma]1^2 + 2 y1 \[Sigma]2 + y1^2 \[Sigma]2^2 + 2 s (5 + 2 x1 \[Sigma]1 + y1 \[Sigma]2)])/(Sqrt[5] (2 + 2 s + x1 \[Sigma]1) (1 + s + y1 \[Sigma]2))      I am interested only in those solutions which are only a function of variable `s`. As a matter of fact I can simply verify that `s+1` is a solution:               eq2 /. {\[Sigma]1 -> 1 + s, \[Sigma]2 -> 1 + s} //FullSimplify[#, s > 0] &      however, I have not been able to find this solution using Mathematica. I have tried the following               Reduce[eq1 == eq2 && 0 < x1 && 0 < y1 && 0 < \[Sigma]1 &&0 < \[Sigma]2 && 0 < s, {\[Sigma]1, \[Sigma]2},Reals] // FullSimplify      and               Solve[eq1 == eq2, {\[Sigma]1, \[Sigma]2}, Reals] // FullSimplify      but none of these result in the simple solution `s+1`. My question is what is the right approach to solving this kind of equations in Mathematica.


title: Improving the speed/efficiency of multiple (finite range) convolutions for a causal response plot

text: So I am looking at modelling the response of a system that is excited by multiple pulses over a period of time. The way to find the response at time t is to take the convolution between the impulse response (response of the system to an infinitely short pulse) and the multiple excitation pulses over the range [0, t]: $$Response(t) = \int_0^t \\! Excitations(\tau) ImpResp(t-\tau) \, \mathrm{d}\tau$$ So if I wanted to plot this as a function of time I would need to evaluate that integral for every point that I wanted to put on the plot and that is clearly very expensive. My code at the moment is pretty simple, I define my gaussian pulses and the impulse response and then define a function which takes the convolution of those over [0, t] and then I plot my convolution as a function of t:               Gaussian[amp_, mean_, std_, t_] := amp*Exp[-(t - mean)^2/(2*std^2)]          GaWindow[amp_, mean_, std_, t_, w_] := Piecewise[{{Gaussian[amp, mean, std, t], mean - w <= t <= mean + w}}]          imp[t_] := 100*Exp[-t/0.01]          twopulse[t_] := GaWindow[1, 0.1, 0.0008, t, 0.008] + GaWindow[1, 0.15, 0.0008, t, 0.008]          conv[t_] := Integrate[twopulse[s]*imp[t-s],{s,0,t}]          Plot[conv[t], {t, 0.09, 0.18}, PlotRange -> All, PlotStyle -> Green]      I tried the built-in convolution function but it can only perform the convolution from negative infinity to positive infinity and when combined with step functions (to make it a function of time) it offers no speed benefits over the regular integral that I perform above. I have had a go at discretized versions of the functions and using `ListConvolve`, although I was unable to recreate the correct plots from the working code I have above. Using the `PlotPoints` and `MaxRecursion` arguments for the plot, I can increase the speed whilst sacrificing the quality of the graph, but it's nicer not to have to resort to that. There seems to be a lot of information about optimization for infinite-range convolutions, but none that I have had the ability to apply to this multiple finite-range convolutions problem. Thanks in advance for any suggestions on how I could improve the speed/efficiency of this.


title: Calculate support of given wavelet

text: I am calculating approximations using wavelets but outside the multi resolution analysis framework; particularly, I am not using the built-in wavelet transforms. Still, I need to calculate coefficients and therefore I am wondering how to calculate the support of a given _wave_ in order to know where to start and stop calculating coefficients for `WaveletPhi[wave]` and `WaveletPsi[wave]` for a given resolution level. Therefore, I need to know the support for a given wavelet. I suspect that I could use `WaveletFilterCoefficients[wave,"PrimalHighpass"]` and, similarly for `"PrimalLowpass"`; but it is just a hunch, not sure how. Basically, I am after something along the lines of: `WaveletSupport[wave]` -> {a,b} support of given wavelet (For the moment just orthogonal wavelets, not biorthogonal). Thanks.


title: how to efficiently apply function to all pairs of a set (and collect the results)

text: To build a graph, I need to apply a function `f[a_, b_]` to all pairs of a list (3500 elements). The function itself returns a link `{a <-> b}` if a particular relation holds - I collect all the results into a list and use it as input to `Graph[]`. The question is: is there an efficient and elegant way to do this? I've tried two ways: a recursive method and a (similar) iterative method. The former went over the usual recursion limits, the latter was slow and (I believe) not the optimal way to do it. Both of these performed by applying `f[]` to the `First[]` element vs. the 2nd, 3rd, ...`Last[]` elements, and collecting the results. Then I'd remove the `First[]` from the list, and repeat - doing n*(n-1)/2 evaluations of `f[]`. This many evaluations is required, but I definitely do not have a clean, functional implementation. So, in short, if this can be turned into an efficient 1-liner, instead of a loop, please do let me know! Thanks in advance.


title: Plotting the simulation of Brownian Motions with multiple thresholds

text: I have the following problem: I have a watermark in this model where not only the mean of all stochastic processes is calculated, but also the mean of those processes which remain beyond a given threshold/ watermark. Now, I want to introduce a second watermark which is lower than the first one. And I also want to calculate and display the mean of the stochastic processes which are beyond the second watermark. My code so far is:               Manipulate[SeedRandom[seed]; meanvector := Mean[assets];       assets = Table[        RandomFunction[          GeometricBrownianMotionProcess[μ, σ, S0], {0, time,            0.1}]["Path"], {P}];       processes = Transpose[assets[[#]]][[2]] & /@ Range@Length[assets];      processes2 = Transpose[assets[[#]]][[2]] & /@ Range@Length[assets];       processesposition =        Flatten[Position[         Min[processes[[#]]] & /@           Range@Length[assets], _?(# > watermark &)]];      processesposition2 =        Flatten[Position[         Min[processes2[[#]]] & /@           Range@Length[assets], _?(# > watermark2 &)]];     watermarkedassets = assets[[#]] & /@ processesposition;       watermarkedmeanvector = Mean[watermarkedassets];      watermarkedassets2 = assets[[#]] & /@ processesposition2;       watermarkedmeanvector2 = Mean[watermarkedassets2];           G1 := ListLogPlot[assets, GridLines -> {{}, {watermark}},          GridLinesStyle -> {Directive[Green, Thick]}, Joined -> True,          AxesLabel -> {"Time", "St"},          PlotLabel ->           Style["Forecasted Stock Price\n (Brownian Motion)", Bold],          PlotRange -> All, PlotStyle -> Directive[{Thin, Lighter @ Gray}]];           G2 := ListLogPlot[{meanvector, watermarkedmeanvector,           watermarkedmeanvector2, GridLines -> {{}, {watermark2}},           GridLinesStyle -> {Directive[Orange, Thick]}}, Joined -> True,          PlotStyle -> {Directive[{Thick, Darker @ Red}],            Directive[{Thick, Darker @ Blue}],            Directive[{Thick, Darker @ Pink}]}];                Show[G1, G2], {{S0, 100, "Initial Stock Value"}, 1, 500, 0.5,        Appearance -> "Labeled"}, {{μ, 0.08, "Drift μ"}, 0.01, 0.2,        0.01, Appearance -> "Labeled"}, {{σ, 0.2,         "Standard Deviation σ"}, 0.01, 1, 0.05,        Appearance -> "Labeled"}, {{P, 6, "Paths"}, 1, 20, 1,        Appearance -> "Labeled"}, {{time, 10, "Time t"}, 1, 20, 1,        Appearance -> "Labeled"}, {{watermark, 75, "Watermark"}, 1, 500,        Appearance -> "Labeled"},      {{watermark2, 70, "Watermark2"}, 1, 500, Appearance -> "Labeled"},      {{seed, 1, "New Random Case"}, 1, 100, 1},       Button["Set Initial Values", {S0 = 100, μ = 0.08, σ =          0.20, P = 6, time = 10, watermark = 75, watermark2 = 70},        ImageSize -> 150],           Dynamic["Mean watermarked processes = " <>         ToString[watermarkedmeanvector[[-1]][[2]]]],      Dynamic["Mean watermarked2 processes = " <>         ToString[watermarkedmeanvector2[[-1]][[2]]]],       Dynamic["Mean of all processes = " <>         ToString[meanvector[[-1]][[2]]]], ControlPlacement -> Left]      Do you have any suggestions?


title: copy paste merging expressions

text: I ran a solve to evaluate a few linear equations,               Solve[{some eqns},{A0,B0,c0,d0,e0}]       and then in the output I got:               {{A0-> stuff+ 1/rho F (stuff) , B0->..,...,e0->..}}.       Now when when I selected, copied and pasted the expression I got for _A0_. I wound up getting :               stuff+ 1/rhoF (stuff)      My subsequent `ContourPlot` was giving me nothing and it took me the longest time to notice that two of my variables, $\rho$ and `F` had been made into a new variable `rhoF` somehow during the copy paste process. I've found this to be a bit unnerving. Is there some way to guarantee that this never happens? I've been doing `ctrl`-`C` and `ctrl`-`v`. Should I do "copy as" and pick one of the options to avoid this formatting issue. Right now I don't have two variables that might merge together to become an pre- existing variable, but if for example **rhoF** had indeed been something I had defined earlier, I would never have found out about this error and I would've been in deep trouble doing some corrupted analysis. Any help will be greatly appreciated. EDIT: I tried the replace rule /. but I still have the same problem. This is what I have actually done:               {{A0, B0, L0, M0, c0, S}} = {A0, B0, L0, M0, c0, S} /. Solve[{     A0*(H0D)^(k1) +  B0*(H0D)^(k2) + (delta/(delta + rho - r))*(H0D)      + u/rho-  c0*F/rho ==-CF,     k1*A0*(H0D)^(k1 - 1) + k2*B0*(H0D)^(k2 - 1) == -((delta)/(delta + rho - r)),     L0*(H0S)^(k1) + M0*(H0S)^(k2) + c0*F/r == F,     L0*(H0D)^(k1) + M0*(H0D)^k2 + c0*F/r == H0D - CFL,     L0*H1R^(k1) + M0*H1R^k2 + c0*F/r -CRL == H1R - CFL + gamma*S,     A0*(H1R)^(k1) + B0*(H1R)^(k2) + (delta/(delta + rho - r))*(H1R) +      u/rho - c0*F/rho -CR == -CF + (1 - gamma)*S}, {A0, B0, L0, M0, c0, S}]      and then when I tried to get the value for `shift`+`enter` A0, again rho and F were combined in line 16 to form rhoF. I tried to boldface it but I guess boldface does not work inside the code format. Please help!               -(-1/(delta - r + rho)        delta (-H0D^           k2 (-(-(-1 + gamma) H0S^k2 H1R^k1 + (-1 + gamma) H0S^k1 H1R^                 k2) (-((F H0D^k2)/r) + (F H0S^k2)/               r) + (-H0D^k2 H0S^k1 + H0D^k1 H0S^k2) ((               F (-1 + gamma) H1R^k2)/r +                H0S^k2 (-((F (-1 + gamma))/r) + (F gamma)/rho))) + (         F gamma H0S^k2 (-H0D^k2 H0S^k1 + H0D^k1 H0S^k2) H1R^k2)/rho) +      H0D^(-1 + k2)       k2 (-(-(-(-1 + gamma) H0S^k2 H1R^k1 + (-1 + gamma) H0S^k1 H1R^                 k2) (-((F H0D^k2)/r) + (F H0S^k2)/               r) + (-H0D^k2 H0S^k1 + H0D^k1 H0S^k2) ((               F (-1 + gamma) H1R^k2)/r +                H0S^k2 (-((F (-1 + gamma))/r) + (F gamma)/rho))) (CF + (           delta H0D)/(delta - r + rho) + u/rho) -         **1/rhoF** (-(F H0D^k2 + (CFL - H0D) H0S^k2) (-(-1 + gamma) H0S^               k2 H1R^k1 + (-1 + gamma) H0S^k1 H1R^k2) + (-H0D^k2 H0S^               k1 + H0D^k1 H0S^k2) (-F (-1 + gamma) H1R^k2 +               H0S^k2 (-(-1 + gamma) (CFL - CRL - H1R) -                  gamma (CF - CR + (delta H1R)/(delta - r + rho) + u/                    rho))))))/(H0D^(-1 + k2)       k2 (-H0D^          k1 (-(-(-1 + gamma) H0S^k2 H1R^k1 + (-1 + gamma) H0S^k1 H1R^                k2) (-((F H0D^k2)/r) + (F H0S^k2)/              r) + (-H0D^k2 H0S^k1 + H0D^k1 H0S^k2) ((              F (-1 + gamma) H1R^k2)/r +               H0S^k2 (-((F (-1 + gamma))/r) + (F gamma)/rho))) + (        F gamma H0S^k2 (-H0D^k2 H0S^k1 + H0D^k1 H0S^k2) H1R^k1)/rho) -      H0D^(-1 + k1)       k1 (-H0D^          k2 (-(-(-1 + gamma) H0S^k2 H1R^k1 + (-1 + gamma) H0S^k1 H1R^                k2) (-((F H0D^k2)/r) + (F H0S^k2)/              r) + (-H0D^k2 H0S^k1 + H0D^k1 H0S^k2) ((              F (-1 + gamma) H1R^k2)/r +               H0S^k2 (-((F (-1 + gamma))/r) + (F gamma)/rho))) + (        F gamma H0S^k2 (-H0D^k2 H0S^k1 + H0D^k1 H0S^k2) H1R^k2)/rho))


title: Solve system of equations related to perspective projection

text: I'm trying to solve system of equations. I have 4 points before perspective projection and after and I whant to obtain matrix of perspective projection $m_{i,j}$ ($x,y,u,v$ are known , $m_{i,j}$ unknown) $u_{1}= (m_{13} + m_{11}*x_{1} + m_{12}*y_{1})/(1 + m_{31}*x_{1} + m_{32}*y_{1})$ $v_{1}= (m_{23} + m_{21}*x_{1} + m_{22}*y_{1})/(1 + m_{31}*x_{1} + m_{32}*y_{1})$ $u_{2}= (m_{13} + m_{11}*x_{2} + m_{12}*y_{2})/(1 + m_{31}*x_{2} + m_{32}*y_{2})$ $v_{2}= (m_{23} + m_{21}*x_{2} + m_{22}*y_{2})/(1 + m_{31}*x_{2} + m_{32}*y_{2})$ $u_{3}= (m_{13} + m_{11}*x_{3} + m_{12}*y_{3})/(1 + m_{31}*x_{3} + m_{32}*y_{3})$ $v_{3}= (m_{23} + m_{21}*x_{3} + m_{22}*y_{3})/(1 + m_{31}*x_{3} + m_{32}*y_{3})$ $u_{4}= (m_{13} + m_{11}*x_{4} + m_{12}*y_{4})/(1 + m_{31}*x_{4} + m_{32}*y_{4})$ $v_{4}= (m_{23} + m_{21}*x_{4} + m_{22}*y_{4})/(1 + m_{31}*x_{4} + m_{32}*y_{4})$ I tried `Solve` but it seems to work infinite time. my input in mathematica               Solve[u1== (m13 + m11*x1 + m12*y1)/(1 + m31*x1 + m32*y1)&&     v1== (m23 + m21*x1 + m22*y1)/(1 + m31*x1 + m32*y1)&&     u2== (m13 + m11*x2 + m12*y2)/(1 + m31*x2 + m32*y2)&&     v2== (m23 + m21*x2 + m22*y2)/(1 + m31*x2 + m32*y2)&&     u3== (m13 + m11*x3 + m12*y3)/(1 + m31*x3 + m32*y3)&&     v3== (m23 + m21*x3 + m22*y3)/(1 + m31*x3 + m32*y3)&&     u4== (m13 + m11*x4 + m12*y4)/(1 + m31*x4 + m32*y4)&&     v4== (m23 + m21*x4 + m22*y4)/(1 + m31*x4 + m32*y4),{m11,m12,m13,m21,m22,m23,m31,m32}]      **UPDATE:** another question rises when I try to solve the same equation but when $x,y$ not given, but I have some restrictions that give me more equations. What I trying to do: I have points $u,v$ (distorted points) and I don't have original points $x,y$ but I can foto the same segment in different places and I know that distance $dx=x_{2}-x_{1}$ and $dy=y_{2}-y_{1}$ is always the same,so I want to reconstruct perspective transform that I don't know. my input in mathematica               Solve[(m31 x1 + m32 y1 + 1) u1 == (m11 x1 + m12 y1 + m13) &&       (m31 x1 + m32 y1 + 1) v1 == (m21 x1 + m22 y1 + m23) &&       (m31 x2 + m32 y2 + 1) u2 == (m11 x2 + m12 y2 + m13) &&       (m31 x2 + m32 y2 + 1) v2 == (m21 x2 + m22 y2 + m23) &&       (m31 x3 + m32 y3 + 1) u3 == (m11 x3 + m12 y3 + m13) &&       (m31 x3 + m32 y3 + 1) v3 == (m21 x3 + m22 y3 + m23) &&       (m31 x4 + m32 y4 + 1) u4 == (m11 x4 + m12 y4 + m13) &&       (m31 x4 + m32 y4 + 1) v4 == (m21 x4 + m22 y4 + m23) &&       (m31 x5 + m32 y5 + 1) u5 == (m11 x5 + m12 y5 + m13) &&       (m31 x5 + m32 y5 + 1) v5 == (m21 x5 + m22 y5 + m23) &&       (m31 x6 + m32 y6 + 1) u6 == (m11 x6 + m12 y6 + m13) &&       (m31 x6 + m32 y6 + 1) v6 == (m21 x6 + m22 y6 + m23) &&       (m31 x7 + m32 y7 + 1) u7 == (m11 x7 + m12 y7 + m13) &&       (m31 x7 + m32 y7 + 1) v7 == (m21 x7 + m22 y7 + m23) &&       (m31 x8 + m32 y8 + 1) u8 == (m11 x8 + m12 y8 + m13) &&       (m31 x8 + m32 y8 + 1) v8 == (m21 x8 + m22 y8 + m23) &&       (m31 x9 + m32 y9 + 1) u9 == (m11 x9 + m12 y9 + m13) &&       (m31 x9 + m32 y9 + 1) v9 == (m21 x9 + m22 y9 + m23) &&       (m31 x10 + m32 y10 + 1) u10 == (m11 x10 + m12 y10 + m13) &&       (m31 x10 + m32 y10 + 1) v10 == (m21 x10 + m22 y10 + m23) &&       dx == x2 - x1 &&       dy == y2 - y1 &&       dx == x4 - x3 &&       dy == y4 - y3 &&       dx == x6 - x5 &&       dy == y6 - y5 &&       dx == x8 - x7 &&       dy == y8 - y7 &&       dx == x10 - x9 &&       dy == y10 - y9      , {m11, m12, m13, m21, m22, m23, m31, m32}]      but Mathematica give me `{}` just trivial solution.what is wrong? maybe it's possible to automatically rewrite system of equations as linear system $AX=B$ ?


title: Strange behaviour of Reduce for Mod[x,1]

text: For every integer $x$ the equation `Mod[x, 1] == 0` holds. While               Simplify[Mod[x, 1] == 0, Element[x,Integers]]       gives `True`,               Reduce[Mod[x, 1] == 0, x, Integers]       gives `False`. Why?


title: Grabbing a number of characters around a string pattern

text: If I have some string data:               text = StringTake[ExampleData[{"Text", "DeclarationOfIndependence"}], 400]      > "When in the Course of human events, it becomes necessary for one people to > dissolve the political bands which have connected them with another, and to > assume, among the Powers of the earth, the separate and equal station to > which the Laws of Nature and of Nature's God entitle them, a decent respect > to the opinions of mankind requires that they should declare the causes > which impel them to the sepa" This is what I use to find a specific pattern inside and grab a bit more data around it:               StringCases[text, (y__ /;StringLength[y] == 4) ~~ "entitle" ~~ x__ /;StringLength[x] == 5]      > >     {"God entitle them"} >   **Are there any alternatives, desirably neater ones? Maybe something with regular expressions?**


title: Help with NDSolveValue

text: I have a small problem solving Schrödinger equation. Here's setup:               nm=10^-9;     R = 50 nm;     r = 25 nm;     d = 30 nm;     k = 1 nm^-1;     U0 = 1.6*10^-19;     m = 10^-31;     h = 5 nm;     hbar = 6.67 10^-34;               usol=NDSolveValue[{1/\[Rho] \!\(     \*SubscriptBox[\(\[PartialD]\), \(\[Rho]\)]\[Rho]\)\!\(     \*SubscriptBox[\(\[PartialD]\), \(\[Rho]\)]\(     \(\*SubscriptBox[\(\[CapitalPsi]\), \(\[Alpha]\)]\)[\[Rho], z]\)\)+\!\(     \*SubscriptBox[\(\[PartialD]\), \(z, z\)]\(     \(\*SubscriptBox[\(\[CapitalPsi]\), \(\[Alpha]\)]\)[\[Rho], z]\)\)+(2*m*E[\    [Rho],z])/hbar^2 Subscript[\[CapitalPsi], \[Alpha]][\[Rho],z]==0,1/\[Rho] \!\(     \*SubscriptBox[\(\[PartialD]\), \(\[Rho]\)]\[Rho]\)\!\(     \*SubscriptBox[\(\[PartialD]\), \(\[Rho]\)]\(     \(\*SubscriptBox[\(\[CapitalPsi]\), \(\[Beta]\)]\)[\[Rho], z]\)\)+\!\(     \*SubscriptBox[\(\[PartialD]\), \(z, z\)]\(     \(\*SubscriptBox[\(\[CapitalPsi]\), \(\[Beta]\)]\)[\[Rho], z]\)\)+(2*m*(U0- E[\    [Rho],z]))/hbar^2 Subscript[\[CapitalPsi], \[Beta]][\[Rho],z]==0,Subscript[\[CapitalPsi],     \[Beta]][\[Rho],h/2]==Subscript[\[CapitalPsi], \[Alpha]][\[Rho],h/2],Subscript[\    [CapitalPsi], \[Beta]][\[Rho],-h/2]==Subscript[\[CapitalPsi], \[Alpha]][\[Rho],-h/2],\!\(     \*SubscriptBox[\(\[PartialD]\), \(\[Rho]\)]\(     \(\*SubscriptBox[\(\[CapitalPsi]\), \(\[Beta]\)]\)[\[Rho], h/2]\)\)==\!\(     \*SubscriptBox[\(\[PartialD]\), \(\[Rho]\)]\(     \(\*SubscriptBox[\(\[CapitalPsi]\), \(\[Alpha]\)]\)[\[Rho], h/2]\)\),\!\(     \*SubscriptBox[\(\[PartialD]\), \(\[Rho]\)]\(     \(\*SubscriptBox[\(\[CapitalPsi]\), \(\[Beta]\)]\)[\[Rho], \(-h\)/2]\)\)==\!\(     \*SubscriptBox[\(\[PartialD]\), \(\[Rho]\)]\(     \(\*SubscriptBox[\(\[CapitalPsi]\), \(\[Alpha]\)]\)[\[Rho], \(-h\)/2]\)\),Subscript[\    [CapitalPsi], \[Beta]][R,z]==Subscript[\[CapitalPsi], \[Alpha]][R,z],\!\(     \*SubscriptBox[\(\[PartialD]\), \(z\)]\(     \(\*SubscriptBox[\(\[CapitalPsi]\), \(\[Beta]\)]\)[R, z]\)\)==\!\(     \*SubscriptBox[\(\[PartialD]\), \(z\)]\(     \(\*SubscriptBox[\(\[CapitalPsi]\), \(\[Alpha]\)]\)[R, z]\)\)},{Subscript[\    [CapitalPsi], \[Alpha]],Subscript[\[CapitalPsi], \[Beta]]},{\[Rho],0,25nm},{z,-h/2,h/2}]      And in suitable LaTex format: $$ \text{usol}=\text{NDSolveValue}\left[\left\\{\frac{\partial ^2\Psi _{\alpha }(\rho ,z)}{\partial z\, \partial z}+\frac{(2 m e(\rho ,z)) \Psi _{\alpha }(\rho ,z)}{\text{hbar}^2}+\frac{\frac{\partial \rho }{\partial \rho } \frac{\partial \Psi _{\alpha }(\rho ,z)}{\partial \rho }}{\rho }=0,\frac{\partial ^2\Psi _{\beta }(\rho ,z)}{\partial z\, \partial z}+\frac{(2 m (\text{U0}-e(\rho ,z))) \Psi _{\beta }(\rho ,z)}{\text{hbar}^2}+\frac{\frac{\partial \rho }{\partial \rho } \frac{\partial \Psi _{\beta }(\rho ,z)}{\partial \rho }}{\rho }=0,\Psi _{\beta }\left(\rho ,\frac{h}{2}\right)=\Psi _{\alpha }\left(\rho ,\frac{h}{2}\right),\Psi _{\beta }\left(\rho ,-\frac{h}{2}\right)=\Psi _{\alpha }\left(\rho ,-\frac{h}{2}\right),\frac{\partial }{\partial \rho }\Psi _{\beta }\left(\rho ,\frac{h}{2}\right)=\frac{\partial }{\partial \rho }\Psi _{\alpha }\left(\rho ,\frac{h}{2}\right),\frac{\partial }{\partial \rho }\Psi _{\beta }\left(\rho ,-\frac{h}{2}\right)=\frac{\partial }{\partial \rho }\Psi _{\alpha }\left(\rho ,-\frac{h}{2}\right),\Psi _{\beta }(R,z)=\Psi _{\alpha }(R,z),\frac{\partial \Psi _{\beta }(R,z)}{\partial z}=\frac{\partial \Psi _{\alpha }(R,z)}{\partial z}\right\\},\left\\{\Psi _{\alpha },\Psi _{\beta }\right\\},\\{\rho ,0,25 \text{nm}\\},\left\\{z,-\frac{h}{2},\frac{h}{2}\right\\}\right] $$


title: How to find major color in a picture?

text: I want to find the major color (the color which appears most often) in a picture and do some analysis later. For example, if I have this picture: ![my picture](http://i.imgur.com/Wd9lPRa.jpg) What I want to do is find out that gray, red, black, and yellow are major colors in the picture. I thought this could be done by getting a histogram with the X-axis as colors (red, blue, yellow, etc.), and the Y-axis as proportions in the image. And once I get that histogram, I can retrieve the highest color by comparing the Y-values. I read some examples of `ImageHistogram`, `ImageLevels` and some other color- related functions, but I still don't know how to do this. Any idea is welcome.


title: How do assign an interval of values to a variable in order to use them in a function?

text: From my code (below) I have K1 and K2 set to zero in order to test this numerical method. However, K1 is on an interval from 0 to 32, and K2 is on an interval from 0 to 8. I would like to know if there is a way to set these intervals to the associated variables, so that it will run the program for the interval itself. That way I don't have to run a combination of 32 or 8 separate calculations, etc. Here is my code pasted directly from the nb.               Subscript[x, 0] := 0; Subscript[y, 0] := 1;     Subscript[u, 3] := 0; h := 0.1;     Subscript[K, 1] := 0; Subscript[K, 2] := 0     x[n_] := (Subscript[x, n] = Subscript[x, 0] + n h);     y[n_] := (Subscript[y, n ] = Subscript[y, 0] + n h);     Table[x[n], {n, 0, 5}];     Table[y[n], {n, 0, 5}]          f[n_] := (Subscript[f,          n] = -Subscript[K, 1] Subscript[x,            n] + -Subscript[K, 2] Subscript[y, n]);     Table[f[n], {n, 0, 5}]          System = {Subscript[u,          0] == {1/           80 (-27 h Subscript[f, 0] - 102 h Subscript[f, 1] -              72 h Subscript[f, 2] - 42 h Subscript[f, 3] +              3 h Subscript[f, 4] + 80 Subscript[u, 3])},         Subscript[u,          1] == {1/           90 (h Subscript[f, 0] - 34 h Subscript[f, 1] -              114 h Subscript[f, 2] - 34 h Subscript[f, 3] +              h Subscript[f, 4] + 90 Subscript[u, 3])},         Subscript[u,          2] == {1/           720 (-11 h Subscript[f, 0] + 74 h Subscript[f, 1] -              456 h Subscript[f, 2] - 346 h Subscript[f, 3] +              19 h Subscript[f, 4] + 720 Subscript[u, 3])},         Subscript[u,          4] == {1/           720 (-19 h Subscript[f, 0] + 106 h Subscript[f, 1] -              264 h Subscript[f, 2] + 646 h Subscript[f, 3] +              251 h Subscript[f, 4] + 720 Subscript[u, 3])},         Subscript[u,          5] == {1/           90 (29 h Subscript[f, 0] - 146 h Subscript[f, 1] +              294 h Subscript[f, 2] - 266 h Subscript[f, 3] +              269 h Subscript[f, 4] + 90 Subscript[u, 3])}};          variables = {Subscript[u, 0], Subscript[u, 1], Subscript[u, 2],         Subscript[u, 4], Subscript[u, 5]};          Solve[System, variables]      ![enter image description here](http://i.stack.imgur.com/1Lvg5.png)


title: TableDirection in TableForm

text: ![enter image description here](http://i.stack.imgur.com/4bxGD.jpg) I got confused about what does "the outermost dimension" and "the first dimension" mean in the document I snipped. Does it mean row or column?


title: Axes Origin & Labels in 3D Plot

text: I'm looking for a way to have the axes at the origin in a 3D plot and to label the (x,y,z) axes in the usual way---with x near the end of the drawn portion of the x axis, y near the end of the drawn portion of the y axis, etc. I've tried               Plot3D[x^2 + y^2 + 3, {x, -3, 3}, {y, -3, 3},            AxesOrigin -> {0, 0, 0}, PlotRange -> {-1, 20}, AxesLabel -> {x, y, z}]      which works well for the axes position but horribly for the labeling. (The labels appear all together near the origin; it is not at all clear which axis is associated with which label.) Any suggestions?


title: MatrixPlot for DFT in black and white with ContourLabel

text: I have several data files such as this:               {{0, 2.86088, 4.44366, 50.9516, 3.26578, 3.76921, 10.2211}, {0.382102,        0.399499, 0.633217, 0.458334, 0.772598, 1.04943,        0.245786}, {2.17053, 0.753159, 1.57424, 0.378372, 0.82554, 0.651859,        0.571577}, {50.5039, 3.35749, 1.70239, 0.205699, 2.27276, 1.42459,        7.90045}, {1.47175, 0.712629, 0.842982, 0.220806, 0.294048, 0.21267,        0.166509}, {0.814432, 1.12644, 0.729741, 0.788745, 0.183342,        0.248011, 0.180827}, {10.4399, 1.53087, 1.52872, 8.1604, 0.480033,        0.538012, 1.29091}}      These are discrete fourier transform frequency values. When I plot them with `MatrixPlot` on **mathematica 8.0** , I get this: ![enter image description here](http://i.stack.imgur.com/6TgPu.png) Now this is what I would like to do and I got the idea from reading about plotting with tooltips and the ContourLabel option in Mathematica:   1. I would like my `MatrixPlot` to be in black and white/monochrome. This is because I would like to include these plots in journal publications and save money over having color images (It's **$325 per color image** on _Physics of fluids_ for instance). I have tired the `ColorFunction->"Monochrome"` option with `MatrixPlot` and have also tried `ArrayPlot` to get black and white spots instead of the orange and yellow spots that I have.   2. Can I have an option like `ContourLabel` for `MatrixPlot` so that I can entirely circumvent having a color bar?   3. To those of you who have published with plots from Mathematica 8.0, what would you do?   4. I have access to Mathematica 8.0 right now and for convenience I would like to stick to that. I have tried to search around here but didn't find an answer that would suit my needs. Having said that, please feel free to yell at me if I didn't search hard enough!


title: Blank plot that shows up briefly when changing plot options

text: I wrote some code in _Mathematica_ to calculate and plot, in tw0 different ways, a function depending of two variables. But the plots are empty even if it takes a few minutes to evaluate the plot command. But the weirdest thing is that when I change an option of the plot when clicking on "plot style" for example, the plot appears briefly and then disappears again! Here is the code:               Vmax = Quantity[1, "Volt"]     L0 = Quantity[0.5 , "MicroHenry"]     C0 = Quantity[2, "PicoFarad"]     Zl = Quantity[100, "Ohm"]     tw = Quantity[0.5, "NanoSeconds"]     l = Quantity[1.2, "Meters"]     Z0 = UnitSimplify[Sqrt[L0/C0]]     Γ = (QuantityMagnitude[Zl] - QuantityMagnitude[Z0])/           (QuantityMagnitude[Zl] + QuantityMagnitude[Z0])     γ = UnitSimplify[Sqrt[C0*L0]]     U[t_] := QuantityMagnitude[        Vmax]*(UnitStep[t] - UnitStep[t - QuantityMagnitude[tw]*10^-9])     Us[s_] := FullSimplify[LaplaceTransform[U[t], t, s]]     Vs[z_, s_] :=        FullSimplify[         Us[s]*(Exp[-s*QuantityMagnitude[γ]*z] +           QuantityMagnitude[Γ]*          Exp[s*QuantityMagnitude[γ]*(z - 2*QuantityMagnitude[l])])/            (1 + QuantityMagnitude[Γ]*Exp[-2*s*QuantityMagnitude[γ]*QuantityMagnitude[l]])]     V2[z_, t_] :=        U[t - QuantityMagnitude[γ]*z] +          Sum[(-1)^(n - 1)*(QuantityMagnitude[Γ]^n*             U[t + QuantityMagnitude[γ]*                (z - 2*n*QuantityMagnitude[l])] -             QuantityMagnitude[Γ]^n*             U[t - QuantityMagnitude[γ]*                (z + 2*n*QuantityMagnitude[l])]),           {n, 1, Infinity}]     Plot3D[{V2[z, t]}, {t, 0, 5*10^-9}, {z, 0, 1.2}]     V1[z_, t_] := InverseLaplaceTransform[Vs[z, s], s, t]     Plot3D[{V1[z, t]}, {t, 0, 5*10^-9}, {z, 0, 1.2}]


title: MapThread to Spheres with various colours

text: I have these two lists               xyz={{1, 1, 1}, {1, 1, -1}, {1, -1, 1}, {1, -1, -1}, {-1, 1, 1}, {-1,        1, -1}, {-1, -1, 1}, {-1, -1, -1}}          color={GrayLevel[0.5], GrayLevel[0.5], RGBColor[0, 1, 0], GrayLevel[0.5],       GrayLevel[0.5], GrayLevel[0.5], GrayLevel[0.5], RGBColor[0, 1, 0]}      I need to use this function `Graphics3D[{*Green*, Sphere[]}]` to plot each sphere with coordinates from `xyz` list and colour from `col` list. by applying `MapThread[]`.


title: What can webmathematica do that CDF cannot do?

text: I've been reading a number of questions and answers on this site that deal with the various capabilities of CDF (computable document format). It seems like sometimes the answer is to make sure to use Enterprise CDF, because only Enterprise CDF supports data import, certain input fields, etc. Another common answer is to use webMathematica. The tone of the answers seems to suggest that webMathematica is much more permissive than CDF. I am wondering what webMathematica can do (what is allowed) that cannot be done with CDF. Why would a person use one vs. the other? **Update** : Regarding FreeCDF, EnterpriseCDF, and Player Pro, this is the most useful break down of what each provides that I have seen so far.


title: Controlling the time step in NDSolve?

text: I generally use NDSolve for stiff non linear partial differential equations of 4th order. I find that a BDF1 method generally does well to placate my beast of a PDE. I've also tried out `"MaxSteps"` to curtail my simulation to a certain number of time steps. I understand that BDF and other methods for stiff equations are adaptive time step methods and I notice that `"Fixed"` step is not a valid option for BDF at least. Is there any way I could solve stiff equations with a fixed time step? I realize that NDSolve knows best but it would give me more flexibility to play around with the wonderful options in NDSolve if there were a way to use fixed time steps. **> My references:** this and this **> This is how I tried using`"FixedStep"`:** `Method -> {"FixedStep", "Method" -> {"BDF", "MaxDifferenceOrder" -> 1}}` Obviously this was incorrect as `"BDF"` isn't a submethod.


title: Font changes itself automatically during typing after == symbol

text: NDSolve[ {y'[x]= -y[x], y[0]=1},y, {x,0,2} ] has no problem in typing, even if cannot run due to error of not using ==.                NDSolve[{y'[x] == ^-y[x], y[0] == ^1}, y, {x, 0, 2}]      This ODE works (without any ^) . A _minor_ bother is that the originally set font spontaneously changes to plain text all by itself at location of ^ immediately after == sign,that is not desired. How to stick to original font choice? What is it due to? EDIT: a screenshot of above highlighted line, Font changes from Cambria to plain text with font size change: ![AutoFontChange](http://i.stack.imgur.com/579PK.png)


title: Manipulate graphs in 3D

text: Is it possible to `Manipulate` `Graph`s (e.g. a `CompleteGraph[100, GraphLayout -> {"SpringElectricalEmbedding"}]` in _Mathematica_ 9 such that I can e.g. rotate it as 3D object and zoom in and out? If not, how else can one inspect large graphs without extra programming?


title: AccountingForm w/o significant figures

text: Basically I want to build a chart like something I would do in Excel. It should look like this: ![enter image description here](http://i.stack.imgur.com/BRKoP.png) Here is the formula I'm using and what I've done so far               a[r_, n_, d_] := (((1 + r)^n) - 1)/(1 - (1 + r)^-d)          TableForm[        Table[AccountingForm[a[r, 30, d], 3],              {r, .000000000001, .15, .01}, {d, 15, 40, 5}],        TableHeadings -> {               {"0%","1%","2%","3%","4%","5%","6%","7%","8%","9%","10%","11%","12%","13%","14%"},               {"15", "20", "25", "30", "35", "40"}          }]      This is the output I'm getting: ![enter image description here](http://i.stack.imgur.com/ELrNe.png) Basically all I want is the integer plus 2 decimal places. What am I missing? Is there a way to automatically generate the headings based on the changing value of r and d?


title: Does Mathematica on Mac OS use virtualization for certain functions?

text: I'm evaluating this code in _Mathematica_ 8.0.0 on **Mac OS X 10.6.8** :               Table[StringCases[TextRecognize[Binarize[Import[imgList[[i]]]]],        RegularExpression["[0.-9]*-[0.-9]*-[0.-9]*"]], {i, 1, 87}]      which finds every CAS registry number present in 87 GIFs. Looking at the Activity Monitor, I can see that _Mathematica_ calls `Tesseract.exe` and `GIF.exe` when working on the images. Are those processes being virtualized, or is their name simply misleading?


title: How do I calculate RSquared in Mathematica 9?

text: I imported data from an Excel package and used LinearModelFit to return a `FittedModel`:               FittedModel[6.90762 - 0.999573 x]      How do I now calculate the RSquared value for my data and this model? Similarly, I imported data from an Excel package and used `NonlinearModelFit` to return               FittedModel[1.0000321558268463` E^(-0.9990618380928935` time)]      How do I calculate RSquared for this as well?


title: Exploiting self-adjointness when changing basis

text: I am using _Mathematica_ to analyze a real, self-adjoint matrix $H$ of the size $32 \times 32$, which comes from a physics problem. In the picture there is also a matrix $Q$ which commutes with $H$. I would like to see what $Q$ looks like in the eigenbasis of $H$, and I run into some technical issues that I was hoping someone might be kind enough to resolve. To find an eigenbasis of $H$ is not difficult - the functions `Eigenvalues` and `Eigenvectors` work well enough. The next step is very simple in theory: combine the eigenvectors into a transition matrix $P$, and compute the matrix of $Q$ relative to the new basis as $Q' = P^{-1}Q P$. In practice, it seems that the computation of the inverse requires a lot of computation, which is time consuming now, and will probably become infeasible for larger $H$. After a moment's thought, I realized that the matters could greatly helped by the fact that $H$ is self-adjoint: it follows that it has an _orthonormal_ eigenbasis, for which computing the inverse amounts to computing the adjoint. This would solve the matters if $H$ had all eigenvalues _distinct_ (then $P$ mentioned above would already be self-adjoint, maybe up to re-scaling the rows), but this is not the case here. Hence the question: Given a self-adjoint matrix $H$, together with its eigenvectors, assuming that the eigenspaces are more than $1$-dimensional, how can I effectively compute the inverse matrix? (Alternatively: how else can I find the matrix form of $Q$ relative to the eigenbasis of $H$?)


title: Is there a function for nearest power of 2 in Mathematica like nextpow2 in MATLAB?

text: I am looking for something like nextpow2 in MATLAB like this: > P = nextpow2(A) returns the exponents for the smallest powers of two that > satisfy $2^P \geq\left|A\right|$.


title: Applying a function of several arguments to the rows of a matrix

text: I have a user-defined function which takes three vectors as input. Suppose that is like this:               f[a_, b_, u_] := Total[a*Total[u]^b]      Usually I have vectors for `a` and `b` but a matrix format for `u`. For example,               a = {1.5, 2, 1}     b = {-1, 1, 0.5}     u = {{1, 2, 0}, {1, 0, 1.5}, {2, 1, 1}}      which should give the result > {8.23205, 7.18114, 10.375} In other words, the function `f` should be applied to each row of `u`. I can do this using a `Do` loop, but I want to know how to do it using `Map` or other functional commands (but not `Table`).


title: Solving a differential equation with initial conditions

text: I want to get a solution to an ordinary differential equation with imposed initial conditions. I'm confused about why my following code doesn't work:               Remove["Global`*"]          eqn = {x g - x v[x] v'[x] - v[x]^2 == 0};     inicond = {v[0] == 0, v'[0] == 0};     eqnlist = Join[eqn, inicond];          DSolve[eqnlist, v[x], x]      > >     {} >   Can anyone help me?


title: How can I get the functionality of a command ReplaceAllList?

text: I'm trying to use ReplaceList to match subexpressions. I expected the command:               ReplaceList[{p, {p, p}}, {x_, y_} -> x y]      to output two results, equivalent to: `p {p, p}` and `{p, p p}`. That's because I expect the rule `{x_,y_}` to match both `{p,{p,p}}` and `{p,p}`. Only one result is output, equivalent to `p {p,p}`. I suppose that this is because `ReplaceAll`'s behavior of replacing all subexpressions is special, whereas the default `Replace` that `ReplaceList` must use, only matches against the first level of the rule. That's great, but how can I get the functionality I expect? I need this to apply to arbitrary levels of nesting. For example, I would expect it to turn `{p, {p, {p, p}}}` into               { p {p, {p, p}}, {p, p {p, p}}, {p, {p, p p}} }      (I'm trying to reproduce the work on page 781 of the New Kind of Science book, in which subexpressions of Nand tautologies are matched/replaced according to the rules on page 775).


title: Using LatticeData to fill a space with spheres in a face-centered cubic (fcc) lattice packing arrangement

text: I have a large sphere of radius $R_1$ which I would like to pack with $N$ smaller radius of radius $r_2<R_1$ arranged in a face-centered cubic (fcc) packing arrangement (i.e. Kepler's optimal sphere packing geometry). Is there a way for me to use Mathematica's built-in LatticeData functionality to accomplish this, perhaps with an after-the-fact pruning step? Can I do this for the other lattice types Mathematica has data for?


title: Double integral 0

text: I am trying to reproduce the results from a paper in Mathematica. This task involves $K$ double integrals of the form $$\int f(x,y)g(x)dx,$$ where $f(x,y)$ is a bivariate normal density with mean $(-4.08, -3.41)$ and diagonal covariance matrix with diagonal $(1/10,1/21)$, and $g(x)$ is a normal density with mean $\beta_0+\beta_1\xi$ and variance $\sigma_e^2$ (all of them known). I want to obtain this integral as a function of $\xi$.               Sigma = {{1/10, 0}, {0, 1/21}}              {β0, β1, σe} = \     {-2.3, 0.5, 0.0005}                        f[ξ_] :=       NIntegrate[       PDF[MultinormalDistribution[{-4.08, -3.41}, Sigma], {η, ξ}]*        PDF[NormalDistribution[β0 + β1*ξ, σe], \     η], {η, -∞, ∞}]             Plot[f[t], {t, -10, 10}]      This code returns a $0$ for all values of $\xi$, while the true value should not be $0$. How can I obtain this integral? What seems to be the problem? Is it the precision? Any ideas would be greatly appreciated. My impression so far is that the $\sigma_e$ is very small and therefore the densities involved in the integration are very concentrated. This makes difficult the automatic integration.


title: Are there any more time-efficient ways to solve a matrix equation than with SparseArray and LinearSolve?

text: I am trying to solve a matrix equation, with the matrix being tridiagonal. The problem I am having is that a message keeps appearing that I don't have enough memory. Here is the code:               n = 10109;(*matrix dimension*)          a = SparseArray[{Band[{1, 1}] -> -2, Band[{1, 2}] -> 1,Band[{2, 1}] -> 1}, {n, n}](*the tridiagonal matrix*)          f[x_] := Piecewise[{{x + 1, x <= 0}, {-x + 1, x > 0}}](*initial condition, just for constructing the right-hand side vector*)          g = Table[f[i], {i, -1 + 2/(n + 1), 1 - 2/(n + 1), 2/(n + 1)}];(*the vector*)          u = LinearSolve[a, g];(*the solution I need*)      Actualy what I need is only               Norm[u,1]      and               u[5055].      Any suggestions would be helpful. Thank you in advance.


title: Declaration of abstract matrices to perform series expansion on them

text: I would like to have abstract matrices M and S to get out the coefficients of matrix power series however it treats M and S as numbers even if i checked that M.S - S.M != 0. I attach my code below:               $Assumptions = {Element[M, Matrices[{3, 3}]], Element[S, Matrices[{3, 3}]]}     Series[Simplify[(1 - a*(M + S))^(-1)], {a, 0, 3}]      How can i cure this to get out proper result? Thanks in advance for reply.


title: How to put legends in a chart plot

text: How can I put a chart legend inside a bar chart? I tried `Placed[ ... ,{Right,Top}]`, but it didn't work. It works for `Plot`. However, it doesn't work for `BarChart`.


title: Mathematica does not understand (R^3)^(1/3) is the same as R

text: In the output from a calculation in mathematica stands `a/((R^3*c)^(1/3))`, with `c` and `a` constants and `R` the variable. Now I want to use the outputformula for a new calculation. But Mathematica does not understand that `(R^3)^(1/3)` is the same as `R`. So I don't get (correct) answers by using this formula. But when I replace `(R^3)^(1/3)` manually in the outputformula by `R`, then it works perfecty. My question is how I can manage that mathematica understands automatically `(R^3)^(1/3)`? I have already tried formulas like `Simplify`, `FullSimplify`, `Collect` and much more formulas like that.


title: FrameTicks given through Show does not work with LogLogPlot

text: This is similar to the closed topic: Frame ticks for a Log Log plot [closed]. Let me reuse (rm -rf)'s example here. FrameTicks given through Show does not appear if used with LogLogPlot:               Show[       LogLogPlot[x^2 + x^3, {x, 1, 100}, Frame -> True],       FrameTicks -> {{All, None}, {{10, 30, 75}, None}}     ]      This works though:               Show[       LogLogPlot[x^2 + x^3, {x, 1, 100}, Frame -> True],       FrameTicks -> {{All, None}, {{N@Log@#, #}& /@ {10, 30, 75}, None}}     ]      Is this a bug or an expected behaviour?


title: (Very) ill-behaved Piecewise Plot

text: I am interested in defining a function (with arguments: a symbol for a variable and a list of 6 points) that represents a quadratic interpolating spline of the points. Here is my attempt               f20[x_, P_, Q_, R_, S_, T_, U_] :=        InterpolatingPolynomial[{{{P[[1]]}, P[[2]], 0}, {{Q[[1]]},           Q[[2]]}}, {x}];     f21[x_, P_, Q_, R_, S_, T_, U_] :=        InterpolatingPolynomial[{{{Q[[1]]}, Q[[2]],           D[f20[x, P, Q, R, S, T, U], x] /. x -> Q[[1]]}, {{R[[1]]},           R[[2]]}}, {x}];     f22[x_, P_, Q_, R_, S_, T_, U_] :=        InterpolatingPolynomial[{{{R[[1]]}, R[[2]],           D[f21[x, P, Q, R, S, T, U], x] /. x -> R[[1]]}, {{S[[1]]},           S[[2]]}}, {x}];     f23[x_, P_, Q_, R_, S_, T_, U_] :=        InterpolatingPolynomial[{{{S[[1]]}, S[[2]],           D[f22[x, P, Q, R, S, T, U], x] /. x -> S[[1]]}, {{T[[1]]},           T[[2]]}}, {x}];     f24[x_, P_, Q_, R_, S_, T_, U_] :=        InterpolatingPolynomial[{{{T[[1]]}, T[[2]],           D[f23[x, P, Q, R, S, T, U], x] /. x -> T[[1]]}, {{U[[1]]},           U[[2]]}}, {x}];     Interp2[x_, P_, Q_, R_, S_, T_, U_] :=        Piecewise[{{f20[x, P, Q, R, S, T, U],           P[[1]] <= x <= Q[[1]]}, {f21[x, P, Q, R, S, T, U],           Q[[1]] < x <= R[[1]]}, {f22[x, P, Q, R, S, T, U],           R[[1]] < x <= S[[1]]}, {f23[x, P, Q, R, S, T, U],           S[[1]] < x <= T[[1]]}, {f24[x, P, Q, R, S, T, U],           T[[1]] < x <= U[[1]]}}];      Then I try to evaluate the function and plot it               Interp2[s, {1, 1}, {2, 3}, {3, 3}, {4, 4}, {5, 5}, {6, 3}]     Plot[Interp2[s, {1, 1}, {2, 3}, {3, 3}, {4, 4}, {5, 5}, {6, 3}], {s,        1, 6}, PlotRange -> Full]      The output is the following ( **problem 1** ) ![enter image description here](http://i.stack.imgur.com/i7Zjo.png) which seems very weird because the function is correct but the plot is not. If I manually edit the first output to plot the function (with the same code as the second line of the input), or if I use the code               Interp2[s, {1, 1}, {2, 3}, {3, 3}, {4, 4}, {5, 5}, {6, 3}]     Plot[%, {s, 1, 6}, PlotRange -> Full]      instead, I get this ( **problem 2** ) ![enter image description here](http://i.stack.imgur.com/qXtnv.png) Notably, the plot is discontinuous, but the discontinuity points are not always matching the extremal points of the intervals in the piecewise definition: the gap near s=4 is between s=4.1 and s=4.2. In this second case I tried various options of MaxRecursion and PerformanceGoal to obtain a better quality, with no different results as the one in the picture. I am interested in a solution for problem 1 (rather than 2), but any suggestion is very welcome. Thanks


title: How to select specific subvalues from a function definition

text: Consider:               h[1][tag1] = 1;     h[1][tag2] = 2;     h[2][tag1] = 3;     h[2][tag2] = 4;      Is there a fast way to obtain downvalues for only h[1], or h[2]? For example               DownValues[h[1]]      does not work, and neither               DownValues[h]      (OwnValues gives the same behavior).


title: workbench: how to extract a piece of code into a function

text: For example assume that the following code is given               f[x_, y_]:=        Block[{a, b},           a = Sin[x];           b = Cos[y];           c = a + b        ]      and I want to change it into (without doing too much typing myself)               prepareAB[x_, y_] := {Sin[x], Cos[y]};          f[x_, y_]:=        Block[{a, b},           {a, b} = prepareAB[x, y];           c = a + b        ]      Is this functionality available in workbench?


title: How to get rid of trailing string after using Convert?

text: Convert[0.05263, Percent] /. Percent -> "%"      I would like to remove the trailing "%" but if I put Percent->"" it concatenates a literal empty pair of quotes. Thanks. Edit: I should have explained it works well in the Mathematica interactive evaluator but not in an InputField where it will concatenate the said quotes.


title: Object differentiation in image

text: After purchasing a box of alphabet pasta for the kids, I wondered if there was way to extract the frequency of appearance of letters in the box by taken a sample and the analyzing the picture.               i = Import["http://i.imgur.com/qpFUSTo.jpg?1"];     a = Import["http://i.imgur.com/rHD21Gm.jpg"];     bwimg = Binarize@i; bwa = Binarize@a;     x = Table[        ImageCorrelate[bwimg, ImageRotate[bwa, i],          NormalizedSquaredEuclideanDistance], {i, 0, 141 Pi/72, Pi/72}];     y = Table[       Dilation[ColorNegate@Binarize[x[[i]], 0.07], DiskMatrix[50]], {i,         Length[x]}]; z =       Fold[ImageAdd, First@y, Rest@y]; HighlightImage[bwimg, z,       HighlightColor -> Lighter@Green];     HighlightImage[i, z, HighlightColor -> Lighter@Green]      The result was less than promising, as a) it is time consuming, and b) several letters were missed by the process. I marked with Red and Orange arrows several letters that were missed. ![enter image description here](http://i.stack.imgur.com/BUkut.jpg) Tried with the Binarize parameter (currently set at 0.07), but increasing it brought false positives into the mix. Thought about MorphologicalComponents, which is very fast, and if the Colorize option can differentiate the objects, maybe it could be used to extract each letter, then maybe ImageAlign and group together. But that is beyond my skillset. ![enter image description here](http://i.stack.imgur.com/KinvA.jpg) Any light on how to differentiate and tally the different letters would be appreciated.


title: How one can programmatically transform a text into Gothic, DoubleStruck, or something similar?

text: In the pieces of text created programmatically I would like to be able to fix that the text is done in one of the styles available in the special characters palette, such as Gothic. It may be useful in preparation of a demonstration or making a title of say, a panel and so on. Is it possible?


title: How to use more/less black textcolor in function of the value of numbers in a table?

text: A few weeks ago, I viewed in the Mathematica Documentation any page withmultiple examples using diferent styles dpending on the value of the number in position (i,j), but I can´t remember... and I can´t find it. How can I use BLACK color to Print numbers that are close to the maximun? and much light gray as much close it is to the minimum ?               a = {1, 3, 6, 3, 2};     b = {3, 2, 5, 6, 9};     c = {2, 7, 3, 1, 6};     TableForm[{a, b, c}]      In this case, 1,2,3 appear with light gray, and 9 with BLACK!!! I remember... in that page there was many examples. Can you help me?


title: Help wanted in evaluating an integral

text: Trying to evaluate an integral. To be specific, I'm trying to find the expectation value of $x^2$ for the ground state of hydrogen. Here is the code I used:               FullSimplify[       Integrate[x^2/(Pi*a^3) E^((-2 Sqrt[x^2 + y^2 + z^2])/a), {x,-Infinity, Infinity}]]      The odd part is it worked when I calculated $\left<x\right>$, i.e. just drop an $x$ from the first fraction.


title: How to set a rule in pattern matching to change a string from one form to another

text: I want to define a rule that will change a particular type of string to another form. For example:- a string having `R1~~"=C"~~"C"("OO|O")~~R2 -> R1~~"C"(O)~~"C"~~R2`


title: Controlling spacing of histograms in Histogram3D

text: I have five histograms, `hist1 = Histogram[data1, 20]`, to which I append `{1, 2, 3, 4, 5}` via `Data1 = Map[{#, 1} &, hist1]`, and then plot * * *  ![3DHistogram](http://i.stack.imgur.com/XAmoQ.jpg) * * *               Histogram3D[{Data1, Data2, Data3, Data4, Data5}, 10,        ChartLegends -> Etc, Boxed -> False,        FaceGrids -> {Bottom, Front, Left}, ChartStyle -> "Pastel",        Ticks -> {Automatic, None, Automatic},        AxesLabel -> {"x","y","z"}]      I cannot see how to control the width of the histograms (in the _y_ -direction). Right now there is a gap between the 1st and the 2nd, etc. What control am I missing?


title: Find a single max value

text: w[n_] := Expand[Sum[Binomial[n - k - 1, k]*(-1)^k*A^(n - 2*k - 1), {k, 0, n - 1}]]     f[x_, y_, z_] :=PolynomialRemainder[(w[z] - 1)*(w[y] - 1), (w[x] - 1), A]          For[i = 3, i < 450, i++,For[j = 3, j < 450, j++,For[k = 3, k < 450, k++,If[i < j < k,      Print[{i, j, k},       N[Max[FindInstance[{Abs[f[i, j, k]] - Abs[w[i] - 1]} == 0 &&           3 <= A, {A}]]] ]]] ]]      Above code gives max A for all each cases. My aim is to find max A for all cases. Q2: How can i reduce the time for above code? Thank you.


title: How to create a planar graph from a set of random points

text: **Question** Given a set of points in the plane, how can you create a planar graph in the standard graph representation of _Mathematica_ (version 9 or higher), from these points? **Background** A planar graph is a graph embedded in the plane in such a way that the edges intersect at vertices only. This is an example of a planar graph:               g = GridGraph[{3, 3}]      ![GridGraph](http://i.stack.imgur.com/KvH1H.jpg) It is stored in the standard _Mathematica_ representation for graphs. You can also draw a planar graph from a set of points in the plane with `ComputationalGeometry`PlanarGraphPlot`:               Needs["ComputationalGeometry`"]         pts = RandomReal[{0, 10}, {10, 2}]     PlanarGraphPlot[pts]      ![Delaunay triangulation of points](http://i.stack.imgur.com/MWlL2.jpg) However, the output is **not** in the standard representation for graphs.


title: Can you set up a remote kernel for computation and a local kernel for predictive interface?

text: I am able to launch remote kernels from my _Windows_ box to our _Linux_ cluster that   1. has the data I need and    2. the capacity to run analysis (numerous & speedy cores, spacious memory, etc.). Works great except for the fact that there's a bit of latency. That's not a huge deal given the cost of the calculations I run, but what kills me is the predictive interface. Any time _Mathematica_ tries to be helpful with the predictive interface functions, the latency kicks in, the program stops responding, and I have to wait for the remote kernel to return its results before any part of _Mathematica_ becomes responsive. Is there a way to peg the local kernel to user interface or predictive interface tasks and assign the remote kernel(s) to computation only?


title: Drawing a cuboid with rounded corners

text: I want to draw a cuboid with rounded corners，like this: ![enter image description here](http://i.stack.imgur.com/HA2el.jpg) RoundingRadius only works with `Rectangle` or `Framed`.I have no idea how to draw a cuboid with rounded corners. What are your ideas? Thanks.


title: Having trouble fitting data using NonlinearModelFit

text: I'm trying to fit               data = {{2002, 45000}, {2004, 90000}, {2005, 120000}, {2013, 211000}};      to an exponential function `a*Exp[b*x]+c` but Mathematica returns `FittedModel[0]` when I use:               NonlinearModelFit[data,a*Exp[b*x]+c,{a,b,c},x]      Any help would be gladly welcomed.


title: Why DSolve and NDSolve give different answer

text: Consider these code, which solve the same equation using `DSolve` and `NDSolve`, why do they give different answer? Which one is correct? I'm using version 9.01 on Mac.               sol1 = DSolve[        Thread[D[{y1[t], y2[t]},             t] == {{0, E^(2 I t)}, {-E^(I t), 0}}.{y1[t], y2[t]}]~         Join~{y1[0] == 0, y2[0] == 1}, {y1, y2}, t];     sol2 = NDSolve[        Thread[D[{y1[t], y2[t]},             t] == {{0, E^(2 I t)}, {-E^(I t), 0}}.{y1[t], y2[t]}]~         Join~{y1[0] == 0, y2[0] == 1}, {y1, y2}, {t, 0, 2 \[Pi]}];          Plot[{Re@(y1[t] /. sol1), Re@(y1[t] /. sol2)}, {t, 0, 2 \[Pi]}]      ![enter image description here](http://i.stack.imgur.com/lMRtA.png)


title: How could I expand this equation

text: How could I expand this equation `(0.837 + x^0.5 + x)^4.870` Neither               Expand[(0.837 + x^0.5 + x)^4.870]      nor               Series[(0.837 + x^0.5 + x)^4.870, {x, 0, 6}]      work.


title: How do I keep a random value associated with a locator point as points are added?

text: I have a `Manipulate` to which I am adding and removing `Locator` points (one of which is different from the others, though that is only context for this question):               lastP = {}; states = {};     setState[p_] := RandomReal[Abs[p[[1]]]];     Manipulate[With[{q = locs[[1]], p = Drop[locs, 1]},       If[Length[lastP] < Length[p], states = Append[states, setState[p[[-1]]]]];       If[Length[lastP] > Length[p], states = states[[Flatten[Position[lastP, #] & /@ p]]]];       lastP = p;       Graphics[{         Text[TableForm[MapThread[List, {p, states}]], {0, 0}],          Red, Table[Circle[q, i/30], {i, 3}],          Blue, Point[#] & /@ p}, PlotRange -> 2]],      Row[{        Button["Clear", {locs = {locs[[1]]}}, ImageSize -> 100,          Alignment -> {Center, Baseline}],        Button["Recalc", states = setState[#] & /@ Drop[locs, 1],          ImageSize -> 100, Alignment -> {Center, Baseline}]        }], {{locs, {{1, 1}}}, Locator, Appearance -> None,        LocatorAutoCreate -> 1}]      I need to associate with each of the `Locator` points in `p` a random value (according to some specified PDF that is a function of the point's coordinates, here using `setState` as an example) that is calculated and associated with the point _only when it is added or moved_ , but not when other points are added or moved. I would also like to have access to the association between this value and the point, so that I can adjust the display of each point according to that associated value (e.g. making those with values less than some threshold one color and those greater another). How can I (ideally without giving up on `Manipulate`) achieve this "stable" association of calculated values with `Locator` points? I've played with various approaches for hours, and, with help, I've gotten as far as getting what I want for adding and removing; but I expect there's some simpler approach that I'm missing, and I haven't managed to get _moving_ (i.e., updates to the calculated value associated with a point) working.


title: Solving a nonlinear, second order d.e. in Mathematica

text: I am trying to solve the following differential equation $$ s''(x) = \frac{8}{9}s(x) -2s^2(x) + s^3(x), $$ with boundary conditions $s(-30) = 4/3 $ and $s(30)=0$, in Mathematica by using the following code:               sol = NDSolve[{s''[x] == 8/9 s[x] - 2 s[x]^2 + s[x]^3, s[-30] == 4/3,      s[30] == 0}, s, {x, -30, 30}]     Plot[s[x] /. sol, {x, -30, 30}].      However, Mathematica gives me an infinite sequence of errors. Is it just my ignorance concerning the numerical solvability of this kind of nasty differential equations, or is there a way to let Mathematica solve this equation neatly?


title: Why is this expression being held, and how can I evaluate it?

text: I can't figure out why an expression isn't evaluating, even though there's no `Hold*` in its `FullForm`:               Plus[Dynamic[a$65712],Dynamic[Part[MousePosition[List["Graphics",Graphics],List[0,0]],1]]]      I've been stuck for hours now, and have gone through all kinds of threads including the one about Trott-Strzebonski and `HoldCondition`, but I'm afraid I may have missed the answer even if it was staring me in the face, due to lacking experience. After reading How to | Evaluate Expressions inside Dynamic or Manipulate, I began to think it must have something to do with `Dynamic` or perhaps `MousePosition`, but my understanding is weak. Here's the full code, before I continue explaining:               opts = {Axes -> False, Frame -> True, ImageSize -> {600, 400}, AspectRatio -> 1/GoldenRatio};     testdata1 = Table[{i, 5 Sin[i/10] + RandomReal[]}, {i, 100}];     testdata2 = {Log[#], #2} & @@@ testdata;     map1 = MapIndexed[Rule[testdata1[[First@#2, 1]], #] &, testdata2[[All, 1]]];     map2 = MapIndexed[Rule[testdata2[[First@#2, 1]], #] &, testdata1[[All, 1]]];     Deploy@DynamicModule[{x1, x2, a, b}, Column[{         Graphics[{PointSize@Tiny, Point /@ testdata}, GridLines -> {{             x1 = test1 = Dynamic[MousePosition[{"Graphics", Graphics}, {0, 0}][[1]]] + Dynamic[a];             b = ((test2 = Nearest[map1[[All, 1]], x1]) /. map1)[[1, 1]];             x1         }, {}}, opts],         Graphics[{PointSize@Tiny, Point /@ testdata2}, GridLines -> {{             x2 = test3 = Dynamic[MousePosition[{"Graphics", Graphics}, {0, 0}][[1]]] + Dynamic[b];             a = ((test4 = Nearest[map2[[All, 1]], x2]) /. map2)[[1, 1]];             x2         }, {}}, opts]     }]]      The line in question is this one:                       x1 = test1 = Dynamic[MousePosition[{"Graphics", Graphics}, {0, 0}][[1]]] + Dynamic[a];      Instead of adding up the two `Dynamic`ed expressions, it's passing the held form to `Nearest`, which, of course, doesn't know what to do with such an input. That is, `debug1` and `debug2` output, respectively,               Plus[Dynamic[a$69525], Dynamic[Part[MousePosition[List["Graphics", Graphics], List[0, 0]], 1]]]      and               Nearest[{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,     31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,     61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,     91,92,93,94,95,96,97,98,99,100},1+0]      I'd greatly appreciate it if someone could point out where I went wrong.


title: Combining Two Manipulated Plots Dependent on Same Variables

text: I need to combine two plots on the same graph to highlight the intersection of the two while being able to manipulate various parameters that are common to both functions. I need to have the slider simultaneously change the parameters for each function and continue to plot on the same graph. Here's my code:               Manipulate[      right = Plot[Cos[2*Pi*b*n/\[Lambda]], {n, 0, 2}], {{a, 25,         "x-separation"}, 20, 30}, {{b, 25, "z-separation"}, 20,        30}, {{r, 1, "Rod Radius"}, .1,        10}, {{\[Lambda], 100, "Wavelength"}, 50, 200}]          Manipulate[      left = Plot[        Cos[2*Pi*           b/\[Lambda]] + (\[Lambda]*Sin[2*Pi*b/\[Lambda]])/(2 a*            Log[a/(2*Pi*r)]), {n, 0, 2}], {{a, 25, "x-separation"}, 20,        30}, {{b, 25, "z-separation"}, 20, 30}, {{r, 1, "Rod Radius"}, .1,        10}, {{\[Lambda], 100, "Wavelength"}, 50, 200}]          Show[right, left] // Dynamic      Any help is much appreciated!