title: How to find out what files are touched when Get is called?

text: Is there a way to **capture all package files touched** whenever a package is called via `Get`, `Needs`, `Beginpackage` or similar? While `FindFile["package`"]` can point to the first file that is called, the problem is not solved yet. The first file might contain additional `Get` (or related) calls that could point to files with completely different names at completely different places. These dependencies can only be resolved at runtime. An idea is hinted in the documentation of `Get`: whenever `Get` is called, it sets `$InputFileName` to the file it reads from. A possible way to capture the temporarily set `$InputFileName` would be to redefine `Get` via the Villegas- Gayley wrapper. Unfortunately, it is not possible, as any further `Get` called _from inside_ a `Get` won't have access to the outermost layer of the redefined `Get`. If someone can do it nevertheless, it would be really useful. Note that in a normal situation, an already loaded package won't be loaded again, so any repeated call would not capture any files. To overcome this, the function must be such that it **always** calls each dependent package/file. For that, it must not leave (too much) footprint on globals (like `$Packages`, `$ContextPath`, etc.).


title: Utility information using FindGeoLocation in Ver.10

text: It is possible for some commuters to track the location of their bus, train or tram through a personalised GPS tracking device (e.g.see http://www.adelaidenow.com.au/news/south-australia/new-timetables- for-51-adelaide-metro-bus-routes/story-e6frea83-1226640915193). My question is can the FindGeoLocation[entity] be used to do this using the latest Ver. 10? What can be substituted for "entity", and can one also obtain information on the location of the nearest shopping center, public school, hospital or other mentionable utilities relative to the user's coordinate location using this command in Ver. 10?


title: invert system of two parametric ODEs and plot results of do-loop

text: I can solve this system of parametric ODE (`u` is the parameter,while `g`,`e` and `zi` are constants depends on the physic of the problem)               zf = -1/2;     g = 1;     e = .2;     Y[t_] :=  g/(2 zf) y[t] + u z[t];     Z[t_] := -g + g/zf z[t] - u y[t];     sol =        FullSimplify[         DSolve[{y'[t] == Y[t], z'[t] == Z[t],y[0] == 0 , z[0] == -zf},           {y[t], z[t]}, t]]      Then, I make the assignement:               zsol[t_] := Evaluate[z[t] /. sol[[1]][[2]]]     ysol[t_] := Evaluate[y[t] /. sol[[1]][[1]]]      My problem is to compare the time `t(u)` taken by trajectories `{y[t,u],z[t,u]}` to reach a neighborhood of `zf` whit radius `e`, with the time `trelax`, relative to `u=0` (`zf` is the fixed point of free dynamic). Not for all `u` the problem has solution: in general, for `u` large enough, trajectories reaches some fixed point in an infinity time following a spiral (as I seen plotting the system for various `u`), cause of the exponential- complex solutions, and there's a set of `u` without solutions (i.e, a set of `u` for which trajectories pass no close to `zf`). Then I have thought to use an iterative costruct, a `do-loop` mixed with an `If`. For simplicity, I've started, in particular, with:               trelax = Log[(-e/(2 zf))]*zf/g;     Do[Do[        If[N[Abs[zsol[T]] <= (zf + e) && N[Abs[ysol[T]] <= e,          If[NSolve[ysol[t], t] <= trelax],             Print[{T, u}]]], {T, 0, .9, .01}], {u, 0, 40, .2}]      Remark_1: `trelax` is the correct analytic result of dynamical system for `u=0`. Remark_2: I expect from this code to obtain a list of couple `{t,u}`, with `t<=trelax` and `u>0`, but really I don't obtain nothing! I think I'm wrong in the definition of the variable in the function...and in many other things! Finally I ask you if is it possible to change the loop to obtain directly a plot `{t,u}`, i.e. a curve to compare with constant `trelax`... Thank you P.S: If you want to see some plots, I attach the ad hoc code:               Clear[u]     u = 5;     ParametricPlot[{y[t] /. sol[[1]][[1]], z[t] /. sol[[1]][[2]]}, {t, 0, 10}, PlotRange-> All]


title: Can you tell (Full)Simplify to introduce a case distinction?

text: I got this term¹ as a partial result $\qquad\displaystyle T = -1 + (-1)^{\frac{1}{3} \cdot (1 - 2 n)} - (-1)^{\frac{2}{3} - \frac{4 n}{3}}$ which Mathematica refuses to (full)simplify further, even assuming that $n$ is a positive integer. By inspecting a plot and verifying by `FullSimplify[T , Mod[n, 3] == k]` for `k = 0,1,2`, I get that $\qquad\displaystyle T = \begin{cases} -3, &n \mathbin{\mathrm{mod}} 3 = 2 \\ 0, &\text{else} \end{cases}$. Is there a way to tell `(Full)Simplify` to prefer case distinctions with simple cases over (complicated) closed forms, or extract a piecewise definition with another function? Preferably without knowing the case conditions a priori, of course. * * *   1. `-1 + (-1)^(1/3 (1 - 2 n)) - (-1)^(2/3 - (4 n)/3)`


title: How to multy-Set a group of lists?

text: I have a group of lists, for example:               lists = RandomInteger[10, {100, 2}]      > >     {{6, 7}, {7, 4}, {3, 3}, ....} >   Now, I want to multy-set as follow:               ls1={6,7};     ls2={7,4};     ,,,,     lsX=lists[[X]]      How to do that by a simple way? Thanks. * * * UPDATE: How about lsX but not ls[X]? I have tried to generate a list of names:               names=ToExpression["ls" <> ToString@# & /@ Range[100]]      How to multy set then?


title: Combining nested lists that meet certain criteria for a permutation

text: I have the following list representing a permutation on 26 characters:               {{G, G}, {O, P}, {V, L}, {Y, Y}, {C, X}, {H, I}, {P, S}, {W, R},      {I, H}, {Q, D}, {X, C}, {J, B}, {D, M}, {K, O}, {R, N}, {Z, K},      {L, Q}, {M, F}, {S, A}, {N, Z}, {A, T}, {E, U}, {T, W}, {B, V},      {F, E}, {U, J}}      How can I "simplify" this list to show the cyclic form of the permutations? A possibility of the above list would be:               {{A, T, W, R, N, Z, K, O, P, S}, {B, V, L, Q, D, M, F, E, U, J},      {C, X}, {G}, {H, I}, {Y}}      I'm new to _Mathematica_ and I could write an ugly loop to do this, but I've noticed that _Mathematica_ usually has elegant solutions for problems like this that I wouldn't be able to think of on my own. Thus, I haven't tried to do anything because I couldn't find anything while searching for this. * * * I could still be overlooking something, but I tried converting the list to numeral values with A=1 and I got the following error:               Cycles::reppoint: Cycles[{{7, 7}, {15, 16}, {22, 12},       {25, 25}, {3, 24}, {8, 9}, {16, 19}, {23, 18}, {9, 8},       {17, 4}, {24, 3}, {10, 2}, {4, 13}, {11, 15}, {18, 14},       {26, 11}, {12, 17}, {13, 6}, {19, 1}, {14, 26}, {1, 20},       {5, 21}, {20, 23}, {2, 22}, {6, 5}, {21, 10}}]     contains repeated integers.


title: How can I delete cells with error messages?

text: I'm new to _Mathematica_ and am unfamiliar with the notebook interface. I haven't been able to delete cells with error messages. For example, when I try to ask _Mathematica_ to compute something, it returns a message like > Solve::nsmet: This system cannot be solved with the methods available to > Solve when it fails. Once I see that, instead of proceeding to the next line, I would like to highlight that error message (along with the erroneous command) and delete it. But _Mathematica_ won't let me do it. How do I do this the right way?


title: Solving Simultaneous Equations

text: I am trying to solve two equations that take the form: > $W_0 \sqrt{1+\left(\dfrac{z}{\lambda\,\pi\, W_{0}^2}\right)}=W_1\;\,\quad > \ldots(1)$ > > $W_0\sqrt{1+\left( \dfrac{z+0.1}{\lambda\, \pi\, > W_{0}^2}\right)}=W_2\quad\;\, \ldots(2)$ The quantities $\lambda, W_1, \text{ and } W_2$ are known parameters. I am trying to solve for the unknowns $W_0\text{ and } z$. How would I go about doing this. The result is to be in the $\mathbb{R}$. My attempts are below: Attempt 1:               Solve[{W Sqrt[1+(z/(\[Lambda] \[Pi] W^2))^2]==A,W Sqrt[1+((z+0.1)/(\[Lambda] \[Pi]     W^2))^2]==B},{W,z}]      Attempt 2:               FindInstance[W Sqrt[1+(z/(\[Lambda] \[Pi] W^2))^2]==A&&W Sqrt[1+((z+0.1)/(\[Lambda]      \[Pi] W^2))^2]==B,{W,z},Complexes]      Attempt 3:               FindRoot[W Sqrt[1+(z/(\[Lambda] \[Pi] W^2))^2]==A,W Sqrt[1+((z+0.1)/(\[Lambda] \[Pi]      W^2))^2]==B,{{W,1.03 10^-3},{z,4.0 10^-1}}]      My question is what is the best method to solve equations such as these and what will yield the best numerical or analytical result.


title: Simulations with MonteCarlo and Autoregressive methods

text: I am trying to find the best-fit trend for my data. Here I just generated it but let's say I don't know my data trend at all.               test = RandomVariate[NormalDistribution[100, 10], 100];     data = TemporalData[test];     proc = EstimatedProcess[data, ARMAProcess[3, 3]];     forecast = TimeSeriesForecast[proc, data, {5}, Method -> Automatic]     sims = RandomFunction[proc, {0, 10^2}, 4];     ListLinePlot[Join[data["Paths"], sims["Paths"]],      PlotStyle -> {Directive[Thick, ColorData[1, 1]], ColorData[10, 1],      ColorData[10, 2], ColorData[10, 3], ColorData[12, 4]},      PlotLegends -> {"data", "Simulations"}, ImageSize -> 550]      As results of the fit shows, neither of AutoRegressive methods of _Mathematica_ are being fitted to my data. How can I use the Euler-Maruyama method mentioned here and disscuded here for fitting my data and have the fitness test data for it? How can I also do the Monte Carlo simulations for them and show upper, lower bound and mean of simulations on my data?


title: How to return the rhs of a transformation rule from within Compile[]

text: I have defined the following function:               g = Compile[{{x0, _Real}},         sol = NSolve[             Rationalize[CDF[ExponentialDistribution[1], x] == x0, 10^-10],             {x}, Reals];        sol]      Running `g[0.5]` it fails with: > In[460]:= g[0.5] > > During evaluation of In[460]:= CompiledFunction::cfse: Compiled expression > {{x->0.693147}} should be a machine-size integer. >> > > During evaluation of In[460]:= CompiledFunction::cfex: Could not complete > external evaluation at instruction 2; proceeding with uncompiled evaluation. > >> > > Out[460]= {{x -> 0.693147}} If I try to extract the rhs from the transformation rule with `sol[[1,1,2]]` I get the following error: > Compile::part: Part specification sol[[1,1,2]] cannot be compiled since the > argument is not a tensor of sufficient rank. Evaluation will use the > uncompiled function. >> > > Compile::part: Part specification {{x->0.693147}}[[1,1,2]] cannot be > compiled since the argument is not a tensor of sufficient rank. Evaluation > will use the uncompiled function. >> How could I let `Compile[]` know that I intend to return `{{a -> b}}` or how could I extract the rhs of the transformation rule and return that only? **EDIT** : It appears that none of my functions (`Rationalize[]`, `NSolve[]`, `ExponentialDistribution[]`) is "compilable" based on this link by @MichaelE2.


title: Parallelization problem in LinearSolve and Minimize

text: My CPU has got 8 cores (it is Intel Core i7-2600 3.40 GHz). When I try to solve a linear matrix equation using LinearSolve for large matrices, Mathematica just uses 4 cores to solve the problem (CPU usage will be 50%). So it means that there is a problem in the Parallel computation options. When I try to Minimize a huge function with several variables, it is even worse and Mathematica just uses one core (CPU usage is about 12%)!! I am not very familiar with Parallel computation, so will be very appreciative if you can help me to solve my problem. How can I use all capacity of the CPU when I run LinearSolve for very large matrices and Minimize for huge functions and make CPU usage 100% to make the computation time as short as possible on my machine?? Thank you very much. ** ## Edit 1: ** My computer for this analysis:               t = AbsoluteTime[];     primelist = Table[Prime[k], {k, 1, 20000000}];     time2 = AbsoluteTime[] - t         Yields a load of 12% on my CPU and time2=43.37 and by breaking this analysis into 8 cores:               t = AbsoluteTime[];     job1 = ParallelSubmit[Table[Prime[k], {k, 1, 2500000}]];     job2 = ParallelSubmit[Table[Prime[k], {k, 2500001, 5000000}]];     job3 = ParallelSubmit[Table[Prime[k], {k, 5000001, 7500000}]];     job4 = ParallelSubmit[Table[Prime[k], {k, 7500001, 10000000}]];     job5 = ParallelSubmit[Table[Prime[k], {k, 10000001, 12500000}]];     job6 = ParallelSubmit[Table[Prime[k], {k, 12500001, 15000000}]];     job7 = ParallelSubmit[Table[Prime[k], {k, 15000001, 17500000}]];     job8 = ParallelSubmit[Table[Prime[k], {k, 17500001, 20000000}]];     {a1, a2, a3, a4, a5, a6, a7, a8} =       WaitAll[{job1, job2, job3, job4, job5, job6, job7, job8}];     time2 = AbsoluteTime[] - t      Yields 100% load on CPU and time2=17.16 ** ## Edit 2: ** To make it completely clear what is happening on my computer and what is my problem, please have a look at the following examples: First if I want to check number of processors and kernels on my machine:               $ProcessorCount     $KernelCount      The results are 4 and 8 respectively on my machine. Now if I want to see MKL conditions on my machine and also how much "CPU usage" reported by the system monitor correspond to actual performance, I can run this in Mathematica:               Clear["Global`*"]; a = RandomReal[{1, 2}, {20000, 20000}]; b = RandomReal[{1}, {20000}];     Table[SetSystemOptions["MKLThreads" -> i]; Print["Case=", i]; Print[SystemOptions["MKLThreads"]]; t = AbsoluteTime[]; LinearSolve[a, b]; time2 = AbsoluteTime[] - t; Print["t(", i, ")=", time2]; Print["******"], {i, 4}];      You can see the result including number of MKL threads and computation time for each case below:               Case=1     {MKLThreads->1}     t(1)=202.9560000     ******     Case=2     {MKLThreads->2}     t(2)=120.3696000     ******     Case=3     {MKLThreads->3}     t(3)=93.5532000     ******     Case=4     {MKLThreads->4}     t(4)=88.5300000     ******      While the CPU usage for Case1=12%, Case2=25%, Case3=37% and Case4=50%, reported by the system monitor. You can see that in this case "CPU usage" reported by the system monitor correspond to actual performance and the more CPU usage we observe, the less computation time we have. Now if I increase the number of MKLThreads in SetSystemOptions["MKLThreads" -> ?] to values more than 4 (I mean 5 to 8), I can see that it doesn't have any effect on compuation time and CPU usage. The same thing happens if I change the number of ParallelThreadNumber in SetSystemOptions["ParallelOptions" -> {"ParallelThreadNumber" -> ?}], means that the computation time and CPU usage in this case do not depend on the ParallelThreadNumber. You can see the cases below:               SetSystemOptions["ParallelOptions" -> {"ParallelThreadNumber" -> 1}];     Print[SystemOptions["ParallelOptions" -> "ParallelThreadNumber"]];     SetSystemOptions["MKLThreads" -> 8]; Print[SystemOptions["MKLThreads"]];     t=AbsoluteTime[];     LinearSolve[a, b];     time2=AbsoluteTime[] - t;     Print["t=", time2];      The result is (CPU usage=50% during analysis):               {ParallelOptions->{ParallelThreadNumber->1}}     {MKLThreads->4}     t=85.3008000      And for other case:               SetSystemOptions["ParallelOptions" -> {"ParallelThreadNumber" -> 8}];     Print[SystemOptions["ParallelOptions" -> "ParallelThreadNumber"]];     SetSystemOptions["MKLThreads" -> 8]; Print[SystemOptions["MKLThreads"]];     t=AbsoluteTime[];     LinearSolve[a, b];     time2=AbsoluteTime[] - t;     Print["t=", time2];      The result is (Again CPU usage=50% during analysis):               {ParallelOptions->{ParallelThreadNumber->8}}     {MKLThreads->4}     t=85.3476000      As you can see, the CPU usage and computation time do not change when I increase MKLThreads to more than 4 (e.g 5 to 8) and they are also independent of the ParallelThreadNumber. Another interesting example is about the case I mentioned in edit 1. Please have a look at these examples and results and CPU usage for each case: 1)               Clear["Global`*"];     t = AbsoluteTime[];     primelist = Table[Prime[k], {k, 1, 20000000}];     time2 = AbsoluteTime[] - t      Result: time2=43.37 and CPU usage=12% 2)               Clear["Global`*"];     t = AbsoluteTime[];     job1 = ParallelSubmit[Table[Prime[k], {k, 1, 10000000}]];     job2 = ParallelSubmit[Table[Prime[k], {k, 10000001, 20000000}]];     {a1, a2} = WaitAll[{job1, job2}];     time2 = AbsoluteTime[] - t      Result: time2=30.01 and CPU usage=25% 3)               Clear["Global`*"];     t = AbsoluteTime[];     job1 = ParallelSubmit[Table[Prime[k], {k, 1, 6666666}]];     job2 = ParallelSubmit[Table[Prime[k], {k, 6666667, 13333332}]];     job3 = ParallelSubmit[Table[Prime[k], {k, 13333333, 20000000}]];     {a1, a2, a3} = WaitAll[{job1, job2, job3}];     time2 = AbsoluteTime[] - t      Result: time2=23.46 and CPU usage=37% 4)               Clear["Global`*"];     t = AbsoluteTime[];     job1 = ParallelSubmit[Table[Prime[k], {k, 1, 5000000}]];     job2 = ParallelSubmit[Table[Prime[k], {k, 5000001, 10000000}]];     job3 = ParallelSubmit[Table[Prime[k], {k, 10000000, 15000000}]];     job4 = ParallelSubmit[Table[Prime[k], {k, 15000001, 20000000}]];     {a1, a2, a3, a4} = WaitAll[{job1, job2, job3, job4}];     time2 = AbsoluteTime[] - t       Result: time2=21.52 and CPU usage=50% 5)               Clear["Global`*"];     t = AbsoluteTime[];     job1 = ParallelSubmit[Table[Prime[k], {k, 1, 3333333}]];     job2 = ParallelSubmit[Table[Prime[k], {k, 3333334, 6666666}]];     job3 = ParallelSubmit[Table[Prime[k], {k, 6666667, 9999999}]];     job4 = ParallelSubmit[Table[Prime[k], {k, 10000000, 13333333}]];     job5 = ParallelSubmit[Table[Prime[k], {k, 13333334, 16666666}]];     job6 = ParallelSubmit[Table[Prime[k], {k, 16666667, 20000000}]];     {a1, a2, a3, a4, a5, a6} = WaitAll[{job1, job2, job3, job4, job5, job6}];     time2 = AbsoluteTime[] - t      Result: time2=18.28 and CPU usage=75% 6)               Clear["Global`*"];     t = AbsoluteTime[];     job1 = ParallelSubmit[Table[Prime[k], {k, 1, 2500000}]];     job2 = ParallelSubmit[Table[Prime[k], {k, 2500001, 5000000}]];     job3 = ParallelSubmit[Table[Prime[k], {k, 5000001, 7500000}]];     job4 = ParallelSubmit[Table[Prime[k], {k, 7500001, 10000000}]];     job5 = ParallelSubmit[Table[Prime[k], {k, 10000001, 12500000}]];     job6 = ParallelSubmit[Table[Prime[k], {k, 12500001, 15000000}]];     job7 = ParallelSubmit[Table[Prime[k], {k, 15000001, 17500000}]];     job8 = ParallelSubmit[Table[Prime[k], {k, 17500001, 20000000}]];     {a1, a2, a3, a4, a5, a6, a7, a8} =       WaitAll[{job1, job2, job3, job4, job5, job6, job7, job8}];     time2 = AbsoluteTime[] - t      Result: time2=17.16 and CPU usage=100% But if I make this analysis using ParallelTable, interestingly the CPU usage is 100%, but computation time is 45.81!!! It means that computation time is quite the same with number 1 when I do this analysis with Table on one core (CPU usage=12%)!!               t = AbsoluteTime[];     primelist = ParallelTable[Prime[k], {k, 1, 20000000}];     time2 = AbsoluteTime[] - t      Result: time2=45.81 and CPU usage=100% I also checked NMinimize for my big function with 75 (or more variables) using all methods available in Mathematica including Automatic, DifferentialEvolution, NelderMead, RandomSearch, and SimulatedAnnealing. The computation time for all of them is quite the same and CPU usage for all methods is only 12%. So it looks that minimization method I use in NMinimize cannot change parallelization conditions. Now I think my conditions and problems are completely clear, so I would be very appreciative if someone can help me to use all capacity of my CPU in LinearSolve and NMinimize (or Minimize). I still wonder how I can make CPU usage in these cases 100%. In this way we can check whether CPU usage corresponds to actual perfomanse (like what we could see in the examples mentioned above) for LinearSolve and NMinimize or not?? Thank you very much. ** ## Edit 3 ** The function I am trying to minimize is a large function including many variables. The general format of the function is sth like this:               (15 (-2.14286*10^-8 Log[E^(-1.*10^6 phi2[2]) + E^(1.*10^6 phi2[2])] + uu1[2]))^2 + 225 (2.14286*10^-8 Log[E^(-1.*10^6 phi2[2]) + E^(1.*10^6 phi2[2])] -2.14286*10^-8 Log[E^(-1.*10^6 (-phi2[2] + phi2[3])) + E^(1.*10^6 (-phi2[2] + phi2[3]))] -2 uu1[2] + uu1[3])^2 + 225 (2.14286*10^-8 Log[E^(-1.*10^6 (-phi2[2] + phi2[3])) + E^(1.*10^6 (-phi2[2] + phi2[3]))] -2.14286*10^-8 Log[E^(-1.*10^6 (-phi2[3] + phi2[4])) + E^(1.*10^6 (-phi2[3] + phi2[4]))] + uu1[2] - 2 uu1[3] + uu1[4])^2 + 225 (2.14286*10^-8 Log[E^(-1.*10^6 (-phi2[3] + phi2[4])) + E^(1.*10^6 (-phi2[3] + phi2[4]))] - 2.14286*10^-8 Log[E^(-1.*10^6 (-phi2[4] + phi2[5])) + E^(1.*10^6 (-phi2[4] + phi2[5]))] + uu1[3] - 2 uu1[4] + uu1[5])^2 + 225 (-2.14286*10^-8 Log[E^(-1.*10^6 phi2[6]) + E^(1.*10^6 phi2[6])]+ 2.14286*10^-8 Log[E^(-1.*10^6 (-phi2[5] + phi2[6])) + E^(1.*10^6 (-phi2[5] + phi2[6]))] + uu1[5] - 2 uu1[6])^2 + 225 (2.14286*10^-8 Log[E^(-1.*10^6 (-phi2[4] + phi2[5])) + E^(1.*10^6 (-phi2[4] + phi2[5]))] - 2.14286*10^-8 Log[E^(-1.*10^6 (-phi2[5] + phi2[6])) + E^(1.*10^6 (-phi2[5] + phi2[6]))] + uu1[4] - 2 uu1[5] + uu1[6])^2 + ((15 (2.14286*10^-8 Log[E^(-1.*10^6 phi2[6]) + E^(1.*10^6 phi2[6])] + uu1[6]))^2) + (0.00918367 phi2[2] + (-0.00175179 - 11/112 (0.007848)) (1 - (1.*10^12 (phi2[2])^2)/(Log[E^(-1.*10^6 phi2[2]) + E^(1.*10^6 phi2[2])])^2) + ...      Where uu1[i], uu3[i] and phi2[i] are variables. The issue is that the number of variables can increase to a large number (for example 5000 or even more) which make the function hugely big!! So if I cannot use all capacity of the CPU it takes maybe days to minimize such a function, even though one computer with full capacity of the CPU is not enough to solve such a problem too, but the first step is to learn how to configure parallelization for NMinimize (or FindRoot) on a single machine to be able to extend it to parallelization on several remote machines. ## Edit 4: An example of the complete form of the function with 75 variables is: Pastebin link Where variables (unknown parameters) are:               {uu1[2], uu3[2], phi2[2], uu1[3], uu3[3], phi2[3], uu1[4], uu3[4], phi2[4], uu1[5], uu3[5], phi2[5], uu1[6], uu3[6], phi2[6], uu1[7], uu3[7], phi2[7], uu1[8], uu3[8], phi2[8], uu1[9], uu3[9], phi2[9], uu1[10], uu3[10], phi2[10], uu1[11], uu3[11], phi2[11], uu1[12], uu3[12], phi2[12], uu1[13], uu3[13], phi2[13], uu1[14], uu3[14], phi2[14], uu1[15], uu3[15], phi2[15], uu1[16], uu3[16], phi2[16], uu1[17], uu3[17], phi2[17], uu1[18], uu3[18], phi2[18], uu1[19], uu3[19], phi2[19], uu1[20], uu3[20], phi2[20], uu1[21], uu3[21], phi2[21], uu1[22], uu3[22], phi2[22], uu1[23], uu3[23], phi2[23], uu1[24], uu3[24], phi2[24], P1, F1, M1, PN, FN, MN}      I know this function is extremely instable, but the optimum point of the function is also known which is equal to zero, so I am trying to find the values of the parameters which make the function minimum (zero). The parameters which can make the whole function as small as possible are the best answers. ** ## Edit 5 ** Thank you all guys for your helpful comments. Based on what KAI and Oleksandr R. mentioned, and as far as I could understand, LinearSolve uses all capacity of the CPU cores to solve the equation involving large matrices. Consequently, it seems that if I want to solve some linear matrix equations for a few times, the best method is to solve each of them one by one in a LOOP to make it most efficient. In this way Mathemathica is able to use all capacity of CPU cores in each step and solve the equation in the most efficient way (in each step) and goes to the next step. But if you have a look at these 2 examples, apparently it is not like this and Parallelization forces Mathematica to solve the problem involving LinearSolve in a way that is likely more efficient and faster. You can check these examples on your computer. Based on the comments we had here, I am wondering how we can explain these examples. Example 1:               Clear["Global`*"];     t = AbsoluteTime[];     NN = 8;     CC = Array[cc, NN];     For[i = 1, i < (NN + 1), i++,       Clear[a, b];       a = RandomReal[{i, i + 1}, {6000, 6000}];       b = RandomReal[{i}, {6000}];       CC[[i]] = LinearSolve[a, b];       ];     time2 = AbsoluteTime[] - t      For example 1 CPU usage is 50% and time2=23.4 Example 2:               Clear["Global`*"];     t = AbsoluteTime[];     job1 = ParallelSubmit[a1 = RandomReal[{1, 2}, {6000, 6000}]; b1 = RandomReal[{1}, {6000}]; c1 = LinearSolve[a1, b1]];     job2 = ParallelSubmit[a2 = RandomReal[{2, 3}, {6000, 6000}]; b2 = RandomReal[{2}, {6000}]; c2 = LinearSolve[a2, b2]];     job3 = ParallelSubmit[a3 = RandomReal[{3, 4}, {6000, 6000}]; b3 = RandomReal[{3}, {6000}]; c3 = LinearSolve[a3, b3]];     job4 = ParallelSubmit[a4 = RandomReal[{4, 5}, {6000, 6000}]; b4 = RandomReal[{4}, {6000}]; c4 = LinearSolve[a4, b4]];     job5 = ParallelSubmit[a5 = RandomReal[{5, 6}, {6000, 6000}]; b5 = RandomReal[{5}, {6000}]; c5 = LinearSolve[a5, b5]];     job6 = ParallelSubmit[a6 = RandomReal[{6, 7}, {6000, 6000}]; b6 = RandomReal[{6}, {6000}]; c6 = LinearSolve[a6, b6]];     job7 = ParallelSubmit[a7 = RandomReal[{7, 8}, {6000, 6000}]; b7 = RandomReal[{7}, {6000}]; c7 = LinearSolve[a7, b7]];     job8 = ParallelSubmit[a8 = RandomReal[{8, 9}, {6000, 6000}]; b8 = RandomReal[{8}, {6000}]; c8 = LinearSolve[a8, b8]];     {R1, R2, R3, R4, R5, R6, R7, R8} = WaitAll[{job1, job2, job3, job4, job5, job6, job7, job8}];     time2 = AbsoluteTime[] - t      For example 2 CPU usage=100% and time2=19.8


title: Saving a notebook as a $\LaTeX$ file, with syntax highlighting preserved

text: How can I save a notebook as a $\LaTeX$ file, while preserving the syntax highlighting (such as input/output boxes)?


title: Emulate Powerpoint behavior: Show additional cell content with each click

text: Is it possible to emulate powerpoint animation behavior during a presentation with _Mathematica_? Considering a notebook with cell of numbered items or even several cells, is it possible to display a new cell or item with each click (or key press), probably in presentation mode?


title: Plot 3D set (or a domain of three-variable function)

text: is there any way to plot a "3D set" of points subject to certain rules? For example, my task is to find maximum of some function of three variables which have to meet some conditions. Of course I can't use Plot3D and RegionFunction because I would need a 4D space. So I tried to plot only the constraints (where "z" would be a function of "x" and "y"): the constraints are 3x^2>2y^2+z^2 and x^2+y^2=1, and then I used               Plot3D[{Sqrt[3 x^2 - 2 y^2],-Sqrt[3 x^2 - 2 y^2]}, {x, -5, 5}, {y, -5, 5},       RegionFunction -> Function[{x, y}, x^2 + y^2 <= 1 && x^2 + y^2 >= 1]]      But this isn't working for some reason - I get only a box without any plot, but even if it did work, it wouldn't be very helpful because the first contraint is inequality and not an equation. I hope I expressed myself correctly and comprehensibly, English is not my mother tongue. Any ideas how to solve my issue?


title: Combining manipulated plots

text: Let's say I have two manipulated plots:               Manipulate[Plot[Sin[a x], {x, 0, Pi}], {a, 0, 10}]     Manipulate[Plot[Cos[b x], {x, 0, Pi}], {b, 0, 10}]      How can I create a new plot that combines these two and is updated dynamically by each of them? Can I somehow use `Show[]`? Of course I could create a unified manipulator, but in reality these are a handful of conceptually separate problems with lots of sliders each and I'd hate to duplicate them all.


title: Combining two plots with inverted xy-axes

text: I need to draw a set of curves on one graph (characteristics equations). As you can see they have exchanged x and y axes. My goal is to plot all those curves on one graph. Are there ways to do that?               f[t_, t0_] := -(2 - 4/Pi*ArcTan[2])*Exp[-t]*(t - t0);     g[x_, x0_] := (x - x0)/(-(2 - 4/Pi*ArcTan[x + 2]));     Show[Table[Plot[f[t, t0], {t, 0, 1},        PlotRange -> {0, -0.3},        AxesLabel -> {t, x}], {t0, 0, 1, 0.1}]]      ![enter image description here](http://i.stack.imgur.com/6BDw9.jpg)               Show[       Table[         Plot[g[x, x0], {x, 0, -0.3}, PlotRange -> {0, 1}, AxesLabel -> {x, t}],          {x0, 0, -0.3, -0.05}]]      ![enter image description here](http://i.stack.imgur.com/F9h7Q.jpg)


title: Brownian Motion with stopping threshold

text: I just want to generate one stochastic process, whereas I want to be able to manipulate the start value and the volatility. Furthermore, the process should stop when it reaches 5 However, as soon as I use the SeedRandom[seed] function some error occurs. Hope you can help me. I also want the function to start at 0 and not at 1 Definition function of: (* x[t+1]=x[t]+μ (drift) + shock[t]; which stops at threshold*) My code:               σ = 0.2     SeedRandom[85]; shock1 =      RandomVariate[NormalDistribution[0, σ],(*time interval/Length of paths*) 10]          μ = 0.1            step[x_, μ_, shock1_] :=       If[x == 5, 5, If[x + μ + shock1 < 5, 5, x + μ + shock1]]               p1 = FoldList[step, 10, shock1]          ListLogPlot[p1, Joined -> True]      This Works perfectly, however, as soon as I enter the following i get some Problems:               Manipulate[SeedRandom[seed];       shock1 = RandomVariate[NormalDistribution[0, σ1], 10]; μ =        0.1; step[x_, μ_, shock1_] :=        If[x == 5, 5, If[x + μ + shock1 < 5, 5, x + μ + shock1]];       ListLogPlot[FoldList[step, S, shock1], Joined -> True], {S, 10,        50}, {σ1, 0.1, 1}]      I get the following error-message: "Argument seed in SeedRandom[seed] should be an integer or a string. " But when I enter:               Manipulate[SeedRandom[85];       shock1 = RandomVariate[NormalDistribution[0, σ1], 10]; μ =        0.1; step[x_, μ_, shock1_] :=        If[x == 5, 5, If[x + μ + shock1 < 5, 5, x + μ + shock1]];       ListLogPlot[FoldList[step, S, shock1], Joined -> True], {S, 10,        50}, {σ1, 0.1, 1}]      and try to manipulate the volatility just nothing happens. do you have any solutions for my problem?


title: Evaluate an expression at a specific point

text: In Maple, you right click and can evaluate an expression (whatever it is) at a specific point say: Expr.= abcddafjosjfoj, then right click and simply evaluate at c=-34 say. But how does one do the correspoinding operation in Mathematica? Must one define a function first for this simple task? ![image](http://i.stack.imgur.com/4Edwb.png)


title: Hermite Normal Form in "columns" convention

text: After describing the _Hermite Normal Form_ (HNF), MathWorld explains: > The Hermite normal form for integer matrices is implemented in _Mathematica_ > as `HermiteDecomposition[A]`, which however uses the "rows" convention (thus > making $\mathbf H$ upper triangular) and replaces (the condition > $h_{i\,j}\leq 0$ and $|h_{i\,j}| < h_{i\,i}$ for $j < i$) with balanced > remainders $\pmod {h_{ii}}$. Is there a way, using _Mathematica_ and without much coding, to compute HNF in "columns" convention?


title: Using Log when working with a time-series

text: I have a time-series list of stockA, which I call `bas`. I have taken the natural log of `bas` by using               LOG[bas]       As you you know this gives the natural log of each number in the time-series list. This is what I want to do now               OPR = Log[bas/(bas at t-1)]*100       How can I get this?


title: How to solve this integral equation?

text: I am trying to solve for x the integral equation :               a Integrate[Exp[-s^2]/(s - c x)^2, {s,-Infinity, Infinity}] +      b Integrate[Exp[-s^2]/(s - d x)^2, {s,-Infinity, Infinity}] = 1          where a, b, c and d are numerical values. I have tried **`NIntegrate`** and some iteration but didn't get me too far... can anyone help me with a better idea?


title: Solving variant of the knapsack/money-changing problem

text: I'm trying to solve a variant of the knapsack/changing money problem where I have a set of a few numbers and I'm trying to find the linear (integer) combinations of them which are close to a given value. I have implemented it with a brute force method that generates all the possible combinations up to some max value of each and then sorts them and finds the desired value using a binary search (from Leonid's answer to another question). With some effort with `Compile` I was able to speed this up such that it is workable, but I was hoping there was a more elegant/efficient solution that would scale better. Unlike the common money changing problem, I am interested in the closest values themselves (not just exact values) and I don't care how many possible combinations there are. Here is what I have, calling this function with a list (`values`) and max value (`nmax`) returns a second function which is used to search for the closest set (within a specified range):               makearray[values_, nmax_] := Module[       {countlist, sums, sorted},       countlist = Rest@Tuples[Range[0, nmax], Length@values];       sums = dot[values, countlist];       sorted = sort[sums];       (* for my specific application duplicates are not desired so I remove            them with a custom compiled function that relies on the sorted list,            although they are rare with random data *)       sorted = Pick[sorted, deleteduplicates[sorted], 1];       Function[{desired, delta}, window[sorted, {desired - delta, desired + delta}]]       ]      Here are the helper functions, if you don't have a `C` compiler installed simply remove `CompilationTarget -> "C"`:               bsearchMin[list_List, elem_] := Module[       {n0 = 1, n1 = Length[list], m},       While[n0 <= n1, m = Floor[(n0 + n1)/2];        If[list[[m]] == elem, While[list[[m]] == elem, m++];         Return[m - 1]];        If[list[[m]] < elem, n0 = m + 1, n1 = m - 1]];       If[list[[m]] < elem, m, m - 1]]          bsearchMax[list_List, elem_] := Module[        {n0 = 1, n1 = Length[list], m},        While[n0 <= n1, m = Floor[(n0 + n1)/2];         If[list[[m]] == elem, While[list[[m]] == elem, m--];          Return[m + 1]];         If[list[[m]] < elem, n0 = m + 1, n1 = m - 1]];        If[list[[m]] > elem, m, m + 1]];          window[list_, {xmin_, xmax_}] :=       With[{minpos = bsearchMax[list, xmin],         maxpos = bsearchMin[list, xmax]},        Take[list, {minpos, maxpos}] /; ! MemberQ[{minpos, maxpos}, -1]]          window[__] := {}          dot = Compile[{{v1, _Real, 1}, {v2, _Real, 1}}, v1.v2,         RuntimeAttributes -> {Listable}, Parallelization -> True,         RuntimeOptions -> "Speed"];          sort = Compile[{{m, _Real, 1}}, Sort[m], RuntimeOptions -> "Speed",         CompilationTarget -> "C"];          deleteduplicates = Compile[{{v, _Real, 1}},        Block[         {i, len = Length[v], output},         output = Table[1, {i, len}];         For[i = 2, i < len, i++,          If[Compile`GetElement[v, i] == Compile`GetElement[v, i - 1],            output[[i]] = 0]          ];         output         ], RuntimeOptions -> "Speed", CompilationTarget -> "C"];      Now using the code lets start with a random list:               list = RandomReal[1,6];          solvef = makearray[list, 10]; // AbsoluteTiming          (*     0.4 seconds so this is workable     *)          solvef[10, 0.05]; // AbsoluteTiming          (*     0. seconds, basically instant     *)


title: ParametricPlot and PlotLegends don't seem to cooperate

text: I noted that only part of the legend shows up in `ParametricPlot` using v9's `PlotLegends`:               ParametricPlot[{{t, t}, {t, 2 t}}, {t, 0, 1}, PlotLegends -> LineLegend[{1, 2}]]      ![Mathematica graphics](http://i.stack.imgur.com/NCR43.png) Inspecting the figure's `FullForm` gets me (among other things)               LineLegend[      List[        Directive[EdgeForm[GrayLevel[0.5`]], Hue[0.9060679774997897`, 0.6`, 0.6`]]      ], List[1, 2],       Rule[LegendLayout, "Column"]]      It looks like Mathematica forgot to add the second color. Adding the color manually gets me the full legend. This looks like a bug, but perhaps I'm missing something? I also noticed that virtually all examples in the "Options/PlotLegends" section of the `ParametricPlot` doc page yield a result differing from the pre-rendered image. Again, this looks like a bug, perhaps introduced by a last-minute addition. I'm using v9.0.1. Anyone with v9.0.0 care to check whether it exists there as well?


title: Function definitions in init.m don't work

text: I can't get any function defined in `$UserBaseDirectory/Kernel/init.m` to work. For example:               SinDeg[d_] := Sin[d * Degree]; (* Only line in init.m *)      Output:               SinDeg[90]     (* => SinDeg[90] *)      However when copying the code and executing it inside a Mathematica notebook, it works fine:               SinDeg[d_] := Sin[d * Degree];     SinDeg[90]     (* => 1 *)      The Mathematica front-end can definitely see the function definitions as it displays `SinDeg` as an autocompletion suggestion, when typing `SinD`. I'm using Mathematica 9 Home Edition on OS X.


title: Output Export in Mathematica

text: I have a command line that generates lists as output and is running in a loop, so generates, multiple long lists. Each list is to be exported as a .txt file. How can I automate the name generation of the output files. I intend to use the same name as the input file but with the .txt extension in output of course.               For[       i = 1,i < 3,i++,       outdata = ReadList[ test[[i]], Record, RecordSeparators -> {{">"},{" "}} ];       Print[outdata]       ]      How can I automate the export?


title: How to print preview a selection?

text: When printing (file->print...) there's the possibility of printing just the current selection. This is useful for printing just a couple of cells, or some chapters. The file menu also has Print Preview, but with no options. Is there a way of making a print preview of a selection?


title: How can selection of delimiter matches be disabled?

text: I often preemptively match delimiters. As a simple example, I'll type `Import[]`, then left arrow, then `"filename"`. The problem is that when I type the `]` in `Import[]`, the `[` highlights in the normal selection color to signify that this pair of brackets matches. During this automatic highlighting, if I type something that involves the shift key (such as something starting with `"`), the `]` is deleted, leaving `Import["`. This behavior is as if the `]` was selected when the `"` was typed, but it was not. To reiterate, the sequence of keys is (quickly typed!) `Import[]` then `Left Arrow` and `Shift`+`'` but the behavior is as if the sequence were `Import[]` and then `Shift`+`Left Arrow` and then `Shift`+`'`. It might be my imagination, but it seems to have gotten worse in _Mathematica_ version 9. Can I disable or shorten the automatic highlighting of matching delimiters? It appears to be the source of the phantom shift keystroke. This is Mathematica version 9 on Mac OS X 10.7.5. * * * Wolfram support suggested unchecking "Enable dynamic highlighting" and this does not fix the problem. I recorded the problem happening twice in a row here. It happens a bit faster than it is being displayed here. ![enter image description here](http://i.stack.imgur.com/Yqt44.gif) I'd settle for just shortening the duration of this highlighting so I'd have to be Superman to reproduce the problem.


title: Elegant Matrix Combinations

text: Suppose you have a matrix (mxn), simplified for illustration               m= {{a, b, c}, {d, e, f}}       And a set of combinations (simplified for illustration purposes but can contain more combinations...)               combinations = {{1, 1, 1}, {1, 1, -1}, {1, -1, 1}, {1, -1, -1}, {-1, 1, 1}, {-1, 1, -1}, {-1, -1, 1}, {-1, -1, -1}}      What is the best way to derive a matrix that holds all the combinations of the matrix m? As an illustration:               m1 = {{a, b, c}, {a, b, -c}, {a, -b, c} … … …  {-d,-e,-f} }


title: How to insert a link to a generic file, in the middle of a text style cell/paragraph?

text: It is easy to insert a Hyperlink to a notebook file, or to an internet address, in the middle of a text style cell (Ctrl+Shift+H or menu: Insert->hyperlink). Trying to create a hyperlink to a file extension different than a notebook (e.g. a PDF file), after waiting for a while, returns nothing (...should it return an error message?). Converting a hyperlink (e.g. for a website) into InputForm, Raw InputForm or FullForm doesn't reveal any secrets (returns a string). One needs to go to the cell expression level to see what makes it different. So, what is the best way of adding a "`SystemOpen` link" in the middle of a text paragraph?


title: FindRoot in range

text: I am trying to find all roots in a range, using               y /. FindRoot[Sin[y] == 0, {y, #}] & /@ Range[7]      which gives               {0., 3.14159, 3.14159, 3.14159, 9.42478, 6.28319, 6.28319}      but I would like to get               {0., 3.14159, 6.28319}      What am I doing wrong?


title: Using enum values with J/Link

text: How can I pass enum values to a function when using J/Link? What is the correct syntax for typing an enum value? For example, call `normalize()` using `NFC` from here.


title: My code for solving n queens problem Compile Failed

text: I want to make my code for solving n-queens problem faster, but it seems that `MapIndexed` can't be compiled. Mathematica return > CompiledFunction::cfse: Compiled expression > If[Abs[1-Compile`GetElement[{2},1]]==1,Throw[False]] should be a machine- > size real number. >>               Clear["`*"];     safe[col_, queens_] :=        FreeQ[queens, col] &&         Catch[MapIndexed[          If[Abs[col - #] == Length@queens - First@#2 + 1, Throw@False] &,           queens];         True];          safeCompiled =        Compile[{{col, _Integer}, {queens, _Integer, 1}},         FreeQ[queens, col] &&          Catch[MapIndexed[           If[Abs[col - #] == Length@queens - First@#2 + 1, Throw@False] &,            queens];          True]        ];          8 /. size_ :>         Nest[Table[sol~Append~i,            {i, size}, {sol, Select[#, safeCompiled[i, #] &]}]~Flatten~1 &,          {{}}, size] // Length // AbsoluteTiming      **Updated** A bit faster version:               safe = Compile[{{col, _Integer}, {queens, _Integer, 1}},         If[MemberQ[queens, col], Return@0];        Catch[Do[If[Abs[col - queens[[i]] ] == Length@queens - i + 1, Throw@0],           {i, Length@queens}]; 1],        RuntimeAttributes -> Listable];          size = 11;     iter = Table[Append[sol, i], {i, size}, {sol, Pick[#, safe[i, #], 1]}]~ Flatten~1 &;     Nest[iter, List /@ Range@size, size - 1] // Length // AbsoluteTiming      > {1.083062, 2680}


title: How to get graph layout that reflects edge weights?

text: My heart soared to discover that Mathematica 8 offers support for specifying a weighted adjacency matrix in WeightedAdjacencyGraph. But it seems that, regardless of the weights between edges, the plotted layouts of the graphs are the same. For instance, the graphs produced here are the same:               adjMat1 = {{Infinity, 1, 1, 1, 1},     {1, Infinity, 1, 1, 1},     {1, 1, Infinity, 1, 1},     {1, 1, 1, Infinity, 1},     {1, 1, 1, 1, Infinity}};          adjMat2 = {{Infinity, 8, 6, 3, 7},     {1, Infinity, 1, 1, 1},     {2, 5, Infinity, 9, 4},     {1, 1, 1, Infinity, 1},     {1, 1, 1, 1, Infinity}};          WeightedAdjacencyGraph[adjMat1, DirectedEdges -> True]     WeightedAdjacencyGraph[adjMat2, DirectedEdges -> True]      I've tried specifying different layouts, but can't get them to display differently. Is there any way to get graphs with different edge weights but the same connectivity to render with the edge weights interpreted as distance between the nodes?


title: MakeJavaObject on list of inhomogeneous objects belonging to the same base class

text: When using J/Link, how can we create an array out of objects belonging to different classes but having the same base class? Here's an example:               partSource =        JLink`JavaNew[        "org.apache.commons.httpclient.methods.multipart.ByteArrayPartSource", "mmagraphics.png",         JLink`MakeJavaObject["abcdefg"]@toCharArray[]];     part1 = JLink`JavaNew[        "org.apache.commons.httpclient.methods.multipart.FilePart",         "filename", partSource];     part2 = JLink`JavaNew[        "org.apache.commons.httpclient.methods.multipart.StringPart",         "someting", "1234"];          MakeJavaObject[{part1, part2}]      > Java::excptn: A Java exception occurred: java.lang.IllegalArgumentException: > array element type mismatch at java.lang.reflect.Array.set(Native Method). I need to create a `Part []` out of `{part1, part2}` so that I can pass it to the constructor of `org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity`


title: Assign variables from list inside With or Module

text: I have found that it is possible to assign variables from lists, as follows.               In[1]:= r = {1, 2, 3};     In[2]:= {a, b, c} = r;     In[3]:= b     Out[3]= 2      However, if I try to do this within a With or Module statement, it does not evaluate:               In[4]:= With[{{x, y, z} = r}, x]     Out[4]= With[{{x, y, z} = r}, x]     In[5]:= Module[{{x, y, z} = r}, x]     Out[5]= Module[{{x, y, z} = r}, x]      whereas I expected it to work as:               In[6]:= With[{x = r[[1]], y = r[[2]], z = r[[3]]}, y]     Out[6]= 2     In[7]:= Module[{x = r[[1]], y = r[[2]], z = r[[3]]}, y]     Out[7]= 2      or even:               In[8]:= Module[{x, y, z}, {x, y, z} = r; y]     Out[8]= 2      Why is this? Is there an accepted way to do this?


title: Cauchy principal value integral of a list of numbers. How?

text: I have a list of numbers that are numerical samples of a function for which I need to find the Cauchy principal value integral. I thought I should be able to combine Interpolation with Integrate to do this, but it appears not. A simple function that shows this problem is `1/x`. If the actual function is known Mathematica can do the integral.               Integrate[1/x, {x, -1, 2}, PrincipalValue -> True]      giving the answer `Log[2]`. But if I only have a numerical approximation to this function the "obvious" way to try this does not work.               foo = Interpolation[Table[{x, 1/x}, {x, -1.1, 2.1, 0.0123}]]     Integrate[foo[x], {x, -1, 2}, PrincipalValue -> True]      gives the error message `General::ivar: "PrincipalValue->True is not a valid variable."` Can anyone tell me how to estimate the Cauchy principal value integral of a numerically sampled function?


title: How do I scale three independent variables in a Manipulate?

text: ### cross-posted on the Wolfram Community forum I'm trying to ilustrate the difficulties in assigning bins to a data set and then running a comparison of the bins against a binomial distribution for all values- n, p. The code I have so far is (mostly thanks to Nasser):               Manipulate[Show[Histogram[dataB, {-0.5, 7.5, c}, "PDF"],        DiscretePlot[PDF[BinomialDistribution[n, p], x], {x, 0, 20},          PlotStyle -> PointSize[Large]], ImagePadding -> All],       {{c, 8, "Column Width"}, 0, 4, .1, Appearance -> "Labeled"},       {{n, 7, "Number Of Quarters"}, 1, 20, 1, Appearance -> "Labeled"},       {{p, 0.5, "Fair Coin Toss"}, 0, 1, 0.01, Appearance -> "Labeled"}]      The remaining problem, scaling the number of quarters in the binomial to the width of the X-axis. Right now my X-axis ranges from 0 to 7.5 in agreement with the range of the numbers in my data set. I think I need two X-axes. One to illustrate the range of the numbers in my data set, and a second X-axis to illustrate the number of quarters in the binomial ensemble (1 to 20). Here is a data set (Binomial[n=7,p=0.65]): dataB = {0.38, 1.39, 1.51, 1.75, 1.97, 2.19, 2.43, 2.49, 2.51, 2.52, 2.71, 2.77, 2.81, 2.92, 2.94, 2.95, 3.00, 3.01, 3.29, 3.36, 3.42, 3.43, 3.45, 3.47, 3.49, 3.51, 3.52, 3.53, 3.54, 3.55, 3.56, 3.57, 3.58, 3.59, 3.60, 3.70, 3.75, 3.80, 4.00, 4.10, 4.12, 4.15, 4.18, 4.19, 4.20, 4.21, 4.22, 4.23, 4.24, 4.27, 4.30, 4.35, 4.37, 4.40, 4.41, 4.42, 4.43, 4.44, 4.45, 4.46, 4.50, 4.51, 4.52, 4.53, 4.54, 4.55, 4.60, 4.61, 4.62, 4.63, 4.70, 4.72, 4.75, 4.79, 4.82, 4.85, 4.86, 4.87, 4.89, 4.92, 5.10, 5.15, 5.16, 5.17, 5.18, 5.19, 5.20, 5.25, 5.27, 5.28, 5.30, 5.31, 5.32, 5.35, 5.37, 5.40, 5.42, 5.45, 5.50, 5.55, 5.57, 5.62, 5.64, 5.65, 5.70, 5.77, 5.82, 5.87, 5.89, 5.94, 5.99, 6.00, 6.01, 6.22, 6.23, 6.42, 6.43, 6.44, 6.46, 6.47, 6.48, 6.49, 6.50, 6.51, 6.57, 6.59, 6.64, 6.75, 7.00}


title: Recursive function taking functions as arguments

text: I'm trying to implement Lie brackets and derivatives of nth order. For doing this, I've stumbled upon something I don't understand. Here is an illustration: First I define the functions:               Operator[f_, g_, x__, opt_] :=       Piecewise[{{f[x], opt == 1}, {Operator[f, g, g[x], 1], opt==2}}]     ff[x__] := {x[[2]], x[[1]]}     gg[x__] := {-x[[1]], -x[[2]]}      Then I ask for these evaluations               Operator[ff, gg, {x1, x2}, 2]     Operator[ff, gg, gg[{x1, x2}], 1]     ff[gg[{x1, x2}]]      The results I found were:               {-x1, -x2}     {-x2, -x1}     {-x2, -x1}      The first result is actually just `gg[{x1,x2}]`, while I wanted it to be the same as the third result `ff[gg[{x1,x2}]]`, and the second result worked as I expected. Anyone has an idea about this problem? Is there some language detail I don't know? Because the first result simply makes no sense to me right now.


title: why maxrecursion didn't work if I specify singularity in NIntegrate

text: I study sigularity specification and MaxRecursion in NIntegrate. And find something unusual. first I define a function               δ[x_, y_: 1/100] := 1/π*y/(x^2 + y^2)      Plot δ[x - 2]               Plot[δ[x - 2], {x, 0, 4}, PlotRange -> All]      gives ![enter image description here](http://i.stack.imgur.com/V8kq4.png) Now NIntegrate δ[x - 2] from -∞ to +∞，I control the MaxRecursion option, and plot the sample points using the `plotrecur` function. I will give `plotrecur` in the end.               Table[{"MaxRecursion" i,      plotrecur[δ[x - 2], {x, -\[Infinity], \[Infinity]},      MaxRecursion -> i]}, {i, 4, 9}]      this gives ![enter image description here](http://i.stack.imgur.com/f7IXu.png) the above picture shows that how reducing `MaxRecursion` step by step will affect sample points used in NIntegrate. then I exclude 2 as a singularity in the integration interval. through 2 is actually not a singularity, but it is sharp.               Table[{"MaxRecursion" i,      plotrecur[\[Delta][x - 2], {x, -\[Infinity], 2,\[Infinity]},      MaxRecursion -> i]}, {i, 4, 9}]      ![enter image description here](http://i.stack.imgur.com/cniFm.png) we can see that the `MaxRecursion` doesn't affect the sampling until `MaxRecursion` reduced to 4. **It's hard for me to understand this. I think the only effect after specifying a singularity manually is to let _Mathematica_ trigger a singularityhandler(e.g. IMT or DoubleExponential) at that point. Is this view right? Why will specifying singularity makes `MaxRecursion` invalid? Can somebody give a explanation** * * * Finally, the `plotrecur` function here:               plotrecur[integrand_, {x_, low_, singularity___, high_},      opt___] := {Length@#[[2, 1]], #[[1]],      ListPlot[      Transpose[{Transpose[#[[2, 1]]][[1]],         Range[Length@#[[2, 1]]]}]]} &[     Reap[NIntegrate[integrand, {x, low, singularity, high}, opt,      EvaluationMonitor :> Sow[{x, integrand}]]]]


title: ClearAll["Global`*"] stops working with Context set to 'unique to this Notebook'

text: I just changed my default notebook context to 'unique to this Notebook' so that variables don't roll across numerous open notebooks. Doing this, however, made the command ClearAll["Global*"] stop working to clear all declared variables. I also tried, `ClearAll[Evaluate[Context[] <> "*"]]`, but that didn't work either. Any ideas?


title: How to calculate the position of a figure in an image?

text: My question is about recognising soccer players in the pitch. Thanks to Bill S who wrote an excellent script to recognise parts of the players. I found this issue after testing his solution. I will describe his solution and then I will try to explain my 'new' problem.               img = Import["http://i.stack.imgur.com/K60Nl.gif"]      This shows you the following image: ![enter image description here](http://i.stack.imgur.com/K60Nl.gif) I want to select all 'blue' soccer players               blue = PixelValuePositions[img, {0.580, 0.705, 0.796}];        {h, v} = ImageDimensions[img];         imgD = ConstantArray[0, {h, v}];         Length[Table[imgD[[Sequence @@ blue[[i]]]] = 1, {i, 1, Length[blue]}]];         bluePeople = ImageRotate[Dilation[Erosion[Image[imgD], 4], 8], Pi/2]     ComponentMeasurements[redPeople, "Centroid"];      ![enter image description here](http://i.stack.imgur.com/7KCXD.gif)               pixels = ComponentMeasurements[bluePeople, "Centroid"][[All, 2]];      This gives the values: `{{95.8636, 1120.96}, {1227.08, 1058.48}, {1598.58, 1049.69}, {1501.61, 919.903}, {1481.09, 854.259}, {83.0436, 740.669}, {61.3402, 662.205}, {786.63, 325.184}, {735.35, 250.843}, {790.906, 207.406}}`               Show[Image[img, ImageSize -> 600],       Graphics[{Black,         Table[Inset[ToString[i], pixels[[i]]], {i, 1, Length[pixels]}]}]]      ![enter image description here](http://i.stack.imgur.com/DarCt.gif) As you can see, the players below wear blue socks so the script recognises three 'centroids'. Why do I want this? I want to calculate the position of the 'blue' soccer players in the pitch. The 'best way' to do this is based on a central pixel position. So calculating the centroid is logical. But in this situation described, one soccer player has three centroids. How can I combine these three?


title: With command does not behave as expected according to its Attributes

text: The attributes of the `With` command are `HoldAll` which means it should not evaluate its arguments before its starts its business. For example, if I try               f[arg_]:=(Print["evaluating"]; arg)      and then               With[{s=f[x]}, s + 1]      it should not evaluate `f[x]`, right? But it does, i.e. it prints "evaluating", despite the fact that it should hold all its arguments. I understand that body is probably held, so that the lexical substitutions can be made, and that is in line with the `HoldAll` instruction (attribute). But, the part that specifies constants (in {...}), that puzzles me. It is actually reasonable to evaluate it, but that contradicts fully the use of the `HoldAll` argument. Would it not be better to use something like `HoldRest` as the attributes for `With`. Hmmm... I really do not understand this. Does anyone understands this?


title: Why is there no PositionFunction in Mathematica?

text: Too often I have seen the programs of inexperienced users greatly slowed by using `Position` in an iterative fashion, when far faster would have been to compute a look-up table for positions beforehand. _Mathematica_ provides such functionality for `Nearest` and `Interpolation` "out of the box" with the syntax of `function[data]` along with dedicated functions `NearestFunction` and `InterpolatingFunction`. There is no equivalent with `Position[data]` producing a `PositionFunction` object. I observe that `Position` appears to be used more often than either of the other functions so this seems like a regrettable omission. Two complications I can think of are:   * the levelspec of `Position`   * the handling of patterns Based on this I ask:   1. What other complications are there for creating a PositionFunction?   2. How best can such a function be implemented?   3. How can the utility and performance of the function be maximized?   4. All limitations considered would such a function be valuable?   Why is there no such functionality in _Mathematica_?


title: How to do this complex integration on the real line?

text: $m, r$ are parameters in the following integral:               Integrate[z Exp[I z r]/Sqrt[z^2 + m^2], {z, -∞, ∞}]      How to do this integration directly? The result should be `2 I m BesselK[1, mr]`. This post may be helpful, but I haven't found anything to solve this question. As suggested by b.gatessucks, this integration can be converted to the following one which can be computed by Mathematica:               Integrate[Exp[I z r]/Sqrt[z^2 + m^2], {z, -∞, ∞}]      and its result is `2 BesselK[0, m r]`. But this method may be not general, because we do not know which form can be recognized by Mathematica for other similar problems.


title: Cell seems to be evaluating in exponential time even though it shouldn't

text: I am trying to implement Newton's method for a given function f[x] and a starting x-value xval. The code should print out each new x-value as it approaches one of the zeroes of the functions. g[x] is a function that returns the new x-value given an old x-value.               f[x_] = x^3 - x;     g[x_] = x - (f[x]/D[f[x], x]);     zeroes = (x /. Solve[f[x] == 0, x]);     xval = 1000;     shouldStop = False;     While[Not[shouldStop], distances = g[xval] - zeroes;            results = Map[Less[Abs[#], 0.00001] &, Abs[distances]];            xval = g[xval]; Print[N[xval]]; shouldStop = Or @@ results]      I am not sure why, but as the while loop continues, each iteration takes longer to run. Any help?


title: Precision of a complex number

text: In an output I'm getting a number like `-0.33998187034939803` + 0.`I`. Finding `Precision[Im[-0.33998187034939803` + 0.`I]]` I'm getting out put `MachinePrecision`. Can I really neglect the imaginary part form my calculation? I've given a link for my mathematica file Have a look at this: ![enter image description here](http://i.stack.imgur.com/4gHIN.png)


title: Physics based Mathematica project ideas?

text: I am looking to make a physics based Mathematica project. Ideally the project would take around 12 hours, gathering any experimental data and analyse the findings. I'd have full access to university physics labs. The project would be for 2nd year physics students in the end and would aim to introduce using Mathematica in their work.


title: How to set range of values on BarLegend and Manipulate Polygons color filling using BarLegend

text: I have a simple graphics which display a polygon and a bar legend. I am having difficulties defining a range of values for my bar legend. What I am looking to get is 4 values: 10^-10, 10^-6, 10^-3, 10^-1 (Green>Amber>Red); Ultimately I would like to control my polygons color filling using bar legend as a controller. Here is what I have at present:                   Manipulate[      Row[       {BarLegend[{{Green, Yellow, Red}, {10^-10, 10^-1}},          LegendLayout -> "Column"],         Graphics[         Polygon[{{-1, 1}, {0, -1}, {1, 1}},           VertexColors -> {Red, Green, Red}], PlotRange -> 1,          ImageSize -> {220, 220}]        }       ]      , {{x, .0, "Level:"}, 0, 1, .1, ImageSize -> Medium},       ControlPlacement -> Bottom] (*Controller for filling goes here *)      I was wondering if anyone would be able to help me out to figure out how to set the appropriate range for my BarLegend and perhaps to give me some pointers on how could I achieve filling my Polygon using BarLegend as a control or some similar structure. Regards,


title: Increase precision of custom function

text: I hope the title is not misleading: Suppose I have a function that is quite complicated, e.g.               f[u_] := Exp[-Exp[- Abs[c.u]^a] Sin[d.u] Sin[(Abs[c.u]^a) ...      I want to use this function for numerical integration `NIntegrate[f, {s, bound1, bound2}]` that is prone to numerical error. Mathematica keeps telling me, that the function evaluates not to the desired precision, I have chosen for the numerical integration. Is there a way to improve the precision of the function evaluation, e.g. using arbitrary precision packages/functions? What could I do? Thanks for your help, it is highly appreciated. _EDIT_ : To be a bit more precise: I am trying to do an oscillatory Hilbert transform for a function (King 2002: "Numerical Evaluation of Hilbert transforms for oscillatory functions"). So the error is scaled up with $t^{-1}$ around the singularity. So far the values I obtain are far from being precise, so maybe the technique won't work at all. But I wanted to give it a try. I now use exact number constants like `a := 1/10` and `T := N[Tan[Pi*a/2], 100]`. I hope that `Pi` will also have the required number of digits then.


title: Changing the background color of a framed plot

text: I frequently generate framed plots like this:               Plot[Sin[x], {x, 0, 2 \[Pi]}, Frame -> True]      ![enter image description here](http://i.stack.imgur.com/HghAo.png) Is there an easy way to change the background color of the framed region only? Specifying the `Background` option changes the background color of the entire plot, not just the framed region:               Plot[Sin[x], {x, 0, 2 \[Pi]}, Frame -> True, Background -> LightGray]      ![enter image description here](http://i.stack.imgur.com/dicOC.png) Also, is there a way to make figures look like MATLAB's default figure style, i.e. a white background surrounded by a gray frame (see below)? ![MATLAB figure](http://i.stack.imgur.com/N0wRM.png)


title: Wagner's trick to monitor FindRoot no longer works in Mathematica version 8

text: I recently learned that we can use `Print` as a monitoring tool. My favorite is Ted Ersek's example               h[f1[a1], f2[e][a2]] /. (a_ /; Print[a] :> 0)      which reveals the order in which `ReplaceAll` goes through parts of an expression. Clearly this is a very useful trick. On page 41 of his book, David Wagner gave the example               FindRoot[Print[x]; Sin[x] - Cos[x], {x, .5}]      which prints the sequence of iterates generated by `FindRoot` along the way. That code no longer works on Mathematica version 8:               In[22]:= FindRoot[Print[x]; Sin[x] - Cos[x], {x, .5}]     During evaluation of In[22]:= x     Out[22]= {x -> 0.785398}      At first I thought this is related to the fact that we now have the `EvaluationMonitor` option, and `FindRoot` somehow weeds out superfluous subexpressions like `Print`. Now I know this is probably false because               Plot[Print[x]; Sin[x], {x, Pi/4, Pi/2}]      still lists all the points considered during its evaluation. **Why does`FindRoot` ignore `Print`?**


title: Numerics with Mathematica

text: From time to time, I would like to use _Mathematica_ purely numerically, e.g., plotting a function which is defined as an integral which cannot be solve analytically or a solution of a differential equation, or ... . It turns out that _Mathematica_ is rather efficient (I would say comparable to Matlab) if you know what you are doing. However, _Mathematica_ even though it has incredible numerical possibilities makes numerical life quite hard. Problems which occur:   1. it tries to evaluate a function analytically, because you type something like `f[x]` where `x` does not have (yet) a numerical value.    2. it tries to symbolically preprocess expressions (check out the `"SymbolicProcessing"` option of `NIntegrate`) even if I know that no symbolic solution exists   3. lists are not properly packed, because somewhere `Pi` appears which does not get converted to a numerical value   4. ... I would like very much if there would be a switch, which changes _Mathematica_ into purely numerical mode which would include:   * a) all numbers are converted in machine numbers (lists are packed)   * b) there is no attempted of any symbolic operation, any function `f[x]` with `x` not a number remains unevaluated (of course, I know the trick to define `f[x_?NumericQ]` but the numerical mode would save me lots of typing)   * c) turn off symbolical (pre-)processing Is there a way which I can get the required behavior a) to c)? Do other people suffer from the same problems? It turns out that for me it is not a problem any more because I know how to deal with it; however, inexperienced user typically suffer from very bad performance if they would like to use _Mathematica_ for numerical means. In fact _Mathematica_ is a marvelous numerical tool with good plotting capabilities. I hope that some of you might even now better than me what I am hunting for. I guess not all problems can be avoided. A problematic expression is, e.g., the following `Plot[{Re[#], Im[#]}&[f[x]], {x,0,1}]`. `Plot` does not know that it has a list as an argument, but running evaluate on it decreases the performance because `f[x]` is evaluated twice. What I am looking for is to put _Mathematica_ in a mode which a typical user with a typical problem does not suffer the low speed as it does now. So typing `Pi + 1` should result in `4.1416`, `{Pi,1}` should give a packed array, and _Mathematica_ should forget about commutativity and associativity of addition since it does not hold for numerical problems.


title: Linear interpolation over 2 variables

text: I'm tuning a function to data over 4-5 variables using Differential Evolution. The objective function calls frequently interpolation function. I came to a point, where compiling the objective function should make things much faster. But interpolation function cannot be compiled. Is there compilable implementation of linear interpolation function over 2 variables that is faster or of similar speed with uncompilable internal interpolation function?


title: Undocumented form for Extract

text: Prompted by a comments conversation here, here's an interesting (and often performance enhancing) use of `Extract`:               target = Join[Range[100], {{1, 2, 3, Range[20]}}];          Rest@Extract[target, {{{}}, {2 ;; 10 ;; 2}, {-1, -1, 1 ;; -1 ;; 2}}]          (* {{2, 4, 6, 8, 10}, {1, 3, 5, 7, 9, 11, 13, 15, 17, 19}} *)      Prepending the `{{}}` to the extraction list appears to suppress the error message one would otherwise get attempting to use `Span`, and it appears that most any valid position/span construct can be used in the extraction list. The extracted list has an empty list as first element (hence the use of `Rest`). Prepending just `{}` makes the first element the original list. I've often found this useful instead of mapping over a list of spans (and faster). This seems similar to the undocumented extension to `MapAt` As noted by Mr. Wizard, this does not appear to work in V7, I'm curious what versions it works in.


title: How to automatically put the part of a variable name after the first letter in symbolized subscripts?

text: So here is what I have thought: Use ToString and StringLength in order to get the number of characters in the variable name. If it is bigger than one, change variable name by putting everything but the first character as subscript. Symbolize subscipt to avoid issues. Example: Going from $ux1 - i1$ to $u_{x1}-i_1$ $x$ is a variable but I do not want any interference with u_{x...}! About the symbolization of subscripts I looked up and found this: Needs["Notation`"]; Symbolize[ParsedBoxWrapper[SubscriptBox[" _", "_ "]]]; For the rest I have not been able to do it mainly because I do not manage to make the function go through an expression and change all the elements of it. I also tried to use Replace but failed.


title: Aligning controls and their labels to grid?

text: I have a `Manipulate` with 6 sliders controlling 6 different variables. I have labelled them all. The problem is that the labels have different lengths, so it looks a bit messy: ![enter image description here](http://i.stack.imgur.com/LB3HG.png) I'd much rather have the sliders aligned with each other perfectly so that they don't start and end in different places, to make them look more orderly. How would it be possible to do this? This is how the control panel is presently built:               {{x, 1, "Time"}, 1, 200*3.154`*^7, Animator,       AnimationRate -> speed*86400, AnimationRunning -> False},     Row[{Control[{{speed, 1, "Speed"}, 1, 30}], Spacer[20],        Dynamic[speed]}],     Row[{Control[{{\[Theta], 10, "Zoom"}, 30, 1}], Spacer[20],        Dynamic[\[Theta]], " degrees"}],     Row[{Control[{{scale, 0, "Scaling"}, 0, 5}], Spacer[20],        Dynamic[10^scale], " \[Times]"}],     Row[{Control[{{Opac, 0.05, "Opacity"}, 0, 0.5}], Spacer[20],        Dynamic[Opac]}],     Row[{Control[{{recurRate, 1, "Recurrence rate"}, 0.1, 1}], Spacer[20],        Dynamic[recurRate]}]      **UPDATE** On @Kuba's recommendation, I have put the whole thing in a `Grid`. Now however, it is displaying the variable names alongside the sliders. How can I hide the variable names from displaying next to the sliders? This is the code I'm currently using:               Grid[{       {"Time",         Control[{{x, 1}, 1, 200*3.154`*^7, Animator,           AnimationRate -> speed*86400, AnimationRunning -> False}],         SpanFromLeft},       {"Speed", Control[{{speed, 1}, 1, 30}], Spacer[20], Dynamic[speed],         Dynamic@If[speed == 1, " day per second",           " days per second"]},        {"Zoom", Control[{{\[Theta], 10}, 30, 1}],         Spacer[20], Dynamic[\[Theta]],         Dynamic@If[\[Theta] == 1, " degree", " degrees"]},       {"Scaling", Control[{{scale, 0}, 0, 5}], Spacer[20],         Dynamic[10^scale], " \[Times]"}},          Alignment -> Left]      ![enter image description here](http://i.stack.imgur.com/N3HQw.png)


title: Explain the difference between ViewPoint and ViewVector?

text: I've read the documentation, but am still very unclear as to what the difference is between `ViewVector` and `ViewPoint` for `Graphics3D`. Could someone explain it concisely and clearly enough so that an amateur like myself could understand?


title: How to compute variances from a matrix/table

text: I have created a matrix/table with an imported dataset. I want to know what the variance is for 3 values at a time but across 68 columns. I would like to do this in an automated way rather than 1 set of values at a time. Is there a way? I'm new to Mathematica, so if there is a really simple way, I don't know about it yet!


title: Calculation of Jacobians for a finite element method simulation

text: I'm attempting to calculate symbolic expressions for the (Newton's method) Jacobian of a Galerkin finite element method using Mathematica. It would seem that this is a perfect application for symbolic differentiation tools but I can't get it working (probably due to my lack of Mathematica knowledge). # Mathematical statement of the problem Let $v(\mathbf{x})$ and $\psi_k(\mathbf{x})$ ($k=1,\ldots,N$) be simple(ish) polynomial functions of space. Let $\mathbf{m}(\mathbf{x}) = [m_1(\mathbf{x}),m_2(\mathbf{x}),m_3(\mathbf{x})] $ be a vector field. Let $$ \mathbf{m}(\mathbf{x}) = \sum_{k=1}^N \psi_k(\mathbf{x}) \mathbf{m}_k, $$ and $$ r(\mathbf{x}) = \int_V (\mathbf{m} \times \nabla^2 \mathbf{m}) v(\mathbf{x}) dV. $$ (I have used $\nabla^2$ as the _vector_ Laplacian $ \nabla^2 \mathbf{m} = [ \nabla^2 m_1, \nabla^2 m_2, \nabla^2 m_3]. $) Calculate $\frac{\partial r}{\partial m_{i,k}}$ for all $i$ (directions of $\mathbf{m}$), and all $k \in {1,\ldots,N}$ (index for the $\psi$ functions). # My code I'm sure this can be written much more elegantly but as I said before I'm not too great with Mathematica. Anyway it should be good enough to give you the idea.               psi[x_, y_, z_] := {a[x, y, z], b[x, y, z]};     (* Really we just need to declare that this is a vector somehow...*)          m[x_, y_, z_] := {m1x*psi[x, y, z][[1]] + m2x*psi[x, y, z][[2]],       m1y*psi[x, y, z][[1]] + m2y*psi[x, y, z][[2]],       m1z*psi[x, y, z][[1]] + m2z*psi[x, y, z][[2]]}          VectorLaplacian[f[x,y,z]_] := {       D[f[x,y,z][[1]], {x, 2}] + D[f[x,y,z][[1]], {y, 2}] + D[f[x,y,z][[1]], {z, 2}],       D[f[x,y,z][[2]], {x, 2}] + D[f[x,y,z][[2]], {y, 2}] + D[f[x,y,z][[2]], {z, 2}],       D[f[x,y,z][[3]], {x, 2}] + D[f[x,y,z][[3]], {y, 2}] + D[f[x,y,z][[3]], {z, 2}]     }          r[x_, y_, z_] := (Cross[m[x, y, z], VectorLaplacian[m[x, y, z]]])*v[x,y,z]      (* I've left out the integration for now to keep things simpler *)          J[x_, y_, z_] := {       {D[r[x,y,z][[1]], m1x], D[r[x,y,z][[2]], m1x], D[r[x,y,z][[3]], m1x]},       {D[r[x,y,z][[1]], m1y], D[r[x,y,z][[2]], m1y], D[r[x,y,z][[3]], m1y]},       {D[r[x,y,z][[1]], m1z], D[r[x,y,z][[2]], m1z], D[r[x,y,z][[3]], m1z]},            {D[r[x,y,z][[1]], m2x], D[r[x,y,z][[2]], m2x], D[r[x,y,z][[3]], m2x]},       {D[r[x,y,z][[1]], m2y], D[r[x,y,z][[2]], m2y], D[r[x,y,z][[3]], m2y]},       {D[r[x,y,z][[1]], m2z], D[r[x,y,z][[2]], m2z], D[r[x,y,z][[3]], m2z]}     }          J[1, 1, 1]      But all I get is:               {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}


title: Simplify using functional equations

text: Is it possible to simplify assuming a functional equation, for examlpe to use that one function, g, is the invers of another, f.               Simplify[g[f[x]], g[f[x_]] == x]      just returns `g[f[x]]`, and similar for FullSimplify.


title: Create composite key - operating across rows in a dataset

text: I would like to be able to create a new dataset by extracting 2 columns to make a composite key, and also extracting other columns. For example, suppose my dataset looked like: ![enter image description here](http://i.stack.imgur.com/wBVza.png) I would like to create:               {<| New Key -> {2013, TYML143}, Earned Prem Est -> -19322.6|>,      <| New Key -> {2013, TYML143}, Earned Prem Est -> -7323.55|>,      <| New Key -> {2013, TYML529}, Earned Prem Est -> -2259.94|>,      ...}


title: Pattern-rewriting Pattern triggers error?

text: I am trying to rewrite patterns. For example, I'd like to rewrite the pattern               jFoo_Integer      which has `FullForm`               Pattern[jFoo,Blank[Integer]]      into just               Blank[Integer]      In other words, I want to strip out the names of patterns. I tried the following               jFoo_Integer /. {Pattern[nym_, Blank[typ_]] :> {nym, typ}}      which does not match or reduce and produces the (IMO bogus) error message               Pattern::patvar: First element in pattern Pattern[nym_,Blank[typ_]] is not a valid pattern name. >>      I also tried                   Pattern[jFoo,Blank[Integer]] /. {Pattern[nym_, Blank[typ_]] :> {nym, typ}}         Pattern[jFoo,Blank[Integer]] /. {Verbatim[Pattern][nym_, Blank[typ_]] :> {nym, typ}}         jFoo_Integer /. {Verbatim[Pattern][nym_, Blank[typ_]] :> {nym, typ}}         jFoo_Integer /. {Verbatim[Pattern][nym_, Blank[typ_]] :> {nym, typ}}      all with exactly the same (failed) results. Any hints, please & thanks?


title: $SU(4)$ Structure constants in mathematica

text: How can I write a mathematica function which will output arbitrary structure constants of SU(4)?


title: Why is a non-convergent series simplified to zero?

text: Sum[Sin[n*x]*Sin[n] /. x -> 1, {n, 1, Infinity}] ==        Sum[Sin[n*x]*Sin[n], {n, 1, Infinity}] /. x -> 1      > Sum::div: Sum does not converge. >> > > Sum::div: Sum does not converge. >> > > Sum[Sin[n]^2, {n, 1, Infinity}] == 0 Can anyone explain this? I do not understand why `Sum[Sin[n*x]*Sin[n], {n, 1, Infinity}]` is automatically simplified to 0 when the series does not converge (unless `Mod[x, Pi] == 0` in which case the sum really is zero).


title: Join two datasets on keys

text: I want to be able to join two datasets by keys, pretty much like I'd do in SQL. I thought the JoinAcross function might do it, but it doesn't operate the way I thought. The example in the documentation shows:               JoinAcross[     {<|a -> 1, b -> X|>, <|a -> 2, b -> Y|>},     {<|a -> 1, c -> X|>, <|a -> 2, c -> Y|>}, Key[a]]      resulting in:               {<|a -> 1, b -> X, c -> X|>, <|a -> 2, b -> Y, c -> Y|>}      This joins down. What I need is like the following:               JoinAcross[     {<|a -> 1, b -> X|>, <|a -> 1, c -> Y|>},     {<|a -> 2, b -> XX|>, <|a -> 2, c -> YY|>}, Key[a]]      To give me:               {<|a->1, b->X, c->Y|>, <|a->2, b->XX, c->YY|>}      That's what I expect from a SQL join. Is there some way to do this with datasets, or should I go back to the "old way" of gathering things together? Also, I really would like to do this by joining on 2 keys. Not just Key[a], but something like {Key[a],Key[b]}.


title: Plotting in projective space

text: I am having difficulty figuring out how to plot to projective space. Suppose I have a region which I have plotted such as:               RegionPlot[2 <= x <= 5 && 2 <= y <= 5, {x, -5, 10}, {y, -5, 10}]      How would I convert this to the projective plane, i.e. it would require transforming the plot into homogenous coordinates and then mapping it onto a sphere... Similarly, with a 1 dimensional region, such as if I have $2 \le x \le 5$, how would I plot that onto the projective line which is a circle? So for example ![one dim solution](http://i.imgur.com/JzO0j7O.jpg) Is a solution in one dimensions to the interval equation [-1,2]x = [5,100]. The solution to this is $(-\infty, -5] \cup [\frac{5}{2}, \infty)$. These intervals are denoted on the real axis as the bold lines. I want to map them onto that circle and shade the regions below the lines. I have found the following http://demonstrations.wolfram.com/HomogeneousCoordinatesAndTheProjectivePlane/ Here is an example of a 2D region I plotted: ![2D Plot](http://i.imgur.com/0qhiL4u.jpg) Some other systems I plot aren't bounded and hence tend to infinity on both axes hence why I would like to be able to plot these to a projective plane so that I can represent infinity. I tried doing this with the function provided by the kind gentlemen below: ![attempt](http://i.imgur.com/DU9HgGZ.jpg) As you can see the plot is empty, but it definitely shouldn't be seeing as the plot in 2D above it has quite a large region filled in


title: Integral evaluation taking too long

text: When I try to evaluate the following integral, it runs for a much longer time than I think is should without producing a result. What might be the problem? Can anybody please point it out?               h[s_, t_] := HeavisideTheta[s] HeavisideTheta[t - s]     Integrate[Abs[(b*(1 - e^((-b)*s)))/b - h[s, t]], {s, 0, Infinity}]


title: How do I divide the columns of a matrix by the sum of its elements?

text: I am trying to create a transition matrix for a network. In order to do this, I need to sum down the column (the out degree), and then divide the column by the out degree in order to normalize it. I am able to sum down the column. What I am unable to figure out how to do efficiently and easily is to divide the column by the sum.               L = {{0, 1, 0, 1, 0, 0, 0},           {0, 0, 1, 1, 1, 0, 0},           {0, 1, 0, 1, 0, 0, 0},           {0, 0, 0, 0, 1, 0, 0},           {1, 0, 0, 0, 0, 0, 0},           {0, 0, 0, 0, 0, 0, 1},           {0, 0, 0, 0, 0, 1, 0}};


title: Dynamically remove element from list based on test

text: Suppose I have a list               l = {a, b, c, d, e, f....}      I would like to remove one of each pair `{x,y}` if some function `check[x,y]` returns `x`or `y` (or do nothing for that particular pair if the function returns `{}`). The order of the list is important. For example, if               check[c,e] === c;     check[a,f] === f;      and `check` on any other combination is empty, the final list should be               {a, b, d, e, ...}      I know how to write a for loop and do index-based removal, but is it a slicker way to do it using Mathematica's list manipulation functions? EDIT: The `check` function should be non-overlapping in my usage, but in case if there is problematic overlap, say               check[a,e] === a;     check[a,f] === f;      both e and f should remain, since after removal of a (assuming position of a is earlier than f), there is no pair that can be formed with {a,f}.


title: Removing zero values from ordered pairs

text: I have some processed data, which are basically a collection of ordered pairs in the form:               {{x1, y1}, {x2, y2}, ..., {xn, yn}}      Ordered pairs which have either a zero $x$ or $y$ component are not physically meaningful, and should be deleted from the data. I can't for the life of me figure out how to delete these points. I've tried `DeleteCases`, `Position`, `Select`, `Cases`, etc. and none of them work for my application.


title: How to hide global variables in package?

text: in the package I'm writing I have a list of global variables which should not be visible from a notebook. Here's an extract of the package:               Begin["`Private`"];          (* Global variables *)     volumeTheorical = "Not calculated value";     absoluteErrorTheorical = "Not calculated value";     relativeErrorTheorical = "Not calculated value";     volumeReal = "Not calculated value";     absoluteErrorReal = "Not calculated value";     relativeErrorReal = "Not calculated value";     reserves = "";          volumeFitted[radiusFitted_] :=  volumeOfFittedTheoricalSphere[pointsCleaned[radiusFitted], radiusFitted];     pointsCleaned[radiusFitted_] :=   cleanPoints[generatePointsHemiSphere[radiusFitted]];     realPointsAdjusted[Diameter_, Anticlinal_, ConstantZ_] :=  cleanAdjustPoints[pointsCleaned[Diameter/2], Diameter, Anticlinal, ConstantZ];     constantH := 40;      and finally:               End[];     EndPackage[];      Anyway when I open a new notebook, after:               SetDirectory[StringJoin[NotebookDirectory[]]];     Needs["VolumeReserves`"]      If I start to write, for example, constantH...the kernel shows me it already has it set to 40. Instead I'd like it not to be visible, so that any user can define it's own constantH and use it for something else...how can I hide them? Thanks


title: Automatically detecting code that will not run on earlier versions

text: > **Possible Duplicate:**   >  Automated testing for compatibility with older Mathematica versions On my personal computer, I am running version 8.0.4, but on a compute cluster I would like to work with, they have stuck with version 6. With two major releases between the two, there is a lot of functionality in my version that is not present on the cluster. How might I detect which functionality will not be present on the prior versions? Obviously, the simplest method is to load the code into the prior version and determine which functions do not have a definition, but I would like to know before I run something on the older version if it will work, or not. Similarly, some functions have changed behavior or call signature between releases, so how might I detect this, also?


title: How does string interpolation work in Mathematica

text: I've noticed that Mathematica 8 seems to have some kind of string interpolation feature, but I couldn't find any documentation on it and I can't figure out how it works. For example, if I enter               StringForm["x=``", 1 + 2]      in a notebook and evaluate it, I get the string `"x=3"`. If I select that cell and choose Cell->Convert To->StandardForm (Ctrl-Shift-N], Mathematica converts the cell to an expression that looks like this:               "x=\!\(1 + 2\)"      that also evaluates to `"x=3"` However, if I enter the exact same character sequence on a new cell, it evaluates to `"x=1 + 2"`. My question is: Is this documented somewhere? How does it work?


title: How can I plot more than one value in the same date?

text: I am trying to plot values that occur in different days and times. I am using `DateListPlot`, but it plots all the values for a day in the same day. Is there a way to somehow "expand" the x-axis to show the hours?. Is there anything such as a "TimeListPlot" ? Example:               dateValues={{{2011, 2, 11, 14, 56, 0.}, 107}, {{2011, 2, 11, 14, 57, 0.}, 104},      {{2011, 2, 11, 14, 59, 0.}, 97}, {{2011, 2, 11, 17, 5, 0.}, 96},      {{2011, 2, 11, 17, 6, 0.}, 94}, {{2011, 3, 11, 9, 34, 0.}, 102},      {{2011, 5, 11, 12, 37, 0.}, 100}, {{2011, 5, 11, 12, 38, 0.}, 99},      {{2011, 7, 11, 14, 53, 0.}, 121}, {{2011, 7, 11, 14, 55, 0.}, 106},      {{2011, 7, 11, 14, 56, 0.}, 106}, {{2011, 7, 11, 14, 57, 0.}, 107},      {{2011, 7, 11, 19, 6, 0.}, 111}, {{2011, 8, 11, 18, 58, 0.}, 106},      {{2011, 8, 11, 19, 0, 0.}, 102}, {{2011, 8, 11, 19, 1, 0.}, 103},      {{2011, 9, 11, 17, 42, 0.}, 95}, {{2011, 9, 11, 17, 46, 0.}, 94},      {{2011, 9, 11, 19, 9, 0.}, 102}, {{2011, 10, 11, 19, 5, 0.}, 106},      {{2011, 10, 11, 19, 6, 0.}, 107}, {{2011, 10, 11, 19, 8, 0.}, 97},      {{2011, 11, 11, 11, 48, 0.}, 107}, {{2011, 11, 11, 11, 49, 0.}, 106},      {{2011, 11, 11, 11, 50, 0.}, 106}, {{2011, 11, 11, 11, 51, 0.}, 91},      {{2011, 11, 11, 11, 52, 0.}, 92}, {{2011, 11, 11, 11, 53, 0.}, 123},      {{2011, 11, 11, 11, 54, 0.}, 120}, {{2011, 11, 11, 11, 55, 0.}, 98}}      Then, if you plot it:               DateListPlot[dateValues]      ![Mathematica graphics](http://i.stack.imgur.com/5JbkV.png) You get all the first 5 values in the same column. Lets try to plot more than one value in the "relaxed" axis that @doctor_image created:               dateValues2={{{2011, 2, 11, 14, 56, 0.}, 107, 60, 51}, {{2011, 2, 11, 14, 57, 0.}, 104, 60, 50},      {{2011, 2, 11, 14, 59, 0.}, 97, 60, 46}, {{2011, 2, 11, 17, 5, 0.}, 96, 65, 49},      {{2011, 2, 11, 17, 6, 0.}, 94, 66, 71}, {{2011, 3, 11, 9, 34, 0.}, 102, 66, 51},      {{2011, 5, 11, 12, 37, 0.}, 100, 65, 59}, {{2011, 5, 11, 12, 38, 0.}, 99, 66, 53},      {{2011, 7, 11, 14, 53, 0.}, 121, 83, 44}, {{2011, 7, 11, 14, 55, 0.}, 106, 59, 37},      {{2011, 7, 11, 14, 56, 0.}, 106, 62, 35}, {{2011, 7, 11, 14, 57, 0.}, 107, 69, 50},      {{2011, 7, 11, 19, 6, 0.}, 111, 66, 49}, {{2011, 8, 11, 18, 58, 0.}, 106, 67, 55},      {{2011, 8, 11, 19, 0, 0.}, 102, 64, 50}, {{2011, 8, 11, 19, 1, 0.}, 103, 68, 53},      {{2011, 9, 11, 17, 42, 0.}, 95, 60, 47}, {{2011, 9, 11, 17, 46, 0.}, 94, 58, 43},         {{2011, 9, 11, 19, 9, 0.}, 102, 61, 54}, {{2011, 10, 11, 19, 5, 0.}, 106, 69, 49},      {{2011, 10, 11, 19, 6, 0.}, 107, 68, 51}, {{2011, 10, 11, 19, 8, 0.}, 97, 60, 47},      {{2011, 11, 11, 11, 48, 0.}, 107, 68, 53}, {{2011, 11, 11, 11, 49, 0.}, 106, 66, 47},      {{2011, 11, 11, 11, 50, 0.}, 106, 64, 49}, {{2011, 11, 11, 11, 51, 0.}, 91, 71, 77},      {{2011, 11, 11, 11, 52, 0.}, 92, 72, 82}, {{2011, 11, 11, 11, 53, 0.}, 123, 85, 57},      {{2011, 11, 11, 11, 54, 0.}, 120, 82, 62}, {{2011, 11, 11, 11, 55, 0.}, 98, 81, 77}}      I managed to plot them on a regular graphics, but can not use the "relaxed axis":               With[{labels =      Rotate[DateString@#, (3 \[Pi])/2] & /@ dateValues2[[All, 1]]},      ListPlot[{dateValues2[[All, 2]], dateValues2[[All, 3]],      dateValues2[[All, 4]]},      Ticks -> {Transpose[{Range@Length@labels, labels}], Automatic},      Filling -> {1 -> {2}}, Joined -> {False, False, True}]]      ![Blood pressure and pulse plot](http://i.stack.imgur.com/23YBj.jpg) It is a visual way to plot blood pressure and pulse. Any suggestion on how to use the "relaxed" axis?


title: Simpler way of performing Gaussian Elimination?

text: Is there a simpler way of performing Gaussian Elimination other than using RowReduce? Such as a single built in function? **Edit:**   Look at the example from our simulation class. Not too difficult, but using this method to solve problems of the sort is new to most of us. We are solving for P# of course.      ![Example ](http://i.stack.imgur.com/y8ClB.png) Also, to those asking... While I can see what is going on below, I really don't understand what it all means. Asking why not RowReduce? I guess not everyone is at that level of use yet, and I don't like just cutting and pasting internet code without understanding it. I simply wondered if there was a function that would do what the code did, but be built in.                 GaussianElimination[m_?MatrixQ, v_?VectorQ] :=         Last /@ RowReduce[Flatten /@ Transpose[{m, v}]]


title: Use of Strassen's algorithm

text: Strassen's algorithm is an algorithm for matrix multiplication that is asymptotically faster than the naive one. In practice, the matrices involved have to be quite large before Strassen's algorithm becomes faster than the naive one. ## Question Does Mathematica ever use Strassen's algorithm? If so, what is the size of the smallest (square) matrices on which it would do so?


title: Clear Citation Style Cache

text: How can I clear the "Citation Styles Cache" created when you use the EndNote citation management feature for the first time in _Mathematica_. The Citation Management tutorial indicates that such a cache is created, but gives no indication of how to clear it.


title: Using Differences on data: trouble with floats and doubles

text: Consider the following data set (after I have run `FullForm`), which is imported from a file (stored typically as 10.040):               data = {10.`,10.02`,10.04`,10.06`,10.08`,10.1`,10.12`,10.14`,10.16`,10.18`,10.2`,10.22`,10.24`,10.26`,10.28`,10.3`,10.32`,10.34`,10.36`,10.38`,10.4`,10.42`,10.44`,10.46`,10.48`,10.5`,10.52`,10.54`,10.56`,10.58`,10.6`,10.62`,10.64`,10.66`,10.68`,10.7`,10.72`,10.74`,10.76`,10.78`,10.8`,10.82`,10.84`,10.86`,10.88`,10.9`,10.92`,10.94`,10.96`,10.98`,11.`}      As you can see, there is a step of `.02` between each (and every) data point. If I run               DeleteDuplicates@Differences@data      I would expect:               {0.2}      Instead I get (on my computer, YMMV, and after `FullForm`):               {0.019999999999999574`,0.02000000000000135`}      Erk. Now, I've run into these types of problems before (I'm looking at you LabView), and so I expect it has something to do with differences of doubles / floats / machine precision numbers. In LabView, I fixed this by essentially creating a `Equivalent` type function which, given a list of numbers, did a "fuzzy" Union of sorts, and I can do the same for MMA:               DeleteDuplicates[Differences@data,Abs[#1-#2]/Min[#1, #2] < 10^-6 &]      Is this something I can stop from happening with some import parameters, or is there a better way of handling this?


title: How to take derivative of parameterized coordinate?

text: Suppose I have a vector in $\mathbb{R}^n$ but $n$ is not known in advance. I want to be able to write functions which operate on the components of that vector, and then I'd like to be able to take derivatives with respect to the components. As an example, consider the relation: $$\frac{\partial}{\partial x_j} \sum_i x_i$$ Under the assumption that the $x_i$ are independent, I want a call to `Simplify[]` to return `1`. Similarly, calling `Simplify[]` on $\frac{\partial x_i}{\partial x_j}$ should give `KroneckerDelta[i,j]`. It's not clear how I should represent generic coordinates like this. I've seen this, but I'm not sure it provides an answer. As the linked post suggests, I _could_ do this for a fixed $n$, but that's not situation I'm working on, especially since I want to see the generic form for any $n$. For reference, it seems that `sympy` let's you do something close to this.               from sympy.tensor import IndexedBase, Idx     x = IndexBase('x')     i, j = map(Idx, ['i', 'j'])     x[i]          x[i].diff     # <bound method Indexed.diff of x[i]>          x[i].diff(x[j])     # ValueError: Can't differentiate wrt the variable: x[j], 1      But despite being able to represent the variables abstractly, I can't seem to differentiate them. Here is another example. Suppose you wanted to calculate the derivative of the entropy with respect to one of the components of the input distribution (again, assuming all the variables are independent). The final form is the same no matter what $n$-simplex the distribution lives on, so you'd like to be able to do this for any dimension. $$ \frac{\partial H}{\partial p_j} = - \frac{\partial}{\partial p_j} \sum_i p_i \log p_i = - (\log p_j + 1)$$ Problems like this come up in optimization, when you need to provide the gradient and Hessian to numerical algorithms. **Update** : Here are two other related posts: how to differentiate formally? How to customize derivative behavior via upvalues?


title: Using Total on a list supplied by a rule

text: I'm confused as to why `Total` complains about a nonatomic expression here:               Total[myList] /. {myList -> {1,2}}     Total::normal: Nonatomic expression expected at position 1 in Total[myList]. >>     3          Total[{1,2}]     3      If it's important, here's the context in which I'm using it:               obj = someClass[myList -> {}, anotherList -> {1,2}];     calculateStuff[someClass[props___]] := (1 + Total[myList] * Mean[anotherList]) /. {props};     calculateStuff[obj]     Total::normal: Nonatomic expression expected at position 1 in Total[myList]. >>     0      I can't find any discussion about using a rule to transform a symbol into a list like this. One of the examples in the `ReplaceAll` documentation makes it seem like this is okay. What am I missing here?


title: Scale plot display area (within the frame)

text: I have 2 data sets of equal length. I've done a `LinearModelFit` of them which gives me:               d = Transpose[{d1, d2}];     lm = LinearModelFit[d, x, x]          FittedModel[0.000245082 + 0.000514887x]      This reflects a relationship of y axis values that vary proportionately to time. I actually suspect that visually seeing this relationship having the data scaled to it may turn up some interesting patterns. I have a notion of now scaling a plot of the original data proportionate to the FittedModel. Not certain how to go about this and I may not have even articulated the question clearly. A clue, some fields refer to this as "square" scaling, but I haven't seen the term used or described widely. Maybe what doesn't seem to work to do this might help clarify things. I do know that `AspectRatio` doesn't seem to get me to what I have in mind. It scales the entire plot including the axes labels and titles. I want to scale the plot area (within the plot frame) itself. It does seem that I might create a couple of plots, say one without labels with the `AspectRatio` then another with just the axes labels and combine them with `Show` or `Grid`, but this seems cumbersome. I travel over the holiday weekend, so I may not have the connectivity to respond with additional information until late Monday. I will if I can. In the meantime, any thoughts appreciated. Late thought: Would `ScalingFunctions` help to do this?


title: Problem with clipping of tick labels

text: Please look at               Show[DiscretizeGraphics[Graphics3D[{Cone[]}]], Axes -> True, Boxed -> True]      ![enter image description here](http://i.stack.imgur.com/BZl52.jpg) Well, there are some `Ticks`, but others are missing or (on the Z-axis) cut- off. Now it becomes even worse:               dg = DiscretizeGraphics[Normal @ Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}]] // Quiet          Show[dg, Axes -> True, Boxed -> True]      ![enter image description here](http://i.stack.imgur.com/ZkqxL.jpg) The `Ticks` are completely missing. Is this a bug or do I overlook something? **EDIT** Thanks to hieron's answer:               Show[dg,      Axes -> True,      Boxed -> True,      SphericalRegion -> True,      PlotRange -> {{-3.2, 3.2}, {-2.4, 2.4}, {-2., 2.}}]      ![enter image description here](http://i.stack.imgur.com/JRW8D.jpg) However, we don't need this work-around with               Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}]      ![enter image description here](http://i.stack.imgur.com/WVp58.jpg)


title: Evaluation of self-defined functions

text: I defined a function that I call `disc` which I want to minimize later. The function is defined as               disc[dt_]:=Total[(Log[vDat] - Log[(x'[tDat -dt] /. nsol)])^2]      and it quantifies the discrepancy between measured data (the time series `{tDat,vDat}`) and the solution to a differential equation that was obtained with `NDSolve`. My problem is that this function works great sometimes: ![graph](http://i.stack.imgur.com/21zCa.png) but fails in other applications: ![Another graph](http://i.stack.imgur.com/JKAx7.png) I tried hard to get to the bottom of this, but I just can't understand what's wrong. Suggestions? Clarification: `disc[1]` returns a number and not a `{number}`.


title: How to vary color of fill between listplots based on y-distance between them

text: I have two lists with the same x-values but different y-values. I have used `ListPlot` to plot and fill the space (line) between them; however, I would like the color of the fill to be representative of the difference in y-values. I have lists of the form `{{x1,y1},..}: a , b` The normalized difference (from 0 to 1) between the points: `diff`               ListPlot[{a,b}, Filling -> {1-> {{2}, Map[Hue, diff]}}]      I have tried other methods, but this one was the simplest to demonstrate my intent. I have had thoughts about `ColorFunction`, but my attempts have been met with frought. The x-values are Real.


title: Import[] bug (video)?

text: I have the following code:               frames = Import["myvideo.avi",{"Frames",{50,60,70}}];      This imports frames 1,2, and 3 of the video, not 50,60 and 70. It imports the first N frames, where N is the length of list of frames given. Is this expected behaviour? ( I tried the same with a .mov file, same result ) Thanks.


title: Implementation of a condition in a Function

text: I have defined that stoptime {5, 2, 10, 2, 1, 11, 11, 1, 5, 11} and have the following function pvcosts = (-5/1.05^#) &[stoptime] Now I want that everytime "stoptime" is 11, the function gets zero. I already thought about modifiying "stoptime", but I want it to stay the way it is. How can I include a condition, that everytime "stoptime" is 11, "pvcosts" gets zero? Thanks for your help


title: Loop and do operations on Matrix, then graph the results

text: I'm trying to do some operations to a matrix in a loop, and then I want to graph the results. The results are pair of numbers. Can I store the results of each iteration on "something" and the use that to graph it? Or can I convert this loop in some kind of function that I an use for instance in `Plot[myfunction, {x, 0, 10}]`               For[i = 2, i < 50, i++,      iM = {{0.3, 0, 0.5, 0.2}, {0, 0.4, 0.3, 0.3}, {0.3, 0.2, 0,          0.5}, {0.4, 0.1, 0, 0.5}};      staDis = {0.300400534045394, 0.12683578104138837,         0.18825100133511352, 0.38451268357810403};      iMP = MatrixPower[iM, i];      iMPV = iMP[[4]];      y = Norm[iMPV - staDis, 1]/2;      Print["i ", i];      Print["y ",  y ];      Print[" "];      ]


title: Not able to load the package in CDF

text: I am facing a problem in loading the package. My code is working in `Mathematica` but after deploying it into `CDF`, it is unable to load the package and shows error. The code was not even working in `Mathematica` when I evaluated it for the first time but when I evaluated it one more time it worked. I got help from this stackexchange question And now it is working in Notebook but not in `CDF`, after relaunching the Mathematica Kernel.