As in the title. I want them to be on the same graph. Additionaly i want to the graph to always be focused on the rectangle.

f[x_, x0_, a_, n0_, C_] := -1/a + C/(a*n0)*Cosh[a*n0/C*(x - x0)]

  Graphics[{Thick, Opacity[0.5], LightBlue, Rectangle[{0, -1}, {3, 1}]}]
    Plot[f[x, x0, a, n0, c], 
    {x, 0, 3}], 
    {x0, 0, 10}, 
    {a, -1, 1}, 
    {n0, 1, 2}, 
    {c, 0.1, 10}]]

Second question, I don't know if i should make another thread about it. How to add two points where the rectangle and function collide?

  • $\begingroup$ Ralnor, welcome to Mathematica.SE! We suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign $\endgroup$
    – kglr
    Dec 19 '17 at 2:55

You can also use the rectangle as a Prolog or Epilog in Plot so that you don't have to use Show.

The intersection of the rectangle with the plotted line can be highlighted using Mesh* options:

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}]

enter image description here

  • $\begingroup$ I see Mesh for the first time and your code only detects it matching the value of function. how to make it also detect it colliding with the arguments? $\endgroup$
    – Ralnor
    Dec 19 '17 at 1:26
  • $\begingroup$ @Ralnor, does using MeshFunctions->{#1&} and Mesh -> {{0,3}} give what you mean by "colliding with the arguments"? $\endgroup$
    – kglr
    Dec 19 '17 at 2:04

May be what you meant is


    ymin=MinValue[{f[x,x0,a,n0,c],x>= 0,x<= 3},x];;
    ymax=MaxValue[{f[x,x0,a,n0,c],x>= 0,x<= 3},x];

Mathematica graphics


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.