 CoCalc Public FilesProjects / Project 1 Sample / Project 1 Topic - Groupmember 1 - Groupmember 2 - Groupmember 3.ipynb
Author: Mason High
Views : 147

# Mason High, Nicole Hester

Due Friday, February 21st at 5PM

MTH 337-001

Remember to use both markdown cells and calculations cells in your writeup.

For instance, the graph of $y=x^2$ as $x$ goes from $-1$ to $3$ is given below.

New York

This is a scatter plot of the given data for the population in thousands of New York from 1790-2000, where $t_0=1790$

In :
s = scatter_plot([[0,340],[1,589],[2,959],[3,1373],[4,1919],[5,2429],[6,3097],[7,3881],[8,4383],[9,5083],[10,6003],[11,7269],[12,9114],[13,10385],[14,12588],[15,13479],[16,14830],[17,16782],[18,18241],[19,17558],[20,17990],[21,18976]], title="New York Population between 1790-2000")
d = s.get_minmax_data()
d['xmin']
0.0
d['ymin']
0
d['xmax']
22
d['ymax']
20000
s+text("Population in Thousands",(-10,10000))+text("Time in Years",(10,-3000)) Exponential Growth Model

$P(t)=Ce^{kt}$ $C=P_0$ $P_0=340$ $t=11,P(t)=7269$ $7269=340e^{k(11)}$ $\frac{7269}{340}=e^{11k}$ $ln|\frac{7269}{340}|=11k$ $\frac{ln|\frac{7269}{340}|}{11}=k$ $k\approx.278$ $P(t)=340e^{(.278)t}$

In :
P,t=var('P,t')
f(t)=340*exp(.278*t)
t_min=-5
t_max= 23
P_min=0
P_max=20000
p=plot(f(t),(t,t_min,t_max),xmin=0,xmax=25,ymin=0,ymax=20000)
s = scatter_plot([[0,340],[1,589],[2,959],[3,1373],[4,1919],[5,2429],[6,3097],[7,3881],[8,4383],[9,5083],[10,6003],[11,7269],[12,9114],[13,10385],[14,12588],[15,13479],[16,14830],[17,16782],[18,18241],[19,17558],[20,17990],[21,18976]])
show(p+s) Estimated 2010 and 2020 Population

For 2010, the estimated population was 154,036 (in thousands) and for 2020 it will be about 203,403 (in thousands). Both of these estimates are larger than the actual values of New York's population which makes sense for our model as the first ten or so value are close but the deviation increases as time increases. In order to increase the accuracy of the 2020 estimate, some other factors that would affect the population would need to be accounted for so that the estimates aren't as large compared to the actual population.

Logistic Growth Model

Let's say that New York has a carrying capacity of 30,000,000. In thousands that is 30,000.

$\frac{dP}{dt}=(1-\frac{P}{N})P$ $N = carrying capacity$ $P(0)=340$ $\frac{dP}{dt}=(1-\frac{P}{30,000})P$ $\frac{30000}{P(30000-P)}dP$ $(\frac{1}{P}+\frac{1}{30000-P})dP=kdt$ $\int{(\frac{1}{P}+\frac{1}{30000-P})dP}=\int{kdt}$ $ln(|P|)-ln(|30000-P|)=kt+C$ $ln(|\frac{P}{30000-P}|)=kt+C$ $\frac{P}{30000-P}=e^{kt+C}$ $\frac{P}{30000-P}=e^{kt}+e^{C}$ $P=Ce^{kt}(30000-P)$ $30000Ce^{kt}-PCe^{kt}$ $P=\frac{30000Ce^{kt}}{Ce^{kt}+1}$ $P=\frac{30000}{Ce^{-kt}+1}$ $P(0)=340$ $340=\frac{30000}{Ce^{-k*0}+1}$ $340=\frac{30000}{C+1}$ $340(C+1)=30000$ $C+1=\frac{30000}{340}$ $C=\frac{1483}{17}$ $k=.278$ $P=\frac{30000}{\frac{1483}{17}e^{-.278t}+1}$

