Find Roots in Do loop

Task: Finding roots in loop

t = List[1, 2, 3, 4, 5]
fx[x_] := a*x^2 – 5
List[Do[Print[FindRoot[fx[k] == 1, {a, 1}]], {k, 0, 5}]]

Output: Currently the output is as follows:

{a-> 6}
{a-> 1.5}

and so forth

But I want to have the values of a in a List in order to perfom further tasks (Plotting root of f_a against a)




Using Table and Map are things you should get really comfortable with in general, so look them up in documentation center, and browse around here a bit:
– ssch
Feb 11 ’13 at 16:06



Please try to avoid procedural loops
– Dr. belisarius
Feb 11 ’13 at 16:31



Don’t use Print to generate values that you want to process further on. ssch has good advice. The List you use doesn’t make sense here either. Another advice: Generally you should not define functions that have more dependencies than shown by the variables in the call pattern. In your case, the function depends on a as well, but that is not made explicit.
– Sjoerd C. de Vries
Feb 11 ’13 at 16:48


1 Answer


You have many many options. Here are just two:

Table[FindRoot[fx[k] == 1, {a, 1}], {k, t}]


FindRoot[fx[#] == 1, {a, 1}] & /@ t

Here is one way to make a plot of t vs the roots:

pts = Table[{k, a /. FindRoot[fx[k] == 1, {a, 1}]}, {k, t}];