# Count and plot the number of solutions in an interval

I have equations depending on one or more parameters and I want to find and plot regions in the parameter space in which there is a specific number of solutions.

For definiteness let's consider a simple case

-3 + 3 mu2 - 6 q mu2 - 8 q^3 mu4 + 4 q^4 mu4 + q^2 (3 mu2+ 4 mu4) == 0


where I want to find and/or plot regions in the space (mu2,mu4) in which the equation has 0, 1,...,4 solutions with 0 < q < 1.

Note that I want to use the same method also for non-polynomial equations (and possibly systems of equations).

-
For the polynomial case, you might find Kharitonov's theorem useful: en.wikipedia.org/wiki/Kharitonov%27s_theorem – bill s May 7 '13 at 10:06
You've seen CountRoots[]? – J. M. May 7 '13 at 11:49
@bills Thanks, very interesting – psmith May 7 '13 at 12:41
@Fabrizio You can of course define cr[mu2_, mu4_] := CountRoots[-3 + 3 mu2 - 6 q mu2 - 8 q^3 mu4 + 4 q^4 mu4 + q^2 (3 mu2 + 4 mu4), {q, 0, 1}], i.e. it counts the number of roots for q in the range [0, 1]. – Artes May 8 '13 at 8:25
@Fabrizio If your equation is not an adequate example could you provide another one you want to deal with? Otherwise your question cannnot be answered in a more reliable way. – Artes Nov 9 '13 at 19:45

CountRoots is an appropriate function. It may work also with more general functions than polynomials. Two or more-variable polynomials may have infinitely many roots in a compact region, e.g. this one: $\;p(x,y,z)=x^2+y^2+z^2-1 \quad$ has infinitely many roots (continuum) on the unit sphere. In such cases CountRoots cannot give an adequate answer since it may count only a finite number of roots (of univariate polynomials, but we can always restrict many-variable functions to one variable) in an adequate domain (it may be a rectangle in the complex plane).

For the problem at hand let's define:

cr[mu2_, mu4_] := CountRoots[-3 + 3 mu2 - 6 q mu2 - 8 q^3 mu4 + 4 q^4 mu4 +
q^2 (3 mu2 + 4 mu4), q]


To get an idea where you should look for interesting regions Manipulate can serve reasonably :

Manipulate[ cr[mu2, mu4], {mu2, -100, 100}, {mu4, -100, 100}]


To visualize spatial dependence of the cr function we can make use of ListPlot3D having an array of its values :

ar = Array[{#1, #2, cr[#1, #2]} &, {200, 200}, {{-30, 30}, {-30, 30}}];
ListPlot3D[ Flatten[ar, 1], Mesh -> None,
ColorFunction -> Function[{x, y, z}, Darker @ Hue[1/4 z]]]


Where we can see the jumps on the plot we might expect 1 and 3 roots of the polynomial.

For more complete discussion of the issue this question needs better examples and more precise formulation. One can proceed further with Reduce and Solve etc. Solving equation with Solve it might be more handy when there are finite number of solutions (because of the output in terms of replacement rules). On the other hand there might be many subtleties and one can proceed on the case by case basis (see e.g. How do I work with Root objects? where one can simply count roots e.g. with Length). For a bit more interesting example of a polynomial equation see this question : 3D Plot: Number of Roots in x of a polynomial in x, a, b and c.

-
The boundary of those regions is where the discriminant wrt q vanishes 9which gives another approach to finding regions for different real-root counts. – Daniel Lichtblau May 7 '13 at 20:20

Following the comment of J.M., it's possible to use CountRoots[], for the case in the question one possible solution is

myF[Q_, mu2_, mu4_] := -3 + 3 mu2 q^2 + 4 mu4 q^4 - 6 mu2 q Q - 8 mu4 q^3 Q + 3 mu2 Q^2 + 4 mu4 q^2 Q^2

myCR[Q_, mu2_, mu4_] := CountRoots[myF[Q, mu2, mu4], {q, 0, Q}]

ContourPlot[myCR[myQ, mu2, mu4], {mu4, 0, 15}, {mu2, 0, 2},
ImageSize -> 300, PlotPoints -> 100, MaxRecursion -> 3,
ContourLabels -> Automatic, ContourStyle -> None,
Contours -> {0, 1, 2, 3, 4}, ColorFunction -> "Rainbow"]


obtaining

Although the question is still open for the case of non-polynomial equations.

-
If you provided certain non-polynomial equations, then it would be possible to answer in a constructive way or justify why that wouldn't be accessible. I mean that basically one can discuss the issue with a problem at hand not in general. – Artes May 10 '13 at 23:07