2
$\begingroup$

This code (from this answer)

Manipulate[Plot[f[x, x0, a, n0, c], {x, 0, 3}, 
  PlotRange -> {{-1, 4}, {-2, 4}}Frame -> True, Axes -> False, 
  MeshStyle -> Directive[Green, PointSize[Large]], 
  MeshFunctions -> {#2 &}, Mesh -> {{1, -1}}, 
  MeshShading -> {Blue, Red}, BaseStyle -> Thick, 
  Prolog -> {EdgeForm[{LightBlue, Thick}], Opacity[0.5], LightBlue, 
    Rectangle[{0, -1}, {3, 1}]}], 
{{x0, 1.5}, 0, 10}, {{a, -.3}, -1, 1}, {{n0, 1.1}, 1, 2}, {{c, 0.1}, 0.1, 10}] 

Shows intersections of the function with the rectangle based of their common value, so on top and bottom of the rectangle. I need the code to show the intersections based of the common categories, so it should display the green points on left and right sides of the rectangle.

Another question - How can i display the coordinates of the green points next to them?

$\endgroup$
  • $\begingroup$ does using MeshFunctions->{#1&} and Mesh -> {{0,3}} give what you need? $\endgroup$ – kglr Dec 19 '17 at 2:20
  • $\begingroup$ Yes, works like a charm. Any idea about the coordinates though? $\endgroup$ – Ralnor Dec 19 '17 at 2:25
1
$\begingroup$
Manipulate[Normal[Plot[f[x, x0, a, n0, c], {x, -.01, 3.01}, 
    Frame -> True, Axes -> False, BaseStyle -> Thick,
    MeshStyle -> Directive[Green, PointSize[Large]], 
    MeshFunctions -> {Boole[-1 <= #2 <= 1] (# - 1) &}, Mesh -> { {2, -1}},  
    Prolog -> {EdgeForm[{LightBlue, Thick}], Opacity[0.5], LightBlue, 
      Rectangle[{0, -1}, {3, 1}]}, PlotRange -> {{-1, 4}, {-6, 6}}] ]  /. 
  Point[x_] :> {Point[x], Text[Style[Round[x, .1], 16, Black], x + {0, .6}]}, 
{{x0, 2.25}, 0, 10}, {{a, -.3}, -1, 1}, {{n0, 1}, 1, 2}, {{c, 0.9}, 0.1, 10}]

enter image description here

Alternatively, you can inject the intersection points and labels inside Prolog

Manipulate[Plot[f[x, x0, a, n0, c], {x,0, 3.}, Frame -> True, 
  Axes -> False, BaseStyle -> Thick, 
  Prolog -> {EdgeForm[{LightBlue, Thick}], Opacity[0.5], LightBlue, 
   Rectangle[{0, -1}, {3, 1}], 
  {Green, PointSize[Large], Point@#, Opacity[1], Black, 
  Text[Style[Round[#, .1], 16], # + {0, .5}]} & /@ ({#, f[#, x0, a, n0, c]} & /@ {0, 3})},
  PlotRange -> {{-1, 4}, {-6, 6}}], 
 {{x0, 2.25}, 0, 10}, {{a, -.3}, -1, 1}, {{n0, 1}, 1, 2}, {{c, 0.9}, 0.1, 10}]

same picture

Note: Why not simply MeshFunctions -> {# &} and Mesh -> { {3, 0}}?

To avoid results like this:

enter image description here

$\endgroup$

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.