4
$\begingroup$

I'm new at Mathematica so please bear with me. I am trying to create an interactive plot that will end up looking like this: enter image description here I want to input values for certain variables and then plot a curve. This is what I have now.


     Manipulate[
     Plot[
      y = -((P*x^2)/(6*R*S)) (3*a - x),
      {x, 0, 10}],
     {P, 0, 10},
     {R, 0, 10},
     {S, 0, 10},
     {a, 0, 10}
     ]

Instead of slider bars, I want to have input boxes.

I have a few other issues. I don't know how to program a square. I believe this should be done piecewise, but I'm not sure how to do it on the same plot as my curve. Also, I'd like it so that the y-intercept auto manipulates so that the curve always touches the corner of the square. This might be a tad harder because I also want to add


    y = -((P*x^2)/(6*R*S)) (3*a - x)cos[[Theta]]

Is that even possible?

Thanks for the help.

edit: working off of @MarcoB 's advice, I got this now.


Manipulate[
 Show[
  Graphics[{Rectangle[{1, 2}, {2, 4}]}],
  Plot[
   -(Px^2/6) (3 - x),
   {x, 0, 1}],
  {P, 2, 10}
   ]
 ]

edit 2: Working off of @MarcoB 's next comment, I managed to get a plot looking like this: enter image description here

My code is:


Manipulate[
 Show[
  Graphics[{Rectangle[{1, 2}, {2, 3}]}],
  Plot[
   -(Px^2/6) (3 - x),
   {x, -2, 10},
   PlotStyle -> green],
  PlotRange -> {{-2, 10}, {-2, 10}},
  Axes -> True
   ],
 {P, -10, 10}
 ]

$\endgroup$
8
  • 1
    $\begingroup$ Generally speaking, get the plot working with some fixed values first, then implement the manipulate functionality. More specifically, 1. Remove the y = in your plotting expression; 2. look up Rectangle, Graphics, and Show, in a combination as Show[Graphics[{Rectange[yourspecs]}], Plot[plottingArguments]]; 3. See InputField as a control type for Manipulate. $\endgroup$
    – MarcoB
    Commented May 18, 2016 at 14:50
  • $\begingroup$ @MarcoB I'm getting this error message "Could not combine the graphics objects in Show[...] From reading the help menu, it would appear as though this is because my equation isn't a "graphics expression". How can I fix this? $\endgroup$
    – rxc370
    Commented May 18, 2016 at 21:35
  • 1
    $\begingroup$ Can you show the exact code you tried? $\endgroup$
    – MarcoB
    Commented May 18, 2016 at 21:51
  • $\begingroup$ It doesn't seem to show up well in the comment. I'll add it to my original post. $\endgroup$
    – rxc370
    Commented May 19, 2016 at 2:50
  • 1
    $\begingroup$ The {P, 2, 10} fragment should be inside Manipulate, but outside Show, so ... {x, 0, 1}]], {P, 2, 10}] $\endgroup$
    – MarcoB
    Commented May 19, 2016 at 3:16

1 Answer 1

4
$\begingroup$

You may start with this, add whatever you need and then remove the unnecessary manipulation parameters:

Manipulate[Show[{


 Graphics[{Opacity[0.5], Red, 
     Rectangle[{1 + a, c + b}, {2 + a, 4 + b}]}, 
    PlotRange -> {{0, 2}, {-3, 0}}, Axes -> True, 
    AxesOrigin -> {1 + a, c}],

   Plot[{-(P*x^2/6) (3 - x), -k*x}, {x, 0, 1}, Axes -> True]
   }],

 {P, 2, 10}, {a, -1, 1}, {b, -5, 1}, {c, 1, 5}, {k, 0, 3}, 
 SaveDefinitions -> True]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thank you so much for this. Let me try to understand it now :) $\endgroup$
    – rxc370
    Commented May 19, 2016 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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