Message Boards Message Boards

0
|
7600 Views
|
6 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Integral evaluation fails

Posted 10 years ago

Hi All, I was trying to derive a formula by evaluating an integral. I defined all the restrictions for that setting and I wanted to have the solution in terms of a simplified formula. But Mathematica did not give the solution like last time (with some modification). I was wondering if there is anyone who can help me solve this problem.

Thank you in advance for your kind attention and support.

Here is the code for the equation A with Cp and infectable functions defined in it.

Cp[te_, Di_, Dv_, D0_] :=
 Which[
  Di + D0 <= Dv + te || Dv + te <= 0, 0,
  D0 < Dv + te && D0 + te < 0 && Di > Dv + te, Inf/(Inf + Ip),
  D0 < Dv + te && D0 + te >= 0 && Di > Dv + te, (D0 Inf)/(
  D0 Inf - Ip te),
  Di <= Dv + 
     te && ((te == 0 && D0 >= Dv) || (D0 >= Dv + te && te >= 0)), Di/
  Dv,
  D0 >= Dv + te && D0 + te < 0 && Di <= Dv + te, (Di Inf)/(
  D0 Ip + Inf (Dv + te)),
  D0 >= Dv + te && te < 0 && D0 + te >= 0 && Di <= Dv + te, (Di Inf)/(
  Dv Inf + Inf te - Ip te),
  D0 < Dv + te && D0 + Di >= Dv + te && D0 + te < 0 && 
   Di <= Dv + te, (Inf (D0 + Di - Dv - te))/(D0 (Inf + Ip)),
  D0 < Dv + te && D0 + Di >= Dv + te && te < 0 && D0 + te >= 0 && 
   Di <= Dv + te, (Inf (D0 + Di - Dv - te))/(D0 Inf - Ip te),
  te == 0 && D0 < Dv && D0 + Di >= Dv, (D0 + Di - Dv)/D0,
  D0 < Dv + te && D0 + Di >= Dv + te && te >= 0, 
  1 + (Di - Dv)/(D0 - te),
  D0 >= Dv + te && D0 + te < 0 && Di > Dv + te && Dv + te > 0, (
  Inf (Dv + te))/(D0 Ip + Inf (Dv + te)),
  D0 >= Dv + te && D0 + te >= 0 && Di > Dv + te && Dv + te > 0, (
  Inf (Dv + te))/(Dv Inf + (Inf - Ip) te),
  True, 0]
infectable[t_] := UnitStep[t]*UnitStep[D0 - t]
{$Assumptions = 
   Di < Dv && Dv < D0 && Di > 0 && Di \[Element] Reals && 
    D0 \[Element] Reals && Inf > 0 && Inf \[Element] Reals && 
    Ip > 0  && Ip \[Element] Reals  };
A = FullSimplify[(Inf/N/D0)*phi*tau*
   Integrate[
    Integrate[
     Integrate[
      infectable[ti] Cp[te, Di, Dv, D0], {tx, te + Dv, ti + Di}], {ti,
       te + Dv - Di, te + Dv}], {te, -Dv, D0 - Dv + Di}]]

It used to work when the Cp was defined as (Cor) for the integral (A).

Cor[te_, Di_, Dv_, D0_] :=
 Which[Di > Dv + te && Dv + te > 0, 1,
  te >= 0 && Dv + te <= D0, Di/Dv,
  te < 0 && Di <= Dv + te && Dv + te <= D0, Di/(Dv + te),
  te < 0 && Dv + te > D0, (Di - Dv - te + D0)/D0,
  Di + D0 < Dv + te || Dv + te <= 0, 0,
  True, 1 + (-Di + Dv)/(te - D0)]

infectable[t_] := UnitStep[t]*UnitStep[D0 - t]

{$Assumptions = 
   Di < Dv && Dv < D0 && Di > 0 && Di \[Element] Reals && 
    D0 \[Element] Reals && Inf > 0 && Inf \[Element] Reals && 
    Ip > 0  && Ip \[Element] Reals  };
A = FullSimplify[(Inf/N/D0)*phi*tau*
   Integrate[
    Integrate[
     Integrate[
      infectable[ti] Cor[te, Di, Dv, D0], {tx, te + Dv, 
       ti + Di}], {ti, te + Dv - Di, te + Dv}], {te, -Dv, 
     D0 - Dv + Di}]]

Here is the result from that equation

1/(4 D0 Dv N)
  Inf phi tau (Di (2 D0 Di^2 + (3 Di - 2 Dv) (Di - Dv) Dv) + 
    2 Dv ((-Di + Dv)^3 Log[1 - Di/Dv] + Di^3 Log[Dv/Di]))
Attachments:
POSTED BY: Welling Oei
6 Replies

Cp is indeed the complete (not all relevant) conditions for various settings we consider in the calculation. The full formulas for Cp was derived by Mathematica when I specified:

I'm still not confident with the model, for example it could be written equivalently as

In[19]:= Clear[infectable, preinfect, Di, Dv, D0, Inf, Ip]
{$Assumptions = Di < Dv && Di > 0 && D0 > 0};
infectable[t_] := UnitStep[t]*UnitStep[D0 - t]
preinfect[t_] := infectable[-t]
(* NRp=Inf/D0*FullSimplify[Integrate[infectable[ti],{ti,te,te+Dv}]]+\
Ip/D0*FullSimplify[Integrate[preinfect[ti],{ti,te,te+Dv}]] *)
NRp = Integrate[
   Inf infectable[ti] + Ip preinfect[ti], {ti, te, te + Dv}, 
   Assumptions -> te \[Element] Reals]/D0

