0
$\begingroup$

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] == 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?

$\endgroup$
2
$\begingroup$

Your differential equation can be solved analytically

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

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

(* 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 *)
$\endgroup$
1
$\begingroup$

Make your integrand numeric!

r[x_] := q[x] /.NDSolve[{q'[t] == 0.0001 + (-1 + I*1 + q[t])*q[t], q[0] == 0}, q, {t, 0, 50}][[1]]
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.07423 + 0.0503328 I
*)
$\endgroup$
  • $\begingroup$ I still get an error :NIntegrate::inumr: "The integrand fn[k] has evaluated to non-numerical values for all sampling points in the region with boundaries {{0,5}}. " $\endgroup$ – Agnieszka Feb 21 '13 at 8:00
  • $\begingroup$ Sorry, that's works, but the only difference which I see is a definition of r[x]. What means at the end of it [[1]]? (I'm not very good in Mathematica) $\endgroup$ – Agnieszka Feb 21 '13 at 8:07
  • $\begingroup$ @Agnieszka Take a look at Part[] in the help $\endgroup$ – Dr. belisarius Feb 21 '13 at 8:29

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.