# Help with plotting solution curves to the Gompertz equation

I'm relatively new in Mathematica. I already checked this post: Need code for differential equation analysis $\dot{x} = rx \ln \frac{K}{x}$ but it doesn't seems to help me. I apologize in advance if this kind of question was already asked, but I don't find an answer that can help me with the following issue: I'm solving the Gompertz equation:

$$\frac{dN}{dt}=-aN\ln(bN)$$

with initial conditions $$N(0)=\frac{1}{2b}$$

I want to plot the solution curves of this equation with the following conditions: \begin{aligned}-3\leq t\leq3\text{ et }-3\leq N\leq3.\end{aligned} all in one graph. something like this:

after trying using the function DNsolve in mathematica with no success, I decided I would plot directly from the solution of the equation: $$N(t)=\frac{1}{b}\exp({\ln{(1/2)}e^{-at}})$$

I use $$a=2$$ and $$b=2$$. I wrote the following code:

ClearAll["Global*"]

b = 2;
cValue = Log[1/2]; (*cte d'integration*)
a = 2;
f[t_] = 1/b*Exp[cValue*Exp[-a*t]]
curve1 = Plot[1/b*Exp[cValue*Exp[-a*t]], {t, -3, 3},
PlotStyle -> {Thickness[0.0065], Blue},
PlotRange -> All, PlotLabel -> "Plot pour condition N(0)",
AxesLabel -> {"t", "N"}]

(*plots pour plusieurs solutions pour les intervalles -3<t<3 et \
-3<n<3*)
samples1 = table[f[t], {t, -3, 3, 1}];
curves = Plot[Evaluate[samples1], {t, -3, 3}, PlotStyle -> {Black}];

Show[curves, curve1]


but I get this:

I can plot the curve with the initial condition (where the constant equals $$\log(1/2)$$) but not the other solution curves in the given interval. Can someone kindly help me to plot the family of curves or indicate me how can I do it with ND solve?

• I'm not quite sure what you are asking for, but I suspect that ParametricNDSolvemight be useful for you. If you just want to see the solution for various values of $a$ and $b$ then that should essentially be what you need.
– chuy
Feb 20 at 18:11
• Note that your code has table and not Table Feb 20 at 19:20
• Jeez, that's embarrasing. thanks for pointing it out @CraigCarter. Feb 21 at 0:03
• @chuy, I didn't know that function until now. thanks for the tip! Feb 21 at 0:05

Maybe

cValue = Log[1/2]; (*cte d'integration*)
f[t_] := 1/b*Exp[cValue*Exp[-a*t]]
Plot[Table[
1/b*Exp[cValue*Exp[-a*t]], {a, -2, 2,
1}, {b, {-1/2, -1/3, -1/6, 1/6, 1/3, 1/2}}] // Evaluate, {t, -3,
3}, PlotStyle -> {Thickness[0.0065], Blue}, PlotRange -> All,
PlotLabel -> "Plot pour condition N(0)",
AxesLabel -> {"t", "N"}] // Show


Or

Clear[funs];
funs = Table[
NDSolveValue[{n'[t] == -a*n[t]*Log[b*n[t]], n[0] == 1/(2 b)},
n[t], {t, -3, 3}], {a, -2, 2,
1}, {b, {-1/2, -1/3, -1/6, 1/6, 1/3, 1/2}}];
Plot[funs, {t, -3, 3}]


Or

Clear[sol];
sol =
ParametricNDSolveValue[{n'[t] == -a*n[t]*Log[b*n[t]],
n[0] == 1/(2  b)}, n[t], {t, -3, 3}, {a, b}];
Plot[Table[sol[a, b],
{a, -2, 2, 1}, {b, {-1/2, -1/3, -1/6, 1/6, 1/3, 1/2}}] //
Evaluate, {t, -3, 3}]


• This was just what I was looking for! thank you so much! now it make sense why the function NDsolve didn't work for solving this ODE in the first place.. If I may bother you with another silly question @cvgmt , I was wondering what is the difference between NDSolveValue and ParametricNDSolveValue. After reading the documentation, it seems to me the behave quite the same way. Feb 20 at 23:59

This is what I get. Note, your latex and code do not match. I assumed it is the Latex which is correct. But what I get does not exactly match what you show. So I think your ode is still missing something or your parameters are off somehow. Feel free to change this as needed.

f[t_, n_, a_, b_] = -a*n*Log[b/n]
a = 2; b = 2;
p1 = StreamPlot[{1, f[t, n, a, b]}, {t, -2, 2}, {n, -5, 5},
Frame -> False,
Axes -> True,
AspectRatio -> 1/GoldenRatio,
AxesLabel -> {"t", "N(t)"}, BaseStyle -> 12,
StreamPoints -> {{{{0, 1/(2*b)}, Red}, Automatic}}]
`

• If I understand correctly, it seems your graph is plotting the function from the right side of the ODE, but not the solution of the ODE itself, right? so, in order to get the right plot I change f by the solution I found, right? Feb 20 at 16:38