% num3plot.m % Generates three plots on page: Euler's method appxs on slope field; error of % Euler appx vs Runge-Kutta (4th order); Runge-Kutta (4th order) appxs on slope % field. % Requires the M-files INITN.M, EULSTDNT.M, SLOPEF.M RK4.M, HWSOL1.M. % INITN.M must be called first and contain appropriate entries for all % variables/parameters. figans=input('Do you already have a separate figure window for num3plot? (y/n) ','s'); if figans=='n'; numfig=figure; end figure(numfig) clf set(numfig,'DefaultAxesFontSize',8) subplot(2,2,2) eulplot eulxmatr=xmatr; subplot(2,2,4) rk4plot rk4xmatr=xmatr; subplot(2,2,3) [u,v]=size(tmatr); cla hold on for j=1:length(hvec) tplot=[]; xplot=[]; for k=1:v if tmatr(j,k)==0 & tmatr(j,k+1)==0 break else tplot=[tplot,tmatr(j,k)]; xplot=[xplot,abs(eulxmatr(j,k)-rk4xmatr(j,k))]; end end plot(tplot,xplot) end xlabel(['Error: Eul vs RK4, h=[',num2str(hvec),']']) hold off clear *xmatr