// Script File: ShowRK // Plots absolute error for fixed step size Runge-Kutta // solution to y' = y, y(0) = 1 across [0,5]. // for %w=winsid(),xdel(%w);end E = zeros(5,5); for i = 1:5 n = 16*(2^i); Exact = exp(-linspace(0,5,n+1)'); for k = 1:5 [tvals,yvals] = FixedRK('f1',0,1,5/n,k,n); //! mtlb_max(abs(yvals-Exact)) may be replaced by //! max(abs(yvals-Exact)) if abs(yvals-Exact)is a vector //! max(abs(yvals-Exact),'r') if abs(yvals-Exact)is a matrix E(i,k) = mtlb_max(abs(yvals-Exact)); end end mtlb_semilogy([32,64,128,256,512]',E); xtitle('Runge-Kutta on y''(t) = -y(t), y(0) = 1, 0<=t<=5, h = 5/n',' ',' '); xtitle(' ','n (Number of Steps)',' '); xtitle(' ',' ','Maximum absolute error'); xstring(530,E(5,1)+0.003,'k=1'); xstring(530,E(5,2),'k=2'); xstring(530,E(5,3),'k=3'); xstring(530,E(5,4),'k=4'); xstring(530,E(5,5),'k=5'); disp('Evolution des erreurs :') for i=1:4 disp(E(i,:) ./ E(i+1, :)) end