# differential equations – Passing a Piecewise function of NIntegrate through NIntegrate?

I am trying to pass a piecewise numerical integral (function1) through another numerical integral (function2). When I try this, however, I receive an error that says “t = T is not a valid limit of integration.” So, it seems that function1 is not “receiving” the values that are being passed to it from function2. Is there a solution to this problem? Any help would be greatly appreciated!

Alex

``````a = 0.03; b = d = 1; c = 0.5; K = HMax = 2000; v = 10^(-7);

function1(g_, t0_) := Block({HandX1, h7, HandX2, h8, B3},

HandX1 = DSolve({H'(t) == -a*H(t), H(0) == HMax,
X'(t) == X(t)*b*H(t)/HMax - X(t)*d*X(t)/K, X(0) == K}, {H(t),
X(t)}, t); h7 = HandX1((1))((1))((2));

B3(u_?NumericQ) := NIntegrate(h7*t, {t, t0, u}, Method -> {Automatic, "SymbolicProcessing" -> 0});

HandX2 = DSolve({H'(u) == -a*H(u), H(0) == HMax,
X'(u) == X(u)*b*H(u)/HMax - X(u)*d*X(u)/K, X(0) == K}, {H(u),
X(u)}, u); h8 = HandX2((1))((1))((2));

Piecewise({{0, g < 0.2}, {2/(1 + NIntegrate(Exp(-B3(u))*h8/K, {u, t0, 5000},Method -> {Automatic, "SymbolicProcessing" -> 0})), g >= 0.2}}))

function2(g_) :=Block({},1 - Exp(-v*
NIntegrate(function1(g, T), {T, 0, 500},
Method -> {Automatic, "SymbolicProcessing" -> 0})))

function2(0.4)
``````