Wrong computation with N

I was trying to solve this problem using Mathematica 8.04. I did this:               f[n_] := 2 Cos[2^(-1 + n) ArcCos[5/2]]     Table[{n, N[f[n+1]/Product[f[k], {k, 1, n}]]}, {n, 1, 20}]      and I got               {{1, 4.6 + 0. I}, {2, 4.58261 + 0. I}, {3, 4.58258 + 0. I}, {4,      4.58258 + 0. I}, {5, 4.58258 + 0. I}, {6, 4.58258 + 0. I}, {7,      4.58258 + 0. I}, {8, 4.58258 + 0. I}, {9, 0. + 0. I}, {10,      0. + 0. I}, {11, 0. + 0. I}, {12, 0. + 0. I}, {13, 0. + 0. I}, {14,      0. + 0. I}, {15, 0. + 0. I}, {16, 0. + 0. I}, {17, 0. + 0. I}, {18,      0. + 0. I}, {19, 0. + 0. I}, {20, 0. + 0. I}}      There is something wrong after `n=9`:               N[f[10]/Product[f[k], {k, 1, 9}]]     0. + 0. I     N[f[10]]/N[Product[f[k], {k, 1, 9}]]     4.58258 + 0. I      What is the problem here? I think the first input should be more accurate than the last one.


How to make noncommutative multiplication agree with commutative multiplication

I need a noncommutative multiplication that is   1. Associative   2. Distributive   3. $A**0=0$, $A**1=A$   4. Agrees with the commutative multiplication ($A**(k B)=(k A)**B=k (A**B)$) I have found a code               Unprotect[NonCommutativeMultiply];     Clear[NonCommutativeMultiply]          (*Factor out numerics -- could generalize to some ScalarQ*)     nc : NonCommutativeMultiply[a__] /; MemberQ[{a}, _?NumericQ] :=        NCMFactorNumericQ[NCM[a]] /. NCM -> NonCommutativeMultiply          (*Simplify Powers*)     b___ ** a_^n_. ** a_^m_. ** c___ :=        NCM[b, a^(n + m), c] /. NCM -> NonCommutativeMultiply          (*Expand Brackets*)     nc : NonCommutativeMultiply[a___, b_Plus, c___] :=        Distribute[NCM[a, b, c]] /. NCM -> NonCommutativeMultiply          (*Sort Subscripts*)     c___ ** Subscript[a_, i_] **Subscript[b_, j_] ** d___ /; i > j :=        c ** Subscript[b, j] ** Subscript[a, i] ** d     Protect[NonCommutativeMultiply];          Unprotect[NCM];     Clear[NCM]     NCMFactorNumericQ[nc_NCM] :=        With[{pos = Position[nc, _?NumericQ, 1]}, Times \@@ Extract[nc, pos] Delete[nc, pos]]     NCM[a_] := a     NCM[] := 1     Protect[NCM];      Here 1, 2, 3 are satisfied and 4 is not. Could you please help me to modify it.


Ctrl+= opens the alpha input instead of below-script

When trying to type "traditional style" inputs such as integrals or sums, I follow the tutorial and type `Esc` sum `Esc`   `Ctrl`+`=` n=1  `Ctrl`+`%` 10 whatever However, when I type `Ctrl`+`=` it opens the (annoying and useless) alpha interface, and I am forced to use either textual input or use the palette. I'm running Mathematica 8 on Fedora. Any ideas?


Differential equations: How do I solve a delay differential equation with 0-1 variables

How do I solve the following non-linear, delay-differential equations using _Mathematica_ under the assumptions $$p(t) = 1 ,\; y(t) > k$$ $$p(t) = 0,\; y(t)<= \ k$$. $$ \frac{dw}{dt} = \frac{1}{R(t)} - \frac{w(t)x(t)}{2R(t)}p(t-D), $$ $$ \frac{dx}{dt} = \frac{g}{R(t)}(p(t-D)-x(t)), $$ $$ \frac{dy}{dt} = N\frac{w(t)}{R(t)} - c $$ $$ D = d + k/c, $$ $$ R(t) = d + y(t)/c $$ $$g,N,c,d,k \; are \; constants$$ Below is the code I wrote for it. I'm getting some errors which are listed just after the code. Cell1               Clear["Global`*"];     w0 = 1500 * 8; x0 = 0; y0 = 0; p0 = 0;      g = 1/16; k = 65 * w0; c = 10000*10^6; d = 100 * 10^-6; n = 20;      Cell2               r[t] = y[t]/c + d;     D0 = k/c + d;     ics = {w[t /; t <= 0] == w0, x[t /; t <= 0] == x0,      y[t /; t <= 0] == y0, p[t /; t <= 0] == 0};     eqs = {w'[t] == 1/r[t] - (p[t - D0] (w[t] x[t]))/(2 r[t]),      x'[t] == (g (p[t - D0] - x[t]))/r[t],      y'[t] == n (w[t]/r[t] - c), p'[t] == 0,      WhenEvent[{y[t] > k, p[t] -> 1,"IntegrateEvent" -> True},     {y[t] < 0, y[t] -> 0, "IntegrateEvent" -> True};      If[y[t] < 0, y[t] -> 0];      If[y[t] <= k, p[t] -> 0]], ics};      Cell3               sol1 = NDSolve[     eqs, {w[t], x[t], y[t], w'[t], x'[t], y'[t]}, {t, 0, 3},      MaxSteps -> 100000];      Cell4               Plot[Evaluate[{w[t], x[t], y[t]} /. sol1], {t, 0, 3}]


LeastSquares with some parameters missing

I want to do a partial least squares (PLS) regression using `LeastSquares` on my data. The input parameters are temperature, humidity and pressure for a given date. The problem is that some parameters are missing, for example on 6. 9. 2013 the temperature and pressure were recorded, but humidity was not.               m = {     ...     {{2013,9,5},30.0,65.,101.45},     {{2013,9,6},28.6,,101.41},     {{2013,9,7},29.3,58.,101.29},     ...     }      Is it possible to use the available data for days like that, or do I have to leave those days out?


Pasting TemplateBox with a Dynamic argument

