How to get following loop output using pure functions such as NestList?
For[i = 0; v = 0, i < 4 && v < 4, i++; v++,
Print[x^i + b^v]]
and the output is
2
b+x
b^2+x^2
b^3+x^3
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityJust a generalization (of many possible):
fun[u_, n_] := Plus @@ (u^#) & /@ Range[0, n]
For example:
fun[{x,b},6]
yields:
{2, b + x, b^2 + x^2, b^3 + x^3, b^4 + x^4, b^5 + x^5, b^6 + x^6}
or
fun[{a,b,c},5]
{3, a + b + c, a^2 + b^2 + c^2, a^3 + b^3 + c^3, a^4 + b^4 + c^4, a^5 + b^5 + c^5}
MapThread[Function[{i, v}, Print[x^i + b^v]], {Range[0, 3], Range[0, 3]}]
$\endgroup$