Message Boards Message Boards

GROUPS:

Update a Plot's upper boundary from Solve[]?

Posted 10 months ago
865 Views
|
2 Replies
|
2 Total Likes
|

Hey guys! I have been having trouble with varying the upper bound for a plot, or an integrand, or any type of Mathematica function that has boundaries. The issue is that whenever the function is executed, the result does not update itself.

Here's a quick example of some simple code demonstrating the goal:

f = [Solve[2 w + 5 == g, w, Reals]]
upper = w /. f[[1]]
Manipulate[Plot[r^2, {r, 1, upper}], {g, 8, 20}]

The first line defines a process whereby w is the output variable.

The second line of code is used to extract the numerical output (as opposed to the solution in the form of {{w -> Number}}).

The third line of code is supposed to plot the graph r^2 from {1, upper}. The variable upper should be changing as g changes, hence why it is a Manipulate[] command.

The result is only the graph from 1 to 3/2 (the first solution to the f equation).

How can I update the variables g, f, and upper to obtain the desired result in the Manipulate[Plot[]] command?

Thanks!

2 Replies
upper[g_] := (w /. First@NSolve[2 w + 5 == g, w, Reals]);
Manipulate[Plot[r^2, {r, 1, upper[g]}, PlotRange -> All], {g, 8, 20}]
Posted 10 months ago

Why didn't I think of that?! So simple and elegant. You're the best!

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