/*********************************************** ************************************************ ************************************************ Euler.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 */ h:0.25; /*Time Step*/ n:4/h; u[0]:1;/*Initial Condition!*/ for i:1 thru n step 1 do u[i]:(1+h)*u[i-1]; EulerApprox1:create_list([i*h,u[i]],i,0,n); h:0.125; n:4/h; y[0]:1; for i:1 thru n step 1 do y[i]:(1+h)*y[i-1]; EulerApprox2:create_list([i*h,y[i]],i,0,n); /* Plot the result: */ plot2d( [[discrete,EulerApprox1],[discrete,EulerApprox2],exp(t)] ,[t,0,4] ,[style, [lines,5]] ,[xlabel,"time"] ,[ylabel,"Population"] ,[title,"Numerical Solution to dy/dt=F(t,y)"] ,[legend,"h=0.25","h=0.125","Exact Population"] )$