Skip to main content

plotting - Creating a Mathieu stability diagram



I am attempting to re-create a Mathieu stability diagram like the one shown here:


enter image description here


I expected that I could use MathieuC to generate this graph by assuming that instability occurs when the function returns a complex number, so I try


Quiet@DiscretePlot[Re@a /. FindRoot[MathieuC[a, q, 1], {a, 0.2}], {q, 0, 1, 0.1}]

which is wrong for two reasons - it produces a plot not even close to the desired output and the output is dependent on what value I use for z (in the example above, 1).


For those interested, the impetus behind this problem is to explore how Mathematica can be used to simulate the behavior of a quadrupole mass spectrometer.



Answer



I think that this question is too localized as it concerns the physics of a specific scientific instrument. Nonetheless, it is upvoted, so here I provide an answer for the benefit of the voters. I would still be happy to discuss this in the chat.


The mathematics of the quadrupole mass filter is more complicated than you might think. Basically, your assumption is not correct; the stability condition is actually



$$-C(a,q,\xi) \dot{S}(a,q,\xi) \in \mathbb{R}$$


which in fact does not depend on the formal parameter $\xi$ (which can be thought of as a sort of dimensionless time variable defining the phase of the oscillating electric field). The oscillation amplitude is proportional to the reciprocal of this quantity.


Additionally, the QMF itself has two planes of symmetry, $a=0$ and $q=0$, and we require stability in all four quadrants. However, the solutions of the Mathieu equation are symmetric about $a=0$ anyway, and we can get away in practice with placing just one mirror plane along the diagonal. So, with


$$P(a,q)=-C(a,q,\xi=0) \dot{S}(a,q,\xi=0)$$


we can plot the (symmetrized) stability diagram simply from the contours of $P(a,q) P(-a,-q)$ as follows:


