## Trying to create an interactive plot (newbie here)

4

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: 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:

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

1

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.

– MarcoB – 2016-05-18T14:50:56.833

@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? – rxc370 – 2016-05-18T21:35:43.340

1Can you show the exact code you tried? – MarcoB – 2016-05-18T21:51:52.410

It doesn't seem to show up well in the comment. I'll add it to my original post. – rxc370 – 2016-05-19T02:50:14.577

1The {P, 2, 10} fragment should be inside Manipulate, but outside Show, so ... {x, 0, 1}]], {P, 2, 10}] – MarcoB – 2016-05-19T03:16:17.677

usually the x goes on the horizontal axis and the y on the vertical axis. Any reason you show them in the opposite order? – Nasser – 2016-05-19T07:40:28.150

@Nasser I'm think I have x on the horizontal axis. Is it not that way? – rxc370 – 2016-05-19T13:30:11.600

I am looking at the screen shot you have above, but I see y on the horizontal axis, not x. may be the screen shot was rotated when pasted. – Nasser – 2016-05-19T16:29:52.023

4

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]

Thank you so much for this. Let me try to understand it now :) – rxc370 – 2016-05-19T13:31:09.293