/*********************************************** ************************************************ ************************************************ Euler_logistic.mac This software is a part of: Kai Velten: Mathematical Modeling and Simulation, Wiley-VCH, 2009. It can be used under the conditions of the GNU General Public License (GPLv3), see http://www.gnu.org/licenses/gpl.html. ************************************************ ************************************************ ************************************************/ /* Initializations */ r : 0.07; K : 1000; /*can store 1/K instead.*/ final_time: 1000; h:1; n:final_time/h; y[0]:100; for i:1 thru n step 1 do y[i]:(1+(h*r*(1 - y[i-1]/K)))*y[i-1]; EulerApprox1:create_list([i*h,y[i]],i,0,n); h:5; n:final_time/h; y[0]:100; for i:1 thru n step 1 do y[i]: (1+(h*r*(1 - y[i-1]/K)))*y[i-1]; EulerApprox2:create_list([i*h,y[i]],i,0,n); /* Plot the result: */ plot2d([[discrete,EulerApprox1],[discrete, EulerApprox2], K*100/(100 +(K-100)*exp(-r*t))] ,[t,0,100] ,[style, points, points, lines], [color, magenta,black, blue, green], [point_type, circle, asterisk] ,[xlabel,"Time"] ,[ylabel,"Population Growth"],[legend, "h= 1 years", "h = 5 years" ,"Actual Population Growth"] ,[title, "Logistic Model for the population"] ,[gnuplot_preamble,"set key bottom"]);