I would like to plot the results of FindRoot over certain range of inputs. I tried to do this with the code:

Plot[Evaluate[FindRoot[f[m, b], {m, 1}][[1, 2]]], {b, 0,2}]

where I want to plot the roots of f[m,b] vs. b ranging over [0,2]. I'm not sure this code is working, because although I do get a plot, I also get this error:

FindRoot::nlnum: "The function value {1.[VeryThinSpace]-(2.\Gamma[2.,0.,(1.[VeryThinSpace]+1. b)/Sqrt[b]])/(1.[VeryThinSpace]+1.\b)}\n is not a list of numbers with dimensions {1} at {m} = {1.`}."

Note the function I'm trying to find the roots for is:

f[M_, b_] := 1 - (2 M Gamma[2, 0, (1/M + b M)/Sqrt[b]])/(1/M + b M)


  • $\begingroup$ You can also remove Evaluate. The FindRoot won't be evaluated until a number for b is plugged in. $\endgroup$ – Michael E2 May 27 '13 at 14:38

Define in addition the function

g[b_?NumericQ] := FindRoot[f[m, b], {m, 1}][[1, 2]]

and then make the Plot for this one:

Plot[g[b], {b, 0, 2}]

enter image description here

  • $\begingroup$ Thanks, I had come up with a way of doing it using Do and ListPlot but this is much nicer. $\endgroup$ – misi Apr 18 '13 at 23:18

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.