Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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)

Thanks!

share|improve this question
    
You can also remove Evaluate. The FindRoot won't be evaluated until a number for b is plugged in. –  Michael E2 May 27 '13 at 14:38
add comment

1 Answer

up vote 3 down vote accepted

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

share|improve this answer
    
Thanks, I had come up with a way of doing it using Do and ListPlot but this is much nicer. –  misi Apr 18 '13 at 23:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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