2
$\begingroup$

I am trying to integrate (function2) an integrand (function1) that is a function of a ParametricNDSolve output (solution1). This somehow works if I use Integrate for function1, as opposed to using NIntegrate. But, if I use NIntegrate, I receive a ParametricNDSolve error saying "500 cannot be used as a parameter." Is there a solution to this? Any help would be greatly appreciated!

Alex

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

solution1[g_, t0_] := H[t] /. ParametricNDSolve[{X'[t] == 
  X[t]*b*H[t]/HMax - X[t]*d*(X[t] + Y[t])/K, 
 Y'[t] == 
  Y[t]*b*(1 - c*g)*H[t]/HMax + 
   Y[t]*b*(1 - c*g)*g*(1 - H[t]/HMax) - Y[t]*d*(X[t] + Y[t])/K, 
 H'[t] == Y[t]*b*(1 - c*g)*(1 - H[t]/HMax)*g - a*H[t], 
 X[0] == ((b E^((b E^(-a t0) K t0)/HMax) K^2)/(d E^(a t0) (-1 + 
         E^((b E^(-a t0) K t0)/HMax)) HMax + b K)), Y[0] == 1, 
 H[0] == Exp[-a*t0]*HMax}, {X[t], Y[t], H[t]}, {t, 0, 
 10000}, {t0}] // First;

function1[g_, t0_] := NIntegrate[t*solution1[g, t0]/K, {t, 0, 200}]

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

function2[0.4]
$\endgroup$

1 Answer 1

0
$\begingroup$

We can set g as parameter in ParametricNDSolve

a = 0.03; b = d = 1; c = 0.5; K = HMax = 2000; v = 10^(-7);
 sol = ParametricNDSolve[{X'[t] == 
     X[t]*b*H[t]/HMax - X[t]*d*(X[t] + Y[t])/K, 
    Y'[t] == 
     Y[t]*b*(1 - c*g)*H[t]/HMax + Y[t]*b*(1 - c*g)*g*(1 - H[t]/HMax) -
       Y[t]*d*(X[t] + Y[t])/K, 
    H'[t] == Y[t]*b*(1 - c*g)*(1 - H[t]/HMax)*g - a*H[t], 
    X[0] == ((b E^((b E^(-a t0) K t0)/HMax) K^2)/(d E^(a t0) (-1 + 
            E^((b E^(-a t0) K t0)/HMax)) HMax + b K)), Y[0] == 1, 
    H[0] == Exp[-a*t0]*HMax}, {X, Y, H}, {t, 0, 10000}, {g, t0}];

function1[g_, t0_] := 
  NIntegrate[t*H[g, t0][t]/K /. sol, {t, 0, 200}];
function1[10, 1]

1059.44

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

function2[0.4]

0.468472

But the last code get some warning message.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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