# Nsolve a parametric equation and using the result of NSolve in another equation

I have the following equation:

(2 r)/(1 - 1/r + r^2 - r^(-1 + b)) - (r^2 (1/r^2 + 2 r - r^(-2 + b) (-1 +
b)))/(1 - 1/r + r^2 - r^(-1 + b))^2 = 0


I need to find r for 0<b<1, and use r to calculate and plot F:

F= r/Sqrt[1 - 1/r^(1 - b) - 1/r]


To plot F with respect to b. First I defined a function R[b], which numerically solves my first equation and gives me r for each value of b, as the following:

R[b_] := NSolve[-((r^2 (1/r^2 + 2 r - (-1 + b) r^(-2 + b)))/(1 - 1/r + r^2 -
r^(-1 + b))^2) + (2 r)/(1 - 1/r + r^2 - r^(-1 + b)) == 0, r]


Now, I need to use R[b_] to calculate and plot F, which is:

 F= R[b]/Sqrt[1 - 1/R[b]^(1 - b) - 1/R[b]]


How can I plot F?

ex = (2 r)/(1 - 1/r + r^2 -
r^(-1 + b)) - (r^2 (1/r^2 + 2 r - r^(-2 + b) (-1 + b)))/(1 -
1/r + r^2 - r^(-1 + b))^2;
ex = Simplify[ex]


If this expression should be zero, the numerator must be zero:

eq=r^2 (-3 + 2 r + (-3 + b) r^b) ==0


That means either r is zero or the second term. If r is zero, b is not determined. Therefore the second term must be zero:

(-3 + 2 r + (-3 + b) r^b) ==0


Note that this determines r only for b<1 Otherwise we get: -3+2 -2==0. And it is to be expected that near b==1 we will have some troubles.

We may use this to get r as a function of b:

fr[b_] := r /. FindRoot[-3 + 2 r + (-3 + b) r^b == 0, {r, 1}][[1]]


And with this we may define the final function and plot it:

ff[b_] := Module[ {r = fr[b]}, r/Sqrt[1 - 1/r^(1 - b) - 1/r]]
Plot[ff[b], {b, 0, 1}]


It is obvious that the function diverges toward 1.

• Thank you very much for your answer. This is really helpful. If I do not simplify my equation, is it possible to use result of NSolve for plot? Commented Sep 1, 2022 at 21:22
• In your plot, the value 1 in the horizontal axis corresponds to 35 in vertical axis. But in the plot by @DanielLichtblau, which is in the below post, 1 in horizontal axis corresponds to 5. where does this difference come from? Commented Sep 1, 2022 at 21:31
• Divide the horizontal axis of DanielLichtblau by the factor 10 to get b, since he generated points with distance 0.1 with Table[func[x], {x, 0., .9, 0.1}] Commented Sep 1, 2022 at 22:26

A little slow but can do like this.

rr[b_?NumberQ] :=
First@NSolveValues[-((r^2 (1/r^2 + 2 r - (-1 + b) r^(-2 + b)))/(1 -
1/r + r^2 - r^(-1 + b))^2) + (2 r)/(1 - 1/r + r^2 -
r^(-1 + b)) == 0, r]
func[b_] := rr[b]/Sqrt[1 - 1/rr[b]^(1 - b) - 1/rr[b]];

ListPlot[Table[func[x], {x, 0., .9, .1}]]


It is quite slow to find values for spacing of .01 though.

• Thank you very much. This is helpful. is not it possible to plot func[x] as a continuous line? Commented Sep 1, 2022 at 21:35
• The method by @DanielHuber seems fine. Commented Sep 1, 2022 at 21:37