1
$\begingroup$

I have a problem trying to solve an ODE with NDSolve. the equation to solve is the following

y'(t) + Coef(t)*y(t) = Coef(t)*f(t)

where Coef(t) and f(t) are piece-wise continuous as follows:

Coef(t) = a * 10^(b1 + b2/(b3 + f(t))) if f(t) <= f_lim1, a*10^(b1' + b2'/(b3' + f(t))) if don't.

f(t) = foExp(ct) if t< t_lim1 , fc if don't.

Something to note is that if I consider a function f(t) being linear for the non-constant region, the problem is solved, but if I use the above definition the error message appears:

--> NDSolve::ndinid: Initial condition Sign[-205.099+25. 13.^(1. -0.01 t)] is not in the range specified by the discrete variable NDSolve`s$64334.

Thanks by advance for your help.

afunLT[T[t]]=10^(-(314317625/88090787) + 1728383341/(
 918231 (7251941891/99821070 + T[t])))
afunHT[T[t]]=10^(-(826491756/48489179) + 1615782175/(
 1430678 (-(19665592279/131685570) + T[t])))

(5000 y[t])/(
   116234853 If[
     If[25 13^(1 - t/100) >= 25, 325 E^(1/100 (-Log[13]) t), 25] <= 
      205.099, 
     afunLT[If[25 13^(1 - t/100) >= 25, 325 E^(1/100 (-Log[13]) t), 
       25]], afunHT[
      If[25 13^(1 - t/100) >= 25, 325 E^(1/100 (-Log[13]) t), 25]]]) +
    Derivative[1][y][t] == (
  5000 (-325 + 
     If[25 13^(1 - t/100) >= 25, 325 E^(1/100 (-Log[13]) t), 25]))/(
  116234853 If[
    If[25 13^(1 - t/100) >= 25, 325 E^(1/100 (-Log[13]) t), 25] <= 
     205.099, 
    afunLT[If[25 13^(1 - t/100) >= 25, 325 E^(1/100 (-Log[13]) t), 
      25]], afunHT[
     If[25 13^(1 - t/100) >= 25, 325 E^(1/100 (-Log[13]) t), 25]]]), 
 y[0] == 0}, y, {t, 0, 100}
$\endgroup$
3
  • $\begingroup$ Could you upload code as well? $\endgroup$ Commented Mar 30, 2021 at 11:07
  • $\begingroup$ There's a variable t in your initial condition. That can't be good. $\endgroup$
    – Michael E2
    Commented Mar 30, 2021 at 17:40
  • $\begingroup$ Initial condition is set to y[0]==0 $\endgroup$ Commented Mar 30, 2021 at 17:47

1 Answer 1

1
$\begingroup$

Maybe this? (You're code is incomplete, so I had to guess some things).

afunLT[T_] = 
  10^(-(314317625/88090787) + 
     1728383341/(918231 (7251941891/99821070 + T)));
afunHT[T_] = 
  10^(-(826491756/48489179) + 
     1615782175/(1430678 (-(19665592279/131685570) + T)));
NDSolve[
 Solve[{(5000 y[t])/(116234853 If[
          If[25 13^(1 - t/100) >= 25, 325 E^(1/100 (-Log[13]) t), 
            25] <= 205.099, 
          afunLT[If[25 13^(1 - t/100) >= 25, 
            325 E^(1/100 (-Log[13]) t), 25]], 
          afunHT[If[25 13^(1 - t/100) >= 25, 
            325 E^(1/100 (-Log[13]) t), 25]]]) + 
      Derivative[1][y][
       t] == (5000 (-325 + 
          If[25 13^(1 - t/100) >= 25, 325 E^(1/100 (-Log[13]) t), 
           25]))/(116234853 If[
         If[25 13^(1 - t/100) >= 25, 325 E^(1/100 (-Log[13]) t), 
           25] <= 205.099, 
         afunLT[If[25 13^(1 - t/100) >= 25, 
           325 E^(1/100 (-Log[13]) t), 25]], 
         afunHT[If[25 13^(1 - t/100) >= 25, 
           325 E^(1/100 (-Log[13]) t), 25]]]), y[0] == 0}, {y'[t], 
    y[0]}
   ] /. Rule[a_, b_] :> a == PiecewiseExpand[b], y, {t, 0, 100}]

Does it look right?:

Mathematica graphics

$\endgroup$
4
  • $\begingroup$ Hi @Michael E2 thanks for the help, yep it is working, could be nice from you to get a hind in why you treat the problem like this :). $\endgroup$ Commented Mar 30, 2021 at 19:24
  • $\begingroup$ I'm trying to solve 25 independent EDOs with the same form and same initial conditions, the thing is in some solutions it gives an error like this: NDSolve::nderr: Error test failure at t == 1.785085980242561`; unable to continue. And there's just 1 coefficient changing, the one multiplying Coef(t) (i.e "a" from the formulation) $\endgroup$ Commented Mar 30, 2021 at 19:27
  • $\begingroup$ @CamiloSuarez I might be able to add more later: Briefly, the error comes from the condition in your If[]'s (by inspection), so I converted them to Piecewise functions, but I had to put them all on the same side of the equals sign. As for nderr on 25-ODE system, try Method -> "StiffnessSwitching". The error comes from the default LSODA solver (IDA also produces that error), and I don't have a good grasp of what causes the error test to fail. "StiffnessSwitching" sometimes succeeds in this case, so it's worth trying. $\endgroup$
    – Michael E2
    Commented Mar 30, 2021 at 19:45
  • $\begingroup$ thanks a lot for the explanations, Actually the Stiffness switching work for most equations just 1 of them still showing error: NDSolve::ndsz: At t == 17.947009325071043`, step size is effectively zero; singularity or stiff system suspected. Thanks a lot for the help :) $\endgroup$ Commented Mar 30, 2021 at 20:04

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.