p[a_, q_] := -MathieuC[a, q, 0] MathieuSPrime[a, q, 0]
ContourPlot[
p[a, q] p[-a, -q], {q, 0.05, 0.95}, {a, 0.00, 0.25},
MaxRecursion -> 3, RegionFunction -> Function[{x, y, f}, f > 0],
ColorFunction -> (ColorData["DarkRainbow"][1 - #] &),

AspectRatio -> 1/GoldenRatio
]

This takes a while to run and produces a large output, which looks as follows:


plot of the stability parameter in the first Mathieu stability region


Although quite aesthetically pleasing and perhaps useful as a visual guide to the variation of the oscillation amplitude in $(a,q)$ space, this is not a very practical way to plot the diagram, and perhaps more importantly, it does not really provide any mathematical insight.


A better approach is to plot our diagram as the domain over which the elliptic sine and cosine functions


$$ce_r(\xi,q)=C(a_r,q,\xi) \\ se_r(\xi,q)=S(b_r,q,\xi)$$


are periodic. This is true for characteristic values $a_r(r,q)=$ MathieuCharacteristicA[r, q] and $b_r(r,q)=$ MathieuCharacteristicB[r, q]. $r$ is an index that numbers the elliptic trigonometric functions according to the number of roots they possess in the interval $0\le\xi\le\pi$. The elliptic sine is an odd function, so there is no $se_0$; the first periodic elliptic sine is thus $se_1$.


In other words,



Plot[
{ MathieuCharacteristicA[0, q], MathieuCharacteristicB[1, q] (* upright *),
-MathieuCharacteristicA[0, q], -MathieuCharacteristicB[1, q] (* reflected*)},
{q, 0, 1}, PlotRange -> {All, {0.0, 0.3}},
PlotStyle -> {
Directive[Thick, Blue], Directive[Thick, Red],
Directive[Thick, Dashed, Blue], Directive[Thick, Dashed, Red]
},
Filling -> Table[{2 n + 1 -> {{2 n + 2}, Directive[Opacity[1/2], Purple]}}, {n, 0, 1}]
]


which looks like this:


plot of the boundaries of the first Mathieu stability region


Its apex is at:


FindRoot[MathieuCharacteristicA[0, q] + MathieuCharacteristicB[1, q], {q, 0.6}]
(* -> {q -> 0.7059960697133709`} *)

{a -> MathieuCharacteristicB[1, q]} /. %
(* -> {a -> 0.23699399311247354`} *)


What was the point of all that mathematical discussion just to plot this, you might ask? Well, actually, there are many stable regions located apart from another in $(a,q)$ space, any of which might be used in a practical instrument. Infinitely many, in fact. Here are the three for which instruments have been constructed so far:


Plot[
Flatten@Table[
{Tooltip[ MathieuCharacteristicA[r, q], Subscript[ce, r ]],
Tooltip[ MathieuCharacteristicB[r + 1, q], Subscript[se, r + 1]],
Tooltip[-MathieuCharacteristicA[r, q], -Subscript[ce, r ]],
Tooltip[-MathieuCharacteristicB[r + 1, q], -Subscript[se, r + 1]]},
{r, 0, 1}
], {q, 0, 8}, Evaluated -> True,
PlotRange -> {All, {0, 4}},

PlotStyle -> {
Directive[Thick, Blue], Directive[Thick, Red],
Directive[Thick, Dashed, Blue], Directive[Thick, Dashed, Red]
},
Filling -> Table[{2 n + 1 -> {{2 n + 2}, Directive[Opacity[1/2], Purple]}}, {n, 0, 3}]
]

plot of the boundaries of the first three Mathieu stability regions


Here's a closer look at them.


The first/conventional region:



first Mathieu stability region


The second/"r.f.-only" region:


second Mathieu stability region


The third/"intermediate" region:


third Mathieu stability region


We can also plot the ion trajectories anywhere in the $(a,q)$ plane if we wish, using the expressions given in V. I. Baranov, J. Am. Soc. Mass Spectrom. 14, 818 (2003). (Beware! This paper contains some mistakes.) But the expressions are complicated and that is beyond the scope of this post.


Comments

Popular posts from this blog

plotting - Filling between two spheres in SphericalPlot3D

Manipulate[ SphericalPlot3D[{1, 2 - n}, {θ, 0, Pi}, {ϕ, 0, 1.5 Pi}, Mesh -> None, PlotPoints -> 15, PlotRange -> {-2.2, 2.2}], {n, 0, 1}] I cant' seem to be able to make a filling between two spheres. I've already tried the obvious Filling -> {1 -> {2}} but Mathematica doesn't seem to like that option. Is there any easy way around this or ... Answer There is no built-in filling in SphericalPlot3D . One option is to use ParametricPlot3D to draw the surfaces between the two shells: Manipulate[ Show[SphericalPlot3D[{1, 2 - n}, {θ, 0, Pi}, {ϕ, 0, 1.5 Pi}, PlotPoints -> 15, PlotRange -> {-2.2, 2.2}], ParametricPlot3D[{ r {Sin[t] Cos[1.5 Pi], Sin[t] Sin[1.5 Pi], Cos[t]}, r {Sin[t] Cos[0 Pi], Sin[t] Sin[0 Pi], Cos[t]}}, {r, 1, 2 - n}, {t, 0, Pi}, PlotStyle -> Yellow, Mesh -> {2, 15}]], {n, 0, 1}]

plotting - Plot 4D data with color as 4th dimension

I have a list of 4D data (x position, y position, amplitude, wavelength). I want to plot x, y, and amplitude on a 3D plot and have the color of the points correspond to the wavelength. I have seen many examples using functions to define color but my wavelength cannot be expressed by an analytic function. Is there a simple way to do this? Answer Here a another possible way to visualize 4D data: data = Flatten[Table[{x, y, x^2 + y^2, Sin[x - y]}, {x, -Pi, Pi,Pi/10}, {y,-Pi,Pi, Pi/10}], 1]; You can use the function Point along with VertexColors . Now the points are places using the first three elements and the color is determined by the fourth. In this case I used Hue, but you can use whatever you prefer. Graphics3D[ Point[data[[All, 1 ;; 3]], VertexColors -> Hue /@ data[[All, 4]]], Axes -> True, BoxRatios -> {1, 1, 1/GoldenRatio}]

plotting - Mathematica: 3D plot based on combined 2D graphs

I have several sigmoidal fits to 3 different datasets, with mean fit predictions plus the 95% confidence limits (not symmetrical around the mean) and the actual data. I would now like to show these different 2D plots projected in 3D as in but then using proper perspective. In the link here they give some solutions to combine the plots using isometric perspective, but I would like to use proper 3 point perspective. Any thoughts? Also any way to show the mean points per time point for each series plus or minus the standard error on the mean would be cool too, either using points+vertical bars, or using spheres plus tubes. Below are some test data and the fit function I am using. Note that I am working on a logit(proportion) scale and that the final vertical scale is Log10(percentage). (* some test data *) data = Table[Null, {i, 4}]; data[[1]] = {{1, -5.8}, {2, -5.4}, {3, -0.8}, {4, -0.2}, {5, 4.6}, {1, -6.4}, {2, -5.6}, {3, -0.7}, {4, 0.04}, {5, 1.0}, {1, -6.8}, {2, -4.7}, {3, -1.