ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 01 Aug 2016 08:44:12 +0200visualizing logistic population growthhttps://ask.sagemath.org/question/34279/visualizing-logistic-population-growth/This is a followup question to [this question](http://ask.sagemath.org/question/34269/using-logistic-differential-equatin-reproducing-ti-nspire-cas-code/) where [@mforets](http://ask.sagemath.org/users/8657/mforets/) helped me translate some Ti Nspire code to Sagemath code. I now have following,
t = var('t')
y = function('y')(t)
ye = desolve(diff(y,t) == 2*10^(-5)*y*(1500-y), y, ics=[0,50])
ye = ye*3/100
yt = solve(ye.simplify_log(), y)
show(expand(yt))
Now I'm interested to visualize this result, reproducing some lecture notes. I looked at the examples given in the [Sage Quickstart for Differential Equations](http://doc.sagemath.org/html/en/prep/Quickstarts/Differential-Equations.html), but I cold not reproduce what was there with my example.
My lecture notes has a lot like this that I'm aim at
![image description](http://i.stack.imgur.com/fq08X.png)
By copying the right hand side (code below figure) manually I can get this, but I feel like I'm missing something;
![image description](http://i.stack.imgur.com/Zmuuw.png)
P = plot((1500*e^(3/100*t)/(e^(3/100*t) + 29)),t,0,250, color='red')
L = line([(0,1500), (260,1500)], linestyle=":", color="grey")
show(P+L, figsize=5)Sun, 31 Jul 2016 15:47:27 +0200https://ask.sagemath.org/question/34279/visualizing-logistic-population-growth/Answer by John Palmieri for <p>This is a followup question to <a href="http://ask.sagemath.org/question/34269/using-logistic-differential-equatin-reproducing-ti-nspire-cas-code/">this question</a> where <a href="http://ask.sagemath.org/users/8657/mforets/"><a href="/users/8657/mforets/">@mforets</a></a> helped me translate some Ti Nspire code to Sagemath code. I now have following,</p>
<pre><code>t = var('t')
y = function('y')(t)
ye = desolve(diff(y,t) == 2*10^(-5)*y*(1500-y), y, ics=[0,50])
ye = ye*3/100
yt = solve(ye.simplify_log(), y)
show(expand(yt))
</code></pre>
<p>Now I'm interested to visualize this result, reproducing some lecture notes. I looked at the examples given in the <a href="http://doc.sagemath.org/html/en/prep/Quickstarts/Differential-Equations.html">Sage Quickstart for Differential Equations</a>, but I cold not reproduce what was there with my example.</p>
<p>My lecture notes has a lot like this that I'm aim at
<img alt="image description" src="http://i.stack.imgur.com/fq08X.png"/></p>
<p>By copying the right hand side (code below figure) manually I can get this, but I feel like I'm missing something;
<img alt="image description" src="http://i.stack.imgur.com/Zmuuw.png"/></p>
<pre><code>P = plot((1500*e^(3/100*t)/(e^(3/100*t) + 29)),t,0,250, color='red')
L = line([(0,1500), (260,1500)], linestyle=":", color="grey")
show(P+L, figsize=5)
</code></pre>
https://ask.sagemath.org/question/34279/visualizing-logistic-population-growth/?answer=34281#post-id-34281When I execute your first block and look at `yt`, I get
sage: yt
[y(t) == 1500*e^(3/100*t)/(e^(3/100*t) + 29)]
So `yt` is a list, and it is better to consider the first entry in that list. For reasons I don't understand, I can't plot that, either, but I can plot its right-hand side.
sage: yt_0 = yt[0]
sage: yt_0_rhs = yt_0.rhs()
sage: yt_0_rhs
1500*e^(3/100*t)/(e^(3/100*t) + 29)
sage: plot(yt_0_rhs, (t, 0, 300))Sun, 31 Jul 2016 17:03:53 +0200https://ask.sagemath.org/question/34279/visualizing-logistic-population-growth/?answer=34281#post-id-34281Comment by ndomes for <p>When I execute your first block and look at <code>yt</code>, I get</p>
<pre><code>sage: yt
[y(t) == 1500*e^(3/100*t)/(e^(3/100*t) + 29)]
</code></pre>
<p>So <code>yt</code> is a list, and it is better to consider the first entry in that list. For reasons I don't understand, I can't plot that, either, but I can plot its right-hand side.</p>
<pre><code>sage: yt_0 = yt[0]
sage: yt_0_rhs = yt_0.rhs()
sage: yt_0_rhs
1500*e^(3/100*t)/(e^(3/100*t) + 29)
sage: plot(yt_0_rhs, (t, 0, 300))
</code></pre>
https://ask.sagemath.org/question/34279/visualizing-logistic-population-growth/?comment=34282#post-id-34282An example with some features like axes labels:
[http://sagecell.sagemath.org/?q=uwecsj](http://sagecell.sagemath.org/?q=uwecsj)Sun, 31 Jul 2016 22:43:20 +0200https://ask.sagemath.org/question/34279/visualizing-logistic-population-growth/?comment=34282#post-id-34282Comment by etb for <p>When I execute your first block and look at <code>yt</code>, I get</p>
<pre><code>sage: yt
[y(t) == 1500*e^(3/100*t)/(e^(3/100*t) + 29)]
</code></pre>
<p>So <code>yt</code> is a list, and it is better to consider the first entry in that list. For reasons I don't understand, I can't plot that, either, but I can plot its right-hand side.</p>
<pre><code>sage: yt_0 = yt[0]
sage: yt_0_rhs = yt_0.rhs()
sage: yt_0_rhs
1500*e^(3/100*t)/(e^(3/100*t) + 29)
sage: plot(yt_0_rhs, (t, 0, 300))
</code></pre>
https://ask.sagemath.org/question/34279/visualizing-logistic-population-growth/?comment=34283#post-id-34283Beautiful. Thanks! @ndomes, would it be possible for you to add your comment as a answer so that I can make it as answered? Thanks.Mon, 01 Aug 2016 08:44:12 +0200https://ask.sagemath.org/question/34279/visualizing-logistic-population-growth/?comment=34283#post-id-34283