1
$\begingroup$

When running the following code, I get the error message that "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

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Michael E2 Dec 1 '18 at 20:58
0
$\begingroup$

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

$\endgroup$
  • $\begingroup$ Thank you very much - this works! However, if I make the equations slightly more complicated (see edited question), I get the same error message. $\endgroup$ – Wolfgang H. Dec 1 '18 at 17:35
0
$\begingroup$

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

$\endgroup$
  • $\begingroup$ Thank you so much - your help is highly appreciated! $\endgroup$ – Wolfgang H. Dec 2 '18 at 9:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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