2
$\begingroup$

I am trying to calculate the differences in natural frequencies between two different dynamic models, and I would like to plot these error contours in terms of ues (mass ratio) and nel (frequency ratio). err1 corresponds to the error when nel > 1 and err2 corresponds to the error when nel < 1.

Naturally these error contours should be plotted on a single graph, but I cannot find a way to combine these on a single graph, especially since nel needs to be plotted on a log X-axis. I have tried Show[], but I cannot get it to plot the graph with the following requirements:

  1. Logarithmic X-axis (ues)
  2. Filled in Contours
  3. Contour Plot Range (error) shall be {0 , 0.5}
  4. X-Axis (ues) Range shall be {0 , 1}
  5. Y-Axis (nes) Range shall be {0 , 3.5}

Here are two separate graphs that accomplish the requirements above but are not combined:

ClearAll["Global`*"]

err1 = -1 + Sqrt[2]/Sqrt[1 + ues + nel^2*(1 + ues) - 
          Sqrt[(1 + ues)*((-1 + nel^2)^2 + (1 + nel^2)^2*
                   ues)]]

err2 = 1 - Sqrt[2]/Sqrt[1 + ues + nel^2*(1 + ues) + 
          Sqrt[(1 + ues)*((-1 + nel^2)^2 + (1 + nel^2)^2*
                   ues)]]

(* Plot Error 1 Contour *)
Show[ContourPlot[
  Tooltip[err1, Row[{"ues = ", ues}]], {ues, 0, 1}, {nel, 1, 3.5}, 
  PlotRange -> {0, 0.501}, 
  Contours -> Join[{0.01}, Range[0.05, 0.50, 0.05]], 
  AxesLabel -> Automatic, ScalingFunctions -> {"Log", None}], 
 AxesLabel -> {None, None}, 
 FrameLabel -> {{HoldForm[nel], None}, {HoldForm[ues], None}}, 
 PlotLabel -> None, LabelStyle -> {GrayLevel[0]}]

(* Plot Error 2 Contour *)
Show[ContourPlot[
  Tooltip[err2, Row[{"ues = ", ues}]], {ues, 0, 1}, {nel, 0, 1}, 
  PlotRange -> {0, 0.501}, 
  Contours -> Join[{0.01}, Range[0.05, 0.50, 0.05]], 
  AxesLabel -> Automatic, ScalingFunctions -> {"Log", None}], 
 AxesLabel -> {None, None}, 
 FrameLabel -> {{HoldForm[nel], None}, {HoldForm[ues], None}}, 
 PlotLabel -> None, LabelStyle -> {GrayLevel[0]}]

Note I use ScalingFunctions from Mathematica 11.

$\endgroup$
1
$\begingroup$
 ContourPlot[Tooltip[If[nel <= 1, err2, err1], Row[{"ues = ", ues}]], 
   {ues, 0, 1}, {nel, 0, 3.5}, 
   Exclusions -> None, PlotPoints -> 100,
   PlotRange -> {{0, 1}, {0, 3.5}, {0, 0.5}}, 
   Contours -> Join[{0.01}, Range[0.05, 0.50, 0.05]], 
   AxesLabel -> Automatic, ScalingFunctions -> {"Log", None}] 

enter image description here

$\endgroup$
  • $\begingroup$ Both If or Piecewise work beautifully. Thanks for showing me a path foward. $\endgroup$ – felimz Oct 14 '18 at 23:00
  • $\begingroup$ @felimz, my pleasure. Thank you for the accept and welcome to mma.se. $\endgroup$ – kglr Oct 14 '18 at 23:02

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.