_id
stringlengths
1
5
title
stringlengths
15
150
text
stringlengths
43
28.9k
7458
Easy button or hot key to switch between `Working` and `SlideShow` Screen Environments to avoid trip to menu
When I edit a slide show it easy to copy whole slides in `Working` Screen Environment but nice to preview slides in `SlideShow` Screen Environment. ![enter image description here](http://i.stack.imgur.com/xo8ZD.png) _Mathematica_ has convenient interactive buttons to go to Full Screen mode and change slides. ![enter image description here](http://i.stack.imgur.com/5lyQy.png) **Is it possible to set up an easy button or hot key to switch between`Working` and `SlideShow` Screen Environments to avoid trips to menu? Maybe using `DockedCells` ? Any similar ideas ?**
48264
Graphical solution of a a two-variable system containing an equation and an inequality
I'm currently studying atmospheric-gravity waves and their dispersion relations. I want to have look at values of $(x,y)$ that solve the following system : \begin{equation}\label{}(1) \left\\{ \begin{array}{rcr} (x+\frac{1}{2}y^{2})\exp(u^2)-y[u+\exp(u^2)]+u\exp(u^2)& = &0\\\ 2u(x+\frac{1}{2}y^{2})\exp(u^2)-y[1+u\exp(u^2)]+u^2& < &0\\\ \end{array} \right. \end{equation} where $x\in [0,1]$, $y\in[0,1]$ and $u\in[0,1]$. My goal is to plot the region $(x,y)$ where this system has a solution. How can I plot S in the $(x,y)$-plane.? The code for the first funtion : f1[u_, x_, y_] := ((y^2)/2 + x)*Exp[u^2] - y*(u + Exp[u^2]) + u*Exp[u^2] f2[u_, x_, y_] := 2*u*((y^2)/2 + x)*Exp[u^2] - y*(1 + u*Exp[u^2]) + u^2 The problem is how to used : ContourPlot or RegionFunction to construct the surface S.
38896
NMinimize stops with no more memory?
I am using NMinimize function for simulation based optimization. So my objective function is a simulation that runs for every combination of variable values evaluated by NMinimize function. However, the problem I have is the Nminimize function ceases after the first run (I am printing the time stamp for every iteration) and eventually after a long time gives me out of memory error. I even tried with different methods such as "RandomSearch" and "SimulatedAnnealing" with custom method parameter values, but in vain. Can some one pinpoint where I am going wrong? edit: My code is long, but as requested is given below: f[a1_, a2_, a3_] := Module[{b1 = a1, b2 = a2, b3 = a3, L = 3, Flen = 1, Rlen = 1,SimTime = 60, Kj = 150,w = 20,Theta = 5, dt = 6,delta = 1,DemandDuration = 10,RMstart = 1,RMLocation = 3, TT = 0}, Print[DateString[]]; Vf = Theta w; dx = Vf dt/3600; capacity = w*Vf*Kj/(Vf + w);n = Round[Flen/dx];m = Round[SimTime/dt];p = Round[Rlen/dx];Rdensity = Table[0*i, {i, p}, {i, m}, {i, n}];Rflow = Table[0*i, {i, p}, {i, m}, {i, n}];Fdensity = Table[0*i, {i, n}, {i, m}];Fflow = Table[0*i, {i, n}, {i, m}];demand[n_, k_] := Min[k*Vf, n*capacity];supply[n_, k_] := Min[(n*Kj - k)*w, n*capacity];flo[demand_, supply_] := Min[demand, supply];den[k_, qin_, qout_] := k + (qin - qout)/Vf; merge[n_, Fu_, Fd_, Rd_] := Min[1, supply[n, Fd]/(demand[n, Fu] + 0.01)]*demand[1, Rd]/delta;Nsupply[n_, k_, qsum_] := Min[(n*Kj - k)*Vf - qsum, n*capacity]; RM[x_, t_] := N[b1 x^2 + b2 x + b3];alpha[a_] := 1500*a/Flen;beta[a_] := 0.1*a/Flen; For[k = 1, k <= n, k++, For[i = 1, i <= p, i++, Rdensity[[i, 1, k]] = 0;]; For[j = 1, j <= DemandDuration, j++, Rdensity[[p, j, k]] = alpha[n*dx]*delta/Vf; TT = TT + Rdensity[[p, j, k]]];]; For[j = 1, j <= 4, j++, For[k = 1, k <= n, k++, If[k == 1, Rflow[[1, j, k]] = merge[L, Fdensity[[k, j]], Fdensity[[k, j]], Rdensity[[1, j, k]]], Rflow[[1, j, k]] = merge[L, Fdensity[[k, j]], Fdensity[[k - 1, j]], Rdensity[[1, j, k]]]]; If[k == 1, Fflow[[k, j]] = flo[demand[L, Fdensity[[k, j]]], supply[L, Fdensity[[k, j]]]], Fflow[[k, j]] = flo[demand[L, Fdensity[[k, j]]], supply[L, Fdensity[[k - 1, j]]] - Rflow[[1, j, k - 1]]*dx]]; If[k > 1 && j < m, Fdensity[[k - 1, j + 1]] = den[Fdensity[[k - 1, j]], (Rflow[[1, j, k - 1]] - beta[(n)*dx]*Fflow[[k, j]])*dx + Fflow[[k, j]], Fflow[[k - 1, j]]]; TT = TT + Fdensity[[k - 1, j + 1]];]; If[k == n && j < m, Fdensity[[k, j + 1]] = den[Fdensity[[k, j]], Rflow[[1, j, k]]*dx, Fflow[[k, j]]]; TT = TT + Fdensity[[k, j + 1]];]; For[i = 2, i <= p, i++, If[i == RMLocation && j >= RMstart, Rflow[[i, j, k]] = Min[RM[k dx, j dt], flo[demand[1, Rdensity[[i, j, k]]], supply[1, Rdensity[[i - 1, j, k]]]]], Rflow[[i, j, k]] = flo[demand[1, Rdensity[[i, j, k]]], supply[1, Rdensity[[i - 1, j, k]]]]]; If[j < m, Rdensity[[i - 1, j + 1, k]] = den[Rdensity[[i - 1, j, k]], Rflow[[i, j, k]], Rflow[[i - 1, j, k]]]; TT = TT + Rdensity[[i - 1, j + 1, k]];]];];]; For[j = 5, j <= m, j++, For[k = 1, k <= n, k++, If[k == 1, Rflow[[1, j, k]] = merge[L, Fdensity[[k, j]], Fdensity[[k, j]], Rdensity[[1, j, k]]], Rflow[[1, j, k]] = merge[L, Fdensity[[k, j]], Fdensity[[k - 1, j]], Rdensity[[1, j, k]]]]; FQsum = 0; For[r = 1, r <= Theta - 1, r++, FQsum = FQsum + Fflow[[k, j - r]]]; If[k == 1, Fflow[[k, j]] = flo[demand[L, Fdensity[[k, j]]], supply[L, Fdensity[[k, j]]]], Fflow[[k, j]] = flo[demand[L, Fdensity[[k, j]]], Nsupply[L, Fdensity[[k - 1, j - Theta + 1]], FQsum] - Rflow[[1, j, k - 1]]*dx]]; If[k > 1 && j < m, Fdensity[[k - 1, j + 1]] = den[Fdensity[[k - 1, j]], (Rflow[[1, j, k - 1]] - beta[(n)*dx]*Fflow[[k, j]])*dx + Fflow[[k, j]], Fflow[[k - 1, j]]]; TT = TT + Fdensity[[k - 1, j + 1]];]; If[k == n && j < m, Fdensity[[k, j + 1]] = den[Fdensity[[k, j]], Rflow[[1, j, k]]*dx, Fflow[[k, j]]]; TT = TT + Fdensity[[k, j + 1]];]; For[i = 2, i <= p, i++, RQsum = 0; For[r = 1, r <= Theta - 1, r++, RQsum = RQsum + Rflow[[i, j - r, k]]]; If[i == RMLocation && j >= RMstart, Rflow[[i, j, k]] = Min[RM[k dx, j dt], flo[demand[1, Rdensity[[i, j, k]]], Nsupply[1, Rdensity[[i - 1, j - Theta + 1, k]], RQsum]]], Rflow[[i, j, k]] = flo[demand[1, Rdensity[[i, j, k]]], Nsupply[1, Rdensity[[i - 1, j - Theta + 1, k]], RQsum]]]; If[j < m, Rdensity[[i - 1, j + 1, k]] = den[Rdensity[[i - 1, j, k]], Rflow[[i, j, k]], Rflow[[i - 1, j, k]]]; TT = TT + Rdensity[[i - 1, j + 1, k]];]];];]; TT] NMinimize[{f[x, y, z], {x, y,z} \[Element] Integers}, {{x , 27, 30}, {y, 797, 800}, {z, 2497, 2500}}]; Ps. Also any suggestions to improve the performance of this code will be greatly appreciated!!
28384
Calling functions which take their arguments interactively
Lets say I have a file named `test.m` containing some functions. test[arg1_, arg2_] := ( Print[arg1]; Print[arg2]; ) test3[arg1_, arg2_] := ( Print[arg1]; Print[arg2]; ) What would be a good way to generate a list of butons that would allow you to invoke the functions easily? For example. ![enter image description here](http://i.stack.imgur.com/3l0yK.png) The tricky part here (and is mainly why I am asking this question) is calling the functions, which will have several different argument types? I had thought about using an `InputField` with a `MessageDialog`, but I would bet there is better way to incorporate _Mathematica_ 's features. ClearAll[loadFile]; loadFile[path_String?FileExistsQ] := DeleteCases[ToExpression[ FromCharacterCode[BinaryReadList[path]] , InputForm, HoldComplete], Null]; x = ReleaseHold[ loadFile["test.m"] /. HoldPattern[sym_[args__] := eval_] :> Button[sym, eval] ]; x[[0]] = List; x
37936
How to get list of duplicates when using DeleteDuplicates?
This might be easy, but can't find a way to use `DeleteDuplicates` to get also list of the actual duplicates. Example: lstA = {1, 2, 4, 4, 6, 7, 8, 8}; r = DeleteDuplicates[lstA] (* {1, 2, 4, 6, 7, 8} *) I also wanted to get list of the actual duplicates, which are `{4,8}` in this example. It would have been nice if `DeleteDuplicates` would also return those, but there is no option there for that. I do not know what many Mathematica functions do not return back more useful information when called. Many seem to return one piece of information only, and one has to call another function to get another piece of information. For example, here `DeleteDuplicates` could had an API like this {r,d}=DeleteDuplicates[lst] and `r` will contain the list after duplicates are moved, but `d` would contain the actual list of duplicates. To make it even more useful, it can be {r,d,p}=DeleteDuplicates[lst] Where `p` will be the positions of the duplicates in the original list. Matlab seems to do it this way. Many functions there can return more than one piece of information at a time. This might be due to WL being functional programming language, and designed for cascading function calls, where each function only does one thing at a time. I am not sure now. DeleteDuplicates.html
55583
How to efficiently process pasted content from PDF
I had selected a matrix in a PDF file, ![Mathematica graphics](http://i.stack.imgur.com/rg5tt.png) and paste it onto my MMA notebook. Below is the exact copy-pasted content: 0.9034 "NAN" 0.7163 0.8588 0.3031 0.5827 0.2699 0.8063 0.0418 0.8426 "NAN" 0.8634 "NAN" 0.8913 0.0662 0.8432 I want to display this content in the matrix form as shown in the original PDF. Thankfully there was no distortion when the content was transferred; however, the white spaces now became implied multiple signs in MMA. ![Mathematica graphics](http://i.stack.imgur.com/3I5dx.png) * * * **My solution** **1)** Convert content to string by simply wrapping it in `""` **2)** I then ran into the problem of the `"NAN"`'s becoming apart from the overall string due to its being wrapped by a pair of `""` previously. I couldn't find a quick way to assimilate them back into the larger string but to manually modify them (by adding a pair of `\`'s such that `"NAN"` became `\"NAN\"`: ref) ![Mathematica graphics](http://i.stack.imgur.com/LMHz5.png) ![Mathematica graphics](http://i.stack.imgur.com/1xn1T.png) ![Mathematica graphics](http://i.stack.imgur.com/VE1aQ.png) **3)** Use `StringSplit` twice, first to split the string at each line break `"\n"` to create 4 "lines"/sublists, and then map it the second time to each line at the `","` to create separate elements for each line. StringSplit[#, {" "}] & /@ StringSplit[%, "\n"] (* {{"0.9034", "\"NAN\"", "0.7163", "0.8588"}, {"0.3031", "0.5827", "0.2699", "0.8063"}, {"0.0418", "0.8426", "\"NAN\"", "0.8634"}, {"\"NAN\"", "0.8913", "0.0662", "0.8432"}} *) **4)** Replace each `"\"NAN\""` with a simple `"NAN"` % /. "\"NAN\"" :> "NAN" (* {{"0.9034", "NAN", "0.7163", "0.8588"}, {"0.3031", "0.5827", "0.2699", "0.8063"}, {"0.0418", "0.8426", "NAN", "0.8634"}, {"NAN", "0.8913", "0.0662", "0.8432"}} *) **_Sidestep_** : I tried to do this step more generally (since the string enclosed by `\"` might be more varied in future cases), by doing this: % /. "\""~~x___~~"\"" :> x This did not work, probably because `ReplaceAll` couldn't handle more complex string replacements (e.g. involving blanks). As a result, I tried `StringReplace`, and it worked as expected: Map[StringReplace[#, "\"" ~~ x___ ~~ "\"" :> x] &, %, {2}] (* {{"0.9034", "NAN", "0.7163", "0.8588"}, {"0.3031", "0.5827", "0.2699", "0.8063"}, {"0.0418", "0.8426", "NAN", "0.8634"}, {"NAN", "0.8913", "0.0662", "0.8432"}} *) **One-step summary** Map[StringReplace[#, "\"" ~~ x___ ~~ "\"" :> x] &, StringSplit[#, {" "}] & /@ StringSplit["0.9034 \"NAN\" 0.7163 0.8588 0.3031 0.5827 0.2699 0.8063 0.0418 0.8426 \"NAN\" 0.8634 \"NAN\" 0.8913 0.0662 0.8432", "\n"], {2}] // MatrixForm ![Mathematica graphics](http://i.stack.imgur.com/btfQe.png) * * * **My question is:** Could anyone help me think of a more elegant/efficient way to get the same result? The greatest bottleneck, I think, is the manual adding of `\`'s, so I'd love to hear how you can do that programmatically.
46949
Is there a built-in procedure for simultaneous diagonalization of a set of commuting matrices?
Given a set $\\{A_1,...,A_m\\}$ of $m$ commuting $N\times N$ diagonalizable matrices, it is known that there exists a basis of eigenvectors $\Lambda$ that simultaneously diagonalizes all the $A_i$. Is there an automated way to compute $\Lambda$ in Mathematica? For a pair of matrices $\\{A_1,A_2\\}$ it can be done "by hand" using `Eigenvectors` to first compute the eigenvectors $\Lambda_1$ of $A_1$, finding similarity transforms $P_k$ that act on the degenerate subspaces of $\Lambda_1$ to make them also eigenvector of $A_2$, and then combining the transformed degenerate subspaces together to form $\Lambda$, but I don't know how to generalize this to more than 2 matrices.
5968
Plotting implicitly-defined space curves
It is known that space curves can either be defined parametrically, $$\begin{align*}x&=f(t)\\\y&=g(t)\\\z&=h(t)\end{align*}$$ or as the intersection of two surfaces, $$\begin{align*}F(x,y,z)&=0\\\G(x,y,z)&=0\end{align*}$$ Curves represented parametrically can of course be plotted in _Mathematica_ using `ParametricPlot3D[]`. Though implicitly-defined plane curves can be plotted with `ContourPlot[]`, and implicitly-defined surfaces can be plotted with `ContourPlot3D[]`, no facilities exist for plotting space curves like the intersection of the torus $(x^2+y^2+z^2+8)^2=36(x^2+y^2)$ and the cylinder $y^2+(z-2)^2=4$: ![torus-cylinder intersection](http://i.stack.imgur.com/ODFj1.png) Sometimes, one might be lucky and manage to find a parametrization for the intersection of two algebraic surfaces, but these situations are few and far between, especially if the two surfaces are of sufficiently high degree. The situation is worse if at least one of the surfaces is transcendental. > How might one write a routine that plots space curves defined as the > intersection of two implicitly-defined surfaces? It would be preferable if the routine returns only `Line[]` objects representing the space curve. A routine that handles only algebraic surfaces would be an acceptable answer, but it would be nice if your routine can handle transcendental surfaces as well. A bonus feature for the routine might be the ability to determine if the two surfaces given do _not_ have a space curve intersection, or intersect only at a single point, or other such degeneracies.
40624
Plotting a curve in 3D
Say I have two polynomials in $\mathbb{R}[X,Y,Z]$, whose intersection of zero loci correspond to a curve in the 3D space. What is the best way to plot the curve? ## Example: $$ f = X^2+Y^2-Z^2, \qquad g = 2X^3+Y^3-Z $$ I want to plot the curve given by $$ \begin{cases} &X^2+Y^2=Z^2 \\\\\\\ &2X^3+Y^3=Z \end{cases} $$
30821
How can I commit files to Github by Mathematica?
# How can I publish Notebooks to Github via using Mathematica? * * * I'm on windows 8.1 x64, _Mathematica_ 9. How can I upload the current notebook to Github? My function expected is: `Notebook2Github[EvaluationNotebook[]]` Now I've installed Github on Windows, and have one test page The **annoying** thing is that each time I added/modified a new file in the destination folder(`E:\Users\HyperGroups\Documents\GitHub\hypergroups.github.com`), I should open GitHub, and add something into the `uncommitted changes` fields and click the `sync` button(shown in the picture) ![enter image description here](http://i.stack.imgur.com/10jQA.png) How can I avoid doing that and complete all such things by the function `Notebook2Github`. * * * ### My tries in Git Shell I can use the following commands in the GitShell. `git add [new file]` /`git commit` and `git push` and the new file will be updated to GitHub.
2745
Deleting parts of a large list
At present I am running an analysis on economic data. Within the data I was able to identify countries which went through recession. I then calculated for example the average decline rate of GDP during recession. All my results are in the following list: CompleteQuarterlyStatData In this list I had to keep also all the countries which did not go through a recession. So if I ask for the decline rate of Australia during recession I get the following answer: In[1328]:= CompleteQuarterlyStatData[[1]][[1]][[1]] Out[1328]= {{"Australia", "AUS", "other countries", "GDP","quarterly data"}, {}} Whereas position 1 (`CompleteQuarterlyStatData[[i]]`) indicates the key figure (in the above example "decline rate during recession"), position 2 (`CompleteQuarterlyStatData[[i]][[j]]`) the economic indicator (in the above example "GDP") and position 3 (`CompleteQuarterlyStatData[[i]][[j]][[k]]`) the country (in the above example "Australia"). (by the way: In total I have nine key figures (so `i` ranges from 1 to 9), 24 economic indicators (`j` ranges from 1 to 24) and 32 countries (`k` ranges from 1 to 32)) As Australia obviously did not got through a recession I want to get rid of all key figures for Australian GDP, which works with the following code: If[ NumberQ[CompleteQuarterlyStatData[[1]][[1]][[2]][[2]]] == False, Table[ Delete[CompleteQuarterlyStatData, i], {i, Map[ Part[#, 1 ;; 3] &, Position[CompleteQuarterlyStatData,CompleteQuarterlyStatData[[1]][[1]][[2]][[1]]]] } ] ]; (Note: Position 2 of `CompleteQuarterlyStatData[[1]][[1]][[2]]` is `{}` and `CompleteQuarterlyStatData[[1]][[1]][[2]]` `{"Australia", "AUS", "other countries", "GDP","quarterly data"}`. (see Out[1328])) So what all countries, which did not go through a recession or a longterm decline, have in common is, that `CompleteQuarterlyStatData[[1]][[EcoIndicator]][[Country]][[2]]` is always of the value `{}`. (Note: `CompleteQuarterlyStatData[[1]]` refers to the key figure "decline rate during recession".) To get rid of all countries which did not suffer from a longterm decline in a given economic indicator I could wrap `Table` around my if-procedure to go through all economic indicators and countries: Table[ Table[ If[ NumberQ[CompleteQuarterlyStatData[[1]][[EcoIndicator]][[Country]][[2]]] == False, Table[ Delete[CompleteQuarterlyStatData, i], {i, Map[ Part[#, 1 ;; 3] &, Position[CompleteQuarterlyStatData,CompleteQuarterlyStatData[[1]][[EcoIndicator]][[Country]][[1]]]] } ] ] ,{Country,Length[CompleteQuarterlyStatData[[1]][[EcoIndicator]]]}] ,{EcoIndicator,Length[CompleteQuarterlyStatData[[1]]]}]; But that does not work. Does anyone has a suggestion? In fact it would be nice to have something like `Delete[CompleteQuarterlyStatData,ArrayXXX]` whereas `ArrayXXX` represents the position of all countries (which did not go through a longterm decline) within `CompleteQuarterlyStatData`. * * * For better understanding I created an example: list = { { {{{"Australia","GDP"},{}}, {{"Korea","GDP"},-2.45}, {{"USA","GDP"},-2.34}}, {{{"Australia","GDP"},2.34}, {{"Korea","GDP"},1.23}, {{"USA","GDP"},1.45}} }, { {{{"Greece", "Imports"},3.25}, {{"Turkey","Imports"}, {}}, {{"USA","Imports"},-2.64}}, {{{"Greece", "Imports"},-1.23}, {{"Turkey","Imports"},3.56}, {{"USA","Imports"},-1.56}} } }; The output of `list[[1]][[1]][[1]]` or `list[[2]][[1]][[2]]` matches the pattern `{_,{}}`. In that case I would like not only to delete those parts of list witch matches the pattern `{_,{}}` but also all other key figures which were calculated for the individual country and economic indicator. The result should then be: { { {{{"Korea","GDP"},-2.45}, {{"USA","GDP"},-2.34}}, {{{"Korea","GDP"},1.23}, {{"USA","GDP"},1.45}} }, { {{{"Greece", "Imports"},3.25}, {{"USA","Imports"},-2.64}}, {{{"Greece", "Imports"},-1.23}, {{"USA","Imports"},-1.56}} } }; The reason: Australia did not go through a longterm decline in GDP, neither did Turkey in imports (if so, all other key figures concerning Australia & GDP or Turkey & imports would be irrelevant for further calculation).
37845
How to implement Kemeny-Young method? (rank aggregation problem)
**Prehistory** I am trying to make some statistical analysis of some experimental data, arises from measurements made ​​on an ordinal scale. I faced with the problem of _rank aggregation_ : to get from many "individuals" orderings (on the same set of objects) one "collective" ordering. The most "natural" approach to this problem is _Kemeny-Young method_ (better look primary source). Surprisingly I found out that there is no program application for this method!!! (There is one C++ code, but it does not allow weak orderings, i.e., does not allow cases when several objects share same position at ordering). Previously I asked some points (one, two) for constructing needed code, but now I have decide to tell all at once — because the problem is more complicated than I thought at first, and I can miss some points since I am null in _Mathematica_ and programming. **Description** Let $R_1, R_2, R_3, ..., R_N$ denote "individuals" weak orderings of $N$ given objects $a, b, c, ...$. Let consider $R$ as set of ordered pairs of objects. Then $(a, b)\in R$ has the usual interpretation: "$a$ is _ordered at least as good as b_ at $R$". In case $(b, a)$ is also in $R$ we say that " _both are ordered equally good_ ". Where in case $(b,a)$ is not in $R$ we say that "$a$ is _ordered above_ $b$" or "$b$ is _ordered below_ $a$". (After introducing metric we will see that it is possible to neglect — since they don't make further difference — such pairs as $(a, a), (b, b), (c, c)...$.) > To demonstrate orderings notation, here are all possible orderings for > $N=3$: > > $\ R_1=\\{(a, b), (a, c), (b, c)\\}$ > > $\ R_2=\\{(a, c), (a, b), (c, b)\\}$ > > $\ R_3=\\{(a, b), (a, c), (b, c), (c, b)\\}$ > > $\ R_4=\\{(b, a), (b, c), (a, c)\\}$ > > $\ R_5=\\{(b, c), (b, a), (c, a)\\}$ > > $\ R_6=\\{(b, a), (b, c), (a, c), (c, a)\\}$ > > $\ R_7=\\{(c, a), (c, b), (a, b)\\}$ > > $\ R_8=\\{(c, b), (c, a), (b, a)\\}$ > > $\ R_9=\\{(c, a), (c, b), (a, b), (b, a)\\}$ > > $R_{10}=\\{(a, b), (b, a), (a, c), (b, c)\\}$ > > $R_{11}=\\{(a, c), (c, a), (a, b), (c, b)\\}$ > > $R_{12}=\\{(b, c), (c, b), (b, a), (c, a)\\}$ > > $R_{13}=\\{(a, b), (b, a), (a, c), (c, a), (b, c), (c, b)\\}$ For such notation we may introduce metric $\delta$ (so-called _Kemeny distance_ ) between any two orderings $R_1$ and $R_2$ by next way: $$\delta(R_1,R_2)=|R_1\setminus R_2|+|R_2\setminus R_1|$$ where $\setminus$ means set-theoretic difference; and $||$ means cardinality of set (i.e., number of elements, because sets are finite). The required "collective" ordering $Ω$ (so-called _Kemeny mean_ ) is such ordering of given objects, that minimizes the sum of the squares of Kemeny distances to all "individuals" orderings, i.e.: $$Ω=\min \sum_{i=1}^{N } \delta(R_i,Ω)^2$$ In fact, $Ω$ may be not unique, there may be several $Ω_1, Ω_2, ...$ for which the appropriate sums of the squares of Kemeny distances are equal and minimal. So in general case $Ω$ is set of such $Ω_i$. **How to attack** So we have several of $R_i$ as input and the goal is to output $Ω$. It looks, like there should be brute-force with one-by-one generating of possible ordering, calculating the sum of the squares of Kemeny distances to all input orderings and verifiaction for minimum. Even for small $N$ number of possible orderings is huge (for my data case $N=10$, there are over $10^8$ possible orderings), so we should keep less data.
50416
Generating an Ulam spiral
An Ulam Spiral is quite an interesting construction, revealing unexpected features in the distribution of primes. Here is a related topic with one answer by Pinguin Dirk, who has provided one approach. I've created a faster implementation, but I believe it can surely be speeded up: ClearAll[spiral] spiral[n_?OddQ] := Nest[ With[{d = Length@#, l = #[[-1, -1]]}, Composition[ Insert[#, l + 3 d + 2 + Range[d + 2], -1] &, Insert[#\[Transpose], l + 2 d + 1 + Range[d + 1], 1]\[Transpose] &, Insert[#, l + d + Range[d + 1, 1, -1], 1] &, Insert[#\[Transpose], l + Range[d, 1, -1], -1]\[Transpose] & ][#]] &, {{1}}, (n - 1)/2]; spiral[5] // MatrixForm spiral[201] // PrimeQ // Boole // ArrayPlot > ![enter image description here](http://i.stack.imgur.com/9p8h8.png) > > ![enter image description here](http://i.stack.imgur.com/v65AV.png) This is good enough for my purposes, and I don't have time to focus on this now, However, it might be interesting for future visitors, so **the question** is how to make it faster by improving/rewriting. * * * **Note:** There may be confusion concerning whether I need a matrix populated with primes or one populated only with 0 and 1, 1 indicating the prime positions. Let's assume it doesn't matter. Maybe someone has a neat idea for the first representation that does not look good in the second one, so I'm leaving it open.
2032
Creating a realtime MIDI Out
I have a live stream of notes and note velocities using `SoundNote` and `SoundVolume`. My problem is that I have no idea how to export the MIDI data in real time to an external synthesizer. Would I just use something like this, for example? Dynamic[Export["file.mid", Sound[SoundNote[0]]] ] I haven't tried this yet because even if I did have a dynamic MIDI file, how would I get the third party software, like GarageBand or Logic to recognize the MIDI input stream? Another way to phrase this question would be: how do I make _Mathematica_ into a live-playing software synth and not just produce a static MIDI composition?
55339
Why is AllTrue much slower than VectorQ?
This seems to be a theme with V10, a new function dedicated to a specific task doesn't live up to expectation performance-wise. Mr. Wizard has already uncovered 2 such functions here and here. So how about `AllTrue` versus `VectorQ`? From the docs ![Mathematica graphics](http://i.stack.imgur.com/vQ9tw.png) ![Mathematica graphics](http://i.stack.imgur.com/iOfva.png) We're interested in the second usage of `VectorQ` here, which is the same as the purpose of `AllTrue`. A quick test shows that `VectorQ` annihilates `AllTrue` when it comes to performance e.g. Needs["GeneralUtilities`"] AccurateTiming[AllTrue[Range[10^6], IntegerQ]] > 0.20069455 While for `VectorQ`: AccurateTiming[VectorQ[Range[10^6], IntegerQ]] > 0.00214923153 That is a two order of magnitude performance increase over `AllTrue`. Using `BenchMarkPlot` from the useful `GeneralUtilities` package we observe the following: BenchmarkPlot[ {VectorQ[#, IntegerQ] &, AllTrue[#, IntegerQ] &}, Range[#] &, PowerRange[10, 10^8], "IncludeFits" -> True, PlotRange -> Full ] ![Mathematica graphics](http://i.stack.imgur.com/PEjLa.png) So, why is `AllTrue` slow compared to `VectorQ`?
31913
How to make a function work on symbols in a specific context
Let us say we have two sets of symbols $(x, y, z)$ with the same names that live in two different contexts: {context1`x,context1`y,context1`z} = {1, 10, 100} {context2`x,context2`y,context2`z} = {2, 20, 200} How can we define a function which takes as an argument a context name, adds $x$ and $y$ that live in the specified context and assigns the result to $z$ in the same context? **Example:** f["context1`"] would result in > > {context1`x, context1`y, context1`z} = {1 ,10, 11} > > {context2`x, context2`y, context2`z} = {2, 20, 200} >
1770
ParallelTable and Table do not give same result
I have a question regarding the use of `Parallelize`. In the help one can read that “`Parallelize[Table[expr,iter, …]]` (which is equivalent to `ParallelTable[expr,iter,…])` will give the same results as `Table`, except for side effects during the computation.” Ok, here I have an easy code where I use an `If`-conditional inside my Table: arrayA=Table[RandomReal[{-1,1}],{i,1,1000}]; arrayToBeFilled=ConstantArray[0,1000]; Parallelize[Table[If[arrayA[[i]]<=0,arrayToBeFilled[[i]]=arrayA[[i]]+5, arrayToBeFilled[[i]]=arrayA[[i]]-5],{i,1,1000}],Method->Automatic];//Timing I do not get any useful result except my unaltered initialized array, but if I use the same code without `Parallelize`, it works fine (and even faster)! Since my real code (in principal the same as above but with more calculations) takes some time for evaluation, I hoped that I could increase the speed by using `Parallelize`. But it seems that either I am doing/understanding something wrong or that something is wrong with `Parallelize` by itself. Can somebody tell me what the case is? I also would be happy if somebody could tell me a better way how I could increase the speed of such code as in my example.
42845
Updating List with Do works but not with ParallelDo
I am trying to find 5 minimas for some function. I can obtain the results if I implement a simple Do function. I tried to speed it up by using ParallelDo and then my code returns spurious results. Here is an example: **With Do Loop** mytable = {{0, 0, 0, 0, 0, 0, 10^7}, {0, 0, 0, 0, 0, 0, 10^6}, {0, 0, 0, 0, 0, 0, 10^10}, {0, 0, 0, 0, 0, 0, 10^8}, {0, 0, 0, 0, 0, 0,10^9}}; ele[a_, b_, c_, d_, e_, f_] := (c/(a + b)) Exp[(d/e)^(-1/f)]; Do[mytable = SortBy[mytable, Last]; If[ele[a, b, c, d, e, f] < Last[Last[mytable]], mytable[[-1, All]] = {a, b, c, d, e, f, ele[a, b, c, d, e, f]}], {a,1, 2, 0.5}, {b, 2, 2.5, 0.05}, {c, 0.1, 1.1, 0.5}, {d, 1, 2, 0.5}, {e, 1, 2, 0.5}, {f, 1, 2, 0.5}] SortBy[mytable, Last] I get the desired output: > {{2., 2.5, 0.1, 2., 1., 1., 0.0366383}, {2., 2.45, 0.1, 2., 1., > 1.,0.0370499}, {2., 2.4, 0.1, 2., 1., 1., 0.0374709}, {2., 2.35, 0.1,2., 1., > 1., 0.0379016}, {2., 2.3, 0.1, 2., 1., 1., 0.0383424}} But when I simply change Do to **ParallelDo** , it gives me the original mytable values without any change. > {{0, 0, 0, 0, 0, 0, 1000000}, {0, 0, 0, 0, 0, 0, 10000000}, {0, 0, 0, 0, 0, > 0, 100000000}, {0, 0, 0, 0, 0, 0, 1000000000}, {0, 0, 0, 0, 0, 0, > 10000000000}} Can anyone tell me if this is due to independence problem or is there a better way to Parallelize my code?
43470
Can I make a function which depends on several arguments which are not independent?
Here's a simple example Suppose have the permanent relation that z is proportional to xy^2, for real numbers s. z = s x y^2 Now, we are interested in functions of x,y,z, say: f[x_,y_,z_] = Sin[x z]-(1-y z Cos[z])^(-1) Let's say for reasons of interpretation of the system, we do not want to simply replace z by sxy^2 and make a new function always g[x_,y_,s_] = Sin[s x^2 y^2] - (1-s x y^3 Cos[s x y^2])^(-1) This same thing could have been obtained from the first function by just calling: f[x, y, s x y^2] Instead, what I would like to be able to do, is retain the full f[x_,y_,z_], unless I have specifically asked for numerical values of x and y. What I would like is to get f[x, y, z] = Sin[x z]-(1-y z Cos[z])^(-1) and f[2,1,(*something*)] = to do something a little different. If the first two arguments are numerical, I would like the function to treat the third argument as the proportionality constant s, instead of as z itself. I suppose I could accomplish this with some kind of If statement? If those arguments are NumberQ false, take the 3rd argument to be z, and if they are both NumberQ True, take the third argument to be s, as in z=s x y^2? I suppose this question really reduces to can I make a conditional function which differs depending on the argument type?
48978
Runge-Kutta 2nd Order ODE Solver
Suppose I have a 2nd order ODE of the form `y''(t) = 1/y` with `y(0) = 0` and `y'(0) = 10`, and want to solve it using a Runge-Kutta solver. I've read that we need to convert the 2nd order ODE into two 1st order ODEs, but I'm having trouble doing that at the moment and am hoping someone here might be able to help. This is my code thus far: Remove["Global`*"] (*dy/dt=*)f[t_, y_] := 1/y; (*d^2y/dt^2=*)g[t_, y_, yd_] :=???; t[0] = 0; y[0] = 0; yd[0] = 10; tmax = 1000; h = 0.01; Do[ {t[n] = t[0] + h n, k1 = h f[t[n], y[n], yd[n]]; l1 = h g[t[n], y[n], yd[n]]; k2 = h f[t[n] + h/2, y[n] + k1/2, yd[n] + l1/2]; l2 = h g[t[n] + h/2, y[n] + k1/2, yd[n] + l1/2]; k3 = h f[t[n] + h/2, y[n] + k2/2, yd[n] + l2/2]; l3 = h g[t[n] + h/2, y[n] + k2/2, yd[n] + l2/2]; k4 = h f[t[n] + h, y[n] + k3, yd[n] + l3]; l4 = h g[t[n] + h, y[n] + k3, yd[n] + l3]; y[n + 1] = y[n] + 1/6 (k1 + 2 k2 + 2 k3 + k4); yd[n + 1] = yd[n] + 1/6 (l1 + 2 l2 + 2 l3 + l4); }, {n, 0, tmax}] As you can see by the question marks for the function `g[t_,y_,yd_]`, I don't know how I can set it in such a way that `y''(t) = 1/y`. Do I feed the results of `y[n+1]` into `g` when running the algorithm? Any help would be appreciated.
55333
Speeding Up Replacing of Labels in Large Matrix?
I am Mathematica novice and am trying to find a fast way to replace labels in some rather large matrices (512x512 or 1024x1024) that have resulted from segmenting images with WatershedComponents or MorphologicalComponents. At present I have written the function below that takes a "label matrix" (matrix that results from segmentation) and a list of "keeper" labels (labels that I want to remain in place in the returned matrix) and returns a new matrix with only those labels remaining in place that are in the listOfKeepersIn. All other labels are replaced in the returned matrix with a single "background" label, here designated as 100. I suspect there are many more efficient ways to achieve this than what I have written here, so I welcome your suggestions. I have tried to convert this to a Compiled Function using Compile but haven't had any success (get an error message about "tensors of different ranks"). I also tried to use ParallelTable instead of Table but didn't notice much improvement. Thanks in advance for any help you can provide. -GR ComponentKeeperFunction[matrixIn_, listOfKeepersIn_] := Block[{matrixToReturn}, matrixToReturn = Table[ Which[ MemberQ[listOfKeepersIn, matrixIn[[r, c]]] == True, (* If label value is on the keeper list then just keep that label in its place, (i.e. make the value in the table the same as matrixIn[[r,c]])*) matrixIn[[r, c]], MemberQ[listOfKeepersIn, matrixIn[[r, c]]] == False, (* If label value is not on the keeper list then replace that label with a designated background label *) 100 (*here I designate the background label as having a value of 100 *) ] (* close Which *), {r, 1, Dimensions[matrixIn][[1]]}, {c, 1, Dimensions[matrixIn][[2]]} ] (*close Table *); Return[matrixToReturn] ](*close Block*)
42888
Simulated Annealing Parameters and Results
I am using `SimulatedAnnealing` method for a simulation based optimization problem and was wondering if someone can enlighten me on the following features: 1. Is there some guidelines on optimal size of `"SearchPoints"` based on the size of the solution space knowing that the objective function is non-linear? 2. It is intuitive that the number of iterations will depend on the objective function, but I have noticed that the number of iterations seem to be a multiple of number of variables. is this true? Sample code is provided in Simulated Annealing Convergence 3. I think it is difficult to prove global optimization results, but was wondering if any one has ideas on alternative ways to do that.
25984
How can I calculate the correlation dimension and/or the Lyapunov exponent of a time series using Mathematica
I have a pretty long time series (4000 data points). How can I calculate the Correlation dimension and/or Lyapunov exponent for such data? Please also advise on how to import the data as well.
40836
How to run all command with same name into a notebook
I have a very big notebook with a command repeated a lot of times but with different parameters each time and I want to run all these commands at the same time without having to run separately all of them. Is there a way? **EDIT: more info** Between different calls of the 'command' there are other things (mainly plots) and I want to preserve the order of the notebook. Using the `Evaluate Notebook` form the menu `Evaluation` can be an option but when I am in a hurry this is bad because it evaluates also all the things in between while I am mainly interested in the output of my commands.
55624
Use of Ito's lemma in ItoProcess
In the documentation for the `ItoProcess` it says: > Converting an `ItoProcess` to standard form automatically makes use of Ito's > lemma. It is unclear to me how this is done, also the example given for the standard form doesn't help. How can I, for example, apply Ito's lemma on the following stochastic differential equation (SDE) $dS=S(σdB+μdt)$, with $B$ being Brownian motion. Applying Itō's lemma with $f(S)=log(S)$ gives $$\begin{align} d\log(S) & = f^\prime(S)\,dS + \frac{1}{2}f^{\prime\prime} (S)S^2\sigma^2 \,dt \\\ & = \frac{1}{S} \left( \sigma S\,dB + \mu S\,dt\right) - \frac{1}{2}\sigma^2\,dt \\\ &= \sigma\,dB +\left (\mu-\tfrac{\sigma^2}{2} \right )\,dt. \end{align}$$ It follows that $$\log (S_t) = \log (S_0) + \sigma B_t + \left (\mu-\tfrac{\sigma^2}{2} \right )t,$$ exponentiating gives the expression for $S$, $$S_t=S_0\exp\left(\sigma B_t+ \left (\mu-\tfrac{\sigma^2}{2} \right )t\right).$$ How can I achieve that in Mathematica?
34813
Expanding a Function in Series works, SeriesCoefficient Doesn't Work
Take the following definitions: rho = Cos[(2 Pi)/7] + I Sin[(2 Pi)/7] F[y, q] = y^3*Product[(1 - Conjugate[lambda] y^-2) Product[(1 - Conjugate[lambda] y^-2*q^n) (1 - lambda*y^2*q^n), {n, 1, Infinity}], {lambda, {rho, rho^2, rho^4}}] G[y, q] = y^2*Product[(1 - Conjugate[mu] y^-1) Product[(1 - Conjugate[mu] y^-1*q^n) (1 - mu*y*q^n), {n, 1, Infinity}], {mu, {1, rho^3, rho^5, rho^6}}] Psi[y, q] = (F[y, q]/G[y, q]) * Product[(1 - q^n)^2, {n, 1, Infinity}] For some reason, I can compute `Series[Psi[y, q], {y, 0, 3}]` quite quickly, but the command `SeriesCoefficient[Psi[y, q], {y, 0, i}]` will not finish for $i=1,2,3$. Why could this be? I've noticed the output of `Series[]` isn't exactly a power series in y, but rather has some powers of y buried into the functions `QPochHammer[]` but I don't know how to get them out. Any help is greatly appreciated. Thanks, Andy.
10885
How to measure segment length and branch angle
I am trying to measure segment length and branch angle or bifurcation angle between each pair of segments. My image after thinning looks like this: ![enter image description here](http://i.stack.imgur.com/me0gY.jpg) i = Import@"http://dl.dropbox.com/u/68983831/thinned.png"; dat = ImageData[i]; i1 = Image[dat[[34 ;; 242, 28 ;; 213]]] g = MorphologicalGraph[i1, EdgeWeight -> Automatic] thus output looks like: ![enter image description here](http://i.stack.imgur.com/tqIPZ.jpg)
10887
Argmax in a List
I have a sequence of 100 lists. A sample list, list[1], looks like this: list[1]=Table[{N[i/10], 25 - (i - 2)^2, 25 - (i - 8)^2}, {i, 1, 10}] {{0.1, 24, -24}, {0.2, 25, -11}, {0.3, 24, 0}, {0.4, 21, 9}, {0.5, 16,16}, {0.6, 9, 21}, {0.7, 0, 24}, {0.8, -11, 25}, {0.9, -24,24}, {1., -39, 21}} I would like to see where the 3rd column, $list[1][[*, 3]]$ is maximized. The 8th Row in this example. Then I want to note the value of the first column in the 8th row, namely $list[1][[8,1]]=0.8$. Then I would like to delete all records where the 1st column is > 0.8, i.e. where $list[1][[*,1]]>list[1][[8,1]]$ . In this example, since the numbers are monotonic, that means the last two rows get deleted. I'll be left with: {{0.1, 24, -24}, {0.2, 25, -11}, {0.3, 24, 0}, {0.4, 21, 9}, {0.5, 16,16}, {0.6, 9, 21}, {0.7, 0, 24}, {0.8, -11, 25}} Then, I would like to see where the 2nd column, $list[1][[*, 2]]$ is maximized. The 2nd Row in this example. Then I want to note the value of the first column in the 2nd row, namely $list[1][[2,1]]=0.2$. Then I would like to delete all records where the 1st column is < 0.2, i.e. where $list[1][[*,1]]<list[1][[2,1]]$ . In this example, since the numbers are monotonic, that means the first row get deleted. I'll be left with: { {0.2, 25, -11}, {0.3, 24, 0}, {0.4, 21, 9}, {0.5, 16,16}, {0.6, 9, 21}, {0.7, 0, 24}, {0.8, -11, 25}} I guess both transformations are identical so if I know how to do one, I can do the other. I just mentioned both simply because it might be feasible to do both in one shot and that code might teach me more than learning the code for a single transformation. Also, I have a hundred different lists and I'd like to be able to do this transformation to all 100 of them in one shot, using Table or something. Thanks, PS: I have read advanced help but I can't seem to figure out how to get the shaded grey background on certain text so I have instead put $$ to get things like $ list[1][[*, 2]] $ as latex math above in my question to appear distinguished from the rest of the text.
10881
Use Mathematica to do a network analysis of Mathematica.SE
Recently Wolfram|Alpha announced that you could use it to analyze your Facebook site. How could I do a network analysis of questioners and answers here on Mathematica.SE?
10883
How to display docked cell (defined in stylesheet) in *.nb only (and not in *.cdf)?
I have a docked cell in a stylesheet (with shortcuts for editing the notebook). Is there an option I can set so that this cell is not displayed in CDF? **Edit** Based on answer by @MikeHoneychurch and the reference provided, here is the code I ended up using. Note this code deploys a notebook to a CDF removing any docked cells and cells tagged with "delete me". It will also ensure that styles embedded in the notebook are copied over to the CDF. Further changes may be required if the notebook inherits a stylesheet (refer to answer and link provided by @MikeHoneychurch). Button["Save as CDF", (*Get the directory/name of the current notebook and change the .nb to .cdf; use this as the default path for the deployed CDF*) tmp = EvaluationNotebook[]; cdfDefaultName = NotebookFileName[EvaluationNotebook[]]; cdfDefaultName = StringReplace[cdfDefaultName, ".nb" -> ".cdf"]; cdfFileName = SystemDialogInput["FileSave", {cdfDefaultName, {"CDF Files" -> {"*.cdf"}}}]; (*Get a copy of the private stylesheet a.k.a child and delete the docked cell*) child = Options[tmp, StyleDefinitions]; childstyles = Cases[child, Cell[StyleData[_, ___], __], \[Infinity]]; modchildstyles = DeleteCases[childstyles, Rule[DockedCells, _], \[Infinity]]; (*Remove specified cells from the notebook *) tmp1 = First@NotebookGet[EvaluationNotebook[]]; tmp1 = tmp1 /. CellGroupData[{Cell[_, "Input", ___, CellTags -> "delete me", ___], ___}, ___] :> Sequence[]; (*Deploy the CDF*) CDFDeploy[cdfFileName, Notebook[tmp1, StyleDefinitions -> Notebook[modchildstyles, StyleDefinitions -> "PrivateStylesheetFormatting.nb"]]], ImageSize -> 100, Method -> "Queued"]
55396
LevelScheme for ListPlot Joined->False exceeds the size of the Panel
In two side by side panels, using LevelScheme, I output the same data using ListPlot. In the first panel I use option Joined-> **False** , while in the second Joined-> **True**. The data in the second panel is properly limited by the size of the panel, while in the first panel it goes beyond the panel limits. So, my question is: how to make objects being displayed be cut exactly by the size of the panel, if even explicitly specifying the PlotRange in ListPlots doesn't make any difference? << "LevelScheme"` Figure[{ Multipanel[{{0, 1}, {0, 1}}, {1, 2}, XGapSizes -> {.5}], FigurePanel[{1, 1}, PlotRange -> {{0, 10}, {0, 1}}], RawGraphics[ ListPlot[Table[{.1 x, Sinc[.1 x]}, {x, Range@200}], PlotRange -> {{0, 1}, {0, 1}},Joined->False] ], FigurePanel[{1, 2}, PlotRange -> {{0, 10}, {0, 1}}], RawGraphics[ ListPlot[Table[{.1 x, Sinc[.1 x]}, {x, Range@200}], PlotRange -> {{0, 1}, {0, 1}}, Joined -> True] ] }, PlotRange -> {{-0.1, 1.1}, {-0.1, 1.1}}] results in ![result of the aforementioned code execution in Mathematica 9](http://i.stack.imgur.com/1Mvs4.png)
31917
Strange response with dynamic texture and MousePosition
I built a cubic, then use `MousePosition` together with `GUIScreenShot` to take a floating region with fixed size (200*200) on the screen, and use it as dynamic texture on the cubic. My code is Needs["GUIKit`"]; $HistoryLength = 1; DynamicModule[{mpp}, Dynamic@{ Refresh[ ClearSystemCache[]; g = GUIScreenShot[With[{mp = MousePosition[]}, mpp = {mp - 100, mp + 100}]]; Graphics3D[{Texture[g], Polygon[coords, VertexTextureCoordinates -> Table[vtc, {6}]]}, Lighting -> "Neutral"], UpdateInterval -> .5], mpp, g}, Initialization :> ( vtc = {{0, 0}, {0, 1}, {1, 1}, {1, 0}}; coords = {{{0, 0, 0}, {0, 1, 0}, {1, 1, 0}, {1, 0, 0}}, {{0, 0, 0}, {1, 0, 0}, {1, 0, 1}, {0, 0, 1}}, {{1, 0, 0}, {1, 1, 0}, {1, 1, 1}, {1, 0, 1}}, {{1, 1, 0}, {0, 1, 0}, {0, 1, 1}, {1, 1, 1}}, {{0, 1, 0}, {0, 0, 0}, {0, 0, 1}, {0, 1, 1}}, {{0, 0, 1}, {1, 0, 1}, {1, 1, 1}, {0, 1, 1}}};)] You can see the result by executing the code then moving your mouse around. Like this, ![enter image description here](http://i.stack.imgur.com/4rNof.png) But there are two strange problems, 1) the size of the floating area taken should be always 200*200, however it will actually change. 2) the memory usage will constantly grow as we move our mouse, but I have already used `$HistoryLength=1` and `ClearSystemCache[]`. Any suggestion?
22674
Creating functions from output of other calculations
Apologies in advance if the title is vague, I'm not really sure what to call this. I have a function (call it 'foo') that generates a largeish polynomial, and it is natural to make the variables be x[1],x[2],x[3] and so on, so I get a polynomial, e.g. x[1]^2 x[2]+x[3] Now, I'd like to store this as a function bar[x[1]_,x[2]_,x[3]_]:=foo[whatever] This doesn't work, of course, but if the variables were e.g. x1,x2,x3 etc. instead, I could do bar[x1_,x2_,x3_]:=foo[whatever] and that would work. I figured some replacement rule would work, e.g. rule={x_[i_] :> ToExpression@(ToString[x] <> ToString[i])} which looks like it should work: x[1]^2 x[2]+x[3]/.rule gives output x1^2 x2 + x3 but if I define bar[x1_,x2_,x3_]:=foo[whatever]/.rule then bar[1,2,3] outputs x1^2 x2 + x3 instead of 5, which it should. Obviously, there is something I don't really understand about the way Mathematica handles variable names, and what I'm trying to do to fix this is probably too naive. Is there some better way to get around this problem? Thanks in advance for any help.
23122
Weighted Kirchhoff Matrix?
I have a weighted graph and I want its graph Laplacian matrix (what Mathematica calls the Kirchhoff matrix in the unweighted case). Is there an easy way to get this? For example, the command: WeightedAdjacencyMatrix[Graph[{0 \[UndirectedEdge] 1},EdgeWeight -> {3}]]//MatrixForm returns the matrix 0 3 3 0 and KirchhoffMatrix[Graph[{0 \[UndirectedEdge] 1}, EdgeWeight -> {3}]] //MatrixForm returns 1 -1 -1 1 whereas I would like 3 -3 -3 3 I can do it in an ugly way, but I am wondering if there is a beautiful way to do it. * * * ### Edit I wrote a small function to do this, and it works. WeightedKirchhoffMatrix[G_] := (M = WeightedAdjacencyMatrix[G]; n = Length[M]; e = Table[1, {i, n}]; DiagonalMatrix[e.M] - M)
50677
How to calculate definite integral when boundary is a limit?
Integrate[Log[x]/(1-x)^2,{x,eta,Infinity}] The conditions are `eta>0`, and `eta->1`, how to incorporate the conditions?
50675
Using Part rather than Extract
In my work I found that I needed the `Extract` function. However I was wondering if there was a way to use `Part`. Assume that `mList` is a 4-dim array. I did the following, which worked. x = {2, 10, 3, 4}; y = Extract[mList, x]; I found that I can't do this. y = mList[[x]] Is there a way to convert the list `x`, into a sequence of integers that I can use in `Part`? I tried enclosing it in `Sequence`, but that seemed to have no effect. As I said, I'm fine without this, I was just wondering.
50674
Solving two-component two-dimensional differential Equation with NDSolve (Brusselator Model)
I'm trying to solve a two-component two-dimensional reaction-diffusion differential equation system with Mathematica. The background of the model is the so called "Brusselator Model" where one can find a nice outline online from the Institute of Theoretical Physics in Münster, Germany. The model is given by the differential equation system: $$u_t=D_u\Delta u+a-(b+1)u+u^2 v$$ $$v_t=D_v\Delta v+b u-u^2 v$$ with u,v as the solution variables depending on x,y and t, $\Delta$ as the Laplace operator $D_u$ and $D_v$ as the diffusion constants and a,b as positive reaction rate constants. This system exhibits a transition from small fluctuations around the uniform steady state solution of the model into a high-amplitude stripe pattern as shown in Fig. 8.6 of the online reference, when the parameterset $D_u$, $D_v$, a and b is in the instability region. Based on stability analysis (see reference) the system is unstable when e.g. using the parameter set $D_u=5$, $D_v=12$, a=3 and b=9. The steady state solution of the system is: $$u_0=a=3, v_0=\frac{b}{a}=1/3$$ In Mathematica we define a small fluctuation (e.g. $\pm2\%$) on the steady state solutions $u_0$ and $v_0$ as initial values (at t=0) of the differential equations u0 = Interpolation[Flatten[Table[{{x, y}, 3 + If[x == 0 || y == 0 || x == 50 || y == 50, 0, RandomReal[{-a/50, a/50} /. a -> 3]], {0, 0}}, {x, 0,50}, {y, 0, 50}], 1], InterpolationOrder -> 2]; v0 = Interpolation[Flatten[Table[{{x, y}, 9/u0[x, y], {0, 0}}, {x, 0,50}, {y, 0, 50}], 1], InterpolationOrder -> 2]; here I restricted the initial value boundaries to the steady state without random fluctuation and enforced that the first derivate of the interpolation function is zero at the boundaries too, to keep the boundary and initial conditions in the differential equation consistent. One can plot the initial condition $u_0$ with the following statements GraphicsRow[{ ContourPlot[u0[x, y], {x, 0, 50}, {y, 0, 50}, PlotLegends -> Automatic, ColorFunction -> "SolarColors", FrameLabel -> {"x", "y"}, ImageSize -> Medium], Plot3D[u0[x, y], {x, 0, 50}, {y, 0, 50}, PlotRange -> {2.9, 3.1}]}] My approach to solve this system for a x-y space interval of 50x50 units and the mentioned parameters, I tried out the following statement NDSolve[Evaluate[{ D[u[x, y, t], t] == Du (Derivative[2, 0, 0][u][x, y, t] + Derivative[0, 2, 0][u][x, y, t]) + a - (b + 1) u[x, y, t] + v[x, y, t] (u[x, y, t])^2, D[v[x, y, t], t] == Dv (Derivative[2, 0, 0][v][x, y, t] + Derivative[0, 2, 0][v][x, y, t]) + b u[x, y, t] - v[x, y, t] (u[x, y, t])^2, u[x, y, 0] == u0[x, y], v[x, y, 0] == v0[x, y], Derivative[1, 0, 0][u][0, y, t] == 0, Derivative[1, 0, 0][u][L, y, t] == 0, Derivative[0, 1, 0][u][x, 0, t] == 0, Derivative[0, 1, 0][u][x, L, t] == 0, Derivative[1, 0, 0][v][0, y, t] == 0, Derivative[1, 0, 0][v][L, y, t] == 0, Derivative[0, 1, 0][v][x, 0, t] == 0, Derivative[0, 1, 0][v][x, L, t] == 0, } /. {L -> 50, Du -> 5, Dv -> 12, a -> 3, b -> 9}], {u, v}, {x, 0, 50}, {y, 0, 50}, {t, 0, 0.05 4000}, MaxSteps -> {15, 15, Infinity}] but get the following error: NDSolve::ibcinc: Warning: boundary and initial conditions are inconsistent. which is strange since I enforced the Neumann boundary conditions through the interpolation function derivate. Finally NDSolve runs forever, yielding no result even with the rather low setting of 15 for MaxSteps in x and y direction. Any proposal for improvements?
50673
RDPStruct.exe: what is it and why are there so many?
I have an old (v7) webMathematica system running and it seems to generate a lot of RDPStruct.exe processes. First, what does this "Converter" do? GIF.exe and JPEG.exe are obvious, but "RDPStruct" doesn't mean anything to me. Does it make sense for there to be more than one running at a time? Does it make sense for there to be like 20 running at a time? Are they being orphaned somehow? If so, how can I figure out which ones are no longer in use? They seem to be causing system problems. I also have some command-line Mathematica processes that stop functioning properly sometimes and I find that killing off the RDPStruct processes will make them start working again. I don't yet have a lot of detail around this yet.
50672
Alternative ways to AppendTo and Delete in a While loop
Is there an alternative way to do `AppendTo` and `Delete` and also replace `k0` during every update? I want to avoid the 3- `CopyTensor`s in the following code which probably are the reason behind the memory and performance problems for large values of `n`. f = Compile[{{n, _Integer}}, Module[{Fk = Table[RandomReal[{0, 1}], {5}, {n}], k0 = Table[RandomReal[{0, 1}], {n}], TT = 0.1, ksum, i = 0}, While[TT > 0 , ksum = Total@Fk; k0 = MapThread[Min[#1, #2 RandomReal[{0, 1}]] &, {k0, ksum}]; TT = Round[Total@k0, 0.01]; i++; Fk = Delete[Fk, {1}]; AppendTo[Fk, k0]; ]; i ] ]
26568
Odd edge-case behavior of Block
In this example, `Block` is used to localize the variable cache as used in the function `g` when called from the function `f`. In `f`, the cache symbol to use is passed in as the second parameter `z`: f[a_, z_] := Block[{cache = z}, g[a]]; g[a_] := (Print["hash" -> Hash[cache]]; cache[1] = a; cache[1]); Everything works as expected: Hash[z] 2065959314 (your number may be different) Calling `f`: f[1, z] hash->2065959314 (same) 1 The symbol `z` now has a single downvalue: DownValues[z] {HoldPattern[z[1]] :> 1} However, what if I use the **actual symbol cache** as the cache symbol (say. by accident; not knowing that is the symbol name used inside `Block`): Hash[cache] 1028301578 (your number may be different) Calling `f`: f[1, cache] hash->1028301578 (same) 1 But nothing stored in the cache this time? DownValues[cache] {} My (partial) theory is that `Block[{cache = cache}, ...]` may have used a temporary variable `cache$xxx` after `cache=cache` collapses, but that doesn't explain why we still see the correct hash for the symbol inside `g`. This is an awkward, but OK situation **if** you know the name of the variable used inside `Block`, but could conceivably lead to some very puzzling bugs (as it did for me) if you chance upon the same symbol name.
30384
Strange behavior on very large numbers
I want to test the value of a differential equation by replacing a solution and setting random values for r and z variables: sol = ψ -> Function[{r, z}, Sinh[2 (r + z)^2] + Tan[4/3 + r] + 5 (-r + Tanh[1/r])]; de2 = 1/(4*r^2) - D[ψ[r, z], z]^2 + D[ψ[r, z], z, z] + D[ψ[r, z], r]/(2 r)+ D[ψ[r, z], r]^2 + D[ψ[r, z], r, r]; If I set for example: N[de2 /. sol /. r -> -9 /. z -> 4]==0 I get a false result. The value is a very large negative number (-3.16913*10^29). If I set: N[de2 /. sol /. r -> -90 /. z -> 4] I get 0.*10^12836 in red, and a message saying "No significant digits are available to display." If I compare this last command to zero: N[de2 /. sol /. r -> -90 /. z -> 4]==0 I get True! What's happening? How could I prevent this from occurring? Not using PZQ because it is too slow for the number of tests I want to do.
26567
How to Export the current graphic state of a dynamic module?
After manipulating the graphics in a dynamic module like this: Synchronizing manual rotations for multiple Graphics3D outputs? How do I get at the current graphic so that I can Export the image? The answer might be burried in here Using DynamicModule variables outside the DynamicModule someplace but i am unable to decipher it..
26565
How can I program the RiemannR function using the LogIntegral command?
I would like to program the `RiemannR` function using the `LogIntegral` command because I would like to later experiment with a double integral instead of the `LogIntegral` function. I have tried to program the `RiemannR` function starting with the `LogIntegral` command as defined in the Stein-Mazur paper called "Primes": ![RiemannR function as in Stein Mazur paper on primes](http://i.stack.imgur.com/uHKVF.png) That agrees almost completely with the definition given in the _Mathematica_ help page about the `RiemannR` command: $$R(x)=\sum_n^\infty \mu(n)\mathrm{li}(x^{1/n})/n$$ The only differences I see are that the summation limit $n=1$ is given in the Stein-Mazur paper while in the _Mathematica_ help page it is not. Also the Stein-Mazur paper uses $\mathrm{Li}$ for the logarithmic integral while the _Mathematica_ help page uses $\mathrm{li}$. However in the _Mathematica_ help page for the `LogIntegral` command the lower case $\mathrm{li}$ is used. My problem is that when I enter the following lines: N[RiemannR[1000]] N[Sum[MoebiusMu[n]*LogIntegral[1000^(1/n)]/n, {n, 1, Infinity}]] in _Mathematica_ , I get different numerical values: 168.359 168.341 What am I doing wrong?
15005
How to create InterpolatingFunction from data?
If I have a function at a number of non-uniformly spaced data points: youtReal[7.8]=2.0332;, youtReal[8.54]=6.24352354;.................. ......... and the imaginary parts: youtImag[7.8]=2.54345345; youtImag[8.54]=-5.2434;................. Is there an easy way to generate an InterpolatingFunction from this data consisting of complex values i.e. so I have yout[7.8]=2.0332+2.54345345I; and can also just get an interpolated value for say yout[8.12] and so on. To make this more concrete, the initial data is read in from a text file that looks like youtReal[39.983881559265192985] =0.003175121157662356963; youtImag[39.983881559265192985] =-0.025570345562818877981; youtReal[39.945803445544929806] =0.0030816430773355882379; youtImag[39.945803445544929806] =-0.025607948113924885628; youtReal[39.907725331824666628] =0.0029879382430246325535; youtImag[39.907725331824666628] =-0.025645261479980185081; youtReal[39.869647218104403449] =0.0028940073645911109315; youtImag[39.869647218104403449] =-0.025682284691974913792; youtReal[39.831569104384140271] =0.0027998511548903118804; youtImag[39.831569104384140271] =-0.025719016782491712295; youtReal[39.793490990663877092] =0.0027054703297639490629; youtImag[39.793490990663877092] =-0.025755456785713930289; youtReal[39.755412876943613914] =0.0026108656080328711776; youtImag[39.755412876943613914] =-0.025791603737433792661; youtReal[39.717334763223350736] =0.00251603771148972405; youtImag[39.717334763223350736] =-0.025827456675060525123; . . . and so on all the way down to around youtReal[~29]. So I read this in then have a function with quite arbitrarily defined value points, and lots and lots of them. I don't have a nice list of points I can just feed into `ListInterpolation` ab initio, I need to somehow generate this.
24709
Plotting array of vectors with conditions
Given data in the form list={{{1,2},{3,4},{5,6}},{{7,8},{9,10},{11,12}},...} a matrix where elements are 2-element vectors, what is a efficient way to plot this as a spatial grid? As I understand ArrayPlot[array,ColorFunction->(If[#>3,Red,White]&), ColorFunctionScaling->False] can only be "fed" with normal array (no 2-vector like above), if you want to use Colorfunction If condition. I want that a cell of the ArrayPlot mesh gets Red, when in {x,y} vector `1<x<2 AND y>3`, otherwise White. I know I could recreate the list into a {{1,0,1},{0,1,0},...} like normal array so ArrayPlot could read it, by using Table and Take, 1 and 0 representing the Red and White Case: If[1<First[Flatten[Take[list,i]]]<2,1,0] Then rebuild that list with Table and Join. But as far as I know MM, there has to be easier way, simply reading list and replacing a 2-vector with 1 or 0 1-vector under above conditions. Or do I really have to build the list completely new, problem is it has some million elements. Thanks for any tips to improve this
43478
How to visualize slope fields of differential equations without vectors?
I'm looking to visualize slope fields of differential equations for my differential equations course. Every example I see draws them as vectors, adding unnecessary "arrows" that, to me, are visually distracting. Is there a way to plot these slope fields without the "arrows" that get in the way?
24704
Is it possible to treat starting values as variables?
I have a problem where I am using FindRoot a gazillion times over a grid of parameters. I need to allow the starting values to vary a bit with the parameters to get it to converge. Here is a simple example in the spirit of my much bigger problem: f[a_] := x /. FindRoot[x^2 - 1 == a, {x, a - 1, a + 1}] NIntegrate[f[z], {z, 0, 5}] NIntegrate actually gives an answer (I think it's even right), but it also gives the following errors: > FindRoot::srect: Value -1.+z in search specification {x,z-1,z+1} is not a > number or array of numbers. >> > > ReplaceAll::reps: {FindRoot[x^2-1==z,{x,z-1,z+1}]} is neither a list of > replacement rules nor a valid dispatch table, and so cannot be used for > replacing. >> It looks like it doesn't like treating the starting values for x as variables. For some reason, the actual numbers between 0 and 5 in the integral are not being passed to the starting values in FindRoot. Any suggestions?
29236
Symbol created in unevaluated second argument of If
Apologies for the long question title, but I couldn't come up with something shorter to describe the following. Starting with a clean session, there are no symbols in, let's say, `myContext`: Names["myContext`*"] (* {} *) But if I now evaluated this If statement, If[False, myContext`mySymbol = "value"] all of the sudden `mySymbol` has been created in `myContext`: Names["myContext`*"] (* {"myContext`mySymbol"} *) but, as expected, `mySymbol` doesn't have a value: myContext`mySymbol (* myContext`mySymbol *) My question is twofold: why has `mySymbol` been created, and how can I prevent this from happening?
24706
Error invoking Information on functions containing Legended
In adapting some plotting functions to utilize the `PlotLegends` option of version 9, I came across the following errors: f[x_] := Legended[Plot[Sin[t], {t, 0, Pi}], x] f[1]; Information[f] > `TextForm[First::first: StandardForm[Short[Shallow[HoldForm[{}], {10, 50}], > 5]] has a length of zero and no first element. >>]` This is just a toy example for a more complex situation where I can't directly use the `PlotLegends` option but have to use `Legended` explicitly. What is the best way to catch this error when a user invokes the above or types `?f` to see the code for this function. It seems the output of `Definition` works as expected (it formats the `Legended` contents, and that happens for other constructs such as `Framed` too).
2038
How to execute kernel command from Front End?
Documentation for Yuri E. Kandrashkin's OptionsExplorer package says to add the following menu commands in MenuSetup.tr: Item["Options &Explorer", KernelExecute[ToExpression["OptionsExplorer[]"]], MenuKey["o", Modifiers->{Control,Command}], MenuEvaluator->Automatic] And I want to accomplish the same thing by a corresponding `FrontEnd`AddMenuCommands...` expression in an `Autoload`PacletManager`Configuration`FrontEnd`init.m`. But I don't find any `KernelExecute` function. How to do it?
46135
Formatting All Appropriate Output as Desired Automatically
I want to output in `MatrixForm` whenever I have a list/vector/matrix, but I do not want to have to type out the command each time. How can I write one command at the beginning of the notebook so that all output is so formatted? (Also: generalization to any formatting would be better, with additional specific detail included for this case.)
24702
solving a cubic equation
I need to find the minimum $r$ and the maximum $k$ of the following cubic equation for which there does not exist three distinct real roots. $rx^3-rkx^2+(r+k)x-rk=0$. Is it possible to find such $r$ and $k$ analytically? Or if you can provide me help using mathematica, that would be fine too.Thanks.
6533
Accessing the Options of the parent Cell
From within the Kernel, it is possible to access a `Cell`'s options using `CurrentValue`. For instance, in a `Cell` tagged `{"Bob", "Frank"}`, executing this CurrentValue[CellTags] (* {"Bob", "Frank"} *) But, how would one go about accessing the options of the parent cell in the hierarchy? One difficulty is that the `Cell` knows nothing about the `CellGroup` it finds itself in, so attacking the problem from that direction seems difficult. However, the current executing `Notebook` can be accessed via `EvaluationNotebook`, so traversing the tree from that direction seems plausible, if not efficient.
15001
generating pdf using UseFrontEnd
I run mathematica on a remote server and run it in batch mode using /math -noprompt -script 'scriptname.m' & Now, I use ssh -X to connect to the server. The server is linux based and my computer is a mac. I use x11 forwarding. I would like to generate PDFs in the above mentioned 'script.m'. In my code, how should I incorporate UseFrontEnd? should I invoke it first using ConnectToFrontEnd[] ? Should I use UseFrontEnd[Export["blah.pdf",fig]] or is it a one time thing? Also, when using the UseFrontEnd command, is it required that I do ssh -X/Y or is it sufficient if I do ssh? I greatly appreciate your help. Thanks. P.S - I am using mathematica 8
8296
Plotting a path in a vector field
I am trying to make a visual representation of the curve $y=x^{2}$, with $x\in\left[0,1\right]$ in the vector field defined by $\vec{F}=\left[-y,x\right]$. However, as far as I can tell there does not seem to be any facility which allows me to do this in Mathematica (I've looked through as much of the documentation as I could find which seemed pertinent). I know how to do each of these separately, e.g. Plot[x^2,{x,0,1}] VectorPlot[{-y,x},{x,-3,3},{y,-3,3}] However, I am unsure how I can combine these two plots (or plot them both at the same time). Thanks in advance!
43440
Choose partition of a set with Manipulate
Suppose I have a set represented by an array of strings, like > set = { "A", "B", "C", "D", "E", "F" } I would like to create a Manipulate which allows the user to build repartitions of the set. To be clear, I'd like the user to be able to build, for instance, the following repartitions: repa1 = { {"A", "B", "C"}, {"D", "E", "F"} } and repa2 = { { "A" }, { "B", "C" }, { "D", "E", "F" } } $$ $$ Is this possible? * * * Even better, I would like to be able to use labels for the manipulate command. I mean, let's say the set is > set = { {"A", 26}, {"B", 33}, {"C", 69}, {"D", 2}, {"E", 16} } then the selector should look like part1 : [ A, B, C, D, E ] part2 : [ A, B, C, D, E ] part3 : [ A, B, C, D, E ] and, supposing I choose the following combination, part1 : [ **A** , B, **C** , D, E ] part2 : [ A, **B** , C, **D** , E ] part3 : [ A, B, C, D, **E** ] the result should be > repa = { { {"A", 26}, {"C", 69} }, {{"B", 33}, {"D", 2}}, {{"E", 16}} }
57781
V10 interface problems
Has anyone noticed the following? 1. Sometimes when I bring up the Help->Wolfram Documentation there is no text field to type into. 2. When I bring up Find and Replace there are two text fields for Find: and Replace with: but no other controls or buttons (No buttons Find Next, Find Previous, Replace etc). In this case on my system - win7-64 - the dialog box is unnaturally tall (whole height of screen). 3. Syntax highlighting seems somewhat erratic - defined symbols stay the wrong color for a while. Symbols that are part of a function signature, say f[x_]:=... stay the wrong color for a while as well. Restarting Mathematica restores these.
32062
How to suppress automatically generated header in packages?
At the top of the `.m` file which is automatically generated from initialization cells in a notebook there appears a header: (************************************************************************) (* This file was generated automatically by the Mathematica front end. *) (* It contains Initialization cells from a Notebook file, which *) ... Is there any way to suppress generating this header?
392
Why is Neptune missing from AstronomicalData?
An old notebook I've recently started working with has a strange error: Prior to version 8, a figure I generated using `Drop[AstronomicalData["Planet"],-1]` to display all of the currently recognized planets, along with some other data, worked fine, but in version 8, Neptune is missing. Is this a bug in 8, or am I missing something?
32564
Plotting a matrix in 3D With specific ticks
I have matrix and I want to plot it in 3D ListPlot3D[{{3.98765, 3.9805722621093267`, 3.6669734993637384`, 3.547140513657327`}, {4.00978, 6.841217936322747`, 3.664440739410208`, 5.55098}, {4.094896872960633`, 4.36315, 6.327539411775844`, 3.962204146812651`}, {3.983216682983883`, 6.26917, 4.7494476017929514`, 16.1384}, {4.04999, 4.79856, 3.659365327920453`, 4.156261830970234`}, {4.059789950180353`, 4.014186008147935`, 4.722610902483124`, 5.748447432928523`}, {4.2315454107761665`, 3.76239, 3.94495, 3.9403001696511617`}, {4.06719, 5.18322, 4.0810431833309`, 3.83299}, {4.01151, 3.9015086486265798`, 20.185861947480277`, 5.08127}}, MeshStyle -> Opacity[0.4], InterpolationOrder -> 3, ColorFunction -> "SouthwestColors"] the result is as below where mathematica assumes the ticks to be natural numbers starting from one while they should be different. {1,2,3,4} should be {2,3,4,5} and {1,2,3...,8} should be {1.1,...,1.8} any suggestions? ![enter image description here](http://i.stack.imgur.com/T5F6f.jpg)
397
Correct way to handle mysterious NaN` result from MathLink function
I have a Mathematica expression that is mapped onto an external `C` function via `MathLink`. The external function passes a `double` array (using `MLPutReal64List[]`), which Mathematica interprets as a list of `Real`'s. Sometimes the external function sends values for which the `C` math library function `isnan(value)` returns `1` (say from division by zero, or `log(0)`). Mathematica reads these values as `NaN``. For example, In[1]:= result = externalFunction[<some input>] Out[1]= {NaN`, 0.18225} Evaluating {NaN`, 0.182255} gives a syntax error: In[2]:= {NaN`, 0.182255} Syntax::tsntxi: "{NaN`,0.182255}" is incomplete; more input is needed. Syntax::sntxi: Incomplete expression; more input is needed. which makes sense, since a variable name is expected to follow the ```, giving some variable in the `NaN` context. But mathematica accepts `result[[1]]` as a number: In[3]:= NumericQ[result[[1]]] Out[3]= True In[4]:= NumberQ[result[[1]]] Out[4]:= True !! Yet I haven't been able to find a pattern that matches `NaN`` and not all other numbers (for use in `Position`, `Cases`, etc.). So what are ways of a) passing NaN's from c into Mathematica so that Mathematica interprets them as `Indeterminate`, or b) handling these `NaN`s inside mathematica (with a pattern match to replace them with `Indeterminate`, for example). Is it possible to construct the first element of `result` using keyboard input? Note that `InputForm[result[[1]]]` gives `NaN`, and `NumericQ[InputForm[result[[1]]]]` gives `False`.
22014
How to simplify expressions containing derivatives
Is there a way to reverse the application of derivative rules in order to simplify expressions including derivatives? e.g. in Mathematica code: Want to go from (g[x, y]*Derivative[1, 0][f][x, y])/h[x, y] + (f[x, y]*Derivative[1, 0][g][x, y])/h[x, y] - (f[x, y]*g[x, y]*Derivative[1, 0][h][x, y])/h[x, y]^2 to D[f[x, y]*g[x, y]/h[x, y], x]
45036
Transformation of a simple logic statement
I'm designing a logic circuit and I was wondering if the following two things are equivalent: (x <= y) and (x < (y + 1)) I can't think of any set of numbers that would make these two things not equivalent. Only real integers are allowed. Thank you.
2309
Problem with NonlinearModelFit
I'm having trouble with a non-linear fit: `fit = NonlinearModelFit[data, y0 + A Sin[\[Pi] (x - xc)/w], {y0, xc, A, w}, x]` where `data` has about 15 thousand points and looks like this: ![data](http://i.stack.imgur.com/QOe5a.png) **The data can be downloadedhere.** Mathematica gives the following adjusted parameters: `{y0 -> 30.4428, xc -> 1.54318, A -> -0.000528519, w -> 0.999975}` However, this is a terrible fit: ![enter image description here](http://i.stack.imgur.com/Xvok3.png) I wouldn't complain, except that there is an obviously better fit: ![enter image description here](http://i.stack.imgur.com/Cnu4l.png) with the parameters: `{y0 -> 30.45775, w -> 752.71185, A -> 3.62443, xc -> 872.72035}` This best fit is returned by Origin without effort. What can I do to achieve the same with Mathematica? (I like Mathematica!)
43463
Make duplicate string then join two strings together in a table
I have two lists of `data`, `dataA` and `dataB`. dataA = {100169} dataB = {0001,Olivine,Process},{0002,Olivine,Process},{0003,Olivine,Process} I don't know how to write a function that would give me a data table that looks like this. {100169,0001,Olivine,Process} {100169,0002,Olivine,Process} {100169,0003,Olivine,Process}
43460
How to find the complex number has least and greatest modul satisfying a given condition?
Let be given the complex number $z$ satisfying the condition $|z-2+2i|=2\sqrt{2}$. I want to find the complex numbers $z$ so that their modul obtain least and greatest value. I tried. Put $z = x + y i$. From $|z-2+2i|=2\sqrt{2}$, we have $$|(x-2) + (y+2)i|=2\sqrt{2}.$$ Therefore, $$(x-2)^2 + (y+2)^2=8.$$ And then, I used Maximize[{x^2 + y^2, (x - 2)^2 + (y + 2)^2 == 8}, {x, y}] > {32, {x -> 4, y -> -4}} and Minimize[{x^2 + y^2, (x - 2)^2 + (y + 2)^2 == 8}, {x, y}] > {0, {x -> 0, y -> 0}} I dont know why I can not use the command Abs[(x - 2) + (y + 2) I] to find the modul of `(x - 2) + (y + 2) I` and how to tell _Mathematica_ to get the result $$(x-2)^2 + (y+2)^2=8$$ when I have $$|(x-2) + (y+2)i|=2\sqrt{2}.$$
27724
SDE boundary condition
I have a simple SDE with white noise: mysde[q_, I_, n0_, sd_] := ItoProcess[ \[DifferentialD]n[t] == ( I - q n[t]) \[DifferentialD]t + sd \[DifferentialD]w[t], n[t], {n, n0}, t, w \[Distributed] WienerProcess[]] I want to impose a condition that n[t] cannot fall below zero. At below zero, or an arbitrarily low value of n[t], it is considered zero. I am not sure how to implement this in the ItoProcess function and/or in the numerical solution: sol[q_, I_, n0_, sd_] := RandomFunction[mysde[q, I, n0, sd], {0, 100, 0.1}, 1] The variable drops below zero many times, which is not a desired behaviour: With[{q = 2, I = 0.1, n0 = 1, sd = 0.1}, Show[ListLinePlot[sol[q, I, n0, sd]], ImageSize -> 400]] What are some ways to implement such a condition? I have tried various functions on `n[t]` within the `ItoProcess[]`, to attempt to re-set negative values of `n[t]` to zero, like `If[]`, `Max[]`, `Clip[]`, and `Piecewise[]` to no avail. Any reasons why these functions do not dynamically work within the solver? Also is there a way to extract the values of the noise, `w[t]`, in a particular simulated path of the temporal data timeseries object? One potential solution, which is not confirmed to be correct, is to write the equation for the log of my variable, `ln[t]` and to use the Geometric Brownian motion random process formulation, obtaining: logsde[q_, I_, ln0_, sd_] := ItoProcess[ \[DifferentialD]ln[t] == ( I - q ln[t] - sd^2/2) \[DifferentialD]t + sd \[DifferentialD]w[t], ln[t], {ln, ln0}, t, w \[Distributed] GeometricBrownianMotionProcess[I - q ln[t], sd, n0]] logsol[q_, I_, ln0_, sd_] := RandomFunction[logsde[q, I, ln0, sd], {0, 100, 0.1}, 1] Then I extract the simulated values, and exponentiate them to obtain the time series or path in the original scale: td = With[{q = 0.1, I1 = 0.1, ln0 = 1, sd = .1}, logsol[q, I1, ln0, sd]]; ListLinePlot[Exp[td["States"]]] However I have lost the stochastic signal in this model; the simulation smooths out and looks continuous with no noise, except at the beginning of the simulation. This is obviously an incorrect formulation. What did I do here? How might I formulate this properly? Are there other approaches? So overall I have three questions: 1. How to implement a boundary condition in `ItoProcess[]` for one of the state variables? 2. How to recover the simulated values of the random variable? <\- self-answered below 3. How to properly specify a log-transformed version of the `ItoProcess[]`?
23931
How can I solve precision problem
I want to set 2 decimal places, whether it's real Number or anything.for that purpose I wrote the following function. decimalPlaces[number_]:=SetPrecision[number, 3] case 1: If you pass `3`as a argument,it should returns `3.00`. case 2: if you pass `3.98967465684` as a argument,it should returns `3.98`. case 3: if you pass `394` as a argument,it should returns `394.00`.But it returns `394`. case 4: if you pass `394.985674` as a argument,it should returns `394.98`.But it returns `394`. finally,my function was not satisfying the case 3,4 testcases How can I solve this. Fell free,If you want to edit my question. Thank you.
24208
How do I get Mathematica to show a number in non-exponential form?
Sometimes I make a calculation in Mathematica that produces a big number, which Mathematica shows like so: -1.52522*10^7 This is annoying to me, because I want to see the number normally, without exponential notation, something like this: -15,252,264.7448716 How can I make Mathematica show the number normally?
16149
How do you force a decimal output?
I have some very small values such as 2.601519253*10^-8. I'd like to output these values to CSV for another program to work with. I've tried N[value, 50], but Mathematica still insists on producing scientific notation (which my program can't read). How can I force Mathematica to output values in decimal form? EDIT: AccountingForm seems to be the answer to my question. AccountingForm[2.601519253458693*10^-8, 30] gives a nice decimal format I can use. –
10664
Representation of negative exponents
> **Possible Duplicate:** > Way to improve "show me this decimal number to M places, don't use > scientific notation"? How can I expand e.g. number 1.*10^-8 so that there would be no exponents? It should look like 0.00000001.
771
Way to improve "show me this decimal number to M places, don't use scientific notation"?
The best way I can come up with to say "show me this fraction as a decimal number to M places, don't use scientific notation" is: NumberForm[N[1/998001,2994],ExponentFunction->(Null&)] It seems like that's an awful lot of typing for a very simple request. Is it possible say it more concisely?
4728
Incorrect results for elementary integrals when using Integrate
There is a rather simple integral ($K_0$ is the 0-th order MacDonald function) $$\int_0^\infty e^{-x \cosh\xi}\, d\xi = K_0(x)$$ which mathematica cannot solve. This even though the documentation claims that Integrate can give results in terms of many special functions. In fact it can solve the integral obtained by substituting $r=\cosh \xi$, $$\int_1^\infty \frac{e^{-x r}}{\sqrt{r^2-1}}\,dr=K_0(x).$$ In fact it also failed in solving the more general integral $$\int_0^\infty e^{-x \cosh\xi} \cosh(\alpha \xi)\, d\xi = K_\alpha(x).$$ I am using "8.0 for Mac OS X x86 (64-bit) (October 5, 2011)". Are there more recent or older versions of Mathematica which can solve this class of integrals? * * * **Edit:** I want to stress that this is not an arbitrary integral but can be thought of as a definition of $K_0$ (the corresponding integral $\int_0^{2\pi} \\!e^{i x \cos \xi}\,d\xi$ for $J_0$ mathematica handles very well). I am just curious how it can happen that a system as developed as Mathematica cannot handle this "elementary" integral. Here is the Mathematica code for those who want to test: Integrate[Exp[-x Cosh[ξ]],{ξ,0,Infinity}] Now I found a related integral which indeed is a bug in mathematica. If you try to evaluate ($x \in \mathbb{R}$) $$\int_0^\infty \cos(x \sinh \xi)\,d\xi = K_0(|x|)$$ then Mathematica claims that the integral diverges.
13614
Is Abs[z]^2 a bad way to calculate the square modulus of z?
For a numerical quantity `z`, `Abs[z]` returns the square root of the sum of the squares of the real and imaginary parts of `z`. If we then square it, do we lose numerical accuracy because we are squaring after taking a square root? Is it better to use `Re[z]^2+Im[z]^2`?
2300
Why does ++++x return an increment of 2 when the value of x is only incremented by 1?
This line returns `3`: x = 1; ++++x ![enter image description here](http://i.stack.imgur.com/80WEy.png) However, the value of `x` after the increment is only 2. Similarly, this line returns `5`, while the value of `x` is again only 2. x = 1; ++++++++x ![enter image description here](http://i.stack.imgur.com/rTYeU.png) Why does it return `3` and `5` respectively in the above examples? * * * (This question is intended as a puzzle, and to encourage people to think through an opaque evaluation chain.)
28558
Applying Some Kind of Timing Function to AutoRunSequence
Ok, so I'm exporting a video to MOV format that is coming from a manipulate function (I'm demonstrating CLT to a class that doesn't have calculus as a pre-req, if anyone is curious). Anyhow, I'm mostly happy with it, but ideally I'd like it to not generate the frames of the video linearly, but rather spend more frames on the front section and decrease as it approaches the max boundary. Is this possible? This is the current code: manr = Manipulate[ Resample = Table[Mean[RandomChoice[SetAll, Length[SetAll]]], {Samples}]; Histogram[Resample, Axes -> {False, False}, ImageSize -> Large], {Samples, 100, 100000}, AutorunSequencing -> {Automatic, 30}]; Export["~/desktop/sam.mov", manr]
52051
How to make the animation rate lower in an exported GIF
I have a ".gif" figure exported from the following codes. 6 separated figures (frames) constitute a ".gif" figure. But the default time interval between each frame is less than 1 second. I hope to increase the time interval to 3 seconds, so the speed can be lower. Any one can help me? Thank you all in advance! g1[a_, b_] := Graphics[{Red, Disk[{a, 0}, 1], Green, Disk[{1, 1}, 1], Blue, Disk[{b, 2}, 1]}]; f1 = Table[Show[g1[a, b] , PlotRange -> {{-2, 12}, {-2, 4}} ], {a, 1, 8, 4}, {b, 0, 10, 5}]; f1 = Flatten[f1] Export["f1.gif", f1] ![enter image description here](http://i.stack.imgur.com/Bf8JZ.jpg) ![enter image description here](http://i.stack.imgur.com/Qdinm.gif)
17587
Making a movie with specific frame-rate out of ListPlot outputs?
> **Possible Duplicate:** > Is it possible to prerender animation in Wolfram Mathematica? > Does Mathematica support variable frame rate for any video format, in > analogue of GIF-style “DisplayDurations”? I would like to make a movie that shows a series of `Plot`/`ListPlot` outputs as frames for `s` seconds of time each. Is there a simple way to do this?
58369
Exporting as GIF
I want to export a simple animation as GIF. I had a look at here but could not understand what was being described. Any help would be appreciated. For instance, how do I export the following animation as an GIF. u[x_, t_] = -(1/2) Cos[x - t]^2 + 1; Animate[Plot[u[x, t],{x, -10, 10},PlotRange->{0, 1.5},PlotStyle->{Red, Thickness[0.005]}],{t, 0, 10, 0.02}] Thanks, Radz.
1428
Is it possible to prerender animation in Wolfram Mathematica?
I have a `DensityPlot` which is evaluated for a long time. I wish to use it with animation, but it is absolutely inapropriate. Is it possible to render animation first and then run it smoothly?
27202
How to Export this animation as a gif file for powerpoint presentation
Animate[ Manipulate[ ParametricPlot[ Evaluate[{x[t], v[t]} /. Quiet@NDSolve[ {x'[t] == v[t], v'[t] == μ (1 - x[t]^2) v[t] - x[t] + A*Cos[ω*t], x[0] == xv0[[1]], v[0] == xv0[[2]]}, {x[t], v[t]}, {t, 0, tt}]], {t, 0, tt}, ImageSize -> {450, 450}, PlotRange -> 4, AxesLabel -> {TraditionalForm[x[t]], TraditionalForm[v[t]]}, PlotStyle -> PointSize[.5]], {{μ, 0.75, "parameter μ"}, 0, 3, 0.01, Appearance -> "Labeled"}, {{ω, 0.75, "parameter ω"}, 0, 3, 0.01, Appearance -> "Labeled"}, {{A, 0.75, "parameter A"}, 0, 3, 0.01, Appearance -> "Labeled"}, {{xv0, {1, 1}}, {-4, -4}, {4, 4}, Locator}], {tt, 0, 200}, AnimationRate -> 3, AnimationRepetitions -> 3, AnimationRunning -> True]
46915
Creating a .gif file from a complex Manipulate function
I am trying to create a .gif file from the following manipulate functions (sorry for the poor formatting but I couldn't figure how to do it better) : manipulateGraph = Manipulate[ parametersManipulate = {dK -> dKValue, d -> dValue, y -> yValue, dI -> dIValue, p -> pValue, a -> aValue, κ -> κValue, kp -> kpValue, dR -> dRValue, kon -> konValue, koff -> koffValue}; (* Define parameters such that they can be manipulated. *) solutionManipulate = NDSolve[{Kk'[t] == -dKValue*Kk[t], Nn'[t] == dValue*(1 - Nn[t]) + yValue*dIValue*(1 - Nn[t]) + pValue*Kk[t]*(1 - Nn[t]) - aValue*Nn[t]*Ii[t], Ii'[t] == dValue*(1 - Nn[t]) - κValue*pValue*Kk[t]*Ii[t] - aValue*Nn[t]*Ii[t] + kpValue*Rr[t] - dIValue*Ii[t], Rr'[t] == dRValue*(Gg[t] - Rr[t]), Gg'[t] == konValue*Nn[t]*(1 - Gg[t]) - koffValue*Ii[t]*Gg[t], Kk[0] == 1, Nn[0] == 0.0204896, Ii[0] == 0.728553, Rr[0] == 0.0138668, Gg[0] == 0.0138668} /. parametersManipulate, {Kk[t], Nn[t], Ii[t], Rr[t], Gg[t]}, {t, 0, 50}, MaxSteps -> Infinity]; (* Substitute the parameters in the NDSolve function such that they can be manipulated. *) Plot[Evaluate[{Kk[t], Nn[t], Ii[t], Rr[t], Gg[t]} /. solutionManipulate], {t, 0, 50}, AxesLabel -> {"Time (Hours)", "Non-Dimensionalized Amount Present in Cell"}, PlotRange -> All, PlotLegends -> LineLegend[{"K", "N", "I", "R", "G"}], PlotStyle -> {Magenta, Green, Red, Cyan, Blue}, PlotLabel -> Style["Manipulate Graph", "Subsection"], LabelStyle -> Medium, ImageSize -> 750], (* Plot the solution. *) {{dKValue, 0.15, "Rate of IKKa inactivation following an initial stimulus - dK"}, 0.015, 1.5}, {{dValue, 3, "Rate of IκBα - NF-kB complex degradation - d"}, 0.3, 30}, {{yValue, 0.2, "Rate factor by which the IκBα in the IκB\ α - NF-kB complex can spontaneously degrade - y"}, 0.2*(10^(-0.25)), 0.2*(10^0.25)}, {{dIValue, 0.24, "Rate of IκBα spontaneous degradation - dI"}, 0.24*(10^(-0.25)), 0.24*(10^(0.25))}, {{pValue, 9, "Rate of IκBα - NF-kB complex degradation induced by IKKa - p"}, 9*(10^(-0.5)), 9*(10^(0.5))}, {{aValue, 200, "Rate of IκBα - NF-kB complex formation - a"}, 20, 2000}, {{κValue, 0.2, "Rate factor by which free IκBα can be degraded by IKKa - κ"}, 0.2*(10^(-0.25)), 0.2*(10^(0.25))}, {{kpValue, 16, "Rate of IκBα mRNA translation - kp"}, 16*(10^(-0.5)), 16*(10^(0.5))}, {{dRValue, 2.7, "Rate of IκBα mRNA degradation - dR"}, 2.7*(10^(-0.25)), 2.7*(10^(0.25))}, {{konValue, 7.5, "Rate of gene expression activation by NF-kB - kon"}, 7.5*(10^(-0.5)), 7.5*(10^(0.5))}, {{koffValue, 15, "Rate of gene expression inactivation by IκBα detaching NF-kB from the promoter - koff"}, 15*(10^(-0.5)), 15*(10^(0.5))}] (* Define the initial values of each variable their name and their range of values. *) I have tried using the `ManToGif` function (http://community.wolfram.com/groups/-/m/t/86994) but my computer with 12gb of ram runs out of memory before finishing. Any help? I absolutely need the result to be a .gif animated picture. I've tried many methods and none seem to be working...
13617
Creating a matrix from the output of a variable inside a for loop
I would like to enter the results of the following loop inside a matrix as its elements: p=1; q=4; For[i = 0, i < p, i++, For[j = 1, j < q + 1, j++, For[h = 0, h < p, h++, For[k = 1 , k < q + 1, k++, Subscript[wtotal, m, i, j, h, k] = Subscript[w, m, i, j, h, k ] + Subscript[w1, m, i, j, h, k] ; Print[Subscript[wtotal, m, i, j, h, k]]]] ] ]; This matrix gives 16 values, so I would like to enter those 16 values inside a 4X4 matrix. So how should I do it... Further how should i convert the 4x4x4x4 table into a 16x16 matrix so that i can take its inverse.?
6572
Is it possible to substitute tick labels with alternative text?
> **Possible Duplicate:** > Labelling ArrayPlot Charts I am making a `MatrixPlot`. For example, consider the following: list = {{1, 1, 0, 1}, {0, 0, 1, 1}, {1, 0, 1, 0}}; MatrixPlot[list] which yields: ![MatrixPlot](http://i.stack.imgur.com/QXRcu.gif) But now suppose I want to label the axes with other numbers. For example, I would like to label the ticks on the horizontal axis as 101, 167, 188, 205 (as they are not now), and the ticks on the vertical axis as 1, 2, 3 (as they already are). I know this is a strange request, but it is because I would like to label the horizontal axis according to "particle number" (which is an integer in my application). Or maybe a better way to phrase the question is, is it possible to label axis/frame ticks with _any_ arbitrary string (for example, labeling the horizontal axis with `"Alice"`, `"Bob"`, `"Carla"`, and `"David"`)? One possibility seems like `FrameTicks`, but I can't seem to figure out if it can be used to map strings. If I use list = {{1, 1, 0, 1}, {0, 0, 1, 1}, {1, 0, 1, 0}}; MatrixPlot[list, FrameTicks -> {{{1, 2, 3}, None}, {{101, 167, 188, 205}, None}}] I get: ![MatrixPlot](http://i.stack.imgur.com/EGt5n.gif) because, of course, `FrameTicks` thinks I'm referring to which discrete values to label. Also, if I try: list = {{1, 1, 0, 1}, {0, 0, 1, 1}, {1, 0, 1, 0}}; MatrixPlot[list, FrameTicks -> {{{1, 2, 3}, None}, {{"101", "167", "188", "205"}, None}}] I get "Not a valid tick specification." Do you have any other ideas?
32901
Custom FrameTicks not working
I would like to have a custom ticks on x-axis on my `ListPlot`, but nothing is showing, what am I doing wrong? data = {{1, 2}, {2, -2}, {3, -1}, {4, 0}, {5, -3}, {6, -2}, {7, -1}, {8, -1}, {9, -1}, {10, 0}}; ListPlot[data, FrameTicks -> {{"ττ", "τr", "τθ", "\τφ", "rr", "rθ", "rφ", "θθ", "θφ", "φφ"}, {-5, 5}}, Frame -> True, PlotMarkers -> {Automatic, Medium}, Axes -> False,ImageSize -> 500] And I get ![enter image description here](http://i.stack.imgur.com/czANt.jpg)
13612
Debugging graphics
All the examples I am seeing on internet are related to normal functions that carry out loops and assignments but I have not seen one example where I can see a graphics based program being debugged. can someone who has used debugging extensively shed some light on this please? Edit: I meant to say that like in `Manipulate`, I can see the graphics dynamically, in the same way suppose I have completed a loop once than can I see the update in graphics successively or I will have to wait for the final values to arrive. In a way can I debug programs that include `Graphics` or `Graphics3d` in them? And thanks for such warm welcome. :) Example: fun[x_]:= Graphics[... parameters] So, can I step into this `Graphics` inbuilt function?
5847
How to define a non-standard algebra in Mathematica?
I want to define an algebra, where there are three elements: 0, 1 and $\infty$ and two operations, addition and multiplication defined, both commutative: $$\begin{align*} 0+0&=0\\\ 0+1&=1\\\ 0+\infty&=\infty\\\ 1+1&=1\\\ 1+\infty&=\infty\\\ \infty+\infty&=\infty\\\ 0\times0&=0\\\ 1\times0&=0\\\ 1\times1&=1\\\ 0\times\infty&=1\\\ 1\times\infty&=\infty\\\ \infty\times\infty&=\infty \end{align*}$$ I want Mathematica to simplify expressions in this system.
5846
Resources for beautiful Mathematica Stylesheets
When the Wolfram Demonstrations were introduced and the Documentation-Center was redesigned, I remember it was the first time I thought someone had put some effort into creating a beautiful stylesheet. I don't like most of the other styles and in fact, I think _PrimaryColor_ is so ugly that I cannot believe it is included in the standard templates. On the other hand, I have seen some quite nice things when I spoke on a _Mathematica_ -day and we used a common stylesheet for the slides. That's why I wonder whether there are other styles out there which are worth sharing. **Question:** Does someone know resources where people shared their stylesheets? I'm especially interested in things one can use for talks.
16067
How to see a long output expression
I often run into long expressions in the process of solving equations. To go forward I need to be able to eye-ball the expressions to make some substitutions or use some existing relations I know to cancel stuff out etc to reduce the expression to as small as possible so I can prove certain properties about the expressions, such as positivity, monotonicity etc. However, many times I am not able to do much because I can't even see the expression properly. Is there a way to present the expression in some rational fraction or something that would make it easy to see.. So something like this: $ \frac{F(x,y,z)}{G(x,y,z)+H(x,y,z)}+\frac{F_2(x,y,z)+G_2(x,y,z)}{G_3(x,y,z)+H_4(x,y,z)}+...\\\ $ instead of something that just spills across lines so it's hard to track what the thing looks like: $ (( x + ((f(x) +g(y)/(......\\\ ..... ))))+ ...\\\ ....\\\ (((((....\\\ ...))$ Below is an actual expression that I have: x->-(-((2 H0D^p (-1+p) p)/(-2 delta p+2 p r-2 rho+(-1+p) p sigma^2))+(H0D^((2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) H0S^(-((2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2))) (2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]) (-1+(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) ((F (c0-rho) (2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]))/(2 rho σ^2)-(2 H0S^p (p-(2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))/(-2 (delta p-p r+rho)+(-1+p) p sigma^2)-(H0S (r-rho) (-1+(2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))/(delta-r+rho)))/(2 σ^2 ((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)-(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))+(H0D^((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) H0S^(-((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2))) (2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]) (-1+(2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) ((F (c0-rho) (2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]))/(2 rho σ^2)-(2 H0S^p (p-(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))/(-2 (delta p-p r+rho)+(-1+p) p sigma^2)-(H0S (r-rho) (-1+(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))/(delta-r+rho)))/(2 σ^2 (-((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2))+(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2))))/(H0D^2 ((H0S^(-1-(2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)-(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) (H0D^((2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) H0S^((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2))-H0D^((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) H0S^((2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2))) ((F (-c0+rho) (2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]) (2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]))/(4 rho σ^4)-(2 H0S^p (p-(2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) (p-(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))/(-2 (delta p-p r+rho)+(-1+p) p sigma^2)+(H0S (r-rho) (-1+(2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) (-1+(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))/(delta-r+rho)) (-((2 H0D^p (-1+p) p)/(-2 delta p+2 p r-2 rho+(-1+p) p sigma^2))+(H0D^((2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) H0S^(-((2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2))) (2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]) (-1+(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) ((F (c0-rho) (2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]))/(2 rho σ^2)-(2 H0S^p (p-(2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))/(-2 (delta p-p r+rho)+(-1+p) p sigma^2)-(H0S (r-rho) (-1+(2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))/(delta-r+rho)))/(2 σ^2 ((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)-(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))+(H0D^((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) H0S^(-((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2))) (2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]) (-1+(2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) ((F (c0-rho) (2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]))/(2 rho σ^2)-(2 H0S^p (p-(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))/(-2 (delta p-p r+rho)+(-1+p) p sigma^2)-(H0S (r-rho) (-1+(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))/(delta-r+rho)))/(2 σ^2 (-((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2))+(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))))/(H0D^2 ((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)-(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))-(H0S^(-1-(2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)-(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) ((H0D^((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) H0S^((2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) (2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]))/(2 σ^2)-(H0D^((2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) H0S^((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) (2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]))/(2 σ^2)) (delta/(delta-r+rho)-(2 H0D^(-1+p) p)/(-2 delta p+2 p r-2 rho+(-1+p) p sigma^2)+(H0D^(-1+(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) H0S^(-((2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2))) (2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]) ((F (c0-rho) (2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]))/(2 rho σ^2)-(2 H0S^p (p-(2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))/(-2 (delta p-p r+rho)+(-1+p) p sigma^2)-(H0S (r-rho) (-1+(2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))/(delta-r+rho)))/(2 σ^2 ((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)-(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))+(H0D^(-1+(2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) H0S^(-((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2))) (2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]) ((F (c0-rho) (2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]))/(2 rho σ^2)-(2 H0S^p (p-(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))/(-2 (delta p-p r+rho)+(-1+p) p sigma^2)-(H0S (r-rho) (-1+(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))/(delta-r+rho)))/(2 σ^2 (-((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2))+(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))) (-((2 H0S^p (p-(2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) (p-(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))/(-2 delta p+2 p r-2 rho+(-1+p) p sigma^2))+1/(rho (delta-r+rho))(-((c0 F (delta-r+rho) (2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]) (2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]))/(4 σ^4))+rho ((delta F (2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]) (2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]))/(4 σ^4)+(r-rho) (-((F (2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]) (2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2]))/(4 σ^4))+H0S (-1+(2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)) (-1+(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2)))))))/(H0D (-((2 delta-2 r+σ^2-Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2))+(2 delta-2 r+σ^2+Sqrt[8 rho σ^2+(-2 delta+2 r-σ^2)^2])/(2 σ^2))))) I tried to copy as Latex and compile it but Latex is giving me something that goes off the page. I guess I can break it into many lines at random places and see what that gives me. I was wondering if there is some automatic way of accomplishing this.
19700
Simplify assumes Boolean 1 and 0 in logical expressions
Per this chat discussion and this previous question where I encountered the strange behaviour: Simplify[1] ==> 1 And[0, 1] ==> 0 && 1 Simplify[And[2, 3]] ==> 2 && 3 Simplify[Not[0]] ==> !0 FullSimplify[Not[0]] ==> True (* expected !0, thanks Jens *) Simplify[And[0, 1]] ==> False (* expected 0 && 1 *) Simplify[And[1, 2]] ==> 2 (* expected 1 && 2 *) Simplify[Or[0, 1]] ==> True (* expected 0 || 1 *) `Simplify` and `Fullsimplify` assume `0 -> False, 1 -> True` in some logical expressions. Only `Or` and `And` are affected but not `Not`. This is certainly undocumented (or underdocumented), and I would say rather inconsistent. Please decide on whether it is a bug or not. Present in versions 8 and 9 but not in version 7 (or before).
19701
Method that can be used to collect the variables of a function
Suppose we have a function `f[x, y, z]` and we want to get all its variables `Sequence[x,y,z]`, what method can we use then? The only one that I can come up with is like this: f[x, y, z] /. func_[vars___] -> Sequence[vars] But it is not very elegant from my point of view. Is there any more suitable method? Thanks!
16063
Non Commutative sorting in Mathematica
I have been trying to do some oscillator algebra in _Mathematica_ and having troubles with sorting and simplifying expressions. I am using the NCAlgebra package which helps to improve the properties of `NonCommutativeMultiply` in _Mathematica_. However I have to create a huge list of rules to replace terms using the algebra. This quickly becomes impractical since I get these enormous expressions and I have to sift through the terms to see what simplifies and add more rules. I have been wondering if there is a way to write a sorting function that would take an elementary expression and change it to a list and then permute the elements of list to sort the expression. I am fairly new to Mathematica but I would eventually like to write a small package which would allow me to these kind of manipulations. For example, I have terms like $a**b**c**a^\dagger$ where $a$, $b$, $c$, etc. commute with each other but $a**a^\dagger-a^\dagger**a =1$. So I would like to sort things such that all dagger operators are to the left and have _Mathematica_ use the fact that $a$, $b$, $c$ commute to rewrite the expressions. Right now I am assigning rules for every type of term that appears in my calculation but the number of terms has become unmanageable.
11281
tricky memoization
Let's say I have the NDSolve example for documentation involving splitting 2nd order into set of 1st order ODEs: NDSolve[{x'[t] == y[t], y'[t] == -x[t], x[0] == 1, y[0] == 0}, {x, y}, {t, 0, 10}] I need to solve my second order system like this for various reasons. My ODE is more complicated, and depends on some other parameters call them $(a,b)$, and so when I solved it as a second order system I used memoization in the form below, so that if a solution for a given parameter set had already been computed, Mathematica wouldn't redo it all again. I would like to do this, or something like it for the first order system and where NDSolve is giving the two variables $x[a,b],y[a,b]$. x[a_,b_]:= x[a,b] = x /.NDSolve[{eq[a,b],x[0]== init[a,b],x'[0]==dinit[a,b],x,{r, 0, 10}][[1]];
11280
Are there any offline tutorials for Mathematica?
As can be seen from my questions, I am struggling to make Mathematica do something useful. The amount of tutorials on the Wolfram web site is a bit overwhelming, especially that I don't have too much time to read them. However, I am commuting for about 90 minutes per day, and having the Mathematica documentation (even just the one that comes with the software) in Kindle-friendly format (I'd even accept pdf) would be a great thing for me. Can I find a downloadable version of Mma docs (in pdf, or even better, in epub/mobi) anywhere?
11284
Map Input A B C to MyProduct[A,B,C] (NOT to Times[A,B,C])
In writing my own (noncommutative) product I want to avoid typing redundant symbols like `A.B.C` or `A**B**C`, I just want to type `A B C` and have that mapped to my own `Product[A,B,C]`. (call me a purist) 1\. Is there a clever way to avoid `A B C` being mapped to `Times[A,B,C]` (besides `ClearAll[Times]`)? 2\. Is there any documentation about the inner workings of (Pre-)Parsing and `Times`?
11286
Does Mathematica use the Elliptic Curve Method (ECM) in FactorInteger[]?
I'm not a mathematician, and I'm not even going to pretend that I understand anything of the ECM. But I know it can be a fast method for factorization. I benchmarked the factorization of $$798645312654798147285393218574111453126547981472185139328574111781$$ by Mathematica against this online applet, where the applet was 75 % faster (16 seconds versus 65 for Mathematica). Other factorizations were up to 6 times faster. Does Mathematica use ECM for factorization of certain cases? If yes, how comes performance is so different? **Additional information** We can investigate in the above problem by calling `FactorInteger[..,Automatic]` on the large number: FactorInteger[ 798645312654798147285393218574111453126547981472185139328574111781, Automatic] // AbsoluteTiming (* {5.647210, {{61, 1}, {67, 1}, {74729, 1}, {2614930428035201342411278280525965452621044417207937542347, 1}}} *) This takes only a fraction of the time, but finds only _simple_ factors. So it seems the rest of the time Mathematic tries to factor the last big number. And in fact: FactorInteger[2614930428035201342411278280525965452621044417207937542347] // AbsoluteTiming (* {43.717204, {{97913387938680010938335707, 1}, {26706566722753457593818813677521, 1}}} *) _(feel free to edit tags if needed)_
17621
How to solve a system of equations of the Vietnamese Mathematical Olympiad?
This is a system of equations of the Vietnamese Mathematical Olympiad 2013, the first day. Solve the system of equations $$\begin{cases} \sqrt{\sin^2 x + \dfrac{1}{\sin^2 x}} + \sqrt{\cos^2 y + \dfrac{1}{\cos^2 y}} = \sqrt{\dfrac{20y}{x+y}},\\\ \sqrt{\sin^2 y + \dfrac{1}{\sin^2 y}} + \sqrt{\cos^2 x + \dfrac{1}{\cos^2 x}} = \sqrt{\dfrac{20x}{x+y}}. \end{cases}$$ I tried Reduce[{Sqrt[ Sin[x]^2 + 1/Sin[x]^2] + Sqrt[ Cos[y]^2 + 1/Cos[y]^2] == Sqrt[ 20 y/(x + y)], Sqrt[ Sin[y]^2 + 1/Sin[y]^2] + Sqrt[ Cos[x]^2 + 1/Cos[x]^2] == Sqrt[ 20 x/(x + y)]}, {x, y}, Reals] My computer runs more than ten minutes, but I have not received results.
17620
Fitting data to an ARProcess using FindProcessParameters
I have 50 data points that I would like to represent as an AR(4) process. I'd like to over-plot the behaivor of the estimated process model with that of the original (raw) data before I use the model to predict 10 days into the future. Remove[a1, a2, a3, a4, v] processdata = {{1, 5.0}, {2, 9.0}, {3, 8.0}, {4, 10.0}, {5, 6.1}, {6, 10.4}, {7, 9.1}, {8, 11.6}, {9, 7.5}, {10, 12.1}, {11, 10.4}, {12, 13.5}, {13, 9.0}, {14, 14.1}, {15, 11.9}, {16, 15.7}, {17, 10.8}, {18, 16.4}, {19, 13.7}, {20, 18.3}, {21, 12.9}, {22, 19.0}, {23, 15.8}, {24, 21.2}, {25, 15.3}, {26, 22.1}, {27, 18.3}, {28, 24.6}, {29, 18.1}, {30, 25.8}, {31, 21.2}, {32, 28.6}, {33, 21.4}, {34, 30.0}, {35, 24.6}, {36, 33.2}, {37, 25.2}, {38, 35.0}, {39, 28.6}, {40, 38.5}, {41, 29.6}, {42, 40.7}, {43, 33.3}, {44, 44.7}, {45, 34.8}, {46, 47.4}, {47, 38.8}, {48, 52.0}, {49, 40.9}, {50, 55.2}}; plot1 = ListPlot[processdata, Joined -> True, Frame -> True, FrameLabel -> {"Time (days)", "Temperature"}, AxesOrigin -> {0, 0}, PlotRange -> All, PlotStyle -> {Thick, Red}, PlotLabel -> "Plot 1: Raw Process Data"] Here I use FindProcessParameters to estimate the four coefficients and the variance. Then I use these values to see how well the model matches the raw data. params = FindProcessParameters[processdata, ARProcess[{a1, a2, a3, a4}, v]] a1 = params[[1, 2]]; a2 = params[[2, 2]]; a3 = params[[3, 2]]; a4 = params[[4, 2]]; v = params[[5, 2]]; sigma = Sqrt[v]; y = Table[0, {50}]; y[[1]] = 5.0; y[[2]] = 9.0; y[[3]] = 8.0; y[[4]] = 10.0; dist = NormalDistribution[0, sigma]; t = 4; Do[{ t = t + 1, If[t > 50, Break[]], whitenoise = RandomVariate[dist], y[[t]] = whitenoise/( 1 - (a1*y[[t - 1]]) - (a2*y[[t - 2]]) - (a3*y[[t - 3]]) - (a4* y[[t - 4]]))}, {100}]; modeldata = Transpose[{Range[Length[y]], y}]; plot2 = ListPlot[modeldata, Joined -> True, Frame -> True, FrameLabel -> {"Time (days)", "Temperature"}, AxesOrigin -> {0, -40}, PlotRange -> All, PlotStyle -> {Thin, Black}, PlotLabel -> "Plot 2: Model Data"]; plot3 = Show[plot1, plot2, PlotLabel -> "Plot 3: Raw Process Data(Red) vs AR Model(Black)", AxesOrigin -> {0, -80}] The above model performance is not very good. Am I doing something wrong here ? I then tried specifying MaximumLikelihood as the process estimator in the hope of getting better parameter estimates but get a FindArgMax error message which I also don't understand. Remove[a1, a2, a3, a4, v] params = FindProcessParameters[processdata, ARProcess[{a1, a2, a3, a4}, v], ProcessEstimator -> "MaximumLikelihood"] FindArgMax::nrnum: "The function value {-Log[PDF[ARProcess[{0.746727,0.814726, . . . I'm not a Mathematica power user or time-series expert so relatively gentle answers would be much appreciated. Thanks. Edit 1: Now that I have more than 10 reputation points (I'm a first time stackexchange user) I'm now able to show a plot of the AR model performance. ![plot3](http://i.stack.imgur.com/vVNXF.png) Since the AR model has a probabilistic component (the white noise), a plot that you may generate will in all likelihood look different than above, nonethless I would expect the fit to still be poor. The question is why ?
59647
How to test for Indeterminate values?
I need something like this a = 101010/0; If[a == ComplexInfinity, True, False] But if I use `ToString`, I get what I want. a = 101010/0; If[ToString[a] == "ComplexInfinity", True, False] Does someone know a better way to do this?, I can't belive that transforming to a string is the only way.
34935
Sorting String Date in Asceding Order
How do I order string dates (month/year format) in ascending order, e.g., from 11/2011 to 07/2012: > 02/2012 > > 04/2012 > > 07/2011 > > 08/2013 > > 08/2011