# How can I plot this integral?

I am in the following situation: I have a complicated ODE for the function f[x] that has no anlytical solution and an integral that depends on f[x]: how can I plot the integral?

As a MWE consider the following situation:

f'[x] = Sqrt[f[x]]
Integrate[f[x]^2,x]


EDIT This is what I get with the following attempt:

NDSolve[{f'[x] == Sqrt[f[x]], f[0] == 1}, f, {x, 0, 10}]
Plot[Integrate[f[x]^2, x], {x, 0, 10}]


• can you not solve the ODE numerically and obtain f(x) that way? Then you can integrate it. – Nasser Jan 16 '19 at 10:40
• I can solve the ODE numerically, but I don't know how to use the result to plot the integral. – mattiav27 Jan 16 '19 at 10:41
• result of NDSolve is a function. Which is f[x]. Then plug it into the integrand there and integrate it. You'll get a result which you can plot. – Nasser Jan 16 '19 at 10:43
• @Nasser see my edit – mattiav27 Jan 16 '19 at 10:55
• This is to calculate both results:DSolve[f'[x] == Sqrt[f[x]] && f [0] == 1, f, x] Integrate[f[x]^2 /. %, x] Plot[ %, {x, 0, 10}] – Boson Jan 16 '19 at 14:24

Does this do what you want?

sol = First@NDSolve[{f'[x] == Sqrt[f[x]], f[0] == 1}, f, {x, 0, 10}];
Plot[Evaluate[Integrate[f[x] /. sol, x]], {x, 0, 10}]


• Yes it does! thank you – mattiav27 Jan 16 '19 at 11:08
• ˋDSolveˋ will find 2 solutions in this case (cf. comments above) - how can this be achieved with ˋNDSolveˋ? (+1 of course) – gwr Jan 17 '19 at 7:15

You might also simply introduce another differential equation to obtain the antiderivative for f[x]:

sol = First @ NDSolve[
{
f'[x] == Sqrt @ f[x],
g'[x] == f[x]^2, (* so g[x] is the antiderivative of f[x]^2 *)
f[0] == 1,
g[0] == 0
}
, { f, g }
, { x, 0, 10 }
];
Plot[ g[x] /. sol, { x, 0, 10 } ]