0
$\begingroup$

Let's say I want to solve f[n,R]==0 with respect to R for n=1,2,3,... (up to some upper bound) and put this in a DiscretePlot or something equivalent. Reading this question, I decided to try

DiscretePlot[R /. NSolve[R*(R + 2)/(1 + R) == n && R > 0, R], {n, 1, 20}]

as an experiment, which worked with no errors. But then when I try my example,

DiscretePlot[R /. NSolve[Gamma[n/2, R^2] == 0.5 Gamma[n/2] && R > 0, R], {n, 1, 20}]

a ton of errors are thrown in between some time elapses, then an empty graph appears. For comparison, NSolve[Gamma[20/2, R^2] == Gamma[20/2] && R > 0, R] throws up a single error yet outputs {{R -> 3.10946}} in a fraction of a second.

How come the inputs for my situation aren't working even though the inputs for the other example are, and how do I fix it?

$\endgroup$
2
  • $\begingroup$ What version are you using? DiscretePlot[R /. NSolve[Gamma[n/2, R^2] == 0.5 Gamma[n/2] && R > 0, R], {n, 1, 20}] executes successfully with v12.1.1, 12.2, 12.3, and 12.3.1; I experienced problems with v12.0 $\endgroup$
    – Bob Hanlon
    Nov 10 '21 at 3:12
  • $\begingroup$ Well that sucks. I'm using v12.0.0 $\endgroup$
    – runway44
    Nov 10 '21 at 3:14
1
$\begingroup$

With v12.0 use FindRoot rather than NSolve

Clear["Global`*"]

$Version

(* "12.0.0 for Mac OS X x86 (64-bit) (April 7, 2019)" *)

DiscretePlot[
 R /. FindRoot[Gamma[n/2, R^2] == 1/2 Gamma[n/2], {R, (n + 9)/10}], 
  {n, 1, 20}]

enter image description here

$\endgroup$
2
  • $\begingroup$ Thanks this works. $\endgroup$
    – runway44
    Nov 10 '21 at 3:36
  • 2
    $\begingroup$ An alternativ workaround for v12.0 is sol[n_?NumericQ] := R /. NSolve[Gamma[n/2, R^2] == 0.5 Gamma[n/2] && R > 0, R][[1, 1]]; DiscretePlot[sol[n ], {n, 1, 20}] $\endgroup$ Nov 10 '21 at 10:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.