In :
t,y,x=var('t,y,x')
t_min=0
t_max=25
f(t)=(30000)/((1483/17)*exp(-.278*t)+1)
q=plot(f(t),(t,t_min,t_max),xmin=0,xmax=25,ymin=0,ymax=32000)
s = scatter_plot([[0,340],[1,589],[2,959],[3,1373],[4,1919],[5,2429],[6,3097],[7,3881],[8,4383],[9,5083],[10,6003],[11,7269],[12,9114],[13,10385],[14,12588],[15,13479],[16,14830],[17,16782],[18,18241],[19,17558],[20,17990],[21,18976]])
show(q+s) For 2010, the estimated population was 25,156 (in thousands) and for 2020 it will be about 26,182(in thousands). Both of these estimates are larger than the actual values of New York's population however, these are much closer to the actual values for New York which makes sense for the graph as the estimated values are more accurate

Euler's Method

In :
t,y = PolynomialRing(QQ,2,"ty").gens()
eulers_method((y*exp(.278*t)),0,340,1,21)

x y h*f(x,y) 0 340 340 1 680 897.930614102185 2 1577.93061410218 2751.41204463138 3 4329.34265873357 9968.35643741993 4 14297.6990961535 43471.1987866371 5 57768.8978827906 231933.462726138 6 289702.360608929 1.53587273153673e6 7 1.82557509214566e6 1.27801739041313e7 8 1.46057489962769e7 1.35018960682557e8 9 1.49624709678834e8 1.82645137431434e9 10 1.97607608399318e9 3.18524117927823e10 11 3.38284878767754e10 7.20037492875595e11 12 7.53865980752371e11 2.11885158320564e13 13 2.19423818128087e13 8.14374235601790e14 14 8.36316617414599e14 4.09868790111629e16 15 4.18231956285775e16 2.70660701367976e18 16 2.74843020930833e18 2.34869470632878e20 17 2.37617900842187e20 2.68135845667822e22 18 2.70512024676244e22 4.03084559430876e24 19 4.05789679677638e24 7.98443980310159e26 20 8.02501877106936e26 2.08508313864416e29 21 2.09310815741523e29 7.18129645787820e31
/ext/sage/sage-8.9_1804/local/lib/python2.7/site-packages/sage/repl/ipython_kernel/__main__.py:2: DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...) See http://trac.sagemath.org/5930 for details. from sage.repl.ipython_kernel.kernel import SageKernel

Eulers Method is accurate for the first population with regards to $t$, but became extremely inacccurate after the fact. This is less accurate when compared the the fourth order Runge-Kutta (below), which is accurate up to the 3rd population with regard to $t$.

Fourth order Runge-Kutta Method

In :
t,P=var('t,P')
desolve_rk4((340*exp(0.278*t)),P, ics=[-1,0], ivar=t, end_points=[0,20], step=1)

[[-1, 0], [0.0, 296.8318396696827], [1.0, 688.7941868456819], [2.0, 1206.375056117268], [3.0, 1889.833449929883], [4.0, 2792.33082532614], [5.0, 3984.066152554332], [6.0, 5557.736202885624], [7.0, 7635.745783309438], [8.0, 10379.72875192735], [9.0, 14003.12038736414], [10.0, 18787.75902904131], [11.0, 25105.80831400929], [12.0, 33448.7051880963], [13.0, 44465.3853550671], [14.0, 59012.75945461924], [15.0, 78222.36615871494], [16.0, 103588.3866652886], [17.0, 137083.866622342], [18.0, 181314.1855745249], [19.0, 239719.7112490383], [20.0, 316843.4017429747]]

Montana

This is a scatter plot of the given data for the population in thousands of Montana from 1870-2000, where $t_0=1870$

