NIntegrate is resetting my variables and not giving me a result?

I am trying to check if mass conservation holds by integrating the area under a curve but to no avail.


Clear[Eq0, EvapThickFilm, h, Bo, ϵ, K1, δ, Bi, m, r]
Eq0[h_, {Bo_, ϵ_, K1_, δ_, Bi_, m_, r_}] :=
D[h, t] + Div[(-h^3)*Bo*Grad[h] + h^3*Grad[Laplacian[h]] + ((δ*h^3)/(Bi*h + K1)^3)*Grad[h]
+ m*(h/(K1 + Bi*h))^2*Grad[h]] + ϵ/(Bi*h + K1) + r*D[D[h^2/(K1 + Bi*h), x]*h^3, x] == 0;

L = 2*92.389;
TMax = 2491.29*100;
hSol[x_, y_, t_] = h[x, y, t] /.
NDSolve[{EvapThickFilm[0.003, 0, 1, 0, 1, 0.025, 0],
h[0, y, t] == h[L, y, t], h[x, 0, t] == h[x, L, t],
h[x, y, 0] == 1 + (-0.25*Cos[2*Pi*(x/L)] – 0.25*Sin[2*Pi*(x/L)])*
Cos[2*Pi*(y/L)]}, h, {x, 0, L}, {y, 0, L}, {t, 0, TMax},
MaxStepFraction -> 1/60][[1]]

When I use NIntegrate[…] to integrate under the area of the curve for a single value of TMax, I don’t get a single valued number. In fact, my variables are reset! What gives?

NIntegrate[hSol[x, y, 0.1*TMax], {x, 0, L}, {y, 0, L}]

I’ve tried it with simpler 2D cases instead of 3D and this works fine.

FOOTNOTE: Is there some way I could host this code elsewhere? Any websites that support mathematica code format?


The error that NIntegrate[..] gives me is that x = L is not a valid limit of integration. whilst L has actually been defined in the problem previously.




Please don’t post your entire assignment/project and ask us to debug. It’s not easy to do, especially when we don’t know the background to your problem. It might be better if you can reduce the issue to a small, readable code snippet and people can think over it and give you a solution over a coffee break 🙂
– R. M.♦
Mar 28 ’12 at 17:56



@R.M Yes, I realize that. I don’t know where else I could post the code itself so as to focus on the problem that the code is stricken by here! 🙁
– drN
Mar 28 ’12 at 17:58



Also, code in box form, e.g. with SubscriptBox, etc, is extremely difficult to read. Can you convert it to InputForm and repost? To do so, select the cell, right click (ctrl-click on mac), and Convert To -> InputForm.
– rcollyer
Mar 28 ’12 at 17:59



@rcollyer did that. Still is an ugly mass of text. Boy mathematica sure can be an ugly environment. Anyway…
– drN
Mar 28 ’12 at 18:02



Actually, that’s readable now.
– rcollyer
Mar 28 ’12 at 18:10


1 Answer


Some of the symbols you’re using depend on the VectorAnalysis package. So, be sure to execute the following from a fresh kernel.


Also, be sure to define your hSol function for only numeric values.

hSol[x_?NumericQ,y_?NumericQ,t_?NumericQ] := …



This is the answer. However, I couldn’t ever have known of the _?NumericQ thingy! I’ll have to look it up. Aah, the trials and tribulations of being a paper and pencil engineer!
– drN
Mar 28 ’12 at 18:33