# How can I perform NIntegrate with NDSolve?

I'm a new user and I have no idea how to perform NIntegrate by using NDSolve. For example consider following differential equation (DE):

sol = NDSolve[{y''[t] + 2/t y'[t] == 10 y[t], y[10] == 10, y'[10] == 0},
y[t], {t, 0, 10^9}, SolveDelayed -> True]

NIntegrate[t^2 y[t]/.sol , {t, 0, 10^5}]

• The solution to your ODE is y(t)=0. Commented Dec 11, 2015 at 5:08

There is no problem with your code except that Mma seems to be confused with the expression 2/t y'[t]. It is better to rewrite it as 2*y'[t]/t. After that this

    sol = NDSolve[{y''[t] + 2* y'[t]/t - 10 y[t] == 0, y[10] == 10,
y'[10] == 0}, y[t], {t, 1, 10}]


returns an interpolation function as a solution. It can be looked at:

LogPlot[Evaluate[y[t] /. sol], {t, 1, 10}]


ans also integrated:

 NIntegrate[Evaluate[t^2 y[t] /. sol], {t, 1, 10}]

(*  {4.61938*10^13}  *)


It is to be noted that the solution diverges at t->0. It is for this reason I started from 1. And the result of the integration is huge, even in my reduced limits. But, may be, it is OK with you.

Have fun!

Your example DE is simple enough for DSolve to show that y[t]==0. That probably isn't what you wanted, or that might be the reason your results don't seem correct.

Let's try another example.

sol = y[t] /. NDSolve[{y'[t]==y[t], y[0]==1}, y[t], {t, 0, 10}][[1]];
NIntegrate[sol, {t, 0, 6}]


which gives you 402.429 while

Integrate[E^t, {t, 0, 6}] // N


also gives you 402.429.