In :
s = scatter_plot([[0,21],[1,39],[2,143],[3,243],[4,376],[5,549],[6,538],[7,559],[8,591],[9,675],[10,694],[11,787],[12,799],[13,902]], title="Montana Population between 1870-2000")
d = s.get_minmax_data()
d['xmin']
0.0
d['ymin']
0
d['xmax']
15
d['ymax']
1000
s+text("Population in Thousands",(-3,500))+text("Time in Years",(7,-100)) Exponential Growth Model

$P(t)=Ce^{kt}$ $C=P_0$ $P_0=21$ $t=1,P(t)=39$ $39=21e^{k(1)}$ $\frac{39}{21}=e^{1k}$ $ln|\frac{39}{21}|=1k$ $\frac{ln|\frac{39}{21}|}{1}=k$ $k\approx.619$ $P(t)=21e^{(.619)t}$

In :
y,x=var('y,x')
f(t)=21*exp(0.619*x)
q=plot(f(t),(t,t_min,t_max),xmin=0,xmax=15,ymin=0,ymax=1000)
s = scatter_plot([[0,21],[1,39],[2,143],[3,243],[4,376],[5,549],[6,538],[7,559],[8,591],[9,675],[10,694],[11,787],[12,799],[13,902]])
show(q+s) We have created the above exponential model using the first population, of 21, as our $P_0$, because that is where the population starts. We decided to use the next year, t=1, P=39, to help us solve for $k$, because it made our exponential more accurate to the original data. This model fits the data for the first about 6 populations 1870-1930, but becomes wildly inaccurate after that.

Estimated 2010 Population

This model estimates that the population of 2010, $t=14$, was 121847, but this in thousands, in real numbers it is 121,847,000. The actually population of Montana in 2010 was 989,415, which is a lot smaller that the estimated value.

Logistic Growth Model

Let's say that Montana has a carrying capacity of 1,500,000, in thousands that is 1500. We chose this carrying capacity, because it gave more room for the population to grow from the year 2000. We will be using the the $k$ value, .417. We found this $k$ value by solving for it using our exponential function,using a mid point of the data which is when $t=8$ (1940) $P=591$. $ln(\frac{591}{21})=8k$, $k=\frac{ln\frac{{591}}{{21}}}{8}$, $k\approx.417$ This $k$ value made our logistic model more accurate to our original data.

$\frac{dP}{dt}=(1-\frac{P}{N})P$ $N = carrying capacity$ $P(0)=21$ $\frac{dP}{dt}=(1-\frac{P}{1500})P$ $\frac{1500}{P(1500-P)}dP$ $(\frac{1}{P}+\frac{1}{1500-P})dP=kdt$ $\int{(\frac{1}{P}+\frac{1}{1500-P})dP}=\int{kdt}$ $ln(|P|)-ln(|1500-P|)=kt+C$ $ln(|\frac{P}{1500-P}|)=kt+C$ $\frac{P}{1500-P}=e^{kt+C}$ $\frac{P}{1500-P}=e^{kt}+e^{C}$ $P=Ce^{kt}(1500-P)$ $1500Ce^{kt}-PCe^{kt}$ $P=\frac{1500Ce^{kt}}{Ce^{kt}+1}$ $P=\frac{1500}{Ce^{-kt}+1}$ $P(0)=21$ $21=\frac{1500}{Ce^{-k*0}+1}$ $21=\frac{1500}{C+1}$ $21(C+1)=1500$ $C+1=\frac{1500}{21}$ $C=\frac{493}{7}$ $k=.417$ $P=\frac{1500}{\frac{493}{7}e^{-.417t}+1}$

