ContourPlot
has trouble with discontinuous functions and the setting Exclusions -> True
does not get the job done here. Let's help it out. When solving symbolic equations, it helps to have exact coefficients, so I'll use Rationalize
on the equations in fulltable
to compute the exclusions in excl
.
plotpoints = 50;
fulltable = Union[Flatten[{table5, q == 0, p == q}]];
excl = Cases[
FactorList /@ (Rationalize@fulltable /.
Equal -> Subtract), {poly_ /; ! NumericQ[poly], _?Negative} :>
poly == 0, Infinity];
(*
{p == q, p == (1 + (0.2 (1 + 3 (p - q)^2))/(1 - (p - q)^2)^3) q, q == 0}
{-1 + p - q == 0, 1 + p - q == 0}
*)
ContourPlot[Evaluate[fulltable], {p, -10, 10}, {q, -10, 10},
PlotPoints -> plotpoints, PlotRange -> All, Exclusions -> excl]
Here's a view of the discontinuities, rotated by Pi/4
.
Plot3D[p - (1 + (0.2` (1 + 3 (p - q)^2))/(1 - (p - q)^2)^3) q /. {p ->
x + y, q -> -x + y}, {x, -1, 1}, {y, -10, 10}, PlotPoints -> 51,
MaxRecursion -> 3, MeshFunctions -> {#3 &}, Mesh -> {{0}},
MeshStyle -> {Thick, Red}, PlotStyle -> Opacity[0.5],
MeshShading -> {Directive[Opacity[0.5], Yellow],
Directive[Opacity[0.5], LightBlue]}, BoundaryStyle -> None,
Exclusions -> {1 - (p - q)^2 == 0 /. {p -> x + y, q -> -x + y}},
PlotRange -> 500]
Responses to comments:
(1) One may get rid of the gaps introduced by the Exclusions
option by plotting where the numerator (of the fraction resulting from Together
):
ContourPlot[
Evaluate@Thread[Numerator@Together[fulltable /. Equal -> Subtract] == 0],
{p, -10, 10}, {q, -10, 10}, PlotPoints -> plotpoints]
(2) Forgive me, but I'm not sure I understand the distinction between limiting range of a parameter in a parametric plot and limiting the plot range. Below is a parametric plot of the wiggly contour. Is that what you want? (Note the errors are unimportant, because that's what happens when the parametric solution heads towards infinity.)
fn = First@Numerator@Together@Union[Flatten[table5] /. Equal -> Subtract]
sol = NDSolve[{{p'[t], q'[t]} == (Cross[D[fn, {{p, q}}]] /. {p -> p[t], q -> q[t]}),
{p[0], q[0]} == {0, 0}}, {p, q}, {t, -4, 4}]
(*
-1. p + 3. p^3 - 3. p^5 + p^7 + 1.2 q - 8.4 p^2 q + 15. p^4 q -
7. p^6 q + 7.8 p q^2 - 30. p^3 q^2 + 21. p^5 q^2 - 2.4 q^3 +
30. p^2 q^3 - 35. p^4 q^3 - 15. p q^4 + 35. p^3 q^4 + 3. q^5 -
21. p^2 q^5 + 7. p q^6 - 1. q^7
*)
NDSolve::mxst: Maximum number of 10000 steps reached at the point t == -3.9211. >>
NDSolve::mxst: Maximum number of 10000 steps reached at the point t == 3.921095435807773`. >>
{{p->InterpolatingFunction[{{-3.9211,3.9211}},<>],
q->InterpolatingFunction[{{-3.9211,3.9211}},<>]}}
ParametricPlot[{p[t], q[t]} /. sol // Evaluate, {t, -3.4, 3.4}]
PlotPoints
run for several hours?ContourPlot[ p == q (1 + (2 (1 + 3 (p - q)^2) (.1))/(1 - (p - q)^2)^3), {p, -3, 3}, {q, -3, 3}, PlotPoints -> 600, PlotRange -> All, Exclusions -> True]
gives smooth result in my testing. You can also try playing withMaxRecursion
a bit. $\endgroup$