Another way to proceed is to use CountRoots[]
+ RootIntervals[]
for finding the real roots:
CountRoots[5 - Sum[k^2 x^k, {k, 1, 100}], {x, -∞, ∞}]
2
which tells us that there are two real roots, and
RootIntervals[5 - Sum[k^2 x^k, {k, 1, 100}]]
{{{-1, 0}, {0, 1}}, {{1}, {1}}}
which tells us that the largest real root is within $(0,1)$; thus:
x /. First[NSolve[5 - Sum[k^2 x^k, {k, 1, 100}] == 0 && 0 < x < 1,
x, WorkingPrecision -> 25]]
0.4787782843622795018143755
For the case of getting the root with the largest real part, we can again use RootIntervals[]
to find isolating intervals, and then pick out the most extreme bounds:
recs = First[RootIntervals[5 - Sum[k^2 x^k, {k, 1, 100}], Complexes]];
cand = MaximalBy[Select[recs, Im[Last[#]] > 0 &], Re @* Last]
{{7/8, 1 + I/8}, {15/16 + I/8, 1 + I/4}, {3/4 + I/2, 1 + I}}
which leaves us with three candidates, instead of a hundred. From there:
(x /. First[NSolve[5 - Sum[k^2 x^k, {k, 1, 100}] == 0 &&
#[[1, 1]] < Re[x] < #[[2, 1]] &&
#[[1, 2]] < Im[x] < #[[2, 2]], x,
WorkingPrecision -> 25]]) & /@ ReIm[cand]
{0.9592093692777315093832973 + 0.0800374424094000451900130 I,
0.9423637156463657775951992 + 0.1412604810949637296158256 I,
0.7745164783087352268927909 + 0.5155444841877413797413391 I}
and it is clear that the first root returned has the largest real part.
sols = x /. Solve[5 - Sum[k^2 x^k, {k, 1, 100}] == 0, x]; Max[N@Re[sols]]
andrsols = x /. Solve[5 - Sum[k^2 x^k, {k, 1, 100}] == 0, x, Reals]; Max[N@Re[rsols]]
. For a wider perspecitve see e.g. this answer. $\endgroup$In[24]:= Max[Cases[x /. NSolve[f[x] == 0, x], _Real]] Out[24]= 0.478778284362
andIn[26]:= Max[Re[x /. NSolve[f[x] == 0, x]]] Out[26]= 0.959209369278
. $\endgroup$