Can't NIntegrate my NDSolve results

I want to NIntegrate my NDSolve result. I don't have a exact function form because it is coming from the NDSolve result. It looks like Integrate only permit numerical forms.

The function y1[t] could be solved through several differential equations:

S1 = NDSolve[{y1'[t] == -0.9*y1[t] + SuperPlus[z1][t] +
SuperMinus[z2][t] + 0.005*SuperPlus[z1][t]*y2[t] +
0.008*SuperMinus[z2][t]*y2[t] + 0.005*x[t]*SuperPlus[z1][t] +
0.008*x[t]*SuperMinus[z2][t] - 0.008*y1[t]*SuperMinus[z1][t] -
0.005*y1[t]*SuperPlus[z2][t],
y2'[t] == -0.8*y2[t] + SuperPlus[z2][t] + SuperMinus[z1][t] +
0.008*y1[t]*SuperMinus[z1][t] + 0.005*y1[t]*SuperPlus[z2][t] +
0.005*x[t]*SuperPlus[z2][t] + 0.008*x[t]*SuperMinus[z1][t] -
0.005*SuperPlus[z1][t]*y2[t] - 0.008*SuperMinus[z2][t]*y2[t],
SuperPlus[z1]'[t] == 0.63*y1[t] - SuperPlus[z1][t],
SuperPlus[z2]'[t] == 0.64*y2[t] - SuperPlus[z2][t],
SuperMinus[z1]'[t] == 0.27*y1[t] - SuperMinus[z1][t],
SuperMinus[z2]'[t] == 0.16*y2[t] - SuperMinus[z2][t],
x[t] + y1[t] + y2[t] + SuperPlus[z1][t] + SuperPlus[z2][t] +
SuperMinus[z1][t] + SuperMinus[z2][t] == 50000000,
SuperPlus[z1][0] == SuperPlus[z2][0] == SuperMinus[z1][0] ==
SuperMinus[z2][0] == 0, y1[0] == y2[0] == 10000000,
x[0] == 30000000}, {x, y1, y2, SuperPlus[z1], SuperMinus[z1],
SuperPlus[z2], SuperMinus[z2]}, {t, 0, 100}]


The result is quite clear in image:

Plot[Evaluate[y1[t] /. S1], {t, 0, 100}, PlotStyle -> Blue,
AxesOrigin -> {0, 0}, PlotRange -> All]


The image is here:

While, I can't use NIntegrate or Integrate to this function y1[t]. It doesn't give me result.

NIntegrate[Boole[y1[t]], {t, 0, 100}]


NIntegrate::inumr: The integrand Boole[y1[t]] has evaluated to non-numerical values for all sampling points in the region with boundaries {{0,100}}. >>

What should I do? Shall I use Monte Carlo method??

• Please clarify your question. What, precisely, do you wish to do but are unable? – bbgodfrey Oct 5 '15 at 0:02
• problem is updated and clarified. – Zhaohui Li Oct 5 '15 at 0:15
• Hint: If Plot[Evaluate[y1[t] /. S1], {t, 0, 100}] works, then NIntegrate[Evaluate[y1[t] /. S1], {t, 0, 100}] probably will. The similarity in the syntax of related functions is by design. – Michael E2 Oct 5 '15 at 1:08
• Why did you not include the error message? Is it not a hint to what is wrong? – Michael E2 Nov 4 '15 at 11:00

NIntegrate[y1[t] /. S1, {t, 0, 100}]


yields

(* {1.17532*10^9} *}


which seems reasonable. Using Boole was the problem.

• I can't believe it is so simple ~!!!! Thanks you very much. You really save my day! – Zhaohui Li Oct 5 '15 at 0:22

As shown by bbgodfrey , NIntegrate can solve your problem, but I just want to add, Integrate can actually handle InterpolatingFunction:

int[t_] = Integrate[y1[t] /. S1, t]


The output is an InterpolatingFunction representing the definite integral of $y_1(t)$ over $[0,t]$. The advantage of this approach is, you don't need to integrate again and again if you want to know the integral at other points. Just compare the following:

Table[int@t, {t, 0, 100, 1/10}]; // AbsoluteTiming
(* {0.015558, Null} *)
int2[tt_] := NIntegrate[y1[t] /. S1, {t, 0, tt}]
Table[int2@t, {t, 0, 100, 1/10}]; // AbsoluteTiming
(* {2.340323, Null} *)


Then

• something went wong... – chris Nov 4 '15 at 12:18
• @chris Yeah, after trying for times I noticed the original timing is inaccurate. Modified, thx for pointing out. – xzczd Nov 4 '15 at 12:54