/*********************************************** ************************************************ ************************************************ Stiff.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.125; /* h:0.25; */ n:1/h; y[0]:1; for i:1 thru n step 1 do y[i]:(1-15*h)*y[i-1]; EulerApprox:create_list([i*h,y[i]],i,0,n); eq:'diff(y,t) = -15*y$ /* Solve ODE: */ sol: rk(rhs(eq),y,1,[t,0,1,h])$ /*RK4Approx:create_list([i*h , soln[i]],i,0,n); */ /* Plot the result: */ plot2d( [ [discrete,EulerApprox], [discrete,sol], exp(-15*t) ] ,[t,0,1] ,[xlabel,"x"] ,[ylabel,"y"] ,[legend, "EulerApprox", "RK" ," Exact"] )$