# Challenging antiderivative loop

I am attempting to create a loop (either Do, For or While) that will continue to take antiderivatives of f(x)= x until the area under it between 0 and 10 is greater than 1000. And whichever function that is, the output should be that specific function.. I've done some leg work but I am certainly confused a bit..

I know that the integral of x^5/120 (which is the antiderivative of x, 4 times) is the function of desire because this antiderivative is x^6/720. Evaluating this from 0 to 10 yields 1388.8 which is greater than 1000.

I also know that:

Clear[f, x];
f[x_] = x;
TableForm[Rest@NestList[Integrate[#, x] &, f[x], 5]]


would produce a nice output of all the antiderivatives, which ends at x^6/120..

This was my best attempt at creating a loop that could solve this task..It doesn't produce anything, but its something I am working on..

Clear[f, x];
f[x_] = x;
Do[If[Integrate[f[x] > 1000, x],
Print[ToString[f[x] <> "area between 0 and 10 is not greater than 1000"],
Print[ToString[f[x] <> "area between 0 and 10 is greater than 1000"]],
{x, 1, 5}]]


The last part of the code is probably what's wrong. I'm trying to somehow iterate the function until that IF condition is satisfied..

Honestly I'm just throwing some things together but nothing is working the way I want it to. Any suggestions would be very helpful. Usually after some trial and error I will get the answer I need but I sure do spend a lot of time doing so!

Thanks again, Brandon

We discourage using loops in Mathematica. This is a functional way of doing the same thing:

f[x_] = x;

NestWhile[Integrate[#, x] &, f[x], (If[Integrate[#, {x, 0, 10}] < 1000,
Print[Integrate[#, x], " area between 0 and 10 is not greater than 1000"],
Print[Integrate[#, x], " area between 0 and 10 is greater than 1000"]];
Integrate[#, {x, 0, 10}] < 1000) &];


If you insist on being procedural, you could do this:

f[x_] = x;
Module[{f = f},
Do[
If[Integrate[f[x], {x, 0, 10}] < 1000,
Print[Integrate[f[x], x], " area between 0 and 10 is not greater than 1000"],
Print[Integrate[f[x], x], " area between 0 and 10 is greater than 1000"]; Return[]];
f[x_] = Integrate[f[x], x];
,10000]
]

• This is perfect. I suppose I was a ways off, but I was certainly in the right direction I would like to think...Thank you! Oct 16, 2016 at 5:24
• An alternative: NestWhile[Integrate[#, x] &, x, ((# /. x -> 10) <= 10^3) &, 1, ∞, -1]. Oct 16, 2016 at 5:29
• Hey @J.M. That's just as great! You guys rock. Oct 16, 2016 at 5:43
• Yet another alternative: D[NestWhile[Integrate[#,x]&,x,(#/.x->10)<=1000&],x] Oct 16, 2016 at 6:37