Logistic growth model in continuous time

deq  =  {n'[t] == r (1  -  n[t]/k) n[t], 
        n[0] == n0}

para  =  {r -> 1,  k -> 10};

deqN  =  deq /. para /. n0 -> 0.1

sol  =  NDSolve[deqN, n[t], {t, 0, 10}]

Plot[ Evaluate[ n[t] /. sol], {t, 0, 10}]

Plot[ Evaluate[ Log[n[t]] /. sol], {t, 0, 10}]

Another growth model

deq  =  {n'[t] == r (1  -  n[t]/k) n[t] n[t], 
        n[0] == n0}

para  =  {r -> 1,  k -> 10};

deqN  =  deq /. para /. n0 -> 0.1

sol  =  NDSolve[deqN, n[t], {t, 0, 20}]

Plot[ Evaluate[ n[t] /. sol], {t, 0, 20}, 
      PlotRange -> All]

Plot[ Evaluate[ Log[n[t]] /. sol], {t, 0, 20}, 
      PlotRange -> All]

Logistic growth with time delay

Definition of NDelaySolve (first evaluate this part!)

\(\(Options[NDelaySolve]\  = \ {Verbose\  -> \ False};\)\(
\)
      \)
\(NDelaySolve[eqnConst_, \ initsConst_, \ indinterval_, \ 
            opts___]\  := 
\ \ Module[{
\ \ \ \ error\  = \ "Something is wrong", 
\ \ \ \ ind\  = \ indinterval[\([1]\)], 
\ \ \ \ start\  = \ 
                indinterval[\([2]\)], 
\ \ \ \ stop\  = \ 
                indinterval[\([3]\)], 
\ \ \ \ eqn\  = \ 
                Flatten[{eqnConst}], 
\ \ \ \ inits\  = \ 
                Flatten[{initsConst}], 
\ \ \ \ tau, \ deps, \ numdeps, \ 
              dtymes, \ delayedfs, \ numb, 
\ \ \ \ numbdelay, \ delaynum, \ 
              onedelay, \ forcedterms, \ sol, 
\ \ \ \ functs, \ 
              witchlist, \ g, \ numiters, \ subs, \ senteqn, 
\ \ \ \ i, j, 
              k1, k2}, 
\ \ 
\ \ deps\  = \ 
              Map[Part[#, 1]\  &, \ inits]; 
\ \ numdeps\  = \ 
              Length[deps]; 
\ \ 
\ \ printQ\  = \ \(Verbose\  /. \ {opts}\)\  /. \ Options[NDelaySolve]; 
\ \ If[printQ, 
              Print["eqn = ", \ eqn]]; 
\ \ If[printQ, 
              Print["inits = ", \ inits]]; 
\ \ If[printQ, \ 
              Print["interval = "\ , \ indinterval]]; 
\ \ If[printQ, \ 
              Print["ind = "\ , \ ind]]; 
\ \ If[printQ, \ 
              Print["start = "\ , \ start]]; 
\ \ If[printQ, \ 
              Print["stop = "\ , \ stop]]; 
\ \ If[printQ, \ 
              Print["deps = ", \ deps]]; 
\ \ 
\ \ dtymes\  = \ 
              Map[\ \((ind - #)\) &, 
\ \ \ \ Union[
                  Flatten[
                    delayedfs\  = \ 
                      Map[Cases[#, \ _Plus, \ Infinity] &, 
\ \ \ \ \ \ Map[
                          Cases[eqn, #, \ Infinity]\  &, \ 
                          deps\  /. \ 
                            ind\  -> \ 
                              Plus[__]]]
\ \ \ \ ]]]; 
\ \ 
\ \ If[printQ, 
              Print["dtymes = ", \ dtymes]]; 

\ \ dtymes\  = \ 
              Sort[
\ \ \ \ Map[
                  If[MemberQ[{Integer, \ Rational, \ Real}, \ 
                        Head[#]], #, 
\ \ \ \ If[
                        Head[\((numb\  = \ N[#])\)]\  === \ Real, \ numb, \ 
                        error]]\  &, dtymes]]; 
\ \ \ \ 
\ \ If[printQ, 
              Print["dtymes = ", \ dtymes]]; 

\ \ If[
              MemberQ[dtymes, error], 
              Return[error]]; 
\ \ If[\((tau\  = \ dtymes[\([1]\)])\)\  <= \ 
                0, \ 
              Return[error]]; 
\ \ onedelay\  = \ \((\((numbdelay\  = \ 
                      Length[dtymes])\)\  == \ 1)\); 

\ \ delayedfs\  = \ 
              Map[Union, delayedfs]; 
\ \ \ \ If[printQ, 
              Print["delayedfs = ", \ 
                delayedfs]]; 
\ \ 
\ \ forcedterms\  = \ 
              Table[Table[
                  deps[\([i]\)]\  /. \ 
                    ind\  -> \ delayedfs[\([i, j]\)], 
\ \ \ \ {j, 1, 
                    Length[delayedfs[\([i]\)]]}], \ {i, 1, 
                  Length[delayedfs]}]; 
\ \ If[printQ, \ 
              Print["forcedterms = ", \ 
                forcedterms]]; 
\ \ 
\ \ delayedfs\  = \ 
              N[delayedfs]; 
\ \ delaynum\  = \ 
              Map[Length, \ delayedfs]; 
\ \ 
\ \ 
\ \ funcs\  = \ 
              Map[Apply[Rule, #] &, \ inits]; 
\ \ If[printQ, \ 
              Print["funcs = ", \ funcs]]; 
\ \ witchlist\  = \ 
              Table[Which[
                  Evaluate[
                    ind\  <= \ start, 
\ \ \ \ deps[\([i]\)]\  /. \ 
                      funcs[\([i]\)]]\ ], \ {i, 1, numdeps}]; 
\ \ g\  = \ 
              Map[Function[Evaluate[ind], \ #]\  &, \ 
                witchlist]; 
\ \ numiters\  = \ 
              Ceiling[\((stop\  - \ start)\)/tau]; 

\ \ For[j\  = \ 1, \ 
              j\  <= \ numiters, \(j++\), 
\ \ \ \ jt\  = \ 
                N[start\  + \ j*tau]; 
\ \ \ \ If[printQ, \ 
                Print["jt = ", \ jt]]; 
\ \ 
\ \ \ \ sub\  = \ 
                Flatten[
                  Table[
\ \ \ \ \ \ Table[
                      forcedterms[\([k2, k1]\)]\  -> \ \(g[\([k2]\)]\)[
                          delayedfs[\([k2, k1]\)]], 
\ \ \ \ \ \ {k1, 1, 
                        delaynum[\([k2]\)]}], \ {k2, 1, 
                      Length[delaynum]}]]; 
\ \ \ 
\ \ \ \ ics\  = \ 
                Table[\((deps[\([i]\)]\  /. \ 
                        ind\  -> \ 
                          jt\  - \ tau)\)\  == 
\ \ \ \ \ \ \(g[\([i]\)]\)[
                      jt\  - \ tau], \ {i, 1, 
                    Length[deps]}]; 
\ \ \ \ \ \ 
\ \ \ \ senteqn\  = \ 
                Union[eqn\  /. \ sub, \ ics]; 
\ \ \ \ 
\ \ \ \ If[
                printQ, \ 
                Print["senteqn ", \ j, \ " = ", \ 
                  senteqn]]; 

\ \ \ \ sol\  = \ 
                Flatten[
\ \ \ \ \ \ NDSolve[senteqn, \ 
                    deps, \ {ind, \ jt\  - \ tau, \ jt}, 
                    opts]]; 

\ \ \ \ If[
                onedelay, 
\ \ \ \ \ \ witchlist\  = \ 
                  Table[Join[
                      witchlist[\([i]\)], \ 
\ \ \ \ \ \ \ \ Apply[
                        Which, {ind\  <= \ 
                            jt, 
\ \ \ \ \ \ \ \ deps[\([i]\)]\  /. \ 
                            sol}]], \ {i, 1, numdeps}]; 
\ \ \ \ \ \ g\  = \ 
                  Map[
                    Function[Evaluate[ind], \ #]\  &, 
\ \ \ \ \ \ \ \ Table[
                      Apply[Which, {ind\  <= \ 
                            jt, 
\ \ \ \ \ \ \ \ deps[\([i]\)]\  /. \ 
                            sol}], \ {i, 1, numdeps}]], 
\ \ \ \ \ \ g\  = \ 
                  Map[Function[
                        Evaluate[ind], \ #]\  &, 
\ \ \ \ \ \ \ \ Table[
                      Join[g[\([i, 2]\)], \ 
                        Apply[Which, {ind\  <= \ 
                              jt, 
\ \ \ \ \ \ \ \ deps[\([i]\)]\  /. \ 
                              sol}]], \ {i, 1, 
                        numdeps}]]
\ \ \ \ ]
\ \ ]; 
\ \ If[
              onedelay, 
\ \ \ \ g\  = \ 
                Map[Function[Evaluate[ind], \ #]\  &, \ 
                  witchlist]]; 
\ \ \ \ \ \ \ \ 
{Thread[
                Rule[deps, Through[g[ind]]]]}

];\)

deq =  {n'[t]  ==  
          r (1  -  n[t - delay]/k) n[t]}

Delay T = 1

para  =  {r -> 1,  k -> 10,  
          delay -> 1};

deqN  =  deq /. para

sol  =  
        NDelaySolve[deqN, {n[t] == 0.01}, {t, 0, 100}];

Plot[ n[t] /. sol, {t, 0, 100}, PlotRange -> All]

Delay T = 1.5

para  =  {r -> 1,  k -> 10,  
          delay -> 1.5};

deqN  =  deq /. para

sol  =  
        NDelaySolve[deqN, {n[t] == 0.01}, {t, 0, 100}];

Plot[ n[t] /. sol, {t, 0, 100}, PlotRange -> All]

Delay T = 1.6

para  =  {r -> 1,  k -> 10,  
          delay -> 1.6};

deqN  =  deq /. para

sol  =  
        NDelaySolve[deqN, {n[t] == 0.01}, {t, 0, 100}];

Plot[ n[t] /. sol, {t, 0, 100}, PlotRange -> All]

Delay T = 2

para  =  {r -> 1,  k -> 10,  
          delay -> 2};

deqN  =  deq /. para

sol  =  
        NDelaySolve[deqN, {n[t] == 0.01}, {t, 0, 100}];

Plot[ n[t] /. sol, {t, 0, 100}, PlotRange -> All]