% eulplot.m % This estimates and plots numerical solutions to an ODE using Euler's method. % It calls the function eulstdnt.m. Both M-files get initial information from % initn.m. cla axis(initax); tmatr=[]; xmatr=[]; tsize=[]; tvec=[]; xvec=[]; tmax=t0; xmin=x0; xmax=x0; for j=1:max(size(hvec)) [t,x]=eulstdnt(eulerfcn,hvec(j),t0,x0,tf) if min(x)>-inf if xmin>min(x) xmin=min(x); end end if max(x)max(size(t)) t=[t,zeros(1,v-max(size(t)))]; else tmatr=[tmatr,zeros(u,max(size(t))-v)]; end tmatr=[tmatr;t]; [u,v]=size(xmatr); if v>max(size(x)) x=[x,zeros(1,v-max(size(x)))]; else xmatr=[xmatr,zeros(u,max(size(x))-v)]; end xmatr=[xmatr;x]; if j==minhindex tmax=max(t); tvec=t; xvec=x; end end axis([t0,tf,xmin,xmax]); ax=axis; plotlabel=['Euler: x'' = ',ftx,', h = [',num2str(hvec),']']; slopef(ftx,N); %hold on for j=1:max(size(hvec)) plot(tmatr(j,1:tsize(j)),xmatr(j,1:tsize(j))) end xlabel(plotlabel) hold off ax=[t0,tf,xmin,xmax];