Message Boards Message Boards

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


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?


POSTED BY: Vinny Pagano
7 months ago
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 BY: Mariusz Iwaniuk
7 months ago

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

POSTED BY: Vinny Pagano
7 months ago

Group Abstract Group Abstract