% A5PROB4C Script to use A5PROB4 to solve problem 4c on A#5 tf = 1.0; manu0 = @(x) 0; manu = @(x,t) t * cos(pi*x/2); J = [5 10 20 40 80 160 320 640 1280]; % expanded refinement path err = zeros(size(J)); for m = 1:length(J) U = a5prob4(J(m),tf,@manf,manu0); x = linspace(0,1,J(m)+1); err(m) = max(abs(U - manu(x,tf))); end dx=1./J; c=polyfit(log(dx),log(err),1) % fit line to data disp(['convergence at rate O(dx^{' num2str(c(1),7) '})']) loglog(dx,err,'o',dx,exp(c(1)*log(dx)+c(2)),'--') xlabel('\Delta x'), ylabel('error = max |U_j^N - u(x_j,t_f)|') axis tight, set(gca,'XTick',[1e-3 5e-3 1e-2 5e-2 1e-1])