Message Boards Message Boards

0
|
5198 Views
|
4 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Manipulate the range of values for the variable in a Plot

Posted 4 years ago

I have the following code: a := 0; b := 5; fxsquared[x_] := x^2; Plot[fxsquared[x], {x, a, b}]

I would like to use Manipulate to vary the values of a and b and see the plot change. Is there any way to do that?

POSTED BY: Tom Goodell
4 Replies

That's perfect! Thank you so much!

POSTED BY: Tom Goodell
Posted 4 years ago

Hi Tom,

ClearAll@ξ
ξ[a_, b_] := (a + b)/2

Manipulate[Plot[fxsquared[x], {x, a, b},
  Epilog -> {Red, PointSize[0.02], Point[{ξ[a, b], fxsquared[ξ[a, b]]}]},
  PlotRange -> {{0, 5}, {0, 25}}],
 {a, 1, 5}, {b, 1.01, 5}]

enter image description here

POSTED BY: Rohit Namjoshi

Thank you! That worked. I'm a novice and learning as I go. I now have this code functioning:

fxsquared[x_] := x^2
Manipulate[Plot[fxsquared[x], {x, a, b}], {a, 1, 5}, {b, 1, 5}]

I want to also show a point on the plot as a function of a and b. I've read through the documentation on Prolog and Point and this is what I've tried:

fxsquared[x_] := x^2
\[Xi] := (a + b)/2
Manipulate[
 Plot[fxsquared[x], {x, a, b}, 
  Prolog -> {Red, PointSize[0.02], Point[{\[Xi], fxsquared[\[Xi]]}]}, 
  PlotRange -> {{0, 5}, {0, 25}}], {a, 1, 5}, {b, 1, 5}]

This lets me manipulate the fxsquared plot, but Xi shows as a fixed point that doesn't change as I change the values of a and b. Can you give me any guidance on how to do this? Again, many thanks for the help. I'm learning ...

POSTED BY: Tom Goodell

Do not set variables of constant values with :=, just use =

For the sake of Manipulate you do not need them at all. The following will give you the basic idea, and from there keep reading the documentation

Manipulate[Plot[Sin[x], {x, a, b}], {a, 0, 2 Pi}, {b, 3 Pi, 10 Pi}]
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract