title: Error Trapping Complex Infinity Error due to Divide by Zero in Manipulate

text: I want to use a `Manipulate` that has two controllers that end up as a difference in the denominator of an expression. It is easy enough to set up the initial conditions such that the two controls are not equal in value, but upon user manipulation the two controls, if set the same give an error. The following code illustrates:                 table = Range[0, 6];       divideByZeroProblem =         Manipulate[         10/(time2 - time1), {{time1, 0}, Most[table],           ControlType -> PopupMenu}, {{time2, time1 + 1},           Drop[table, Position[table, time1][[1, 1]]],           ControlType -> PopupMenu}]      ![Output](http://i.stack.imgur.com/U0I1G.png) But of course if I change `time1` to be 1, then I get the following: ![Bad Output](http://i.stack.imgur.com/pK60P.png) I naively thought that I might be able to utilize `Initialization` to get around the problem by basing the initial value of `time2` on a function, but that doesn't update the initial value set for `time2`. The best lead that I have found in my searching for the answer on Mathematica.SE is Control variable and body variable decoupling in Manipulate, but I didn't succeed in translating that answer into a solution for my problem. It did lead me to try some things though. For example, my initial attempts at writing this question resulted in a simpler code that works as I would like it to.[Note added in later edit: I swear that it worked once this way, but I cannot get it to work again. It has the exact same kind of error. Must have been dreaming.]                   divideByZeroProblem2 =           Manipulate[           10/(time2 - time1), {{time1, 0}, Range[0, 5],             ControlType -> PopupMenu}, {{time2, Dynamic[time1] + 1}, Range[1,6],ControlType->PopupMenu}]      I played around quite a bit with using `Dynamic` and `Setting` in opportune spots to see if I could get it to work, but failed to find an appropriate combination. Any help that folks could provide would be much appreciated.


title: Undocumented use of Integrate: Integrating over regions

text: I have come across a few questions asking about integrating over regions. And while the answers are impressive there should be a better more consistent way. So my question is, are there ways, documented or undocumented, that allow one to expressly integrate over regions in an elegant fashion.


title: Creating a parallelizable DiscretePlot

text: To my knowledge, `DiscretePlot` cannot be parallelized, although one can simulate the default behavior of `DiscretePlot` and get the benefits of parallelization with a combination of `ListPlot` and `ParallelTable`. For example.               f[x_]:=(Pause[0.5];x^2);     DiscretePlot[f[x], {x, 0, 2, 0.2}] // AbsoluteTiming      ![Mathematica graphics](http://i.stack.imgur.com/lPOfX.png)               ListPlot[ParallelTable[{x, f[x]}, {x, 0, 2, 0.2}],        Filling -> Axis] // AbsoluteTiming      ![Mathematica graphics](http://i.stack.imgur.com/FmRyo.png) The problem with this alternative is that we lose access to several useful `DiscretePlot` options: `ExtentMarkers`, `ExtentSize` and `ExtentElementFunction`. How can we simulate the behavior of these options in `ListPlot` so that we may preserve the benefits of parallelization?


title: Probablity weighted ReplaceAll

text: I'm looking for an elegant way of doing a probability weighted replacement rule, something like this               f[x_] :=  x /.  {1,2,3,4} -> {50%{ 4,3,2,1} ,50%{1,3,2,4}}      Using an If statement and generating a RandomReal will be very clumsy as I want different probabilities depending on the pattern I want replaced. Thanks


title: Efficient replacement of conditional nested Do over elements of a matrix

text: I have two matrices like these:               m1=Table[Random[],{i,10},{j,10}]          m2=Table[Random[],{i,10},{j,10}]      I want to create a new matrix in which its main diagonal elements are zero and off-diagonals are determined based on               Min(m1[[i,j]],m2[[i,j]])      I came up with this `Do` loop:               newm=ConstantArray[0,{10,10}];     Do[     Do[     If[m1[[i,j]]<m2[[i,j]],newm[[i,j]]=m1[[i,j]],newm[[i,j]]=m2[[i,j]]],     {j,10}],     {i,10}]      What is the better way for doing this and avoiding `Do` loops?Is it possible to use `Map` and `Which`?


title: Setting CheckboxBar defaults under Manipulate

text: How is the default for the checkboxes created by `CheckboxBar` in a `Manipulate` set to be checked instead of unchecked? (The number of checkboxes may be variable.)


title: Listable on first level

text: I have some function which take `List` as input.               f[l_List]:=someActions[l]      I need apply this function to a list of lists. Now I use this approach               lst = {{1, 2}, {3, 4}};     f /@ lst     (*{someActions[{1, 2}], someActions[{3, 4}]}*)      But as we know `Map` over list is slower than using function with attribute `Listable`. When I set attribute `Listable` to my function I get not expected result:               SetAttributes[f, Listable]     f[lst]     (*{{f[1], f[2]}, {f[3], f[4]}}*)      How can I use attribute `Listable` with function which take a list of lists as input?


title: Generate Non-Singular Matrix of $n*n$ dimension

text: I want to create a function that will make an $n*n$ matrix which is non- singular that will always retrieve the same matrix (meaning that the matrix will not be random each time). I tried using the table function with different expressions using $i$ and $j$ but they always ended up singular because they had similar rules. So please don't give me a random matrix, the matrix needs to have a pattern that if two people used the function on different computers with the same $n$ value, they would get the same matrix P.S. Keep the matrix in the Real set of numbers (also Integers) and don't make them too high so that its not too big to work with (I want the values to be ideally under 20)


title: Map of Swedish regions?

text: There have been some questions dealing with how to draw individual US states since such data doesn't come with _Mathematica_ through its `CountryData` which offers similar functionality for countries. However, thus far, I haven't seen any questions regarding Swedish counties and municipalities. How would can I get similar functionality for Swedish counties and municipalities as that which exists in `CountryData`?


title: Taking the derivative of a function with indexed variables

text: I have a number of functions that depend on a variable `x`. I am using a second, integer variable to index these functions, i.e. something like               f[x_, 1] = a     f[x_, 2] = b x + c      When taking derivatives of these functions with `D`, it works the way I intend, i.e.               D[f[x, 1], x]     D[f[x, 2], x]      returns `0` respectively `b`. Now, however, I have a set of differential equations involving derivatives of these functions. These are expressed by _Mathematica_ as               Derivative[1, 0][f][x, 1]     Derivative[1, 0][f][x, 2]      which remains unevaluated. Is there any way to have `Derivative` ignore the second variable? More specifically, I would like to have a way of doing something along the lines of               Derivative[1][g][x]      and then replacing `g` by `f[x, 1]`. I guess I could just assign specific names to each of the functions `f[x, k]`, but in the end I want to sum them all up               Sum[f[x, k],{k, 1, n}]      for which it would be convienient to have some index variable rather than writing out the sum over different functions. Maybe I am approaching the whole idea of indexing functions in the wrong way?


title: how to make cursor jump automatically to next input cell after evaluating previous one?

text: When making separate cells in order to make separate computations to better see the result of each one before going to the next cell to do the next computation (which is a good way of doing things), it will be very useful and more efficient if the cursor would jump to the start of next input cell automatically. This allows one to keep the hand on the `ENTER` key, and just hit `ENTER` again, without having to reach to the `downarrow` key to reposition the cursor to the next cell, and move the hand again to the `ENTER` key. This can get tiring if one has many cells to process one by one. (This is btw how Maple does it, it automatically jumps to start of next command) Here is an example ![enter image description here](http://i.stack.imgur.com/0fZ2I.png) Is it possible to make the notebook do this?


title: Concatenating strings, unevaluated expressions and evaluated expressions/values

text: Maybe this is something very simple to some of you. Anyway, I think this can be useful to many others like me. I would like to build an output that involves strings, unevaluated expressions and evaluated expressions/values —something like this: > The value for $C_\mathrm{p}$ is $1.5$ and the value for $\delta^*$ is > $0.123$. where _1.5_ and _0.123_ are the result of evaluating respective expressions. This is what I tried:               Cp = 1.5; deltastar = 0.123;     HoldForm["The value for " HoldForm[Subscript[C, p]] " is " Evaluate[        Cp] " and the value for " HoldForm[        Superscript[\[Delta], "*"]] " is " Evaluate[deltastar] "."]      With this result: ![enter image description here](http://i.stack.imgur.com/2FU3f.png) The outer `HoldForm` is necessary to maintain the order of the _pieces_ , that are actually considered by Mathematica as being multiplied. For instance, this piece of code:               Cp = 1.5; deltastar = 0.123;     "The value for " HoldForm[Subscript[C, p]] " is " Evaluate[        Cp] " and the value for " HoldForm[        Superscript[\[Delta], "*"]] " is " Evaluate[deltastar] "."      yields to this output: ![enter image description here](http://i.stack.imgur.com/npCJV.png) Using `ToString` is not an option when there are superscripts and subscripts, as it is the case (I mean, the raw string output is awful). And because of that, I can't use string concatenation , which would be the most natural approach to me. There should be an easy way to do this in Mathematica, shouldn't there? As I said, I guess there _actually_ is a simple solution for this —that is, **properly building an output text or message that involves strings, unevaluated expressions and evaluated expressions.** Could you help me, please?


title: Smooth 4D (3D + color) plot from discrete points

text: I have a file containing isosurface $\\{x,y,z,F\\}$ data (around 9000 points). My goal is to generate a **smooth** (NOT a discrete set of points!) colored surface using `ListContourPlot3D`, i.e., something like this: ![enter image description here](http://i.stack.imgur.com/RWte5.png) More specifically, the surface I am trying to plot is closed. This what I am getting if I plot _x,y,z_ : ![surface](http://i.stack.imgur.com/tri2J.png) Now, I want to add color on top, i.e., I want different regions of the surface to be colored differently depending _F_. I am using `ListContourPlot3D`, because according to the description this what I need: > `ListContourPlot3D` linearly interpolates values to give smooth contours Any hints? So far all my attempts have been unsuccessful. This is what I am getting with `ListContourPlot3D[data]`: ![enter image description here](http://i.stack.imgur.com/dBaUP.png) **EDIT:** attached the file. file I want to plot col. 1(x): col.2(y): col.3(z) col4(color)


title: Semidefinite Programming

text: I want to solve a numerical optimization problem using semi-definite programming. Is there a package or add-on that equips mathematica with this functionality?


title: Dialog inside dialog not DialogReturn-ing properly

text: How can I prevent the DialogInput from failing (or returning early) as soon as I close the "Close this" dialog?               DialogInput@Button["Click this", CreateDialog["Close this" ]]


title: Input field that appends to a list

text: I'd like to make a dynamic, changeable list, which has elements that are supplied by the user in an InputField. I want the program to have an InputField and a "reset" button. Every time the user types an element into the InputField and presses TAB, this element is added to the list. The list is reset to the empty list when clicking on the "reset" button. Is this possible in _Mathematica_? The reset part seems easy, but the first part seems difficult. Perhaps should I use a second button, "add element"?


title: Creating a Block from a list of rules

text: How can I create a function which works like `Block` but takes a list of rules as its first argument, rather than a list of assignments? The function needs to be able to work with rules supplied either as an explicit list or via a symbol, and it should work when some of the symbols to be blocked have global values. Test code:               a = 100;     code := a + b;     rules := {a -> 1, b -> 2};          (* using an explicit list of rules *)     ruleBlock[{a -> 1, b -> 2}, code]     (* 3 *)          (* using a symbol *)     ruleBlock[rules, code]     (* 3 *)          (* global values are unaffected *)     {a, b}     (* {100, b} *)      I have a working solution (below) but I have had to write separate functions for `List` and `Symbol` patterns, and I find the code a bit cumbersome. I would like to know if there is a simpler, cleaner way to write `ruleBlock`.               SetAttributes[ruleBlock, HoldAll]          ruleBlock[rules_List, code_] :=       Replace[Apply[Set, Hold[rules], {2}], Hold[x_] :> Block[x, code]]          ruleBlock[rules_Symbol, code_] :=       Replace[Apply[Set, OwnValues[rules] /. HoldPattern[{_ :> r_}] :> Hold[r], {2}],        Hold[x_] :> Block[x, code]]


title: Using Boost with CreateLibrary

text: I was looking at the answer of Leonid of Faster alternatives for DayOfWeek and wanted to see how hard it would be to do something similar in C++ using an external library like Boost. I tried to include a Boost header in the example of the CreateLibrary help located here http://reference.wolfram.com/mathematica/CCompilerDriver/ref/CreateLibrary.html specifying also the path for the Boost files to include and Boost compiled libraries, like I would do in VisualStudio that I use, but the example didn't compile. So before trying harder, has anyone already succesfully used Boost with the CreateLibrary function ? (new in Mathematica 8). Thanks


title: Don't understand why Do-loop index is not evaluated in Play expression

text: So here is some weird behavior: When I create a list inside a loop whose elements are Play functions, with arguments that depend on the counter, it is as if the counter is being stored symbolically, so all the list elements - not just the last one - change with each iteration. THis only happens with Play. If I do the same thing with Plot, for example, it works as expected. Here is an example, though I have also tried creating the list using Append and AppendTo, I have assigned the outputs, etc. list1 has every part the same, and all equal to the result with the current value of i. list2 has each part equal to what it was when it was first created (so the first with the results evaluated with i=1, the second with i=2, etc.). Why? How do I fix Play?               list1 = {0, 0, 0};     list2 = list1;     Do[      list1[[i]] = Play[Cos[150*i*2*Pi*t], {t, 0, 0.5}];      list2[[i]] = Plot[Cos[i*2*Pi*t], {t, 0, 0.5}];      Print[list1, list2],      {i, 3}      ]     Show[list1]     Show[list2]     list1     list2


title: Solving a linear system in three unknowns

text: solve[{2 x + ay - z, bx - 4 y + z, -x + y} == {10, -30, 20}] $$ \begin{array}{lcr} 2x + a\,y - z & = & 10 \\\ b\,x -4y + z & = &-30 \\\ -x + y & = & 20 \end{array} $$ For what values of "a" and "b"   (a) will the system have a unique solution   (b) are the equations consistent?   (c) are the equations inconsistent?


title: How to insert / merge a list into another list?

text: Background: I am working on a 2D geometry algorithm where I need to insert a list of 2D points into another list of 2D points. Somewhat to my surprise I found no Mathematica function capable of doing this. My requirement is for a function that when provided for example:                {{1,1},{2,2},{3,3},{4,4},{5,5}}       and                {{100,100}, {200,200}}      returns               {{1,1},{2,2}, {100,100}, {200,200},{3,3},{4,4},{5,5}}       I looked at various Mathematica functions where Insert seemed the candidate to use, now                Insert[{{1,1},{2,2},{3,3},{4,4},{5,5}},{{100,100}, {200,200}},3]       returns                {{1, 1}, {2, 2}, {{100, 100}, {200, 200}}, {3, 3}, {4, 4}, {5, 5}}      note the extra braces around                {100, 100}, {200, 200}      Inspired by this question/answers I created insertM.                insertM[list_, values_, at_] := Module[{i = 0},        Insert[list, "mark", Array[{at} &, Length[values]]] /. "mark" :> (++i; values[[i]])]      which gives                insertM[{{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}}, {{100, 100}, {200, 200}}, 3]      {{1, 1}, {2, 2}, {100, 100}, {200, 200}, {3, 3}, {4, 4}, {5, 5}}      Although insertM does the job, I have this ' there must be a better way ' feeling. Now my question(s): Is there a Mathematica function that performs my requirement? If not, **is there a better function then insertM to do this?** In better I rank beautiful code (short, functional) highest unless it is significantly slower than a less beautiful alternative.


title: Better way to evaluate integral containing Boolean function

text: I am trying to compute the integral               $Assumptions = {0 < x[3] < 1, 0 < x[4] < 1, 0 < x[5] < 1};     Integrate[       x[2] Boole[2 (x[2] + x[3]) + x[4] < 1 &&                    2 x[2] + x[3] + x[4] + 2 x[5] > 1 &&                   x[2] + x[5] < x[3] + x[4]],       {x[2], 0, 1}]      but for some reason it takes forever. However, if I manually simplify the integrand               Boole[2 (x[2] + x[3]) + x[4] < 1 &&            2 x[2] + x[3] + x[4] + 2 x[5] > 1 &&            x[2] + x[5] < x[3] + x[4]] ==     Boole[(1 - x[3] - x[4])/2 - x[5] < x[2] <            Min[(1 - x[4])/2 - x[3], x[3] + x[4] - x[5]]] // PiecewiseExpand // Simplify          (* True *)      the integral is easily computed as               Integrate[Boole[a < x[2] < b] x[2], {x[2], 0, 1}] /.       a -> (1 - x[3] - x[4])/2 - x[5] /.        b -> Min[(1 - x[4])/2 - x[3], x[3] + x[4] - x[5]] // PiecewiseExpand // Simplify      I'd appreciate any hints as to how I can compute the integral more quickly without manual intervention.


title: How to typeset a system of equations with multiple alignment points

text: I'm aware of how to align a system of equations on the = sign (or other single alignment point), but I'd like to align a system at multiple points so that each variable stays in its own "column" so to speak. This is especially an issue if some variables have a 0 coefficient in some equations. I'd like to extend this idea to typesetting a linear programming problem such as this: ![enter image description here](http://i.stack.imgur.com/bYcQm.png) I use \alignat in LaTeX for this, but am trying to write more in Mathematica and would like to learn how to do it there. Thanks!


title: Is Mathematica comparable to C++ for creating standalone applications?

text: At my university, I have a yearly essay. I'm allowed to use any technology for implementing it. I've been coding it in C++ with Qt. I thought of about Wolfram _Mathematica_ because I have some experience in it. I need such functionality:   * Timers — for calling functions by timer    * Threads (or Processes are good too)    * User-friendly GUI (buttons, input forms)   * Be able to catch when user clicked left/right mouse buttons or key on keyboard    * Dynamic graphics (with changing graphics in time)    * Launching applications as a standalone executable file  I'm ready to put more effort into it. But I wonder whether I'm burying myself alive trying to implement things which _Mathematica_ isn't devoted to do. I would appreciate links to topics marked with questions signs. How bad is this idea? What are your opinions? Should I do it in C++? (Doing it in _Mathematica_ would be challenging for me.) ![enter image description here](http://i.stack.imgur.com/nUl5a.png)


title: arthmetic progression problem series upto 40 terms?

text: Find the sum of series 5+7+9+10+13+13+17+16+....., upto 40 terms? Please help i am facing problem while solving this question.i have tried my best to solve this but unable to find the common difference.?


title: Find positions of duplicates that are neighbours

text: Assuming the following list {1,2,3,3,5,6,3} I would like to get the position of values that are next to each other and are duplicates. That is, the output should be {3,4}. Thank you for any help. Cheers, Vaclav


title: Reversing every second "row" in a list

text: I have a list that is obtained by flattening a matrix               list=Flatten[Table[{i, j}, {i, 1, 4}, {j, 2, 6, 2}], 1]      > {{1, 2}, {1, 4}, {1, 6}, {2, 2}, {2, 4}, {2, 6}, {3, 2}, {3, 4}, {3, 6}, {4, > 2}, {4, 4}, {4, 6}} And I am looking for at way to reverse all "rows" with even numbers (the first element). So that my list will look like this               {{1,2}, {1,4}, {1,6}, {2,6}, {2,4}, {2,2}, {3,2}, {3,4}, {3,6}, {4,6}, {4, 4}, {4, 2}}       Note that the first element stays the same, but the last element (for list with even first element) for the whole "row" has reversed. Maybe there is an easy solutions to this, but I have not been able to find it yet.


title: Converting a date to a calendar quarter

text: I have a list that includes dates. I need to convert each date to be the last day of the quarter that it's in. So for example I want {2013,7,1,0,0,0} to become {2013,9,30,0,0,0}. Actually I don't need the zero's. I was trying to do this with a rule, but ran into problems. I wanted a rule like: 7,_ -> 9,30. Further I was going to try to insert alternatives into this with something like 7,_ |8,_ |9,_ -> 9,30. Is there a way to write a rule to handle this? Or, for this specific problem is there a better way to convert these dates to quarter end dates? An example of a row of data is: {{2009,5,1,0,0,0},"TYAU145A", 92468., 0.5, 46234.}.


title: Difference in output from R's mvtnorm and Mathematica/Java

text: Let a=$\mathcal{N}(6.532056,0.06532056)$,b~$\mathcal{N}(8.390961,0.08390961)$ and c~$\mathcal{N}(8.736566,0.08736566)$. We use $\mathcal{N}(\mu,\sigma^2)$ notation unless specified otherwise. We construct two normal variables x~$a-b$ and y~$a-c$.So, x=$\mathcal{N}(-1.858905,0.14923017)$ and y=$\mathcal{N}(-2.20451,0.15268622)$ Correlation between $x$ and $y$ i.e. $\textrm{cor}(x,y)= \frac{\textrm{var(a)}}{\sigma_x \times \sigma_y}$ by using the basic properties of covariance. Solving, $\textrm{cor}(x,y)=0.4327346392418512 \approx 0.433$ which can be written in matrix (let it be called $ mat $)for as \begin{bmatrix} 1.0 & 0.433 \\\\[0.3em] 0.433 & 1.0 \\\\[0.3em] \end{bmatrix} Now I want to find the $\Pr[-\infty<x<0 \textrm{ and } -\infty<y<0]$. I used the mvtnorm package's pmvnorm method by invoking pr<-pmvnorm(mean=c(-1.858905,-2.20451), corr=mat, lower=rep(-Inf, 2), upper=rep(0,2)) The result was 0.9575448. The same when I want to compute in Mathematica/Java(an implementation of the Genz algorithm found on internet) I am getting the result as 0.9999992445813132. I am including the _Mathematica_ code below. Please note here, the second argument in this case, is standard deviation.               px = NormalDistribution[-1.858905000000001, 0.38630320992712447]          py = NormalDistribution[-2.20451, 0.3907508413298685]          pxy = ProductDistribution[px, py]          Probability[-Infinity < x < 0 && -Infinity < y < 0, {x, y} \[Distributed] pxy]      What is the mistake I am doing? For my application domain (visualization) this difference is turning out to be very costly,especially because I run it over more than 700,000 data points.


title: Importing from Excel

text: I'm trying to import a matrix from Excel to Mathematica. My code is:               Import["desktop/stproj.xls", "xls", data, 1]      The output is some weird stuff about population counts and not at all related to what's in the excel file. Can anyone help me with importing this?


title: Programming a Meijer G related result

text: I am not that new in Mathematica, but I do not remember I have ever used it for programming (like we may do in Java). I have an important result given here by this integral: $$ \int_0^{+\infty} x^{\alpha-1} G^{st}_{uv} \left[ \sigma x \left| \begin{array}{c} (c_u) \\\ (d_v) \end{array} \right. \right] G^{mn}_{pq} \left[ \omega x^{l/k} \left| \begin{array}{c} (a_p) \\\ (b_q) \end{array} \right. \right] dx = \frac{k^\mu l^{\rho + \alpha(v-u)-1} \sigma^{-\alpha}}{(2\pi)^{b^*(l-1) + c^*(k-1)}} \\\ G^{mn}_{pq} \left[ \frac{\omega^k k^{k(p-q)}}{\sigma^l l^{l(u-v)}} \left| \begin{array}{c} \Delta(k,a_1),\ldots,\Delta(k,a_n),\Delta(k,1-\alpha- d_1),\ldots,\Delta(k,1-\alpha-d_v), \\\ \Delta(k,b_1),\ldots,\Delta(k,b_m),\Delta(k,1-\alpha- c_1),\ldots,\Delta(k,1-\alpha-c_u), \end{array} \right. \right. \\\ \left. \begin{array}{c} \Delta(k,a_{n+1}),\ldots,\Delta(k,a_p) \\\ \Delta(k,b_{m+1}),\ldots,\Delta(k,b_q) \end{array} \right] $$ where $G$ is the Meijer G function, $(s,t,u,v,m,n,p,q)$ are integers, $\alpha$ is real, $\Delta(k,a) = \frac{a}{k},\frac{a+1}{k},\ldots,\frac{a+k-1}{k}$, $b^* = s+t - \frac{v+u}{2}$, $c^* = m+n - \frac{p+q}{2}$, $\mu = \sum_{j=1}^{q} b_j - \sum_{j=1}^{p} a_j + \frac{p-q}{2} + 1$, $\rho = \sum_{j=1}^{v} d_j - \sum_{j=1}^{u} c_j + \frac{u-v}{2} + 1. I tried to create a module that gives me the result in a Traditional Form               \[CapitalDelta][k_, a_] := Range[a/k, (a + k - 1)/k, 1/k]               Res[\[Alpha]_, s_, t_, u_, v_, \[Sigma]_, c_, d_, m_, n_, p_,      q_, \[Omega]_, l_, k_, a_, b_] :=      Module[{a1, b1, arg1, arg2, arg3, arg4, expr},     Print["km+lt = ", k m + l t]      a1 := {Table[\[CapitalDelta][k, a[[i]]], {i, 1, n, 1}],      Table[\[CapitalDelta][l, 1 - \[Alpha] - d[[i]]], {i, 1, v, 1}],      Table[\[CapitalDelta][k, a[[i]]], {i, n + 1, p, 1}]};     Print["a1 = ", a1]     b1 := {Table[\[CapitalDelta][k, b[[i]]], {i, 1, m, 1}],      Table[\[CapitalDelta][l, 1 - \[Alpha] - c[[i]]], {i, 1, u, 1}],      Table[\[CapitalDelta][k, b[[i]]], {i, m + 1, q, 1}]};     Print["b1 = ", b1]     If [Length[a1] > 0, arg1 := Table[a1[[i]], {i, 1, k m + l t}]]     arg2 := Table[a1[[i]], {i, k m + l t + 1, k q + l u}];     If [Length[b1] > 0, arg3 := Table[b1[[j]], {j, 1, k n + l s}]]     arg4 := Table[b1[[j]], {j, k n + l s + 1, k p + l v}];     expr :=      MeijerG[{arg3, arg4}, {arg1, arg2}, (\[Omega]^k k^(     k (p - q)))/(\[Sigma]^l l^(l (u - v)))];     Return[expr];      ] This code returns me a bunch of errors, so your help is much appreciated.


title: Search function stops working after converting to CDF

text: My problem is, that when a make a notebook and convert it to CDF using the 'CDF-Export', the search field, which appears on CDF player, does not work. When trying to search for a word, the computer simply makes a sound indicating that the word was not found. But when I use 'CDF-preview' before converting, the search field works just fine. I have tried it with very simple notebooks and the problem is still there. Am I the only one with this problem? Does anyone have an idea for a solution?


title: How to do System dynamics simulations / diagrams in Mathematica?

text: System dynamics is an approach to understanding the behaviour of complex systems over time. It deals with internal feedback loops and time delays that affect the behaviour of the entire system. What makes using system dynamics different from other approaches to studying complex systems is the use of feedback loops and stocks and flows. These elements help describe how even seemingly simple systems display **baffling nonlinearity** Here is how a system diagram looks like: ![enter image description here](http://i.stack.imgur.com/6TrpW.gif) Apperently I should be able to this with System Modeler by loading this modelica library but I am also told here that: > The downside, as I understand it, is that **each different use of a System > Dynamics symbol requires its own entry in the library**. For example, a > stock with one inflow and one outflow requires a different Modelica symbol > from one with one inflow and 2 outflows. Also (again, as I understand it), > every separate equation requires its own symbol to be defined and added to > the library before it can be used. ¿Anyone here can confirm or deny this? ¿Is this a limitation inherent in all **Modelica** enviroments? ¿or it is an implementation limitation on this particular library? and, going back to the original aim of this question: Is there a less expensive way (than System Modeler) to do this **in Mathematica, _without_ System Modeler**?


title: How do I make two styles in a stylesheet inherit the same style

text: Specifically I want different versions of 'Item1Numbered'. For example one with a frame and another with a background colour. How is that done?


title: Good ways to organize and document collections of mathematica notebooks?

text: I've now been using _Mathematica_ for about a year, and am starting to get a somewhat unwieldy collection of notebooks. Sometimes I've figured out how to do a particular task in one of them, and want to use that again, but have to search through what I've done. To tackle this, I've cobbled together a script that generates an html page for all the notebooks that I've checked into my source code repository (I happen to be using github to store my notebooks, latex, and other source code), and can put comments in that generated html file about what I did in each notebook, including any special techniques that I learned to accomplish the task. By way of example, I can list these with something like on this page. From a local copy of my source repository I generate something similar, allowing a click on the various notebooks to view them with the CDF player. I'm able to navigate my collection of notebooks well enough this way, but was curious how other people tackle the same organizational problem?


title: Finding the characteristic polynomial of a matrix modulus n

text: Given a square matrix, is it possible to calculate its characteristic polynomial modulo `n`? Unfortunately, this function `CharacteristicPolynomial` doesn't have the `Modulus` option that many other functions have.


title: MapThread and Compile

text: After discovering that MapIndexed cannot be used with `compile` (see MapIndexed and Compile) I am now trying do implement similar functionality using a combination of `MapThread` and `Map`. Unfortunately I am running into problems even when only using `MapThread`. Here is a test-scenario: Create Lists first:               A = {{1, 2}, {2, 3}};     B = {{{1, 2, 3}, {2, 3, 4}}, {{2, 3, 4}, {3, 4, 5}}};      The I simply run `MapThread` with function `List[]` to obtain a suitable combination of those lists and put the whole thing inside a `Compile`-statement:               test = Compile[{{B, _Real, 3}, {A, _Real, 2}}, MapThread[List[#1, #2, #3] &, {B, A, A}, 2]];      But when running `test[B,A]` I get the following compile error: > CompiledFunction::cfex: Could not complete external evaluation at > instruction 15; proceeding with uncompiled evaluation. When using `CompilePrint[test]` instruction 15 shows a call to `MainEvaluate`. Unfortunately I currently have no clue how to fix that problem. Any hint is appreciated.


title: Requesting explanation of FitModel code

text: I am struggling with understanding the code given in this original post I understand how the tests are conducted, both of them. However, I do not understand this part:               FitModel[data_List, coords_List] :=       With[{lm = LinearModelFit[data, coords, coords]},         dispatch[{           "BreuschPagan" -> BreuschPagan[data, lm, coords],           "WhitesHeteroskedasticity" -> WhitesHeteroskedasticity[lm, coords]}]];     dispatch[list_][field_] := field /. list     dispatch[list_]["Properties"] := list /. Rule[field_, _] :> field     dispatch /: ReplaceAll[fields_, dispatch[list_]] := fields /. list     Format[dispatch[list_], StandardForm] :=        HoldForm[dispatch]["<" <> ToString@Length@list <> ">"]      Could someone explain what this is doing? If you recommend that I do it in a chat, I have created a chat room for such discussion. I find it particularly difficult to understand the code for `dispatch` and how it works.


title: Partial Differential Equation in Parallel

text: is there any native way to implement multi-core parallel solving of PDE in Wolfram Mathematica? WM 10 now supports Finite Elements Method, but it is actually useless without parallelization. Usually PDE-systems are heavy and no one solves it using just one core. If there is any sort of domain decomposition or some other way parallelize the calculation?


title: Find the minima and maxima of a list

text: I have a list, such as:               testdata = {{1, 317}, {2, 317}, {3, 317}, {4, 317}, {5, 317}, {6,          317}, {7, 318}, {8, 318}, {9, 318}, {10, 318}, {11, 319}, {12,          319}, {13, 319}, {14, 319}, {15, 314}, {16, 314}, {17, 314}, {18,          314}, {19, 314}, {20, 314}, {21, 314}, {22, 314}, {23, 314}, {24,          314}, {25, 314}, {26, 314}, {27, 314}, {28, 306}, {29, 306}, {30,          306}, {31, 306}, {32, 293}, {33, 293}, {34, 293}, {35, 293}, {36,          293}, {37, 293}, {38, 293}, {39, 223}, {40, 223}, {41, 223}, {42,          223}, {43, 154}, {44, 154}, {45, 154}, {46, 154}, {47, 219}, {48,          219}, {49, 219}, {50, 219}, {51, 267}, {52, 267}, {53, 267}, {54,          267}, {55, 293}, {56, 293}, {57, 293}, {58, 293}, {59, 300}, {60,          300}, {61, 300}, {62, 300}, {63, 287}, {64, 287}, {65, 287}, {66,          287}, {67, 273}, {68, 273}, {69, 273}, {70, 248}, {71, 248}, {72,          248}, {73, 248}, {74, 232}, {75, 232}, {76, 232}, {77, 232}, {78,          203}, {79, 203}, {80, 203}, {81, 203}, {82, 180}, {83, 180}, {84,          180}, {85, 180}, {86, 163}, {87, 163}, {88, 163}, {89, 163}, {90,          158}, {91, 158}, {92, 158}, {93, 158}, {94, 179}, {95, 179}, {96,          179}, {97, 179}, {98, 203}, {99, 203}, {100, 203}, {101,          203}, {102, 228}, {103, 228}, {104, 228}, {105, 228}, {106,          228}, {107, 228}, {108, 228}, {109, 228}, {110, 228}, {111,          228}, {112, 228}, {113, 228}, {114, 228}, {115, 230}, {116,          230}, {117, 230}, {118, 230}, {119, 225}, {120, 225}, {121,          225}, {122, 225}, {123, 214}, {124, 214}, {125, 214}, {126,          224}, {127, 224}, {128, 224}, {129, 224}, {130, 228}, {131,          228}, {132, 228}, {133, 228}, {134, 239}, {135, 239}, {136,          239}, {137, 239}, {138, 244}, {139, 244}, {140, 244}, {141,          244}, {142, 232}, {143, 232}, {144, 232}, {145, 232}, {146,          231}, {147, 231}, {148, 231}, {149, 231}, {150, 192}, {151,          192}, {152, 192}, {153, 192}, {154, 128}, {155, 128}, {156,          128}, {157, 128}, {158, 112}, {159, 112}, {160, 112}, {161,          192}, {162, 192}, {163, 192}, {164, 192}, {165, 249}, {166,          249}, {167, 249}, {168, 249}, {169, 257}, {170, 257}, {171,          257}, {172, 257}, {173, 240}, {174, 240}, {175, 240}, {176,          240}, {177, 214}, {178, 214}, {179, 214}, {180, 214}, {181,          200}, {182, 200}, {183, 200}, {184, 200}, {185, 212}, {186,          212}, {187, 212}, {188, 212}, {189, 201}, {190, 201}, {191,          201}, {192, 201}, {193, 173}, {194, 173}, {195, 173}, {196,          140}, {197, 140}, {198, 140}, {199, 140}, {200, 137}, {201,          137}, {202, 137}, {203, 137}, {204, 149}, {205, 149}, {206,          149}, {207, 149}, {208, 164}, {209, 164}, {210, 164}, {211,          164}, {212, 203}, {213, 203}, {214, 203}, {215, 203}, {216,          242}, {217, 242}, {218, 242}, {219, 242}, {220, 270}, {221,          270}, {222, 270}, {223, 270}, {224, 275}, {225, 275}, {226,          275}, {227, 275}, {228, 266}, {229, 266}, {230, 266}, {231,          275}, {232, 275}, {233, 275}, {234, 275}, {235, 285}, {236,          285}, {237, 285}, {238, 285}, {239, 291}, {240, 291}, {241,          291}, {242, 291}, {243, 277}, {244, 277}, {245, 277}, {246,          277}, {247, 271}, {248, 271}, {249, 271}, {250, 271}, {251,          271}, {252, 271}, {253, 271}, {254, 271}, {255, 271}, {256,          271}, {257, 271}, {258, 271}, {259, 271}, {260, 266}, {261,          266}, {262, 266}, {263, 266}, {264, 195}, {265, 195}, {266,          195}, {267, 195}, {268, 128}, {269, 128}, {270, 128}, {271,          128}, {272, 193}, {273, 193}, {274, 193}, {275, 193}, {276,          252}, {277, 252}, {278, 252}, {279, 276}, {280, 276}, {281,          276}, {282, 276}, {283, 271}, {284, 271}, {285, 271}, {286,          271}, {287, 256}, {288, 256}, {289, 256}, {290, 256}, {291,          250}, {292, 250}, {293, 250}, {294, 250}, {295, 236}, {296,          236}, {297, 236}, {298, 236}, {299, 211}, {300, 211}, {301,          211}, {302, 211}, {303, 188}, {304, 188}, {305, 188}, {306,          188}, {307, 165}, {308, 165}, {309, 165}, {310, 165}, {311,          156}, {312, 156}, {313, 156}, {314, 153}, {315, 153}, {316,          153}, {317, 153}, {318, 165}, {319, 165}, {320, 165}, {321,          165}, {322, 191}, {323, 191}, {324, 191}, {325, 191}, {326,          228}, {327, 228}, {328, 228}, {329, 228}, {330, 261}, {331,          261}, {332, 261}, {333, 261}, {334, 267}, {335, 267}, {336,          267}, {337, 267}, {338, 267}, {339, 267}, {340, 267}, {341,          267}, {342, 267}, {343, 267}, {344, 267}, {345, 267}, {346,          267}, {347, 266}, {348, 266}, {349, 266}, {350, 266}, {351,          259}, {352, 259}, {353, 259}, {354, 259}, {355, 258}, {356,          258}, {357, 258}, {358, 258}, {359, 251}, {360, 251}, {361,          251}, {362, 251}, {363, 254}, {364, 254}, {365, 254}, {366,          252}, {367, 252}, {368, 252}, {369, 252}, {370, 260}, {371,          260}, {372, 260}, {373, 260}, {374, 275}, {375, 275}, {376,          275}, {377, 275}, {378, 209}, {379, 209}, {380, 209}, {381,          209}, {382, 136}, {383, 136}, {384, 136}, {385, 136}, {386,          175}, {387, 175}, {388, 175}, {389, 175}, {390, 240}, {391,          240}, {392, 240}, {393, 240}, {394, 267}, {395, 267}, {396,          267}, {397, 267}, {398, 255}, {399, 255}, {400, 255}, {401,          243}, {402, 243}, {403, 243}, {404, 243}, {405, 227}, {406,          227}, {407, 227}, {408, 227}, {409, 218}, {410, 218}, {411,          218}, {412, 218}, {413, 207}, {414, 207}, {415, 207}, {416,          207}, {417, 196}, {418, 196}, {419, 196}, {420, 196}, {421,          195}, {422, 195}, {423, 195}, {424, 195}, {425, 200}, {426,          200}, {427, 200}, {428, 200}, {429, 214}, {430, 214}, {431,          214}, {432, 214}, {433, 229}, {434, 229}, {435, 229}, {436,          229}, {437, 256}, {438, 256}, {439, 256}, {440, 283}, {441,          283}, {442, 283}, {443, 283}, {444, 285}, {445, 285}, {446,          285}, {447, 285}, {448, 293}, {449, 293}, {450, 293}, {451,          293}, {452, 294}, {453, 294}, {454, 294}, {455, 294}, {456,          294}, {457, 294}, {458, 294}, {459, 294}, {460, 293}, {461,          293}, {462, 293}, {463, 293}, {464, 278}, {465, 278}, {466,          278}, {467, 278}, {468, 277}, {469, 277}, {470, 277}, {471,          277}, {472, 266}, {473, 266}, {474, 266}, {475, 251}, {476,          251}, {477, 251}, {478, 251}, {479, 250}, {480, 250}, {481,          250}, {482, 250}, {483, 250}, {484, 250}, {485, 250}, {486,          250}, {487, 250}, {488, 250}, {489, 250}, {490, 250}, {491,          250}, {492, 239}, {493, 239}, {494, 239}, {495, 239}, {496,          159}, {497, 159}, {498, 159}, {499, 159}, {500, 139}, {501,          139}, {502, 139}, {503, 139}, {504, 215}, {505, 215}, {506,          215}, {507, 215}, {508, 267}, {509, 267}, {510, 267}, {511,          267}, {512, 289}, {513, 289}, {514, 289}, {515, 289}, {516,          267}, {517, 267}, {518, 267}, {519, 267}, {520, 256}, {521,          256}, {522, 256}, {523, 256}, {524, 222}, {525, 222}, {526,          222}, {527, 194}, {528, 194}, {529, 194}, {530, 194}, {531,          185}, {532, 185}, {533, 185}, {534, 185}, {535, 181}, {536,          181}, {537, 181}, {538, 181}, {539, 195}, {540, 195}, {541,          195}, {542, 195}, {543, 199}, {544, 199}, {545, 199}, {546,          199}, {547, 199}, {548, 199}, {549, 199}, {550, 199}, {551,          214}, {552, 214}, {553, 214}, {554, 214}, {555, 226}, {556,          226}, {557, 226}, {558, 226}, {559, 255}, {560, 255}, {561,          255}, {562, 268}, {563, 268}, {564, 268}, {565, 268}, {566,          274}, {567, 274}, {568, 274}, {569, 274}, {570, 274}, {571,          274}, {572, 274}, {573, 274}, {574, 274}, {575, 274}, {576,          274}, {577, 274}, {578, 274}, {579, 268}, {580, 268}, {581,          268}, {582, 268}, {583, 270}, {584, 270}, {585, 270}, {586,          270}, {587, 260}, {588, 260}, {589, 260}, {590, 260}, {591,          250}, {592, 250}, {593, 250}, {594, 250}, {595, 230}, {596,          230}, {597, 230}, {598, 230}, {599, 227}, {600, 227}, {601,          227}, {602, 227}, {603, 240}, {604, 240}, {605, 240}, {606,          240}, {607, 240}, {608, 240}, {609, 240}, {610, 235}, {611,          235}, {612, 235}, {613, 235}, {614, 156}, {615, 156}, {616,          156}, {617, 156}, {618, 108}, {619, 108}, {620, 108}, {621,          108}, {622, 190}, {623, 190}, {624, 190}, {625, 190}, {626,          237}, {627, 237}, {628, 237}, {629, 237}, {630, 261}, {631,          261}, {632, 261}, {633, 261}, {634, 242}, {635, 242}, {636,          242}, {637, 242}, {638, 215}, {639, 215}, {640, 215}, {641,          215}, {642, 191}, {643, 191}, {644, 191}, {645, 162}, {646,          162}, {647, 162}, {648, 162}, {649, 160}, {650, 160}, {651,          160}, {652, 160}, {653, 148}, {654, 148}, {655, 148}, {656,          148}, {657, 147}, {658, 147}, {659, 147}, {660, 147}, {661,          160}, {662, 160}, {663, 160}, {664, 160}, {665, 177}, {666,          177}, {667, 177}, {668, 177}, {669, 211}, {670, 211}, {671,          211}, {672, 211}, {673, 234}, {674, 234}, {675, 234}, {676,          234}, {677, 252}, {678, 252}, {679, 252}, {680, 261}, {681,          261}, {682, 261}, {683, 261}, {684, 261}, {685, 261}, {686,          261}, {687, 261}, {688, 259}, {689, 259}, {690, 259}, {691,          259}, {692, 245}, {693, 245}, {694, 245}, {695, 245}, {696,          252}, {697, 252}, {698, 252}, {699, 252}, {700, 267}, {701,          267}, {702, 267}, {703, 267}, {704, 278}, {705, 278}, {706,          278}, {707, 278}, {708, 277}, {709, 277}, {710, 277}, {711,          277}, {712, 267}, {713, 267}, {714, 267}, {715, 267}, {716,          267}, {717, 267}, {718, 267}, {719, 267}, {720, 267}, {721,          267}, {722, 267}, {723, 267}, {724, 267}, {725, 267}, {726,          267}, {727, 267}, {728, 267}, {729, 259}, {730, 259}, {731,          259}, {732, 259}, {733, 177}, {734, 177}, {735, 177}, {736,          132}, {737, 132}, {738, 132}, {739, 132}, {740, 202}, {741,          202}, {742, 202}, {743, 202}, {744, 258}, {745, 258}, {746,          258}, {747, 258}, {748, 285}, {749, 285}, {750, 285}, {751,          285}, {752, 278}, {753, 278}, {754, 278}, {755, 278}, {756,          268}, {757, 268}, {758, 268}, {759, 268}, {760, 251}, {761,          251}, {762, 251}, {763, 251}, {764, 242}, {765, 242}, {766,          242}, {767, 251}, {768, 251}, {769, 251}, {770, 251}, {771,          222}, {772, 222}, {773, 222}, {774, 222}, {775, 186}, {776,          186}, {777, 186}, {778, 186}, {779, 164}, {780, 164}, {781,          164}, {782, 164}, {783, 161}, {784, 161}, {785, 161}, {786,          161}, {787, 177}, {788, 177}, {789, 177}, {790, 177}, {791,          198}, {792, 198}, {793, 198}, {794, 198}, {795, 234}, {796,          234}, {797, 234}, {798, 249}, {799, 249}, {800, 249}, {801,          249}, {802, 249}, {803, 249}, {804, 249}, {805, 249}, {806,          249}, {807, 249}, {808, 249}, {809, 249}, {810, 249}, {811,          249}, {812, 256}, {813, 256}, {814, 256}, {815, 244}, {816,          244}, {817, 244}, {818, 244}, {819, 239}, {820, 239}, {821,          239}, {822, 239}, {823, 248}, {824, 248}, {825, 248}, {826,          248}, {827, 256}, {828, 256}, {829, 256}, {830, 256}, {831,          244}, {832, 244}, {833, 244}, {834, 244}, {835, 228}, {836,          228}, {837, 228}, {838, 228}, {839, 225}, {840, 225}, {841,          225}, {842, 225}, {843, 224}, {844, 224}, {845, 224}, {846,          224}, {847, 222}, {848, 222}, {849, 222}, {850, 222}, {851,          154}, {852, 154}, {853, 154}, {854, 128}, {855, 128}, {856,          128}, {857, 128}, {858, 206}, {859, 206}, {860, 206}, {861,          206}, {862, 262}, {863, 262}, {864, 262}, {865, 262}, {866,          289}, {867, 289}, {868, 289}, {869, 289}, {870, 271}, {871,          271}, {872, 271}, {873, 271}, {874, 244}, {875, 244}, {876,          244}, {877, 244}, {878, 222}, {879, 222}, {880, 222}, {881,          222}, {882, 206}, {883, 206}, {884, 206}, {885, 206}, {886,          196}, {887, 196}, {888, 196}, {889, 183}, {890, 183}, {891,          183}, {892, 183}, {893, 178}, {894, 178}, {895, 178}, {896,          178}, {897, 172}, {898, 172}, {899, 172}, {900, 172}, {901,          171}, {902, 171}, {903, 171}, {904, 171}, {905, 192}, {906,          192}, {907, 192}, {908, 192}, {909, 213}, {910, 213}, {911,          213}, {912, 213}, {913, 249}, {914, 249}, {915, 249}, {916,          279}, {917, 279}, {918, 279}, {919, 279}, {920, 282}};      Q1: I would like to get the peak and valley in the graph and draw it, Q2: I would like to find how many valleys are in this list, Q3: I would like to get the first 200 points and minimum valleys. This is what I've tried so far:               ListLinePlot[testdata]      * * * Thanks for your help, I have been successful :) this is my code               mins=Pick[testdata,MinDetect[testdata[[All,2]]],1];     maxs=Pick[testdata,MaxDetect[testdata[[All,2]]],1];     Show[ListLinePlot[testdata[[All,2]],Filling->Axis,AxesLabel->{number,ECG_Data}],ListPlot[maxs,PlotStyle->Red,PlotLegends->{"Peak"}],ListPlot[mins,PlotStyle->Blue,PlotLegends->{"Valley"}]]     Thr=200;          findpeak=Position[Differences[MaxDetect[testdata[[All,2]]]],-1];     findvalley=Position[Differences[MinDetect[testdata[[All,2]]]],-1];     peak=Extract[testdata,findpeak];     valley=Extract[testdata,findvalley];     valleysmin200=Select[valley,#[[2]]<Thr&];     f1=ListLinePlot[testdata,AxesLabel->{number,ECG_Data},Filling->Axis,FillingStyle->Automatic];     f2=ListPlot[peak,PlotStyle->{Red,PointSize[Large]},PlotLegends->{"Peak"}];     f3=ListPlot[valley,PlotStyle->{Blue,PointSize[Large]},PlotLegends->{"Valley"}];     f4=ListPlot[valleysmin200,PlotStyle->{Blue,PointSize[Large]},PlotLegends->{"Valley"}];     f5=ListLinePlot[Table[Thr,{Length[testdata]}],PlotStyle -> Pink];     Show[f1,f2,f3] (*modify peak & valley*)     Show[f1,f4,f5] (*valley<200*)     Length[valleysmin200]/2*12


title: define a function from a list

text: I would like to create a mapping from a list and I am wondering if there is a slick way of doing it. For example, consider the list               ls = WaveletFilterCoefficients[DaubechiesWavelet[2], "PrimalHighpass"]          {{-2, -0.0915064},{-1, -0.158494},{0, 0.591506},{1, -0.341506}}      I would like to define a function that maps                -2 -> -0.0915064      -1 -> -0.158494       0 ->  0.591506       1 -> -0.341506      and all other integers to zero. Any suggestions?


title: When does a list contain only ones?

text: I am starting with a list of length n that contains all -1's. For instance, when `n = 6` the list is `{-1, -1, -1, -1, -1, -1}`. I pick a random integer from 1 to n and toggle the element by multiplying by -1. In the given list, if I pick the third element, the new list would be `{-1, -1, 1, -1, -1, -1}`. I continue in this manner, picking an element randomly and toggling it from plus to minus or minus to plus. I wish to know how long it will take for the list to have all 1's. How long will it take to become `{1, 1, 1, 1, 1, 1}`? My code is:               toggle[box_, n_] :=       Block[{r, h = box},         r = RandomInteger[{1, n}];         h[[r]] = -h[[r]];         h]          n = 6;     trials = 40000;     box = ConstantArray[-1, n];     ans =        Table[sbox = box;              (NestWhileList[toggle[#, n] &,                             sbox,                             Total[#] != n &] // Length) - 1,             {trials}];     Mean[ans] // N      The exact answer for this one is 416 / 5. I am getting around 83 for my simulation, but it is deadly slow. Can I speed it up?


title: What are the min and max arguments to EdgeDetect?

text: What are the min and max arguments to `EdgeDetect`, for all methods and specifically `"Sobel"`? How do I find the limits or ranges of functions in the future? Or is it 255?


title: GraphPlot3D: How to plot undirected graph with a list of edges?

text: I have a list of edges defined based on vertices like this:               Edges={{2, 1}, {10, 9}, {11, 10}, {11, 4}, {17, 12},.....}      (*Where each number is the index of a vertex which has 3D coordinates*)      In order to plot a graph I first made Edges looks like this (I want to plot **undirected** graph)               edges = Flatten[Table[{Edges[[i, 1]] <-> Edges[[i, 2]]}, {i, 1, Length[Edges]}]];      Then I plot the graph               GraphPlot3D[edges, VertexLabeling -> False, (*VertexCoordinateRules -> nodescoord*), \BoxRatios -> Automatic,ViewPoint -> {0, 0, -Infinity}];      Where am I wrong? Is it the way I define edges using "<->"?


title: Nonlinear Optimization with conditional statement

text: I find Maximize doesn't work well under **conditional statement**. Here is an example. ![enter image description here](http://i.stack.imgur.com/q44hN.jpg) A car is driving up a slope. I want to find out the largest slope angle the car can drive upwards. I choose the slope angle `θ` and engine torque `τ` as decision variables. The friction force can be described by Coulomb friction model, which is a conditional statement ![enter image description here](http://i.stack.imgur.com/3OCva.jpg) The complete formulation is ![enter image description here](http://i.stack.imgur.com/DFbvG.jpg) Therefore, the Nonlinear Optimization can be solved by                 Maximize[{θ, 0 < θ < Pi/2 && 0 < τ < 2 &&                  If[τ/r < μs*G*Cos[θ], τ/r, μd G Cos[θ]] > G Sin[θ]}, {θ, τ}]      given the parameters: G = 70; r = 0.025; μs = 0.5; μd = 0.4; Mathematica gives `θ=0.380506`,,which is ArcTan[μd], whereas the expected result should be `θ=0.46364`,which is ArcTan[μs].


title: Plot lines and measure the distances between them

text: I have the following code:               aJ = 5.2;     OmJ = N[2 Pi/aJ^(3/2)]     {val1} = NSolve[o/OmJ == 2., o]      {val2} = NSolve[o/OmJ == 3., o]     {val3} = NSolve[o/OmJ == 5./2., o]     {val4} = NSolve[o/OmJ == 7./2., o]     {val5} = NSolve[o/OmJ == 4., o]      {val6} = NSolve[o/OmJ == 3./2., o]     {val7} = NSolve[o/OmJ == 5./3., o]     {val8} = NSolve[o/OmJ == 7./3., o]          d = 7;     n = 6;     p = ListPlot[        Flatten[Table[{o /. NSolve[o/OmJ == j/i, o], n}, {j, 2, 9, 1}, {i,            1, 4, 1}], 1],        Filling -> Axis, AxesLabel -> {"mean motion", "par"},         FillingStyle -> {Red}, PlotRange -> {{0.3, 2.2}, {0, 800}},         PlotMarkers -> Automatic, PlotStyle -> Black, ImageSize -> 700,        Epilog -> {{AbsolutePointSize[8], Black,            Text["Jupiter Position", {OmJ, 1}],            Point[{OmJ, 0.1}]},          {Blue, Text[Style["2:1", Bold, Black, 16], {o /. val1, d}],            Text[Style["3:1", Bold, Black, 16], {o /. val2, d}],            Text[Style["5:2", Bold, Black, 16], {o /. val3,  d}],            Text[Style["7:2", Bold, Black, 16], {o /. val4,  d}],            Text[Style["4:1", Bold, Black, 16], {o /. val5,  d}],            Text[Style["3:2", Bold, Black, 16], {o /. val6,  d}],           Text[Style["5:3", Bold, Black, 16], {o /. val7,  d}],            Text[Style["7:3", Bold, Black, 16], {o /. val8,  d}]}}];          t = Show[{p}, PlotRange -> {{0.3, 2.2}, {0, 8}}, ImageSize -> 600]      And i like to draw also lines under every texts. **Then** i like to know in such a way how far (the distance) a line is from another one. I red this post: Distance between point and line segments but i ddin't understand a lot.


title: How to replace subscript symbols

text: I have an expression with subscripted variables. I would like to replace all those terms with other symbols. For example, $P_1 + P_2^3 \rightarrow P1 + P2^3$ I used the following code but it doesn't work               X = Subscript[P, 1] + Subscript[P, 3]^2 - I*Subscript[P, 5]     X /. {Subscript[P, n_] -> Pn}      If I replace `Subscript[P, n_]` with `P[n]` then it works (e.g. $P_1$ will be replaced with `P[1]`) but I don't want the bracket. I want `P1` instead. Is there any way to solve this?


title: Using derivative d in Mathematica

text: In mathematics derivates are often written like $$d^2y \over dx^2$$ or $$dy \over dx$$ In Mathematica we have the function D, but is it possible to use a similar approach?


title: Having variables appear aqua in user defined function

text: In many of the inbuilt mathematica function, variables appear aqua like in: ![enter image description here](http://i.stack.imgur.com/flHO1.png) However, when creating your own function, variables no longer have that green coloring and are instead colored like an undefined variable ![enter image description here](http://i.stack.imgur.com/m1xqw.png) Is there any way to define functions so that variables used in arguments like in the manner above can get the aqua syntax coloring?


title: How do I make my function behave more like Plot?

text: I have written a function `Fun` as below:               Fun[x_Symbol, xrange_, imageSize_, axeslabel_] :=      Plot[x^2, {x, xrange[[1]], xrange[[2]]},         ImageSize -> imageSize,         AxesLabel -> axeslabel]          Fun[x, {-1, 2}, 400, {"x", "y"}]      ![enter image description here](http://i.stack.imgur.com/XRgbe.png) However, I'd like to rewrite it to use `OptionsPattern`               RewriteFun[x_Symbol, OptionsPattern[Plot]] :=        Plot[x^2, {x, -1, 2},          ImageSize -> OptionValue[ImageSize],          AxesLabel -> OptionValue[AxesLabel]]          RewriteFun[x, ImageSize -> 400, AxesLabel -> {"x", "y"}]      ![enter image description here](http://i.stack.imgur.com/pERvd.png) I have two problems.   * I don't know how to deal with an option like `{x, xmin, xmax}`.   * I don't how to get the kind of syntax coloring the varible `x` has in `Plot[x^2, {x, -1, 2}]`. ![enter image description here](http://i.stack.imgur.com/Ajifs.png) So my question is: How do I revise the `RewriteFun` to solve my problems?


title: Making sure that Timing[] isn't thrown off by caching

text: In playing with and comparing the various answers to my question here, I tried applying `Timing[]` to see how fast things ran, but it seemed that some of the answers (but not all of them) were a lot faster when run for a second time. How can I make sure that there isn't some kind of caching of intermediate results throwing off the `Timing[]`?


title: Why does JLink lock unopened jar-files in Windows

text: Since the introduction of `JLink` (maybe a bit later) it is possible to put jar libraries inside the directory-structure of packages. If this package is installed in one of the places Mathematica searches, the jar libraries are automatically found by `JLink`. The problem is that under 64 bit Windows XP, after loading `JLink` these files are locked and cannot be removed from within Mathematica, although none of the jars are really used, but only added to the class-path of Java. Let me give a short example: Place a `Test` folder with `Java` subfolder inside your `$UserAddOnsDirectory` and copy any jar file into the `Java` folder. This looks like               Test/     └── Java         └── blub.jar      When you now start a fresh Kernel and load `<<JLink`` you can verify by looking at `JavaClassPath[]`, that this directory and the jar was indeed added to the class-path. When you try to remove the complete folder, you get (a misleading) error message               DeleteDirectory[path, DeleteContents -> True]          (*         DeleteDirectory::dirne: Directory D:\Documents and Settings\mscheibe\         Application Data\Mathematica\Applications\Test not empty. >>     *)      After `Quit`-ing the kernel, calling `UninstallJava[]` or `JLink`QuitJava[]` the directory can be removed. This behavior does not occur in Linux or on MacOSX and I could only test it on `Windows XP 64 bit`. **Question:** Why, if the jar-path is only appended to the class-path, does `JLink` lock the files as they where opened for reading? Why does this happen on `Windows` only? Is there anyone, who has a deeper insight into `JLink` who can suggest a better solution that calling `JLink`QuitJava[]; Pause[2];` inside my module when I want to remove a jar-file found by Mathematica. **Remark 1:** This behavior is not restricted to automatically found jars. When you use java-code by manually adding a jar with `AddToClassPath[path]` the similar thing happens. **Remark 2:** I forgot to mention, that `JLink`QuitJava[]` does not really quit java like `Quit` would kill the kernel. Meaning, I call this and _without_ doing anything else I can still call my functions inside the jars. This seems to suggest, that `QuitJava[]` kills the class-loader instance Leonid is mentioning which locks the files. But a call to e.g. `JavaNew` seems to set up everything correct again.


title: Is it safe to launch/close kernels in the middle of a parallel calculation?

text: It appears that it is possible to launch additional kernels (or close existing ones) _during_ a parallel calculation. The newly launched kernels will be utilized for the rest of the calculation. Here's a simple way to test and illustrate this (in a fresh kernel):               LaunchKernels[2]          Parallelize[      Table[Pause@RandomInteger[20]; $KernelID, {i, 8}],      Method -> "FinestGrained"     ]      Now use `Evaluation -> Interrupt Evaluation...` to interrupt the evaluation and go into a subsession. In the subsession evaluate               $KernelCount (* check that we only have 2 kernels *)          LaunchKernels[4] (* launch 4 more *)          Return (* return from the dialog *)      Notice that when the `Table[]` finally finishes, we get results between 1 and 6 (I got `{2, 1, 6, 5, 4, 3, 2, 1}`). This means that all 6 kernels have been utilized during the rest of the evaluation, even though some kernels were only launched in the middle of the calculation. It is also possible to close some kernels during the calculation. In another test I got the following messages ... ![Mathematica graphics](http://i.stack.imgur.com/ePKP1.png) ... and the calculation seemed to finish correctly. **Question:** Is it safe to do this? Can this break anything if the timings are wrong? * * * Consider some code like this:               (* This uses LaunchKernels[] to launch more kernels        as compute resources become available: *)     manageKernels[] := ...          (* ensure that manageKernels[] is always evaluated on the master kernel *)     SetSharedFunction[manageKernels]           Parallelize[      Table[manageKernels[]; compute[i], {i, 100}],      Method -> "FinestGrained"     ]      Is this going to be safe? What if `manageKernels[]` uses `CloseKernels[]` as well?


title: Built-in Mathematica data: are they cached? how to speed up the loading?

text: Mathematica has numerous built-in data for **science** and **math**. Every first call to a data function in a new Mathematica session will "re-initialize indices" (download the data). Is there a way to store this data locally to save time on the next data call after Mathematica is restarted? ![enter image description here](http://i.stack.imgur.com/bUkv8.png) **======== Edit: further thoughts with Leonid's answer ========** After Leonid posted his answer, I decided to update this question – the title and content. I would ask about this anyway – so may as well do it here. The point is not in whether data were cached or not, but really in a method to speed up the load process. I just confused caching and loading. I do not want to take away “best answer” from Spartacus, because he did answer what I asked ideally, thanks. But thank you very much Leonid for posting your answer too. +1 to both of you.


title: Why these (error) messages?

text: Testing this answer I used:               stream = OpenWrite["A:\\out.txt"];          Block[{$Messages = stream},       Mod[1, 2, 3, 4, 5]     ]      and I was surprised to find that the contents of `out.txt` read: > >     Intersection::normal: >        Nonatomic expression expected at position \[NoBreak]\!\(\*StyleBox[2 >         , "MT"]\)\[NoBreak] in \[NoBreak]\!\(\*StyleBox[ >         Intersection[{StandardForm, TraditionalForm}, FormatType] >         , "MT"]\)\[NoBreak]. >> >   >     Intersection::normal: >        Nonatomic expression expected at position \[NoBreak]\!\(\*StyleBox[2 >         , "MT"]\)\[NoBreak] in \[NoBreak]\!\(\*StyleBox[ >         Intersection[{StandardForm, TraditionalForm}, FormatType] >         , "MT"]\)\[NoBreak]. >> >   >     Intersection::normal: >        Nonatomic expression expected at position \[NoBreak]\!\(\*StyleBox[2 >         , "MT"]\)\[NoBreak] in \[NoBreak]\!\(\*StyleBox[ >         Intersection[{StandardForm, TraditionalForm}, FormatType] >         , "MT"]\)\[NoBreak]. >> >   >     General::stop: Further output of > \[NoBreak]\!\(\*StyleBox[Intersection::normal >         , "MT"]\)\[NoBreak] will be suppressed during this calculation. >> >   >     Options::optnf: >        \[NoBreak]\!\(\*StyleBox[FormatType >         , "MT"]\)\[NoBreak] is not a known option for > \[NoBreak]\!\(\*StyleBox[ >         Intersection[OutputStream[A:\out.txt, 12], >          {OutputStream[stdout, 1], OutputStream[stderr, 2], >           OutputStream[A:\out.txt, 12], stdout, stderr}], "MT"]\)\[NoBreak]. > >> >   >     Options::optnf: >        \[NoBreak]\!\(\*StyleBox[FormatType >         , "MT"]\)\[NoBreak] is not a known option for > \[NoBreak]\!\(\*StyleBox[ >         Intersection[OutputStream[A:\out.txt, 12], >          {OutputStream[stdout, 1], OutputStream[stderr, 2], >           OutputStream[A:\out.txt, 12], stdout, stderr}], "MT"]\)\[NoBreak]. > >> >   >     Options::optnf: >        \[NoBreak]\!\(\*StyleBox[FormatType >         , "MT"]\)\[NoBreak] is not a known option for > \[NoBreak]\!\(\*StyleBox[ >         Intersection[OutputStream[A:\out.txt, 12], >          {OutputStream[stdout, 1], OutputStream[stderr, 2], >           OutputStream[A:\out.txt, 12], stdout, stderr}], "MT"]\)\[NoBreak]. > >> >   >     General::stop: Further output of \[NoBreak]\!\(\*StyleBox[Options::optnf >         , "MT"]\)\[NoBreak] will be suppressed during this calculation. >> >   >     Intersection::heads: >        Heads \[NoBreak]\!\(\*StyleBox[List >         , "MT"]\)\[NoBreak] and \[NoBreak]\!\(\*StyleBox[OutputStream >         , "MT"]\)\[NoBreak] at positions \[NoBreak]\!\(\*StyleBox[2 >         , "MT"]\)\[NoBreak] and \[NoBreak]\!\(\*StyleBox[1 >         , "MT"]\)\[NoBreak] are expected to be the same. >> >   >     Intersection::heads: >        Heads \[NoBreak]\!\(\*StyleBox[List >         , "MT"]\)\[NoBreak] and \[NoBreak]\!\(\*StyleBox[OutputStream >         , "MT"]\)\[NoBreak] at positions \[NoBreak]\!\(\*StyleBox[2 >         , "MT"]\)\[NoBreak] and \[NoBreak]\!\(\*StyleBox[1 >         , "MT"]\)\[NoBreak] are expected to be the same. >> >   >     Intersection::heads: >        Heads \[NoBreak]\!\(\*StyleBox[List >         , "MT"]\)\[NoBreak] and \[NoBreak]\!\(\*StyleBox[OutputStream >         , "MT"]\)\[NoBreak] at positions \[NoBreak]\!\(\*StyleBox[2 >         , "MT"]\)\[NoBreak] and \[NoBreak]\!\(\*StyleBox[1 >         , "MT"]\)\[NoBreak] are expected to be the same. >> >   >     General::stop: Further output of > \[NoBreak]\!\(\*StyleBox[Intersection::heads >         , "MT"]\)\[NoBreak] will be suppressed during this calculation. >> >   >     Mod::argt: \[NoBreak]\!\(\*StyleBox[Mod >         , "MT"]\)\[NoBreak] called with \[NoBreak]\!\(\*StyleBox[5 >         , "MT"]\)\[NoBreak] arguments; \[NoBreak]\!\(\*StyleBox[2 >         , "MT"]\)\[NoBreak] or \[NoBreak]\!\(\*StyleBox[3 >         , "MT"]\)\[NoBreak] arguments are expected. >> >   I expected only the last message. This looks like the result of a misconfiguration or Style Sheet problem but I don't know what it is. Do others get these messages? If yes, what is the explanation? If not, what might I have done to cause this?


title: How do I plot two Gaussians/normal distributions with 2 different means and 2 different standard deviations?

text: This is probably very easy for someone with more experience, but I am trying to plot only two Normal distributions, but for some reason my Method plots 4, instead of 2. I have:               Plot[Evaluate@       Table[PDF[NormalDistribution[μ, σ], x],             {μ, 6, 7}, {σ, 1, 2}],       {x, 0, 12}, Filling -> Axis]      which plots: ![enter image description here](http://i.stack.imgur.com/N8qyI.jpg) My intention was to plot $Normal(\mu_1,\sigma_1)$ and $Normal(\mu_2,\sigma_2)$ instead of all the 4 possible combinations of them. Thanks!


title: Plot in cylindrical coordinates

text: I am trying to plot a simple vortex in cylindrical coordinates give by $v_{\phi} = \frac{\Gamma}{2 \pi r}$ Is there an alternative method to plot this than, for example, using streamplot and converting r and the cylindrical unit vector $\vec{\phi}$ to cartesian rectangular coordinates?


title: Trouble combining planet orbits and positions in Graphics3D and Show

text: I am building an animated model of the solar system, where I would like to display the `OrbitPath`s of the planets along with their `Position`s at any one point in time. I would like to display the orbital paths as lines, just as they are given when inputting `AstronomicalData["Earth", "OrbitPath"]`. I'd like to display the positions as `Sphere`s though. For some reason, even though I am combining the two graphical elements, only the spheres are displaying, and I cannot see the orbit lines at all. Would anyone be able to pinpoint what I am doing wrong in my code?               Animate[      Show[       Graphics3D[        AstronomicalData[#, "OrbitPath"] & /@ AstronomicalData["Planet"]],        Graphics3D[        Sphere[AstronomicalData[#, {"Position", DateList[x][[;; 3]]}] & /@           AstronomicalData["Planet"], 5*10^10]]       ], {x, 1, 10000000000}, AnimationRate -> 100000000      ]      For the record, I tried putting the graphics primitives in a single `Graphics3D` and combining the spheres and lines into a single list of primitives, but that was throwing up too many problems so I figured this way would be more straightforward.


title: Mathematica cannot find CUDA driver

text: I have successfully installed CUDA 5.0 on my Ubuntu 12.10, with driver 304.54, toolkit and samples. Running deviceQuery gives me a successful output:                   Detected 1 CUDA Capable device(s)                Device 0: "GeForce 9500 GT"           CUDA Driver Version / Runtime Version          5.0 / 5.0           CUDA Capability Major/Minor version number:    1.1           Total amount of global memory:                 512 MBytes (536543232 bytes)           ( 4) Multiprocessors x (  8) CUDA Cores/MP:    32 CUDA Cores                etc...      bandwidthTest is also successful:                    Device 0: GeForce 9500 GT          Quick Mode               Host to Device Bandwidth, 1 Device(s)          PINNED Memory Transfers            Transfer Size (Bytes)    Bandwidth(MB/s)            33554432         5628.6               etc...      I stress that my card is listed among the compatible CUDA cards for Mathematica. However, in Mathematica 9.0.1.0, running                   Needs["CUDALink`"]         CUDAQ[]      returns                   False      running                   CUDAInformation[]      returns                   CUDAInformation::invdriv : CUDA was not able to find a valid CUDA driver.         Refer to CUDALink System Requirements      and running                   CUDADriverVersion[]      returns                   CUDADriverVersion::nodriv :          CUDALink was not able to locate the NVIDIA driver binary.         Refer to CUDALink System Requirements      So it cannot find both the binary and the libraries, and referring to the CUDALink system requirements help page is not helping. Any ideas?


title: Using Findroot within a loop

text: I am trying to get solution to an equation in a loop. The isolate equation works               rb = 2;     ri[x_] := FindRoot[y - ArcTan[y] - x == 0, {y, 0.01}]     ri[0.02151]     srb = y /. %     s = srb/rb     rinv = (s^2 + rb^2)^(1/2)      However, when I try to do it repeatedly with a `While`, `Do` or any other command, I do not get a solution for `y`. Any clues?               rb = 2;     ri[x_] := (FindRoot[Tan[y] - y - x == 0, {y, 0.01}];       srb := y /. %;       s := srb/rb;       rinv := (s^2 + rb^2)^(1/2))     i = 0.001;     While[i < 0.004, ri[i]; Print["i ", i]; Print["s ", s];        i = i + 0.001];      Thanks!


title: Multiplicate in an Integration with time

text: I am calculating the area of a step response. I try to use this Integral Criterion for my Calculation. The time t is multiplicated with the control error xd raised to the second power. ![enter image description here](http://i.stack.imgur.com/MvIzP.png) The problem is, that I dont know how to multiplicate the time with the control error xd in Mathematica. So my Integral looks like this: ![enter image description here](http://i.stack.imgur.com/pAbtd.png) My code is:                 fp2pi[tn_, kpr_, kps_, t1_, t2_?NumberQ] :=        NIntegrate[(1 - (InverseLaplaceTransform[(kpr kps (1 + 1/(s tn)))/(             s (1 + s t1) (1 + s t2) (1 + (                kpr kps (1 + 1/(s tn)))/((1 + s t1) (1 + s t2)))), s,              t]))^2, {t, 0, Infinity}, WorkingPrecision -> 5];      Here I am writing the function in a list, with different values for tn:               list = {};     Do[{values = Function[x, fp2pi[x, 3, 1, 1, 2]] /@ {i},         AppendTo[list, values]        }, {i, 1, 5}];     Print[list];      Thank you :)


title: Trouble with Flatten[]

text: I made this function:               f[g_] := Table[{ToExpression[ToString[x] <> ToString[n]], 1, 3}, {n, 1, g}]      When I evaluate the function with some g (say 8), I'll have this output:               {{x1, 1, 3}, {x2, 1, 3}, {x3, 1, 3}, {x4, 1, 3}, {x5, 1, 3}, {x6, 1, 3}, {x7, 1, 3}, {x8, 1, 3}}      When I add flatten to the function:               f[g_] := Flatten[Table[{ToExpression[ToString[x] <> ToString[n]], 1, 3}, {n, 1, g}]]      I'll have:               {x1, 1, 3, x2, 1, 3, x3, 1, 3, x4, 1, 3, x5, 1, 3, x6, 1, 3, x7, 1, 3, x8, 1, 3}      When I actually want:               {x1, 1, 3}, {x2, 1, 3}, {x3, 1, 3}, {x4, 1, 3}, {x5, 1, 3}, {x6, 1, 3}, {x7, 1, 3}, {x8, 1, 3}      I have also tried to use the `Flatten[]` with a level:               f[g_] := Flatten[Table[{ToExpression[ToString[x] <> ToString[n]], 1, 3}, {n, 1, g}], 1]      But I was unable to do it. What's happening? I could do it with string manipulation, but I guess there might be a way for `Flatten[]` to work. I'm trying to do this:               ArrayPlot[Table[RandomChoice[{q1, q2, q3} -> Range[1, 3]], {q1, 1, 3}, {q2, 1, 3}, {q3, 1, 3}], Mesh -> True, MeshStyle -> Black]      Where the result of the function is going to replace the `{q1, 1, 3}, {q2, 1, 3}, {q3, 1, 3}`.


title: How to sum up subelements of a list of unknown length

text: I'm simply looking for the `{}+{}` function for sublist elements of a list: (Parallel sums of elements)               c = {{1, 2, 3, 4}, {8, 7, 6, 5}};     Plus[c]     Mean[c]       desired={9, 9, 9, 9}      Where `Mean` does directly what it's supposed to, unfortunately `Plus` doesn't. I tried `Take` and `Part` but they both do not seem to work here . Additionally, my `c` consists of a varying number of elements. I tried to work with `Length[c]` and `Range` .. (`{}+{}` is no solution as list element number varies) thank you for help!!


title: Selectively converting numerical strings to expressions

text: I have a list of strings representing different types of data               {{"gw12-26b-pl1", "63.6512", "0.0076", "--", "Al2O3", "%", "23.4002"},      {"gw12-26b-pl3", "65.1182", "0.1257", "--", "SiO2", "ppm", "76.3388"}};      I want to convert the 'numerical strings' to expressions so that I can work with them. I want to end up with something like:               {{"gw12-26b-pl1", 63.6512, 0.0076, "--", "Al2O3", "%", 23.4002},      {"gw12-26b-pl3", 65.1182, 0.1257, "--", "SiO2", "ppm", 76.3388}}      I tried to convert the whole list using `ToExpression` and then convert non- numeric elements back to strings but this doesn't work because it is trying to evaluate elements like `gw12-26b-pl1`as an expression. Can anyone suggest an easy way to do this?


title: How can I draw a Cuboid given its center and its dimensions?

text: I want to draw a Cuboid accroding to the coordinates of its geometric center and its dimensions, rather than its diagnoal coordiantes. And How can I draw a triangular prism?


title: Color lost when saving Mathematica cell as HTML

text: Question 1(Color Lost Question[Solved by using `Item`]): When I evaluate the cell generated by               Grid[WordData /@ {"what","my"}, Frame -> True,        Background -> {None, {LightRed, Pink}}]      ![enter image description here](http://i.stack.imgur.com/SSGH8.jpg) ![enter image description here](http://i.stack.imgur.com/qtSIh.jpg) it looks good in my notebook, but the color get lost when I save the notebook as an HTML file. The same thing happens with some other functions, such as `Column`. I've spent some time to solve the problem and I found a solution which can partly solve the problem is to use `Item` to set the background colour. However, the `ItemSize` is still not working properly when the notebook is saved as HTML format. Here is the code:               Column[Table[Grid[Map[Item[Text@Style[#, FontSize->50,        FontColor->RGBColor@@RandomReal[{0,1},3]],        Background->RGBColor@@RandomReal[{0,1},3],        FrameStyle->AbsoluteThickness[3]]&,        resultListToUse[[i]],{2}],        Alignment->{{Center,Center,Center}},        Frame->All,        ItemSize->{20,5},        Spacings->{{20,20,20},1}],{i,Length@resultListToUse[[1;;4]]}],        Background->LightRed]      Here is my sample blog: quaternions.blog.163.com/blog/static/206082147201323095141897 Now I can select the words in the colored frame, however the words in one row are two tight with no enough spaces. Because some options such like `ItemSize` and `Spacings` didn't work properly when the notebook is saved as .html question2(Spaces Lost question): I want to convert the cell generated by `Grid` to HTML format with content is "Plaintext". I found that the `ItemSize` setting will no longer work properly when convert the output cell to HTML format. As cormullion show in the answer, when The output content in HTML is gif pictures, they looks good. How to make the words in one row with enough spaces?


title: Auto-complete for user defined functions

text: If I define a symbol in Mathematica, it doesn't show up in the autocomplete list that works for symbols in `System`. Test code:               foo = 1;     bar[x_] := x + 1     $ContextPath     Context@foo     Context@bar     (* =>          {Notebook$$35$859131`, System`}          Notebook$$35$859131`          Notebook$$35$859131`     *)      Neither `foo` nor `bar` will show up in the autocomplete list. Is it possible to make `foo` and `bar` show up in this list, without defining them in the `System` context? **Edit:** It works if I switch to the `Global` context, however I would like to have a separate context for each notebook. The question is then if you can add the notebook specific contexts to the autocomplete contexts?


title: How to blend some colors on a curve

text: I need to define a color gradient on a 3D curve, but I'm having some problems with this. Suppose we have a 3D curve defined as a parametric function of some real variable `phi` :               curve[phi_] := {...};      where `phi` runs from `phi1` to `phi2`. Now, I defined the **start** , **middle** and **end** colors like this :               Color1 := RGBColor[0.99, 0.2, 0.2, 0.2];     Color2 := RGBColor[0.2, 0.99, 0.2, 0.8];     Color3 := RGBColor[0.2, 0.2, 0.99, 0.2];          CurveColor[phi_] = Blend[{Color1, Color2, Color3}, phi];      The last definition doesn't work. I need the function `CurveColor[phi]` to output four real **positive** numbers **smaller than 1** , like this :               CurveColor[phi1] := {0.99, 0.2, 0.2, 0.2}     CurveColor[phi2] := {0.2, 0.2, 0.99, 0.2}      The colors should **blend smoothly** between `Color1` to `Color2` to `Color3`, and be uniformly distributed along the interval `phi1` to `phi2`). So how should I define that color function ? I don't need that function to be used in a plot3D. I only need the color data as a list of numbers. Please, notice that I'm working with _Mathematica 7_.


title: Strange behaviour of PolyLog Function

text: I discovered some strange behaviour of the `PolyLog[]` Function in _Mathematica_ which seems to me like a bug in the function implementation. It looks like `PolyLog` is breaking down for big arguments and non-integer orders               In[1]:=  -PolyLog[5/2, -E^500] // N     Out[1]:= 2.691151407447062*10^8626 + 9.87331945684138*10^8623 I      which is for sure incorrect. For such big arguments the `PolyLog` function has nice asymptotic approximations (which are e.g. used for complete Fermi-Dirac Integrals which are related to `PolyLog`'s) through $F_n(x)=-\mathrm{Li}_{n+1}(-e^x)$. This can be demonstrated by using even orders for the `PolyLog[]` with similar big arguments               In[2]:=  -PolyLog[4, -E^500] // N     Out[2]:= 2.60437*10^9      if compared to the asymptotic approximation $\frac{u^n}{\Gamma(n+1)}$ of $-\mathrm{Li}_n(-e^u)$               In[3]:=  u^4/Gamma[5] /. u->500 //N     Out[3]:= 2.60417*10^9      the results look o.k. The expected result of above given argument `E^500` and order `5/2` should be               In[4]:=  u^(5/2)/Gamma[5/2 + 1] /. u -> 500 // N     Out[4]:= 1.68209*10^6      I assume that the function algorithm somehow gets troubles with internal accuracy. Any ideas to "tell" _Mathematica_ to increase the accuracy for the numerical calculation?


title: How to check an algebraic number for membership in a list

text: I need to check an algebraic number for membership in a list of algebraic numbers. The numbers can be expressed in different forms (combinations of radicals, `Root` objects, trig functions), but the check should be exact. Now I use the following code:               ContainsAlgebraicQ[list_, a_] :=        MatchQ[Intersection[ list, {a}, SameTest -> (MinimalPolynomial[#1 - #2] === (#&) &)], {_}]      but in some cases evaluation of `MinimalPolynomial` takes significant time, although I only want to check the difference for zero. Is there a better approach for my task?


title: WeatherData acquirement in ListStreamPlot

text: I am trying to show the wind streams in a geographic area as following code for a range of time.Even if it works for realtime data but it doesn't work for range of time.I am filtering and also taking mean and it has no problem there.Could somebody help me please?                ListStreamPlot[Table[{{x, y},Through[{Cos, Sin}[Mean[DeleteCases[WeatherData[{y, x},      "WindDirection", {{2013, 5, 28}, {2013, 5, 29}}][[All, 2]],          Missing["NotAvailable"]]] \[Degree]]]}, {x, 20, 56, 4}, {y, 32,57, 4}]]


title: SparseArray row operations

text: Given a large (very) sparse matrix, A, how can I efficiently "operate" on only the nonzeros in a given row? For example: For each row in A, generate a list of column indices that have a magnitude (absolute value) greater than a threshold, r. My current approach is similar in spirit to a previous answer by Leonid (Efficient way to combine SparseArray objects?). I shamelessly steal his implementation of `spart`. **My current approach** First, let's build a random `SparseArray` for testing purposes.               randomSparseArray[n_Integer, r_Integer] := SparseArray[       Table[{Random[Integer, {1, n}], Random[Integer, {1, n}]} ->RandomReal[],{r}]     ,{n, n}];          A = randomSparseArray[10, 20]; (*10x10 matrix with 20 nonzeros*)      When `Part` is used to grab a row of `A`, a `SparseArray` representation is returned. Okay so let's rip this representation apart into its raw form using `spart`. For example the 3rd row of `A`               HoldPattern[spart[SparseArray[s___], p_]] := {s}[[p]];         raw = spart[A[[3]], 4];     (*{1, {{0, 2}, {{10}, {5}}}, {0.534313, 0.981372}}*)      And then use a combination of `Part` and `Position` to extract the column indices from `raw` . (here I use a threshold of 0.5)               ind = Flatten@Position[Flatten@raw[[3]],x_/;Abs[x]>0.5];     Flatten[raw[[2, 2]]][[ind]]      Wrapping this all up into a function:               thresholdIndex[A_SparseArray, r_] := Module[{raw, ind},     raw = spart[A, 4];     ind = Flatten@Position[Flatten@raw[[3]], x_ /; Abs[x] > r];     Flatten[raw[[2, 2]]][[ind]]     ]      We can now use `Map` to hit each row of `A` and search for column indices for elements with magnitudes greater than say, 0.5               Map[thresholdIndex[#, .5] &, A]      This whole process feels a little roundabout. First Mathematica has to extract a new `SparseArray` representation of a row (is this expensive?), we then chop it into pieces in order to work on it. Is there an easier way to do this while still maintaining performance? My other idea is to apply `spart` to the original matrix and work with the CSR (compressed-sparse-row) representation. But this seems to defeat the purpose of even using a `SparseArray` from the get go. **Sidebar** I've been starting to implement an efficient algebraic multigrid (AMG) package in Mathematica. AMG is a fast iterative method traditionally used to solve large sparse matrix equations produced from the discretization of elliptic PDEs. One of the steps in the algorithm is very similar in flavor to `thresholdIndex`. As a sidebar, does anyone know if a nice AMG has been implemented in Mathematica? I would like to build a tool similar to PyAMG (http://code.google.com/p/pyamg/).


title: Basic question on producing non-overlapping graph nodes in a graph

text: I am plotting a graph which has about 196 nodes.               GraphPlot[{1 -> 24, 2 -> 24, 20 -> 364, 20 -> 779, 21 -> 130, ...                    378 -> 386, 492 -> 841, 779 -> 783, 839 -> 841},           DirectedEdges -> False, VertexLabeling -> True,           Method -> "SpringElectricalEmbedding",           PackingMethod -> "ClosestPackingCenter"]      However when the output is produced it looks like below where many of the nodes are overlapping. How to tell Mathematica to produce a large picture so that no nodes overlap. True this might not be practical for very large graphs, but for 196 nodes, I would like no node to overlap another. ![enter image description here](http://i.stack.imgur.com/ehQwc.jpg)


title: Calculating pleasant colors for source code or web-design

text: I really like when the programs or editors I use have pleasant colors. Sometimes when there's nothing else to do or sometimes when there are very important, but incredibly boring things to do, I find myself tweaking color and font settings to make everything as comfortable as possible for me. This was one reason why I asked this question some time ago and it is the reason why I really appreciate people like Ethan Schoonover who invented the solorized color palette. Although his colors are nice, you cannot always use them because sometimes your IDE has maybe a _color basis_ you would like to keep because icons and buttons work nice with it. This is the case with the new Dracula theme of IDEA. Below is a screenshot of a method. Although the colors look good, there are details which I don't like   * The annotations (@Nullable) are too bright and the greenish yellow is ugly   * The method name is a bit too bright   * The green and red background selection is too colorful for my taste   * Finally, the normal font-color is a bit too bright to be calming.  ![enter image description here](http://i.stack.imgur.com/nx0vQ.png) **Question:** Can we use _Mathematica_ (and mathmatics) to create a custom set of colors   * which can be integrated into an existing color environment   * which play nicely together   * where no color catches all attention


title: Scoping in recursive function leading to unexpected results

text: I'm trying to implement Ramer-Douglas-Peucker line simplification in _Mathematica_ , and I'm running into an issue with recursion. My implementation of the algorithm is below:               RDP[points_, ϵ_] := (       Print[points];       start := points[[1]];       end := points[[-1]];       vec := Normalize[end - start];       dist[p_] := (         t := Dot[(p - start), vec];         loc := start + t*vec;         Norm[loc - p]         );       distances := Map[dist, points];       maxdist := Max[distances];       maxelem := FirstPosition[distances, maxdist][[1]];       res := If[maxdist < ϵ,         {start, end},         p0 := points[[1 ;; maxelem]];         p1 := points[[maxelem ;;]];         fst := RDP[p0, ϵ];          Print["Run with p1 = ", p1];         snd := RDP[p1, ϵ];         Join[fst, snd];         ];       Print["result ", res];       res       )     line := {{0, -1}, {5, 5}, {5, 16}, {11, 23}}     Block[{$RecursionLimit = 25}, RDP[line, 1]]      I'm getting a very strange result. A snippet of the output: > >     {{0,-1},{5,5},{5,16},{11,23}}   >     Run with p1 = {{5,16},{11,23}}   >     {{0,-1},{5,5},{5,16}}   >     Run with p1 = {{5,5},{5,16}}   >     {{0,-1},{5,5}}   >     result {{0,-1},{5,5}}   >     {{0,-1},{5,5},{5,16}}   >     Run with p1 = {{5,5},{5,16}}   >     {{0,-1},{5,5}}   >     result {{0,-1},{5,5}}   >     {{0,-1},{5,5},{5,16}}   >     Run with p1 = {{5,5},{5,16}}   >     {{0,-1},{5,5}}   >     result {{0,-1},{5,5}}   >     {{0,-1},{5,5},{5,16}}   >     Run with p1 = {{5,5},{5,16}} >   It looks like `p0` and `p1` are set correctly after the split, and I can verify that the recursive call succeeds when it's called on `p0`. However, on the second recursive call, the value passed into the function is not the value that the function actually runs on; you can see that, when p1 is set to `{{5,16},{11,23}}`, `RDP[p1, ϵ]` actually runs with points set to `{{0,-1},{5,5},{5,16}}`. I'm not the most experienced _Mathematica_ user, and this is my first time implementing this sort of recursive function, so I might be missing something pretty simple. Any help or pointers welcome!


title: Subset of edges with a different color

text: I want to color a subset of the edges of my graph with a different color. My graph currently has a large number of edges, so the following is just a toy example               s = {1->2,1->3}     g = {1->2, 1->3,3->4,4->1}     GraphPlot[g,VertexLabeling->True]      Here `s` is a subset of `g` I would like to tell `GraphPlot` to plot the edges in `s` with a different color, and make the edges of `s` directed. How to do this? * * * EDIT: The closest I have coming after looking at some answer to another question on this site is               s = {{1,2},{1,3}}     g = {1->2, 1->3,3->4,4->1}     GraphPlot[g,VertexLabeling->True,EdgeRenderingFunction -> (If[          Intersection[s, {#2}] != {}, {Red ,Arrow[#1, .1]},                                        {Blue,Arrow[#1, .1]}] &)]      However, since I want the complement of the set `s` in `g` to be represented as blue segment (and not an arrow) I am not sure what I should write in place of `Arrow` inside `{Blue,Arrow[#1, .1]}` above.


title: Can mathematica simplify an expression setting simplified answer equal to zero?

text: Basically I want to reduce something like:               Subscript[P, 4] - Subscript[P, 5] == Subscript[R, 4, 5]* Subscript[i, 4, 5]      when only one of them is known (`Subscript[R, 4, 5] == 1`), so that _Mathematica_ expresses the simplified form as:               Subscript[i, 4, 5] + Subscript[P, 5] - Subscript[P, 4] == 0


title: Why Can't Mathematica Integrate this?

text: I have the following problem from a textbook I am trying to integrate: ![enter image description here](http://i.stack.imgur.com/gCjLN.png) So, following the directions in text, I am required to integrate each function. However, I cannot get Mathematica to integrate the first function. Here is my code:               Z1 := E^-x^2*Cos[x^2 + y^2]     Z2 := 2 - x^2 - y^2     Plot3D[{Z1, Z2}, {x, -1, 1}, {y, -1, 1}, AspectRatio -> 1, ViewPoint -> {4, 1, 1}]     Integrate[Z2, {y, -1, 1}, {x, -1, 1}] - Integrate[Z1, {y, -1, 1}, {x, -1, 1}]      They plot OK: ![enter image description here](http://i.stack.imgur.com/mnZSr.png) but give me really strange output: ![enter image description here](http://i.stack.imgur.com/rWvpA.png) Could someone please explain how I can overcome this? Wolfram|Alpha can evaluate it without (much) trouble. Thank you for your time.


title: Why does saved graphic not look the same as graphic in notebook?

text: g1 = Plot[(x^2 - 4 x + 3)/(x + 1), {x, -5, 5}];          Rotate[g1, -90 Degree]      After saving the output of the rotated graph, I still get the graph of `g1`. ![enter image description here](http://i.stack.imgur.com/UZock.png) I get ![enter image description here](http://i.stack.imgur.com/MCf0V.jpg)


title: PolynomialReduce not working

text: I have a polynomial $f(x_1, x_2, \ldots , x_n)$ with coefficients in $Z[q,t]$, and I have a list of polynomials $g = g_1, g_2, \ldots , g_k$ where they are also polynomials in $(x_1, x_2, \ldots, x_n)$ and with coefficients in $Z[q,t]$. (Note that we are using specific values of $n$, like $n=3$ or $4$.) I am using PolynomialReduce$[f, \\{g\\}, \\{q,t\\}]$ to try to find the coefficients when $f$ is written as a $Z[q,t]$ linear combination of polynomials in $g$. However Mathematica always ouputs coefficients with $x_1, x_2,$ etc. when I only want $q$ and $t$ to be in the coefficients. Update: Upon suggestion, I also tried PolynomialReduce$[f, \\{g\\}, \\{x_1,x_2, \ldots x_n\\}]$ for the input, but mathematica still outputted coefficients with $x_1$, $x_2$, etc. For a couple of test cases I tried, I know for a fact that $f$ can be expressed as a $Z[q,t]$ linear combination of polynomials in $g$, so that is not the issue. Why is this happening? What can I do to fix it?


title: After editing a file Mathematica 10 interprets [...]^2 as [...(])^2

text: This is a very weird bug and I don't really know how to reproduce it, so I'll just copy-paste the whole code               Manipulate[Row[{DensityPlot[     Cos[k Norm[{x, y} - d {0, 2}] - f Pi t]/Norm[{x, y} - d {0, 2}] +       Cos[k Norm[{x, y} - d {0, -2}] - f Pi t]/       Norm[{x, y} - d {0, -2}], {x, 0, 10}, {y, -5, 5},        PlotPoints -> 50, ImageSize -> 300, PlotTheme -> "Minimal"],      Rotate[Plot[(200 + Abs[-2 d + y]^2 + Abs[2 d + y]^2 + 2 Sqrt[(100 + Abs[-2 d + y]^2) (100 + Abs[2 d + y]^2)]Cos[k (Sqrt[100 + Abs[-2 d + y]^2] - Sqrt[100 + Abs[2 d + y]^2])])/(2 f (100 + Abs[-2 d + y]^2) (100 + Abs[2 d + y]^2)), {y, -5, 5}, ImageSize -> 280], -Pi/2]}], {t, 0, 15}, {{f, 5}, 1, 10}, {{k, 5}, 1, 10}, {{d, 1}, 0.5, 3}]      Basically this is a simulation of the double-slit interference experiment with a plot of the intensity to the right. Note that **all the squares have to be written by Ctrl-6** so that they are superscript! So, the code looks like this when I open the notebook ![enter image description here](http://i.stack.imgur.com/9ggm8.png) Now try changing the `PlotTheme` by adding a second name, like `"Monochrome"`. Suddenly, all brackets and parentheses go red. Upon evaluation, Mathematica spits out errors as if there are no closing brackets. It seems like everything breaks down the moment I enter the quotation marks `""`. It is possible that this is a Mac-only bug. ![enter image description here](http://i.stack.imgur.com/s6xHe.png)


title: Get the unevaluated expression from a numbered cell

text: If a cell exists as below:               In[1] := (xyPoints = {{1,2},{2,5},{3,10}}; ListLinePlot[xyPoints])      Is it possible to get at the expression rather than the plot shown in Out[1]. In other words, can I somehow get the held CompoundExpression in In[1] rather than the evaluated plot?


title: SmoothDensityHistogram with logarithmic density

text: Is there a simple way for making `SmoothDensityHistogram` plots have logarithmic scaling for the density? With `DensityHistogram` it's a simple matter of `{"Log","PDF"}` for the _hspec_ argument, but `SmoothDensityHistogram` doesn't have a native option.


title: How to visualize Riemann surfaces?

text: In `WolframAlpha` we can easily visualize Riemann surfaces of arbitrary functions, ![enter image description here](http://i.stack.imgur.com/N1UD4.png) can we plot the Riemann surface of an arbitrary function using _Mathematica_ and with a better color scheme like these plots so that I can see the connection of the branches? ![enter image description here](http://i.stack.imgur.com/ytb0N.png) _Edit_ Here are more Riemann surfaces by Matthias Nieser et. Automatic Generation of Riemann Surface Meshes ![enter image description here](http://i.stack.imgur.com/fM007.png) ![enter image description here](http://i.stack.imgur.com/aSGVr.png) ![enter image description here](http://i.stack.imgur.com/wKssT.png) related: How can I recreate Trott's Riemann Surface plot in Mathematica? Visualization of Riemann Surfaces of Algebraic Functions Automatic Generation of Riemann Surface Meshes


title: Simplifying an ArcTan expression

text: The expression $\tan ^{-1}\left(\frac{\sqrt{L^2 \sin ^2(\theta )}}{\sqrt{L^2 \cos ^2(\theta )}}\right)$ can be simplified to $\theta$. After some attempts I got the following to do the job.               ArcTan[Sqrt[L^2 Cos[θ]^2], Sqrt[L^2 Sin[θ]^2]] //      PowerExpand // TrigToExp // Simplify // PowerExpand      It appears rather clunky to me. Is there a better way to simplify this expression.


title: Graphics copy paste

text: Background. I have a function ( stored in a package ) that creates 2D graphic images, its prototype looks like this:                 question[wi_, he_, co_] :=        DynamicModule[{},         Manipulate[           Graphics[{Translate[{color, Rectangle[{0, 0}, {.8, .4}]},              Tuples[{Range[width], Range[heigth]}]]}],          {color, Red}, {width, 1, 5}, {heigth, 1, 5},           Initialization :> {color = co, width = wi, heigth = he}]]       In the actual function the Graphics function is enclosed in a Dynamic[]. The function works as expected. Something that I don't understand happens when I do the following: 1) right- click ( Windows ) on an image and paste the image to elsewhere in the notebook; 2) repeat this for several different width / height combinations. 3) save the notebook 4) open the notebook 5) execute the function but with a different color, THEN: the color of the pasted images changes as well. **Question: How can I permanently copy and paste ( not, in any way, linked to code ) a graphic created in a Notebook with Graphics2D?** EDIT(2) per request of halirutan : Cell[BoxData[ GraphicsBox[GeometricTransformationBox[GeometricTransformationBox[ DynamicBox[Typeset`ToBoxes[ MapThread[FE`Y2`Y2`Private`fun$$93, {FE`Y2`Y2`Private`ptlst$$93, FE`Y2`Y2`Private`tplst$$93, FE`Y2`Y2`Private`colst$$93}], StandardForm, Graphics], ImageSizeCache->{{89.7606933090101, 182.2393066909899}, {81.76069330901011, 169.2393066909899}}], {{{{1, 0}, {0, 1}}, {0, 0}}, {{{-1, 0}, {0, 1}}, {1, 0}}, {{{1, 0}, {0, -1}}, {0, 1}}, {{{-1, 0}, {0, -1}}, {1, 1}}}], {{{0, 0}}, {{-0.7071067811865475, 0.7071067811865475}}, {{0.7071067811865475, 0.7071067811865475}}, {{0, 1.4142135623730951`}}}], PlotRegion->Automatic]], "Input"]


title: Get the coordinates from ContourPlot and RegionPlot

text: How do I get the coordinates from a contour plot I've done in _Mathematica_? For example, I have a two-variable function `f[x, y]`, for which I can make a contour plot:                   contour = ContourPlot[f[x, y] == 1, {x, -1, 1}, {y, -1, 1}];      I can access a nested list, containing lists of coordinates, from an exported file using                   Export["output.m", contour, "TEXT"]       but the nested list is inside the function `Graphics`. I would like to export only the corresponding nested list. What is a straightforward way to do that? Is there a way of doing that by manipulating directly the variable `contour`? **Edit** @Jens solution was                   Cases[Normal@contour, Line[x_] :> x, Infinity]      Is there a way to generalize it? The issue is that `Line` won't give us the points inside a region. E.g., I would like to get the coordinates corresponding to a region plot:                   region = RegionPlot[f[x, y] > 1, {x, -1, 1}, {y, -1, 1}];


title: Traces of products of Pauli matrices

text: Given a matrix $M$ of shape $2^L*2^L$, I would like to compute all the traces $\text{Tr}( M.(\sigma^{n_1}\otimes\sigma^{n_2}\otimes\ldots\otimes\sigma^{n_L})) $ for $n_1=1...4$, $n_2=1...4$, ..., $n_{L}=1...4.$, where $\sigma^n$ are the Pauli Matrices for $n=1..3$ and the identity for $n=4$. I can do this for specific values of $L$, but how do I write a function of $M$ and $L$ only that will perform this computation?


title: BarChart with ScalingFunctions -> "Log", Fixed axis

text: I want to make an animated `BarChart`. In this I want to plot different tables which range from $10^{-60}$ to $1$. For example:               {0.1,0.2,10^-3,10^-16,0.01,10^-20}      and the next data set goes to:               {0.11,0.19,10^-2,10^-12,0.0001,10^-10}      However, I can't set the `BarChart` with `ScalingFunctions->"Log"` to only start if a number for the chart is higher than $10^{-12}$. Does anyone know a way to fix this? P.S.: I already tried `PlotRange->{10^-12,1}`. Doesn't work though.


title: A problem on generating convex hull

text: For example, I typed the following:               data3D = {{3, -1, -6}, {3, -3, -4}, {1, 1, -6}, {1, -3, -2}, {-1,  1, -4}, {-1, -1, -2}};       Needs["TetGenLink`"];      {pts, surface} = TetGenConvexHull[data3D]      But I couldn't get the needed points and surfaces to generate a convex hull, instead I got error messages. How can I make it work or fix it?