2
$\begingroup$

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}]
$\endgroup$
1
  • 1
    $\begingroup$ The solution to your ODE is y(t)=0. $\endgroup$
    – Nasser
    Commented Dec 11, 2015 at 5:08

2 Answers 2

5
$\begingroup$

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}]

enter image description here

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!

$\endgroup$
2
$\begingroup$

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.

Perhaps you can adapt this to your real problem.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.