# Error Message NIntegrate: "The integrand ... has evaluated to non-numerical values..."

When running the following code, I get the error message that "NIntegrate::inumr: The integrand ... has evaluated to non-numerical values for all sampling points in the region with boundaries {{0,0.0695171}}". Can anyone help?

Here is the code:

ClearAll["Global*"]
R0[S_] := Integrate[RC[s] - RA, {s, 0, S}];
V[s_, S_] := αh ((RC[s] + ph)^(-(ρ/σ))  + (αh/αz)^(-(ρ/σ)))^((1 - ρ)/ρ)*
(w - Tw + G + R0[S]/L - pf s - FC) ;
h[s_, S_] := (RC[s] + ph)^-σ/((αh/αz)^(-(ρ/σ)) + (RC[s] + ph)^(-(ρ/σ)))*
(w - Tw + G + R0[S]/L - pf s - FC);
sol[S_] = Solve[{D[V[s, S], s] == 0}, RC'[s]];
solprime = Equal @@@ Flatten[sol[S]];
αh = 0.2; αz = 0.2; γ = 5; ph = 0.01; pf = 1; Tw = 0.3; G = 2; FC = 0.1;
w = 1; ρ = 0.2; σ = 1/(1 - ρ); L = 1; RA = 0.1; S = 0.9;
solND = NDSolve[{solprime[[1]], RC[S] == RA}, RC, {s, 0, S}]
Plot[RC[s] /. solND, {s, 0, S}]
pop = NIntegrate[1/h[s, S] /. First[solND], {s, 0, S}];


I don't know what goes wrong here.

ADDED after Henrik Schumacher's comment:

ClearAll["Global*"]
R0[S_] := Integrate[RC[s] - RA, {s, 0, S}];
P[s_, S_] := γ Integrate[(((αh/αz)^(-(ρ/σ))) + ((RC[x] + ph)^(-(ρ/σ))) )/
((RC[x] + ph)^-σ (w - Tw + G + R0[S]/L - (pf + tC) x - FC - TC)), {x, s, S}]
V[s_, S_] := αh ((RC[s] + ph)^(-(ρ/\[Sigma])) + (αh/αz)^(-(ρ/σ)))^((1 - ρ)/
ρ) (w - Tw + G + R0[S]/L - (pf + tC) s - FC - TC) - P[s, S] ;
h[s_, S_] := (RC[s] + ph)^-σ/((αh/αz)^(-(ρ/σ)) + (RC[s] + ph)^(-(ρ/σ)))*
(w - Tw + G + R0[S]/L - (pf + tC) s - FC - TC);
sol[S_] = Solve[{D[V[s, S], s] == 0}, RC'[s]];
solprime = Equal @@@ Flatten[sol[S]]
αh = 0.2; αz = 0.2; γ = 5; ph = 0.01; pf = 1; Tw = 0.3; G = 2; FC = 0.1;
tC = 0; TC = 0; w = 1; ρ = 0.2; σ = 1/(1 - ρ); L = 1; RA = 0.1; R0 = 1; S = 0.9;
solND = NDSolve[{solprime[[1]], RC[S] == RA}, RC, {s, 0, S}]
pop = NIntegrate[1/h[s, S] /. First[solND] /. Integrate -> NIntegrate, {s, 0, S}]


This gives me the same error message.

Thanks, Wolfgang

• The first thing I try in such a circumstance is to evaluate the integrand myself at some value in the interval of integration to see what the result. Often I've left something undefined or misused another function. Dec 1, 2018 at 20:58

The Integrate in R0 does not get evaluated (because the integrand is a InterpolatingFunction?).

Try the following:

pop = NIntegrate[1/h[s, S] /. First[solND] /. Integrate -> NIntegrate, {s, 0, S}]


0.129487

• Thank you very much - this works! However, if I make the equations slightly more complicated (see edited question), I get the same error message. Dec 1, 2018 at 17:35

Try the following on your revised more complicated code.

ClearAll["Global*"]
αh=0.2; αz=0.2; γ=5; ph=0.01; pf=1; Tw=0.3; G=2; FC=0.1; tC=0; TC=0; w=1;
ρ=0.2; σ=1/(1-ρ); L=1; RA=0.1; R0=1; S=0.9;
V[s_, S_] := αh ((RC[s]+ph)^(-ρ/σ)+(αh/αz)^(-ρ/σ))^((1-ρ)/ρ)*
(w-Tw+G+Integrate[RC[s]-RA,{s,0,S}]/L-(pf+tC)s-FC-TC)-γ*
Integrate[((αh/αz)^(-ρ/σ)+(RC[x]+ph)^(-ρ/σ))/((RC[x]+ph)^-σ*
(w-Tw+G+Integrate[RC[s]-RA,{s,0,S}]/L-(pf+tC)x-FC-TC)),{x,s,S}];
h[s_, S_] := (RC[s]+ph)^-σ/((αh/αz)^(-ρ/σ)+(RC[s]+ph)^(-ρ/σ))(w-Tw+G+
Integrate[RC[s]-RA,{s,0,S}]/L-(pf+tC)s-FC-TC);
sol[S_] = Solve[{D[V[s, S],s]==0},RC'[s]];
solprime = Equal@@@Flatten[sol[S]];
solND = NDSolve[{solprime[[1]], RC[S] == RA},RC,{s,0,S}];
pop = NIntegrate[1/h[s,S]/.First[solND]/.Integrate->NIntegrate,{s,0,S}]
`

which returns 0.120297

• Thank you so much - your help is highly appreciated! Dec 2, 2018 at 9:11