Out[23]= (1/D0)(Inf UnitStep[
    Dv + te] (UnitStep[
       D0 - te] (D0 - 
        te + (-D0 + Dv + te) UnitStep[D0 - Dv - te]) UnitStep[
       te] - (-1 + 
        UnitStep[
         te]) ((Dv + te) UnitStep[-Dv - te] UnitStep[
          D0 - Dv - 
           te] + (D0 + (-D0 + Dv + te) UnitStep[
             D0 - Dv - te]) UnitStep[Dv + te])) + 
  Ip UnitStep[
    D0 + Dv + 
     te] ((-te + (Dv + te) UnitStep[-Dv - te]) UnitStep[-te] UnitStep[
       D0 + te] - (-1 + 
        UnitStep[
         D0 + te]) ((D0 + Dv + te) UnitStep[-Dv - te] UnitStep[-D0 - 
           Dv - te] + (D0 + (Dv + te) UnitStep[-Dv - te]) UnitStep[
          D0 + Dv + te])))

if this NRp is inverted, one gets a clear statement where the NRp is zero (there 1/NRp equals to ComplexInfinity) which was absent in other formulations ...

1/NRp reformulated

POSTED BY: Udo Krause
POSTED BY: Udo Krause
POSTED BY: Udo Krause

I will suggest removing the nested Integrate[Integrate[...]] and simply use one Integrate with all ranges inside. That way Integrate will know about ranges for all variables of integration, not just the one it is handling at the time. This might make a difference.

POSTED BY: Daniel Lichtblau
POSTED BY: Udo Krause

Dear Udo, Thank you for your kind assessment and suggestions.

Cp is indeed the complete (not all relevant) conditions for various settings we consider in the calculation. The full formulas for Cp was derived by Mathematica when I specified:

{$Assumptions = Di < Dv && Di > 0 && D0 > 0};
infectable[t_] := UnitStep[t]*UnitStep[D0 - t]
preinfect[t_] := UnitStep[D0 + t]*UnitStep[-t]
NRp = Inf/D0*
    FullSimplify[Integrate[infectable[ti], {ti, te, te + Dv}]] + 
   Ip/D0*FullSimplify[Integrate[preinfect[ti], {ti, te, te + Dv}]];
FullSimplify[PiecewiseExpand[TR/NRp], 
 Assumptions -> 
  Di < Dv && Di > 0 && D0 > 0 && Inf > 0 && Ip > 0  &&  D0 > 0  && 
   te \[Element] Reals]

Following your suggestion, I tried to reduce the conditions to a specific setting where Do>Dv>Di and te<0:

Cp[te_, Di_, Dv_, D0_] := 
 Which[D0 >= Dv + te && te < 0 && D0 + te >= 0 && 
   Di <= Dv + te, (Di Inf)/(Dv Inf + Inf te - Ip te), 
  D0 < Dv + te && D0 + Di >= Dv + te && te < 0 && D0 + te >= 0 && 
   Di <= Dv + te, (Inf (D0 + Di - Dv - te))/(D0 Inf - Ip te), 
  D0 >= Dv + te && D0 + te >= 0 && Di > Dv + te && Dv + te > 0, (
  Inf (Dv + te))/(Dv Inf + (Inf - Ip) te), True, 0]
infectable[t_] := UnitStep[t]*UnitStep[D0 - t]

{$Assumptions = 
   Di < Dv && Dv < D0 && Di > 0 && Di \[Element] Reals && 
    D0 \[Element] Reals && Inf > 0 && Inf \[Element] Reals && Ip > 0 &&
     Ip \[Element] Reals};

A = FullSimplify[(Inf/N/D0)*phi*tau*
   Integrate[
    Integrate[
     Integrate[
      infectable[ti] Cp[te, Di, Dv, D0], {tx, te + Dv, ti + Di}], {ti,
       te + Dv - Di, te + Dv}], {te, -Dv, D0 - Dv + Di}]]

Or for the setting where Do>Di>Dv and te<0:

Cp[te_, Di_, Dv_, D0_] := 
 Which[D0 >= Dv + te && te < 0 && D0 + te >= 0 && 
   Di <= Dv + te, (Di Inf)/(Dv Inf + Inf te - Ip te), 
  D0 < Dv + te && D0 + Di >= Dv + te && te < 0 && D0 + te >= 0 && 
   Di <= Dv + te, (Inf (D0 + Di - Dv - te))/(D0 Inf - Ip te), 
  D0 >= Dv + te && D0 + te >= 0 && Di > Dv + te && Dv + te > 0, (
  Inf (Dv + te))/(Dv Inf + (Inf - Ip) te), True, 0]
infectable[t_] := UnitStep[t]*UnitStep[D0 - t]

{$Assumptions = 
   Di > Dv && Dv < D0 && Di > 0 && Di \[Element] Reals && 
    D0 \[Element] Reals && Inf > 0 && Inf \[Element] Reals && Ip > 0 &&
     Ip \[Element] Reals};

A = FullSimplify[(Inf/N/D0)*phi*tau*
   Integrate[
    Integrate[
     Integrate[
      infectable[ti] Cp[te, Di, Dv, D0], {tx, te + Dv, ti + Di}], {ti,
       te + Dv - Di, te + Dv}], {te, -Dv, D0 - Dv + Di}]]

But I still got a conditional expression as the output.

Do you have some suggestions how to solve this?

Kind regards, Welling

POSTED BY: Welling Oei
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract