% ShowRK2 script demonstrates % error of 2nd-order Runge-Kutta method % Requires RK2FixH, lnhde close all colors='ymcrgb'; xspan=[0 2*pi];y0=0; figure(1) hold on for p = 6:9 nsteps = 2^p; [x,y]=RK2FixH('lnhde',xspan,y0,nsteps); yext = (25/13)*cos(x) + ... (5/13)*sin(x) - ... (25/13)*exp(-5*x); err=(y-yext); plot(x,err,colors(p-3)) end xlabel('x') ylabel('y_{Computed} - y_{Exact}') title('Error in Runke-Kutta-2 solution with 2^{6}, 2^{7}, 2^{8}, 2^{9} steps')