1
$\begingroup$

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.3`10, a2 -> 1.2`10, a3 -> 1.5`10, a4 -> 2`10, 
 a5 -> 1.8`10};

AA1 = ContourPlot[{(Equation /. Sub) == 0.}, {z, 0`10, 9.9`10}, {s, 
0`10, 1.4`10}, 
 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 enter image description here

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

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

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]

enter image description here

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.3`10, a2 -> 1.2`10, a3 -> 1.5`10, a4 -> 2`10, a5 -> 1.8`10};
AA1 = ContourPlot[{(equation /. sub) == 0.}, {z, 0`10, 9.9`10}, {s, 0.8`10, 1.0`10}, 
  FrameLabel -> {{"\[Omega]/k \!\(\*SubscriptBox[\(c\), \(0\)]\)", 
     ""}, {"k \!\(\*SubscriptBox[\(x\), \(0\)]\)", ""}}, 
  WorkingPrecision -> MachinePrecision, PlotPoints -> 50]

enter image description here

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.