# Equation Plotting using ContourPlot

I wanted to plot this equation

Equation = (s^2 + a1^2 (-1 + s^2)) s^2 (-a1 + s) (a1 +
s) Sqrt[((-1 + s^2) (-a1^2 + s^2))/(s^2 + a1^2 (-1 + s^2))]
Cos[2 Sqrt[((-1 + s^2) (-a1^2 + s^2))/(s^2 + a1^2 (-1 + s^2))]
z] (-Sqrt[
a4 (a2^2 - s^2)] (a5 Sqrt[a2^2 a4 - a3 s^2] +
a3 Sqrt[a2^2 a4 - a5 s^2]) Cosh[(Sqrt[a2^2 - s^2] z)/a2] -
a4 Sqrt[a2^2 a4 - a3 s^2] Sqrt[a2^2 a4 - a5 s^2]
Sinh[(Sqrt[a2^2 - s^2] z)/a2] +
a3 a5 (-a2^2 + s^2) Sinh[Sqrt[1 - s^2/a2^2] z]) +
a2^2 Sin[
2 Sqrt[((-1 + s^2) (-a1^2 + s^2))/(s^2 + a1^2 (-1 + s^2))]
z] (a2^2 a4  (-a1^2 + s^2) Sqrt[
1 - s^2/a2^2] (a3 a5  s^4 (-1 + s^2) -
Sqrt[1 - (a3 s^2)/(a2^2 a4)] Sqrt[
1 - (a5 s^2)/(
a2^2 a4)] (s^4 + a1^2 s^2 (-2 + s^2) -
a1^4 (-1 + s^2))) Cosh[
Sqrt[1 - s^2/a2^2]
z] - ((s^2 + a1^2 (-1 + s^2)) a1^4 a5 (a2^2 - s^2) Sqrt[
1 - (a3 s^2)/(
a2^2 a4)] - (s^2 + a1^2 (-1 + s^2)) 2 a1^2 a5  s^2 (a2^2 -
s^2) Sqrt[1 - (a3 s^2)/(a2^2 a4)] +
a5  s^4 (a2^2 - s^2) Sqrt[1 - (a3 s^2)/(a2^2 a4)] -
a2^2 a3 a4^2  s^4 (-1 + s^2) (-a1^2 + s^2) Sqrt[
1 - (a5 s^2)/(a2^2 a4)]) Sinh[Sqrt[1 - s^2/a2^2] z]);


Using ContourPlot command

Sub = {a1 -> 1.310, a2 -> 1.210, a3 -> 1.510, a4 -> 210,
a5 -> 1.810};

AA1 = ContourPlot[{(Equation /. Sub) == 0.}, {z, 010, 9.910}, {s,
010, 1.410},
FrameLabel -> {{"\[Omega]/k \!$$\*SubscriptBox[\(c$$, $$0$$]\)",
""}, {"k \!$$\*SubscriptBox[\(x$$, $$0$$]\)", ""}},
WorkingPrecision -> MachinePrecision]


Unfortunately as a result I have the plot that looks like a mess

Where I believe it should be more smooth one, may I ask for any advice or suggestions to how may I improve my code.

• Have you tried adjusting the PlotPoints and MaxRecursion options? – Szabolcs Aug 15 '17 at 7:39

I think your plot may be right. It's just that your function is highly oscillatory and the plot limits are a bit off.

Specifically, compare these two Plot3Ds with different s ranges:

GraphicsRow[{
Plot3D[equation /. sub, {z, 0, 9.9}, {s, 0, 1.4}],
Plot3D[equation /. sub, {z, 0, 9.9}, {s, 0.8, 1}]
}, ImageSize -> 800]


The first one corresponds to the plot limits in your ContourPlot. Observe that the equation is undefined for large ranges of s. Taking these out of the plot range makes it a lot more understandable.

Doing the ContourPlot with these ranges (and setting PlotPoints -> 50, as @Szabolcs suggested):

sub = {a1 -> 1.310, a2 -> 1.210, a3 -> 1.510, a4 -> 210, a5 -> 1.810};
AA1 = ContourPlot[{(equation /. sub) == 0.}, {z, 010, 9.910}, {s, 0.810, 1.010},
FrameLabel -> {{"\[Omega]/k \!$$\*SubscriptBox[\(c$$, $$0$$]\)",
""}, {"k \!$$\*SubscriptBox[\(x$$, $$0$$]\)", ""}},
WorkingPrecision -> MachinePrecision, PlotPoints -> 50]


• Thank you for the help – Alexander Aug 15 '17 at 8:35
• @Alexander No worries. Thanks for the accept. – aardvark2012 Aug 15 '17 at 9:06