Ok, this is pretty specific... The objective is to use a `TemplateBox` to format something that is programatically inserted with `NotebookWrite`. That thing which is inserted is some dynamic control, an `OpenerBox`. So, for example:               (*Pause[3];*)NotebookWrite[InputNotebook[],       TemplateBox[{Dynamic[x]}, "blah",        DisplayFunction :> (OpenerBox[#] &)]]      Uncomment the `Pause[3]` to try it. Run it and select something in another input cell. The problem is, in this example, that the `OpenerBox`doesn't open/close, or not until you convert the cell to cell expression and back to normal doing nothing, or until you cut and paste the `OpenerBox`, or until you write something in the cell expression, etc... Point is, the cell expression is perfect but it doesn't work until you slap the FE a little bit... What's going on? How can I use a `TemplateBox` that gets pasted programatically to control some dynamic variable?


Global variable initialization in packages

Is it a good idea to Initialize variables globally inside a package ? will they be local by default to that package ?


FunctionTreeForm

I'd like to implement a function _FunctionTreeForm_ which takes an arbitrary complex function and renders all the captionable subfunctions in a TreeForm.   * **Explanation** If we take e.g. a function:               TreeForm[Exp[-(x/3)^2]*Cos[2 x + x^2/3]]      the corresponding TreeForm is: ![enter image description here](http://i.stack.imgur.com/XwXzR.png) If we tokenize this function into its subfunctions and plot them seperately:               {Plot[Exp[-(x/3)^2]*Cos[2 x + x^2/3], {x, -2 \[Pi], 2 \[Pi]},      PlotLegends -> "Expressions"],      Plot[E^(-(x^2/9)), {x, -2 \[Pi], 2 \[Pi]}, PlotLegends -> "Expressions"],     Plot[Cos[2 x + x^2/3], {x, -2 \[Pi], 2 \[Pi]}, PlotLegends -> "Expressions"],     Plot[2 x + x^2/3, {x, -2 \[Pi], 2 \[Pi]}, PlotLegends -> "Expressions"]}      we get: ![enter image description here](http://i.stack.imgur.com/F7zoS.png) What I'd like to do is to traverse the corresponding TreeForm and check if a Node is not an Atomic. If it is not I'd suspect it is a function. After collecting all these plots I'd like to display the corresponding TreeForm as a plot of the main function and all its sub-functions in TreeForm. I played around with Level[] etc. but did not came to a solution that does reliable tokenisation of a function definition into sub-functions and I totally lack any idea how to transfer these into a Tree representation.   * **Why I think this could be a feasible functionality** I think in education this FunctionTreeFrom could give a good clue how a rather complicated function is actually assembled from its sub-functions. I hope this is an interesting question and I'm eager to learn how to tackle problems like that.


How do I construct a "named character" programmatically?

Why am I getting the error > Syntax::sntunc: Unicode longname in the string is unterminated. from the following?               astroSymbol[name_String] := ToString[ToExpression["\[" <> name <> "]"]] <> "" ;      Is there something I need to do to wrap the escape sequence to avoid this error?


Solving a system of PDEs expressed in matrix notation

A = SparseArray[{Band[{1, 2}] -> 1, Band[{2, 1}] -> -1}, {n, n}]/(2*Δx);          B = SparseArray[{Band[{1, 1}] -> -2, Band[{1, 2}] -> 1, Band[{2, 1}] -> 1}, {n, n}]/(Δx^2);          R = SparseArray[{Band[{1, 1}] -> 1}, {n, n}];          pde = -D[V[S, t], t] == ((r - 0.5 σ^2).A + (0.5 σ^2).B - r.R)V      Having constructed my matrices A, B and R, **how do I get _Mathematica_ to solve for a single matrix?** I need to replace it in the above equation. I've tried the above codes but failed. I need every element in each matrix be multiplied by the respective scalar.


Extracting vertex coordinates from an automatically laid out graph

Given a `Graph` with an automatically computed layout (i.e. not explicitly given `VertexCoordinates`, but using a `GraphLayout` method), how can we extract the coordinates of the vertices?               In[]:= g = RandomGraph[{10, 20}, GraphLayout -> "SpringEmbedding"]     Out[]= << picture of graph >>          In[]:= PropertyValue[g, VertexCoordinates]     Out[]= Automatic (* <-- I'd like to have a list of coordinates here *)      It's possible to convert the graph into a graphics object using `Show` and extract the coordinates from there. Is there a less hacky, more direct/robust way?


Generating convex polyhedron from face planes?

Suppose I have lists of normals and points for planes. There's a convex polyhedron whose faces lie on these planes and are bounded by plane intersections. What would be the easiest way to produce an image of this polyhedron (preferably with the vertices known) in Mathematica? I thought of one really ugly way to do it, but I'm looking for something more automated/efficient than:   1. Iterate through all triples of planes looking to see if they have a common intersection point, and throwing those intersection points into a list.   2. Using a Mathematica command to strip duplicates from the list.   3. `ListPointPlot3D` to display those points so I can manually decide which should be grouped together in a polygonal face.   4. Using a Mathematica command to build the polyhedron from properly oriented lists of vertices for faces. **Edit:** As requested, here's an example: Suppose I have               normals = {{0, 0, 1}, {0, -2, 2}, {2, 0, 2}, {0, 2, 2}, {-2, 0, 2}}      and               pts = {{1, 1, 0}, {0, 0, 1}, {0, 0, 1}, {0, 0, 1}, {0, 0, 1}}      Then I can make a bunch of plane equations with, say               Table[Table[       Dot[normals[[i]], {x, y, z} - pts[[i]]], {i, 1,        Dimensions[normals][[1]]}][[j]] == 0, {j, 1,        Dimensions[normals][[1]]}]      Three of these five planes intersect at a single point at exactly five points (which could be calculated in a number of ways): those in `{{0, 0, 1}, {1, 1, 0}, {1, -1, 0}, {-1, 1, 0}, {-1, -1, 0}}`. The final result I'd be looking for in this case would be something like               Graphics3D[      Polygon[{{{0, 0, 1}, {1, -1, 0}, {1, 1, 0}}, {{0, 0, 1}, {1, 1,       0}, {-1, 1, 0}}, {{0, 0, 1}, {-1, 1, 0}, {-1, -1, 0}}, {{0, 0,       1}, {-1, -1, 0}, {1, -1, 0}}, {{1, 1, 0}, {-1, 1, 0}, {-1, -1,       0}, {1, -1, 0}}}]]


boundary problem

I have some conditions at `t=0`, like `r1^2+r2^2=0.5` and `x^2+y^2=6` and I want to find the right initial values in the past like `t=-20`, which reproduces this conditions. For example I have this system here.               alpha = 0.5     beta = 1          sol = NDSolve[{          x'[t] == -x[t]*a[t] - 3*x[t] + alpha*y[t]^2 +        1/2*beta*(r1[t]^2 - r2[t]^2),     y'[t] == -y[t]*a[t] - alpha*x[t]*y[t],      r1'[t] == -r1[t]*a[t] - 3/2*r1[t] + beta*x[t]*r1[t],      r2'[t] == -r2[t]*a[t] - 3/2*r2[t] - beta*x[t]*r2[t],     z'[t] == -z[t]*a[t] - 2*z[t],     x[-20] == 0, y[-20] == 10^(-12), r1[-20] == 0.008,      r2[-20] == 0.008, z[-20] == 0.999},     {x, y, r1, r2, z},     {t, 0, -20}];     a[t_] = -1/2*(3 - 3*y[t]^2 + 3*x[t]^2 + z[t]^2)      In c++ I would build something with a `While` loop. But in _Mathematica_ I don't know and the documentation of _Mathematica_ doesn't help me.


How does ListPlot3D interpolate data?

I have data of the form `{{x1, y1, f(x1, y1}, {x2, y2, f(x2, y2)}, ...}`. I need to interpolate the data to get an interpolated `f(x, y)`. When I just do `Interpolation[data]`, I get a function, but the result is not very smooth, independent on the interpolation order (there is a difference between the orders, but it does not get better). When I plot the data with `ListPlot3D[data]`, I get a really nice result. It is really smooth. When I change the interpolation order in `ListPlot3D`, the result does seem to not change, except when going from 0th order to 1st order. So I would like to get a function, which looks like the result of `ListPlot3D`. How does `ListPlot3D` interpolate the data? Or can I get a function of the `ListPlot3D` result? ### Edit First of all, thanks a lot for the detailed answers. I just tried the `InterpolationPolynomial`, but it turned out that it is too demanding for our machine. Maybe, if I post two pictures showing what I'm seeing, one of you will show me how to interpolate my data in the proper way. First the plot made with `ListPlot3D`, the nice one: ![enter image description here](http://i.stack.imgur.com/3LR3l.jpg) And the interpolated function plotted: ![enter image description here](http://i.stack.imgur.com/oBKRK.jpg) My data grid has the resolution of 0.2, so I have 101 x 101 data points; that is, the grid is based on `{x, -10, 10, .2}, {y, -10, 10, .2}`). As one can clearly see, the second plot shows some edges and is not as smooth as the first one. Maybe someone has an idea?


"Stacked" BarChart with BarOrigin $\to$ Top makes y-tick marks negative

This bug was fixed in version 10.0.0 * * * When `BarChart` layout is `"Stacked"`, setting `BarOrigin -> Top` makes the y-axis tick marks negative. BarChart documentation shows an example - but not "Stacked" - with correct positive y-axis tick marks. For example,               data = Table[RandomInteger[{1, 10}], {3}, {4}];          BarChart[MapThread[Labeled[#1, #2, Above] &, {data, {1, 2, 3}}],       ChartLayout -> "Stacked",      BarOrigin -> Top,       ChartStyle ->        Reverse@{Lighter@Blue, Blue, Darker@Blue, Darker@Darker@Blue},       ChartLabels -> {{"a", "b", "c"}, None},       Frame -> {False, True, False, False},       FrameLabel -> {"x axis", "y axis"},      FrameTicks -> {None, Automatic},       BaseStyle -> {FontFamily -> "Helvetica", FontSize -> 14}]      Gives: ![enter image description here](http://i.stack.imgur.com/axqPp.png) Is there an option to control this behavior without explicitly setting `FrameTicks -> {None, Table[{-i, i}, {i, 0, 25, 5}]}`, which works but is a hack.


Creating a Specific Boolean Function

How can I implement a Boolean function F(A,B) that has outputs that are not specific and, therefore, the truth table output of this two-input function will be (a, b, c, d) -- here the first term refers to the case F(0,0), the second to F(0,1), and so on. This is how this Boolean function F(A,B) is represented on Wolfram|Alpha. How would I then evaluate the simplified Boolean expression for: F(A, B) AND F(B, A XOR B)?


Part::partd error on one of two similar lists

I have run into a problem that I can't explain. Here is the code:               σ = {{{0, 1}, {1, 0}}, {{0, -I}, {I, 0}}, {{1, 0}, {0, -1}}}     σ[[1]]          σr[t_] = Map[{Cos[t], Sin[t]}, {-Sin[t], Cos[t]}.# &, σ]     σr[[1]]      I just want to store the Pauli matrices in a list and call them as needed. The first block works fine. In the second block I'd like to apply a rotation on all matrices and be able to use the new matrices as with the first part. However, even though `σ` and `σr` have the same structure, I get a > >     "Part::partd: "Part specification σr[[1]] is longer than depth of > object" >   Can anyone tell me what I'm missing here? Thanks!


Mathematica not simplifing when using FullSimplify

I am trying to simplify the following $(Z_i - Z_{i+1})^4$ using               FullSimplify[(Subscript[Z, i] - Subscript[Z, 1 + i])^4 ,      Assumptions -> {\[CapitalDelta]z > 0,      Subscript[Z, i] \[Element] Reals,      Subscript[Z, i - 1] < Subscript[Z, i] < Subscript[Z, i + 1],      Subscript[Z, i + 1] - Subscript[Z, i ] == \[CapitalDelta]z,      Subscript[Z, i] - Subscript[Z, i - 1 ] == \[CapitalDelta]z}]      The answer should be $\Delta z^4$ but it just returns the same thing that I put in. Is there something that I am missing?


Can I add legends to a SmoothHistogram?

Under the options menu for `Histogram`, there is an option called `ChartLegends`, which adds little boxes beside the plot to indicate which curve represents what. I cannot find a similar option for `SmoothHistogram`. I know that `PlotLegends` is new in version 9, and I would've expected the option to be valid for `SmoothHistogram` as well. Does anybody know of a way around this issue?


How to import a CSV file into column vectors

I just got a trial version of _Mathematica_. I want to experiment with using it for data analysis. I have a CSV file here that I would like to import into Mathematica so that the data is represented as a matrix (2D array) where the columns are represented as column vectors rather than each cell representing a row. I also need to chop off the headers, too. Here's what I've got so far:               data = Import["https://raw.githubusercontent.com/camenergydatalab/EnergyDataSimulationChallenge/master/challenge1/data/dataset_500.csv"]


Solving the Travelling Salesman Problem

I've been trying to find some kind of mathematical computer software to solve the Travelling Salesman Problem. The Excel Solver is able to do it, but I've noticed there is a built-in function in _Mathematica_ : > TravelingSalesman[g] finds an optimal traveling salesman tour in graph g. I've been given a matrix which represents the costs of traveling between six cities. I could start typing them in to the `Graph` function and then use the `TravelingSalesman` function to solve it. But I'm too lazy for such work. Is there a way to type in the matrix, convert it to some kind of graph, and then apply the `TravelingSalesman` function directly to the graph? Hope you understand my question! Thanks in advance.


How to increase Spectrogram resolution?

I have a time-domain signal that I want do a time-frequency analysis on it. When I tried the `Spectrogram`, I always get very low resolution. For example: I have a signal like this:               data = Table[        Piecewise[{{Sin[2 \[Pi] 10 t], 0 <= t < 1/4}, {Sin[2 \[Pi] 25 t],            1/4 <= t < 1/2}, {Sin[2 \[Pi] 50 t],            1/2 <= t < 3/4}, {Sin[2 \[Pi] 100 t], 3/4 <= t <= 1}}], {t, 0,          1, 1/1023}];     ListLinePlot[data, AspectRatio -> 0.2]      ![enter image description here](http://i.stack.imgur.com/8faH0.png) when I do a wavelet transform, I get a result that I can identify each frequency and their arrival time.               cwd = ContinuousWaveletTransform[data, GaborWavelet[6], {Automatic, 12}];     freq = (1023/(#*GaborWavelet[6]["FourierFactor"])) & /@ (Thread[{Range[8], 1}] /. cwd["Scales"]);     ticks = Transpose[{Range[Length[freq]], freq}];     WaveletScalogram[cwd, Frame -> True, FrameTicks -> {{ticks, Automatic}, Automatic},FrameLabel -> {"Time", "Frequency(Hz)"}, ColorFunction -> "RustTones"]      ![enter image description here](http://i.stack.imgur.com/J7eMb.png) The wavelet transform is very good for me except I prefer a linear scale instead of a log scale. So I tried the Spectrogram.               Spectrogram[data, SampleRate -> 1023, ColorFunction -> "RustTones", FrameLabel -> {"Time", "Frequency(Hz)"}]      ![enter image description here](http://i.stack.imgur.com/eXaGn.png) From the spectrogram I can barely see that there are four frequencies components, but the resolution is very low compared to the wavelet transform, and there seems be a lot of "noise" in it. So how can I use Spectrogram to plot a similar result as that of wavelet transform, a result that I can easily see the difference frequencies and their occurrence in time? **Edit** : Second example               data2 = {0.0000688553, 0.0000688557, 0.0000688564, 0.000068857, 0.0000688571, 0.0000688563, 0.0000688551, 0.000068854, 0.0000688539,0.0000688551, 0.0000688573, 0.0000688591, 0.0000688593, 0.0000688572, 0.0000688536, 0.0000688507, 0.0000688504, 0.0000688538, 0.0000688594, 0.0000688641, 0.0000688644, 0.0000688591, 0.0000688504, 0.0000688431, 0.0000688426, 0.0000688506, 0.0000688639, 0.0000688747, 0.0000688756, 0.0000688636, 0.0000688439, 0.0000688279, 0.0000688268, 0.0000688443, 0.0000688727, 0.0000688957, 0.0000688975, 0.0000688724, 0.0000688318, 0.0000687991, 0.0000687969, 0.0000688321, 0.0000688886, 0.0000689341, 0.0000689375, 0.000068889,0.0000688108, 0.0000687484, 0.0000687447, 0.0000688111, 0.0000689165, 0.0000690002, 0.0000690059, 0.0000689171, 0.0000687754, 0.000068664, 0.0000686589, 0.000068778, 0.0000689632, 0.000069108, 0.0000691159, 0.0000689611, 0.0000687182, 0.0000685311,0.0000685273, 0.0000687314, 0.0000690404, 0.0000692758, 0.0000692824, 0.0000690239, 0.0000686276, 0.000068331, 0.0000683373,0.0000686747, 0.0000691661, 0.0000695268, 0.0000695212, 0.0000691047, 0.0000684868, 0.0000680431, 0.0000680816, 0.0000686216, 0.0000693686, 0.0000698882, 0.0000698443, 0.0000691941, 0.0000682709, 0.0000676461, 0.0000677627, 0.0000686028, 0.0000696891, 0.0000703884, 0.000070254, 0.0000692688,0.0000679463, 0.0000671236, 0.0000674037, 0.0000686737, 0.0000701814, 0.0000710486, 0.0000707318, 0.0000692847, 0.0000674719, 0.0000664738, 0.0000670596, 0.0000689181, 0.0000709029, 0.0000718656, 0.0000712238, 0.0000691734, 0.0000668091, 0.0000657258, 0.000066827, 0.000069441, 0.0000718908, 0.0000727864, 0.0000716293, 0.0000688506, 0.0000659424, 0.0000649574, 0.0000668415, 0.0000703392, 0.0000731224, 0.0000736827, 0.0000718041, 0.0000682428, 0.0000649098, 0.0000643029, 0.000067249, 0.0000716496, 0.0000744731, 0.0000743462,0.0000715934, 0.0000673322, 0.0000638262, 0.0000639329, 0.0000681481, 0.0000732907, 0.0000757007, 0.0000745275, 0.0000708955, 0.0000662018, 0.0000628777, 0.0000639981, 0.0000695195, 0.000075033, 0.0000764844, 0.0000740176, 0.0000697294,0.0000650442, 0.0000622699, 0.0000645526, 0.0000711839, 0.0000765324, 0.0000765193, 0.0000727403, 0.0000682638, 0.0000641159, 0.0000621449, 0.000065499, 0.000072824, 0.0000774271, 0.0000756283, 0.0000708033, 0.000066779, 0.0000636471, 0.0000625116,0.0000665943, 0.000074074, 0.0000774592, 0.0000738344, 0.0000684751, 0.0000655744, 0.0000637559, 0.0000632316, 0.0000675249, 0.0000746401, 0.0000765622, 0.0000713567, 0.0000660968, 0.0000648676, 0.0000644101, 0.000064073, 0.0000680156,0.0000743922, 0.0000748728, 0.0000685322, 0.0000639731, 0.0000647345, 0.0000654567, 0.0000648017, 0.0000679187, 0.0000733889, 0.0000726689, 0.0000657091, 0.0000622946, 0.0000651115, 0.0000666921, 0.0000652615, 0.0000672442, 0.0000718318, 0.0000702735, 0.0000631592, 0.0000611172, 0.0000658463, 0.0000679338, 0.0000654099, 0.0000661311, 0.0000699868, 0.0000679712, 0.0000610429, 0.0000603915, 0.0000667595, 0.0000690611, 0.0000653029, 0.0000647858, 0.0000681115, 0.0000659659, 0.0000594197, 0.0000600132, 0.0000676898, 0.0000700163, 0.0000650527, 0.000063423, 0.0000664129,0.0000643775, 0.0000582827, 0.0000598674, 0.0000685134, 0.000070784, 0.0000647821, 0.0000622261, 0.0000650355, 0.0000632614,0.0000575952, 0.000059858, 0.0000691461, 0.0000713679, 0.0000645938, 0.0000613302, 0.000064069, 0.0000626336, 0.0000573173,0.0000599219, 0.0000695408, 0.0000717756, 0.0000645558, 0.0000608195, 0.0000635588, 0.0000624885, 0.0000574204, 0.0000600333, 0.0000696834, 0.0000720124, 0.0000646977, 0.0000607281, 0.0000635126, 0.0000628061, 0.0000578888, 0.0000602007, 0.0000695902, 0.0000720824, 0.0000650125, 0.0000610423, 0.0000639015, 0.0000635503, 0.0000587147, 0.0000604608, 0.0000693062, 0.0000719916, 0.000065463, 0.0000617039,0.0000646594, 0.000064664, 0.0000598881, 0.0000608677, 0.0000689002, 0.0000717529, 0.0000659909, 0.0000626183, 0.0000656854, 0.0000660624, 0.0000613839, 0.0000614786, 0.0000684577, 0.0000713905, 0.0000665298, 0.0000636677, 0.0000668497, 0.0000676302, 0.0000631474, 0.000062335, 0.0000680682,0.0000709408, 0.0000670184, 0.0000647289, 0.0000680081, 0.0000692241, 0.0000650845, 0.0000634439, 0.0000678097, 0.0000704504, 0.0000674126, 0.000065693, 0.0000690214, 0.0000706853,0.00006706, 0.000064764, 0.0000677327, 0.0000699684, 0.0000676912, 0.000066482, 0.0000697781, 0.0000718607, 0.0000689098, 0.0000662045,0.0000678498, 0.0000695389, 0.0000678562, 0.0000670585, 0.0000702138, 0.000072631, 0.0000704663, 0.0000676364, 0.0000681344,0.0000691935, 0.0000679274, 0.0000674255, 0.0000703228, 0.0000729367, 0.0000715913, 0.0000689162, 0.0000685272, 0.0000689492, 0.0000679364, 0.0000676184, 0.0000701554, 0.000072794,0.0000722085, 0.0000699157, 0.0000689494, 0.0000688079, 0.0000679212, 0.0000676936, 0.0000698037, 0.0000722933, 0.0000723258, 0.0000705539, 0.0000693212, 0.0000687577, 0.00006792, 0.0000677163, 0.0000693786, 0.0000715782, 0.0000720359, 0.0000708189, 0.0000695815, 0.0000687748, 0.000067962, 0.0000677458,0.0000689833, 0.0000708076, 0.0000714897, 0.0000707694, 0.0000697032, 0.0000688285, 0.0000680579, 0.0000678211, 0.0000686895, 0.0000701136, 0.0000708499, 0.00007051, 0.0000696956, 0.0000688882, 0.000068197, 0.000067952, 0.0000685249, 0.0000695739, 0.0000702467, 0.0000701544, 0.0000695939, 0.0000689322, 0.0000683544, 0.000068123, 0.0000684773, 0.0000692078, 0.0000697549,0.0000697941, 0.0000694432, 0.0000689511, 0.0000685038, 0.0000683059, 0.000068511, 0.0000689924, 0.0000693973, 0.0000694848,0.0000692835, 0.0000689472, 0.000068627, 0.0000684739, 0.0000685852, 0.0000688856, 0.0000691611, 0.0000692488, 0.0000691419, 0.0000689291, 0.0000687172, 0.0000686102, 0.0000686674, 0.0000688449, 0.0000690179, 0.0000690851, 0.0000690317, 0.0000689062, 0.0000687771, 0.0000687096, 0.0000687381, 0.0000688373, 0.0000689375, 0.0000689807, 0.0000689548, 0.0000688857, 0.0000688133, 0.0000687752, 0.0000687896, 0.0000688418, 0.0000688953, 0.0000689191, 0.0000689065, 0.0000688709, 0.0000688339, 0.0000688149, 0.0000688224, 0.0000688483, 0.0000688742, 0.0000688855, 0.0000688791, 0.000068862, 0.0000688449, 0.0000688367, 0.0000688408,0.0000688527, 0.0000688641, 0.0000688686, 0.0000688653, 0.0000688577, 0.0000688507, 0.0000688478, 0.0000688499, 0.000068855,0.0000688594, 0.0000688608, 0.0000688591, 0.0000688561, 0.0000688535, 0.0000688527, 0.0000688538, 0.0000688558, 0.0000688573, 0.0000688576, 0.0000688568, 0.0000688558, 0.000068855,0.0000688549, 0.0000688554, 0.000068856, 0.0000688564, 0.0000688564, 0.0000688561, 0.0000688557, 0.0000688556, 0.0000688556, 0.0000688558, 0.000068856, 0.0000688561, 0.0000688561,0.000068856, 0.0000688559, 0.0000688559, 0.0000688559, 0.0000688559, 0.000068856, 0.000068856};          cwd=ContinuousWaveletTransform[data2, GaborWavelet[6], {Automatic, 12}]     WaveletScalogram[cwd, ColorFunction -> "RustTones"]      ![enter image description here](http://i.stack.imgur.com/ALTvL.png)               Spectrogram[data2, ColorFunction -> "RustTones"]      ![enter image description here](http://i.stack.imgur.com/xs48j.png)


How to solve this combination equation?

I want to solve the equation $$ 2n\cdot\binom{n}{0} + 5(n-1)\binom{n}{1}+13(n-2)\binom{n}{2}+\cdots + \left(2^{n-1} + 3^{n-1}\right)\binom{n}{n-1} = 1685. $$ or using alternative notion for binomial coefficients: $$ 2nC_{n}^0 + 5(n-1)C_n^1 + 13(n-2)C_n^2 +\cdots + \left(2^{n-1} + 3^{n-1}\right) C_n^{n-1}=1685. $$ where, $n$ is a natural number. I do not know how to solve this. How do I tell Mathematica to do that?


Export a Grid in a xls file naming the sheets

I try to export two grid in a same xls file, naming the sheets. This is an exemplification of my issue, and it doesn't work.               m = Grid[Table[i - j, {i, 3}, {j, 4}]];     Export["m.xls", m]      it works correctly, but if I try this code, naming the sheet, it doesn't work               Export["m.xls", {"MySheet" -> m}]      Thanks


How to force an evaluation to use only one core?

There are some evaluations which are automatically parallelized or multithread if there are cores available.( for example, `Eigenvalues`) But I don't want the evaluation to be automatically multithreaded, I want it to use only one core. How can I do it?


"Save as (html)" and still render Input cell code as text?

When I' m testing on this post' s method I found some problems.               Export["test.html", nb = EvaluationNotebook[], "HTML",           "ConversionRules" -> {"Input" -> {"
", DisplayForm[#] &, "/code>/pre>"}},         CharacterEncoding -> "CP936", "CSS" -> None]               Export["test.html", nb = EvaluationNotebook[], "HTML",            "ConversionRules" -> {"Input" -> {"
", InputForm[#] &, "/pre>"}},            CharacterEncoding -> "CP936", "CSS" -> None]      ![enter image description here](http://i.stack.imgur.com/zgNDj.png) How can I keep the Codes completely the same as that in the Notebook? Are there any easy ways to do that? For example, change the `DisplayFormula[#]&` into something else that I don't know?


Rule for orderless function Times

I have problems extending a replacement rule. Schematically, this is the situation: I have an expression and a rule, and they work perfectly together.               In[1] =  result = expr /.rule     Out[1] = ...      Now I want to extend the rule to let it cope with extra multiplication factors. It should be such that               In[2] =  5 result - (5 expr /. ruleex)     Out[2] = 0      And               In[3] =  5 w result - (5 w expr /. ruleex)     Out[3] = 0      These are the expression and the rule I am working with:               In[4]:=  rule = Times[f[x__][y__], z__] -> Times[-1, q, y, f[x][z]]     In[5]:=  expr = f[-a][s[c, -b]]*f[a][s[-c, b]]     In[6]:=  result = expr /. rule     Out[4]:= -s[c, -b] f[-a][f[a][s[-c, b]]]      To make the rule cope with an arbitrary number of multiplicative factors on the left, I guess adding a BlankNullSequence would do.               In[7]:=   ruleex = Times[q___, f[x__][y__], z__] -> Times[-1, q, y, f[x][z]];     In[8]:=   expr /.rulex     In[9]:=   5 expr /. ruleex     In[10]:=  5 w expr /. ruleex     Out[5]:=  -s[c, -b] f[-a][f[a][s[-c, b]]]     Out[6]:=  -s[c, -b] f[-a][5, f[a][s[-c, b]]]     Out[7]:=  -s[c, -b] f[-a][5, w, f[a][s[-c, b]]]      Out[5] is as expected. The extra factor 5 ends up not at the front of the expression, but somewhere in the in f[a][...]. In Out[7] something similar occurs. Why does this not work? How can I extend the rule to act in the way I described?


How to keep the vector product form?

When we deal with the vector product problem, we usually should define some fixed form for the vector product. For instance, I define it in this way,                  Unprotect[Times];        R[x1_] Rp[x2_] := RRp[x1, x2];        R[x1_] R[x2_] := If[x1==x2,R[x1]^2, RR[x1, x2]];         Rp[x1_] Rp[x2_] := If[x1==x2,Rp[x1]^2,RpRp[x1, x2]];        Protect[Times];      Here, R[ _] and Rp[_ ] are vectors. In some simple cases, it works. For example,                  (R[1] - Rp[3])^2 // Expand        =R[1]^2 + Rp[3]^2 - 2 RRp[1, 3]      However, in the following case, something is wrong.                  (R[1] - Rp[3])^3 // Expand       =R[1]^3 - 3 R[1]^2 Rp[3] + 3 R[1] Rp[3]^2 - Rp[3]^3        The expected result is                 R[1]^3-R[1]^2Rp[3]+R[1]Rp[3]^2-Rp[3]^3-2 R[1]RRp[1, 3] +2 Rp[3]RRp[1, 3]      So, how to find a simple way to fixed the vector product in the complicated expand form ?


Exponential of a Differential Operator

In Mathematica, is it possible to exponentiate a differential operator such that the operator will act on a function, $f(x,p)$? Specifically, I wondering if I can get Mathematica to do this: $\exp(c\frac{d}{dp})f(x,p)=(1+c\frac{d}{dp}+\frac{c^2}{2}\frac{d^2}{dp^2}+\cdots)f(x,p)=(f(x,p)+c\frac{df}{dp}+\frac{c^2}{2}\frac{d^2f}{dp^2}+\cdots)$ where $c\in\Re$. Thanks.


Laurent series expansion

Can someone share how to find a Laurent series expansion of $$f(z)=\frac{1}{(z^2-1)(z^2-4)}$$ centered at zero on the annular disk $1<|z|<2$?


Numerical problems with calculation of function

I have a problem with a calculation which I try to do with Mathematica (8.0.1). I have the following function which describes a cone (with half opening angle `theta`) which can be tilted (with the angles `thetaTilt` and `phiTilt`) around its base point `lG`. For some unimportant reasons the tip of this cone (if not tilted) is at the position `–rout/Tan[theta]`. So, `rout` describes in the following function the diameter of the cone tip at the position `z=0` (again for the not tilted case):               coneFunction[x_, y_, theta_, thetaTilt_, phiTilt_, lG_, rout_] :=      1/(Cos[2 theta] -      Cos[2 thetaTilt]) (rout Cos[thetaTilt] Sin[2 theta] +       2 lG (1 + Cos[2 theta] + 2 Cos[thetaTilt]) Sin[thetaTilt/        2]^2 - \[Sqrt](Cos[theta]^2 (lG^2 + x^2 + y^2 +            rout Cot[theta] (2 lG + rout Cot[theta]) +  2 x y Sin[2 phiTilt] +            Cos[2 thetaTilt] (-lG^2 + x^2 + y^2 -  rout Cot[theta]      (2 lG + rout Cot[theta]) -  2 x y Sin[2 phiTilt]) +            8 (x Cos[phiTilt] + y Sin[phiTilt]) Sin[theta] (rout Cos[theta] +     lG Sin[theta]) Sin[thetaTilt] +            2 (x - y) (x + y) Cos[2 phiTilt] Sin[thetaTilt]^2 +            Cos[2 theta] (-lG^2 - 2 (x^2 + y^2) +               lG^2 Cos[2 thetaTilt] - 2 rout Cot[theta] (2 lG + rout Cot[theta])      Sin[thetaTilt]^2))) + (x Cos[phiTilt] + y Sin[phiTilt]) Sin[2 thetaTilt]);      Since it is difficult to understand what this function does (and what I mean in my text), I suggest that one plots an cross-section of this function, e.g. with               theta=3.5*10^-3;(*half opening angle of cone in rad*)     rout=0.65*10^-6;(*diameter at tip of cone*)     lG=10*10^-3;(*basepoint of the cone*)     Plot[coneFunction[x, 0, theta, 0, 0, lG, rout],      {x, -0.000005,0.000005},      PlotRange -> {1.2*{-0.000005, 0.000005}, {-0.0002, 0.001}},      PerformanceGoal -> "Quality", PlotPoints -> 120]      ![cross section of cone](http://i.stack.imgur.com/grela.png) Or a 3D plot with e.g.:               thetaTilt = 0;     phiTilt = 0;     Show[Plot3D[{coneFunction[x, y, theta, thetaTilt, phiTilt, lG, rout]},      {x, -0.001, 0.001}, {y, -0.001, 0.001},      Exclusions -> None, PlotPoints -> 60, PerformanceGoal -> "Quality",      Mesh -> False, PlotStyle -> Directive[Opacity[0.4], Gray]],     Axes -> True, AxesLabel -> {"x/m", "y/m", "z/m"},      BoxRatios -> {1, 1, 1},      PlotRange -> {{-0.0001, 0.0001}, {-0.0001, 0.0001}, {-0.001, 0.012}}]      ![3D plot of cone](http://i.stack.imgur.com/bO3bo.png) If one sets `thetaTilt` to small values such as 10^-4, it can be seen easily, that the cone is being tilted by this value. If the cone is not tilted, the function is independent of `lG`. This can be seen easily by:               Simplify[coneFunction[x, y, theta, 0, 0, lG, rout]]      So, regardless what x or y values I chose, I should get back always the same result for different values of the base point `lG`. But that is not the case! If I use e.g.               testTable =      Table[SetPrecision[     coneFunction[-0.000005, 0, theta, 0, 0, lG, rout], 10],      {lG, 0.0053, 0.0055, 0.0000001}];      I get as output most time 0.001242850670, but also some other values (e.g. 0.001242846719). So, if I have bad luck and chose a “bad” `lG` value, I would get back wrong results. I assume that this has something to do with the numeric of Mathematica. I tried to get rid of this effect with some attempts (e.g. `SetPrecision`, `Rationalize`, `Evaluate`), but none of them worked. So, who can give me some advice? How can I manage that my function gives back for all `lG` the right result (also for the tilted case)? Since I am clueless I would appreciate any support!


How to find the global maximum of a function?

I tried the following but plotting the function clearly reveals that there is a global maximum around $r = 7$ (here $a = 0.53$)               FindMaximum [{r^2*(Exp[-(r)/(3 a)]* (27 a^2 - 18 a r + 2 r^2)/(9 a^2))^2 ,                   0 <= r < Infinity}  , {r, 0}]      {0.253131, {r -> 0.39222}} I tried `NMaximum`, `Max`, `MaxValue`, `Maximize`, `FindMaxValue`, `FindMaximum` but nothing works! _(..I wonder why there are so many maxima finding functions anyway!..)_


How to check which file is older

Is there a command in Mathematica to check the date when a file was last modified? Suppose I have two notebooks: `File1.nb` and `File2.nb`, I need a way to find out which notebook is older. If no such command exists is there a way to do this in _Mathematica_ regardless of the operating system we are working on?


NDSolve and results of the previous computations

I want to solve following system of ODEs: $ \Bigg\\{ \begin{array}{} \frac{\partial C}{\partial t}=\frac{2W_b}{Rsin(\theta)}(1-\frac{C}{\gamma})+\frac{\nu}{\pi R^2}\frac{\partial C}{\partial Z} \\\ \frac{\partial R}{\partial t}=\frac{W_b}{\gamma sin(\theta)} \end{array} $ Where $W_b=k_bC_h(1-\frac{C}{C_h})^{\frac{4}{3}}$ and $\nu, k_b, C_h, h, \gamma, \theta$ are constants. It is known that: $ \frac{\partial C}{\partial Z}=\frac{C_i-C_{i-1}}{Z_i-Z_{i-1}} $, where $Z_i- Z_{i-1}=h$ and $h$ is a constant. So, the first equation become this: $ \frac{\partial C}{\partial t}=\frac{2W_b}{Rsin(\theta)}(1-\frac{C}{\gamma})+\frac{\nu}{\pi R^2}\frac{C_i- C_{i-1}}{h} $ My question is how can I get the result of previous computation, namely $C_{i-1}$? Here is the mathematica code I wrote:               Wb[C_] := kb*Ch*(1 - C/Ch)^(4/3);     system := {       c'[t] == (2*Wb[c[t]])/(r[t]*Sin[theta])*(1 - C/gamma) + v/(Pi*r[t]^2)*(c[t] - ?? )/h,       r'[t] == Wb[c[t]]/(gamma*Sin[theta]),       c[0] == 0, r[0] == 0.15};     solution = First@NDSolve[system, {c, r}, {t, 0, 25900000}, Method -> "BDF"];      **UPDATE** : Simplified version of the problem. This is a model based on a plug flow reactor.   $ \Bigg\\{ \begin{array}{} \dot{x} = \frac{c_1 x f(x)}{y} + \frac{\partial x}{\partial z} \\\ \dot{y} = c_2 f(x) \end{array} $ Where c1 and c2 are constants. This is a model of a physical process and it was shown that `z` dimension is quantified by a chunks of a constant size `h` and `x` is monotonously increasing, so $\frac{\partial x}{\partial z}=\frac{\Delta x}{\Delta z}=\frac{x_i - x_{i-1}}{h}$               f[x_] := ...;     system := {       x'[t] == c1*x*f[x[t]]/y[t] + (x[t] - ?)/h,       y'[t] == c2*f[x[t]],       x[0] == 0, y[0] == 0.15};     solution = First@NDSolve[system, {x, y}, {t, 0, 25900000}, Method -> "BDF"];


RSolve with simple initial condition

Suppose we have the following equation: $$ g_ma_m=r_ma_{m-1} $$ with initial condition $a_L=d$ and $L$ might be negative. The following command               RSolve[{g[m] a[m] == r[m] a[m - 1], a[-10] == d}, a, m]      gives me               {{a -> Function[{m},        d*Product[r[1 + K[1]]/g[1 + K[1]], {K[1], 0, -1 + m}]]     }}      where `K[1]` runs from 0 to $m-1$. But shouldn't `K[1]` runs from -10 to $m-1$?


MapIndexed stops at levelspec 1 if only the index is passed?

If the function passed to MapIndexed references the first (or data) argument, the following performs as expected:               MapIndexed[#2 &, 1 -> {2 -> {3 -> 4}}, Infinity]      As well as               MapIndexed[(#1; #2) &, 1 -> {2 -> {3 -> 4}}, Infinity]      yield:               {1} -> {2}      Not respecting the Infinity level spec, whereas:               MapIndexed[{#1, #2} &, 1 -> {2 -> {3 -> 4}}, Infinity]      gives               {1, {1}} -> {{{{2, {2, 1,             1}} -> {{{{3, {2, 1, 2, 1, 1}} -> {4, {2, 1, 2, 1, 2}}, {2, 1,               2, 1}}}, {2, 1, 2}}, {2, 1}}}, {2}}


Profiling from Mathematica

I've always wished I could do some profiling like you get in Wolfram Workbench, but directly from _Mathematica_ , without using or having Workbench. If it is possible, how can I do it?


How does Mathematica wrap code for front-end needs? Why does this wrapping affect the evaluation?

Mathematica wraps any expression with some boxing code before showing the evaluation result in the front-end. Unfortunately, the wrapping algorithm and its position in the Mathematica end-to-end flow are not described in the official documentation. Surprisingly, this stuff can affect the evaluation of the expressions. Please, see an `UpValues`-based approach to problem of removing head `X` by head `Y`:               UpValues[Y] = {};     UpValues[X] =        {HoldPattern[(head: __)[a___, X[b__], c___]] :> Hold[head[a, Y[b], c]]};          1 + X[432] + A[2] (* ==> Hold[1 + A[2] + Y[432] *)     X[X[545]] (* ==> Hold[Hold[Y[Y[545]]]] *)      `Hold`/`HoldPattern` were used in the transformation pattern to keep expression unevaluated but transformed by `UpValues[X]`. So it works. Now I want this transformation rule to work only if pattern `head` is not `X`:               UpValues[Y] = {};     UpValues[X] =        {HoldPattern[(head: Except[X])[a___, X[b__], c___]] :> Hold[head[a, Y[b], c]]};          1 + X[432] + A[2] (* ==> Hold[1 + A[2] + Y[432] *)     X[X[545]]     (* ==>          Hold[             If[False,                 Y[X[545]],                 With[{OutputSizeLimit`Dump`boxes$ =                         Block[{$RecursionLimit = Typeset`$RecursionLimit},                             MakeBoxes[X[X[545]], StandardForm]                         ]},                          OutputSizeLimit`Dump`loadSizeCountRules[];                     If[TrueQ[BoxForm`SizeCount[OutputSizeLimit`Dump`boxes$, 1048576]],                         OutputSizeLimit`Dump`boxes$,                         OutputSizeLimit`Dump`encapsulateOutput[X[X[545]], $Line, $SessionID, 5]                     ]                ],                X[X[545]]            ]        ] *)      It seems, that pattern object `Except[X]` captures wrapping code that Mathematica uses to adopt any expression for the front-end needs. As for me it is a surprise because the case using general pattern object `__` works well. So, my claim is that code wrapping used for front-end needs can affect the evaluation process in the Mathematica core. Resulting,   1. Where can I read about Mathematica's end-to-end in details? I mean something like "The TeXbook" by D. Knuth for TeX.   2. Is the described behaviour a bug? Probably, it corresponds to features of implicit end-to-end flow.   3. Probably, the code above is not the only case. What technique can help me to avoid such behaviour?


Simple Jacobians, Gradients, etc. with arbitrary length vectors/matrices?

Is there any way (or a package built for it) can do simple operations with vectors and matricies of arbitrary size, but conforming extents? For the simplest example to test, given an arbitrary vector $a,z\in R^n$ and $A \in R^{n \times n}$, $\nabla(a \cdot z) = a$ and the jabobian: $\nabla(A \cdot z) = A$, etc. I tried the obvious (assuming that $z$ was a vector) `Grad[a . z, {z}]` etc, but it didn't work. I noticed Differentiating with respect to vectors of unspecified length, and Generating a vector of dummy variables but they didn't appear to help - and may be suggesting that it isn't possible...


Building graph based on the cities connection?

I built a `Graph` based on the permutations of city's connections from :               largUSCities =      Select[CityData[{All, "USA"}], CityData[#, "Population"] > 600000 &];     uScityCoords = CityData[#, "Coordinates"] & /@ largUSCities;     Graph[#[[1]] -> #[[2]] & /@ Permutations[largUSCities, {2}] ,      VertexCoordinates -> Reverse[uScityCoords, 2], VertexStyle -> Red,      Prolog -> {LightBrown, CountryData["USA", "FullPolygon"]},ImageSize -> 650]      It looks like this: ![graph](http://i.stack.imgur.com/1ea6c.png) My question, is there any way to have the Graph like this? ![enter image description here](http://i.stack.imgur.com/ajwOT.png)


How to switch off messages on all kernels?

I am using `ParallelMap` for my code,however, it gives some messages that don't affect the evaluation process but fill up the memory and take some more time. So, I want to turn off all messages on all kernels. I used `Quiet` but it doesn't work. Is there a way to switch off messages on all kernels? Any help is appreciated. Thanks in advance.


Generating schedules/timetables in Mathematica

I've always used MS Excel to create my school schedules, and I've always been happy with the results. Is there a similar GUI way to generate schedules/timetables in _Mathematica_ or a third-party functionality (e.g. in a package) available?? My own search has taught me that undocumented functions exist (`TableView`) and that presumably more elaborate functions (`SpreadsheetView`) will be part of future _Mathematica_ releases. `TableView` is nice, but I haven't managed to create pretty layouts with it, as I could easily do in Excel. All it seems to do is enable me to generate big matrices quickly. Here's what my current timetable looks like: ![enter image description here](http://i.stack.imgur.com/QH2ue.png)


sequence of matrix multipications

My linear algebra book has questions that are are marked to use math software. There's probably some $50 guide on how to do everything but usually documentation has gotten me through. I've been kind of stumped by this though. I'm doing some applications problems where I have to do something n times. Simple               x_1 = A.x_0,     x_2 = A.x_1,     ...      I remember these as sequences in calc. As it stands I am just doing `x = A.x` and repeating as many times as I need to, but this is obviously more work than needed if I knew the right tools. Could you please tell me what would be this tool?


LogLogPlot giving many error messages

I'm trying to do a `LogLogPlot` of the following function:               fun[t_, n_, ρ_, λ_, μ_] := (         1 - NIntegrate[(E^(s*(-λ - μ))*BesselI[1, 2*s*Sqrt[λ*μ]])/(s*Sqrt[ρ]),        {s, 0, t}]^(n))      Which works only when I use `Plot`. For example,               Manipulate[Plot[fun[t, j, 1/2, 0.5, 1], {t, 0, 50}, PlotRange -> {0, 1}],                {{j, 0.5, "n"}, 1.0, 1000, Appearance -> "Labeled"}]      But when I try to do a `LogLogPlot`, which is done with this code,               Manipulate[LogLogPlot[fun[t, j, 1/2, 0.5, 1], {t, 0.0001, 50}, PlotRange -> {0, 1}],                {{j, 0.5, "n"}, 1.0, 1000, Appearance -> "Labeled"}]      then things get crazy and _Mathematica_ outputs a bunch of errors. I'm not sure what I am doing wrong and any help with this matter would be much appreciated.


Efficiently determining the largest minimum cost to travel from a fixed source to an arbitrary sink in a weighted graph

Let $v_i$ be a vertex in a graph $G$ with vertices $(v_1,...,v_N) \in V$ and edges $(e_1,...,e_M) \in E$ with associated weights $(w_1,...,w_M)$. Let $v_s \in V$ be specified vertex in the graph. In Mathematica 9, beyond repeatedly applying Dijkstra's algorithm by way of FindShortestPath[] and then summing the weights along the edges of each path, is there an efficient way to return the set of minimum costs to travel from $v_s$ to all other vertices $v_i \neq v_s$? Also, other than finding the maximum value of this matrix, is there an efficient way to detect if one path exists where the minimum cost exceeds some threshold $T$?


How does Mathematica calculate the nth prime?

When I enter `Prime[2000000000000]`, the two-trillionth prime, _Mathematica_ gives `61427839512211` for the answer after several minutes of calculation. I wonder how it calculates to get this number. Apparently, it does not pull that number out from a list, since it spends several minutes to get the answer.


Improving the plotting time of a very complicated expression

The quatity $R$ is defined by a complicated expression in terms of $a_1,a_2,\ldots,a_n$. Now each $a_i$ is a function of $x$, $a_i(x)$. I would like to know what is the most efficient way to substitute in R the expression for the $a$s and then plot it as a function of $x$. I am only interested in the plot. For concreteness consider the following code:               With[{vecup = Table[(Abs[a[i]]^2 - 1)*If[ε^2 >= 2 i, 1, 0], {i, NN}],            vecdown = Table[(1 - 1/Abs[a[i]]^2)*If[ε^2 >= 2 i, 1, 0], {i,  NN}]},        R = Abs[ψorbR]^2.vecup/(1 + Abs[ψorbT]^2.vecdown)];     v[n_] := Sqrt[1 - 2 n/ε^2];     a[i_] := -I Sqrt[(1 + Sign[i] v[Abs[i]])/(1 - Sign[i] v[Abs[i]])];      I would like to plot `R`. The vectors `ψorbR` and `ψorbT` are very large expressions, and as I increase `NN`, these vectors increase in size causing the expressions of their elements also to increase in size, eventually making `R` impossible to plot. Are there efficient ways to do operations on large expressions such as R that will help in keeping the plotting time reasonable?


Update: Interpolation error message?

I have the following data that needs to be analyzed :               data = ToExpression@Import["http://pastebin.com/raw.php?i=8XKGYvSy", "Data"];      I have 6 sets of coordinates (including this one) that I can easily plot on the same graph with `ListLinePlot`. However, I need to determine the `x-coordinate` of each of the 6 curves that has a y-value of a specific number of my choosing, say, -3. My goal is to do something like this with an intersection (using `FindRoot` between the line `y=-3` and `Interpolation[data]`. When I run `Interpolation[data]`, I get the following error message: > Interpolation::inder: The order-2 derivative of {-1.47,-7.0394} is not a > tensor of rank 2 with dimensions 2. >> I've seen similar uses of `Interpolation` for data sets much smaller than mine. Also, I'm importing my data from _Excel_ if that makes a difference. **EDIT:** I have done what others pointed out and removed the redundant braces. However, some of my sets still turn up an error message when I use `FindRoot`. `data = First@ToExpression@Import["http://pastebin.com/raw.php?i=ayyGwmHw", "Data"][[1]]; f = Interpolation[data] FindRoot[f[x] = -3, {x,-.001}]` Produces the following error message: > Set::write: Tag InterpolatingFunction in > InterpolatingFunction[{{-0.0316228,-0.0000316225}},{4,7,0,{100},{4},0,0,0,0,Automatic},{{-0.0316228,<<49>>,<<50>>}},{Developer`PackedArrayForm,{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,<<51>>},{-3.18065,-3.1091,-3.03726,-2.9653,-2.89326,-2.82049,-2.74795,-2.67462,-2.6016,-2.52775,-2.45388,-2.37942,-2.3048,-2.22943,-2.15383,-2.07749,-2.00068,-1.92324,-1.84519,-1.76636,-1.68673,-1.6063,-1.52493,-1.44259,-1.35918,-1.2746,-1.18877,-1.10161,-1.01302,-0.922938,-0.831354,-0.738193,-0.643498,-0.547431,-0.450204,-0.352232,-0.25411,-0.156647,-0.0608189,0.0322768,0.121594,0.206229,0.285555,0.359262,0.427319,0.489892,0.547309,0.599959,0.648252,0.692602,<<50>>}},{Automatic}][x] > is Protected. >> > > FindRoot::jsing: Encountered a singular Jacobian at the point {x} = > {-0.001}. Try perturbing the initial point(s). >>


A simple ListPlot with different colours and a Tooltip

I know that the threads ListPlot with each point a different color and a legend bar and Extracting the coordinate of a particular point of interest from a ListPlot are somehow the answers to my questions but I am having a hard time understanding them when trying to apply them to the following problem:               ListPlot[{{0,1},{0,0},{1,0},{1,1},{0.5,0.2}},        PlotStyle->Directive[PointSize[Large]]]      The x-coordinate of the first four points won't change; only the y-coordinate will. {0,1} and {1,0} must have the same color; {0,0} and {1,1} must have the same colour but different from the first case and {0.5,0.2} a different color when compared to the other two cases. The resulting plot must also have the value of the y-coordinate for each point shown all the time (no need to click a mouse or the like). I believe that the solution should be self-contained within `ListPlot` since I am planning to use it inside a `Manipulate` with other plots.


windrose with data from Excel

How to Import data from excel and use them to Plot windrose instead? Example, `{{Strength, Angle(degrees)}..}`               data = {{11.84,24.70}, {13.64,0}, {14.11,24.70}, {11.92,16.20}, {7.95,337.10},              {8.34,326.60}, {7.85,335.40}, {8.90,6.30}, {10.43,338.40}, {10.36,325.60},              {10.93,332.00}, {14.78,318.20}, {14.30,345.30}};      $0$ is `North`.


How to find full names of all packages already on the $Path?

I'll show one specific example of what I am trying to do, I think it will explain things. On the default `$Path` there exist (in version 8) the following 4 packages               DifferentialEquations`BoundaryRegionPlot`     DifferentialEquations`NDSolveProblems`     DifferentialEquations`NDSolveUtilities`     DifferentialEquations`InterpolatingFunctionAnatomy`      These happened to be located in               C:\Program Files\Wolfram Research\Mathematica\8.0.4\AddOns\ExtraPackages\DifferentialEquations      Currently to load these packages, I load each one explicitly, using the full name. I have a list of all packages, and go over each package listed to load it. (I searched all the folders and opened all the .m files to find listing of all packages, then copied the names and put them in a list). I am trying to find a way to automatically obtain the full names of these packages. Then load them, so that I do not have to have the names hardcoded in a list, which I have to update when things changes. (say when version 9 is out) I will be happy if I can find a way to find obtain full name of packages that starts with some context name. For example, here, if I can find a way to find names of packages that start with context `DifferentialEquations` before loading the packages ofcourse. I'd like to be able to tell Mathematica: Please load all packages you find on the $Path that has such a name, and I give a name as a string pattern, may be using wildcard. Then I can type                <<DifferentialEquations`*      and have all those 4 packages loaded. The above does not work, since there is no such package. Or tell Mathematica to find me the full name of all packages in the $Path, then I can use the result of this to load them. Ofcourse all of this would this will require a program to go open each .m file found in the `$Path`, parse the content of the file to determine if it is a package or not, and if so, read the package name from the .m file. I thought to ask in case there is a way or a command or a trick to do this already that I have overlooked. thanks


recursively solve equation and saving the values

I am new to Mathematica. I am trying to recursively solve an equation and saving the values into a `Table`. Since I need the real solutions only I use `Reduce`. The following is my code:               f = 5.68672 T + 6.46776 T^3          t = Table[i, {i, 0.2, 3, 0.2}]          sols = Table[Reduce[f == t[[i]], T, Reals], {i, Length[t]}]     {T == 0.0351204, T == 0.06995, T == 0.104221, T == 0.137708,       T == 0.170237, T == 0.201687, T == 0.231988, T == 0.26111,       T == 0.289058, T == 0.315857, T == 0.34155, T == 0.366188,       T == 0.389828, T == 0.412529, T == 0.434347}      The solution is OK as I compared it to other software as well. The only thing that matters me is how to remove the T== , i.e. I just need the solution and then to copy this into another table, say sols2 that contains               sols2 = {0.0351204, 0.06995, 0.104221, T == 0.137708,.., 0.434347}      I tried the following: `sols2 = T/.sols` but get the following error: > >     sols2 = ReplaceAll::reps: ... is neither a list of replacement rules nor >        a valid dispatch table, and so cannot be used for replacing. >> >   Does anyone know how to remove the T==?


Autonomous equations' critical points and eigenvalues

I have three-dimensional autonomous equations and want to find their critical points and corresponding eigenvalues. They have 6 critical points each. `x`, `y` and `z` are functions of time and `m` is a function of `z/y`               x'=-1 - z - 3*y + x^2 - x*z,     y'=(x*z/m[z/y]) - y*(2*z - 4 - x),     z'=-(x*z/m[z/y]) - 2 z*(z - 2),      I wrote this code but it didn't work. Top of the page says running but nothing happens.               f[x, y, z] == -1 - z - 3*y + x^2 - x*z     g[x, y, z] == (x*z/m[z/y]) - y*(2*z - 4 - x)     h[x, y, z] == -(x*z/m[z/y]) - 2 z*(z - 2)          sys == {D[x[t], t] == f[x[t], y[t], z[t]],        D[y[t], t] == g[x[t], y[t], z[t]],        D[z[t], t] == h[x[t], y[t], z[t]]};          Solve[{f[x, y, z] == 0, g[x, y, z] == 0, h[x, y, z] == 0}, {x, y, z}]


3D arrow tail properties

I would like to use `VectorPlot3D` to plot a vector field with 3D arrows:               B1 = 0.0005;  (*G/μm*)     B2 = -2*B1;     b[x_, y_, z_, Bf_] := {B1*x, B1*y, B2*z + Bf};          VectorPlot3D[b[x, y, z, 0], {x, -13, 13}, {y, -13, 13}, {z, -13, 13},                   PlotRange -> {{-13, 13}, {-13, 13}, {-13, 13}},                   VectorScale -> {0.1, 1, None}, VectorPoints -> {6, 6, 5},                   VectorStyle -> {"Arrow3D", Red},                   RegionFunction -> Function[{x, y, z}, x^2 + y^2 + 2 z^2 < 13^2],                   Boxed -> True, Axes -> False]      Is there a way to change the properties of the 3D arrow tails? For example, to make them thicker. I'm guessing it has something to do with the `Tube[]` function, but I cannot quite figure it out. Thanks in advance!


Logarithmic slider

Is it possible to create a logarithmic slider similar to this one that responds to a change of the variable value? That is, when the slider is moved, the variable value should update. When the variable value is changed separately, the slider position should update too. The ultimate aim is to use this in `Manipulate` and have both a text input and a logarithmic slider input for the same parameter. * * * The post I linked to does not address changing the slider position when the variable is changed elsewhere.


Optimizing a function containing a complex exponential

I've noticed the following significant different in performance for different formulations of the same function:               Exp[-t - 256 I Pi t] == Exp[-t] Exp[-256 I Pi t]     Table[Exp[-t - 256 I Pi t], {t, 0, 1, 1/30000}]; // AbsoluteTiming     Table[Exp[-t] Exp[-256 I Pi t], {t, 0, 1, 1/30000}]; // AbsoluteTiming     (* True, 0.765, 0.496 *)      I've got a function with the form below, which oddly splits the difference               func[a_, b_] := Exp[-a t] Exp[-b I Pi t]     func[1, 256] == Exp[-t - 256 I Pi t]     Table[func[1, 256], {t, 0, 1, 1/30000}]; // AbsoluteTiming     (* True, 0.614 *)      The way _Mathematica_ is storing the complex exponential seems to be the slower one:               Exp[-t - 256 I Pi t]     Table[%, {t, 0, 1, 1/30000}]; // AbsoluteTiming     Exp[-t] Exp[-256 I Pi t]     Table[%, {t, 0, 1, 1/30000}]; // AbsoluteTiming      ![enter image description here](http://i.stack.imgur.com/fpsE9.png) The issue does appear to be caused by the presence of complex values               Exp[-t - 256  Pi t] == Exp[-t] Exp[-256  Pi t]     Table[Exp[-t - 256  Pi t], {t, 0, 1, 1/30000}]; // AbsoluteTiming     Table[Exp[-t] Exp[-256  Pi t], {t, 0, 1, 1/30000}]; // AbsoluteTiming     (* True, 0.37, 0.37 *)      I can reproduce this behavior in v9 and v10 on Win 7/64-bit. I am looking for insight into how one might achieve the speeds observed when the exponential terms are not combined.


Automatically close Mathematica

It seems there are a lot of related topics but I haven't found an answer. I want to automatically quit _Mathematica_ after some procedures are done but dialog window appears:               1 + 1;     NotebookSave[EvaluationNotebook[]];     FrontEndExecute[FrontEndToken["FrontEndQuit"]]      ![enter image description here](http://i.stack.imgur.com/mTJcI.png) One can put this inside `Button`               Button["close",             1 + 1; NotebookSave[EvaluationNotebook[]];             FrontEndExecute[FrontEndToken["FrontEndQuit"]]           ]      what will work but I need it works as a part of procedure because the notebook is called automatically and no one is going to click OK. This Q&A is almost a duplicate of undisputed FrontEndTokenExecute but there was the work around. **I appreciate a work around but also the general question, how to stop or automatically agree with`Dialogs` is what I'm interested in.** Maybe it's relevant: Win XP/Win 7 _Mathematica_ V9.0.0.1


Understanding Dirichlet regularization in Sum

I've tried to calculate few classic sums using Dirichlet regularization:               Sum[n, {n, 1, ∞}, Regularization -> "Dirichlet"]     Sum[n^2, {n, 1, ∞}, Regularization -> "Dirichlet"]      I get expected results: `-1/12` and `0`. But when I start sum from the `0`, I notice an interesting pattern: $$ \sum_0^\infty n^k - \sum_1^\infty n^k = (-1)^{k+1}\frac{1}{k + 1} $$ I'm having trouble understanding this. Is this some misuse of Dirichlet regularization in _Mathematica_ , or some interesting (or not) thing in the math itself?


Image partition according to contours

I want to extract contours from following image or I am wondering how to partition following image: line image looks like: ![enter image description here](http://i.stack.imgur.com/agPO0.png) This question is linked: How to superimpose contour lines on transformed image


How can I set an image as the background of a panel?

Is it possible to set an `Image` as the `Background` of a `Panel`? I've studied all the options in the Documentation center, but didn't find anything about it.                 image=Import["http://i.stack.imgur.com/U6Pby.jpg"]      ![Background Image](http://i.stack.imgur.com/U6Pby.jpg)                 Panel[Style["This is Infratab",                      Bold,                      20,                     Editable -> False                    ],            Background -> image, Alignment -> Center, ImageSize -> {400, 400}       ](*panel is closed*)      Instead of a color, I want to set `image` as background of the `Panel`.


Using MousePosition on the entire screen - Screencast with Linux

In order to record animations more easily while using _Mathematica_ on _Linux_ , I would need to know how to get the position of three clicks. The following picture (main part generated by `Panel[Graphics@Disk[], ImageSize -> 200]`) shows the idea: ![enter image description here](http://i.stack.imgur.com/ryLAL.png) `Dynamic@MousePositon[]` shows the coordinates of the mouse within the _Mathematica_ window but how to save the position of the clicks? (knowing that `EventHandler` works only in the Output cell). Then the idea is to get `posi={xi,yi}` and to record the screen (using byzanz) automatically:               time = 5; delay = 2; path = "test";     toGIF = ToString@StringForm[       "byzanz-record --duration=`` --x=`` --y=`` --width=`` --height=`` --delay=``",       time, First@pos1, Last@pos1, Subtract[#, #2] & @@ (First /@ {pos2, pos1}),       Subtract[#, #2] & @@ (Last /@ {pos3, pos2}), delay] <> path <> ".gif"      Then `Run@toGIF` would produce the GIF.


How to study the sign of an expression including a function, with conditions on the function?

I'm trying to study the sign of an expression, having information on some of my parameters. I don't know how to code these conditions. For example, I want to know when this expression:               k (2(a'[x])^2 - a[x]a''[x]) / (a[x]^2)       is positive given that `k > 0`, `x > 0` and that my function `a` is positive and increasing for all `x > 0` (`k` is a constant, `a` is a function) So basically, since `a''[x]` is the only term of the equation that I don't know anything about, I want _Mathematica_ to give me:               (* a''[x] < a'[x]^2/a[x] *)


Simulating discrete time stochastic dynamic systems

What is the canonical way of simulating discrete time stochastic dynamical systems in _Mathematica_ using the new functionality of Random processes? To take a concrete example, lets consider the optimal gambling problem. A gambler comes to a casino with an initial fortune $x_1$ and let $X_n$ denote his fortune at time $n$. At each time he bets a fraction $\alpha x_n$. At each time he wins with probability $p$ and loses with probability $(1-p)$. Thus, the dynamics of the system can be written as: $$ X_{n+1} = \begin{cases} (1+\alpha) X_n, & \text{with probability } p \\\ (1-\alpha) X_n, & \text{with probability } 1-p \\\ \end{cases} $$ I want to simulate this system for 20 time steps with $x_1 = 12$, $p=0.8$, and then plot 50 sample paths and the mean value of $X_{20}$.


integrating slightly complicated expression which includes Abs

I have been waiting for _Mathematica_ to give me something for the following integral, errors welcome, but it has been "running" for almost 30 minutes now.                    h[s_] := If[1 < s, 1, 0]          Integrate[                   Abs[1/(b1^2 + b2^2)                    2 E^(-b1 s) ((a1 b1 + a2 b2) E^(                   b1 s) - (a1 b1 + a2 b2) Cos[b2 s] + (-a2 b1 + a1 b2) Sin[                    b2 s]) - h[s]],  {s, 0, Infinity}, Assumptions -> b1 > 0]      Is there a way to simplify this so that _Mathematica_ would not take this long, or is this an entirely lost case? Thank you in advance.


How to exchange two arguments?

Recently, I have being using _Mathematica_ to write my undergraduate paper. I want to use two pattern lists such as `{ A -> a, B -> b, c -> C, ....}` and `{ a -> A, b -> B, c -> C, ....}` to make my code short. I can exchange `{ A -> a, B -> b, c -> C, ....}`'s elements to achieve `{ a -> A, b -> B, c -> C, ....}`, my trail is as below:               firstPattern = { A -> a, B -> b, c -> C, one -> two, tom -> david};      To achieve `{ a -> A, b -> B, C -> c, two -> one, david -> tom}`, I write the code:               {#1, #2} -> {#2, #1}& /@ firstPattern      However, it failed. I wonder why and how to correct it.


How can I terminate a running computation in Manipulate?

I want to make a simple cdf file that makes some hard computations inside Manipulate. Is there a simple way, lets say using a "stop!" Button, to terminate the time consuming calculations--without closing the web browser or Mathematica? To clarify my self: The following code works well because 2014 is not large enough, so Mathematica can easily compute the sum of Logs. `Manipulate[tick; tot = 1. Total[Log@Range[2014]]; color = Green;, tot, Button["Run", color = Red; tick = Not[tick], Background -> Dynamic@color], {{color, Green}, None}, {{tot, 0}, None}, {{tick, False}, None}, TrackedSymbols :> {tick}]` but when I introduce range at the place of 2014 as in :               Manipulate[tick;      tot = 1. Total[Log@Range[range]];      color = Green;      tot, Button["Run", color = Red; tick = Not[tick],        Background -> Dynamic@color], {{color, Green}, None}, {{tot, 0},        None}, {{tick, False}, None}, {{range, 1}, 1, 300000000, 1},       TrackedSymbols :> {tick}]      the things are coming very bad for huge values of range! So my question is : Is it possible to terminate a running calculation from inside Manipulate?


Generating all matrices with 1 (possibly) replaced by -1

I have a matrix $M$, whose dimension I am unsure of, which has only $\lbrace0,1\rbrace$ entries. I would like to generate all the possible matrices that result from changing (some subset) of the $1$'s to $-1$'s. For example, if $M=\lbrace\lbrace0,1\rbrace,\lbrace 1,0\rbrace\rbrace$, then I would like to generate the list: $$ \lbrace\lbrace\lbrace0,1\rbrace,\lbrace 1,0\rbrace\rbrace,\lbrace\lbrace0,-1\rbrace,\lbrace 1,0\rbrace\rbrace,\lbrace\lbrace0,1\rbrace,\lbrace -1,0\rbrace\rbrace,\lbrace\lbrace0,-1\rbrace,\lbrace -1,0\rbrace\rbrace\rbrace.$$ I am trying to use ReplaceList to do this, but it is not working out exactly as I would want. For example, here is an example for a 2x2 matrix:               ReplaceList[{1, 1, 1, 1},      {{x___, 1, y___} -> {x, -1, y},     {z___, 1, x___, 1, y___} -> {z, -1, x, -1, y},     {t___, 1, z___, 1, x___, 1, y___} -> {t, -1, z, -1, x, -1, y},     {1, 1, 1, 1} -> {-1, -1, -1, -1}}]      Not exactly extensible (nor very pretty). Is there a nice way to do this? Again, I would like to have code that works regardless of dimension, and also accepts as input a matrix (you might notice I Flattened my 2x2 above), and returns a list of matrices. Thanks!


Analytically finding critical values in a hysteresis curve made with ListPlot

Let me start with a super basic explanation of what I'm trying to do, and I will follow with a more detailed discussion afterwards. From data in the form shown below (a `Table[]` of `(x,y)` pairs), I would like to   1. Extract the coordinates of the left-most and right-most points. I know how to find the minimum and maximum x-coordinates but not the corresponding y-coordinates.   2. Extract the x-value for which a sharp transition occurs between two saturated y-values. I'm trying to figure out if there's a way to find things like saturation and coercivity in a hysteresis curve from real data using Mathematica. For those not familiar, hysteresis curves generally looks something like this: ![enter image description here](http://i.stack.imgur.com/zA0ur.jpg) Pardon the overlay of 3 different plots but this is particularly helpful as it shows the sometimes varied nature of such curves. I have a variable which is a `Table` of `(x,y)` pairs of my data,               pairs =      Table[{xvalues[[x]], yvalues[[x]]}, {x, 1,      Length[xvalues]}]      From this data I would like to extract the saturation and coercivity (labeled `M_s` and `H_c` respectively in the image above). The curves are not in general not centered about `H=0` and `M=0`. A common definition for the coercivity is to take the x value for which the y value is half way between its min and max, and this is what I was planning on using. A possible issue is that most of my curves don't have a physical data point corresponding to this because the transition is very sharp (like the blue curve above) and occurs faster than I am sampling. There is an example below. For the saturation, a cheap trick would be to take the left-most and right- most data points. However, I'm not entirely sure how to go about that even though it sounds pretty simple. I could find the minimum and maximum x-coordinates using something like               Min[Table[pairs[[x, 1]], {x, 1, Length[pairs]}]]      but then I don't know how to get the corresponding y-coordinate. Maybe the approach should be very different... The overall issue is I will be analyzing hundreds of data sets like this and it is completely impractical to try to find these values by hand. Here is an example of what some of my real data looks like: ![enter image description here](http://i.stack.imgur.com/j69Rn.png) Edit: Here is a sample data set in a csv file. I use the following code in Mathematica to import the csv and make the data usable:               imp = Import["sampledata.csv", "Table"];     coilcurrents = Table[.8*imp[[x, 1]], {x, 1, Length[imp]}];     resistances = Table[0.05/imp[[x, 2]], {x, 1, Length[imp]}];     pairs = Table[{1810*coilcurrents[[x]], resistances[[x]]}, {x, 1,      Length[coilcurrents]}];     plot = ListLinePlot[pairs, Frame -> True,      ImageSize -> {575.`, Automatic}]      The first few lines convert the raw data to meaningful units and can be ignored for all intents and purposes. If anyone is feeling ambitious enough to try something out with this data, be my guest! Added in response to a suggestion. **Final Edit:** I've accepted an answer. Here is what my code looks like (the appearance of "25" everywhere is because I have Python spit out my Mathematica code and loop over a bunch of iterations):               imp25 = Import["RHLoopArrayV(25).csv", "Table"];     coilcurrents25 = Table[.8*imp25[[x, 1]], {x, 1, Length[imp25]}];     resistances25 = Table[0.05/imp25[[x, 2]], {x, 1, Length[imp25]}];     pairs25 = Table[{1810*coilcurrents25[[x]], resistances25[[x]]}, {x, 1,          Length[coilcurrents25]}];     pairsordered25 = Sort[pairs25];     pairpairs25 = Partition[pairsordered25, 2, 1];     thresh25 = (Max[pairs25[[All, 2]]] - Min[pairs25[[All, 2]]])/2.     distantcousins25 =        Select[pairpairs25, Abs[#[[1, 2]] - #[[2, 2]]] > thresh25 &];     jumps25 = {distantcousins25[[1, 1, 1]], distantcousins25[[-1, -1, 1]]}     rsat25 = {First[SortBy[pairs25, First]][[2]],        Last[SortBy[pairs25, First]][[2]]}     hmin25 = First[SortBy[pairs12, First]][[1]];     hmax25 = Last[SortBy[pairs12, First]][[1]];     plot25simp =        ListLinePlot[pairs25, Frame -> True,         ImageSize -> {575.`, Automatic}];     out25=Show[plot25simp,       Graphics[{Thick, Green,         Line[{{jumps25[[1]], rsat25[[1]]}, {jumps25[[1]], rsat25[[2]]}}]}],       Graphics[{Thick, Green,         Line[{{jumps25[[2]], rsat25[[1]]}, {jumps25[[2]], rsat25[[2]]}}]}],       Graphics[{Thick, Green,         Line[{{hmin25, rsat25[[1]]}, {jumps25[[2]], rsat25[[1]]}}]}],       Graphics[{Thick, Green,         Line[{{jumps25[[1]], rsat25[[2]]}, {hmax25, rsat25[[2]]}}]}],FrameLabel -> {"", "", Text[Style["Device 25", Large]], ""}]      This gives me a plot of the real data as well as a representation of the values found by Mathematica.


Are table headings functional?

Are table headings for aesthetics only? If I have:               table1 = TableForm[{{1, 1, 0, 0, 0}, {0, 1, 0, 0, 0}, {0, 0, 1, 0, 0}, {0, 0,         1, 1, 1}, {0, 0, 1, 0, 1}, {1, 1, 0, 0, 0}, {0, 1, 1, 0, 0}},       TableHeadings -> {{"1", "2", "3", "4", "5", "6", "7"}, {"a", "b",          "c", "d", "e"}}]      Is there any way to refer to a part of the table by the heading names? For example, if I want the position of all 1's in the table,               Position[table1, 1]      I would like this to return both numbers and letters. Is this possible? I apologize if this question is elementary. Any help is much appreciated!


Force ellipsis to print an end of an expression

For pedantic reasons I want to display an infinite sum of fractions in fractional form (i.e. as 1/x not as x^(-1)) with an ellipsis at the end of the expression. I have tried a number of ways and none seem to give me what I want. For example               HoldForm[1/#^s] & /@ Table[3^n, {n, 1, 4}]     {1, %, \[Ellipsis]} // Flatten     (Plus @@ %) // TraditionalForm      gives me output ordered as: **fractional forms + ... + 1** , while StandardForm gave me **1 + ... + the fractional forms**. Other ways I tried led to similar forms - none of them yield the book form of **1 + fractions + ...** that I want. I am probably missing something simple here - Thank you for any help


How can I see which transformations Simplify attempts?

The documentation for Simplify[expr] says that it _performs a sequence of algebraic and other transformations on expr, and returns the simplest form it finds._ How can I see which transformations it applies?


Lie-Bracket of two vector fields

I'm new to Mathematica (installed couple of hours ago) and I need to compute a few Lie brackets between two vector fields $f$ and $g$. $$ f\left(\mathbf{x}\right) = \left( \begin{array}{c} x_3\\\ x_4\\\ \frac{-2m_2x_2x_3x_4 -g\cos\\!\left(x_1\right)\left(m_2x_2 + m_1r\right)}{m_2{x_2}^2 + m_1r^2 + J_1 + J_2}\\\ x_2{x_3}^2 - g\sin\\!\left(x_1\right)\\\ \end{array} \right)$$ $$g\left(\mathbf{x}\right) = \left( \begin{array}{c} 0\\\ 0\\\ \frac{1}{m_2{x_2}^2 + m_1r^2 + J_1 + J_2}\\\ 0\\\ \end{array} \right) $$ Where the vector for variables is $\mathbf{x}=\left(x_1,x_2,x_3,x_4\right)^T$. To compute the Lie bracket of $f$ along $g$ I need to do the following: $$\left[f,g\right] = \frac{\partial g}{\partial x} f - \frac{\partial f}{\partial x} g $$ And to do that I need the Jacobian of $f$ and $g$ which seems I can't do in Mathematica. I used the following code for $f$:               f  = {{x3}, {x4}, {-(2 m2 x2 x3 x4 + g Cos[x1] (m2 x2 + m1 r))/ (m2 x2^2 + m1 r^2 + J1 + J2)}, {x2 x3^2 - g Sin[x1]}}     x = {{x1}, {x2}, {x3}, {x4}}     jf = D[f, {x}]     jf // MatrixForm      This code while it gives the numerical values somehow correct, it kinda mess up the dimensions of the results. It should be a $4 \times 4$ matrix, but it gives me a $4 \times 1 \times 4 \times 1$ tensor. What am I doing wrong here ? The output of `jf`:               {{{{0}, {0}, {1}, {0}}}, {{{0}, {0}, {0}, {1}}}, {{{(g (m1 r + m2 x2) Sin[x1])/(J1 + J2 + m1 r^2 + m2 x2^2)}, {(-2 m2 x3 x4 - g m2 Cos[x1])/(J1 + J2 + m1 r^2 + m2 x2^2) - (m2 x2 (-2 m2 x2 x3 x4 - g (m1 r + m2 x2) Cos[x1]))/(J1 + J2 + m1 r^2 + m2 x2^2)^2}, {-((2 m2 x2 x4)/(J1 + J2 + m1 r^2 + m2 x2^2))}, {-((2 m2 x2 x3)/(J1 + J2 + m1 r^2 + m2 x2^2))}}}, {{{-g Cos[x1]}, {x3^2}, {2 x2 x3},0}}}}     Dimensions[jf]     {4, 1, 4, 1}


Evaluation of a triple sum does not finish in reasonable time

I'm trying to compute the following triple sum, but no result is produced within a reasonable amount of time. What to do?               Sum[1/( i j k (i + j + k + 1)), {i, 1, Infinity}, {j, 1, Infinity}, {k, 1, Infinity}]      I use _Mathematica_ 8.0.


Extract a smaller matrix from a bigger one

May be duplicate, but, how it is possible to make a matrix or table of smaller dimensions, from a matrix with bigger dimensions. I mean, one may want to extract a 25*25 table from a 25*50 matrix. I did not understand the solutions mentioned in this page and this one.


Syntax highlighting conflict

I'm trying to syntax highlight this expression: x=$\sqrt{\pi }$//N and from various sources I've learned that x (the assigned symbol) belongs to context Global while the Pi and N belongs to System. So I set out to change the style of both using a hodgepodge of tips I gleaned from this StackExchange as well as from StackOverflow. However, the weird thing is that the style changes do not add to each other. If I change the style of System, any previous style change to Global would be wiped away, and vice versa. In other words, I can have syntax highlighting for either System, or Global, but not both. This could be seen from these screenshots (sorry for the small font, code added): * * * First line:               SetOptions[$FrontEndSession,       "AutoStyleOptions" -> {"SymbolContextStyles" -> {"System`" ->            RGBColor[211./255, 54./255, 130./255]}}] (*magenta*)      ![System Magenta](http://i.stack.imgur.com/w2whO.png) _Setting System style: magenta_ * * * Second line:               SetOptions[$FrontEndSession,       "AutoStyleOptions" -> {"SymbolContextStyles" -> {"Global`" ->            RGBColor[181./255, 137./255, 0./255]}}] (*yellow*)      ![Global Yellow](http://i.stack.imgur.com/3qXqO.png) _Setting Global style: yellow; when evaluated, previously set System style was wiped out_ * * * Could anyone guide me toward getting syntax highlighting for both of them? I really hope MMA has better syntax highlighting on their future releases.


Create polynomials from Series

This question actually doesn't have quite a lot to do with the `Series` function, but I don't know how to describe my problem. So here's the thing. I'm trying to plot function `f[x]` and its Maclaurin expansion together               ff[n_,x_] := Normal@Series[f[x],{x,0,n}]      But when I feed `ff` with an `x`, Mathematica always substitute the `x` in the expression with its actual value, which is not how `Series` works. So how could I hold the numerical value of `x` until `Series` finishes its calculation? This problem always happens to me, though in different contexts, and I used to find ways around it, but this time I want to solve it in the correct way.


Derivatives of list elements

Could someone explain the odd behavior of the `Derivative` function when drawing arguments from lists? We have,               Derivative[1][a + #*(b - c) &]     (* b - c & *)      and analogously,               Derivative[1][{a1, a2} + #*({b1, b2} - {c1, c2}) &]     (* {0, 0} + {b1, b2} - {c1, c2} + ({0, 0} + {0, 0}) #1 & *)      So far so good. However,               lst = {{a1, a2}, {b1, b2}, {c1, c2}};     Derivative[1][lst[[1]] + #*(lst[[2]] - lst[[3]]) &]     (* {lst[[2]] - lst[[3]], lst[[2]] - lst[[3]]} & *)      Why is the output in the last case not,               lst[[2]] - lst[[3]] &      as one would expect based on the previous examples? Why do I get a list of lists as an answer, instead of just a list? (And what should I do to get the expected result?)


SetPrecision within Block

I am reading Mathematica Cookbook, chapter 1. Author gives two examples, with the following explanation > You can control precision within a complex calculation (without using `N[]` > on every intermediate result) by changing these values; however, you should > only do so within a `Block` (a local context). For example, compare the > difference between a calculation with automatic precision for intermediate > results to the same calculation with fixed precision (obtained by making > `$MinPrecision == $MaxPrecision` ).               In[1]:= SetPrecision[(1 + Exp[Sqrt[2] + Sqrt[3]])/2^25, 32]          Out[1]= 7.226780742612584668840452114476*10^-7          In[2]:=         Block[{$MinPrecision = 32, $MaxPrecision = 32},           SetPrecision[(1 + Exp[Sqrt[2] + Sqrt[3]])/2^25, 32]]          Out[2]= 7.2267807426125846688404521144759*10^-7      Why two results are different, despite the fact that precision was set to 32 digits in both expression ? And what is "automatic precision" ?   Edit: user "rcollyer" points out that > running `Precision` on the two results gives 31.5935 and 32..


How do you change the font size of a Manipulator label?

I have a stand alone `Manipulator` (it is not in a `Manipulate`) and would like to know how to alter the style of the label. There are no explicit styling options for `Manipulator` so I tried wrapping it in `Style`:               Style[      Manipulator[0.5, AppearanceElements -> None,       Appearance -> {"Labeled"}, ImageSize -> Small],      FontSize -> 20]      this didn't work. I have also noticed that I cannot set an image size other than a named size. In other words `ImageSize` does not accept a number!               Manipulator[0.5, AppearanceElements -> None,       Appearance -> {"Labeled"}, ImageSize -> 100]      and               Manipulator[0.5, AppearanceElements -> None,       Appearance -> {"Labeled"}, ImageSize -> 400]      produce the same output. Are these issues possible bugs or am I overlooking something? Q1. How can I change the font size (and other font styling but mainly font size) for the Manipulator label? Q2. How can I make `ImageSize` accept a number rather than a name? **Edit** My question is **not** about what alternatives exist to using `Manipulator`. I have posted an example with `AppearanceElements -> None` so as to make the label the sole focus. However I want the possibility of being able to add back in the `AppearanceElements` is desired/required. The setting `AppearanceElements -> None` obviously looks like a stand alone slider and has led to readers thinking in terms of sliders rather than "fixing" the `Manipulator`. **Edit #2** In situations when no `Manipulator` controls are wanted `Slider` is an alternative but it also has some strange behaviour:               Framed@Slider[Dynamic[x], Appearance -> "Labeled", BaseStyle -> FontSize -> 20, ImageSize -> 100]     Framed@Slider[Dynamic[x], Appearance -> "Labeled", BaseStyle -> FontSize -> 20, ImageSize -> 200]      ![enter image description here](http://i.stack.imgur.com/moTS9.png) So it appears that the label occupies the same image size as the slider! This presents a problem in a GUI layout but there is a work around:               Framed@Pane[Slider[Dynamic[x], Appearance -> "Labeled",      BaseStyle -> FontSize -> 20, ImageSize -> 200], ImageSize -> 260]      ![enter image description here](http://i.stack.imgur.com/Hk9iR.png) But the image space allocated to the label looks like a bug or something unintended. This doesn't address my question but I add it here because slider answered have been given. FWIW: ![enter image description here](http://i.stack.imgur.com/I3MMY.png) **Edit #3** Tech support confirm that the strange image sizing for `Slider` when a label is used is a bug.


How do you define the domain of a plot?

How do you define the domain of a plot? For instance, if I want to plot a standardized bivariate normal density function (with $r=0$), how do I specify the domain to be $[-3,3]$?


Remove singularity at zero from $-((i^{-n} (-1 + i^n)^2)/(n^2 π^2))$

The expression               h[n_] = -((I^-n (-1 + I^n)^2)/(n^2 π^2))       is real for all integers `n`. Although indeterminate at `n = 0`, _Mathematica_ computes the limit to be `1/4` as `n -> 0`. I'd like to use the expression in `DiscreteConvolve`, but even when I first declare `h[0] = 1/4`, a computation like               y[0] = DiscreteConvolve[h, DiscreteDelta[n], n, m]       yields only `h` and its explicit infinite summation representation results in "Indeterminate". How do I make operations with `h` usable?


Finding the centroid of a disk in an image

I got about 100 images of the sun and have to find the centre of the star in the images. I have binarized the images and used `ComponentMeasurements`to find the `Centroid` and the `EquivalentDiskRadius`. So far so good, but I have noticed that in Mma's calculation the centroid appears to have the tendency to gravitate slightly towards the right bottom edge. I first thought that is due to the fact the the disk of the sun is a slight ellipse due to objective imperfection etc but I can replicate the effect with an image I create in Mma using the `Disk` command.               disk = Rasterize[Graphics[{Disk[]}], ImageResolution -> 100];     ndisk = 1 /.        ComponentMeasurements[        ColorNegate@disk, {"Centroid", "EquivalentDiskRadius"}];     pdisk = 1 /.        ComponentMeasurements[disk, {"Centroid", "EquivalentDiskRadius"}];     Show[{disk,        Graphics[{{Red, Circle[ndisk[[1]], ndisk[[2]]]}, {Green,           Circle[pdisk[[1]], pdisk[[2]]]}}]}]      The result of the centroid calculation depends also on whether the disk is positive or negative. What am I missing here or how could I fit a circle to a binary image which contains a **slightly** distorted disk? ![Result of the above Show command](http://i.stack.imgur.com/wTFDS.png) **Edit:** Based on some of the answers I simpified the input image by using an even and an odd sized array.               m = {{0, 0, 0, 0, 0, 0, 0},{0, 0, 0, 1, 0, 0, 0},{0, 0, 1, 1, 1, 0, 0},        {0, 1, 1, 1, 1, 1, 0},{0, 0, 1, 1, 1, 0, 0},{0, 0, 0, 1, 0, 0, 0},        {0, 0, 0, 0, 0, 0, 0}};          k = {{0, 0, 1, 1, 0, 0},{0, 1, 1, 1, 1, 0},{1, 1, 1, 1, 1, 1},        {1, 1, 1, 1, 1, 1},{0, 1, 1, 1, 1, 0},{0, 0, 1, 1, 0, 0}};          circ = 1 /.        ComponentMeasurements[m, {"Centroid", "EquivalentDiskRadius"}]     (* {{3.5, 3.5}, 2.03421} *)          circ2 = 1 /.        ComponentMeasurements[k, {"Centroid", "EquivalentDiskRadius"}]     (* {{3., 3.}, 2.76395} *)          Show[{ArrayPlot[m],        Graphics[{Red, Thick, Circle[circ[[1]], circ[[2]]]}]}]     Show[{ArrayPlot[k],        Graphics[{Red, Thick, Circle[circ2[[1]], circ2[[2]]]}]}]      Gives the results below. ComponentMeasurements finds the right centre in both cases what is off is the Circle that I draw over it. Look at the sizes of the small triangle the circle cuts off the black squares. ![ArrayPlot 1](http://i.stack.imgur.com/5Qlz6.png) ![ArrayPlot 2](http://i.stack.imgur.com/4xTTI.png)


Edges and crossing

I want to make a program where I have a collection of labeled vertices and edges between the vertices such that they join up with edges $a_{1} a_{2}, \; a_{2} a_{3}, \ldots ,\; a_{n} a_{1}$, so the edges form a "circle". Then I want to be able to input whether edges cross each other, and if they do, which edge crosses over and which edge crosses under. Is it possible to do this with _Mathematica_?


Output precision

I've solved some equations using `FindRoot` and then computed some values. Now when I print the output, I only get a certain precision > {{0.01, 496.983, 61.3147, 80., 0.047},   >  {0.02, 496.983, 61.3147, 80., 0.047},   >  {0.03, 496.983, 61.3147, 80., 0.047},   >  ...   >  {0.18, 496.97, 61.3142, 80., 0.047001},   >  {0.19, 496.969, 61.3141, 80., 0.0470011},   >  {0.2, 496.968, 61.3141, 80., 0.0470012}} But when I copy and past the individual numbers, say the 61.3147 in the first two rows, I get > 61.314699633952216`   >  61.31469210981553` What can I do to increase the precision of the visible output so I can eyeball it?


Catching only the first event in NDSolve EventLocator

I have a system of ODEs that I solve. During the integration process, there's an event that I want to catch, but I want to (a) continue the integration after the event and (b) catch only the first one. For example, let's say I want to calculate $\pi/2$ by this method:               flag = False;     NDSolve[{y''[t] == -y[t], y[0] == 0, y'[0] == 1}, y, {t, 0, 20},       Method -> {"EventLocator", "Event" -> ((! flag) && y'[t] == 0),         "EventAction" :> (flag = True; piHalf = t;)}]      For some reason this does not work - the events keep being triggered even though the value of `flag` does change. ![screenshot](http://i.stack.imgur.com/yeXnJ.png) In the end of the process I get $\pi/2=17.28$ (this might be disastrous if I'll use this value to build airplanes!) How can I solve this?


Best way to extract values from a list of rules?

Mathematica has _a lot_ of list manipulation functions, and, also because I don't work with lists often, at times I'm a bit lost. I'll find a way, but I'm sure it's not the most efficient. Case in point, this list:               list = {{x -> -1, y -> 5}, {x -> -1, y -> 6}, {x -> -1, y -> 7}, {x -> 0, y -> 2},       {x -> 0, y -> 3}, {x -> 0, y -> 4}, {x -> 0, y -> 5}, {x -> 0, y -> 6},        {x -> 0, y -> 7}, {x -> 1, y -> 2}, {x -> 1, y -> 3}, {x -> 1, y -> 4},        {x -> 1, y -> 5}, {x -> 1, y -> 6}, {x -> 1, y -> 7}, {x -> 2, y -> 3},       {x -> 2, y -> 4}, {x -> 2, y -> 5}, {x -> 2, y -> 6}, {x -> 2, y -> 7},       {x -> 3, y -> 4}, {x -> 3, y -> 5}, {x -> 3, y -> 6}, {x -> 3, y -> 7},       {x -> 4, y -> 5}, {x -> 4, y -> 6}, {x -> 4, y -> 7}, {x -> 5, y -> 6},       {x -> 5, y -> 7}, {x -> 5, y -> 8}, {x -> 6, y -> 7}, {x -> 6, y -> 8}, {x -> 7, y -> 8}}        I just need the numerical data, then this function:               Transpose[{list[[All, 1]][[All, 2]], list[[All, 2]][[All, 2]]}]      gives me the desired result, but it doesn't look good, and I'm afraid of wearing out my `[` and `]` keys.               {{-1, 5}, {-1, 6}, {-1, 7}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {0, 6}, {0, 7},       {1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, {1, 7}, {2, 3}, {2, 4}, {2, 5},       {2, 6}, {2, 7}, {3, 4}, {3, 5}, {3, 6}, {3, 7}, {4, 5}, {4, 6}, {4, 7},       {5, 6}, {5, 7}, {5, 8}, {6, 7}, {6, 8}, {7, 8}}        What's the best way to extract the data from the list?


Removing -> from list of numbers

> **Possible Duplicate:**   >  Best way to extract values from a list of rules? If I have a vector v = {x->1.03, x-> 2.01, .... }, and I want to use an element in the list, I can get an element as v[[1]] = x-> 1.03 but suppose I want to get rid of the arrow? Thanks for any suggestions.


LMS distance from a point to an InterpolatingFunction

I have a short script to `NDSolve` a second-order nonlinear BVP, which as its output produces an `InterpolatingFunction` object. I would like to load in some data, and check how well this data fits the function by performing a Least-Mean-Squares sum. I don't know how to go about this with a function represented by one of these `InterpolatingFunction` objects. Minimal(ish) code to produce the function is included below.               {r0, f0} = {1.349, 1.421}; {r1, f1} = {3.913, 0.044};     eqn = 2 H == f''[r]/((1 + f'[r]^2)^(3/2)) + (1/r) (f'[r]/(1 + f'[r]^2)^(1/2));     H = -0.021414;     F = First[f /. NDSolve[{eqn, f'[r0] == -1.127435, f[r1] == f1}, f, {r, r0, r1}]]      Any help would be appreciated.


Finding undetermined coefficients with boundary conditions

I have 2 equations which are;               To[x_] := c1 E^(-a1 x)/2 + c2 E^(a1 x)/2 + a2          Tu[x_] := c3 E^(-a3 x)/2 + c4 E^(a3 x)/2      Tu equals almost zero `(10^-6)` at end of the wires. To must be equal to Tu at +-L/2. Also To has to be continous at +-L/2 by using Drichlet boundary condition which is `To'[L/2] == a4 Tu'[L/2]`. In order to understand easily, Tu shows ends of figures, and To shows middle of the figure.![enter image description here](http://i.stack.imgur.com/JfBty.png) All things considered, I have 4 coefficient and 4 boundary conditions which have to satisfy each other. Functions have to be symmetric , therefore I wrote a trigonometric form as a Cosh[x]. How can I find c1 and c2 to satisfy all boundary conditions ? I wrote a program with Mathematica. But it is wrong. I think that something is wrong on finding c1. Can anyone help my code ? Here is my code:               To[x_] := 2 c1 Cosh[x a1] + a2     Tu[x_] := 2 c2 Cosh[x a3]           ff = Solve[Tu[Le] == 0.000001,c2]          bcs = {To[L/2] == Tu[L/2], To'[L/2] == a4 Tu'[L/2]};     s = First@Solve[bcs[[1]], c1]     Quiet@Solve[bcs[[2]] /. s[[1]], c1]


Plot list of million points

I am working on large datasets of size $10\times 10^6$ and would like to visualize these in _Mathematica_ , but they take lot of time to plot. How can I speed it up? I also want to save the plots as PDFs. Here is the equivalent _MATLAB_ code, which is fast                n=16000000;      x=([-(n/2)+1:1:n/2]*0.5);      y=([-(n/2)+1:1:n/2]*2.5);      plot(x,y)      In _Mathematica_               n = 16000000;     x = Range[-(n/2), n/2]*0.5;     y = Range[-(n/2), n/2]*2.5;     ListLinePlot[{x, y}\[Transpose], PlotRange -> All]


Change ticks from number to hours

I have an unidimensional array (let's call it **list** )ranging from 0 to 86400, each one representing a second of a day (a day has 86400 secs). For example,               list = {73496.3, 85974.6, 86085., 86136., 16.6256, 19.6975, 25.8896, 26.1856, 26.3937}      ## ![enter image description here](http://i.stack.imgur.com/05if4.png) My goal is to change the ticks of plotted list with ListPlot, so that instead of the numbers, it gives you the hour. Also, there must be 24 ticks, each one representing one hour. For example, the number 49616 would become 13:46:56


A problem with set values

The following code is just an example to clearly explain my problem. Assume that :               In[1]:= Vars = Table[Symbol["x" <> ToString[i]], {i, 1, 4}];          In[2]:= Partition1 = Partition[Vars, 2];      Which the Results are :               Out[1]:=  {x1, x2, x3, x4}          Out[2]:=  {{x1, x2}, {x3, x4}}      Now, I want to do a calculation using above and following codes like below :               ExtractionCon = {};          Do[       Do[          Extraction = Extract[{{1, 2}, {3, 4}, {5, 6}, {7, 8}}, {i + 1}];          Divided1 = AppendTo[ExtractionCon, Extraction];          , {i, 1, 2}];               SetFunc = MapThread[Set, {Partition1, Divided1}, 2];          , {j, 1, 3}];          SetFunc      When I run this code, following error appears :               MapThread::mptc: Incompatible dimensions of objects at positions {2, 1} and {2, 2} of     MapThread[Set,{{{3,4},{5,6}},{{3,4},{5,6},{3,4},{5,6}}},2]; dimensions are {2,2} and     {4,2}. >>          MapThread::mptc: Incompatible dimensions of objects at positions {2, 1} and {2, 2} of     MapThread[Set,{{{3,4},{5,6}},{{3,4},{5,6},{3,4},{5,6},{3,4},{5,6}}},2]; dimensions     are {2,2} and {6,2}. >>          Out[5]:= MapThread[Set, {{{3, 4}, {5, 6}}, {{3, 4}, {5, 6}, {3, 4}, {5, 6}, {3,     4}, {5, 6}}}, 2]      Clearly, the problem is `MapThread` ( `SetFunc = MapThread[Set, {Partition1, Divided1}, 2];`). It sets the values `{x1,x2}={3,4} and {x3,x4}={5,6}`. For the first Iteration (`j=1`),it works perfectly, but for more than one Iteration ( `{j,1,3}`), it doesn't. I have already used `Clear[]` or `ClearAll[]`, baut I couldn't fixed it. How is it possible to unset and reset the values to do the iterations correctly ? **-EDITED-** As _**Mr.Wizard**_ requested, I put here a better code (I hope!) which unnecessary parts are omitted. I have already add _**Mr.Wizard**_ 's suggestions and corrections into the following code. The inputs are :               Npop = 2;     NPart = 3;     L = 1;     FEN = 16;      Which are `Npop=Number of elements of the Chrom`, `NPart=Number of intervals that I want to have in the outputs`, `L= The unit length that I want to extraxt my intervals from it` and `FEN= The number of whole intervals` .               Chrom = {{0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0}, {1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1}};                         varsP = Table[Symbol["x" <> ToString[i]], {i, 1, 2 NPart}];          Partitionvars = Partition[varsP, 2];          DivideLenghth = Range[0, L, N[L/FEN]];          ElementPosition = Partition[DivideLenghth, 2, 1];          NumberOfPositionCon = {};      `Chrom` is my input with multi-elements (not just one element) for the bellow function:               Clear[DoFunction];     DoFunction[Chrom_] :=     Block[{sigma1, Extraction, SplitChrom, NumberOfPosition,      PositionsOn, ExtractionDL, DivLen, SetEqual, List1},          sigma1 = {};               Do[          ExtractionDLCon = {};               Extraction = Extract[Chrom, {r}];          SplitChrom = Partition[Extraction, Log2[FEN]];          Do[           NumberOfPosition = FromDigits[SplitChrom[[i]], 2];      PositionsOn = AppendTo[NumberOfPositionCon, NumberOfPosition];           ExtractionDL = Extract[ElementPosition, (PositionsOn[[i]] + 1)];           DivLen = AppendTo[ExtractionDLCon, ExtractionDL];           Clear["x*"];           , {i, 1, NPart}];               SetEqual = MapThread[Set, {Partitionvars, DivLen}, 2];          List1 = AppendTo[sigma1, SetEqual];          , {r, 1, Npop}];          List1];      When use `DoFunction[]` with input `Chrom`, the result will be :               In[1]:=DoFunction[Chrom]          Out[1]:= {{{0.0625, 0.125}, {0.125, 0.1875}, {0.5, 0.5625}}, {{0.0625,      0.125}, {0.125, 0.1875}, {0.5, 0.5625}}}      But the correct answer for `In[1]` must be :               The Correct Answer=: {{{0.0625`, 0.125`}, {0.125`, 0.1875`}, {0.5`, 0.5625`}},     {{0.5625`, 0.625`}, {0.625`, 0.6875`}, {0.6875`, 0.75`}}}      It seems that `SetEqual` keeps the values and doesn't reset and save new values for next iterations. Could you please help me with this problem ?


How can I construct a distance table?

I have a list of city names (of arbitrary length), f.e.               c = {"BAL", "NYC", "LAS", "AUS"};      and the distances between them :               d = {232, 318, 467, 285, 670, 530};      With               m = (Flatten /@ Transpose[{c, DiagonalMatrix@Table["x", {Length@c}]}])~Prepend~({""}~Join~c)      I get: ![enter image description here](http://i.stack.imgur.com/nszrd.jpg) Now, misusing `Mathematica` as a typewriter:               m[[2, 3]] = d[[1]];     m[[2, 4]] = d[[2]];     m[[2, 5]] = d[[3]];     m[[3, 2]] = d[[1]];     m[[3, 4]] = d[[5]];     m[[3, 5]] = d[[6]];     m[[4, 2]] = d[[2]];     (* etc. *)      I get: ![enter image description here](http://i.stack.imgur.com/1GDy7.jpg) 1st question: How can I automate this? 2nd question: How can I get a graph of these distances? Thank you in advance for any help