In :
t,y,x=var('t,y,x')
t_min=0
t_max=15
f(t)=(1500/((493/7)*exp(-.417*t)+1))
q=plot(f(t),(t,t_min,t_max),ymin=0,ymax=1700)
s = scatter_plot([[0,21],[1,39],[2,143],[3,243],[4,376],[5,549],[6,538],[7,559],[8,591],[9,675],[10,694],[11,787],[12,799],[13,902]])
show(q+s) The above Logistic model is accurate at the first 2 populations, 1870-1880, and between the 8th and 12th populations, 1950-1990, but is not as accurate between the 2nd and 8th populations, 1880-1950.

Estimated 2010 Population

This model extimates that the population in 2010, $t=14$, will be 1245 in thousands, in real numbers that is 1,245,000. This is not as far off of 989,415 as the exponential model was. This means that the logistic model better fits the way the population in Montana is growing than the exponential model.

Euler's Method

In :
t,y = PolynomialRing(QQ,2,"ty").gens()
eulers_method((y*exp(.619*t)),0,21,1,14)

x y h*f(x,y) 0 21 21 1 42 77.9969418042685 2 119.996941804268 413.834550507003 3 533.831492311271 3418.92082389472 4 3952.75231620599 47012.4342476488 5 50965.1865638548 1.12568023274638e6 6 1.17664541931023e6 4.82631111654341e7 7 4.94397565847443e7 3.76594795601901e9 8 3.81538771260375e9 5.39715575111615e11 9 5.43530962824218e11 1.42783771040922e14 10 1.43327302003746e14 6.99216661967487e16 11 7.00649934987525e16 6.34763890551583e19 12 6.35464540486571e19 1.06913053420253e23 13 1.06976599874302e23 3.34238509624232e26 14 3.34345486224106e26 1.93995405594528e30
/ext/sage/sage-8.9_1804/local/lib/python2.7/site-packages/sage/repl/ipython_kernel/__main__.py:2: DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...) See http://trac.sagemath.org/5930 for details. from sage.repl.ipython_kernel.kernel import SageKernel

Eulers Method is accurate for the first 3 populations with regards to $t$, which means it is accurate between the years 1870-1890, but becomes extremely inacccurate after the fact.

Estimated 2010 Population

In 2010 t=14, and the above model, Euler's Method, predicts the population will be $\approx 3.343e26$, which is extremely larger than the actually population of Montana which was 989,415. It shows that Euler's Method is more accurate in the begining of the data and not as the data gets farther and farther away from the starting point.

Fourth order Runge-Kutta Method

In :
t,P=var('t,P')
desolve_rk4((21*exp(0.619*t)),P, ics=[-1,0], ivar=t, end_points=[0,14], step=1)

[[-1, 0], [0.0, 15.65808207840933], [1.0, 44.73623723641293], [2.0, 98.73640808484853], [3.0, 199.0185076821339], [4.0, 385.2493906892606], [5.0, 731.0931845955554], [6.0, 1373.349333802144], [7.0, 2566.063988399758], [8.0, 4781.018643250908], [9.0, 8894.344579287066], [10.0, 16533.07895202516], [11.0, 30718.74372175657], [12.0, 57062.51680508041], [13.0, 105984.7486166248], [14.0, 196836.7597485285]]

The fourth order Runge-Kutta is accurate up to the 6th population with regard to $t$, which means it is accurate between the years 1870-1920. This means it is a little more accurate Euler's Method, but it becomes less accurate as time goes on.

Estimated 2010 Population

The Runge-Kutta Method predicted in 2010, $t=14$ to be 196836 in thousands in real numbers that is 196,836,000. The model is still far off the actually population of 989,415, but it is closer than Eulers Method. This also supports the above statement that Runge-Kutta is more accurate than Eulers Method, but Runge-Kutta is also more accurate when it is closer to the beggining of the data and becomes more innaccurate as time goes on.

Estimating 2020 Population

The model that would be the best at estimating the 2020 population would be the logistic model, because it is the most accurate out of all the models above, with regards to the data provided. The logistic model is also the model that has the closest estimate to the actual 2010 population of Montana.

In [ ]: