# Nested NIntegrate - NIntegrate::inum: - error

I have the problem quite similar as in: Nested NIntegrate I define two functions:

r[x_] := Evaluate[q[x] /. NDSolve[{q'[t] == 0.0001 + (-1 + I*1 + q[t])*q[t],q == 0}, q,
{t, 0, 50}]]

fn[k_?NumericQ] := Exp[8*NIntegrate[r[s]*Exp[2*beta*1] + 8*r[s], {s, 0, k}]]

beta=1


When I want to know the value of:

NIntegrate[fn[k], {k, 0, 5}]


I obtain following error:

NIntegrate::inum: "Integrand fn[k] is not numerical at {k} = {0.03978659976289378}."

Adding ?NumericQ to r[k_] I obtain error:

NIntegrate::inumr: "The integrand fn[k] has evaluated to non-numerical values for all sampling points in the region with boundaries {{0,5}}"

What do I wrong?

Your differential equation can be solved analytically

eqns = {q'[t] == 10^-4 + (-1 + I*1 + q[t])*q[t], q == 0};

sol = DSolve[eqns, q, t][]

(* Solve::ifun: Inverse functions are being used by Solve, so some solutions may
not be found; use Reduce for complete solution information.

{q -> Function[{t}, 1/100 ((50-50 I)+Sqrt[1+5000 I] Tan[1/100 (Sqrt[1+5000 I] t+
100 ArcTan[(249950/25000001+(250050 I)/25000001) Sqrt[1+5000 I]])])]} *)


Verifying that sol satisfies eqns

eqns /. sol // Simplify

(* {True, True} *)

r[x_] = q[x] /. sol;

beta = 1;

fn[k_?NumericQ] := Exp[8*NIntegrate[r[s]*Exp[2*beta*1] + 8*r[s], {s, 0, k}]]

NIntegrate[fn[k], {k, 0, 5}]

(* 5.07422 + 0.0503325 I *)


r[x_] := q[x] /.NDSolve[{q'[t] == 0.0001 + (-1 + I*1 + q[t])*q[t], q == 0}, q, {t, 0, 50}][]

• @Agnieszka Take a look at Part[]` in the help – Dr. belisarius Feb 21 '13 at 8:29